Migrate from @sinclair/typebox 0.34.x to typebox 1.0#364
Migrate from @sinclair/typebox 0.34.x to typebox 1.0#364masad-frost wants to merge 3 commits intomainfrom
Conversation
Monkatraz
left a comment
There was a problem hiding this comment.
looks quite reasonable, surprised we didn't have to do more honestly
| payload: { | ||
| code: 'SOME_ERROR', | ||
| message: 'something went wrong', | ||
| extras: { detail: 'extra info' }, |
There was a problem hiding this comment.
did anyone accidentally shove entire error class instances in these things anywhere? wonder what 1. typebox does with that and 2. if it did "handle" it before, if it still does.
There was a problem hiding this comment.
extras is just a generic Record so typebox didn't do anything with them, the codec probably resulted in Error objects being {} since the properties are usually non-enumerable.
| }); | ||
| }); | ||
|
|
||
| describe('composite types', () => { |
There was a problem hiding this comment.
we do use some Type.Intersect and other more esoteric types, might be worth checking those.
| @@ -1,4 +1,4 @@ | |||
| import { TNever, TObject, Type } from '@sinclair/typebox'; | |||
| import { TNever, TObject, Type } from 'typebox'; | |||
There was a problem hiding this comment.
oh wow, he actually got the typebox package name?
| ...options, | ||
| }), | ||
| (value): value is Uint8Array => { | ||
| if (!(value instanceof Uint8Array)) return false; |
There was a problem hiding this comment.
sanity check: no insane bullshit with node Buffer right?
There was a problem hiding this comment.
Whatever bullshit that may have been, it's preserved https://github.com/sinclairzx81/typebox/blob/0.34.41/src/value/guard/guard.ts#L101-L104
customSchemas/index.ts
Outdated
| if ( | ||
| typeof options.minByteLength === 'number' && | ||
| value.byteLength < options.minByteLength | ||
| ) | ||
| return false; | ||
| if ( | ||
| typeof options.maxByteLength === 'number' && | ||
| value.byteLength > options.maxByteLength | ||
| ) | ||
| return false; |
customSchemas/index.ts
Outdated
| if ( | ||
| typeof options.minimumTimestamp === 'number' && | ||
| value.getTime() < options.minimumTimestamp | ||
| ) | ||
| return false; | ||
| if ( | ||
| typeof options.maximumTimestamp === 'number' && | ||
| value.getTime() > options.maximumTimestamp | ||
| ) | ||
| return false; |
There was a problem hiding this comment.
Lol, I'll throw in some lint rules
| const RecursivePayload = Type.Cyclic( | ||
| { | ||
| RecursivePayload: Type.Object({ | ||
| n: Type.Number(), | ||
| next: Type.Optional(Type.Ref('RecursivePayload')), | ||
| }), | ||
| }, | ||
| 'RecursivePayload', | ||
| ); |
There was a problem hiding this comment.
it bothers me that he made the defs go first
| // In TypeBox 1.0, TSchema is {} so Static<TSchema> doesn't resolve the same way | ||
| // as in 0.34. Using `any` for schema type params in the implementation signature | ||
| // is safe because the public overload signatures still enforce correct types for | ||
| // all callers. The implementation body doesn't inspect handler types at runtime. | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| handler: RpcProcedure<any, any, any, any, any, any>['handler']; |
There was a problem hiding this comment.
yeah this makes sense, it's annoying how you can't use describe unknown extends ... or infer or something.
There was a problem hiding this comment.
Yeah was painful for me and my agent and it went in circles, until I realized who cares lol.
| * Flattens a union-nested error schema into a single level in order to | ||
| * satisfy ProcedureErrorSchemaType which accepts only a single level of union | ||
| * so that we can enforce a schema validation on the error schema. |
There was a problem hiding this comment.
yeah the original comment was quite spiteful wasn't it
| type TLiteralString = TLiteral<string>; | ||
|
|
||
| type TEnumString = TEnum<Record<string, string>>; | ||
| type TEnumString = TEnum<Array<string>>; |
There was a problem hiding this comment.
huh. enums are no longer TypeScript shaped, I guess? that might be a really painful migration...
There was a problem hiding this comment.
Yep, I think it's for the better, they're JSON Schema shaped.
Monkatraz
left a comment
There was a problem hiding this comment.
cache change looks fine
Why
TypeBox 1 has been out for some time now, we should start using it so that we're not left in the dust!
What changed
Do necessary work per
https://github.com/sinclairzx81/typebox/blob/4f0832d2f0e4b94c84d9f94c1318a5fc9d5015f4/changelog/1.0.0-migration.md
https://github.com/sinclairzx81/typebox/blob/4f0832d2f0e4b94c84d9f94c1318a5fc9d5015f4/changelog/1.1.0.md
The most notable change is the we now export our own schemas for UInt8Array and Date to preserve backwards compatibility from
@replit/river/customSchemas. Longer term, we may want to evaluate more JSON Schema–native representations, as long as they do not undermine the efficiency of our MessagePack encoding.Validation error messages changed
Versioning
No breaking schema-level or wire-format changes introduced at all, validated through a new tests
Consumers will have to now use typebox >=1.0.0 and use the exported
UInt8ArrayTypeandDateType