This repository has no description
1import { Client, simpleFetchHandler } from "@atcute/client";
2
3export { ClientResponseError, isXRPCErrorPayload, ok } from "@atcute/client";
4export type { XRPCErrorPayload } from "@atcute/client";
5
6// generated lexicons register ambient types; don't import the barrel at runtime.
7
8export interface BobbinContext {
9 readonly xrpc: Client;
10 readonly serviceUrl: string;
11 readonly fetch: typeof globalThis.fetch;
12}
13
14export interface CreateBobbinOptions {
15 serviceUrl: string;
16 fetch?: typeof globalThis.fetch;
17}
18
19export const createBobbinClient = ({ serviceUrl, fetch }: CreateBobbinOptions): BobbinContext => {
20 const origin = serviceUrl.replace(/\/+$/, "");
21 const boundFetch = fetch ?? globalThis.fetch;
22 const xrpc = new Client({ handler: simpleFetchHandler({ service: origin, fetch: boundFetch }) });
23 return { xrpc, serviceUrl: origin, fetch: boundFetch };
24};
25
26export type QueryValue = string | number | boolean | readonly (string | number)[] | undefined;
27
28export interface XrpcRequestInit {
29 signal?: AbortSignal;
30 headers?: HeadersInit;
31}