capnweb 0.2.0 → 0.4.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/README.md +12 -0
- package/dist/index-workers.cjs +13 -4
- 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 +13 -4
- package/dist/index-workers.js.map +1 -1
- package/dist/index.cjs +13 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -21
- package/dist/index.d.ts +29 -21
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -528,6 +528,14 @@ export default {
|
|
|
528
528
|
}
|
|
529
529
|
```
|
|
530
530
|
|
|
531
|
+
#### Compatibility with Workers' built-in RPC
|
|
532
|
+
|
|
533
|
+
Cloudflare Workers has long featured [a built-in RPC system with semantics similar to Cap'n Web](https://developers.cloudflare.com/workers/runtime-apis/rpc/).
|
|
534
|
+
|
|
535
|
+
Cap'n Web is designed to be compatible with Workers RPC, meaning you can pass Cap'n Web RPC stubs over Workers RPC and vice versa. The system will automatically wrap one stub type in the other and arrange to proxy calls.
|
|
536
|
+
|
|
537
|
+
For best compatibility, make sure to set your [Workers compatibilty date](https://developers.cloudflare.com/workers/configuration/compatibility-dates/) to at least `2026-01-20`, or enable the [compatibility flag](https://developers.cloudflare.com/workers/configuration/compatibility-flags/) `rpc_params_dup_stubs`. (As of this writing, `2026-01-20` is in the future, so you will need to use the flag for now.)
|
|
538
|
+
|
|
531
539
|
### HTTP server on Node.js
|
|
532
540
|
|
|
533
541
|
A server on Node.js is a bit more involved, due to the awkward handling of WebSockets in Node's HTTP library.
|
|
@@ -642,6 +650,10 @@ function newWebSocketRpcSession(
|
|
|
642
650
|
: Disposable;
|
|
643
651
|
```
|
|
644
652
|
|
|
653
|
+
### HTTP server using Hono
|
|
654
|
+
|
|
655
|
+
If your app is built on [Hono](https://hono.dev/) (on any runtime it supports), check out [`@hono/capnweb`](https://github.com/honojs/middleware/tree/main/packages/capnweb).
|
|
656
|
+
|
|
645
657
|
### MessagePort
|
|
646
658
|
|
|
647
659
|
Cap'n Web can also talk over MessagePorts. This can be used in a browser to talk to Web Workers, iframes, etc.
|
package/dist/index-workers.cjs
CHANGED
|
@@ -23,15 +23,15 @@ function _interopNamespace(e) {
|
|
|
23
23
|
var cfw__namespace = /*#__PURE__*/_interopNamespace(cfw);
|
|
24
24
|
|
|
25
25
|
// src/symbols.ts
|
|
26
|
-
var WORKERS_MODULE_SYMBOL = Symbol("workers-module");
|
|
26
|
+
var WORKERS_MODULE_SYMBOL = /* @__PURE__ */ Symbol("workers-module");
|
|
27
27
|
globalThis[WORKERS_MODULE_SYMBOL] = cfw__namespace;
|
|
28
28
|
|
|
29
29
|
// src/core.ts
|
|
30
30
|
if (!Symbol.dispose) {
|
|
31
|
-
Symbol.dispose = Symbol.for("dispose");
|
|
31
|
+
Symbol.dispose = /* @__PURE__ */ Symbol.for("dispose");
|
|
32
32
|
}
|
|
33
33
|
if (!Symbol.asyncDispose) {
|
|
34
|
-
Symbol.asyncDispose = Symbol.for("asyncDispose");
|
|
34
|
+
Symbol.asyncDispose = /* @__PURE__ */ Symbol.for("asyncDispose");
|
|
35
35
|
}
|
|
36
36
|
if (!Promise.withResolvers) {
|
|
37
37
|
Promise.withResolvers = function() {
|
|
@@ -47,6 +47,8 @@ if (!Promise.withResolvers) {
|
|
|
47
47
|
var workersModule = globalThis[WORKERS_MODULE_SYMBOL];
|
|
48
48
|
var RpcTarget = workersModule ? workersModule.RpcTarget : class {
|
|
49
49
|
};
|
|
50
|
+
var AsyncFunction = (async function() {
|
|
51
|
+
}).constructor;
|
|
50
52
|
function typeForRpc(value) {
|
|
51
53
|
switch (typeof value) {
|
|
52
54
|
case "boolean":
|
|
@@ -71,6 +73,7 @@ function typeForRpc(value) {
|
|
|
71
73
|
case Object.prototype:
|
|
72
74
|
return "object";
|
|
73
75
|
case Function.prototype:
|
|
76
|
+
case AsyncFunction.prototype:
|
|
74
77
|
return "function";
|
|
75
78
|
case Array.prototype:
|
|
76
79
|
return "array";
|
|
@@ -154,7 +157,7 @@ function withCallInterceptor(interceptor, callback) {
|
|
|
154
157
|
doCall = oldValue;
|
|
155
158
|
}
|
|
156
159
|
}
|
|
157
|
-
var RAW_STUB = Symbol("realStub");
|
|
160
|
+
var RAW_STUB = /* @__PURE__ */ Symbol("realStub");
|
|
158
161
|
var PROXY_HANDLERS = {
|
|
159
162
|
apply(target, thisArg, argumentsList) {
|
|
160
163
|
let stub = target.raw;
|
|
@@ -422,6 +425,12 @@ var RpcPayload = class _RpcPayload {
|
|
|
422
425
|
// Get the StubHook representing the given RpcTarget found inside this payload.
|
|
423
426
|
getHookForRpcTarget(target, parent, dupStubs = true) {
|
|
424
427
|
if (this.source === "params") {
|
|
428
|
+
if (dupStubs) {
|
|
429
|
+
let dupable = target;
|
|
430
|
+
if (typeof dupable.dup === "function") {
|
|
431
|
+
target = dupable.dup();
|
|
432
|
+
}
|
|
433
|
+
}
|
|
425
434
|
return TargetStubHook.create(target, parent);
|
|
426
435
|
} else if (this.source === "return") {
|
|
427
436
|
let hook = this.rpcTargets?.get(target);
|