Skip to content

refactor(fields): declare a JSON column with one jsonField helper - #756

Merged
sydevs-bot merged 11 commits into
mainfrom
claude/refactor-726-json-field-schema
Sep 12, 2026
Merged

sydevs-bot merged 11 commits into
mainfrom
claude/refactor-726-json-field-schema

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • One helper, jsonField, declares a JSON column: its type, uri, fileMatch, $id and title all derive from a schemaTitle plus a shape. All 21 sites move onto it, and it is the module's only export.
  • Sixteen columns declare their shape in Zod, inline at the field, so a reader sees what a column holds where it is declared.
  • No *_SCHEMA_URI is exported from src/ any more, no hand-written jsonSchema literal remains, and one URI literal survives — the prefix inside the helper.

Changes

  • src/fields/jsonField.ts — the helper. Takes schema: JSONSchema4 | z.ZodType plus the rest of the field, and returns the whole JSONField.
  • src/lib/{clients,meditations,lectures,eventQuality,schedule,status,utilities}/…, src/jobs/*, src/collections/* — the 21 migrated sites.
  • src/fields/systemMetaField.ts, src/fields/fileMetadataField.ts, src/fields/translationsField.ts — the three field factories build their field through jsonField too.

Preview

Contract impact

src/payload-types.ts gains three named interfaces: RegistrationQuestions, UserMessageScreeningResult, UserMessageContext. Each was previously inlined because its schema carried a $id but no title; the bodies are byte-identical, so a consumer's structural reads are unaffected.

It also loses five:

  • FileMetadata1, FileMetadata2 and FileMetadata3 — three duplicate copies of FileMetadata, which the four upload collections now share. See "One shape, one interface" below for why they existed.
  • CleanupTestDateRange and SyncLectureMetadataIds — both named a job input, not a column, and both jobs now declare that input as plain fields (see "Answered in review").

Nothing in any of the five repos imports any of them. Consumers re-syncing types (pnpm types:cms in WeMeditateWeb) see those eight changes and nothing else.

Test results

  • Lean gate: ✓ pnpm lint, pnpm typecheck, pnpm typecheck:tests, pnpm test:unit (129 files, 1681 tests)
  • Targeted specs: ✓ cleanup-orphaned-media — 25 passed; earlier rounds: collections-smoke, videos
  • pnpm generate:types: diff is the eight interfaces above and nothing else
  • Contract step: db:migrations:create --skip-empty wrote nothing — no schema drift
  • Build: N/A (Railway builds the preview)

Manual verification

  1. On the preview, open Videos → a video with subtitles. The Monaco editor should show the schema; hover a key for its description. Save — it should succeed.
  2. Open Clients → one with embedMetadata, and a Manager's notification preferences. Same check: schema visible, save succeeds.
  3. Confirm the admin panel still loads with no client-bundle error — two schemas moved out of 'use client'-reachable modules for exactly that reason.

Answered in review

Four threads from the 2026-09-10 review, each adopted in its own commit.

  • schemaTitle, not title (afa0f04). Beside name, label and admin, title read as a field label — every other key in a jsonField call configures the admin field, and JSONField has no title of its own. This one names the TypeScript interface Payload generates. All 24 call sites, systemMetaField's pass-through option and translationsField's Pick<…> move with it. The emitted schema's title keyword is unchanged, so no URI and no generated name moves.
  • upcomingDatesSchema moved inline (a24403f). It had one consumer, and this PR's own rule is that a column's shape is read where the column is declared. It sat beside computeUpcomingDates because that hook writes it, but the hook is named at the same field. scheduleHooks drops its last zod import.
  • lectureIds is a hasMany number field (ce980ee). A list of ids is a list of numbers, and Payload has a field for that. jsonField was describing a shape the field system already describes.
  • The cleanup span is two date fields (0ec0689). testDateRange was a JSON column wrapping two ISO strings. They also stop being test-only in name — the handler takes an explicit span from whoever supplies one, and only the integration spec does, so test* described the caller rather than the input. Both halves stay required together: one alone would pair a chosen bound with a rotated one and silently run a third range.

Neither job input was ever validated at runtime, under either form — Payload feeds inputSchema only to generateJobsJSONSchemas — so both handlers keep the guards they had.

Notes for reviewer

One shape, one interface — the reason jsonField interns. Payload names a generated interface off the schema object, not off the title. Six shapes used to sit in a module purely so several fields could share one object; moving them to their fields as plain Zod would have emitted Subtitles, Subtitles1, Subtitles2 — the same body under three names, and a rename for anyone importing the second. So jsonField returns one object per distinct shape, and the generated name becomes a function of the shape. FileMetadata1/2/3 are what the old behaviour looked like; they collapse for the same reason.

The emission target is draft-7, not the draft-04 the ticket specifies. JSONSchema4 is a TypeScript type that never reaches a validator; Ajv 8 is what compiles the schema, and it carries no draft-04 meta-schema. Under draft-04, z.number().positive() emits { minimum: 0, exclusiveMinimum: true } and Ajv rejects the schema outright — so the first author to write .positive(), .gt() or .lt() gets a column that fails every save, naming a keyword they never typed. Measured against this repo's own [email protected]. payload-types.ts regenerates byte-identically under either target.

Two schemas moved to their fields (Clients.ts, Managers.ts) rather than staying in src/lib/clients/verification.ts and NotificationPreferences/config.ts. Both of those are value-imported by 'use client' admin components, and declaring a schema there ships zod plus a toJSONSchema call to the browser to describe a shape only the server validates.

Two shapes stay named at module level: EventQualityReport and ReadinessReport. A three-branch union nested in a report is past what a reader can take in beside a field's config, and both are exported as Zod from the module that owns the domain. The field is still declared with jsonField.

Dismissed, with reasons. Converting the five raw-schema holdouts to Zod: a reviewer showed Zod can express them (maxProperties via .meta(), and its enum/nullable forms generate the same TypeScript), so the original "Zod cannot express this" comments were wrong and are corrected. But four of the five splice enums from exported const arrays and the fifth builds properties with Object.fromEntries — assembled as data, where a Zod round trip buys nothing. The criterion in the guide now says that instead. Extracting a shared field-walker for the two sibling specs: they answer different questions (find one named field vs. enumerate all), and fixtures stay next to their assertions here.

Detail

How "no behaviour change" was verified. Every jsonSchema the config declares was dumped on main and on this branch and diffed. The only semantic differences are six idiom shifts, none of which alters what Ajv accepts:

from to why equivalent
oneOf anyOf branches are closed and discriminated, so at most one can ever match
additionalProperties: true {} the empty schema is always true
type: ['integer','string'] anyOf identical
type: ['object','null'] anyOf identical
enum: [X] const: X identical
— + propertyNames: {type:'string'} every JSON key is a string

Everything else in that diff is URIs, which nothing dereferences: Payload's validator builds a fresh Ajv per call and validates against schema directly, and configToJSONSchema reads only schema.

Stale in the ticket, for the next reader. The predicted HttpsSahajcloudDev…Json renames do not appear — #714 had already migrated those five schemas to urn:. And the ticket's note that z.number().int() avoids the safe-integer bounds is wrong; it emits them too, so the helper strips them with an override hook. That strip is not cosmetic: Ajv enforces the bounds, so keeping them would narrow an integer column that accepts 1e21 today.

Each new assertion was watched failing against its reintroduced defect: the $schema deletion, the integer-bound strip, the emission target, a hand-written schema bypassing the helper, two shapes colliding on one derived URI, and the interning, which reddens as TagAssignments is declared as 4 separate objects.

What the $schema case actually pins. Removing the delete reddens only toBeUndefined(): both runSchema calls still pass, because Ajv 8 resolves the draft-07 meta-schema, and payload-types.ts regenerates byte-identically. So the delete is a consistency choice — a raw-schema field carries no $schema, so neither may a Zod one — not a necessity. Under a draft-04 target it was a necessity, which is what made draft-04 look survivable.

kebabCase was toKebabCase from payload/shared rewritten by hand — identical output on all 23 titles in the tree — so the copy and its test are gone.

Closes #726

🤖 Generated with Claude Code

https://claude.ai/code/session_01FNMyzjxxC4gWdVhpnqpf6p

Payload's `jsonSchema` is `{ uri, fileMatch, schema }`, and every hand-written
site repeated one string three or four times — an exported `*_SCHEMA_URI`,
`fileMatch: [URI]`, `$id: URI`, plus a `title` restating it in PascalCase. No
URI is referenced for its own sake: Payload needs `uri` only non-empty, and
Monaco only needs it unique. So all four now derive from the title, which is
the only name that matters — it is what the generated interface is called.

Two overloads. Zod, so a column's shape can be declared inline at the field
that declares it; and raw `JSONSchema4` for what Zod cannot say.

Two hazards the helper exists to close, both measured against this repo's own
[email protected] rather than assumed:

- `z.toJSONSchema` emits `$schema`, and Ajv 8 resolves it as a meta-schema
  reference it does not carry — `no schema with key or ref
  "…draft-04/schema#"`. That throws on every save of a schema-bearing column,
  so it breaks writes rather than validation. Deleting it is what makes the
  output usable. `draft-07` does not throw but emits `const`/`propertyNames`,
  which drift from the rest of the tree.
- `z.int()` emits the safe-integer bounds as `minimum`/`maximum`. Harmless,
  but noise in the schema a reader opens in Monaco. `z.number().int()` emits
  them too, so an `override` hook is the only way to be rid of them.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01E2vsDPxnBrrxTkKYCGc2yh
All 21 sites in one pass — the 15 from #714, the 5 that predate it, and
`systemMetaField`, whose caller-supplied `uri` becomes a title so it is the
general helper's special case rather than a parallel implementation.
`stringsJsonSchema` goes with them, which retires the last URI literal
(`https://sahajcloud.dev/schemas/translations`). Leaving any of them on the
old shape is the inconsistency this set out to fix.

No `*_SCHEMA_URI` is exported from `src/` any more, no `jsonSchema: {` literal
remains, and exactly one URI literal survives — the prefix inside the helper.
Sixteen sites now declare their shape in Zod, inline at the field. Five keep a
raw schema, each with a one-line reason: `maxProperties` and bare `enum`s
spliced from const arrays have no Zod equivalent.

Verified rather than assumed, by dumping every `jsonSchema` the config
declares on both `main` and this branch and diffing them. The only semantic
changes are four equivalent idiom shifts, none of which alters what Ajv
accepts: `oneOf` -> `anyOf` on branches that are closed and discriminated, so
at most one can ever match; `additionalProperties: true` -> `{}`;
`type: ['integer','string']` -> `anyOf`; `type: ['object','null']` ->
`anyOf`. The rest is URIs, which nothing dereferences.

`payload-types.ts` moves in exactly one way, and it is the ticket's
"expect a real diff" case: `Registration.questions`,
`UserMessage.screeningResult` and `UserMessage.context` had a `$id` but no
`title`, so their shapes were inlined. Given titles, they become named
interfaces with byte-identical bodies. Every other generated shape — the
sixteen Zod conversions included — is unchanged.

The four `HttpsSahajcloudDev…Json` renames the ticket predicted do not
appear: #714 had already migrated those five schemas to `urn:`.

Test URI assertions repoint at `jsonSchema.schema.title`, so nothing is
exported solely for a test. The new spec covers what the helper makes
impossible: a `$schema` reaching Ajv, and two shapes colliding on one derived
URI. Each new assertion was watched failing against its reintroduced defect.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01E2vsDPxnBrrxTkKYCGc2yh
…n's shape

Both guides described the hand-written triple the helper replaces, so a reader
following them would reintroduce it. `src/collections/AGENTS.md` now leads with
the helper, states which Zod idiom emits which JSON Schema keyword, and names
the two hazards (`$schema` reaching Ajv, two shapes colliding on one title)
with the spec that catches each. `src/types/AGENTS.md` gains the corollary: a
Zod type used this way types the column, so `z.infer` of it would be a second
definition — read the shape off `@/payload-types` as for any other column.

Two smaller corrections the refactor makes: the union bullet said `oneOf` where
`z.union` emits `anyOf`, which accepts identically on closed discriminated
branches; and the `HttpsSahajcloudDev…Json` fallback no longer exists, since
every schema now carries a title.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01E2vsDPxnBrrxTkKYCGc2yh
Six findings from the review pass, three of them defects the refactor
introduced.

**The emission target was chosen from a type name, not from the runtime.**
`draft-04` was picked because `JSONSchema4` names it — but that type never
reaches a validator. Ajv 8 is what compiles the schema, it implements draft-07,
and it carries no draft-04 meta-schema. The two spell exclusive bounds
differently, and only one compiles:

    draft-04  z.number().positive() -> { minimum: 0, exclusiveMinimum: true }
              Ajv: schema is invalid: data/exclusiveMinimum must be number
    draft-7   z.number().positive() -> { exclusiveMinimum: 0 }          ok

So draft-04 handed the next author a column that fails every save the first
time they wrote `.positive()`, `.gt()` or `.lt()`, naming a keyword nobody
typed. Measured against this repo's [email protected]. The two forms draft-07 changes
for shapes already here are no-ops — `const` for a one-element `enum`, and
`propertyNames: {type:'string'}` on a record, since every JSON key is a string
— and `payload-types.ts` regenerates byte-identically either way.

**Two schemas were shipping zod to the browser.** Declaring a `jsonSchema`
pulls zod and a `toJSONSchema` call into whatever chunk the module lands in.
`verification.ts` and `NotificationPreferences/config.ts` are both value-imported
by `'use client'` admin components, and neither reached zod before — config.ts
had no runtime imports at all. Both schemas now sit at their fields, in
`Clients.ts` and `Managers.ts`, which is where this ticket's own rule says a
schema belongs. Each module carries a note saying why it must stay light.

**Three claims in the prose were false, and prose is what the next person
copies.** `$schema` does not break Ajv under draft-07 — that was true of
draft-04 only, so it is now stated as tidiness rather than necessity, and the
test that asserted it (passing only because it injected the draft-04 string)
is replaced by one pinning the target itself. `.nullable()` does not produce
`X & (X | null)`; that pathology belonged to `type: ['object','null']`, and
Zod's `anyOf` generates a clean `X | null`. And the escape hatch is not "what
Zod cannot express" — Zod reaches `maxProperties` via `.meta()`, and its enum
and nullable forms generate the same TypeScript. The honest criterion is that
the shape is assembled as data, which covers all five holdouts and does not
decay.

Also: `kebabCase` was `toKebabCase` from `payload/shared` rewritten — identical
output on all 23 titles in the tree, so the copy and its test are gone;
`stripSafeIntegerBounds` is not cosmetic as claimed, since Ajv enforces those
bounds and keeping them would narrow an integer column that accepts 1e21 today;
the unused barrel export and two unused Zod exports are dropped; the block
walker in the spec now reaches `TableOfContentsHeadings`, which hangs off a
Lexical editor rather than a field, and tolerates a Payload 3 `blockReferences`
slug; and a JSDoc block orphaned by a deleted constant is back on the factory
it documents.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01E2vsDPxnBrrxTkKYCGc2yh
@railway-app

railway-app Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-756 environment in sahajcloud

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Sep 12, 2026 at 12:06 am UTC
1 service not affected by this PR
  • mailpit

@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-756 September 9, 2026 17:00 Destroyed
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 9, 2026
@sydevs-bot

sydevs-bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 23:52Z address-review · attempt 1 · session · done
  • 23:52Z address-review · attempt 1 · session
  • 21:36Z address-review · attempt 2 · session · done
  • 21:36Z address-review · attempt 2 · session
  • 18:58Z address-review · attempt 1 · session · timed out

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🧐 Adversarial review

The diff matches the ticket's shape: one helper, 21 sites, no *_SCHEMA_URI and no URI literal left in src/. Code is net-negative — the growth is the new spec and two AGENTS.md files. Both deviations hold up: draft-7 is pinned by a case that reddens if the target moves back, and relocating two schemas to their fields rests on a real 'use client' value-import chain.

Findings

  • should-fix — json-field-schema-helper.spec.ts:73: the $schema case names a causality the helper's own doc denies, and looks non-falsifying.
  • consider — Managers.ts:235: 20 lines of narration above a 10-line schema.

What was checked

  • #726's criteria one by one. All met but the $schema one, which the target dissolved.
  • Sweeps over src/ for SCHEMA_URI, jsonSchema: {, urn:sahajcloud, sahajcloud.dev. Only the helper's prefix survives.
  • payload-types.ts read whole: three named interfaces, bodies byte-identical, nothing else moves.
  • The client-bundle claim, both sides. NotificationPreferencesField.tsx:17 imports ./config; CanonicalEmbedPicker.tsx:10 → model.ts:5 imports splitMountKey.
  • The uniqueness spec walks the real config.

Generated by Claude Code

Comment thread src/collections/Managers/Managers.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 9, 2026
The case read "emits no $schema, so Ajv can compile the result". The helper's
own doc denies that causality, and the measurement agrees: with the delete
removed, both runSchema calls still pass and payload-types.ts regenerates
byte-identically. Only the toBeUndefined assertion reddens.

So the name claimed a necessity the delete does not have. Rename it to the
consistency property it does pin — a raw-overload schema carries no $schema,
so neither may a Zod one — and record the measurement beside both the case and
fromZod, so the next reader does not re-derive it.

The assertion itself is unchanged and still falsifying; the PR body's claim
that it was watched failing holds.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MWnNG5pRL6QCiYMgUoSHXm
…uide

Twenty lines of narration sat above a ten-line schema, and part of it
described what the PR removed — the #659 alias, and a TS2411 combination
nobody will now write.

src/collections/AGENTS.md already carries the "open shape can still be typed"
rule and names this very field as its example, so the #659 half was a second
copy. The TS2411 trap was not there; it is now, as a bullet beside that rule,
where the next author writing a `z.record` column will read it.

What stays at the field is what is local to it: which keys the admin renders,
and why the frequency is a string rather than an enum.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MWnNG5pRL6QCiYMgUoSHXm
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-756 September 9, 2026 17:24 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

🤖 address-review — both adversarial-review threads adopted, pushed as f43a23e.

Nothing rebutted, nothing asked. Lean gate green — lint, both typechecks, 1679 unit tests. Both files changed are comments and a spec name; no behaviour moves.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 9, 2026
@sydevs-bot
sydevs-bot requested a review from Ardnived September 9, 2026 17:35
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

I could not mark ready here — the dispatch token is not allowed to. Everything else on this item is done, so this is the one step left for you.

🤖 sydevs dispatcher

@sydevs-bot

Copy link
Copy Markdown
Contributor Author

This draft has had no CI activity for hours and no session holds it. Comment or push to wake me.

🤖 sydevs dispatcher

@sydevs-bot
sydevs-bot marked this pull request as ready for review September 10, 2026 01:21

@Ardnived Ardnived left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we go a step further and implement a jsonField helper. We can rename src/fields/jsonFieldSchema.ts to src/fields/jsonField.ts and basically create a field helper for json fields that takes a schema: JSONSchema4 | z.ZodType and constructs the rest. Then stop exporting jsonFieldSchema and only export jsonField. This will let us keep the definitions in the collections even shorter and hopefully let us actually move the Zod definition inline in all collections.

systemMetaField and translationsField will use jsonField under the hook.

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 10, 2026
Review asked for a `jsonField` helper: rename `jsonFieldSchema.ts` to
`jsonField.ts`, take `schema: JSONSchema4 | z.ZodType` plus the rest of the
field, and export nothing else. Every one of the 21 sites now declares its
column with it, `systemMetaField`, `fileMetadataField` and `translationsField`
included.

Two consequences the rename alone does not give:

A field can no longer skip the helper. There is no bare `jsonSchema` to
obtain, so `type`, `uri`, `fileMatch`, `$id` and `title` cannot be written by
hand at a field — they were five lines a caller could get wrong before.

Six shapes that lived in a module only to be shared as one `jsonSchema` object
move to their fields as plain Zod: `MeditationFrames`, `MeditationNodeWeights`,
`Subtitles`, `LectureMetadata`, `ClientAbuseScore`, `ScheduleUpcomingDates`,
plus `EventQualityReport` and `ReadinessReport`, which stay named where they
are because a reader cannot take them in beside a field.

That last move would have renamed generated interfaces, which is why
`jsonField` interns: Payload names an interface off the schema OBJECT, not the
title, so handing three `subtitles` columns equal-but-separate objects emits
`Subtitles`, `Subtitles1`, `Subtitles2` — the same body under three names. One
object per distinct shape keeps a name a function of the shape. The new case
in the helper spec was watched failing with the interning removed:
`TagAssignments is declared as 4 separate objects`.

`payload-types.ts` moves in one direction only: `FileMetadata1/2/3` collapse
into `FileMetadata`, three duplicate interfaces nothing imported. No other
generated shape changes, and `db:migrations:create --skip-empty` wrote nothing.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AzQHVAUMN3oxRKsmVmqJ66
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-756 September 10, 2026 05:09 Destroyed
@sydevs-bot sydevs-bot changed the title refactor(fields): derive jsonSchema metadata and define shapes in Zod refactor(fields): declare a JSON column with one jsonField helper Sep 10, 2026
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 11, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

The session for this item did not finish after 3 attempts. I have stopped retrying. A comment, a verb, or a push from you starts me again.

🤖 sydevs dispatcher

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting and removed awaiting bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 11, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

The session for this item did not finish after 3 attempts. I have stopped retrying. A comment, a verb, or a push from you starts me again.

🤖 sydevs dispatcher

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 11, 2026
Review: `title` reads as a field label beside `name`, `label` and `admin`,
which is what every other key in a `jsonField` call configures. This one
names a TypeScript interface — the one Payload generates into
`payload-types.ts` — and `JSONField` has no `title` of its own for it to be
confused with. `schemaTitle` says which of the two it is at the call site,
where the reader is.

All 24 call sites, `systemMetaField`'s own pass-through option, the
`Pick<JsonFieldOptions, …>` in `translationsField`, and both guides move
with it. The emitted JSON Schema's `title` keyword is unchanged, so no URI,
no generated interface name and no `payload-types.ts` line moves.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FNMyzjxxC4gWdVhpnqpf6p
Review asked whether `upcomingDatesSchema` had a reason to stay in
`@/lib/schedule/scheduleHooks`. It did not. It had exactly one consumer —
the field three lines of Zod now declare inline — and this PR's own rule is
that a column's shape is read where the column is declared.

It sat beside `computeUpcomingDates` because that hook is what writes it,
but the hook is named at the same field, so the pairing survives the move.
`scheduleHooks` drops its last `zod` import with it.

No generated type changes: `ScheduleUpcomingDates` is still one interned
object under one schemaTitle.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FNMyzjxxC4gWdVhpnqpf6p
Review: a list of lecture ids is a list of numbers, and Payload has a field
for that. `jsonField` was reaching for a JSON column to describe a shape the
field system already describes.

`{ type: 'number', hasMany: true }` generates `lectureIds?: number[] | null`
— what the handler already reads — and drops the `SyncLectureMetadataIds`
alias, an interface that existed only to name that array.

Nothing is lost by the move. `inputSchema` is fed only to
`generateJobsJSONSchemas`, so neither form was ever a runtime check, and the
handler's `Array.isArray` guard stands either way. The comment that called
the input "an unvalidated `json` field" now names the real reason instead.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FNMyzjxxC4gWdVhpnqpf6p
Review: `testDateRange` was a JSON column wrapping two ISO strings, which is
what `type: 'date'` already is. Two optional date fields say it in the field
system instead, and the `CleanupTestDateRange` interface — generated solely
to name that pair — goes with them.

They stop being test-only in name. The handler takes an explicit span from
anyone who supplies one, and only the integration spec does; calling it
`test*` described the one caller rather than the input. Both halves are
still required together, since one alone would pair a chosen bound with a
rotated one and silently run a third range.

The label moves with the name: `test-range` becomes `explicit-range`, so a
log line says what the run did rather than who asked for it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FNMyzjxxC4gWdVhpnqpf6p
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-756 September 12, 2026 00:03 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

🤖 address-review — all four threads adopted, pushed as 0ec0689.

Both job inputs drop a generated interface that named a job input, not a column. Contract impact updated.

Nothing rebutted, nothing asked. Lean gate green, plus cleanup-orphaned-media (25 passed). No schema drift.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 12, 2026
@sydevs-bot
sydevs-bot merged commit a9ae837 into main Sep 12, 2026
40 of 46 checks passed
@sydevs-bot
sydevs-bot deleted the claude/refactor-726-json-field-schema branch September 12, 2026 03:30
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Sep 12, 2026
sydevs-bot pushed a commit that referenced this pull request Sep 12, 2026
One conflict, in `tests/COVERAGE.md`: both sides appended a row to the
same coverage table. Kept both — #744's two Sentry rows and this branch's
Atlas seed row.

`src/payload-types.ts` and `src/globals/AGENTS.md` auto-merged and were
verified rather than trusted: `pnpm generate:types` reproduces the merged
types byte for byte, and both sides' AGENTS.md paragraphs survive (#705's
`stringsSchema` rename beside #706's Atlas tab list).

No semantic conflict. `main` brought #756's `jsonField` helper, which
rewrites `src/fields/translationsField.ts` — a file this branch never
touched — and added no migration, so the branch's migration stays last in
`src/migrations/index.ts`.

Gate: lint, typecheck, typecheck:tests, 1757 unit tests in 132 files.
Targeted: translations-globals, available-locales and the Atlas seed
spec, 43 tests, against a real Payload and Postgres.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DEd12ZA8W99LeMM2ukWup1
sydevs-bot pushed a commit that referenced this pull request Sep 15, 2026
`screeningResult` and `proposed` still hand-built a `JSONSchema4` literal and a
`{ uri, fileMatch, schema }` wrapper. #756 made `jsonField` the one way to
declare a JSON column, with the shape in Zod inline at the field, so both are
now declared that way and the three repeated URI strings are gone.

`screening.ts` keeps `SUBMISSION_VERDICTS` and drops the schema. That module is
a leaf an admin component may import, and a Zod shape there would pull `zod`
and a `toJSONSchema` call into the browser chunk to describe a column only the
server validates — the rule in `src/collections/AGENTS.md`. `z.enum` reads the
verdict list directly, so nothing is spliced.

`pnpm generate:types` regenerates `src/payload-types.ts` byte-identically, which
is the evidence that `SubmissionScreeningResult` and `SubmissionProposal` are
the same shapes as before.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q35b7JXvBHQv1tdYbm4dtY
sydevs-bot pushed a commit that referenced this pull request Sep 15, 2026
`logField` built its own `{ uri, fileMatch, schema }` wrapper from a
hand-written `JSONSchema4`, which is exactly what `jsonField` exists to stop
(#756) — and it exported `ACTIVITY_LOG_SCHEMA_URI`, the kind of `*_SCHEMA_URI`
constant that refactor deleted everywhere else. Nothing imported any of the
three, so they go rather than being re-exported.

The shape is unchanged: every property stays optional and the entry object
stays open, because Payload runs this validator on every save of the document
and the column predates the factory — a `required` key strands a row holding
an older entry. `z.looseObject` emits `additionalProperties: {}` for that, and
`.max(500)` keeps the cap a single bypassing write would otherwise ignore.

`jsonField` interns one object per distinct shape, so Events, Registrations and
`user-submissions` still share one generated `ActivityLog` interface rather
than getting `ActivityLog1`. `pnpm generate:types` regenerates
`src/payload-types.ts` byte-identically, which is what proves it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q35b7JXvBHQv1tdYbm4dtY
Ardnived added a commit that referenced this pull request Sep 15, 2026
…754)

* feat(api)!: unify public intakes on a `user-submissions` collection (phase 1)

Phase 1 of #695, per #723: the form-builder plugin's submissions collection
is renamed `user-submissions` and given the typed columns every public write
needs, beside the three collections it will eventually replace. Nothing is
deleted here — `registrations`, `user-messages` and `event-submissions` keep
working until Phase 3.

- `formSubmissionOverrides.slug` + a `fields` override adds `type`, `uuid`,
  `status`, `senderEmail`, `user`, `client`, `subject`, `screeningResult`,
  `activityLog`, `event`, `startingAt`, `unsubscribedAt`, `eventFeedback`,
  `followUpSentAt` and `proposed`. `submissionData` keeps only the flat
  free-form remainder, since it is client-writable as one blob and nothing
  queryable, unique, relational or system-gated can be protected inside it.
- `prepareUserSubmission` (beforeValidate) enforces per-type allowed keys and
  lengths on that blob, issues the `uuid`, composes `subject`, upserts the
  sender into `users`, and stamps provenance from the authenticated key.
- The plugin's unconditional `form` requirement becomes per-type: required for
  `contact` and `subscribe`, refused for the two that name an `event`. The
  plugin's own existence check is composed with, not replaced.
- Forms gain `actionType` with conditional `recipient` / `client`, save-time
  validation of the authored field list, and lose `emails` — a structural
  disable of the plugin's pre-screening `sendEmail`, not a suppression.
- Every `type: 'json'` column declares a `jsonSchema`, `logField`'s included.
  Its entries stay open (`additionalProperties: true`) because machine data is
  each writer's own; `LogDisplayCells` declares the matching index signature.
- `user-submissions` joins RESTRICTED_COLLECTIONS and leaves the wemeditate-web
  project. Clients get create-only; a manager's read is narrowed per row to
  contact rows addressed to them plus proposals.
- The `registrations: ['update']` client grant, its uuid-scoped access branch
  and `restrictClientRegistrationUpdate` are removed. The vote's only writer is
  the CMS-hosted feedback page, which writes with `overrideAccess` — that grant
  was an open write path nothing used.
- `Users` shows one `submissions` join in place of `registrations` and
  `submittedEvents`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYXZbMFo1WvADtgEwSxHXP

* test(api): cover the unified intake's create path, access matrix and form actions

Four spec files, plus the two the change re-points.

Each caught a defect while being written, which is the reason for the shape
they take:

- `user-submissions-access.int.spec.ts` reads rows back through
  `overrideAccess: false` rather than asserting grants, and found that the
  form-builder plugin's own `access` block outranks the whole RBAC layer
  (`accessPlugin` composes `{ ...rbac, ...collection.access }`). Its
  `read: !!user` would have granted every API client read of every stranger's
  message, with `RESTRICTED_COLLECTIONS` looking like it applied. The plugin's
  `access` is now cleared for this collection.
- `user-submissions-create.int.spec.ts` found the Turnstile stub succeeding for
  any argument, so the "no token" case passed for the wrong reason; found the
  offending key missing from a `ValidationError`'s message, which is the one
  thing the acceptance criterion asks for; and found the plugin's `sendEmail`
  throwing once per form-less submission.
- `forms-action-type.int.spec.ts` pins the save-time rules and that `emails` is
  absent from the sanitized config.
- `submission-data.spec.ts` holds the per-type key matrix in the unit lane, and
  the URL-scan exemption that keeps a crash report from reading as spam.

The access, form-action and submission-data specs were each re-run with the
rule they cover disabled, and each went red.

`event-feedback.int.spec.ts` is re-pointed at the real writer: the feedback
page's server action, which votes with `overrideAccess`. Its client-vote block
becomes the assertion that no client write path exists.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYXZbMFo1WvADtgEwSxHXP

* fix(api): gate the proposed patch, and loosen the activity-log schema

Two corrections found reviewing the branch against `src/collections/AGENTS.md`.

`proposed` reaches `user-submissions` from a public POST and is a patch of real
Events fields, so Phase 3's accept path would apply it to an Event with a
manager's authority behind it — a submitter setting `verificationStage` mints a
verified listing, and `registrationNotificationEmail` forwards registrants'
answers to an inbox of their choosing. `validateProposal` is `event-submissions`'
own gate and derives its allowlist from the live Events config, so it is reused
rather than re-derived. It moves to a shared home in Phase 3, when that
collection is deleted.

`activityLog`'s schema now declares no `required` keys. Payload runs a JSON
validator on every save of the document, including one that never touches the
column — and this column predates the `logField` factory: it was Registrations'
`reminderLog`, whose entries were reminders with no `cells`. A `required` list
would have made any row holding one permanently unsaveable, which no test here
could see because no test holds a pre-#626 row. Type checks on the properties
that are present still apply.

The verification spec's hand-built log fixture is rebuilt with the real entry
builders either way: the entries it spelled out omitted `type` and `cells`,
which nothing that writes the column omits, so the crash it simulates was a
state the app cannot reach.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYXZbMFo1WvADtgEwSxHXP

* docs(api): describe the unified intake's client contract and access rules

The new refusal codes, the URL-scan exemption, and the create-only grant are
things an integrator observes, so they belong beside the Turnstile contract
rather than only in the code that raises them. Also corrects a cross-reference
in EventSubmissions to the Users join that replaced `submittedEvents`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYXZbMFo1WvADtgEwSxHXP

* fix(api): close the defects an adversarial review found in the intake

Nine findings from a security pass and a code-quality pass over the branch.
Five would have shipped a defect; each now has a test that fails without the
fix.

- **An unrecognised `type` crashed the public POST with a 500.** This hook runs
  before Payload validates the select's options, so the cast reached
  `TYPE_SUBMISSION_KEYS[type]` and spread `undefined`. Checked now, with the
  same 400 the neighbouring refusals use.
- **`type` was never reconciled with the form's `actionType`**, and
  `enforceSubscribeReach` keys on `type` — so a restricted client could post
  against another client's subscribe form while calling the row a `contact`,
  and the reach check never ran. The form is the authority; a disagreement is
  refused rather than silently corrected.
- **`activityLog` was client-writable.** `logField`'s docblock promised it was
  never writable through the API and stated that nowhere the server reads, which
  did not matter while the column sat on collections no client could write. The
  admin renders it as system-written history. Denied to clients — deliberately
  not a flat `update: () => false`, because the admin verify action writes that
  log with `overrideAccess: false` so the manager's own permissions gate it, and
  a blanket deny silently dropped the record of who verified a listing.
- **`validateFormAction` merged with `??`.** Payload normalises a cleared
  relationship to `null` and hands the hook data already merged with the stored
  document, so clearing a subscribe form's client read as the old client and
  passed the one rule the hook exists for. It now reads the merged value, and
  judges a save only when it changes the field list, the action or the client —
  which is also what stops a legacy form, back-filled to `contact` and lacking a
  message field, becoming unsaveable on an unrelated edit.
- **`subject` echoed the title of any event id a client named**, drafts and
  trashed rows included, routing around the published-only narrowing a client's
  own reads get.

Three test cases could not fail for their own rule: a form fixture that also
broke a second rule, a `?? []` join assertion that could not tell "filtered to
nothing" from "never populated", and an "admins read everything" case reading
with `overrideAccess: true`. All three assert the property they name now.

Also: the entry cap short-circuits instead of emitting one message per row;
`activityLog` gained `maxItems`; a `.catch(() => null)` that turned a transient
database error into a 400 blaming the integrator is gone; the dead
`urlScanFields: ['subject']` entry is removed with a note saying why field
access had already emptied it; and the docs' claim that both new refusals are
400 is corrected — `subscribe_target_forbidden` is 403.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYXZbMFo1WvADtgEwSxHXP

* build(deps): patch drizzle-kit so migrate:create survives a table rename

`pnpm payload migrate:create` died with "Cannot read properties of
undefined (reading 'columns')" on this branch, before writing any file.

drizzle-kit's `applyPgSnapshotsDiff` rewrites the old snapshot as it
resolves each rename, but hands `preparePgAlterColumns` the raw `json1`
instead of the rename-patched copy. So a renamed table that also has
altered columns — `form_submissions` -> `user_submissions`, which is every
collection rename — is looked up in the pre-rename snapshot under its new
name, comes back undefined, and the diff throws.

The patch passes the rename-patched `tables` while keeping the original
`enums`: the same function reads `json1.enums` by *old* enum name, so
substituting the fully patched snapshot would break enum-rename detection.

Still unfixed upstream through 0.31.10, and @payloadcms/db-postgres pins
drizzle-kit to exactly 0.31.7, so patch rather than bump. `payload` and
`@payloadcms/db-postgres` drop their carets for the same reason — a float
onto a release carrying a different drizzle-kit would leave the patch
matching nothing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* feat(db): add the user-submissions migration

The schema change landed in 537da0c with no migration, so every Railway
preview boot ran this branch's code against an unmigrated database and
`GET /api/forms` 500'd on the missing `forms.action_type`.

Renames rather than rebuilds, so existing submissions survive:
`form_submissions` -> `user_submissions`, its `submission_data` child
table, and `payload_locked_documents_rels.form_submissions_id`. Then the
intake columns (`type`, `status`, `sender_email`, `uuid`, the event and
client relations, the jsonb `proposed`/`screening_result`/`activity_log`),
`forms.action_type`/`recipient_id`/`client_id`, and the drop of
`forms_emails` + `forms_emails_locales`, which `action_type` and
`recipient_id` replace. `user_submissions.form_id` loses NOT NULL — a
submission need no longer come from a form.

`down` reverses all of it, including recreating both dropped tables.
Validator: 4 pass, 0 fail; the four warnings are the expected DROP TABLE /
DROP COLUMN / RENAME notices. No DDL here repeats anything in the applied
chain.

Generating it needed the drizzle-kit patch in the previous commit.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* docs(migrations): record the drizzle-kit rename patch

The patch and its exact-version pins landed in b001669 undocumented, so the
next person to hit "Cannot read properties of undefined (reading 'columns')"
would re-derive the whole diagnosis. States what the patch fixes, why the
versions lost their carets, and that the rename prompt still needs an
attended run.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MtUegBuq8Kg6aqp797zxPL

* Create migration

* fix(db): empty the duplicate resync migration

20260914_175014 was generated against the pre-merge snapshot, so its 142
statements were all re-emissions of DDL this chain already applies. Checked
one by one against every other migration: zero were new. They come from
20260705_160029, 20260705_161112, 20260909_161243, 20260909_161353,
20260909_161848, 20260909_162104, 20260911_235823, 20260912_031449 and
20260913_212558 — every one of them ahead of it in index.ts.

Replaying that aborts the boot migration on its first statement, CREATE TYPE
enum_wm_app_config_available_locales already exists, and the drops further
down would take the translation columns with them. This is #566, the
out-of-order snapshot trap the PR body warned was still open.

The .json half is the fix, not the problem: it was generated on the merged
tree, so it carries both user_submissions and main's 20260909-20260913
schema. Keeping it as the highest-timestamp snapshot with no DDL beneath it
heals the chain. Verified: db:migrations:create --skip-empty now writes no
files, so the snapshot and the config agree exactly.

Nothing rolls back here. The migration failed on statement one, so it
committed no schema and left no payload_migrations row.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LYKfe6EDGUTFV7rDmi8a7w

* docs(migrations): record how to heal a stale snapshot

The trap section said the chain heals once a fresh snapshot lands, but not
what to do with the unusable .ts that arrives beside it. Names the shape —
keep the snapshot, empty the DDL, keep the timestamp — and the probe that
proves it worked.

Also states what cost this a second round: push: !isProduction means no test
lane ever replays the chain, so CI is silent about a migration that cannot
apply. Only a Railway boot runs prodMigrations.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LYKfe6EDGUTFV7rDmi8a7w

* fix(users): keep the registration and proposal joins until Phase 3

The `submissions` join was added in place of `registrations` and
`submittedEvents`, but nothing writes `user-submissions` yet — Phase 1 adds
the schema only. `registerForEvent` still creates `registrations`, and
`event-submissions` still takes proposals. So the new join showed nothing
while the two it replaced were the admin's only window onto a registrant's
live history.

#723 is explicit that the old collections' behaviour does not change this
phase. All three joins now sit side by side; the two legacy ones go in Phase
3, with the collections they read. The comment says why they are still there,
so the next reader does not re-derive it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01THSsECbMbjXErzVELQSDUH

* fix(deps): pin the whole Payload family, not two of it

`payload` and `@payloadcms/db-postgres` dropped their carets so the
drizzle-kit patch key keeps matching. The other eight family members kept
`^3.86.0`, and Payload does not support a mixed-version family — so one
`pnpm update` could put `@payloadcms/[email protected]` beside a pinned
`[email protected]`, a break with no patch involved.

Every `@payloadcms/*` now pins `3.86.0`, `typescript-plugin` included. No
version moves: only the nine `specifier:` lines change in the lockfile, and
`pnpm install --frozen-lockfile` accepts it unchanged.

`src/migrations/AGENTS.md` says why the pins are there and how to bump them,
beside the patch story that made the first two exact.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01THSsECbMbjXErzVELQSDUH

* fix(forms): one home for the sendEmail removal story

The mechanism was told three times and one telling was wrong.
`Forms/fields.ts` and the first `formBuilder/index.ts` docblock both said
stripping `emails` disables the plugin's `sendEmail` hook, via its
"nothing-to-send" branch. It does not get that far: it loads `data.form` and
spreads `data.submissionData` first, both optional here, so it throws.
Removing the hook is what disables it.

The detailed docblock also sat on `formBuilder` while describing what
`formsPlugin` does. It moves onto `formsPlugin`, which is where the `access`
clear and the hook removal happen, and is now the one statement of both.
`formBuilder` documents the plugin options alone. `Forms/fields.ts` keeps
why `emails` is stripped — it owns that list — and points here for the hook.
`collections/AGENTS.md` points here too rather than restating it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01THSsECbMbjXErzVELQSDUH

* fix(submissions): say what subject is actually composed from

The docblock said "not client-writable: it is derived". The column is indeed
denied to clients, but `composeSubject` joins a contact form's title with the
sender's own `subject` pair — so unreviewed submitter text does reach the
admin list title, which is the thing the old wording promised it would not.

Wording, not a hole: the pair is URL-scanned, bounded by `checkSubmissionData`
and truncated to 300. The docblock now says both halves, and says to treat the
value as untrusted at any new render site.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01THSsECbMbjXErzVELQSDUH

* fix(submissions): fold the proposal schema into its field

`proposal.ts` was 38 lines for one constant with one consumer, 29 of them
comment. The rationale reads better beside the field it governs, and there is
nothing left to share: the Phase 2 job and admin component that would have
made it a leaf module do not exist yet.

`screening.ts` stays. It has two importers — `UserMessages` reads
`screeningResultJsonSchema` too — so folding it here would make one collection
import another's field list.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01THSsECbMbjXErzVELQSDUH

* fix(forms): inline the one-use block helper

`blockTypes` was a four-line wrapper over `new Set(...)` with one caller, and
its name said what it did rather than why — so a reader met an abstraction
before the rule it serves. The set is now built where it is read, with a line
saying what it is for.

The hook's own purpose is unchanged and stated in its docblock: a subscribe
form with no email field, or a contact form with no message body, collects
nothing usable and fails on every submission thereafter, one visitor at a
time, with the author never present to see it. Refusing the save is the one
moment the person who can fix it is there.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q35b7JXvBHQv1tdYbm4dtY

* fix(submissions): drop the subscribe reach check

Any client role may now subscribe a person to any client's list, as asked in
review. `enforceSubscribeReach`, its `subscribe_target_forbidden` refusal, the
`UNRESTRICTED_SUBSCRIBE_ROLES` exemption and its integration case are gone,
along with the row in `docs/rules/api-clients.md`.

The `type`/`actionType` reconciliation in `prepareUserSubmission` stays. It was
introduced partly to keep this check reachable, but it stands on its own: every
per-type rule downstream keys on `type`, so a row calling itself a `contact`
against a subscribe form is judged by the wrong rules throughout. Its comment
no longer cites the removed hook.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q35b7JXvBHQv1tdYbm4dtY

* fix(submissions): declare the JSON columns in zod

`screeningResult` and `proposed` still hand-built a `JSONSchema4` literal and a
`{ uri, fileMatch, schema }` wrapper. #756 made `jsonField` the one way to
declare a JSON column, with the shape in Zod inline at the field, so both are
now declared that way and the three repeated URI strings are gone.

`screening.ts` keeps `SUBMISSION_VERDICTS` and drops the schema. That module is
a leaf an admin component may import, and a Zod shape there would pull `zod`
and a `toJSONSchema` call into the browser chunk to describe a column only the
server validates — the rule in `src/collections/AGENTS.md`. `z.enum` reads the
verdict list directly, so nothing is spliced.

`pnpm generate:types` regenerates `src/payload-types.ts` byte-identically, which
is the evidence that `SubmissionScreeningResult` and `SubmissionProposal` are
the same shapes as before.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q35b7JXvBHQv1tdYbm4dtY

* fix(fields): declare the activity log in zod

`logField` built its own `{ uri, fileMatch, schema }` wrapper from a
hand-written `JSONSchema4`, which is exactly what `jsonField` exists to stop
(#756) — and it exported `ACTIVITY_LOG_SCHEMA_URI`, the kind of `*_SCHEMA_URI`
constant that refactor deleted everywhere else. Nothing imported any of the
three, so they go rather than being re-exported.

The shape is unchanged: every property stays optional and the entry object
stays open, because Payload runs this validator on every save of the document
and the column predates the factory — a `required` key strands a row holding
an older entry. `z.looseObject` emits `additionalProperties: {}` for that, and
`.max(500)` keeps the cap a single bypassing write would otherwise ignore.

`jsonField` interns one object per distinct shape, so Events, Registrations and
`user-submissions` still share one generated `ActivityLog` interface rather
than getting `ActivityLog1`. `pnpm generate:types` regenerates
`src/payload-types.ts` byte-identically, which is what proves it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q35b7JXvBHQv1tdYbm4dtY

* fix(submissions): derive the submission unions from payload types

`SubmissionType` and `SubmissionStatus` were `(typeof ARRAY)[number]`, which is
a restatement one hop away from the generated column — the pattern
`src/types/AGENTS.md` refuses, because such a type drifts wider than the CMS and
then compiles values the database rejects.

Both now read off `UserSubmission['type']` and `UserSubmission['status']`. The
const arrays stay: they are the runtime values `fields.ts` builds the two
selects from, so the column is generated from them and deriving the types back
closes the loop. An option added without a `TYPE_LABELS` or
`TYPE_SUBMISSION_KEYS` entry is now a compile error instead of an `undefined`
spread at runtime.

The module stays a leaf — `@/payload-types` is types only, so nothing reaches a
browser chunk that did not before.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q35b7JXvBHQv1tdYbm4dtY

* fix(submissions): fold the verdict list in beside its column

`screening.ts` held one const with one consumer and an alias with none, so
it goes the way `proposal.ts` went in b4c2d8f. `SUBMISSION_VERDICTS` now sits
beside `screeningResultField` in `fields.ts`, which builds the schema's enum
from it, and the module's one substantive paragraph — why the machine verdict
lives in this column and never in `status` — moves onto that field.

`SubmissionVerdict` is deleted rather than re-derived. Nothing imported it, and
the list already generates `SubmissionScreeningResult['verdict']`; an exported
alias would be the second definition `src/types/AGENTS.md` says to delete, not
to point somewhere else. A Phase 2 consumer reads the generated type directly.

`pnpm generate:types` leaves `payload-types.ts` byte-identical, which is the
evidence no shape moved.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XpWhgSLpDEgsryNu4btTJt

* fix(submissions): read the type unions straight from payload-types

`UserSubmissions/types.ts` is gone. Its two exported aliases were the
re-export chain `src/types/AGENTS.md` prohibits: `SubmissionType` and
`SubmissionStatus` already spelled `UserSubmission['type']` and
`['status']`, and exporting them gave each shape a second home for every
consumer to reach through.

Each consumer now names the generated union at its own call site —
`submissionData.ts` twice, `fields.ts` once, `prepareUserSubmission.ts`
three times — so no file imports a type from another module that is only
forwarding one. With `submissionData.ts` off the module entirely, the
pure-module objection that kept `types.ts` alive last round is gone: it
takes `@/payload-types`, which is types only, and pulls no `zod` or
`logField` into the unit lane.

The runtime halves move to `fields.ts`, beside the selects they build —
the same fold `proposal.ts` and `screening.ts` got. `SUBMISSION_STATUSES`
and `STATUS_LABELS` stop being exported: only `statusField` reads them.

No shape moves. `pnpm generate:types` leaves `src/payload-types.ts`
byte-identical.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Nrgkhg12CwBzFcYKtRbmnu

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: Devindra <[email protected]>
Co-authored-by: sydevs-bot <[email protected]>

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-756 — 0ec06898 Deployed Sep 12, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

refactor(fields): derive jsonSchema metadata and define shapes in Zod

3 participants