Skip to content

Conversation

@alexandercerutti
Copy link
Owner

@alexandercerutti alexandercerutti commented Nov 11, 2025

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

  • I've run tests (through npm test) and they passed
  • I generated a working Apple Wallet Pass after the change
  • Provided examples keep working after the change
  • This improvement is or might be a breaking change

Relevant information

…ields to allow both PassFieldContentWithRow and PassFieldContent
Copy link
Contributor

Copilot AI left a 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 of z.enum()
  • .check() method (doesn't exist in Zod)
  • z.url({ protocol: /.../ }) with invalid syntax
  • z.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.

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