capnweb 0.0.0-85fde1b → 0.0.0-8a47045
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/index-workers.cjs.map +1 -1
- package/dist/index-workers.d.cts +1 -1
- package/dist/index-workers.d.ts +1 -1
- package/dist/index-workers.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -21
- package/dist/index.d.ts +21 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -23,21 +23,21 @@ type Stubable = RpcTargetBranded | ((...args: any[]) => any);
|
|
|
23
23
|
// The reason for using a generic type here is to build a serializable subset of structured
|
|
24
24
|
// cloneable composite types. This allows types defined with the "interface" keyword to pass the
|
|
25
25
|
// serializable check as well. Otherwise, only types defined with the "type" keyword would pass.
|
|
26
|
-
type
|
|
26
|
+
type RpcCompatible<T> =
|
|
27
27
|
// Structured cloneables
|
|
28
28
|
| BaseType
|
|
29
29
|
// Structured cloneable composites
|
|
30
30
|
| Map<
|
|
31
|
-
T extends Map<infer U, unknown> ?
|
|
32
|
-
T extends Map<unknown, infer U> ?
|
|
31
|
+
T extends Map<infer U, unknown> ? RpcCompatible<U> : never,
|
|
32
|
+
T extends Map<unknown, infer U> ? RpcCompatible<U> : never
|
|
33
33
|
>
|
|
34
|
-
| Set<T extends Set<infer U> ?
|
|
35
|
-
| Array<T extends Array<infer U> ?
|
|
36
|
-
| ReadonlyArray<T extends ReadonlyArray<infer U> ?
|
|
34
|
+
| Set<T extends Set<infer U> ? RpcCompatible<U> : never>
|
|
35
|
+
| Array<T extends Array<infer U> ? RpcCompatible<U> : never>
|
|
36
|
+
| ReadonlyArray<T extends ReadonlyArray<infer U> ? RpcCompatible<U> : never>
|
|
37
37
|
| {
|
|
38
|
-
[K in keyof T]: K extends number | string ?
|
|
38
|
+
[K in keyof T]: K extends number | string ? RpcCompatible<T[K]> : never;
|
|
39
39
|
}
|
|
40
|
-
| Promise<T extends Promise<infer U> ?
|
|
40
|
+
| Promise<T extends Promise<infer U> ? RpcCompatible<U> : never>
|
|
41
41
|
// Special types
|
|
42
42
|
| Stub<Stubable>
|
|
43
43
|
// Serialized as stubs, see `Stubify`
|
|
@@ -45,12 +45,12 @@ type Serializable<T> =
|
|
|
45
45
|
|
|
46
46
|
// Base type for all RPC stubs, including common memory management methods.
|
|
47
47
|
// `T` is used as a marker type for unwrapping `Stub`s later.
|
|
48
|
-
interface StubBase<T extends
|
|
48
|
+
interface StubBase<T extends RpcCompatible<T>> extends Disposable {
|
|
49
49
|
[__RPC_STUB_BRAND]: T;
|
|
50
50
|
dup(): this;
|
|
51
51
|
onRpcBroken(callback: (error: any) => void): void;
|
|
52
52
|
}
|
|
53
|
-
type Stub<T extends
|
|
53
|
+
type Stub<T extends RpcCompatible<T>> =
|
|
54
54
|
T extends object ? Provider<T> & StubBase<T> : StubBase<T>;
|
|
55
55
|
|
|
56
56
|
type TypedArray =
|
|
@@ -127,7 +127,7 @@ type MaybeDisposable<T> = T extends object ? Disposable : unknown;
|
|
|
127
127
|
|
|
128
128
|
// Type for method return or property on an RPC interface.
|
|
129
129
|
// - Stubable types are replaced by stubs.
|
|
130
|
-
// -
|
|
130
|
+
// - RpcCompatible types are passed by value, with stubable types replaced by stubs
|
|
131
131
|
// and a top-level `Disposer`.
|
|
132
132
|
// Everything else can't be passed over RPC.
|
|
133
133
|
// Technically, we use custom thenables here, but they quack like `Promise`s.
|
|
@@ -135,7 +135,7 @@ type MaybeDisposable<T> = T extends object ? Disposable : unknown;
|
|
|
135
135
|
// prettier-ignore
|
|
136
136
|
type Result<R> =
|
|
137
137
|
R extends Stubable ? Promise<Stub<R>> & Provider<R> & StubBase<R>
|
|
138
|
-
: R extends
|
|
138
|
+
: R extends RpcCompatible<R> ? Promise<Stubify<R> & MaybeDisposable<R>> & Provider<R> & StubBase<R>
|
|
139
139
|
: never;
|
|
140
140
|
|
|
141
141
|
// Type for method or property on an RPC interface.
|
|
@@ -266,9 +266,9 @@ declare function nodeHttpBatchRpcResponse(request: IncomingMessage, response: Se
|
|
|
266
266
|
* such method exists on the remote object, an exception is thrown back. But the client does not
|
|
267
267
|
* actually know, until that point, what methods exist.
|
|
268
268
|
*/
|
|
269
|
-
type RpcStub<T extends
|
|
269
|
+
type RpcStub<T extends RpcCompatible<T>> = Stub<T>;
|
|
270
270
|
declare const RpcStub: {
|
|
271
|
-
new <T extends
|
|
271
|
+
new <T extends RpcCompatible<T>>(value: T): RpcStub<T>;
|
|
272
272
|
};
|
|
273
273
|
/**
|
|
274
274
|
* Represents the result of an RPC call.
|
|
@@ -288,14 +288,14 @@ declare const RpcStub: {
|
|
|
288
288
|
* if you only intend to use the promise for pipelining and you never await it, then there's no
|
|
289
289
|
* need to transmit the resolution!
|
|
290
290
|
*/
|
|
291
|
-
type RpcPromise<T extends
|
|
291
|
+
type RpcPromise<T extends RpcCompatible<T>> = Stub<T> & Promise<Stubify<T>>;
|
|
292
292
|
declare const RpcPromise: {};
|
|
293
293
|
/**
|
|
294
294
|
* Use to construct an `RpcSession` on top of a custom `RpcTransport`.
|
|
295
295
|
*
|
|
296
296
|
* Most people won't use this. You only need it if you've implemented your own `RpcTransport`.
|
|
297
297
|
*/
|
|
298
|
-
interface RpcSession<T extends
|
|
298
|
+
interface RpcSession<T extends RpcCompatible<T> = undefined> {
|
|
299
299
|
getRemoteMain(): RpcStub<T>;
|
|
300
300
|
getStats(): {
|
|
301
301
|
imports: number;
|
|
@@ -304,7 +304,7 @@ interface RpcSession<T extends Serializable<T> = undefined> {
|
|
|
304
304
|
drain(): Promise<void>;
|
|
305
305
|
}
|
|
306
306
|
declare const RpcSession: {
|
|
307
|
-
new <T extends
|
|
307
|
+
new <T extends RpcCompatible<T> = undefined>(transport: RpcTransport, localMain?: any, options?: RpcSessionOptions): RpcSession<T>;
|
|
308
308
|
};
|
|
309
309
|
/**
|
|
310
310
|
* Classes which are intended to be passed by reference and called over RPC must extend
|
|
@@ -333,7 +333,7 @@ interface Empty {
|
|
|
333
333
|
* @param localMain The main RPC interface to expose to the peer. Returns a stub for the main
|
|
334
334
|
* interface exposed from the peer.
|
|
335
335
|
*/
|
|
336
|
-
declare let newWebSocketRpcSession: <T extends
|
|
336
|
+
declare let newWebSocketRpcSession: <T extends RpcCompatible<T> = Empty>(webSocket: WebSocket | string, localMain?: any, options?: RpcSessionOptions) => RpcStub<T>;
|
|
337
337
|
/**
|
|
338
338
|
* Initiate an HTTP batch session from the client side.
|
|
339
339
|
*
|
|
@@ -341,13 +341,13 @@ declare let newWebSocketRpcSession: <T extends Serializable<T> = Empty>(webSocke
|
|
|
341
341
|
* value is an RpcStub. You can customize anything about the request except for the method
|
|
342
342
|
* (it will always be set to POST) and the body (which the RPC system will fill in).
|
|
343
343
|
*/
|
|
344
|
-
declare let newHttpBatchRpcSession: <T extends
|
|
344
|
+
declare let newHttpBatchRpcSession: <T extends RpcCompatible<T>>(urlOrRequest: string | Request, options?: RpcSessionOptions) => RpcStub<T>;
|
|
345
345
|
/**
|
|
346
346
|
* Initiate an RPC session over a MessagePort, which is particularly useful for communicating
|
|
347
347
|
* between an iframe and its parent frame in a browser context. Each side should call this function
|
|
348
348
|
* on its own end of the MessageChannel.
|
|
349
349
|
*/
|
|
350
|
-
declare let newMessagePortRpcSession: <T extends
|
|
350
|
+
declare let newMessagePortRpcSession: <T extends RpcCompatible<T> = Empty>(port: MessagePort, localMain?: any, options?: RpcSessionOptions) => RpcStub<T>;
|
|
351
351
|
/**
|
|
352
352
|
* Implements unified handling of HTTP-batch and WebSocket responses for the Cloudflare Workers
|
|
353
353
|
* Runtime.
|
|
@@ -361,4 +361,4 @@ declare let newMessagePortRpcSession: <T extends Serializable<T> = Empty>(port:
|
|
|
361
361
|
*/
|
|
362
362
|
declare function newWorkersRpcResponse(request: Request, localMain: any): Promise<Response>;
|
|
363
363
|
|
|
364
|
-
export { RpcPromise, RpcSession, type RpcSessionOptions, RpcStub, RpcTarget, type RpcTransport, deserialize, newHttpBatchRpcResponse, newHttpBatchRpcSession, newMessagePortRpcSession, newWebSocketRpcSession, newWorkersRpcResponse, newWorkersWebSocketRpcResponse, nodeHttpBatchRpcResponse, serialize };
|
|
364
|
+
export { type RpcCompatible, RpcPromise, RpcSession, type RpcSessionOptions, RpcStub, RpcTarget, type RpcTransport, deserialize, newHttpBatchRpcResponse, newHttpBatchRpcSession, newMessagePortRpcSession, newWebSocketRpcSession, newWorkersRpcResponse, newWorkersWebSocketRpcResponse, nodeHttpBatchRpcResponse, serialize };
|
package/dist/index.d.ts
CHANGED
|
@@ -23,21 +23,21 @@ type Stubable = RpcTargetBranded | ((...args: any[]) => any);
|
|
|
23
23
|
// The reason for using a generic type here is to build a serializable subset of structured
|
|
24
24
|
// cloneable composite types. This allows types defined with the "interface" keyword to pass the
|
|
25
25
|
// serializable check as well. Otherwise, only types defined with the "type" keyword would pass.
|
|
26
|
-
type
|
|
26
|
+
type RpcCompatible<T> =
|
|
27
27
|
// Structured cloneables
|
|
28
28
|
| BaseType
|
|
29
29
|
// Structured cloneable composites
|
|
30
30
|
| Map<
|
|
31
|
-
T extends Map<infer U, unknown> ?
|
|
32
|
-
T extends Map<unknown, infer U> ?
|
|
31
|
+
T extends Map<infer U, unknown> ? RpcCompatible<U> : never,
|
|
32
|
+
T extends Map<unknown, infer U> ? RpcCompatible<U> : never
|
|
33
33
|
>
|
|
34
|
-
| Set<T extends Set<infer U> ?
|
|
35
|
-
| Array<T extends Array<infer U> ?
|
|
36
|
-
| ReadonlyArray<T extends ReadonlyArray<infer U> ?
|
|
34
|
+
| Set<T extends Set<infer U> ? RpcCompatible<U> : never>
|
|
35
|
+
| Array<T extends Array<infer U> ? RpcCompatible<U> : never>
|
|
36
|
+
| ReadonlyArray<T extends ReadonlyArray<infer U> ? RpcCompatible<U> : never>
|
|
37
37
|
| {
|
|
38
|
-
[K in keyof T]: K extends number | string ?
|
|
38
|
+
[K in keyof T]: K extends number | string ? RpcCompatible<T[K]> : never;
|
|
39
39
|
}
|
|
40
|
-
| Promise<T extends Promise<infer U> ?
|
|
40
|
+
| Promise<T extends Promise<infer U> ? RpcCompatible<U> : never>
|
|
41
41
|
// Special types
|
|
42
42
|
| Stub<Stubable>
|
|
43
43
|
// Serialized as stubs, see `Stubify`
|
|
@@ -45,12 +45,12 @@ type Serializable<T> =
|
|
|
45
45
|
|
|
46
46
|
// Base type for all RPC stubs, including common memory management methods.
|
|
47
47
|
// `T` is used as a marker type for unwrapping `Stub`s later.
|
|
48
|
-
interface StubBase<T extends
|
|
48
|
+
interface StubBase<T extends RpcCompatible<T>> extends Disposable {
|
|
49
49
|
[__RPC_STUB_BRAND]: T;
|
|
50
50
|
dup(): this;
|
|
51
51
|
onRpcBroken(callback: (error: any) => void): void;
|
|
52
52
|
}
|
|
53
|
-
type Stub<T extends
|
|
53
|
+
type Stub<T extends RpcCompatible<T>> =
|
|
54
54
|
T extends object ? Provider<T> & StubBase<T> : StubBase<T>;
|
|
55
55
|
|
|
56
56
|
type TypedArray =
|
|
@@ -127,7 +127,7 @@ type MaybeDisposable<T> = T extends object ? Disposable : unknown;
|
|
|
127
127
|
|
|
128
128
|
// Type for method return or property on an RPC interface.
|
|
129
129
|
// - Stubable types are replaced by stubs.
|
|
130
|
-
// -
|
|
130
|
+
// - RpcCompatible types are passed by value, with stubable types replaced by stubs
|
|
131
131
|
// and a top-level `Disposer`.
|
|
132
132
|
// Everything else can't be passed over RPC.
|
|
133
133
|
// Technically, we use custom thenables here, but they quack like `Promise`s.
|
|
@@ -135,7 +135,7 @@ type MaybeDisposable<T> = T extends object ? Disposable : unknown;
|
|
|
135
135
|
// prettier-ignore
|
|
136
136
|
type Result<R> =
|
|
137
137
|
R extends Stubable ? Promise<Stub<R>> & Provider<R> & StubBase<R>
|
|
138
|
-
: R extends
|
|
138
|
+
: R extends RpcCompatible<R> ? Promise<Stubify<R> & MaybeDisposable<R>> & Provider<R> & StubBase<R>
|
|
139
139
|
: never;
|
|
140
140
|
|
|
141
141
|
// Type for method or property on an RPC interface.
|
|
@@ -266,9 +266,9 @@ declare function nodeHttpBatchRpcResponse(request: IncomingMessage, response: Se
|
|
|
266
266
|
* such method exists on the remote object, an exception is thrown back. But the client does not
|
|
267
267
|
* actually know, until that point, what methods exist.
|
|
268
268
|
*/
|
|
269
|
-
type RpcStub<T extends
|
|
269
|
+
type RpcStub<T extends RpcCompatible<T>> = Stub<T>;
|
|
270
270
|
declare const RpcStub: {
|
|
271
|
-
new <T extends
|
|
271
|
+
new <T extends RpcCompatible<T>>(value: T): RpcStub<T>;
|
|
272
272
|
};
|
|
273
273
|
/**
|
|
274
274
|
* Represents the result of an RPC call.
|
|
@@ -288,14 +288,14 @@ declare const RpcStub: {
|
|
|
288
288
|
* if you only intend to use the promise for pipelining and you never await it, then there's no
|
|
289
289
|
* need to transmit the resolution!
|
|
290
290
|
*/
|
|
291
|
-
type RpcPromise<T extends
|
|
291
|
+
type RpcPromise<T extends RpcCompatible<T>> = Stub<T> & Promise<Stubify<T>>;
|
|
292
292
|
declare const RpcPromise: {};
|
|
293
293
|
/**
|
|
294
294
|
* Use to construct an `RpcSession` on top of a custom `RpcTransport`.
|
|
295
295
|
*
|
|
296
296
|
* Most people won't use this. You only need it if you've implemented your own `RpcTransport`.
|
|
297
297
|
*/
|
|
298
|
-
interface RpcSession<T extends
|
|
298
|
+
interface RpcSession<T extends RpcCompatible<T> = undefined> {
|
|
299
299
|
getRemoteMain(): RpcStub<T>;
|
|
300
300
|
getStats(): {
|
|
301
301
|
imports: number;
|
|
@@ -304,7 +304,7 @@ interface RpcSession<T extends Serializable<T> = undefined> {
|
|
|
304
304
|
drain(): Promise<void>;
|
|
305
305
|
}
|
|
306
306
|
declare const RpcSession: {
|
|
307
|
-
new <T extends
|
|
307
|
+
new <T extends RpcCompatible<T> = undefined>(transport: RpcTransport, localMain?: any, options?: RpcSessionOptions): RpcSession<T>;
|
|
308
308
|
};
|
|
309
309
|
/**
|
|
310
310
|
* Classes which are intended to be passed by reference and called over RPC must extend
|
|
@@ -333,7 +333,7 @@ interface Empty {
|
|
|
333
333
|
* @param localMain The main RPC interface to expose to the peer. Returns a stub for the main
|
|
334
334
|
* interface exposed from the peer.
|
|
335
335
|
*/
|
|
336
|
-
declare let newWebSocketRpcSession: <T extends
|
|
336
|
+
declare let newWebSocketRpcSession: <T extends RpcCompatible<T> = Empty>(webSocket: WebSocket | string, localMain?: any, options?: RpcSessionOptions) => RpcStub<T>;
|
|
337
337
|
/**
|
|
338
338
|
* Initiate an HTTP batch session from the client side.
|
|
339
339
|
*
|
|
@@ -341,13 +341,13 @@ declare let newWebSocketRpcSession: <T extends Serializable<T> = Empty>(webSocke
|
|
|
341
341
|
* value is an RpcStub. You can customize anything about the request except for the method
|
|
342
342
|
* (it will always be set to POST) and the body (which the RPC system will fill in).
|
|
343
343
|
*/
|
|
344
|
-
declare let newHttpBatchRpcSession: <T extends
|
|
344
|
+
declare let newHttpBatchRpcSession: <T extends RpcCompatible<T>>(urlOrRequest: string | Request, options?: RpcSessionOptions) => RpcStub<T>;
|
|
345
345
|
/**
|
|
346
346
|
* Initiate an RPC session over a MessagePort, which is particularly useful for communicating
|
|
347
347
|
* between an iframe and its parent frame in a browser context. Each side should call this function
|
|
348
348
|
* on its own end of the MessageChannel.
|
|
349
349
|
*/
|
|
350
|
-
declare let newMessagePortRpcSession: <T extends
|
|
350
|
+
declare let newMessagePortRpcSession: <T extends RpcCompatible<T> = Empty>(port: MessagePort, localMain?: any, options?: RpcSessionOptions) => RpcStub<T>;
|
|
351
351
|
/**
|
|
352
352
|
* Implements unified handling of HTTP-batch and WebSocket responses for the Cloudflare Workers
|
|
353
353
|
* Runtime.
|
|
@@ -361,4 +361,4 @@ declare let newMessagePortRpcSession: <T extends Serializable<T> = Empty>(port:
|
|
|
361
361
|
*/
|
|
362
362
|
declare function newWorkersRpcResponse(request: Request, localMain: any): Promise<Response>;
|
|
363
363
|
|
|
364
|
-
export { RpcPromise, RpcSession, type RpcSessionOptions, RpcStub, RpcTarget, type RpcTransport, deserialize, newHttpBatchRpcResponse, newHttpBatchRpcSession, newMessagePortRpcSession, newWebSocketRpcSession, newWorkersRpcResponse, newWorkersWebSocketRpcResponse, nodeHttpBatchRpcResponse, serialize };
|
|
364
|
+
export { type RpcCompatible, RpcPromise, RpcSession, type RpcSessionOptions, RpcStub, RpcTarget, type RpcTransport, deserialize, newHttpBatchRpcResponse, newHttpBatchRpcSession, newMessagePortRpcSession, newWebSocketRpcSession, newWorkersRpcResponse, newWorkersWebSocketRpcResponse, nodeHttpBatchRpcResponse, serialize };
|