@emeryld/rrroutes-client 2.3.10 → 2.3.12

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/dist/index.mjs CHANGED
@@ -190,8 +190,6 @@ function createRouteClient(opts) {
190
190
  const queryClient = opts.queryClient;
191
191
  const fetcher = opts.fetcher ?? defaultFetcher;
192
192
  const baseUrl = opts.baseUrl;
193
- const cursorParam = opts.cursorParam ?? "pagination_cursor";
194
- const getNextCursor = opts.getNextCursor ?? defaultGetNextCursor;
195
193
  const environment = opts.environment ?? void 0;
196
194
  const { emit: emitDebug, mode: debugMode } = createDebugEmitter(
197
195
  opts.debug,
@@ -218,11 +216,28 @@ function createRouteClient(opts) {
218
216
  const debugName = meta?.name;
219
217
  const emit = (event) => emitDebug(event, debugName);
220
218
  emit({ type: "build", leaf: leafLabel });
219
+ let feedCursorParam = "pagination_cursor";
220
+ let feedNextPageParam;
221
+ let feedInitialPageParam;
222
+ let feedQueryOptions;
223
+ if (isGet && isFeed) {
224
+ const infiniteOptions = rqOpts ?? {};
225
+ const {
226
+ cursorParam,
227
+ getNextPageParam,
228
+ initialPageParam,
229
+ ...passthroughOptions
230
+ } = infiniteOptions;
231
+ feedCursorParam = cursorParam ?? "pagination_cursor";
232
+ feedNextPageParam = getNextPageParam ?? ((lastPage) => defaultGetNextCursor(lastPage));
233
+ feedInitialPageParam = typeof initialPageParam === "undefined" ? void 0 : initialPageParam;
234
+ feedQueryOptions = passthroughOptions;
235
+ }
221
236
  const getQueryKeys = (...tuple) => {
222
237
  const a = extractArgs(tuple);
223
238
  const params = a?.params;
224
239
  const query = a?.query;
225
- const qForKey = isGet && isFeed ? stripKey(query, cursorParam) : query;
240
+ const qForKey = isGet && isFeed ? stripKey(query, feedCursorParam) : query;
226
241
  return buildCacheKey({
227
242
  leaf,
228
243
  params,
@@ -388,7 +403,7 @@ function createRouteClient(opts) {
388
403
  });
389
404
  const params = args?.params;
390
405
  const query = args?.query;
391
- const buildOptions = rqOpts ?? {};
406
+ const buildOptions = feedQueryOptions ?? {};
392
407
  const listenersRef = useRef(/* @__PURE__ */ new Set());
393
408
  const notifyOnReceive = useCallback((data) => {
394
409
  buildOptions?.onReceive?.(data);
@@ -412,14 +427,14 @@ function createRouteClient(opts) {
412
427
  const queryResult = useInfiniteQuery(
413
428
  {
414
429
  ...buildOptions,
430
+ placeholderData: buildOptions.placeholderData ?? keepPreviousData,
431
+ initialPageParam: feedInitialPageParam,
432
+ getNextPageParam: (lastPage) => (feedNextPageParam ?? defaultGetNextCursor)(lastPage),
415
433
  queryKey: queryKeys,
416
- initialPageParam: void 0,
417
- getNextPageParam: (lastPage) => getNextCursor(lastPage),
418
- placeholderData: keepPreviousData,
419
434
  queryFn: ({ pageParam }) => {
420
435
  const pageQuery = {
421
436
  ...normalizedQuery,
422
- ...pageParam ? { [cursorParam]: pageParam } : {}
437
+ ...pageParam ? { [feedCursorParam]: pageParam } : {}
423
438
  };
424
439
  return fetchEndpoint(tuple, {
425
440
  queryOverride: pageQuery,
@@ -468,7 +483,6 @@ function createRouteClient(opts) {
468
483
  },
469
484
  []
470
485
  );
471
- buildUrl({ ...leaf, cfg: leafCfg }, baseUrl, params, query);
472
486
  const queryResult = useQuery(
473
487
  {
474
488
  ...buildOptions,