Skip to content

Commit

Permalink
fix: incorrect multi payload type
Browse files Browse the repository at this point in the history
  • Loading branch information
tien committed Jun 12, 2024
1 parent 974a570 commit 07c3765
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
3 changes: 1 addition & 2 deletions apps/example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ const Query = () => {
.readStorage("Balances", "TotalIssuance", [])
.readStorage("Staking", "ActiveEra", [])
.readStorage("NominationPools", "TotalValueLocked", [])
.readStorages("NominationPools", "Metadata", [[0], [1], [2], [3], [4]])
.readStorage("Treasury", "ProposalCount", []),
.readStorages("NominationPools", "Metadata", [[0], [1], [2], [3], [4]]),
);

const bondingDurationMs =
Expand Down
36 changes: 18 additions & 18 deletions packages/core/src/QueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type ConstantFetchPayload<
TypedApi<TDescriptor>["constants"][TInstruction["pallet"]][TInstruction["constant"]]
>;

type StorageReadPayload<
type StorageReadResponse<
TInstruction extends
| StorageReadInstruction<any, any, any, TDescriptor>
| MultiInstruction<StorageReadInstruction<any, any, any, TDescriptor>>,
Expand All @@ -109,7 +109,7 @@ type StorageReadPayload<
TypedApi<TDescriptor>["query"][TInstruction["pallet"]][TInstruction["storage"]]
>["response"];

type StorageEntriesReadPayload<
type StorageEntriesReadResponse<
TInstruction extends StorageEntriesReadInstruction<
any,
any,
Expand All @@ -121,7 +121,7 @@ type StorageEntriesReadPayload<
TypedApi<TDescriptor>["query"][TInstruction["pallet"]][TInstruction["storage"]]
>["response"];

type ApiCallPayload<
type ApiCallResponse<
TInstruction extends
| ApiCallInstruction<any, any, any, TDescriptor>
| MultiInstruction<ApiCallInstruction<any, any, any, TDescriptor>>,
Expand All @@ -139,42 +139,42 @@ export type InferInstructionResponse<
: TInstruction extends MultiInstruction<
StorageReadInstruction<any, any, any, TDescriptor>
>
? Array<StorageReadPayload<TInstruction, TDescriptor>>
? Array<StorageReadResponse<TInstruction, TDescriptor>>
: TInstruction extends StorageReadInstruction<any, any, any, TDescriptor>
? StorageReadPayload<TInstruction, TDescriptor>
? StorageReadResponse<TInstruction, TDescriptor>
: TInstruction extends StorageEntriesReadInstruction<
any,
any,
any,
TDescriptor
>
? StorageEntriesReadPayload<TInstruction, TDescriptor>
? StorageEntriesReadResponse<TInstruction, TDescriptor>
: TInstruction extends MultiInstruction<
ApiCallInstruction<any, any, any, TDescriptor>
>
? Array<ApiCallPayload<TInstruction, TDescriptor>>
? Array<ApiCallResponse<TInstruction, TDescriptor>>
: TInstruction extends ApiCallInstruction<
any,
any,
any,
TDescriptor
>
? ApiCallPayload<TInstruction, TDescriptor>
? ApiCallResponse<TInstruction, TDescriptor>
: never;

type ResponsePayload<T> =
T extends Promise<infer Payload>
? Payload
: T extends Observable<infer Payload>
? Payload
: T extends Array<infer Element>
? Array<ResponsePayload<Element>>
: unknown;

export type InferInstructionPayload<
TInstruction extends QueryInstruction,
TDescriptor extends ChainDefinition = ReDotDescriptor,
> =
InferInstructionResponse<TInstruction, TDescriptor> extends Promise<
infer Payload
>
? Payload
: InferInstructionResponse<TInstruction, TDescriptor> extends Observable<
infer Payload
>
? Payload
: InferInstructionResponse<TInstruction, TDescriptor>;
> = ResponsePayload<InferInstructionResponse<TInstruction, TDescriptor>>;

export type InferInstructionsResponse<
TInstructions extends QueryInstruction[],
Expand Down

0 comments on commit 07c3765

Please sign in to comment.