Skip to content

Decode/Encode to the next level#152

Open
DZakh wants to merge 284 commits intomainfrom
dz/decode-encode
Open

Decode/Encode to the next level#152
DZakh wants to merge 284 commits intomainfrom
dz/decode-encode

Conversation

@DZakh
Copy link
Copy Markdown
Owner

@DZakh DZakh commented Aug 29, 2025

No description provided.

claude and others added 30 commits April 12, 2026 16:07
S.refine on object schemas is not generating the refine check in
compiled output. Reverted test expectations to the old (correct)
values so they fail, exposing the regression for future fix.

https://claude.ai/code/session_01Q4Pz7uS2GHmfCAwp3NaPcQ
Refactor refinements to use structured checks instead of code strings
Use `stringify` for the error message (consistent with parse errors) so
users see e.g. `Expected number, received "abc"` instead of the less
helpful `Expected number, received string`. Also reject NaN values which
are typeof "number" but invalid for min/max/length constraints.

https://claude.ai/code/session_01GJSLrSZwrGrFuNmncENGde
Error messages now include the calling function name and the actual
received value (via stringify) instead of just the type name. Also
rejects NaN which passes typeof "number" but is invalid for constraints.

Before: `Expected number, received string`
After:  `[S.min] Expected number, received "abc"`

https://claude.ai/code/session_01GJSLrSZwrGrFuNmncENGde
Instead of special-casing bigint→string in jsonDecoder, attempt to decode
any unhandled type to string. If the decode succeeds (e.g., Date→string
via toISOString, bigint→string), continue with the string result. If it
fails, throw "Can't decode X to JSON".

Also changes "Unsupported conversion" wording to "Unsupported decode" in
error messages.

https://claude.ai/code/session_019k2RRqbaYzaLzjH3m9BiRE
…bfZHj

Improve assertNumber validation with NaN checks and better error messages
Copy the original expected as .to on the new string expected so that
downstream transformations (e.g., string→jsonString) are not lost.

https://claude.ai/code/session_019k2RRqbaYzaLzjH3m9BiRE
Replace the metadata-based Refinement modules (Int.Refinement, Float.Refinement,
Array.Refinement) with direct JSON Schema-compatible fields on the schema type:
- String: minLength, maxLength, pattern
- Number: minimum, maximum
- Array: minItems, maxItems

Error messages are stored in an `errorMessages` dict keyed by field name.

String.Refinement is kept for email/uuid/cuid/url/pattern (to be migrated later).

https://claude.ai/code/session_01RHggBPobH61hxR33XcD8nz
…ttern field

- errorMessages is now on the base Schema type in S.d.ts (not per-variant)
- Remove empty Int, Float, Array modules from .res and .resi files
- Use `pattern` directly as the internal field name (no @as alias needed)

https://claude.ai/code/session_01RHggBPobH61hxR33XcD8nz
- Rename variant UnsupportedConversion → UnsupportedDecode
- Rename @as tag "unsupported_conversion" → "unsupported_decode"
- Rename helper function unsupportedConversion → unsupportedDecode
- Unify error message to "Can't decode X to Y" everywhere
- Update S.d.ts, S.resi, Sury.resi, and all test expectations

https://claude.ai/code/session_019k2RRqbaYzaLzjH3m9BiRE
Error now reads: "Can't decode X to Y. Use S.to to transform it to a
compatible type" — guiding users toward the fix.

Also simplifies jsonDecoder catch to reuse B.unsupportedDecode instead
of manually constructing the error.

https://claude.ai/code/session_019k2RRqbaYzaLzjH3m9BiRE
… patterns

- setErrorMessage now takes ~mut as labeled argument
- Int32 outputs minimum/maximum (-2147483648/2147483647) in toJSONSchema
- Tests use plain pattern match (no ?Some) and assert full errorMessages dict

https://claude.ai/code/session_01RHggBPobH61hxR33XcD8nz
Copy the dict before mutating when one already exists from the
shallow-copied schema. Added regression test that chains S.min then
S.max and verifies the original schema is not mutated.

https://claude.ai/code/session_01RHggBPobH61hxR33XcD8nz
…site

Copies the dict once per internalRefine call, then callers set keys
directly. Avoids redundant copies when setting multiple keys (e.g.
stringLength, arrayLength).

https://claude.ai/code/session_01RHggBPobH61hxR33XcD8nz
…ment grammar

- Add toString() snapshot test for S.decoder(dateSchema, S.json)
- Add S.decoder(dateSchema, S.jsonString) test for full pipeline
- Fix "value decode" → "value decoding" in comments

https://claude.ai/code/session_019k2RRqbaYzaLzjH3m9BiRE
…saging

Rename unsupported_conversion to unsupported_decode with improved messaging
…tadata

Refactor constraint validation to use schema properties instead of metadata
Add instance type handling in jsonEncoder to decode JSON strings to Date
objects by routing through the string→Date decoder. This enables
S.decoder(S.json, dateSchema) and S.decoder(S.jsonString, dateSchema)
to automatically convert ISO date strings in JSON to Date instances.

https://claude.ai/code/session_016jDaH24p3QQNygeA7yWoY2
Instead of only trying the string decode route for instance types,
apply it to any target type except union and ref (which have their
own downstream decoders that handle JSON values correctly).

https://claude.ai/code/session_016jDaH24p3QQNygeA7yWoY2
The bigint branch was identical to the general else fallback (both
route through string→target). Now bigint, instance, and any other
non-union/ref type all use the same string decode path.

https://claude.ai/code/session_016jDaH24p3QQNygeA7yWoY2
Fix JSON encoding/decoding for Date types and refactor shaped serializer
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.

2 participants