Remove index signature for better type safety
This commit is contained in:
parent
fa2eae5060
commit
eb04b02b82
@ -1,5 +1,5 @@
|
||||
import { fromBase64, fromUtf8, toHex, toUtf8 } from "@cosmjs/encoding";
|
||||
import { LcdApiArray, LcdClient, LcdExtension, normalizeLcdApiArray } from "@cosmjs/sdk38";
|
||||
import { LcdApiArray, LcdClient, normalizeLcdApiArray } from "@cosmjs/sdk38";
|
||||
|
||||
import { JsonObject, Model, parseWasmData, WasmData } from "../types";
|
||||
|
||||
@ -75,7 +75,7 @@ function unwrapWasmResponse<T>(response: WasmResponse<T>): T {
|
||||
/**
|
||||
* @see https://github.com/cosmwasm/wasmd/blob/master/x/wasm/client/rest/query.go#L19-L27
|
||||
*/
|
||||
export interface WasmExtension extends LcdExtension {
|
||||
export interface WasmExtension {
|
||||
readonly wasm: {
|
||||
readonly listCodeInfo: () => Promise<readonly CodeInfo[]>;
|
||||
|
||||
|
||||
4
packages/cosmwasm/types/lcdapi/wasm.d.ts
vendored
4
packages/cosmwasm/types/lcdapi/wasm.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
import { LcdClient, LcdExtension } from "@cosmjs/sdk38";
|
||||
import { LcdClient } from "@cosmjs/sdk38";
|
||||
import { JsonObject, Model } from "../types";
|
||||
export interface CodeInfo {
|
||||
readonly id: number;
|
||||
@ -40,7 +40,7 @@ export interface ContractDetails extends ContractInfo {
|
||||
/**
|
||||
* @see https://github.com/cosmwasm/wasmd/blob/master/x/wasm/client/rest/query.go#L19-L27
|
||||
*/
|
||||
export interface WasmExtension extends LcdExtension {
|
||||
export interface WasmExtension {
|
||||
readonly wasm: {
|
||||
readonly listCodeInfo: () => Promise<readonly CodeInfo[]>;
|
||||
/**
|
||||
|
||||
@ -27,7 +27,6 @@ export {
|
||||
BroadcastMode,
|
||||
EncodeTxResponse,
|
||||
LcdApiArray,
|
||||
LcdExtension,
|
||||
LcdClient,
|
||||
NodeInfoResponse,
|
||||
normalizeLcdApiArray,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Coin } from "../coins";
|
||||
import { LcdClient, LcdExtension } from "./lcdclient";
|
||||
import { LcdClient } from "./lcdclient";
|
||||
|
||||
export interface CosmosSdkAccount {
|
||||
/** Bech32 account address */
|
||||
@ -19,7 +19,7 @@ export interface AuthAccountsResponse {
|
||||
};
|
||||
}
|
||||
|
||||
export interface AuthExtension extends LcdExtension {
|
||||
export interface AuthExtension {
|
||||
readonly auth: {
|
||||
readonly account: (address: string) => Promise<AuthAccountsResponse>;
|
||||
};
|
||||
|
||||
@ -18,4 +18,4 @@ export {
|
||||
SearchTxsResponse,
|
||||
TxsResponse,
|
||||
} from "./base";
|
||||
export { LcdApiArray, LcdClient, LcdExtension, normalizeLcdApiArray } from "./lcdclient";
|
||||
export { LcdApiArray, LcdClient, normalizeLcdApiArray } from "./lcdclient";
|
||||
|
||||
@ -23,7 +23,7 @@ import {
|
||||
import { StdFee } from "../types";
|
||||
import { setupAuthExtension } from "./auth";
|
||||
import { TxsResponse } from "./base";
|
||||
import { LcdApiArray, LcdClient, LcdExtension, normalizeLcdApiArray } from "./lcdclient";
|
||||
import { LcdApiArray, LcdClient, normalizeLcdApiArray } from "./lcdclient";
|
||||
|
||||
/** Deployed as part of scripts/wasmd/init.sh */
|
||||
export const deployedErc20 = {
|
||||
@ -79,7 +79,7 @@ describe("LcdClient", () => {
|
||||
return response.result;
|
||||
}
|
||||
|
||||
interface WasmExtension extends LcdExtension {
|
||||
interface WasmExtension {
|
||||
wasm: {
|
||||
listCodeInfo: () => Promise<readonly CodeInfo[]>;
|
||||
};
|
||||
|
||||
@ -20,9 +20,7 @@ export function normalizeLcdApiArray<T>(backend: LcdApiArray<T>): readonly T[] {
|
||||
return backend || [];
|
||||
}
|
||||
|
||||
export type LcdExtension = Record<string, Record<string, (...args: any[]) => any>>;
|
||||
|
||||
type LcdExtensionSetup<P extends LcdExtension> = (base: LcdClient) => P;
|
||||
type LcdExtensionSetup<P> = (base: LcdClient) => P;
|
||||
|
||||
export interface LcdClientBaseOptions {
|
||||
readonly apiUrl: string;
|
||||
@ -68,20 +66,20 @@ export class LcdClient {
|
||||
public static withExtensions(options: LcdClientBaseOptions): LcdClient;
|
||||
|
||||
/** Constructs an LCD client with 1 extension */
|
||||
public static withExtensions<A extends LcdExtension>(
|
||||
public static withExtensions<A extends object>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
): LcdClient & A;
|
||||
|
||||
/** Constructs an LCD client with 2 extensions */
|
||||
public static withExtensions<A extends LcdExtension, B extends LcdExtension>(
|
||||
public static withExtensions<A extends object, B extends object>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
setupExtensionB: LcdExtensionSetup<B>,
|
||||
): LcdClient & A & B;
|
||||
|
||||
/** Constructs an LCD client with 3 extensions */
|
||||
public static withExtensions<A extends LcdExtension, B extends LcdExtension, C extends LcdExtension>(
|
||||
public static withExtensions<A extends object, B extends object, C extends object>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
setupExtensionB: LcdExtensionSetup<B>,
|
||||
@ -89,12 +87,7 @@ export class LcdClient {
|
||||
): LcdClient & A & B & C;
|
||||
|
||||
/** Constructs an LCD client with 4 extensions */
|
||||
public static withExtensions<
|
||||
A extends LcdExtension,
|
||||
B extends LcdExtension,
|
||||
C extends LcdExtension,
|
||||
D extends LcdExtension
|
||||
>(
|
||||
public static withExtensions<A extends object, B extends object, C extends object, D extends object>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
setupExtensionB: LcdExtensionSetup<B>,
|
||||
@ -104,11 +97,11 @@ export class LcdClient {
|
||||
|
||||
/** Constructs an LCD client with 5 extensions */
|
||||
public static withExtensions<
|
||||
A extends LcdExtension,
|
||||
B extends LcdExtension,
|
||||
C extends LcdExtension,
|
||||
D extends LcdExtension,
|
||||
E extends LcdExtension
|
||||
A extends object,
|
||||
B extends object,
|
||||
C extends object,
|
||||
D extends object,
|
||||
E extends object
|
||||
>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
@ -120,12 +113,12 @@ export class LcdClient {
|
||||
|
||||
/** Constructs an LCD client with 6 extensions */
|
||||
public static withExtensions<
|
||||
A extends LcdExtension,
|
||||
B extends LcdExtension,
|
||||
C extends LcdExtension,
|
||||
D extends LcdExtension,
|
||||
E extends LcdExtension,
|
||||
F extends LcdExtension
|
||||
A extends object,
|
||||
B extends object,
|
||||
C extends object,
|
||||
D extends object,
|
||||
E extends object,
|
||||
F extends object
|
||||
>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
@ -138,13 +131,13 @@ export class LcdClient {
|
||||
|
||||
/** Constructs an LCD client with 7 extensions */
|
||||
public static withExtensions<
|
||||
A extends LcdExtension,
|
||||
B extends LcdExtension,
|
||||
C extends LcdExtension,
|
||||
D extends LcdExtension,
|
||||
E extends LcdExtension,
|
||||
F extends LcdExtension,
|
||||
G extends LcdExtension
|
||||
A extends object,
|
||||
B extends object,
|
||||
C extends object,
|
||||
D extends object,
|
||||
E extends object,
|
||||
F extends object,
|
||||
G extends object
|
||||
>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
@ -158,14 +151,14 @@ export class LcdClient {
|
||||
|
||||
/** Constructs an LCD client with 8 extensions */
|
||||
public static withExtensions<
|
||||
A extends LcdExtension,
|
||||
B extends LcdExtension,
|
||||
C extends LcdExtension,
|
||||
D extends LcdExtension,
|
||||
E extends LcdExtension,
|
||||
F extends LcdExtension,
|
||||
G extends LcdExtension,
|
||||
H extends LcdExtension
|
||||
A extends object,
|
||||
B extends object,
|
||||
C extends object,
|
||||
D extends object,
|
||||
E extends object,
|
||||
F extends object,
|
||||
G extends object,
|
||||
H extends object
|
||||
>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
@ -179,14 +172,14 @@ export class LcdClient {
|
||||
): LcdClient & A & B & C & D & E & F & G & H;
|
||||
|
||||
public static withExtensions<
|
||||
A extends LcdExtension,
|
||||
B extends LcdExtension,
|
||||
C extends LcdExtension,
|
||||
D extends LcdExtension,
|
||||
E extends LcdExtension,
|
||||
F extends LcdExtension,
|
||||
G extends LcdExtension,
|
||||
H extends LcdExtension
|
||||
A extends object,
|
||||
B extends object,
|
||||
C extends object,
|
||||
D extends object,
|
||||
E extends object,
|
||||
F extends object,
|
||||
G extends object,
|
||||
H extends object
|
||||
>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA?: LcdExtensionSetup<A>,
|
||||
@ -200,7 +193,7 @@ export class LcdClient {
|
||||
): any {
|
||||
const client = new LcdClient(options.apiUrl, options.broadcastMode);
|
||||
|
||||
const extensions = new Array<LcdExtension>();
|
||||
const extensions = new Array<object>();
|
||||
if (setupExtensionA) extensions.push(setupExtensionA(client));
|
||||
if (setupExtensionB) extensions.push(setupExtensionB(client));
|
||||
if (setupExtensionC) extensions.push(setupExtensionC(client));
|
||||
@ -211,9 +204,8 @@ export class LcdClient {
|
||||
if (setupExtensionH) extensions.push(setupExtensionH(client));
|
||||
for (const extension of extensions) {
|
||||
assert(isNonNullObject(extension), `Extension must be a non-null object`);
|
||||
for (const key in extension) {
|
||||
assert(typeof key == "string", `Found non-string extension key: ${key}`);
|
||||
(client as any)[key] = extension[key];
|
||||
for (const [key, value] of Object.entries(extension)) {
|
||||
(client as any)[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Coin } from "../coins";
|
||||
import { LcdApiArray, LcdClient, LcdExtension } from "./lcdclient";
|
||||
import { LcdApiArray, LcdClient } from "./lcdclient";
|
||||
|
||||
export interface TotalSupplyAllReponse {
|
||||
readonly height: string;
|
||||
@ -12,7 +12,7 @@ export interface TotalSupplyReponse {
|
||||
readonly result: string;
|
||||
}
|
||||
|
||||
export interface SupplyExtension extends LcdExtension {
|
||||
export interface SupplyExtension {
|
||||
readonly supply: {
|
||||
readonly totalAll: () => Promise<TotalSupplyAllReponse>;
|
||||
readonly total: (denom: string) => Promise<TotalSupplyReponse>;
|
||||
|
||||
1
packages/sdk38/types/index.d.ts
vendored
1
packages/sdk38/types/index.d.ts
vendored
@ -25,7 +25,6 @@ export {
|
||||
BroadcastMode,
|
||||
EncodeTxResponse,
|
||||
LcdApiArray,
|
||||
LcdExtension,
|
||||
LcdClient,
|
||||
NodeInfoResponse,
|
||||
normalizeLcdApiArray,
|
||||
|
||||
4
packages/sdk38/types/lcdapi/auth.d.ts
vendored
4
packages/sdk38/types/lcdapi/auth.d.ts
vendored
@ -1,5 +1,5 @@
|
||||
import { Coin } from "../coins";
|
||||
import { LcdClient, LcdExtension } from "./lcdclient";
|
||||
import { LcdClient } from "./lcdclient";
|
||||
export interface CosmosSdkAccount {
|
||||
/** Bech32 account address */
|
||||
readonly address: string;
|
||||
@ -16,7 +16,7 @@ export interface AuthAccountsResponse {
|
||||
readonly value: CosmosSdkAccount;
|
||||
};
|
||||
}
|
||||
export interface AuthExtension extends LcdExtension {
|
||||
export interface AuthExtension {
|
||||
readonly auth: {
|
||||
readonly account: (address: string) => Promise<AuthAccountsResponse>;
|
||||
};
|
||||
|
||||
2
packages/sdk38/types/lcdapi/index.d.ts
vendored
2
packages/sdk38/types/lcdapi/index.d.ts
vendored
@ -9,4 +9,4 @@ export {
|
||||
SearchTxsResponse,
|
||||
TxsResponse,
|
||||
} from "./base";
|
||||
export { LcdApiArray, LcdClient, LcdExtension, normalizeLcdApiArray } from "./lcdclient";
|
||||
export { LcdApiArray, LcdClient, normalizeLcdApiArray } from "./lcdclient";
|
||||
|
||||
68
packages/sdk38/types/lcdapi/lcdclient.d.ts
vendored
68
packages/sdk38/types/lcdapi/lcdclient.d.ts
vendored
@ -11,8 +11,7 @@ import {
|
||||
/** Unfortunately, Cosmos SDK encodes empty arrays as null */
|
||||
export declare type LcdApiArray<T> = readonly T[] | null;
|
||||
export declare function normalizeLcdApiArray<T>(backend: LcdApiArray<T>): readonly T[];
|
||||
export declare type LcdExtension = Record<string, Record<string, (...args: any[]) => any>>;
|
||||
declare type LcdExtensionSetup<P extends LcdExtension> = (base: LcdClient) => P;
|
||||
declare type LcdExtensionSetup<P> = (base: LcdClient) => P;
|
||||
export interface LcdClientBaseOptions {
|
||||
readonly apiUrl: string;
|
||||
readonly broadcastMode?: BroadcastMode;
|
||||
@ -33,30 +32,25 @@ export declare class LcdClient {
|
||||
/** Constructs an LCD client with 0 extensions */
|
||||
static withExtensions(options: LcdClientBaseOptions): LcdClient;
|
||||
/** Constructs an LCD client with 1 extension */
|
||||
static withExtensions<A extends LcdExtension>(
|
||||
static withExtensions<A extends object>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
): LcdClient & A;
|
||||
/** Constructs an LCD client with 2 extensions */
|
||||
static withExtensions<A extends LcdExtension, B extends LcdExtension>(
|
||||
static withExtensions<A extends object, B extends object>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
setupExtensionB: LcdExtensionSetup<B>,
|
||||
): LcdClient & A & B;
|
||||
/** Constructs an LCD client with 3 extensions */
|
||||
static withExtensions<A extends LcdExtension, B extends LcdExtension, C extends LcdExtension>(
|
||||
static withExtensions<A extends object, B extends object, C extends object>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
setupExtensionB: LcdExtensionSetup<B>,
|
||||
setupExtensionC: LcdExtensionSetup<C>,
|
||||
): LcdClient & A & B & C;
|
||||
/** Constructs an LCD client with 4 extensions */
|
||||
static withExtensions<
|
||||
A extends LcdExtension,
|
||||
B extends LcdExtension,
|
||||
C extends LcdExtension,
|
||||
D extends LcdExtension
|
||||
>(
|
||||
static withExtensions<A extends object, B extends object, C extends object, D extends object>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
setupExtensionB: LcdExtensionSetup<B>,
|
||||
@ -65,11 +59,11 @@ export declare class LcdClient {
|
||||
): LcdClient & A & B & C & D;
|
||||
/** Constructs an LCD client with 5 extensions */
|
||||
static withExtensions<
|
||||
A extends LcdExtension,
|
||||
B extends LcdExtension,
|
||||
C extends LcdExtension,
|
||||
D extends LcdExtension,
|
||||
E extends LcdExtension
|
||||
A extends object,
|
||||
B extends object,
|
||||
C extends object,
|
||||
D extends object,
|
||||
E extends object
|
||||
>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
@ -80,12 +74,12 @@ export declare class LcdClient {
|
||||
): LcdClient & A & B & C & D & E;
|
||||
/** Constructs an LCD client with 6 extensions */
|
||||
static withExtensions<
|
||||
A extends LcdExtension,
|
||||
B extends LcdExtension,
|
||||
C extends LcdExtension,
|
||||
D extends LcdExtension,
|
||||
E extends LcdExtension,
|
||||
F extends LcdExtension
|
||||
A extends object,
|
||||
B extends object,
|
||||
C extends object,
|
||||
D extends object,
|
||||
E extends object,
|
||||
F extends object
|
||||
>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
@ -97,13 +91,13 @@ export declare class LcdClient {
|
||||
): LcdClient & A & B & C & D & E & F;
|
||||
/** Constructs an LCD client with 7 extensions */
|
||||
static withExtensions<
|
||||
A extends LcdExtension,
|
||||
B extends LcdExtension,
|
||||
C extends LcdExtension,
|
||||
D extends LcdExtension,
|
||||
E extends LcdExtension,
|
||||
F extends LcdExtension,
|
||||
G extends LcdExtension
|
||||
A extends object,
|
||||
B extends object,
|
||||
C extends object,
|
||||
D extends object,
|
||||
E extends object,
|
||||
F extends object,
|
||||
G extends object
|
||||
>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
@ -116,14 +110,14 @@ export declare class LcdClient {
|
||||
): LcdClient & A & B & C & D & E & F & G;
|
||||
/** Constructs an LCD client with 8 extensions */
|
||||
static withExtensions<
|
||||
A extends LcdExtension,
|
||||
B extends LcdExtension,
|
||||
C extends LcdExtension,
|
||||
D extends LcdExtension,
|
||||
E extends LcdExtension,
|
||||
F extends LcdExtension,
|
||||
G extends LcdExtension,
|
||||
H extends LcdExtension
|
||||
A extends object,
|
||||
B extends object,
|
||||
C extends object,
|
||||
D extends object,
|
||||
E extends object,
|
||||
F extends object,
|
||||
G extends object,
|
||||
H extends object
|
||||
>(
|
||||
options: LcdClientBaseOptions,
|
||||
setupExtensionA: LcdExtensionSetup<A>,
|
||||
|
||||
4
packages/sdk38/types/lcdapi/supply.d.ts
vendored
4
packages/sdk38/types/lcdapi/supply.d.ts
vendored
@ -1,5 +1,5 @@
|
||||
import { Coin } from "../coins";
|
||||
import { LcdApiArray, LcdClient, LcdExtension } from "./lcdclient";
|
||||
import { LcdApiArray, LcdClient } from "./lcdclient";
|
||||
export interface TotalSupplyAllReponse {
|
||||
readonly height: string;
|
||||
readonly result: LcdApiArray<Coin>;
|
||||
@ -9,7 +9,7 @@ export interface TotalSupplyReponse {
|
||||
/** The amount */
|
||||
readonly result: string;
|
||||
}
|
||||
export interface SupplyExtension extends LcdExtension {
|
||||
export interface SupplyExtension {
|
||||
readonly supply: {
|
||||
readonly totalAll: () => Promise<TotalSupplyAllReponse>;
|
||||
readonly total: (denom: string) => Promise<TotalSupplyReponse>;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user