feat(routing): accept zod 4 route schemas (4.x) - #69
Conversation
4.x port of the same change on master (PR #68). Route `paramsSchema`/`querySchema` were typed as zod 3's `Z.ZodObject<any>`, which zod 4 schemas do not satisfy. Routing only ever calls `parse` and `merge` on a schema and reads its `_output` marker, and both zod majors expose all three, so the schema type is now the structural `RouteSchema` and the `zod` import is gone from the routing source. The peer range widens to `^3.x || ^4.x`; nothing changes for zod 3 callers. The 4.x line needs this as well as 5.x because a consumer that hosts v4 machines under a v5 routing root (kawaka's `hostV4Machine`) hands v5 routes to v4 APIs such as `useIsRouteActive`; that assignability only held while both lines spelled the schema type identically. `createRoute.zod4.spec.ts` drives `simpleRoute` with `zod/v4` schemas so the compatibility is tested rather than assumed; the dev `zod` moves to 3.25.76 to make that subpath available in-repo. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xa9BAPFheAQLJwta16v67z
`test-examples` runs `tsc --noEmit` over src and examples, which now includes `createRoute.zod4.spec.ts`. That spec imports `zod/v4`, whose declarations use `const` type parameters (TypeScript 5.0) and `NoInfer` (5.4), so the 4.x line's TypeScript ^4.7 fails to parse them and 5.0 still cannot check them. master already typechecks with TypeScript 5.0.2 and `skipLibCheck: true`; this brings 4.x to the same configuration. Only in-repo typechecking changes; the published declarations no longer mention zod at all. lint, test, test-examples, build and api-extractor all pass locally with this. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xa9BAPFheAQLJwta16v67z
|
CI failed at a89f290 brings 4.x to master's configuration (TypeScript 5.0.2 + The alternative was excluding the spec from the root tsconfig and leaving TS 4.x alone; say if you would rather do that. |
|
🎉 This PR is included in version 4.12.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Why
4.x port of #68 (
master). koordinates hosts its remaining v4 machines under a v5 routing root and hands v5 routes to v4 APIs (useIsRouteActiveinv4RoutingShim.spec, a v4 consumer in browse-data's standalone dataset sheet spec). That cross-line assignability only holds while both lines spellAnyRoute.paramsSchemaidentically, so once 5.x moves to the structuralRouteSchema, 4.x has to as well or those call sites fail withRouteSchema<any>is missing_cached, _getCached, _parse, shape, and 49 more.What
Same change as #68, applied to
4.x:createRoutedrops itszodimport; schemas are typed against the structuralRouteSchema(_output,parse,merge), exported from the root,routingandcreateRoutebarrels.peerDependencies.zodwidens from^3.xto^3.x || ^4.x.createRoute.zod4.spec.tsdrivessimpleRoutewithzod/v4schemas; devzodmoves to 3.25.76 so that subpath exists in-repo.xstate-tree.api.mdregenerated.Verification
npm run lint -- --fix: 0 errors.npm test: 120/120.npm run buildandnpm run api-extractor -- --local: clean.lib/xstate-tree.d.tsover the installed 4.11.1 alongside feat(routing): accept zod 4 route schemas #68's over 5.6.0:@kx/xstatetypechecks clean again.🤖 Generated with Claude Code
https://claude.ai/code/session_01Xa9BAPFheAQLJwta16v67z