Skip to content

fix(zod): DateTime, Bytes, and Decimal field inference for z.input#2685

Open
sanny-io wants to merge 5 commits into
zenstackhq:devfrom
sanny-io:fix/zod-datetime-input
Open

fix(zod): DateTime, Bytes, and Decimal field inference for z.input#2685
sanny-io wants to merge 5 commits into
zenstackhq:devfrom
sanny-io:fix/zod-datetime-input

Conversation

@sanny-io
Copy link
Copy Markdown
Contributor

@sanny-io sanny-io commented May 26, 2026

Closes #2673

Summary by CodeRabbit

  • Bug Fixes

    • DateTime fields now validate and infer as actual Date values for correct runtime/input handling.
  • New Features

    • Added concrete validators for decimal and binary (bytes) scalars for stricter validation and clearer inputs.
  • Tests

    • Added type-level tests covering input types for date, decimal, and binary fields.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8602e6a8-3d07-40e0-89ee-300b45f03eca

📥 Commits

Reviewing files that changed from the base of the PR and between 3e80f6a and f61fb77.

📒 Files selected for processing (2)
  • packages/zod/src/utils.ts
  • packages/zod/test/factory.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/zod/src/utils.ts
  • packages/zod/test/factory.test.ts

📝 Walkthrough

Walkthrough

Adds exported Zod helper schemas decimalSchema and bytesSchema, updates FieldTypeZodMap to use concrete Zod types (DateTime -> z.ZodDate, Decimal/Bytes -> typeof decimalSchema/typeof bytesSchema), and adds a type-level test asserting refined input types.

Changes

Zod scalar schema updates

Layer / File(s) Summary
Add decimalSchema and bytesSchema
packages/zod/src/utils.ts
Exports decimalSchema (custom Decimal predicate) and bytesSchema (Uint8Array instanceof check).
FieldTypeZodMap uses concrete schemas
packages/zod/src/types.ts
Imports decimalSchema/bytesSchema; FieldTypeZodMap.DateTime maps to z.ZodDate, Decimal/Bytes map to typeof decimalSchema/typeof bytesSchema.
Refine tests for input types
packages/zod/test/factory.test.ts
Adds a type-level test asserting z.input<typeof _userSchema> for birthdate, balance, and avatar input types.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through schemas, neat and small,
I shaped the bytes and decimals all,
DateTime now answers clear and straight,
Inputs align — no unknown state,
A tiny hop for types, a joyful call.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main fix: improving DateTime, Bytes, and Decimal field inference for z.input, which matches the core changes and objectives.
Linked Issues check ✅ Passed The PR addresses issue #2673 by updating FieldTypeZodMap to use concrete Zod types (z.ZodDate, decimalSchema, bytesSchema) enabling correct z.input inference for DateTime, Bytes, and Decimal fields.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing DateTime, Bytes, and Decimal field type mappings; the type test addition validates the fix without introducing unrelated changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/zod/src/utils.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/zod/test/factory.test.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sanny-io sanny-io changed the title fix(zod): DateTime field inference for z.input fix(zod): DateTime, Bytes, and Decimal field inference for z.input May 29, 2026
@sanny-io
Copy link
Copy Markdown
Contributor Author

sanny-io commented May 30, 2026

The cast for bytesSchema is because otherwise the underlying value is inferred as uint8Array<ArrayBuffer> rather than uint8Array<ArrayBufferLike>, which is the default generic parameter of uint8Array and is the one present in the existing tests.

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.

makeModelSchema: DateTime fields infer as unknown in z.input

1 participant