@@ -6,7 +6,11 @@ The official TypeScript client for ObjectStack.
66
77- ** Auto-Discovery** : Connects to your ObjectStack server and automatically configures API endpoints.
88- ** Typed Metadata** : Retrieve Object and View definitions with full type support.
9+ - ** Metadata Caching** : ETag-based conditional requests for efficient metadata caching.
910- ** Unified Data Access** : Simple CRUD operations for any object in your schema.
11+ - ** Batch Operations** : Efficient bulk create/update/delete with transaction support.
12+ - ** View Storage** : Save, load, and share custom UI view configurations.
13+ - ** Standardized Errors** : Machine-readable error codes with retry guidance.
1014
1115## Installation
1216
@@ -47,8 +51,48 @@ async function main() {
4751 priority: 1
4852 });
4953
50- // 6. Batch Operations
51- await client .data .deleteMany (' todo_task' , [' id1' , ' id2' ]);
54+ // 6. Batch Operations (New!)
55+ const batchResult = await client .data .batch (' todo_task' , {
56+ operation: ' update' ,
57+ records: [
58+ { id: ' 1' , data: { status: ' active' } },
59+ { id: ' 2' , data: { status: ' active' } }
60+ ],
61+ options: {
62+ atomic: true , // Rollback on any failure
63+ returnRecords: true // Include full records in response
64+ }
65+ });
66+ console .log (` Updated ${batchResult .succeeded } records ` );
67+
68+ // 7. Metadata Caching (New!)
69+ const cachedObject = await client .meta .getCached (' todo_task' , {
70+ ifNoneMatch: ' "686897696a7c876b7e"' // ETag from previous request
71+ });
72+ if (cachedObject .notModified ) {
73+ console .log (' Using cached metadata' );
74+ }
75+
76+ // 8. View Storage (New!)
77+ const view = await client .views .create ({
78+ name: ' active_tasks' ,
79+ label: ' Active Tasks' ,
80+ object: ' todo_task' ,
81+ type: ' list' ,
82+ visibility: ' public' ,
83+ query: {
84+ object: ' todo_task' ,
85+ where: { status: ' active' },
86+ orderBy: [{ field: ' priority' , order: ' desc' }],
87+ limit: 50
88+ },
89+ layout: {
90+ columns: [
91+ { field: ' subject' , label: ' Task' , width: 200 },
92+ { field: ' priority' , label: ' Priority' , width: 100 }
93+ ]
94+ }
95+ });
5296}
5397```
5498
@@ -59,18 +103,29 @@ Initializes the client by fetching the system discovery manifest from `/api/v1`.
59103
60104### ` client.meta `
61105- ` getObject(name: string) ` : Get object schema.
106+ - ` getCached(name: string, options?) ` : Get object schema with ETag-based caching.
62107- ` getView(name: string) ` : Get view configuration.
63108
64109### ` client.data `
65110- ` find<T>(object, options) ` : Advanced query with filtering, sorting, selection.
66111- ` get<T>(object, id) ` : Get single record by ID.
67112- ` query<T>(object, ast) ` : Execute complex query using full AST.
68113- ` create<T>(object, data) ` : Create record.
69- - ` 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).
70116- ` update<T>(object, id, data) ` : Update record.
71- - ` updateMany<T>(object, ids [], data ) ` : Batch update records.
117+ - ` updateMany<T>(object, records [], options? ) ` : Batch update records (convenience method) .
72118- ` delete(object, id) ` : Delete record.
73- - ` deleteMany(object, ids[]) ` : Batch delete records.
119+ - ` deleteMany(object, ids[], options?) ` : Batch delete records (convenience method).
120+
121+ ### ` client.views ` (New!)
122+ - ` create(request) ` : Create a new saved view.
123+ - ` get(id) ` : Get a saved view by ID.
124+ - ` list(request?) ` : List saved views with optional filters.
125+ - ` update(request) ` : Update an existing view.
126+ - ` delete(id) ` : Delete a saved view.
127+ - ` share(id, userIds[]) ` : Share a view with users/teams.
128+ - ` setDefault(id, object) ` : Set a view as default for an object.
74129
75130### Query Options
76131The ` find ` method accepts an options object:
@@ -80,3 +135,32 @@ The `find` method accepts an options object:
80135- ` top ` : Limit number of records.
81136- ` skip ` : Offset for pagination.
82137
138+ ### Batch Options
139+ Batch operations support the following options:
140+ - ` atomic ` : If true, rollback entire batch on any failure (default: true).
141+ - ` returnRecords ` : If true, return full record data in response (default: false).
142+ - ` continueOnError ` : If true (and atomic=false), continue processing remaining records after errors.
143+ - ` validateOnly ` : If true, validate records without persisting changes (dry-run mode).
144+
145+ ### Error Handling
146+ The client provides standardized error handling with machine-readable error codes:
147+
148+ ``` typescript
149+ try {
150+ await client .data .create (' todo_task' , { subject: ' ' });
151+ } catch (error ) {
152+ console .error (' Error code:' , error .code ); // e.g., 'validation_error'
153+ console .error (' Category:' , error .category ); // e.g., 'validation'
154+ console .error (' HTTP status:' , error .httpStatus ); // e.g., 400
155+ console .error (' Retryable:' , error .retryable ); // e.g., false
156+ console .error (' Details:' , error .details ); // Additional error info
157+ }
158+ ```
159+
160+ Common error codes:
161+ - ` validation_error ` : Input validation failed
162+ - ` unauthenticated ` : Authentication required
163+ - ` permission_denied ` : Insufficient permissions
164+ - ` resource_not_found ` : Resource does not exist
165+ - ` rate_limit_exceeded ` : Too many requests
166+
0 commit comments