@volter/tabnode 0.5.49 → 0.5.51

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.
@@ -100,6 +100,11 @@ const _PortBridge = class _PortBridge extends BridgeEvents {
100
100
  /** The server the service worker answers at the origin's root, the preview's; null for none. */
101
101
  __publicField(this, "primaryPort", null);
102
102
  __publicField(this, "ownDocuments");
103
+ /**
104
+ * Handle messages from Service Worker
105
+ */
106
+ /** The channels whose worker takes a response chunk as transferred bytes (`sw-capabilities`). */
107
+ __publicField(this, "binaryChunkPorts", /* @__PURE__ */ new WeakSet());
103
108
  /** Flow-controlled requests in flight: a pull is one chunk's credit, a cancel ends the upstream. */
104
109
  __publicField(this, "controlledStreams", /* @__PURE__ */ new Map());
105
110
  this.options = options;
@@ -275,12 +280,20 @@ const _PortBridge = class _PortBridge extends BridgeEvents {
275
280
  this.announceServers();
276
281
  this.emit("sw-ready");
277
282
  }
278
- /**
279
- * Handle messages from Service Worker
280
- */
283
+ /** One response chunk on `port`: its bytes transferred where the worker said it takes them,
284
+ * base64 to a worker that predates that. `bytes` must be the chunk's own buffer. */
285
+ postChunk(port, id, bytes) {
286
+ if (!port) return;
287
+ if (this.binaryChunkPorts.has(port)) port.postMessage({ type: "stream-chunk", id, data: { chunk: bytes } }, [bytes.buffer]);
288
+ else port.postMessage({ type: "stream-chunk", id, data: { chunkBase64: uint8ToBase64(bytes) } });
289
+ }
281
290
  async handleServiceWorkerMessage(event) {
282
291
  var _a, _b, _c;
283
292
  const { type, id, data } = event.data;
293
+ if (type === "sw-capabilities") {
294
+ if ((data == null ? void 0 : data.binaryChunks) === 1 && event.target instanceof MessagePort) this.binaryChunkPorts.add(event.target);
295
+ return;
296
+ }
284
297
  _PortBridge.DEBUG && console.log("[ServerBridge] SW message:", type, id, data == null ? void 0 : data.url);
285
298
  if (type === "stream-pull" || type === "stream-cancel") {
286
299
  const stream = this.controlledStreams.get(id);
@@ -445,14 +458,9 @@ const _PortBridge = class _PortBridge extends BridgeEvents {
445
458
  // onChunk - called for each chunk
446
459
  (chunk) => {
447
460
  var _a2;
448
- const bytes = typeof chunk === "string" ? _encoder.encode(chunk) : chunk;
449
- const chunkBase64 = uint8ToBase64(bytes);
450
- _PortBridge.DEBUG && console.log("[ServerBridge] 🟡 onChunk called, sending stream-chunk, size:", chunkBase64.length);
451
- (_a2 = this.messageChannel) == null ? void 0 : _a2.port1.postMessage({
452
- type: "stream-chunk",
453
- id,
454
- data: { chunkBase64 }
455
- });
461
+ const bytes = typeof chunk === "string" ? _encoder.encode(chunk) : ownedBytes(chunk);
462
+ _PortBridge.DEBUG && console.log("[ServerBridge] 🟡 onChunk called, sending stream-chunk, size:", bytes.byteLength);
463
+ this.postChunk((_a2 = this.messageChannel) == null ? void 0 : _a2.port1, id, bytes);
456
464
  },
457
465
  // onEnd - called when response is complete
458
466
  () => {
@@ -474,12 +482,8 @@ const _PortBridge = class _PortBridge extends BridgeEvents {
474
482
  }
475
483
  });
476
484
  if (response.body && response.body.length > 0) {
477
- const bytes = response.body instanceof Uint8Array ? response.body : new Uint8Array(0);
478
- (_d = this.messageChannel) == null ? void 0 : _d.port1.postMessage({
479
- type: "stream-chunk",
480
- id,
481
- data: { chunkBase64: uint8ToBase64(bytes) }
482
- });
485
+ const bytes = response.body instanceof Uint8Array ? ownedBytes(response.body) : new Uint8Array(0);
486
+ this.postChunk((_d = this.messageChannel) == null ? void 0 : _d.port1, id, bytes);
483
487
  }
484
488
  (_e = this.messageChannel) == null ? void 0 : _e.port1.postMessage({ type: "stream-end", id });
485
489
  }
@@ -521,7 +525,7 @@ const _PortBridge = class _PortBridge extends BridgeEvents {
521
525
  if (finished) return;
522
526
  while (credits > 0 && queue.length > 0) {
523
527
  credits -= 1;
524
- post("stream-chunk", { chunkBase64: uint8ToBase64(queue.shift()) });
528
+ this.postChunk(channel == null ? void 0 : channel.port1, id, queue.shift());
525
529
  }
526
530
  if (upstreamEnded && queue.length === 0) {
527
531
  post("stream-end");
@@ -122,6 +122,11 @@ export declare class PortBridge extends BridgeEvents {
122
122
  /**
123
123
  * Handle messages from Service Worker
124
124
  */
125
+ /** The channels whose worker takes a response chunk as transferred bytes (`sw-capabilities`). */
126
+ private readonly binaryChunkPorts;
127
+ /** One response chunk on `port`: its bytes transferred where the worker said it takes them,
128
+ * base64 to a worker that predates that. `bytes` must be the chunk's own buffer. */
129
+ private postChunk;
125
130
  private handleServiceWorkerMessage;
126
131
  /**
127
132
  * Handle a streaming request - sends chunks as they arrive
@@ -1,4 +1,4 @@
1
- import { P, g, o } from "./port-bridge-CixAESwA.js";
1
+ import { P, g, o } from "./port-bridge-Cergvxli.js";
2
2
  export {
3
3
  P as PortBridge,
4
4
  g as getPortBridge,
@@ -0,0 +1,203 @@
1
+ import { GHASH } from '@noble/ciphers/_polyval.js';
2
+ type Mode = 'gcm' | 'cbc' | 'ctr' | 'ecb';
3
+ type Bytes = Uint8Array;
4
+ export interface CipherDeps {
5
+ /** The guest's Buffer.from over bytes. */
6
+ toBuffer(bytes: Bytes): Uint8Array;
7
+ /** Bytes of a string (in its encoding) or a view, as the rest of crypto reads them. */
8
+ bytesOf(value: unknown, encoding?: string): Bytes;
9
+ /** A secret KeyObject's bytes, or undefined when the value is not a KeyObject. */
10
+ secretKeyBytes(value: unknown): Bytes | undefined;
11
+ /** Bytes in an output encoding, as `digest` answers them. */
12
+ encode(bytes: Bytes, encoding?: string): unknown;
13
+ error(code: string, message: string): Error;
14
+ }
15
+ /** The ciphers `createCipheriv` accepts, as `getCiphers` lists them. */
16
+ export declare function cipherNames(): string[];
17
+ export declare function createCipherClasses(deps: CipherDeps): {
18
+ Cipheriv: {
19
+ new (algorithm: unknown, key: unknown, iv: unknown, options?: {
20
+ authTagLength?: number;
21
+ }): {
22
+ getAuthTag(): Uint8Array;
23
+ readonly "__#private@#decrypt": boolean;
24
+ readonly "__#private@#mode": Mode;
25
+ readonly "__#private@#xk": Uint32Array;
26
+ readonly "__#private@#xkDec": Uint32Array | undefined;
27
+ "__#private@#padding": boolean;
28
+ "__#private@#finished": boolean;
29
+ "__#private@#started": boolean;
30
+ /** CBC/ECB: bytes not yet a whole block (and, decrypting with padding, the last whole block). */
31
+ "__#private@#pending": Bytes;
32
+ /** CBC's chaining block. */
33
+ "__#private@#chain": Bytes | undefined;
34
+ /** CTR/GCM: the next counter block and what is left of the current keystream block. */
35
+ "__#private@#counter": Bytes | undefined;
36
+ "__#private@#keystream": Bytes;
37
+ /** GCM. */
38
+ "__#private@#ghash": GHASH | undefined;
39
+ "__#private@#tagMask": Bytes | undefined;
40
+ "__#private@#ghashPending": Bytes;
41
+ "__#private@#aadLength": number;
42
+ "__#private@#dataLength": number;
43
+ "__#private@#authTagLength": number | undefined;
44
+ "__#private@#authTag": Bytes | undefined;
45
+ setAutoPadding(autoPadding?: boolean): /*elided*/ any;
46
+ setAAD(buffer: unknown, _options?: {
47
+ plaintextLength?: number;
48
+ }): /*elided*/ any;
49
+ "__#private@#getTag"(): Bytes;
50
+ "__#private@#setTag"(tag: unknown, encoding?: string): void;
51
+ update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
52
+ final(outputEncoding?: string): unknown;
53
+ "__#private@#process"(input: Bytes): Bytes;
54
+ /** XOR with the counter's keystream, carrying a partial block across calls. */
55
+ "__#private@#stream"(input: Bytes): Bytes;
56
+ /** GHASH over the ciphertext, in whole blocks: GHASH pads each update, so a partial block waits for the next. */
57
+ "__#private@#absorb"(ciphertext: Bytes): void;
58
+ /** CBC and ECB: every whole block now; decrypting with padding, the last whole block waits for `final`. */
59
+ "__#private@#blocks"(input: Bytes): Bytes;
60
+ "__#private@#block"(block: Bytes): Bytes;
61
+ "__#private@#finish"(): Bytes;
62
+ "__#private@#finishGcm"(): Bytes;
63
+ };
64
+ };
65
+ Decipheriv: {
66
+ new (algorithm: unknown, key: unknown, iv: unknown, options?: {
67
+ authTagLength?: number;
68
+ }): {
69
+ setAuthTag(tag: unknown, encoding?: string): /*elided*/ any;
70
+ readonly "__#private@#decrypt": boolean;
71
+ readonly "__#private@#mode": Mode;
72
+ readonly "__#private@#xk": Uint32Array;
73
+ readonly "__#private@#xkDec": Uint32Array | undefined;
74
+ "__#private@#padding": boolean;
75
+ "__#private@#finished": boolean;
76
+ "__#private@#started": boolean;
77
+ /** CBC/ECB: bytes not yet a whole block (and, decrypting with padding, the last whole block). */
78
+ "__#private@#pending": Bytes;
79
+ /** CBC's chaining block. */
80
+ "__#private@#chain": Bytes | undefined;
81
+ /** CTR/GCM: the next counter block and what is left of the current keystream block. */
82
+ "__#private@#counter": Bytes | undefined;
83
+ "__#private@#keystream": Bytes;
84
+ /** GCM. */
85
+ "__#private@#ghash": GHASH | undefined;
86
+ "__#private@#tagMask": Bytes | undefined;
87
+ "__#private@#ghashPending": Bytes;
88
+ "__#private@#aadLength": number;
89
+ "__#private@#dataLength": number;
90
+ "__#private@#authTagLength": number | undefined;
91
+ "__#private@#authTag": Bytes | undefined;
92
+ setAutoPadding(autoPadding?: boolean): /*elided*/ any;
93
+ setAAD(buffer: unknown, _options?: {
94
+ plaintextLength?: number;
95
+ }): /*elided*/ any;
96
+ "__#private@#getTag"(): Bytes;
97
+ "__#private@#setTag"(tag: unknown, encoding?: string): void;
98
+ update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
99
+ final(outputEncoding?: string): unknown;
100
+ "__#private@#process"(input: Bytes): Bytes;
101
+ /** XOR with the counter's keystream, carrying a partial block across calls. */
102
+ "__#private@#stream"(input: Bytes): Bytes;
103
+ /** GHASH over the ciphertext, in whole blocks: GHASH pads each update, so a partial block waits for the next. */
104
+ "__#private@#absorb"(ciphertext: Bytes): void;
105
+ /** CBC and ECB: every whole block now; decrypting with padding, the last whole block waits for `final`. */
106
+ "__#private@#blocks"(input: Bytes): Bytes;
107
+ "__#private@#block"(block: Bytes): Bytes;
108
+ "__#private@#finish"(): Bytes;
109
+ "__#private@#finishGcm"(): Bytes;
110
+ };
111
+ };
112
+ createCipheriv: (algorithm: unknown, key: unknown, iv: unknown, options?: {
113
+ authTagLength?: number;
114
+ }) => {
115
+ getAuthTag(): Uint8Array;
116
+ readonly "__#private@#decrypt": boolean;
117
+ readonly "__#private@#mode": Mode;
118
+ readonly "__#private@#xk": Uint32Array;
119
+ readonly "__#private@#xkDec": Uint32Array | undefined;
120
+ "__#private@#padding": boolean;
121
+ "__#private@#finished": boolean;
122
+ "__#private@#started": boolean;
123
+ /** CBC/ECB: bytes not yet a whole block (and, decrypting with padding, the last whole block). */
124
+ "__#private@#pending": Bytes;
125
+ /** CBC's chaining block. */
126
+ "__#private@#chain": Bytes | undefined;
127
+ /** CTR/GCM: the next counter block and what is left of the current keystream block. */
128
+ "__#private@#counter": Bytes | undefined;
129
+ "__#private@#keystream": Bytes;
130
+ /** GCM. */
131
+ "__#private@#ghash": GHASH | undefined;
132
+ "__#private@#tagMask": Bytes | undefined;
133
+ "__#private@#ghashPending": Bytes;
134
+ "__#private@#aadLength": number;
135
+ "__#private@#dataLength": number;
136
+ "__#private@#authTagLength": number | undefined;
137
+ "__#private@#authTag": Bytes | undefined;
138
+ setAutoPadding(autoPadding?: boolean): /*elided*/ any;
139
+ setAAD(buffer: unknown, _options?: {
140
+ plaintextLength?: number;
141
+ }): /*elided*/ any;
142
+ "__#private@#getTag"(): Bytes;
143
+ "__#private@#setTag"(tag: unknown, encoding?: string): void;
144
+ update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
145
+ final(outputEncoding?: string): unknown;
146
+ "__#private@#process"(input: Bytes): Bytes;
147
+ /** XOR with the counter's keystream, carrying a partial block across calls. */
148
+ "__#private@#stream"(input: Bytes): Bytes;
149
+ /** GHASH over the ciphertext, in whole blocks: GHASH pads each update, so a partial block waits for the next. */
150
+ "__#private@#absorb"(ciphertext: Bytes): void;
151
+ /** CBC and ECB: every whole block now; decrypting with padding, the last whole block waits for `final`. */
152
+ "__#private@#blocks"(input: Bytes): Bytes;
153
+ "__#private@#block"(block: Bytes): Bytes;
154
+ "__#private@#finish"(): Bytes;
155
+ "__#private@#finishGcm"(): Bytes;
156
+ };
157
+ createDecipheriv: (algorithm: unknown, key: unknown, iv: unknown, options?: {
158
+ authTagLength?: number;
159
+ }) => {
160
+ setAuthTag(tag: unknown, encoding?: string): /*elided*/ any;
161
+ readonly "__#private@#decrypt": boolean;
162
+ readonly "__#private@#mode": Mode;
163
+ readonly "__#private@#xk": Uint32Array;
164
+ readonly "__#private@#xkDec": Uint32Array | undefined;
165
+ "__#private@#padding": boolean;
166
+ "__#private@#finished": boolean;
167
+ "__#private@#started": boolean;
168
+ /** CBC/ECB: bytes not yet a whole block (and, decrypting with padding, the last whole block). */
169
+ "__#private@#pending": Bytes;
170
+ /** CBC's chaining block. */
171
+ "__#private@#chain": Bytes | undefined;
172
+ /** CTR/GCM: the next counter block and what is left of the current keystream block. */
173
+ "__#private@#counter": Bytes | undefined;
174
+ "__#private@#keystream": Bytes;
175
+ /** GCM. */
176
+ "__#private@#ghash": GHASH | undefined;
177
+ "__#private@#tagMask": Bytes | undefined;
178
+ "__#private@#ghashPending": Bytes;
179
+ "__#private@#aadLength": number;
180
+ "__#private@#dataLength": number;
181
+ "__#private@#authTagLength": number | undefined;
182
+ "__#private@#authTag": Bytes | undefined;
183
+ setAutoPadding(autoPadding?: boolean): /*elided*/ any;
184
+ setAAD(buffer: unknown, _options?: {
185
+ plaintextLength?: number;
186
+ }): /*elided*/ any;
187
+ "__#private@#getTag"(): Bytes;
188
+ "__#private@#setTag"(tag: unknown, encoding?: string): void;
189
+ update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
190
+ final(outputEncoding?: string): unknown;
191
+ "__#private@#process"(input: Bytes): Bytes;
192
+ /** XOR with the counter's keystream, carrying a partial block across calls. */
193
+ "__#private@#stream"(input: Bytes): Bytes;
194
+ /** GHASH over the ciphertext, in whole blocks: GHASH pads each update, so a partial block waits for the next. */
195
+ "__#private@#absorb"(ciphertext: Bytes): void;
196
+ /** CBC and ECB: every whole block now; decrypting with padding, the last whole block waits for `final`. */
197
+ "__#private@#blocks"(input: Bytes): Bytes;
198
+ "__#private@#block"(block: Bytes): Bytes;
199
+ "__#private@#finish"(): Bytes;
200
+ "__#private@#finishGcm"(): Bytes;
201
+ };
202
+ };
203
+ export {};