@emeryld/rrroutes-client 2.8.1 → 2.8.3

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
@@ -85,12 +85,20 @@ const client = createRouteClient({
85
85
  })
86
86
  ```
87
87
 
88
- If you want a typed client-wide hook error, pass it as the second generic:
88
+ If you want a typed client-wide hook error without passing generics everywhere, augment the global RRRoutes client register once:
89
89
 
90
90
  ```ts
91
91
  import { createRouteClient, type HttpError } from '@emeryld/rrroutes-client'
92
92
 
93
- const client = createRouteClient<string, HttpError>({
93
+ declare global {
94
+ namespace RRRoutesClient {
95
+ interface Register {
96
+ error: HttpError
97
+ }
98
+ }
99
+ }
100
+
101
+ const client = createRouteClient({
94
102
  baseUrl: 'https://api.example.com',
95
103
  queryClient,
96
104
  })
package/dist/index.cjs CHANGED
@@ -680,11 +680,14 @@ function buildGetLeaf(leaf, rqOpts, env) {
680
680
  const mergedEnabled = mergedQueryOptions.enabled;
681
681
  const guardedEnabled = hasCompleteArgs && (typeof mergedEnabled === "undefined" ? true : mergedEnabled);
682
682
  const listenersRef = (0, import_react2.useRef)(/* @__PURE__ */ new Set());
683
- const notifyOnReceive = (0, import_react2.useCallback)((data) => {
684
- buildOnReceive2?.(data);
685
- useOnReceive?.(data);
686
- listenersRef.current.forEach((listener) => listener(data));
687
- }, [buildOnReceive2, useOnReceive]);
683
+ const notifyOnReceive = (0, import_react2.useCallback)(
684
+ (data) => {
685
+ buildOnReceive2?.(data);
686
+ useOnReceive?.(data);
687
+ listenersRef.current.forEach((listener) => listener(data));
688
+ },
689
+ [buildOnReceive2, useOnReceive]
690
+ );
688
691
  const registerOnReceive = (0, import_react2.useCallback)(
689
692
  (listener) => {
690
693
  listenersRef.current.add(listener);
@@ -1343,7 +1346,6 @@ function buildMutationLeaf(leaf, rqOpts, env) {
1343
1346
  }
1344
1347
 
1345
1348
  // src/routesV3.client.ts
1346
- var BUILT_LEAF_META = "__rrroutesLeaf";
1347
1349
  var defaultDebugLogger = (event) => {
1348
1350
  if (typeof console === "undefined") return;
1349
1351
  const fn = console.debug ?? console.log;
@@ -1427,7 +1429,7 @@ function createRouteClient(opts) {
1427
1429
  }
1428
1430
  const toArgsTuple2 = (args) => typeof args === "undefined" ? [] : [args];
1429
1431
  const getBuiltLeaf = (built) => {
1430
- const leaf = built[BUILT_LEAF_META];
1432
+ const leaf = built["__rrroutesLeaf"];
1431
1433
  if (!leaf) {
1432
1434
  throw new Error(
1433
1435
  "buildBranch(...) expects endpoints created with this route client via client.build(...)."
@@ -1472,18 +1474,12 @@ function createRouteClient(opts) {
1472
1474
  env
1473
1475
  );
1474
1476
  }
1475
- Object.defineProperty(built, BUILT_LEAF_META, {
1477
+ Object.defineProperty(built, "__rrroutesLeaf", {
1476
1478
  value: leaf,
1477
1479
  enumerable: false,
1478
1480
  configurable: false,
1479
1481
  writable: false
1480
1482
  });
1481
- Object.defineProperty(built, "metadata", {
1482
- value: { leaf },
1483
- enumerable: true,
1484
- configurable: false,
1485
- writable: false
1486
- });
1487
1483
  return built;
1488
1484
  }
1489
1485
  const fetchRaw = async (input) => {