export type CreateApiDataTableShardArgs = {table: string, shard: number, body: BodyInit}; export type CreateApiDataTableShardOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Post new data batch to a existing table shard * * POST /data/{table}/{shard} */ export const createApiDataTableShard = async (args: CreateApiDataTableShardArgs, options: CreateApiDataTableShardOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/upsert-data") const url = `${baseUrl.replace(/\/+$/, '')}/data/${encodeURIComponent(String(args.table))}/${encodeURIComponent(String(args.shard))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };