export type DataSchema = string; export type UpdateApiV1DataPathArgs = {'If-None-Match'?: string | undefined, body: DataSchema}; export type UpdateApiV1DataPathOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Create or overwrite a document * * PUT /v1/data/{path} */ export const updateApiV1DataPath = async (args: UpdateApiV1DataPathArgs, options: UpdateApiV1DataPathOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['If-None-Match'] != null) headers.set("If-None-Match", String(args['If-None-Match'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/data/${encodeURIComponent(String(args.path))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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 };