Repository navigation
refactor(types): derive schedule, region level and verification types from payload-types - #681
Conversation
|
🚅 Deployed to the SahajCloud-pr-681 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The PR is the right size for its ticket and the derivations are exact, not approximate — I checked each against payload-types.ts rather than taking the body's word. Items 1–3 of #671, nothing smuggled in. The corrected premise on item 2 is correct: canonicalVerificationJsonSchema is built by splatting the const arrays, so deriving them from the schema would have inverted the dependency; and the generated HttpsSahajcloudDevSchemasClientCanonicalVerificationJson (payload-types.ts:2335-2349) is byte-for-byte the three interfaces it replaces — routing: 'query' | 'path', the seven-member reason union, no [k: string]: unknown escape hatch — so nothing loosened on the way through. The seed defect is real and the one-resolution fix is the right one.
The shape criticism is that the refactor collapsed a union and stopped at the files it opened. EventScheduleInput is no longer a union, but the cast and the doc paragraph that existed to reconcile that union are still in icsBuilder.ts and collections/AGENTS.md. And the new src/types/schedule.ts introduces a private alias that exists only to be aliased again — contradicted, in this same PR, by the one-line form its own AGENTS.md prescribes. A PR whose subject is "stop keeping two names for one shape" is the wrong PR to add one in.
One thing worth naming even though I am not flagging it: this bundles a zero-runtime type refactor with the only behaviour change in the diff — silent UTC substitution in the Atlas importer. The narrowing forced it, so splitting was not free, but it means the part that can alter written data is also the part with no integration coverage on this branch.
Findings
should-fix
src/types/schedule.ts:42— the collapsed union left an identity cast and a stale comment inicsBuilder.ts:121-123, and a stale paragraph incollections/AGENTS.md:785-787.src/types/schedule.ts:11—EventScheduleis a private alias renamed on the next line; three spellings of one shape, against the one-liner this PR's own doc prescribes.
consider
seeds/atlas/helpers/scheduleMapper.ts:28—Timezoneis three hops toSupportedTimezones, whichpayload-typesexports directly.seeds/atlas/helpers/scheduleMapper.ts:175— the timezone substitution is silent, whereimport.ts:1177warns for the analogous one and this same function refuses a silent fallback 25 lines down.seeds/atlas/helpers/scheduleMapper.ts:117— the identical raw-timezone write survives atimport.ts:1318; apply the helper or file the ticket rather than offering to.src/types/AGENTS.md:50— the "not a restatement" list omits deliberate narrowing, which is a shape this PR ships (endingType?: 'until'); as written a future sweep would widen it.
What was checked
Ticket and its history. #671 (current body, rewritten after this PR), all 5 comments — including the sweep that produced items 1–4 and the reviewer's two follow-ups. Verified the scope claim: the diff contains items 1–3 and nothing from item 4; src/plugins/access/types.ts is untouched.
Diff. git diff origin/main...FETCH_HEAD over all 9 files, plus each touched file read whole at FETCH_HEAD.
Every derivation checked against the generated type, not the description:
Event['schedule'](payload-types.ts:1729-1774) — confirmedfirstDate: stringandfirstDate_tz: SupportedTimezonesare required, soScheduleInputdid not silently widen when its two required members switched to derived; confirmedweekdays,weekNumber,weekdayOfMonth,monthlyMode,recurrenceTypeare the enumerations the PR claims; confirmedicalRule/upcomingDatesare on the group, soScheduleSubFieldsgenuinely gained them.HttpsSahajcloudDevSchemasClientCanonicalVerificationJson(payload-types.ts:2335-2349) vs the three deleted interfaces — member-by-member, including thatattemptsis required (orCanonicalVerification['attempts'][number]would not compile) and thatadditionalProperties: falsein the schema means no index signature reached the generated type.Region['level']vs the deleted literal union;ROUTING_MODES(canonical.ts:30) vs the generated'query' | 'path'.
The SUPPORTED_TIMEZONES claim, measured. src/lib/timezones/index.ts is the list payload.config.ts:90 installs as admin.timezones.supportedTimezones, so the membership test and the generated union cannot disagree — confirmed by reading both. Then parsed the 581 members of SupportedTimezones out of payload-types.ts and diffed them against every distinct time_zone in the committed dump: venues.json 47 distinct / 0 unsupported, regions.json 53 / 0, registrations.json 64 / 0. events.json carries no time_zone key at all — an event's zone comes from its venue or its area (import.ts:1168-1169), which is what makes the venue/region check the relevant one, not the one the PR body cites.
Consumer sides followed. All 15 importers of @/types/schedule (scheduleHooks, icsBuilder, scheduleMatch, scheduleStatus, backfillLastDate, gating, watermark, verify, syncVerificationOnSave, seeds, 4 specs) — findings 1 and 2 came out of that pass. Consumers of the verification types (VerifyEmbeds.ts, CanonicalEmbedPicker/{model,Description}) read for anything depending on the old hand-written shapes; nothing does. mapSchedule's only caller (import.ts:1189) read with its surroundings, which is where the addWarning precedent and the startingAt_tz sibling turned up.
Not flagged, deliberately. The two whitespace-only hunks in the spec files; the candidate as Timezone cast (unavoidable behind a Set<string> membership test); test-coverage volume; anything the author-side pass owns.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
… from payload-types Items 1–3 of #671. Four hand-written types restated shapes `payload-types.ts` already generates, and two of them were *wider than the CMS* — they type-checked values a write then rejected: - `ScheduleSubFields` (`src/types/schedule.ts`) declared `firstDate_tz?: string`, `weekdays?: string[]` and `weekNumber?: string` where the column enumerates `SupportedTimezones`, `'MO'|…|'SU'` and `'1'|…|'-1'`. So `weekdays: ['Monday']` compiled and failed at the database. It is now `NonNullable<Event['schedule']>`, and `ExclusionRange` derives from its `exclusions` member. - `RegionLevel` (`src/lib/mapbox/geocoder.ts`) was byte-identical to `Region['level']`. `TYPES_BY_LEVEL` is a `Record` over it, so deriving turns a new CMS level into a compile error rather than a silent gap in the geocoder. - `CanonicalVerification`, `VerifiedEmbed` and `VerificationAttempt` (`src/lib/clients/verification.ts`) hand-declared the column beside a generated type that nothing imported. They now alias `HttpsSahajcloudDevSchemasClientCanonicalVerificationJson`. The narrowing surfaced one real defect, which is the point of the exercise. `seeds/atlas/helpers/scheduleMapper.ts` declared its own fifth copy of the same shape and passed `timeZone || 'UTC'` straight through from the Atlas dump — an unrecognised zone would reach a write the CMS refuses. `ScheduleInput` now derives every member, and `supportedTimezone()` narrows against the same `SUPPORTED_TIMEZONES` list the Payload config installs (and that `payload-types.ts` is generated from), falling back to `UTC` as the caller already did for an absent zone. Item 2's premise in the ticket is corrected rather than implemented: the const reason arrays are spliced *into* the JSON schema Payload generates the type from, so they are the single source, not a third one. Deriving the arrays from the schema would invert a correct dependency. Item 4 (`TypedAuthUser` and the `currentProject` `''` narrowing) is deliberately not here — it is gated on a design decision nobody has made. #671 stays open for it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01ShFzQH9fUk4XbiGguzLExA
…d its column Caught by the review pass on the previous commit. `firstDate` is an instant computed *in* a zone and `firstDate_tz` is the zone it is read back in, so the two must be the same string. Narrowing only the column left an unsupported zone — `+05:30`, or an IANA alias the pinned `@vvo/tzdb` does not group — resolving the instant at that zone while storing `UTC`, putting the event and its whole recurrence hours out. That is strictly worse than what it replaced: before, the mismatched zone was refused by the column's enum on write. Trading a loud rejection for silently wrong data is the opposite of what #671 is for. The spec was watched failing at the real site — restoring `timeZone || 'UTC'` on the `toFirstDateUtc` call gives `2021-07-27T13:30:00.000Z` against the expected `…T19:00:00.000Z`, the 5.5 hours exactly — then restored. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01ShFzQH9fUk4XbiGguzLExA
Review on #681 asked for two things that turn out to be the same thing: `ScheduleSubFields` was a flat rename of the private `EventSchedule` on the next line, and `RegionLevel` was exported from `geocoder.ts` and re-exported again from `sidebarModel.ts`. Both put a name between a reader and the generated type it derives from, which is what the PR was opened to stop. - `src/types/schedule.ts` exports `EventSchedule` — the name the group already had — and nothing aliases it. `ScheduleSubFields` is gone from all 8 files. - `scheduleHooks.ts`'s `export type { ExclusionRange, ScheduleSubFields }` is gone; its two consumers import from `@/types/schedule`. That re-export is precisely the shape `src/types/AGENTS.md` argues against, in the PR adding the argument. - `RegionLevel` is now an unexported local in each of the three files that repeat it (geocoder, sidebarModel, the Atlas importer). The two admin components and the sidebar spec name it once each and write `Region['level']`. - `icsBuilder.ts`'s `input.schedule as Partial<ScheduleSubFields>` was an identity cast once the union collapsed — dropped, with the comment that explained the union it reconciled. `EventScheduleInput` stays. It is `Partial<EventSchedule>`, which is not `Event['schedule']`: the generated group keeps `firstDate` and `firstDate_tz` required, and all 10 consumers take a field patch or a `siblingData` merge. Removing the sidebarModel → geocoder import left `geocoder.ts` reading as single-consumer to `lib-boundary.spec.ts`, whose graph scanned `src` and `scripts` only — so the Atlas importer, its second owner, was invisible. Added `seeds/` to the roots, which is what that spec's own docblock already claims. That surfaced one pre-existing single-consumer, `richEditor/plainTextToLexical`; recorded in the baseline rather than moved, since a plain-text→Lexical converter is general-purpose and moving it is nobody's job in a types refactor. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JrS3RGMd96BwUAM7g2g5vU
… substituted Two findings from the review pass on the timezone narrowing, both about the half that was left behind. `import.ts:1318` wrote `startingAt_tz: reg.timeZone ?? undefined` — the raw `time_zone` string off the dump, into the same `SupportedTimezones` enum column `firstDate_tz` uses. It is the identical defect this PR was opened to fix, one file away, and it did not surface as a type error only because `upsert` accepts a looser shape. `supportedTimezone()` is now exported and applied there. The substitution was also silent, in both places. It does not merely reject a value — it writes the row at a different instant than the source states, which is strictly worse than the loud enum rejection it replaces, and the importer already warns for the analogous language substitution 20 lines up. `reportTimezoneSubstitution` compares the raw zone against the resolved one and warns; the mapper stays pure, since the caller holds both values already. Unreachable against the committed dump — every distinct zone is in the generated 581-member union (venues 47/47, regions 53/53, registrations 64/64) — which is exactly why a refreshed dump introducing one would go unnoticed. `Timezone` was three hops (`EventSchedule['firstDate_tz']`) to `SupportedTimezones`, which `@/payload-types` exports directly and which the Payload config and the CMS both call by that name. Imported instead. Three `supportedTimezone` cases added, and watched failing at the site that would cause it — dropping the membership test reddens both the new case and the existing `+05:30` one, which is the pair that has to move together. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JrS3RGMd96BwUAM7g2g5vU
Writes down the rule the review asked for, beside the one this PR already added: derive from the generated type, and don't put an exported name in front of the derivation. An alias earns its place where one file repeats the indexed form enough that it gets in the way, and then it stays unexported there. Also adds the third non-restatement — a deliberate narrowing at a boundary. The importer's `ScheduleInput.endingType` is `'until'` where the column is `'count' | 'until'`, and the two exceptions as written covered a relationship and a loose input but not that, so a future sweep reading the section would widen it back and lose the intent the comment exists to preserve. `src/collections/AGENTS.md` still described `EventScheduleInput` as "`ScheduleSubFields` **or** Payload's generated `| null` shape" — a union this PR deleted, under a name that no longer exists. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JrS3RGMd96BwUAM7g2g5vU
b327628 to
6212336
Compare
|
All four of your comments are handled — three adopted, one answered with the source. Two threads left open on purpose, both needing your call.
The six adversarial-review threads are all addressed and resolved. Two of them turned into real fixes rather than tidying: the seed wrote an unvalidated dump timezone into a second enum column ( The one thing worth your eye beyond the types: removing the Lean gate green (1545 specs), and the integration lane runs locally again now that #679 has landed. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…e-generated-types
@Ardnived, on the thread: "`Partial<EventSchedule>` actually reads better because it tells us this is the common `EventSchedule` type but with a modifier. The alias obscures that." `EventScheduleInput` is gone; every call site spells the shape. The alias was the third name for one type in a PR whose whole subject is that one shape should have one name, and it only survived the first round because the argument for it — that `Event['schedule']` keeps `firstDate` and `firstDate_tz` required, so the callers genuinely hold something looser — is an argument for `Partial`, not for a name. That distinction still needs writing down, so it moved to a docblock on `EventSchedule` rather than disappearing with the alias: a field hook's `siblingData`, a merge of a previous doc over an incoming patch, and a partially-built schedule all lack both required members. `src/types/AGENTS.md` gains the general form as its own rule — a modifier applied to a derived name is still spellable from the generated type, so it does not earn an alias. It replaces the carve-out that had cited this very alias as the example of a shape needing a name, which the review has now overruled. Also fixes drift this PR itself introduced: `src/collections/CLAUDE.md` was the ONE `CLAUDE.md` in the repo checked in as a regular file rather than a symlink to its `AGENTS.md`, so 6212336 updated the guide and left the copy Claude Code actually reads still naming `ScheduleSubFields` — a type this PR deletes. The two files agreed until that commit, and their only difference was those three lines. Replaced with a symlink, matching the other eighteen; `git ls-files -s '*CLAUDE.md'` is now all 120000. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01W3bncHkCBKywbTiJSniKh8
|
Inlined as you asked — Your reason is the one that settles it: the alias was the third name for one shape in a PR arguing that one shape gets one name. The argument I kept it on — that The sweep turned up drift this PR itself caused. ⏳ One thread is still yours — the Gate green on this head: lint, typecheck, typecheck:tests, 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Review on #681 asked for two things that turn out to be the same thing: `ScheduleSubFields` was a flat rename of the private `EventSchedule` on the next line, and `RegionLevel` was exported from `geocoder.ts` and re-exported again from `sidebarModel.ts`. Both put a name between a reader and the generated type it derives from, which is what the PR was opened to stop. - `src/types/schedule.ts` exports `EventSchedule` — the name the group already had — and nothing aliases it. `ScheduleSubFields` is gone from all 8 files. - `scheduleHooks.ts`'s `export type { ExclusionRange, ScheduleSubFields }` is gone; its two consumers import from `@/types/schedule`. That re-export is precisely the shape `src/types/AGENTS.md` argues against, in the PR adding the argument. - `RegionLevel` is now an unexported local in each of the three files that repeat it (geocoder, sidebarModel, the Atlas importer). The two admin components and the sidebar spec name it once each and write `Region['level']`. - `icsBuilder.ts`'s `input.schedule as Partial<ScheduleSubFields>` was an identity cast once the union collapsed — dropped, with the comment that explained the union it reconciled. `EventScheduleInput` stays. It is `Partial<EventSchedule>`, which is not `Event['schedule']`: the generated group keeps `firstDate` and `firstDate_tz` required, and all 10 consumers take a field patch or a `siblingData` merge. Removing the sidebarModel → geocoder import left `geocoder.ts` reading as single-consumer to `lib-boundary.spec.ts`, whose graph scanned `src` and `scripts` only — so the Atlas importer, its second owner, was invisible. Added `seeds/` to the roots, which is what that spec's own docblock already claims. That surfaced one pre-existing single-consumer, `richEditor/plainTextToLexical`; recorded in the baseline rather than moved, since a plain-text→Lexical converter is general-purpose and moving it is nobody's job in a types refactor. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JrS3RGMd96BwUAM7g2g5vU
Summary
payload-types.tsnow derive from it. Two were wider than the CMS:weekdays: ['Monday']type-checked and was rejected at the database.TypedAuthUserontoManager/Client— and decide where the admin-view''is handled #671 only. Item 4 (TypedAuthUser, and thecurrentProject''narrowing behind it) is gated on a design decision nobody has made. NarrowTypedAuthUserontoManager/Client— and decide where the admin-view''is handled #671 stays open for it.Changes
src/types/schedule.ts— one exported name per shape.EventScheduleisNonNullable<Event['schedule']>;ExclusionRangederives from itsexclusionsmember. A caller holding a partial schedule writesPartial<EventSchedule>at the call site.src/lib/schedule/scheduleHooks.ts— theexport type { … }re-export is gone; its two consumers import from@/types/schedule.src/lib/mapbox/geocoder.ts,src/lib/atlasSidebar/sidebarModel.ts,seeds/atlas/import.ts—RegionLevelis an unexported local in each. The two admin components and the sidebar spec writeRegion['level'].src/lib/clients/verification.ts—CanonicalVerification/VerifiedEmbed/VerificationAttemptalias the generatedHttpsSahajcloudDevSchemasClientCanonicalVerificationJson, which nothing imported before.seeds/atlas/helpers/scheduleMapper.ts—ScheduleInputderives every member; the timezone is narrowed againstSUPPORTED_TIMEZONESand resolved once, forfirstDateandfirstDate_tztogether.seeds/atlas/import.ts—startingAt_tztakes the same narrowing, and a substitution is now reported rather than swallowed.src/types/AGENTS.md— the rule, the shapes that are not restatements, that a derived alias is local and never re-exported, and that a modifier applied to a derived name does not earn an alias either.src/collections/CLAUDE.md— was the onlyCLAUDE.mdin the repo checked in as a regular file rather than a symlink, so this PR's own guide edit left the copy Claude Code reads describing a deleted type. Now a symlink like the other eighteen.What changed in review
@Ardnived left five comments across two rounds; four adopted, one still open. The adversarial pass left six; all six addressed.
ScheduleSubFieldsis gone — a flat rename of the privateEventScheduleon the next line. One name, across all 8 files. (Raised independently by both reviews.)EventScheduleInputis gone too (round 2). It was the third name for one shape in a PR arguing that one shape gets one name; every call site now writesPartial<EventSchedule>. The reason it is notEvent['schedule']— both members required — survives as a docblock onEventScheduleand as a general rule insrc/types/AGENTS.md.RegionLevelwas exported fromgeocoder.tsand re-exported again fromsidebarModel.ts, so the shape had three homes and the admin components were two hops from the generated type.icsBuilder.tsand a stale paragraph incollections/AGENTS.mddescribing the deleted union — are removed.import.ts:1318wrote the raw dump string into the same enum column; it takessupportedTimezone()now.reportTimezoneSubstitutioncompares the raw zone against the resolved one, mirroring the language warning 20 lines up. The mapper stays pure; the caller holds both values already.⏳ One thread is still open and it is a question for you — the
lib-boundary.spec.tsroots change. Summary in the<details>below; the alternative is a one-line revert plus a waiver, which I didn't take because the waiver would assert something false.⚠ One change to a gate, forced by the above — worth a look
Removing the
sidebarModel→geocodertype import leftgeocoder.tsreading as single-consumer totests/unit/lib-boundary.spec.ts, which failed the unit lane. Its import graph scannedsrcandscriptsonly, soseeds/atlas/import.ts— the module's second owner — was invisible to it.I added
seeds/to the roots, which is what that spec's own docblock already claims ("consumers are counted over the whole repo, in every import form"). That surfaced one pre-existing offender the gap had been hiding:@/lib/richEditor/plainTextToLexical, whose only consumer isseeds/atlas/helpers/lexical.ts. Recorded inKNOWN_SINGLE_CONSUMERwith the reason rather than moved — a plain-text→Lexical converter is general-purpose, and moving it is nobody's job in a types refactor.The alternative was waiving
geocoderin that baseline instead, which I didn't take because the waiver would have asserted something false: it has two consumers, the check just couldn't see one.The negative proof, the seed defects, and what was left alone
The narrowing was proven, not assumed
A scratch file asserting the five values the old types accepted, compiled against the new ones:
All five compiled before. The file was deleted; it is not in the diff.
The seed defect, the second one the fix introduced, and the third one next door
mapSchedulebuiltfirstDate_tzastimeZone || 'UTC'from the Atlas dump — an arbitrary string.ScheduleInputdeclared itstring, so nothing objected; the CMS would have refused the write.Narrowing only the column then created a worse bug:
firstDateis an instant computed in a zone andfirstDate_tzis the zone it is read back in. Resolving the column toUTCwhile computing the instant at+05:30puts the event and its whole recurrence 5.5 hours out, silently. Both now come from onesupportedTimezone()call.import.ts:1318was the same defect a file away, onstartingAt_tz, and did not surface as a type error only becauseupsertaccepts a looser shape. Same helper, same import run.Both are latent, not live: every distinct zone in the committed dump is in the generated 581-member union (venues 47/47, regions 53/53, registrations 64/64). That is precisely why a refreshed dump introducing one would have gone unnoticed — hence the warning.
The assertions were watched failing
tests/unit/atlas-schedule-mapper.spec.tsgained threesupportedTimezonecases, and dropping the membership test reddens the new "substitutes UTC" case and the existing+05:30mapper case — the pair that has to move together. Restored after.The mapper case itself was watched failing at the real site earlier: restoring
timeZone || 'UTC'on thetoFirstDateUtccall gives2021-07-27T13:30:00.000Zagainst the expected…T19:00:00.000Z— the 5.5 hours exactly.Left alone deliberately
ScheduleInput.endingTypestays'until', narrower than the column's'count' | 'until' | null. The importer never writes acountending.src/types/AGENTS.mdnow records deliberate narrowing as a non-restatement, so a future sweep does not widen it back.icalRule/upcomingDatesappear onEventSchedulebecause they are on the column. Nothing reads them through this type; they are virtual, computed on read.WeekdayCode/WeekNumberstay derived by indexing the group — nothing exports those unions.Test results
a55e841): ✓ lint, ✓typecheck, ✓typecheck:tests, ✓test:unit— 120 files / 1557 specs, all exit 0. Typecheck is the load-bearing one for the inlining: an identifier substitution either compiles at all 37 positions or it does not.tests/unit/atlas-schedule-mapper.spec.ts(17),tests/unit/lib-boundary.spec.tsscripts/ensure-test-db.shbrings the cluster up, andtests/int/schedule-last-date-backfill.int.spec.tsis green (7 specs). Nothing here touches an integration-covered path; the runtime changes are all inseeds/atlas/, which no integration spec exercises.origin/mainmerged in, so this is now tested on top of fix(api): map a Postgres 22P02 cast failure to 400, on Payload's routes and in geojson #685.Preview
Railway builds this PR's preview on push; nothing here is reachable from a URL — the change is type-level plus a seed helper — so there is no route to deep-link.
Contributes to #671
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01W3bncHkCBKywbTiJSniKh8