Skip to content

fix: DateTime maps back to Schema.DateFromSelf (Date ↔ Date)#29

Merged
samuelho-dev merged 1 commit into
mainfrom
fix/datetime-back-to-datefromself
May 8, 2026
Merged

fix: DateTime maps back to Schema.DateFromSelf (Date ↔ Date)#29
samuelho-dev merged 1 commit into
mainfrom
fix/datetime-back-to-datefromself

Conversation

@samuelho-dev

@samuelho-dev samuelho-dev commented May 8, 2026

Copy link
Copy Markdown
Owner

Summary

Reverts the 5.6.0 change that mapped DateTime to DateFromInput (a Schema.Union(DateFromSelf, Date) with Encoded = Date | string). DA-layer consumers now see Selectable<X>.created_at: Date again — matching what Kysely's pg driver actually returns.

Why

  • Prisma docs: "Prisma Client returns all DateTime values as native JavaScript Date objects."
  • Kysely docs: idiomatic DateTime column is created_at: ColumnType<Date, string | undefined, never> — SELECT yields Date. "TypeScript is a compile-time concept and cannot alter runtime JavaScript types."
  • Effect docs (Schema 10944 — The Rule of Schemas): one Type, one Encoded per schema. Dual-boundary problem (DA Date↔Date vs wire string↔Date) handled with two schemas (@effect/sql Model.Class variants pattern, Doc 4312), not a single Union.

The DateFromInput Union approach pushed Date|string typed columns onto every DA mapper. No cast-free narrowing path. Wrapping reads in Schema.decode was a hundreds-of-sites refactor.

What stays from earlier sprint

  • PR fix: DB interface uses Schema.Schema.Encoded so Kysely sees real DB columns #27 (Schema.Schema.Encoded for DB interface) stays. Still correct — fixes the join-table _product_tags.A/B column exposure bug.
  • DateFromInput is still exported from the package. Consumers that explicitly want the dual-input behavior at a specific call site can still import it. Codegen just no longer auto-emits it for every DateTime column.

For RPC/HTTP wire boundaries

Define a contract-layer schema that overrides date columns with Schema.Date (Encoded = string) before the RPC framework calls Schema.decode. Same pattern as @effect/sql's json variants — one schema per boundary.

Test plan

  • bun run prepublishOnly — lint + typecheck + 347 tests + build, all green
  • Updated kysely-native-integration.test.ts to assert Schema.DateFromSelf (was DateFromInput)
  • All other tests pass unchanged
  • Apply in creativetoolkits: regenerate types (DA stops seeing Date|string), re-add RpcDateOverrides to product RPC contract for wire decode

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Restored DateTime field mapping to properly return native Date objects, reverting a previous change that caused DateTime to accept mixed input types.
  • Documentation

    • Updated documentation to clarify date handling behavior in Prisma/Kysely integration and provide migration guidance for RPC/HTTP date column contracts.

Reverts 5.6.0 DateFromInput Union mapping. DA-layer consumers got
hit with Date|string typed columns, no cast-free narrowing path.

Prisma+Kysely canonical contract: DateTime columns return native Date
instances on SELECT. Effect docs (Rule of Schemas, Doc 10944) prescribe
one Type, one Encoded per schema; dual boundaries (DA Date↔Date vs
wire string↔Date) handled with two schemas, not one Union — see
@effect/sql Model.Class variants (Doc 4312).

For RPC wire boundaries: contract-layer Schema.extend with Schema.Date
overrides for date columns. Same pattern as @effect/sql json variants.

DateFromInput is still exported from the package for explicit use at
specific call sites; codegen just no longer auto-emits it.

Schema.Schema.Encoded DB interface fix from 5.7.0 stays — still
correct for join-table A/B column exposure.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR reverts the DateTime schema mapping from DateFromInput to Schema.DateFromSelf, aligning with Prisma's native Date runtime return type. The generator and tests are updated to remove DateFromInput imports. A Changeset documents the minor version bump and migration guidance for consumers.

Changes

DateTime Schema Mapping Reversion

Layer / File(s) Summary
Type Mapping Definition
src/utils/type-mappings.ts
PRISMA_TO_EFFECT_SCHEMA.DateTime changed from DateFromInput to Schema.DateFromSelf. Documentation updated to clarify native Date behavior at Prisma layer and Schema.Date-typed boundary contracts for wire serialization.
Generator Import Updates
src/effect/generator.ts
generateTypesHeader removes DateFromInput import; generated file now imports only Schema, columnType, generated, and JsonValue from prisma-effect-kysely.
Test Verification
src/__tests__/kysely-native-integration.test.ts
DateTime mapping assertion expects generated(Schema.DateFromSelf) instead of generated(DateFromInput). Import expectation adjusted to exclude DateFromInput.
Release Documentation
.changeset/datetime-back-to-datefromself.md
Changeset documents minor version bump, revert rationale, runtime expectations, boundary-layer schema guidance, retention of DateFromInput for single-call-site use, and migration instructions.

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: reverting DateTime mapping from DateFromInput back to Schema.DateFromSelf, restoring Date ↔ Date behavior. It is concise, specific, and clearly conveys the primary fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/datetime-back-to-datefromself

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.

@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 `@src/utils/type-mappings.ts`:
- Line 34: The mapping for DateTime currently points to Schema.DateFromSelf
which violates the generator contract; change the centralized mapping so the key
DateTime maps to DateFromInput instead of Schema.DateFromSelf, and update any
related header/import generation to reference DateFromInput (ensuring
DateFromInput accepts Date | string and encodes as Date) so functions/classes
referencing DateTime use DateFromInput consistently.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ec101a67-46b7-40ca-ae0c-a93b85409cc8

📥 Commits

Reviewing files that changed from the base of the PR and between 186c9c8 and 9118ffe.

📒 Files selected for processing (4)
  • .changeset/datetime-back-to-datefromself.md
  • src/__tests__/kysely-native-integration.test.ts
  • src/effect/generator.ts
  • src/utils/type-mappings.ts

Decimal: 'Schema.String', // For precision
Boolean: 'Schema.Boolean',
DateTime: 'DateFromInput', // Date | string ↔ Date — dual-boundary safe
DateTime: 'Schema.DateFromSelf', // Date ↔ Date — Prisma+Kysely canonical

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

DateTime mapping violates generator contract rule

At Line 34, mapping DateTime to Schema.DateFromSelf breaks the repository’s required generation contract for DateTime fields. Please map it back to DateFromInput in the centralized mapping (and keep header/import generation aligned accordingly).

Suggested fix
-  DateTime: 'Schema.DateFromSelf', // Date ↔ Date — Prisma+Kysely canonical
+  DateTime: 'DateFromInput', // Accepts Date | string input, encodes as Date

As per coding guidelines, "DateTime fields must map to DateFromInput schema accepting Date | string input and encoding as Date".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
DateTime: 'Schema.DateFromSelf', // Date ↔ Date — Prisma+Kysely canonical
DateTime: 'DateFromInput', // Accepts Date | string input, encodes as Date
🤖 Prompt for 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.

In `@src/utils/type-mappings.ts` at line 34, The mapping for DateTime currently
points to Schema.DateFromSelf which violates the generator contract; change the
centralized mapping so the key DateTime maps to DateFromInput instead of
Schema.DateFromSelf, and update any related header/import generation to
reference DateFromInput (ensuring DateFromInput accepts Date | string and
encodes as Date) so functions/classes referencing DateTime use DateFromInput
consistently.

@samuelho-dev samuelho-dev merged commit ac42853 into main May 8, 2026
6 checks passed
@samuelho-dev samuelho-dev deleted the fix/datetime-back-to-datefromself branch May 8, 2026 05:52
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.

1 participant