capnweb 0.0.0-409821 → 0.0.0-43aa384
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 +10 -2
- package/dist/index-bun.cjs +374 -78
- package/dist/index-bun.cjs.map +1 -1
- package/dist/index-bun.d.cts +105 -8
- package/dist/index-bun.d.ts +105 -8
- package/dist/index-bun.js +372 -79
- package/dist/index-bun.js.map +1 -1
- package/dist/index-workers.cjs +374 -78
- package/dist/index-workers.cjs.map +1 -1
- package/dist/index-workers.d.cts +102 -8
- package/dist/index-workers.d.ts +102 -8
- package/dist/index-workers.js +372 -79
- package/dist/index-workers.js.map +1 -1
- package/dist/index.cjs +374 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -8
- package/dist/index.d.ts +102 -8
- package/dist/index.js +372 -79
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index-bun.d.cts
CHANGED
|
@@ -40,7 +40,8 @@ interface StubBase<T = unknown> extends Disposable {
|
|
|
40
40
|
}
|
|
41
41
|
type Stub<T extends RpcCompatible<T>> = T extends object ? Provider<T> & StubBase<T> : StubBase<T>;
|
|
42
42
|
type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array; // This represents all the types that can be sent as-is over an RPC boundary
|
|
43
|
-
type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | Blob | ReadableStream<
|
|
43
|
+
type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | Blob | ReadableStream<any> // Chunk type can be any RPC-compatible type
|
|
44
|
+
| WritableStream<any> // Chunk type can be any RPC-compatible type
|
|
44
45
|
| Request | Response | Headers; // Recursively rewrite all `Stubable` types with `Stub`s, and resolve promises.
|
|
45
46
|
// prettier-ignore
|
|
46
47
|
type Stubify<T> = T extends Stubable ? Stub<T> : T extends Promise<infer U> ? Stubify<U> : T extends StubBase<any> ? T : T extends Map<infer K, infer V> ? Map<Stubify<K>, Stubify<V>> : T extends Set<infer V> ? Set<Stubify<V>> : T extends [] ? [] : T extends [infer Head, ...infer Tail] ? [Stubify<Head>, ...Stubify<Tail>] : T extends readonly [] ? readonly [] : T extends readonly [infer Head, ...infer Tail] ? readonly [Stubify<Head>, ...Stubify<Tail>] : T extends Array<infer V> ? Array<Stubify<V>> : T extends ReadonlyArray<infer V> ? ReadonlyArray<Stubify<V>> : T extends BaseType ? T // When using "unknown" instead of "any", interfaces are not stubified.
|
|
@@ -171,6 +172,9 @@ declare class RpcPayload {
|
|
|
171
172
|
private deliverTo;
|
|
172
173
|
private static deliverRpcPromiseTo;
|
|
173
174
|
deliverCall(func: Function, thisArg: object | undefined): Promise<RpcPayload>;
|
|
175
|
+
deliverStreamWrite(writer: {
|
|
176
|
+
write(chunk: unknown): Promise<void>;
|
|
177
|
+
}): Promise<RpcPayload>;
|
|
174
178
|
deliverResolve(): Promise<unknown>;
|
|
175
179
|
dispose(): void;
|
|
176
180
|
private disposeImpl;
|
|
@@ -179,6 +183,32 @@ declare class RpcPayload {
|
|
|
179
183
|
}
|
|
180
184
|
//#endregion
|
|
181
185
|
//#region src/serialize.d.ts
|
|
186
|
+
/**
|
|
187
|
+
* Encoding levels determine what representation the RPC system hands to the transport.
|
|
188
|
+
* Each level names what the transport can assume about message values.
|
|
189
|
+
*
|
|
190
|
+
* - `"string"`: JSON string. Default, used by HTTP batch and WebSocket transports.
|
|
191
|
+
* - `"jsonCompatible"`: JSON-compatible JS value tree. For custom encoders.
|
|
192
|
+
* - `"jsonCompatibleWithBytes"`: Like `"jsonCompatible"` but Uint8Array stays raw.
|
|
193
|
+
* - `"structuredClonable"`: Structured-clonable native values pass through where possible.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* // What happens to Uint8Array([1, 2, 3]) at each level:
|
|
198
|
+
* "string" → '["bytes","AQID"]' // JSON string with base64
|
|
199
|
+
* "jsonCompatible" → ["bytes", "AQID"] // JS array with base64
|
|
200
|
+
* "jsonCompatibleWithBytes" → ["bytes", Uint8Array] // JS array with raw bytes
|
|
201
|
+
* "structuredClonable" → ["bytes", Uint8Array] // + Date, BigInt stay native
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
type EncodingLevel = "string" | "jsonCompatible" | "jsonCompatibleWithBytes" | "structuredClonable";
|
|
205
|
+
interface RpcLimits {
|
|
206
|
+
maxBigIntDigits: number;
|
|
207
|
+
maxDepth: number;
|
|
208
|
+
maxMessageSize: number;
|
|
209
|
+
}
|
|
210
|
+
declare const DEFAULT_MAX_DEPTH = 256;
|
|
211
|
+
declare const DEFAULT_LIMITS: RpcLimits;
|
|
182
212
|
/**
|
|
183
213
|
* Serialize a value, using Cap'n Web's underlying serialization. This won't be able to serialize
|
|
184
214
|
* RPC stubs, but it will support basic data types.
|
|
@@ -191,14 +221,21 @@ declare function deserialize(value: string): unknown;
|
|
|
191
221
|
//#endregion
|
|
192
222
|
//#region src/rpc.d.ts
|
|
193
223
|
/**
|
|
194
|
-
* Interface for
|
|
195
|
-
*
|
|
224
|
+
* Interface for a string-based RPC transport. This is the default transport type — no
|
|
225
|
+
* `encodingLevel` field is needed. Messages are JSON strings. Implement this interface if the
|
|
226
|
+
* built-in transports (e.g. for HTTP batch and WebSocket) don't meet your needs.
|
|
196
227
|
*/
|
|
197
228
|
interface RpcTransport {
|
|
198
229
|
/**
|
|
199
|
-
*
|
|
230
|
+
* The encoding level this transport works with. For this interface it is always "string";
|
|
231
|
+
* it may be omitted. (See `RpcTransportWithCustomEncoding` for the other levels.)
|
|
200
232
|
*/
|
|
201
|
-
|
|
233
|
+
readonly encodingLevel?: "string";
|
|
234
|
+
/**
|
|
235
|
+
* Sends a message to the other end. May optionally return a promise; if the promise rejects,
|
|
236
|
+
* the session is aborted.
|
|
237
|
+
*/
|
|
238
|
+
send(message: string): void | Promise<void>;
|
|
202
239
|
/**
|
|
203
240
|
* Receives a message sent by the other end.
|
|
204
241
|
*
|
|
@@ -217,6 +254,45 @@ interface RpcTransport {
|
|
|
217
254
|
*/
|
|
218
255
|
abort?(reason: any): void;
|
|
219
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Interface for a transport that receives partially encoded JS values instead of JSON strings.
|
|
259
|
+
* The selected `encodingLevel` describes what the transport can assume about message values.
|
|
260
|
+
*/
|
|
261
|
+
interface RpcTransportWithCustomEncoding {
|
|
262
|
+
/**
|
|
263
|
+
* The encoding level this transport works with.
|
|
264
|
+
*
|
|
265
|
+
* - "jsonCompatible": JSON-compatible JS value tree; transport handles final serialization.
|
|
266
|
+
* - "jsonCompatibleWithBytes": Like "jsonCompatible" but Uint8Array values are left raw.
|
|
267
|
+
* - "structuredClonable": Structured-clonable native values pass through where possible.
|
|
268
|
+
*/
|
|
269
|
+
readonly encodingLevel: "jsonCompatible" | "jsonCompatibleWithBytes" | "structuredClonable";
|
|
270
|
+
/**
|
|
271
|
+
* Encodes and sends a message to the other end. Returns the encoded byte size if known.
|
|
272
|
+
* If the size is unavailable, return void; Cap'n Web will estimate stream message sizes for
|
|
273
|
+
* flow control. Send errors should be propagated via `receive()` rejecting.
|
|
274
|
+
*/
|
|
275
|
+
send(message: unknown): number | void;
|
|
276
|
+
/**
|
|
277
|
+
* Receives and decodes a message sent by the other end.
|
|
278
|
+
*
|
|
279
|
+
* If and when the transport becomes disconnected, this will reject. The thrown error will be
|
|
280
|
+
* propagated to all outstanding calls and future calls on any stubs associated with the session.
|
|
281
|
+
* If there are no outstanding calls (and none are made in the future), then the error does not
|
|
282
|
+
* propagate anywhere -- this is considered a "clean" shutdown.
|
|
283
|
+
*/
|
|
284
|
+
receive(): Promise<unknown>;
|
|
285
|
+
/**
|
|
286
|
+
* Indicates that the RPC system has suffered an error that prevents the session from continuing.
|
|
287
|
+
* The transport should ideally try to send any queued messages if it can, and then close the
|
|
288
|
+
* connection. (It's not strictly necessary to deliver queued messages, but the last message sent
|
|
289
|
+
* before abort() is called is often an "abort" message, which communicates the error to the
|
|
290
|
+
* peer, so if that is dropped, the peer may have less information about what happened.)
|
|
291
|
+
*/
|
|
292
|
+
abort?(reason: any): void;
|
|
293
|
+
}
|
|
294
|
+
/** Any supported transport type. */
|
|
295
|
+
type AnyRpcTransport = RpcTransport | RpcTransportWithCustomEncoding;
|
|
220
296
|
/**
|
|
221
297
|
* Options to customize behavior of an RPC session. All functions which start a session should
|
|
222
298
|
* optionally accept this.
|
|
@@ -234,6 +310,16 @@ type RpcSessionOptions = {
|
|
|
234
310
|
* to serialize the error with the stack omitted.
|
|
235
311
|
*/
|
|
236
312
|
onSendError?: (error: Error) => Error | void;
|
|
313
|
+
/**
|
|
314
|
+
* Overrides for the resource limits enforced while deserializing messages from the peer. Any
|
|
315
|
+
* field left unset falls back to `DEFAULT_LIMITS`. These guard against resource-exhaustion
|
|
316
|
+
* attacks from untrusted peers; see `RpcLimits` for the meaning and defaults of each field.
|
|
317
|
+
*
|
|
318
|
+
* Limits are a purely local, receiver-side decision -- the protocol has no negotiation step, so
|
|
319
|
+
* the peer never learns these values. A message that exceeds a limit is rejected, aborting the
|
|
320
|
+
* session.
|
|
321
|
+
*/
|
|
322
|
+
limits?: Partial<RpcLimits>;
|
|
237
323
|
};
|
|
238
324
|
//#endregion
|
|
239
325
|
//#region src/websocket.d.ts
|
|
@@ -242,6 +328,17 @@ type RpcSessionOptions = {
|
|
|
242
328
|
* with the given `localMain`.
|
|
243
329
|
*/
|
|
244
330
|
declare function newWorkersWebSocketRpcResponse(request: Request, localMain?: any, options?: RpcSessionOptions): Response;
|
|
331
|
+
/**
|
|
332
|
+
* Generic WebSocket transport. Default `T = string` is backward-compatible and satisfies
|
|
333
|
+
* `RpcTransport`. Use `T = ArrayBuffer` as a building block for binary transports.
|
|
334
|
+
*/
|
|
335
|
+
declare class WebSocketTransport<T extends string | ArrayBuffer = string> {
|
|
336
|
+
#private;
|
|
337
|
+
constructor(webSocket: WebSocket);
|
|
338
|
+
send(message: T): void;
|
|
339
|
+
receive(): Promise<T>;
|
|
340
|
+
abort(reason: any): void;
|
|
341
|
+
}
|
|
245
342
|
//#endregion
|
|
246
343
|
//#region src/batch.d.ts
|
|
247
344
|
/**
|
|
@@ -316,7 +413,7 @@ interface RpcSession<T extends RpcCompatible<T> = undefined> {
|
|
|
316
413
|
drain(): Promise<void>;
|
|
317
414
|
}
|
|
318
415
|
declare const RpcSession: {
|
|
319
|
-
new <T extends RpcCompatible<T> = undefined>(transport:
|
|
416
|
+
new <T extends RpcCompatible<T> = undefined>(transport: AnyRpcTransport, localMain?: any, options?: RpcSessionOptions): RpcSession<T>;
|
|
320
417
|
};
|
|
321
418
|
/**
|
|
322
419
|
* Classes which are intended to be passed by reference and called over RPC must extend
|
|
@@ -369,7 +466,7 @@ declare let newMessagePortRpcSession: <T extends RpcCompatible<T> = Empty$1>(por
|
|
|
369
466
|
* credentials as parameters and returns the authorized API), then cross-origin requests should
|
|
370
467
|
* be safe.
|
|
371
468
|
*/
|
|
372
|
-
declare function newWorkersRpcResponse(request: Request, localMain: any): Promise<Response>;
|
|
469
|
+
declare function newWorkersRpcResponse(request: Request, localMain: any, options?: RpcSessionOptions): Promise<Response>;
|
|
373
470
|
//#endregion
|
|
374
471
|
//#region src/bun.d.ts
|
|
375
472
|
type WsData = {
|
|
@@ -420,5 +517,5 @@ declare let newBunWebSocketRpcSession: <T extends RpcCompatible<T> = Empty, D =
|
|
|
420
517
|
transport: BunWebSocketTransport<D>;
|
|
421
518
|
};
|
|
422
519
|
//#endregion
|
|
423
|
-
export { BunWebSocketTransport, type RpcCompatible, RpcPromise, RpcSession, type RpcSessionOptions, RpcStub, RpcTarget, type RpcTransport, deserialize, newBunWebSocketRpcHandler, newBunWebSocketRpcSession, newHttpBatchRpcResponse, newHttpBatchRpcSession, newMessagePortRpcSession, newWebSocketRpcSession, newWorkersRpcResponse, newWorkersWebSocketRpcResponse, nodeHttpBatchRpcResponse, serialize };
|
|
520
|
+
export { type AnyRpcTransport, BunWebSocketTransport, DEFAULT_LIMITS, DEFAULT_MAX_DEPTH, type EncodingLevel, type RpcCompatible, type RpcLimits, RpcPromise, RpcSession, type RpcSessionOptions, RpcStub, RpcTarget, type RpcTransport, type RpcTransportWithCustomEncoding, WebSocketTransport, deserialize, newBunWebSocketRpcHandler, newBunWebSocketRpcSession, newHttpBatchRpcResponse, newHttpBatchRpcSession, newMessagePortRpcSession, newWebSocketRpcSession, newWorkersRpcResponse, newWorkersWebSocketRpcResponse, nodeHttpBatchRpcResponse, serialize };
|
|
424
521
|
//# sourceMappingURL=index-bun.d.cts.map
|
package/dist/index-bun.d.ts
CHANGED
|
@@ -40,7 +40,8 @@ interface StubBase<T = unknown> extends Disposable {
|
|
|
40
40
|
}
|
|
41
41
|
type Stub<T extends RpcCompatible<T>> = T extends object ? Provider<T> & StubBase<T> : StubBase<T>;
|
|
42
42
|
type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array; // This represents all the types that can be sent as-is over an RPC boundary
|
|
43
|
-
type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | Blob | ReadableStream<
|
|
43
|
+
type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | Blob | ReadableStream<any> // Chunk type can be any RPC-compatible type
|
|
44
|
+
| WritableStream<any> // Chunk type can be any RPC-compatible type
|
|
44
45
|
| Request | Response | Headers; // Recursively rewrite all `Stubable` types with `Stub`s, and resolve promises.
|
|
45
46
|
// prettier-ignore
|
|
46
47
|
type Stubify<T> = T extends Stubable ? Stub<T> : T extends Promise<infer U> ? Stubify<U> : T extends StubBase<any> ? T : T extends Map<infer K, infer V> ? Map<Stubify<K>, Stubify<V>> : T extends Set<infer V> ? Set<Stubify<V>> : T extends [] ? [] : T extends [infer Head, ...infer Tail] ? [Stubify<Head>, ...Stubify<Tail>] : T extends readonly [] ? readonly [] : T extends readonly [infer Head, ...infer Tail] ? readonly [Stubify<Head>, ...Stubify<Tail>] : T extends Array<infer V> ? Array<Stubify<V>> : T extends ReadonlyArray<infer V> ? ReadonlyArray<Stubify<V>> : T extends BaseType ? T // When using "unknown" instead of "any", interfaces are not stubified.
|
|
@@ -171,6 +172,9 @@ declare class RpcPayload {
|
|
|
171
172
|
private deliverTo;
|
|
172
173
|
private static deliverRpcPromiseTo;
|
|
173
174
|
deliverCall(func: Function, thisArg: object | undefined): Promise<RpcPayload>;
|
|
175
|
+
deliverStreamWrite(writer: {
|
|
176
|
+
write(chunk: unknown): Promise<void>;
|
|
177
|
+
}): Promise<RpcPayload>;
|
|
174
178
|
deliverResolve(): Promise<unknown>;
|
|
175
179
|
dispose(): void;
|
|
176
180
|
private disposeImpl;
|
|
@@ -179,6 +183,32 @@ declare class RpcPayload {
|
|
|
179
183
|
}
|
|
180
184
|
//#endregion
|
|
181
185
|
//#region src/serialize.d.ts
|
|
186
|
+
/**
|
|
187
|
+
* Encoding levels determine what representation the RPC system hands to the transport.
|
|
188
|
+
* Each level names what the transport can assume about message values.
|
|
189
|
+
*
|
|
190
|
+
* - `"string"`: JSON string. Default, used by HTTP batch and WebSocket transports.
|
|
191
|
+
* - `"jsonCompatible"`: JSON-compatible JS value tree. For custom encoders.
|
|
192
|
+
* - `"jsonCompatibleWithBytes"`: Like `"jsonCompatible"` but Uint8Array stays raw.
|
|
193
|
+
* - `"structuredClonable"`: Structured-clonable native values pass through where possible.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* // What happens to Uint8Array([1, 2, 3]) at each level:
|
|
198
|
+
* "string" → '["bytes","AQID"]' // JSON string with base64
|
|
199
|
+
* "jsonCompatible" → ["bytes", "AQID"] // JS array with base64
|
|
200
|
+
* "jsonCompatibleWithBytes" → ["bytes", Uint8Array] // JS array with raw bytes
|
|
201
|
+
* "structuredClonable" → ["bytes", Uint8Array] // + Date, BigInt stay native
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
type EncodingLevel = "string" | "jsonCompatible" | "jsonCompatibleWithBytes" | "structuredClonable";
|
|
205
|
+
interface RpcLimits {
|
|
206
|
+
maxBigIntDigits: number;
|
|
207
|
+
maxDepth: number;
|
|
208
|
+
maxMessageSize: number;
|
|
209
|
+
}
|
|
210
|
+
declare const DEFAULT_MAX_DEPTH = 256;
|
|
211
|
+
declare const DEFAULT_LIMITS: RpcLimits;
|
|
182
212
|
/**
|
|
183
213
|
* Serialize a value, using Cap'n Web's underlying serialization. This won't be able to serialize
|
|
184
214
|
* RPC stubs, but it will support basic data types.
|
|
@@ -191,14 +221,21 @@ declare function deserialize(value: string): unknown;
|
|
|
191
221
|
//#endregion
|
|
192
222
|
//#region src/rpc.d.ts
|
|
193
223
|
/**
|
|
194
|
-
* Interface for
|
|
195
|
-
*
|
|
224
|
+
* Interface for a string-based RPC transport. This is the default transport type — no
|
|
225
|
+
* `encodingLevel` field is needed. Messages are JSON strings. Implement this interface if the
|
|
226
|
+
* built-in transports (e.g. for HTTP batch and WebSocket) don't meet your needs.
|
|
196
227
|
*/
|
|
197
228
|
interface RpcTransport {
|
|
198
229
|
/**
|
|
199
|
-
*
|
|
230
|
+
* The encoding level this transport works with. For this interface it is always "string";
|
|
231
|
+
* it may be omitted. (See `RpcTransportWithCustomEncoding` for the other levels.)
|
|
200
232
|
*/
|
|
201
|
-
|
|
233
|
+
readonly encodingLevel?: "string";
|
|
234
|
+
/**
|
|
235
|
+
* Sends a message to the other end. May optionally return a promise; if the promise rejects,
|
|
236
|
+
* the session is aborted.
|
|
237
|
+
*/
|
|
238
|
+
send(message: string): void | Promise<void>;
|
|
202
239
|
/**
|
|
203
240
|
* Receives a message sent by the other end.
|
|
204
241
|
*
|
|
@@ -217,6 +254,45 @@ interface RpcTransport {
|
|
|
217
254
|
*/
|
|
218
255
|
abort?(reason: any): void;
|
|
219
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Interface for a transport that receives partially encoded JS values instead of JSON strings.
|
|
259
|
+
* The selected `encodingLevel` describes what the transport can assume about message values.
|
|
260
|
+
*/
|
|
261
|
+
interface RpcTransportWithCustomEncoding {
|
|
262
|
+
/**
|
|
263
|
+
* The encoding level this transport works with.
|
|
264
|
+
*
|
|
265
|
+
* - "jsonCompatible": JSON-compatible JS value tree; transport handles final serialization.
|
|
266
|
+
* - "jsonCompatibleWithBytes": Like "jsonCompatible" but Uint8Array values are left raw.
|
|
267
|
+
* - "structuredClonable": Structured-clonable native values pass through where possible.
|
|
268
|
+
*/
|
|
269
|
+
readonly encodingLevel: "jsonCompatible" | "jsonCompatibleWithBytes" | "structuredClonable";
|
|
270
|
+
/**
|
|
271
|
+
* Encodes and sends a message to the other end. Returns the encoded byte size if known.
|
|
272
|
+
* If the size is unavailable, return void; Cap'n Web will estimate stream message sizes for
|
|
273
|
+
* flow control. Send errors should be propagated via `receive()` rejecting.
|
|
274
|
+
*/
|
|
275
|
+
send(message: unknown): number | void;
|
|
276
|
+
/**
|
|
277
|
+
* Receives and decodes a message sent by the other end.
|
|
278
|
+
*
|
|
279
|
+
* If and when the transport becomes disconnected, this will reject. The thrown error will be
|
|
280
|
+
* propagated to all outstanding calls and future calls on any stubs associated with the session.
|
|
281
|
+
* If there are no outstanding calls (and none are made in the future), then the error does not
|
|
282
|
+
* propagate anywhere -- this is considered a "clean" shutdown.
|
|
283
|
+
*/
|
|
284
|
+
receive(): Promise<unknown>;
|
|
285
|
+
/**
|
|
286
|
+
* Indicates that the RPC system has suffered an error that prevents the session from continuing.
|
|
287
|
+
* The transport should ideally try to send any queued messages if it can, and then close the
|
|
288
|
+
* connection. (It's not strictly necessary to deliver queued messages, but the last message sent
|
|
289
|
+
* before abort() is called is often an "abort" message, which communicates the error to the
|
|
290
|
+
* peer, so if that is dropped, the peer may have less information about what happened.)
|
|
291
|
+
*/
|
|
292
|
+
abort?(reason: any): void;
|
|
293
|
+
}
|
|
294
|
+
/** Any supported transport type. */
|
|
295
|
+
type AnyRpcTransport = RpcTransport | RpcTransportWithCustomEncoding;
|
|
220
296
|
/**
|
|
221
297
|
* Options to customize behavior of an RPC session. All functions which start a session should
|
|
222
298
|
* optionally accept this.
|
|
@@ -234,6 +310,16 @@ type RpcSessionOptions = {
|
|
|
234
310
|
* to serialize the error with the stack omitted.
|
|
235
311
|
*/
|
|
236
312
|
onSendError?: (error: Error) => Error | void;
|
|
313
|
+
/**
|
|
314
|
+
* Overrides for the resource limits enforced while deserializing messages from the peer. Any
|
|
315
|
+
* field left unset falls back to `DEFAULT_LIMITS`. These guard against resource-exhaustion
|
|
316
|
+
* attacks from untrusted peers; see `RpcLimits` for the meaning and defaults of each field.
|
|
317
|
+
*
|
|
318
|
+
* Limits are a purely local, receiver-side decision -- the protocol has no negotiation step, so
|
|
319
|
+
* the peer never learns these values. A message that exceeds a limit is rejected, aborting the
|
|
320
|
+
* session.
|
|
321
|
+
*/
|
|
322
|
+
limits?: Partial<RpcLimits>;
|
|
237
323
|
};
|
|
238
324
|
//#endregion
|
|
239
325
|
//#region src/websocket.d.ts
|
|
@@ -242,6 +328,17 @@ type RpcSessionOptions = {
|
|
|
242
328
|
* with the given `localMain`.
|
|
243
329
|
*/
|
|
244
330
|
declare function newWorkersWebSocketRpcResponse(request: Request, localMain?: any, options?: RpcSessionOptions): Response;
|
|
331
|
+
/**
|
|
332
|
+
* Generic WebSocket transport. Default `T = string` is backward-compatible and satisfies
|
|
333
|
+
* `RpcTransport`. Use `T = ArrayBuffer` as a building block for binary transports.
|
|
334
|
+
*/
|
|
335
|
+
declare class WebSocketTransport<T extends string | ArrayBuffer = string> {
|
|
336
|
+
#private;
|
|
337
|
+
constructor(webSocket: WebSocket);
|
|
338
|
+
send(message: T): void;
|
|
339
|
+
receive(): Promise<T>;
|
|
340
|
+
abort(reason: any): void;
|
|
341
|
+
}
|
|
245
342
|
//#endregion
|
|
246
343
|
//#region src/batch.d.ts
|
|
247
344
|
/**
|
|
@@ -316,7 +413,7 @@ interface RpcSession<T extends RpcCompatible<T> = undefined> {
|
|
|
316
413
|
drain(): Promise<void>;
|
|
317
414
|
}
|
|
318
415
|
declare const RpcSession: {
|
|
319
|
-
new <T extends RpcCompatible<T> = undefined>(transport:
|
|
416
|
+
new <T extends RpcCompatible<T> = undefined>(transport: AnyRpcTransport, localMain?: any, options?: RpcSessionOptions): RpcSession<T>;
|
|
320
417
|
};
|
|
321
418
|
/**
|
|
322
419
|
* Classes which are intended to be passed by reference and called over RPC must extend
|
|
@@ -369,7 +466,7 @@ declare let newMessagePortRpcSession: <T extends RpcCompatible<T> = Empty$1>(por
|
|
|
369
466
|
* credentials as parameters and returns the authorized API), then cross-origin requests should
|
|
370
467
|
* be safe.
|
|
371
468
|
*/
|
|
372
|
-
declare function newWorkersRpcResponse(request: Request, localMain: any): Promise<Response>;
|
|
469
|
+
declare function newWorkersRpcResponse(request: Request, localMain: any, options?: RpcSessionOptions): Promise<Response>;
|
|
373
470
|
//#endregion
|
|
374
471
|
//#region src/bun.d.ts
|
|
375
472
|
type WsData = {
|
|
@@ -420,5 +517,5 @@ declare let newBunWebSocketRpcSession: <T extends RpcCompatible<T> = Empty, D =
|
|
|
420
517
|
transport: BunWebSocketTransport<D>;
|
|
421
518
|
};
|
|
422
519
|
//#endregion
|
|
423
|
-
export { BunWebSocketTransport, type RpcCompatible, RpcPromise, RpcSession, type RpcSessionOptions, RpcStub, RpcTarget, type RpcTransport, deserialize, newBunWebSocketRpcHandler, newBunWebSocketRpcSession, newHttpBatchRpcResponse, newHttpBatchRpcSession, newMessagePortRpcSession, newWebSocketRpcSession, newWorkersRpcResponse, newWorkersWebSocketRpcResponse, nodeHttpBatchRpcResponse, serialize };
|
|
520
|
+
export { type AnyRpcTransport, BunWebSocketTransport, DEFAULT_LIMITS, DEFAULT_MAX_DEPTH, type EncodingLevel, type RpcCompatible, type RpcLimits, RpcPromise, RpcSession, type RpcSessionOptions, RpcStub, RpcTarget, type RpcTransport, type RpcTransportWithCustomEncoding, WebSocketTransport, deserialize, newBunWebSocketRpcHandler, newBunWebSocketRpcSession, newHttpBatchRpcResponse, newHttpBatchRpcSession, newMessagePortRpcSession, newWebSocketRpcSession, newWorkersRpcResponse, newWorkersWebSocketRpcResponse, nodeHttpBatchRpcResponse, serialize };
|
|
424
521
|
//# sourceMappingURL=index-bun.d.ts.map
|