mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 20:55:48 +00:00
fix: make docs not output confusing information in xrpl client (#2337)
* fix: make docs not output confusing information in xrpl client --------- Co-authored-by: Jackson Mills <jmills@ripple.com> Co-authored-by: Caleb Kniffen <ckniffen@ripple.com>
This commit is contained in:
committed by
Caleb Kniffen
parent
21c2423bac
commit
3b70a3b919
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-inline-comments -- Necessary for important note */
|
||||
/* eslint-disable max-lines -- There is a lot to export */
|
||||
import {
|
||||
AccountChannelsRequest,
|
||||
@@ -71,6 +72,11 @@ import {
|
||||
LedgerQueueData,
|
||||
LedgerRequest,
|
||||
LedgerResponse,
|
||||
LedgerRequestExpandedTransactionsOnly,
|
||||
LedgerResponseExpanded,
|
||||
LedgerRequestExpandedAccountsAndTransactions,
|
||||
LedgerRequestExpandedAccountsOnly,
|
||||
LedgerRequestExpandedTransactionsBinary,
|
||||
} from './ledger'
|
||||
import { LedgerClosedRequest, LedgerClosedResponse } from './ledgerClosed'
|
||||
import { LedgerCurrentRequest, LedgerCurrentResponse } from './ledgerCurrent'
|
||||
@@ -259,6 +265,177 @@ type Response =
|
||||
// AMM methods
|
||||
| AMMInfoResponse
|
||||
|
||||
export type RequestResponseMap<T> = T extends AccountChannelsRequest
|
||||
? AccountChannelsResponse
|
||||
: T extends AccountCurrenciesRequest
|
||||
? AccountCurrenciesResponse
|
||||
: T extends AccountInfoRequest
|
||||
? AccountInfoResponse
|
||||
: T extends AccountLinesRequest
|
||||
? AccountLinesResponse
|
||||
: T extends AccountNFTsRequest
|
||||
? AccountNFTsResponse
|
||||
: T extends AccountObjectsRequest
|
||||
? AccountObjectsResponse
|
||||
: T extends AccountOffersRequest
|
||||
? AccountOffersResponse
|
||||
: T extends AccountTxRequest
|
||||
? AccountTxResponse
|
||||
: T extends AMMInfoRequest
|
||||
? AMMInfoResponse
|
||||
: T extends GatewayBalancesRequest
|
||||
? GatewayBalancesResponse
|
||||
: T extends NoRippleCheckRequest
|
||||
? NoRippleCheckResponse
|
||||
: // NOTE: The order of these LedgerRequest types is important
|
||||
// to get the proper type matching overrides based on parameters set
|
||||
// in the request. For example LedgerRequestExpandedTransactionsBinary
|
||||
// should match LedgerRequestExpandedTransactionsOnly, but not
|
||||
// LedgerRequestExpandedAccountsOnly. This is because the
|
||||
// LedgerRequestExpandedTransactionsBinary type is a superset of
|
||||
// LedgerRequestExpandedTransactionsOnly, but not of the other.
|
||||
// This is why LedgerRequestExpandedTransactionsBinary is listed
|
||||
// first in the type list.
|
||||
//
|
||||
// Here is an example using real data:
|
||||
// LedgerRequestExpandedTransactionsBinary = {
|
||||
// command: 'ledger',
|
||||
// ledger_index: 'validated',
|
||||
// expand: true,
|
||||
// transactions: true,
|
||||
// binary: true,
|
||||
// }
|
||||
// LedgerRequestExpandedTransactionsOnly = {
|
||||
// command: 'ledger',
|
||||
// ledger_index: 'validated',
|
||||
// expand: true,
|
||||
// transactions: true,
|
||||
// }
|
||||
// LedgerRequestExpandedAccountsOnly = {
|
||||
// command: 'ledger',
|
||||
// ledger_index: 'validated',
|
||||
// accounts: true,
|
||||
// expand: true,
|
||||
// }
|
||||
// LedgerRequest = {
|
||||
// command: 'ledger',
|
||||
// ledger_index: 'validated',
|
||||
// }
|
||||
//
|
||||
// The type with the most parameters set should be listed first. In this
|
||||
// case LedgerRequestExpandedTransactionsBinary has the most parameters (`expand`, `transactions`, and `binary`)
|
||||
// set, so it is listed first. When TypeScript tries to match the type of
|
||||
// a request to a response, it will try to match the request type to the
|
||||
// response type in the order they are listed. So, if we have a request
|
||||
// with the following parameters:
|
||||
// {
|
||||
// command: 'ledger',
|
||||
// ledger_index: 'validated',
|
||||
// expand: true,
|
||||
// transactions: true,
|
||||
// binary: true,
|
||||
// }
|
||||
// TypeScript will first try to match the request type to
|
||||
// LedgerRequestExpandedTransactionsBinary, which will succeed. It will
|
||||
// then try to match the response type to LedgerResponseExpanded, which
|
||||
// will also succeed. If we had listed LedgerRequestExpandedTransactionsOnly
|
||||
// first, TypeScript would have tried to match the request type to
|
||||
// LedgerRequestExpandedTransactionsOnly, which would have succeeded, but
|
||||
// then we'd get the wrong response type, LedgerResponse, instead of
|
||||
// LedgerResponseExpanded.
|
||||
T extends LedgerRequestExpandedTransactionsBinary
|
||||
? LedgerResponse
|
||||
: T extends LedgerRequestExpandedAccountsAndTransactions
|
||||
? LedgerResponseExpanded
|
||||
: T extends LedgerRequestExpandedTransactionsOnly
|
||||
? LedgerResponseExpanded
|
||||
: T extends LedgerRequestExpandedAccountsOnly
|
||||
? LedgerResponseExpanded
|
||||
: T extends LedgerRequest
|
||||
? LedgerResponse
|
||||
: T extends LedgerClosedRequest
|
||||
? LedgerClosedResponse
|
||||
: T extends LedgerCurrentRequest
|
||||
? LedgerCurrentResponse
|
||||
: T extends LedgerDataRequest
|
||||
? LedgerDataResponse
|
||||
: T extends LedgerEntryRequest
|
||||
? LedgerEntryResponse
|
||||
: T extends SubmitRequest
|
||||
? SubmitResponse
|
||||
: T extends SubmitMultisignedRequest
|
||||
? SubmitMultisignedResponse
|
||||
: T extends TransactionEntryRequest
|
||||
? TransactionEntryResponse
|
||||
: T extends TxRequest
|
||||
? TxResponse
|
||||
: T extends BookOffersRequest
|
||||
? BookOffersResponse
|
||||
: T extends DepositAuthorizedRequest
|
||||
? DepositAuthorizedResponse
|
||||
: T extends PathFindRequest
|
||||
? PathFindResponse
|
||||
: T extends RipplePathFindRequest
|
||||
? RipplePathFindResponse
|
||||
: T extends ChannelVerifyRequest
|
||||
? ChannelVerifyResponse
|
||||
: T extends SubscribeRequest
|
||||
? SubscribeResponse
|
||||
: T extends UnsubscribeRequest
|
||||
? UnsubscribeResponse
|
||||
: T extends FeeRequest
|
||||
? FeeResponse
|
||||
: T extends ManifestRequest
|
||||
? ManifestResponse
|
||||
: T extends ServerInfoRequest
|
||||
? ServerInfoResponse
|
||||
: T extends ServerStateRequest
|
||||
? ServerStateResponse
|
||||
: T extends ServerDefinitionsRequest
|
||||
? ServerDefinitionsResponse
|
||||
: T extends PingRequest
|
||||
? PingResponse
|
||||
: T extends RandomRequest
|
||||
? RandomResponse
|
||||
: T extends NFTBuyOffersRequest
|
||||
? NFTBuyOffersResponse
|
||||
: T extends NFTSellOffersRequest
|
||||
? NFTSellOffersResponse
|
||||
: T extends NFTInfoRequest
|
||||
? NFTInfoResponse
|
||||
: T extends NFTHistoryRequest
|
||||
? NFTHistoryResponse
|
||||
: Response
|
||||
|
||||
export type MarkerRequest = Request & {
|
||||
limit?: number
|
||||
marker?: unknown
|
||||
}
|
||||
|
||||
export type MarkerResponse = Response & {
|
||||
result: {
|
||||
marker?: unknown
|
||||
}
|
||||
}
|
||||
|
||||
export type RequestAllResponseMap<T> = T extends AccountChannelsRequest
|
||||
? AccountChannelsResponse
|
||||
: T extends AccountLinesRequest
|
||||
? AccountLinesResponse
|
||||
: T extends AccountObjectsRequest
|
||||
? AccountObjectsResponse
|
||||
: T extends AccountOffersRequest
|
||||
? AccountOffersResponse
|
||||
: T extends AccountTxRequest
|
||||
? AccountTxResponse
|
||||
: T extends LedgerDataRequest
|
||||
? LedgerDataResponse
|
||||
: T extends AccountTxRequest
|
||||
? AccountTxResponse
|
||||
: T extends BookOffersRequest
|
||||
? BookOffersResponse
|
||||
: MarkerResponse
|
||||
|
||||
export {
|
||||
// Allow users to define their own requests and responses. This is useful for releasing experimental versions
|
||||
BaseRequest,
|
||||
|
||||
Reference in New Issue
Block a user