Conversation
…ant libraries
Add OkSchema, ErrSchema, and ResultSchema functions that wrap any Standard
Schema compliant library (Zod, Valibot, ArkType, etc.) with wellcrafted's
Result pattern ({ data: T, error: null } | { data: null, error: E }).
- Library-agnostic: works with any StandardSchemaV1/StandardJSONSchemaV1
- Capability-preserving: output includes validate/jsonSchema only if input has them
- Async-aware: preserves Promise returns from inner schemas
- Path prefixing: inner validation errors prefixed with 'data' or 'error'
Replace mock schema implementations with actual Standard Schema compliant libraries for more realistic and comprehensive testing. Tests now cover: - All three major libraries (Zod, Valibot, ArkType) for each wrapper - Complex nested objects and validation error path propagation - Mixed library usage (e.g., Zod data schema + Valibot error schema) - Edge cases like null values, empty objects, deeply nested errors
…ilure results
Call sites simplified from:
return { issues: [ISSUES.EXPECTED_OBJECT] };
To:
return FAILURES.EXPECTED_OBJECT;
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 a new
wellcrafted/standard-schemamodule that wraps Standard Schema v1 compliant libraries (Zod, Valibot, ArkType, etc.) into wellcrafted's Result pattern.New APIs
OkSchema(schema)- wraps any schema into{ data: T, error: null }ErrSchema(schema)- wraps any schema into{ data: null, error: E }ResultSchema(dataSchema, errorSchema)- creates discriminated unionThe wrappers preserve schema capabilities: if the input schema has
validate, the output hasvalidate; if it hasjsonSchema, the output hasjsonSchema.Implementation Details
StandardSchemaV1.FailureResult