@robohall/react-query-factory 1.0.4 → 1.0.5
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 -1
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +66 -38
- package/dist/index.mjs +66 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,7 +92,7 @@ const describeInstances = queryFactory({
|
|
|
92
92
|
// ...
|
|
93
93
|
reduce: (acc, page): Instance[] => [...(acc ?? []), ...page.Reservations.flatMap(r => r.Instances)],
|
|
94
94
|
shouldFetchNextPage: (instances, opts: { minResults?: number }) =>
|
|
95
|
-
opts.minResults != null && instances.length < opts.minResults,
|
|
95
|
+
opts.minResults != null && instances.length < opts.minResults,
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
// stop after accumulating at least 50 instances
|
package/dist/index.d.mts
CHANGED
|
@@ -27,7 +27,9 @@ type QueryFactoryConfig<TParams = void, TData = unknown, TError = Error, TSelect
|
|
|
27
27
|
/** Namespace segments. Params are appended as the final element at call time,
|
|
28
28
|
* giving a full key of [...namespace, 'infinite'?, params, crawlOptions?]. */
|
|
29
29
|
queryKey: QueryKey;
|
|
30
|
-
queryFn?: (params: TParams, context: QueryFunctionContext<QueryKey, [
|
|
30
|
+
queryFn?: (params: TParams, context: QueryFunctionContext<QueryKey, [
|
|
31
|
+
unknown
|
|
32
|
+
] extends [TPageParam] ? never : TPageParam>) => TData | Promise<TData>;
|
|
31
33
|
select?: (data: TData) => TSelected;
|
|
32
34
|
} & ({
|
|
33
35
|
/** TanStack v5 generic order: GetNextPageParamFunction<TPageParam, TData> */
|
|
@@ -106,7 +108,9 @@ interface QueryFactory<TParams = void, TData = unknown, TError = Error, TSelecte
|
|
|
106
108
|
*/
|
|
107
109
|
declare function queryFactory<TParams = void, TData = unknown, TError = Error, TSelected = TData, TPageParam = unknown, TCrawlOptions extends Record<string, unknown> = Record<string, unknown>>(config: StandardQueryOptions<TError, TData> & {
|
|
108
110
|
queryKey: QueryKey;
|
|
109
|
-
queryFn?: (params: TParams, context: QueryFunctionContext<QueryKey, [
|
|
111
|
+
queryFn?: (params: TParams, context: QueryFunctionContext<QueryKey, [
|
|
112
|
+
unknown
|
|
113
|
+
] extends [TPageParam] ? never : TPageParam>) => TData | Promise<TData>;
|
|
110
114
|
select?: (data: TData) => TSelected;
|
|
111
115
|
getNextPageParam: GetNextPageParamFunction<TPageParam, TData>;
|
|
112
116
|
initialPageParam: TPageParam;
|
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,9 @@ type QueryFactoryConfig<TParams = void, TData = unknown, TError = Error, TSelect
|
|
|
27
27
|
/** Namespace segments. Params are appended as the final element at call time,
|
|
28
28
|
* giving a full key of [...namespace, 'infinite'?, params, crawlOptions?]. */
|
|
29
29
|
queryKey: QueryKey;
|
|
30
|
-
queryFn?: (params: TParams, context: QueryFunctionContext<QueryKey, [
|
|
30
|
+
queryFn?: (params: TParams, context: QueryFunctionContext<QueryKey, [
|
|
31
|
+
unknown
|
|
32
|
+
] extends [TPageParam] ? never : TPageParam>) => TData | Promise<TData>;
|
|
31
33
|
select?: (data: TData) => TSelected;
|
|
32
34
|
} & ({
|
|
33
35
|
/** TanStack v5 generic order: GetNextPageParamFunction<TPageParam, TData> */
|
|
@@ -106,7 +108,9 @@ interface QueryFactory<TParams = void, TData = unknown, TError = Error, TSelecte
|
|
|
106
108
|
*/
|
|
107
109
|
declare function queryFactory<TParams = void, TData = unknown, TError = Error, TSelected = TData, TPageParam = unknown, TCrawlOptions extends Record<string, unknown> = Record<string, unknown>>(config: StandardQueryOptions<TError, TData> & {
|
|
108
110
|
queryKey: QueryKey;
|
|
109
|
-
queryFn?: (params: TParams, context: QueryFunctionContext<QueryKey, [
|
|
111
|
+
queryFn?: (params: TParams, context: QueryFunctionContext<QueryKey, [
|
|
112
|
+
unknown
|
|
113
|
+
] extends [TPageParam] ? never : TPageParam>) => TData | Promise<TData>;
|
|
110
114
|
select?: (data: TData) => TSelected;
|
|
111
115
|
getNextPageParam: GetNextPageParamFunction<TPageParam, TData>;
|
|
112
116
|
initialPageParam: TPageParam;
|
package/dist/index.js
CHANGED
|
@@ -26,30 +26,39 @@ module.exports = __toCommonJS(index_exports);
|
|
|
26
26
|
|
|
27
27
|
// src/queryFactory.ts
|
|
28
28
|
var FACTORY_CONFIG = /* @__PURE__ */ Symbol("factoryConfig");
|
|
29
|
+
var getEnvelopeNextPageParam = (envelope) => envelope.nextPageParam;
|
|
30
|
+
var noNextPage = () => void 0;
|
|
29
31
|
function resolveKey(namespace, params, crawlOptions) {
|
|
30
32
|
const base = Array.isArray(namespace) ? namespace : [namespace];
|
|
31
33
|
const withParams = params === void 0 ? base : [...base, params];
|
|
32
34
|
if (!crawlOptions) return withParams;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
let defined;
|
|
36
|
+
for (const key in crawlOptions) {
|
|
37
|
+
if (crawlOptions[key] !== void 0) {
|
|
38
|
+
(defined != null ? defined : defined = {})[key] = crawlOptions[key];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return defined ? [...withParams, defined] : withParams;
|
|
35
42
|
}
|
|
36
|
-
function wrapGetNextPageParam(getNextPageParam, shouldFetchNextPage, crawlOptions
|
|
43
|
+
function wrapGetNextPageParam(getNextPageParam, shouldFetchNextPage, crawlOptions) {
|
|
37
44
|
return (lastPage, allPages, lastPageParam, allPageParams) => {
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
if (!shouldFetchNextPage(lastPage, crawlOptions))
|
|
46
|
+
return void 0;
|
|
40
47
|
return getNextPageParam(lastPage, allPages, lastPageParam, allPageParams);
|
|
41
48
|
};
|
|
42
49
|
}
|
|
43
|
-
function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shouldFetchNextPage, reduce
|
|
44
|
-
return async (context) => {
|
|
50
|
+
function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shouldFetchNextPage, reduce) {
|
|
51
|
+
return async (params, crawlOptions, context) => {
|
|
45
52
|
var _a, _b;
|
|
46
53
|
const pages = [];
|
|
47
54
|
const pageParams = [];
|
|
48
55
|
let currentParam = initialPageParam;
|
|
49
56
|
let acc = void 0;
|
|
57
|
+
const ctx = { ...context, pageParam: currentParam };
|
|
50
58
|
while (true) {
|
|
51
59
|
if ((_a = context.signal) == null ? void 0 : _a.aborted) break;
|
|
52
|
-
|
|
60
|
+
ctx.pageParam = currentParam;
|
|
61
|
+
const page = await queryFn(params, ctx);
|
|
53
62
|
pages.push(page);
|
|
54
63
|
pageParams.push(currentParam);
|
|
55
64
|
if (reduce) acc = reduce(acc, page);
|
|
@@ -66,17 +75,19 @@ function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shoul
|
|
|
66
75
|
return pages;
|
|
67
76
|
};
|
|
68
77
|
}
|
|
69
|
-
function buildInfiniteCrawlingQueryFn(queryFn, getNextPageParam, shouldFetchNextPage, reduce
|
|
70
|
-
return async (context) => {
|
|
78
|
+
function buildInfiniteCrawlingQueryFn(queryFn, getNextPageParam, shouldFetchNextPage, reduce) {
|
|
79
|
+
return async (params, crawlOptions, context) => {
|
|
71
80
|
var _a, _b;
|
|
72
81
|
const pages = [];
|
|
73
82
|
const pageParams = [];
|
|
74
83
|
let currentParam = context.pageParam;
|
|
75
84
|
let acc = void 0;
|
|
76
85
|
let nextBatchParam = null;
|
|
86
|
+
const ctx = { ...context, pageParam: currentParam };
|
|
77
87
|
while (true) {
|
|
78
88
|
if ((_a = context.signal) == null ? void 0 : _a.aborted) break;
|
|
79
|
-
|
|
89
|
+
ctx.pageParam = currentParam;
|
|
90
|
+
const page = await queryFn(params, ctx);
|
|
80
91
|
pages.push(page);
|
|
81
92
|
pageParams.push(currentParam);
|
|
82
93
|
acc = reduce(acc, page);
|
|
@@ -105,10 +116,31 @@ function buildFactory(cfg) {
|
|
|
105
116
|
} = cfg;
|
|
106
117
|
const hasCrawling = rawQueryFn !== void 0 && getNextPageParam !== void 0;
|
|
107
118
|
const hasInfiniteCrawling = hasCrawling && reduce !== void 0;
|
|
119
|
+
const crawlingFn = hasCrawling ? buildCrawlingQueryFn(
|
|
120
|
+
rawQueryFn,
|
|
121
|
+
getNextPageParam,
|
|
122
|
+
initialPageParam,
|
|
123
|
+
shouldFetchNextPage,
|
|
124
|
+
reduce
|
|
125
|
+
) : void 0;
|
|
126
|
+
const infiniteCrawlingFn = hasInfiniteCrawling ? buildInfiniteCrawlingQueryFn(
|
|
127
|
+
rawQueryFn,
|
|
128
|
+
getNextPageParam,
|
|
129
|
+
shouldFetchNextPage,
|
|
130
|
+
reduce
|
|
131
|
+
) : void 0;
|
|
132
|
+
const infiniteNamespace = [...resolveKey(namespace, void 0), "infinite"];
|
|
133
|
+
const envelopeSelect = infiniteCrawlingFn ? (data) => ({
|
|
134
|
+
...data,
|
|
135
|
+
pages: data.pages.map((e) => select ? select(e.data) : e.data)
|
|
136
|
+
}) : void 0;
|
|
137
|
+
const infiniteSelect = !infiniteCrawlingFn && select ? (data) => ({
|
|
138
|
+
...data,
|
|
139
|
+
pages: data.pages.map(select)
|
|
140
|
+
}) : void 0;
|
|
108
141
|
const factory = function(params, crawlOptions = {}) {
|
|
109
142
|
const queryKey = resolveKey(namespace, params, crawlOptions);
|
|
110
|
-
const
|
|
111
|
-
const resolvedQueryFn = hasCrawling ? buildCrawlingQueryFn(boundQueryFn, getNextPageParam, initialPageParam, shouldFetchNextPage, reduce, crawlOptions) : boundQueryFn;
|
|
143
|
+
const resolvedQueryFn = crawlingFn ? (ctx) => crawlingFn(params, crawlOptions, ctx) : rawQueryFn ? (ctx) => rawQueryFn(params, ctx) : void 0;
|
|
112
144
|
return {
|
|
113
145
|
...standardOptions,
|
|
114
146
|
queryKey,
|
|
@@ -118,37 +150,25 @@ function buildFactory(cfg) {
|
|
|
118
150
|
};
|
|
119
151
|
};
|
|
120
152
|
factory.infinite = function(params, crawlOptions = {}) {
|
|
121
|
-
const queryKey = resolveKey(
|
|
122
|
-
|
|
123
|
-
if (hasInfiniteCrawling) {
|
|
124
|
-
const crawlingQueryFn = buildInfiniteCrawlingQueryFn(
|
|
125
|
-
boundQueryFn,
|
|
126
|
-
getNextPageParam,
|
|
127
|
-
shouldFetchNextPage,
|
|
128
|
-
reduce,
|
|
129
|
-
crawlOptions
|
|
130
|
-
);
|
|
131
|
-
const envelopeGetNextPageParam = (envelope) => envelope.nextPageParam;
|
|
132
|
-
const envelopeSelect = (data) => ({
|
|
133
|
-
...data,
|
|
134
|
-
pages: data.pages.map((e) => select ? select(e.data) : e.data)
|
|
135
|
-
});
|
|
153
|
+
const queryKey = resolveKey(infiniteNamespace, params, crawlOptions);
|
|
154
|
+
if (infiniteCrawlingFn) {
|
|
136
155
|
return {
|
|
137
156
|
...standardOptions,
|
|
138
157
|
queryKey,
|
|
139
|
-
queryFn:
|
|
140
|
-
getNextPageParam:
|
|
158
|
+
queryFn: (ctx) => infiniteCrawlingFn(params, crawlOptions, ctx),
|
|
159
|
+
getNextPageParam: getEnvelopeNextPageParam,
|
|
141
160
|
initialPageParam,
|
|
142
161
|
select: envelopeSelect,
|
|
143
162
|
...getPreviousPageParam !== void 0 && { getPreviousPageParam },
|
|
144
163
|
[FACTORY_CONFIG]: cfg
|
|
145
164
|
};
|
|
146
165
|
}
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
166
|
+
const boundQueryFn = rawQueryFn ? (ctx) => rawQueryFn(params, ctx) : void 0;
|
|
167
|
+
const infiniteGetNextPageParam = getNextPageParam && shouldFetchNextPage ? wrapGetNextPageParam(
|
|
168
|
+
getNextPageParam,
|
|
169
|
+
shouldFetchNextPage,
|
|
170
|
+
crawlOptions
|
|
171
|
+
) : getNextPageParam != null ? getNextPageParam : noNextPage;
|
|
152
172
|
return {
|
|
153
173
|
...standardOptions,
|
|
154
174
|
queryKey,
|
|
@@ -168,11 +188,16 @@ function queryFactory(configOrParent, childConfig) {
|
|
|
168
188
|
const result = configOrParent();
|
|
169
189
|
const parentCfg = result == null ? void 0 : result[FACTORY_CONFIG];
|
|
170
190
|
if (!parentCfg) {
|
|
171
|
-
throw new Error(
|
|
191
|
+
throw new Error(
|
|
192
|
+
"queryFactory: first argument must be a factory created by queryFactory()"
|
|
193
|
+
);
|
|
172
194
|
}
|
|
173
195
|
const hasNewQueryFn = childConfig.queryFn !== void 0;
|
|
174
196
|
const childNamespace = childConfig.queryKey ? Array.isArray(childConfig.queryKey) ? childConfig.queryKey : [childConfig.queryKey] : [];
|
|
175
|
-
const composedNamespace = [
|
|
197
|
+
const composedNamespace = [
|
|
198
|
+
...parentCfg.queryKey,
|
|
199
|
+
...childNamespace
|
|
200
|
+
];
|
|
176
201
|
let resolvedSelect;
|
|
177
202
|
if (hasNewQueryFn) {
|
|
178
203
|
resolvedSelect = childConfig.select;
|
|
@@ -212,7 +237,10 @@ function queryFactory(configOrParent, childConfig) {
|
|
|
212
237
|
queryFn: hasNewQueryFn ? childConfig.queryFn : parentCfg.queryFn,
|
|
213
238
|
select: resolvedSelect,
|
|
214
239
|
...crawling,
|
|
215
|
-
standardOptions: {
|
|
240
|
+
standardOptions: {
|
|
241
|
+
...parentCfg.standardOptions,
|
|
242
|
+
...childStandardOptions
|
|
243
|
+
}
|
|
216
244
|
});
|
|
217
245
|
}
|
|
218
246
|
const {
|
package/dist/index.mjs
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
// src/queryFactory.ts
|
|
2
2
|
var FACTORY_CONFIG = /* @__PURE__ */ Symbol("factoryConfig");
|
|
3
|
+
var getEnvelopeNextPageParam = (envelope) => envelope.nextPageParam;
|
|
4
|
+
var noNextPage = () => void 0;
|
|
3
5
|
function resolveKey(namespace, params, crawlOptions) {
|
|
4
6
|
const base = Array.isArray(namespace) ? namespace : [namespace];
|
|
5
7
|
const withParams = params === void 0 ? base : [...base, params];
|
|
6
8
|
if (!crawlOptions) return withParams;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
let defined;
|
|
10
|
+
for (const key in crawlOptions) {
|
|
11
|
+
if (crawlOptions[key] !== void 0) {
|
|
12
|
+
(defined != null ? defined : defined = {})[key] = crawlOptions[key];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return defined ? [...withParams, defined] : withParams;
|
|
9
16
|
}
|
|
10
|
-
function wrapGetNextPageParam(getNextPageParam, shouldFetchNextPage, crawlOptions
|
|
17
|
+
function wrapGetNextPageParam(getNextPageParam, shouldFetchNextPage, crawlOptions) {
|
|
11
18
|
return (lastPage, allPages, lastPageParam, allPageParams) => {
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
if (!shouldFetchNextPage(lastPage, crawlOptions))
|
|
20
|
+
return void 0;
|
|
14
21
|
return getNextPageParam(lastPage, allPages, lastPageParam, allPageParams);
|
|
15
22
|
};
|
|
16
23
|
}
|
|
17
|
-
function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shouldFetchNextPage, reduce
|
|
18
|
-
return async (context) => {
|
|
24
|
+
function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shouldFetchNextPage, reduce) {
|
|
25
|
+
return async (params, crawlOptions, context) => {
|
|
19
26
|
var _a, _b;
|
|
20
27
|
const pages = [];
|
|
21
28
|
const pageParams = [];
|
|
22
29
|
let currentParam = initialPageParam;
|
|
23
30
|
let acc = void 0;
|
|
31
|
+
const ctx = { ...context, pageParam: currentParam };
|
|
24
32
|
while (true) {
|
|
25
33
|
if ((_a = context.signal) == null ? void 0 : _a.aborted) break;
|
|
26
|
-
|
|
34
|
+
ctx.pageParam = currentParam;
|
|
35
|
+
const page = await queryFn(params, ctx);
|
|
27
36
|
pages.push(page);
|
|
28
37
|
pageParams.push(currentParam);
|
|
29
38
|
if (reduce) acc = reduce(acc, page);
|
|
@@ -40,17 +49,19 @@ function buildCrawlingQueryFn(queryFn, getNextPageParam, initialPageParam, shoul
|
|
|
40
49
|
return pages;
|
|
41
50
|
};
|
|
42
51
|
}
|
|
43
|
-
function buildInfiniteCrawlingQueryFn(queryFn, getNextPageParam, shouldFetchNextPage, reduce
|
|
44
|
-
return async (context) => {
|
|
52
|
+
function buildInfiniteCrawlingQueryFn(queryFn, getNextPageParam, shouldFetchNextPage, reduce) {
|
|
53
|
+
return async (params, crawlOptions, context) => {
|
|
45
54
|
var _a, _b;
|
|
46
55
|
const pages = [];
|
|
47
56
|
const pageParams = [];
|
|
48
57
|
let currentParam = context.pageParam;
|
|
49
58
|
let acc = void 0;
|
|
50
59
|
let nextBatchParam = null;
|
|
60
|
+
const ctx = { ...context, pageParam: currentParam };
|
|
51
61
|
while (true) {
|
|
52
62
|
if ((_a = context.signal) == null ? void 0 : _a.aborted) break;
|
|
53
|
-
|
|
63
|
+
ctx.pageParam = currentParam;
|
|
64
|
+
const page = await queryFn(params, ctx);
|
|
54
65
|
pages.push(page);
|
|
55
66
|
pageParams.push(currentParam);
|
|
56
67
|
acc = reduce(acc, page);
|
|
@@ -79,10 +90,31 @@ function buildFactory(cfg) {
|
|
|
79
90
|
} = cfg;
|
|
80
91
|
const hasCrawling = rawQueryFn !== void 0 && getNextPageParam !== void 0;
|
|
81
92
|
const hasInfiniteCrawling = hasCrawling && reduce !== void 0;
|
|
93
|
+
const crawlingFn = hasCrawling ? buildCrawlingQueryFn(
|
|
94
|
+
rawQueryFn,
|
|
95
|
+
getNextPageParam,
|
|
96
|
+
initialPageParam,
|
|
97
|
+
shouldFetchNextPage,
|
|
98
|
+
reduce
|
|
99
|
+
) : void 0;
|
|
100
|
+
const infiniteCrawlingFn = hasInfiniteCrawling ? buildInfiniteCrawlingQueryFn(
|
|
101
|
+
rawQueryFn,
|
|
102
|
+
getNextPageParam,
|
|
103
|
+
shouldFetchNextPage,
|
|
104
|
+
reduce
|
|
105
|
+
) : void 0;
|
|
106
|
+
const infiniteNamespace = [...resolveKey(namespace, void 0), "infinite"];
|
|
107
|
+
const envelopeSelect = infiniteCrawlingFn ? (data) => ({
|
|
108
|
+
...data,
|
|
109
|
+
pages: data.pages.map((e) => select ? select(e.data) : e.data)
|
|
110
|
+
}) : void 0;
|
|
111
|
+
const infiniteSelect = !infiniteCrawlingFn && select ? (data) => ({
|
|
112
|
+
...data,
|
|
113
|
+
pages: data.pages.map(select)
|
|
114
|
+
}) : void 0;
|
|
82
115
|
const factory = function(params, crawlOptions = {}) {
|
|
83
116
|
const queryKey = resolveKey(namespace, params, crawlOptions);
|
|
84
|
-
const
|
|
85
|
-
const resolvedQueryFn = hasCrawling ? buildCrawlingQueryFn(boundQueryFn, getNextPageParam, initialPageParam, shouldFetchNextPage, reduce, crawlOptions) : boundQueryFn;
|
|
117
|
+
const resolvedQueryFn = crawlingFn ? (ctx) => crawlingFn(params, crawlOptions, ctx) : rawQueryFn ? (ctx) => rawQueryFn(params, ctx) : void 0;
|
|
86
118
|
return {
|
|
87
119
|
...standardOptions,
|
|
88
120
|
queryKey,
|
|
@@ -92,37 +124,25 @@ function buildFactory(cfg) {
|
|
|
92
124
|
};
|
|
93
125
|
};
|
|
94
126
|
factory.infinite = function(params, crawlOptions = {}) {
|
|
95
|
-
const queryKey = resolveKey(
|
|
96
|
-
|
|
97
|
-
if (hasInfiniteCrawling) {
|
|
98
|
-
const crawlingQueryFn = buildInfiniteCrawlingQueryFn(
|
|
99
|
-
boundQueryFn,
|
|
100
|
-
getNextPageParam,
|
|
101
|
-
shouldFetchNextPage,
|
|
102
|
-
reduce,
|
|
103
|
-
crawlOptions
|
|
104
|
-
);
|
|
105
|
-
const envelopeGetNextPageParam = (envelope) => envelope.nextPageParam;
|
|
106
|
-
const envelopeSelect = (data) => ({
|
|
107
|
-
...data,
|
|
108
|
-
pages: data.pages.map((e) => select ? select(e.data) : e.data)
|
|
109
|
-
});
|
|
127
|
+
const queryKey = resolveKey(infiniteNamespace, params, crawlOptions);
|
|
128
|
+
if (infiniteCrawlingFn) {
|
|
110
129
|
return {
|
|
111
130
|
...standardOptions,
|
|
112
131
|
queryKey,
|
|
113
|
-
queryFn:
|
|
114
|
-
getNextPageParam:
|
|
132
|
+
queryFn: (ctx) => infiniteCrawlingFn(params, crawlOptions, ctx),
|
|
133
|
+
getNextPageParam: getEnvelopeNextPageParam,
|
|
115
134
|
initialPageParam,
|
|
116
135
|
select: envelopeSelect,
|
|
117
136
|
...getPreviousPageParam !== void 0 && { getPreviousPageParam },
|
|
118
137
|
[FACTORY_CONFIG]: cfg
|
|
119
138
|
};
|
|
120
139
|
}
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
140
|
+
const boundQueryFn = rawQueryFn ? (ctx) => rawQueryFn(params, ctx) : void 0;
|
|
141
|
+
const infiniteGetNextPageParam = getNextPageParam && shouldFetchNextPage ? wrapGetNextPageParam(
|
|
142
|
+
getNextPageParam,
|
|
143
|
+
shouldFetchNextPage,
|
|
144
|
+
crawlOptions
|
|
145
|
+
) : getNextPageParam != null ? getNextPageParam : noNextPage;
|
|
126
146
|
return {
|
|
127
147
|
...standardOptions,
|
|
128
148
|
queryKey,
|
|
@@ -142,11 +162,16 @@ function queryFactory(configOrParent, childConfig) {
|
|
|
142
162
|
const result = configOrParent();
|
|
143
163
|
const parentCfg = result == null ? void 0 : result[FACTORY_CONFIG];
|
|
144
164
|
if (!parentCfg) {
|
|
145
|
-
throw new Error(
|
|
165
|
+
throw new Error(
|
|
166
|
+
"queryFactory: first argument must be a factory created by queryFactory()"
|
|
167
|
+
);
|
|
146
168
|
}
|
|
147
169
|
const hasNewQueryFn = childConfig.queryFn !== void 0;
|
|
148
170
|
const childNamespace = childConfig.queryKey ? Array.isArray(childConfig.queryKey) ? childConfig.queryKey : [childConfig.queryKey] : [];
|
|
149
|
-
const composedNamespace = [
|
|
171
|
+
const composedNamespace = [
|
|
172
|
+
...parentCfg.queryKey,
|
|
173
|
+
...childNamespace
|
|
174
|
+
];
|
|
150
175
|
let resolvedSelect;
|
|
151
176
|
if (hasNewQueryFn) {
|
|
152
177
|
resolvedSelect = childConfig.select;
|
|
@@ -186,7 +211,10 @@ function queryFactory(configOrParent, childConfig) {
|
|
|
186
211
|
queryFn: hasNewQueryFn ? childConfig.queryFn : parentCfg.queryFn,
|
|
187
212
|
select: resolvedSelect,
|
|
188
213
|
...crawling,
|
|
189
|
-
standardOptions: {
|
|
214
|
+
standardOptions: {
|
|
215
|
+
...parentCfg.standardOptions,
|
|
216
|
+
...childStandardOptions
|
|
217
|
+
}
|
|
190
218
|
});
|
|
191
219
|
}
|
|
192
220
|
const {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robohall/react-query-factory",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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",
|