@rspc/client
TypeScript API reference for @rspc/client, version 0.0.7.
0.0.7
Generated from the published type declarations for this exact release.
Public exports of @rspc/client at version 0.0.7.
This page documents 0.0.7. The documented version is 0.3.1.
Classes
Client
declare class Client<T extends Procedures> {
private transport;
private subscriptionMap;
private onError?;
constructor(args: ClientArgs);
query<K extends T["queries"]["key"]>(key: K): Promise<Extract<T["queries"], {
key: K;
}>["result"]>;
mutation<K extends T["mutations"]["key"][0]>(key: [
K,
Extract<T["mutations"], {
key: [
K,
any
];
}>["key"][1]
]): Promise<Extract<T["mutations"], {
key: K;
}>["result"]>;
addSubscription<K extends T["subscriptions"]["key"][0]>(key: Extract<T["subscriptions"]["key"], {
key: [
K,
any
];
}>[1] extends undefined ? [
K
] : [
K,
Extract<T["subscriptions"]["key"], {
key: [
K,
any
];
}>[1]
], options: {
onNext(msg: Extract<T["subscriptions"], {
key: [
// … truncated, see the source link
FetchTransport
declare class FetchTransport implements Transport {
private url;
transformer?: ClientTransformer;
clientSubscriptionCallback?: (id: string, key: string, value: any) => void;
constructor(url: string);
doRequest(operation: OperationType, key: ProcedureKey): Promise<any>;
}
RSPCError
declare class RSPCError {
code: number;
message: string;
constructor(code: number, message: string);
}
WebsocketTransport
declare class WebsocketTransport implements Transport {
private url;
private ws;
private requestMap;
transformer?: ClientTransformer;
clientSubscriptionCallback?: (id: string, key: string, value: any) => void;
constructor(url: string);
attachEventListeners(): void;
reconnect(timeoutIndex?: number): Promise<void>;
doRequest(operation: OperationType, key: ProcedureKey): Promise<any>;
}
Interfaces
ClientArgs
interface ClientArgs {
transport: Transport;
transformer?: ClientTransformer;
onError?: (err: RSPCError) => void | Promise<void>;
}
ClientTransformer
interface ClientTransformer {
serialize(type: OperationType, key: ProcedureKey): ProcedureKey;
deserialize(type: OperationType, key: ProcedureKey, data: any): any;
}
Transport
interface Transport {
transformer?: ClientTransformer;
clientSubscriptionCallback?: (id: string, key: string, value: any) => void;
doRequest(operation: OperationType, key: ProcedureKey): Promise<any>;
}
Type aliases
inferBindingsType
/** * This is a helper method to infer the type of bindings for this router off other rspc types. * The inferred type is what is generated by Rust. * @example * const rspc = createReactQueryHooks<Operations>(); * type Bindings = inferBindingsType<typeof rspc> */ declare type inferBindingsType<TBindings extends Procedures | ProcedureLike> = TBindings extends ProcedureLike ? TBindings["_rspc_def"] : TBindings;
This is a helper method to infer the type of bindings for this router off other rspc types. The inferred type is what is generated by Rust. @example const rspc = createReactQueryHooks<Operations>(); type Bindings = inferBindingsType<typeof rspc>
inferMutationInput
declare type inferMutationInput<TBindings extends Procedures | ProcedureLike, T extends inferBindingsType<TBindings>["mutations"]["key"][0]> = inferProcedureInput<inferBindingsType<TBindings>, "mutations", T>;
inferMutationResult
declare type inferMutationResult<TBindings extends Procedures | ProcedureLike, T extends inferBindingsType<TBindings>["mutations"]["key"][0]> = inferProcedureResult<inferBindingsType<TBindings>, "mutations", T>;
inferProcedureInput
declare type inferProcedureInput<TBindings extends Procedures | ProcedureLike, TOperation extends keyof Procedures, T extends inferBindingsType<TBindings>[TOperation]["key"][0]> = inferProcedureKey<TBindings, TOperation, T>[1];
inferProcedureKey
declare type inferProcedureKey<TBindings extends Procedures | ProcedureLike, TOperation extends keyof Procedures, T extends inferBindingsType<TBindings>[TOperation]["key"][0]> = Extract<inferBindingsType<TBindings>[TOperation], {
key: procedureKey<T>;
}>["key"];
inferProcedureResult
declare type inferProcedureResult<TBindings extends Procedures | ProcedureLike, TOperation extends keyof Procedures, T extends inferBindingsType<TBindings>[TOperation]["key"][0]> = Extract<inferBindingsType<TBindings>[TOperation], {
key: procedureKey<T>;
}>["result"];
inferQueryInput
declare type inferQueryInput<TBindings extends Procedures | ProcedureLike, T extends inferBindingsType<TBindings>["queries"]["key"][0]> = inferProcedureInput<inferBindingsType<TBindings>, "queries", T>;
inferQueryResult
declare type inferQueryResult<TBindings extends Procedures | ProcedureLike, T extends inferBindingsType<TBindings>["queries"]["key"][0]> = inferProcedureResult<inferBindingsType<TBindings>, "queries", T>;
inferSubscriptionInput
declare type inferSubscriptionInput<TBindings extends Procedures | ProcedureLike, T extends inferBindingsType<TBindings>["subscriptions"]["key"][0]> = inferProcedureInput<inferBindingsType<TBindings>, "subscriptions", T>;
inferSubscriptionResult
declare type inferSubscriptionResult<TBindings extends Procedures | ProcedureLike, T extends inferBindingsType<TBindings>["subscriptions"]["key"][0]> = inferProcedureResult<inferBindingsType<TBindings>, "subscriptions", T>;
OperationType
declare type OperationType = "query" | "mutation" | "subscriptionAdd" | "subscriptionRemove";
procedureKey
declare type procedureKey<T extends string> = [
T
] | [
T, /* input */
any
];
ProcedureKey
/**
* The key to an operation
*/
declare type ProcedureKey = [
string
] | [
string, /* input */
any
];
The key to an operation
ProcedureLike
/**
* A type which allows inferring the type of the bindings
*/
declare type ProcedureLike = {
_rspc_def: Procedures;
};
A type which allows inferring the type of the bindings
Procedures
/**
* This type represents the Typescript bindings which are generated from the router by Rust.
*/
declare type Procedures = {
queries: {
key: ProcedureKey;
result: any;
};
mutations: {
key: ProcedureKey;
result: any;
};
subscriptions: {
key: ProcedureKey;
result: any;
};
};
This type represents the Typescript bindings which are generated from the router by Rust.
Functions
createClient
declare function createClient<T extends Procedures>(args: ClientArgs): Client<T>;
Variables
randomId
randomId: () => string
