Format generated now/now_on_write values to the field's declared type - #3
Open
chrisstrahl wants to merge 1 commit into
Open
Format generated now/now_on_write values to the field's declared type#3chrisstrahl wants to merge 1 commit into
chrisstrahl wants to merge 1 commit into
Conversation
Generated now/now_on_write values were always stamped as a full ISO
datetime, regardless of the field's declared type. A field like
updated:
type: date
generated: now_on_write
made every create() and update() fail its own validation with
invalid_date: the operation stamped an ISO datetime into a date field
and then rejected the value it had just generated. validate() passed
on the same files because the on-disk values were proper YYYY-MM-DD
dates — the invalid value was introduced by the write path itself.
Fix: generateValue() and the inline now_on_write stamping in update()
now format the timestamp to the declared field type (date → YYYY-MM-DD,
time → HH:MM:SS, otherwise full ISO datetime, all UTC — consistent with
the existing {today: true} lifecycle provider and Date coercion). The
v0.2→v0.3 type migration likewise maps now/now_on_write on date-typed
fields to the {today: true} provider instead of {now: true}, so
migrated collections don't inherit the same failure.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Any field that pairs a
datetype with a generated timestamp makescreate()andupdate()fail their own validation:generateValue()(and the inlinenow_on_writestamping inupdate()) always emitnew Date().toISOString()— a full ISO datetime — regardless of the field's declared type. The operation stamps2026-07-23T06:09:41.123Zinto adatefield, then validation rejects the value it just generated withinvalid_date, and the whole write fails withvalidation_failed.validate()passes on the same files because the on-disk values are properYYYY-MM-DDdates; the invalid value is introduced by the write path itself. So collections in this shape validate clean but can never be written through the API — everyupdatefails even when the requested field change is a no-op.Repro (v0.2 profile,
default_validation: error): declare the field above, create a file with a valid date value, then callcollection.update({path, fields: {title: "x"}})→validation_failed/invalid_dateonupdated.Fix
generateValue()formatsnow/now_on_writeto the declared field type:date→YYYY-MM-DD,time→HH:MM:SS, anything else → full ISO datetime (all UTC, consistent with the existing{today: true}lifecycle provider and the validator's UTC-based Date coercion).now_on_writestamping inupdate()now goes through the same helper instead of a hardcodedtoISOString().now/now_on_writeon date-typed fields to the{today: true}provider instead of{now: true}, so migrated collections don't inherit the same failure.Tests
New
test/generated-date-fields.test.tscovers create, update, and migration for date/datetime/time-typed generated fields (all three failed before the fix). Full suite: 2005 passed; the one failing test (v03-conformancelifecycle conflict diagnostic) fails identically on a clean checkout ofmainand is unrelated.Found in production use: a knowledge-base collection where every type declares
updated: {type: date, generated: now_on_write}—mdbase updatewas unusable across the entire collection.🤖 Generated with Claude Code