feat(js): add wRPC codec package and use it in the web example#1345
Open
rvolosatovs wants to merge 2 commits into
Open
feat(js): add wRPC codec package and use it in the web example#1345rvolosatovs wants to merge 2 commits into
rvolosatovs wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
js/(@bytecodealliance/wrpc), a dependency-free, transport-agnostic JavaScript codec for the wRPC wire format, mirroringwrpc-transport'svalue.rsand default framing:t/typesbuild the structural WIT type tree;valueencodes/decodes component-model values (a jco-compatible mapping);witparses inlined WIT text back into the type tree;framebuilds 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 --testround-trip tests and atsctypecheck.Use the codec in the
wasi:keyvalueweb example: the UI imports it from/wrpc(served viaServeDir) 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