@robohall/react-query-factory 2.1.4 → 2.1.6
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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -18
- package/dist/index.mjs +14 -18
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -133,7 +133,7 @@ declare function queryFactory<TParams = void, TData = unknown, TError = Error, T
|
|
|
133
133
|
* paginator). Inherits the parent's key namespace. Use this overload when switching
|
|
134
134
|
* to a paginator-based fetch while keeping the same result shape and crawl options.
|
|
135
135
|
*/
|
|
136
|
-
declare function queryFactory<TChildParams extends TParentParams, TData = unknown, TError = Error, TParentSelected = TData, TChildSelected = TParentSelected, TParentParams = TChildParams, TPageParam = unknown, TCrawlOptions extends Record<string, unknown> = Record<string, unknown>>(parent: QueryFactory<TParentParams,
|
|
136
|
+
declare function queryFactory<TChildParams extends TParentParams, TData = unknown, TError = Error, TParentSelected = TData, TChildSelected = TParentSelected, TParentParams = TChildParams, TPageParam = unknown, TCrawlOptions extends Record<string, unknown> = Record<string, unknown>>(parent: QueryFactory<TParentParams, TData, any, TParentSelected, TPageParam, any, any>, config: StandardQueryOptions<TError, TData> & {
|
|
137
137
|
queryKey?: QueryKey;
|
|
138
138
|
queryFn: (params: TChildParams, context: QueryFunctionContext<QueryKey, [
|
|
139
139
|
unknown
|
package/dist/index.d.ts
CHANGED
|
@@ -133,7 +133,7 @@ declare function queryFactory<TParams = void, TData = unknown, TError = Error, T
|
|
|
133
133
|
* paginator). Inherits the parent's key namespace. Use this overload when switching
|
|
134
134
|
* to a paginator-based fetch while keeping the same result shape and crawl options.
|
|
135
135
|
*/
|
|
136
|
-
declare function queryFactory<TChildParams extends TParentParams, TData = unknown, TError = Error, TParentSelected = TData, TChildSelected = TParentSelected, TParentParams = TChildParams, TPageParam = unknown, TCrawlOptions extends Record<string, unknown> = Record<string, unknown>>(parent: QueryFactory<TParentParams,
|
|
136
|
+
declare function queryFactory<TChildParams extends TParentParams, TData = unknown, TError = Error, TParentSelected = TData, TChildSelected = TParentSelected, TParentParams = TChildParams, TPageParam = unknown, TCrawlOptions extends Record<string, unknown> = Record<string, unknown>>(parent: QueryFactory<TParentParams, TData, any, TParentSelected, TPageParam, any, any>, config: StandardQueryOptions<TError, TData> & {
|
|
137
137
|
queryKey?: QueryKey;
|
|
138
138
|
queryFn: (params: TChildParams, context: QueryFunctionContext<QueryKey, [
|
|
139
139
|
unknown
|
package/dist/index.js
CHANGED
|
@@ -64,7 +64,7 @@ function wrapGetNextPageParam(getNextPageParam, shouldFetchNextPage, crawlOption
|
|
|
64
64
|
}
|
|
65
65
|
function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shouldFetchNextPage, reduce) {
|
|
66
66
|
return async (params, crawlOptions, context) => {
|
|
67
|
-
var _a, _b, _c
|
|
67
|
+
var _a, _b, _c;
|
|
68
68
|
if ((_a = context.signal) == null ? void 0 : _a.aborted) {
|
|
69
69
|
if (reduce) throw new DOMException("Aborted", "AbortError");
|
|
70
70
|
return [];
|
|
@@ -74,10 +74,10 @@ function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shoul
|
|
|
74
74
|
if (isAsyncIterable(initialResult)) {
|
|
75
75
|
const pages2 = [];
|
|
76
76
|
let acc2 = void 0;
|
|
77
|
-
for await (const
|
|
77
|
+
for await (const page2 of initialResult) {
|
|
78
78
|
if ((_b = context.signal) == null ? void 0 : _b.aborted) break;
|
|
79
|
-
pages2.push(
|
|
80
|
-
if (reduce) acc2 = reduce(acc2,
|
|
79
|
+
pages2.push(page2);
|
|
80
|
+
if (reduce) acc2 = reduce(acc2, page2);
|
|
81
81
|
if (!shouldFetchNextPage(acc2, crawlOptions)) break;
|
|
82
82
|
}
|
|
83
83
|
if (reduce) {
|
|
@@ -90,9 +90,8 @@ function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shoul
|
|
|
90
90
|
const pageParams = [];
|
|
91
91
|
let currentParam = initialPageParam;
|
|
92
92
|
let acc = void 0;
|
|
93
|
-
let
|
|
93
|
+
let page = await initialResult;
|
|
94
94
|
while (true) {
|
|
95
|
-
const page = await nextResult;
|
|
96
95
|
pages.push(page);
|
|
97
96
|
pageParams.push(currentParam);
|
|
98
97
|
if (reduce) acc = reduce(acc, page);
|
|
@@ -102,9 +101,8 @@ function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shoul
|
|
|
102
101
|
const nextParam = getNextPageParam(page, pages, currentParam, pageParams);
|
|
103
102
|
if (nextParam == null) break;
|
|
104
103
|
currentParam = nextParam;
|
|
105
|
-
if ((_d = context.signal) == null ? void 0 : _d.aborted) break;
|
|
106
104
|
ctx.pageParam = currentParam;
|
|
107
|
-
|
|
105
|
+
page = await queryFn(params, ctx);
|
|
108
106
|
}
|
|
109
107
|
if (reduce) {
|
|
110
108
|
if (acc === void 0) throw new DOMException("Aborted", "AbortError");
|
|
@@ -115,7 +113,7 @@ function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shoul
|
|
|
115
113
|
}
|
|
116
114
|
function buildInfiniteCrawlingQueryFn(queryFn, getNextPageParam, shouldFetchNextPage, reduce) {
|
|
117
115
|
return async (params, crawlOptions, context) => {
|
|
118
|
-
var _a, _b, _c
|
|
116
|
+
var _a, _b, _c;
|
|
119
117
|
if ((_a = context.signal) == null ? void 0 : _a.aborted)
|
|
120
118
|
throw new DOMException("Aborted", "AbortError");
|
|
121
119
|
const ctx = { ...context, pageParam: context.pageParam };
|
|
@@ -125,11 +123,11 @@ function buildInfiniteCrawlingQueryFn(queryFn, getNextPageParam, shouldFetchNext
|
|
|
125
123
|
const startParam = context.pageParam;
|
|
126
124
|
let acc2 = void 0;
|
|
127
125
|
let nextBatchParam2 = null;
|
|
128
|
-
for await (const
|
|
126
|
+
for await (const page2 of initialResult) {
|
|
129
127
|
if ((_b = context.signal) == null ? void 0 : _b.aborted) break;
|
|
130
|
-
pages2.push(
|
|
131
|
-
acc2 = reduce(acc2,
|
|
132
|
-
const nextParam = getNextPageParam(
|
|
128
|
+
pages2.push(page2);
|
|
129
|
+
acc2 = reduce(acc2, page2);
|
|
130
|
+
const nextParam = getNextPageParam(page2, pages2, startParam, [
|
|
133
131
|
startParam
|
|
134
132
|
]);
|
|
135
133
|
nextBatchParam2 = nextParam != null ? nextParam : null;
|
|
@@ -144,9 +142,8 @@ function buildInfiniteCrawlingQueryFn(queryFn, getNextPageParam, shouldFetchNext
|
|
|
144
142
|
let currentParam = context.pageParam;
|
|
145
143
|
let acc = void 0;
|
|
146
144
|
let nextBatchParam = null;
|
|
147
|
-
let
|
|
145
|
+
let page = await initialResult;
|
|
148
146
|
while (true) {
|
|
149
|
-
const page = await nextResult;
|
|
150
147
|
pages.push(page);
|
|
151
148
|
pageParams.push(currentParam);
|
|
152
149
|
acc = reduce(acc, page);
|
|
@@ -156,9 +153,8 @@ function buildInfiniteCrawlingQueryFn(queryFn, getNextPageParam, shouldFetchNext
|
|
|
156
153
|
if (nextParam == null) break;
|
|
157
154
|
if (!shouldFetchNextPage(acc, crawlOptions)) break;
|
|
158
155
|
currentParam = nextParam;
|
|
159
|
-
if ((_d = context.signal) == null ? void 0 : _d.aborted) break;
|
|
160
156
|
ctx.pageParam = currentParam;
|
|
161
|
-
|
|
157
|
+
page = await queryFn(params, ctx);
|
|
162
158
|
}
|
|
163
159
|
if (acc === void 0) throw new DOMException("Aborted", "AbortError");
|
|
164
160
|
return { data: acc, nextPageParam: nextBatchParam };
|
|
@@ -276,7 +272,7 @@ function queryFactory(configOrParent, childConfig) {
|
|
|
276
272
|
const crawling = hasNewQueryFn ? {
|
|
277
273
|
getNextPageParam: childConfig.getNextPageParam,
|
|
278
274
|
getPreviousPageParam: childConfig.getPreviousPageParam,
|
|
279
|
-
initialPageParam: childConfig.initialPageParam,
|
|
275
|
+
initialPageParam: "initialPageParam" in childConfig ? childConfig.initialPageParam : parentCfg.initialPageParam,
|
|
280
276
|
// Fall back to parent's crawling logic when child doesn't override —
|
|
281
277
|
// useful when the child only changes how pages are fetched (e.g. switching
|
|
282
278
|
// to a paginator queryFn) but accumulates the same result shape.
|
package/dist/index.mjs
CHANGED
|
@@ -38,7 +38,7 @@ function wrapGetNextPageParam(getNextPageParam, shouldFetchNextPage, crawlOption
|
|
|
38
38
|
}
|
|
39
39
|
function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shouldFetchNextPage, reduce) {
|
|
40
40
|
return async (params, crawlOptions, context) => {
|
|
41
|
-
var _a, _b, _c
|
|
41
|
+
var _a, _b, _c;
|
|
42
42
|
if ((_a = context.signal) == null ? void 0 : _a.aborted) {
|
|
43
43
|
if (reduce) throw new DOMException("Aborted", "AbortError");
|
|
44
44
|
return [];
|
|
@@ -48,10 +48,10 @@ function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shoul
|
|
|
48
48
|
if (isAsyncIterable(initialResult)) {
|
|
49
49
|
const pages2 = [];
|
|
50
50
|
let acc2 = void 0;
|
|
51
|
-
for await (const
|
|
51
|
+
for await (const page2 of initialResult) {
|
|
52
52
|
if ((_b = context.signal) == null ? void 0 : _b.aborted) break;
|
|
53
|
-
pages2.push(
|
|
54
|
-
if (reduce) acc2 = reduce(acc2,
|
|
53
|
+
pages2.push(page2);
|
|
54
|
+
if (reduce) acc2 = reduce(acc2, page2);
|
|
55
55
|
if (!shouldFetchNextPage(acc2, crawlOptions)) break;
|
|
56
56
|
}
|
|
57
57
|
if (reduce) {
|
|
@@ -64,9 +64,8 @@ function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shoul
|
|
|
64
64
|
const pageParams = [];
|
|
65
65
|
let currentParam = initialPageParam;
|
|
66
66
|
let acc = void 0;
|
|
67
|
-
let
|
|
67
|
+
let page = await initialResult;
|
|
68
68
|
while (true) {
|
|
69
|
-
const page = await nextResult;
|
|
70
69
|
pages.push(page);
|
|
71
70
|
pageParams.push(currentParam);
|
|
72
71
|
if (reduce) acc = reduce(acc, page);
|
|
@@ -76,9 +75,8 @@ function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shoul
|
|
|
76
75
|
const nextParam = getNextPageParam(page, pages, currentParam, pageParams);
|
|
77
76
|
if (nextParam == null) break;
|
|
78
77
|
currentParam = nextParam;
|
|
79
|
-
if ((_d = context.signal) == null ? void 0 : _d.aborted) break;
|
|
80
78
|
ctx.pageParam = currentParam;
|
|
81
|
-
|
|
79
|
+
page = await queryFn(params, ctx);
|
|
82
80
|
}
|
|
83
81
|
if (reduce) {
|
|
84
82
|
if (acc === void 0) throw new DOMException("Aborted", "AbortError");
|
|
@@ -89,7 +87,7 @@ function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shoul
|
|
|
89
87
|
}
|
|
90
88
|
function buildInfiniteCrawlingQueryFn(queryFn, getNextPageParam, shouldFetchNextPage, reduce) {
|
|
91
89
|
return async (params, crawlOptions, context) => {
|
|
92
|
-
var _a, _b, _c
|
|
90
|
+
var _a, _b, _c;
|
|
93
91
|
if ((_a = context.signal) == null ? void 0 : _a.aborted)
|
|
94
92
|
throw new DOMException("Aborted", "AbortError");
|
|
95
93
|
const ctx = { ...context, pageParam: context.pageParam };
|
|
@@ -99,11 +97,11 @@ function buildInfiniteCrawlingQueryFn(queryFn, getNextPageParam, shouldFetchNext
|
|
|
99
97
|
const startParam = context.pageParam;
|
|
100
98
|
let acc2 = void 0;
|
|
101
99
|
let nextBatchParam2 = null;
|
|
102
|
-
for await (const
|
|
100
|
+
for await (const page2 of initialResult) {
|
|
103
101
|
if ((_b = context.signal) == null ? void 0 : _b.aborted) break;
|
|
104
|
-
pages2.push(
|
|
105
|
-
acc2 = reduce(acc2,
|
|
106
|
-
const nextParam = getNextPageParam(
|
|
102
|
+
pages2.push(page2);
|
|
103
|
+
acc2 = reduce(acc2, page2);
|
|
104
|
+
const nextParam = getNextPageParam(page2, pages2, startParam, [
|
|
107
105
|
startParam
|
|
108
106
|
]);
|
|
109
107
|
nextBatchParam2 = nextParam != null ? nextParam : null;
|
|
@@ -118,9 +116,8 @@ function buildInfiniteCrawlingQueryFn(queryFn, getNextPageParam, shouldFetchNext
|
|
|
118
116
|
let currentParam = context.pageParam;
|
|
119
117
|
let acc = void 0;
|
|
120
118
|
let nextBatchParam = null;
|
|
121
|
-
let
|
|
119
|
+
let page = await initialResult;
|
|
122
120
|
while (true) {
|
|
123
|
-
const page = await nextResult;
|
|
124
121
|
pages.push(page);
|
|
125
122
|
pageParams.push(currentParam);
|
|
126
123
|
acc = reduce(acc, page);
|
|
@@ -130,9 +127,8 @@ function buildInfiniteCrawlingQueryFn(queryFn, getNextPageParam, shouldFetchNext
|
|
|
130
127
|
if (nextParam == null) break;
|
|
131
128
|
if (!shouldFetchNextPage(acc, crawlOptions)) break;
|
|
132
129
|
currentParam = nextParam;
|
|
133
|
-
if ((_d = context.signal) == null ? void 0 : _d.aborted) break;
|
|
134
130
|
ctx.pageParam = currentParam;
|
|
135
|
-
|
|
131
|
+
page = await queryFn(params, ctx);
|
|
136
132
|
}
|
|
137
133
|
if (acc === void 0) throw new DOMException("Aborted", "AbortError");
|
|
138
134
|
return { data: acc, nextPageParam: nextBatchParam };
|
|
@@ -250,7 +246,7 @@ function queryFactory(configOrParent, childConfig) {
|
|
|
250
246
|
const crawling = hasNewQueryFn ? {
|
|
251
247
|
getNextPageParam: childConfig.getNextPageParam,
|
|
252
248
|
getPreviousPageParam: childConfig.getPreviousPageParam,
|
|
253
|
-
initialPageParam: childConfig.initialPageParam,
|
|
249
|
+
initialPageParam: "initialPageParam" in childConfig ? childConfig.initialPageParam : parentCfg.initialPageParam,
|
|
254
250
|
// Fall back to parent's crawling logic when child doesn't override —
|
|
255
251
|
// useful when the child only changes how pages are fetched (e.g. switching
|
|
256
252
|
// to a paginator queryFn) but accumulates the same result shape.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robohall/react-query-factory",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"description": "A factory abstraction for TanStack Query (React Query) with composable keys, crawling support, and automatic infinite query generation",
|
|
5
5
|
"author": "Robert Hall",
|
|
6
6
|
"license": "MIT",
|