Skip to content

feat: serialize URL objects over RPC - #224

Open
dimitropoulos wants to merge 4 commits into
mainfrom
feat/serialize-url-headers
Open

feat: serialize URL objects over RPC#224
dimitropoulos wants to merge 4 commits into
mainfrom
feat/serialize-url-headers

Conversation

@dimitropoulos

Copy link
Copy Markdown
Collaborator

Adds by-value serialization for URL, extracted from the URL portion of #99. Headers (the other type in #99) already landed on main.

Credit to @lmaccherone for the original work in #99.

Adds by-value serialization for URL, extracted from the URL portion of #99.
(Headers, the other type in that PR, already landed on main separately.)

Co-authored-by: Larry Maccherone <927864+lmaccherone@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 27, 2026 01:23
@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dbae7db

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
capnweb Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/capnweb@224

commit: dbae7db

Co-authored-by: Larry Maccherone <927864+lmaccherone@users.noreply.github.com>

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm Bonk, and I've done a quick review of your PR.

Summary: adds by-value serialization for URL via a new ["url", href] wire type, wired through typeForRpc/RpcPayload in core.ts and the devaluator/evaluator in serialize.ts, with a round-trip test.

The implementation itself looks correct and consistent with the existing patterns (exact-prototype match, structuredClonable short-circuit mirrors Date, evaluator validates value.length === 2 && typeof value[1] === 'string' and otherwise falls through to the unknown special value error). Cross-runtime URL is a global everywhere, so the URL.prototype reference is safe.

One actionable item:

  1. (medium) New wire type not documented in protocol.md. protocol.md documents every serialization type (["headers", ...], ["request", ...], ["response", ...], etc.), but this PR introduces ["url", href] without adding it there. Per the repo's protocol-compatibility policy, intentional wire-protocol additions must be reflected in protocol.md. Suggested text to add near the other Fetch/Date types (e.g. just before the ["headers", pairs] entry around line 201):

    `["url", href]`
    
    A JavaScript `URL` value. `href` is the string form of the URL (i.e. `url.href`), suitable to pass to the `URL` constructor. For example: `["url", "https://example.com/path?q=1"]`.
    

(protocol.md isn't part of this diff, so I couldn't attach this as an inline suggestion.)

@ask-bonk

ask-bonk Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review posted to PR #224.

Summary of my review: The URL serialization implementation is correct and consistent with existing patterns (exact-prototype matching, structuredClonable short-circuit mirroring Date, and strict evaluator validation that falls through to the standard error path on malformed input). No security, capability-safety, or cross-runtime concerns.

One actionable item flagged: the new ["url", href] wire type is not documented in protocol.md, which documents every other serialization type. I provided the suggested doc text (posted as a top-level comment since protocol.md isn't in the diff and an inline suggestion would have 422'd).

github run

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for passing URL objects by value over Cap’n Web RPC, aligning the supported serialization types with the previously proposed work in #99.

Changes:

  • Adds URL detection to RPC type classification and payload handling.
  • Implements URL wire format encoding/decoding as ["url", url.href].
  • Updates documentation, tests, and versioning (changeset) to reflect new support.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/serialize.ts Adds URL tuple encoding in Devaluator and decoding in Evaluator.
src/core.ts Extends TypeForRpc and related switch statements to include "url".
README.md Documents URL as a supported RPC type.
.changeset/serialize-url.md Declares a minor release for URL serialization support.
tests/index.test.ts Adds a URL round-trip serialization/deserialization test case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/serialize.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The initial commit only wired URL into the runtime serializer. Also add it
to the BaseType union and give capnweb-validate full URL support (introspector
kind + mapping, emitter, and runtime brand), matching how RegExp/Headers/etc.
are handled.

Co-authored-by: Larry Maccherone <927864+lmaccherone@users.noreply.github.com>
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.

3 participants