@emeryld/rrroutes-client 2.7.8 → 2.7.9
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 +2 -2
- package/dist/index.cjs +31 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +31 -18
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.types.d.ts +13 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,8 +97,8 @@ const getUser = client.build(registry.byKey['GET /v1/users/:userId'], {
|
|
|
97
97
|
|
|
98
98
|
// Infinite/feed GET (cfg.feed === true)
|
|
99
99
|
const listFeed = client.build(registry.byKey['GET /v1/posts'], {
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
cursorQueryKey: 'page', // defaults to "pagination_cursor"
|
|
101
|
+
getNextPageCursor: (last) => last.nextCursor, // cursor extraction override
|
|
102
102
|
})
|
|
103
103
|
|
|
104
104
|
// Mutation
|
package/dist/index.cjs
CHANGED
|
@@ -773,16 +773,15 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
773
773
|
emit({ type: "build", leaf: leafLabel });
|
|
774
774
|
const infiniteOptions = rqOpts ?? {};
|
|
775
775
|
const {
|
|
776
|
-
|
|
777
|
-
|
|
776
|
+
cursorQueryKey,
|
|
777
|
+
getNextPageCursor,
|
|
778
778
|
initialPageParam,
|
|
779
779
|
splitPageSize,
|
|
780
780
|
splitPageSizeParam,
|
|
781
781
|
...passthroughOptions
|
|
782
782
|
} = infiniteOptions;
|
|
783
|
-
const
|
|
784
|
-
const
|
|
785
|
-
const cursorFromPage = (page) => feedNextPageParam(page);
|
|
783
|
+
const feedCursorQueryKey = cursorQueryKey ?? "pagination_cursor";
|
|
784
|
+
const feedNextPageCursor = getNextPageCursor ?? ((lastPage) => defaultGetNextCursor(lastPage));
|
|
786
785
|
const feedInitialPageParam = typeof initialPageParam === "undefined" ? void 0 : initialPageParam;
|
|
787
786
|
const feedQueryOptions = passthroughOptions;
|
|
788
787
|
const effectiveSplitPageSize = typeof splitPageSize === "number" && splitPageSize > 0 ? splitPageSize : void 0;
|
|
@@ -791,7 +790,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
791
790
|
const a = extractArgs(tuple);
|
|
792
791
|
const params = a?.params;
|
|
793
792
|
const query = a?.query;
|
|
794
|
-
const qForKey = stripKey(query,
|
|
793
|
+
const qForKey = stripKey(query, feedCursorQueryKey);
|
|
795
794
|
return (0, import_rrroutes_contract4.buildCacheKey)({
|
|
796
795
|
leaf,
|
|
797
796
|
params,
|
|
@@ -954,18 +953,32 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
954
953
|
const useEndpointOptions = expectsArgs ? useArgs[1] : useArgs[0];
|
|
955
954
|
const hasCompleteArgs = !expectsArgs || areEndpointArgsComplete(leaf, args);
|
|
956
955
|
const tuple = toArgsTuple(args);
|
|
957
|
-
const
|
|
956
|
+
const params = args?.params;
|
|
957
|
+
const query = args?.query;
|
|
958
|
+
const buildOptions = feedQueryOptions ?? {};
|
|
959
|
+
const { onReceive: buildOnReceive2, ...buildInfiniteQueryOptions } = buildOptions;
|
|
960
|
+
const {
|
|
961
|
+
onReceive: useOnReceive,
|
|
962
|
+
cursorQueryKey: useCursorQueryKey,
|
|
963
|
+
getNextPageCursor: useGetNextPageCursor,
|
|
964
|
+
initialPageParam: useInitialPageParam,
|
|
965
|
+
...runtimeInfiniteQueryOptions
|
|
966
|
+
} = useEndpointOptions ?? {};
|
|
967
|
+
const effectiveCursorParam = useCursorQueryKey ?? feedCursorQueryKey;
|
|
968
|
+
const effectiveNextPageCursor = useGetNextPageCursor ?? feedNextPageCursor;
|
|
969
|
+
const effectiveInitialPageParam = typeof useInitialPageParam === "undefined" ? feedInitialPageParam : useInitialPageParam;
|
|
970
|
+
const qForKey = stripKey(query, effectiveCursorParam);
|
|
971
|
+
const queryKeys = (0, import_rrroutes_contract4.buildCacheKey)({
|
|
972
|
+
leaf,
|
|
973
|
+
params,
|
|
974
|
+
query: qForKey
|
|
975
|
+
});
|
|
958
976
|
emit({
|
|
959
977
|
type: "useEndpoint",
|
|
960
978
|
leaf: leafLabel,
|
|
961
979
|
variant: "infiniteGet",
|
|
962
980
|
keys: queryKeys
|
|
963
981
|
});
|
|
964
|
-
const params = args?.params;
|
|
965
|
-
const query = args?.query;
|
|
966
|
-
const buildOptions = feedQueryOptions ?? {};
|
|
967
|
-
const { onReceive: buildOnReceive2, ...buildInfiniteQueryOptions } = buildOptions;
|
|
968
|
-
const { onReceive: useOnReceive, ...runtimeInfiniteQueryOptions } = useEndpointOptions ?? {};
|
|
969
982
|
const mergedInfiniteQueryOptions = {
|
|
970
983
|
...buildInfiniteQueryOptions,
|
|
971
984
|
...runtimeInfiniteQueryOptions
|
|
@@ -999,8 +1012,8 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
999
1012
|
...mergedInfiniteQueryOptions,
|
|
1000
1013
|
enabled: guardedEnabled,
|
|
1001
1014
|
placeholderData: mergedInfiniteQueryOptions.placeholderData ?? import_react_query3.keepPreviousData,
|
|
1002
|
-
initialPageParam:
|
|
1003
|
-
getNextPageParam: (lastPage) =>
|
|
1015
|
+
initialPageParam: effectiveInitialPageParam,
|
|
1016
|
+
getNextPageParam: (lastPage) => effectiveNextPageCursor(lastPage),
|
|
1004
1017
|
queryKey: queryKeys,
|
|
1005
1018
|
queryFn: ({ pageParam }) => {
|
|
1006
1019
|
if (!hasCompleteArgs) {
|
|
@@ -1009,7 +1022,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
1009
1022
|
if (!effectiveSplitPageSize) {
|
|
1010
1023
|
const pageQuery = {
|
|
1011
1024
|
...normalizedQuery,
|
|
1012
|
-
...pageParam ? { [
|
|
1025
|
+
...pageParam ? { [effectiveCursorParam]: pageParam } : {}
|
|
1013
1026
|
};
|
|
1014
1027
|
return fetchEndpoint(tuple, {
|
|
1015
1028
|
queryOverride: pageQuery,
|
|
@@ -1021,7 +1034,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
1021
1034
|
if (!basePageSize || !Number.isFinite(basePageSize) || basePageSize <= effectiveSplitPageSize) {
|
|
1022
1035
|
const pageQuery = {
|
|
1023
1036
|
...normalizedQuery,
|
|
1024
|
-
...pageParam ? { [
|
|
1037
|
+
...pageParam ? { [effectiveCursorParam]: pageParam } : {}
|
|
1025
1038
|
};
|
|
1026
1039
|
return fetchEndpoint(tuple, {
|
|
1027
1040
|
queryOverride: pageQuery,
|
|
@@ -1038,7 +1051,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
1038
1051
|
const thisCallSize = Math.min(remaining, effectiveSplitPageSize);
|
|
1039
1052
|
const splitQuery = {
|
|
1040
1053
|
...normalizedQuery,
|
|
1041
|
-
...currentCursor ? { [
|
|
1054
|
+
...currentCursor ? { [effectiveCursorParam]: currentCursor } : {},
|
|
1042
1055
|
[effectiveSplitPageSizeParam]: thisCallSize
|
|
1043
1056
|
};
|
|
1044
1057
|
const page = await fetchEndpoint(tuple, {
|
|
@@ -1047,7 +1060,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
|
|
|
1047
1060
|
});
|
|
1048
1061
|
aggregated = aggregated ? mergePageOutputs(aggregated, page) : page;
|
|
1049
1062
|
remaining -= thisCallSize;
|
|
1050
|
-
const nextCursor =
|
|
1063
|
+
const nextCursor = effectiveNextPageCursor(page);
|
|
1051
1064
|
currentCursor = nextCursor;
|
|
1052
1065
|
const k = queryKeys;
|
|
1053
1066
|
queryClient.setQueryData(k, (prev) => {
|