Skip to content

Conversation

@jfrank-summit
Copy link
Member

Summary

Refactors the RPC client callback definitions to use a shared RpcClientCallbacks type and explicitly exposes the onEveryOpen callback which was previously missing from the TypeScript definition.

Motivation and Context

Fixes #495.

The createRpcClient function supports an onEveryOpen callback at runtime, but the TypeScript definition for the callbacks parameter was missing this property. This forced consumers to cast their callback objects to any or ignore type errors when trying to use this hook (e.g., for reconnection logic).

Implementation Details

  • packages/utility/rpc/src/rpc/types.ts:
    • Created a new exported type RpcClientCallbacks.
    • Added onEveryOpen to the interface.
  • packages/utility/rpc/src/rpc/client.ts:
    • Updated createRpcClient to use RpcClientCallbacks instead of an inline type.
  • packages/utility/rpc/src/rpc/api/definition.ts:
    • Updated createApiDefinition and its generated client to use RpcClientCallbacks.

Breaking Changes

None. This is a non-breaking type definition update. The runtime behavior remains the same, but the TypeScript types are now more accurate.

Testing

  • Existing tests should pass.
  • Manual verification: Using onEveryOpen in a TypeScript project with this change should no longer trigger a type error.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a TypeScript type definition issue where the onEveryOpen callback was missing from the RPC client's callback options, despite being supported at runtime. The change refactors the inline callback type definitions to use a shared RpcClientCallbacks type.

  • Introduces a new exported RpcClientCallbacks type that includes all callback options, including the previously missing onEveryOpen
  • Updates createRpcClient and createApiDefinition to use the shared type instead of inline definitions
  • Eliminates type inconsistencies between the TypeScript definitions and runtime behavior

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/utility/rpc/src/rpc/types.ts Adds new RpcClientCallbacks type with all callback options including onEveryOpen
packages/utility/rpc/src/rpc/client.ts Refactors createRpcClient to use the new shared RpcClientCallbacks type
packages/utility/rpc/src/rpc/api/definition.ts Updates createClient and createMockServerClient to use the shared RpcClientCallbacks type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jfrank-summit jfrank-summit merged commit 145b477 into main Nov 20, 2025
9 checks passed
@jfrank-summit jfrank-summit deleted the fix/expose-onEveryOpen branch November 20, 2025 17:28
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.

Expose onEveryOpen in @autonomys/rpc

2 participants