Skip to content

Commit 58a340b

Browse files
Merge pull request #489 from objectstack-ai/copilot/update-documentation
2 parents e852964 + 2d0b424 commit 58a340b

File tree

4 files changed

+207
-17
lines changed

4 files changed

+207
-17
lines changed

ARCHITECTURE.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,40 @@ ObjectStack is organized as a **monorepo** with distinct package layers:
200200

201201
#### `@objectstack/client`
202202
**Location**: `packages/client/`
203-
**Role**: Client SDK
204-
205-
- Client-side API wrapper
206-
- Request/response handling
207-
- Type-safe API calls
203+
**Role**: Official TypeScript Client SDK for ObjectStack Protocol
204+
205+
**Features**:
206+
- **Auto-Discovery**: Connects to ObjectStack server and auto-configures API endpoints
207+
- **Typed Metadata**: Retrieve Object and View definitions with full TypeScript support
208+
- **Metadata Caching**: ETag-based conditional requests for efficient metadata caching
209+
- **Data Operations**:
210+
- Advanced queries with filtering, sorting, and field selection
211+
- CRUD operations (create, read, update, delete)
212+
- Batch operations with transaction support (batch create/update/upsert/delete)
213+
- Query builder with type-safe filters
214+
- **View Storage**: Save, load, share, and manage custom UI view configurations
215+
- **Error Handling**: Standardized error codes with retry guidance
216+
- **HTTP Caching**: ETag support for optimized metadata requests
217+
218+
**API Surface**:
219+
- `client.connect()`: Initialize client with server discovery
220+
- `client.meta.*`: Metadata operations (getObject, getCached, getView)
221+
- `client.data.*`: Data operations (find, get, query, create, batch, update, delete)
222+
- `client.views.*`: View storage operations (create, get, list, update, delete, share)
208223

209224
**Dependencies**: `@objectstack/core`, `@objectstack/spec`
210225

211226
#### `@objectstack/client-react`
212227
**Location**: `packages/client-react/`
213-
**Role**: React Hooks
214-
215-
- React hooks for ObjectStack
216-
- State management integration
217-
- React Query / SWR patterns
228+
**Role**: React Hooks for ObjectStack Client SDK
229+
230+
**Features**:
231+
- **Data Hooks**: `useQuery`, `useMutation`, `usePagination`, `useInfiniteQuery`
232+
- **Metadata Hooks**: `useObject`, `useView`, `useFields`, `useMetadata`
233+
- **Context Management**: `ObjectStackProvider`, `useClient`
234+
- **Type Safety**: Full TypeScript generics support for type-safe data
235+
- **Auto-refetch**: Automatic data refetching and caching
236+
- **Loading States**: Built-in loading and error state management
218237

219238
**Dependencies**: `@objectstack/client`, `@objectstack/core`, `@objectstack/spec`
220239
**Peer Dependencies**: `react`

PROTOCOL-QUICK-REFERENCE.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,40 @@
77
- **Find by Category**: Browse protocols by domain (Data, UI, System, etc.)
88
- **Find by Example**: Every protocol links to practical examples
99
- **Find by Feature**: Use the index to jump to specific features
10+
- **Client SDKs**: See [Client SDK](#client-sdk) section for TypeScript and React integration
11+
12+
---
13+
14+
## 🔌 Client SDK
15+
16+
Access ObjectStack from your applications using the official client libraries:
17+
18+
| SDK | Description | Documentation | Status |
19+
|-----|-------------|---------------|--------|
20+
| **@objectstack/client** | Official TypeScript client with metadata caching, batch operations, and view storage | [Client SDK Docs](./content/docs/references/client-sdk/) ||
21+
| **@objectstack/client-react** | React hooks for data fetching, mutations, pagination, and infinite scrolling | [React Hooks Docs](./content/docs/references/client-sdk/react-hooks.mdx) ||
22+
23+
**Quick Start:**
24+
```typescript
25+
import { ObjectStackClient } from '@objectstack/client';
26+
27+
const client = new ObjectStackClient({ baseUrl: 'http://localhost:3004' });
28+
await client.connect();
29+
30+
// Query data with filtering and sorting
31+
const tasks = await client.data.find('todo_task', {
32+
filters: ['status', '=', 'active'],
33+
sort: ['-priority'],
34+
top: 10
35+
});
36+
37+
// Batch operations with transaction support
38+
await client.data.batch('todo_task', {
39+
operation: 'update',
40+
records: [/* ... */],
41+
options: { atomic: true }
42+
});
43+
```
1044

1145
---
1246

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,49 @@ ObjectStack is a metadata-driven platform built on three foundational protocols:
6161

6262
## 🚀 Quick Start
6363

64+
### For Application Developers (Using the Client SDK)
65+
66+
If you want to build applications using ObjectStack:
67+
68+
```bash
69+
# Install the client SDK
70+
pnpm add @objectstack/client
71+
72+
# For React applications
73+
pnpm add @objectstack/client-react
74+
```
75+
76+
```typescript
77+
import { ObjectStackClient } from '@objectstack/client';
78+
79+
// Connect to your ObjectStack server
80+
const client = new ObjectStackClient({
81+
baseUrl: 'http://localhost:3004'
82+
});
83+
84+
await client.connect();
85+
86+
// Query data
87+
const tasks = await client.data.find('todo_task', {
88+
select: ['subject', 'priority'],
89+
filters: ['status', '=', 'active'],
90+
sort: ['-priority'],
91+
top: 10
92+
});
93+
94+
// Create data
95+
await client.data.create('todo_task', {
96+
subject: 'New Task',
97+
priority: 1
98+
});
99+
```
100+
101+
📖 **[View Client SDK Documentation](./content/docs/references/client-sdk/)** - Complete SDK reference with React hooks
102+
103+
### For Protocol Developers (Contributing to ObjectStack)
104+
105+
If you want to contribute to the ObjectStack protocol or build plugins:
106+
64107
```bash
65108
# 1. Install dependencies
66109
pnpm install

content/docs/references/client-sdk/index.mdx

Lines changed: 101 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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`)
89144
The `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

Comments
 (0)