Skip to content

Commit

Permalink
feat: update connection typedefs
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Feb 15, 2022
1 parent 46599f5 commit fbc3d79
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
36 changes: 27 additions & 9 deletions types/connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ export interface InputNode {
endpoint: string;
}

export type AssetResult = {
id: string;
data: Record<string, any>;
};

export type MetadataResult = {
id: string;
metadata: Record<string, any>;
};

export enum Endpoints {
blocks = 'blocks',
blocksDetail = 'blocksDetail',
Expand Down Expand Up @@ -76,8 +86,8 @@ export interface EndpointsResponse<
[Endpoints.transactionsDetail]: O extends TransactionOperations.CREATE
? CreateTransaction<A, M>
: TransferTransaction<M>;
[Endpoints.assets]: { id: string; data: Record<string, any> }[];
[Endpoints.metadata]: { id: string; metadata: Record<string, any> }[];
[Endpoints.assets]: AssetResult[];
[Endpoints.metadata]: MetadataResult[];
}

export default class Connection {
Expand Down Expand Up @@ -111,7 +121,9 @@ export default class Connection {
transactionId: string
): Promise<EndpointsResponse<O>[Endpoints.transactionsDetail]>;

listBlocks(transactionId: string): Promise<EndpointsResponse[Endpoints.blocks]>;
listBlocks(
transactionId: string
): Promise<EndpointsResponse[Endpoints.blocks]>;

listOutputs(
publicKey: string,
Expand All @@ -124,38 +136,44 @@ export default class Connection {
): Promise<EndpointsResponse<typeof operation>[Endpoints.transactions]>;

postTransaction<
O = TransactionOperations.CREATE,
O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, any>,
M = Record<string, any>
>(
transaction: TransactionCommon<O>
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;

postTransactionSync<
O = TransactionOperations.CREATE,
O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, any>,
M = Record<string, any>
>(
transaction: TransactionCommon<O>
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsSync]>;

postTransactionAsync<
O = TransactionOperations.CREATE,
O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, any>,
M = Record<string, any>
>(
transaction: TransactionCommon<O>
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsAsync]>;

postTransactionCommit<
O = TransactionOperations.CREATE,
O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, any>,
M = Record<string, any>
>(
transaction: TransactionCommon<O>
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;

searchAssets(search: string): Promise<EndpointsResponse[Endpoints.assets]>;
searchAssets(
search: string,
limit?: number
): Promise<EndpointsResponse[Endpoints.assets]>;

searchMetadata(search: string): Promise<EndpointsResponse[Endpoints.metadata]>;
searchMetadata(
search: string,
limit?: number
): Promise<EndpointsResponse[Endpoints.metadata]>;
}
6 changes: 3 additions & 3 deletions types/sanitize.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ declare type FilterFn = (val: any, key?: string) => void;

declare function filterFromObject<I = Record<string, any>>(
obj: I,
filter: Array | FilterFn,
conf: { isInclusion?: boolean } = {}
filter: Array<any> | FilterFn,
conf: { isInclusion?: boolean }
): Partial<I>;

declare function applyFilterOnObject<I = Record<string, any>>(
Expand All @@ -17,7 +17,7 @@ declare function applyFilterOnObject<I = Record<string, any>>(

declare function selectFromObject<I = Record<string, any>>(
obj: I,
filter: Array | FilterFn
filter: Array<any> | FilterFn
): Partial<I>;

export default function sanitize<I = Record<string, any>>(
Expand Down

0 comments on commit fbc3d79

Please sign in to comment.