Skip to content

Add delete-success, list-query and include-subset overrides - #68

Merged
thomasfosterau merged 3 commits into
mainfrom
claude/effect-jsonapi-handler-overrides-s13y1t
Aug 15, 2026
Merged

thomasfosterau merged 3 commits into
mainfrom
claude/effect-jsonapi-handler-overrides-s13y1t

Conversation

@thomasfosterau

@thomasfosterau thomasfosterau commented Aug 15, 2026 •

Copy link
Copy Markdown
Owner

Three handler-layer overrides for consumers whose contract doesn't match the package's defaults — the follow-on to #61. Each is opt-in, defaults to today's behaviour, threads through Group.resource's per-endpoint config, and is pinned by a regression test.

All three gaps were re-verified against current main (0.8.0) before implementing.

1. success override on Endpoint.delete (fc6c707)

deleteEndpoint bound its response unconditionally to HttpApiSchema.NoContent, and DeleteConfig was { name, path, errors } only — so a soft delete that returns the tombstone resource had no way to say so.

Endpoint.delete(Article, { success: Article.document(), errors: [ArticleNotFound] }) // → 200 + document
Endpoint.delete(Article, { success: Article.document(), status: 202 })               // → 202 + document
Group.resource(Article, { endpoints: { delete: { success: Article.document() } } })

The override is served as application/vnd.api+json like every other body in the package. Without it the endpoint is the 204 it always was.

2. query override on Endpoint.list (aa7784b)

list hard-wired query: Query.schema(resource, …), which always nests what it decodes (page: { offset, limit }, filter: { … }). An api whose list input is a flat struct, or that carries a parameter JSON:API has no query family for, had no route but a bracketed filter[…] key.

const ListArticles = Query.bracketPageKeys(
  Schema.Struct({
    ...Query.Page.offset({ maxLimit: 100 }),
    sort: Schema.optionalKey(Schema.String),
    authorId: Schema.optionalKey(Schema.String),
    includeDeleted: Schema.optionalKey(Schema.Literals(["true", "false"]))
  })
)

Endpoint.list(Article, { query: ListArticles })
Group.resource(Article, { endpoints: { list: { query: ListArticles } } })

page[limit] / page[offset] stay spec-canonical on the wire; the handler sees { limit, offset, … } flat. The include / fields / sort / page / filter options are ignored once query is given. Mirrors the payload override from #61.

3. Constrainable include paths (58956ac)

Query.Include derived the resource's whole relationship graph at depth 2, so ?include= advertised paths whose resolver was never written — answering 200 with an empty included, worse than the 400 an unknown path already gives.

Endpoint.get(Work, { include: { paths: ["composer", "recordings"] } })
Endpoint.list(Track, { include: { depth: 1 } })

// Query.Include(Article, { paths: ["author"] }).Type is ReadonlyArray of "author"
const include = Query.Include(Article, { paths: ["author"] })

Group.resource(Work, {
  include: { depth: 1 },
  endpoints: { get: { include: { paths: ["composer", "recordings"] } } }
})

paths and/or depth (1 / 2 / 3; paths wins when both are given), accepted anywhere include was a boolean — Endpoint.get / list / related / collection / polymorphic, Query.schema, and Endpoint.resource / Group.resource top-level and per endpoint. The literal path type narrows with the runtime set, so an unlisted path fails to compile as well as to decode. include: true still derives the full depth-2 graph.

The relationship endpoints' paths are their target's graph rather than the configured resource's, so a constrained top-level include reaches them as a plain "on"; constrain those with Endpoint.related directly.

New type-level surface — Resource.IncludeDepth, Resource.IncludePathsTo (over a resource and a depth), and Query.IncludeOptions / Query.IncludeOption / Query.IncludePathsOf:

export type IncludeDepth = 1 | 2 | 3
export type IncludePathsTo<R extends Any, Depth extends IncludeDepth> = ...

export interface Include<R extends Any, Paths extends string = IncludePath<R>> ...
export interface GetConfig<Meta extends Schema.Top, R extends Any = Any> ...

Query.Include gains a defaulted second parameter for its path set, and Endpoint.GetConfig a defaulted second parameter for the resource it configures — both source-compatible.

Verification

pnpm run check (typecheck incl. type-level tests, lint, format, 424 package tests + all three example workspaces) and pnpm run docgen (type-checks and runs every JSDoc example) pass locally. Three minor changesets, one per override.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HfZHAjtAcZXHMhjvPjCCdS

claude added 3 commits August 15, 2026 06:48
`deleteEndpoint` bound its response unconditionally to
`HttpApiSchema.NoContent`, so every delete — hand-written or generated — was
a 204 with an empty body, and `DeleteConfig` was `{ name, path, errors }`
only. Apis whose deletion is a soft delete have something to return: the
tombstone resource document, so a viewer can render what was removed. A
forced 204 breaks that contract on every delete endpoint.

Add an optional `success` schema (and a `status`, for the rare non-200 case)
to `Endpoint.delete`, defaulting to today's `NoContent`. An override is
served as `application/vnd.api+json`, like every other body in the package.
Thread both through `Endpoint.resource` / `Group.resource`'s per-endpoint
`delete` config. Only the response changes; path, params, errors and
middleware are untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HfZHAjtAcZXHMhjvPjCCdS
`list` hard-wired its query to the `Query.schema` composition of its
`include` / `fields` / `sort` / `page` / `filter` options, and `ListConfig`
exposed those features but no way out of the composition. `Query.schema`
nests everything it decodes — `page: { offset, limit }`, `filter: { … }` —
so an api whose list input is a flat struct, or that carries a parameter
JSON:API has no query family for, had no route but `filter[<name>]`: a wire
break on every list endpoint.

Add an optional `query` schema to `Endpoint.list`, defaulting to today's
composition (the feature options are ignored once it is given), mirroring
the `payload` override on create/update. Thread it through
`Endpoint.resource` / `Group.resource`'s per-endpoint `list` config. Only
the query changes; path, success document, errors and middleware are
untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HfZHAjtAcZXHMhjvPjCCdS
`Query.Include` derived `Schema.Literals(dedupe(toResources(r).flatMap((r) =>
includePaths(r, 2))))` — a boolean over the resource's complete relationship
graph — so `?include=` advertised every path the graph reaches at depth 2,
including ones the endpoint's resolver was never written for. A to-one
relationship on a related resource is enough to surface such a path.
Advertising it answers 200 with an empty `included`: worse than the 400 an
unknown path already produces.

Add `Query.IncludeOptions` — `paths` (an explicit allow-list) and/or `depth`
(1/2/3, `paths` winning when both are given) — accepted by `Query.Include`
and anywhere `include` was a boolean: `Endpoint.get` / `list` / `related` /
`collection` / `polymorphic`, `Query.schema`, and `Endpoint.resource` /
`Group.resource` top-level and per endpoint. The literal path type narrows
with the runtime set, so an unlisted path fails to compile as well as to
decode. `include: true` still derives today's full graph at depth 2.

The relationship endpoints' paths are their target's graph rather than the
configured resource's, so a constrained top-level `include` reaches them as
a plain "on" — constrain those with `Endpoint.related` directly.

Adds `Resource.IncludeDepth` and `Resource.IncludePathsTo`, the type-level
mirror of `includePaths`' `maxDepth`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HfZHAjtAcZXHMhjvPjCCdS
@thomasfosterau
thomasfosterau merged commit dac8a88 into main Aug 15, 2026
2 checks passed
@thomasfosterau
thomasfosterau deleted the claude/effect-jsonapi-handler-overrides-s13y1t branch September 15, 2026 07:12
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