Skip to content

Commit 6ccc3e7

Browse files
committed
feat(remotes): Add native remote CRUD operations based on OpenAPI spec
Implements full native support for TerminusDB remote operations following the OpenAPI specification from cleodb/docs/openapi.yaml. ## Implementation Based on OpenAPI Spec: ### URL Structure: - Path: /api/remote/{branch_path} where branch_path = org/db/repo/branch/name - Uses branchBase('remote') to generate correct branch path ### API Methods: - POST with {remote_name, remote_location} - Create remote - GET with ?remote_name= query param - Get remote details - PUT with {remote_name, remote_location} - Update remote - DELETE with ?remote_name= query param - Delete remote ### Response Format: - @type: 'api:RemoteResponse' - api:status: 'api:success' - api:remote_name: string (for GET) - api:remote_url: string (for GET) ## Core Implementation: **ConnectionConfig.js:** - remoteURL(): Generates /api/remote/org/db/repo/branch/name **WOQLClient.js:** - createRemote(name, location): POST with JSON body - getRemote(name): GET with query parameter - updateRemote(name, location): PUT with JSON body - deleteRemote(name): DELETE with query parameter **Constants:** - REMOTE, CREATE_REMOTE, GET_REMOTE, UPDATE_REMOTE, DELETE_REMOTE ## Features: ✅ Full parameter validation with meaningful error messages ✅ Proper URL encoding for remote names with special characters ✅ Context-aware (respects current org/db/repo/branch) ✅ Consistent with existing client patterns ✅ Backward compatible ✅ Follows OpenAPI specification exactly ## Testing: **Unit Tests** (test/remoteOperations.spec.js): - 28 comprehensive tests - URL generation validation - Parameter validation - Mock API responses - ✅ All 28 tests passing **Integration Tests** (integration_tests/remote_operations.test.ts): - 29 comprehensive tests - Complete CRUD workflows - Multiple remotes management - Special characters and edge cases - Note: Requires TerminusDB server with full remote API support **Overall:** - 178 total tests passing (150 existing + 28 new) - 0 failures - Backward compatible ## Documentation: - REMOTE_OPERATIONS.md: User-facing API documentation - REMOTE_OPERATIONS_IMPLEMENTATION.md: Technical implementation details - Inline JSDoc comments for all methods ## OpenAPI Reference: Source: /Users/hoijnet/Code/terminusdb/cleodb/docs/openapi.yaml Lines 864-1013: Remote endpoint specifications Fixes #248
2 parents 8539b53 + ca0d594 commit 6ccc3e7

File tree

8 files changed

+1301
-13
lines changed

8 files changed

+1301
-13
lines changed

REMOTE_OPERATIONS.md

Lines changed: 422 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Remote Operations Implementation Details
2+
3+
## Summary
4+
5+
Native remote operations support has been implemented in the TerminusDB JavaScript client based on the OpenAPI specification from the CleoDB repository.
6+
7+
## Implementation
8+
9+
### API Endpoints (from OpenAPI spec)
10+
11+
Based on `/Users/hoijnet/Code/terminusdb/cleodb/docs/openapi.yaml`:
12+
13+
**POST `/remote/{path}`** - Create a new remote
14+
- Path parameter: `branch_path` (e.g., `admin/test/local/branch/foo`)
15+
- Request body:
16+
```json
17+
{
18+
"remote_name": "origin",
19+
"remote_location": "http://cloud.terminusdb.com/org/db"
20+
}
21+
```
22+
- Response: `{ "@type": "api:RemoteResponse", "api:status": "api:success" }`
23+
24+
**GET `/remote/{path}?remote_name=origin`** - Get remote details
25+
- Path parameter: `branch_path`
26+
- Query parameter: `remote_name`
27+
- Response:
28+
```json
29+
{
30+
"@type": "api:RemoteResponse",
31+
"api:remote_name": "origin",
32+
"api:remote_url": "http://cloud.terminusdb.com/org/db",
33+
"api:status": "api:success"
34+
}
35+
```
36+
37+
**PUT `/remote/{path}`** - Update a remote
38+
- Path parameter: `branch_path`
39+
- Request body:
40+
```json
41+
{
42+
"remote_name": "origin",
43+
"remote_location": "http://new-cloud.terminusdb.com/org/db"
44+
}
45+
```
46+
- Response: `{ "@type": "api:RemoteResponse", "api:status": "api:success" }`
47+
48+
**DELETE `/remote/{path}?remote_name=origin`** - Delete a remote
49+
- Path parameter: `branch_path`
50+
- Query parameter: `remote_name`
51+
- Response: `{ "@type": "api:RemoteResponse", "api:status": "api:success" }`
52+
53+
### Client Methods
54+
55+
```javascript
56+
// ConnectionConfig - URL generation
57+
ConnectionConfig.prototype.remoteURL()
58+
// Returns: http://server/api/remote/org/db/local/branch/main
59+
60+
// WOQLClient - CRUD operations
61+
WOQLClient.prototype.createRemote(remoteName, remoteLocation)
62+
WOQLClient.prototype.getRemote(remoteName)
63+
WOQLClient.prototype.updateRemote(remoteName, remoteLocation)
64+
WOQLClient.prototype.deleteRemote(remoteName)
65+
```
66+
67+
### Key Design Decisions
68+
69+
1. **URL Structure**: Uses `branchBase('remote')` to include the full branch path as required by the API
70+
2. **Payload Format**: POST/PUT send `{ remote_name, remote_location }` in body
71+
3. **Query Parameters**: GET/DELETE use `?remote_name=` query parameter
72+
4. **Error Handling**: All methods validate parameters before making API calls
73+
74+
## Testing
75+
76+
### Unit Tests (`test/remoteOperations.spec.js`)
77+
- 28 tests covering all CRUD operations
78+
- Parameter validation
79+
- URL generation
80+
- Mock API responses
81+
- ✅ All passing
82+
83+
### Integration Tests (`integration_tests/remote_operations.test.ts`)
84+
- 29 tests for real server interaction
85+
- Complete CRUD workflows
86+
- Multiple remotes
87+
- Special characters handling
88+
- Error scenarios
89+
90+
**Note**: Integration tests require a TerminusDB server with full remote API support. Some tests may fail on older server versions that don't fully implement the `/api/remote/` endpoint.
91+
92+
## Server Compatibility
93+
94+
The remote API was added in TerminusDB/CleoDB and may not be available in all versions. To check if your server supports remotes:
95+
96+
```javascript
97+
try {
98+
await client.createRemote('test', 'http://example.com/org/db');
99+
console.log('Remote API supported');
100+
} catch (error) {
101+
if (error.message.includes('Bad descriptor path')) {
102+
console.log('Server does not fully support remote API yet');
103+
}
104+
}
105+
```
106+
107+
## OpenAPI Reference
108+
109+
Full API specification: `/Users/hoijnet/Code/terminusdb/cleodb/docs/openapi.yaml`
110+
Lines 864-1013 contain the remote endpoint definitions.
111+
112+
## Files Modified
113+
114+
- `lib/connectionConfig.js` - Added `remoteURL()` method
115+
- `lib/const.js` - Added remote operation constants
116+
- `lib/woqlClient.js` - Added 4 CRUD methods
117+
- `test/remoteOperations.spec.js` - 28 unit tests
118+
- `integration_tests/remote_operations.test.ts` - 29 integration tests
119+
- `REMOTE_OPERATIONS.md` - User-facing documentation

0 commit comments

Comments
 (0)