@tanstack/query-core 5.67.3 → 5.69.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/build/legacy/index.cjs +3 -0
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/index.d.cts +1 -0
- package/build/legacy/index.d.ts +1 -0
- package/build/legacy/index.js +2 -0
- package/build/legacy/index.js.map +1 -1
- package/build/legacy/streamedQuery.cjs +61 -0
- package/build/legacy/streamedQuery.cjs.map +1 -0
- package/build/legacy/streamedQuery.d.cts +18 -0
- package/build/legacy/streamedQuery.d.ts +18 -0
- package/build/legacy/streamedQuery.js +38 -0
- package/build/legacy/streamedQuery.js.map +1 -0
- package/build/modern/index.cjs +3 -0
- package/build/modern/index.cjs.map +1 -1
- package/build/modern/index.d.cts +1 -0
- package/build/modern/index.d.ts +1 -0
- package/build/modern/index.js +2 -0
- package/build/modern/index.js.map +1 -1
- package/build/modern/streamedQuery.cjs +61 -0
- package/build/modern/streamedQuery.cjs.map +1 -0
- package/build/modern/streamedQuery.d.cts +18 -0
- package/build/modern/streamedQuery.d.ts +18 -0
- package/build/modern/streamedQuery.js +36 -0
- package/build/modern/streamedQuery.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/streamedQuery.ts +51 -0
package/build/legacy/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
defaultShouldDehydrateMutation: () => import_hydration.defaultShouldDehydrateMutation,
|
|
35
35
|
defaultShouldDehydrateQuery: () => import_hydration.defaultShouldDehydrateQuery,
|
|
36
36
|
dehydrate: () => import_hydration.dehydrate,
|
|
37
|
+
experimental_streamedQuery: () => import_streamedQuery.streamedQuery,
|
|
37
38
|
focusManager: () => import_focusManager.focusManager,
|
|
38
39
|
hashKey: () => import_utils.hashKey,
|
|
39
40
|
hydrate: () => import_hydration.hydrate,
|
|
@@ -62,6 +63,7 @@ var import_onlineManager = require("./onlineManager.cjs");
|
|
|
62
63
|
var import_utils = require("./utils.cjs");
|
|
63
64
|
var import_retryer2 = require("./retryer.cjs");
|
|
64
65
|
var import_hydration = require("./hydration.cjs");
|
|
66
|
+
var import_streamedQuery = require("./streamedQuery.cjs");
|
|
65
67
|
__reExport(src_exports, require("./types.cjs"), module.exports);
|
|
66
68
|
var import_query = require("./query.cjs");
|
|
67
69
|
var import_mutation = require("./mutation.cjs");
|
|
@@ -80,6 +82,7 @@ var import_mutation = require("./mutation.cjs");
|
|
|
80
82
|
defaultShouldDehydrateMutation,
|
|
81
83
|
defaultShouldDehydrateQuery,
|
|
82
84
|
dehydrate,
|
|
85
|
+
experimental_streamedQuery,
|
|
83
86
|
focusManager,
|
|
84
87
|
hashKey,
|
|
85
88
|
hydrate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\nexport { CancelledError } from './retryer'\nexport { QueryCache } from './queryCache'\nexport type { QueryCacheNotifyEvent } from './queryCache'\nexport { QueryClient } from './queryClient'\nexport { QueryObserver } from './queryObserver'\nexport { QueriesObserver } from './queriesObserver'\nexport { InfiniteQueryObserver } from './infiniteQueryObserver'\nexport { MutationCache } from './mutationCache'\nexport type { MutationCacheNotifyEvent } from './mutationCache'\nexport { MutationObserver } from './mutationObserver'\nexport { notifyManager } from './notifyManager'\nexport { focusManager } from './focusManager'\nexport { onlineManager } from './onlineManager'\nexport {\n hashKey,\n replaceEqualDeep,\n isServer,\n matchQuery,\n matchMutation,\n keepPreviousData,\n skipToken,\n} from './utils'\nexport type { MutationFilters, QueryFilters, Updater, SkipToken } from './utils'\nexport { isCancelledError } from './retryer'\nexport {\n dehydrate,\n hydrate,\n defaultShouldDehydrateQuery,\n defaultShouldDehydrateMutation,\n} from './hydration'\n\n// Types\nexport * from './types'\nexport type { QueryState } from './query'\nexport { Query } from './query'\nexport type { MutationState } from './mutation'\nexport { Mutation } from './mutation'\nexport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n} from './hydration'\nexport type { QueriesObserverOptions } from './queriesObserver'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAA+B;AAC/B,wBAA2B;AAE3B,yBAA4B;AAC5B,2BAA8B;AAC9B,6BAAgC;AAChC,mCAAsC;AACtC,2BAA8B;AAE9B,8BAAiC;AACjC,2BAA8B;AAC9B,0BAA6B;AAC7B,2BAA8B;AAC9B,mBAQO;AAEP,IAAAA,kBAAiC;AACjC,uBAKO;
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\nexport { CancelledError } from './retryer'\nexport { QueryCache } from './queryCache'\nexport type { QueryCacheNotifyEvent } from './queryCache'\nexport { QueryClient } from './queryClient'\nexport { QueryObserver } from './queryObserver'\nexport { QueriesObserver } from './queriesObserver'\nexport { InfiniteQueryObserver } from './infiniteQueryObserver'\nexport { MutationCache } from './mutationCache'\nexport type { MutationCacheNotifyEvent } from './mutationCache'\nexport { MutationObserver } from './mutationObserver'\nexport { notifyManager } from './notifyManager'\nexport { focusManager } from './focusManager'\nexport { onlineManager } from './onlineManager'\nexport {\n hashKey,\n replaceEqualDeep,\n isServer,\n matchQuery,\n matchMutation,\n keepPreviousData,\n skipToken,\n} from './utils'\nexport type { MutationFilters, QueryFilters, Updater, SkipToken } from './utils'\nexport { isCancelledError } from './retryer'\nexport {\n dehydrate,\n hydrate,\n defaultShouldDehydrateQuery,\n defaultShouldDehydrateMutation,\n} from './hydration'\n\nexport { streamedQuery as experimental_streamedQuery } from './streamedQuery'\n\n// Types\nexport * from './types'\nexport type { QueryState } from './query'\nexport { Query } from './query'\nexport type { MutationState } from './mutation'\nexport { Mutation } from './mutation'\nexport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n} from './hydration'\nexport type { QueriesObserverOptions } from './queriesObserver'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAA+B;AAC/B,wBAA2B;AAE3B,yBAA4B;AAC5B,2BAA8B;AAC9B,6BAAgC;AAChC,mCAAsC;AACtC,2BAA8B;AAE9B,8BAAiC;AACjC,2BAA8B;AAC9B,0BAA6B;AAC7B,2BAA8B;AAC9B,mBAQO;AAEP,IAAAA,kBAAiC;AACjC,uBAKO;AAEP,2BAA4D;AAG5D,wBAAc,wBApCd;AAsCA,mBAAsB;AAEtB,sBAAyB;","names":["import_retryer"]}
|
package/build/legacy/index.d.cts
CHANGED
|
@@ -4,5 +4,6 @@ export { InfiniteQueryObserver } from './infiniteQueryObserver.cjs';
|
|
|
4
4
|
export { notifyManager } from './notifyManager.cjs';
|
|
5
5
|
export { focusManager } from './focusManager.cjs';
|
|
6
6
|
export { onlineManager } from './onlineManager.cjs';
|
|
7
|
+
export { streamedQuery as experimental_streamedQuery } from './streamedQuery.cjs';
|
|
7
8
|
import './removable.cjs';
|
|
8
9
|
import './subscribable.cjs';
|
package/build/legacy/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export { InfiniteQueryObserver } from './infiniteQueryObserver.js';
|
|
|
4
4
|
export { notifyManager } from './notifyManager.js';
|
|
5
5
|
export { focusManager } from './focusManager.js';
|
|
6
6
|
export { onlineManager } from './onlineManager.js';
|
|
7
|
+
export { streamedQuery as experimental_streamedQuery } from './streamedQuery.js';
|
|
7
8
|
import './removable.js';
|
|
8
9
|
import './subscribable.js';
|
package/build/legacy/index.js
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
defaultShouldDehydrateQuery,
|
|
29
29
|
defaultShouldDehydrateMutation
|
|
30
30
|
} from "./hydration.js";
|
|
31
|
+
import { streamedQuery } from "./streamedQuery.js";
|
|
31
32
|
export * from "./types.js";
|
|
32
33
|
import { Query } from "./query.js";
|
|
33
34
|
import { Mutation } from "./mutation.js";
|
|
@@ -45,6 +46,7 @@ export {
|
|
|
45
46
|
defaultShouldDehydrateMutation,
|
|
46
47
|
defaultShouldDehydrateQuery,
|
|
47
48
|
dehydrate,
|
|
49
|
+
streamedQuery as experimental_streamedQuery,
|
|
48
50
|
focusManager,
|
|
49
51
|
hashKey,
|
|
50
52
|
hydrate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\nexport { CancelledError } from './retryer'\nexport { QueryCache } from './queryCache'\nexport type { QueryCacheNotifyEvent } from './queryCache'\nexport { QueryClient } from './queryClient'\nexport { QueryObserver } from './queryObserver'\nexport { QueriesObserver } from './queriesObserver'\nexport { InfiniteQueryObserver } from './infiniteQueryObserver'\nexport { MutationCache } from './mutationCache'\nexport type { MutationCacheNotifyEvent } from './mutationCache'\nexport { MutationObserver } from './mutationObserver'\nexport { notifyManager } from './notifyManager'\nexport { focusManager } from './focusManager'\nexport { onlineManager } from './onlineManager'\nexport {\n hashKey,\n replaceEqualDeep,\n isServer,\n matchQuery,\n matchMutation,\n keepPreviousData,\n skipToken,\n} from './utils'\nexport type { MutationFilters, QueryFilters, Updater, SkipToken } from './utils'\nexport { isCancelledError } from './retryer'\nexport {\n dehydrate,\n hydrate,\n defaultShouldDehydrateQuery,\n defaultShouldDehydrateMutation,\n} from './hydration'\n\n// Types\nexport * from './types'\nexport type { QueryState } from './query'\nexport { Query } from './query'\nexport type { MutationState } from './mutation'\nexport { Mutation } from './mutation'\nexport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n} from './hydration'\nexport type { QueriesObserverOptions } from './queriesObserver'\n"],"mappings":";;;AAEA,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAE3B,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAE9B,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\nexport { CancelledError } from './retryer'\nexport { QueryCache } from './queryCache'\nexport type { QueryCacheNotifyEvent } from './queryCache'\nexport { QueryClient } from './queryClient'\nexport { QueryObserver } from './queryObserver'\nexport { QueriesObserver } from './queriesObserver'\nexport { InfiniteQueryObserver } from './infiniteQueryObserver'\nexport { MutationCache } from './mutationCache'\nexport type { MutationCacheNotifyEvent } from './mutationCache'\nexport { MutationObserver } from './mutationObserver'\nexport { notifyManager } from './notifyManager'\nexport { focusManager } from './focusManager'\nexport { onlineManager } from './onlineManager'\nexport {\n hashKey,\n replaceEqualDeep,\n isServer,\n matchQuery,\n matchMutation,\n keepPreviousData,\n skipToken,\n} from './utils'\nexport type { MutationFilters, QueryFilters, Updater, SkipToken } from './utils'\nexport { isCancelledError } from './retryer'\nexport {\n dehydrate,\n hydrate,\n defaultShouldDehydrateQuery,\n defaultShouldDehydrateMutation,\n} from './hydration'\n\nexport { streamedQuery as experimental_streamedQuery } from './streamedQuery'\n\n// Types\nexport * from './types'\nexport type { QueryState } from './query'\nexport { Query } from './query'\nexport type { MutationState } from './mutation'\nexport { Mutation } from './mutation'\nexport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n} from './hydration'\nexport type { QueriesObserverOptions } from './queriesObserver'\n"],"mappings":";;;AAEA,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAE3B,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAE9B,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAA0B,qBAAkC;AAG5D,cAAc;AAEd,SAAS,aAAa;AAEtB,SAAS,gBAAgB;","names":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/streamedQuery.ts
|
|
21
|
+
var streamedQuery_exports = {};
|
|
22
|
+
__export(streamedQuery_exports, {
|
|
23
|
+
streamedQuery: () => streamedQuery
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(streamedQuery_exports);
|
|
26
|
+
function streamedQuery({
|
|
27
|
+
queryFn,
|
|
28
|
+
refetchMode
|
|
29
|
+
}) {
|
|
30
|
+
return async (context) => {
|
|
31
|
+
if (refetchMode !== "append") {
|
|
32
|
+
const query = context.client.getQueryCache().find({ queryKey: context.queryKey, exact: true });
|
|
33
|
+
if (query && query.state.data !== void 0) {
|
|
34
|
+
query.setState({
|
|
35
|
+
status: "pending",
|
|
36
|
+
data: void 0,
|
|
37
|
+
error: null,
|
|
38
|
+
fetchStatus: "fetching"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const stream = await queryFn(context);
|
|
43
|
+
for await (const chunk of stream) {
|
|
44
|
+
if (context.signal.aborted) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
context.client.setQueryData(
|
|
48
|
+
context.queryKey,
|
|
49
|
+
(prev = []) => {
|
|
50
|
+
return prev.concat(chunk);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return context.client.getQueryData(context.queryKey);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
streamedQuery
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=streamedQuery.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import type { QueryFunction, QueryFunctionContext, QueryKey } from './types'\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param queryFn - The function that returns an AsyncIterable to stream data from.\n * @param refetchMode - Defaults to 'reset', which replaces data when a refetch happens. Set to 'append' to append new data to the existing data.\n */\nexport function streamedQuery<\n TQueryFnData = unknown,\n TQueryKey extends QueryKey = QueryKey,\n>({\n queryFn,\n refetchMode,\n}: {\n queryFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n refetchMode?: 'append' | 'reset'\n}): QueryFunction<Array<TQueryFnData>, TQueryKey> {\n return async (context) => {\n if (refetchMode !== 'append') {\n const query = context.client\n .getQueryCache()\n .find({ queryKey: context.queryKey, exact: true })\n if (query && query.state.data !== undefined) {\n query.setState({\n status: 'pending',\n data: undefined,\n error: null,\n fetchStatus: 'fetching',\n })\n }\n }\n const stream = await queryFn(context)\n for await (const chunk of stream) {\n if (context.signal.aborted) {\n break\n }\n context.client.setQueryData<Array<TQueryFnData>>(\n context.queryKey,\n (prev = []) => {\n return prev.concat(chunk)\n },\n )\n }\n return context.client.getQueryData(context.queryKey)!\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,SAAS,cAGd;AAAA,EACA;AAAA,EACA;AACF,GAKkD;AAChD,SAAO,OAAO,YAAY;AACxB,QAAI,gBAAgB,UAAU;AAC5B,YAAM,QAAQ,QAAQ,OACnB,cAAc,EACd,KAAK,EAAE,UAAU,QAAQ,UAAU,OAAO,KAAK,CAAC;AACnD,UAAI,SAAS,MAAM,MAAM,SAAS,QAAW;AAC3C,cAAM,SAAS;AAAA,UACb,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,OAAO;AAAA,UACP,aAAa;AAAA,QACf,CAAC;AAAA,MACH;AAAA,IACF;AACA,UAAM,SAAS,MAAM,QAAQ,OAAO;AACpC,qBAAiB,SAAS,QAAQ;AAChC,UAAI,QAAQ,OAAO,SAAS;AAC1B;AAAA,MACF;AACA,cAAQ,OAAO;AAAA,QACb,QAAQ;AAAA,QACR,CAAC,OAAO,CAAC,MAAM;AACb,iBAAO,KAAK,OAAO,KAAK;AAAA,QAC1B;AAAA,MACF;AAAA,IACF;AACA,WAAO,QAAQ,OAAO,aAAa,QAAQ,QAAQ;AAAA,EACrD;AACF;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { A as QueryKey, X as QueryFunctionContext, P as QueryFunction } from './hydration-BZgfn3GW.cjs';
|
|
2
|
+
import './removable.cjs';
|
|
3
|
+
import './subscribable.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This is a helper function to create a query function that streams data from an AsyncIterable.
|
|
7
|
+
* Data will be an Array of all the chunks received.
|
|
8
|
+
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
9
|
+
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
10
|
+
* @param queryFn - The function that returns an AsyncIterable to stream data from.
|
|
11
|
+
* @param refetchMode - Defaults to 'reset', which replaces data when a refetch happens. Set to 'append' to append new data to the existing data.
|
|
12
|
+
*/
|
|
13
|
+
declare function streamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>({ queryFn, refetchMode, }: {
|
|
14
|
+
queryFn: (context: QueryFunctionContext<TQueryKey>) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>;
|
|
15
|
+
refetchMode?: 'append' | 'reset';
|
|
16
|
+
}): QueryFunction<Array<TQueryFnData>, TQueryKey>;
|
|
17
|
+
|
|
18
|
+
export { streamedQuery };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { A as QueryKey, X as QueryFunctionContext, P as QueryFunction } from './hydration-B_mC2U5v.js';
|
|
2
|
+
import './removable.js';
|
|
3
|
+
import './subscribable.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This is a helper function to create a query function that streams data from an AsyncIterable.
|
|
7
|
+
* Data will be an Array of all the chunks received.
|
|
8
|
+
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
9
|
+
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
10
|
+
* @param queryFn - The function that returns an AsyncIterable to stream data from.
|
|
11
|
+
* @param refetchMode - Defaults to 'reset', which replaces data when a refetch happens. Set to 'append' to append new data to the existing data.
|
|
12
|
+
*/
|
|
13
|
+
declare function streamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>({ queryFn, refetchMode, }: {
|
|
14
|
+
queryFn: (context: QueryFunctionContext<TQueryKey>) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>;
|
|
15
|
+
refetchMode?: 'append' | 'reset';
|
|
16
|
+
}): QueryFunction<Array<TQueryFnData>, TQueryKey>;
|
|
17
|
+
|
|
18
|
+
export { streamedQuery };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import "./chunk-2HYBKCYP.js";
|
|
2
|
+
|
|
3
|
+
// src/streamedQuery.ts
|
|
4
|
+
function streamedQuery({
|
|
5
|
+
queryFn,
|
|
6
|
+
refetchMode
|
|
7
|
+
}) {
|
|
8
|
+
return async (context) => {
|
|
9
|
+
if (refetchMode !== "append") {
|
|
10
|
+
const query = context.client.getQueryCache().find({ queryKey: context.queryKey, exact: true });
|
|
11
|
+
if (query && query.state.data !== void 0) {
|
|
12
|
+
query.setState({
|
|
13
|
+
status: "pending",
|
|
14
|
+
data: void 0,
|
|
15
|
+
error: null,
|
|
16
|
+
fetchStatus: "fetching"
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const stream = await queryFn(context);
|
|
21
|
+
for await (const chunk of stream) {
|
|
22
|
+
if (context.signal.aborted) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
context.client.setQueryData(
|
|
26
|
+
context.queryKey,
|
|
27
|
+
(prev = []) => {
|
|
28
|
+
return prev.concat(chunk);
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return context.client.getQueryData(context.queryKey);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
streamedQuery
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=streamedQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import type { QueryFunction, QueryFunctionContext, QueryKey } from './types'\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param queryFn - The function that returns an AsyncIterable to stream data from.\n * @param refetchMode - Defaults to 'reset', which replaces data when a refetch happens. Set to 'append' to append new data to the existing data.\n */\nexport function streamedQuery<\n TQueryFnData = unknown,\n TQueryKey extends QueryKey = QueryKey,\n>({\n queryFn,\n refetchMode,\n}: {\n queryFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n refetchMode?: 'append' | 'reset'\n}): QueryFunction<Array<TQueryFnData>, TQueryKey> {\n return async (context) => {\n if (refetchMode !== 'append') {\n const query = context.client\n .getQueryCache()\n .find({ queryKey: context.queryKey, exact: true })\n if (query && query.state.data !== undefined) {\n query.setState({\n status: 'pending',\n data: undefined,\n error: null,\n fetchStatus: 'fetching',\n })\n }\n }\n const stream = await queryFn(context)\n for await (const chunk of stream) {\n if (context.signal.aborted) {\n break\n }\n context.client.setQueryData<Array<TQueryFnData>>(\n context.queryKey,\n (prev = []) => {\n return prev.concat(chunk)\n },\n )\n }\n return context.client.getQueryData(context.queryKey)!\n }\n}\n"],"mappings":";;;AAUO,SAAS,cAGd;AAAA,EACA;AAAA,EACA;AACF,GAKkD;AAChD,SAAO,OAAO,YAAY;AACxB,QAAI,gBAAgB,UAAU;AAC5B,YAAM,QAAQ,QAAQ,OACnB,cAAc,EACd,KAAK,EAAE,UAAU,QAAQ,UAAU,OAAO,KAAK,CAAC;AACnD,UAAI,SAAS,MAAM,MAAM,SAAS,QAAW;AAC3C,cAAM,SAAS;AAAA,UACb,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,OAAO;AAAA,UACP,aAAa;AAAA,QACf,CAAC;AAAA,MACH;AAAA,IACF;AACA,UAAM,SAAS,MAAM,QAAQ,OAAO;AACpC,qBAAiB,SAAS,QAAQ;AAChC,UAAI,QAAQ,OAAO,SAAS;AAC1B;AAAA,MACF;AACA,cAAQ,OAAO;AAAA,QACb,QAAQ;AAAA,QACR,CAAC,OAAO,CAAC,MAAM;AACb,iBAAO,KAAK,OAAO,KAAK;AAAA,QAC1B;AAAA,MACF;AAAA,IACF;AACA,WAAO,QAAQ,OAAO,aAAa,QAAQ,QAAQ;AAAA,EACrD;AACF;","names":[]}
|
package/build/modern/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
defaultShouldDehydrateMutation: () => import_hydration.defaultShouldDehydrateMutation,
|
|
35
35
|
defaultShouldDehydrateQuery: () => import_hydration.defaultShouldDehydrateQuery,
|
|
36
36
|
dehydrate: () => import_hydration.dehydrate,
|
|
37
|
+
experimental_streamedQuery: () => import_streamedQuery.streamedQuery,
|
|
37
38
|
focusManager: () => import_focusManager.focusManager,
|
|
38
39
|
hashKey: () => import_utils.hashKey,
|
|
39
40
|
hydrate: () => import_hydration.hydrate,
|
|
@@ -62,6 +63,7 @@ var import_onlineManager = require("./onlineManager.cjs");
|
|
|
62
63
|
var import_utils = require("./utils.cjs");
|
|
63
64
|
var import_retryer2 = require("./retryer.cjs");
|
|
64
65
|
var import_hydration = require("./hydration.cjs");
|
|
66
|
+
var import_streamedQuery = require("./streamedQuery.cjs");
|
|
65
67
|
__reExport(src_exports, require("./types.cjs"), module.exports);
|
|
66
68
|
var import_query = require("./query.cjs");
|
|
67
69
|
var import_mutation = require("./mutation.cjs");
|
|
@@ -80,6 +82,7 @@ var import_mutation = require("./mutation.cjs");
|
|
|
80
82
|
defaultShouldDehydrateMutation,
|
|
81
83
|
defaultShouldDehydrateQuery,
|
|
82
84
|
dehydrate,
|
|
85
|
+
experimental_streamedQuery,
|
|
83
86
|
focusManager,
|
|
84
87
|
hashKey,
|
|
85
88
|
hydrate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\nexport { CancelledError } from './retryer'\nexport { QueryCache } from './queryCache'\nexport type { QueryCacheNotifyEvent } from './queryCache'\nexport { QueryClient } from './queryClient'\nexport { QueryObserver } from './queryObserver'\nexport { QueriesObserver } from './queriesObserver'\nexport { InfiniteQueryObserver } from './infiniteQueryObserver'\nexport { MutationCache } from './mutationCache'\nexport type { MutationCacheNotifyEvent } from './mutationCache'\nexport { MutationObserver } from './mutationObserver'\nexport { notifyManager } from './notifyManager'\nexport { focusManager } from './focusManager'\nexport { onlineManager } from './onlineManager'\nexport {\n hashKey,\n replaceEqualDeep,\n isServer,\n matchQuery,\n matchMutation,\n keepPreviousData,\n skipToken,\n} from './utils'\nexport type { MutationFilters, QueryFilters, Updater, SkipToken } from './utils'\nexport { isCancelledError } from './retryer'\nexport {\n dehydrate,\n hydrate,\n defaultShouldDehydrateQuery,\n defaultShouldDehydrateMutation,\n} from './hydration'\n\n// Types\nexport * from './types'\nexport type { QueryState } from './query'\nexport { Query } from './query'\nexport type { MutationState } from './mutation'\nexport { Mutation } from './mutation'\nexport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n} from './hydration'\nexport type { QueriesObserverOptions } from './queriesObserver'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAA+B;AAC/B,wBAA2B;AAE3B,yBAA4B;AAC5B,2BAA8B;AAC9B,6BAAgC;AAChC,mCAAsC;AACtC,2BAA8B;AAE9B,8BAAiC;AACjC,2BAA8B;AAC9B,0BAA6B;AAC7B,2BAA8B;AAC9B,mBAQO;AAEP,IAAAA,kBAAiC;AACjC,uBAKO;
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\nexport { CancelledError } from './retryer'\nexport { QueryCache } from './queryCache'\nexport type { QueryCacheNotifyEvent } from './queryCache'\nexport { QueryClient } from './queryClient'\nexport { QueryObserver } from './queryObserver'\nexport { QueriesObserver } from './queriesObserver'\nexport { InfiniteQueryObserver } from './infiniteQueryObserver'\nexport { MutationCache } from './mutationCache'\nexport type { MutationCacheNotifyEvent } from './mutationCache'\nexport { MutationObserver } from './mutationObserver'\nexport { notifyManager } from './notifyManager'\nexport { focusManager } from './focusManager'\nexport { onlineManager } from './onlineManager'\nexport {\n hashKey,\n replaceEqualDeep,\n isServer,\n matchQuery,\n matchMutation,\n keepPreviousData,\n skipToken,\n} from './utils'\nexport type { MutationFilters, QueryFilters, Updater, SkipToken } from './utils'\nexport { isCancelledError } from './retryer'\nexport {\n dehydrate,\n hydrate,\n defaultShouldDehydrateQuery,\n defaultShouldDehydrateMutation,\n} from './hydration'\n\nexport { streamedQuery as experimental_streamedQuery } from './streamedQuery'\n\n// Types\nexport * from './types'\nexport type { QueryState } from './query'\nexport { Query } from './query'\nexport type { MutationState } from './mutation'\nexport { Mutation } from './mutation'\nexport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n} from './hydration'\nexport type { QueriesObserverOptions } from './queriesObserver'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAA+B;AAC/B,wBAA2B;AAE3B,yBAA4B;AAC5B,2BAA8B;AAC9B,6BAAgC;AAChC,mCAAsC;AACtC,2BAA8B;AAE9B,8BAAiC;AACjC,2BAA8B;AAC9B,0BAA6B;AAC7B,2BAA8B;AAC9B,mBAQO;AAEP,IAAAA,kBAAiC;AACjC,uBAKO;AAEP,2BAA4D;AAG5D,wBAAc,wBApCd;AAsCA,mBAAsB;AAEtB,sBAAyB;","names":["import_retryer"]}
|
package/build/modern/index.d.cts
CHANGED
|
@@ -4,5 +4,6 @@ export { InfiniteQueryObserver } from './infiniteQueryObserver.cjs';
|
|
|
4
4
|
export { notifyManager } from './notifyManager.cjs';
|
|
5
5
|
export { focusManager } from './focusManager.cjs';
|
|
6
6
|
export { onlineManager } from './onlineManager.cjs';
|
|
7
|
+
export { streamedQuery as experimental_streamedQuery } from './streamedQuery.cjs';
|
|
7
8
|
import './removable.cjs';
|
|
8
9
|
import './subscribable.cjs';
|
package/build/modern/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export { InfiniteQueryObserver } from './infiniteQueryObserver.js';
|
|
|
4
4
|
export { notifyManager } from './notifyManager.js';
|
|
5
5
|
export { focusManager } from './focusManager.js';
|
|
6
6
|
export { onlineManager } from './onlineManager.js';
|
|
7
|
+
export { streamedQuery as experimental_streamedQuery } from './streamedQuery.js';
|
|
7
8
|
import './removable.js';
|
|
8
9
|
import './subscribable.js';
|
package/build/modern/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
defaultShouldDehydrateQuery,
|
|
27
27
|
defaultShouldDehydrateMutation
|
|
28
28
|
} from "./hydration.js";
|
|
29
|
+
import { streamedQuery } from "./streamedQuery.js";
|
|
29
30
|
export * from "./types.js";
|
|
30
31
|
import { Query } from "./query.js";
|
|
31
32
|
import { Mutation } from "./mutation.js";
|
|
@@ -43,6 +44,7 @@ export {
|
|
|
43
44
|
defaultShouldDehydrateMutation,
|
|
44
45
|
defaultShouldDehydrateQuery,
|
|
45
46
|
dehydrate,
|
|
47
|
+
streamedQuery as experimental_streamedQuery,
|
|
46
48
|
focusManager,
|
|
47
49
|
hashKey,
|
|
48
50
|
hydrate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\nexport { CancelledError } from './retryer'\nexport { QueryCache } from './queryCache'\nexport type { QueryCacheNotifyEvent } from './queryCache'\nexport { QueryClient } from './queryClient'\nexport { QueryObserver } from './queryObserver'\nexport { QueriesObserver } from './queriesObserver'\nexport { InfiniteQueryObserver } from './infiniteQueryObserver'\nexport { MutationCache } from './mutationCache'\nexport type { MutationCacheNotifyEvent } from './mutationCache'\nexport { MutationObserver } from './mutationObserver'\nexport { notifyManager } from './notifyManager'\nexport { focusManager } from './focusManager'\nexport { onlineManager } from './onlineManager'\nexport {\n hashKey,\n replaceEqualDeep,\n isServer,\n matchQuery,\n matchMutation,\n keepPreviousData,\n skipToken,\n} from './utils'\nexport type { MutationFilters, QueryFilters, Updater, SkipToken } from './utils'\nexport { isCancelledError } from './retryer'\nexport {\n dehydrate,\n hydrate,\n defaultShouldDehydrateQuery,\n defaultShouldDehydrateMutation,\n} from './hydration'\n\n// Types\nexport * from './types'\nexport type { QueryState } from './query'\nexport { Query } from './query'\nexport type { MutationState } from './mutation'\nexport { Mutation } from './mutation'\nexport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n} from './hydration'\nexport type { QueriesObserverOptions } from './queriesObserver'\n"],"mappings":";AAEA,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAE3B,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAE9B,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\nexport { CancelledError } from './retryer'\nexport { QueryCache } from './queryCache'\nexport type { QueryCacheNotifyEvent } from './queryCache'\nexport { QueryClient } from './queryClient'\nexport { QueryObserver } from './queryObserver'\nexport { QueriesObserver } from './queriesObserver'\nexport { InfiniteQueryObserver } from './infiniteQueryObserver'\nexport { MutationCache } from './mutationCache'\nexport type { MutationCacheNotifyEvent } from './mutationCache'\nexport { MutationObserver } from './mutationObserver'\nexport { notifyManager } from './notifyManager'\nexport { focusManager } from './focusManager'\nexport { onlineManager } from './onlineManager'\nexport {\n hashKey,\n replaceEqualDeep,\n isServer,\n matchQuery,\n matchMutation,\n keepPreviousData,\n skipToken,\n} from './utils'\nexport type { MutationFilters, QueryFilters, Updater, SkipToken } from './utils'\nexport { isCancelledError } from './retryer'\nexport {\n dehydrate,\n hydrate,\n defaultShouldDehydrateQuery,\n defaultShouldDehydrateMutation,\n} from './hydration'\n\nexport { streamedQuery as experimental_streamedQuery } from './streamedQuery'\n\n// Types\nexport * from './types'\nexport type { QueryState } from './query'\nexport { Query } from './query'\nexport type { MutationState } from './mutation'\nexport { Mutation } from './mutation'\nexport type {\n DehydrateOptions,\n DehydratedState,\n HydrateOptions,\n} from './hydration'\nexport type { QueriesObserverOptions } from './queriesObserver'\n"],"mappings":";AAEA,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAE3B,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAE9B,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAA0B,qBAAkC;AAG5D,cAAc;AAEd,SAAS,aAAa;AAEtB,SAAS,gBAAgB;","names":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/streamedQuery.ts
|
|
21
|
+
var streamedQuery_exports = {};
|
|
22
|
+
__export(streamedQuery_exports, {
|
|
23
|
+
streamedQuery: () => streamedQuery
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(streamedQuery_exports);
|
|
26
|
+
function streamedQuery({
|
|
27
|
+
queryFn,
|
|
28
|
+
refetchMode
|
|
29
|
+
}) {
|
|
30
|
+
return async (context) => {
|
|
31
|
+
if (refetchMode !== "append") {
|
|
32
|
+
const query = context.client.getQueryCache().find({ queryKey: context.queryKey, exact: true });
|
|
33
|
+
if (query && query.state.data !== void 0) {
|
|
34
|
+
query.setState({
|
|
35
|
+
status: "pending",
|
|
36
|
+
data: void 0,
|
|
37
|
+
error: null,
|
|
38
|
+
fetchStatus: "fetching"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const stream = await queryFn(context);
|
|
43
|
+
for await (const chunk of stream) {
|
|
44
|
+
if (context.signal.aborted) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
context.client.setQueryData(
|
|
48
|
+
context.queryKey,
|
|
49
|
+
(prev = []) => {
|
|
50
|
+
return prev.concat(chunk);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return context.client.getQueryData(context.queryKey);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
streamedQuery
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=streamedQuery.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import type { QueryFunction, QueryFunctionContext, QueryKey } from './types'\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param queryFn - The function that returns an AsyncIterable to stream data from.\n * @param refetchMode - Defaults to 'reset', which replaces data when a refetch happens. Set to 'append' to append new data to the existing data.\n */\nexport function streamedQuery<\n TQueryFnData = unknown,\n TQueryKey extends QueryKey = QueryKey,\n>({\n queryFn,\n refetchMode,\n}: {\n queryFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n refetchMode?: 'append' | 'reset'\n}): QueryFunction<Array<TQueryFnData>, TQueryKey> {\n return async (context) => {\n if (refetchMode !== 'append') {\n const query = context.client\n .getQueryCache()\n .find({ queryKey: context.queryKey, exact: true })\n if (query && query.state.data !== undefined) {\n query.setState({\n status: 'pending',\n data: undefined,\n error: null,\n fetchStatus: 'fetching',\n })\n }\n }\n const stream = await queryFn(context)\n for await (const chunk of stream) {\n if (context.signal.aborted) {\n break\n }\n context.client.setQueryData<Array<TQueryFnData>>(\n context.queryKey,\n (prev = []) => {\n return prev.concat(chunk)\n },\n )\n }\n return context.client.getQueryData(context.queryKey)!\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,SAAS,cAGd;AAAA,EACA;AAAA,EACA;AACF,GAKkD;AAChD,SAAO,OAAO,YAAY;AACxB,QAAI,gBAAgB,UAAU;AAC5B,YAAM,QAAQ,QAAQ,OACnB,cAAc,EACd,KAAK,EAAE,UAAU,QAAQ,UAAU,OAAO,KAAK,CAAC;AACnD,UAAI,SAAS,MAAM,MAAM,SAAS,QAAW;AAC3C,cAAM,SAAS;AAAA,UACb,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,OAAO;AAAA,UACP,aAAa;AAAA,QACf,CAAC;AAAA,MACH;AAAA,IACF;AACA,UAAM,SAAS,MAAM,QAAQ,OAAO;AACpC,qBAAiB,SAAS,QAAQ;AAChC,UAAI,QAAQ,OAAO,SAAS;AAC1B;AAAA,MACF;AACA,cAAQ,OAAO;AAAA,QACb,QAAQ;AAAA,QACR,CAAC,OAAO,CAAC,MAAM;AACb,iBAAO,KAAK,OAAO,KAAK;AAAA,QAC1B;AAAA,MACF;AAAA,IACF;AACA,WAAO,QAAQ,OAAO,aAAa,QAAQ,QAAQ;AAAA,EACrD;AACF;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { A as QueryKey, X as QueryFunctionContext, P as QueryFunction } from './hydration-BZgfn3GW.cjs';
|
|
2
|
+
import './removable.cjs';
|
|
3
|
+
import './subscribable.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This is a helper function to create a query function that streams data from an AsyncIterable.
|
|
7
|
+
* Data will be an Array of all the chunks received.
|
|
8
|
+
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
9
|
+
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
10
|
+
* @param queryFn - The function that returns an AsyncIterable to stream data from.
|
|
11
|
+
* @param refetchMode - Defaults to 'reset', which replaces data when a refetch happens. Set to 'append' to append new data to the existing data.
|
|
12
|
+
*/
|
|
13
|
+
declare function streamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>({ queryFn, refetchMode, }: {
|
|
14
|
+
queryFn: (context: QueryFunctionContext<TQueryKey>) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>;
|
|
15
|
+
refetchMode?: 'append' | 'reset';
|
|
16
|
+
}): QueryFunction<Array<TQueryFnData>, TQueryKey>;
|
|
17
|
+
|
|
18
|
+
export { streamedQuery };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { A as QueryKey, X as QueryFunctionContext, P as QueryFunction } from './hydration-B_mC2U5v.js';
|
|
2
|
+
import './removable.js';
|
|
3
|
+
import './subscribable.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This is a helper function to create a query function that streams data from an AsyncIterable.
|
|
7
|
+
* Data will be an Array of all the chunks received.
|
|
8
|
+
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
9
|
+
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
10
|
+
* @param queryFn - The function that returns an AsyncIterable to stream data from.
|
|
11
|
+
* @param refetchMode - Defaults to 'reset', which replaces data when a refetch happens. Set to 'append' to append new data to the existing data.
|
|
12
|
+
*/
|
|
13
|
+
declare function streamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>({ queryFn, refetchMode, }: {
|
|
14
|
+
queryFn: (context: QueryFunctionContext<TQueryKey>) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>;
|
|
15
|
+
refetchMode?: 'append' | 'reset';
|
|
16
|
+
}): QueryFunction<Array<TQueryFnData>, TQueryKey>;
|
|
17
|
+
|
|
18
|
+
export { streamedQuery };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/streamedQuery.ts
|
|
2
|
+
function streamedQuery({
|
|
3
|
+
queryFn,
|
|
4
|
+
refetchMode
|
|
5
|
+
}) {
|
|
6
|
+
return async (context) => {
|
|
7
|
+
if (refetchMode !== "append") {
|
|
8
|
+
const query = context.client.getQueryCache().find({ queryKey: context.queryKey, exact: true });
|
|
9
|
+
if (query && query.state.data !== void 0) {
|
|
10
|
+
query.setState({
|
|
11
|
+
status: "pending",
|
|
12
|
+
data: void 0,
|
|
13
|
+
error: null,
|
|
14
|
+
fetchStatus: "fetching"
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const stream = await queryFn(context);
|
|
19
|
+
for await (const chunk of stream) {
|
|
20
|
+
if (context.signal.aborted) {
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
context.client.setQueryData(
|
|
24
|
+
context.queryKey,
|
|
25
|
+
(prev = []) => {
|
|
26
|
+
return prev.concat(chunk);
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return context.client.getQueryData(context.queryKey);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
streamedQuery
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=streamedQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import type { QueryFunction, QueryFunctionContext, QueryKey } from './types'\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param queryFn - The function that returns an AsyncIterable to stream data from.\n * @param refetchMode - Defaults to 'reset', which replaces data when a refetch happens. Set to 'append' to append new data to the existing data.\n */\nexport function streamedQuery<\n TQueryFnData = unknown,\n TQueryKey extends QueryKey = QueryKey,\n>({\n queryFn,\n refetchMode,\n}: {\n queryFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n refetchMode?: 'append' | 'reset'\n}): QueryFunction<Array<TQueryFnData>, TQueryKey> {\n return async (context) => {\n if (refetchMode !== 'append') {\n const query = context.client\n .getQueryCache()\n .find({ queryKey: context.queryKey, exact: true })\n if (query && query.state.data !== undefined) {\n query.setState({\n status: 'pending',\n data: undefined,\n error: null,\n fetchStatus: 'fetching',\n })\n }\n }\n const stream = await queryFn(context)\n for await (const chunk of stream) {\n if (context.signal.aborted) {\n break\n }\n context.client.setQueryData<Array<TQueryFnData>>(\n context.queryKey,\n (prev = []) => {\n return prev.concat(chunk)\n },\n )\n }\n return context.client.getQueryData(context.queryKey)!\n }\n}\n"],"mappings":";AAUO,SAAS,cAGd;AAAA,EACA;AAAA,EACA;AACF,GAKkD;AAChD,SAAO,OAAO,YAAY;AACxB,QAAI,gBAAgB,UAAU;AAC5B,YAAM,QAAQ,QAAQ,OACnB,cAAc,EACd,KAAK,EAAE,UAAU,QAAQ,UAAU,OAAO,KAAK,CAAC;AACnD,UAAI,SAAS,MAAM,MAAM,SAAS,QAAW;AAC3C,cAAM,SAAS;AAAA,UACb,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,OAAO;AAAA,UACP,aAAa;AAAA,QACf,CAAC;AAAA,MACH;AAAA,IACF;AACA,UAAM,SAAS,MAAM,QAAQ,OAAO;AACpC,qBAAiB,SAAS,QAAQ;AAChC,UAAI,QAAQ,OAAO,SAAS;AAC1B;AAAA,MACF;AACA,cAAQ,OAAO;AAAA,QACb,QAAQ;AAAA,QACR,CAAC,OAAO,CAAC,MAAM;AACb,iBAAO,KAAK,OAAO,KAAK;AAAA,QAC1B;AAAA,MACF;AAAA,IACF;AACA,WAAO,QAAQ,OAAO,aAAa,QAAQ,QAAQ;AAAA,EACrD;AACF;","names":[]}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { QueryFunction, QueryFunctionContext, QueryKey } from './types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is a helper function to create a query function that streams data from an AsyncIterable.
|
|
5
|
+
* Data will be an Array of all the chunks received.
|
|
6
|
+
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
7
|
+
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
8
|
+
* @param queryFn - The function that returns an AsyncIterable to stream data from.
|
|
9
|
+
* @param refetchMode - Defaults to 'reset', which replaces data when a refetch happens. Set to 'append' to append new data to the existing data.
|
|
10
|
+
*/
|
|
11
|
+
export function streamedQuery<
|
|
12
|
+
TQueryFnData = unknown,
|
|
13
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
14
|
+
>({
|
|
15
|
+
queryFn,
|
|
16
|
+
refetchMode,
|
|
17
|
+
}: {
|
|
18
|
+
queryFn: (
|
|
19
|
+
context: QueryFunctionContext<TQueryKey>,
|
|
20
|
+
) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>
|
|
21
|
+
refetchMode?: 'append' | 'reset'
|
|
22
|
+
}): QueryFunction<Array<TQueryFnData>, TQueryKey> {
|
|
23
|
+
return async (context) => {
|
|
24
|
+
if (refetchMode !== 'append') {
|
|
25
|
+
const query = context.client
|
|
26
|
+
.getQueryCache()
|
|
27
|
+
.find({ queryKey: context.queryKey, exact: true })
|
|
28
|
+
if (query && query.state.data !== undefined) {
|
|
29
|
+
query.setState({
|
|
30
|
+
status: 'pending',
|
|
31
|
+
data: undefined,
|
|
32
|
+
error: null,
|
|
33
|
+
fetchStatus: 'fetching',
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const stream = await queryFn(context)
|
|
38
|
+
for await (const chunk of stream) {
|
|
39
|
+
if (context.signal.aborted) {
|
|
40
|
+
break
|
|
41
|
+
}
|
|
42
|
+
context.client.setQueryData<Array<TQueryFnData>>(
|
|
43
|
+
context.queryKey,
|
|
44
|
+
(prev = []) => {
|
|
45
|
+
return prev.concat(chunk)
|
|
46
|
+
},
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
return context.client.getQueryData(context.queryKey)!
|
|
50
|
+
}
|
|
51
|
+
}
|