export type PatchesSchema = Array<{op: 'add' | 'remove' | 'replace' | 'move' | 'copy' | 'test', path: string, value?: {[key: string]: unknown} | undefined}>; export type PatchApiV1DataPathArgs = {body: PatchesSchema}; export type PatchApiV1DataPathOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Update a document * * PATCH /v1/data/{path} */ export const patchApiV1DataPath = async (args: PatchApiV1DataPathArgs, options: PatchApiV1DataPathOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/data/${encodeURIComponent(String(args.path))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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 };