@radheim/plugin-browser 0.0.0-stage → 2.4.3
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/README.md +144 -3
- package/dist/connection.d.ts +516 -0
- package/dist/connection.js +432 -0
- package/dist/egress-policy.d.ts +65 -0
- package/dist/egress-policy.js +446 -0
- package/dist/files.d.ts +75 -0
- package/dist/files.js +200 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +11 -0
- package/dist/machine.d.ts +231 -0
- package/dist/machine.js +435 -0
- package/dist/preview-path.d.ts +7 -0
- package/dist/preview-path.js +28 -0
- package/dist/proxy-machine.d.ts +33 -0
- package/dist/proxy-machine.js +30 -0
- package/dist/proxy.d.ts +29 -0
- package/dist/proxy.js +438 -0
- package/dist/rpc.d.ts +2739 -0
- package/dist/rpc.js +502 -0
- package/dist/skill.d.ts +11 -0
- package/dist/skill.js +93 -0
- package/dist/stream-mux.d.ts +72 -0
- package/dist/stream-mux.js +1129 -0
- package/dist/stream-wire.d.ts +92 -0
- package/dist/stream-wire.js +273 -0
- package/dist/stream.d.ts +4 -0
- package/dist/stream.js +4 -0
- package/dist/tools.d.ts +534 -0
- package/dist/tools.js +451 -0
- package/dist/tunnel-host.d.ts +65 -0
- package/dist/tunnel-host.js +55 -0
- package/dist/tunnel-machine.d.ts +84 -0
- package/dist/tunnel-machine.js +127 -0
- package/dist/tunnel.d.ts +17 -0
- package/dist/tunnel.js +181 -0
- package/dist/wildcard.d.ts +11 -0
- package/dist/wildcard.js +21 -0
- package/dist/workspace.d.ts +3 -0
- package/dist/workspace.js +19 -0
- package/package.json +66 -4
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export * as StreamWire from "./stream-wire.js";
|
|
2
|
+
export declare const STREAM_PROTOCOL_VERSION: 1;
|
|
3
|
+
export declare const FRAME_HEADER_BYTES = 10;
|
|
4
|
+
/** Target payload size for outbound DATA frames: small enough for fair interleaving with HMR/control. */
|
|
5
|
+
export declare const FRAME_DATA_CHUNK_BYTES: number;
|
|
6
|
+
/** Maximum payload accepted in any single frame. */
|
|
7
|
+
export declare const MAX_FRAME_PAYLOAD_BYTES: number;
|
|
8
|
+
/** Hard WebSocket maxPayload cap including header overhead. */
|
|
9
|
+
export declare const MAX_WS_FRAME_BYTES: number;
|
|
10
|
+
/** Default server-side per-stream receive window for uploads (1.5 MiB). */
|
|
11
|
+
export declare const DEFAULT_STREAM_WINDOW_BYTES: number;
|
|
12
|
+
/**
|
|
13
|
+
* Default desktop-side per-stream receive window for downloads (512 KiB; derives a 128 KiB credit batch).
|
|
14
|
+
* Asymmetric against the 1.5 MiB server receive window to bound downstream queueing ahead of concurrent
|
|
15
|
+
* interactive streams such as WebSocket echoes and HMR updates.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_CLIENT_STREAM_WINDOW_BYTES: number;
|
|
18
|
+
/** Hard upper bound on any stream window to prevent credit overflow attacks. */
|
|
19
|
+
export declare const MAX_STREAM_WINDOW_BYTES: number;
|
|
20
|
+
/** Bound WebSocket library write buffer so control/HMR frames are never buried behind a bulk download. */
|
|
21
|
+
export declare const MAX_WS_BUFFERED_BYTES: number;
|
|
22
|
+
/** Hard cap on total buffered bytes across all streams of one attachment. */
|
|
23
|
+
export declare const MAX_ATTACHMENT_BUFFERED_BYTES: number;
|
|
24
|
+
/** Hard cap on concurrent streams per attachment. */
|
|
25
|
+
export declare const MAX_STREAMS_PER_ATTACHMENT = 128;
|
|
26
|
+
/** Hard cap on concurrent in-flight TCP connects per attachment. */
|
|
27
|
+
export declare const MAX_PENDING_CONNECTS_PER_ATTACHMENT = 32;
|
|
28
|
+
export declare const MAX_HOST_BYTES = 253;
|
|
29
|
+
export declare const MAX_REASON_BYTES = 256;
|
|
30
|
+
export declare const FrameType: {
|
|
31
|
+
readonly OPEN: 1;
|
|
32
|
+
readonly OPENED: 2;
|
|
33
|
+
readonly DATA: 3;
|
|
34
|
+
readonly WINDOW_UPDATE: 4;
|
|
35
|
+
readonly FIN: 5;
|
|
36
|
+
readonly RESET: 6;
|
|
37
|
+
readonly PING: 7;
|
|
38
|
+
readonly PONG: 8;
|
|
39
|
+
readonly GOAWAY: 9;
|
|
40
|
+
};
|
|
41
|
+
export declare const ResetCode: {
|
|
42
|
+
readonly CANCELLED: 0;
|
|
43
|
+
readonly CONNECT_FAILED: 1;
|
|
44
|
+
readonly POLICY_DENIED: 2;
|
|
45
|
+
readonly LIMIT_EXCEEDED: 3;
|
|
46
|
+
readonly PROTOCOL_ERROR: 4;
|
|
47
|
+
readonly ATTACHMENT_CLOSED: 5;
|
|
48
|
+
readonly INTERNAL_ERROR: 6;
|
|
49
|
+
};
|
|
50
|
+
export type ResetCodeValue = (typeof ResetCode)[keyof typeof ResetCode];
|
|
51
|
+
export type Frame = {
|
|
52
|
+
readonly type: typeof FrameType.OPEN;
|
|
53
|
+
readonly streamID: number;
|
|
54
|
+
readonly host: string;
|
|
55
|
+
readonly port: number;
|
|
56
|
+
readonly initialWindow: number;
|
|
57
|
+
} | {
|
|
58
|
+
readonly type: typeof FrameType.OPENED;
|
|
59
|
+
readonly streamID: number;
|
|
60
|
+
readonly initialWindow: number;
|
|
61
|
+
} | {
|
|
62
|
+
readonly type: typeof FrameType.DATA;
|
|
63
|
+
readonly streamID: number;
|
|
64
|
+
readonly data: Uint8Array;
|
|
65
|
+
} | {
|
|
66
|
+
readonly type: typeof FrameType.WINDOW_UPDATE;
|
|
67
|
+
readonly streamID: number;
|
|
68
|
+
readonly delta: number;
|
|
69
|
+
} | {
|
|
70
|
+
readonly type: typeof FrameType.FIN;
|
|
71
|
+
readonly streamID: number;
|
|
72
|
+
} | {
|
|
73
|
+
readonly type: typeof FrameType.RESET;
|
|
74
|
+
readonly streamID: number;
|
|
75
|
+
readonly code: ResetCodeValue;
|
|
76
|
+
readonly reason: string;
|
|
77
|
+
} | {
|
|
78
|
+
readonly type: typeof FrameType.PING;
|
|
79
|
+
readonly token: Uint8Array;
|
|
80
|
+
} | {
|
|
81
|
+
readonly type: typeof FrameType.PONG;
|
|
82
|
+
readonly token: Uint8Array;
|
|
83
|
+
} | {
|
|
84
|
+
readonly type: typeof FrameType.GOAWAY;
|
|
85
|
+
readonly code: ResetCodeValue;
|
|
86
|
+
readonly reason: string;
|
|
87
|
+
};
|
|
88
|
+
export declare class WireProtocolError extends Error {
|
|
89
|
+
constructor(message: string);
|
|
90
|
+
}
|
|
91
|
+
export declare function encodeFrame(frame: Frame): Uint8Array;
|
|
92
|
+
export declare function decodeFrame(raw: Uint8Array): Frame;
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
export * as StreamWire from "./stream-wire.js";
|
|
2
|
+
export const STREAM_PROTOCOL_VERSION = 1;
|
|
3
|
+
export const FRAME_HEADER_BYTES = 10;
|
|
4
|
+
/** Target payload size for outbound DATA frames: small enough for fair interleaving with HMR/control. */
|
|
5
|
+
export const FRAME_DATA_CHUNK_BYTES = 16 * 1024;
|
|
6
|
+
/** Maximum payload accepted in any single frame. */
|
|
7
|
+
export const MAX_FRAME_PAYLOAD_BYTES = 64 * 1024;
|
|
8
|
+
/** Hard WebSocket maxPayload cap including header overhead. */
|
|
9
|
+
export const MAX_WS_FRAME_BYTES = MAX_FRAME_PAYLOAD_BYTES + FRAME_HEADER_BYTES + 1024;
|
|
10
|
+
/** Default server-side per-stream receive window for uploads (1.5 MiB). */
|
|
11
|
+
export const DEFAULT_STREAM_WINDOW_BYTES = 1536 * 1024;
|
|
12
|
+
/**
|
|
13
|
+
* Default desktop-side per-stream receive window for downloads (512 KiB; derives a 128 KiB credit batch).
|
|
14
|
+
* Asymmetric against the 1.5 MiB server receive window to bound downstream queueing ahead of concurrent
|
|
15
|
+
* interactive streams such as WebSocket echoes and HMR updates.
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_CLIENT_STREAM_WINDOW_BYTES = 512 * 1024;
|
|
18
|
+
/** Hard upper bound on any stream window to prevent credit overflow attacks. */
|
|
19
|
+
export const MAX_STREAM_WINDOW_BYTES = 4 * 1024 * 1024;
|
|
20
|
+
/** Bound WebSocket library write buffer so control/HMR frames are never buried behind a bulk download. */
|
|
21
|
+
export const MAX_WS_BUFFERED_BYTES = 256 * 1024;
|
|
22
|
+
/** Hard cap on total buffered bytes across all streams of one attachment. */
|
|
23
|
+
export const MAX_ATTACHMENT_BUFFERED_BYTES = 8 * 1024 * 1024;
|
|
24
|
+
/** Hard cap on concurrent streams per attachment. */
|
|
25
|
+
export const MAX_STREAMS_PER_ATTACHMENT = 128;
|
|
26
|
+
/** Hard cap on concurrent in-flight TCP connects per attachment. */
|
|
27
|
+
export const MAX_PENDING_CONNECTS_PER_ATTACHMENT = 32;
|
|
28
|
+
export const MAX_HOST_BYTES = 253;
|
|
29
|
+
export const MAX_REASON_BYTES = 256;
|
|
30
|
+
const HOST_PATTERN = /^[a-zA-Z0-9._:%-]+$/u;
|
|
31
|
+
const encoder = new TextEncoder();
|
|
32
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
33
|
+
export const FrameType = {
|
|
34
|
+
OPEN: 0x01,
|
|
35
|
+
OPENED: 0x02,
|
|
36
|
+
DATA: 0x03,
|
|
37
|
+
WINDOW_UPDATE: 0x04,
|
|
38
|
+
FIN: 0x05,
|
|
39
|
+
RESET: 0x06,
|
|
40
|
+
PING: 0x07,
|
|
41
|
+
PONG: 0x08,
|
|
42
|
+
GOAWAY: 0x09,
|
|
43
|
+
};
|
|
44
|
+
export const ResetCode = {
|
|
45
|
+
CANCELLED: 0x0000,
|
|
46
|
+
CONNECT_FAILED: 0x0001,
|
|
47
|
+
POLICY_DENIED: 0x0002,
|
|
48
|
+
LIMIT_EXCEEDED: 0x0003,
|
|
49
|
+
PROTOCOL_ERROR: 0x0004,
|
|
50
|
+
ATTACHMENT_CLOSED: 0x0005,
|
|
51
|
+
INTERNAL_ERROR: 0x0006,
|
|
52
|
+
};
|
|
53
|
+
export class WireProtocolError extends Error {
|
|
54
|
+
constructor(message) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.name = "WireProtocolError";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function encodeFrame(frame) {
|
|
60
|
+
switch (frame.type) {
|
|
61
|
+
case FrameType.OPEN: {
|
|
62
|
+
assertStreamID(frame.streamID);
|
|
63
|
+
assertPort(frame.port);
|
|
64
|
+
assertWindow(frame.initialWindow);
|
|
65
|
+
const hostBytes = encoder.encode(frame.host);
|
|
66
|
+
if (hostBytes.byteLength < 1 || hostBytes.byteLength > MAX_HOST_BYTES || !HOST_PATTERN.test(frame.host)) {
|
|
67
|
+
throw new WireProtocolError(`Invalid OPEN host: ${frame.host}`);
|
|
68
|
+
}
|
|
69
|
+
const payloadLength = 6 + hostBytes.byteLength;
|
|
70
|
+
const out = allocHeader(FrameType.OPEN, frame.streamID, payloadLength);
|
|
71
|
+
const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
72
|
+
view.setUint16(FRAME_HEADER_BYTES, frame.port, false);
|
|
73
|
+
view.setUint32(FRAME_HEADER_BYTES + 2, frame.initialWindow, false);
|
|
74
|
+
out.set(hostBytes, FRAME_HEADER_BYTES + 6);
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
case FrameType.OPENED: {
|
|
78
|
+
assertStreamID(frame.streamID);
|
|
79
|
+
assertWindow(frame.initialWindow);
|
|
80
|
+
const out = allocHeader(FrameType.OPENED, frame.streamID, 4);
|
|
81
|
+
const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
82
|
+
view.setUint32(FRAME_HEADER_BYTES, frame.initialWindow, false);
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
case FrameType.DATA: {
|
|
86
|
+
assertStreamID(frame.streamID);
|
|
87
|
+
if (frame.data.byteLength < 1 || frame.data.byteLength > MAX_FRAME_PAYLOAD_BYTES) {
|
|
88
|
+
throw new WireProtocolError(`Invalid DATA length: ${frame.data.byteLength}`);
|
|
89
|
+
}
|
|
90
|
+
const out = allocHeader(FrameType.DATA, frame.streamID, frame.data.byteLength);
|
|
91
|
+
out.set(frame.data, FRAME_HEADER_BYTES);
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
case FrameType.WINDOW_UPDATE: {
|
|
95
|
+
assertStreamID(frame.streamID);
|
|
96
|
+
assertWindow(frame.delta);
|
|
97
|
+
const out = allocHeader(FrameType.WINDOW_UPDATE, frame.streamID, 4);
|
|
98
|
+
const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
99
|
+
view.setUint32(FRAME_HEADER_BYTES, frame.delta, false);
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
case FrameType.FIN: {
|
|
103
|
+
assertStreamID(frame.streamID);
|
|
104
|
+
return allocHeader(FrameType.FIN, frame.streamID, 0);
|
|
105
|
+
}
|
|
106
|
+
case FrameType.RESET: {
|
|
107
|
+
assertStreamID(frame.streamID);
|
|
108
|
+
const reasonBytes = encoder.encode(frame.reason.slice(0, MAX_REASON_BYTES)).subarray(0, MAX_REASON_BYTES);
|
|
109
|
+
const out = allocHeader(FrameType.RESET, frame.streamID, 2 + reasonBytes.byteLength);
|
|
110
|
+
const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
111
|
+
view.setUint16(FRAME_HEADER_BYTES, frame.code, false);
|
|
112
|
+
out.set(reasonBytes, FRAME_HEADER_BYTES + 2);
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
case FrameType.PING:
|
|
116
|
+
case FrameType.PONG: {
|
|
117
|
+
if (frame.token.byteLength !== 8)
|
|
118
|
+
throw new WireProtocolError("PING/PONG token must be 8 bytes.");
|
|
119
|
+
const out = allocHeader(frame.type, 0, 8);
|
|
120
|
+
out.set(frame.token, FRAME_HEADER_BYTES);
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
case FrameType.GOAWAY: {
|
|
124
|
+
const reasonBytes = encoder.encode(frame.reason.slice(0, MAX_REASON_BYTES)).subarray(0, MAX_REASON_BYTES);
|
|
125
|
+
const out = allocHeader(FrameType.GOAWAY, 0, 2 + reasonBytes.byteLength);
|
|
126
|
+
const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
127
|
+
view.setUint16(FRAME_HEADER_BYTES, frame.code, false);
|
|
128
|
+
out.set(reasonBytes, FRAME_HEADER_BYTES + 2);
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export function decodeFrame(raw) {
|
|
134
|
+
if (raw.byteLength < FRAME_HEADER_BYTES) {
|
|
135
|
+
throw new WireProtocolError(`Frame too short: ${raw.byteLength} bytes.`);
|
|
136
|
+
}
|
|
137
|
+
const view = new DataView(raw.buffer, raw.byteOffset, raw.byteLength);
|
|
138
|
+
const version = view.getUint8(0);
|
|
139
|
+
if (version !== STREAM_PROTOCOL_VERSION) {
|
|
140
|
+
throw new WireProtocolError(`Unsupported stream protocol version: ${version}.`);
|
|
141
|
+
}
|
|
142
|
+
const type = view.getUint8(1);
|
|
143
|
+
const streamID = view.getUint32(2, false);
|
|
144
|
+
const length = view.getUint32(6, false);
|
|
145
|
+
if (length > MAX_FRAME_PAYLOAD_BYTES) {
|
|
146
|
+
throw new WireProtocolError(`Frame payload exceeds limit: ${length} bytes.`);
|
|
147
|
+
}
|
|
148
|
+
if (raw.byteLength !== FRAME_HEADER_BYTES + length) {
|
|
149
|
+
throw new WireProtocolError(`Frame length mismatch: header declares ${length}, actual ${raw.byteLength - FRAME_HEADER_BYTES}.`);
|
|
150
|
+
}
|
|
151
|
+
const payload = raw.subarray(FRAME_HEADER_BYTES);
|
|
152
|
+
switch (type) {
|
|
153
|
+
case FrameType.OPEN: {
|
|
154
|
+
assertStreamID(streamID);
|
|
155
|
+
if (length < 7 || length > 6 + MAX_HOST_BYTES) {
|
|
156
|
+
throw new WireProtocolError(`Invalid OPEN payload length: ${length}.`);
|
|
157
|
+
}
|
|
158
|
+
const port = view.getUint16(FRAME_HEADER_BYTES, false);
|
|
159
|
+
assertPort(port);
|
|
160
|
+
const initialWindow = view.getUint32(FRAME_HEADER_BYTES + 2, false);
|
|
161
|
+
assertWindow(initialWindow);
|
|
162
|
+
const host = decodeUtf8(payload.subarray(6));
|
|
163
|
+
if (host.length < 1 || host.length > MAX_HOST_BYTES || !HOST_PATTERN.test(host)) {
|
|
164
|
+
throw new WireProtocolError("Invalid OPEN target host.");
|
|
165
|
+
}
|
|
166
|
+
return { type: FrameType.OPEN, streamID, host, port, initialWindow };
|
|
167
|
+
}
|
|
168
|
+
case FrameType.OPENED: {
|
|
169
|
+
assertStreamID(streamID);
|
|
170
|
+
if (length !== 4)
|
|
171
|
+
throw new WireProtocolError(`Invalid OPENED payload length: ${length}.`);
|
|
172
|
+
const initialWindow = view.getUint32(FRAME_HEADER_BYTES, false);
|
|
173
|
+
assertWindow(initialWindow);
|
|
174
|
+
return { type: FrameType.OPENED, streamID, initialWindow };
|
|
175
|
+
}
|
|
176
|
+
case FrameType.DATA: {
|
|
177
|
+
assertStreamID(streamID);
|
|
178
|
+
if (length < 1)
|
|
179
|
+
throw new WireProtocolError("DATA frame must carry at least 1 byte.");
|
|
180
|
+
// Copy slice so retaining the buffer does not pin a larger WebSocket slab.
|
|
181
|
+
return { type: FrameType.DATA, streamID, data: new Uint8Array(payload) };
|
|
182
|
+
}
|
|
183
|
+
case FrameType.WINDOW_UPDATE: {
|
|
184
|
+
assertStreamID(streamID);
|
|
185
|
+
if (length !== 4)
|
|
186
|
+
throw new WireProtocolError(`Invalid WINDOW_UPDATE payload length: ${length}.`);
|
|
187
|
+
const delta = view.getUint32(FRAME_HEADER_BYTES, false);
|
|
188
|
+
assertWindow(delta);
|
|
189
|
+
return { type: FrameType.WINDOW_UPDATE, streamID, delta };
|
|
190
|
+
}
|
|
191
|
+
case FrameType.FIN: {
|
|
192
|
+
assertStreamID(streamID);
|
|
193
|
+
if (length !== 0)
|
|
194
|
+
throw new WireProtocolError(`Invalid FIN payload length: ${length}.`);
|
|
195
|
+
return { type: FrameType.FIN, streamID };
|
|
196
|
+
}
|
|
197
|
+
case FrameType.RESET: {
|
|
198
|
+
assertStreamID(streamID);
|
|
199
|
+
if (length < 2 || length > 2 + MAX_REASON_BYTES) {
|
|
200
|
+
throw new WireProtocolError(`Invalid RESET payload length: ${length}.`);
|
|
201
|
+
}
|
|
202
|
+
const code = normalizeResetCode(view.getUint16(FRAME_HEADER_BYTES, false));
|
|
203
|
+
const reason = length > 2 ? decodeUtf8(payload.subarray(2)) : "";
|
|
204
|
+
return { type: FrameType.RESET, streamID, code, reason };
|
|
205
|
+
}
|
|
206
|
+
case FrameType.PING:
|
|
207
|
+
case FrameType.PONG: {
|
|
208
|
+
if (streamID !== 0)
|
|
209
|
+
throw new WireProtocolError("PING/PONG must use streamID 0.");
|
|
210
|
+
if (length !== 8)
|
|
211
|
+
throw new WireProtocolError(`Invalid PING/PONG payload length: ${length}.`);
|
|
212
|
+
return { type, token: new Uint8Array(payload) };
|
|
213
|
+
}
|
|
214
|
+
case FrameType.GOAWAY: {
|
|
215
|
+
if (streamID !== 0)
|
|
216
|
+
throw new WireProtocolError("GOAWAY must use streamID 0.");
|
|
217
|
+
if (length < 2 || length > 2 + MAX_REASON_BYTES) {
|
|
218
|
+
throw new WireProtocolError(`Invalid GOAWAY payload length: ${length}.`);
|
|
219
|
+
}
|
|
220
|
+
const code = normalizeResetCode(view.getUint16(FRAME_HEADER_BYTES, false));
|
|
221
|
+
const reason = length > 2 ? decodeUtf8(payload.subarray(2)) : "";
|
|
222
|
+
return { type: FrameType.GOAWAY, code, reason };
|
|
223
|
+
}
|
|
224
|
+
default:
|
|
225
|
+
throw new WireProtocolError(`Unknown stream frame type: ${type}.`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function allocHeader(type, streamID, payloadLength) {
|
|
229
|
+
const out = new Uint8Array(FRAME_HEADER_BYTES + payloadLength);
|
|
230
|
+
const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
231
|
+
view.setUint8(0, STREAM_PROTOCOL_VERSION);
|
|
232
|
+
view.setUint8(1, type);
|
|
233
|
+
view.setUint32(2, streamID, false);
|
|
234
|
+
view.setUint32(6, payloadLength, false);
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
function assertStreamID(streamID) {
|
|
238
|
+
if (!Number.isInteger(streamID) || streamID < 1 || streamID > 0xffffffff) {
|
|
239
|
+
throw new WireProtocolError(`Invalid streamID: ${streamID}.`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function assertPort(port) {
|
|
243
|
+
if (!Number.isInteger(port) || port < 1 || port > 65_535) {
|
|
244
|
+
throw new WireProtocolError(`Invalid port: ${port}.`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function assertWindow(bytes) {
|
|
248
|
+
if (!Number.isInteger(bytes) || bytes < 1 || bytes > MAX_STREAM_WINDOW_BYTES) {
|
|
249
|
+
throw new WireProtocolError(`Invalid window/credit size: ${bytes}.`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function normalizeResetCode(code) {
|
|
253
|
+
switch (code) {
|
|
254
|
+
case ResetCode.CANCELLED:
|
|
255
|
+
case ResetCode.CONNECT_FAILED:
|
|
256
|
+
case ResetCode.POLICY_DENIED:
|
|
257
|
+
case ResetCode.LIMIT_EXCEEDED:
|
|
258
|
+
case ResetCode.PROTOCOL_ERROR:
|
|
259
|
+
case ResetCode.ATTACHMENT_CLOSED:
|
|
260
|
+
case ResetCode.INTERNAL_ERROR:
|
|
261
|
+
return code;
|
|
262
|
+
default:
|
|
263
|
+
return ResetCode.INTERNAL_ERROR;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function decodeUtf8(bytes) {
|
|
267
|
+
try {
|
|
268
|
+
return decoder.decode(bytes);
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
throw new WireProtocolError("Frame contains invalid UTF-8.");
|
|
272
|
+
}
|
|
273
|
+
}
|
package/dist/stream.d.ts
ADDED
package/dist/stream.js
ADDED