@webtransport-bun/webtransport 0.2.0 → 0.2.2
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/dist/errors.d.ts +54 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +53 -0
- package/dist/index.d.ts +489 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1367 -0
- package/dist/streams.d.ts +72 -0
- package/dist/streams.d.ts.map +1 -0
- package/dist/streams.js +177 -0
- package/package.json +1 -1
- package/prebuilds/SHA256SUMS +3 -3
- package/prebuilds/webtransport-native.darwin-arm64.node +0 -0
- package/prebuilds/webtransport-native.darwin-x64.node +0 -0
- package/prebuilds/webtransport-native.linux-x64-gnu.node +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node stream wrappers for WebTransport QUIC streams.
|
|
3
|
+
*
|
|
4
|
+
* All bidi streams are exposed as Duplex.
|
|
5
|
+
* Outgoing uni streams are Writable, incoming uni streams are Readable.
|
|
6
|
+
*
|
|
7
|
+
* Stream control extensions (reset / stopSending) are attached via symbols
|
|
8
|
+
* to avoid name collisions with Node stream methods.
|
|
9
|
+
*/
|
|
10
|
+
import { Duplex, Readable, Writable } from "node:stream";
|
|
11
|
+
import type { DuplexOptions, ReadableOptions, WritableOptions } from "node:stream";
|
|
12
|
+
/**
|
|
13
|
+
* Symbol to call stream reset (abort receiving). Use on BidiStream, SendStream, RecvStream.
|
|
14
|
+
* @example `(stream as Resettable)[WT_RESET](code)`
|
|
15
|
+
*/
|
|
16
|
+
export declare const WT_RESET: unique symbol;
|
|
17
|
+
/**
|
|
18
|
+
* Symbol to send stopSending (abort sending). Use on BidiStream, RecvStream.
|
|
19
|
+
* @example `(stream as StopSendable)[WT_STOP_SENDING](code)`
|
|
20
|
+
*/
|
|
21
|
+
export declare const WT_STOP_SENDING: unique symbol;
|
|
22
|
+
/** Stream that supports reset via WT_RESET. */
|
|
23
|
+
export type Resettable = {
|
|
24
|
+
[WT_RESET](code?: number): void;
|
|
25
|
+
};
|
|
26
|
+
/** Stream that supports stopSending via WT_STOP_SENDING. */
|
|
27
|
+
export type StopSendable = {
|
|
28
|
+
[WT_STOP_SENDING](code?: number): void;
|
|
29
|
+
};
|
|
30
|
+
type StreamHandleId = number;
|
|
31
|
+
export interface BidiStreamOptions extends DuplexOptions {
|
|
32
|
+
handleId: StreamHandleId;
|
|
33
|
+
nativeHandle?: any;
|
|
34
|
+
}
|
|
35
|
+
export declare class BidiStream extends Duplex implements Resettable, StopSendable {
|
|
36
|
+
#private;
|
|
37
|
+
private readonly _handleId;
|
|
38
|
+
constructor(opts: BidiStreamOptions);
|
|
39
|
+
_read(_size: number): void;
|
|
40
|
+
_write(chunk: Buffer, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
41
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
42
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
43
|
+
[WT_RESET](code?: number): void;
|
|
44
|
+
[WT_STOP_SENDING](code?: number): void;
|
|
45
|
+
}
|
|
46
|
+
export interface SendStreamOptions extends WritableOptions {
|
|
47
|
+
handleId: StreamHandleId;
|
|
48
|
+
nativeHandle?: any;
|
|
49
|
+
}
|
|
50
|
+
export declare class SendStream extends Writable implements Resettable {
|
|
51
|
+
#private;
|
|
52
|
+
private readonly _handleId;
|
|
53
|
+
constructor(opts: SendStreamOptions);
|
|
54
|
+
_write(chunk: Buffer, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
55
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
56
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
57
|
+
[WT_RESET](code?: number): void;
|
|
58
|
+
}
|
|
59
|
+
export interface RecvStreamOptions extends ReadableOptions {
|
|
60
|
+
handleId: StreamHandleId;
|
|
61
|
+
nativeHandle?: any;
|
|
62
|
+
}
|
|
63
|
+
export declare class RecvStream extends Readable implements StopSendable {
|
|
64
|
+
#private;
|
|
65
|
+
private readonly _handleId;
|
|
66
|
+
constructor(opts: RecvStreamOptions);
|
|
67
|
+
_read(_size: number): void;
|
|
68
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
69
|
+
[WT_STOP_SENDING](code?: number): void;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=streams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streams.d.ts","sourceRoot":"","sources":["../src/streams.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EACX,aAAa,EACb,eAAe,EACf,eAAe,EACf,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,OAAO,MAA2B,CAAC;AAC1D;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,OAAO,MAAkC,CAAC;AAExE,+CAA+C;AAC/C,MAAM,MAAM,UAAU,GAAG;IAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAC7D,4DAA4D;AAC5D,MAAM,MAAM,YAAY,GAAG;IAAE,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAKtE,KAAK,cAAc,GAAG,MAAM,CAAC;AAM7B,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACvD,QAAQ,EAAE,cAAc,CAAC;IACzB,YAAY,CAAC,EAAE,GAAG,CAAC;CACnB;AAED,qBAAa,UAAW,SAAQ,MAAO,YAAW,UAAU,EAAE,YAAY;;IACzE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiB;gBAI/B,IAAI,EAAE,iBAAiB;IAc1B,KAAK,CAAC,KAAK,EA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MAAM,WAAW,iBAAkB,SAAQ,eAAe;IACzD,QAAQ,EAAE,cAAc,CAAC;IACzB,YAAY,CAAC,EAAE,GAAG,CAAC;CACnB;AAED,qBAAa,UAAW,SAAQ,QAAS,YAAW,YAAY;;IAC/D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiB;gBAI/B,IAAI,EAAE,iBAAiB;IAU1B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAc1B,QAAQ,CAChB,KAAK,EAAE,KAAK,GAAG,IAAI,EACnB,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GACtC,IAAI;IAaP,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;CAGtC"}
|
package/dist/streams.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node stream wrappers for WebTransport QUIC streams.
|
|
3
|
+
*
|
|
4
|
+
* All bidi streams are exposed as Duplex.
|
|
5
|
+
* Outgoing uni streams are Writable, incoming uni streams are Readable.
|
|
6
|
+
*
|
|
7
|
+
* Stream control extensions (reset / stopSending) are attached via symbols
|
|
8
|
+
* to avoid name collisions with Node stream methods.
|
|
9
|
+
*/
|
|
10
|
+
import { Duplex, Readable, Writable } from "node:stream";
|
|
11
|
+
/**
|
|
12
|
+
* Symbol to call stream reset (abort receiving). Use on BidiStream, SendStream, RecvStream.
|
|
13
|
+
* @example `(stream as Resettable)[WT_RESET](code)`
|
|
14
|
+
*/
|
|
15
|
+
export const WT_RESET = Symbol("WT_RESET");
|
|
16
|
+
/**
|
|
17
|
+
* Symbol to send stopSending (abort sending). Use on BidiStream, RecvStream.
|
|
18
|
+
* @example `(stream as StopSendable)[WT_STOP_SENDING](code)`
|
|
19
|
+
*/
|
|
20
|
+
export const WT_STOP_SENDING = Symbol("WT_STOP_SENDING");
|
|
21
|
+
export class BidiStream extends Duplex {
|
|
22
|
+
_handleId;
|
|
23
|
+
#nativeHandle;
|
|
24
|
+
#destroyed = false;
|
|
25
|
+
constructor(opts) {
|
|
26
|
+
super({
|
|
27
|
+
...opts,
|
|
28
|
+
allowHalfOpen: true,
|
|
29
|
+
autoDestroy: false,
|
|
30
|
+
readableHighWaterMark: opts.readableHighWaterMark ?? 256 * 1024,
|
|
31
|
+
writableHighWaterMark: opts.writableHighWaterMark ?? 256 * 1024,
|
|
32
|
+
});
|
|
33
|
+
this._handleId = opts.handleId;
|
|
34
|
+
this.#nativeHandle = opts.nativeHandle;
|
|
35
|
+
}
|
|
36
|
+
// -- Node stream overrides -----------------------
|
|
37
|
+
_read(_size) {
|
|
38
|
+
const h = this.#nativeHandle;
|
|
39
|
+
if (!h || this.#destroyed) {
|
|
40
|
+
this.push(null);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
h.read()
|
|
44
|
+
.then((buf) => {
|
|
45
|
+
if (buf && !this.#destroyed)
|
|
46
|
+
this.push(buf);
|
|
47
|
+
else
|
|
48
|
+
this.push(null);
|
|
49
|
+
})
|
|
50
|
+
.catch((err) => this.destroy(err));
|
|
51
|
+
}
|
|
52
|
+
_write(chunk, _encoding, callback) {
|
|
53
|
+
const h = this.#nativeHandle;
|
|
54
|
+
if (!h || this.#destroyed) {
|
|
55
|
+
callback(new Error("E_STREAM_RESET"));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
h.write(chunk)
|
|
59
|
+
.then(() => callback())
|
|
60
|
+
.catch(callback);
|
|
61
|
+
}
|
|
62
|
+
_final(callback) {
|
|
63
|
+
this.#nativeHandle?.finish?.();
|
|
64
|
+
callback();
|
|
65
|
+
}
|
|
66
|
+
_destroy(error, callback) {
|
|
67
|
+
if (!this.#destroyed) {
|
|
68
|
+
this.#destroyed = true;
|
|
69
|
+
try {
|
|
70
|
+
this.#nativeHandle?.reset?.(0);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
/* already closed */
|
|
74
|
+
}
|
|
75
|
+
this.#nativeHandle = null;
|
|
76
|
+
}
|
|
77
|
+
callback(error);
|
|
78
|
+
}
|
|
79
|
+
// -- Stream control extensions -------------------------------------------
|
|
80
|
+
[WT_RESET](code) {
|
|
81
|
+
this.#nativeHandle?.reset(code ?? 0);
|
|
82
|
+
this.destroy();
|
|
83
|
+
}
|
|
84
|
+
[WT_STOP_SENDING](code) {
|
|
85
|
+
this.#nativeHandle?.stopSending(code ?? 0);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export class SendStream extends Writable {
|
|
89
|
+
_handleId;
|
|
90
|
+
#nativeHandle;
|
|
91
|
+
#destroyed = false;
|
|
92
|
+
constructor(opts) {
|
|
93
|
+
super({
|
|
94
|
+
...opts,
|
|
95
|
+
autoDestroy: true,
|
|
96
|
+
highWaterMark: opts.highWaterMark ?? 256 * 1024,
|
|
97
|
+
});
|
|
98
|
+
this._handleId = opts.handleId;
|
|
99
|
+
this.#nativeHandle = opts.nativeHandle;
|
|
100
|
+
}
|
|
101
|
+
_write(chunk, _encoding, callback) {
|
|
102
|
+
const h = this.#nativeHandle;
|
|
103
|
+
if (!h || this.#destroyed) {
|
|
104
|
+
callback(new Error("E_STREAM_RESET"));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
h.write(chunk)
|
|
108
|
+
.then(() => callback())
|
|
109
|
+
.catch(callback);
|
|
110
|
+
}
|
|
111
|
+
_final(callback) {
|
|
112
|
+
this.#nativeHandle?.finish?.();
|
|
113
|
+
callback();
|
|
114
|
+
}
|
|
115
|
+
_destroy(error, callback) {
|
|
116
|
+
if (!this.#destroyed) {
|
|
117
|
+
this.#destroyed = true;
|
|
118
|
+
try {
|
|
119
|
+
this.#nativeHandle?.reset?.(0);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
/* already closed */
|
|
123
|
+
}
|
|
124
|
+
this.#nativeHandle = null;
|
|
125
|
+
}
|
|
126
|
+
callback(error);
|
|
127
|
+
}
|
|
128
|
+
[WT_RESET](code) {
|
|
129
|
+
this.#nativeHandle?.reset(code ?? 0);
|
|
130
|
+
this.destroy();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export class RecvStream extends Readable {
|
|
134
|
+
_handleId;
|
|
135
|
+
#nativeHandle;
|
|
136
|
+
#destroyed = false;
|
|
137
|
+
constructor(opts) {
|
|
138
|
+
super({
|
|
139
|
+
...opts,
|
|
140
|
+
autoDestroy: true,
|
|
141
|
+
highWaterMark: opts.highWaterMark ?? 256 * 1024,
|
|
142
|
+
});
|
|
143
|
+
this._handleId = opts.handleId;
|
|
144
|
+
this.#nativeHandle = opts.nativeHandle;
|
|
145
|
+
}
|
|
146
|
+
_read(_size) {
|
|
147
|
+
const h = this.#nativeHandle;
|
|
148
|
+
if (!h || this.#destroyed) {
|
|
149
|
+
this.push(null);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
h.read()
|
|
153
|
+
.then((buf) => {
|
|
154
|
+
if (buf && !this.#destroyed)
|
|
155
|
+
this.push(buf);
|
|
156
|
+
else
|
|
157
|
+
this.push(null);
|
|
158
|
+
})
|
|
159
|
+
.catch((err) => this.destroy(err));
|
|
160
|
+
}
|
|
161
|
+
_destroy(error, callback) {
|
|
162
|
+
if (!this.#destroyed) {
|
|
163
|
+
this.#destroyed = true;
|
|
164
|
+
try {
|
|
165
|
+
this.#nativeHandle?.stopSending?.(0);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
/* already closed */
|
|
169
|
+
}
|
|
170
|
+
this.#nativeHandle = null;
|
|
171
|
+
}
|
|
172
|
+
callback(error);
|
|
173
|
+
}
|
|
174
|
+
[WT_STOP_SENDING](code) {
|
|
175
|
+
this.#nativeHandle?.stopSending(code ?? 0);
|
|
176
|
+
}
|
|
177
|
+
}
|
package/package.json
CHANGED
package/prebuilds/SHA256SUMS
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
3388211bfec9b7c14f33f2fe1b88aa13e5f3dbfffbc7bce84936c1d78dc626e8 webtransport-native.darwin-arm64.node
|
|
2
|
+
634ce73b0a6280b456680c4cbd5d90bd43218d5664845620087add84c62ef52a webtransport-native.darwin-x64.node
|
|
3
|
+
4029469b08be023d20a7e32be69c329b364f7812ec3853b43dccca5e9bbccd95 webtransport-native.linux-x64-gnu.node
|
|
Binary file
|
|
Binary file
|
|
Binary file
|