Skip to content

Commit b7a3b01

Browse files
Copilothotlong
andcommitted
fix(client): address code review feedback
- Fix ETag parsing to properly detect weak ETags (check W/ before removing quotes) - Fix 304 response to correctly parse weak ETags from ifNoneMatch - Remove redundant array mapping in updateMany method - Change createMany endpoint to /createMany to avoid conflict with /batch - Remove deprecated tag from updateMany (it's a convenience method) - Update README to clarify batch() is the recommended method Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent f0e16b3 commit b7a3b01

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

packages/client/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ Initializes the client by fetching the system discovery manifest from `/api/v1`.
111111
- `get<T>(object, id)`: Get single record by ID.
112112
- `query<T>(object, ast)`: Execute complex query using full AST.
113113
- `create<T>(object, data)`: Create record.
114-
- `createMany<T>(object, data[])`: Batch create records.
114+
- `batch(object, request)`: **Recommended** - Execute batch operations (create/update/upsert/delete) with full control.
115+
- `createMany<T>(object, data[])`: Batch create records (convenience method).
115116
- `update<T>(object, id, data)`: Update record.
116-
- `batch(object, request)`: Execute batch operations (create/update/upsert/delete).
117-
- `updateMany<T>(object, records[], options?)`: Simplified batch update.
117+
- `updateMany<T>(object, records[], options?)`: Batch update records (convenience method).
118118
- `delete(object, id)`: Delete record.
119-
- `deleteMany(object, ids[], options?)`: Batch delete records.
119+
- `deleteMany(object, ids[], options?)`: Batch delete records (convenience method).
120120

121121
### `client.views` (New!)
122122
- `create(request)`: Create a new saved view.

packages/client/src/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ export class ObjectStackClient {
151151
if (res.status === 304) {
152152
return {
153153
notModified: true,
154-
etag: cacheOptions?.ifNoneMatch ? { value: cacheOptions.ifNoneMatch, weak: false } : undefined
154+
etag: cacheOptions?.ifNoneMatch ? {
155+
value: cacheOptions.ifNoneMatch.replace(/^W\/|"/g, ''),
156+
weak: cacheOptions.ifNoneMatch.startsWith('W/')
157+
} : undefined
155158
};
156159
}
157160

@@ -161,7 +164,10 @@ export class ObjectStackClient {
161164

162165
return {
163166
data,
164-
etag: etag ? { value: etag.replace(/"/g, ''), weak: etag.startsWith('W/') } : undefined,
167+
etag: etag ? {
168+
value: etag.replace(/^W\/|"/g, ''),
169+
weak: etag.startsWith('W/')
170+
} : undefined,
165171
lastModified: lastModified || undefined,
166172
notModified: false
167173
};
@@ -261,7 +267,7 @@ export class ObjectStackClient {
261267

262268
createMany: async <T = any>(object: string, data: Partial<T>[]): Promise<T[]> => {
263269
const route = this.getRoute('data');
264-
const res = await this.fetch(`${this.baseUrl}${route}/${object}/batch`, {
270+
const res = await this.fetch(`${this.baseUrl}${route}/${object}/createMany`, {
265271
method: 'POST',
266272
body: JSON.stringify(data)
267273
});
@@ -292,7 +298,7 @@ export class ObjectStackClient {
292298

293299
/**
294300
* Update multiple records (simplified batch update)
295-
* @deprecated Use batch() method for full control
301+
* Convenience method for batch updates without full BatchUpdateRequest
296302
*/
297303
updateMany: async <T = any>(
298304
object: string,
@@ -301,7 +307,7 @@ export class ObjectStackClient {
301307
): Promise<BatchUpdateResponse> => {
302308
const route = this.getRoute('data');
303309
const request: UpdateManyRequest = {
304-
records: records.map(r => ({ id: r.id, data: r.data })),
310+
records,
305311
options
306312
};
307313
const res = await this.fetch(`${this.baseUrl}${route}/${object}/updateMany`, {

0 commit comments

Comments
 (0)