Specta LogoSpecta
RspcTypescript apiTs rspc client

@rspc/client

TypeScript API reference for @rspc/client, version 0.0.6.

Public exports of @rspc/client at version 0.0.6.

This page documents 0.0.6. The documented version is 0.3.1.

Classes

Client

declare class Client<T extends OperationsDef> {
    private transport;
    private subscriptionMap;
    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: [
                K,
// … truncated, see the source link

View source ↗

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: OperationKey): Promise<any>;
}

View source ↗

RSPCError

declare class RSPCError {
    code: number;
    message: string;
    constructor(code: number, message: string);
}

View source ↗

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: OperationKey): Promise<any>;
}

View source ↗

Interfaces

ClientArgs

interface ClientArgs {
    transport: Transport;
    transformer?: ClientTransformer;
}

View source ↗

ClientTransformer

interface ClientTransformer {
    serialize(type: OperationType, key: OperationKey): OperationKey;
    deserialize(type: OperationType, key: OperationKey, data: any): any;
}

View source ↗

Transport

interface Transport {
    transformer?: ClientTransformer;
    clientSubscriptionCallback?: (id: string, key: string, value: any) => void;
    doRequest(operation: OperationType, key: OperationKey): Promise<any>;
}

View source ↗

Type aliases

OperationKey

declare type OperationKey = [
    string
] | [
    string, /* args */
    any
];

View source ↗

OperationsDef

declare type OperationsDef = {
    queries: {
        key: OperationKey;
        result: any;
    };
    mutations: {
        key: OperationKey;
        result: any;
    };
    subscriptions: {
        key: OperationKey;
        result: any;
    };
};

View source ↗

OperationType

declare type OperationType = "query" | "mutation" | "subscriptionAdd" | "subscriptionRemove";

View source ↗

Functions

createClient

declare function createClient<T extends OperationsDef>(args: ClientArgs): Client<T>;

View source ↗

Variables

randomId

randomId: () => string

View source ↗

On this page