You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(json-rpc): add comprehensive tests and docs for Q2 features
- Add 18 E2E tests for object.count(), action.execute(), and batch requests
- Enhance README with detailed examples for all three features
- Document batch requests per JSON-RPC 2.0 spec §6
- Include examples for notifications, partial errors, and call chaining
- All 135 tests passing
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copy file name to clipboardExpand all lines: packages/protocols/json-rpc/README.md
+300-6Lines changed: 300 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -167,16 +167,85 @@ Delete a record.
167
167
168
168
Count records matching filters.
169
169
170
-
**Request:**
170
+
**Request (no filter - count all):**
171
171
```json
172
172
{
173
173
"jsonrpc": "2.0",
174
174
"method": "object.count",
175
-
"params": ["users", {"active": true}],
175
+
"params": ["users"],
176
+
"id": 6
177
+
}
178
+
```
179
+
180
+
**Response:**
181
+
```json
182
+
{
183
+
"jsonrpc": "2.0",
184
+
"result": 42,
176
185
"id": 6
177
186
}
178
187
```
179
188
189
+
**Request (with filter):**
190
+
```json
191
+
{
192
+
"jsonrpc": "2.0",
193
+
"method": "object.count",
194
+
"params": ["users", {
195
+
"type": "comparison",
196
+
"field": "active",
197
+
"operator": "=",
198
+
"value": true
199
+
}],
200
+
"id": 7
201
+
}
202
+
```
203
+
204
+
**Response:**
205
+
```json
206
+
{
207
+
"jsonrpc": "2.0",
208
+
"result": 28,
209
+
"id": 7
210
+
}
211
+
```
212
+
213
+
**Request (with complex filter):**
214
+
```json
215
+
{
216
+
"jsonrpc": "2.0",
217
+
"method": "object.count",
218
+
"params": ["users", {
219
+
"type": "logical",
220
+
"operator": "and",
221
+
"conditions": [
222
+
{
223
+
"type": "comparison",
224
+
"field": "active",
225
+
"operator": "=",
226
+
"value": true
227
+
},
228
+
{
229
+
"type": "comparison",
230
+
"field": "role",
231
+
"operator": "=",
232
+
"value": "admin"
233
+
}
234
+
]
235
+
}],
236
+
"id": 8
237
+
}
238
+
```
239
+
240
+
**Response:**
241
+
```json
242
+
{
243
+
"jsonrpc": "2.0",
244
+
"result": 5,
245
+
"id": 8
246
+
}
247
+
```
248
+
180
249
### Metadata Methods
181
250
182
251
#### metadata.list
@@ -245,6 +314,59 @@ Execute a custom action.
245
314
}
246
315
```
247
316
317
+
**Response:**
318
+
```json
319
+
{
320
+
"jsonrpc": "2.0",
321
+
"result": {
322
+
"success": true,
323
+
"messageId": "msg_1234567890",
324
+
"to": "user@example.com",
325
+
"subject": "Hello"
326
+
},
327
+
"id": 10
328
+
}
329
+
```
330
+
331
+
**Example: Calculate Discount**
332
+
```json
333
+
{
334
+
"jsonrpc": "2.0",
335
+
"method": "action.execute",
336
+
"params": ["calculateDiscount", {
337
+
"amount": 100,
338
+
"percentage": 20
339
+
}],
340
+
"id": 11
341
+
}
342
+
```
343
+
344
+
**Response:**
345
+
```json
346
+
{
347
+
"jsonrpc": "2.0",
348
+
"result": {
349
+
"originalAmount": 100,
350
+
"discountPercentage": 20,
351
+
"discountAmount": 20,
352
+
"finalAmount": 80
353
+
},
354
+
"id": 11
355
+
}
356
+
```
357
+
358
+
**Error Response (action not found):**
359
+
```json
360
+
{
361
+
"jsonrpc": "2.0",
362
+
"error": {
363
+
"code": -32603,
364
+
"message": "Action not found: unknownAction"
365
+
},
366
+
"id": 12
367
+
}
368
+
```
369
+
248
370
#### action.list
249
371
250
372
List all available actions.
@@ -254,7 +376,21 @@ List all available actions.
254
376
{
255
377
"jsonrpc": "2.0",
256
378
"method": "action.list",
257
-
"id": 11
379
+
"id": 13
380
+
}
381
+
```
382
+
383
+
**Response:**
384
+
```json
385
+
{
386
+
"jsonrpc": "2.0",
387
+
"result": [
388
+
"sendEmail",
389
+
"calculateDiscount",
390
+
"processPayment",
391
+
"generateReport"
392
+
],
393
+
"id": 13
258
394
}
259
395
```
260
396
@@ -320,9 +456,11 @@ Get method signature and description.
320
456
321
457
## Advanced Features
322
458
323
-
### Batch Requests
459
+
### Batch Requests (JSON-RPC 2.0 §6)
460
+
461
+
Execute multiple RPC calls in a single HTTP request. Per JSON-RPC 2.0 specification section 6, batch requests allow you to send an array of request objects and receive an array of response objects.
324
462
325
-
Execute multiple RPC calls in a single HTTP request.
463
+
#### Basic Batch Request
326
464
327
465
**Request:**
328
466
```json
@@ -337,6 +475,12 @@ Execute multiple RPC calls in a single HTTP request.
337
475
"method": "object.find",
338
476
"params": ["users", {}],
339
477
"id": 2
478
+
},
479
+
{
480
+
"jsonrpc": "2.0",
481
+
"method": "object.count",
482
+
"params": ["users"],
483
+
"id": 3
340
484
}
341
485
]
342
486
```
@@ -351,8 +495,158 @@ Execute multiple RPC calls in a single HTTP request.
351
495
},
352
496
{
353
497
"jsonrpc": "2.0",
354
-
"result": {"value": [...], "count": 10},
498
+
"result": [
499
+
{"id": "1", "name": "Alice"},
500
+
{"id": "2", "name": "Bob"}
501
+
],
355
502
"id": 2
503
+
},
504
+
{
505
+
"jsonrpc": "2.0",
506
+
"result": 2,
507
+
"id": 3
508
+
}
509
+
]
510
+
```
511
+
512
+
#### Batch with Mixed Operations
513
+
514
+
Execute CRUD operations, counts, and actions in a single batch:
0 commit comments