Repository navigation
refactor!: Relationship descriptor key / order are Option (#626) - #629
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 630acbb 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 |
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
force-pushed
the
option-null-relationship-descriptors
branch
from
November 12, 2026 09:31
a7efa95 to
630acbb
Compare
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
Implements the decided option 4 for #626: a relationship descriptor's storage
keyand canonicalorderareOptions instead ofT | undefined. This sits between PR 3 (#628, landed) and PR 6 of theeffect/prefer-option-over-nullseries, and is rebased onto trunked15763.Relationship.One/Optional/one/optional:key: Option.Option<K>. It isOption.some("authorId")when declared andOption.none()when not. A declared key still infers its literal (Option<"authorId">), and an undeclared one reads asOption<never>.Relationship.StorageKeyis nowstring. The undeclared default ofKin the lowercase annotations and the constructors isnever.Relationship.Paginated/paginated(interface and constructor):order: Option.Option<O>, withO extends Order<R>(it wasOrder<R> | undefined) andneveras the undeclared default.One<Any>,Optional<Any>,ToOne<Any>,Paginated<Any>,Descriptor) still match keyed and unkeyed, ordered and order-less descriptors.Option<never>is assignable toOption<string>/Option<Order<Any>>.Readers changed:
src/Resource.ts:validateStorageKeysusesOption.isNone(descriptor.key)/descriptor.key.value, with no per-element allocation.src/Relationship.ts: the internalstorageKeyhelper validates anOption. Thepaginatedconstructor buildsOption.none()/Option.some(order), which also drops theorder as NoInfer<O>assertion.oneandpaginated, andREADME.md.src/Relationship.test.ts;test/relationship-storage-key.types.ts(unkeyedIsUndefinedbecomesunkeyedIsNone:Option<never>);test/recursive-resources.types.ts(the ~l.358 order case);test/resource-metadata.types.ts.On trunk, Endpoint, Lid, Atomic, Handlers, Assemble and the examples do not read
.key/.orderon descriptors. The type checker and a grep turned up no other readers. TheirRelationship.One<Any>-style matchers keep working unchanged.Closes #626. Part of #533.
Verification
Re-run after rebasing onto
ed15763:pnpm install --frozen-lockfile: passvp run build: passvp check: pass (0 errors)vp run check(sources, type-level tests, examples, emitted declarations, includingtest/emittedandtest/declaration-emit): passvp run -r test:unit: pass (root 4010 tests, plus the examples' suites)vp run docgen(every JSDoc@examplecompiled and executed): passvp run test:coverage, thenvp exec fallow audit --base origin/trunk: pass (no issues in 8 changed files)Lint (
vp lint, per rule, trunked15763→ this branch):effect(prefer-option-over-null)src/Relationship.ts, 5 diagnostics on 4 declarations, go to 0)effect(casting-awareness)effect(require-safety-comment-for-type-assertion)typescript(no-unsafe-type-assertion)There are no inline disables and no overrides. The rule stays at
warnbecause 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 coversOption.getOrElse(descriptor.key, () => defaultColumn),Option.isSome(descriptor.order),Option.map,Option.match, andOption.getOrUndefinedto keep the old shape. It also shows how to omit a maybe-undefinedkeyunderexactOptionalPropertyTypes.Notes
undefinedtype argument (Relationship.one<C, false, undefined>,Relationship.paginated<C, undefined>) is now a constraint error. A maybe-undefined{ key }/{ order }option value is now rejected.🤖 Generated with Claude Code
https://claude.ai/code/session_01Y5G6PMempKsgjiV1NDcCJY