Skip to content

refactor(types): read the content block types from SahajCloud's generated schema - #294

Merged
sydevs-bot merged 6 commits into
mainfrom
claude/refactor-generated-block-types
Nov 20, 2026
Merged

sydevs-bot merged 6 commits into
mainfrom
claude/refactor-generated-block-types

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Nothing changes for a visitor or an editor. The JavaScript that lib/content-blocks.ts emits is identical to main's. The change is to types only.

For a developer: the field types of the custom rich-text blocks (text box, quote, button, gallery, showcase, subtle system, splash, layout and table of contents) used to be copied by hand from SahajCloud into *BlockFields interfaces. pnpm types:cms already generates each one as a *Block interface in server/payload-types.ts, so every reader now imports that interface directly and the hand copies are gone. When upstream renames or removes a block field, every converter that reads it fails to compile.

Findings addressed

F10a: the block field types were hand-mirrored on a false premise.

  • The false premise. lib/content-blocks.ts:5-9 on main said the block shapes are "not in the generated payload-types.ts". In fact server/payload-types.ts exports all ten of them (TextBoxBlock … SplashBlock), and nothing imported them.
  • Every consumer reads the generated interface. blockConverters.tsx casts node.fields to TextBoxBlock, QuoteBlock, ButtonBlock, ImageGalleryBlock, LayoutBlock, TableOfContentsBlock, ShowcaseBlock, SubtleSystemBlock and SplashBlock, imported from server/payload-types. The helpers in lib/content-blocks.ts take the same interfaces. LayoutBlock arrives as LayoutBlockSchema in the two files whose own molecule owns the unprefixed name.
  • TocHeading is gone. The generated TableOfContentsHeadings is that array, so TableOfContents takes it as its headings prop.
  • ShowcaseRelationTo is dropped. It had no consumer on main or on any open claude/* branch.
  • Two names stay, because the generated schema leaves the shape anonymous and there is nothing to import: ShowcaseItem and LayoutItem, both indexed straight out of the generated interface in lib/content-blocks.ts.
  • SUBTLE_SYSTEM_NODE_IDS was Record<string, string>, so an upstream rename resolved to undefined and silently dropped that node from the chart. It now satisfies Record<SubtleSystemField, string>, where SubtleSystemField is keyed off the generated block, so a rename, an addition or a removal fails the build.
  • server/AGENTS.md. Lines 150-154 repeated the same premise ("generates collection types only"). They now say the command generates the collection, global and block schema.

ContentIndexBlockFields is the one type that is not a generated block. The server's pre-resolve pass in +data attaches resolvedItems and resolvedTracks, which the editor never stores, so this interface is app-side by nature. Its stored half stays hand-written while #293 edits the same lines, under a shortcut: line at lib/content-blocks.ts and the type test ContentIndexBlockFields › restates exactly the stored fields the SahajCloud schema defines. That test asserts Omit<ContentIndexBlockFields, `resolved${string}`> equals ContentIndexBlock minus its envelope, and tsc enforces it both ways. I checked that tsc fails on that line, and only that line, in three cases: 'albums' added to the generated type union, a moodFilters field added upstream, and apiEndpoint removed upstream.

Where the generated and hand-written types disagreed. I checked each case against production before letting the generated type win: 66 pages, all 16 locales, read at depth 0 and at the site's depth-3 populate.

  1. textbox.image and all 12 subtle-system relationships were optional by hand, but the schema requires them. All 55 production text boxes and the only subtle-system block carry them. The converters keep their runtime guards, because live preview renders unsaved blocks. The subtleSystemItems fixture now names all 12 relationships, with bare ids for unpublished pages. Its expectations are unchanged.
  2. table-of-contents.headings lost | null. All 9 production blocks store an array. Entries gain [k: string]: unknown; production entries hold only slug, text and level.
  3. textbox.textPosition, textbox.textColor and the layout item id gained | null. Production always has strings, and the converters already read them with ??.
  4. Showcase items are now the generated discriminated union. Production has zero showcase blocks, so this rests on the schema alone.
  5. The text box also carries the generated importData field now. All 55 production text boxes have it, and no reader uses it.
  6. Content-index matches: pageFilters are strings, and userChoiceFilters and songFilters are numbers at both depths.

Not in this PR

  • Deriving ContentIndexBlockFields. It should extend ContentIndexBlock once feat(components): a MeditationLibrary for the meditations index block #293 lands, and the shortcut: line marks that. Until then the type test keeps the two in step, including after that PR merges: the resolved${string} key pattern filters out its resolvedMoods.
  • Narrowing populated documents. The generated ShowcaseBlock, SubtleSystemBlock, TextBoxBlock and SplashBlock still claim full Page, Image and Meditation documents, while PAGE_POPULATE narrows them. The hand-written types made the same claim, so this is not a regression, and it is out of scope here.
  • No new translation keys are needed.

Reconciled with open PRs

I ran git merge-tree of this branch against all 20 other open PRs, and type-checked the merged tree where one touches the same files.

origin/main is merged into this branch, cleanly, so the gate below ran on the merged tree.

Test results

I ran the gate, .claude/skills/pr-prep/check.sh, on the pushed head c0c22b6.

Check Result
Lint 0 errors, 1087 warnings, all pre-existing
tsc passed
Vitest 140 files, 1328/1328 tests passed
pnpm build not run (this is not a BUILD bundle)

The warnings in the touched files are on lines this PR does not change: the prettier warnings in lib/content-blocks.test.ts, the perfectionist/sort-jsx-props one in blockConverters.tsx, and the unused useColumnsOnDesktop in LayoutBlock.tsx.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Mg9rjX2WYRPpjwPSxNWYFL

…ck interfaces

lib/content-blocks.ts hand-mirrored the field shapes of every custom
Lexical block, on the premise that payload-types.ts did not generate them.
It does: TextBoxBlock, LayoutBlock, ImageGalleryBlock, ShowcaseBlock,
ButtonBlock, QuoteBlock, TableOfContentsBlock, ContentIndexBlock,
SubtleSystemBlock and SplashBlock are all exported there, and nothing read
them. So `pnpm types:cms` could change a block upstream and no converter
would notice.

Each `*BlockFields` name is now an alias over the generated interface, minus
the `id`/`blockName`/`blockType` envelope, and `ShowcaseItem`,
`ShowcaseRelationTo`, `LayoutItem` and `TocHeading` are indexed out of
them, so every existing import keeps compiling. ContentIndexBlockFields
extends the generated block and keeps only its `type` union restated,
because #293 widens that line; `extends` already refuses a member the
schema lacks.

Where the two disagreed, the generated type was checked against
production (66 pages, every locale, depth 0 and the site's depth-3
populate) before it won:

- textbox `image` and all twelve subtle-system relationships were optional
  and nullable by hand; the schema requires them, and every stored block
  carries them. The converters keep their runtime guards, since live
  preview renders a block before it is saved.
- table-of-contents `headings` lost `| null`; every stored block has an
  array. Its entries gain the generated `[k: string]: unknown`.
- textbox `textPosition`/`textColor` and a layout item's `id` gained
  `| null`, which the converters already absorb with `??`.
- showcase entries become the generated discriminated union. No showcase
  block exists in production, so that one rests on the schema alone.
- splash `textColor` is authored upstream now, so the note saying it was
  not goes with the hand-written interface.

The subtle-system test fixture now names all twelve relationships, as the
schema requires.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
…ader handles

ContentIndexBlockFields restates `type` instead of deriving it, and
`extends` only checks one direction: the restated union may not name a
type the schema lacks. A type `pnpm types:cms` adds upstream would pass
that check and reach neither the converter nor QUERY_BY_TYPE. Adding
'albums' to the generated union makes this assertion the only error tsc
reports.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
…rges clean

Deriving ContentIndexBlockFields from the generated block put an `extends`
header and five deleted lines right beside the `type` union #293 widens,
so the two branches conflicted in lib/content-blocks.ts. The interface body
goes back to main's text, with a `shortcut:` to derive it once #293 lands.

The type test now compares the whole stored shape both ways:
`Omit<ContentIndexBlockFields, resolved*>` must equal the generated block
minus its envelope. A field or content-index type the schema adds, drops
or retypes fails tsc, which the `type`-only check missed for fields. The
`resolved${string}` key filter leaves #293's resolvedMoods out, so the
guard holds after that merge too.

Also drops the dead `Ref<T>` export (no reader on main or any open
branch), narrows the header's claim to what a derived type really catches,
and corrects server/AGENTS.md: `pnpm types:cms` generates blocks and
globals as well as collections.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-web c0c22b6 Commit Preview URL

Branch Preview URL
Nov 20 2026, 12:02 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-design 3811d5b Commit Preview URL

Branch Preview URL
Nov 19 2026, 11:59 PM

Comment thread lib/content-blocks.ts Resolved
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 19, 2026
@sydevs-bot

sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 23:49Z address-review · attempt 1 · session · done
  • 23:49Z address-review · attempt 1 · session

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

@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 19, 2026
sydevs-bot and others added 3 commits November 19, 2026 23:52
The `*BlockFields` aliases in `lib/content-blocks.ts` renamed interfaces
`payload-types.ts` already exports, so a reader had to follow one more hop
to learn what a converter casts to. Every consumer now imports the
generated `*Block` interface itself.

`TocHeading` goes the same way: the generated `TableOfContentsHeadings` is
that array, and `TableOfContents` takes it. `ShowcaseRelationTo` had no
consumer and is dropped.

Two names stay, because the generated schema leaves the shape anonymous and
there is nothing to import: `ShowcaseItem` beside the helper that maps it,
and `LayoutItem` in `LayoutBlock`, whose props declare it. Both are indexed
straight out of the generated interface.

`SUBTLE_SYSTEM_NODE_IDS` was `Record<string, string>`, so a renamed
relationship silently resolved to `undefined` and dropped its node. It now
satisfies `Record<SubtleSystemField, string>`, which fails the build
instead.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjX2WYRPpjwPSxNWYFL
Payload leaves a `layout` block's array member anonymous, so no consumer can
import that shape from `payload-types.ts`. Moving the name into the component
would have broken every open branch that reads it for nothing in return.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjX2WYRPpjwPSxNWYFL
@sydevs-bot sydevs-bot changed the title refactor(types): derive the content block field types from SahajCloud's generated schema refactor(types): read the content block types from SahajCloud's generated schema Nov 20, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the one open thread, on a freshly merged main.

Adopted — don't re-export under new names. The nine *BlockFields aliases and TocHeading are gone; every reader imports the generated *Block interface from server/payload-types. ShowcaseRelationTo had no reader and is dropped. ShowcaseItem and LayoutItem stay, because Payload leaves those array members anonymous.

Two things that fell out, both in the refreshed body:

Gate on c0c22b6: lint 0 errors, tsc passed, 1328/1328 tests.

🤖 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 Nov 20, 2026
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 20, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Nov 20, 2026
@sydevs-bot sydevs-bot moved this from Awaiting to Pending in SYDevelopers Technical Roadmap Nov 20, 2026
Merged via the queue into main with commit c3e2523 Nov 20, 2026
41 checks passed
@sydevs-bot
sydevs-bot deleted the claude/refactor-generated-block-types branch November 20, 2026 00:30
@sydevs-bot sydevs-bot moved this from Pending to Done in SYDevelopers Technical Roadmap Nov 20, 2026
sydevs-bot pushed a commit that referenced this pull request Nov 20, 2026
…ofix

`lib/content-blocks.ts` conflicted. #294 replaced the local
`SplashBlockFields` with the generated `SplashBlock`, and this branch had
only re-wrapped the old cast. The local type no longer exists, so main's
line stands.

The 24 files main brought in need no second mechanical commit: `pnpm lint`
exits 0 on the merge as it stands.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjXX3XS7FBnDYruefGT
sydevs-bot pushed a commit that referenced this pull request Nov 20, 2026
#294 replaced the hand-written `*BlockFields` interfaces with the generated
`*Block` ones, so the ornament work now reads `TextBoxBlock` from
`server/payload-types`. The `blockType` envelope comes with that interface,
so `renderedTextBox` no longer intersects one in, and the decoration
fixtures name it.

Both sides' additions to the converter's import block and its `textbox`
converter are kept: main's generated type, this branch's `parent` read and
`textBoxDecorationAt` call.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWFS9Qzu3VyRSDarNq
sydevs-bot pushed a commit that referenced this pull request Nov 21, 2026
main's only textual conflict was blockConverters.test.tsx's import block.
main dropped `enT`, because #269 removed the ornate sidetext its one caller
asserted. This branch widened the markup-helper import beside it. Both are
kept: the helpers stay, `enT` goes, and nothing in the merged file reads it.

The silent conflict was in lib/content-blocks.ts. main (#294) deleted the
hand-written `*BlockFields` interfaces and moved every consumer to the
generated `*Block` types, while this branch added `splashTitle` over
`Pick<SplashBlockFields, 'layout' | 'title'>`. git merged both cleanly into
a file naming a type that no longer exists. `splashTitle` now takes
`Pick<SplashBlock, 'layout' | 'title'>`, the same move main made for
`splashSurface` and `getLeadSplash`. The generated interface carries both
fields with the same union, so the behaviour is unchanged.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVNeCVXMGgzzZjZ4n9
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.

3 participants