feat(rpc)!: support Standard Schema for RPC definitions with runtime validation - #157
Open
antfubot wants to merge 2 commits into
Open
feat(rpc)!: support Standard Schema for RPC definitions with runtime validation#157antfubot wants to merge 2 commits into
antfubot wants to merge 2 commits into
Conversation
…te at runtime Widen `args`/`returns` from valibot's `GenericSchema` to the `StandardSchemaV1` interface so valibot, zod, arktype, and any other Standard Schema validator work interchangeably, and infer handler types from the schema's Standard Schema input types. Every invocation path (local, over-the-wire, agent/MCP) now validates declared `args`/`returns` at the boundary via `getRpcHandler`, throwing coded diagnostics DF0043 / DF0044 on failure. Validation is guard-only: payloads are never rewritten, so schemas describing a subset of an object don't strip the sender's extra fields. The MCP JSON-schema surface keeps valibot's converter for precise schemas and degrades non-valibot vendors to a permissive object schema.
✅ Deploy Preview for devfra ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
What
RPC function definitions now accept any Standard Schema validator for their
argsandreturns— valibot, zod, arktype, and others work interchangeably — instead of being locked to valibot'sGenericSchema. Declared schemas are also enforced at runtime on every call.Why
Handlers previously had to author
args/returnsin valibot, and those schemas only fed type inference and MCP JSON-schema generation — nothing validated the actual payloads at call time. Standing on the Standard Schema interface lets tools bring whichever validator they already use, and makes the declared schemas a real boundary guarantee.How
RpcArgsSchema/RpcReturnSchemaand the arg/return type inference are keyed offStandardSchemaV1(new@standard-schema/specdependency) rather than valibot.getRpcHandler— wraps the resolved handler so local, over-the-wire, and agent/MCP invocations all validate declaredargs/returnsat the boundary. Failures raise coded diagnostics DF0043 (argument) / DF0044 (return value).BREAKING CHANGE
Declared
args/returnsschemas are now enforced at runtime. Previously they were inert (type inference + JSON-schema only), so a call whose real payload didn't match its declared schema still ran. Such calls now throwDF0043(invalid argument) /DF0044(invalid return value). Guard-only validation means extra object fields are still allowed, but a schema stricter than reality will start rejecting calls that used to pass. Audit RPCs whose declared schemas may be narrower than what they actually accept/return.Docs:
docs/guide/rpc.md(with a runtime-enforcement warning), plus newdocs/errors/DF0043.mdandDF0044.md.This PR was created with the help of an agent.