Skip to content

Conversation

@tequdev
Copy link
Member

@tequdev tequdev commented Jul 17, 2025

High Level Overview of Change

Context of Change

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

Did you update HISTORY.md?

  • Yes
  • No, this change does not impact library users

Test Plan

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 17, 2025

Walkthrough

This update introduces generic boolean type parameters (typically named Binary) to various request and response interfaces and type aliases throughout the XRPL client and model method layers. These generics propagate the binary flag through type signatures, enabling more precise typing and conditional response structures based on whether binary data is requested.

Changes

Files/Areas Change Summary
packages/xrpl/src/client/index.ts Added generic boolean parameters to RequestNextPageType, RequestNextPageReturnMap, and method signatures for request and requestNextPage in the Client class. Enhanced type inference for binary mode and API version. Updated imports for API version constants.
packages/xrpl/src/models/methods/accountTx.ts Made AccountTxRequest and related response types generic over a Binary boolean. Refactored AccountTxTransaction into a discriminated union based on API version and binary flag. Updated response base and map types to propagate the binary flag.
packages/xrpl/src/models/methods/baseMethod.ts Changed the api_version property type from number to APIVersion in BaseRequest, BaseResponse, and ErrorResponse. Updated import statements.
packages/xrpl/src/models/methods/index.ts Added a generic Binary parameter to Request, Response, and RequestResponseMap type aliases. Updated all relevant request and response types to propagate the binary flag. Added import for LedgerEntry.
packages/xrpl/src/models/methods/ledger.ts Made LedgerRequest and all its extended interfaces generic over a Binary boolean. Updated the binary property type and inheritance structure to reflect binary mode.
packages/xrpl/src/models/methods/ledgerData.ts Made LedgerDataRequest, LedgerDataLedgerState, and LedgerDataResponse generic over a Binary boolean. Conditionally typed the state property in responses based on binary mode.
packages/xrpl/src/models/methods/ledgerEntry.ts Made LedgerEntryRequest and LedgerEntryResponse generic over a Binary boolean. Introduced a new base response interface and enforced mutually exclusive response fields based on binary mode.
packages/xrpl/src/models/methods/nftHistory.ts Made NFTHistoryRequest, NFTHistoryTransaction, and NFTHistoryResponse generic over a Binary boolean. Used discriminated unions to conditionally type transaction fields based on API version and binary mode. Updated imports accordingly.
packages/xrpl/src/models/methods/tx.ts Made TxRequest, TxResponse, and TxV1Response generic over a Binary boolean. Simplified BaseTxResult. Updated response types to conditionally include binary or JSON transaction and metadata fields. Modified TxVersionResponseMap to propagate the binary flag.
packages/xrpl/snippets/src/getTransaction.ts Added ESLint directive to disable @typescript-eslint/no-unnecessary-condition for a null check on tx.result.meta. No logic changes.
packages/xrpl/test/integration/requests/accountTx.test.ts Removed optional chaining in test assertions accessing transaction properties. Added type assertions for Fee. Adjusted property access for hash and other fields to be non-optional.
packages/xrpl/test/integration/requests/ledgerData.test.ts Simplified test by removing explicit LedgerDataRequest creation; passed request parameters inline. Removed unused import. No logic changes.
packages/xrpl/test/integration/transactions/nftokenMint.test.ts Changed binary property in request to be asserted as literal true as const for stricter typing; no runtime or logic changes.

Suggested reviewers

  • mvadari
  • achowdhry-ripple

Poem

🐇✨
The binary flag now hops along,
Through types and shapes where it belongs.
With generics set, the code’s more bright,
Each request and response typed just right.
From JSON fields to blobs of bits,
This rabbit’s code now perfectly fits!
🥕

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE package: '@es-joy/[email protected]',
npm warn EBADENGINE required: { node: '^14 || ^16 || ^17 || ^18 || ^19' },
npm warn EBADENGINE current: { node: 'v24.3.0', npm: '11.4.2' }
npm warn EBADENGINE }
npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE package: '[email protected]',
npm warn EBADENGINE required: { node: '^14 || ^16 || ^17 || ^18 || ^19' },
npm warn EBADENGINE current: { node: 'v24.3.0', npm: '11.4.2' }
npm warn EBADENGINE }
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-17T09_36_51_637Z-debug-0.log


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8e7fdd and 3e5b325.

📒 Files selected for processing (4)
  • packages/xrpl/snippets/src/getTransaction.ts (1 hunks)
  • packages/xrpl/src/models/methods/tx.ts (7 hunks)
  • packages/xrpl/test/integration/requests/ledgerData.test.ts (2 hunks)
  • packages/xrpl/test/integration/transactions/nftokenMint.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/xrpl/test/integration/transactions/nftokenMint.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/xrpl/snippets/src/getTransaction.ts
  • packages/xrpl/src/models/methods/tx.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/models/permissionedDomainDelete.test.ts:15-20
Timestamp: 2025-01-08T02:11:21.997Z
Learning: In validation test cases for XRPL transactions, using generic JSON input (e.g., `as any`) is preferred over strict typing as it better represents real-world scenarios where the `validate` method needs to handle arbitrary JSON/map/dictionary input from users.
packages/xrpl/test/integration/requests/ledgerData.test.ts (9)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2895
File: packages/xrpl/test/models/clawback.test.ts:0-0
Timestamp: 2025-02-12T23:28:55.377Z
Learning: The `validate` function in xrpl.js is synchronous and should be tested using `assert.doesNotThrow` rather than async assertions.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2873
File: packages/xrpl/test/integration/transactions/trustSet.test.ts:0-0
Timestamp: 2025-01-31T17:46:25.375Z
Learning: For the XRPL implementation, extensive test cases for deep freeze behavior (high/low side interactions, clearing flags, etc.) are maintained in the C++ implementation and don't need to be duplicated in the JavaScript implementation.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/src/models/transactions/common.ts:18-18
Timestamp: 2025-01-16T04:11:37.316Z
Learning: Test libraries like chai should not be used in source code. For runtime checks in browser-compatible code, use vanilla JS error throwing instead of assertion libraries.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/src/models/transactions/common.ts:0-0
Timestamp: 2025-01-16T04:26:36.757Z
Learning: Test libraries like chai should not be used in source code. Use existing validation functions where available, or implement custom validation using ValidationError for runtime checks.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: build-and-lint (22.x)
  • GitHub Check: unit (22.x)
  • GitHub Check: browser (22.x)
  • GitHub Check: integration (20.x)
  • GitHub Check: unit (20.x)
  • GitHub Check: integration (22.x)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
packages/xrpl/test/integration/requests/ledgerData.test.ts (3)

3-3: LGTM: Import supports binary ledger entry typing.

The import of LedgerDataBinaryLedgerEntry is correctly added to support the type assertion used in the test assertions.


25-30: LGTM: Inline request object improves readability.

The simplified approach using an inline request object is cleaner than creating a separate LedgerDataRequest object. The binary: true parameter correctly enables binary response format testing, which aligns with the PR's focus on binary value determination.


56-56: LGTM: Type assertion appropriately handles binary ledger entry.

The type assertion to LedgerDataBinaryLedgerEntry is appropriate since the test explicitly requests binary data with binary: true. This ensures proper TypeScript typing for accessing the data property specific to binary entries.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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

🔭 Outside diff range comments (1)
packages/xrpl/src/client/index.ts (1)

393-405: Avoid unsafe type casting in requestNextPage.

The double cast as unknown as U on line 405 bypasses TypeScript's type checking and could hide type errors. Consider using a more type-safe approach.

Instead of casting, ensure the return type is correctly inferred:

-    return this.request(nextPageRequest) as unknown as U
+    return this.request(nextPageRequest) as Promise<RequestNextPageReturnMap<T, B>>
🧹 Nitpick comments (1)
packages/xrpl/src/models/methods/ledger.ts (1)

183-188: Consider the redundancy in LedgerRequestExpandedTransactionsBinary.

The interface extends LedgerRequest<true> and also explicitly defines binary: true. While this ensures type safety, the explicit binary: true property might be redundant since the generic parameter already enforces this.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2309d59 and 6fd0579.

📒 Files selected for processing (9)
  • packages/xrpl/src/client/index.ts (4 hunks)
  • packages/xrpl/src/models/methods/accountTx.ts (6 hunks)
  • packages/xrpl/src/models/methods/baseMethod.ts (4 hunks)
  • packages/xrpl/src/models/methods/index.ts (10 hunks)
  • packages/xrpl/src/models/methods/ledger.ts (6 hunks)
  • packages/xrpl/src/models/methods/ledgerData.ts (3 hunks)
  • packages/xrpl/src/models/methods/ledgerEntry.ts (3 hunks)
  • packages/xrpl/src/models/methods/nftHistory.ts (5 hunks)
  • packages/xrpl/src/models/methods/tx.ts (7 hunks)
🧰 Additional context used
🧠 Learnings (10)
📓 Common learnings
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/test/models/Batch.test.ts:0-0
Timestamp: 2025-04-16T15:22:45.633Z
Learning: Using `as any` type assertions is acceptable in test files for the XRPL.js project, as strict typing is not required for test code.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2874
File: packages/xrpl/test/models/permissionedDomainDelete.test.ts:15-20
Timestamp: 2025-01-08T02:11:21.997Z
Learning: In validation test cases for XRPL transactions, using generic JSON input (e.g., `as any`) is preferred over strict typing as it better represents real-world scenarios where the `validate` method needs to handle arbitrary JSON/map/dictionary input from users.
packages/xrpl/src/models/methods/baseMethod.ts (1)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
packages/xrpl/src/models/methods/ledgerData.ts (3)
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#3027
File: packages/xrpl/src/models/ledger/MPTokenIssuance.ts:13-16
Timestamp: 2025-06-26T17:25:36.429Z
Learning: In the XRPL ecosystem, type choices for amount fields (like `number` vs `string`) in ledger objects such as `LockedAmount` vs `OutstandingAmount` in `MPTokenIssuance` are deliberate design decisions made across multiple products and cannot be changed unilaterally by individual contributors.
packages/xrpl/src/models/methods/index.ts (4)
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
packages/xrpl/src/models/methods/ledgerEntry.ts (2)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
packages/xrpl/src/models/methods/tx.ts (5)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/src/Wallet/batchSigner.ts:0-0
Timestamp: 2025-04-16T15:55:50.121Z
Learning: When using `encodeForSigningBatch` for Batch transactions in the XRPL.js library, the field names should use camelCase (`flags`, `txIDs`) even though the transaction object properties themselves use PascalCase (`Flags`, `TxIDs`).
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/ledger/Credential.ts:36-36
Timestamp: 2024-12-09T07:06:47.258Z
Learning: In TypeScript interfaces, ensure that fields documented as optional are marked with the `?` operator to denote optionality.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:18-18
Timestamp: 2024-10-08T16:29:11.194Z
Learning: `SField.cpp` and `TxFormats.cpp` are located in the `rippled` repository (`https://github.com/XRPLF/rippled/`), not in the current repository.
packages/xrpl/src/models/methods/nftHistory.ts (3)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
Learnt from: mvadari
PR: XRPLF/xrpl.js#2690
File: packages/xrpl/tools/generateModels.js:18-18
Timestamp: 2024-10-08T16:29:11.194Z
Learning: `SField.cpp` and `TxFormats.cpp` are located in the `rippled` repository (`https://github.com/XRPLF/rippled/`), not in the current repository.
packages/xrpl/src/models/methods/accountTx.ts (5)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2801
File: packages/xrpl/src/Wallet/batchSigner.ts:0-0
Timestamp: 2025-04-16T15:55:50.121Z
Learning: When using `encodeForSigningBatch` for Batch transactions in the XRPL.js library, the field names should use camelCase (`flags`, `txIDs`) even though the transaction object properties themselves use PascalCase (`Flags`, `TxIDs`).
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
packages/xrpl/src/client/index.ts (4)
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
packages/xrpl/src/models/methods/ledger.ts (6)
Learnt from: mvadari
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/methods/ledgerEntry.ts:74-85
Timestamp: 2024-12-12T01:12:01.868Z
Learning: In the XRPL.js library, request parameters use camelCase (e.g., `credentialType`), while transaction model fields follow the XRP Ledger protocol's PascalCase convention (e.g., `CredentialType`).
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/clawback.test.ts:165-178
Timestamp: 2024-12-06T19:27:11.147Z
Learning: In the integration tests for `clawback.test.ts`, it's acceptable to use `@ts-expect-error` to bypass type checking when verifying ledger entries, and no additional type safety improvements are needed.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/integration/transactions/mptokenAuthorize.test.ts:29-118
Timestamp: 2024-12-06T19:25:15.376Z
Learning: In the XRPLF/xrpl.js TypeScript client library, when writing tests (e.g., in `packages/xrpl/test/integration/transactions/`), we generally do not need to test rippled server behaviors, because those behaviors are covered by rippled's own integration and unit tests.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#2829
File: packages/xrpl/src/models/ledger/Credential.ts:36-36
Timestamp: 2024-12-09T07:06:47.258Z
Learning: In TypeScript interfaces, ensure that fields documented as optional are marked with the `?` operator to denote optionality.
Learnt from: ckeshava
PR: XRPLF/xrpl.js#3027
File: packages/xrpl/src/models/ledger/MPTokenIssuance.ts:13-16
Timestamp: 2025-06-26T17:25:36.429Z
Learning: In the XRPL ecosystem, type choices for amount fields (like `number` vs `string`) in ledger objects such as `LockedAmount` vs `OutstandingAmount` in `MPTokenIssuance` are deliberate design decisions made across multiple products and cannot be changed unilaterally by individual contributors.
Learnt from: shawnxie999
PR: XRPLF/xrpl.js#2661
File: packages/xrpl/test/models/MPTokenAuthorize.test.ts:60-71
Timestamp: 2024-12-06T18:44:55.095Z
Learning: In the XRPL.js library's TypeScript test file `packages/xrpl/test/models/MPTokenAuthorize.test.ts`, negative test cases for invalid `Account` address format, invalid `Holder` address format, invalid `MPTokenIssuanceID` format, and invalid flag combinations are not necessary.
🧬 Code Graph Analysis (7)
packages/xrpl/src/models/methods/baseMethod.ts (1)
packages/xrpl/src/models/common/index.ts (1)
  • APIVersion (4-4)
packages/xrpl/src/models/methods/ledgerData.ts (2)
packages/xrpl/src/models/methods/index.ts (7)
  • LedgerDataRequest (564-564)
  • BaseRequest (512-512)
  • LedgerDataLedgerState (568-568)
  • LedgerDataBinaryLedgerEntry (566-566)
  • LedgerDataLabeledLedgerEntry (565-565)
  • LedgerDataResponse (567-567)
  • BaseResponse (513-513)
packages/xrpl/src/models/methods/baseMethod.ts (3)
  • BaseRequest (5-17)
  • LookupByLedgerRequest (19-24)
  • BaseResponse (32-41)
packages/xrpl/src/models/methods/ledgerEntry.ts (2)
packages/xrpl/src/models/methods/baseMethod.ts (3)
  • BaseRequest (5-17)
  • LookupByLedgerRequest (19-24)
  • BaseResponse (32-41)
packages/xrpl/src/models/ledger/index.ts (1)
  • LedgerEntry (60-60)
packages/xrpl/src/models/methods/tx.ts (5)
packages/xrpl/src/models/methods/baseMethod.ts (2)
  • BaseRequest (5-17)
  • BaseResponse (32-41)
packages/xrpl/src/models/transactions/index.ts (2)
  • BaseTransaction (1-1)
  • Transaction (7-7)
packages/xrpl/src/models/transactions/transaction.ts (1)
  • Transaction (211-211)
packages/xrpl/src/models/transactions/metadata.ts (1)
  • TransactionMetadata (95-108)
packages/xrpl/src/models/common/index.ts (1)
  • RIPPLED_API_V1 (1-1)
packages/xrpl/src/models/methods/nftHistory.ts (5)
packages/xrpl/src/models/methods/index.ts (5)
  • NFTHistoryRequest (653-653)
  • BaseRequest (512-512)
  • NFTHistoryTransaction (655-655)
  • NFTHistoryResponse (654-654)
  • BaseResponse (513-513)
packages/xrpl/src/models/methods/baseMethod.ts (3)
  • BaseRequest (5-17)
  • LookupByLedgerRequest (19-24)
  • BaseResponse (32-41)
packages/xrpl/src/models/common/index.ts (4)
  • APIVersion (4-4)
  • DEFAULT_API_VERSION (3-3)
  • RIPPLED_API_V2 (2-2)
  • ResponseOnlyTxInfo (110-131)
packages/xrpl/src/models/transactions/index.ts (1)
  • Transaction (7-7)
packages/xrpl/src/models/transactions/metadata.ts (1)
  • TransactionMetadata (95-108)
packages/xrpl/src/models/methods/accountTx.ts (4)
packages/xrpl/src/models/methods/baseMethod.ts (2)
  • BaseRequest (5-17)
  • LookupByLedgerRequest (19-24)
packages/xrpl/src/models/common/index.ts (5)
  • APIVersion (4-4)
  • DEFAULT_API_VERSION (3-3)
  • RIPPLED_API_V2 (2-2)
  • ResponseOnlyTxInfo (110-131)
  • RIPPLED_API_V1 (1-1)
packages/xrpl/src/models/transactions/index.ts (1)
  • Transaction (7-7)
packages/xrpl/src/models/transactions/metadata.ts (1)
  • TransactionMetadata (95-108)
packages/xrpl/src/models/methods/ledger.ts (2)
packages/xrpl/src/models/methods/index.ts (2)
  • LedgerRequest (554-554)
  • BaseRequest (512-512)
packages/xrpl/src/models/methods/baseMethod.ts (2)
  • BaseRequest (5-17)
  • LookupByLedgerRequest (19-24)
🔇 Additional comments (26)
packages/xrpl/src/models/methods/baseMethod.ts (1)

1-1: Type safety improvement for API version fields

The change from number to APIVersion type for the api_version properties improves type safety by restricting the values to the supported API versions (V1 and V2).

Also applies to: 16-16, 40-40, 58-58

packages/xrpl/src/models/methods/ledgerData.ts (3)

23-31: Well-implemented generic parameter for binary mode

The generic Binary parameter with a default value of false maintains backward compatibility while enabling precise typing of the binary mode.


56-60: Correct use of conditional types for discriminated unions

The conditional type correctly discriminates between LedgerDataBinaryLedgerEntry and LedgerDataLabeledLedgerEntry based on the Binary flag, ensuring type safety for consumers.


67-78: Consistent type propagation in response interface

The Binary parameter correctly flows through to the state array type, maintaining type consistency between request and response.

packages/xrpl/src/models/methods/ledgerEntry.ts (3)

22-69: Consistent generic parameter implementation

The Binary generic parameter follows the same pattern as other request interfaces, maintaining consistency across the codebase.


235-245: Good refactoring with LedgerEntryResponseBase

Extracting common response fields into a base interface reduces duplication and improves maintainability.


252-268: Improved type safety with discriminated union

The conditional type ensures mutual exclusivity between node_binary and node properties based on the Binary flag, preventing ambiguous states where both could be present.

packages/xrpl/src/models/methods/index.ts (3)

197-246: Correct selective application of Binary generic

The Binary generic parameter is correctly applied only to request types that support binary mode, maintaining type safety without unnecessary complexity for other requests.


316-476: Comprehensive Binary parameter propagation

The RequestResponseMap correctly propagates the Binary parameter to all relevant response types, maintaining type safety throughout the request-response flow.


4-4: Confirm LedgerEntry import is required

The LedgerEntry import is used for the LedgerEntryResponse<LedgerEntry, Binary> type in the RequestResponseMap (around line 417), so it’s necessary. Approving this change.

packages/xrpl/src/models/methods/tx.ts (6)

1-1: Clean import statement

Good cleanup removing the unused RIPPLED_API_V2 import.


13-28: Consistent Binary generic implementation

The TxRequest interface follows the established pattern with the Binary generic parameter.


50-72: Improved type structure with simplified BaseTxResult

Moving the format-specific fields (meta_blob, meta, etc.) from BaseTxResult to the conditional types in the response interfaces improves type safety by ensuring these fields only appear in the appropriate context.


79-109: Well-structured conditional response types

The TxResponse interface correctly discriminates between binary and JSON responses, ensuring type safety for consumers.


116-145: Correct V1-specific field naming

The conditional types correctly use V1-specific field names (tx and meta) for binary responses, maintaining compatibility with the V1 API.


152-157: Proper version mapping with Binary parameter

The TxVersionResponseMap correctly propagates the Binary parameter to both V1 and V2 response types.

packages/xrpl/src/models/methods/nftHistory.ts (4)

1-6: LGTM! Imports support the new generic type system.

The added imports are necessary for implementing the generic type parameters and API version discriminations.


18-20: Good implementation of generic binary parameter.

The generic Binary parameter with a default value of false maintains backward compatibility while enabling stronger typing for binary mode requests.

Also applies to: 42-42


69-111: Verify the inconsistent date/time fields across different modes.

The discriminated union type correctly handles different response shapes, but there are inconsistencies in date/time fields:

  • V2 binary mode uses date
  • V2 JSON mode uses close_time_iso
  • V1 binary mode uses date
  • V1 JSON mode has no date/time field

Please confirm these differences align with the rippled API specification.


117-120: Well-structured generic response interface.

The generic parameters correctly flow through to the transactions array type, ensuring type-safe responses based on the request parameters.

Also applies to: 147-147

packages/xrpl/src/models/methods/ledger.ts (1)

29-31: Consistent implementation of generic binary parameter.

The changes align with the pattern used across other request interfaces, providing stronger typing for the binary flag.

Also applies to: 66-66

packages/xrpl/src/models/methods/accountTx.ts (3)

19-21: Consistent generic implementation.

The changes follow the established pattern for binary mode typing.

Also applies to: 41-41


68-108: Verify property naming consistency across similar types.

The discriminated union structure is well-implemented, but there are naming inconsistencies compared to NFTHistoryTransaction:

  • V1 binary uses meta (string) here vs meta_blob in NFTHistoryTransaction
  • Different date/time field handling

Please confirm these differences align with the rippled API specification for each endpoint.


155-156: Well-structured response type generics.

The response types correctly propagate the generic parameters while maintaining backward compatibility through default values.

Also applies to: 163-164, 171-177

packages/xrpl/src/client/index.ts (2)

17-18: Required imports for API version inference.

The API version constants are necessary for the enhanced type inference in the request methods.


126-126: Correct generic parameterization of paginated request types.

Only the request types that support binary mode are parameterized with the Binary generic, which is the correct approach.

Also applies to: 131-132

Comment on lines +346 to +351
R extends Request<B>,
V extends APIVersion = R['api_version'] extends typeof RIPPLED_API_V1
? typeof RIPPLED_API_V1
: typeof RIPPLED_API_V2,
B extends boolean = R['binary'] extends true ? true : false,
T = RequestResponseMap<R, V, B>,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Review the generic constraint order in the request method.

The generic signature has a potential issue where R extends Request<B> uses B before it's defined in the parameter list. This might cause TypeScript compilation issues.

Consider reordering the generic parameters or using a different constraint pattern:

-public async request<
-  R extends Request<B>,
-  V extends APIVersion = R['api_version'] extends typeof RIPPLED_API_V1
-    ? typeof RIPPLED_API_V1
-    : typeof RIPPLED_API_V2,
-  B extends boolean = R['binary'] extends true ? true : false,
-  T = RequestResponseMap<R, V, B>,
->(req: R): Promise<T> {
+public async request<
+  R extends Request,
+  V extends APIVersion = R['api_version'] extends typeof RIPPLED_API_V1
+    ? typeof RIPPLED_API_V1
+    : typeof RIPPLED_API_V2,
+  B extends boolean = R['binary'] extends true ? true : false,
+  T = RequestResponseMap<R, V, B>,
+>(req: R): Promise<T> {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
R extends Request<B>,
V extends APIVersion = R['api_version'] extends typeof RIPPLED_API_V1
? typeof RIPPLED_API_V1
: typeof RIPPLED_API_V2,
B extends boolean = R['binary'] extends true ? true : false,
T = RequestResponseMap<R, V, B>,
public async request<
R extends Request,
V extends APIVersion = R['api_version'] extends typeof RIPPLED_API_V1
? typeof RIPPLED_API_V1
: typeof RIPPLED_API_V2,
B extends boolean = R['binary'] extends true ? true : false,
T = RequestResponseMap<R, V, B>,
>(req: R): Promise<T> {
// …
}
🤖 Prompt for AI Agents
In packages/xrpl/src/client/index.ts around lines 346 to 351, the generic
parameter B is used in the constraint of R before B is defined, which can cause
TypeScript compilation errors. To fix this, reorder the generic parameters so
that B is declared before R, or refactor the constraints to avoid referencing B
before its declaration. Ensure that all generic parameters are declared before
they are used in constraints.

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.

1 participant