Skip to content

Upgrade to TypeBox 1.x#374

Open
jackyzha0 wants to merge 8 commits intomainfrom
jacky/typebox-upgrade
Open

Upgrade to TypeBox 1.x#374
jackyzha0 wants to merge 8 commits intomainfrom
jacky/typebox-upgrade

Conversation

@jackyzha0
Copy link
Copy Markdown
Member

Summary

  • Migrate from @sinclair/typebox 0.34.x to typebox 1.x (package was renamed for the 1.0 release)
  • Address all breaking changes per the official migration guide
  • All 661 tests pass, TypeScript compiles clean, build succeeds

Breaking changes addressed

Change Migration
Kind symbol removed Type.IsUnion() / Type.IsNever() guards
Type.Uint8Array() removed Type.Base<Uint8Array> custom type
Type.Recursive() removed Type.Cyclic() + Type.Ref()
ValueErrorIterator removed Value.Errors() now returns TLocalizedValidationError[]
Error shape changed error.instancePath mapped to path for wire compat
TEnum type param changed TEnum<Record<string, string>>TEnum<string[]>

Test plan

  • tsc --noEmit passes
  • All 661 tests pass (1 skipped, same as before)
  • npm run build succeeds
  • Snapshot updated for changed Uint8Array serialization format
  • Invalid-request test assertions updated for Ajv-style error messages

🤖 Generated with Claude Code

Breaking dependency change: the npm package renamed from
@sinclair/typebox to typebox for the 1.0 release.

Key migration changes:
- Replace Kind symbol with Type.IsUnion()/Type.IsNever() guards
- Replace Type.Uint8Array() with Type.Base<Uint8Array> custom type
- Replace Type.Recursive() with Type.Cyclic() + Type.Ref()
- Replace ValueErrorIterator with TLocalizedValidationError[]
- Map error.instancePath → path for Ajv-aligned error format
- Update TEnum type parameter from Record to array form
- Widen procedure implementation handler types for overload compat
- Update test assertions for new validation error messages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jackyzha0 jackyzha0 requested a review from a team as a code owner May 8, 2026 00:35
@jackyzha0 jackyzha0 requested review from poorvapotnis and removed request for a team May 8, 2026 00:35
jackyzha0 and others added 3 commits May 7, 2026 18:38
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
TUint8Array now serializes with {"type": "Uint8Array"} instead of {}
by adding a `type` class field. Required-property validation errors
now expand to per-field paths via validationErrorToRiverErrors helper.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread protobuf/handshake.ts Outdated
* over River's existing handshake extension slot.
*/
const HandshakeBytesSchema = Type.Uint8Array();
class TUint8Array extends Type.Base<Uint8Array> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type.Base is already deprecated, should be using Type.Refine with Type.Unsafe

We should also probably expose this type for backwards compat https://github.com/replit/river/pull/364/changes#diff-9a6d6522160cca40477e1d56e4be812ef47d78f2f7ffefdfcfda52dede2fb880R29-R30

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added Date for complete backwards compatibility.

- Add customSchemas/ with Uint8ArrayType and DateType for backwards
  compat (matching #364 pattern)
- Replace deprecated Type.Base subclass with Type.Refine + Type.Unsafe
- Fix procedure handler impl types: Function → typed any overload
- Add ./customSchemas export to package.json and tsup entry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread router/errors.ts
Comment on lines +63 to +78
export function validationErrorToRiverErrors(
error: TLocalizedValidationError,
): Array<{ path: string; message: string }> {
if (error.keyword === 'required') {
const { requiredProperties } = (error as TRequiredError).params;

return requiredProperties.map((prop) => ({
path: `${error.instancePath}/${prop}`,
message: error.message,
});
}));
}

return result;
return [{ path: error.instancePath, message: error.message }];
}

export function castTypeboxValueErrors(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on adopting the new standard error format? https://github.com/replit/river/pull/364/changes#diff-6d1b576c8b42f3c38a9da7f660705f9720477793a6665ae30d0aeaf84a534b72R64-R69 I believe these errors match some sort of standard, forgot what it was but it's in the changelog.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@masad-frost masad-frost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

FYI only reason I didn't merge #364 is because I didn't have time to migrate river in our other repos, and didn't want to be in a situation where river changes have to continue to be backported to 0.x, so just beware!

Also, for our piece of mind, so that we can upgrade server independent of clients, might be worth throwing in a backwards compat test like the codec and serialization ones from the other PR, we'll delete it once we migrate.

gang gang
Image

jackyzha0 and others added 2 commits May 7, 2026 19:35
typebox 1.x is ESM-only, so CJS require() entries would fail at
runtime. Remove all "require" exports and drop cjs from tsup format.

Expand validationErrorToRiverErrors to reconstruct per-field paths
for additionalProperties, propertyNames, and unevaluatedProperties
errors (not just required).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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