Skip to content

refactor!: Relationship descriptor key / order are Option (#626) - #629

Merged
thomasfosterau merged 1 commit into
trunkfrom
option-null-relationship-descriptors
Nov 12, 2026
Merged

thomasfosterau merged 1 commit into
trunkfrom
option-null-relationship-descriptors

Conversation

@thomasfosterau

@thomasfosterau thomasfosterau commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

Implements the decided option 4 for #626: a relationship descriptor's storage key and canonical order are Options instead of T | undefined. This sits between PR 3 (#628, landed) and PR 6 of the effect/prefer-option-over-null series, and is rebased onto trunk ed15763.

  • Relationship.One / Optional / one / optional: key: Option.Option<K>. It is Option.some("authorId") when declared and Option.none() when not. A declared key still infers its literal (Option<"authorId">), and an undeclared one reads as Option<never>.
  • Relationship.StorageKey is now string. The undeclared default of K in the lowercase annotations and the constructors is never.
  • Relationship.Paginated / paginated (interface and constructor): order: Option.Option<O>, with O extends Order<R> (it was Order<R> | undefined) and never as the undeclared default.
  • The wide matchers (One<Any>, Optional<Any>, ToOne<Any>, Paginated<Any>, Descriptor) still match keyed and unkeyed, ordered and order-less descriptors. Option<never> is assignable to Option<string> / Option<Order<Any>>.

Readers changed:

  • src/Resource.ts: validateStorageKeys uses Option.isNone(descriptor.key) / descriptor.key.value, with no per-element allocation.
  • src/Relationship.ts: the internal storageKey helper validates an Option. The paginated constructor builds Option.none() / Option.some(order), which also drops the order as NoInfer<O> assertion.
  • The JSDoc examples on one and paginated, and README.md.
  • Tests: src/Relationship.test.ts; test/relationship-storage-key.types.ts (unkeyedIsUndefined becomes unkeyedIsNone: Option<never>); test/recursive-resources.types.ts (the ~l.358 order case); test/resource-metadata.types.ts.
  • New type cases show that the wide matchers match both forms, through conditional matching and through assignability.

On trunk, Endpoint, Lid, Atomic, Handlers, Assemble and the examples do not read .key / .order on descriptors. The type checker and a grep turned up no other readers. Their Relationship.One<Any>-style matchers keep working unchanged.

Closes #626. Part of #533.

Verification

Re-run after rebasing onto ed15763:

  • pnpm install --frozen-lockfile: pass
  • vp run build: pass
  • vp check: pass (0 errors)
  • vp run check (sources, type-level tests, examples, emitted declarations, including test/emitted and test/declaration-emit): pass
  • vp run -r test:unit: pass (root 4010 tests, plus the examples' suites)
  • vp run docgen (every JSDoc @example compiled and executed): pass
  • vp run test:coverage, then vp exec fallow audit --base origin/trunk: pass (no issues in 8 changed files)

Lint (vp lint, per rule, trunk ed15763 → this branch):

rule before after
effect(prefer-option-over-null) 204 199 (the #626 sites in src/Relationship.ts, 5 diagnostics on 4 declarations, go to 0)
effect(casting-awareness) 455 454
effect(require-safety-comment-for-type-assertion) 441 440
typescript(no-unsafe-type-assertion) 421 420
every other rule unchanged unchanged

There are no inline disables and no overrides. The rule stays at warn because the rest of the series still has sites; PR 6 flips it.

Changeset

  • .changeset/relationship-key-order-option.md: minor, marked Breaking. Its migration note covers Option.getOrElse(descriptor.key, () => defaultColumn), Option.isSome(descriptor.order), Option.map, Option.match, and Option.getOrUndefined to keep the old shape. It also shows how to omit a maybe-undefined key under exactOptionalPropertyTypes.

Notes

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y5G6PMempKsgjiV1NDcCJY

@changeset-bot

changeset-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 630acbb

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

A to-one descriptor's storage `key` and a paginated descriptor's canonical
`order` are `Option`s instead of `T | undefined`: `Option.some(k)` when
declared, `Option.none()` (typed `Option<never>`) when not. A declared key
or order still infers its literal; `Relationship.StorageKey` is `string`
and `Paginated`'s `O` is constrained by `Order<R>` alone, with `never` as
the undeclared default of the lowercase annotations and the constructors.
The wide matchers (`One<Any>`, `Optional<Any>`, `Paginated<Any>`) still
match keyed and unkeyed, ordered and order-less descriptors.

Readers: `Resource.make`'s storage-key validation, the Relationship tests,
the storage-key / recursive-resources / resource-metadata type tests (with
new wide-matcher cases) and the README.

Clears the four `effect/prefer-option-over-null` sites in
src/Relationship.ts. Closes #626. Part of #533.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y5G6PMempKsgjiV1NDcCJY
@thomasfosterau
thomasfosterau force-pushed the option-null-relationship-descriptors branch from a7efa95 to 630acbb Compare November 12, 2026 09:31
@thomasfosterau
thomasfosterau merged commit 06fa426 into trunk Nov 12, 2026
4 checks passed
@thomasfosterau
thomasfosterau deleted the option-null-relationship-descriptors branch November 12, 2026 09:35
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.

prefer-option-over-null: Relationship.StorageKey and Paginated's order need a design decision

2 participants