Fix function-spec crash when using v.literal(BigInt) #297
+95
−4
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.
Problem
Running
npx convex function-speccrashes when a function usesv.literal(BigInt(1))in its validator:This happens because:
{"$integer": "base64"}function-specreturns validator metadata as a query result, it goes throughjsonToConvexjsonToConvexrejects any object fields starting with$(reserved for Convex internal formats)Solution
Changed BigInt literal serialization in validator metadata to use a new format:
{"__convexBigIntLiteral": "1"}{"$integer": "AQAAAAAAAAA="}This separates validator metadata serialization from Convex value serialization.
Changes
Rust (
crates/common/src/schemas/json.rs)LiteralValidator::Int64serialization to use__convexBigIntLiteral$integerformatTypeScript (
npm-packages/convex/src/values/validators.ts)VLiteral.jsongetter to use new format for BigInt valuesconvexToJsonfor BigInt to prevent$integerformatTests
Testing
All Rust tests passing (5/5 in
schemas::json::tests)All TypeScript tests passing (27/27 in
schema.test.ts)Package builds successfully
Manual verification: new format works with
jsonToConvexBackward Compatibility
The old
$integerformat is still accepted when deserializing, so existing validator metadata will continue to work.Fixes #212
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.