-
-
Notifications
You must be signed in to change notification settings - Fork 132
Migration from Zod to Joi #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ields to allow both PassFieldContentWithRow and PassFieldContent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR migrates the schema validation library from Joi to Zod 4, aiming to enable automatic type inference and reduce manual TypeScript declarations. The migration significantly reduces package size from 436 kB to 128.6 kB.
Key changes:
- Replaced all Joi schemas with Zod equivalents across the codebase
- Enabled strict mode in TypeScript configuration
- Updated type definitions to use
z.infer<>for automatic type inference - Modified validation helper functions to work with Zod's API
Reviewed Changes
Copilot reviewed 19 out of 21 changed files in this pull request and generated 25 comments.
Show a summary per file
| File | Description |
|---|---|
| src/schemas/index.ts | Core schema definitions migrated from Joi to Zod, including PassProps, OverridablePassProps, and related schemas |
| src/schemas/Semantics.ts | Semantic tags schema converted to Zod with all field definitions |
| src/schemas/PassFields.ts | Pass fields schema migrated with TransitType and field structure definitions |
| src/schemas/PassFieldContent.ts | Field content validation migrated to Zod with data detector and alignment types |
| src/schemas/UpcomingPassInformation.ts | iOS 26+ upcoming pass information schema converted to Zod |
| src/schemas/SemanticTagType.ts | Semantic tag type definitions migrated (CurrencyAmount, Location, etc.) |
| src/schemas/Personalize.ts | Personalization schema converted to Zod |
| src/schemas/NFC.ts | NFC schema migrated with message length validation |
| src/schemas/Location.ts | Location schema simplified with Zod |
| src/schemas/Beacon.ts | Beacon schema converted with UUID and number range validation |
| src/schemas/Barcode.ts | Barcode format and message validation migrated |
| src/schemas/Certificates.ts | Certificate schema updated to use Zod's instanceof check |
| src/PKPass.ts | Updated to use Zod validation methods and adjusted type assertions |
| src/FieldsArray.ts | Modified to work with Zod schemas and improved type safety |
| src/utils.ts | Return type of processDate changed from string | undefined to string |
| tsconfig.json | Added strict mode |
| package.json | Added zod@4.1.12 dependency (Joi remains, should likely be removed) |
Critical Issues Found: The migration contains numerous incorrect Zod API usages including:
z.iso.datetime()(non-existent method)z.literal()with arrays instead ofz.enum().check()method (doesn't exist in Zod)z.url({ protocol: /.../ })with invalid syntaxz.json(),z.email(),z.maxLength()used as standalone schemas
These issues will cause runtime failures and the code will not function correctly with the current implementation.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ntics structure to not have to put optional to all the properties
Description
This PR handles the migration from Joi, from which this repository is stuck due to an issue with Typescript, to Zod 4 - which I was waiting due to a missing thing in the previous versions.
This helps by removing manual Typescript declarations, which led to #256, for automatic inference.
I'm not sure this is a breaking change yet. The project exports types of schemas, so it will likely be a breaking, even if they shouldn't be a problem.
The only relevant statistic I can see is that the package tar.gz, sadly, passes from 436 kB to 1.5 Mb (but probably there are just a lot more of comments and repeated definitions, due to Zod).
After the last few checks and review from Copilot, I'll leave this here for a while, just to give it time to receive some feedbacks.
Check relevant checkboxes
npm test) and they passedRelevant information