Repository navigation
feat(translations): typed JSON groups, per-locale publish status, and an availableLocales field gated on published translations - #731
Conversation
… src/lib/translations Three owners now read the same schema-to-data-path mapping, so it stops being one owner's private helper: - `pluralCategories.ts` holds `PLURAL_CATEGORIES` (re-exported from `@/fields/translationsField`, so existing importers and its spec keep working) plus `pluralStorageKeys`, the expansion the field builder and the English merge both need. - `schemaWalker.ts` takes `collectLeafLookups` and `extractPlainText` out of `WeMeditateAppStatus/sections/translations.ts`, and adds an `expandPlurals` option. The status report asks about one declared key; the English merge asks about the keys actually stored. - `availableLocales.ts` and `clientEnglishFallback.ts` are new, and are consumed by the two commits that follow. The failure this prevents: a second copy of the nesting rules drifting from the field builder's. The status report already encoded them, and the English merge needs exactly the same answer — a `<tab>_<sub>` column, a JSON blob keyed by leaf key — for a different question. `clientEnglishFallback` fills blank keys from English for API-client reads only. Payload's locale fallback is per field, not per key, so a locale with any translation at all returns a blob missing everything untranslated, and each consumer repo would otherwise carry the same merge. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013Yeh5CnyHkXr2HZguigryi
…ake a strict maxLength block
Each leaf group's JSON column now carries a `jsonSchema`, so Payload
generates a named interface per group instead of the
`{ [k: string]: unknown } | … | null` union every consumer had to cast
away, and Ajv enforces the shape on write.
- `stringsJsonSchema` builds one schema per leaf group: plural keys
expanded to their CLDR family, every property optional, per-key
`description` kept (it becomes JSDoc), `additionalProperties` from the
group. Title is `<Global><Parent><Leaf>Strings`, uri under
`https://sahajcloud.dev/schemas/translations/`.
- The hand-rolled `validate` goes. Supplying one *replaces* Payload's
built-in `json` validator; leaving it undefined installs that validator
bound to the schema, which enforces exactly what the function did.
- `strict: true` beside a `maxLength` emits the limit into the schema, so
the save is refused. `lengthStatus` gains `blocking`, and the row
renders `ErrorIcon` plus "over the limit, this will not save".
- Sub-groups render as collapsibles, not inner tabs. Tabs inside tabs hide
every sub-group but one, which is the wrong shape for a translator
working down a page.
Three failures this prevents. A consumer casting a translations blob and
getting the cast wrong, silently. An over-length `strict` string saving
and breaking a layout, because the limit was advisory everywhere. And a
translator not finding a sub-group at all, because it sat behind a second
tab row.
Every property stays optional on purpose: Payload validates a stored
column on every save of its document, so a `required` key would strand
every locale not yet translated. `maxLength` is emitted only for a
`strict` key for the same reason — an advisory limit that suddenly blocked
would break keys already over it.
Only standard JSON Schema keywords may appear. Payload runs Ajv 8 in
strict mode, where an unknown keyword throws at validate time rather than
at boot, so `plural`, `screenshot` and `strict` must never leak in.
The collapsible change is presentational only: the data path and the
column name are `<tab>_<sub>` either way, so `wm-app-translations` reads
and saves as before and no migration is involved.
The two new `blocking` assertions were confirmed failing first, with
`blocking` forced to `false` at its own return site.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013Yeh5CnyHkXr2HZguigryi
…s field gated on it
Two config globals now carry `availableLocales` — the set of languages the
project is offered in — and a locale can only be selected once that
project's translations are published in it.
- `experimental.localizeStatus` on the config root, plus
`versions.drafts.localizeStatus` on `sy-atlas-translations` and
`wm-web-translations`. `_status` becomes a localized column, so
"published in French" is a fact the CMS can answer.
`wm-app-translations` keeps `drafts: true` and one status for everything.
- `availableLocalesField({ translationsSlug, surface })` composes Payload's
built-in `select` validator, then requires `en`, then reads the
translations global once per request at `locale: 'all'` and rejects any
selected locale whose status is not `published`.
- Both translations globals gain the `clientEnglishFallback` afterRead
hook, so an API client reading a partially translated locale gets
English for the blanks.
- `sy-atlas-config.languages` is replaced by the new field, and
`src/lib/atlas/defaultLocales.ts` is deleted with it.
The failure this prevents: an operator offering a language whose
translations do not exist. `hreflang` then tells a crawler that language
has a page, the widget renders English, and nothing in the CMS could have
said no. `languages` was an unvalidated list of locale codes.
Two behaviour changes worth naming:
- **An unconfigured row now answers `['en']`, not the ten launch
locales.** `ATLAS_DEFAULT_LOCALES` existed because a `defaultValue` does
not backfill an existing row, and production's does exist. Keeping that
fallback would promise a crawler nine languages before an operator said
any of them were translated — the exact promise this field exists to
stop. The atlas-seo spec asserts the new default rather than the old
count.
- **`locale: 'all'` is load-bearing in the validator.** A single-locale
read of an untranslated locale resolves `_status` through the English
fallback and reports it published. The raw per-locale map cannot.
`skipAvailableLocalesCheck` on `req.context` relaxes only the publish
check, for local-API seeds and specs that create a config row before
anything is published. `en` stays required with it set.
`unpublishedLocales` also accepts a plain string `_status`, so the field
stays reusable on a global that has not opted into `localizeStatus`.
`tests/unit/atlas-locales.spec.ts` is replaced by
`tests/unit/available-locales.spec.ts` in the commit that adds it.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013Yeh5CnyHkXr2HZguigryi
…d the English merge Four new or rewritten suites, split by what each can actually prove: - `tests/unit/available-locales.spec.ts` replaces `atlas-locales.spec.ts`. It covers `parseAvailableLocales`/`readAvailableLocales` and `unpublishedLocales` — including the new `['en']` default for an unconfigured column, which is the behaviour change #705 makes. - `tests/unit/client-english-fallback.spec.ts` enumerates the four shapes of "blank", and the one case that must NOT be filled: a field the caller's `select` stripped. - `translations-field.int.spec.ts` swaps its `validate` block for a `jsonSchema` block — the emitted schema's properties, its absent `required`, `additionalProperties`, `maxLength` only for `strict`, the interface title, and that no non-standard keyword leaks in. It also asserts collapsibles instead of an inner tabs row, and that `a11y` starts collapsed. - `available-locales.int.spec.ts` is new: the English invariant, the publish gate refusing and then accepting, the message naming every unpublished locale, `skipAvailableLocalesCheck` relaxing only the publish check, the wm-web field gating on its own global, and the English merge reaching an API client but not a manager. - `translations-globals.int.spec.ts` gains `localizeStatus` on/off per global, a per-locale publish, and three writes that prove the JSON column enforces its own schema. - `testHelpers.ts` mirrors `experimental.localizeStatus`. Without it every suite would silently run the two web globals with one status for all locales, and every publish-gating assertion would pass for the wrong reason. Every new assertion was confirmed failing first, at the site that causes it: | Defect reintroduced | Goes red | | --- | --- | | `blocking` forced to `false` in `lengthStatus` | 2 cases in `length-status` | | the `['en']` fallback dropped from `readAvailableLocales` | `answers English alone for an unconfigured column` | | the `Object.hasOwn` guard dropped from `mergeEnglish` | `never re-adds a field the document does not have` | | `expandPlurals: false` in `schemaLookups` | 2 cases in `client-english-fallback` | | an absent locale read as published in `unpublishedLocales` | `treats a locale absent from the map as unpublished` | | `jsonSchema` unwired from the JSON field | 2 write-rejection cases in `translations-globals` | | the `afterRead` hook removed from the atlas global | `fills a blank key from English for an API client` | | `readPublishStatus` reading one locale instead of `'all'` | 3 publish-gate cases | The last row is the one worth keeping. A single-locale read resolves `_status` through the English fallback, so an untranslated locale reports itself published and the gate opens for everything. Two shapes the specs deliberately do not assert. Ajv is not a top-level dependency here, so the schema's *enforcement* is proven by real writes in the integration lane rather than by compiling the schema in a unit test. And `wm-web-config` has four other required fields, so the positive case there asserts that `availableLocales` stops objecting, not that the write succeeds — filling in a home page and two page lists would test Payload's `required`, not this field. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013Yeh5CnyHkXr2HZguigryi
…languages for availableLocales
Generated by `payload.db.createMigration`, answering **create** at every
drizzle prompt. A "rename" would have carried
`sy_atlas_config_languages`' old `{ code }` rows into
`availableLocales`, whose stored shape is a bare locale code.
What it does:
- creates `sy_atlas_config_available_locales` and
`wm_web_config_available_locales` (+ their enums), and drops
`sy_atlas_config_languages` (+ its enum);
- moves `_status` / `version__status` for both web-project translations
globals from the base tables into their `_locales` tables, with the
matching indexes.
⚠ **Every locale lands as `draft`.** `ADD COLUMN "_status" … DEFAULT
'draft'` cannot know which locales were published before, and the old
column held one value for all of them. Operators publish each locale
after the seed, which the rollout requires anyway.
Payload's own `localizeStatus.up` data migration is deliberately not used:
it cannot coexist with the generated DDL, it takes its locale list from
`filterAvailableLocales({ req })` — `['en']` for a user-less migration
`req` — and it leaves `VARCHAR` columns without the index the snapshot
expects.
**Two lines here are not this ticket's.** `ALTER TABLE "songs" /
"images" ALTER COLUMN "file_metadata" SET DEFAULT '{}'::jsonb` is the
catch-up #714 flagged and could not generate ("that needs a migration this
session cannot generate"). Drizzle diffs against the snapshot, so the next
migration on this branch necessarily carries it, and hand-editing a
generated migration is not allowed. It is safe on its own terms: a column
default affects future inserts only, and `frames` and `videos` already
carry it.
Verified on a scratch database built from `origin/main`'s schema with rows
in `sy_atlas_config_languages`, not only on a clean one: `payload migrate`
applies, the old table is gone, `_status` is on the `_locales` tables and
off the base tables, and `payload migrate:down` puts all three back.
`migration-validator`: 4 pass, 0 fail, 3 warnings — the two DROP warnings
are the intended replacement and the intended `_status` move, and the D1
foreign-key warning predates the move to Postgres.
`src/payload-types.ts` is regenerated for all three preceding commits: a
named `…Strings` interface per translations group (114 of them, no
collisions), `availableLocales` on both config globals, `languages` gone.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013Yeh5CnyHkXr2HZguigryi
…the English merge - `src/globals/AGENTS.md` — rewrites the config-globals section around `availableLocales` (both invariants, why `locale: 'all'` is load-bearing, what `skipAvailableLocalesCheck` relaxes, and why an unconfigured column answers `['en']`), and adds three sections to the translations part: the JSON column declaring its own shape (never give one a `validate`), sub-groups as collapsibles, and `strict` beside `maxLength`. - `docs/architecture.md` — the atlas `alternates` set is now `availableLocales`, and is gated on published translations. - `docs/rules/email.md` — says why `EMAIL_STRING_DEFAULTS` stays even though the CMS merges English now: the hook only fires for a `clients` read, and `resolveEmailStrings` is not one. - `tests/COVERAGE.md` — rows for the emitted schema, the publish gate and the merge; the deleted `atlas-locales.spec.ts` is replaced by `available-locales.spec.ts`. The failure this prevents is the next author giving one of these JSON fields a `validate` again. That silently replaces the validator bound to `jsonSchema`, and every shape check stops running with nothing to show for it — which is exactly how the field arrived in this state. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013Yeh5CnyHkXr2HZguigryi
…the array check
Three defects the review pass found, each verified by reintroducing it:
**1. The publish gate deadlocked English against itself.** Payload merges a
field's stored value into its sibling data and validates it on *every* save
of the global, not only when someone edits that field. The migration lands
every locale as `draft`. So on the deploy that ships this field, both config
globals would have been unsaveable — with an error telling the operator to
publish the one locale they cannot deselect. English is mandatory rather
than chosen, and every other locale falls back to it, so gating it buys
nothing. It is now exempt; every other locale is gated exactly as before.
**2. Dropping the hand-written `validate` newly accepted `[]`.** Payload's
built-in `json` validator short-circuits on an "empty" value, and an empty
array counts as empty, so the schema never saw it — an array could land in a
column whose generated type is an object. The field now **composes** the
built-in (the same pattern `Managers` and `Meditations` use) rather than
going without: one array check, then delegate. Replacing it outright is what
would switch the schema off, so the rule in `src/globals/AGENTS.md` is
restated as "compose, never replace".
**3. `mergeEnglish` wrote through into the caller's nested groups.**
`{ ...doc }` is one level deep, so a nested group's object was shared with
the input and the "does not mutate" claim held only at the top level — which
is why the existing spec passed either way. Groups are now cloned lazily on
first write.
Also here, all from the same cause as (1) — a newly `required` field refuses
a partial write that never mentions it:
- `seeds/wemeditate/import.ts` carries the stored value through, or seeds
English, which is what `readAvailableLocales` already answers for an
unconfigured row.
- `atlas-sitemap.int.spec.ts` and `region-canonical-url.int.spec.ts` supply
the field on their `canonicalFallbackClient` writes.
| Defect reintroduced | Goes red |
| --- | --- |
| the `DEFAULT_LOCALE` exemption removed | 5 cases in `available-locales` |
| the array check dropped, delegating only | 2 cases in `translations-field` + `translations-globals` |
| the nested group shared instead of cloned | `does not mutate a nested group…` |
Verified green after: the full integration lane, 73 files / 1194 tests.
⚠ It needs `VITEST_INT_MAX_FORKS=2` on a 4-CPU box — the default of 6 gives
nondeterministic failures across unrelated suites.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013Yeh5CnyHkXr2HZguigryi
|
🚅 Deployed to the SahajCloud-pr-731 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 diff is the size of its ticket, and its shape. #705 is unusually prescriptive and this follows it clause by clause, including the Payload traps it named; the "implement the whole thing in one run" instruction on the ticket settles the scope question, so there is no split to argue for. Of 32.8k added lines, ~31.5k are the drizzle snapshot and regenerated types — the hand-written surface is about 800 lines across nine source files, which is proportionate. The three fixes in cf7a51b are the right three: the English exemption in particular is the difference between two config globals that save on deploy and two that do not.
Two things I would want answered before merge, neither a rewrite: the publish gate silently drops the select the ticket specified and now reads the largest global in all 19 locales on every admin change event, and alternates has a live consumer — the WordPress plugin — that Contract impact does not name and that changes on this deploy rather than in a follow-up. The rest is small: an alias and a barrel entry that no longer have callers, and one acceptance criterion that quietly did not ship.
Findings
| should-fix | availableLocalesField.ts:44 |
the gate's read drops the ticket's select: { _status: true }, and runs per onChange form-state rebuild |
| should-fix | availableLocales.ts:52 |
SahajAtlasWordpress/includes/seo.php renders alternates on 13 client domains and is not in Contract impact |
| consider | translationsField.ts:56 |
PLURAL_CATEGORIES back-compat re-export, one importer, in a spec this PR rewrites |
| consider | fields/index.ts:33 |
four barrel exports with no importer; stringsJsonSchema has no caller at all |
| consider | available-locales.int.spec.ts |
the REST-read AC (createRestClient against both config globals) is neither met nor listed as manual |
What was checked
- Ticket vs diff — #705 body and both comments; the reviewer's "implement this entire ticket in a single run" instruction. Walked all 12 acceptance criteria; the REST-read one above is the only one I could not find evidence for.
- The new code, whole —
availableLocalesField.ts,lib/translations/{availableLocales,clientEnglishFallback,schemaWalker,pluralCategories}.ts, thetranslationsField.tsdiff, both config and both translations globals,atlasLocales.ts,lengthStatus/TranslationsRow(Field), the migration and itsdown(),WeMeditateAppStatus/sections/translations.ts(the walker move is behaviour-identical),seeds/wemeditate/import.ts. - Payload 3.86.0 source, for the four claims the PR rests on.
globals/config/sanitize.js:80-105andcollections/config/sanitize.js:160-190— the rootexperimental.localizeStatusflag really is inert for every other entity, globals and collections alike.fields/validations.js:166-215— the built-injsonvalidator does readjsonSchemaoff the spread field config, so the composedvalidatekeeps the schema live, andisNotEmptyreally does short-circuit[].globals/operations/findOne.js— adraft: falseglobal read applies no_statusfilter, so the all-draft migration does not hide these globals from readers (worth knowing; I went looking for that failure and it is not there).@payloadcms/ui addFieldStatePromise.js:107-133—event: 'onChange', which is the basis of the first finding. - Schema generation, simulated over the real data. Reproduced
stringsJsonSchema's title/uri derivation across all threetranslationsSchema.jsonfiles: 57 leaf groups, 57 distinct titles, no collisions, and no level mixing leaf keys with sub-groups (which the builder does not support). Matches the PR's "57 named interfaces". - Consumer sides.
WeMeditateWeb/server/cms-client.ts:178-186—WEB_CONFIG_SELECTis include-mode and names neither field, so it still satisfiesWmWebConfigSelect<true>;getWebConfigreturnsas WebConfig, so the new non-optional property does not break its typecheck. (Note for WeMeditateWeb#81:WebConfig extends Omit<WmWebConfig, …>will typeavailableLocalesas present while the select never fetches it.)SahajAtlasWebreads neither yet — checked.SahajAtlasWordpress/includes/seo.php:154-165does, hence the finding. - Queries — grepped every writer and reader of
sy-atlas-config/wm-web-configacrosssrc,seeds,scripts,tests:seeds/wemeditate/import.tsand the two int suites are the three partial writes that needed a line, and all three have one.ATLAS_DEFAULT_LOCALESanddefaultLocales.tsare fully gone; noSyAtlasConfig.languagesremains inpayload-types.ts.
Advisory only — approval is @Ardnived's.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The ticket specified `select: { _status: true }` on the gate's read and
named one fallback for dropping it. The fallback never fired, and the
`select` went anyway, so the gate pulled every translations JSON column in
every locale — 12 columns x 19 locale rows on `sy-atlas-translations` — to
answer a question about `_status` alone.
The width matters because the read is not only on save. `@payloadcms/ui`'s
`addFieldStatePromise` calls a field's `validate` with `event: 'onChange'`,
so the admin repeats this on every form-state rebuild of `sy-atlas-config`
and `wm-web-config`. Without the `select` that is a full localized read of
the largest global per interaction.
`select` composes with `locale: 'all'` — the publish-gate cases in
`available-locales.int.spec.ts` still distinguish a published locale from an
unpublished one, which they could not if `_status` came back empty.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ABp2XiB7GQSFE8jVPWR65J
Three dead surfaces, all introduced by this branch: - `PLURAL_CATEGORIES` was re-exported from `translationsField` for back-compat, and its one importer was `translations-field.int.spec.ts` — a file this branch rewrites wholesale. The spec now imports the constant from its home, and the alias goes. - `stringsJsonSchema` left the `@/fields` barrel. It has no importer outside `translationsField.ts` itself; the specs read the emitted schema off the built field instead, which tests the wiring rather than the helper. `availableLocalesField` stays in the barrel — the ticket asked for it. - The re-export's docstring claimed three owners read the constant. Two do: the field builder and the schema walker. The email resolver derives the category from `Intl.PluralRules` and shares only the naming convention, so `pluralCategories.ts` now says that instead. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01ABp2XiB7GQSFE8jVPWR65J
… asked #705 lists a REST read of `/api/globals/sy-atlas-config` and `/api/globals/wm-web-config` via `createRestClient` among its acceptance criteria. It did not ship, and was not on the manual-verification list either, so nothing recorded that the criterion was open. It is worth having rather than waiving. The `languages` -> `locales` collision this field replaces was a read-time Drizzle failure: the config compiled, the local API was never reached, and only a REST read surfaced it. Both config globals gain a sub-table here, so the same class of failure is in range. The atlas case asserts the stored set comes back, not merely a 200 — an assertion that only checked the status would pass against a global that dropped the column. Confirmed by setting a different set and watching it go red. The We Meditate case reads the global unconfigured, which is what production looks like on this deploy. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01ABp2XiB7GQSFE8jVPWR65J
|
All five review threads answered, three commits pushed. Ready for review.
Body updated: SahajAtlasWordpress is now named in Contract impact. It is the one Lint, both typechecks, the unit lane and both touched int suites pass locally. CI runs the full lane on 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…e option Answers both open review threads on #731. `surface` existed only to interpolate a default `admin.description`. The atlas call site already passed its own description, so the option was dead there; the We Meditate one now passes its own too, naming that surface's consumers the way the atlas one does. Generic help text was the weaker half of the pair anyway — it could not say what the field drives. Three other pieces of scaffolding go with it: - `memoKey()` wrapped one template string, called once. Inlined, with the by-slug reason kept as a line where the key is built. - the two error-message shapes collapse to one. "Publish the French translations before offering them." reads the same for one locale and for several, so the `missing.length === 1` branch bought nothing. - `description` is now required rather than optional, which is what removing the default makes it. No behaviour changes. The gate, the English exemption, the per-request memo and the skip flag are untouched. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014xMzPr9e342pbCm5toSJFH
|
Both threads answered, one commit pushed. Ready for another look.
No behaviour change: the publish gate, the English exemption, the per-request memo and the skip flag are untouched. Lean gate green on ⚠ The integration lane did not re-run here. This routine has no Postgres, so 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…ds, so a client can read per-locale publish state (#765) * feat(pages): store _status per locale on Pages and AppCards Opt both collections into `versions.drafts.localizeStatus`, so `_status` lives in their `_locales` tables and `?locale=all&select[_status]=true` answers which languages a document is published in, in one query. WeMeditateWeb#81 needs that to emit an `hreflang` cluster that names only the locales it really has. The object form of `drafts` is required — `drafts: true` sanitises the flag back to false. The root `experimental.localizeStatus` key is already on main from #731, and is deliberately not written again here. The migration's DDL is drizzle-generated, matching #731's worked example: same enum types, same indexes moved onto `(_status, _locale)`, snapshot chain intact. The backfill between its two DDL blocks is hand-written, and the migration is wrong without it. As generated, the locale column is added with DEFAULT 'draft' and the base column is then dropped — so every already-published page lands draft in all 19 locales, and `pages` is read published-only by `wemeditate-web-client`. That deploy would unpublish the entire We Meditate site. #731 accepted the same outcome for the translations globals, where the blast radius was one config gate; it is not acceptable here. Copying the base value to every locale preserves exactly what is observable today, since a published page renders in all 19 locales through the English fallback. `down()` needs the mirror of it for the same reason. Proven on a scratch database built from origin/main's schema, seeded with published and draft rows, in its own migration batch: up() keeps the published page published in both locales and the draft page draft, and down() restores the base column with the published page still published. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MC6QJKbQazsJfVCZ6RcyUb * fix(fields): read the publish gate per locale in publicUrlFields A field `afterRead` hook sees `_status` in whichever shape its collection stores it: a plain string without `localizeStatus`, a per-locale map with it. The bare `data?._status !== 'published'` check reads the map as "not published" and nulled `webUrl` / `appUrl` on every page the moment the flag went on — five cases in `pages.int.spec.ts` caught it. The map reaches this hook unresolved because Payload hoists a localized value down to the requested locale in the same afterRead field pass that runs this hook, so whether `_status` is already a string here depends on field order. Handling both shapes is the fix, not reordering fields. At `locale: 'all'` any published locale counts — the alternative nulls the field for every document on a `locale=all` read. The access `Where` in accessConfigs needs no change: it constrains `_status`, that column moved, and Drizzle scopes the same clause to the requested locale for free. Comment only, recording that it is now per-locale and load-bearing — with it removed, a read at `?locale=de` returns the German text of a locale the editor unpublished. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MC6QJKbQazsJfVCZ6RcyUb * test(pages): pin the per-locale publish contract Nine cases over the status map, the published-only gate, the consumer contract, the query count, and live preview's draft unlock. Checked against criterion 11 by removing `localizeStatus` from both collection configs and re-running: six of the nine go red, including every status-map case and the access leak. The three that stay green are genuinely flag-independent — an unpublished page is served in no locale either way, the query count is a property of the adapter, and live preview reads through `draft: true`. The two Czech `webUrl` cases in `pages.int.spec.ts` now publish the locale they read. They are about the path shape for a non-English locale, and creating a page `published` publishes the default locale alone — so without it they were asserting the publish gate by accident. A new case covers the gate itself, paired with an English assertion, because it would otherwise pass against the old bug that nulled the URL in every locale. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MC6QJKbQazsJfVCZ6RcyUb * docs(api-clients): document the per-locale _status map The host-facing half of #718: what `?locale=all&select[_status]=true` returns, and the one rule for reading it — a locale is published only when it says so, and a never-translated locale is absent from the map rather than `draft`. Also records why there is no `publishedLocales` field, that `payload-types.ts` still types `_status` as a single string so a consumer casts, and that the published-only filter is now per locale. The OpenAPI `locale` parameter accepts `all` alongside the concrete codes, which it enumerated exclusively before. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MC6QJKbQazsJfVCZ6RcyUb * docs(collections): record the per-locale publish state on Pages The Pages guide still described `publishSpecificLocale` as tracking `published_locale` in the versions table, which was the pre-flag behaviour. Replaces it with what a contributor now has to know, each item being something this branch tripped over: a field afterRead hook sees `_status` in two shapes and the map arrives unresolved, publishing a locale validates that locale's required fields so a missing title refuses the write, and the published-only filter is per locale. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MC6QJKbQazsJfVCZ6RcyUb * fix(access)!: stop locale=all handing a client an unpublished locale The published-only client filter is `{ _status: { equals: 'published' } }`, and making `_status` localized scopes it per locale — but only for a request naming one locale. At `?locale=all` the clause filters *documents*, matching any document published in any locale, while the response still carries every locale's value for every localized field. Measured on this branch, not inferred: a page published in English, published in German, then unpublished in German, read by a published-only client at `?locale=all`, returned `title: { en: 'Leak EN', de: 'Leck DE' }`. The German text is the last thing published there, and the editor has since taken it down. Unpublishing one locale leaves its text in the main table with `_status = 'draft'`, which is exactly what makes it reachable. This is new with the flag — before it, a locale could not be unpublished on its own, so every locale of a published document was published. A cross-locale read by such a client now answers which locales are published and nothing else: `_status` and `id`. That is the documented contract (`?locale=all&select[_status]=true`) and the one cross-locale fact the client is entitled to. Content stays available one locale at a time, where the clause gates it properly. Managers, the admin panel, and live preview are untouched — the hook uses the same three conditions as the access branch, so the two cannot disagree about who is restricted. Redacting per field instead would mean walking each document against its field tree — groups, named tabs, arrays, blocks — to find which values are locale maps, and every gap in that walk is a leak. Keeping two keys cannot leak. Attached by `accessPlugin` off the collection's own config rather than a slug list, so a third collection opting into `localizeStatus` is covered the day it does. BREAKING CHANGE: an API client reading a drafts-enabled collection at `?locale=all` receives only `_status` and `id`. No current consumer does this — the read was introduced by this branch. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MC6QJKbQazsJfVCZ6RcyUb * fix(fields): trim the publish-gate comment to the rule The `isPublished` doc comment ran 19 lines for a 6-line function, most of it narrating the regression that caused it. A caller needs the rule — `_status` is a string or a per-locale map, handle both — and the reason the map can arrive unresolved, because that is what stops the next reader simplifying the check away. The history stays in PR #765, where it reads better than in the file. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QcPzYuzr3bfjA1n7mxL8LQ * fix(access): stop exporting the redaction's private predicate `hasLocalizedStatus` has one caller, `withPublishedLocaleRedaction`, in the same file. Exported it read as a shared helper the rest of the access plugin could ask about a collection, which it never does. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QcPzYuzr3bfjA1n7mxL8LQ * fix(openapi): document locale=all where a consumer reads it Criterion 10 was met on `eventGeoJsonParameters`, which only `GET /api/events/geojson` uses — and `events` has no localized field, so `all` does nothing there. The collection reads a consumer actually calls documented no `locale` parameter at all: `injectClientReadParameters` injects select, populate, depth, limit and page, and nothing else. So `locale` joins that injected set, carrying the `_status` map contract, and the geojson parameter goes back to naming concrete locales. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QcPzYuzr3bfjA1n7mxL8LQ * docs(api-clients): correct what the migration preserves The contract said "on existing data nothing changes: the migration carried every document's old status into all 19 locales". It carries it into every locale row that exists, and an untranslated locale has none — so the published-only filter, which is SQL and sees rows rather than the English fallback, drops that locale on existing data. Payload's own localizeStatus template behaves the same way: it UPDATEs locale rows, never inserts one. Also records `locale` joining the injected client read parameters. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QcPzYuzr3bfjA1n7mxL8LQ * test(pages): pin what a never-translated locale serves The criterion-8 block covered a locale an editor unpublished, and the fallback case read with overrideAccess, so nothing exercised the published- only clause against a locale that has no row at all. That is the case with the rollout consequence: measured here, a client read at `?locale=de` of an English-only page returns 0 docs while `?locale=en` returns the page. Goes red with `localizeStatus` removed from Pages, as criterion 11 requires — checked by removing the key, not assumed. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QcPzYuzr3bfjA1n7mxL8LQ * fix(access): drop the cross-locale read redaction Ardnived's review on #765: read access to content across locales is not sensitive here — write, edit and delete are what the roles guard — and the filtering is a complication that would cost more going forward. So `withPublishedLocaleRedaction` is gone, and with it the accessPlugin wiring. A `?locale=all` client read now carries every locale's value again, including a locale the editor has unpublished. The per-locale published-only filter still gates an ordinary single-locale read, which is the gate a consumer actually goes through. The spec case that pinned the redaction is inverted rather than deleted, so the next reader meets the decision instead of re-deriving the gap and re-plugging it. The manager cross-locale case goes with it: it read with `overrideAccess: true` and only ever asserted the redaction spared managers. `docs/rules/api-clients.md` states the new contract. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0191944fWtwUR1ZgnYhiCPPd * docs(pages): an unpublished locale 404s by design Ardnived's review on #765 settled the open blocker: a 404 is the right answer when a locale is not published, and an English-only page must not fall back to German. So the migration stays as written — no backfill inserts the 19 missing locale rows, and no consumer restores the fallback. Only the framing changes. `docs/rules/api-clients.md` and the spec comment called the untranslated-locale case a rollout hazard a consumer had to adapt to first. Both now state the decision, so the next reader meets it instead of reading an open question and re-plugging the gap — the same treatment the cross-locale read got in 17f9df0. The assertions are untouched: a never-translated locale is absent from the status map and serves nobody, measured rather than argued. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HY8U5JaE2s2qNefv2a4mFx --------- Co-authored-by: Claude <[email protected]> Co-authored-by: sydevs-bot <[email protected]>
Summary
jsonSchema, so Payload generates a named interface per group and Ajv enforces the shape on write.sy-atlas-configandwm-web-configcarryavailableLocales— a language set gated on that project's translations being published in each one.Changes
Eleven commits, one behaviour each, each separately revertable:
95f6c35— the schema walker and CLDR plural family move tosrc/lib/translations/, gainingexpandPlurals. Three owners read the same schema-to-data-path mapping.892a917—stringsJsonSchemaper leaf group, the hand-rolledvalidatedeleted,strict: trueturning amaxLengthblocking, sub-groups rendering as collapsibles.32e69ba—experimental.localizeStatus,availableLocalesField, both config globals, theclientEnglishFallbackhook,sy-atlas-config.languagesandATLAS_DEFAULT_LOCALESdeleted.e52fb4b— the specs.37a4d11— the migration and regenerated types.d568967— docs.cf7a51b— three defects the review pass found: the publish gate deadlocking English,[]newly accepted, andmergeEnglishwriting through into nested groups.Three answer the adversarial review's five threads:
45513be— the publish gate's read narrows back toselect: { _status: true }, as the ticket specified.d25405d— thePLURAL_CATEGORIESre-export and thestringsJsonSchemabarrel entry go; neither had an importer.dfb8aaf— the REST-read acceptance criterion, which had not shipped.One answers @Ardnived's two:
d887486—availableLocalesFieldloses thesurfaceoption, the one-callermemoKey()helper, and one of its two error-message shapes.admin.descriptionis now required, and each config global writes its own, naming what the field drives there. No behaviour change: the gate, the English exemption, the per-request memo and the skip flag are untouched.Preview
availableLocalesfield — https://sahajcloud-sahajcloud-pr-731.up.railway.app/admin/globals/sy-atlas-configContract impact
src/payload-types.tschanges, andpnpm types:cmscopies it into WeMeditateWeb.SyAtlasConfig.languagesis gone; both config globals gainavailableLocales. No consumer reads either today — WeMeditateWeb'sWEB_CONFIG_SELECT(server/cms-client.ts:178) is include-mode and names neither, so it stays satisfiable againstWmWebConfigSelect<true>. WeMeditateWeb#81 and SahajAtlasWeb#198 are the tickets that adopt the field.…Stringsinterfaces replace the{ [k: string]: unknown } | … | nullunion on every translations group. Additive for a consumer: the old union accepted anything.GET /api/atlas/seoalternatesnarrow toenon deploy until an operator configures the field. See the rollout note below.alternateshas a third consumer, and it changes on this deploy rather than in a follow-up.sydevs/SahajAtlasWordpressincludes/seo.php:154-165prints one<link rel="alternate" hreflang>per entry, on 13 of 29 known client domains. Unlike the two adoption tickets, nothing ships there — it reads the endpoint fresh on every request, so those pages drop from eleven hreflang links to one on deploy, and recover the moment both globals are configured. That makes it a rollout step, not a follow-up ticket.Migration
src/migrations/20260907_213802_translations_localize_status_available_locales.tssy_atlas_config_available_localesandwm_web_config_available_locales(+ enums); dropssy_atlas_config_languages(+ enum); moves_status/version__statusfor both web-project translations globals from the base tables into their_localestables, with the matching indexes.down()restores all three, verified by running it.⚠ Every locale lands as
draft.ADD COLUMN "_status" … DEFAULT 'draft'cannot know which locales were published, because the old column held one value for all of them. Operators publish each locale after the seed, which the rollout requires anyway.⚠ Two lines are not this ticket's.
ALTER TABLE "songs" / "images" ALTER COLUMN "file_metadata" SET DEFAULT '{}'::jsonbis the catch-up #714 flagged and could not generate. Drizzle diffs against the snapshot, so the next migration on this branch necessarily carries it, and hand-editing a generated migration is not allowed. Safe on its own terms: a column default affects future inserts only, andframesandvideosalready carry it.Test results
cf7a51b, the commit before the first review round — Lint, Test & Smoke, and the Railway preview deploy. CI runs the full lane again ond887486.d887486: ✓pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(127 files, 1664 tests)dfb8aaf: ✓available-locales.int.spec.ts(15 cases, up from 13) andtranslations-field.int.spec.ts(21 cases).cf7a51b: ✓ 73 files, 1197 tests. ⚠ It needsVITEST_INT_MAX_FORKS=2on a 4-CPU box — the default of 6 gives nondeterministic failures across unrelated suites, which is how the first run here looked like 52 regressions.d887486. That commit was written in the cloud routine, which has no Postgres —pnpm test:intfails atconnect ECONNREFUSED 127.0.0.1:5432before any suite loads. CI runs it against its ownpostgres:18container. The one assertion that reads the changed error string,available-locales.int.spec.ts:141(/Publish the French translations/), matches the collapsed message unchanged.origin/main's schema, with rows insy_atlas_config_languages— not only on a clean one.migration-validator: 4 pass, 0 fail, 3 warnings (two intended DROPs, and a D1 foreign-key warning predating the move to Postgres).Every new assertion was confirmed failing first, at the site that causes it.
blockingforced tofalseinlengthStatuslength-status['en']fallback dropped fromreadAvailableLocalesanswers English alone for an unconfigured columnObject.hasOwnguard dropped frommergeEnglishnever re-adds a field the document does not haveexpandPlurals: falseinschemaLookupsclient-english-fallbackunpublishedLocalestreats a locale absent from the map as unpublishedjsonSchemaunwired from the JSON fieldtranslations-globalsafterReadhook removed from the atlas globalfills a blank key from English for an API clientreadPublishStatusreading one locale instead of'all'DEFAULT_LOCALEexemption removed from the gateavailable-localestranslations-field+translations-globalsmergeEnglishdoes not mutate a nested group…returns 200 with the stored set for sy-atlas-configThe
locale: 'all'row is the one worth keeping. A single-locale read resolves_statusthrough the English fallback, so an untranslated locale reports itself published and the gate opens for everything.Manual verification
Five things the automated tests here cannot reach — four admin UI, one API:
a11ygroups start collapsed, and the rest open. Save a value in one and reload.strictkey over budget blocks the save — no schema key declaresstrictyet, so this needs one added temporarily to observe.curl '/api/globals/sy-atlas-translations?locale=fr'shows English for blank keys; the same read as a manager does not.Notes for reviewer
draft. So both config globals would have been unsaveable on deploy, with an error telling the operator to publish English, the one locale they cannot deselect. English is now exempt from the gate: it is mandatory rather than chosen, and every other locale falls back to it. The other two:[]was newly accepted (the built-injsonvalidator short-circuits on an "empty" value, and an empty array counts as empty), fixed by composing the built-in rather than going without; andmergeEnglishwrote through into the caller's nested groups, because{ ...doc }is one level deep.availableLocalesisrequired, but adefaultValuenever backfills an existing row — and both production rows exist. So on deploy,GET /api/atlas/seoemitsen+x-defaultwhere it emitted eleven. WeMeditateWeb and SahajAtlasWeb adopt the field in their own PRs, so nothing changes for them until then; the WordPress plugin's 13 client domains change immediately, because they already renderalternates. So: configure both globals promptly after merge, publishing each language's translations first. Nothing else recovers those hreflang links. The ticket decides the['en']fallback itself ("no backfill fromlanguages") and I think it is right — keeping the ten-language fallback would keep promising crawlers pages in nine languages nobody has said are translated, which is the promise this field exists to stop.requiredfield with no stored value. Reads are unaffected —requiredis write-time only — but every write must carryavailableLocales, including a partial one that never mentions it. That brokeseeds/wemeditate/import.tsand two integration suites, all fixed here; check any operator script of your own that writes either global. Selecting English alone always saves, thanks to the exemption above.Effort: Hardticket, at your explicit request. Everything the body specifies is implemented; what no automated assertion covers is listed under Manual verification above, with its reason, rather than left implicit.strictships with no user. No key in anytranslationsSchema.jsondeclares it. It is the mechanism the ticket asked for; turning an existing advisory limit strict can make keys already over it unsaveable, which is why none were converted here.translationsField.tshalf of refactor(fields): declare a jsonSchema on every JSON column, and delete the aliases they replace #714's "two definitions to reconcile" note is resolved here.logField.tsstill waits on feat(api)!: unify public intakes on the form-submissions pipeline #695.Detail
Why the JSON columns'
validatecomposes rather than replaces. Supplying one replaces Payload's built-injsonvalidator (dist/fields/config/sanitize.js), and that built-in is the one bound tojsonSchema— so a hand-rolled rule switches the whole schema off silently. The one here adds a single check the built-in cannot reach (an array, which it short-circuits past as "empty") and then delegates.translations-field.int.spec.tsasserts both halves, andsrc/globals/AGENTS.mdnow carries it as a rule.Why every property is optional. Payload validates a stored column on every save of its document, including a save that never touched translations. A
requiredkey would strand every locale written under an earlier shape.maxLengthis emitted only for astrictkey for the same reason — an advisory limit that suddenly blocked would break keys already over it.Why only standard keywords may appear. Payload runs
new Ajv(), whose strict mode throws on an unknown keyword at validate time, not at boot (dist/fields/validations.js:166-215). A leakedplural,screenshotorstrictwould surface as a failed save in production rather than a failed build, so a spec asserts the emitted schema carries exactly$id,title,type,additionalProperties,properties.Why the schema's
urinever dials out. The same validator fetchesurionly whenschemais absent. Both are always passed together here.Why the collapsible change needs no migration. A tab with sub-groups still wraps them in a Payload
groupnamed after the tab, so the API path istab.sub.keyand the column is<tab>_<sub>either way. Only the innertabsfield became onecollapsibleper sub-group.wm-app-translationsreads and saves exactly as before, whichtranslations-globals.int.spec.tsasserts.Why the English merge is scoped to
clients. A manager editing the global must keep seeing which keys are empty — merging English in would make the admin claim every key is translated, and the WeMeditate App status report would agree. It also leavesresolveEmailStringsuntouched, which reads as a manager or with no user, soEMAIL_STRING_DEFAULTSstays necessary.docs/rules/email.mdrecords that the two are complementary, not duplicated.Why the merge never re-adds an absent field. An include-mode
selectstrips a field from the document entirely. Re-adding it would return a field the caller explicitly excluded and makeselectunusable against these globals.mergeEnglishguards onObject.hasOwn, and the guard is spec'd by reintroducing its absence.Why
unpublishedLocalesalso reads a plain string. A global withoutlocalizeStatusstores one status for everything, so the answer is all-or-nothing. That keepsavailableLocalesFieldreusable onwm-app-configbefore that global opts in.Why
availableLocalesFieldtakes nosurface. It once interpolated one into a defaultadmin.description. Generic help text is the weaker half of that pair — it cannot say what the field drives — sodescriptionis required instead, and each global writes its own. (@Ardnived's review.)Two findings from the security pass, neither introduced here, both worth a ticket.
access.readVersionsis undefined on every global and collection, and Payload'sexecuteAccessreturnstruefor any authenticated user when the access function is undefined — so a published client API key can read unpublished drafts throughGET /api/globals/<slug>/versions. That predates this PR (both globals already haddrafts: true), but it means "published" is not yet a read boundary, which is the assumptionavailableLocalesis built on. Separately,localeIsolatedReqcopiesreqshallowly, soreq.querystays shared andcreateLocalReqwritesdepthonto the caller's query object; nothing reads it today, but it is the same aliasing class that helper exists to prevent.Ajv is not a top-level dependency here, so the schema's enforcement is proven by real writes in the integration lane rather than by compiling the schema in a unit test.
The
wm-web-configpositive case asserts thatavailableLocalesstops objecting, not that the write succeeds — the global has four other required fields, and filling in a home page, audiences and two page lists would test Payload'srequiredrather than this field.Payload's own
localizeStatus.updata migration is not used. It cannot coexist with the generated DDL, it takes its locale list fromfilterAvailableLocales({ req })—['en']for a user-less migrationreq— and it leavesVARCHARcolumns without the index the snapshot expects.What the gate's read costs, now that
selectis back. OnefindGlobalper validation event on those two globals, narrowed to the_statuscolumn. It is memoized per request, so a save is one read. The event is not only a save:@payloadcms/ui'saddFieldStatePromisecallsvalidatewithevent: 'onChange', so the admin repeats it on every form-state rebuild of the config global. Withoutselectthat was a full localized read of the largest global — 12 JSON columns × 19 locale rows — per interaction.How the migration was generated.
pnpm db:migrations:createstops on drizzle's create-vs-rename prompt, and.claude/skills/payload-cli/interactive.pyonly matches the column form of that prompt, so it hung on the first enum one. Generated with a widened copy of that driver, answering create everywhere — a "rename" would have carriedsy_atlas_config_languages'{ code }rows into a column storing bare locale codes. Worth folding the wider regex back into the committed driver in a follow-up; it is under.claude/, which an unattended run must not write to.Closes #705
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01ABp2XiB7GQSFE8jVPWR65J