Skip to content

Conversation

@braden-w
Copy link
Collaborator

Adds a new wellcrafted/standard-schema module 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 union

The wrappers preserve schema capabilities: if the input schema has validate, the output has validate; if it has jsonSchema, the output has jsonSchema.

Implementation Details

  • Types copied from Standard Schema spec (official recommendation)
  • Type-safe failure constants with StandardSchemaV1.FailureResult
  • 35 tests covering Zod, Valibot, and ArkType integration

…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;
@braden-w braden-w merged commit ea4f517 into main Dec 31, 2025
1 of 2 checks passed
@braden-w braden-w deleted the feat/standard-schema-result-wrappers branch December 31, 2025 23:03
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