@emeryld/rrroutes-client 2.6.13 → 2.7.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.md +1 -1
- package/dist/index.cjs +59 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +59 -22
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.types.d.ts +18 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -605,7 +605,8 @@ function buildGetLeaf(leaf, rqOpts, env) {
|
|
|
605
605
|
});
|
|
606
606
|
};
|
|
607
607
|
const useEndpoint = (...useArgs) => {
|
|
608
|
-
const args = useArgs[0];
|
|
608
|
+
const args = expectsArgs ? useArgs[0] : void 0;
|
|
609
|
+
const useEndpointOptions = expectsArgs ? useArgs[1] : useArgs[0];
|
|
609
610
|
const tuple = toArgsTuple(args);
|
|
610
611
|
const queryKeys = getQueryKeys(...tuple);
|
|
611
612
|
emit({
|
|
@@ -614,12 +615,18 @@ function buildGetLeaf(leaf, rqOpts, env) {
|
|
|
614
615
|
variant: "get",
|
|
615
616
|
keys: queryKeys
|
|
616
617
|
});
|
|
617
|
-
const
|
|
618
|
+
const { onReceive: buildOnReceive2, ...buildQueryOptions } = rqOpts ?? {};
|
|
619
|
+
const { onReceive: useOnReceive, ...runtimeQueryOptions } = useEndpointOptions ?? {};
|
|
620
|
+
const mergedQueryOptions = {
|
|
621
|
+
...buildQueryOptions,
|
|
622
|
+
...runtimeQueryOptions
|
|
623
|
+
};
|
|
618
624
|
const listenersRef = useRef2(/* @__PURE__ */ new Set());
|
|
619
625
|
const notifyOnReceive = useCallback2((data) => {
|
|
620
|
-
|
|
626
|
+
buildOnReceive2?.(data);
|
|
627
|
+
useOnReceive?.(data);
|
|
621
628
|
listenersRef.current.forEach((listener) => listener(data));
|
|
622
|
-
}, []);
|
|
629
|
+
}, [buildOnReceive2, useOnReceive]);
|
|
623
630
|
const registerOnReceive = useCallback2(
|
|
624
631
|
(listener) => {
|
|
625
632
|
listenersRef.current.add(listener);
|
|
@@ -631,9 +638,9 @@ function buildGetLeaf(leaf, rqOpts, env) {
|
|
|
631
638
|
);
|
|
632
639
|
const queryResult = useQuery2(
|
|
633
640
|
{
|
|
634
|
-
...
|
|
641
|
+
...mergedQueryOptions,
|
|
635
642
|
queryKey: getQueryKeys(...tuple),
|
|
636
|
-
placeholderData: keepPreviousData2,
|
|
643
|
+
placeholderData: mergedQueryOptions.placeholderData ?? keepPreviousData2,
|
|
637
644
|
queryFn: () => fetchEndpoint(tuple, {
|
|
638
645
|
onReceive: notifyOnReceive
|
|
639
646
|
})
|
|
@@ -881,7 +888,8 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
881
888
|
});
|
|
882
889
|
};
|
|
883
890
|
const useEndpoint = (...useArgs) => {
|
|
884
|
-
const args = useArgs[0];
|
|
891
|
+
const args = expectsArgs ? useArgs[0] : void 0;
|
|
892
|
+
const useEndpointOptions = expectsArgs ? useArgs[1] : useArgs[0];
|
|
885
893
|
const tuple = toArgsTuple(args);
|
|
886
894
|
const queryKeys = getQueryKeys(...tuple);
|
|
887
895
|
emit({
|
|
@@ -893,11 +901,18 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
893
901
|
const params = args?.params;
|
|
894
902
|
const query = args?.query;
|
|
895
903
|
const buildOptions = feedQueryOptions ?? {};
|
|
904
|
+
const { onReceive: buildOnReceive2, ...buildInfiniteQueryOptions } = buildOptions;
|
|
905
|
+
const { onReceive: useOnReceive, ...runtimeInfiniteQueryOptions } = useEndpointOptions ?? {};
|
|
906
|
+
const mergedInfiniteQueryOptions = {
|
|
907
|
+
...buildInfiniteQueryOptions,
|
|
908
|
+
...runtimeInfiniteQueryOptions
|
|
909
|
+
};
|
|
896
910
|
const listenersRef = useRef3(/* @__PURE__ */ new Set());
|
|
897
911
|
const notifyOnReceive = useCallback3((data) => {
|
|
898
|
-
|
|
912
|
+
buildOnReceive2?.(data);
|
|
913
|
+
useOnReceive?.(data);
|
|
899
914
|
listenersRef.current.forEach((listener) => listener(data));
|
|
900
|
-
}, []);
|
|
915
|
+
}, [buildOnReceive2, useOnReceive]);
|
|
901
916
|
const registerOnReceive = useCallback3(
|
|
902
917
|
(listener) => {
|
|
903
918
|
listenersRef.current.add(listener);
|
|
@@ -915,8 +930,8 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
915
930
|
);
|
|
916
931
|
const queryResult = useInfiniteQuery(
|
|
917
932
|
{
|
|
918
|
-
...
|
|
919
|
-
placeholderData:
|
|
933
|
+
...mergedInfiniteQueryOptions,
|
|
934
|
+
placeholderData: mergedInfiniteQueryOptions.placeholderData ?? keepPreviousData3,
|
|
920
935
|
initialPageParam: feedInitialPageParam,
|
|
921
936
|
getNextPageParam: (lastPage) => cursorFromPage(lastPage),
|
|
922
937
|
queryKey: queryKeys,
|
|
@@ -1055,6 +1070,7 @@ function buildMutationLeaf(leaf, rqOpts, env) {
|
|
|
1055
1070
|
return next;
|
|
1056
1071
|
};
|
|
1057
1072
|
const mutationBuildOptions = rqOpts ?? {};
|
|
1073
|
+
const { onReceive: mutationBuildOnReceive, ...mutationBuildQueryOptions } = mutationBuildOptions;
|
|
1058
1074
|
const fetchEndpoint = async (tuple, options) => {
|
|
1059
1075
|
const a = extractArgs(tuple);
|
|
1060
1076
|
const params = a?.params;
|
|
@@ -1186,13 +1202,14 @@ function buildMutationLeaf(leaf, rqOpts, env) {
|
|
|
1186
1202
|
const body = tupleWithBody[bodyIndex];
|
|
1187
1203
|
const result = await fetchEndpoint(tuple, {
|
|
1188
1204
|
body,
|
|
1189
|
-
onReceive: (data) =>
|
|
1205
|
+
onReceive: (data) => mutationBuildOnReceive?.(data),
|
|
1190
1206
|
requireBody: true
|
|
1191
1207
|
});
|
|
1192
1208
|
return result;
|
|
1193
1209
|
};
|
|
1194
1210
|
const useEndpoint = (...useArgs) => {
|
|
1195
|
-
const args = useArgs[0];
|
|
1211
|
+
const args = expectsArgs ? useArgs[0] : void 0;
|
|
1212
|
+
const useEndpointOptions = expectsArgs ? useArgs[1] : useArgs[0];
|
|
1196
1213
|
const tuple = toArgsTuple(args);
|
|
1197
1214
|
const mutationKey = getQueryKeys(...tuple);
|
|
1198
1215
|
emit({
|
|
@@ -1201,6 +1218,11 @@ function buildMutationLeaf(leaf, rqOpts, env) {
|
|
|
1201
1218
|
variant: "mutation",
|
|
1202
1219
|
keys: mutationKey
|
|
1203
1220
|
});
|
|
1221
|
+
const { onReceive: useOnReceive, ...runtimeMutationOptions } = useEndpointOptions ?? {};
|
|
1222
|
+
const mergedMutationOptions = {
|
|
1223
|
+
...mutationBuildQueryOptions,
|
|
1224
|
+
...runtimeMutationOptions
|
|
1225
|
+
};
|
|
1204
1226
|
const listenersRef = useRef4(/* @__PURE__ */ new Set());
|
|
1205
1227
|
const notifyListeners = useCallback4((data) => {
|
|
1206
1228
|
listenersRef.current.forEach((listener) => listener(data));
|
|
@@ -1216,12 +1238,13 @@ function buildMutationLeaf(leaf, rqOpts, env) {
|
|
|
1216
1238
|
);
|
|
1217
1239
|
const mutationResult = useMutation(
|
|
1218
1240
|
{
|
|
1219
|
-
...
|
|
1241
|
+
...mergedMutationOptions,
|
|
1220
1242
|
mutationKey,
|
|
1221
1243
|
mutationFn: async (body) => {
|
|
1222
1244
|
const result = await fetchMutation(
|
|
1223
1245
|
...[...tuple, body]
|
|
1224
1246
|
);
|
|
1247
|
+
useOnReceive?.(result);
|
|
1225
1248
|
notifyListeners(result);
|
|
1226
1249
|
return result;
|
|
1227
1250
|
}
|
|
@@ -2728,6 +2751,16 @@ function roomsFromData(data, args, toRooms) {
|
|
|
2728
2751
|
}
|
|
2729
2752
|
|
|
2730
2753
|
// src/sockets/socketedRoute/socket.client.helper.route.ts
|
|
2754
|
+
function parseUseEndpointArgs(useArgs) {
|
|
2755
|
+
const firstArg = useArgs[0];
|
|
2756
|
+
const firstArgRecord = firstArg && typeof firstArg === "object" ? firstArg : void 0;
|
|
2757
|
+
const hasRouteArgs = Boolean(
|
|
2758
|
+
firstArgRecord && (Object.prototype.hasOwnProperty.call(firstArgRecord, "params") || Object.prototype.hasOwnProperty.call(firstArgRecord, "query"))
|
|
2759
|
+
);
|
|
2760
|
+
const endpointArgs = hasRouteArgs ? firstArg : void 0;
|
|
2761
|
+
const endpointArgsTuple = typeof endpointArgs === "undefined" ? [] : [endpointArgs];
|
|
2762
|
+
return { endpointArgs, endpointArgsTuple };
|
|
2763
|
+
}
|
|
2731
2764
|
function buildSocketedRoute(options) {
|
|
2732
2765
|
const { built, toRooms, applySocket, useSocketClient: useSocketClient2, debug } = options;
|
|
2733
2766
|
const { useEndpoint: useInnerEndpoint, ...rest } = built;
|
|
@@ -2737,11 +2770,15 @@ function buildSocketedRoute(options) {
|
|
|
2737
2770
|
const endpointResult = useInnerEndpoint(
|
|
2738
2771
|
...useArgs
|
|
2739
2772
|
);
|
|
2740
|
-
const
|
|
2773
|
+
const { endpointArgs, endpointArgsTuple } = parseUseEndpointArgs(useArgs);
|
|
2774
|
+
const argsKey = useMemo3(
|
|
2775
|
+
() => safeJsonKey(endpointArgs ?? null),
|
|
2776
|
+
[endpointArgs]
|
|
2777
|
+
);
|
|
2741
2778
|
const [roomState, setRoomState] = useState2(
|
|
2742
2779
|
() => roomsFromData(
|
|
2743
2780
|
endpointResult.data,
|
|
2744
|
-
|
|
2781
|
+
endpointArgs,
|
|
2745
2782
|
toRooms
|
|
2746
2783
|
)
|
|
2747
2784
|
);
|
|
@@ -2799,13 +2836,13 @@ function buildSocketedRoute(options) {
|
|
|
2799
2836
|
setRoomState((prev) => {
|
|
2800
2837
|
const next = mergeRoomState(
|
|
2801
2838
|
prev,
|
|
2802
|
-
toRoomsRef.current(data,
|
|
2839
|
+
toRoomsRef.current(data, endpointArgs)
|
|
2803
2840
|
);
|
|
2804
2841
|
return roomStateEqual(prev, next) ? prev : next;
|
|
2805
2842
|
});
|
|
2806
2843
|
});
|
|
2807
2844
|
return unsubscribe;
|
|
2808
|
-
}, [endpointResult.onReceive]);
|
|
2845
|
+
}, [endpointResult.onReceive, argsKey]);
|
|
2809
2846
|
useEffect3(() => {
|
|
2810
2847
|
trackHookTrigger2({
|
|
2811
2848
|
ref: deriveRoomsEffectDebugRef,
|
|
@@ -2817,7 +2854,7 @@ function buildSocketedRoute(options) {
|
|
|
2817
2854
|
toRoomsRef: describeObjectReference(toRooms)
|
|
2818
2855
|
}
|
|
2819
2856
|
});
|
|
2820
|
-
const next = roomsFromData(endpointDataRef.current,
|
|
2857
|
+
const next = roomsFromData(endpointDataRef.current, endpointArgs, toRooms);
|
|
2821
2858
|
setRoomState((prev) => roomStateEqual(prev, next) ? prev : next);
|
|
2822
2859
|
}, [argsKey, toRooms, debug]);
|
|
2823
2860
|
useEffect3(() => {
|
|
@@ -2936,7 +2973,7 @@ function buildSocketedRoute(options) {
|
|
|
2936
2973
|
const next = nextUpdate.fn({
|
|
2937
2974
|
prev,
|
|
2938
2975
|
payload: nextUpdate.payload,
|
|
2939
|
-
args:
|
|
2976
|
+
args: endpointArgs,
|
|
2940
2977
|
meta: nextUpdate.meta ?? {}
|
|
2941
2978
|
});
|
|
2942
2979
|
if (next === null) return prev;
|
|
@@ -2948,7 +2985,7 @@ function buildSocketedRoute(options) {
|
|
|
2948
2985
|
}
|
|
2949
2986
|
const nextRoomState = roomsFromData(
|
|
2950
2987
|
next,
|
|
2951
|
-
|
|
2988
|
+
endpointArgs,
|
|
2952
2989
|
toRooms
|
|
2953
2990
|
);
|
|
2954
2991
|
setRoomState(
|
|
@@ -2956,7 +2993,7 @@ function buildSocketedRoute(options) {
|
|
|
2956
2993
|
);
|
|
2957
2994
|
return next;
|
|
2958
2995
|
},
|
|
2959
|
-
...
|
|
2996
|
+
...endpointArgsTuple
|
|
2960
2997
|
);
|
|
2961
2998
|
}
|
|
2962
2999
|
} finally {
|