UNPKG

@bigmi/client

Version:

Reactive primitives for Bitcoin apps.

86 lines (85 loc) 5.18 kB
import { Emitter, EventData } from "./createEmitter.js"; import { Storage } from "../types/storage.js"; import { ConnectorEventMap, CreateConnectorFn } from "../types/connector.js"; import { Account, BtcRpcRequestFn, Chain, ChainId, Client, ClientConfig, Compute, ExactPartial, LooseOmit, OneOf, Transport as Transport$1 } from "@bigmi/core"; import { Mutate, StoreApi } from "zustand/vanilla"; //#region src/factories/createConfig.d.ts declare function createConfig<const chains extends readonly [Chain, ...Chain[]], transports extends Record<chains[number]["id"], Transport>, const connectorFns extends readonly CreateConnectorFn[]>(parameters: CreateConfigParameters<chains, transports, connectorFns>): Config<chains, transports, connectorFns>; type CreateConfigParameters<chains extends readonly [Chain, ...Chain[]] = readonly [Chain, ...Chain[]], transports extends Record<chains[number]["id"], Transport> = Record<chains[number]["id"], Transport>, connectorFns extends readonly CreateConnectorFn[] = readonly CreateConnectorFn[]> = Compute<{ chains: chains; connectors?: connectorFns | undefined; multiInjectedProviderDiscovery?: boolean | undefined; storage?: Storage | null | undefined; ssr?: boolean | undefined; syncConnectedChain?: boolean | undefined; } & OneOf<({ transports: transports; } & { [key in keyof ClientConfig$1]?: ClientConfig$1[key] | { [_ in chains[number]["id"]]?: ClientConfig$1[key] | undefined } | undefined }) | { client(parameters: { chain: chains[number]; }): Client<transports[chains[number]["id"]], chains[number]>; }>>; type Config<chains extends readonly [Chain, ...Chain[]] = readonly [Chain, ...Chain[]], transports extends Record<chains[number]["id"], Transport> = Record<chains[number]["id"], Transport>, connectorFns extends readonly CreateConnectorFn[] = readonly CreateConnectorFn[]> = { readonly chains: chains; readonly connectors: readonly Connector<connectorFns[number]>[]; readonly storage: Storage | null; readonly state: State<chains>; setState<tchains extends readonly [Chain, ...Chain[]] = chains>(value: State<tchains> | ((state: State<tchains>) => State<tchains>)): void; subscribe<state>(selector: (state: State<chains>) => state, listener: (state: state, previousState: state) => void, options?: { emitImmediately?: boolean | undefined; equalityFn?: ((a: state, b: state) => boolean) | undefined; } | undefined): () => void; getClient<chainId extends chains[number]["id"]>(parameters?: { chainId?: chainId | chains[number]["id"] | undefined; }): Client<transports[chainId], Extract<chains[number], { id: chainId; }>>; /** * Not part of versioned API, proceed with caution. * @internal */ _internal: Internal<chains, transports>; }; type Internal<chains extends readonly [Chain, ...Chain[]] = readonly [Chain, ...Chain[]], transports extends Record<chains[number]["id"], Transport> = Record<chains[number]["id"], Transport>> = { readonly store: Mutate<StoreApi<any>, [["zustand/persist", any]]>; readonly ssr: boolean; readonly syncConnectedChain: boolean; readonly transports: transports; chains: { setState(value: readonly [Chain, ...Chain[]] | ((state: readonly [Chain, ...Chain[]]) => readonly [Chain, ...Chain[]])): void; subscribe(listener: (state: readonly [Chain, ...Chain[]], prevState: readonly [Chain, ...Chain[]]) => void): () => void; }; connectors: { setup<connectorFn extends CreateConnectorFn>(connectorFn: connectorFn): Connector<connectorFn>; setState(value: Connector[] | ((state: Connector[]) => Connector[])): void; subscribe(listener: (state: Connector[], prevState: Connector[]) => void): () => void; }; events: { change(data: EventData<ConnectorEventMap, "change">): void; connect(data: EventData<ConnectorEventMap, "connect">): void; disconnect(data: EventData<ConnectorEventMap, "disconnect">): void; }; }; type State<chains extends readonly [Chain, ...Chain[]] = readonly [Chain, ...Chain[]]> = { chainId: chains[number]["id"]; connections: Map<string, Connection>; current: string | null; status: "connected" | "connecting" | "disconnected" | "reconnecting"; }; type PartializedState = Compute<ExactPartial<Pick<State, "chainId" | "connections" | "current" | "status">>>; type Connection = { accounts: readonly [Account, ...Account[]]; chainId: ChainId; connector: Connector; }; type Connector<createConnectorFn extends CreateConnectorFn = CreateConnectorFn> = ReturnType<createConnectorFn> & { emitter: Emitter<ConnectorEventMap>; uid: string; }; type Transport<type extends string = string, rpcAttributes = Record<string, any>, btcRequestFn extends BtcRpcRequestFn = BtcRpcRequestFn> = (params: Parameters<Transport$1<type, rpcAttributes, btcRequestFn>>[0] & { connectors?: StoreApi<Connector[]> | undefined; }) => ReturnType<Transport$1<type, rpcAttributes, btcRequestFn>>; type ClientConfig$1 = LooseOmit<ClientConfig, "account" | "chain" | "key" | "name" | "transport" | "type">; //#endregion export { Config, Connection, Connector, CreateConfigParameters, PartializedState, State, Transport, createConfig }; //# sourceMappingURL=createConfig.d.ts.map