Repository navigation
feat(Negotiation): the JSON:API representation and refusal mapping for a generic negotiator (#577) - #580
Merged
Conversation
🦋 Changeset detectedLatest commit: 2688394 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This was referenced Nov 12, 2026
…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
force-pushed
the
issue-577-jsonapi-representation
branch
from
November 12, 2026 03:32
63b26cd to
2688394
Compare
This was referenced Nov 12, 2026
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.
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:APIRepresentation:mediaType: "application/vnd.api+json", the optionalservesPath, andacceptsParameters, which applies JSON:API §5's rule. Onlyextandprofileare allowed, and everyextURI must be declared. The predicate isinternal/media'sparametersAreAcceptable, the same oneMiddleware.contentTypeIsAcceptable/acceptIsAcceptableuse.extensionsdefaults to none, so an api with no extension refuses everyext, as §5 requires.Negotiation.toApiError(outcome)maps the negotiator'sNotAcceptablerefusal of the JSON:API representation toApiError.NotAcceptable(406) and itsUnsupportedMediaTyperefusal toApiError.UnsupportedMediaType(415).Selected,Fallbackand a refusal of another representation (a Markdown alternate) all returnOption.none().Parameterised,Representation,Outcome). effect-ext'sMime.MimeTypeandNegotiate.Negotiationalready satisfy these types, so this package doesn't importNegotiate. That keeps theentry-pointseffect-ext allow-list unchanged, and a/Negotiateimport 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.0MimeType.parseoutput.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
Negotiateand the optional peer on this package.negotiateRepresentation. The 406/415 cases from effect-ext's oldtests/web/negotiate.test.tsare ported here at the parameter rule they reduce to: profile, declared/undeclaredext,charset, a disallowed parameter afterprofile, case and whitespace, andextwith no declared extension.qreconciliation.Middlewarealready reads a malformedqas weight 1, like effect-ext. The one remaining difference is effect-ext'sparseFloat, which readsq=2as 2 whereMiddlewarereads 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'sjsonApiRepresentation: in theNegotiationnamespace, the prefix would repeat the module.Verification
pnpm install --frozen-lockfile: passvp run build: passvp check: pass aftervp 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: passvp run -r test:unit: pass, including 7 newrepresentation (#577)/toApiError (#577)testsvp run docgen: pass (both new@examples compiled and executed)vp run test:coverage, thenvp exec fallow audit --base origin/trunk: passChangeset
.changeset/negotiation-representation.md, minor (additive)Notes
Negotiation.Parameterised,Representation,RepresentationOptionsandOutcome. Options-object members are spelledreadonly x?: T, per the owner's family rule.Generated by Claude Code