Repository navigation
Add write status/media-type overrides and a get query override - #72
Merged
thomasfosterau merged 3 commits intoAug 16, 2026
Merged
Conversation
`Endpoint.create` stamped `asJsonApi(success, 201)` unconditionally, and `asJsonApi` pipes `HttpApiSchema.status` last, so even a caller-supplied `success` was re-stamped 201. `WriteConfig` carried `name` / `path` / `errors` / `meta` / `payload` / `success` and no `status`, where `DeleteConfig` has had one since 0.9.0. An api whose whole write surface answers 200 — or that accepts a write for later application and answers 202 — could not adopt the constructors without a wire change on every create endpoint. Add an optional `status` to `Endpoint.create` and `Endpoint.update`, defaulting to today's 201 and 200 whether or not `success` is given, and thread it through `Endpoint.resource` / `Group.resource`'s per-endpoint `create` / `update` config. `update` takes it for symmetry: its default is the status `HttpApi` gives any success schema carrying a body, so passing nothing is exactly today. Only the status changes; path, params, request payload, success schema, errors and middleware are untouched. Regression tests drive a real web handler and pin 201/200 for both constructors and for the generated group, with and without a `success` override. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NcH6RU1HzkH6U665DjDQug
`Endpoint.create` and `Endpoint.update` wrapped their `payload` — the override included — in `asJsonApi`, so the router's *request* registration was always `application/vnd.api+json` with no way out. Effect's router matches an incoming `Content-Type` against that registration and answers 415 on a mismatch, so an api whose host enforces JSON:API §6 at its own seam and then dispatches writes to the router relabelled `application/json` had every package-built write rejected before a handler saw it — the situation `Middleware.ContentNegotiationPassthrough` already exists for, on the request half rather than the negotiation half. Add an optional `payloadMediaType` to both constructors, defaulting to today's JSON:API media type, and thread it through `Endpoint.resource` / `Group.resource`'s per-endpoint `create` / `update` config. `asMediaType` in `internal/media.ts` is the seam; everything the package emits itself still goes through `asJsonApi`, so no other body moves. Only the request registration changes: the payload schema, the response media type, path, params, errors and middleware are untouched — and the registration moves rather than widens, so an api that opts in is stating which label its host dispatches. Round-trip tests drive a real web handler at both labels and pin the vnd.api+json default, for the constructors and the generated group. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NcH6RU1HzkH6U665DjDQug
Two halves of the same gap on the read path. `Query.schema` declared `include`'s wire form as `Schema.optionalKey(Schema.String)`, so the repeated-key spelling `?include=a&include=b` — which `UrlParams.toRecord` decodes to an array — failed to decode and answered 400, while `?include=a,b`, which denotes the same set, answered 200. JSON:API treats the two spellings as equivalent, so that was a bug in its own right: identical requests answered differently. The flat leaf is now a `Repeatable` codec accepting either, joining an array back to the canonical comma form the item codec already splits. Encoding still emits the single comma form, so nothing a client is handed changes shape, and an unknown or unlisted path is still the 400 it was in either spelling. `sort` and `fields[TYPE]` keep their single-string wire form — the failing case is `include`, and widening the rest is a wire-contract change nobody has asked for. `Endpoint.get` gains the `query` override `Endpoint.list` has carried since 0.9.0: any `Schema.Top`, defaulting to the composed `include` / `fields` parameters, with those options ignored once it is given. Threaded through `Endpoint.resource` / `Group.resource`'s per-endpoint `get` config, with `GetConfig.query` alongside `ListConfig`'s. `get`'s type parameter list gains `QuerySchema` before `Success`, mirroring `list`. Only the query changes; the `:id` path param, success document, errors and middleware are untouched. Regression tests pin the composed default for both spellings and drive a real web handler over `?include=a&include=b`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NcH6RU1HzkH6U665DjDQug
thomasfosterau
deleted the
claude/effect-jsonapi-handler-blockers-so173v
branch
September 15, 2026 07:11
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.
Closes the three gaps blocking the downstream consumer's handler-layer adoption, recorded as blockers E, F and G in thomasfosterau/website#1274's Phase 1 verdict (2026-08-16). One commit per ask, three
minorchangesets, so the release lands as 0.11.0 — the@sincetags on the new surface say0.11.0.All three were re-verified as still present against
main(cd0d517) before implementing — the verdict inspected published 0.10.0, and nothing since touched them. Measured, not inferred:cd0d517Endpoint.create(Article, { success: … })→ success statuses[201](the caller's schema re-stamped)POST /articleswithContent-Type: application/json→ 415 Unsupported content-type;application/vnd.api+json→ 201include: ["author","author"]→ decodeFailure;"author,author"→SuccessEach is opt-in and defaults to today's behaviour, so a
^0.10.0→^0.11.0bump is a no-op until a call site chooses to use one. Every ask carries a regression test pinning the default.1.
statusonEndpoint.create/Endpoint.update— blocker EcreatestampedasJsonApi(success, 201)unconditionally, andasJsonApipipesHttpApiSchema.statuslast, so even a caller-suppliedsuccesswas re-stamped 201.WriteConfigcarried nostatus, whereDeleteConfighas had one since 0.9.0.Defaults to 201 for
createand 200 forupdate, whether or notsuccessis given.updatetakes it for symmetry — its default is the statusHttpApigives any success schema carrying a body, so passing nothing is exactly today. Only the status changes; path, params, payload, success schema, errors and middleware are untouched.2.
payloadMediaTypeonEndpoint.create/Endpoint.update— blocker FBoth constructors wrapped their
payload— the override included — inasJsonApi, so the router's request registration was alwaysapplication/vnd.api+jsonwith no seam. Effect's router matches an incomingContent-Typeagainst that registration and answers 415 on a mismatch, so a host that enforces §6 at its own seam and then hands the router a write relabelledapplication/jsonhad it rejected before any handler saw it.The registration moves rather than widens, so opting in is a statement of which label the host dispatches. Only the request registration changes: the payload schema, the response media type, path, params, errors and middleware are untouched. Pair it with
Middleware.layerHostNegotiated, or the package's own §5 check rejects what the host admitted — the request-half counterpart to the negotiation halfContentNegotiationPassthroughalready covers.asMediaTypeininternal/media.tsis the seam; everything the package emits itself still goes throughasJsonApi, so no other body moves.3. Repeated
?include=keys, andGetConfig.query— blocker GBoth halves of the ask, since they are the same gap on the read path.
The include parameter is widened, no opt-in.
Query.schemadeclaredinclude's wire form asSchema.optionalKey(Schema.String), so?include=a&include=b— whichUrlParams.toRecorddecodes to an array — answered 400 while?include=a,b, denoting the same set, answered 200. That is a spec bug in its own right: JSON:API treats the two spellings as equivalent, so identical requests were answered differently. The flat leaf is now aRepeatablecodec accepting either and joining an array back to the canonical comma form the item codec already splits. Encoding still emits the single comma form, so nothing a client is handed changes shape, and an unknown or unlisted path (including under a constrainedpathsallow-list) is still the same 400 in either spelling.sortandfields[TYPE]deliberately keep their single-string wire form: the failing case isinclude, and widening the rest is a wire-contract change nobody has asked for. Say the word and they can follow.Endpoint.getgainsquery, the overrideEndpoint.listhas carried since 0.9.0 — anySchema.Top, defaulting to the composedinclude/fieldsparameters, with those options ignored once it is given:Only the query changes; the
:idpath param, success document, errors and middleware are untouched.One type-level note:
Endpoint.get's type parameter list gainsQuerySchemabeforeSuccess, mirroringlist's order. That is visible only to code instantiatingtypeof Endpoint.get<…>explicitly — never to a normal call site, where the options are inferred.Symmetry
This is the same escape-hatch shape the package has now accepted four times, applied to the endpoints that still lacked it:
WriteConfig.statusDeleteConfig.status(#68)GetConfig.queryListConfig.query(#68)WriteConfig.payloadMediaTypeWriteConfig.payload(#61) /ContentNegotiationPassthrough(#61), on the request halfwith the
successoverrides (#70) as the fourth. Each is opt-in, each defaults to today's behaviour, each is threaded throughGroup.resource's per-endpoint config.Tests
pnpm run checkgreen locally — 467 package tests plus the three example suites (39 / 36 / 33). The new coverage is on the wire wherever the wire is what changed:successoverride) and 200/202 with it, for the constructors and forGroup.resource.vnd.api+jsonand 415sapplication/json, the override does the reverse, and the response media type staysvnd.api+json.?include=author&include=commentsand 400 for?include=author&include=nope.getquery — the composed default, the replacement, the feature options being ignored, the type-level identity, and bothEndpoint.resourceandGroup.resourcethreading.Generated by Claude Code