mirror of
https://github.com/zap-proto/web.git
synced 2026-10-30 15:03:09 +00:00
Browser-frontend RPC over ZAP: a drop-in tRPC replacement speaking native ZAP
envelopes over WebSocket binary frames, layered on @hanzo/zap. No JSON, no
Cap'n Proto, no bearer-JWT plumbing.
Surfaces:
- transport.ts: isomorphic WsTransport (node `ws` + browser native WebSocket);
one ZAP envelope per WS binary message; text frames close with code 1003.
- conn.ts: transport-agnostic request/response correlation (the ZapClient
correlation logic generalised over WS, both directions).
- server.ts: serve(httpServer, opts) attaches a ws.Server to http.Server's
upgrade event for opts.path; mintCap(req) runs at the boundary (null → 401);
rootCap(ctx) yields the per-conn dispatch handler.
- client.ts: connect(url, opts) opens the WS, awaits open, returns
{ bootstrap, close }; bearer rides an Authorization header on header-capable
impls (node ws), query-param fallback for the browser native WebSocket.
- auth.ts: MintCap<Ctx> SLOT — apps supply (req) => Promise<Ctx|null>. The
canonical ML-DSA-65 signed Capability mint (zap-spec/capabilities.zap) lands
in a later version; documented honestly in README.
- errors.ts: re-exports ZapParseError; adds WebRpcError for transport failures.
Tests (test/echo.test.ts, 3/3 passing): real end-to-end ZAP roundtrip over a
live WebSocket (no mocks) using an `echo.zap` schema codegen'd via
`zapgen --target=ts`; 401 rejection when mintCap returns null; two sequential
calls sharing one conn.
Reality-vs-spec notes (the task spec was written against a fictional Cap'n
Proto `@zap-proto/zap` v1.1.0):
- The real foundation is `@hanzo/zap` v0.1.0 — a zero-copy ZAP wire format,
explicitly NOT Cap'n Proto, with no `src/rpc/` Transport/Conn/Server/Client
/bootstrap-capability API. Built honestly on what exists (buildRequest/
parseRequest/buildResponse/parseResponse + method ordinals from .zap structs).
- Package named `@hanzo/zap-web` (not `@zap-proto/web`) to depend cleanly on
the real sibling `@hanzo/zap`. GitHub repo is zap-proto/web as requested.
- `@hanzo/zap` is not on npm yet, so the dep is `link:../zap-ts` and vitest
aliases `@hanzo/zap` → ../zap-ts/src. TODO: flip to npm semver once published.
Pre-1.0 by policy: NOT tagged, NOT published, no Docker.
14 lines
246 B
JSON
14 lines
246 B
JSON
{
|
|
"extends": "./tsconfig.json",
|
|
"compilerOptions": {
|
|
"noEmit": false,
|
|
"outDir": "./dist",
|
|
"rootDir": "./src",
|
|
"declaration": true,
|
|
"declarationMap": true,
|
|
"sourceMap": true,
|
|
"paths": {}
|
|
},
|
|
"include": ["src"]
|
|
}
|