1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-12-27 07:07:50 +01:00

fix: improve typedefs

Signed-off-by: getlarge <ed@getlarge.eu>
This commit is contained in:
getlarge 2021-03-11 13:05:14 +01:00
parent 71a231a50a
commit 6aeece49cb
No known key found for this signature in database
GPG Key ID: E4E13243600F9566
6 changed files with 31 additions and 16 deletions

View File

@ -26,6 +26,6 @@ declare function handleResponse(res: Response): Response;
export default function baseRequest(
url: string,
config: RequestConfig = {},
config: RequestConfig,
requestTimeout?: number
): Promise<Response>;

View File

@ -12,7 +12,6 @@ import type {
TransactionCommon,
} from './transaction';
declare const HEADER_BLACKLIST = ['content-type'];
declare const DEFAULT_NODE = 'http://localhost:9984/api/v1/';
declare const DEFAULT_TIMEOUT = 20000; // The default value is 20 seconds
@ -88,7 +87,7 @@ export default class Connection {
constructor(
nodes: string | InputNode | (string | InputNode)[],
headers: Record<string, string | string[]> = {},
headers?: Record<string, string | string[]>,
timeout?: number
);
@ -97,11 +96,11 @@ export default class Connection {
headers: Record<string, string | string[]>
): Node;
static getApiUrls<E = Endpoint>(endpoint: E): EndpointsUrl[E];
static getApiUrls<E extends keyof EndpointsUrl>(endpoint: E): EndpointsUrl[E];
private _req<E = Endpoint, O = Record<string, any>>(
private _req<E extends keyof EndpointsUrl, O = Record<string, any>>(
path: EndpointsUrl[E],
options: RequestConfig = {}
options: RequestConfig
): Promise<O>;
getBlock(

4
types/request.d.ts vendored
View File

@ -17,9 +17,9 @@ export default class Request {
constructor(node: Node);
async request<O = Record<string, any>>(
request<O = Record<string, any>>(
urlPath: string,
config: RequestConfig = {},
config?: RequestConfig,
timeout?: number,
maxBackoffTime?: number
): Promise<O>;

View File

@ -96,13 +96,23 @@ interface TxTemplate {
version: '2.0';
}
declare function DelegateSignFunction(
declare type DelegateSignFunction = (
serializedTransaction: string,
input: TransactionInput,
index?: number
): string;
) => string;
declare type DelegateSignFunctionAsync = (
serializedTransaction: string,
input: TransactionInput,
index?: number
) => Promise<string>;
export default class Transaction {
static serializeTransactionIntoCanonicalString<O = TransactionOperations>(
transaction: TransactionCommon<O>
): string;
static serializeTransactionIntoCanonicalString(
transaction: CreateTransaction | TransferTransaction
): string;
@ -118,7 +128,7 @@ export default class Transaction {
static makeEd25519Condition(
publicKey: string,
json: boolean = true
json?: boolean
): Ed25519Sha256 | Ed25519Sha256JSONCondition;
static makeSha256Condition(preimage: string): PreimageSha256JSONCondition;
@ -132,7 +142,7 @@ export default class Transaction {
static makeSha256Condition(
preimage: string,
json: boolean = true
json?: boolean
): PreimageSha256 | PreimageSha256JSONCondition;
static makeThresholdCondition(
@ -155,7 +165,7 @@ export default class Transaction {
static makeThresholdCondition(
threshold: number,
subconditions: (string | Fulfillment)[],
json: boolean = true
json?: boolean
): ThresholdSha256 | ThresholdSha256JSONCondition;
static makeInputTemplate(
@ -169,7 +179,7 @@ export default class Transaction {
| PreimageSha256JSONCondition
| ThresholdSha256JSONCondition
| Ed25519Sha256JSONCondition,
amount: string = '1'
amount?: string
): TransactionOutput;
static makeTransactionTemplate(): TxTemplate;
@ -207,8 +217,14 @@ export default class Transaction {
...privateKeys: string[]
): TransactionCommonSigned<O>;
static delegateSignTransaction<O = TransactionOperations.CREATE>(
transaction: TransactionCommon<O>,
signFn: DelegateSignFunction
): TransactionCommonSigned<O>;
static delegateSignTransactionAsync<O = TransactionOperations.CREATE>(
transaction: TransactionCommon<O>,
signFn: DelegateSignFunctionAsync
): Promise<TransactionCommonSigned<O>>;
}

View File

@ -14,7 +14,7 @@ export default class Transport {
pickConnection(): Request;
async forwardRequest<O = Record<string, any>>(
forwardRequest<O = Record<string, any>>(
path: string,
config: RequestConfig
): Promise<O>;

View File

@ -8,7 +8,7 @@ import type {
PreimageSha256,
ThresholdSha256,
} from 'crypto-conditions';
import type { TypeId } from 'crypto-conditions/types/types';
import type { TypeId, TypeName } from 'crypto-conditions/types/types';
interface BaseJSONCondition {
details: {