Skip to content

feat(Negotiation): the JSON:API representation and refusal mapping for a generic negotiator (#577) - #580

Merged
thomasfosterau merged 1 commit into
trunkfrom
issue-577-jsonapi-representation
Nov 12, 2026
Merged

thomasfosterau merged 1 commit into
trunkfrom
issue-577-jsonapi-representation

Conversation

@thomasfosterau

Copy link
Copy Markdown
Owner

Summary

Part of #577. This adds the JSON:API half that sits on top of effect-ext's media-type-agnostic Negotiate (thomasfosterau/effect-ext#70, PR effect-ext#94). website's front door and gardeneria#1459 need it.

  • Negotiation.representation({ extensions?, servesPath? }) returns the JSON:API Representation: mediaType: "application/vnd.api+json", the optional servesPath, and acceptsParameters, which applies JSON:API §5's rule. Only ext and profile are allowed, and every ext URI must be declared. The predicate is internal/media's parametersAreAcceptable, the same one Middleware.contentTypeIsAcceptable / acceptIsAcceptable use. extensions defaults to none, so an api with no extension refuses every ext, as §5 requires.
  • Negotiation.toApiError(outcome) maps the negotiator's NotAcceptable refusal of the JSON:API representation to ApiError.NotAcceptable (406) and its UnsupportedMediaType refusal to ApiError.UnsupportedMediaType (415). Selected, Fallback and a refusal of another representation (a Markdown alternate) all return Option.none().
  • Typed structurally (Parameterised, Representation, Outcome). effect-ext's Mime.MimeType and Negotiate.Negotiation already satisfy these types, so this package doesn't import Negotiate. That keeps the entry-points effect-ext allow-list unchanged, and a /Negotiate import there would have been the cycle Add a success override to the primary-data endpoints #70 removes. The tests feed real effect-ext 0.1.0 MimeType.parse output.

Still open on #577, waiting for effect-ext's next minor

effect-ext 0.2.0, published today, is not it: it still has the old Negotiate and the optional peer on this package.

  • End-to-end tests through negotiateRepresentation. The 406/415 cases from effect-ext's old tests/web/negotiate.test.ts are ported here at the parameter rule they reduce to: profile, declared/undeclared ext, charset, a disallowed parameter after profile, case and whitespace, and ext with no declared extension.
  • Removing the catalog comment about the nested effect-jsonapi copy.
  • The optional q reconciliation. Middleware already reads a malformed q as weight 1, like effect-ext. The one remaining difference is effect-ext's parseFloat, which reads q=2 as 2 where Middleware reads it as malformed, which also gives 1. That is effect-ext's ranking, so nothing changes here.

The name is Negotiation.representation, not the issue's jsonApiRepresentation: in the Negotiation namespace, the prefix would repeat the module.

Verification

  • pnpm install --frozen-lockfile: pass
  • vp run build: pass
  • vp check: pass after vp fmt README.md. The first run failed on README formatting. Final run: 0 errors and 5301 warnings, the same count as trunk, so no new sites.
  • vp run check: pass
  • vp run -r test:unit: pass, including 7 new representation (#577) / toApiError (#577) tests
  • vp run docgen: pass (both new @examples compiled and executed)
  • vp run test:coverage, then vp exec fallow audit --base origin/trunk: pass

Changeset

  • .changeset/negotiation-representation.md, minor (additive)

Notes

  • These are new exported types: Negotiation.Parameterised, Representation, RepresentationOptions and Outcome. Options-object members are spelled readonly x?: T, per the owner's family rule.
  • The README gets one short paragraph under the Negotiation section.

Generated by Claude Code

@changeset-bot

changeset-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2688394

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

…r a generic negotiator (#577)

`Negotiation.representation({ extensions, servesPath })` is the JSON:API
`Representation` a media-type-agnostic negotiator (effect-ext's
`Negotiate.negotiateRepresentation`) takes: `application/vnd.api+json`,
with JSON:API §5's parameter rule as `acceptsParameters`.
`Negotiation.toApiError` maps that negotiator's refusal of it to
`ApiError.NotAcceptable` (406) / `ApiError.UnsupportedMediaType` (415).
Both are typed structurally, so effect-ext's `Negotiate` is not imported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y5G6PMempKsgjiV1NDcCJY
@thomasfosterau
thomasfosterau force-pushed the issue-577-jsonapi-representation branch from 63b26cd to 2688394 Compare November 12, 2026 03:32
@thomasfosterau
thomasfosterau merged commit 1804112 into trunk Nov 12, 2026
4 checks passed
@thomasfosterau
thomasfosterau deleted the issue-577-jsonapi-representation branch November 12, 2026 03:50
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.

2 participants