-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add apiVersion
option to Client constructor
#2877
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces enhanced API versioning support for the XRPL.js library's Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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
Documentation and Community
|
There was a problem hiding this 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
🧹 Nitpick comments (1)
packages/xrpl/HISTORY.md (1)
7-9
: Move the newClient
feature to the "Added" section.The introduction of the
apiVersion
option in theClient
constructor is a new feature rather than a fix. For clarity and proper documentation, consider moving this entry from the "Fixed" section to the "Added" section under "Unreleased Changes".Apply this diff to reposition the entry:
## Unreleased Changes -### Fixed +### Added * `Client` supports `apiVersion` option on constructor
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/xrpl/HISTORY.md
(1 hunks)packages/xrpl/src/client/index.ts
(9 hunks)
🔇 Additional comments (8)
packages/xrpl/src/client/index.ts (8)
95-97
: Appropriate use of generic parameter inClientOptions
.The introduction of the
ClientAPIVersion
generic parameter in theClientOptions
interface enhances type safety and flexibility.
116-121
: Documentation forapiVersion
is clear and informative.The added JSDoc comment for the
apiVersion
property provides a clear description and default value, aiding in code readability and maintainability.
195-197
: Correct extension ofEventEmitter
with generic parameter.The
Client
class correctly extendsEventEmitter
while introducing theClientAPIVersion
generic parameter, maintaining consistency with the interface.
251-254
: Constructor correctly utilizes the generic parameter.The constructor correctly accepts
ClientOptions<ClientAPIVersion>
, ensuring that theapiVersion
is consistently applied throughout theClient
instance.
265-266
: Proper assignment ofapiVersion
with fallback to default.The use of the nullish coalescing operator ensures that
apiVersion
is assigned appropriately, defaulting toDEFAULT_API_VERSION
when not provided.
Line range hint
350-354
: Generic parameters enhancerequest
method flexibility.The updated
request
method signature uses theClientAPIVersion
type parameter effectively, allowing for type-safe requests corresponding to the client's API version.
473-476
:requestAll
method correctly integrates generic parameter.The inclusion of
ClientAPIVersion
in therequestAll
method signature ensures consistent API versioning across batched requests.
501-502
: Correct type assertion withClientAPIVersion
.The type assertion of
singleResponse
asMarkerResponse<ClientAPIVersion>
is appropriate and ensures that the result is correctly typed for further processing.
@@ -222,7 +232,7 @@ class Client extends EventEmitter<EventTypes> { | |||
* API Version used by the server this client is connected to | |||
* | |||
*/ | |||
public apiVersion: APIVersion = DEFAULT_API_VERSION | |||
public apiVersion: APIVersion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Type of apiVersion
property should match the generic parameter.
Currently, apiVersion
is typed as APIVersion
. To ensure consistency and leverage the benefits of the generic parameter, consider typing it as ClientAPIVersion
.
Apply this diff to update the type:
-public apiVersion: APIVersion
+public apiVersion: ClientAPIVersion
Committable suggestion skipped: line range outside the PR's diff.
export interface ClientOptions< | ||
ClientAPIVersion extends APIVersion = typeof DEFAULT_API_VERSION, | ||
> extends ConnectionUserOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this typing change is needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, Client
class will not be able to recognize the API version set in the constructor, and the response of request()
and requestAll()
will only be the types of APIv2 (DEFAULT_API_VERSION
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/xrpl/src/sugar/submit.ts (1)
162-163
: Consider improving type assertion safety.The TODO comment indicates a need to resolve the type assertion. Consider using type guards or restructuring the code to avoid the type assertion.
- // TODO: resolve the type assertion below - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- we know that txResponse is of type TxResponse - return txResponse as TxResponse<T, V> + if ('result' in txResponse && 'tx_json' in txResponse.result) { + return txResponse as TxResponse<T, V> + } + throw new XrplError('Unexpected response format')
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
packages/xrpl/src/client/index.ts
(15 hunks)packages/xrpl/src/models/methods/tx.ts
(1 hunks)packages/xrpl/src/sugar/autofill.ts
(7 hunks)packages/xrpl/src/sugar/getFeeXrp.ts
(2 hunks)packages/xrpl/src/sugar/getOrderbook.ts
(2 hunks)packages/xrpl/src/sugar/submit.ts
(6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
- GitHub Check: snippets (22.x)
- GitHub Check: integration (22.x)
- GitHub Check: snippets (20.x)
- GitHub Check: integration (20.x)
- GitHub Check: snippets (18.x)
- GitHub Check: integration (18.x)
- GitHub Check: browser (18.x)
🔇 Additional comments (17)
packages/xrpl/src/sugar/getFeeXrp.ts (1)
18-20
: LGTM! Type-safe API version support added.The generic type parameter is correctly implemented with proper constraints and default value.
packages/xrpl/src/models/methods/tx.ts (1)
96-100
: LGTM! Enhanced type safety for API versioning.The TxResponse interface correctly implements generic type parameters for both transaction type and API version, maintaining type safety throughout the response chain.
packages/xrpl/src/sugar/getOrderbook.ts (1)
145-147
: LGTM! Type-safe API version support added.The requestAllOffers function correctly implements the generic type parameter for API versioning.
packages/xrpl/src/sugar/submit.ts (1)
51-54
: LGTM! Comprehensive API version support added.The generic type parameters are consistently implemented across all functions, maintaining type safety throughout the submission process.
Also applies to: 117-124, 232-235
packages/xrpl/src/sugar/autofill.ts (6)
6-6
: LGTM!The import of
APIVersion
andDEFAULT_API_VERSION
is necessary for the generic type parameters being added to the functions.
95-97
: LGTM!The addition of the generic type parameter
V extends APIVersion
with a default toDEFAULT_API_VERSION
maintains type safety while allowing flexibility in API versions.
221-223
: LGTM!The addition of the generic type parameter
V extends APIVersion
with a default toDEFAULT_API_VERSION
maintains type safety while allowing flexibility in API versions.
241-243
: LGTM!The addition of the generic type parameter
V extends APIVersion
with a default toDEFAULT_API_VERSION
maintains type safety while allowing flexibility in API versions.
262-264
: LGTM!The addition of the generic type parameter
V extends APIVersion
with a default toDEFAULT_API_VERSION
maintains type safety while allowing flexibility in API versions.
325-327
: LGTM!The addition of the generic type parameter
V extends APIVersion
with a default toDEFAULT_API_VERSION
maintains type safety while allowing flexibility in API versions for both functions.Also applies to: 340-342
packages/xrpl/src/client/index.ts (7)
Line range hint
96-122
: LGTM!The addition of the generic type parameter and
apiVersion
option is well-documented and provides type-safe API version configuration.
Line range hint
134-146
: LGTM!The type changes properly handle API versioning for paginated responses, particularly for account transactions.
199-201
: LGTM!The addition of the generic type parameter to the
Client
class provides type safety for API versioning at the class level.
Line range hint
255-270
: LGTM!The constructor properly handles the
apiVersion
option, defaulting toDEFAULT_API_VERSION
if not provided.
354-354
: LGTM!The method now correctly uses the client's API version by default for request types.
399-400
: LGTM!The method now correctly uses the client's API version for paginated response types.
859-859
: LGTM!The method now correctly uses the client's API version for transaction response types.
High Level Overview of Change
Fixes #2872
Context of Change
Client
constructor.Type of Change
Did you update HISTORY.md?
Test Plan