@zap-proto/web 0.1.0 → 0.1.1

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
@@ -127,15 +127,32 @@ zapgen --target=ts -single hello.zap # → hello_zap.ts (views + builders)
127
127
  Method ordinals (the interface method `@n`) are the integers you pass to
128
128
  `bootstrap.call(method, …)` and match in your `rootCap` dispatch.
129
129
 
130
+ ## Entry points
131
+
132
+ The root entry (`@zap-proto/web`) is **browser-safe** — it imports no Node
133
+ built-ins and exposes only the client surface (`connect`, `browserWsTransport`,
134
+ `Conn`, errors). The Node server (`serve`, `nodeWsTransport`, the `MintCap`
135
+ auth slot) reaches `node:module` (`createRequire`) / `node:http` / `node:net`
136
+ and lives behind `@zap-proto/web/server`, so it never enters a browser bundle.
137
+
138
+ ```ts
139
+ // Browser — the client connection.
140
+ import { connect } from "@zap-proto/web/client";
141
+
142
+ // Node — attach the RPC endpoint to an http.Server.
143
+ import { serve } from "@zap-proto/web/server";
144
+ ```
145
+
130
146
  ## API
131
147
 
132
148
  | Export | Entry | Purpose |
133
149
  | --- | --- | --- |
134
- | `serve(httpServer, opts)` | `@zap-proto/web/server` | Attach a ZAP RPC endpoint to a Node `http.Server`. |
135
- | `connect(url, opts?)` | `@zap-proto/web/client` | Open a ZAP RPC WebSocket; returns `{ bootstrap, close }`. |
136
- | `nodeWsTransport(ws)` / `browserWsTransport(ws)` | `@zap-proto/web/transport` | Wrap a `ws`/native WebSocket as a `WsTransport`. |
137
- | `MintCap<Ctx>` | `@zap-proto/web/auth` | The bearer→ctx slot. |
138
- | `WebRpcError` | `@zap-proto/web` | Transport-level RPC failure (rejected upgrade, mid-call close, non-OK status). |
150
+ | `connect(url, opts?)` | `@zap-proto/web/client` (or root) | Open a ZAP RPC WebSocket; returns `{ bootstrap, close }`. |
151
+ | `browserWsTransport(ws)` | `@zap-proto/web/transport` (or root) | Wrap a native WebSocket as a `WsTransport`. |
152
+ | `Conn`, `WebRpcError` | `@zap-proto/web` (root, browser-safe) | Duplex RPC connection; transport-level RPC failure. |
153
+ | `serve(httpServer, opts)` | `@zap-proto/web/server` | **Node only.** Attach a ZAP RPC endpoint to a Node `http.Server`. |
154
+ | `nodeWsTransport(ws)` | `@zap-proto/web/server` (or `/transport`) | **Node only.** Wrap a `ws` WebSocket as a `WsTransport`. |
155
+ | `MintCap<Ctx>` | `@zap-proto/web/server` (or `/auth`) | **Node only.** The bearer→ctx slot. |
139
156
 
140
157
  ## License
141
158
 
package/dist/index.d.ts CHANGED
@@ -6,19 +6,24 @@
6
6
  * runtime). Service shape comes from .zap schemas via `zapgen --target=ts`, not
7
7
  * a Zod/procedure DSL. Binary only — no JSON fallback, no Cap'n Proto.
8
8
  *
9
- * - serve(httpServer, opts) — Node: attach a ZAP RPC endpoint to http.Server.
10
- * - connect(url, opts) — browser/Node: open a typed RPC connection.
11
- * - {node,browser}WsTransport isomorphic WS transport factories.
12
- * - MintCap — the bearer→ctx auth slot at the upgrade.
9
+ * This root entry is BROWSER-SAFE it imports no Node built-ins. The Node
10
+ * server (`serve`, `nodeWsTransport`, the `MintCap` auth slot) lives behind the
11
+ * `@zap-proto/web/server` sub-path so `node:module` / `createRequire` never
12
+ * leaks into a browser bundle.
13
+ *
14
+ * - connect(url, opts) — open a typed RPC connection (browser or Node).
15
+ * - browserWsTransport — wrap the browser's native WebSocket.
16
+ * - Conn — the duplex ZAP RPC connection.
17
+ *
18
+ * For the Node server side, import from `@zap-proto/web/server`:
19
+ *
20
+ * import { serve } from "@zap-proto/web/server";
13
21
  */
14
- export { serve } from "./server.js";
15
- export type { ServeOptions, ServeHandle, RootCap } from "./server.js";
16
22
  export { connect } from "./client.js";
17
23
  export type { ConnectOptions, Connection } from "./client.js";
18
- export { nodeWsTransport, browserWsTransport, WS_CLOSE_UNSUPPORTED, } from "./transport.js";
24
+ export { browserWsTransport, WS_CLOSE_UNSUPPORTED } from "./transport.js";
19
25
  export type { WsTransport } from "./transport.js";
20
26
  export { Conn } from "./conn.js";
21
27
  export type { CallHandler, CallOptions } from "./conn.js";
22
- export type { MintCap } from "./auth.js";
23
28
  export { WebRpcError, ZapParseError } from "./errors.js";
24
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE1D,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -8,14 +8,21 @@
8
8
  * runtime). Service shape comes from .zap schemas via `zapgen --target=ts`, not
9
9
  * a Zod/procedure DSL. Binary only — no JSON fallback, no Cap'n Proto.
10
10
  *
11
- * - serve(httpServer, opts) — Node: attach a ZAP RPC endpoint to http.Server.
12
- * - connect(url, opts) — browser/Node: open a typed RPC connection.
13
- * - {node,browser}WsTransport isomorphic WS transport factories.
14
- * - MintCap — the bearer→ctx auth slot at the upgrade.
11
+ * This root entry is BROWSER-SAFE it imports no Node built-ins. The Node
12
+ * server (`serve`, `nodeWsTransport`, the `MintCap` auth slot) lives behind the
13
+ * `@zap-proto/web/server` sub-path so `node:module` / `createRequire` never
14
+ * leaks into a browser bundle.
15
+ *
16
+ * - connect(url, opts) — open a typed RPC connection (browser or Node).
17
+ * - browserWsTransport — wrap the browser's native WebSocket.
18
+ * - Conn — the duplex ZAP RPC connection.
19
+ *
20
+ * For the Node server side, import from `@zap-proto/web/server`:
21
+ *
22
+ * import { serve } from "@zap-proto/web/server";
15
23
  */
16
- export { serve } from "./server.js";
17
24
  export { connect } from "./client.js";
18
- export { nodeWsTransport, browserWsTransport, WS_CLOSE_UNSUPPORTED, } from "./transport.js";
25
+ export { browserWsTransport, WS_CLOSE_UNSUPPORTED } from "./transport.js";
19
26
  export { Conn } from "./conn.js";
20
27
  export { WebRpcError, ZapParseError } from "./errors.js";
21
28
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,4CAA4C;AAE5C;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAKjC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,4CAA4C;AAE5C;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAG1E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
package/dist/server.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { Server as HttpServer } from "node:http";
2
2
  import type { CallHandler } from "./conn.js";
3
3
  import type { MintCap } from "./auth.js";
4
+ export { nodeWsTransport } from "./transport.js";
5
+ export type { MintCap } from "./auth.js";
4
6
  /**
5
7
  * rootCap produces the per-connection dispatch root for a minted ctx.
6
8
  *
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAmB,MAAM,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,WAAW,CAAC;AAErD,iCAAiC;AACjC,MAAM,WAAW,YAAY,CAAC,GAAG;IAC/B,4DAA4D;IAC5D,IAAI,CAA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ClC;AAED,qEAAqE;AACrE,MAAM,WAAW,WAAW;IAC1B,oDAAoD;IACpD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,GAAG,EACvB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,YAAY,CAAC,GAAG,CAAC,GACtB,WAAW,CAmEb"}
package/dist/server.js CHANGED
@@ -22,6 +22,10 @@
22
22
  import { createRequire } from "node:module";
23
23
  import { Conn } from "./conn.js";
24
24
  import { nodeWsTransport } from "./transport.js";
25
+ // `@zap-proto/web/server` is the complete Node surface. Re-export the
26
+ // server-side transport factory and the auth slot so consumers import the whole
27
+ // server API from one sub-path (the root entry is browser-safe and omits these).
28
+ export { nodeWsTransport } from "./transport.js";
25
29
  /**
26
30
  * Attach a ZAP RPC endpoint to `httpServer`. Returns a handle whose close()
27
31
  * tears down the WebSocket server and all open connections.
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,4CAA4C;AAE5C;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAgCjD;;;GAGG;AACH,MAAM,UAAU,KAAK,CACnB,UAAsB,EACtB,IAAuB;IAEvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC;IACjC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAE3C,0EAA0E;IAC1E,4EAA4E;IAC5E,iEAAiE;IACjE,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3C,MAAM,EAAE,eAAe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AC,CAAC;QACL,CAAC,CAAC,EAAE,CAAC;IACP,CAAC,CAAC;IAEF,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAEpC,OAAO;QACL,KAAK,CAAC,KAAK;YACT,UAAU,CAAC,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YAChD,KAAK,MAAM,IAAI,IAAI,KAAK;gBAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;YACnE,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACnE,CAAC;KACF,CAAC;AACJ,CAAC;AAED,iFAAiF;AACjF,SAAS,MAAM,CAAC,MAAc,EAAE,IAAY,EAAE,IAAY;IACxD,MAAM,CAAC,KAAK,CACV,YAAY,IAAI,IAAI,IAAI,MAAM;QAC5B,uBAAuB;QACvB,uBAAuB;QACvB,MAAM,CACT,CAAC;IACF,MAAM,CAAC,OAAO,EAAE,CAAC;AACnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zap-proto/web",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Browser frontend RPC over ZAP — a drop-in tRPC replacement for Next.js / Remix / SvelteKit. Native ZAP envelopes over WebSocket binary frames; layered on @zap-proto/zap. No Cap'n Proto, no JSON.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -40,7 +40,7 @@
40
40
  "src"
41
41
  ],
42
42
  "dependencies": {
43
- "@zap-proto/zap": "^1.1.0"
43
+ "@zap-proto/zap": "^1.2.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "ws": ">=8"
@@ -54,6 +54,7 @@
54
54
  "@types/node": "^22.0.0",
55
55
  "@types/ws": "^8.5.12",
56
56
  "eslint": "^9.0.0",
57
+ "happy-dom": "^20.10.4",
57
58
  "prettier": "^3.3.0",
58
59
  "typescript": "^5.9.3",
59
60
  "vitest": "^4.1.4",
package/src/index.ts CHANGED
@@ -9,28 +9,27 @@
9
9
  * runtime). Service shape comes from .zap schemas via `zapgen --target=ts`, not
10
10
  * a Zod/procedure DSL. Binary only — no JSON fallback, no Cap'n Proto.
11
11
  *
12
- * - serve(httpServer, opts) — Node: attach a ZAP RPC endpoint to http.Server.
13
- * - connect(url, opts) — browser/Node: open a typed RPC connection.
14
- * - {node,browser}WsTransport isomorphic WS transport factories.
15
- * - MintCap — the bearer→ctx auth slot at the upgrade.
12
+ * This root entry is BROWSER-SAFE it imports no Node built-ins. The Node
13
+ * server (`serve`, `nodeWsTransport`, the `MintCap` auth slot) lives behind the
14
+ * `@zap-proto/web/server` sub-path so `node:module` / `createRequire` never
15
+ * leaks into a browser bundle.
16
+ *
17
+ * - connect(url, opts) — open a typed RPC connection (browser or Node).
18
+ * - browserWsTransport — wrap the browser's native WebSocket.
19
+ * - Conn — the duplex ZAP RPC connection.
20
+ *
21
+ * For the Node server side, import from `@zap-proto/web/server`:
22
+ *
23
+ * import { serve } from "@zap-proto/web/server";
16
24
  */
17
25
 
18
- export { serve } from "./server.js";
19
- export type { ServeOptions, ServeHandle, RootCap } from "./server.js";
20
-
21
26
  export { connect } from "./client.js";
22
27
  export type { ConnectOptions, Connection } from "./client.js";
23
28
 
24
- export {
25
- nodeWsTransport,
26
- browserWsTransport,
27
- WS_CLOSE_UNSUPPORTED,
28
- } from "./transport.js";
29
+ export { browserWsTransport, WS_CLOSE_UNSUPPORTED } from "./transport.js";
29
30
  export type { WsTransport } from "./transport.js";
30
31
 
31
32
  export { Conn } from "./conn.js";
32
33
  export type { CallHandler, CallOptions } from "./conn.js";
33
34
 
34
- export type { MintCap } from "./auth.js";
35
-
36
35
  export { WebRpcError, ZapParseError } from "./errors.js";
package/src/server.ts CHANGED
@@ -29,6 +29,12 @@ import { Conn } from "./conn.js";
29
29
  import { nodeWsTransport } from "./transport.js";
30
30
  import type { MintCap } from "./auth.js";
31
31
 
32
+ // `@zap-proto/web/server` is the complete Node surface. Re-export the
33
+ // server-side transport factory and the auth slot so consumers import the whole
34
+ // server API from one sub-path (the root entry is browser-safe and omits these).
35
+ export { nodeWsTransport } from "./transport.js";
36
+ export type { MintCap } from "./auth.js";
37
+
32
38
  /**
33
39
  * rootCap produces the per-connection dispatch root for a minted ctx.
34
40
  *