@orpc/tanstack-query 1.11.1 → 1.11.2
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 +34 -21
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -40,44 +40,57 @@ function experimental_liveQuery(queryFn) {
|
|
|
40
40
|
function experimental_serializableStreamedQuery(queryFn, { refetchMode = "reset", maxChunks = Number.POSITIVE_INFINITY } = {}) {
|
|
41
41
|
return async (context) => {
|
|
42
42
|
const query = context.client.getQueryCache().find({ queryKey: context.queryKey, exact: true });
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
const hasPreviousData = !!query && query.state.data !== void 0;
|
|
44
|
+
if (hasPreviousData) {
|
|
45
|
+
if (refetchMode === "reset") {
|
|
46
|
+
query.setState({
|
|
47
|
+
status: "pending",
|
|
48
|
+
data: void 0,
|
|
49
|
+
error: null,
|
|
50
|
+
fetchStatus: "fetching"
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
context.client.setQueryData(
|
|
54
|
+
context.queryKey,
|
|
55
|
+
(prev = []) => limitArraySize(prev, maxChunks)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
51
58
|
}
|
|
52
59
|
let result = [];
|
|
53
60
|
const stream = await queryFn(context);
|
|
61
|
+
const shouldUpdateCacheDuringStream = !hasPreviousData || refetchMode !== "replace";
|
|
62
|
+
context.client.setQueryData(
|
|
63
|
+
context.queryKey,
|
|
64
|
+
(prev = []) => limitArraySize(prev, maxChunks)
|
|
65
|
+
);
|
|
54
66
|
for await (const chunk of stream) {
|
|
55
67
|
if (context.signal.aborted) {
|
|
56
68
|
throw context.signal.reason;
|
|
57
69
|
}
|
|
58
|
-
|
|
70
|
+
result.push(chunk);
|
|
71
|
+
result = limitArraySize(result, maxChunks);
|
|
72
|
+
if (shouldUpdateCacheDuringStream) {
|
|
59
73
|
context.client.setQueryData(
|
|
60
74
|
context.queryKey,
|
|
61
|
-
(prev = []) =>
|
|
62
|
-
return addToEnd(prev, chunk, maxChunks);
|
|
63
|
-
}
|
|
75
|
+
(prev = []) => limitArraySize([...prev, chunk], maxChunks)
|
|
64
76
|
);
|
|
65
77
|
}
|
|
66
|
-
result = addToEnd(result, chunk, maxChunks);
|
|
67
78
|
}
|
|
68
|
-
if (
|
|
79
|
+
if (!shouldUpdateCacheDuringStream) {
|
|
69
80
|
context.client.setQueryData(context.queryKey, result);
|
|
70
81
|
}
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
return
|
|
82
|
+
const cachedData = context.client.getQueryData(context.queryKey);
|
|
83
|
+
if (cachedData) {
|
|
84
|
+
return limitArraySize(cachedData, maxChunks);
|
|
74
85
|
}
|
|
75
|
-
return
|
|
86
|
+
return result;
|
|
76
87
|
};
|
|
77
88
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
function limitArraySize(items, maxSize) {
|
|
90
|
+
if (items.length <= maxSize) {
|
|
91
|
+
return items;
|
|
92
|
+
}
|
|
93
|
+
return items.slice(items.length - maxSize);
|
|
81
94
|
}
|
|
82
95
|
|
|
83
96
|
const OPERATION_CONTEXT_SYMBOL = Symbol("ORPC_OPERATION_CONTEXT");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/tanstack-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.11.
|
|
4
|
+
"version": "1.11.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
],
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@tanstack/query-core": ">=5.80.2",
|
|
28
|
-
"@orpc/client": "1.11.
|
|
28
|
+
"@orpc/client": "1.11.2"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@orpc/shared": "1.11.
|
|
31
|
+
"@orpc/shared": "1.11.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@angular/core": "^20.3.10",
|