From 11ecd426f3f793d715bcef4e7e591c498e88d1fd Mon Sep 17 00:00:00 2001 From: Alexander T Date: Tue, 29 Oct 2019 05:53:33 +0200 Subject: [PATCH] stellar-sdk: Provides its own types (#39549) --- notNeededPackages.json | 6 + types/stellar-sdk/index.d.ts | 665 ------------------------- types/stellar-sdk/stellar-sdk-tests.ts | 4 - types/stellar-sdk/tsconfig.json | 23 - types/stellar-sdk/tslint.json | 3 - 5 files changed, 6 insertions(+), 695 deletions(-) delete mode 100644 types/stellar-sdk/index.d.ts delete mode 100644 types/stellar-sdk/stellar-sdk-tests.ts delete mode 100644 types/stellar-sdk/tsconfig.json delete mode 100644 types/stellar-sdk/tslint.json diff --git a/notNeededPackages.json b/notNeededPackages.json index 8c3de9d58c..2dc9d92ec1 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -3798,6 +3798,12 @@ "sourceRepoURL": "https://servicestack.net/", "asOfVersion": "0.1.5" }, + { + "libraryName": "stellar-sdk", + "typingsPackageName": "stellar-sdk", + "sourceRepoURL": "https://github.com/stellar/js-stellar-sdk", + "asOfVersion": "0.15.1" + }, { "libraryName": "@storybook/addon-a11y", "typingsPackageName": "storybook__addon-a11y", diff --git a/types/stellar-sdk/index.d.ts b/types/stellar-sdk/index.d.ts deleted file mode 100644 index cf05b3412d..0000000000 --- a/types/stellar-sdk/index.d.ts +++ /dev/null @@ -1,665 +0,0 @@ -// Type definitions for stellar-sdk 0.11 -// Project: https://github.com/stellar/js-stellar-sdk -// Definitions by: Carl Foster -// Triston Jones -// Paul Selden -// Max Bause -// Timur Ramazanov -// Kalvis Kalniņš -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.9 - -/// - -import { AssetType, Asset, Memo, MemoType, Transaction } from 'stellar-base'; - -// Re-StellarBase -export { - Account, - Asset, - AssetType, - AuthFlag, - AuthImmutableFlag, - AuthRequiredFlag, - AuthRevocableFlag, - FastSigning, - Keypair, - Memo, - MemoType, - MemoValue, - MemoHash, - MemoID, - MemoNone, - MemoReturn, - MemoText, - Network, - Networks, - Operation, - OperationOptions, - OperationType, - StrKey, - Signer, - SignerOptions, - Transaction, - TransactionBuilder, - hash, - sign, - verify, - xdr -} from 'stellar-base'; - -// Shorthands, not-to-export. -export {}; -type Key = string|number|symbol; -type Diff = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]; -type Omit = Pick>; - -export class NetworkError extends Error { - private response: any; - constructor(message: string, response: any) - getResponse(): any; -} -export class NotFoundError extends NetworkError {} -export class BadRequestError extends NetworkError {} -export class BadResponseError extends NetworkError {} - -export namespace Config { - function setAllowHttp(allow: boolean): void; - function isAllowHttp(): boolean; - function setDefault(): void; -} - -export class Server { - constructor(serverURL: string, options?: Server.Options) - accounts(): Server.AccountCallBuilder; - assets(): Server.AssetsCallBuilder; - effects(): Server.EffectCallBuilder; - ledgers(): Server.LedgerCallBuilder; - loadAccount(accountId: string): Promise; - offers(resource: string, ...parameters: string[]): Server.OfferCallBuilder; - operations(): Server.OperationCallBuilder; - orderbook(selling: Asset, buying: Asset): Server.OrderbookCallBuilder; - paths( - source: string, - destination: string, - destinationAsset: Asset, - destinationAmount: string, - ): Server.PathCallBuilder; - payments(): Server.PaymentCallBuilder; - submitTransaction(transaction: Transaction): Promise; - tradeAggregation( - base: Asset, - counter: Asset, - startTime: Date, - endTime: Date, - resolution: Date, - ): Server.TradeAggregationCallBuilder; - trades(): Server.TradesCallBuilder; - transactions(): Server.TransactionCallBuilder; - - serverURL: any; // TODO: require("urijs") -} - -export namespace Server { - abstract class CallBuilder { - constructor(serverUrl: string) - call(): Promise>; - cursor(cursor: string): this; - limit(limit: number | string): this; - order(direction: 'asc' | 'desc'): this; - stream(options?: { onmessage?: (record: T) => void, onerror?: (error: Error) => void }): () => void; - } - - interface CollectionPage { - records: T[]; - next: () => Promise>; - prev: () => Promise>; - } - - /* Due to a bug with the recursive function requests */ - interface CollectionRecord { - _links: { - next: Horizon.ResponseLink - prev: Horizon.ResponseLink - self: Horizon.ResponseLink - }; - _embedded: { - records: T[] - }; - } - - interface CallFunctionTemplateOptions { - cursor?: string | number; - limit?: number; - order?: 'asc' | 'desc'; - } - - type CallFunction = () => Promise; - type CallCollectionFunction = - (options?: CallFunctionTemplateOptions) => Promise>; - - interface AccountRecord extends Horizon.BaseResponse { - id: string; - paging_token: string; - account_id: string; - sequence: number; - subentry_count: number; - thresholds: Horizon.AccountThresholds; - flags: Horizon.Flags; - balances: Horizon.BalanceLine[]; - signers: Array< - { - public_key: string - weight: number - } - >; - data: (options: {value: string}) => Promise<{value: string}>; - data_attr: { - [key: string]: string - }; - effects: CallCollectionFunction; - offers: CallCollectionFunction; - operations: CallCollectionFunction; - payments: CallCollectionFunction; - trades: CallCollectionFunction; - } - - interface AssetRecord extends Horizon.BaseResponse { - asset_type: AssetType.credit4 | AssetType.credit12; - asset_code: string; - asset_issuer: string; - paging_token: string; - amount: string; - num_accounts: number; - flags: Horizon.Flags; - } - - interface EffectRecord extends Horizon.BaseResponse { - account: string; - paging_token: string; - starting_balance: string; - type_i: string; - type: string; - amount?: any; - - operation?: CallFunction; - precedes?: CallFunction; - succeeds?: CallFunction; - } - - interface LedgerRecord extends Horizon.BaseResponse { - id: string; - paging_token: string; - hash: string; - prev_hash: string; - sequence: number; - transaction_count: number; - operation_count: number; - closed_at: string; - total_coins: string; - fee_pool: string; - base_fee: number; - base_reserve: string; - max_tx_set_size: number; - protocol_version: number; - header_xdr: string; - base_fee_in_stroops: number; - base_reserve_in_stroops: number; - - effects: CallCollectionFunction; - operations: CallCollectionFunction; - self: CallFunction; - transactions: CallCollectionFunction; - } - - interface OfferRecord extends Horizon.BaseResponse { - id: string; - paging_token: string; - seller_attr: string; - selling: Asset; - buying: Asset; - amount: string; - price_r: Horizon.PriceR; - price: string; - - seller?: CallFunction; - } - - import OperationResponseType = Horizon.OperationResponseType; - import OperationResponseTypeI = Horizon.OperationResponseTypeI; - interface BaseOperationRecord< - T extends OperationResponseType = OperationResponseType, - TI extends OperationResponseTypeI = OperationResponseTypeI, - > extends Horizon.BaseOperationResponse { - self: CallFunction; - succeeds: CallFunction; - precedes: CallFunction; - effects: CallCollectionFunction; - transaction: CallFunction; - } - - interface CreateAccountOperationRecord extends BaseOperationRecord, Horizon.CreateAccountOperationResponse {} - interface PaymentOperationRecord extends BaseOperationRecord, Horizon.PaymentOperationResponse { - sender: CallFunction; - receiver: CallFunction; - } - interface PathPaymentOperationRecord extends BaseOperationRecord, Horizon.PathPaymentOperationResponse {} - interface ManageOfferOperationRecord extends BaseOperationRecord, Horizon.ManageOfferOperationResponse {} - interface PassiveOfferOperationRecord extends BaseOperationRecord, Horizon.PassiveOfferOperationResponse {} - interface SetOptionsOperationRecord extends BaseOperationRecord, Horizon.SetOptionsOperationResponse {} - interface ChangeTrustOperationRecord extends BaseOperationRecord, Horizon.ChangeTrustOperationResponse {} - interface AllowTrustOperationRecord extends BaseOperationRecord, Horizon.AllowTrustOperationResponse {} - interface AccountMergeOperationRecord extends BaseOperationRecord, Horizon.AccountMergeOperationResponse {} - interface InflationOperationRecord extends BaseOperationRecord, Horizon.InflationOperationResponse {} - interface ManageDataOperationRecord extends BaseOperationRecord, Horizon.ManageDataOperationResponse {} - interface BumpSequenceOperationRecord extends BaseOperationRecord, Horizon.BumpSequenceOperationResponse {} - - type OperationRecord = CreateAccountOperationRecord - | PaymentOperationRecord - | PathPaymentOperationRecord - | ManageOfferOperationRecord - | PassiveOfferOperationRecord - | SetOptionsOperationRecord - | ChangeTrustOperationRecord - | AllowTrustOperationRecord - | AccountMergeOperationRecord - | InflationOperationRecord - | ManageDataOperationRecord - | BumpSequenceOperationRecord; - - interface OrderbookRecord extends Horizon.BaseResponse { - bids: Array<{ price_r: {}, price: number, amount: string }>; - asks: Array<{ price_r: {}, price: number, amount: string }>; - selling: Asset; - buying: Asset; - } - - interface PaymentPathRecord extends Horizon.BaseResponse { - path: Array<{ - asset_code: string - asset_issuer: string - asset_type: string - }>; - source_amount: string; - source_asset_type: string; - source_asset_code: string; - source_asset_issuer: string; - destination_amount: string; - destination_asset_type: string; - destination_asset_code: string; - destination_asset_issuer: string; - } - - interface TradeRecord extends Horizon.BaseResponse { - id: string; - paging_token: string; - ledger_close_time: string; - base_account: string; - base_amount: string; - base_asset_type: string; - base_asset_code: string; - base_asset_issuer: string; - counter_account: string; - counter_amount: string; - counter_asset_type: string; - counter_asset_code: string; - counter_asset_issuer: string; - base_is_seller: boolean; - - base: CallFunction; - counter: CallFunction; - operation: CallFunction; - } - - interface TradeAggregationRecord extends Horizon.BaseResponse { - timestamp: string; - trade_count: number; - base_volume: string; - counter_volume: string; - avg: string; - high: string; - low: string; - open: string; - close: string; - } - - interface TransactionRecord extends Omit { - ledger_attr: Horizon.TransactionResponse['ledger']; - - account: CallFunction; - effects: CallCollectionFunction; - ledger: CallFunction; - operations: CallCollectionFunction; - precedes: CallFunction; - self: CallFunction; - succeeds: CallFunction; - } - - abstract class AccountCallBuilder extends CallBuilder { - accountId(id: string): this; - } - class AccountResponse implements AccountRecord { - _links: { [key in 'self']: Horizon.ResponseLink }; - id: string; - paging_token: string; - account_id: string; - sequence: number; - subentry_count: number; - thresholds: Horizon.AccountThresholds; - flags: Horizon.Flags; - balances: Horizon.BalanceLine[]; - signers: Horizon.AccountSigner[]; - data: (options: {value: string}) => Promise<{value: string}>; - data_attr: { - [key: string]: string - }; - inflation_destination?: any; - - effects: CallCollectionFunction; - offers: CallCollectionFunction; - operations: CallCollectionFunction; - payments: CallCollectionFunction; - trades: CallCollectionFunction; - constructor(response: AccountRecord) - accountId(): string; - sequenceNumber(): string; - incrementSequenceNumber(): void; - } - - abstract class AssetsCallBuilder extends CallBuilder { - forCode(value: string): this; - forIssuer(value: string): this; - } - - abstract class EffectCallBuilder extends CallBuilder { - forAccount(accountId: string): this; - forLedger(sequence: string): this; - forOperation(operationId: number): this; - forTransaction(transactionId: string): this; - } - - abstract class LedgerCallBuilder extends CallBuilder { } - - abstract class OfferCallBuilder extends CallBuilder { } - - abstract class OperationCallBuilder extends CallBuilder { - forAccount(accountId: string): this; - forLedger(sequence: string): this; - forTransaction(transactionId: string): this; - } - abstract class OrderbookCallBuilder extends CallBuilder { } - abstract class PathCallBuilder extends CallBuilder { } - abstract class PaymentCallBuilder extends CallBuilder { - forAccount(accountId: string): this; - forLedger(sequence: string): this; - forTransaction(transactionId: string): this; - } - - interface Options { - allowHttp: boolean; - } - - abstract class TradeAggregationCallBuilder extends CallBuilder { } - abstract class TradesCallBuilder extends CallBuilder { - forAssetPair(base: Asset, counter: Asset): this; - forOffer(offerId: string): this; - } - - abstract class TransactionCallBuilder extends CallBuilder { - transaction(transactionId: string): this; - forAccount(accountId: string): this; - forLedger(sequence: string | number): this; - } -} - -export class FederationServer { - static createForDomain(domain: string, options?: FederationServer.Options): Promise; - static resolve(value: string, options?: FederationServer.Options): Promise; - - constructor(serverURL: string, domain: string, options?: FederationServer.Options) - resolveAccountId(account: string): Promise; - resolveAddress(address: string): Promise; - resolveTransactionId(transactionId: string): Promise; -} -export namespace FederationServer { - interface Record { - account_id: string; - memo_type?: string; - memo?: string; - } - - interface Options { - allowHttp: boolean; - } -} - -export namespace StellarTomlResolver { - interface StellarTomlResolveOptions { - allowHttp?: boolean; - timeout?: number; - } - - function resolve(domain: string, options?: StellarTomlResolveOptions): Promise<{ [key: string]: any }>; -} - -export namespace Horizon { - interface ResponseLink { - href: string; - templated?: boolean; - } - interface BaseResponse { - _links: { - [key in T|'self']: ResponseLink - }; - } - interface TransactionResponse extends BaseResponse<'account'|'ledger'|'operations'|'effects'|'succeeds'|'precedes'> { - created_at: string; - envelope_xdr: string; - fee_meta_xdr: string; - fee_paid: number; - hash: string; - id: string; - ledger: number; - memo_type: MemoType; - memo?: string; - operation_count: number; - paging_token: string; - result_meta_xdr: string; - result_xdr: string; - signatures: string[]; - source_account: string; - source_account_sequence: string; - } - - interface BalanceLineNative { - balance: string; - asset_type: AssetType.native; - } - interface BalanceLineAsset { - balance: string; - limit: string; - asset_type: T; - asset_code: string; - asset_issuer: string; - } - type BalanceLine = - T extends AssetType.native ? BalanceLineNative : - T extends AssetType.credit4 | AssetType.credit12 ? BalanceLineAsset : - BalanceLineNative | BalanceLineAsset; - - interface PriceR { - numerator: number; - denominator: number; - } - interface AccountThresholds { - low_threshold: number; - med_threshold: number; - high_threshold: number; - } - interface Flags { - auth_required: boolean; - auth_revocable: boolean; - } - interface AccountSigner { - public_key: string; - weight: number; - } - interface AccountResponse extends BaseResponse<'transactions'|'operations'|'payments'|'effects'|'offers'|'trades'|'data'> { - id: string; - paging_token: string; - account_id: string; - sequence: string; - subentry_count: number; - thresholds: AccountThresholds; - flags: Flags; - balances: BalanceLine[]; - signers: AccountSigner[]; - data: { - [key: string]: string - }; - } - - enum OperationResponseType { - createAccount = 'create_account', - payment = 'payment', - pathPayment = 'path_payment', - createPassiveOffer = 'create_passive_offer', - manageOffer = 'manage_offer', - setOptions = 'set_options', - changeTrust = 'change_trust', - allowTrust = 'allow_trust', - accountMerge = 'account_merge', - inflation = 'inflation', - manageData = 'manage_data', - bumpSequence = 'bump_sequence', - } - enum OperationResponseTypeI { - createAccount = 0, - payment = 1, - pathPayment = 2, - createPassiveOffer = 3, - manageOffer = 4, - setOptions = 5, - changeTrust = 6, - allowTrust = 7, - accountMerge = 8, - inflation = 9, - manageData = 10, - bumpSequence = 11, - } - interface BaseOperationResponse< - T extends OperationResponseType = OperationResponseType, - TI extends OperationResponseTypeI = OperationResponseTypeI, - > extends BaseResponse<'succeeds'|'precedes'|'effects'|'transaction'> { - id: string; - paging_token: string; - source_account: string; - type: T; - type_i: TI; - created_at: string; - transaction_hash: string; - } - interface CreateAccountOperationResponse extends BaseOperationResponse { - account: string; - funder: string; - starting_balance: string; - } - interface PaymentOperationResponse extends BaseOperationResponse { - from: string; - to: string; - asset_type: AssetType; - asset_code?: string; - asset_issuer?: string; - amount: string; - } - interface PathPaymentOperationResponse extends BaseOperationResponse { - from: string; - to: string; - asset_type: AssetType; - asset_code?: string; - asset_issuer?: string; - amount: string; - source_asset_type: AssetType; - source_asset_code?: string; - source_asset_issuer?: string; - source_max: string; - source_amount: string; - } - interface ManageOfferOperationResponse extends BaseOperationResponse { - offer_id: number; - amount: string; - buying_asset_type: AssetType; - buying_asset_code?: string; - buying_asset_issuer?: string; - price: string; - price_r: PriceR; - selling_asset_type: AssetType; - selling_asset_code?: string; - selling_asset_issuer?: string; - } - interface PassiveOfferOperationResponse extends BaseOperationResponse { - offer_id: number; - amount: string; - buying_asset_type: AssetType; - buying_asset_code?: string; - buying_asset_issuer?: string; - price: string; - price_r: PriceR; - selling_asset_type: AssetType; - selling_asset_code?: string; - selling_asset_issuer?: string; - } - interface SetOptionsOperationResponse extends BaseOperationResponse { - signer_key?: string; - signer_weight?: number; - master_key_weight?: number; - low_threshold?: number; - med_threshold?: number; - high_threshold?: number; - home_domain?: string; - set_flags: Array<(1 | 2)>; - set_flags_s: Array<('auth_required_flag' | 'auth_revocable_flag')>; - clear_flags: Array<(1 | 2)>; - clear_flags_s: Array<('auth_required_flag' | 'auth_revocable_flag')>; - } - interface ChangeTrustOperationResponse extends BaseOperationResponse { - asset_type: AssetType.credit4 | AssetType.credit12; - asset_code: string; - asset_issuer: string; - trustee: string; - trustor: string; - limit: string; - } - interface AllowTrustOperationResponse extends BaseOperationResponse { - asset_type: AssetType; - asset_code: string; - asset_issuer: string; - authorize: boolean; - trustee: string; - trustor: string; - } - interface AccountMergeOperationResponse extends BaseOperationResponse { - into: string; - } - interface InflationOperationResponse extends BaseOperationResponse { - } - interface ManageDataOperationResponse extends BaseOperationResponse { - name: string; - value: Buffer; - } - interface BumpSequenceOperationResponse extends BaseOperationResponse { - bump_to: string; - } - - interface ResponseCollection { - _links: { - self: ResponseLink - next: ResponseLink - prev: ResponseLink - }; - _embedded: { - records: T[] - }; - } - interface TransactionResponseCollection extends ResponseCollection {} -} diff --git a/types/stellar-sdk/stellar-sdk-tests.ts b/types/stellar-sdk/stellar-sdk-tests.ts deleted file mode 100644 index d531fc850f..0000000000 --- a/types/stellar-sdk/stellar-sdk-tests.ts +++ /dev/null @@ -1,4 +0,0 @@ -import * as StellarSdk from 'stellar-sdk'; - -StellarSdk.StellarTomlResolver.resolve("example.com", {allowHttp: true, timeout: 100}) - .then(toml => toml.FEDERATION_SERVER); diff --git a/types/stellar-sdk/tsconfig.json b/types/stellar-sdk/tsconfig.json deleted file mode 100644 index 12dfa57fa0..0000000000 --- a/types/stellar-sdk/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "stellar-sdk-tests.ts" - ] -} diff --git a/types/stellar-sdk/tslint.json b/types/stellar-sdk/tslint.json deleted file mode 100644 index f93cf8562a..0000000000 --- a/types/stellar-sdk/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "dtslint/dt.json" -}