Skip to content

Commit

Permalink
fix: improve typedefs
Browse files Browse the repository at this point in the history
Signed-off-by: getlarge <ed@getlarge.eu>
  • Loading branch information
getlarge committed Mar 11, 2021
1 parent 71a231a commit 6aeece4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion types/baseRequest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ declare function handleResponse(res: Response): Response;

export default function baseRequest(
url: string,
config: RequestConfig = {},
config: RequestConfig,
requestTimeout?: number
): Promise<Response>;
9 changes: 4 additions & 5 deletions types/connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
);

Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions types/request.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
28 changes: 22 additions & 6 deletions types/transaction.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -118,7 +128,7 @@ export default class Transaction {

static makeEd25519Condition(
publicKey: string,
json: boolean = true
json?: boolean
): Ed25519Sha256 | Ed25519Sha256JSONCondition;

static makeSha256Condition(preimage: string): PreimageSha256JSONCondition;
Expand All @@ -132,7 +142,7 @@ export default class Transaction {

static makeSha256Condition(
preimage: string,
json: boolean = true
json?: boolean
): PreimageSha256 | PreimageSha256JSONCondition;

static makeThresholdCondition(
Expand All @@ -155,7 +165,7 @@ export default class Transaction {
static makeThresholdCondition(
threshold: number,
subconditions: (string | Fulfillment)[],
json: boolean = true
json?: boolean
): ThresholdSha256 | ThresholdSha256JSONCondition;

static makeInputTemplate(
Expand All @@ -169,7 +179,7 @@ export default class Transaction {
| PreimageSha256JSONCondition
| ThresholdSha256JSONCondition
| Ed25519Sha256JSONCondition,
amount: string = '1'
amount?: string
): TransactionOutput;

static makeTransactionTemplate(): TxTemplate;
Expand Down Expand Up @@ -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>>;
}
2 changes: 1 addition & 1 deletion types/transport.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
2 changes: 1 addition & 1 deletion types/utils/ccJsonify.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 6aeece4

Please sign in to comment.