Skip to content

Renaming options to ctx#2934

Merged
RobinTail merged 29 commits intomake-v26from
mv-options-to-context
Sep 26, 2025
Merged

Renaming options to ctx#2934
RobinTail merged 29 commits intomake-v26from
mv-options-to-context

Conversation

@RobinTail
Copy link
Copy Markdown
Owner

@RobinTail RobinTail commented Sep 13, 2025

I realized that context is more clear naming for that entity, which is also the same in hono and trpc. It should also reduce the potential confusion with "config options" and OPTIONS request method.

However, it might not be possible to rename in without breaking changes, since it's present in public interfaces.

todo

  • diagram
  • migration
  • changelog

Summary by CodeRabbit

  • Breaking Changes
    • Standardized context naming: replace options with ctx across handlers, middleware, and factory APIs. Renamed addOptions to addContext. This affects handler signatures and how context is accessed.
  • Documentation
    • Updated README and examples to reflect ctx-based usage and patterns.
  • Tooling/Migration
    • Added automated migration rules to rename options→ctx and addOptions→addContext.
  • Tests
    • Updated test suites to align with ctx terminology and behavior.
  • Chores
    • CHANGELOG updated to document the API rename and guidance.

@RobinTail RobinTail added the refactoring The better way to achieve the same result label Sep 13, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 13, 2025

Walkthrough

Renames the contextual argument across the codebase from options to ctx and updates related types, signatures, and usages. EndpointsFactory.addOptions is renamed to addContext. Core endpoint/middleware flow, tests, examples, docs, and migration rules are updated accordingly. No functional logic changes; interface and parameter names are standardized.

Changes

Cohort / File(s) Summary
Docs
CHANGELOG.md, README.md
Documentation updated to use ctx instead of options; examples and text adjusted; addOptions references replaced with addContext.
Core endpoint flow
express-zod-api/src/endpoint.ts, express-zod-api/src/result-handler.ts
Types and internals refactored to pass and accumulate ctx instead of options; Handler third generic renamed to CTX; all method parameters/locals updated.
Middleware layer
express-zod-api/src/middleware.ts
Middleware handler and execute signatures switched from options to ctx; generic names updated (OPT/OUT → CTX/RET); ExpressMiddleware provider types adjusted.
Factory and helpers
express-zod-api/src/endpoints-factory.ts, express-zod-api/src/server-helpers.ts
EndpointsFactory generics and BuildProps shifted to CTX; addOptions renamed to addContext; server helpers now call error handler with ctx: {}.
Testing utilities
express-zod-api/src/testing.ts
testMiddleware parameter renamed from options to ctx and usages updated.
Examples
example/endpoints/*
Handlers destructure ctx instead of options for method/authorized/emit/isClosed.
Tests
express-zod-api/tests/*.spec.ts
All tests updated to use ctx instead of options; assertions, mocks, and messages adjusted; factory API rename reflected.
Migration rule
migration/index.ts, migration/index.spec.ts
ESLint rule extended to auto-rename options→ctx and addOptions→addContext; added selectors and tests for new cases.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor C as Client
  participant S as Server
  participant E as Endpoint
  participant M as Middlewares
  participant H as Handler
  participant R as ResultHandler

  C->>S: HTTP Request
  S->>E: route match(request)
  E->>M: execute(request, ctx = {})
  loop each middleware
    M-->>E: merge into ctx
  end
  E->>H: handler({ input, request, response, logger, ctx })
  H-->>E: result or throws
  alt success
    E->>R: execute({ input, ctx, ... })
    R-->>S: send response
  else error
    E->>R: execute({ input: null, ctx, ... })
    R-->>S: send error response
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

I nudge my nose at ctx, not options past,
Hop-hop through types, the rename done at last.
Fact’ries addContext, middlewares align,
Endpoints sip carrot-logs—everything’s fine.
Tests burrow through flows, all green on the run,
A tidy warren of context—refactor won! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title succinctly states the main change—renaming options to ctx—and directly reflects the broad code and API refactor described in the pull request, making it clear and specific to readers.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mv-options-to-context

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread express-zod-api/src/middleware.ts
@coveralls-official
Copy link
Copy Markdown

coveralls-official Bot commented Sep 13, 2025

Coverage Status

coverage: 100.0%. remained the same
when pulling 555d503 on mv-options-to-context
into a8138fb on make-v26.

@RobinTail RobinTail added the breaking Backward incompatible changes label Sep 13, 2025
@RobinTail RobinTail changed the title Exp: renaming options to ctx Renaming options to ctx Sep 13, 2025
@RobinTail RobinTail changed the title Renaming options to ctx v26: Renaming options to ctx Sep 13, 2025
@RobinTail RobinTail added this to the v26 milestone Sep 13, 2025
@RobinTail RobinTail added the documentation Improvements or additions to documentation label Sep 13, 2025
@RobinTail RobinTail changed the base branch from master to make-v26 September 15, 2025 15:33
@RobinTail RobinTail mentioned this pull request Sep 15, 2025
@RobinTail RobinTail marked this pull request as ready for review September 25, 2025 18:50
@RobinTail
Copy link
Copy Markdown
Owner Author

@coderabbitai, review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 25, 2025

@RobinTail I'll review the changes in this PR about renaming options to ctx.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8138fb and 555d503.

⛔ Files ignored due to path filters (1)
  • dataflow.svg is excluded by !**/*.svg
📒 Files selected for processing (21)
  • CHANGELOG.md (1 hunks)
  • README.md (11 hunks)
  • example/endpoints/retrieve-user.ts (1 hunks)
  • example/endpoints/time-subscription.ts (1 hunks)
  • example/endpoints/update-user.ts (1 hunks)
  • express-zod-api/src/endpoint.ts (12 hunks)
  • express-zod-api/src/endpoints-factory.ts (8 hunks)
  • express-zod-api/src/middleware.ts (5 hunks)
  • express-zod-api/src/result-handler.ts (1 hunks)
  • express-zod-api/src/server-helpers.ts (2 hunks)
  • express-zod-api/src/testing.ts (2 hunks)
  • express-zod-api/tests/endpoint.spec.ts (5 hunks)
  • express-zod-api/tests/endpoints-factory.spec.ts (3 hunks)
  • express-zod-api/tests/middleware.spec.ts (2 hunks)
  • express-zod-api/tests/result-handler.spec.ts (5 hunks)
  • express-zod-api/tests/routing.spec.ts (1 hunks)
  • express-zod-api/tests/sse.spec.ts (3 hunks)
  • express-zod-api/tests/system.spec.ts (3 hunks)
  • express-zod-api/tests/testing.spec.ts (1 hunks)
  • migration/index.spec.ts (2 hunks)
  • migration/index.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2025-06-14T16:42:52.972Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2736
File: express-zod-api/tsup.config.ts:12-26
Timestamp: 2025-06-14T16:42:52.972Z
Learning: In express-zod-api tsup configurations, the direct mutation of `options.supported` in the `esbuildOptions` callback is intentional behavior and should not be flagged as a side effect issue.

Applied to files:

  • express-zod-api/tests/routing.spec.ts
  • express-zod-api/tests/result-handler.spec.ts
  • express-zod-api/tests/testing.spec.ts
  • express-zod-api/src/server-helpers.ts
  • express-zod-api/tests/endpoint.spec.ts
  • express-zod-api/src/testing.ts
  • express-zod-api/tests/middleware.spec.ts
  • express-zod-api/tests/system.spec.ts
  • express-zod-api/tests/sse.spec.ts
📚 Learning: 2025-05-28T07:58:09.853Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2546
File: express-zod-api/src/documentation-helpers.ts:508-512
Timestamp: 2025-05-28T07:58:09.853Z
Learning: In express-zod-api, when working with Zod's JSON schema override callbacks, using `delete` to mutate `ctx.jsonSchema` is the recommended approach per Zod's official documentation, even if it triggers performance linting warnings. This is preferable to creating copies with `undefined` values, especially for snapshot testing.

Applied to files:

  • express-zod-api/tests/testing.spec.ts
  • express-zod-api/tests/endpoint.spec.ts
  • express-zod-api/src/testing.ts
  • express-zod-api/tests/system.spec.ts
📚 Learning: 2025-05-27T19:35:57.357Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2546
File: express-zod-api/tests/buffer-schema.spec.ts:32-37
Timestamp: 2025-05-27T19:35:57.357Z
Learning: In the express-zod-api project, tests are run from the `express-zod-api` workspace directory, and the project uses an ESM-first environment without `__dirname`. Relative paths like `../logo.svg` in test files correctly resolve to the repository root due to this test execution context.

Applied to files:

  • express-zod-api/tests/endpoint.spec.ts
📚 Learning: 2025-06-02T21:08:56.475Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2697
File: CHANGELOG.md:5-5
Timestamp: 2025-06-02T21:08:56.475Z
Learning: The `cjs-test` directory in the express-zod-api repository is a test workspace and should be excluded when checking for main project version consistency with changelog entries.

Applied to files:

  • express-zod-api/tests/endpoint.spec.ts
📚 Learning: 2025-08-25T17:43:34.491Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2904
File: express-zod-api/src/routing.ts:74-79
Timestamp: 2025-08-25T17:43:34.491Z
Learning: In express-zod-api, OPTIONS (CORS preflight) requests intentionally go through the same middleware and parser chain as other HTTP methods. This was specifically implemented to fix Issue #514 where middlewares were not running for OPTIONS requests. The framework seeds "options" with the same [parsers, endpoint] pair as other methods to ensure consistent middleware execution for CORS preflight requests.

Applied to files:

  • express-zod-api/tests/middleware.spec.ts
  • express-zod-api/tests/system.spec.ts
  • README.md
  • express-zod-api/src/endpoint.ts
🪛 Biome (2.1.2)
express-zod-api/tests/endpoints-factory.spec.ts

[error] 135-135: Unexpected empty object pattern.

(lint/correctness/noEmptyPattern)


[error] 181-181: Unexpected empty object pattern.

(lint/correctness/noEmptyPattern)


[error] 207-207: Unexpected empty object pattern.

(lint/correctness/noEmptyPattern)


[error] 207-207: Unexpected empty object pattern.

(lint/correctness/noEmptyPattern)


[error] 224-224: Unexpected empty object pattern.

(lint/correctness/noEmptyPattern)


[error] 224-224: Unexpected empty object pattern.

(lint/correctness/noEmptyPattern)

🔇 Additional comments (25)
example/endpoints/retrieve-user.ts (1)

34-55: Rename aligns the handler with the new context API

Switching to ctx keeps the destructuring in sync with the middleware changes and preserves runtime behavior. Looks good.

migration/index.spec.ts (1)

21-159: Great migration coverage

These new fixtures capture the key optionsctx migration patterns (plain, aliased, and nested destructuring, plus method rename). The rule set should now confidently nudge consumers onto the new API.

example/endpoints/time-subscription.ts (1)

15-23: Context rename looks correct

Accessing emit/isClosed via ctx mirrors the surrounding refactor without altering the stream loop behavior. All good.

example/endpoints/update-user.ts (1)

33-41: Context destructuring stays consistent

Picking authorized from ctx matches the new factory surface and keeps the handler logic intact.

CHANGELOG.md (1)

8-13: Changelog entry reads well

The note clearly communicates the breaking rename and touches every affected surface. No further tweaks needed.

migration/index.ts (1)

121-143: Selectors and fixers line up with the ctx rename

The new handlers cover the critical AST shapes for renaming optionsctx and addOptionsaddContext, and the fixes stay safely scoped to the identifiers you match. Looks solid.

express-zod-api/tests/routing.spec.ts (1)

502-505: Test arguments reflect the ctx contract

The expectations now mirror the updated handler signature by asserting an empty ctx. Thanks for keeping the verification aligned with the public API change.

express-zod-api/tests/testing.spec.ts (1)

64-76: Middleware test updated correctly

Swapping the fixture input and assertions to ctx keeps the helper contract in sync with the rename. Nice and tidy.

express-zod-api/tests/result-handler.spec.ts (1)

94-228: Result handler exercises now track ctx flawlessly

Every execute invocation and related expectation moved over to ctx, so the suite continues to validate the handler interface without gaps. Great work.

express-zod-api/src/server-helpers.ts (1)

40-64: Server error helpers now pass ctx

Forwarding an empty ctx keeps the helper utilities compatible with the refactored ResultHandler signature. All consistent.

express-zod-api/src/testing.ts (1)

123-129: Rename to ctx is consistent and correct.

Parameter rename and propagation through commons look good.

Also applies to: 143-144

express-zod-api/src/result-handler.ts (1)

26-26: Handler param rename to ctx looks good.

Type contract remains clear and consistent with call sites.

express-zod-api/tests/sse.spec.ts (1)

79-79: SSE tests aligned to ctx.

Type expectations and handler destructuring updated correctly.

Also applies to: 121-121, 156-161

express-zod-api/tests/middleware.spec.ts (1)

48-49: Middleware tests updated to ctx.

Invocation and assertions are consistent with the new API.

Also applies to: 68-68, 76-76

express-zod-api/tests/endpoints-factory.spec.ts (2)

57-67: Context chaining assertions are correct.

Type-level checks on ctx propagation are sound.


104-117: addContext test reads clean and types match expectations.

API rename and resulting factory type are correct.

express-zod-api/src/middleware.ts (4)

10-24: Consistent handler signature rename

The switch to ctx throughout the handler contract is clean and keeps the intent of the argument obvious without altering behavior. Looks good to me.


31-37: Base execute contract stays aligned

Renaming the abstract execution payload to ctx keeps the public surface in sync with the rest of the refactor while preserving the same type guarantees. No issues spotted here.


41-105: Middleware generics and flow remain sound

The generic rename to CTX/RET, handler wiring, and the execute implementation all track the new terminology without introducing behavioral changes. Everything continues to type-check against FlatObject as before.


108-133: Express wrapper matches the new context shape

ExpressMiddleware now forwards and resolves ctx under the updated naming, and the default provider still yields a valid flat object. This section looks solid.

express-zod-api/tests/endpoint.spec.ts (1)

49-50: Tests now mirror the ctx-based handler contract

Thanks for updating the test doubles and assertions to expect ctx. This keeps the test suite acting as a strong guardrail for the rename.

Also applies to: 74-85, 92-93

express-zod-api/tests/system.spec.ts (1)

38-39: End-to-end coverage follows the ctx terminology

The system spec still walks the full request lifecycle and now exercises the ctx plumbing, which is exactly what we need to catch regressions in real usage.

Also applies to: 78-81, 88-99

README.md (1)

22-24: Documentation refresh is thorough

The renaming is reflected across the table of contents, narrative explanation, and examples, so developers reading the guide will stay in sync with the API.

Also applies to: 149-231, 383-414

express-zod-api/src/endpoint.ts (1)

35-40: Endpoint pipeline now consistently speaks ctx

Type aliases, middleware accumulation, and result handling all align on ctx, so the runtime behavior and type surfaces stay coherent after the rename.

Also applies to: 214-239, 286-333

express-zod-api/src/endpoints-factory.ts (1)

30-47: Factory API rename is clean

BuildProps, generics, and the new addContext helper all converge on the updated naming, which keeps consumers’ ergonomics tidy.

Also applies to: 72-122, 120-122

Comment thread express-zod-api/tests/endpoints-factory.spec.ts
Comment thread README.md Outdated
Comment thread README.md Outdated
Copy link
Copy Markdown
Owner Author

@RobinTail RobinTail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏁 okay

@RobinTail RobinTail changed the title v26: Renaming options to ctx Renaming options to ctx Sep 26, 2025
@RobinTail RobinTail merged commit d0a135b into make-v26 Sep 26, 2025
13 checks passed
@RobinTail RobinTail deleted the mv-options-to-context branch September 26, 2025 17:46
RobinTail added a commit that referenced this pull request Dec 1, 2025
<img width="283" height="353" alt="image"
src="https://github.com/user-attachments/assets/5355c68c-e807-4b61-83a8-17e66a117f7d"
/>

[Lia Smith](https://en.wikipedia.org/wiki/Suicide_of_Lia_Smith) was a 21
years young transgender woman.

She attended Middlebury College in Middlebury, Vermont, majoring in
computer science and statistics. She was a member of the college's chess
club, bridge club, LGBTQ+ club, and Japanese club. She was a diver on
the Middlebury Panthers women's swimming and diving team.

In February 2025 Middlebury College had removed Lia Smith diving profile
from their website, following President Donald Trump's executive order,
which attempts to ban transgender women and girls from competing in
women's sports.

On October 18, 2025 Lia Smith committed suicide.

The tragedy of Lia Smith highlights that the push for exclusion of
transgender women from public women's spaces and sports is not an issue
of theoretical fairness, but one with devastating consequences for the
dignity, safety, and lives of trans individuals. Smith, who was an
openly transgender student athlete, described the immense difficulty and
feeling of being unwelcome in locker rooms, emphasizing the lack of a
clear, safe space for her. Her plea that transgender people are "not
trying to get into women's spaces to be perverts... we're just being
ourselves" underscores that inclusion is a matter of allowing trans
women to exist and access necessary public facilities with basic
dignity, rather than an invasion of privacy or a threat. Denying access
to these spaces does not eliminate their need for them, but instead
subjects them to alienation and heightened psychological distress.

Furthermore, Lia's experience as a diver, where she was reportedly
targeted by anti-trans websites and ultimately left her team citing
difficulties, demonstrates the severe emotional and social toll of
exclusion in sports. Critics of anti-trans policies explicitly linked
her death by suicide to the hostile climate and constant public scrutiny
and harassment directed at trans athletes. Allowing trans women to
participate in women's sports and access women's facilities is therefore
a vital component of protecting the mental health and physical safety of
transgender people. When a society creates systems that reject a
person’s identity and deny them opportunities for community, activity,
and belonging—all essential parts of a functioning life—it creates an
environment of intense hostility and vulnerability. Inclusion, in
contrast, affirms the full humanity of trans women and is a necessary
measure against the systemic discrimination that contributed to her
anguish.

--------------------------------

- #2938 
- #3049
- #2934 
- #3086 
- #3087 
- #3094
- ❔  #3102 

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Config-driven routing behavior; Integration instances accept
per-instance config.
  * Zod plugin adds CJS compatibility and new schema metadata helpers.
  * Release bumped to v26 (beta).

* **Bug Fixes**
  * Restored Zod examples/metadata in CommonJS environments.

* **Breaking Changes**
  * Handler/middleware parameter renamed: options → ctx.
  * Removed DependsOnMethod; use inline per-route objects.
  * EndpointsFactory.addOptions() renamed to addContext().

* **Docs**
  * README and CHANGELOG updated for v26 migration and examples.

* **Tests**
  * Added CJS runtime tests and updated tests to use ctx.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Backward incompatible changes documentation Improvements or additions to documentation refactoring The better way to achieve the same result

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant