Skip to content

Make Schema.Date reject invalid dates#6620

Merged
gcanti merged 1 commit into
mainfrom
schema/date-valid-by-default
Jul 25, 2026
Merged

Make Schema.Date reject invalid dates#6620
gcanti merged 1 commit into
mainfrom
schema/date-valid-by-default

Conversation

@gcanti

@gcanti gcanti commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Date validation now consistently rejects invalid Date values across schemas, configuration, CLI parsing, and IndexedDB keys.
    • Date strings and millisecond values that produce invalid dates now fail decoding.
    • Generated dates are valid by default.
  • Breaking Changes

    • Removed the separate DateValid schema and related date-validation helpers.
  • Documentation

    • Updated date validation and migration guidance to reflect the simplified API.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 25, 2026
@changeset-bot

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 66cff9b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 28 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the 4.0 label Jul 25, 2026
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Schema.Date now rejects invalid Date instances, date decoders fail for invalid results, and redundant validity APIs are removed. Arbitrary generation, integrations, tests, migration guidance, and documentation are updated accordingly.

Changes

Date validation consolidation

Layer / File(s) Summary
Date schema and arbitrary contract
packages/effect/src/Schema.ts, packages/effect/src/internal/schema/toArbitrary.ts
Schema.Date rejects invalid dates, date arbitraries exclude them, and DateValid, isDateValid, isDateValidReviver, and the valid generation constraint are removed.
Date consumer integration
packages/effect/src/Config.ts, packages/effect/src/unstable/cli/Primitive.ts, packages/platform-browser/src/IndexedDb.ts
Date consumers now use Schema.Date for validation.
Validation and compatibility tests
packages/effect/test/schema/*, packages/effect/test/Config.test.ts, packages/effect/test/unstable/cli/*, packages/effect/typetest/schema/*
Tests cover invalid date decoding and encoding, updated errors, arbitrary generation, differ behavior, and removed APIs.
Migration and API documentation
migration/schema.md, packages/effect/SCHEMA.md, packages/effect/src/SchemaTransformation.ts, .changeset/*
Documentation describes valid-date-only behavior and removes explicit validity checks from migration examples.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: bug

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

@coderabbitai coderabbitai Bot added the bug Something isn't working label Jul 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Name Current Size Previous Size Difference
basic.ts 6.64 KB 6.64 KB 0.00 KB (0.00%)
batching.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
brand.ts 6.20 KB 6.20 KB 0.00 KB (0.00%)
cache.ts 10.13 KB 10.13 KB 0.00 KB (0.00%)
config.ts 19.08 KB 19.08 KB 0.00 KB (0.00%)
differ.ts 18.41 KB 18.41 KB 0.00 KB (0.00%)
http-client.ts 20.73 KB 20.73 KB 0.00 KB (0.00%)
logger.ts 10.30 KB 10.30 KB 0.00 KB (0.00%)
metric.ts 8.56 KB 8.56 KB 0.00 KB (0.00%)
optic.ts 7.41 KB 7.41 KB 0.00 KB (0.00%)
pubsub.ts 14.17 KB 14.17 KB 0.00 KB (0.00%)
queue.ts 11.10 KB 11.10 KB 0.00 KB (0.00%)
schedule.ts 10.28 KB 10.28 KB 0.00 KB (0.00%)
schema-class.ts 18.16 KB 18.16 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 27.31 KB 27.31 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 24.16 KB 24.16 KB 0.00 KB (0.00%)
schema-string-transformation.ts 12.68 KB 12.68 KB 0.00 KB (0.00%)
schema-string.ts 10.36 KB 10.36 KB 0.00 KB (0.00%)
schema-template-literal.ts 14.38 KB 14.38 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 20.93 KB 20.94 KB -0.00 KB (-0.02%)
schema-toCodeDocument.ts 23.42 KB 23.42 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 18.30 KB 18.30 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.01 KB 18.01 KB 0.00 KB (0.00%)
schema-toFormatter.ts 17.86 KB 17.86 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 21.49 KB 21.49 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 18.55 KB 18.55 KB 0.00 KB (0.00%)
schema.ts 17.43 KB 17.43 KB 0.00 KB (0.00%)
stm.ts 12.07 KB 12.07 KB 0.00 KB (0.00%)
stream.ts 9.36 KB 9.36 KB 0.00 KB (0.00%)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/effect/src/Schema.ts`:
- Around line 12082-12083: Update the Date guard passed to declare so invalid
forged or proxied Date-like values cannot throw during getTime(). Catch
exceptions from the validity check and return false, while preserving true for
genuine, non-NaN globalThis.Date instances.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f4e91bcf-0d8f-4eae-a617-a379c94c2f3e

📥 Commits

Reviewing files that changed from the base of the PR and between c323d8b and 66cff9b.

📒 Files selected for processing (20)
  • .changeset/schema-date-valid.md
  • migration/schema.md
  • packages/effect/SCHEMA.md
  • packages/effect/src/Config.ts
  • packages/effect/src/Schema.ts
  • packages/effect/src/SchemaTransformation.ts
  • packages/effect/src/internal/schema/toArbitrary.ts
  • packages/effect/src/unstable/cli/Primitive.ts
  • packages/effect/test/Config.test.ts
  • packages/effect/test/schema/Schema.test.ts
  • packages/effect/test/schema/representation/builtInRevivers.test.ts
  • packages/effect/test/schema/representation/toCodeDocument.test.ts
  • packages/effect/test/schema/toArbitrary.test.ts
  • packages/effect/test/schema/toDifferJsonPatch.test.ts
  • packages/effect/test/schema/toIso.test.ts
  • packages/effect/test/schema/toJsonSchemaDocument.test.ts
  • packages/effect/test/unstable/cli/Primitive.test.ts
  • packages/effect/typetest/schema/SchemaBuiltInDateRevivers.tst.ts
  • packages/effect/typetest/schema/toIso.tst.ts
  • packages/platform-browser/src/IndexedDb.ts
💤 Files with no reviewable changes (4)
  • packages/effect/test/schema/representation/builtInRevivers.test.ts
  • packages/effect/typetest/schema/SchemaBuiltInDateRevivers.tst.ts
  • packages/effect/test/schema/toJsonSchemaDocument.test.ts
  • packages/effect/test/schema/representation/toCodeDocument.test.ts

Comment thread packages/effect/src/Schema.ts
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Jul 25, 2026
@gcanti
gcanti merged commit ff5d6e2 into main Jul 25, 2026
17 checks passed
@gcanti
gcanti deleted the schema/date-valid-by-default branch July 25, 2026 13:10
@github-project-automation github-project-automation Bot moved this from Waiting on Author to Done in PR Backlog Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant