vercel-labs / vercel-labs/json-render
DynamicValueSchema is narrower than resolveActionParam's actual contract
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 16.8k
- Forks
- 901
- Avg merge
- 3h 14m
- Merged PRs (30d)
- 4
Description
Summary
DynamicValueSchema rejects shapes that resolveActionParam resolves correctly at runtime. This causes false positives for tools that schema-validate emitted specs against ActionBindingSchema.
Repro
import {
ActionBindingSchema,
DynamicValueSchema,
resolveActionParam,
} from "@json-render/core"; // 0.19.0
const ctx = {
stateModel: { form: { text: "hi" } },
repeatBasePath: "/todos/2",
repeatIndex: 2,
};
// Runtime accepts each shape:
resolveActionParam({ $index: true }, ctx); // → 2
resolveActionParam(["a", "b"], ctx); // → ["a", "b"]
resolveActionParam({ id: { $state: "/form/text" } }, ctx); // → { id: "hi" }
// Schema rejects each:
DynamicValueSchema.safeParse({ $index: true }).success; // false
DynamicValueSchema.safeParse(["a", "b"]).success; // false
DynamicValueSchema.safeParse({ id: { $state: "/x" } }).success; // false
// Same rejection cascades into ActionBindingSchema:
ActionBindingSchema.safeParse({
action: "setState",
params: { value: ["a", "b"] },
}).success; // false
Why this matters
resolveActionParam is documented to:
- Resolve
{ $item: "field" }to an absolute state path. - Resolve
{ $index: true }to a numeric index. - Delegate everything else to
resolvePropValue, which recurses into objects/arrays and handles the fullPropExpressiongrammar.
But DynamicValueSchema is union(string, number, boolean, null, { $state: string }) — anything else fails validation even though the runtime resolves it correctly.
Concrete impact: external tooling that validates an emitted Spec against ActionBindingSchema gets false positives on legitimate emissions like params: { value: ["a", "b"] } (literal array) or params: { value: { id: { \$state: "/x" } } } (object with state refs).
Context
Surfaced while building a parity test suite for a DSL → json-render compiler against @json-render/core@0.19.0. Happy to PR if alignment on the approach is reached.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating DynamicValueSchema and compare its accepted shapes with resolveActionParam and resolvePropValue. Use the reproduction examples as regression cases and verify that ActionBindingSchema accepts valid arrays, indexed values, and nested state references.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100