@emeryld/rrroutes-client 2.6.6 → 2.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <!--
2
2
  Summary:
3
3
  - Added comprehensive usage for `createRouteClient`, built endpoints (GET/feeds/mutations), cache helpers, invalidation, debug modes, custom fetchers, and React Query integration.
4
- - Added new sections for router helpers, infinite/feeds, FormData uploads, and socket utilities (SocketClient, provider hooks, socketed routes).
4
+ - Added new sections for router helpers, batched branches (`buildBranch`), infinite/feeds, FormData uploads, and socket utilities (SocketClient, provider hooks, socketed routes).
5
5
  - Removed the sparse README and outdated publishing script focus; future additions should cover server-side Socket.IO envelope expectations and testing recipes for hooks.
6
6
  -->
7
7
 
@@ -220,7 +220,53 @@ const listUsers = buildRoute('listUsers') // builds from routes.listUsers
220
220
  const updateUser = buildRoute('updateUser', {}, { name: 'profile' }) // debug name filtering
221
221
  ```
222
222
 
223
- ### 8) File uploads (FormData)
223
+ ### 8) Batch multiple built endpoints (`buildBranch`)
224
+
225
+ `buildBranch` lets you batch already-built endpoints behind one batch path.
226
+
227
+ ```ts
228
+ const getUser = client.build(registry.byKey['GET /v1/users/:userId'])
229
+ const updateUser = client.build(registry.byKey['PATCH /v1/users/:userId'])
230
+
231
+ const userBatch = client.buildBranch(
232
+ { getUser, updateUser },
233
+ { path: '/v1/batch', method: 'post' }, // method defaults to POST
234
+ )
235
+
236
+ const result = await userBatch.fetch({
237
+ getUser: {
238
+ args: { params: { userId: 'u_1' } },
239
+ },
240
+ updateUser: {
241
+ args: { params: { userId: 'u_1' } },
242
+ body: { name: 'Emery' }, // required for mutation leaves
243
+ },
244
+ })
245
+
246
+ // result keys map back to your aliases:
247
+ // { getUser: ..., updateUser: ... }
248
+ ```
249
+
250
+ The request body sent to `/v1/batch` is keyed by URL-encoded leaf keys:
251
+
252
+ ```ts
253
+ {
254
+ [encodeURIComponent('GET /v1/users/:userId')]: { params: { userId: 'u_1' } },
255
+ [encodeURIComponent('PATCH /v1/users/:userId')]: {
256
+ params: { userId: 'u_1' },
257
+ body: { name: 'Emery' },
258
+ },
259
+ }
260
+ ```
261
+
262
+ `buildBranch` also provides:
263
+
264
+ - `useEndpoint(input, options?)` for a single React Query hook over the batched response.
265
+ - `getQueryKeys(input?)` to derive per-alias keys.
266
+ - `invalidate(input?)` to invalidate each leaf alias exactly.
267
+ - `setData(input)` to write cache per alias.
268
+
269
+ ### 9) File uploads (FormData)
224
270
 
225
271
  If a leaf has `bodyFiles` set in its contract, the client automatically converts the body to `FormData`.
226
272
  For each declared file field name, pass files using `file${name}` in the input body.
@@ -251,7 +297,7 @@ await uploadAvatar.fetch(
251
297
  )
252
298
  ```
253
299
 
254
- ### 9) Debug logging
300
+ ### 10) Debug logging
255
301
 
256
302
  ```ts
257
303
  const client = createRouteClient({