@elice/material-shared-utils 1.251120.1 → 1.260128.0-rc.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/cjs/_virtual/_rollupPluginBabelHelpers.js +177 -376
- package/cjs/_virtual/index.js +5 -0
- package/cjs/_virtual/use-sync-external-store-shim.production.js +5 -0
- package/cjs/hooks/useHelpyLogo.js +3 -7
- package/cjs/index.js +4 -4
- package/cjs/material-config/MaterialConfigContext.d.ts +0 -1
- package/cjs/material-config/MaterialConfigContext.js +2 -2
- package/cjs/material-fetch/useMaterialFetch.d.ts +2 -47
- package/cjs/material-fetch/useMaterialFetch.js +1 -4
- package/cjs/material-fetch/useMaterialFetchRaw.d.ts +1 -1
- package/cjs/material-fetch/useMaterialFetchRaw.js +12 -19
- package/cjs/material-hoc/withMaterial.d.ts +1 -1
- package/cjs/material-hoc/withMaterial.js +0 -1
- package/cjs/node_modules/@tanstack/query-core/build/lib/focusManager.js +93 -0
- package/cjs/node_modules/@tanstack/query-core/build/lib/notifyManager.js +101 -0
- package/cjs/node_modules/@tanstack/query-core/build/lib/onlineManager.js +95 -0
- package/cjs/node_modules/@tanstack/query-core/build/lib/queryObserver.js +571 -0
- package/cjs/node_modules/@tanstack/query-core/build/lib/retryer.js +21 -0
- package/cjs/node_modules/@tanstack/query-core/build/lib/subscribable.js +33 -0
- package/cjs/node_modules/@tanstack/query-core/build/lib/utils.js +154 -0
- package/cjs/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.js +65 -0
- package/cjs/node_modules/@tanstack/react-query/build/lib/QueryErrorResetBoundary.js +46 -0
- package/cjs/node_modules/@tanstack/react-query/build/lib/errorBoundaryUtils.js +52 -0
- package/cjs/node_modules/@tanstack/react-query/build/lib/isRestoring.js +31 -0
- package/cjs/node_modules/@tanstack/react-query/build/lib/suspense.js +39 -0
- package/cjs/node_modules/@tanstack/react-query/build/lib/useBaseQuery.js +94 -0
- package/cjs/node_modules/@tanstack/react-query/build/lib/useQuery.js +14 -0
- package/cjs/node_modules/@tanstack/react-query/build/lib/useSyncExternalStore.js +9 -0
- package/cjs/node_modules/@tanstack/react-query/build/lib/utils.js +12 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/BehaviorSubject.js +39 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/Observable.js +105 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/Subject.js +165 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/Subscriber.js +157 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/Subscription.js +148 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/config.js +6 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/scheduler/timeoutProvider.js +19 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/symbol/observable.js +5 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/util/ObjectUnsubscribedError.js +13 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/util/UnsubscriptionError.js +16 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/util/arrRemove.js +10 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js +14 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/util/errorContext.js +9 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/util/identity.js +7 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/util/isFunction.js +7 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/util/noop.js +5 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/util/pipe.js +17 -0
- package/cjs/node_modules/rxjs/dist/esm5/internal/util/reportUnhandledError.js +13 -0
- package/cjs/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +77 -0
- package/cjs/node_modules/use-sync-external-store/shim/index.js +13 -0
- package/es/_virtual/_rollupPluginBabelHelpers.js +176 -376
- package/es/_virtual/index.js +3 -0
- package/es/_virtual/use-sync-external-store-shim.production.js +3 -0
- package/es/hooks/useCallbackProp.js +3 -3
- package/es/hooks/useDeepClonedCompareEffect.js +2 -2
- package/es/hooks/useHelpyLogo.js +2 -6
- package/es/index.js +2 -2
- package/es/material-config/MaterialConfigContext.d.ts +0 -1
- package/es/material-config/MaterialConfigContext.js +1 -1
- package/es/material-config/MaterialConfigProvider.js +5 -5
- package/es/material-fetch/useMaterialFetch.d.ts +2 -47
- package/es/material-fetch/useMaterialFetch.js +1 -4
- package/es/material-fetch/useMaterialFetchRaw.d.ts +1 -1
- package/es/material-fetch/useMaterialFetchRaw.js +13 -20
- package/es/material-hoc/withMaterial.d.ts +1 -1
- package/es/material-hoc/withMaterial.js +0 -1
- package/es/node_modules/@tanstack/query-core/build/lib/focusManager.js +90 -0
- package/es/node_modules/@tanstack/query-core/build/lib/notifyManager.js +98 -0
- package/es/node_modules/@tanstack/query-core/build/lib/onlineManager.js +92 -0
- package/es/node_modules/@tanstack/query-core/build/lib/queryObserver.js +569 -0
- package/es/node_modules/@tanstack/query-core/build/lib/retryer.js +17 -0
- package/es/node_modules/@tanstack/query-core/build/lib/subscribable.js +31 -0
- package/es/node_modules/@tanstack/query-core/build/lib/utils.js +140 -0
- package/es/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.js +42 -0
- package/es/node_modules/@tanstack/react-query/build/lib/QueryErrorResetBoundary.js +24 -0
- package/es/node_modules/@tanstack/react-query/build/lib/errorBoundaryUtils.js +28 -0
- package/es/node_modules/@tanstack/react-query/build/lib/isRestoring.js +9 -0
- package/es/node_modules/@tanstack/react-query/build/lib/suspense.js +34 -0
- package/es/node_modules/@tanstack/react-query/build/lib/useBaseQuery.js +72 -0
- package/es/node_modules/@tanstack/react-query/build/lib/useQuery.js +12 -0
- package/es/node_modules/@tanstack/react-query/build/lib/useSyncExternalStore.js +7 -0
- package/es/node_modules/@tanstack/react-query/build/lib/utils.js +10 -0
- package/es/node_modules/rxjs/dist/esm5/internal/BehaviorSubject.js +37 -0
- package/es/node_modules/rxjs/dist/esm5/internal/Observable.js +103 -0
- package/es/node_modules/rxjs/dist/esm5/internal/Subject.js +162 -0
- package/es/node_modules/rxjs/dist/esm5/internal/Subscriber.js +153 -0
- package/es/node_modules/rxjs/dist/esm5/internal/Subscription.js +144 -0
- package/es/node_modules/rxjs/dist/esm5/internal/config.js +4 -0
- package/es/node_modules/rxjs/dist/esm5/internal/scheduler/timeoutProvider.js +17 -0
- package/es/node_modules/rxjs/dist/esm5/internal/symbol/observable.js +3 -0
- package/es/node_modules/rxjs/dist/esm5/internal/util/ObjectUnsubscribedError.js +11 -0
- package/es/node_modules/rxjs/dist/esm5/internal/util/UnsubscriptionError.js +14 -0
- package/es/node_modules/rxjs/dist/esm5/internal/util/arrRemove.js +8 -0
- package/es/node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js +12 -0
- package/es/node_modules/rxjs/dist/esm5/internal/util/errorContext.js +7 -0
- package/es/node_modules/rxjs/dist/esm5/internal/util/identity.js +5 -0
- package/es/node_modules/rxjs/dist/esm5/internal/util/isFunction.js +5 -0
- package/es/node_modules/rxjs/dist/esm5/internal/util/noop.js +3 -0
- package/es/node_modules/rxjs/dist/esm5/internal/util/pipe.js +15 -0
- package/es/node_modules/rxjs/dist/esm5/internal/util/reportUnhandledError.js +11 -0
- package/es/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +69 -0
- package/es/node_modules/use-sync-external-store/shim/index.js +11 -0
- package/package.json +6 -4
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// TYPES
|
|
2
|
+
// UTILS
|
|
3
|
+
const isServer = typeof window === 'undefined' || 'Deno' in window;
|
|
4
|
+
function noop() {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
function isValidTimeout(value) {
|
|
8
|
+
return typeof value === 'number' && value >= 0 && value !== Infinity;
|
|
9
|
+
}
|
|
10
|
+
function timeUntilStale(updatedAt, staleTime) {
|
|
11
|
+
return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
|
|
12
|
+
}
|
|
13
|
+
function parseQueryArgs(arg1, arg2, arg3) {
|
|
14
|
+
if (!isQueryKey(arg1)) {
|
|
15
|
+
return arg1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return { ...arg2,
|
|
19
|
+
queryKey: arg1
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* This function returns `a` if `b` is deeply equal.
|
|
24
|
+
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
25
|
+
* This can be used for structural sharing between JSON values for example.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
function replaceEqualDeep(a, b, depth = 0) {
|
|
29
|
+
if (a === b) {
|
|
30
|
+
return a;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (depth > 500) return b;
|
|
34
|
+
const array = isPlainArray(a) && isPlainArray(b);
|
|
35
|
+
|
|
36
|
+
if (array || isPlainObject(a) && isPlainObject(b)) {
|
|
37
|
+
const aSize = array ? a.length : Object.keys(a).length;
|
|
38
|
+
const bItems = array ? b : Object.keys(b);
|
|
39
|
+
const bSize = bItems.length;
|
|
40
|
+
const copy = array ? [] : {};
|
|
41
|
+
let equalItems = 0;
|
|
42
|
+
|
|
43
|
+
for (let i = 0; i < bSize; i++) {
|
|
44
|
+
const key = array ? i : bItems[i];
|
|
45
|
+
copy[key] = replaceEqualDeep(a[key], b[key], depth + 1);
|
|
46
|
+
|
|
47
|
+
if (copy[key] === a[key]) {
|
|
48
|
+
equalItems++;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return b;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Shallow compare objects. Only works with objects that always have the same properties.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
function shallowEqualObjects(a, b) {
|
|
62
|
+
if (a && !b || b && !a) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (const key in a) {
|
|
67
|
+
if (a[key] !== b[key]) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
function isPlainArray(value) {
|
|
75
|
+
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
76
|
+
} // Copied from: https://github.com/jonschlinkert/is-plain-object
|
|
77
|
+
|
|
78
|
+
function isPlainObject(o) {
|
|
79
|
+
if (!hasObjectPrototype(o)) {
|
|
80
|
+
return false;
|
|
81
|
+
} // If has modified constructor
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
const ctor = o.constructor;
|
|
85
|
+
|
|
86
|
+
if (typeof ctor === 'undefined') {
|
|
87
|
+
return true;
|
|
88
|
+
} // If has modified prototype
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
const prot = ctor.prototype;
|
|
92
|
+
|
|
93
|
+
if (!hasObjectPrototype(prot)) {
|
|
94
|
+
return false;
|
|
95
|
+
} // If constructor does not have an Object-specific method
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if (!prot.hasOwnProperty('isPrototypeOf')) {
|
|
99
|
+
return false;
|
|
100
|
+
} // Most likely a plain Object
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function hasObjectPrototype(o) {
|
|
107
|
+
return Object.prototype.toString.call(o) === '[object Object]';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function isQueryKey(value) {
|
|
111
|
+
return Array.isArray(value);
|
|
112
|
+
}
|
|
113
|
+
function sleep(timeout) {
|
|
114
|
+
return new Promise(resolve => {
|
|
115
|
+
setTimeout(resolve, timeout);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Schedules a microtask.
|
|
120
|
+
* This can be useful to schedule state updates after rendering.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
function scheduleMicrotask(callback) {
|
|
124
|
+
sleep(0).then(callback);
|
|
125
|
+
}
|
|
126
|
+
function replaceData(prevData, data, options) {
|
|
127
|
+
// Use prev data if an isDataEqual function is defined and returns `true`
|
|
128
|
+
if (options.isDataEqual != null && options.isDataEqual(prevData, data)) {
|
|
129
|
+
return prevData;
|
|
130
|
+
} else if (typeof options.structuralSharing === 'function') {
|
|
131
|
+
return options.structuralSharing(prevData, data);
|
|
132
|
+
} else if (options.structuralSharing !== false) {
|
|
133
|
+
// Structurally share data between prev and new data if needed
|
|
134
|
+
return replaceEqualDeep(prevData, data);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return data;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export { isPlainArray, isPlainObject, isQueryKey, isServer, isValidTimeout, noop, parseQueryArgs, replaceData, replaceEqualDeep, scheduleMicrotask, shallowEqualObjects, sleep, timeUntilStale };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
const defaultContext = /*#__PURE__*/React.createContext(undefined);
|
|
6
|
+
const QueryClientSharingContext = /*#__PURE__*/React.createContext(false); // If we are given a context, we will use it.
|
|
7
|
+
// Otherwise, if contextSharing is on, we share the first and at least one
|
|
8
|
+
// instance of the context across the window
|
|
9
|
+
// to ensure that if React Query is used across
|
|
10
|
+
// different bundles or microfrontends they will
|
|
11
|
+
// all use the same **instance** of context, regardless
|
|
12
|
+
// of module scoping.
|
|
13
|
+
|
|
14
|
+
function getQueryClientContext(context, contextSharing) {
|
|
15
|
+
if (context) {
|
|
16
|
+
return context;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (contextSharing && typeof window !== 'undefined') {
|
|
20
|
+
if (!window.ReactQueryClientContext) {
|
|
21
|
+
window.ReactQueryClientContext = defaultContext;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return window.ReactQueryClientContext;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return defaultContext;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const useQueryClient = ({
|
|
31
|
+
context
|
|
32
|
+
} = {}) => {
|
|
33
|
+
const queryClient = React.useContext(getQueryClientContext(context, React.useContext(QueryClientSharingContext)));
|
|
34
|
+
|
|
35
|
+
if (!queryClient) {
|
|
36
|
+
throw new Error('No QueryClient set, use QueryClientProvider to set one');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return queryClient;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { defaultContext, useQueryClient };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
function createValue() {
|
|
6
|
+
let isReset = false;
|
|
7
|
+
return {
|
|
8
|
+
clearReset: () => {
|
|
9
|
+
isReset = false;
|
|
10
|
+
},
|
|
11
|
+
reset: () => {
|
|
12
|
+
isReset = true;
|
|
13
|
+
},
|
|
14
|
+
isReset: () => {
|
|
15
|
+
return isReset;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const QueryErrorResetBoundaryContext = /*#__PURE__*/React.createContext(createValue()); // HOOK
|
|
21
|
+
|
|
22
|
+
const useQueryErrorResetBoundary = () => React.useContext(QueryErrorResetBoundaryContext); // COMPONENT
|
|
23
|
+
|
|
24
|
+
export { useQueryErrorResetBoundary };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { shouldThrowError } from './utils.js';
|
|
5
|
+
|
|
6
|
+
const ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
|
|
7
|
+
if (options.suspense || options.useErrorBoundary) {
|
|
8
|
+
// Prevent retrying failed query if the error boundary has not been reset yet
|
|
9
|
+
if (!errorResetBoundary.isReset()) {
|
|
10
|
+
options.retryOnMount = false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const useClearResetErrorBoundary = errorResetBoundary => {
|
|
15
|
+
React.useEffect(() => {
|
|
16
|
+
errorResetBoundary.clearReset();
|
|
17
|
+
}, [errorResetBoundary]);
|
|
18
|
+
};
|
|
19
|
+
const getHasError = ({
|
|
20
|
+
result,
|
|
21
|
+
errorResetBoundary,
|
|
22
|
+
useErrorBoundary,
|
|
23
|
+
query
|
|
24
|
+
}) => {
|
|
25
|
+
return result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(useErrorBoundary, [result.error, query]);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { ensurePreventErrorBoundaryRetry, getHasError, useClearResetErrorBoundary };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensures minimum staleTime and cacheTime values when suspense is enabled.
|
|
3
|
+
* Despite the name, this function guards both staleTime and cacheTime to prevent
|
|
4
|
+
* infinite re-render loops with synchronous queries.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated in v5 - replaced by ensureSuspenseTimers
|
|
7
|
+
*/
|
|
8
|
+
const ensureStaleTime = defaultedOptions => {
|
|
9
|
+
if (defaultedOptions.suspense) {
|
|
10
|
+
// Always set stale time when using suspense to prevent
|
|
11
|
+
// fetching again when directly mounting after suspending
|
|
12
|
+
if (typeof defaultedOptions.staleTime !== 'number') {
|
|
13
|
+
defaultedOptions.staleTime = 1000;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof defaultedOptions.cacheTime === 'number') {
|
|
17
|
+
defaultedOptions.cacheTime = Math.max(defaultedOptions.cacheTime, 1000);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const willFetch = (result, isRestoring) => result.isLoading && result.isFetching && !isRestoring;
|
|
22
|
+
const shouldSuspend = (defaultedOptions, result, isRestoring) => (defaultedOptions == null ? void 0 : defaultedOptions.suspense) && willFetch(result, isRestoring);
|
|
23
|
+
const fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).then(({
|
|
24
|
+
data
|
|
25
|
+
}) => {
|
|
26
|
+
defaultedOptions.onSuccess == null ? void 0 : defaultedOptions.onSuccess(data);
|
|
27
|
+
defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(data, null);
|
|
28
|
+
}).catch(error => {
|
|
29
|
+
errorResetBoundary.clearReset();
|
|
30
|
+
defaultedOptions.onError == null ? void 0 : defaultedOptions.onError(error);
|
|
31
|
+
defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(undefined, error);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export { ensureStaleTime, fetchOptimistic, shouldSuspend, willFetch };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { useSyncExternalStore } from './useSyncExternalStore.js';
|
|
5
|
+
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary.js';
|
|
6
|
+
import { useQueryClient } from './QueryClientProvider.js';
|
|
7
|
+
import { useIsRestoring } from './isRestoring.js';
|
|
8
|
+
import { ensurePreventErrorBoundaryRetry, useClearResetErrorBoundary, getHasError } from './errorBoundaryUtils.js';
|
|
9
|
+
import { ensureStaleTime, shouldSuspend, fetchOptimistic } from './suspense.js';
|
|
10
|
+
import { notifyManager } from '../../../query-core/build/lib/notifyManager.js';
|
|
11
|
+
|
|
12
|
+
function useBaseQuery(options, Observer) {
|
|
13
|
+
const queryClient = useQueryClient({
|
|
14
|
+
context: options.context
|
|
15
|
+
});
|
|
16
|
+
const isRestoring = useIsRestoring();
|
|
17
|
+
const errorResetBoundary = useQueryErrorResetBoundary();
|
|
18
|
+
const defaultedOptions = queryClient.defaultQueryOptions(options); // Make sure results are optimistically set in fetching state before subscribing or updating options
|
|
19
|
+
|
|
20
|
+
defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic'; // Include callbacks in batch renders
|
|
21
|
+
|
|
22
|
+
if (defaultedOptions.onError) {
|
|
23
|
+
defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (defaultedOptions.onSuccess) {
|
|
27
|
+
defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (defaultedOptions.onSettled) {
|
|
31
|
+
defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
ensureStaleTime(defaultedOptions);
|
|
35
|
+
ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);
|
|
36
|
+
useClearResetErrorBoundary(errorResetBoundary);
|
|
37
|
+
const [observer] = React.useState(() => new Observer(queryClient, defaultedOptions));
|
|
38
|
+
const result = observer.getOptimisticResult(defaultedOptions);
|
|
39
|
+
useSyncExternalStore(React.useCallback(onStoreChange => {
|
|
40
|
+
const unsubscribe = isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)); // Update result to make sure we did not miss any query updates
|
|
41
|
+
// between creating the observer and subscribing to it.
|
|
42
|
+
|
|
43
|
+
observer.updateResult();
|
|
44
|
+
return unsubscribe;
|
|
45
|
+
}, [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
46
|
+
React.useEffect(() => {
|
|
47
|
+
// Do not notify on updates because of changes in the options because
|
|
48
|
+
// these changes should already be reflected in the optimistic result.
|
|
49
|
+
observer.setOptions(defaultedOptions, {
|
|
50
|
+
listeners: false
|
|
51
|
+
});
|
|
52
|
+
}, [defaultedOptions, observer]); // Handle suspense
|
|
53
|
+
|
|
54
|
+
if (shouldSuspend(defaultedOptions, result, isRestoring)) {
|
|
55
|
+
throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
|
|
56
|
+
} // Handle error boundary
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if (getHasError({
|
|
60
|
+
result,
|
|
61
|
+
errorResetBoundary,
|
|
62
|
+
useErrorBoundary: defaultedOptions.useErrorBoundary,
|
|
63
|
+
query: observer.getCurrentQuery()
|
|
64
|
+
})) {
|
|
65
|
+
throw result.error;
|
|
66
|
+
} // Handle result property usage tracking
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { useBaseQuery };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useBaseQuery } from './useBaseQuery.js';
|
|
4
|
+
import { parseQueryArgs } from '../../../query-core/build/lib/utils.js';
|
|
5
|
+
import { QueryObserver } from '../../../query-core/build/lib/queryObserver.js';
|
|
6
|
+
|
|
7
|
+
function useQuery(arg1, arg2, arg3) {
|
|
8
|
+
const parsedOptions = parseQueryArgs(arg1, arg2);
|
|
9
|
+
return useBaseQuery(parsedOptions, QueryObserver);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { useQuery };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function shouldThrowError(_useErrorBoundary, params) {
|
|
2
|
+
// Allow useErrorBoundary function to override throwing behavior on a per-error basis
|
|
3
|
+
if (typeof _useErrorBoundary === 'function') {
|
|
4
|
+
return _useErrorBoundary(...params);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
return !!_useErrorBoundary;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { shouldThrowError };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { __extends } from 'tslib';
|
|
2
|
+
import { Subject } from './Subject.js';
|
|
3
|
+
|
|
4
|
+
var BehaviorSubject = (function (_super) {
|
|
5
|
+
__extends(BehaviorSubject, _super);
|
|
6
|
+
function BehaviorSubject(_value) {
|
|
7
|
+
var _this = _super.call(this) || this;
|
|
8
|
+
_this._value = _value;
|
|
9
|
+
return _this;
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(BehaviorSubject.prototype, "value", {
|
|
12
|
+
get: function () {
|
|
13
|
+
return this.getValue();
|
|
14
|
+
},
|
|
15
|
+
enumerable: false,
|
|
16
|
+
configurable: true
|
|
17
|
+
});
|
|
18
|
+
BehaviorSubject.prototype._subscribe = function (subscriber) {
|
|
19
|
+
var subscription = _super.prototype._subscribe.call(this, subscriber);
|
|
20
|
+
!subscription.closed && subscriber.next(this._value);
|
|
21
|
+
return subscription;
|
|
22
|
+
};
|
|
23
|
+
BehaviorSubject.prototype.getValue = function () {
|
|
24
|
+
var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, _value = _a._value;
|
|
25
|
+
if (hasError) {
|
|
26
|
+
throw thrownError;
|
|
27
|
+
}
|
|
28
|
+
this._throwIfClosed();
|
|
29
|
+
return _value;
|
|
30
|
+
};
|
|
31
|
+
BehaviorSubject.prototype.next = function (value) {
|
|
32
|
+
_super.prototype.next.call(this, (this._value = value));
|
|
33
|
+
};
|
|
34
|
+
return BehaviorSubject;
|
|
35
|
+
}(Subject));
|
|
36
|
+
|
|
37
|
+
export { BehaviorSubject };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { SafeSubscriber, Subscriber } from './Subscriber.js';
|
|
2
|
+
import { isSubscription } from './Subscription.js';
|
|
3
|
+
import { observable } from './symbol/observable.js';
|
|
4
|
+
import { pipeFromArray } from './util/pipe.js';
|
|
5
|
+
import { config } from './config.js';
|
|
6
|
+
import { isFunction } from './util/isFunction.js';
|
|
7
|
+
import { errorContext } from './util/errorContext.js';
|
|
8
|
+
|
|
9
|
+
var Observable = (function () {
|
|
10
|
+
function Observable(subscribe) {
|
|
11
|
+
if (subscribe) {
|
|
12
|
+
this._subscribe = subscribe;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
Observable.prototype.lift = function (operator) {
|
|
16
|
+
var observable = new Observable();
|
|
17
|
+
observable.source = this;
|
|
18
|
+
observable.operator = operator;
|
|
19
|
+
return observable;
|
|
20
|
+
};
|
|
21
|
+
Observable.prototype.subscribe = function (observerOrNext, error, complete) {
|
|
22
|
+
var _this = this;
|
|
23
|
+
var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
|
|
24
|
+
errorContext(function () {
|
|
25
|
+
var _a = _this, operator = _a.operator, source = _a.source;
|
|
26
|
+
subscriber.add(operator
|
|
27
|
+
?
|
|
28
|
+
operator.call(subscriber, source)
|
|
29
|
+
: source
|
|
30
|
+
?
|
|
31
|
+
_this._subscribe(subscriber)
|
|
32
|
+
:
|
|
33
|
+
_this._trySubscribe(subscriber));
|
|
34
|
+
});
|
|
35
|
+
return subscriber;
|
|
36
|
+
};
|
|
37
|
+
Observable.prototype._trySubscribe = function (sink) {
|
|
38
|
+
try {
|
|
39
|
+
return this._subscribe(sink);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
sink.error(err);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
Observable.prototype.forEach = function (next, promiseCtor) {
|
|
46
|
+
var _this = this;
|
|
47
|
+
promiseCtor = getPromiseCtor(promiseCtor);
|
|
48
|
+
return new promiseCtor(function (resolve, reject) {
|
|
49
|
+
var subscriber = new SafeSubscriber({
|
|
50
|
+
next: function (value) {
|
|
51
|
+
try {
|
|
52
|
+
next(value);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
reject(err);
|
|
56
|
+
subscriber.unsubscribe();
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
error: reject,
|
|
60
|
+
complete: resolve,
|
|
61
|
+
});
|
|
62
|
+
_this.subscribe(subscriber);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
Observable.prototype._subscribe = function (subscriber) {
|
|
66
|
+
var _a;
|
|
67
|
+
return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
|
|
68
|
+
};
|
|
69
|
+
Observable.prototype[observable] = function () {
|
|
70
|
+
return this;
|
|
71
|
+
};
|
|
72
|
+
Observable.prototype.pipe = function () {
|
|
73
|
+
var operations = [];
|
|
74
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
75
|
+
operations[_i] = arguments[_i];
|
|
76
|
+
}
|
|
77
|
+
return pipeFromArray(operations)(this);
|
|
78
|
+
};
|
|
79
|
+
Observable.prototype.toPromise = function (promiseCtor) {
|
|
80
|
+
var _this = this;
|
|
81
|
+
promiseCtor = getPromiseCtor(promiseCtor);
|
|
82
|
+
return new promiseCtor(function (resolve, reject) {
|
|
83
|
+
var value;
|
|
84
|
+
_this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
Observable.create = function (subscribe) {
|
|
88
|
+
return new Observable(subscribe);
|
|
89
|
+
};
|
|
90
|
+
return Observable;
|
|
91
|
+
}());
|
|
92
|
+
function getPromiseCtor(promiseCtor) {
|
|
93
|
+
var _a;
|
|
94
|
+
return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
|
|
95
|
+
}
|
|
96
|
+
function isObserver(value) {
|
|
97
|
+
return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
|
|
98
|
+
}
|
|
99
|
+
function isSubscriber(value) {
|
|
100
|
+
return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { Observable };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { __extends, __values } from 'tslib';
|
|
2
|
+
import { Observable } from './Observable.js';
|
|
3
|
+
import { EMPTY_SUBSCRIPTION, Subscription } from './Subscription.js';
|
|
4
|
+
import { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError.js';
|
|
5
|
+
import { arrRemove } from './util/arrRemove.js';
|
|
6
|
+
import { errorContext } from './util/errorContext.js';
|
|
7
|
+
|
|
8
|
+
var Subject = (function (_super) {
|
|
9
|
+
__extends(Subject, _super);
|
|
10
|
+
function Subject() {
|
|
11
|
+
var _this = _super.call(this) || this;
|
|
12
|
+
_this.closed = false;
|
|
13
|
+
_this.currentObservers = null;
|
|
14
|
+
_this.observers = [];
|
|
15
|
+
_this.isStopped = false;
|
|
16
|
+
_this.hasError = false;
|
|
17
|
+
_this.thrownError = null;
|
|
18
|
+
return _this;
|
|
19
|
+
}
|
|
20
|
+
Subject.prototype.lift = function (operator) {
|
|
21
|
+
var subject = new AnonymousSubject(this, this);
|
|
22
|
+
subject.operator = operator;
|
|
23
|
+
return subject;
|
|
24
|
+
};
|
|
25
|
+
Subject.prototype._throwIfClosed = function () {
|
|
26
|
+
if (this.closed) {
|
|
27
|
+
throw new ObjectUnsubscribedError();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
Subject.prototype.next = function (value) {
|
|
31
|
+
var _this = this;
|
|
32
|
+
errorContext(function () {
|
|
33
|
+
var e_1, _a;
|
|
34
|
+
_this._throwIfClosed();
|
|
35
|
+
if (!_this.isStopped) {
|
|
36
|
+
if (!_this.currentObservers) {
|
|
37
|
+
_this.currentObservers = Array.from(_this.observers);
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
41
|
+
var observer = _c.value;
|
|
42
|
+
observer.next(value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e_1) throw e_1.error; }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
Subject.prototype.error = function (err) {
|
|
56
|
+
var _this = this;
|
|
57
|
+
errorContext(function () {
|
|
58
|
+
_this._throwIfClosed();
|
|
59
|
+
if (!_this.isStopped) {
|
|
60
|
+
_this.hasError = _this.isStopped = true;
|
|
61
|
+
_this.thrownError = err;
|
|
62
|
+
var observers = _this.observers;
|
|
63
|
+
while (observers.length) {
|
|
64
|
+
observers.shift().error(err);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
Subject.prototype.complete = function () {
|
|
70
|
+
var _this = this;
|
|
71
|
+
errorContext(function () {
|
|
72
|
+
_this._throwIfClosed();
|
|
73
|
+
if (!_this.isStopped) {
|
|
74
|
+
_this.isStopped = true;
|
|
75
|
+
var observers = _this.observers;
|
|
76
|
+
while (observers.length) {
|
|
77
|
+
observers.shift().complete();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
Subject.prototype.unsubscribe = function () {
|
|
83
|
+
this.isStopped = this.closed = true;
|
|
84
|
+
this.observers = this.currentObservers = null;
|
|
85
|
+
};
|
|
86
|
+
Object.defineProperty(Subject.prototype, "observed", {
|
|
87
|
+
get: function () {
|
|
88
|
+
var _a;
|
|
89
|
+
return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
90
|
+
},
|
|
91
|
+
enumerable: false,
|
|
92
|
+
configurable: true
|
|
93
|
+
});
|
|
94
|
+
Subject.prototype._trySubscribe = function (subscriber) {
|
|
95
|
+
this._throwIfClosed();
|
|
96
|
+
return _super.prototype._trySubscribe.call(this, subscriber);
|
|
97
|
+
};
|
|
98
|
+
Subject.prototype._subscribe = function (subscriber) {
|
|
99
|
+
this._throwIfClosed();
|
|
100
|
+
this._checkFinalizedStatuses(subscriber);
|
|
101
|
+
return this._innerSubscribe(subscriber);
|
|
102
|
+
};
|
|
103
|
+
Subject.prototype._innerSubscribe = function (subscriber) {
|
|
104
|
+
var _this = this;
|
|
105
|
+
var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
|
|
106
|
+
if (hasError || isStopped) {
|
|
107
|
+
return EMPTY_SUBSCRIPTION;
|
|
108
|
+
}
|
|
109
|
+
this.currentObservers = null;
|
|
110
|
+
observers.push(subscriber);
|
|
111
|
+
return new Subscription(function () {
|
|
112
|
+
_this.currentObservers = null;
|
|
113
|
+
arrRemove(observers, subscriber);
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
Subject.prototype._checkFinalizedStatuses = function (subscriber) {
|
|
117
|
+
var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
|
|
118
|
+
if (hasError) {
|
|
119
|
+
subscriber.error(thrownError);
|
|
120
|
+
}
|
|
121
|
+
else if (isStopped) {
|
|
122
|
+
subscriber.complete();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
Subject.prototype.asObservable = function () {
|
|
126
|
+
var observable = new Observable();
|
|
127
|
+
observable.source = this;
|
|
128
|
+
return observable;
|
|
129
|
+
};
|
|
130
|
+
Subject.create = function (destination, source) {
|
|
131
|
+
return new AnonymousSubject(destination, source);
|
|
132
|
+
};
|
|
133
|
+
return Subject;
|
|
134
|
+
}(Observable));
|
|
135
|
+
var AnonymousSubject = (function (_super) {
|
|
136
|
+
__extends(AnonymousSubject, _super);
|
|
137
|
+
function AnonymousSubject(destination, source) {
|
|
138
|
+
var _this = _super.call(this) || this;
|
|
139
|
+
_this.destination = destination;
|
|
140
|
+
_this.source = source;
|
|
141
|
+
return _this;
|
|
142
|
+
}
|
|
143
|
+
AnonymousSubject.prototype.next = function (value) {
|
|
144
|
+
var _a, _b;
|
|
145
|
+
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
|
|
146
|
+
};
|
|
147
|
+
AnonymousSubject.prototype.error = function (err) {
|
|
148
|
+
var _a, _b;
|
|
149
|
+
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
|
|
150
|
+
};
|
|
151
|
+
AnonymousSubject.prototype.complete = function () {
|
|
152
|
+
var _a, _b;
|
|
153
|
+
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
154
|
+
};
|
|
155
|
+
AnonymousSubject.prototype._subscribe = function (subscriber) {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION;
|
|
158
|
+
};
|
|
159
|
+
return AnonymousSubject;
|
|
160
|
+
}(Subject));
|
|
161
|
+
|
|
162
|
+
export { AnonymousSubject, Subject };
|