@@ -11,7 +11,11 @@ The `@objectstack/client` is the official TypeScript client for ObjectStack. It
1111
1212- ** Auto-Discovery** : Connects to your ObjectStack server and automatically configures API endpoints.
1313- ** Typed Metadata** : Retrieve Object and View definitions with full type support.
14- - ** Unified Data Access** : Simple and Advanced CRUD operations for any object in your schema.
14+ - ** Metadata Caching** : ETag-based conditional requests for efficient metadata caching.
15+ - ** Unified Data Access** : Simple CRUD operations for any object in your schema.
16+ - ** Batch Operations** : Efficient bulk create/update/delete with transaction support.
17+ - ** View Storage** : Save, load, and share custom UI view configurations.
18+ - ** Standardized Errors** : Machine-readable error codes with retry guidance.
1519
1620## Installation
1721
@@ -52,8 +56,48 @@ async function main() {
5256 priority: 1
5357 });
5458
55- // 6. Batch Operations
56- await client .data .deleteMany (' todo_task' , [' id1' , ' id2' ]);
59+ // 6. Batch Operations (New!)
60+ const batchResult = await client .data .batch (' todo_task' , {
61+ operation: ' update' ,
62+ records: [
63+ { id: ' 1' , data: { status: ' active' } },
64+ { id: ' 2' , data: { status: ' active' } }
65+ ],
66+ options: {
67+ atomic: true , // Rollback on any failure
68+ returnRecords: true // Include full records in response
69+ }
70+ });
71+ console .log (` Updated ${batchResult .succeeded } records ` );
72+
73+ // 7. Metadata Caching (New!)
74+ const cachedObject = await client .meta .getCached (' todo_task' , {
75+ ifNoneMatch: ' "686897696a7c876b7e"' // ETag from previous request
76+ });
77+ if (cachedObject .notModified ) {
78+ console .log (' Using cached metadata' );
79+ }
80+
81+ // 8. View Storage (New!)
82+ const view = await client .views .create ({
83+ name: ' active_tasks' ,
84+ label: ' Active Tasks' ,
85+ object: ' todo_task' ,
86+ type: ' list' ,
87+ visibility: ' public' ,
88+ query: {
89+ object: ' todo_task' ,
90+ where: { status: ' active' },
91+ orderBy: [{ field: ' priority' , order: ' desc' }],
92+ limit: 50
93+ },
94+ layout: {
95+ columns: [
96+ { field: ' subject' , label: ' Task' , width: 200 },
97+ { field: ' priority' , label: ' Priority' , width: 100 }
98+ ]
99+ }
100+ });
57101}
58102```
59103
@@ -72,18 +116,29 @@ Initializes the client by fetching the system discovery manifest from `/api/v1`.
72116
73117### ` client.meta `
74118- ` getObject(name: string) ` : Get object schema.
119+ - ` getCached(name: string, options?) ` : Get object schema with ETag-based caching.
75120- ` getView(name: string) ` : Get view configuration (e.g. for automatic UI generation).
76121
77122### ` client.data `
78- - ` find<T>(object, options) ` : Advanced query.
123+ - ` find<T>(object, options) ` : Advanced query with filtering, sorting, selection .
79124- ` get<T>(object, id) ` : Get single record by ID.
80125- ` query<T>(object, ast) ` : Execute complex query using full AST (support for Joins, Aggregations).
81126- ` create<T>(object, data) ` : Create record.
82- - ` createMany<T>(object, data[]) ` : Batch create.
127+ - ` batch(object, request) ` : ** Recommended** - Execute batch operations (create/update/upsert/delete) with full control.
128+ - ` createMany<T>(object, data[]) ` : Batch create records (convenience method).
83129- ` update<T>(object, id, data) ` : Update record.
84- - ` updateMany<T>(object, ids [], data ) ` : Batch update.
130+ - ` updateMany<T>(object, records [], options? ) ` : Batch update records (convenience method) .
85131- ` delete(object, id) ` : Delete record.
86- - ` deleteMany(object, ids[]) ` : Batch delete.
132+ - ` deleteMany(object, ids[], options?) ` : Batch delete records (convenience method).
133+
134+ ### ` client.views ` (New!)
135+ - ` create(request) ` : Create a new saved view.
136+ - ` get(id) ` : Get a saved view by ID.
137+ - ` list(request?) ` : List saved views with optional filters.
138+ - ` update(request) ` : Update an existing view.
139+ - ` delete(id) ` : Delete a saved view.
140+ - ` share(id, userIds[]) ` : Share a view with users/teams.
141+ - ` setDefault(id, object) ` : Set a view as default for an object.
87142
88143### Query Options (` QueryOptions ` )
89144The ` find ` method accepts an options object to control the query:
@@ -95,3 +150,42 @@ The `find` method accepts an options object to control the query:
95150| ` sort ` | ` string ` or ` string[] ` | Sort order | ` ['-created_at'] ` |
96151| ` top ` | ` number ` | Limit records | ` 20 ` |
97152| ` skip ` | ` number ` | Offset (Pagination) | ` 0 ` |
153+
154+ ### Batch Options
155+ Batch operations support the following options:
156+ - ` atomic ` : If true, rollback entire batch on any failure (default: true).
157+ - ` returnRecords ` : If true, return full record data in response (default: false).
158+ - ` continueOnError ` : If true (and atomic=false), continue processing remaining records after errors.
159+ - ` validateOnly ` : If true, validate records without persisting changes (dry-run mode).
160+
161+ ### Error Handling
162+ The client provides standardized error handling with machine-readable error codes:
163+
164+ ``` typescript
165+ try {
166+ await client .data .create (' todo_task' , { subject: ' ' });
167+ } catch (error ) {
168+ console .error (' Error code:' , error .code ); // e.g., 'validation_error'
169+ console .error (' Category:' , error .category ); // e.g., 'validation'
170+ console .error (' HTTP status:' , error .httpStatus ); // e.g., 400
171+ console .error (' Retryable:' , error .retryable ); // e.g., false
172+ console .error (' Details:' , error .details ); // Additional error info
173+ }
174+ ```
175+
176+ Common error codes:
177+ - ` validation_error ` : Input validation failed
178+ - ` unauthenticated ` : Authentication required
179+ - ` permission_denied ` : Insufficient permissions
180+ - ` resource_not_found ` : Resource does not exist
181+ - ` rate_limit_exceeded ` : Too many requests
182+
183+ ## React Hooks
184+
185+ For React applications, use ` @objectstack/client-react ` which provides hooks for data fetching and mutations:
186+
187+ ``` bash
188+ pnpm add @objectstack/client-react
189+ ```
190+
191+ See the [ React Hooks documentation] ( ./react-hooks ) for detailed usage.
0 commit comments