|
| 1 | +--- |
| 2 | +title: Batch |
| 3 | +description: Batch protocol schemas |
| 4 | +--- |
| 5 | + |
| 6 | +# Batch |
| 7 | + |
| 8 | +<Callout type="info"> |
| 9 | +**Source:** `packages/spec/src/api/batch.zod.ts` |
| 10 | +</Callout> |
| 11 | + |
| 12 | +## TypeScript Usage |
| 13 | + |
| 14 | +```typescript |
| 15 | +import { BatchOperationResultSchema, BatchOperationTypeSchema, BatchOptionsSchema, BatchRecordSchema, BatchUpdateRequestSchema, BatchUpdateResponseSchema, DeleteManyRequestSchema, UpdateManyRequestSchema } from '@objectstack/spec/api'; |
| 16 | +import type { BatchOperationResult, BatchOperationType, BatchOptions, BatchRecord, BatchUpdateRequest, BatchUpdateResponse, DeleteManyRequest, UpdateManyRequest } from '@objectstack/spec/api'; |
| 17 | + |
| 18 | +// Validate data |
| 19 | +const result = BatchOperationResultSchema.parse(data); |
| 20 | +``` |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## BatchOperationResult |
| 25 | + |
| 26 | +### Properties |
| 27 | + |
| 28 | +| Property | Type | Required | Description | |
| 29 | +| :--- | :--- | :--- | :--- | |
| 30 | +| **id** | `string` | optional | Record ID if operation succeeded | |
| 31 | +| **success** | `boolean` | ✅ | Whether this record was processed successfully | |
| 32 | +| **errors** | `object[]` | optional | Array of errors if operation failed | |
| 33 | +| **data** | `Record<string, any>` | optional | Full record data (if returnRecords=true) | |
| 34 | +| **index** | `number` | optional | Index of the record in the request array | |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## BatchOperationType |
| 39 | + |
| 40 | +### Allowed Values |
| 41 | + |
| 42 | +* `create` |
| 43 | +* `update` |
| 44 | +* `upsert` |
| 45 | +* `delete` |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## BatchOptions |
| 50 | + |
| 51 | +### Properties |
| 52 | + |
| 53 | +| Property | Type | Required | Description | |
| 54 | +| :--- | :--- | :--- | :--- | |
| 55 | +| **atomic** | `boolean` | optional | If true, rollback entire batch on any failure (transaction mode) | |
| 56 | +| **returnRecords** | `boolean` | optional | If true, return full record data in response | |
| 57 | +| **continueOnError** | `boolean` | optional | If true (and atomic=false), continue processing remaining records after errors | |
| 58 | +| **validateOnly** | `boolean` | optional | If true, validate records without persisting changes (dry-run mode) | |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## BatchRecord |
| 63 | + |
| 64 | +### Properties |
| 65 | + |
| 66 | +| Property | Type | Required | Description | |
| 67 | +| :--- | :--- | :--- | :--- | |
| 68 | +| **id** | `string` | optional | Record ID (required for update/delete) | |
| 69 | +| **data** | `Record<string, any>` | optional | Record data (required for create/update/upsert) | |
| 70 | +| **externalId** | `string` | optional | External ID for upsert matching | |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## BatchUpdateRequest |
| 75 | + |
| 76 | +### Properties |
| 77 | + |
| 78 | +| Property | Type | Required | Description | |
| 79 | +| :--- | :--- | :--- | :--- | |
| 80 | +| **operation** | `Enum<'create' \| 'update' \| 'upsert' \| 'delete'>` | ✅ | Type of batch operation | |
| 81 | +| **records** | `object[]` | ✅ | Array of records to process (max 200 per batch) | |
| 82 | +| **options** | `object` | optional | Batch operation options | |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## BatchUpdateResponse |
| 87 | + |
| 88 | +### Properties |
| 89 | + |
| 90 | +| Property | Type | Required | Description | |
| 91 | +| :--- | :--- | :--- | :--- | |
| 92 | +| **success** | `boolean` | ✅ | Operation success status | |
| 93 | +| **error** | `object` | optional | Error details if success is false | |
| 94 | +| **meta** | `object` | optional | Response metadata | |
| 95 | +| **operation** | `Enum<'create' \| 'update' \| 'upsert' \| 'delete'>` | optional | Operation type that was performed | |
| 96 | +| **total** | `number` | ✅ | Total number of records in the batch | |
| 97 | +| **succeeded** | `number` | ✅ | Number of records that succeeded | |
| 98 | +| **failed** | `number` | ✅ | Number of records that failed | |
| 99 | +| **results** | `object[]` | ✅ | Detailed results for each record | |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## DeleteManyRequest |
| 104 | + |
| 105 | +### Properties |
| 106 | + |
| 107 | +| Property | Type | Required | Description | |
| 108 | +| :--- | :--- | :--- | :--- | |
| 109 | +| **ids** | `string[]` | ✅ | Array of record IDs to delete (max 200) | |
| 110 | +| **options** | `object` | optional | Delete options | |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## UpdateManyRequest |
| 115 | + |
| 116 | +### Properties |
| 117 | + |
| 118 | +| Property | Type | Required | Description | |
| 119 | +| :--- | :--- | :--- | :--- | |
| 120 | +| **records** | `object[]` | ✅ | Array of records to update (max 200 per batch) | |
| 121 | +| **options** | `object` | optional | Update options | |
| 122 | + |
0 commit comments