@rspc/client
TypeScript API reference for @rspc/client, version 0.0.0-main-a312a505.
0.0.0-main-a312a505
Generated from the published type declarations for this exact release.
Public exports of @rspc/client at version 0.0.0-main-a312a505.
This page documents 0.0.0-main-a312a505. The documented version is 0.3.1.
Classes
Client
declare class Client<TProcedures extends ProceduresDef> {
_rspc_def: ProceduresDef;
private transport;
private subscriptionMap;
private onError?;
constructor(args: ClientArgs);
query<K extends TProcedures["queries"]["key"] & string>(keyAndInput: [
key: K,
...input: _inferProcedureHandlerInput<TProcedures, "queries", K>
]): Promise<inferQueryResult<TProcedures, K>>;
mutation<K extends TProcedures["mutations"]["key"] & string>(keyAndInput: [
key: K,
...input: _inferProcedureHandlerInput<TProcedures, "mutations", K>
]): Promise<inferMutationResult<TProcedures, K>>;
addSubscription<K extends TProcedures["subscriptions"]["key"] & string, TData = inferSubscriptionResult<TProcedures, K>>(keyAndInput: [
K,
..._inferProcedureHandlerInput<TProcedures, "subscriptions", K>
], opts: SubscriptionOptions<TData>): () => void;
}
FetchTransport
declare class FetchTransport implements Transport {
private url;
clientSubscriptionCallback?: (id: string, key: string, value: any) => void;
private fetch;
constructor(url: string, fetch?: typeof globalThis.fetch);
doRequest(operation: OperationType, key: string, input: any): Promise<any>;
}
NoOpTransport
declare class NoOpTransport implements Transport {
constructor();
doRequest(operation: OperationType, key: string, input: string): Promise<any>;
}
RSPCError
declare class RSPCError {
code: number;
message: string;
constructor(code: number, message: string);
}
v2:AlphaClient
declare class AlphaClient<P extends ProceduresDef> {
_rspc_def: ProceduresDef;
private links;
private onError?;
private mapQueryKey?;
constructor(args: ClientArgs);
query<K extends P["queries"]["key"] & string>(keyAndInput: [
key: K,
...input: _inferProcedureHandlerInput<P, "queries", K>
], opts?: OperationOpts): Promise<inferQueryResult<P, K>>;
mutation<K extends P["mutations"]["key"] & string>(keyAndInput: [
key: K,
...input: _inferProcedureHandlerInput<P, "mutations", K>
], opts?: OperationOpts): Promise<inferMutationResult<P, K>>;
addSubscription<K extends P["subscriptions"]["key"] & string, TData = inferProcedureResult<P, "subscriptions", K>>(keyAndInput: [
K,
..._inferProcedureHandlerInput<P, "subscriptions", K>
], opts: SubscriptionOptions<TData> & {
context?: OperationContext;
}): () => void;
dangerouslyHookIntoInternals<P2 extends ProceduresDef = P>(opts?: {
// … truncated, see the source link
v2:AlphaRSPCError
declare class AlphaRSPCError {
code: number;
message: string;
constructor(code: number, message: string);
}
WebsocketTransport
declare class WebsocketTransport implements Transport {
private url;
private ws;
private requestMap;
clientSubscriptionCallback?: (id: string, value: any) => void;
constructor(url: string);
attachEventListeners(): void;
reconnect(timeoutIndex?: number): Promise<void>;
doRequest(operation: OperationType, key: string, input: any, opts?: {
id?: string;
}): Promise<any>;
}
Interfaces
ClientArgs
interface ClientArgs {
transport: Transport;
onError?: (err: RSPCError) => void | Promise<void>;
}
SubscriptionOptions
interface SubscriptionOptions<TOutput> {
onStarted?: () => void;
onData: (data: TOutput) => void;
onError?: (err: RSPCError) => void;
}
Transport
interface Transport {
clientSubscriptionCallback?: (id: string, key: string, value: any) => void;
doRequest(operation: OperationType, key: string, input: any): Promise<any>;
}
v2:LinkOperation
/**
* The argument to a link. Contains information about the current operation and a function to call the next link.
*
* @internal
*/
interface LinkOperation {
op: Operation;
next(op: {
op: Operation;
}): LinkResult;
}
The argument to a link. Contains information about the current operation and a function to call the next link. @internal
v2:Operation
/**
* TODO
*
* @internal
*/
interface Operation {
id: string;
type: "query" | "mutation" | "subscription" | "subscriptionStop";
input: unknown;
path: string;
context: OperationContext;
}
TODO @internal
v2:SubscriptionOptions
interface SubscriptionOptions<TOutput> {
onData: (data: TOutput) => void;
onError?: (err: AlphaRSPCError | Error) => void;
}
Type aliases
_inferInfiniteQueryProcedureHandlerInput
type _inferInfiniteQueryProcedureHandlerInput<TProcedures extends ProceduresLike, K extends inferInfiniteQueries<TProcedures>["key"]> = inferInfiniteQueryInput<TProcedures, K> extends never ? [
] : [
inferInfiniteQueryInput<TProcedures, K>
];
_inferProcedureHandlerInput
type _inferProcedureHandlerInput<TProcedures extends ProceduresLike, TOperation extends keyof ProceduresDef, K extends inferProcedures<TProcedures>[TOperation]["key"]> = inferProcedure<TProcedures, TOperation, K>["input"] extends never ? [
] : [
inferProcedure<TProcedures, TOperation, K>["input"]
];
inferInfiniteQueries
type inferInfiniteQueries<TProcedures extends ProceduresLike> = Exclude<Extract<inferProcedures<TProcedures>["queries"], {
input: {
cursor: any;
};
}>, {
input: never;
}>;
inferInfiniteQuery
type inferInfiniteQuery<TProcedures extends ProceduresLike, K extends inferInfiniteQueries<TProcedures>["key"]> = Extract<inferInfiniteQueries<TProcedures>, {
key: K;
}>;
inferInfiniteQueryInput
type inferInfiniteQueryInput<TProcedures extends ProceduresLike, K extends inferInfiniteQueries<TProcedures>["key"]> = EmptyObjToNever<Omit<inferInfiniteQuery<TProcedures, K>["input"], "cursor">>; // Referenced local context (not public exports): type EmptyObjToNever<T> = keyof T extends never ? never : T;
inferInfiniteQueryResult
type inferInfiniteQueryResult<TProcedures extends ProceduresLike, K extends inferInfiniteQueries<TProcedures>["key"]> = inferInfiniteQuery<TProcedures, K>["result"];
inferMutationInput
type inferMutationInput<TProcedures extends ProceduresLike, T extends inferProcedures<TProcedures>["mutations"]["key"][0]> = inferProcedureInput<inferProcedures<TProcedures>, "mutations", T>;
inferMutationResult
type inferMutationResult<TProcedures extends ProceduresLike, T extends inferProcedures<TProcedures>["mutations"]["key"][0]> = inferProcedureResult<inferProcedures<TProcedures>, "mutations", T>;
inferProcedure
type inferProcedure<TProcedures extends ProceduresLike, TOperation extends keyof ProceduresDef, K extends inferProcedureKey<TProcedures, TOperation>> = Extract<inferProcedures<TProcedures>[TOperation], {
key: K;
}>;
inferProcedureInput
type inferProcedureInput<TProcedures extends ProceduresLike, TOperation extends keyof ProceduresDef, K extends inferProcedureKey<TProcedures, TOperation>> = inferProcedure<TProcedures, TOperation, K>["input"];
inferProcedureKey
type inferProcedureKey<TProcedures extends ProceduresLike, TOperation extends keyof ProceduresDef> = inferProcedures<TProcedures>[TOperation]["key"];
inferProcedureResult
type inferProcedureResult<TProcedures extends ProceduresLike, TOperation extends keyof ProceduresDef, K extends inferProcedureKey<TProcedures, TOperation>> = inferProcedure<TProcedures, TOperation, K>["result"];
inferProcedures
/**
* 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>
*/
type inferProcedures<TProcedures extends ProceduresLike> = TProcedures extends {
_rspc_def: ProceduresDef;
} ? TProcedures["_rspc_def"] : TProcedures;
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>
inferQueryInput
type inferQueryInput<TProcedures extends ProceduresLike, T extends inferProcedures<TProcedures>["queries"]["key"][0]> = inferProcedureInput<inferProcedures<TProcedures>, "queries", T>;
inferQueryResult
type inferQueryResult<TProcedures extends ProceduresLike, T extends inferProcedures<TProcedures>["queries"]["key"][0]> = inferProcedureResult<inferProcedures<TProcedures>, "queries", T>;
inferSubscriptionInput
type inferSubscriptionInput<TProcedures extends ProceduresLike, T extends inferProcedures<TProcedures>["subscriptions"]["key"][0]> = inferProcedureInput<inferProcedures<TProcedures>, "subscriptions", T>;
inferSubscriptionResult
type inferSubscriptionResult<TProcedures extends ProceduresLike, T extends inferProcedures<TProcedures>["subscriptions"]["key"][0]> = inferProcedureResult<inferProcedures<TProcedures>, "subscriptions", T>;
OperationType
type OperationType = "query" | "mutation" | "subscription" | "subscriptionStop";
ProcedureDef
type ProcedureDef = {
key: string;
input: any;
result: any;
};
ProceduresDef
/**
* This type represents the Typescript bindings which are generated from the router by Rust.
*/
type ProceduresDef = {
queries: ProcedureDef;
mutations: ProcedureDef;
subscriptions: ProcedureDef;
};
This type represents the Typescript bindings which are generated from the router by Rust.
ProceduresLike
/**
* A type which allows inferring the type of the bindings
*/
type ProceduresLike = {
_rspc_def: ProceduresDef;
} | ProceduresDef;
A type which allows inferring the type of the bindings
v2:AbortFn
/** * TODO * * @internal */ type AbortFn = () => void;
TODO @internal
v2:FakeObservable
/**
* TODO
*
* @internal
*/
type FakeObservable = {
exec: () => PromiseAndCancel<any>;
};
TODO @internal
v2:Link
/** * TODO * * @internal */ type Link = (p: LinkOperation) => LinkResult;
TODO @internal
v2:LinkResult
/**
* TODO
*
* @internal
*/
type LinkResult = {
exec: (resolve: (result: any) => void, reject: (error: Error | AlphaRSPCError) => void) => void;
abort: () => void;
};
TODO @internal
v2:OperationContext
/** * A map of data that can be used by links to store metadata about the current operation. * This allows links to communicate with each other. * * @internal */ type OperationContext = Record<string, unknown>;
A map of data that can be used by links to store metadata about the current operation. This allows links to communicate with each other. @internal
v2:PromiseAndCancel
/**
* TODO
*
* @internal
*/
type PromiseAndCancel<TValue> = {
promise: Promise<TValue>;
abort: AbortFn;
};
TODO @internal
v2:RspcRequest
/**
* TODO
*
* @internal
*/
type Request = ({
method: "query";
params: {
path: string;
input: any | null;
};
} | {
method: "mutation";
params: {
path: string;
input: any | null;
};
} | {
method: "subscription";
params: {
path: string;
input: NewOrOldInput;
};
} | {
method: "subscriptionStop";
params: SubscriptionStop | null;
}) & {
jsonrpc: string | null;
id: RequestId;
};
// Referenced local context (not public exports):
type NewOrOldInput = any | null | [
RequestId,
any | null
];
type SubscriptionStop = {
input: RequestId;
};
/**
* TODO
*
* @internal
*/
type RequestId = null | number | string;
TODO @internal
Functions
createClient
declare function createClient<TProcedures extends ProceduresLike>(args: ClientArgs): Client<inferProcedures<TProcedures>>;
v2:httpBatchLink
/**
* Wrapper around httpLink that applies request batching. This is great for performance but may be problematic if your using HTTP caching.
*/
declare function httpBatchLink(opts: HttpBatchLinkOpts): Link;
// Referenced local context (not public exports):
type HttpBatchLinkOpts = BaseHttpLinkOpts & {
/**
* Headers to be set on outgoing requests or a callback that of said headers
*/
headers?: HTTPHeaders | ((opts: {
ops: Operation[];
}) => HTTPHeaders | Promise<HTTPHeaders>);
};
type BaseHttpLinkOpts = {
url: string;
/**
* Add ponyfill for fetch
*/
fetch?: typeof fetch;
/**
* Add ponyfill for AbortController
*/
AbortController?: typeof AbortController | null;
};
type HTTPHeaders = Record<string, string | string[] | undefined>;
Wrapper around httpLink that applies request batching. This is great for performance but may be problematic if your using HTTP caching.
v2:httpLink
/**
* HTTP Fetch link for rspc
*/
declare function httpLink(opts: HttpLinkOpts): Link;
// Referenced local context (not public exports):
type HttpLinkOpts = BaseHttpLinkOpts & {
/**
* Headers to be set on outgoing requests or a callback that of said headers
*/
headers?: HTTPHeaders | ((opts: {
op: Operation;
}) => HTTPHeaders | Promise<HTTPHeaders>);
};
type BaseHttpLinkOpts = {
url: string;
/**
* Add ponyfill for fetch
*/
fetch?: typeof fetch;
/**
* Add ponyfill for AbortController
*/
AbortController?: typeof AbortController | null;
};
type HTTPHeaders = Record<string, string | string[] | undefined>;
HTTP Fetch link for rspc
v2:initRspc
declare function initRspc<P extends ProceduresDef>(args: ClientArgs): AlphaClient<P>;
// Referenced local context (not public exports):
interface ClientArgs {
links: Link[];
onError?: (err: AlphaRSPCError) => void | Promise<void>;
}
v2:loggerLink
/** * Link for logging operations. * * This must go before the terminating link for it to work! * */ declare function loggerLink(): Link;
Link for logging operations.
This must go before the terminating link for it to work!
v2:wsBatchLink
/**
* Wrapper around wsLink that applies request batching.
*/
declare function wsBatchLink(opts: WsLinkOpts): Link;
// Referenced local context (not public exports):
type WsLinkOpts = {
url: string;
/**
* Add ponyfill for WebSocket
*/
WebSocket?: typeof WebSocket;
};
Wrapper around wsLink that applies request batching.
v2:wsLink
/**
* Websocket link for rspc
*/
declare function wsLink(opts: WsLinkOpts): Link;
// Referenced local context (not public exports):
type WsLinkOpts = {
url: string;
/**
* Add ponyfill for WebSocket
*/
WebSocket?: typeof WebSocket;
};
Websocket link for rspc
Variables
randomId
randomId: () => string
