@fungi.computer/capnweb 0.0.0-stage → 0.12.0
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/LICENSE.txt +21 -0
- package/NOTICE +10 -0
- package/README.md +95 -2
- package/dist/index-bun.cjs +3347 -0
- package/dist/index-bun.cjs.map +1 -0
- package/dist/index-bun.d.cts +478 -0
- package/dist/index-bun.d.ts +478 -0
- package/dist/index-bun.js +3328 -0
- package/dist/index-bun.js.map +1 -0
- package/dist/index-workers.cjs +3262 -0
- package/dist/index-workers.cjs.map +1 -0
- package/dist/index-workers.d.cts +354 -0
- package/dist/index-workers.d.ts +354 -0
- package/dist/index-workers.js +3218 -0
- package/dist/index-workers.js.map +1 -0
- package/dist/index.cjs +3228 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +354 -0
- package/dist/index.d.ts +354 -0
- package/dist/index.js +3212 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -3
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Cloudflare, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
@fungi.computer/capnweb
|
|
2
|
+
Copyright (c) 2025 Cloudflare, Inc. (upstream capnweb, MIT; see LICENSE.txt)
|
|
3
|
+
|
|
4
|
+
This package is a fork of capnweb (https://github.com/cloudflare/capnweb) at the
|
|
5
|
+
v0.12.0 release commit 7702075. The source is unchanged except for one fix in
|
|
6
|
+
src/types.d.ts: UnstubifyInner spreads a tuple tail through UnstubifyAll<Tail>
|
|
7
|
+
instead of Unstubify<Tail>. Unstubify<Tail> is a union that includes Promise, so
|
|
8
|
+
the upstream declarations fail with TS2574 ("A rest element type must be an
|
|
9
|
+
array type") under skipLibCheck: false and lose tuple parameter types.
|
|
10
|
+
Drop this fork when upstream capnweb publishes the fix.
|
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fungi.computer/capnweb
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Cap'n Web is a JavaScript-native, object-capability RPC system: no schemas, no
|
|
4
|
+
code generation, human-readable (JSON-based) wire format, and support for
|
|
5
|
+
bidirectional calling, passing functions/objects by reference, and promise
|
|
6
|
+
pipelining (chaining dependent calls into a single network round trip). It
|
|
7
|
+
works over HTTP, WebSocket, and `postMessage()`, in browsers, Cloudflare
|
|
8
|
+
Workers, Node.js, Bun, and Deno.
|
|
9
|
+
|
|
10
|
+
## Fungi fork
|
|
11
|
+
|
|
12
|
+
This package is a Fungi fork of
|
|
13
|
+
[cloudflare/capnweb](https://github.com/cloudflare/capnweb) at the `0.12.0`
|
|
14
|
+
release (commit `7702075`). The source is unchanged except for one fix in
|
|
15
|
+
`src/types.d.ts`: `UnstubifyInner` spreads a tuple tail through
|
|
16
|
+
`UnstubifyAll<Tail>` instead of `Unstubify<Tail>`. `Unstubify<Tail>` is a union
|
|
17
|
+
that includes `Promise`, so the upstream declarations fail with TS2574 ("A
|
|
18
|
+
rest element type must be an array type") under `skipLibCheck: false` and lose
|
|
19
|
+
tuple parameter types. Drop this fork when upstream capnweb publishes the fix.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install @fungi.computer/capnweb
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
A client:
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { newWebSocketRpcSession } from "@fungi.computer/capnweb";
|
|
33
|
+
|
|
34
|
+
// One-line setup.
|
|
35
|
+
let api = newWebSocketRpcSession("wss://example.com/api");
|
|
36
|
+
|
|
37
|
+
// Call a method on the server!
|
|
38
|
+
let result = await api.hello("World");
|
|
39
|
+
|
|
40
|
+
console.log(result);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
A server:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import { RpcTarget, newWorkersRpcResponse } from "@fungi.computer/capnweb";
|
|
47
|
+
|
|
48
|
+
// This is the server implementation.
|
|
49
|
+
class MyApiServer extends RpcTarget {
|
|
50
|
+
hello(name) {
|
|
51
|
+
return `Hello, ${name}!`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Standard Cloudflare Workers HTTP handler.
|
|
56
|
+
//
|
|
57
|
+
// (Node, Deno, Bun and other runtimes are supported too.)
|
|
58
|
+
export default {
|
|
59
|
+
fetch(request, env, ctx) {
|
|
60
|
+
let url = new URL(request.url);
|
|
61
|
+
|
|
62
|
+
if (url.pathname === "/api") {
|
|
63
|
+
return newWorkersRpcResponse(request, new MyApiServer());
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return new Response("Not found", { status: 404 });
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Three dependent calls, one round trip:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
using api = newHttpBatchRpcSession<Api>("https://example.com/api");
|
|
75
|
+
|
|
76
|
+
// No awaits, so no round trips yet.
|
|
77
|
+
using authed = api.authenticate(apiToken);
|
|
78
|
+
let friendIds = authed.getFriendIds();
|
|
79
|
+
|
|
80
|
+
// One await. One round trip. Everything above travelled together.
|
|
81
|
+
let friends = await friendIds.map(id => api.getUserProfile(id));
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
For the full API, transports, and server-runtime guides, see the
|
|
85
|
+
[upstream documentation site](https://github.com/cloudflare/capnweb/tree/main/packages/docs)
|
|
86
|
+
and the [upstream README](https://github.com/cloudflare/capnweb#readme).
|
|
87
|
+
|
|
88
|
+
## Where it's used
|
|
89
|
+
|
|
90
|
+
[Oyster](https://github.com/fungi-computer/oyster) uses this fork for its RPC
|
|
91
|
+
transport.
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT. This package carries the upstream Cloudflare copyright and license
|
|
96
|
+
unchanged — see [LICENSE.txt](./LICENSE.txt) and [NOTICE](./NOTICE).
|