Skip to content

Commit 4972e56

Browse files
committed
feat: re-implement schemas as codecs
BREAKING CHANGE: this requires zod 4.1.0 or higher.
1 parent 0828272 commit 4972e56

17 files changed

Lines changed: 492 additions & 388 deletions

.github/workflows/pull-request.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,3 @@ jobs:
3333

3434
- name: Type Check
3535
run: pnpm tsc --noEmit
36-
37-
- name: Validate commit messages
38-
run: pnpm commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2025, Ben Scholzen 'DASPRiD'
1+
Copyright (c) 2025-present, Ben Scholzen 'DASPRiD'
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ yarn add zod-temporal
2020

2121
## Quick Start
2222

23-
Import the schema types from this package. You can either import individual types or import all types via convenience
23+
Import the schema types from this package. You can either import individual types or import all types via a convenience
2424
method:
2525

26-
```typescript
27-
import {zt} from 'zod-temporal';
26+
```ts
27+
import { zt } from 'zod-temporal';
2828
```
2929

3030
For `zod/v4/mini`, import from the mini sub-path:
3131

32-
```typescript
33-
import {zt} from 'zod-temporal/mini';
32+
```ts
33+
import { zt } from 'zod-temporal/mini';
3434
```
3535

3636
This library supplies the following types:
@@ -44,3 +44,13 @@ This library supplies the following types:
4444

4545
In contrast to zod-joda, `zt.zonedDateTime()` represents date times with timezone information, while
4646
`zt.offsetDateTime()` also parses to a `Temporal.ZonedDateTime` but cast to UTC.
47+
48+
## Encoding
49+
50+
The temporal schemas are implemented as [codecs](https://zod.dev/codecs). This allows you to not only parse temporal
51+
values from their ISO string representation but also to encode them back:
52+
53+
```ts
54+
const schema = zt.plainTime();
55+
const value = schema.encode(Temporal.PlainTime.from('12:34:56.789'));
56+
```

biome.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
33
"assist": { "actions": { "source": { "organizeImports": "on" } } },
44
"files": {
5-
"includes": [
6-
"**/biome.json",
7-
"**/commitlint.config.cjs",
8-
"**/vite.config.ts",
9-
"**/src/**/*",
10-
"**/demo/**/*",
11-
"**/test/**/*"
12-
]
5+
"includes": ["biome.json", "commitlint.config.cjs", "src/**/*", "test/**/*"]
136
},
147
"linter": {
158
"enabled": true,
@@ -47,10 +40,7 @@
4740
"suspicious": {
4841
"noApproximativeNumericConstant": "warn",
4942
"noEmptyBlockStatements": "error",
50-
"noConsole": {
51-
"level": "error",
52-
"options": { "allow": ["assert", "error", "info", "warn", "debug"] }
53-
}
43+
"noConsole": "error"
5444
}
5545
}
5646
},

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
},
3636
"scripts": {
3737
"build": "tsc -p tsconfig.build.json",
38-
"test": "c8 tsx --test --experimental-test-module-mocks --no-warnings=ExperimentalWarning",
39-
"test:ci": "c8 --reporter=lcov tsx --test --experimental-test-module-mocks --no-warnings=ExperimentalWarning",
38+
"test": "c8 tsx --import temporal-polyfill/global --test",
39+
"test:ci": "c8 --reporter=lcov pnpm test",
4040
"format": "biome format . --write",
4141
"check": "biome check . --write"
4242
},
4343
"peerDependencies": {
44-
"zod": "^3.25.56 || ^4.0.0"
44+
"zod": "^4.1.0"
4545
},
4646
"peerDependenciesMeta": {
4747
"@zod/mini": {
@@ -52,18 +52,18 @@
5252
}
5353
},
5454
"devDependencies": {
55-
"@biomejs/biome": "^2.1.3",
55+
"@biomejs/biome": "^2.2.2",
5656
"@commitlint/cli": "^19.8.1",
5757
"@commitlint/config-conventional": "^19.8.1",
5858
"@tsconfig/node22": "^22.0.2",
59-
"@types/node": "^24.1.0",
59+
"@types/node": "^24.3.0",
6060
"c8": "^10.1.3",
61-
"lefthook": "^1.12.2",
61+
"lefthook": "^1.12.3",
6262
"temporal-polyfill": "^0.3.0",
6363
"temporal-spec": "^0.3.0",
64-
"tsx": "^4.20.3",
65-
"typescript": "^5.8.3",
66-
"zod": "^4.0.14"
64+
"tsx": "^4.20.5",
65+
"typescript": "^5.9.2",
66+
"zod": "^4.1.5"
6767
},
6868
"packageManager": "pnpm@10.12.1+sha512.f0dda8580f0ee9481c5c79a1d927b9164f2c478e90992ad268bbb2465a736984391d6333d2c327913578b2804af33474ca554ba29c04a8b13060a717675ae3ac"
6969
}

0 commit comments

Comments
 (0)