export type WorkerAppend = {payload: string, stream: string, time: string}; export type CreateApi0WorkerAppendArgs = {body: Array}; export type CreateApi0WorkerAppendOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * POST /0/worker/append */ export const createApi0WorkerAppend = async (args: CreateApi0WorkerAppendArgs, options: CreateApi0WorkerAppendOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/0/worker/append${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };