feat(server): enhance call util to support signal and lastEventId options#687
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ProcedureUtils
participant ProcedureClient
Caller->>ProcedureUtils: call(procedure, input, {context, signal, lastEventId})
ProcedureUtils->>ProcedureClient: createProcedureClient(procedure, options)
ProcedureClient->>ProcedureUtils: returns clientFn
ProcedureUtils->>ProcedureClient: clientFn(input, options)
ProcedureClient-->>ProcedureUtils: result
ProcedureUtils-->>Caller: result
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Summary of Changes
Hello @unnoq, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request enhances the call utility function within the server package to support signal and lastEventId options. This provides greater control over client-side request behavior, such as cancellation and event stream management, by passing these options down to the underlying client. The changes include updates to the core implementation, unit tests, and type definitions to ensure robustness and type safety.
Highlights
- Enhanced 'call' utility: The
callutility function now acceptssignal(for request cancellation viaAbortSignal) andlastEventIdoptions, aligning its capabilities with common client-side request patterns, particularly useful for streaming or long-polling scenarios. - Type Safety: Updated TypeScript definitions and added new type tests (
.test-d.ts) to ensure correct usage and strict type-checking for the newsignalandlastEventIdoptions, preventing invalid types from being passed. - Option Propagation: The newly supported
signalandlastEventIdoptions are now correctly propagated from thecallutility throughcreateProcedureClientto the underlying client function, ensuring they are utilized in the actual request execution.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-event-iterator
@orpc/hey-api
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/react
@orpc/react-query
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
Code Review
The pull request introduces support for signal and lastEventId options to the call utility. The changes include updates to type definitions and runtime tests. A potential improvement involves explicitly including signal and lastEventId in the Omit type within procedure-utils.ts to ensure these options are correctly passed through.
| const options = resolveMaybeOptionalOptions(rest) | ||
| return createProcedureClient(procedure, options)(input, options) |
There was a problem hiding this comment.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/server/src/procedure-utils.ts (1)
42-51: Consider updating documentation.The JSDoc comment could be enhanced to mention the new
signalandlastEventIdoptions for better developer experience./** * Directly call a procedure without creating a client. * * @example * ```ts * const output = await call(getting, 'input') * const output = await call(getting, 'input', { context: { db: 'postgres' } }) + * const output = await call(getting, 'input', { + * context: { db: 'postgres' }, + * signal: AbortSignal.timeout(5000), + * lastEventId: 'event-123' + * }) * ``` * */
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/server/src/procedure-utils.test-d.ts(2 hunks)packages/server/src/procedure-utils.test.ts(1 hunks)packages/server/src/procedure-utils.ts(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/server/src/procedure-utils.ts (3)
packages/client/src/types.ts (2)
ClientOptions(8-12)ClientPromiseResult(24-24)packages/shared/src/args.ts (1)
resolveMaybeOptionalOptions(5-7)packages/server/src/procedure-client.ts (1)
createProcedureClient(71-123)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: publish-commit
- GitHub Check: lint
🔇 Additional comments (9)
packages/server/src/procedure-utils.test.ts (2)
51-51: LGTM: Test properly covers the new options.The test correctly includes the new
signalandlastEventIdoptions alongside the existingcontextoption.
58-58: LGTM: Test expectation updated correctly.The test now properly verifies that the client is called with the full options object, aligning with the implementation changes.
packages/server/src/procedure-utils.test-d.ts (3)
17-20: LGTM: Comprehensive type testing for new options.The type tests properly validate that
signalandlastEventIdoptions are supported alongside the existingcontextoption.
21-24: LGTM: Good coverage of optional context scenarios.The tests correctly verify that calls without a
contextargument are allowed when all context fields are optional, which maintains backward compatibility.
34-37: LGTM: Proper negative type testing.The
@ts-expect-errorcomments correctly ensure that invalid types forsignalandlastEventIdare caught by TypeScript, maintaining type safety.packages/server/src/procedure-utils.ts (4)
1-1: LGTM: Proper imports for new functionality.The additional imports for
ClientOptionsandClientPromiseResultare necessary for the enhanced type signature.
7-7: LGTM: Import follows established pattern.The import of
resolveMaybeOptionalOptionsis consistent with how optional options are handled throughout the codebase.
68-68: LGTM: Well-designed type extension.The use of
Omit<ClientOptions<Record<never, never>>, 'context'>correctly allowssignalandlastEventIdoptions while avoiding duplication of thecontextfield that's already handled byCreateProcedureClientOptions.
71-72: LGTM: Proper options normalization and usage.The implementation correctly:
- Uses
resolveMaybeOptionalOptionsto normalize the rest parameters- Passes the normalized options to both
createProcedureClientand the client invocation- Follows the established pattern for handling optional options in the codebase
Summary by CodeRabbit
New Features
Bug Fixes
Tests