@statewalker/webrun-http-streams 0.2.1 → 0.2.2

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 CHANGED
@@ -3,6 +3,63 @@
3
3
  HTTP request / response over a `Duplex` from any `webrun-streams-*` adapter.
4
4
  Replaces the retired `webrun-http` + `webrun-http-port` packages.
5
5
 
6
+ ## Install
7
+
8
+ ```sh
9
+ npm install @statewalker/webrun-http-streams
10
+ ```
11
+
12
+ One runtime dependency, [`@statewalker/webrun-streams`](../webrun-streams); no
13
+ peer dependencies. ESM only (`"type": "module"`). Needs standard `Request`,
14
+ `Response`, `ReadableStream`, `TextEncoder` and `TextDecoder` — present in
15
+ browsers, Node 18+, Deno, Bun and Cloudflare Workers.
16
+
17
+ Pair it with a transport adapter to get a `Duplex`:
18
+ [`-ws`](../webrun-streams-ws), [`webrun-rpc`](../webrun-rpc),
19
+ [`-webrtc`](../webrun-streams-webrtc), [`-libp2p`](../webrun-streams-libp2p),
20
+ [`-livekit`](../webrun-streams-livekit), [`-peerjs`](../webrun-streams-peerjs).
21
+
22
+ ## Getting started
23
+
24
+ Pick a transport, then move standard `Request` / `Response` objects across it.
25
+ Here the transport is an in-process `MessageChannel`, so the whole exchange runs
26
+ in one process with no network:
27
+
28
+ ```ts
29
+ import { connect, serve } from "@statewalker/webrun-rpc";
30
+ import { fetchOverDuplex, serveFetchOverDuplex } from "@statewalker/webrun-http-streams";
31
+
32
+ // --- server side ---
33
+ const channel = new MessageChannel();
34
+ const stop = await serve(
35
+ { port: channel.port2 },
36
+ serveFetchOverDuplex(async (request) => {
37
+ const url = new URL(request.url);
38
+ return Response.json({ path: url.pathname, method: request.method });
39
+ }),
40
+ );
41
+
42
+ // --- client side ---
43
+ const { call, close } = await connect({ port: channel.port1 });
44
+ const response = await fetchOverDuplex(call, new Request("http://local/api/todo/7"));
45
+
46
+ console.log(response.status); // 200
47
+ console.log(await response.json()); // { path: "/api/todo/7", method: "GET" }
48
+
49
+ await close();
50
+ await stop();
51
+ ```
52
+
53
+ Swap `@statewalker/webrun-rpc` for
54
+ [`-ws`](../webrun-streams-ws), [`-webrtc`](../webrun-streams-webrtc),
55
+ [`-libp2p`](../webrun-streams-libp2p), [`-livekit`](../webrun-streams-livekit)
56
+ or [`-peerjs`](../webrun-streams-peerjs) and nothing else changes — that is the
57
+ whole point of the `Duplex` seam.
58
+
59
+ Streaming bodies work as you would expect: a `Response` whose body is a
60
+ `ReadableStream` streams across the transport chunk by chunk, which is what
61
+ makes server-sent events work over a `MessagePort` or a WebRTC link.
62
+
6
63
  ## Layers
7
64
 
8
65
  Three of them sit on the `Duplex` seam, plus one older transport-agnostic pair
@@ -73,7 +130,7 @@ signal terminates the call.
73
130
 
74
131
  ```ts
75
132
  import { DuplexSiteBuilder } from "@statewalker/webrun-http-streams";
76
- import { serve } from "@statewalker/webrun-streams-port";
133
+ import { serve } from "@statewalker/webrun-rpc";
77
134
 
78
135
  const stop = await new DuplexSiteBuilder()
79
136
  .setHandler(siteHandler) // (Request) => Promise<Response>
@@ -88,7 +145,7 @@ own; endpoints, files and auth belong to the `SiteHandler` producer (typically
88
145
  `SiteBuilder`).
89
146
 
90
147
  > Not runnable as written above: it needs a live `MessagePort` and
91
- > `@statewalker/webrun-streams-port`, which this package does not depend on.
148
+ > `@statewalker/webrun-rpc`, which this package does not depend on.
92
149
  > `start` accepts any `Serve<P>`, so an in-process one is enough to exercise
93
150
  > it. Calling `start()` before `setHandler()` throws.
94
151
 
@@ -314,6 +371,20 @@ exception.
314
371
  | `PEER_ERROR_HEADER` | `"x-webrun-error"`. |
315
372
  | `MessageCodec`, `ByteSource`, `RequestEnvelope`, `ResponseEnvelope`, `DecodedRequest`, `DecodedResponse`, `ResponseCodecOptions` | The codec seam's types. |
316
373
 
374
+ ## Dependencies
375
+
376
+ | Dependency | Kind | Why |
377
+ | --- | --- | --- |
378
+ | [`@statewalker/webrun-streams`](../webrun-streams) | runtime | The `Duplex` seam, chunk collectors and error serialisation. |
379
+
380
+ No peer dependencies and no runtime dependencies outside the workspace. Relies
381
+ on the platform for `Request`, `Response`, `ReadableStream`, `TextEncoder` and
382
+ `TextDecoder`.
383
+
384
+ Downstream consumers in this workspace:
385
+ [`webrun-http-browser`](../webrun-http-browser) and
386
+ [`webrun-rpc-http`](../webrun-rpc-http).
387
+
317
388
  ## Scripts
318
389
 
319
390
  ```sh
@@ -324,4 +395,4 @@ pnpm lint # biome check src tests
324
395
 
325
396
  ## License
326
397
 
327
- MIT
398
+ MIT © statewalker — see [LICENSE](../../LICENSE).
@@ -12,7 +12,7 @@ export type SiteHandler = (request: Request) => Promise<Response>;
12
12
  * ```ts
13
13
  * import { SiteBuilder } from "@statewalker/webrun-site-builder";
14
14
  * import { DuplexSiteBuilder } from "@statewalker/webrun-http-streams";
15
- * import { serve } from "@statewalker/webrun-streams-port";
15
+ * import { serve } from "@statewalker/webrun-rpc";
16
16
  *
17
17
  * const handler = new SiteBuilder()
18
18
  * .setEndpoint("/api/time", () => new Response(new Date().toISOString()))
package/dist/index.js CHANGED
@@ -1213,7 +1213,7 @@ function abortReason(signal) {
1213
1213
  * ```ts
1214
1214
  * import { SiteBuilder } from "@statewalker/webrun-site-builder";
1215
1215
  * import { DuplexSiteBuilder } from "@statewalker/webrun-http-streams";
1216
- * import { serve } from "@statewalker/webrun-streams-port";
1216
+ * import { serve } from "@statewalker/webrun-rpc";
1217
1217
  *
1218
1218
  * const handler = new SiteBuilder()
1219
1219
  * .setEndpoint("/api/time", () => new Response(new Date().toISOString()))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statewalker/webrun-http-streams",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "HTTP request/response over Duplex — merge of webrun-http + webrun-http-port",
@@ -15,14 +15,17 @@
15
15
  "url": "git@github.com:statewalker/webrun-wire.git"
16
16
  },
17
17
  "exports": {
18
- ".": "./src/index.ts"
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
19
22
  },
20
23
  "files": [
21
24
  "dist",
22
25
  "src"
23
26
  ],
24
27
  "dependencies": {
25
- "@statewalker/webrun-streams": "0.1.1"
28
+ "@statewalker/webrun-streams": "0.2.0"
26
29
  },
27
30
  "devDependencies": {
28
31
  "@types/node": "^26.2.0",
@@ -35,6 +38,7 @@
35
38
  "publishConfig": {
36
39
  "access": "public"
37
40
  },
41
+ "types": "./dist/index.d.ts",
38
42
  "scripts": {
39
43
  "build": "rimraf dist && rolldown -c && tsc --emitDeclarationOnly --declaration",
40
44
  "test": "vitest run",
@@ -15,7 +15,7 @@ export type SiteHandler = (request: Request) => Promise<Response>;
15
15
  * ```ts
16
16
  * import { SiteBuilder } from "@statewalker/webrun-site-builder";
17
17
  * import { DuplexSiteBuilder } from "@statewalker/webrun-http-streams";
18
- * import { serve } from "@statewalker/webrun-streams-port";
18
+ * import { serve } from "@statewalker/webrun-rpc";
19
19
  *
20
20
  * const handler = new SiteBuilder()
21
21
  * .setEndpoint("/api/time", () => new Response(new Date().toISOString()))
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022-2026 statewalker
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.