Skip to content

fix(Group, Assemble, ResourceHandlers): type a flat group's include surface end to end (#595) - #599

Merged
thomasfosterau merged 3 commits into
trunkfrom
issue-595-flat-included-services
Nov 12, 2026
Merged

thomasfosterau merged 3 commits into
trunkfrom
issue-595-flat-included-services

Conversation

@thomasfosterau

@thomasfosterau thomasfosterau commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #595 (from preferenceflow#382 phase 2), including the orchestrator's 03:30Z addendum.

1. Group.flat / flatReadOnly kept unknown services

Root cause. The documents were built with Endpoint.ResourceDocument(options.resource, { included }), where included = options.include?.included. Inferring Included from that expression while Surface was still generic widened it to Schema.Top, whose DecodingServices are unknown. Every endpoint's success, and every typed Client.make method, then required unknown. lazyTarget back-references aren't the cause: probed in preferenceflow at 779268c, the resources and Include.make(...).included all have never services.

Fix. flatWire passes the surface's included as an explicit type argument (SurfaceIncluded<Surface>). With no surface that is never, which Endpoint.ResourceDocument / FlatCollectionDocument read as Schema.Top (IncludedOrNone), so a surface-less group's types are unchanged.

2. Handlers couldn't satisfy the precise included (the addendum)

With a precise success schema, ResourceHandlers.readOnly / make output (included?: ReadonlyArray<WireResource<ResourceLike>>) no longer fit: TS2322, as preferenceflow saw in 11 AEC groups.

  • Assemble.ResourceDocument / CollectionDocument / UnpaginatedCollectionDocument gain a trailing I (the included members' type, default ResourceLike).
  • Assemble.resource / collection / unpaginatedCollection set I from targets through the new Assemble.TargetsIncluded<Targets>: what the registry's loaders return (Handlers.IncludeTargetResource), or never with no registry, since nothing can be included then. A registry whose loaders' types aren't visible (annotated, not satisfies) keeps ResourceLike. CollectionOptions / UnpaginatedCollectionOptions gain a trailing X for caller-resolved extras.
  • ResourceHandlers' list / get use TargetsIncluded<Targets>. create / update use never, because a write assembles with no walk.
  • No new cast: Assemble already asserts its built document as D at one seam, and only the type it names changed.

Tests

test/include-services.types.ts covers the following; on trunk, all of these fail.

  • A ref-typed back-reference.
  • flat, flatReadOnly and hiddenWrites success schemas with never services.
  • A Client.make program typed Effect<void, unknown, HttpClient>.
  • ResourceHandlers.readOnly(...) over a flatReadOnly with a surface, and ResourceHandlers.make(...) over a flat with a surface, each satisfies Registry.FamilyFor<group>.

test/assemble-collection.types.ts's exact-type assertions now name I = never for calls without a registry.

Verification

  • pnpm install --frozen-lockfile: pass
  • vp run build: pass
  • vp check: pass, 0 errors (4347 warnings, the trunk baseline)
  • vp run check (--concurrency-limit 1): pass
  • vp run -r test:unit: pass
  • vp run docgen: pass
  • vp run test:coverage, then vp exec fallow audit --base origin/trunk: pass. These ran before the final rebase; gates 1–6 were re-run after it.

Changeset

  • .changeset/flat-included-services.md, minor: narrower, correct published types and a new export (Assemble.TargetsIncluded). It includes a migration note: drop the Codec<…, never, never> / handler-output casts, and declare registries with satisfies Handlers.IncludeTargets.

Notes

  • For preferenceflow: packages/api/src/resource.ts must stop erasing through Include.SurfaceFor<R>. Make it generic over the surface, or move it onto Group.flat. The registry must be declared with satisfies Handlers.IncludeTargets for the handlers' included to be precise.
  • A document assembled without a registry now types included?: ReadonlyArray<never>, which is still assignable to the old ReadonlyArray<WireResource<ResourceLike>>.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y5G6PMempKsgjiV1NDcCJY

@changeset-bot

changeset-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 10bc700

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@thomasfosterau/effect-jsonapi Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

#595)

`Group.flat` / `flatReadOnly` inferred the documents' `Included` from
`options.include?.included` while `Surface` was still generic, which
widened it to `Schema.Top`: every endpoint's decoding services became
`unknown`, and so did a typed client's. Pass the surface's `included`
as an explicit type argument. `test/include-services.types.ts` pins it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y5G6PMempKsgjiV1NDcCJY
…stry (#595)

Assemble's documents gain a trailing `I` (the `included` members' type,
default `ResourceLike`); `resource` / `collection` /
`unpaginatedCollection` set it from `targets` through the new
`Assemble.TargetsIncluded` (what the loaders return; `never` with no
registry), and `ResourceHandlers` uses it for `list` / `get` (`never` for
the writes). A family's handlers then satisfy a flat group whose
`included` is its surface's precise union, without a cast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y5G6PMempKsgjiV1NDcCJY
@thomasfosterau
thomasfosterau force-pushed the issue-595-flat-included-services branch from 6fc15c6 to 10bc700 Compare November 12, 2026 03:55
@thomasfosterau thomasfosterau changed the title fix(Group): keep a flat group's include surface in its success schemas (#595) fix(Group, Assemble, ResourceHandlers): type a flat group's include surface end to end (#595) Nov 12, 2026
@thomasfosterau
thomasfosterau merged commit c5e5ab9 into trunk Nov 12, 2026
4 checks passed
@thomasfosterau
thomasfosterau deleted the issue-595-flat-included-services branch November 12, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include.Surface["included"] and the flat groups' included slot widen decoding services to unknown

2 participants