feat(zod,valibot,arktype): add option to cache generated JSON schemas - #1753
Merged
dinwwwh merged 1 commit intoJul 30, 2026
Merged
Conversation
Adds an opt-in `cache` option to ZodToJsonSchemaConverter, ValibotToJsonSchemaConverter, and ArkTypeToJsonSchemaConverter that memoizes conversion results in per-direction WeakMaps keyed by the schema instance, so repeated conversions of the same schema are free.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/bun
@orpc/client
@orpc/cloudflare
@orpc/contract
@orpc/experimental-effect
@orpc/evlog
@orpc/json-schema
@orpc/nest
@orpc/next
@orpc/openapi
@orpc/opentelemetry
@orpc/pinia-colada
@orpc/pino
@orpc/publisher
@orpc/ratelimit
@orpc/server
@orpc/shared
@orpc/swr
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/zod
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — a consistent, clean addition of an opt-in cache option to the three schema converters:
cacheoption onZodToJsonSchemaConverterOptions— constructor stripscachebefore forwarding params;convert()checks per-directionWeakMapbefore calling extractedconvertUncached().cacheoption onValibotToJsonSchemaConverterOptions— same pattern; constructor field renamedoptions→conversionConfig.cacheoption onArkTypeToJsonSchemaConverterOptions— same pattern.- Tests — verify reference-equality cache hits, direction independence, call-count on the underlying library function, and disabled passthrough across all three packages.
- Docs —
::: tipblocks with immutability warning.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
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.

Adds an opt-in
cacheoption toZodToJsonSchemaConverter,ValibotToJsonSchemaConverter, andArkTypeToJsonSchemaConverterthat memoizes conversion results in per-direction WeakMaps keyed by the schema instance. Converting the same schema repeatedly — e.g. regenerating an OpenAPI spec or sharing a converter across plugins — no longer re-runs the underlying JSON schema conversion.Performance
[jsonSchema, optional]tuple with no conversion work.inputandoutputdirections are cached independently, and WeakMap keys keep schemas garbage-collectable.Notes
cacheflag is stripped before options are forwarded to the underlyingtoJsonSchemaimplementations.Testing