Repository navigation
Add a success override to the primary-data endpoints - #70
Merged
thomasfosterau merged 1 commit intoAug 16, 2026
Merged
Conversation
`get`, `list`, `create` and `update` bound their response unconditionally to the resource's `document()` / `collection()`, so the only shape a handler could answer with was the resource itself, and `GetConfig` / `ListConfig` / `WriteConfig` had no seam for anything else. Apis whose assembler emits a narrower shape than the resource's decoded types have one to declare: a wire variant whose `links.self` is a plain string, where the resource's own `Document.Link` decodes an absolute reference to a `URL` and hands every generated-client call site the wrong type. Add an optional `success` schema — any `Schema.Top`, like `payload` — to all four constructors, defaulting to today's documents. An override is served as `application/vnd.api+json` at the same status as before (201 for `create`), and the document envelope is untouched, so `Handlers.offsetPaginationLinks` still applies to an overridden `list`. Thread it through `Endpoint.resource` / `Group.resource`'s per-endpoint config. Only the response changes; path, params, query parameters, request payload, errors and middleware are untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019cwVHMAmfnFV1PQzuXaNcA
thomasfosterau
deleted the
claude/effect-jsonapi-success-override-t7bf2w
branch
September 15, 2026 07:11
8 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Endpoint.get,list,createandupdatebound their response unconditionally to the resource'sdocument()/collection(), so the only shape a handler could answer with was the resourceitself, and
GetConfig/ListConfig/WriteConfigcarried no seam for anything else — verifiedagainst
mainat c5f7064 (published 0.9.0).The failing case
A consumer whose resources declare
links.selfasSchema.URLFromString— as the package's ownDocument.Linkdoes, decoding an absolute reference to aURL— but whose assembler stringifiesevery link before the document leaves the server needs a wire variant of the resource in its
success documents: plain-string link members. With the success schema hard-bound to
resource.document(),links.selfdecodes asURLwhere every generated-client call site consumesa
string, and there is no seam to supply the wire variant.The change
An optional
successschema on all four constructors, defaulting to today's documents, mirroringthe two escape hatches already accepted —
WriteConfig.payload(#61) andDeleteConfig.success(#68). Any
Schema.Topis accepted, likepayload— not just document-shaped derivations.Threaded through
Endpoint.resource/Group.resource's per-endpoint config, so a generated groupcan adopt the wire variant without being spelled out by hand:
An override is served as
application/vnd.api+jsonlike every other body in the package, at thesame status as before (201 for
create). The document envelope is untouched, soHandlers.offsetPaginationLinksstill populates the top-levellinksof an overriddenlist. Onlythe response changes — path, params, query parameters, request payload, errors and middleware are
unaffected, and
payloadandsuccesscompose independently.Surface
Endpoint.get/list/create/update:readonly success?: Schema.Top(a new trailingSuccesstype parameter, defaulting to the resource's document / collection at the effectivedocument
meta).GetConfig,ListConfig,WriteConfig:readonly success?: Schema.Top,@since 0.10.0.resource.document()/resource.collection().Tests
12 new tests in
src/Endpoint.test.ts, in the shape of the #61 / #68 suites:links.selfstill decodes to aURLforget/create/update/list, both hand-written and viaEndpoint.resource;links.selfto a plainstring, at the endpoint and throughEndpoint.resource/Group.resource;Article.document()/Article.collection(), and thatpayloadandsuccesscompose;get/list/create: the client receiveslinks.selfas astring(
expectTypeOf(...).toEqualTypeOf<string | undefined>()),listcarriesHandlers.offsetPaginationLinksoutput in its top-levellinks, andcreatestill answers 201;pnpm check(typecheck, lint, format, 436 unit tests + the three example suites) andpnpm docgenpass. Changeset:
minor. README gains an "Overriding the success document" section.🤖 Generated with Claude Code
https://claude.ai/code/session_019cwVHMAmfnFV1PQzuXaNcA