Skip to content

Extract the code lists into a @zod/codes package with a weekly refresh - #6602

Open
colinhacks wants to merge 6 commits into
mainfrom
iso-datasets
Open

colinhacks wants to merge 6 commits into
mainfrom
iso-datasets

Conversation

@colinhacks

@colinhacks colinhacks commented Sep 14, 2026 •

Copy link
Copy Markdown
Owner

Extracts the code lists behind zod's format validators into one workspace package and moves the refresh job with them. The single-list script and workflow that landed with z.currencyCode() in cc4cd4e are replaced by a generator feeding the package, and the regex is regenerated from it instead of from SIX directly.

@zod/codes has one entry point per list. Each exports codes as a readonly tuple, so the literal union falls out of the type, plus a records array with the source's fields; the root re-exports the three as namespaces.

  • @zod/codes/currencies: the active ISO 4217 codes from SIX Group's list one, with numeric code, name, minor units and fund flag, plus the withdrawn codes from list three.
  • @zod/codes/countries: the assigned ISO 3166-1 alpha-2 codes from the IANA language subtag registry, with alpha-3 and numeric codes from CLDR, and the ten exceptionally reserved codes exported separately.
  • @zod/codes/languages: the ISO 639-1 codes from the same registry, deprecated subtags excluded.

Zero dependencies, ESM plus CJS through zshy, starting at 1.0.0 so a minor flows through a caret range. One package rather than three: the country and language lists are near-static and the existing packages for them are correct, so they ride along as the data zod's own validators are generated from, while the currency list is the one that needs a maintained source, since every published ISO 4217 package is stale today.

The generator is a private packages/datasets package. Every run cross-checks each list against Debian's iso-codes, read and never copied since those files are LGPL, and reports any disagreement in the PR body rather than failing, because Debian lagged the ISO 4217 amendments by three years once. The weekly workflow generates in a job with no write token in reach, hands the patch to a second job that runs no installed code, and that job bumps a minor when a code set changes and a patch otherwise, refuses a removal that the source itself does not record as a withdrawal or a deprecation, runs the tests that read the data, and opens or updates one PR with the per-list diff; it leaves that PR alone only while it is one bot commit over the generated paths, and otherwise closes it and opens a fresh one. A source republished with the same data changes nothing, so a new publication date alone opens no PR. A second workflow, dispatched by a maintainer like the zod release, builds and tests in one job and stages the built package from another, which holds the OIDC token and installs only the npm CLI, through the same npm environment and the shared stage script; the maintainer then approves it with 2FA, so CI can fill the staged queue and nothing else.

The first version needs a maintainer: npm binds a trusted publisher to an existing package, so the package is created by a staged publish from a logged-in session, approved with 2FA, and only then gets its stage-only trusted publisher for this workflow and the npm environment. The workflow header spells out the order. Validators for country and language codes are not in this PR; they can be generated from the package the same way the currency one is.

Refs #6601.

Copilot AI lite review requested due to automatic review settings September 14, 2026 17:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@pullfrog

pullfrog Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using GPT Sol | 𝕏

@colinhacks colinhacks changed the title Extract the code lists into @zod/*-codes packages with a weekly refresh Extract the code lists into a @zod/codes package with a weekly refresh Sep 23, 2026
@colinhacks
colinhacks changed the base branch from iso-currency to main October 9, 2026 19:53
…ekly by CI

Three zero-dependency data packages, currency-codes, country-codes and language-codes, generated from SIX Group, the IANA language subtag registry and CLDR by a private packages/datasets generator that cross-checks every list against Debian iso-codes. A weekly workflow regenerates them, bumps versions and opens one PR with the per-list diff; a second workflow publishes any version missing from npm. The single-list script and job from the currencyCode change are replaced, and zod's regex is regenerated from the currency package.
One package with an entry point per list (/currencies, /countries, /languages) and a root that re-exports them as namespaces, replacing @zod/currency-codes, @zod/country-codes and @zod/language-codes. The generator bumps one manifest and treats a new publication date alone as no change, so a source republished with the same data opens no PR. Both workflows follow the package.

The live sources moved since the last generation: SIX marks UYW and XAD as funds, and the registry now names NR "Naoero".
Dispatch only, through the npm environment and the shared npm-stage-publish.sh, so CI can only fill the staged queue and a maintainer approves the version with 2FA, the same shape release.yml took after the 2026-09-21 compromise. A push to main no longer triggers it.
- the Debian cross-check reports a disagreement in the PR body instead of failing the run; Debian lagged the ISO 4217 amendments by three years once, and a hard gate would have blocked every refresh in that window
- a currency, numeric or CLDR code that is not the expected shape fails the parse, so a poisoned list cannot reach the regex literal
- a missing CLDR mapping for a newly assigned country is reported and left out instead of failing the run
- the version rule is major for a removed code, minor for an added one, patch otherwise, and the package starts at 1.0.0 so a minor flows through a caret range
- the decisions of a run live in rules.ts, free of I/O, with tests; a test proves the zod regex carries the package's codes
- biome formats from stdin, so a failed format leaves no dirty module behind
- the refresh job keeps the token out of .git/config, times out after 20 minutes, and replaces an open generated PR unless it is one commit over the tracked paths
- the publish workflow header spells out the first staged publish by hand, since npm binds a trusted publisher to an existing package
- a code may leave a list only with a retirement record in the source (list three for a currency, a deprecated subtag for a country or a language), so a source glitch cannot become a removal; a code set that moved is a minor, since a withdrawn code leaving the union is the point of the refresh
- every write is planned and checked before the first one, so a failed run leaves the tree as it found it
- the Debian fetches are advisory: an outage is a warning, and warnings also reach the run page as annotations
- an IsFund value other than true or WAHR fails the parse instead of silently un-funding a code
- the refresh job generates with no write token in reach and hands a patch to a second job that runs no installed code; that job resolves the open generated PR by number, same-repo only, fetches its head by id, and closes it when main already carries the data
- the publish workflow builds and tests with no OIDC token in reach and stages the built package from a second job that installs nothing; its header names the environment in the npm trust command and the build before the first staged publish
- the tracked paths are a bash array, so actionlint is clean like release.yml
The stage job takes only the build outputs from the artifact, keeps it for the 30 days an environment can hold a job, checks the entry points landed, stages with --ignore-scripts and skips the summary once the registry serves the version. The refresh workflow takes its patch after the build and the tests, holds the workflow token on the steps that call gh, and replaces a stale generated PR instead of force-pushing over it.

This branch had an error being deployed

1 failed deployment
Preview – zod-v4 — c7705c58 Deployed Oct 12, 2026 by vercel[bot]
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