@bereasoftware/nexa 1.6.0 → 1.8.0

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.en.md CHANGED
@@ -266,6 +266,13 @@ const result = await client.head("/users/1");
266
266
 
267
267
  // OPTIONS (CORS preflight, available methods)
268
268
  const result = await client.options("/users");
269
+
270
+ // QUERY (IETF-draft method: safe, idempotent, JSON body)
271
+ // Ideal for complex search/filter payloads that don't fit in a URL.
272
+ const result = await client.query<User[]>("/users/search", {
273
+ filters: { role: "admin", active: true },
274
+ sort: ["-createdAt"],
275
+ });
269
276
  ```
270
277
 
271
278
  All methods accept an optional config object as the last parameter:
@@ -303,6 +310,31 @@ const result = await client.get<User[]>("/users", {
303
310
  // → GET /users?page=1&limit=20&active=true
304
311
  ```
305
312
 
313
+ Arrays are serialized as repeated keys, and one level of nested objects uses bracket notation. `null`/`undefined` values are omitted:
314
+
315
+ ```typescript
316
+ await client.get("/users", {
317
+ query: {
318
+ tag: ["admin", "vip"], // → tag=admin&tag=vip
319
+ filter: { status: "active" }, // → filter[status]=active
320
+ sort: undefined, // omitted
321
+ },
322
+ });
323
+ ```
324
+
325
+ ### QUERY method: complex searches with a body
326
+
327
+ The `QUERY` HTTP method (IETF draft) is safe and idempotent like `GET`, but allows sending a JSON body — useful for complex filters that would exceed a URL's practical length. Nexa caches it the same way as `GET` when `cache.enabled` is set (the body is part of the cache key):
328
+
329
+ ```typescript
330
+ const result = await client.query("/users/search", {
331
+ filters: { role: "admin" },
332
+ sort: ["-createdAt"],
333
+ }, {
334
+ cache: { enabled: true, ttlMs: 30000 },
335
+ });
336
+ ```
337
+
306
338
  ### Auto Body Serialization
307
339
 
308
340
  Nexa automatically detects and serializes the request body:
package/README.md CHANGED
@@ -280,6 +280,13 @@ const result = await client.head("/users/1");
280
280
 
281
281
  // OPTIONS (preflight CORS, métodos disponibles)
282
282
  const result = await client.options("/users");
283
+
284
+ // QUERY (método IETF-draft: seguro, idempotente, con body JSON)
285
+ // Ideal para búsquedas/filtros complejos que no entran en una URL.
286
+ const result = await client.query<User[]>("/users/search", {
287
+ filters: { role: "admin", active: true },
288
+ sort: ["-createdAt"],
289
+ });
283
290
  ```
284
291
 
285
292
  Todos los métodos aceptan un objeto de configuración opcional como último parámetro:
@@ -317,6 +324,31 @@ const result = await client.get<User[]>("/users", {
317
324
  // → GET /users?page=1&limit=20&active=true
318
325
  ```
319
326
 
327
+ Los arrays se serializan como claves repetidas, y un nivel de objetos anidados usa notación de corchetes. Los valores `null`/`undefined` se omiten:
328
+
329
+ ```typescript
330
+ await client.get("/users", {
331
+ query: {
332
+ tag: ["admin", "vip"], // → tag=admin&tag=vip
333
+ filter: { status: "active" }, // → filter[status]=active
334
+ sort: undefined, // se omite
335
+ },
336
+ });
337
+ ```
338
+
339
+ ### Método QUERY: búsquedas complejas con body
340
+
341
+ El método HTTP `QUERY` (propuesta IETF) es seguro e idempotente como `GET`, pero permite enviar un body JSON — útil para filtros complejos que excederían el largo práctico de una URL. Nexa lo cachea igual que `GET` cuando `cache.enabled` está activo (el body forma parte de la clave de caché):
342
+
343
+ ```typescript
344
+ const result = await client.query("/users/search", {
345
+ filters: { role: "admin" },
346
+ sort: ["-createdAt"],
347
+ }, {
348
+ cache: { enabled: true, ttlMs: 30000 },
349
+ });
350
+ ```
351
+
320
352
  ### Serialización Automática del Body
321
353
 
322
354
  Nexa detecta y serializa automáticamente el cuerpo de la petición:
@@ -1164,7 +1196,8 @@ const wsClient = createWebSocketClient("wss://echo.websocket.org", {
1164
1196
  });
1165
1197
 
1166
1198
  await wsClient.connect();
1167
- wsClient.sendJson({ type: "message", data: "Hello" });
1199
+ const result = wsClient.sendJson({ type: "message", data: "Hello" });
1200
+ if (!result.ok) console.error("No se pudo enviar:", result.error.message);
1168
1201
  wsClient.onMessage((event) => console.log("Mensaje:", event.data));
1169
1202
 
1170
1203
  // SSE para streams de eventos
@@ -1810,7 +1843,7 @@ Ver la carpeta `examples/` para ejemplos de uso con diferentes frameworks:
1810
1843
 
1811
1844
  **HTTP Client** (`test/http-client.test.ts`) — **88 tests**:
1812
1845
 
1813
- - ✓ Métodos core: create, GET/POST/PUT/DELETE/PATCH/HEAD/OPTIONS (7 tests)
1846
+ - ✓ Métodos core: create, GET/POST/PUT/DELETE/PATCH/HEAD/OPTIONS/QUERY (8 tests)
1814
1847
  - ✓ Estrategias de reintentos & timeouts (3 tests)
1815
1848
  - ✓ Interceptores & disposal (5 tests)
1816
1849
  - ✓ Caché & validación (4 tests)