@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/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
|
@@ -104,23 +104,16 @@ function toSearchString(query) {
|
|
|
104
104
|
if (!query) return "";
|
|
105
105
|
const params = new URLSearchParams();
|
|
106
106
|
for (const [k, v] of Object.entries(query)) {
|
|
107
|
-
if (v
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
if (x == null) return;
|
|
111
|
-
if (typeof x === "object") {
|
|
112
|
-
params.append(k, JSON.stringify(x));
|
|
113
|
-
} else {
|
|
114
|
-
params.append(k, String(x));
|
|
115
|
-
}
|
|
116
|
-
});
|
|
107
|
+
if (v === void 0 || v === null) continue;
|
|
108
|
+
if (typeof v === "string") {
|
|
109
|
+
params.append(k, v);
|
|
117
110
|
continue;
|
|
118
111
|
}
|
|
119
|
-
if (typeof v === "
|
|
120
|
-
params.
|
|
112
|
+
if (typeof v === "number" || typeof v === "boolean") {
|
|
113
|
+
params.append(k, String(v));
|
|
121
114
|
continue;
|
|
122
115
|
}
|
|
123
|
-
params.
|
|
116
|
+
params.append(k, JSON.stringify(v));
|
|
124
117
|
}
|
|
125
118
|
const s = params.toString();
|
|
126
119
|
return s ? `?${s}` : "";
|
|
@@ -225,8 +218,6 @@ function createRouteClient(opts) {
|
|
|
225
218
|
const queryClient = opts.queryClient;
|
|
226
219
|
const fetcher = opts.fetcher ?? defaultFetcher;
|
|
227
220
|
const baseUrl = opts.baseUrl;
|
|
228
|
-
const cursorParam = opts.cursorParam ?? "pagination_cursor";
|
|
229
|
-
const getNextCursor = opts.getNextCursor ?? defaultGetNextCursor;
|
|
230
221
|
const environment = opts.environment ?? void 0;
|
|
231
222
|
const { emit: emitDebug, mode: debugMode } = createDebugEmitter(
|
|
232
223
|
opts.debug,
|
|
@@ -253,11 +244,28 @@ function createRouteClient(opts) {
|
|
|
253
244
|
const debugName = meta?.name;
|
|
254
245
|
const emit = (event) => emitDebug(event, debugName);
|
|
255
246
|
emit({ type: "build", leaf: leafLabel });
|
|
247
|
+
let feedCursorParam = "pagination_cursor";
|
|
248
|
+
let feedNextPageParam;
|
|
249
|
+
let feedInitialPageParam;
|
|
250
|
+
let feedQueryOptions;
|
|
251
|
+
if (isGet && isFeed) {
|
|
252
|
+
const infiniteOptions = rqOpts ?? {};
|
|
253
|
+
const {
|
|
254
|
+
cursorParam,
|
|
255
|
+
getNextPageParam,
|
|
256
|
+
initialPageParam,
|
|
257
|
+
...passthroughOptions
|
|
258
|
+
} = infiniteOptions;
|
|
259
|
+
feedCursorParam = cursorParam ?? "pagination_cursor";
|
|
260
|
+
feedNextPageParam = getNextPageParam ?? ((lastPage) => defaultGetNextCursor(lastPage));
|
|
261
|
+
feedInitialPageParam = typeof initialPageParam === "undefined" ? void 0 : initialPageParam;
|
|
262
|
+
feedQueryOptions = passthroughOptions;
|
|
263
|
+
}
|
|
256
264
|
const getQueryKeys = (...tuple) => {
|
|
257
265
|
const a = extractArgs(tuple);
|
|
258
266
|
const params = a?.params;
|
|
259
267
|
const query = a?.query;
|
|
260
|
-
const qForKey = isGet && isFeed ? stripKey(query,
|
|
268
|
+
const qForKey = isGet && isFeed ? stripKey(query, feedCursorParam) : query;
|
|
261
269
|
return (0, import_rrroutes_contract.buildCacheKey)({
|
|
262
270
|
leaf,
|
|
263
271
|
params,
|
|
@@ -423,7 +431,7 @@ function createRouteClient(opts) {
|
|
|
423
431
|
});
|
|
424
432
|
const params = args?.params;
|
|
425
433
|
const query = args?.query;
|
|
426
|
-
const buildOptions =
|
|
434
|
+
const buildOptions = feedQueryOptions ?? {};
|
|
427
435
|
const listenersRef = (0, import_react.useRef)(/* @__PURE__ */ new Set());
|
|
428
436
|
const notifyOnReceive = (0, import_react.useCallback)((data) => {
|
|
429
437
|
buildOptions?.onReceive?.(data);
|
|
@@ -447,14 +455,14 @@ function createRouteClient(opts) {
|
|
|
447
455
|
const queryResult = (0, import_react_query.useInfiniteQuery)(
|
|
448
456
|
{
|
|
449
457
|
...buildOptions,
|
|
458
|
+
placeholderData: buildOptions.placeholderData ?? import_react_query.keepPreviousData,
|
|
459
|
+
initialPageParam: feedInitialPageParam,
|
|
460
|
+
getNextPageParam: (lastPage) => (feedNextPageParam ?? defaultGetNextCursor)(lastPage),
|
|
450
461
|
queryKey: queryKeys,
|
|
451
|
-
initialPageParam: void 0,
|
|
452
|
-
getNextPageParam: (lastPage) => getNextCursor(lastPage),
|
|
453
|
-
placeholderData: import_react_query.keepPreviousData,
|
|
454
462
|
queryFn: ({ pageParam }) => {
|
|
455
463
|
const pageQuery = {
|
|
456
464
|
...normalizedQuery,
|
|
457
|
-
...pageParam ? { [
|
|
465
|
+
...pageParam ? { [feedCursorParam]: pageParam } : {}
|
|
458
466
|
};
|
|
459
467
|
return fetchEndpoint(tuple, {
|
|
460
468
|
queryOverride: pageQuery,
|