@tanstack/query-core 4.39.0 → 4.39.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/build/lib/focusManager.esm.js +91 -0
- package/build/lib/focusManager.esm.js.map +1 -0
- package/build/lib/focusManager.js +96 -0
- package/build/lib/focusManager.js.map +1 -0
- package/build/lib/focusManager.mjs +91 -0
- package/build/lib/focusManager.mjs.map +1 -0
- package/build/lib/hydration.esm.js +109 -0
- package/build/lib/hydration.esm.js.map +1 -0
- package/build/lib/hydration.js +116 -0
- package/build/lib/hydration.js.map +1 -0
- package/build/lib/hydration.mjs +109 -0
- package/build/lib/hydration.mjs.map +1 -0
- package/build/lib/index.esm.js +15 -0
- package/build/lib/index.esm.js.map +1 -0
- package/build/lib/index.js +48 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/index.mjs +15 -0
- package/build/lib/index.mjs.map +1 -0
- package/build/lib/infiniteQueryBehavior.esm.js +146 -0
- package/build/lib/infiniteQueryBehavior.esm.js.map +1 -0
- package/build/lib/infiniteQueryBehavior.js +154 -0
- package/build/lib/infiniteQueryBehavior.js.map +1 -0
- package/build/lib/infiniteQueryBehavior.mjs +146 -0
- package/build/lib/infiniteQueryBehavior.mjs.map +1 -0
- package/build/lib/infiniteQueryObserver.esm.js +85 -0
- package/build/lib/infiniteQueryObserver.esm.js.map +1 -0
- package/build/lib/infiniteQueryObserver.js +89 -0
- package/build/lib/infiniteQueryObserver.js.map +1 -0
- package/build/lib/infiniteQueryObserver.mjs +85 -0
- package/build/lib/infiniteQueryObserver.mjs.map +1 -0
- package/build/lib/logger.esm.js +4 -0
- package/build/lib/logger.esm.js.map +1 -0
- package/build/lib/logger.js +8 -0
- package/build/lib/logger.js.map +1 -0
- package/build/lib/logger.mjs +4 -0
- package/build/lib/logger.mjs.map +1 -0
- package/build/lib/logger.native.esm.js +12 -0
- package/build/lib/logger.native.esm.js.map +1 -0
- package/build/lib/logger.native.js +16 -0
- package/build/lib/logger.native.js.map +1 -0
- package/build/lib/logger.native.mjs +12 -0
- package/build/lib/logger.native.mjs.map +1 -0
- package/build/lib/mutation.esm.js +261 -0
- package/build/lib/mutation.esm.js.map +1 -0
- package/build/lib/mutation.js +266 -0
- package/build/lib/mutation.js.map +1 -0
- package/build/lib/mutation.mjs +261 -0
- package/build/lib/mutation.mjs.map +1 -0
- package/build/lib/mutationCache.esm.js +93 -0
- package/build/lib/mutationCache.esm.js.map +1 -0
- package/build/lib/mutationCache.js +97 -0
- package/build/lib/mutationCache.js.map +1 -0
- package/build/lib/mutationCache.mjs +93 -0
- package/build/lib/mutationCache.mjs.map +1 -0
- package/build/lib/mutationObserver.esm.js +134 -0
- package/build/lib/mutationObserver.esm.js.map +1 -0
- package/build/lib/mutationObserver.js +138 -0
- package/build/lib/mutationObserver.js.map +1 -0
- package/build/lib/mutationObserver.mjs +134 -0
- package/build/lib/mutationObserver.mjs.map +1 -0
- package/build/lib/notifyManager.esm.js +99 -0
- package/build/lib/notifyManager.esm.js.map +1 -0
- package/build/lib/notifyManager.js +104 -0
- package/build/lib/notifyManager.js.map +1 -0
- package/build/lib/notifyManager.mjs +99 -0
- package/build/lib/notifyManager.mjs.map +1 -0
- package/build/lib/onlineManager.esm.js +93 -0
- package/build/lib/onlineManager.esm.js.map +1 -0
- package/build/lib/onlineManager.js +98 -0
- package/build/lib/onlineManager.js.map +1 -0
- package/build/lib/onlineManager.mjs +93 -0
- package/build/lib/onlineManager.mjs.map +1 -0
- package/build/lib/queriesObserver.esm.js +168 -0
- package/build/lib/queriesObserver.esm.js.map +1 -0
- package/build/lib/queriesObserver.js +172 -0
- package/build/lib/queriesObserver.js.map +1 -0
- package/build/lib/queriesObserver.mjs +168 -0
- package/build/lib/queriesObserver.mjs.map +1 -0
- package/build/lib/query.esm.js +475 -0
- package/build/lib/query.esm.js.map +1 -0
- package/build/lib/query.js +479 -0
- package/build/lib/query.js.map +1 -0
- package/build/lib/query.mjs +475 -0
- package/build/lib/query.mjs.map +1 -0
- package/build/lib/queryCache.esm.js +133 -0
- package/build/lib/queryCache.esm.js.map +1 -0
- package/build/lib/queryCache.js +137 -0
- package/build/lib/queryCache.js.map +1 -0
- package/build/lib/queryCache.mjs +133 -0
- package/build/lib/queryCache.mjs.map +1 -0
- package/build/lib/queryClient.esm.js +402 -0
- package/build/lib/queryClient.esm.js.map +1 -0
- package/build/lib/queryClient.js +406 -0
- package/build/lib/queryClient.js.map +1 -0
- package/build/lib/queryClient.mjs +402 -0
- package/build/lib/queryClient.mjs.map +1 -0
- package/build/lib/queryObserver.esm.js +580 -0
- package/build/lib/queryObserver.esm.js.map +1 -0
- package/build/lib/queryObserver.js +584 -0
- package/build/lib/queryObserver.js.map +1 -0
- package/build/lib/queryObserver.mjs +580 -0
- package/build/lib/queryObserver.mjs.map +1 -0
- package/build/lib/removable.esm.js +33 -0
- package/build/lib/removable.esm.js.map +1 -0
- package/build/lib/removable.js +37 -0
- package/build/lib/removable.js.map +1 -0
- package/build/lib/removable.mjs +33 -0
- package/build/lib/removable.mjs.map +1 -0
- package/build/lib/retryer.esm.js +167 -0
- package/build/lib/retryer.esm.js.map +1 -0
- package/build/lib/retryer.js +174 -0
- package/build/lib/retryer.js.map +1 -0
- package/build/lib/retryer.mjs +167 -0
- package/build/lib/retryer.mjs.map +1 -0
- package/build/lib/subscribable.esm.js +32 -0
- package/build/lib/subscribable.esm.js.map +1 -0
- package/build/lib/subscribable.js +36 -0
- package/build/lib/subscribable.js.map +1 -0
- package/build/lib/subscribable.mjs +32 -0
- package/build/lib/subscribable.mjs.map +1 -0
- package/build/lib/types.d.ts +1 -0
- package/build/lib/utils.esm.js +320 -0
- package/build/lib/utils.esm.js.map +1 -0
- package/build/lib/utils.js +350 -0
- package/build/lib/utils.js.map +1 -0
- package/build/lib/utils.mjs +320 -0
- package/build/lib/utils.mjs.map +1 -0
- package/build/umd/index.development.js +3361 -0
- package/build/umd/index.development.js.map +1 -0
- package/build/umd/index.production.js +2 -0
- package/build/umd/index.production.js.map +1 -0
- package/package.json +1 -1
- package/src/types.ts +5 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { focusManager } from './focusManager.mjs';
|
|
2
|
+
import { onlineManager } from './onlineManager.mjs';
|
|
3
|
+
import { sleep } from './utils.mjs';
|
|
4
|
+
|
|
5
|
+
function defaultRetryDelay(failureCount) {
|
|
6
|
+
return Math.min(1000 * 2 ** failureCount, 30000);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function canFetch(networkMode) {
|
|
10
|
+
return (networkMode != null ? networkMode : 'online') === 'online' ? onlineManager.isOnline() : true;
|
|
11
|
+
}
|
|
12
|
+
class CancelledError {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.revert = options == null ? void 0 : options.revert;
|
|
15
|
+
this.silent = options == null ? void 0 : options.silent;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
function isCancelledError(value) {
|
|
20
|
+
return value instanceof CancelledError;
|
|
21
|
+
}
|
|
22
|
+
function createRetryer(config) {
|
|
23
|
+
let isRetryCancelled = false;
|
|
24
|
+
let failureCount = 0;
|
|
25
|
+
let isResolved = false;
|
|
26
|
+
let continueFn;
|
|
27
|
+
let promiseResolve;
|
|
28
|
+
let promiseReject;
|
|
29
|
+
const promise = new Promise((outerResolve, outerReject) => {
|
|
30
|
+
promiseResolve = outerResolve;
|
|
31
|
+
promiseReject = outerReject;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const cancel = cancelOptions => {
|
|
35
|
+
if (!isResolved) {
|
|
36
|
+
reject(new CancelledError(cancelOptions));
|
|
37
|
+
config.abort == null ? void 0 : config.abort();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const cancelRetry = () => {
|
|
42
|
+
isRetryCancelled = true;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const continueRetry = () => {
|
|
46
|
+
isRetryCancelled = false;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const shouldPause = () => !focusManager.isFocused() || config.networkMode !== 'always' && !onlineManager.isOnline();
|
|
50
|
+
|
|
51
|
+
const resolve = value => {
|
|
52
|
+
if (!isResolved) {
|
|
53
|
+
isResolved = true;
|
|
54
|
+
config.onSuccess == null ? void 0 : config.onSuccess(value);
|
|
55
|
+
continueFn == null ? void 0 : continueFn();
|
|
56
|
+
promiseResolve(value);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const reject = value => {
|
|
61
|
+
if (!isResolved) {
|
|
62
|
+
isResolved = true;
|
|
63
|
+
config.onError == null ? void 0 : config.onError(value);
|
|
64
|
+
continueFn == null ? void 0 : continueFn();
|
|
65
|
+
promiseReject(value);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const pause = () => {
|
|
70
|
+
return new Promise(continueResolve => {
|
|
71
|
+
continueFn = value => {
|
|
72
|
+
const canContinue = isResolved || !shouldPause();
|
|
73
|
+
|
|
74
|
+
if (canContinue) {
|
|
75
|
+
continueResolve(value);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return canContinue;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
config.onPause == null ? void 0 : config.onPause();
|
|
82
|
+
}).then(() => {
|
|
83
|
+
continueFn = undefined;
|
|
84
|
+
|
|
85
|
+
if (!isResolved) {
|
|
86
|
+
config.onContinue == null ? void 0 : config.onContinue();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}; // Create loop function
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
const run = () => {
|
|
93
|
+
// Do nothing if already resolved
|
|
94
|
+
if (isResolved) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let promiseOrValue; // Execute query
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
promiseOrValue = config.fn();
|
|
102
|
+
} catch (error) {
|
|
103
|
+
promiseOrValue = Promise.reject(error);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
Promise.resolve(promiseOrValue).then(resolve).catch(error => {
|
|
107
|
+
var _config$retry, _config$retryDelay;
|
|
108
|
+
|
|
109
|
+
// Stop if the fetch is already resolved
|
|
110
|
+
if (isResolved) {
|
|
111
|
+
return;
|
|
112
|
+
} // Do we need to retry the request?
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
const retry = (_config$retry = config.retry) != null ? _config$retry : 3;
|
|
116
|
+
const retryDelay = (_config$retryDelay = config.retryDelay) != null ? _config$retryDelay : defaultRetryDelay;
|
|
117
|
+
const delay = typeof retryDelay === 'function' ? retryDelay(failureCount, error) : retryDelay;
|
|
118
|
+
const shouldRetry = retry === true || typeof retry === 'number' && failureCount < retry || typeof retry === 'function' && retry(failureCount, error);
|
|
119
|
+
|
|
120
|
+
if (isRetryCancelled || !shouldRetry) {
|
|
121
|
+
// We are done if the query does not need to be retried
|
|
122
|
+
reject(error);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
failureCount++; // Notify on fail
|
|
127
|
+
|
|
128
|
+
config.onFail == null ? void 0 : config.onFail(failureCount, error); // Delay
|
|
129
|
+
|
|
130
|
+
sleep(delay) // Pause if the document is not visible or when the device is offline
|
|
131
|
+
.then(() => {
|
|
132
|
+
if (shouldPause()) {
|
|
133
|
+
return pause();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return;
|
|
137
|
+
}).then(() => {
|
|
138
|
+
if (isRetryCancelled) {
|
|
139
|
+
reject(error);
|
|
140
|
+
} else {
|
|
141
|
+
run();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}; // Start loop
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
if (canFetch(config.networkMode)) {
|
|
149
|
+
run();
|
|
150
|
+
} else {
|
|
151
|
+
pause().then(run);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
promise,
|
|
156
|
+
cancel,
|
|
157
|
+
continue: () => {
|
|
158
|
+
const didContinue = continueFn == null ? void 0 : continueFn();
|
|
159
|
+
return didContinue ? promise : Promise.resolve();
|
|
160
|
+
},
|
|
161
|
+
cancelRetry,
|
|
162
|
+
continueRetry
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { CancelledError, canFetch, createRetryer, isCancelledError };
|
|
167
|
+
//# sourceMappingURL=retryer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retryer.mjs","sources":["../../src/retryer.ts"],"sourcesContent":["import { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { sleep } from './utils'\nimport type { CancelOptions, NetworkMode } from './types'\n\n// TYPES\n\ninterface RetryerConfig<TData = unknown, TError = unknown> {\n fn: () => TData | Promise<TData>\n abort?: () => void\n onError?: (error: TError) => void\n onSuccess?: (data: TData) => void\n onFail?: (failureCount: number, error: TError) => void\n onPause?: () => void\n onContinue?: () => void\n retry?: RetryValue<TError>\n retryDelay?: RetryDelayValue<TError>\n networkMode: NetworkMode | undefined\n}\n\nexport interface Retryer<TData = unknown> {\n promise: Promise<TData>\n cancel: (cancelOptions?: CancelOptions) => void\n continue: () => Promise<unknown>\n cancelRetry: () => void\n continueRetry: () => void\n}\n\nexport type RetryValue<TError> = boolean | number | ShouldRetryFunction<TError>\n\ntype ShouldRetryFunction<TError> = (\n failureCount: number,\n error: TError,\n) => boolean\n\nexport type RetryDelayValue<TError> = number | RetryDelayFunction<TError>\n\ntype RetryDelayFunction<TError = unknown> = (\n failureCount: number,\n error: TError,\n) => number\n\nfunction defaultRetryDelay(failureCount: number) {\n return Math.min(1000 * 2 ** failureCount, 30000)\n}\n\nexport function canFetch(networkMode: NetworkMode | undefined): boolean {\n return (networkMode ?? 'online') === 'online'\n ? onlineManager.isOnline()\n : true\n}\n\nexport class CancelledError {\n revert?: boolean\n silent?: boolean\n constructor(options?: CancelOptions) {\n this.revert = options?.revert\n this.silent = options?.silent\n }\n}\n\nexport function isCancelledError(value: any): value is CancelledError {\n return value instanceof CancelledError\n}\n\nexport function createRetryer<TData = unknown, TError = unknown>(\n config: RetryerConfig<TData, TError>,\n): Retryer<TData> {\n let isRetryCancelled = false\n let failureCount = 0\n let isResolved = false\n let continueFn: ((value?: unknown) => boolean) | undefined\n let promiseResolve: (data: TData) => void\n let promiseReject: (error: TError) => void\n\n const promise = new Promise<TData>((outerResolve, outerReject) => {\n promiseResolve = outerResolve\n promiseReject = outerReject\n })\n\n const cancel = (cancelOptions?: CancelOptions): void => {\n if (!isResolved) {\n reject(new CancelledError(cancelOptions))\n\n config.abort?.()\n }\n }\n const cancelRetry = () => {\n isRetryCancelled = true\n }\n\n const continueRetry = () => {\n isRetryCancelled = false\n }\n\n const shouldPause = () =>\n !focusManager.isFocused() ||\n (config.networkMode !== 'always' && !onlineManager.isOnline())\n\n const resolve = (value: any) => {\n if (!isResolved) {\n isResolved = true\n config.onSuccess?.(value)\n continueFn?.()\n promiseResolve(value)\n }\n }\n\n const reject = (value: any) => {\n if (!isResolved) {\n isResolved = true\n config.onError?.(value)\n continueFn?.()\n promiseReject(value)\n }\n }\n\n const pause = () => {\n return new Promise((continueResolve) => {\n continueFn = (value) => {\n const canContinue = isResolved || !shouldPause()\n if (canContinue) {\n continueResolve(value)\n }\n return canContinue\n }\n config.onPause?.()\n }).then(() => {\n continueFn = undefined\n if (!isResolved) {\n config.onContinue?.()\n }\n })\n }\n\n // Create loop function\n const run = () => {\n // Do nothing if already resolved\n if (isResolved) {\n return\n }\n\n let promiseOrValue: any\n\n // Execute query\n try {\n promiseOrValue = config.fn()\n } catch (error) {\n promiseOrValue = Promise.reject(error)\n }\n\n Promise.resolve(promiseOrValue)\n .then(resolve)\n .catch((error) => {\n // Stop if the fetch is already resolved\n if (isResolved) {\n return\n }\n\n // Do we need to retry the request?\n const retry = config.retry ?? 3\n const retryDelay = config.retryDelay ?? defaultRetryDelay\n const delay =\n typeof retryDelay === 'function'\n ? retryDelay(failureCount, error)\n : retryDelay\n const shouldRetry =\n retry === true ||\n (typeof retry === 'number' && failureCount < retry) ||\n (typeof retry === 'function' && retry(failureCount, error))\n\n if (isRetryCancelled || !shouldRetry) {\n // We are done if the query does not need to be retried\n reject(error)\n return\n }\n\n failureCount++\n\n // Notify on fail\n config.onFail?.(failureCount, error)\n\n // Delay\n sleep(delay)\n // Pause if the document is not visible or when the device is offline\n .then(() => {\n if (shouldPause()) {\n return pause()\n }\n return\n })\n .then(() => {\n if (isRetryCancelled) {\n reject(error)\n } else {\n run()\n }\n })\n })\n }\n\n // Start loop\n if (canFetch(config.networkMode)) {\n run()\n } else {\n pause().then(run)\n }\n\n return {\n promise,\n cancel,\n continue: () => {\n const didContinue = continueFn?.()\n return didContinue ? promise : Promise.resolve()\n },\n cancelRetry,\n continueRetry,\n }\n}\n"],"names":["defaultRetryDelay","failureCount","Math","min","canFetch","networkMode","onlineManager","isOnline","CancelledError","constructor","options","revert","silent","isCancelledError","value","createRetryer","config","isRetryCancelled","isResolved","continueFn","promiseResolve","promiseReject","promise","Promise","outerResolve","outerReject","cancel","cancelOptions","reject","abort","cancelRetry","continueRetry","shouldPause","focusManager","isFocused","resolve","onSuccess","onError","pause","continueResolve","canContinue","onPause","then","undefined","onContinue","run","promiseOrValue","fn","error","catch","retry","retryDelay","delay","shouldRetry","onFail","sleep","continue","didContinue"],"mappings":";;;;AA0CA,SAASA,iBAAT,CAA2BC,YAA3B,EAAiD;EAC/C,OAAOC,IAAI,CAACC,GAAL,CAAS,OAAO,CAAKF,IAAAA,YAArB,EAAmC,KAAnC,CAAP,CAAA;AACD,CAAA;;AAEM,SAASG,QAAT,CAAkBC,WAAlB,EAAiE;AACtE,EAAA,OAAO,CAACA,WAAD,IAACA,IAAAA,GAAAA,WAAD,GAAgB,QAAhB,MAA8B,QAA9B,GACHC,aAAa,CAACC,QAAd,EADG,GAEH,IAFJ,CAAA;AAGD,CAAA;AAEM,MAAMC,cAAN,CAAqB;EAG1BC,W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OAAR,EAA/B,CAAA;KALG;IAOLL,WAPK;AAQLC,IAAAA,aAAAA;GARF,CAAA;AAUD;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
class Subscribable {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.listeners = new Set();
|
|
4
|
+
this.subscribe = this.subscribe.bind(this);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
subscribe(listener) {
|
|
8
|
+
const identity = {
|
|
9
|
+
listener
|
|
10
|
+
};
|
|
11
|
+
this.listeners.add(identity);
|
|
12
|
+
this.onSubscribe();
|
|
13
|
+
return () => {
|
|
14
|
+
this.listeners.delete(identity);
|
|
15
|
+
this.onUnsubscribe();
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
hasListeners() {
|
|
20
|
+
return this.listeners.size > 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
onSubscribe() {// Do nothing
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
onUnsubscribe() {// Do nothing
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { Subscribable };
|
|
32
|
+
//# sourceMappingURL=subscribable.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribable.esm.js","sources":["../../src/subscribable.ts"],"sourcesContent":["type Listener = () => void\n\nexport class Subscribable<TListener extends Function = Listener> {\n protected listeners: Set<{ listener: TListener }>\n\n constructor() {\n this.listeners = new Set()\n this.subscribe = this.subscribe.bind(this)\n }\n\n subscribe(listener: TListener): () => void {\n const identity = { listener }\n this.listeners.add(identity)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(identity)\n this.onUnsubscribe()\n }\n }\n\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n protected onSubscribe(): void {\n // Do nothing\n }\n\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"names":["Subscribable","constructor","listeners","Set","subscribe","bind","listener","identity","add","onSubscribe","delete","onUnsubscribe","hasListeners","size"],"mappings":"AAEO,MAAMA,YAAN,CAA0D;AAG/DC,EAAAA,WAAW,GAAG;AACZ,IAAA,IAAA,CAAKC,SAAL,GAAiB,IAAIC,GAAJ,EAAjB,CAAA;IACA,IAAKC,CAAAA,SAAL,GAAiB,IAAKA,CAAAA,SAAL,CAAeC,IAAf,CAAoB,IAApB,CAAjB,CAAA;AACD,GAAA;;EAEDD,SAAS,CAACE,QAAD,EAAkC;AACzC,IAAA,MAAMC,QAAQ,GAAG;AAAED,MAAAA,QAAAA;KAAnB,CAAA;AACA,IAAA,IAAA,CAAKJ,SAAL,CAAeM,GAAf,CAAmBD,QAAnB,CAAA,CAAA;AAEA,IAAA,IAAA,CAAKE,WAAL,EAAA,CAAA;AAEA,IAAA,OAAO,MAAM;AACX,MAAA,IAAA,CAAKP,SAAL,CAAeQ,MAAf,CAAsBH,QAAtB,CAAA,CAAA;AACA,MAAA,IAAA,CAAKI,aAAL,EAAA,CAAA;KAFF,CAAA;AAID,GAAA;;AAEDC,EAAAA,YAAY,GAAY;AACtB,IAAA,OAAO,IAAKV,CAAAA,SAAL,CAAeW,IAAf,GAAsB,CAA7B,CAAA;AACD,GAAA;;AAESJ,EAAAA,WAAW,GAAS;AAE7B,GAAA;;AAESE,EAAAA,aAAa,GAAS;AAE/B,GAAA;;AA9B8D;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
class Subscribable {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.listeners = new Set();
|
|
8
|
+
this.subscribe = this.subscribe.bind(this);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
subscribe(listener) {
|
|
12
|
+
const identity = {
|
|
13
|
+
listener
|
|
14
|
+
};
|
|
15
|
+
this.listeners.add(identity);
|
|
16
|
+
this.onSubscribe();
|
|
17
|
+
return () => {
|
|
18
|
+
this.listeners.delete(identity);
|
|
19
|
+
this.onUnsubscribe();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
hasListeners() {
|
|
24
|
+
return this.listeners.size > 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
onSubscribe() {// Do nothing
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onUnsubscribe() {// Do nothing
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.Subscribable = Subscribable;
|
|
36
|
+
//# sourceMappingURL=subscribable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribable.js","sources":["../../src/subscribable.ts"],"sourcesContent":["type Listener = () => void\n\nexport class Subscribable<TListener extends Function = Listener> {\n protected listeners: Set<{ listener: TListener }>\n\n constructor() {\n this.listeners = new Set()\n this.subscribe = this.subscribe.bind(this)\n }\n\n subscribe(listener: TListener): () => void {\n const identity = { listener }\n this.listeners.add(identity)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(identity)\n this.onUnsubscribe()\n }\n }\n\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n protected onSubscribe(): void {\n // Do nothing\n }\n\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"names":["Subscribable","constructor","listeners","Set","subscribe","bind","listener","identity","add","onSubscribe","delete","onUnsubscribe","hasListeners","size"],"mappings":";;;;AAEO,MAAMA,YAAN,CAA0D;AAG/DC,EAAAA,WAAW,GAAG;AACZ,IAAA,IAAA,CAAKC,SAAL,GAAiB,IAAIC,GAAJ,EAAjB,CAAA;IACA,IAAKC,CAAAA,SAAL,GAAiB,IAAKA,CAAAA,SAAL,CAAeC,IAAf,CAAoB,IAApB,CAAjB,CAAA;AACD,GAAA;;EAEDD,SAAS,CAACE,QAAD,EAAkC;AACzC,IAAA,MAAMC,QAAQ,GAAG;AAAED,MAAAA,QAAAA;KAAnB,CAAA;AACA,IAAA,IAAA,CAAKJ,SAAL,CAAeM,GAAf,CAAmBD,QAAnB,CAAA,CAAA;AAEA,IAAA,IAAA,CAAKE,WAAL,EAAA,CAAA;AAEA,IAAA,OAAO,MAAM;AACX,MAAA,IAAA,CAAKP,SAAL,CAAeQ,MAAf,CAAsBH,QAAtB,CAAA,CAAA;AACA,MAAA,IAAA,CAAKI,aAAL,EAAA,CAAA;KAFF,CAAA;AAID,GAAA;;AAEDC,EAAAA,YAAY,GAAY;AACtB,IAAA,OAAO,IAAKV,CAAAA,SAAL,CAAeW,IAAf,GAAsB,CAA7B,CAAA;AACD,GAAA;;AAESJ,EAAAA,WAAW,GAAS;AAE7B,GAAA;;AAESE,EAAAA,aAAa,GAAS;AAE/B,GAAA;;AA9B8D;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
class Subscribable {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.listeners = new Set();
|
|
4
|
+
this.subscribe = this.subscribe.bind(this);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
subscribe(listener) {
|
|
8
|
+
const identity = {
|
|
9
|
+
listener
|
|
10
|
+
};
|
|
11
|
+
this.listeners.add(identity);
|
|
12
|
+
this.onSubscribe();
|
|
13
|
+
return () => {
|
|
14
|
+
this.listeners.delete(identity);
|
|
15
|
+
this.onUnsubscribe();
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
hasListeners() {
|
|
20
|
+
return this.listeners.size > 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
onSubscribe() {// Do nothing
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
onUnsubscribe() {// Do nothing
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { Subscribable };
|
|
32
|
+
//# sourceMappingURL=subscribable.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribable.mjs","sources":["../../src/subscribable.ts"],"sourcesContent":["type Listener = () => void\n\nexport class Subscribable<TListener extends Function = Listener> {\n protected listeners: Set<{ listener: TListener }>\n\n constructor() {\n this.listeners = new Set()\n this.subscribe = this.subscribe.bind(this)\n }\n\n subscribe(listener: TListener): () => void {\n const identity = { listener }\n this.listeners.add(identity)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(identity)\n this.onUnsubscribe()\n }\n }\n\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n protected onSubscribe(): void {\n // Do nothing\n }\n\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"names":["Subscribable","constructor","listeners","Set","subscribe","bind","listener","identity","add","onSubscribe","delete","onUnsubscribe","hasListeners","size"],"mappings":"AAEO,MAAMA,YAAN,CAA0D;AAG/DC,EAAAA,WAAW,GAAG;AACZ,IAAA,IAAA,CAAKC,SAAL,GAAiB,IAAIC,GAAJ,EAAjB,CAAA;IACA,IAAKC,CAAAA,SAAL,GAAiB,IAAKA,CAAAA,SAAL,CAAeC,IAAf,CAAoB,IAApB,CAAjB,CAAA;AACD,GAAA;;EAEDD,SAAS,CAACE,QAAD,EAAkC;AACzC,IAAA,MAAMC,QAAQ,GAAG;AAAED,MAAAA,QAAAA;KAAnB,CAAA;AACA,IAAA,IAAA,CAAKJ,SAAL,CAAeM,GAAf,CAAmBD,QAAnB,CAAA,CAAA;AAEA,IAAA,IAAA,CAAKE,WAAL,EAAA,CAAA;AAEA,IAAA,OAAO,MAAM;AACX,MAAA,IAAA,CAAKP,SAAL,CAAeQ,MAAf,CAAsBH,QAAtB,CAAA,CAAA;AACA,MAAA,IAAA,CAAKI,aAAL,EAAA,CAAA;KAFF,CAAA;AAID,GAAA;;AAEDC,EAAAA,YAAY,GAAY;AACtB,IAAA,OAAO,IAAKV,CAAAA,SAAL,CAAeW,IAAf,GAAsB,CAA7B,CAAA;AACD,GAAA;;AAESJ,EAAAA,WAAW,GAAS;AAE7B,GAAA;;AAESE,EAAAA,aAAa,GAAS;AAE/B,GAAA;;AA9B8D;;;;"}
|
package/build/lib/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { QueryCache } from './queryCache';
|
|
|
6
6
|
import type { MutationCache } from './mutationCache';
|
|
7
7
|
import type { Logger } from './logger';
|
|
8
8
|
export declare type NonUndefinedGuard<T> = T extends undefined ? never : T;
|
|
9
|
+
export declare type DistributiveOmit<TObject, TKey extends keyof TObject> = TObject extends any ? Omit<TObject, TKey> : never;
|
|
9
10
|
export declare type OmitKeyof<TObject, TKey extends TStrictly extends 'safely' ? keyof TObject | (string & Record<never, never>) | (number & Record<never, never>) | (symbol & Record<never, never>) : keyof TObject, TStrictly extends 'strictly' | 'safely' = 'strictly'> = Omit<TObject, TKey>;
|
|
10
11
|
export declare type QueryKey = readonly unknown[];
|
|
11
12
|
export declare type QueryFunction<T = unknown, TQueryKey extends QueryKey = QueryKey, TPageParam = any> = (context: QueryFunctionContext<TQueryKey, TPageParam>) => T | Promise<T>;
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// TYPES
|
|
2
|
+
// UTILS
|
|
3
|
+
const isServer = typeof window === 'undefined' || 'Deno' in window;
|
|
4
|
+
function noop() {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
function functionalUpdate(updater, input) {
|
|
8
|
+
return typeof updater === 'function' ? updater(input) : updater;
|
|
9
|
+
}
|
|
10
|
+
function isValidTimeout(value) {
|
|
11
|
+
return typeof value === 'number' && value >= 0 && value !== Infinity;
|
|
12
|
+
}
|
|
13
|
+
function difference(array1, array2) {
|
|
14
|
+
return array1.filter(x => !array2.includes(x));
|
|
15
|
+
}
|
|
16
|
+
function replaceAt(array, index, value) {
|
|
17
|
+
const copy = array.slice(0);
|
|
18
|
+
copy[index] = value;
|
|
19
|
+
return copy;
|
|
20
|
+
}
|
|
21
|
+
function timeUntilStale(updatedAt, staleTime) {
|
|
22
|
+
return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
|
|
23
|
+
}
|
|
24
|
+
function parseQueryArgs(arg1, arg2, arg3) {
|
|
25
|
+
if (!isQueryKey(arg1)) {
|
|
26
|
+
return arg1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof arg2 === 'function') {
|
|
30
|
+
return { ...arg3,
|
|
31
|
+
queryKey: arg1,
|
|
32
|
+
queryFn: arg2
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { ...arg2,
|
|
37
|
+
queryKey: arg1
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function parseMutationArgs(arg1, arg2, arg3) {
|
|
41
|
+
if (isQueryKey(arg1)) {
|
|
42
|
+
if (typeof arg2 === 'function') {
|
|
43
|
+
return { ...arg3,
|
|
44
|
+
mutationKey: arg1,
|
|
45
|
+
mutationFn: arg2
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { ...arg2,
|
|
50
|
+
mutationKey: arg1
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (typeof arg1 === 'function') {
|
|
55
|
+
return { ...arg2,
|
|
56
|
+
mutationFn: arg1
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return { ...arg1
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function parseFilterArgs(arg1, arg2, arg3) {
|
|
64
|
+
return isQueryKey(arg1) ? [{ ...arg2,
|
|
65
|
+
queryKey: arg1
|
|
66
|
+
}, arg3] : [arg1 || {}, arg2];
|
|
67
|
+
}
|
|
68
|
+
function parseMutationFilterArgs(arg1, arg2, arg3) {
|
|
69
|
+
return isQueryKey(arg1) ? [{ ...arg2,
|
|
70
|
+
mutationKey: arg1
|
|
71
|
+
}, arg3] : [arg1 || {}, arg2];
|
|
72
|
+
}
|
|
73
|
+
function matchQuery(filters, query) {
|
|
74
|
+
const {
|
|
75
|
+
type = 'all',
|
|
76
|
+
exact,
|
|
77
|
+
fetchStatus,
|
|
78
|
+
predicate,
|
|
79
|
+
queryKey,
|
|
80
|
+
stale
|
|
81
|
+
} = filters;
|
|
82
|
+
|
|
83
|
+
if (isQueryKey(queryKey)) {
|
|
84
|
+
if (exact) {
|
|
85
|
+
if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
} else if (!partialMatchKey(query.queryKey, queryKey)) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (type !== 'all') {
|
|
94
|
+
const isActive = query.isActive();
|
|
95
|
+
|
|
96
|
+
if (type === 'active' && !isActive) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (type === 'inactive' && isActive) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (typeof stale === 'boolean' && query.isStale() !== stale) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (typeof fetchStatus !== 'undefined' && fetchStatus !== query.state.fetchStatus) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (predicate && !predicate(query)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
function matchMutation(filters, mutation) {
|
|
120
|
+
const {
|
|
121
|
+
exact,
|
|
122
|
+
fetching,
|
|
123
|
+
predicate,
|
|
124
|
+
mutationKey
|
|
125
|
+
} = filters;
|
|
126
|
+
|
|
127
|
+
if (isQueryKey(mutationKey)) {
|
|
128
|
+
if (!mutation.options.mutationKey) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (exact) {
|
|
133
|
+
if (hashQueryKey(mutation.options.mutationKey) !== hashQueryKey(mutationKey)) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
} else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (typeof fetching === 'boolean' && mutation.state.status === 'loading' !== fetching) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (predicate && !predicate(mutation)) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
function hashQueryKeyByOptions(queryKey, options) {
|
|
152
|
+
const hashFn = (options == null ? void 0 : options.queryKeyHashFn) || hashQueryKey;
|
|
153
|
+
return hashFn(queryKey);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Default query keys hash function.
|
|
157
|
+
* Hashes the value into a stable hash.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
function hashQueryKey(queryKey) {
|
|
161
|
+
return JSON.stringify(queryKey, (_, val) => isPlainObject(val) ? Object.keys(val).sort().reduce((result, key) => {
|
|
162
|
+
result[key] = val[key];
|
|
163
|
+
return result;
|
|
164
|
+
}, {}) : val);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Checks if key `b` partially matches with key `a`.
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
function partialMatchKey(a, b) {
|
|
171
|
+
return partialDeepEqual(a, b);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Checks if `b` partially matches with `a`.
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
function partialDeepEqual(a, b) {
|
|
178
|
+
if (a === b) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (typeof a !== typeof b) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
187
|
+
return !Object.keys(b).some(key => !partialDeepEqual(a[key], b[key]));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* This function returns `a` if `b` is deeply equal.
|
|
194
|
+
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
195
|
+
* This can be used for structural sharing between JSON values for example.
|
|
196
|
+
*/
|
|
197
|
+
|
|
198
|
+
function replaceEqualDeep(a, b) {
|
|
199
|
+
if (a === b) {
|
|
200
|
+
return a;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const array = isPlainArray(a) && isPlainArray(b);
|
|
204
|
+
|
|
205
|
+
if (array || isPlainObject(a) && isPlainObject(b)) {
|
|
206
|
+
const aSize = array ? a.length : Object.keys(a).length;
|
|
207
|
+
const bItems = array ? b : Object.keys(b);
|
|
208
|
+
const bSize = bItems.length;
|
|
209
|
+
const copy = array ? [] : {};
|
|
210
|
+
let equalItems = 0;
|
|
211
|
+
|
|
212
|
+
for (let i = 0; i < bSize; i++) {
|
|
213
|
+
const key = array ? i : bItems[i];
|
|
214
|
+
copy[key] = replaceEqualDeep(a[key], b[key]);
|
|
215
|
+
|
|
216
|
+
if (copy[key] === a[key]) {
|
|
217
|
+
equalItems++;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return b;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Shallow compare objects. Only works with objects that always have the same properties.
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
function shallowEqualObjects(a, b) {
|
|
231
|
+
if (a && !b || b && !a) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
for (const key in a) {
|
|
236
|
+
if (a[key] !== b[key]) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
function isPlainArray(value) {
|
|
244
|
+
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
245
|
+
} // Copied from: https://github.com/jonschlinkert/is-plain-object
|
|
246
|
+
|
|
247
|
+
function isPlainObject(o) {
|
|
248
|
+
if (!hasObjectPrototype(o)) {
|
|
249
|
+
return false;
|
|
250
|
+
} // If has modified constructor
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
const ctor = o.constructor;
|
|
254
|
+
|
|
255
|
+
if (typeof ctor === 'undefined') {
|
|
256
|
+
return true;
|
|
257
|
+
} // If has modified prototype
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
const prot = ctor.prototype;
|
|
261
|
+
|
|
262
|
+
if (!hasObjectPrototype(prot)) {
|
|
263
|
+
return false;
|
|
264
|
+
} // If constructor does not have an Object-specific method
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
if (!prot.hasOwnProperty('isPrototypeOf')) {
|
|
268
|
+
return false;
|
|
269
|
+
} // Most likely a plain Object
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function hasObjectPrototype(o) {
|
|
276
|
+
return Object.prototype.toString.call(o) === '[object Object]';
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function isQueryKey(value) {
|
|
280
|
+
return Array.isArray(value);
|
|
281
|
+
}
|
|
282
|
+
function isError(value) {
|
|
283
|
+
return value instanceof Error;
|
|
284
|
+
}
|
|
285
|
+
function sleep(timeout) {
|
|
286
|
+
return new Promise(resolve => {
|
|
287
|
+
setTimeout(resolve, timeout);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Schedules a microtask.
|
|
292
|
+
* This can be useful to schedule state updates after rendering.
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
function scheduleMicrotask(callback) {
|
|
296
|
+
sleep(0).then(callback);
|
|
297
|
+
}
|
|
298
|
+
function getAbortController() {
|
|
299
|
+
if (typeof AbortController === 'function') {
|
|
300
|
+
return new AbortController();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
function replaceData(prevData, data, options) {
|
|
306
|
+
// Use prev data if an isDataEqual function is defined and returns `true`
|
|
307
|
+
if (options.isDataEqual != null && options.isDataEqual(prevData, data)) {
|
|
308
|
+
return prevData;
|
|
309
|
+
} else if (typeof options.structuralSharing === 'function') {
|
|
310
|
+
return options.structuralSharing(prevData, data);
|
|
311
|
+
} else if (options.structuralSharing !== false) {
|
|
312
|
+
// Structurally share data between prev and new data if needed
|
|
313
|
+
return replaceEqualDeep(prevData, data);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return data;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export { difference, functionalUpdate, getAbortController, hashQueryKey, hashQueryKeyByOptions, isError, isPlainArray, isPlainObject, isQueryKey, isServer, isValidTimeout, matchMutation, matchQuery, noop, parseFilterArgs, parseMutationArgs, parseMutationFilterArgs, parseQueryArgs, partialDeepEqual, partialMatchKey, replaceAt, replaceData, replaceEqualDeep, scheduleMicrotask, shallowEqualObjects, sleep, timeUntilStale };
|
|
320
|
+
//# sourceMappingURL=utils.esm.js.map
|