@emeryld/rrroutes-client 2.3.11 → 2.4.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 -2
- package/dist/index.cjs +29 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +29 -21
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.types.d.ts +16 -6
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -69,23 +69,16 @@ function toSearchString(query) {
|
|
|
69
69
|
if (!query) return "";
|
|
70
70
|
const params = new URLSearchParams();
|
|
71
71
|
for (const [k, v] of Object.entries(query)) {
|
|
72
|
-
if (v
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
if (x == null) return;
|
|
76
|
-
if (typeof x === "object") {
|
|
77
|
-
params.append(k, JSON.stringify(x));
|
|
78
|
-
} else {
|
|
79
|
-
params.append(k, String(x));
|
|
80
|
-
}
|
|
81
|
-
});
|
|
72
|
+
if (v === void 0 || v === null) continue;
|
|
73
|
+
if (typeof v === "string") {
|
|
74
|
+
params.append(k, v);
|
|
82
75
|
continue;
|
|
83
76
|
}
|
|
84
|
-
if (typeof v === "
|
|
85
|
-
params.
|
|
77
|
+
if (typeof v === "number" || typeof v === "boolean") {
|
|
78
|
+
params.append(k, String(v));
|
|
86
79
|
continue;
|
|
87
80
|
}
|
|
88
|
-
params.
|
|
81
|
+
params.append(k, JSON.stringify(v));
|
|
89
82
|
}
|
|
90
83
|
const s = params.toString();
|
|
91
84
|
return s ? `?${s}` : "";
|
|
@@ -190,8 +183,6 @@ function createRouteClient(opts) {
|
|
|
190
183
|
const queryClient = opts.queryClient;
|
|
191
184
|
const fetcher = opts.fetcher ?? defaultFetcher;
|
|
192
185
|
const baseUrl = opts.baseUrl;
|
|
193
|
-
const cursorParam = opts.cursorParam ?? "pagination_cursor";
|
|
194
|
-
const getNextCursor = opts.getNextCursor ?? defaultGetNextCursor;
|
|
195
186
|
const environment = opts.environment ?? void 0;
|
|
196
187
|
const { emit: emitDebug, mode: debugMode } = createDebugEmitter(
|
|
197
188
|
opts.debug,
|
|
@@ -218,11 +209,28 @@ function createRouteClient(opts) {
|
|
|
218
209
|
const debugName = meta?.name;
|
|
219
210
|
const emit = (event) => emitDebug(event, debugName);
|
|
220
211
|
emit({ type: "build", leaf: leafLabel });
|
|
212
|
+
let feedCursorParam = "pagination_cursor";
|
|
213
|
+
let feedNextPageParam;
|
|
214
|
+
let feedInitialPageParam;
|
|
215
|
+
let feedQueryOptions;
|
|
216
|
+
if (isGet && isFeed) {
|
|
217
|
+
const infiniteOptions = rqOpts ?? {};
|
|
218
|
+
const {
|
|
219
|
+
cursorParam,
|
|
220
|
+
getNextPageParam,
|
|
221
|
+
initialPageParam,
|
|
222
|
+
...passthroughOptions
|
|
223
|
+
} = infiniteOptions;
|
|
224
|
+
feedCursorParam = cursorParam ?? "pagination_cursor";
|
|
225
|
+
feedNextPageParam = getNextPageParam ?? ((lastPage) => defaultGetNextCursor(lastPage));
|
|
226
|
+
feedInitialPageParam = typeof initialPageParam === "undefined" ? void 0 : initialPageParam;
|
|
227
|
+
feedQueryOptions = passthroughOptions;
|
|
228
|
+
}
|
|
221
229
|
const getQueryKeys = (...tuple) => {
|
|
222
230
|
const a = extractArgs(tuple);
|
|
223
231
|
const params = a?.params;
|
|
224
232
|
const query = a?.query;
|
|
225
|
-
const qForKey = isGet && isFeed ? stripKey(query,
|
|
233
|
+
const qForKey = isGet && isFeed ? stripKey(query, feedCursorParam) : query;
|
|
226
234
|
return buildCacheKey({
|
|
227
235
|
leaf,
|
|
228
236
|
params,
|
|
@@ -388,7 +396,7 @@ function createRouteClient(opts) {
|
|
|
388
396
|
});
|
|
389
397
|
const params = args?.params;
|
|
390
398
|
const query = args?.query;
|
|
391
|
-
const buildOptions =
|
|
399
|
+
const buildOptions = feedQueryOptions ?? {};
|
|
392
400
|
const listenersRef = useRef(/* @__PURE__ */ new Set());
|
|
393
401
|
const notifyOnReceive = useCallback((data) => {
|
|
394
402
|
buildOptions?.onReceive?.(data);
|
|
@@ -412,14 +420,14 @@ function createRouteClient(opts) {
|
|
|
412
420
|
const queryResult = useInfiniteQuery(
|
|
413
421
|
{
|
|
414
422
|
...buildOptions,
|
|
423
|
+
placeholderData: buildOptions.placeholderData ?? keepPreviousData,
|
|
424
|
+
initialPageParam: feedInitialPageParam,
|
|
425
|
+
getNextPageParam: (lastPage) => (feedNextPageParam ?? defaultGetNextCursor)(lastPage),
|
|
415
426
|
queryKey: queryKeys,
|
|
416
|
-
initialPageParam: void 0,
|
|
417
|
-
getNextPageParam: (lastPage) => getNextCursor(lastPage),
|
|
418
|
-
placeholderData: keepPreviousData,
|
|
419
427
|
queryFn: ({ pageParam }) => {
|
|
420
428
|
const pageQuery = {
|
|
421
429
|
...normalizedQuery,
|
|
422
|
-
...pageParam ? { [
|
|
430
|
+
...pageParam ? { [feedCursorParam]: pageParam } : {}
|
|
423
431
|
};
|
|
424
432
|
return fetchEndpoint(tuple, {
|
|
425
433
|
queryOverride: pageQuery,
|