Skip to content

feat(js): add wRPC codec package and use it in the web example#1345

Open
rvolosatovs wants to merge 2 commits into
mainfrom
feat/js
Open

feat(js): add wRPC codec package and use it in the web example#1345
rvolosatovs wants to merge 2 commits into
mainfrom
feat/js

Conversation

@rvolosatovs

Copy link
Copy Markdown
Member

Add js/ (@bytecodealliance/wrpc), a dependency-free, transport-agnostic JavaScript codec for the wRPC wire format, mirroring wrpc-transport's value.rs and default framing:

  • t/types build the structural WIT type tree;
  • value encodes/decodes component-model values (a jco-compatible mapping);
  • wit parses inlined WIT text back into the type tree;
  • frame builds an invocation's request bytes and decodes its results.

The ESM source runs directly in the browser and is publishable to npm; it ships a hand-written .d.ts, JSDoc, node --test round-trip tests and a tsc typecheck.

Use the codec in the wasi:keyvalue web example: the UI imports it from /wrpc (served via ServeDir) and drops the hand-rolled byte encoding, removing the 127-byte request/response size limits. The example keeps its own WebTransport stream handling.

Assisted-by: claude:claude-opus-4-8

Add `js/` (`@bytecodealliance/wrpc`), a dependency-free, transport-agnostic
JavaScript codec for the wRPC wire format, mirroring `wrpc-transport`'s
`value.rs` and default framing:

- `t`/`types` build the structural WIT type tree;
- `value` encodes/decodes component-model values (a jco-compatible mapping);
- `wit` parses inlined WIT text back into the type tree;
- `frame` builds an invocation's request bytes and decodes its results.

The ESM source runs directly in the browser and is publishable to npm; it
ships a hand-written `.d.ts`, JSDoc, `node --test` round-trip tests and a
`tsc` typecheck.

Use the codec in the `wasi:keyvalue` web example: the UI imports it from
`/wrpc` (served via `ServeDir`) and drops the hand-rolled byte encoding,
removing the 127-byte request/response size limits. The example keeps its
own WebTransport stream handling.

Assisted-by: claude:claude-opus-4-8
`decodeResults` treated an empty response identically whether or not
results were expected, returning `[]` in both cases. When a peer closes
the wRPC stream without writing a result frame — e.g. the web example's
proxy backend is unreachable and the invocation fails server-side — the
caller's `const [res] = ...` destructure yielded `undefined`, surfacing
as a cryptic "can't access property tag, res is undefined" in the UI.

Throw a descriptive error in that case instead, while still returning
`[]` for functions that legitimately have no results.

Assisted-by: claude:claude-opus-4-8
@rvolosatovs rvolosatovs marked this pull request as ready for review June 22, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant