@bunbase-ae/js 3.4.3-next.433.7846066 → 3.4.3-next.437.94850c5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunbase-ae/js",
3
- "version": "3.4.3-next.433.7846066",
3
+ "version": "3.4.3-next.437.94850c5",
4
4
  "type": "module",
5
5
  "description": "TypeScript/JavaScript SDK for BunBase",
6
6
  "license": "UNLICENSED",
package/src/collection.ts CHANGED
@@ -65,9 +65,23 @@ export class CollectionClient<T extends Record<string, unknown> = Record<string,
65
65
  });
66
66
  }
67
67
 
68
- async update(id: string, patch: Partial<T>): Promise<T & BunBaseRecord> {
68
+ /**
69
+ * Update a record. Pass `{ expectedVersion }` for an optimistic-lock
70
+ * (compare-and-set) update: the write is sent with an `If-Match` header and
71
+ * the server rejects it with a `412` {@link BunBaseError} if the record's
72
+ * `_version` has moved since you read it. On success the returned record
73
+ * carries the new `_version`.
74
+ */
75
+ async update(
76
+ id: string,
77
+ patch: Partial<T>,
78
+ options: { expectedVersion?: number } = {},
79
+ ): Promise<T & BunBaseRecord> {
69
80
  return this.http.request<T & BunBaseRecord>("PATCH", `/api/v1/${this.name}/${id}`, {
70
81
  body: patch,
82
+ ...(options.expectedVersion !== undefined
83
+ ? { headers: { "If-Match": String(options.expectedVersion) } }
84
+ : {}),
71
85
  });
72
86
  }
73
87
 
package/src/http.ts CHANGED
@@ -110,6 +110,7 @@ export class HttpClient {
110
110
  skipAuth?: boolean;
111
111
  signal?: AbortSignal;
112
112
  keepalive?: boolean;
113
+ headers?: Record<string, string>;
113
114
  } = {},
114
115
  ): Promise<T> {
115
116
  const res = await this.performWithRefresh(method, path, options);
@@ -138,6 +139,7 @@ export class HttpClient {
138
139
  skipAuth?: boolean;
139
140
  signal?: AbortSignal;
140
141
  keepalive?: boolean;
142
+ headers?: Record<string, string>;
141
143
  },
142
144
  ): Promise<Response> {
143
145
  const res = await this.send(method, path, options);
@@ -174,6 +176,7 @@ export class HttpClient {
174
176
  skipAuth?: boolean;
175
177
  signal?: AbortSignal;
176
178
  keepalive?: boolean;
179
+ headers?: Record<string, string>;
177
180
  },
178
181
  ): Promise<Response> {
179
182
  let url = `${this.baseUrl}${path}`;
@@ -202,6 +205,10 @@ export class HttpClient {
202
205
  body = JSON.stringify(options.body);
203
206
  }
204
207
 
208
+ // Caller-supplied headers (e.g. If-Match for optimistic-lock updates) are
209
+ // merged last so they can't be clobbered by the defaults above.
210
+ if (options.headers) Object.assign(headers, options.headers);
211
+
205
212
  return fetch(url, {
206
213
  method,
207
214
  headers,