Skip to content

Switch to Typebox 1.x #58

Description

@jmjf

@sinclair/typebox@1.x introduces changes that break at least oneOf and possibly other outputs.

Evaluation

Migration guide

  • ESM - already done that
  • Kind, Hint, ReadonlyKind, OptionalKind replaced - affects oneOf
  • Type.Date and Type.Uint8Array removed - not used (dates are based on Type.String())
  • Type.Recursive replaced - not used
  • Type.Regex removed - check b/c I'm not sure
  • Type.Composite replaced - used in experiment
  • Type.Transform renamed - used in experiment
  • Type.Const removed in favor of Script - not used
  • Type.Pick and Type.Omit changed - not used
  • TypeCompiler changes - not used
  • Referential type support - seems to be TypeCompiler and Transform related
  • FormatRegistry moved - not used
  • TypeRegistry removed in favor of Type.Base - affects oneOf
  • TypeGuard removed - not used
  • Value.Errors changes from iterator to array - not used
  • Value.Cast renamed Repair - not used
  • SetErrorFunction removed - not used
  • CustomError handling - not used

To do

  • oneOf needs changes for TypeRegistry and Kind changes in TypeBox 1.x
  • Check how/if regex matters. Generally, I recommend avoiding OpenAPI regex formats in favor of known formats, which are more readable. API specs, like the museum spec, that use a pattern instead of format: time are painful to read in comparison.
  • Update experiments that use Composite and Transform -- not critical, but might as well see if I can get them working.
    • Transform seems to be a simple rename to Type.Codec
    • Composite is replaced by Type.Interface and Type.Evaluate.

Notes

For use cases I'm most concerned with, I'm using AJV for validation, so code that uses output from to4ft doesn't care about changes to TypeBox's validator, validator error handling, validator formats. If you're using any of those TypeBox features, you need to update to TypeBox 1.x as part of moving to to4ft@2.x

to4ft doesn't use Type.Date because it works with the application/json media type where date and time data is a string and Fastify's JSON serializer. See #20, #21, #22, and #25 for previous work that ended with using Type.Unsafe<Date>() that supports passing a Date type to the serializer so Fastify will format it correctly while representing it as a string in input parameters. The application/json condition might change if #34 happens.

Items for later

  • Revisit the concept of Type.Date and decide if it makes sense or not given our use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions