@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/README.md +1 -2
- package/dist/index.cjs +23 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +23 -9
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.types.d.ts +18 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -76,8 +76,6 @@ const client = createRouteClient({
|
|
|
76
76
|
headers: { ...req.headers, Authorization: `Bearer ${getToken()}` },
|
|
77
77
|
})
|
|
78
78
|
},
|
|
79
|
-
cursorParam: 'cursor', // optional; default is "cursor"
|
|
80
|
-
getNextCursor: (page) => page?.links?.next ?? page?.nextCursor, // optional override
|
|
81
79
|
environment: process.env.NODE_ENV, // disables debug when "production"
|
|
82
80
|
debug: {
|
|
83
81
|
fetch: true,
|
|
@@ -99,6 +97,7 @@ const getUser = client.build(registry.byKey['GET /v1/users/:userId'], {
|
|
|
99
97
|
|
|
100
98
|
// Infinite/feed GET (cfg.feed === true)
|
|
101
99
|
const listFeed = client.build(registry.byKey['GET /v1/posts'], {
|
|
100
|
+
cursorParam: 'page', // defaults to "pagination_cursor"
|
|
102
101
|
getNextPageParam: (last) => last.nextCursor, // React Query option override
|
|
103
102
|
})
|
|
104
103
|
|
package/dist/index.cjs
CHANGED
|
@@ -225,8 +225,6 @@ function createRouteClient(opts) {
|
|
|
225
225
|
const queryClient = opts.queryClient;
|
|
226
226
|
const fetcher = opts.fetcher ?? defaultFetcher;
|
|
227
227
|
const baseUrl = opts.baseUrl;
|
|
228
|
-
const cursorParam = opts.cursorParam ?? "pagination_cursor";
|
|
229
|
-
const getNextCursor = opts.getNextCursor ?? defaultGetNextCursor;
|
|
230
228
|
const environment = opts.environment ?? void 0;
|
|
231
229
|
const { emit: emitDebug, mode: debugMode } = createDebugEmitter(
|
|
232
230
|
opts.debug,
|
|
@@ -253,11 +251,28 @@ function createRouteClient(opts) {
|
|
|
253
251
|
const debugName = meta?.name;
|
|
254
252
|
const emit = (event) => emitDebug(event, debugName);
|
|
255
253
|
emit({ type: "build", leaf: leafLabel });
|
|
254
|
+
let feedCursorParam = "pagination_cursor";
|
|
255
|
+
let feedNextPageParam;
|
|
256
|
+
let feedInitialPageParam;
|
|
257
|
+
let feedQueryOptions;
|
|
258
|
+
if (isGet && isFeed) {
|
|
259
|
+
const infiniteOptions = rqOpts ?? {};
|
|
260
|
+
const {
|
|
261
|
+
cursorParam,
|
|
262
|
+
getNextPageParam,
|
|
263
|
+
initialPageParam,
|
|
264
|
+
...passthroughOptions
|
|
265
|
+
} = infiniteOptions;
|
|
266
|
+
feedCursorParam = cursorParam ?? "pagination_cursor";
|
|
267
|
+
feedNextPageParam = getNextPageParam ?? ((lastPage) => defaultGetNextCursor(lastPage));
|
|
268
|
+
feedInitialPageParam = typeof initialPageParam === "undefined" ? void 0 : initialPageParam;
|
|
269
|
+
feedQueryOptions = passthroughOptions;
|
|
270
|
+
}
|
|
256
271
|
const getQueryKeys = (...tuple) => {
|
|
257
272
|
const a = extractArgs(tuple);
|
|
258
273
|
const params = a?.params;
|
|
259
274
|
const query = a?.query;
|
|
260
|
-
const qForKey = isGet && isFeed ? stripKey(query,
|
|
275
|
+
const qForKey = isGet && isFeed ? stripKey(query, feedCursorParam) : query;
|
|
261
276
|
return (0, import_rrroutes_contract.buildCacheKey)({
|
|
262
277
|
leaf,
|
|
263
278
|
params,
|
|
@@ -423,7 +438,7 @@ function createRouteClient(opts) {
|
|
|
423
438
|
});
|
|
424
439
|
const params = args?.params;
|
|
425
440
|
const query = args?.query;
|
|
426
|
-
const buildOptions =
|
|
441
|
+
const buildOptions = feedQueryOptions ?? {};
|
|
427
442
|
const listenersRef = (0, import_react.useRef)(/* @__PURE__ */ new Set());
|
|
428
443
|
const notifyOnReceive = (0, import_react.useCallback)((data) => {
|
|
429
444
|
buildOptions?.onReceive?.(data);
|
|
@@ -447,14 +462,14 @@ function createRouteClient(opts) {
|
|
|
447
462
|
const queryResult = (0, import_react_query.useInfiniteQuery)(
|
|
448
463
|
{
|
|
449
464
|
...buildOptions,
|
|
465
|
+
placeholderData: buildOptions.placeholderData ?? import_react_query.keepPreviousData,
|
|
466
|
+
initialPageParam: feedInitialPageParam,
|
|
467
|
+
getNextPageParam: (lastPage) => (feedNextPageParam ?? defaultGetNextCursor)(lastPage),
|
|
450
468
|
queryKey: queryKeys,
|
|
451
|
-
initialPageParam: void 0,
|
|
452
|
-
getNextPageParam: (lastPage) => getNextCursor(lastPage),
|
|
453
|
-
placeholderData: import_react_query.keepPreviousData,
|
|
454
469
|
queryFn: ({ pageParam }) => {
|
|
455
470
|
const pageQuery = {
|
|
456
471
|
...normalizedQuery,
|
|
457
|
-
...pageParam ? { [
|
|
472
|
+
...pageParam ? { [feedCursorParam]: pageParam } : {}
|
|
458
473
|
};
|
|
459
474
|
return fetchEndpoint(tuple, {
|
|
460
475
|
queryOverride: pageQuery,
|
|
@@ -503,7 +518,6 @@ function createRouteClient(opts) {
|
|
|
503
518
|
},
|
|
504
519
|
[]
|
|
505
520
|
);
|
|
506
|
-
buildUrl({ ...leaf, cfg: leafCfg }, baseUrl, params, query);
|
|
507
521
|
const queryResult = (0, import_react_query.useQuery)(
|
|
508
522
|
{
|
|
509
523
|
...buildOptions,
|