Repository navigation
Conversation
Derive the field's JSON Schema from `subtitlesZodSchema` with Zod 4's native `z.toJSONSchema` (no new dependency), and wire it as the fields' `jsonSchema` on Videos and Lessons. Payload now runs it through Ajv on write and generates the TypeScript type from the same schema, so the hand-maintained mirror — and the Workers-era `validate`/`typescriptSchema` pair it existed to feed — are both gone. Refs #597 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Project each leaf group's own schema onto its JSON field as a `jsonSchema` (keys → optional strings, plural keys expanded to their CLDR family, `additionalProperties` honoured) and drop the hand-rolled `validate` it replaces — a custom validate would override Payload's built-in json validation and silently disable the schema. Every translations global now carries a real per-group TypeScript type with each key's description as JSDoc, where it was `unknown` before. Refs #597 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…nSchema - `Managers.notificationPreferences` gets a schema derived from NOTIFICATION_TYPES (each type's frequency confined to its own options). Its `validate` now delegates to Payload's built-in json validation before applying the cross-field "method unless Never" rule — a custom validate replaces the built-in outright, so without the delegation the schema would never run. - `Events.notificationLog` gets the verification/reminder entry union, and `Registrations.reminderLog` its occurrence-ledger shape. Both read back typed instead of `unknown`. `reminderLedger.ts` moves to `src/lib/registrations/reminderLog.ts`: the Registrations collection now shares it with the job, and a collection may not import a job folder's internals. The stricter types surfaced an int fixture writing a reminder entry with no `level`/`role`, which the `as NotificationLogEntry[]` cast had been hiding — filled in to match what `buildReminderEntry` actually produces. Refs #597 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
One int case per newly-schema'd field: a malformed write is a 400, and a
well-formed one round-trips. The rejection cases can't pass vacuously —
the helper throws when the write succeeds, which is how the conditional
`Lessons.panels.*.subtitles` field was caught skipping validation until
its panel has media.
Also types `Meditations.subtleSystemNodeWeights` as
`{ [slug]: seconds } | null`, spelling out the null that clearing the
cache really writes.
Refs #597
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Adds a "reach for jsonSchema" section to the collections rule with the four things that bite (a custom validate silently disables the schema, empty values skip validation, Ajv wants draft-07, typescriptSchema is redundant) plus the full audit: every json field, with either the source its schema derives from or a one-line reason it has none. Refs #597 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Fold the `questions` uri/fileMatch into `registrationQuestionsJsonSchema` so every json field now passes a complete `jsonSchema` object from its owning module, rather than one field wrapping a bare schema at the call site with a hardcoded URI. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`additionalProperties: false` on the cue would have rejected the extra keys stored rows carry (`startOfParagraph`, …) — not once, but on every later save of an otherwise untouched lesson or video. The Zod validator this schema replaces accepted them, and `lessons.int.spec.ts` documents that tolerance as intentional. Derive the field schema from a loose variant of the same shared cue, so the declared fields still can't drift from the strict parser the seed importer uses. The generated type gains `[k: string]: unknown`, which is the honest shape for data that really does carry more. Refs #597 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-618 environment in sahajcloud
|
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-618
August 4, 2026 21:01
Destroyed
Contributor
Author
|
Closing as superseded. The |
Ardnived
added a commit
that referenced
this pull request
Aug 19, 2026
…on lifecycle (#638) * refactor(events): derive per-stage semantics from one attention level Five simplifications across the verification lifecycle, all removing a second encoding of a fact the stage table already knows: - `relationId` had two implementations; 7 of 10 call sites imported the one that can't parse a string id. Consolidated onto the complete one. - Every stage now declares an `attention` level. The sidebar bucket, the admin notice severity and the quality-check skip derive from it instead of each keeping their own per-stage table; `bucketForEvent`'s `default:` case (which silently labelled unfamiliar stages "verified") is gone, and the three tables that remain are exhaustive Records. - Deleted the `eventVerification` barrel (no importers) and the `UNMANAGED_STAGES` / `daysUntilUnpublish` exports nothing outside the module read. - `DAY_MS` is declared once in `lib/utilities/time` rather than inline in nine modules. - `addMonths` clamped: 31 Aug + 6 months was rolling into 3 March, so a finished event's retention ran a few days long. Co-Authored-By: Claude Opus 5 <[email protected]> * refactor(tokens): sign every email link through one HMAC module There were three near-identical hand-rolled HMAC token modules — eventVerification/token, registrations/unsubscribeToken, and the generic utilities/signedToken written for #625 — with the same twenty lines of crypto and subtly different validity checks. The two older ones are now thin wrappers that supply their claims, TTL and `kind`. Beyond the duplication, this closes a real gap: all four link kinds are signed with the same Payload secret, and only the envelope's `kind` discriminator (which the two older modules lacked) stops a token issued for one link from being replayed against another. Pinned by a test. `signToken` gains `ttlMs: null` for never-expiring tokens, which is what the unsubscribe link needs — it may legitimately be clicked months into a course, and the action it authorizes is narrow and idempotent. Existing verify / unsubscribe links in already-sent emails stop validating, since the envelope shape changed. Accepted: the events being reminded about are re-notified on the job's next run. Co-Authored-By: Claude Opus 5 <[email protected]> * refactor(events): validate notificationLog with a JSON Schema `notificationLog` was a bare JSON array with a hand-written narrower (`Array.isArray(value) ? value as Entry[] : []`) — a cast, not a check, so a malformed entry landed in the column and every reader had to hope. It now carries a JSON Schema, which Payload uses to generate `Event['notificationLog']` AND to reject a bad write with a ValidationError. The stored shape is unchanged (still a bare array), so no data migration is needed. Adopted from the approach in #618, which this supersedes. The schema's enums are derived from VERIFICATION_STAGES and, for the two unions declared in an email template, from a `completeList` helper that makes an incomplete restatement a compile error — the types are imported type-only, so no react-email code reaches the admin client bundle. A pair of assignments in the unit spec fails to compile if the schema and the hand-written entry types drift apart; both guards were verified by mutation, as was the validation itself (an int case asserts a missing key, an undeclared key and an out-of-enum value are all rejected). Registrations.reminderLog is the same pattern and has NOT followed — its comments now say so rather than claiming a mirror that no longer holds. Co-Authored-By: Claude Opus 5 <[email protected]> * chore(migrations): one payload entry point, and document why commands go quiet `db:migrate` and `db:migrations:create` were aliases for `payload migrate` and `payload migrate:create`, and `payload` was a passthrough to a binary pnpm already resolves from node_modules/.bin. Three names for two commands meant docs used them interchangeably, and whenever a command failed the wrapper looked like the suspect. All removed; everything is `pnpm payload <command>`. The wrappers were never the problem. Three real causes, each traced to library source and now written up in .claude/rules/migrations.md: - Dev email calls `nodemailer.createTestAccount()` — a live request to ethereal.email — on every config load, so on every CLI invocation. When it fails the adapter throws, and payload's `bin.js` runs the CLI under a bare `void start()` with no `.catch()`, so the process dies with exit 0 and NO output. This is the intermittent one: `pnpm payload migrate:status` alternates between a full table and zero lines on successive runs. Documented, not yet fixed — killing the network call costs the ethereal preview URL, so it needs a decision first. - `generate:types` logs "Compiling TS types…" then returns early and silently when the compiled output matches the file on disk. Silence means "no schema change", not a hang. - A `src/migrations/index.ts` referencing a missing migration file breaks EVERY payload command, because payload.config.ts imports the index for `prodMigrations` and the index statically imports all 44 files. The ERR_MODULE_NOT_FOUND sits at the top of a long stack trace, so it scrolls away — and vanishes entirely when piped through head/tail. Co-Authored-By: Claude Opus 5 <[email protected]> --------- Co-authored-by: Claude Opus 5 <[email protected]>
Ardnived
added a commit
that referenced
this pull request
Nov 5, 2026
`notificationLog` was a bare JSON array with a hand-written narrower (`Array.isArray(value) ? value as Entry[] : []`) — a cast, not a check, so a malformed entry landed in the column and every reader had to hope. It now carries a JSON Schema, which Payload uses to generate `Event['notificationLog']` AND to reject a bad write with a ValidationError. The stored shape is unchanged (still a bare array), so no data migration is needed. Adopted from the approach in #618, which this supersedes. The schema's enums are derived from VERIFICATION_STAGES and, for the two unions declared in an email template, from a `completeList` helper that makes an incomplete restatement a compile error — the types are imported type-only, so no react-email code reaches the admin client bundle. A pair of assignments in the unit spec fails to compile if the schema and the hand-written entry types drift apart; both guards were verified by mutation, as was the validation itself (an int case asserts a missing key, an undeclared key and an out-of-enum value are all rejected). Registrations.reminderLog is the same pattern and has NOT followed — its comments now say so rather than claiming a mirror that no longer holds. Co-Authored-By: Claude Opus 5 <[email protected]>
This branch was successfully deployed
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.
Summary
type: 'json'field with a known structure now carries ajsonSchemaderived from its source of truth, so Payload validates it on write (400, not a silently-stored blob) and generates its TypeScript type instead ofunknown.jsonSchemaoff these fields —new Function()/Ajv run fine on Railway/Node.z.toJSONSchema()natively, sozod-to-json-schemawasn't needed.Changes
properties— plural keys expanded to their CLDR familyManagers.notificationPreferencesNOTIFICATION_TYPES(each frequency confined to its own options)Videos.subtitles,Lessons.introSubtitles,Lessons.panels.*.subtitlessubtitleCueviaz.toJSONSchema(…, { target: 'draft-7' })Events.notificationLogVERIFICATION_STAGES/VERIFICATION_METHODSRegistrations.reminderLogReminderLogEntryMeditations.subtleSystemNodeWeightsRecord<slug, seconds> | nullAlso:
reminderLedger.ts→src/lib/registrations/reminderLog.ts(the Registrations collection now shares it with the job, and a collection may not import a job folder's internals);registrationQuestionsJsonSchemareshaped so every field passes a completejsonSchemaobject from its owning module.The remaining json fields are recorded as deliberately unschema'd, with a one-line reason each, in
.claude/rules/collections.md.Notes for reviewer
Three findings worth your attention, all resolved:
validatesilently disablesjsonSchema.sanitize.jsonly installs Payload's built-in json validation whenvalidateisundefined. SotranslationsField's hand-rolled validator had to go, andManagers.notificationPreferences— which keeps a cross-field rule JSON Schema can't express with a readable message — delegates tovalidations.json(value, options)first. The int case "rejects a frequency outside the type's own options" is what proves that delegation runs.additionalProperties: falseis a claim about rows already in the database. Subtitles hit this: the Zod validator being replaced stripped unknown cue keys and passed, andlessons.int.spec.tsdocuments that tolerance as intentional. Rejecting them would have 400'd every later save of any lesson/video holding a legacystartOfParagraph. The cue schema is therefore derived from a loose variant of the same shared object — strict for the seed parser, tolerant for the field. Every other newadditionalProperties: false/requiredwas checked against each writer insrc/,seeds/,scripts/and against git history (NOTIFICATION_TYPESoptions and the log-entry shapes are unchanged since introduction), so none can reject stored data.level/role, hidden by anas NotificationLogEntry[]cast. Filled in to match whatbuildReminderEntryactually produces.No migration:
jsonSchemais config-only, thejsonbcolumns are unchanged (db:migrations:create --skip-emptygenerates nothing).Pre-existing and left alone:
src/components/admin/NotificationPreferences/config.tsis pure business logic imported by two collections, so byproject-structure.mdit belongs insrc/lib/. Moving it is a separate refactor — happy to open a follow-up if you'd like.Test Results
tests/int/json-schema-fields.int.spec.ts— 11 cases, one per newly-schema'd field (malformed write → 400, well-formed → round-trips). The rejection cases can't pass vacuously: the helper throws when a write succeeds, which is how the conditionalLessons.panels.*.subtitlesfield was caught skipping validation until its panel has media.translations-globals,translations-field,lessons,videos,meditations,collections-smoke,event-verification,event-registration,session-reminders,registration-digests,meditation-lecturesManual verification
TranslationsRowcomponent; only validation changed).Closes #597
🤖 Generated with Claude Code