/* eslint-disable @typescript-eslint/no-explicit-any */ import { HexString } from '@gear-js/api'; import { SignerOptions } from '@polkadot/api/types'; import { IKeyringPair } from '@polkadot/types/types'; import { TransactionBuilder } from 'sails-js'; type NonServiceKeys = 'api' | 'registry' | 'programId' | 'newCtorFromCode' | 'newCtorFromCodeId'; type ServiceName = Exclude; type FunctionName = { [K in keyof T]: T[K] extends (...args: any[]) => TReturn ? K : never; }[keyof T]; // transactions type GenericTransactionReturn = TransactionBuilder; type Transaction = T extends (...args: infer P) => GenericTransactionReturn ? (...args: P) => GenericTransactionReturn : never; // unwrapping value and wrapping it again, // cuz somehow useSendProgramTransaction is not able to interpret usePrepareProgramTransaction's return type type _TransactionReturn = ReturnType> extends GenericTransactionReturn ? R : never; type TransactionReturn = GenericTransactionReturn<_TransactionReturn>; type UseSendProgramTransactionParameters = { program: TProgram | undefined; serviceName: TServiceName; functionName: TFunctionName; }; type UsePrepareProgramTransactionParameters = UseSendProgramTransactionParameters; type CalculateGasParameters = { allowOtherPanics?: boolean; increaseGas?: number; }; type AccountParameters = { addressOrPair: string | IKeyringPair; signerOptions?: Partial; }; type SignAndSendOptions = { args: T; value?: bigint; voucherId?: HexString; gasLimit?: bigint | CalculateGasParameters; account?: AccountParameters; }; // events type EventReturn = Promise<() => void>; type Event = T extends (...args: infer P) => EventReturn ? (...args: P) => EventReturn : never; type EventCallbackArgs = Parameters>[0] extends (...args: infer P) => void | Promise ? P : never; // queries type PromiseReturn = T extends (...args: any[]) => Promise ? R : never; // is it possible to combine with FunctionName? type QueryName = { [K in keyof T]: PromiseReturn extends Awaited ? never : K; }[keyof T]; type ExcludeConfigArgs = T extends [...infer U, any, any?, any?] ? U : T; type NonConfigArgs = T extends (...args: infer P) => Promise ? ExcludeConfigArgs

: never; type Query = T extends (...args: infer P) => Promise ? (...args: P) => Promise : never; type QueryArgs = NonConfigArgs; type QueryReturn = Awaited>>; export type { ServiceName, FunctionName, GenericTransactionReturn, Transaction, TransactionReturn, UseSendProgramTransactionParameters, UsePrepareProgramTransactionParameters, SignAndSendOptions, EventReturn, Event, EventCallbackArgs, QueryName, Query, QueryArgs, QueryReturn, };