@shipengine/alchemy 0.4.9 → 0.4.10

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.
Files changed (3) hide show
  1. package/index.js +249 -3424
  2. package/index.mjs +213 -3388
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -7,7 +7,7 @@ const jsxRuntime = require('react/jsx-runtime');
7
7
  const react = require('@emotion/react');
8
8
  const brands = require('@packlink/brands');
9
9
  const giger = require('@packlink/giger');
10
- const ReactDOM = require('react-dom');
10
+ const reactQuery = require('react-query');
11
11
  const reactI18next = require('react-i18next');
12
12
 
13
13
  function _interopNamespaceDefault(e) {
@@ -1541,21 +1541,6 @@ var createCache = function createCache(options) {
1541
1541
  return cache;
1542
1542
  };
1543
1543
 
1544
- function _extends() {
1545
- _extends = Object.assign ? Object.assign.bind() : function (target) {
1546
- for (var i = 1; i < arguments.length; i++) {
1547
- var source = arguments[i];
1548
- for (var key in source) {
1549
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1550
- target[key] = source[key];
1551
- }
1552
- }
1553
- }
1554
- return target;
1555
- };
1556
- return _extends.apply(this, arguments);
1557
- }
1558
-
1559
1544
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
1560
1545
 
1561
1546
  function getDefaultExportFromCjs (x) {
@@ -2211,3453 +2196,285 @@ function createStringFromObject(mergedProps, registered, obj) {
2211
2196
  return string;
2212
2197
  }
2213
2198
 
2214
- var labelPattern = /label:\s*([^\s;\n{]+)\s*(;|$)/g;
2215
- var sourceMapPattern;
2216
-
2217
- if (process.env.NODE_ENV !== 'production') {
2218
- sourceMapPattern = /\/\*#\ssourceMappingURL=data:application\/json;\S+\s+\*\//g;
2219
- } // this is the cursor for keyframes
2220
- // keyframes are stored on the SerializedStyles object as a linked list
2221
-
2222
-
2223
- var cursor;
2224
- var serializeStyles = function serializeStyles(args, registered, mergedProps) {
2225
- if (args.length === 1 && typeof args[0] === 'object' && args[0] !== null && args[0].styles !== undefined) {
2226
- return args[0];
2227
- }
2228
-
2229
- var stringMode = true;
2230
- var styles = '';
2231
- cursor = undefined;
2232
- var strings = args[0];
2233
-
2234
- if (strings == null || strings.raw === undefined) {
2235
- stringMode = false;
2236
- styles += handleInterpolation(mergedProps, registered, strings);
2237
- } else {
2238
- if (process.env.NODE_ENV !== 'production' && strings[0] === undefined) {
2239
- console.error(ILLEGAL_ESCAPE_SEQUENCE_ERROR);
2240
- }
2241
-
2242
- styles += strings[0];
2243
- } // we start at 1 since we've already handled the first arg
2244
-
2245
-
2246
- for (var i = 1; i < args.length; i++) {
2247
- styles += handleInterpolation(mergedProps, registered, args[i]);
2248
-
2249
- if (stringMode) {
2250
- if (process.env.NODE_ENV !== 'production' && strings[i] === undefined) {
2251
- console.error(ILLEGAL_ESCAPE_SEQUENCE_ERROR);
2252
- }
2253
-
2254
- styles += strings[i];
2255
- }
2256
- }
2257
-
2258
- var sourceMap;
2259
-
2260
- if (process.env.NODE_ENV !== 'production') {
2261
- styles = styles.replace(sourceMapPattern, function (match) {
2262
- sourceMap = match;
2263
- return '';
2264
- });
2265
- } // using a global regex with .exec is stateful so lastIndex has to be reset each time
2266
-
2267
-
2268
- labelPattern.lastIndex = 0;
2269
- var identifierName = '';
2270
- var match; // https://esbench.com/bench/5b809c2cf2949800a0f61fb5
2271
-
2272
- while ((match = labelPattern.exec(styles)) !== null) {
2273
- identifierName += '-' + // $FlowFixMe we know it's not null
2274
- match[1];
2275
- }
2276
-
2277
- var name = murmur2(styles) + identifierName;
2278
-
2279
- if (process.env.NODE_ENV !== 'production') {
2280
- // $FlowFixMe SerializedStyles type doesn't have toString property (and we don't want to add it)
2281
- return {
2282
- name: name,
2283
- styles: styles,
2284
- map: sourceMap,
2285
- next: cursor,
2286
- toString: function toString() {
2287
- return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop).";
2288
- }
2289
- };
2290
- }
2291
-
2292
- return {
2293
- name: name,
2294
- styles: styles,
2295
- next: cursor
2296
- };
2297
- };
2298
-
2299
- var syncFallback = function syncFallback(create) {
2300
- return create();
2301
- };
2302
-
2303
- var useInsertionEffect = React__namespace['useInsertion' + 'Effect'] ? React__namespace['useInsertion' + 'Effect'] : false;
2304
- var useInsertionEffectAlwaysWithSyncFallback = useInsertionEffect || syncFallback;
2305
-
2306
- var hasOwnProperty = {}.hasOwnProperty;
2307
-
2308
- var EmotionCacheContext = /* #__PURE__ */React.createContext( // we're doing this to avoid preconstruct's dead code elimination in this one case
2309
- // because this module is primarily intended for the browser and node
2310
- // but it's also required in react native and similar environments sometimes
2311
- // and we could have a special build just for that
2312
- // but this is much easier and the native packages
2313
- // might use a different theme context in the future anyway
2314
- typeof HTMLElement !== 'undefined' ? /* #__PURE__ */createCache({
2315
- key: 'css'
2316
- }) : null);
2317
-
2318
- if (process.env.NODE_ENV !== 'production') {
2319
- EmotionCacheContext.displayName = 'EmotionCacheContext';
2320
- }
2321
-
2322
- EmotionCacheContext.Provider;
2323
-
2324
- var withEmotionCache = function withEmotionCache(func) {
2325
- // $FlowFixMe
2326
- return /*#__PURE__*/React.forwardRef(function (props, ref) {
2327
- // the cache will never be null in the browser
2328
- var cache = React.useContext(EmotionCacheContext);
2329
- return func(props, cache, ref);
2330
- });
2331
- };
2332
-
2333
- var ThemeContext = /* #__PURE__ */React.createContext({});
2334
-
2335
- if (process.env.NODE_ENV !== 'production') {
2336
- ThemeContext.displayName = 'EmotionThemeContext';
2337
- }
2338
-
2339
- var getLastPart = function getLastPart(functionName) {
2340
- // The match may be something like 'Object.createEmotionProps' or
2341
- // 'Loader.prototype.render'
2342
- var parts = functionName.split('.');
2343
- return parts[parts.length - 1];
2344
- };
2345
-
2346
- var getFunctionNameFromStackTraceLine = function getFunctionNameFromStackTraceLine(line) {
2347
- // V8
2348
- var match = /^\s+at\s+([A-Za-z0-9$.]+)\s/.exec(line);
2349
- if (match) return getLastPart(match[1]); // Safari / Firefox
2350
-
2351
- match = /^([A-Za-z0-9$.]+)@/.exec(line);
2352
- if (match) return getLastPart(match[1]);
2353
- return undefined;
2354
- };
2355
-
2356
- var internalReactFunctionNames = /* #__PURE__ */new Set(['renderWithHooks', 'processChild', 'finishClassComponent', 'renderToString']); // These identifiers come from error stacks, so they have to be valid JS
2357
- // identifiers, thus we only need to replace what is a valid character for JS,
2358
- // but not for CSS.
2359
-
2360
- var sanitizeIdentifier = function sanitizeIdentifier(identifier) {
2361
- return identifier.replace(/\$/g, '-');
2362
- };
2363
-
2364
- var getLabelFromStackTrace = function getLabelFromStackTrace(stackTrace) {
2365
- if (!stackTrace) return undefined;
2366
- var lines = stackTrace.split('\n');
2367
-
2368
- for (var i = 0; i < lines.length; i++) {
2369
- var functionName = getFunctionNameFromStackTraceLine(lines[i]); // The first line of V8 stack traces is just "Error"
2370
-
2371
- if (!functionName) continue; // If we reach one of these, we have gone too far and should quit
2372
-
2373
- if (internalReactFunctionNames.has(functionName)) break; // The component name is the first function in the stack that starts with an
2374
- // uppercase letter
2375
-
2376
- if (/^[A-Z]/.test(functionName)) return sanitizeIdentifier(functionName);
2377
- }
2378
-
2379
- return undefined;
2380
- };
2381
-
2382
- var typePropName = '__EMOTION_TYPE_PLEASE_DO_NOT_USE__';
2383
- var labelPropName = '__EMOTION_LABEL_PLEASE_DO_NOT_USE__';
2384
- var createEmotionProps = function createEmotionProps(type, props) {
2385
- if (process.env.NODE_ENV !== 'production' && typeof props.css === 'string' && // check if there is a css declaration
2386
- props.css.indexOf(':') !== -1) {
2387
- throw new Error("Strings are not allowed as css prop values, please wrap it in a css template literal from '@emotion/react' like this: css`" + props.css + "`");
2388
- }
2389
-
2390
- var newProps = {};
2391
-
2392
- for (var key in props) {
2393
- if (hasOwnProperty.call(props, key)) {
2394
- newProps[key] = props[key];
2395
- }
2396
- }
2397
-
2398
- newProps[typePropName] = type; // For performance, only call getLabelFromStackTrace in development and when
2399
- // the label hasn't already been computed
2400
-
2401
- if (process.env.NODE_ENV !== 'production' && !!props.css && (typeof props.css !== 'object' || typeof props.css.name !== 'string' || props.css.name.indexOf('-') === -1)) {
2402
- var label = getLabelFromStackTrace(new Error().stack);
2403
- if (label) newProps[labelPropName] = label;
2404
- }
2405
-
2406
- return newProps;
2407
- };
2408
-
2409
- var Insertion = function Insertion(_ref) {
2410
- var cache = _ref.cache,
2411
- serialized = _ref.serialized,
2412
- isStringTag = _ref.isStringTag;
2413
- registerStyles(cache, serialized, isStringTag);
2414
- useInsertionEffectAlwaysWithSyncFallback(function () {
2415
- return insertStyles(cache, serialized, isStringTag);
2416
- });
2417
-
2418
- return null;
2419
- };
2420
-
2421
- var Emotion = /* #__PURE__ */withEmotionCache(function (props, cache, ref) {
2422
- var cssProp = props.css; // so that using `css` from `emotion` and passing the result to the css prop works
2423
- // not passing the registered cache to serializeStyles because it would
2424
- // make certain babel optimisations not possible
2425
-
2426
- if (typeof cssProp === 'string' && cache.registered[cssProp] !== undefined) {
2427
- cssProp = cache.registered[cssProp];
2428
- }
2429
-
2430
- var WrappedComponent = props[typePropName];
2431
- var registeredStyles = [cssProp];
2432
- var className = '';
2433
-
2434
- if (typeof props.className === 'string') {
2435
- className = getRegisteredStyles(cache.registered, registeredStyles, props.className);
2436
- } else if (props.className != null) {
2437
- className = props.className + " ";
2438
- }
2439
-
2440
- var serialized = serializeStyles(registeredStyles, undefined, React.useContext(ThemeContext));
2441
-
2442
- if (process.env.NODE_ENV !== 'production' && serialized.name.indexOf('-') === -1) {
2443
- var labelFromStack = props[labelPropName];
2444
-
2445
- if (labelFromStack) {
2446
- serialized = serializeStyles([serialized, 'label:' + labelFromStack + ';']);
2447
- }
2448
- }
2449
-
2450
- className += cache.key + "-" + serialized.name;
2451
- var newProps = {};
2452
-
2453
- for (var key in props) {
2454
- if (hasOwnProperty.call(props, key) && key !== 'css' && key !== typePropName && (process.env.NODE_ENV === 'production' || key !== labelPropName)) {
2455
- newProps[key] = props[key];
2456
- }
2457
- }
2458
-
2459
- newProps.ref = ref;
2460
- newProps.className = className;
2461
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Insertion, {
2462
- cache: cache,
2463
- serialized: serialized,
2464
- isStringTag: typeof WrappedComponent === 'string'
2465
- }), /*#__PURE__*/React.createElement(WrappedComponent, newProps));
2466
- });
2467
-
2468
- if (process.env.NODE_ENV !== 'production') {
2469
- Emotion.displayName = 'EmotionCssPropInternal';
2470
- }
2471
-
2472
- function jsx(type, props, key) {
2473
- if (!hasOwnProperty.call(props, 'css')) {
2474
- return jsxRuntime.jsx(type, props, key);
2475
- }
2476
-
2477
- return jsxRuntime.jsx(Emotion, createEmotionProps(type, props), key);
2478
- }
2479
- function jsxs(type, props, key) {
2480
- if (!hasOwnProperty.call(props, 'css')) {
2481
- return jsxRuntime.jsxs(type, props, key);
2482
- }
2483
-
2484
- return jsxRuntime.jsxs(Emotion, createEmotionProps(type, props), key);
2485
- }
2486
-
2487
- var dist = {};
2488
-
2489
- Object.defineProperty(dist, "__esModule", { value: true });
2490
- var _default = dist.default = (function () {
2491
- });
2492
-
2493
- function _setPrototypeOf(o, p) {
2494
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
2495
- o.__proto__ = p;
2496
- return o;
2497
- };
2498
- return _setPrototypeOf(o, p);
2499
- }
2500
-
2501
- function _inheritsLoose(subClass, superClass) {
2502
- subClass.prototype = Object.create(superClass.prototype);
2503
- subClass.prototype.constructor = subClass;
2504
- _setPrototypeOf(subClass, superClass);
2505
- }
2506
-
2507
- var Subscribable = /*#__PURE__*/function () {
2508
- function Subscribable() {
2509
- this.listeners = [];
2510
- }
2511
-
2512
- var _proto = Subscribable.prototype;
2513
-
2514
- _proto.subscribe = function subscribe(listener) {
2515
- var _this = this;
2516
-
2517
- var callback = listener || function () {
2518
- return undefined;
2519
- };
2520
-
2521
- this.listeners.push(callback);
2522
- this.onSubscribe();
2523
- return function () {
2524
- _this.listeners = _this.listeners.filter(function (x) {
2525
- return x !== callback;
2526
- });
2527
-
2528
- _this.onUnsubscribe();
2529
- };
2530
- };
2531
-
2532
- _proto.hasListeners = function hasListeners() {
2533
- return this.listeners.length > 0;
2534
- };
2535
-
2536
- _proto.onSubscribe = function onSubscribe() {// Do nothing
2537
- };
2538
-
2539
- _proto.onUnsubscribe = function onUnsubscribe() {// Do nothing
2540
- };
2541
-
2542
- return Subscribable;
2543
- }();
2544
-
2545
- // TYPES
2546
- // UTILS
2547
- var isServer = typeof window === 'undefined';
2548
- function noop$1() {
2549
- return undefined;
2550
- }
2551
- function functionalUpdate(updater, input) {
2552
- return typeof updater === 'function' ? updater(input) : updater;
2553
- }
2554
- function isValidTimeout(value) {
2555
- return typeof value === 'number' && value >= 0 && value !== Infinity;
2556
- }
2557
- function ensureQueryKeyArray(value) {
2558
- return Array.isArray(value) ? value : [value];
2559
- }
2560
- function timeUntilStale(updatedAt, staleTime) {
2561
- return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
2562
- }
2563
- function parseQueryArgs(arg1, arg2, arg3) {
2564
- if (!isQueryKey(arg1)) {
2565
- return arg1;
2566
- }
2567
-
2568
- if (typeof arg2 === 'function') {
2569
- return _extends({}, arg3, {
2570
- queryKey: arg1,
2571
- queryFn: arg2
2572
- });
2573
- }
2574
-
2575
- return _extends({}, arg2, {
2576
- queryKey: arg1
2577
- });
2578
- }
2579
- function parseMutationArgs(arg1, arg2, arg3) {
2580
- if (isQueryKey(arg1)) {
2581
- if (typeof arg2 === 'function') {
2582
- return _extends({}, arg3, {
2583
- mutationKey: arg1,
2584
- mutationFn: arg2
2585
- });
2586
- }
2587
-
2588
- return _extends({}, arg2, {
2589
- mutationKey: arg1
2590
- });
2591
- }
2592
-
2593
- if (typeof arg1 === 'function') {
2594
- return _extends({}, arg2, {
2595
- mutationFn: arg1
2596
- });
2597
- }
2598
-
2599
- return _extends({}, arg1);
2600
- }
2601
- function parseFilterArgs(arg1, arg2, arg3) {
2602
- return isQueryKey(arg1) ? [_extends({}, arg2, {
2603
- queryKey: arg1
2604
- }), arg3] : [arg1 || {}, arg2];
2605
- }
2606
- function mapQueryStatusFilter(active, inactive) {
2607
- if (active === true && inactive === true || active == null && inactive == null) {
2608
- return 'all';
2609
- } else if (active === false && inactive === false) {
2610
- return 'none';
2611
- } else {
2612
- // At this point, active|inactive can only be true|false or false|true
2613
- // so, when only one value is provided, the missing one has to be the negated value
2614
- var isActive = active != null ? active : !inactive;
2615
- return isActive ? 'active' : 'inactive';
2616
- }
2617
- }
2618
- function matchQuery(filters, query) {
2619
- var active = filters.active,
2620
- exact = filters.exact,
2621
- fetching = filters.fetching,
2622
- inactive = filters.inactive,
2623
- predicate = filters.predicate,
2624
- queryKey = filters.queryKey,
2625
- stale = filters.stale;
2626
-
2627
- if (isQueryKey(queryKey)) {
2628
- if (exact) {
2629
- if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {
2630
- return false;
2631
- }
2632
- } else if (!partialMatchKey(query.queryKey, queryKey)) {
2633
- return false;
2634
- }
2635
- }
2636
-
2637
- var queryStatusFilter = mapQueryStatusFilter(active, inactive);
2638
-
2639
- if (queryStatusFilter === 'none') {
2640
- return false;
2641
- } else if (queryStatusFilter !== 'all') {
2642
- var isActive = query.isActive();
2643
-
2644
- if (queryStatusFilter === 'active' && !isActive) {
2645
- return false;
2646
- }
2647
-
2648
- if (queryStatusFilter === 'inactive' && isActive) {
2649
- return false;
2650
- }
2651
- }
2652
-
2653
- if (typeof stale === 'boolean' && query.isStale() !== stale) {
2654
- return false;
2655
- }
2656
-
2657
- if (typeof fetching === 'boolean' && query.isFetching() !== fetching) {
2658
- return false;
2659
- }
2660
-
2661
- if (predicate && !predicate(query)) {
2662
- return false;
2663
- }
2664
-
2665
- return true;
2666
- }
2667
- function matchMutation(filters, mutation) {
2668
- var exact = filters.exact,
2669
- fetching = filters.fetching,
2670
- predicate = filters.predicate,
2671
- mutationKey = filters.mutationKey;
2672
-
2673
- if (isQueryKey(mutationKey)) {
2674
- if (!mutation.options.mutationKey) {
2675
- return false;
2676
- }
2677
-
2678
- if (exact) {
2679
- if (hashQueryKey(mutation.options.mutationKey) !== hashQueryKey(mutationKey)) {
2680
- return false;
2681
- }
2682
- } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {
2683
- return false;
2684
- }
2685
- }
2686
-
2687
- if (typeof fetching === 'boolean' && mutation.state.status === 'loading' !== fetching) {
2688
- return false;
2689
- }
2690
-
2691
- if (predicate && !predicate(mutation)) {
2692
- return false;
2693
- }
2694
-
2695
- return true;
2696
- }
2697
- function hashQueryKeyByOptions(queryKey, options) {
2698
- var hashFn = (options == null ? void 0 : options.queryKeyHashFn) || hashQueryKey;
2699
- return hashFn(queryKey);
2700
- }
2701
- /**
2702
- * Default query keys hash function.
2703
- */
2704
-
2705
- function hashQueryKey(queryKey) {
2706
- var asArray = ensureQueryKeyArray(queryKey);
2707
- return stableValueHash(asArray);
2708
- }
2709
- /**
2710
- * Hashes the value into a stable hash.
2711
- */
2712
-
2713
- function stableValueHash(value) {
2714
- return JSON.stringify(value, function (_, val) {
2715
- return isPlainObject$1(val) ? Object.keys(val).sort().reduce(function (result, key) {
2716
- result[key] = val[key];
2717
- return result;
2718
- }, {}) : val;
2719
- });
2720
- }
2721
- /**
2722
- * Checks if key `b` partially matches with key `a`.
2723
- */
2724
-
2725
- function partialMatchKey(a, b) {
2726
- return partialDeepEqual(ensureQueryKeyArray(a), ensureQueryKeyArray(b));
2727
- }
2728
- /**
2729
- * Checks if `b` partially matches with `a`.
2730
- */
2731
-
2732
- function partialDeepEqual(a, b) {
2733
- if (a === b) {
2734
- return true;
2735
- }
2736
-
2737
- if (typeof a !== typeof b) {
2738
- return false;
2739
- }
2740
-
2741
- if (a && b && typeof a === 'object' && typeof b === 'object') {
2742
- return !Object.keys(b).some(function (key) {
2743
- return !partialDeepEqual(a[key], b[key]);
2744
- });
2745
- }
2746
-
2747
- return false;
2748
- }
2749
- /**
2750
- * This function returns `a` if `b` is deeply equal.
2751
- * If not, it will replace any deeply equal children of `b` with those of `a`.
2752
- * This can be used for structural sharing between JSON values for example.
2753
- */
2754
-
2755
- function replaceEqualDeep(a, b) {
2756
- if (a === b) {
2757
- return a;
2758
- }
2759
-
2760
- var array = Array.isArray(a) && Array.isArray(b);
2761
-
2762
- if (array || isPlainObject$1(a) && isPlainObject$1(b)) {
2763
- var aSize = array ? a.length : Object.keys(a).length;
2764
- var bItems = array ? b : Object.keys(b);
2765
- var bSize = bItems.length;
2766
- var copy = array ? [] : {};
2767
- var equalItems = 0;
2768
-
2769
- for (var i = 0; i < bSize; i++) {
2770
- var key = array ? i : bItems[i];
2771
- copy[key] = replaceEqualDeep(a[key], b[key]);
2772
-
2773
- if (copy[key] === a[key]) {
2774
- equalItems++;
2775
- }
2776
- }
2777
-
2778
- return aSize === bSize && equalItems === aSize ? a : copy;
2779
- }
2780
-
2781
- return b;
2782
- }
2783
- /**
2784
- * Shallow compare objects. Only works with objects that always have the same properties.
2785
- */
2786
-
2787
- function shallowEqualObjects(a, b) {
2788
- if (a && !b || b && !a) {
2789
- return false;
2790
- }
2791
-
2792
- for (var key in a) {
2793
- if (a[key] !== b[key]) {
2794
- return false;
2795
- }
2796
- }
2797
-
2798
- return true;
2799
- } // Copied from: https://github.com/jonschlinkert/is-plain-object
2800
-
2801
- function isPlainObject$1(o) {
2802
- if (!hasObjectPrototype(o)) {
2803
- return false;
2804
- } // If has modified constructor
2805
-
2806
-
2807
- var ctor = o.constructor;
2808
-
2809
- if (typeof ctor === 'undefined') {
2810
- return true;
2811
- } // If has modified prototype
2812
-
2813
-
2814
- var prot = ctor.prototype;
2815
-
2816
- if (!hasObjectPrototype(prot)) {
2817
- return false;
2818
- } // If constructor does not have an Object-specific method
2819
-
2820
-
2821
- if (!prot.hasOwnProperty('isPrototypeOf')) {
2822
- return false;
2823
- } // Most likely a plain Object
2824
-
2825
-
2826
- return true;
2827
- }
2828
-
2829
- function hasObjectPrototype(o) {
2830
- return Object.prototype.toString.call(o) === '[object Object]';
2831
- }
2832
-
2833
- function isQueryKey(value) {
2834
- return typeof value === 'string' || Array.isArray(value);
2835
- }
2836
- function sleep(timeout) {
2837
- return new Promise(function (resolve) {
2838
- setTimeout(resolve, timeout);
2839
- });
2840
- }
2841
- /**
2842
- * Schedules a microtask.
2843
- * This can be useful to schedule state updates after rendering.
2844
- */
2845
-
2846
- function scheduleMicrotask(callback) {
2847
- Promise.resolve().then(callback).catch(function (error) {
2848
- return setTimeout(function () {
2849
- throw error;
2850
- });
2851
- });
2852
- }
2853
- function getAbortController() {
2854
- if (typeof AbortController === 'function') {
2855
- return new AbortController();
2856
- }
2857
- }
2858
-
2859
- var FocusManager = /*#__PURE__*/function (_Subscribable) {
2860
- _inheritsLoose(FocusManager, _Subscribable);
2861
-
2862
- function FocusManager() {
2863
- var _this;
2864
-
2865
- _this = _Subscribable.call(this) || this;
2866
-
2867
- _this.setup = function (onFocus) {
2868
- var _window;
2869
-
2870
- if (!isServer && ((_window = window) == null ? void 0 : _window.addEventListener)) {
2871
- var listener = function listener() {
2872
- return onFocus();
2873
- }; // Listen to visibillitychange and focus
2874
-
2875
-
2876
- window.addEventListener('visibilitychange', listener, false);
2877
- window.addEventListener('focus', listener, false);
2878
- return function () {
2879
- // Be sure to unsubscribe if a new handler is set
2880
- window.removeEventListener('visibilitychange', listener);
2881
- window.removeEventListener('focus', listener);
2882
- };
2883
- }
2884
- };
2885
-
2886
- return _this;
2887
- }
2888
-
2889
- var _proto = FocusManager.prototype;
2890
-
2891
- _proto.onSubscribe = function onSubscribe() {
2892
- if (!this.cleanup) {
2893
- this.setEventListener(this.setup);
2894
- }
2895
- };
2896
-
2897
- _proto.onUnsubscribe = function onUnsubscribe() {
2898
- if (!this.hasListeners()) {
2899
- var _this$cleanup;
2900
-
2901
- (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
2902
- this.cleanup = undefined;
2903
- }
2904
- };
2905
-
2906
- _proto.setEventListener = function setEventListener(setup) {
2907
- var _this$cleanup2,
2908
- _this2 = this;
2909
-
2910
- this.setup = setup;
2911
- (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
2912
- this.cleanup = setup(function (focused) {
2913
- if (typeof focused === 'boolean') {
2914
- _this2.setFocused(focused);
2915
- } else {
2916
- _this2.onFocus();
2917
- }
2918
- });
2919
- };
2920
-
2921
- _proto.setFocused = function setFocused(focused) {
2922
- this.focused = focused;
2923
-
2924
- if (focused) {
2925
- this.onFocus();
2926
- }
2927
- };
2928
-
2929
- _proto.onFocus = function onFocus() {
2930
- this.listeners.forEach(function (listener) {
2931
- listener();
2932
- });
2933
- };
2934
-
2935
- _proto.isFocused = function isFocused() {
2936
- if (typeof this.focused === 'boolean') {
2937
- return this.focused;
2938
- } // document global can be unavailable in react native
2939
-
2940
-
2941
- if (typeof document === 'undefined') {
2942
- return true;
2943
- }
2944
-
2945
- return [undefined, 'visible', 'prerender'].includes(document.visibilityState);
2946
- };
2947
-
2948
- return FocusManager;
2949
- }(Subscribable);
2950
- var focusManager = new FocusManager();
2951
-
2952
- var OnlineManager = /*#__PURE__*/function (_Subscribable) {
2953
- _inheritsLoose(OnlineManager, _Subscribable);
2954
-
2955
- function OnlineManager() {
2956
- var _this;
2957
-
2958
- _this = _Subscribable.call(this) || this;
2959
-
2960
- _this.setup = function (onOnline) {
2961
- var _window;
2962
-
2963
- if (!isServer && ((_window = window) == null ? void 0 : _window.addEventListener)) {
2964
- var listener = function listener() {
2965
- return onOnline();
2966
- }; // Listen to online
2967
-
2968
-
2969
- window.addEventListener('online', listener, false);
2970
- window.addEventListener('offline', listener, false);
2971
- return function () {
2972
- // Be sure to unsubscribe if a new handler is set
2973
- window.removeEventListener('online', listener);
2974
- window.removeEventListener('offline', listener);
2975
- };
2976
- }
2977
- };
2978
-
2979
- return _this;
2980
- }
2981
-
2982
- var _proto = OnlineManager.prototype;
2983
-
2984
- _proto.onSubscribe = function onSubscribe() {
2985
- if (!this.cleanup) {
2986
- this.setEventListener(this.setup);
2987
- }
2988
- };
2989
-
2990
- _proto.onUnsubscribe = function onUnsubscribe() {
2991
- if (!this.hasListeners()) {
2992
- var _this$cleanup;
2993
-
2994
- (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
2995
- this.cleanup = undefined;
2996
- }
2997
- };
2998
-
2999
- _proto.setEventListener = function setEventListener(setup) {
3000
- var _this$cleanup2,
3001
- _this2 = this;
3002
-
3003
- this.setup = setup;
3004
- (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
3005
- this.cleanup = setup(function (online) {
3006
- if (typeof online === 'boolean') {
3007
- _this2.setOnline(online);
3008
- } else {
3009
- _this2.onOnline();
3010
- }
3011
- });
3012
- };
3013
-
3014
- _proto.setOnline = function setOnline(online) {
3015
- this.online = online;
3016
-
3017
- if (online) {
3018
- this.onOnline();
3019
- }
3020
- };
3021
-
3022
- _proto.onOnline = function onOnline() {
3023
- this.listeners.forEach(function (listener) {
3024
- listener();
3025
- });
3026
- };
3027
-
3028
- _proto.isOnline = function isOnline() {
3029
- if (typeof this.online === 'boolean') {
3030
- return this.online;
3031
- }
3032
-
3033
- if (typeof navigator === 'undefined' || typeof navigator.onLine === 'undefined') {
3034
- return true;
3035
- }
3036
-
3037
- return navigator.onLine;
3038
- };
3039
-
3040
- return OnlineManager;
3041
- }(Subscribable);
3042
- var onlineManager = new OnlineManager();
3043
-
3044
- function defaultRetryDelay(failureCount) {
3045
- return Math.min(1000 * Math.pow(2, failureCount), 30000);
3046
- }
3047
-
3048
- function isCancelable(value) {
3049
- return typeof (value == null ? void 0 : value.cancel) === 'function';
3050
- }
3051
- var CancelledError = function CancelledError(options) {
3052
- this.revert = options == null ? void 0 : options.revert;
3053
- this.silent = options == null ? void 0 : options.silent;
3054
- };
3055
- function isCancelledError(value) {
3056
- return value instanceof CancelledError;
3057
- } // CLASS
3058
-
3059
- var Retryer = function Retryer(config) {
3060
- var _this = this;
3061
-
3062
- var cancelRetry = false;
3063
- var cancelFn;
3064
- var continueFn;
3065
- var promiseResolve;
3066
- var promiseReject;
3067
- this.abort = config.abort;
3068
-
3069
- this.cancel = function (cancelOptions) {
3070
- return cancelFn == null ? void 0 : cancelFn(cancelOptions);
3071
- };
3072
-
3073
- this.cancelRetry = function () {
3074
- cancelRetry = true;
3075
- };
3076
-
3077
- this.continueRetry = function () {
3078
- cancelRetry = false;
3079
- };
3080
-
3081
- this.continue = function () {
3082
- return continueFn == null ? void 0 : continueFn();
3083
- };
3084
-
3085
- this.failureCount = 0;
3086
- this.isPaused = false;
3087
- this.isResolved = false;
3088
- this.isTransportCancelable = false;
3089
- this.promise = new Promise(function (outerResolve, outerReject) {
3090
- promiseResolve = outerResolve;
3091
- promiseReject = outerReject;
3092
- });
3093
-
3094
- var resolve = function resolve(value) {
3095
- if (!_this.isResolved) {
3096
- _this.isResolved = true;
3097
- config.onSuccess == null ? void 0 : config.onSuccess(value);
3098
- continueFn == null ? void 0 : continueFn();
3099
- promiseResolve(value);
3100
- }
3101
- };
3102
-
3103
- var reject = function reject(value) {
3104
- if (!_this.isResolved) {
3105
- _this.isResolved = true;
3106
- config.onError == null ? void 0 : config.onError(value);
3107
- continueFn == null ? void 0 : continueFn();
3108
- promiseReject(value);
3109
- }
3110
- };
3111
-
3112
- var pause = function pause() {
3113
- return new Promise(function (continueResolve) {
3114
- continueFn = continueResolve;
3115
- _this.isPaused = true;
3116
- config.onPause == null ? void 0 : config.onPause();
3117
- }).then(function () {
3118
- continueFn = undefined;
3119
- _this.isPaused = false;
3120
- config.onContinue == null ? void 0 : config.onContinue();
3121
- });
3122
- }; // Create loop function
3123
-
3124
-
3125
- var run = function run() {
3126
- // Do nothing if already resolved
3127
- if (_this.isResolved) {
3128
- return;
3129
- }
3130
-
3131
- var promiseOrValue; // Execute query
3132
-
3133
- try {
3134
- promiseOrValue = config.fn();
3135
- } catch (error) {
3136
- promiseOrValue = Promise.reject(error);
3137
- } // Create callback to cancel this fetch
3138
-
3139
-
3140
- cancelFn = function cancelFn(cancelOptions) {
3141
- if (!_this.isResolved) {
3142
- reject(new CancelledError(cancelOptions));
3143
- _this.abort == null ? void 0 : _this.abort(); // Cancel transport if supported
3144
-
3145
- if (isCancelable(promiseOrValue)) {
3146
- try {
3147
- promiseOrValue.cancel();
3148
- } catch (_unused) {}
3149
- }
3150
- }
3151
- }; // Check if the transport layer support cancellation
3152
-
3153
-
3154
- _this.isTransportCancelable = isCancelable(promiseOrValue);
3155
- Promise.resolve(promiseOrValue).then(resolve).catch(function (error) {
3156
- var _config$retry, _config$retryDelay;
3157
-
3158
- // Stop if the fetch is already resolved
3159
- if (_this.isResolved) {
3160
- return;
3161
- } // Do we need to retry the request?
3162
-
3163
-
3164
- var retry = (_config$retry = config.retry) != null ? _config$retry : 3;
3165
- var retryDelay = (_config$retryDelay = config.retryDelay) != null ? _config$retryDelay : defaultRetryDelay;
3166
- var delay = typeof retryDelay === 'function' ? retryDelay(_this.failureCount, error) : retryDelay;
3167
- var shouldRetry = retry === true || typeof retry === 'number' && _this.failureCount < retry || typeof retry === 'function' && retry(_this.failureCount, error);
3168
-
3169
- if (cancelRetry || !shouldRetry) {
3170
- // We are done if the query does not need to be retried
3171
- reject(error);
3172
- return;
3173
- }
3174
-
3175
- _this.failureCount++; // Notify on fail
3176
-
3177
- config.onFail == null ? void 0 : config.onFail(_this.failureCount, error); // Delay
3178
-
3179
- sleep(delay) // Pause if the document is not visible or when the device is offline
3180
- .then(function () {
3181
- if (!focusManager.isFocused() || !onlineManager.isOnline()) {
3182
- return pause();
3183
- }
3184
- }).then(function () {
3185
- if (cancelRetry) {
3186
- reject(error);
3187
- } else {
3188
- run();
3189
- }
3190
- });
3191
- });
3192
- }; // Start loop
3193
-
3194
-
3195
- run();
3196
- };
3197
-
3198
- // CLASS
3199
- var NotifyManager = /*#__PURE__*/function () {
3200
- function NotifyManager() {
3201
- this.queue = [];
3202
- this.transactions = 0;
3203
-
3204
- this.notifyFn = function (callback) {
3205
- callback();
3206
- };
3207
-
3208
- this.batchNotifyFn = function (callback) {
3209
- callback();
3210
- };
3211
- }
3212
-
3213
- var _proto = NotifyManager.prototype;
3214
-
3215
- _proto.batch = function batch(callback) {
3216
- var result;
3217
- this.transactions++;
3218
-
3219
- try {
3220
- result = callback();
3221
- } finally {
3222
- this.transactions--;
3223
-
3224
- if (!this.transactions) {
3225
- this.flush();
3226
- }
3227
- }
3228
-
3229
- return result;
3230
- };
3231
-
3232
- _proto.schedule = function schedule(callback) {
3233
- var _this = this;
3234
-
3235
- if (this.transactions) {
3236
- this.queue.push(callback);
3237
- } else {
3238
- scheduleMicrotask(function () {
3239
- _this.notifyFn(callback);
3240
- });
3241
- }
3242
- }
3243
- /**
3244
- * All calls to the wrapped function will be batched.
3245
- */
3246
- ;
3247
-
3248
- _proto.batchCalls = function batchCalls(callback) {
3249
- var _this2 = this;
3250
-
3251
- return function () {
3252
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3253
- args[_key] = arguments[_key];
3254
- }
3255
-
3256
- _this2.schedule(function () {
3257
- callback.apply(void 0, args);
3258
- });
3259
- };
3260
- };
3261
-
3262
- _proto.flush = function flush() {
3263
- var _this3 = this;
3264
-
3265
- var queue = this.queue;
3266
- this.queue = [];
3267
-
3268
- if (queue.length) {
3269
- scheduleMicrotask(function () {
3270
- _this3.batchNotifyFn(function () {
3271
- queue.forEach(function (callback) {
3272
- _this3.notifyFn(callback);
3273
- });
3274
- });
3275
- });
3276
- }
3277
- }
3278
- /**
3279
- * Use this method to set a custom notify function.
3280
- * This can be used to for example wrap notifications with `React.act` while running tests.
3281
- */
3282
- ;
3283
-
3284
- _proto.setNotifyFunction = function setNotifyFunction(fn) {
3285
- this.notifyFn = fn;
3286
- }
3287
- /**
3288
- * Use this method to set a custom function to batch notifications together into a single tick.
3289
- * By default React Query will use the batch function provided by ReactDOM or React Native.
3290
- */
3291
- ;
3292
-
3293
- _proto.setBatchNotifyFunction = function setBatchNotifyFunction(fn) {
3294
- this.batchNotifyFn = fn;
3295
- };
3296
-
3297
- return NotifyManager;
3298
- }(); // SINGLETON
3299
-
3300
- var notifyManager = new NotifyManager();
3301
-
3302
- // TYPES
3303
- // FUNCTIONS
3304
- var logger$3 = console;
3305
- function getLogger() {
3306
- return logger$3;
3307
- }
3308
- function setLogger(newLogger) {
3309
- logger$3 = newLogger;
3310
- }
3311
-
3312
- // CLASS
3313
- var Query = /*#__PURE__*/function () {
3314
- function Query(config) {
3315
- this.abortSignalConsumed = false;
3316
- this.hadObservers = false;
3317
- this.defaultOptions = config.defaultOptions;
3318
- this.setOptions(config.options);
3319
- this.observers = [];
3320
- this.cache = config.cache;
3321
- this.queryKey = config.queryKey;
3322
- this.queryHash = config.queryHash;
3323
- this.initialState = config.state || this.getDefaultState(this.options);
3324
- this.state = this.initialState;
3325
- this.meta = config.meta;
3326
- this.scheduleGc();
3327
- }
3328
-
3329
- var _proto = Query.prototype;
3330
-
3331
- _proto.setOptions = function setOptions(options) {
3332
- var _this$options$cacheTi;
3333
-
3334
- this.options = _extends({}, this.defaultOptions, options);
3335
- this.meta = options == null ? void 0 : options.meta; // Default to 5 minutes if not cache time is set
3336
-
3337
- this.cacheTime = Math.max(this.cacheTime || 0, (_this$options$cacheTi = this.options.cacheTime) != null ? _this$options$cacheTi : 5 * 60 * 1000);
3338
- };
3339
-
3340
- _proto.setDefaultOptions = function setDefaultOptions(options) {
3341
- this.defaultOptions = options;
3342
- };
3343
-
3344
- _proto.scheduleGc = function scheduleGc() {
3345
- var _this = this;
3346
-
3347
- this.clearGcTimeout();
3348
-
3349
- if (isValidTimeout(this.cacheTime)) {
3350
- this.gcTimeout = setTimeout(function () {
3351
- _this.optionalRemove();
3352
- }, this.cacheTime);
3353
- }
3354
- };
3355
-
3356
- _proto.clearGcTimeout = function clearGcTimeout() {
3357
- if (this.gcTimeout) {
3358
- clearTimeout(this.gcTimeout);
3359
- this.gcTimeout = undefined;
3360
- }
3361
- };
3362
-
3363
- _proto.optionalRemove = function optionalRemove() {
3364
- if (!this.observers.length) {
3365
- if (this.state.isFetching) {
3366
- if (this.hadObservers) {
3367
- this.scheduleGc();
3368
- }
3369
- } else {
3370
- this.cache.remove(this);
3371
- }
3372
- }
3373
- };
3374
-
3375
- _proto.setData = function setData(updater, options) {
3376
- var _this$options$isDataE, _this$options;
3377
-
3378
- var prevData = this.state.data; // Get the new data
3379
-
3380
- var data = functionalUpdate(updater, prevData); // Use prev data if an isDataEqual function is defined and returns `true`
3381
-
3382
- if ((_this$options$isDataE = (_this$options = this.options).isDataEqual) == null ? void 0 : _this$options$isDataE.call(_this$options, prevData, data)) {
3383
- data = prevData;
3384
- } else if (this.options.structuralSharing !== false) {
3385
- // Structurally share data between prev and new data if needed
3386
- data = replaceEqualDeep(prevData, data);
3387
- } // Set data and mark it as cached
3388
-
3389
-
3390
- this.dispatch({
3391
- data: data,
3392
- type: 'success',
3393
- dataUpdatedAt: options == null ? void 0 : options.updatedAt
3394
- });
3395
- return data;
3396
- };
3397
-
3398
- _proto.setState = function setState(state, setStateOptions) {
3399
- this.dispatch({
3400
- type: 'setState',
3401
- state: state,
3402
- setStateOptions: setStateOptions
3403
- });
3404
- };
3405
-
3406
- _proto.cancel = function cancel(options) {
3407
- var _this$retryer;
3408
-
3409
- var promise = this.promise;
3410
- (_this$retryer = this.retryer) == null ? void 0 : _this$retryer.cancel(options);
3411
- return promise ? promise.then(noop$1).catch(noop$1) : Promise.resolve();
3412
- };
3413
-
3414
- _proto.destroy = function destroy() {
3415
- this.clearGcTimeout();
3416
- this.cancel({
3417
- silent: true
3418
- });
3419
- };
3420
-
3421
- _proto.reset = function reset() {
3422
- this.destroy();
3423
- this.setState(this.initialState);
3424
- };
3425
-
3426
- _proto.isActive = function isActive() {
3427
- return this.observers.some(function (observer) {
3428
- return observer.options.enabled !== false;
3429
- });
3430
- };
3431
-
3432
- _proto.isFetching = function isFetching() {
3433
- return this.state.isFetching;
3434
- };
3435
-
3436
- _proto.isStale = function isStale() {
3437
- return this.state.isInvalidated || !this.state.dataUpdatedAt || this.observers.some(function (observer) {
3438
- return observer.getCurrentResult().isStale;
3439
- });
3440
- };
3441
-
3442
- _proto.isStaleByTime = function isStaleByTime(staleTime) {
3443
- if (staleTime === void 0) {
3444
- staleTime = 0;
3445
- }
3446
-
3447
- return this.state.isInvalidated || !this.state.dataUpdatedAt || !timeUntilStale(this.state.dataUpdatedAt, staleTime);
3448
- };
3449
-
3450
- _proto.onFocus = function onFocus() {
3451
- var _this$retryer2;
3452
-
3453
- var observer = this.observers.find(function (x) {
3454
- return x.shouldFetchOnWindowFocus();
3455
- });
3456
-
3457
- if (observer) {
3458
- observer.refetch();
3459
- } // Continue fetch if currently paused
3460
-
3461
-
3462
- (_this$retryer2 = this.retryer) == null ? void 0 : _this$retryer2.continue();
3463
- };
3464
-
3465
- _proto.onOnline = function onOnline() {
3466
- var _this$retryer3;
3467
-
3468
- var observer = this.observers.find(function (x) {
3469
- return x.shouldFetchOnReconnect();
3470
- });
3471
-
3472
- if (observer) {
3473
- observer.refetch();
3474
- } // Continue fetch if currently paused
3475
-
3476
-
3477
- (_this$retryer3 = this.retryer) == null ? void 0 : _this$retryer3.continue();
3478
- };
3479
-
3480
- _proto.addObserver = function addObserver(observer) {
3481
- if (this.observers.indexOf(observer) === -1) {
3482
- this.observers.push(observer);
3483
- this.hadObservers = true; // Stop the query from being garbage collected
3484
-
3485
- this.clearGcTimeout();
3486
- this.cache.notify({
3487
- type: 'observerAdded',
3488
- query: this,
3489
- observer: observer
3490
- });
3491
- }
3492
- };
3493
-
3494
- _proto.removeObserver = function removeObserver(observer) {
3495
- if (this.observers.indexOf(observer) !== -1) {
3496
- this.observers = this.observers.filter(function (x) {
3497
- return x !== observer;
3498
- });
3499
-
3500
- if (!this.observers.length) {
3501
- // If the transport layer does not support cancellation
3502
- // we'll let the query continue so the result can be cached
3503
- if (this.retryer) {
3504
- if (this.retryer.isTransportCancelable || this.abortSignalConsumed) {
3505
- this.retryer.cancel({
3506
- revert: true
3507
- });
3508
- } else {
3509
- this.retryer.cancelRetry();
3510
- }
3511
- }
3512
-
3513
- if (this.cacheTime) {
3514
- this.scheduleGc();
3515
- } else {
3516
- this.cache.remove(this);
3517
- }
3518
- }
3519
-
3520
- this.cache.notify({
3521
- type: 'observerRemoved',
3522
- query: this,
3523
- observer: observer
3524
- });
3525
- }
3526
- };
3527
-
3528
- _proto.getObserversCount = function getObserversCount() {
3529
- return this.observers.length;
3530
- };
3531
-
3532
- _proto.invalidate = function invalidate() {
3533
- if (!this.state.isInvalidated) {
3534
- this.dispatch({
3535
- type: 'invalidate'
3536
- });
3537
- }
3538
- };
3539
-
3540
- _proto.fetch = function fetch(options, fetchOptions) {
3541
- var _this2 = this,
3542
- _this$options$behavio,
3543
- _context$fetchOptions,
3544
- _abortController$abor;
3545
-
3546
- if (this.state.isFetching) {
3547
- if (this.state.dataUpdatedAt && (fetchOptions == null ? void 0 : fetchOptions.cancelRefetch)) {
3548
- // Silently cancel current fetch if the user wants to cancel refetches
3549
- this.cancel({
3550
- silent: true
3551
- });
3552
- } else if (this.promise) {
3553
- var _this$retryer4;
3554
-
3555
- // make sure that retries that were potentially cancelled due to unmounts can continue
3556
- (_this$retryer4 = this.retryer) == null ? void 0 : _this$retryer4.continueRetry(); // Return current promise if we are already fetching
3557
-
3558
- return this.promise;
3559
- }
3560
- } // Update config if passed, otherwise the config from the last execution is used
3561
-
3562
-
3563
- if (options) {
3564
- this.setOptions(options);
3565
- } // Use the options from the first observer with a query function if no function is found.
3566
- // This can happen when the query is hydrated or created with setQueryData.
3567
-
3568
-
3569
- if (!this.options.queryFn) {
3570
- var observer = this.observers.find(function (x) {
3571
- return x.options.queryFn;
3572
- });
3573
-
3574
- if (observer) {
3575
- this.setOptions(observer.options);
3576
- }
3577
- }
3578
-
3579
- var queryKey = ensureQueryKeyArray(this.queryKey);
3580
- var abortController = getAbortController(); // Create query function context
3581
-
3582
- var queryFnContext = {
3583
- queryKey: queryKey,
3584
- pageParam: undefined,
3585
- meta: this.meta
3586
- };
3587
- Object.defineProperty(queryFnContext, 'signal', {
3588
- enumerable: true,
3589
- get: function get() {
3590
- if (abortController) {
3591
- _this2.abortSignalConsumed = true;
3592
- return abortController.signal;
3593
- }
3594
-
3595
- return undefined;
3596
- }
3597
- }); // Create fetch function
3598
-
3599
- var fetchFn = function fetchFn() {
3600
- if (!_this2.options.queryFn) {
3601
- return Promise.reject('Missing queryFn');
3602
- }
3603
-
3604
- _this2.abortSignalConsumed = false;
3605
- return _this2.options.queryFn(queryFnContext);
3606
- }; // Trigger behavior hook
3607
-
3608
-
3609
- var context = {
3610
- fetchOptions: fetchOptions,
3611
- options: this.options,
3612
- queryKey: queryKey,
3613
- state: this.state,
3614
- fetchFn: fetchFn,
3615
- meta: this.meta
3616
- };
3617
-
3618
- if ((_this$options$behavio = this.options.behavior) == null ? void 0 : _this$options$behavio.onFetch) {
3619
- var _this$options$behavio2;
3620
-
3621
- (_this$options$behavio2 = this.options.behavior) == null ? void 0 : _this$options$behavio2.onFetch(context);
3622
- } // Store state in case the current fetch needs to be reverted
3623
-
3624
-
3625
- this.revertState = this.state; // Set to fetching state if not already in it
3626
-
3627
- if (!this.state.isFetching || this.state.fetchMeta !== ((_context$fetchOptions = context.fetchOptions) == null ? void 0 : _context$fetchOptions.meta)) {
3628
- var _context$fetchOptions2;
3629
-
3630
- this.dispatch({
3631
- type: 'fetch',
3632
- meta: (_context$fetchOptions2 = context.fetchOptions) == null ? void 0 : _context$fetchOptions2.meta
3633
- });
3634
- } // Try to fetch the data
3635
-
3636
-
3637
- this.retryer = new Retryer({
3638
- fn: context.fetchFn,
3639
- abort: abortController == null ? void 0 : (_abortController$abor = abortController.abort) == null ? void 0 : _abortController$abor.bind(abortController),
3640
- onSuccess: function onSuccess(data) {
3641
- _this2.setData(data); // Notify cache callback
3642
-
3643
-
3644
- _this2.cache.config.onSuccess == null ? void 0 : _this2.cache.config.onSuccess(data, _this2); // Remove query after fetching if cache time is 0
3645
-
3646
- if (_this2.cacheTime === 0) {
3647
- _this2.optionalRemove();
3648
- }
3649
- },
3650
- onError: function onError(error) {
3651
- // Optimistically update state if needed
3652
- if (!(isCancelledError(error) && error.silent)) {
3653
- _this2.dispatch({
3654
- type: 'error',
3655
- error: error
3656
- });
3657
- }
3658
-
3659
- if (!isCancelledError(error)) {
3660
- // Notify cache callback
3661
- _this2.cache.config.onError == null ? void 0 : _this2.cache.config.onError(error, _this2); // Log error
3662
-
3663
- getLogger().error(error);
3664
- } // Remove query after fetching if cache time is 0
3665
-
3666
-
3667
- if (_this2.cacheTime === 0) {
3668
- _this2.optionalRemove();
3669
- }
3670
- },
3671
- onFail: function onFail() {
3672
- _this2.dispatch({
3673
- type: 'failed'
3674
- });
3675
- },
3676
- onPause: function onPause() {
3677
- _this2.dispatch({
3678
- type: 'pause'
3679
- });
3680
- },
3681
- onContinue: function onContinue() {
3682
- _this2.dispatch({
3683
- type: 'continue'
3684
- });
3685
- },
3686
- retry: context.options.retry,
3687
- retryDelay: context.options.retryDelay
3688
- });
3689
- this.promise = this.retryer.promise;
3690
- return this.promise;
3691
- };
3692
-
3693
- _proto.dispatch = function dispatch(action) {
3694
- var _this3 = this;
3695
-
3696
- this.state = this.reducer(this.state, action);
3697
- notifyManager.batch(function () {
3698
- _this3.observers.forEach(function (observer) {
3699
- observer.onQueryUpdate(action);
3700
- });
3701
-
3702
- _this3.cache.notify({
3703
- query: _this3,
3704
- type: 'queryUpdated',
3705
- action: action
3706
- });
3707
- });
3708
- };
3709
-
3710
- _proto.getDefaultState = function getDefaultState(options) {
3711
- var data = typeof options.initialData === 'function' ? options.initialData() : options.initialData;
3712
- var hasInitialData = typeof options.initialData !== 'undefined';
3713
- var initialDataUpdatedAt = hasInitialData ? typeof options.initialDataUpdatedAt === 'function' ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
3714
- var hasData = typeof data !== 'undefined';
3715
- return {
3716
- data: data,
3717
- dataUpdateCount: 0,
3718
- dataUpdatedAt: hasData ? initialDataUpdatedAt != null ? initialDataUpdatedAt : Date.now() : 0,
3719
- error: null,
3720
- errorUpdateCount: 0,
3721
- errorUpdatedAt: 0,
3722
- fetchFailureCount: 0,
3723
- fetchMeta: null,
3724
- isFetching: false,
3725
- isInvalidated: false,
3726
- isPaused: false,
3727
- status: hasData ? 'success' : 'idle'
3728
- };
3729
- };
3730
-
3731
- _proto.reducer = function reducer(state, action) {
3732
- var _action$meta, _action$dataUpdatedAt;
3733
-
3734
- switch (action.type) {
3735
- case 'failed':
3736
- return _extends({}, state, {
3737
- fetchFailureCount: state.fetchFailureCount + 1
3738
- });
3739
-
3740
- case 'pause':
3741
- return _extends({}, state, {
3742
- isPaused: true
3743
- });
3744
-
3745
- case 'continue':
3746
- return _extends({}, state, {
3747
- isPaused: false
3748
- });
3749
-
3750
- case 'fetch':
3751
- return _extends({}, state, {
3752
- fetchFailureCount: 0,
3753
- fetchMeta: (_action$meta = action.meta) != null ? _action$meta : null,
3754
- isFetching: true,
3755
- isPaused: false
3756
- }, !state.dataUpdatedAt && {
3757
- error: null,
3758
- status: 'loading'
3759
- });
3760
-
3761
- case 'success':
3762
- return _extends({}, state, {
3763
- data: action.data,
3764
- dataUpdateCount: state.dataUpdateCount + 1,
3765
- dataUpdatedAt: (_action$dataUpdatedAt = action.dataUpdatedAt) != null ? _action$dataUpdatedAt : Date.now(),
3766
- error: null,
3767
- fetchFailureCount: 0,
3768
- isFetching: false,
3769
- isInvalidated: false,
3770
- isPaused: false,
3771
- status: 'success'
3772
- });
3773
-
3774
- case 'error':
3775
- var error = action.error;
3776
-
3777
- if (isCancelledError(error) && error.revert && this.revertState) {
3778
- return _extends({}, this.revertState);
3779
- }
3780
-
3781
- return _extends({}, state, {
3782
- error: error,
3783
- errorUpdateCount: state.errorUpdateCount + 1,
3784
- errorUpdatedAt: Date.now(),
3785
- fetchFailureCount: state.fetchFailureCount + 1,
3786
- isFetching: false,
3787
- isPaused: false,
3788
- status: 'error'
3789
- });
3790
-
3791
- case 'invalidate':
3792
- return _extends({}, state, {
3793
- isInvalidated: true
3794
- });
3795
-
3796
- case 'setState':
3797
- return _extends({}, state, action.state);
3798
-
3799
- default:
3800
- return state;
3801
- }
3802
- };
3803
-
3804
- return Query;
3805
- }();
3806
-
3807
- // CLASS
3808
- var QueryCache = /*#__PURE__*/function (_Subscribable) {
3809
- _inheritsLoose(QueryCache, _Subscribable);
3810
-
3811
- function QueryCache(config) {
3812
- var _this;
3813
-
3814
- _this = _Subscribable.call(this) || this;
3815
- _this.config = config || {};
3816
- _this.queries = [];
3817
- _this.queriesMap = {};
3818
- return _this;
3819
- }
3820
-
3821
- var _proto = QueryCache.prototype;
3822
-
3823
- _proto.build = function build(client, options, state) {
3824
- var _options$queryHash;
3825
-
3826
- var queryKey = options.queryKey;
3827
- var queryHash = (_options$queryHash = options.queryHash) != null ? _options$queryHash : hashQueryKeyByOptions(queryKey, options);
3828
- var query = this.get(queryHash);
3829
-
3830
- if (!query) {
3831
- query = new Query({
3832
- cache: this,
3833
- queryKey: queryKey,
3834
- queryHash: queryHash,
3835
- options: client.defaultQueryOptions(options),
3836
- state: state,
3837
- defaultOptions: client.getQueryDefaults(queryKey),
3838
- meta: options.meta
3839
- });
3840
- this.add(query);
3841
- }
3842
-
3843
- return query;
3844
- };
3845
-
3846
- _proto.add = function add(query) {
3847
- if (!this.queriesMap[query.queryHash]) {
3848
- this.queriesMap[query.queryHash] = query;
3849
- this.queries.push(query);
3850
- this.notify({
3851
- type: 'queryAdded',
3852
- query: query
3853
- });
3854
- }
3855
- };
3856
-
3857
- _proto.remove = function remove(query) {
3858
- var queryInMap = this.queriesMap[query.queryHash];
3859
-
3860
- if (queryInMap) {
3861
- query.destroy();
3862
- this.queries = this.queries.filter(function (x) {
3863
- return x !== query;
3864
- });
3865
-
3866
- if (queryInMap === query) {
3867
- delete this.queriesMap[query.queryHash];
3868
- }
3869
-
3870
- this.notify({
3871
- type: 'queryRemoved',
3872
- query: query
3873
- });
3874
- }
3875
- };
3876
-
3877
- _proto.clear = function clear() {
3878
- var _this2 = this;
3879
-
3880
- notifyManager.batch(function () {
3881
- _this2.queries.forEach(function (query) {
3882
- _this2.remove(query);
3883
- });
3884
- });
3885
- };
3886
-
3887
- _proto.get = function get(queryHash) {
3888
- return this.queriesMap[queryHash];
3889
- };
3890
-
3891
- _proto.getAll = function getAll() {
3892
- return this.queries;
3893
- };
3894
-
3895
- _proto.find = function find(arg1, arg2) {
3896
- var _parseFilterArgs = parseFilterArgs(arg1, arg2),
3897
- filters = _parseFilterArgs[0];
3898
-
3899
- if (typeof filters.exact === 'undefined') {
3900
- filters.exact = true;
3901
- }
3902
-
3903
- return this.queries.find(function (query) {
3904
- return matchQuery(filters, query);
3905
- });
3906
- };
3907
-
3908
- _proto.findAll = function findAll(arg1, arg2) {
3909
- var _parseFilterArgs2 = parseFilterArgs(arg1, arg2),
3910
- filters = _parseFilterArgs2[0];
3911
-
3912
- return Object.keys(filters).length > 0 ? this.queries.filter(function (query) {
3913
- return matchQuery(filters, query);
3914
- }) : this.queries;
3915
- };
3916
-
3917
- _proto.notify = function notify(event) {
3918
- var _this3 = this;
3919
-
3920
- notifyManager.batch(function () {
3921
- _this3.listeners.forEach(function (listener) {
3922
- listener(event);
3923
- });
3924
- });
3925
- };
3926
-
3927
- _proto.onFocus = function onFocus() {
3928
- var _this4 = this;
3929
-
3930
- notifyManager.batch(function () {
3931
- _this4.queries.forEach(function (query) {
3932
- query.onFocus();
3933
- });
3934
- });
3935
- };
3936
-
3937
- _proto.onOnline = function onOnline() {
3938
- var _this5 = this;
3939
-
3940
- notifyManager.batch(function () {
3941
- _this5.queries.forEach(function (query) {
3942
- query.onOnline();
3943
- });
3944
- });
3945
- };
3946
-
3947
- return QueryCache;
3948
- }(Subscribable);
3949
-
3950
- // CLASS
3951
- var Mutation = /*#__PURE__*/function () {
3952
- function Mutation(config) {
3953
- this.options = _extends({}, config.defaultOptions, config.options);
3954
- this.mutationId = config.mutationId;
3955
- this.mutationCache = config.mutationCache;
3956
- this.observers = [];
3957
- this.state = config.state || getDefaultState();
3958
- this.meta = config.meta;
3959
- }
3960
-
3961
- var _proto = Mutation.prototype;
3962
-
3963
- _proto.setState = function setState(state) {
3964
- this.dispatch({
3965
- type: 'setState',
3966
- state: state
3967
- });
3968
- };
3969
-
3970
- _proto.addObserver = function addObserver(observer) {
3971
- if (this.observers.indexOf(observer) === -1) {
3972
- this.observers.push(observer);
3973
- }
3974
- };
3975
-
3976
- _proto.removeObserver = function removeObserver(observer) {
3977
- this.observers = this.observers.filter(function (x) {
3978
- return x !== observer;
3979
- });
3980
- };
3981
-
3982
- _proto.cancel = function cancel() {
3983
- if (this.retryer) {
3984
- this.retryer.cancel();
3985
- return this.retryer.promise.then(noop$1).catch(noop$1);
3986
- }
3987
-
3988
- return Promise.resolve();
3989
- };
3990
-
3991
- _proto.continue = function _continue() {
3992
- if (this.retryer) {
3993
- this.retryer.continue();
3994
- return this.retryer.promise;
3995
- }
3996
-
3997
- return this.execute();
3998
- };
3999
-
4000
- _proto.execute = function execute() {
4001
- var _this = this;
4002
-
4003
- var data;
4004
- var restored = this.state.status === 'loading';
4005
- var promise = Promise.resolve();
4006
-
4007
- if (!restored) {
4008
- this.dispatch({
4009
- type: 'loading',
4010
- variables: this.options.variables
4011
- });
4012
- promise = promise.then(function () {
4013
- // Notify cache callback
4014
- _this.mutationCache.config.onMutate == null ? void 0 : _this.mutationCache.config.onMutate(_this.state.variables, _this);
4015
- }).then(function () {
4016
- return _this.options.onMutate == null ? void 0 : _this.options.onMutate(_this.state.variables);
4017
- }).then(function (context) {
4018
- if (context !== _this.state.context) {
4019
- _this.dispatch({
4020
- type: 'loading',
4021
- context: context,
4022
- variables: _this.state.variables
4023
- });
4024
- }
4025
- });
4026
- }
4027
-
4028
- return promise.then(function () {
4029
- return _this.executeMutation();
4030
- }).then(function (result) {
4031
- data = result; // Notify cache callback
4032
-
4033
- _this.mutationCache.config.onSuccess == null ? void 0 : _this.mutationCache.config.onSuccess(data, _this.state.variables, _this.state.context, _this);
4034
- }).then(function () {
4035
- return _this.options.onSuccess == null ? void 0 : _this.options.onSuccess(data, _this.state.variables, _this.state.context);
4036
- }).then(function () {
4037
- return _this.options.onSettled == null ? void 0 : _this.options.onSettled(data, null, _this.state.variables, _this.state.context);
4038
- }).then(function () {
4039
- _this.dispatch({
4040
- type: 'success',
4041
- data: data
4042
- });
4043
-
4044
- return data;
4045
- }).catch(function (error) {
4046
- // Notify cache callback
4047
- _this.mutationCache.config.onError == null ? void 0 : _this.mutationCache.config.onError(error, _this.state.variables, _this.state.context, _this); // Log error
4048
-
4049
- getLogger().error(error);
4050
- return Promise.resolve().then(function () {
4051
- return _this.options.onError == null ? void 0 : _this.options.onError(error, _this.state.variables, _this.state.context);
4052
- }).then(function () {
4053
- return _this.options.onSettled == null ? void 0 : _this.options.onSettled(undefined, error, _this.state.variables, _this.state.context);
4054
- }).then(function () {
4055
- _this.dispatch({
4056
- type: 'error',
4057
- error: error
4058
- });
4059
-
4060
- throw error;
4061
- });
4062
- });
4063
- };
4064
-
4065
- _proto.executeMutation = function executeMutation() {
4066
- var _this2 = this,
4067
- _this$options$retry;
4068
-
4069
- this.retryer = new Retryer({
4070
- fn: function fn() {
4071
- if (!_this2.options.mutationFn) {
4072
- return Promise.reject('No mutationFn found');
4073
- }
4074
-
4075
- return _this2.options.mutationFn(_this2.state.variables);
4076
- },
4077
- onFail: function onFail() {
4078
- _this2.dispatch({
4079
- type: 'failed'
4080
- });
4081
- },
4082
- onPause: function onPause() {
4083
- _this2.dispatch({
4084
- type: 'pause'
4085
- });
4086
- },
4087
- onContinue: function onContinue() {
4088
- _this2.dispatch({
4089
- type: 'continue'
4090
- });
4091
- },
4092
- retry: (_this$options$retry = this.options.retry) != null ? _this$options$retry : 0,
4093
- retryDelay: this.options.retryDelay
4094
- });
4095
- return this.retryer.promise;
4096
- };
4097
-
4098
- _proto.dispatch = function dispatch(action) {
4099
- var _this3 = this;
4100
-
4101
- this.state = reducer(this.state, action);
4102
- notifyManager.batch(function () {
4103
- _this3.observers.forEach(function (observer) {
4104
- observer.onMutationUpdate(action);
4105
- });
4106
-
4107
- _this3.mutationCache.notify(_this3);
4108
- });
4109
- };
4110
-
4111
- return Mutation;
4112
- }();
4113
- function getDefaultState() {
4114
- return {
4115
- context: undefined,
4116
- data: undefined,
4117
- error: null,
4118
- failureCount: 0,
4119
- isPaused: false,
4120
- status: 'idle',
4121
- variables: undefined
4122
- };
4123
- }
4124
-
4125
- function reducer(state, action) {
4126
- switch (action.type) {
4127
- case 'failed':
4128
- return _extends({}, state, {
4129
- failureCount: state.failureCount + 1
4130
- });
4131
-
4132
- case 'pause':
4133
- return _extends({}, state, {
4134
- isPaused: true
4135
- });
4136
-
4137
- case 'continue':
4138
- return _extends({}, state, {
4139
- isPaused: false
4140
- });
4141
-
4142
- case 'loading':
4143
- return _extends({}, state, {
4144
- context: action.context,
4145
- data: undefined,
4146
- error: null,
4147
- isPaused: false,
4148
- status: 'loading',
4149
- variables: action.variables
4150
- });
4151
-
4152
- case 'success':
4153
- return _extends({}, state, {
4154
- data: action.data,
4155
- error: null,
4156
- status: 'success',
4157
- isPaused: false
4158
- });
4159
-
4160
- case 'error':
4161
- return _extends({}, state, {
4162
- data: undefined,
4163
- error: action.error,
4164
- failureCount: state.failureCount + 1,
4165
- isPaused: false,
4166
- status: 'error'
4167
- });
4168
-
4169
- case 'setState':
4170
- return _extends({}, state, action.state);
4171
-
4172
- default:
4173
- return state;
4174
- }
4175
- }
4176
-
4177
- // CLASS
4178
- var MutationCache = /*#__PURE__*/function (_Subscribable) {
4179
- _inheritsLoose(MutationCache, _Subscribable);
4180
-
4181
- function MutationCache(config) {
4182
- var _this;
4183
-
4184
- _this = _Subscribable.call(this) || this;
4185
- _this.config = config || {};
4186
- _this.mutations = [];
4187
- _this.mutationId = 0;
4188
- return _this;
4189
- }
4190
-
4191
- var _proto = MutationCache.prototype;
4192
-
4193
- _proto.build = function build(client, options, state) {
4194
- var mutation = new Mutation({
4195
- mutationCache: this,
4196
- mutationId: ++this.mutationId,
4197
- options: client.defaultMutationOptions(options),
4198
- state: state,
4199
- defaultOptions: options.mutationKey ? client.getMutationDefaults(options.mutationKey) : undefined,
4200
- meta: options.meta
4201
- });
4202
- this.add(mutation);
4203
- return mutation;
4204
- };
4205
-
4206
- _proto.add = function add(mutation) {
4207
- this.mutations.push(mutation);
4208
- this.notify(mutation);
4209
- };
4210
-
4211
- _proto.remove = function remove(mutation) {
4212
- this.mutations = this.mutations.filter(function (x) {
4213
- return x !== mutation;
4214
- });
4215
- mutation.cancel();
4216
- this.notify(mutation);
4217
- };
4218
-
4219
- _proto.clear = function clear() {
4220
- var _this2 = this;
4221
-
4222
- notifyManager.batch(function () {
4223
- _this2.mutations.forEach(function (mutation) {
4224
- _this2.remove(mutation);
4225
- });
4226
- });
4227
- };
4228
-
4229
- _proto.getAll = function getAll() {
4230
- return this.mutations;
4231
- };
4232
-
4233
- _proto.find = function find(filters) {
4234
- if (typeof filters.exact === 'undefined') {
4235
- filters.exact = true;
4236
- }
4237
-
4238
- return this.mutations.find(function (mutation) {
4239
- return matchMutation(filters, mutation);
4240
- });
4241
- };
4242
-
4243
- _proto.findAll = function findAll(filters) {
4244
- return this.mutations.filter(function (mutation) {
4245
- return matchMutation(filters, mutation);
4246
- });
4247
- };
4248
-
4249
- _proto.notify = function notify(mutation) {
4250
- var _this3 = this;
4251
-
4252
- notifyManager.batch(function () {
4253
- _this3.listeners.forEach(function (listener) {
4254
- listener(mutation);
4255
- });
4256
- });
4257
- };
4258
-
4259
- _proto.onFocus = function onFocus() {
4260
- this.resumePausedMutations();
4261
- };
4262
-
4263
- _proto.onOnline = function onOnline() {
4264
- this.resumePausedMutations();
4265
- };
4266
-
4267
- _proto.resumePausedMutations = function resumePausedMutations() {
4268
- var pausedMutations = this.mutations.filter(function (x) {
4269
- return x.state.isPaused;
4270
- });
4271
- return notifyManager.batch(function () {
4272
- return pausedMutations.reduce(function (promise, mutation) {
4273
- return promise.then(function () {
4274
- return mutation.continue().catch(noop$1);
4275
- });
4276
- }, Promise.resolve());
4277
- });
4278
- };
4279
-
4280
- return MutationCache;
4281
- }(Subscribable);
4282
-
4283
- function infiniteQueryBehavior() {
4284
- return {
4285
- onFetch: function onFetch(context) {
4286
- context.fetchFn = function () {
4287
- var _context$fetchOptions, _context$fetchOptions2, _context$fetchOptions3, _context$fetchOptions4, _context$state$data, _context$state$data2;
4288
-
4289
- var refetchPage = (_context$fetchOptions = context.fetchOptions) == null ? void 0 : (_context$fetchOptions2 = _context$fetchOptions.meta) == null ? void 0 : _context$fetchOptions2.refetchPage;
4290
- var fetchMore = (_context$fetchOptions3 = context.fetchOptions) == null ? void 0 : (_context$fetchOptions4 = _context$fetchOptions3.meta) == null ? void 0 : _context$fetchOptions4.fetchMore;
4291
- var pageParam = fetchMore == null ? void 0 : fetchMore.pageParam;
4292
- var isFetchingNextPage = (fetchMore == null ? void 0 : fetchMore.direction) === 'forward';
4293
- var isFetchingPreviousPage = (fetchMore == null ? void 0 : fetchMore.direction) === 'backward';
4294
- var oldPages = ((_context$state$data = context.state.data) == null ? void 0 : _context$state$data.pages) || [];
4295
- var oldPageParams = ((_context$state$data2 = context.state.data) == null ? void 0 : _context$state$data2.pageParams) || [];
4296
- var abortController = getAbortController();
4297
- var abortSignal = abortController == null ? void 0 : abortController.signal;
4298
- var newPageParams = oldPageParams;
4299
- var cancelled = false; // Get query function
4300
-
4301
- var queryFn = context.options.queryFn || function () {
4302
- return Promise.reject('Missing queryFn');
4303
- };
4304
-
4305
- var buildNewPages = function buildNewPages(pages, param, page, previous) {
4306
- newPageParams = previous ? [param].concat(newPageParams) : [].concat(newPageParams, [param]);
4307
- return previous ? [page].concat(pages) : [].concat(pages, [page]);
4308
- }; // Create function to fetch a page
4309
-
4310
-
4311
- var fetchPage = function fetchPage(pages, manual, param, previous) {
4312
- if (cancelled) {
4313
- return Promise.reject('Cancelled');
4314
- }
4315
-
4316
- if (typeof param === 'undefined' && !manual && pages.length) {
4317
- return Promise.resolve(pages);
4318
- }
4319
-
4320
- var queryFnContext = {
4321
- queryKey: context.queryKey,
4322
- signal: abortSignal,
4323
- pageParam: param,
4324
- meta: context.meta
4325
- };
4326
- var queryFnResult = queryFn(queryFnContext);
4327
- var promise = Promise.resolve(queryFnResult).then(function (page) {
4328
- return buildNewPages(pages, param, page, previous);
4329
- });
4330
-
4331
- if (isCancelable(queryFnResult)) {
4332
- var promiseAsAny = promise;
4333
- promiseAsAny.cancel = queryFnResult.cancel;
4334
- }
4335
-
4336
- return promise;
4337
- };
4338
-
4339
- var promise; // Fetch first page?
4340
-
4341
- if (!oldPages.length) {
4342
- promise = fetchPage([]);
4343
- } // Fetch next page?
4344
- else if (isFetchingNextPage) {
4345
- var manual = typeof pageParam !== 'undefined';
4346
- var param = manual ? pageParam : getNextPageParam(context.options, oldPages);
4347
- promise = fetchPage(oldPages, manual, param);
4348
- } // Fetch previous page?
4349
- else if (isFetchingPreviousPage) {
4350
- var _manual = typeof pageParam !== 'undefined';
4351
-
4352
- var _param = _manual ? pageParam : getPreviousPageParam(context.options, oldPages);
4353
-
4354
- promise = fetchPage(oldPages, _manual, _param, true);
4355
- } // Refetch pages
4356
- else {
4357
- (function () {
4358
- newPageParams = [];
4359
- var manual = typeof context.options.getNextPageParam === 'undefined';
4360
- var shouldFetchFirstPage = refetchPage && oldPages[0] ? refetchPage(oldPages[0], 0, oldPages) : true; // Fetch first page
4361
-
4362
- promise = shouldFetchFirstPage ? fetchPage([], manual, oldPageParams[0]) : Promise.resolve(buildNewPages([], oldPageParams[0], oldPages[0])); // Fetch remaining pages
4363
-
4364
- var _loop = function _loop(i) {
4365
- promise = promise.then(function (pages) {
4366
- var shouldFetchNextPage = refetchPage && oldPages[i] ? refetchPage(oldPages[i], i, oldPages) : true;
4367
-
4368
- if (shouldFetchNextPage) {
4369
- var _param2 = manual ? oldPageParams[i] : getNextPageParam(context.options, pages);
4370
-
4371
- return fetchPage(pages, manual, _param2);
4372
- }
4373
-
4374
- return Promise.resolve(buildNewPages(pages, oldPageParams[i], oldPages[i]));
4375
- });
4376
- };
4377
-
4378
- for (var i = 1; i < oldPages.length; i++) {
4379
- _loop(i);
4380
- }
4381
- })();
4382
- }
4383
-
4384
- var finalPromise = promise.then(function (pages) {
4385
- return {
4386
- pages: pages,
4387
- pageParams: newPageParams
4388
- };
4389
- });
4390
- var finalPromiseAsAny = finalPromise;
4391
-
4392
- finalPromiseAsAny.cancel = function () {
4393
- cancelled = true;
4394
- abortController == null ? void 0 : abortController.abort();
4395
-
4396
- if (isCancelable(promise)) {
4397
- promise.cancel();
4398
- }
4399
- };
4400
-
4401
- return finalPromise;
4402
- };
4403
- }
4404
- };
4405
- }
4406
- function getNextPageParam(options, pages) {
4407
- return options.getNextPageParam == null ? void 0 : options.getNextPageParam(pages[pages.length - 1], pages);
4408
- }
4409
- function getPreviousPageParam(options, pages) {
4410
- return options.getPreviousPageParam == null ? void 0 : options.getPreviousPageParam(pages[0], pages);
4411
- }
4412
-
4413
- // CLASS
4414
- var QueryClient = /*#__PURE__*/function () {
4415
- function QueryClient(config) {
4416
- if (config === void 0) {
4417
- config = {};
4418
- }
4419
-
4420
- this.queryCache = config.queryCache || new QueryCache();
4421
- this.mutationCache = config.mutationCache || new MutationCache();
4422
- this.defaultOptions = config.defaultOptions || {};
4423
- this.queryDefaults = [];
4424
- this.mutationDefaults = [];
4425
- }
4426
-
4427
- var _proto = QueryClient.prototype;
4428
-
4429
- _proto.mount = function mount() {
4430
- var _this = this;
4431
-
4432
- this.unsubscribeFocus = focusManager.subscribe(function () {
4433
- if (focusManager.isFocused() && onlineManager.isOnline()) {
4434
- _this.mutationCache.onFocus();
4435
-
4436
- _this.queryCache.onFocus();
4437
- }
4438
- });
4439
- this.unsubscribeOnline = onlineManager.subscribe(function () {
4440
- if (focusManager.isFocused() && onlineManager.isOnline()) {
4441
- _this.mutationCache.onOnline();
4442
-
4443
- _this.queryCache.onOnline();
4444
- }
4445
- });
4446
- };
4447
-
4448
- _proto.unmount = function unmount() {
4449
- var _this$unsubscribeFocu, _this$unsubscribeOnli;
4450
-
4451
- (_this$unsubscribeFocu = this.unsubscribeFocus) == null ? void 0 : _this$unsubscribeFocu.call(this);
4452
- (_this$unsubscribeOnli = this.unsubscribeOnline) == null ? void 0 : _this$unsubscribeOnli.call(this);
4453
- };
4454
-
4455
- _proto.isFetching = function isFetching(arg1, arg2) {
4456
- var _parseFilterArgs = parseFilterArgs(arg1, arg2),
4457
- filters = _parseFilterArgs[0];
4458
-
4459
- filters.fetching = true;
4460
- return this.queryCache.findAll(filters).length;
4461
- };
4462
-
4463
- _proto.isMutating = function isMutating(filters) {
4464
- return this.mutationCache.findAll(_extends({}, filters, {
4465
- fetching: true
4466
- })).length;
4467
- };
4468
-
4469
- _proto.getQueryData = function getQueryData(queryKey, filters) {
4470
- var _this$queryCache$find;
4471
-
4472
- return (_this$queryCache$find = this.queryCache.find(queryKey, filters)) == null ? void 0 : _this$queryCache$find.state.data;
4473
- };
4474
-
4475
- _proto.getQueriesData = function getQueriesData(queryKeyOrFilters) {
4476
- return this.getQueryCache().findAll(queryKeyOrFilters).map(function (_ref) {
4477
- var queryKey = _ref.queryKey,
4478
- state = _ref.state;
4479
- var data = state.data;
4480
- return [queryKey, data];
4481
- });
4482
- };
4483
-
4484
- _proto.setQueryData = function setQueryData(queryKey, updater, options) {
4485
- var parsedOptions = parseQueryArgs(queryKey);
4486
- var defaultedOptions = this.defaultQueryOptions(parsedOptions);
4487
- return this.queryCache.build(this, defaultedOptions).setData(updater, options);
4488
- };
4489
-
4490
- _proto.setQueriesData = function setQueriesData(queryKeyOrFilters, updater, options) {
4491
- var _this2 = this;
4492
-
4493
- return notifyManager.batch(function () {
4494
- return _this2.getQueryCache().findAll(queryKeyOrFilters).map(function (_ref2) {
4495
- var queryKey = _ref2.queryKey;
4496
- return [queryKey, _this2.setQueryData(queryKey, updater, options)];
4497
- });
4498
- });
4499
- };
4500
-
4501
- _proto.getQueryState = function getQueryState(queryKey, filters) {
4502
- var _this$queryCache$find2;
4503
-
4504
- return (_this$queryCache$find2 = this.queryCache.find(queryKey, filters)) == null ? void 0 : _this$queryCache$find2.state;
4505
- };
4506
-
4507
- _proto.removeQueries = function removeQueries(arg1, arg2) {
4508
- var _parseFilterArgs2 = parseFilterArgs(arg1, arg2),
4509
- filters = _parseFilterArgs2[0];
4510
-
4511
- var queryCache = this.queryCache;
4512
- notifyManager.batch(function () {
4513
- queryCache.findAll(filters).forEach(function (query) {
4514
- queryCache.remove(query);
4515
- });
4516
- });
4517
- };
4518
-
4519
- _proto.resetQueries = function resetQueries(arg1, arg2, arg3) {
4520
- var _this3 = this;
4521
-
4522
- var _parseFilterArgs3 = parseFilterArgs(arg1, arg2, arg3),
4523
- filters = _parseFilterArgs3[0],
4524
- options = _parseFilterArgs3[1];
4525
-
4526
- var queryCache = this.queryCache;
4527
-
4528
- var refetchFilters = _extends({}, filters, {
4529
- active: true
4530
- });
4531
-
4532
- return notifyManager.batch(function () {
4533
- queryCache.findAll(filters).forEach(function (query) {
4534
- query.reset();
4535
- });
4536
- return _this3.refetchQueries(refetchFilters, options);
4537
- });
4538
- };
4539
-
4540
- _proto.cancelQueries = function cancelQueries(arg1, arg2, arg3) {
4541
- var _this4 = this;
4542
-
4543
- var _parseFilterArgs4 = parseFilterArgs(arg1, arg2, arg3),
4544
- filters = _parseFilterArgs4[0],
4545
- _parseFilterArgs4$ = _parseFilterArgs4[1],
4546
- cancelOptions = _parseFilterArgs4$ === void 0 ? {} : _parseFilterArgs4$;
4547
-
4548
- if (typeof cancelOptions.revert === 'undefined') {
4549
- cancelOptions.revert = true;
4550
- }
4551
-
4552
- var promises = notifyManager.batch(function () {
4553
- return _this4.queryCache.findAll(filters).map(function (query) {
4554
- return query.cancel(cancelOptions);
4555
- });
4556
- });
4557
- return Promise.all(promises).then(noop$1).catch(noop$1);
4558
- };
4559
-
4560
- _proto.invalidateQueries = function invalidateQueries(arg1, arg2, arg3) {
4561
- var _ref3,
4562
- _filters$refetchActiv,
4563
- _filters$refetchInact,
4564
- _this5 = this;
4565
-
4566
- var _parseFilterArgs5 = parseFilterArgs(arg1, arg2, arg3),
4567
- filters = _parseFilterArgs5[0],
4568
- options = _parseFilterArgs5[1];
4569
-
4570
- var refetchFilters = _extends({}, filters, {
4571
- // if filters.refetchActive is not provided and filters.active is explicitly false,
4572
- // e.g. invalidateQueries({ active: false }), we don't want to refetch active queries
4573
- active: (_ref3 = (_filters$refetchActiv = filters.refetchActive) != null ? _filters$refetchActiv : filters.active) != null ? _ref3 : true,
4574
- inactive: (_filters$refetchInact = filters.refetchInactive) != null ? _filters$refetchInact : false
4575
- });
4576
-
4577
- return notifyManager.batch(function () {
4578
- _this5.queryCache.findAll(filters).forEach(function (query) {
4579
- query.invalidate();
4580
- });
4581
-
4582
- return _this5.refetchQueries(refetchFilters, options);
4583
- });
4584
- };
4585
-
4586
- _proto.refetchQueries = function refetchQueries(arg1, arg2, arg3) {
4587
- var _this6 = this;
4588
-
4589
- var _parseFilterArgs6 = parseFilterArgs(arg1, arg2, arg3),
4590
- filters = _parseFilterArgs6[0],
4591
- options = _parseFilterArgs6[1];
4592
-
4593
- var promises = notifyManager.batch(function () {
4594
- return _this6.queryCache.findAll(filters).map(function (query) {
4595
- return query.fetch(undefined, _extends({}, options, {
4596
- meta: {
4597
- refetchPage: filters == null ? void 0 : filters.refetchPage
4598
- }
4599
- }));
4600
- });
4601
- });
4602
- var promise = Promise.all(promises).then(noop$1);
4603
-
4604
- if (!(options == null ? void 0 : options.throwOnError)) {
4605
- promise = promise.catch(noop$1);
4606
- }
4607
-
4608
- return promise;
4609
- };
4610
-
4611
- _proto.fetchQuery = function fetchQuery(arg1, arg2, arg3) {
4612
- var parsedOptions = parseQueryArgs(arg1, arg2, arg3);
4613
- var defaultedOptions = this.defaultQueryOptions(parsedOptions); // https://github.com/tannerlinsley/react-query/issues/652
4614
-
4615
- if (typeof defaultedOptions.retry === 'undefined') {
4616
- defaultedOptions.retry = false;
4617
- }
4618
-
4619
- var query = this.queryCache.build(this, defaultedOptions);
4620
- return query.isStaleByTime(defaultedOptions.staleTime) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
4621
- };
4622
-
4623
- _proto.prefetchQuery = function prefetchQuery(arg1, arg2, arg3) {
4624
- return this.fetchQuery(arg1, arg2, arg3).then(noop$1).catch(noop$1);
4625
- };
4626
-
4627
- _proto.fetchInfiniteQuery = function fetchInfiniteQuery(arg1, arg2, arg3) {
4628
- var parsedOptions = parseQueryArgs(arg1, arg2, arg3);
4629
- parsedOptions.behavior = infiniteQueryBehavior();
4630
- return this.fetchQuery(parsedOptions);
4631
- };
4632
-
4633
- _proto.prefetchInfiniteQuery = function prefetchInfiniteQuery(arg1, arg2, arg3) {
4634
- return this.fetchInfiniteQuery(arg1, arg2, arg3).then(noop$1).catch(noop$1);
4635
- };
4636
-
4637
- _proto.cancelMutations = function cancelMutations() {
4638
- var _this7 = this;
4639
-
4640
- var promises = notifyManager.batch(function () {
4641
- return _this7.mutationCache.getAll().map(function (mutation) {
4642
- return mutation.cancel();
4643
- });
4644
- });
4645
- return Promise.all(promises).then(noop$1).catch(noop$1);
4646
- };
4647
-
4648
- _proto.resumePausedMutations = function resumePausedMutations() {
4649
- return this.getMutationCache().resumePausedMutations();
4650
- };
4651
-
4652
- _proto.executeMutation = function executeMutation(options) {
4653
- return this.mutationCache.build(this, options).execute();
4654
- };
4655
-
4656
- _proto.getQueryCache = function getQueryCache() {
4657
- return this.queryCache;
4658
- };
4659
-
4660
- _proto.getMutationCache = function getMutationCache() {
4661
- return this.mutationCache;
4662
- };
4663
-
4664
- _proto.getDefaultOptions = function getDefaultOptions() {
4665
- return this.defaultOptions;
4666
- };
4667
-
4668
- _proto.setDefaultOptions = function setDefaultOptions(options) {
4669
- this.defaultOptions = options;
4670
- };
4671
-
4672
- _proto.setQueryDefaults = function setQueryDefaults(queryKey, options) {
4673
- var result = this.queryDefaults.find(function (x) {
4674
- return hashQueryKey(queryKey) === hashQueryKey(x.queryKey);
4675
- });
4676
-
4677
- if (result) {
4678
- result.defaultOptions = options;
4679
- } else {
4680
- this.queryDefaults.push({
4681
- queryKey: queryKey,
4682
- defaultOptions: options
4683
- });
4684
- }
4685
- };
4686
-
4687
- _proto.getQueryDefaults = function getQueryDefaults(queryKey) {
4688
- var _this$queryDefaults$f;
4689
-
4690
- return queryKey ? (_this$queryDefaults$f = this.queryDefaults.find(function (x) {
4691
- return partialMatchKey(queryKey, x.queryKey);
4692
- })) == null ? void 0 : _this$queryDefaults$f.defaultOptions : undefined;
4693
- };
4694
-
4695
- _proto.setMutationDefaults = function setMutationDefaults(mutationKey, options) {
4696
- var result = this.mutationDefaults.find(function (x) {
4697
- return hashQueryKey(mutationKey) === hashQueryKey(x.mutationKey);
4698
- });
4699
-
4700
- if (result) {
4701
- result.defaultOptions = options;
4702
- } else {
4703
- this.mutationDefaults.push({
4704
- mutationKey: mutationKey,
4705
- defaultOptions: options
4706
- });
4707
- }
4708
- };
4709
-
4710
- _proto.getMutationDefaults = function getMutationDefaults(mutationKey) {
4711
- var _this$mutationDefault;
4712
-
4713
- return mutationKey ? (_this$mutationDefault = this.mutationDefaults.find(function (x) {
4714
- return partialMatchKey(mutationKey, x.mutationKey);
4715
- })) == null ? void 0 : _this$mutationDefault.defaultOptions : undefined;
4716
- };
4717
-
4718
- _proto.defaultQueryOptions = function defaultQueryOptions(options) {
4719
- if (options == null ? void 0 : options._defaulted) {
4720
- return options;
4721
- }
4722
-
4723
- var defaultedOptions = _extends({}, this.defaultOptions.queries, this.getQueryDefaults(options == null ? void 0 : options.queryKey), options, {
4724
- _defaulted: true
4725
- });
4726
-
4727
- if (!defaultedOptions.queryHash && defaultedOptions.queryKey) {
4728
- defaultedOptions.queryHash = hashQueryKeyByOptions(defaultedOptions.queryKey, defaultedOptions);
4729
- }
4730
-
4731
- return defaultedOptions;
4732
- };
4733
-
4734
- _proto.defaultQueryObserverOptions = function defaultQueryObserverOptions(options) {
4735
- return this.defaultQueryOptions(options);
4736
- };
4737
-
4738
- _proto.defaultMutationOptions = function defaultMutationOptions(options) {
4739
- if (options == null ? void 0 : options._defaulted) {
4740
- return options;
4741
- }
4742
-
4743
- return _extends({}, this.defaultOptions.mutations, this.getMutationDefaults(options == null ? void 0 : options.mutationKey), options, {
4744
- _defaulted: true
4745
- });
4746
- };
4747
-
4748
- _proto.clear = function clear() {
4749
- this.queryCache.clear();
4750
- this.mutationCache.clear();
4751
- };
4752
-
4753
- return QueryClient;
4754
- }();
4755
-
4756
- var QueryObserver = /*#__PURE__*/function (_Subscribable) {
4757
- _inheritsLoose(QueryObserver, _Subscribable);
4758
-
4759
- function QueryObserver(client, options) {
4760
- var _this;
4761
-
4762
- _this = _Subscribable.call(this) || this;
4763
- _this.client = client;
4764
- _this.options = options;
4765
- _this.trackedProps = [];
4766
- _this.selectError = null;
4767
-
4768
- _this.bindMethods();
4769
-
4770
- _this.setOptions(options);
4771
-
4772
- return _this;
4773
- }
4774
-
4775
- var _proto = QueryObserver.prototype;
4776
-
4777
- _proto.bindMethods = function bindMethods() {
4778
- this.remove = this.remove.bind(this);
4779
- this.refetch = this.refetch.bind(this);
4780
- };
4781
-
4782
- _proto.onSubscribe = function onSubscribe() {
4783
- if (this.listeners.length === 1) {
4784
- this.currentQuery.addObserver(this);
4785
-
4786
- if (shouldFetchOnMount(this.currentQuery, this.options)) {
4787
- this.executeFetch();
4788
- }
4789
-
4790
- this.updateTimers();
4791
- }
4792
- };
4793
-
4794
- _proto.onUnsubscribe = function onUnsubscribe() {
4795
- if (!this.listeners.length) {
4796
- this.destroy();
4797
- }
4798
- };
4799
-
4800
- _proto.shouldFetchOnReconnect = function shouldFetchOnReconnect() {
4801
- return shouldFetchOn(this.currentQuery, this.options, this.options.refetchOnReconnect);
4802
- };
4803
-
4804
- _proto.shouldFetchOnWindowFocus = function shouldFetchOnWindowFocus() {
4805
- return shouldFetchOn(this.currentQuery, this.options, this.options.refetchOnWindowFocus);
4806
- };
4807
-
4808
- _proto.destroy = function destroy() {
4809
- this.listeners = [];
4810
- this.clearTimers();
4811
- this.currentQuery.removeObserver(this);
4812
- };
4813
-
4814
- _proto.setOptions = function setOptions(options, notifyOptions) {
4815
- var prevOptions = this.options;
4816
- var prevQuery = this.currentQuery;
4817
- this.options = this.client.defaultQueryObserverOptions(options);
4818
-
4819
- if (typeof this.options.enabled !== 'undefined' && typeof this.options.enabled !== 'boolean') {
4820
- throw new Error('Expected enabled to be a boolean');
4821
- } // Keep previous query key if the user does not supply one
4822
-
4823
-
4824
- if (!this.options.queryKey) {
4825
- this.options.queryKey = prevOptions.queryKey;
4826
- }
4827
-
4828
- this.updateQuery();
4829
- var mounted = this.hasListeners(); // Fetch if there are subscribers
4830
-
4831
- if (mounted && shouldFetchOptionally(this.currentQuery, prevQuery, this.options, prevOptions)) {
4832
- this.executeFetch();
4833
- } // Update result
4834
-
4835
-
4836
- this.updateResult(notifyOptions); // Update stale interval if needed
4837
-
4838
- if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
4839
- this.updateStaleTimeout();
4840
- }
4841
-
4842
- var nextRefetchInterval = this.computeRefetchInterval(); // Update refetch interval if needed
4843
-
4844
- if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.currentRefetchInterval)) {
4845
- this.updateRefetchInterval(nextRefetchInterval);
4846
- }
4847
- };
4848
-
4849
- _proto.getOptimisticResult = function getOptimisticResult(options) {
4850
- var defaultedOptions = this.client.defaultQueryObserverOptions(options);
4851
- var query = this.client.getQueryCache().build(this.client, defaultedOptions);
4852
- return this.createResult(query, defaultedOptions);
4853
- };
4854
-
4855
- _proto.getCurrentResult = function getCurrentResult() {
4856
- return this.currentResult;
4857
- };
4858
-
4859
- _proto.trackResult = function trackResult(result, defaultedOptions) {
4860
- var _this2 = this;
4861
-
4862
- var trackedResult = {};
4863
-
4864
- var trackProp = function trackProp(key) {
4865
- if (!_this2.trackedProps.includes(key)) {
4866
- _this2.trackedProps.push(key);
4867
- }
4868
- };
4869
-
4870
- Object.keys(result).forEach(function (key) {
4871
- Object.defineProperty(trackedResult, key, {
4872
- configurable: false,
4873
- enumerable: true,
4874
- get: function get() {
4875
- trackProp(key);
4876
- return result[key];
4877
- }
4878
- });
4879
- });
4880
-
4881
- if (defaultedOptions.useErrorBoundary || defaultedOptions.suspense) {
4882
- trackProp('error');
4883
- }
4884
-
4885
- return trackedResult;
4886
- };
4887
-
4888
- _proto.getNextResult = function getNextResult(options) {
4889
- var _this3 = this;
4890
-
4891
- return new Promise(function (resolve, reject) {
4892
- var unsubscribe = _this3.subscribe(function (result) {
4893
- if (!result.isFetching) {
4894
- unsubscribe();
4895
-
4896
- if (result.isError && (options == null ? void 0 : options.throwOnError)) {
4897
- reject(result.error);
4898
- } else {
4899
- resolve(result);
4900
- }
4901
- }
4902
- });
4903
- });
4904
- };
4905
-
4906
- _proto.getCurrentQuery = function getCurrentQuery() {
4907
- return this.currentQuery;
4908
- };
4909
-
4910
- _proto.remove = function remove() {
4911
- this.client.getQueryCache().remove(this.currentQuery);
4912
- };
4913
-
4914
- _proto.refetch = function refetch(options) {
4915
- return this.fetch(_extends({}, options, {
4916
- meta: {
4917
- refetchPage: options == null ? void 0 : options.refetchPage
4918
- }
4919
- }));
4920
- };
4921
-
4922
- _proto.fetchOptimistic = function fetchOptimistic(options) {
4923
- var _this4 = this;
4924
-
4925
- var defaultedOptions = this.client.defaultQueryObserverOptions(options);
4926
- var query = this.client.getQueryCache().build(this.client, defaultedOptions);
4927
- return query.fetch().then(function () {
4928
- return _this4.createResult(query, defaultedOptions);
4929
- });
4930
- };
4931
-
4932
- _proto.fetch = function fetch(fetchOptions) {
4933
- var _this5 = this;
4934
-
4935
- return this.executeFetch(fetchOptions).then(function () {
4936
- _this5.updateResult();
4937
-
4938
- return _this5.currentResult;
4939
- });
4940
- };
4941
-
4942
- _proto.executeFetch = function executeFetch(fetchOptions) {
4943
- // Make sure we reference the latest query as the current one might have been removed
4944
- this.updateQuery(); // Fetch
4945
-
4946
- var promise = this.currentQuery.fetch(this.options, fetchOptions);
4947
-
4948
- if (!(fetchOptions == null ? void 0 : fetchOptions.throwOnError)) {
4949
- promise = promise.catch(noop$1);
4950
- }
4951
-
4952
- return promise;
4953
- };
4954
-
4955
- _proto.updateStaleTimeout = function updateStaleTimeout() {
4956
- var _this6 = this;
4957
-
4958
- this.clearStaleTimeout();
4959
-
4960
- if (isServer || this.currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
4961
- return;
4962
- }
4963
-
4964
- var time = timeUntilStale(this.currentResult.dataUpdatedAt, this.options.staleTime); // The timeout is sometimes triggered 1 ms before the stale time expiration.
4965
- // To mitigate this issue we always add 1 ms to the timeout.
4966
-
4967
- var timeout = time + 1;
4968
- this.staleTimeoutId = setTimeout(function () {
4969
- if (!_this6.currentResult.isStale) {
4970
- _this6.updateResult();
4971
- }
4972
- }, timeout);
4973
- };
4974
-
4975
- _proto.computeRefetchInterval = function computeRefetchInterval() {
4976
- var _this$options$refetch;
4977
-
4978
- return typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.currentResult.data, this.currentQuery) : (_this$options$refetch = this.options.refetchInterval) != null ? _this$options$refetch : false;
4979
- };
4980
-
4981
- _proto.updateRefetchInterval = function updateRefetchInterval(nextInterval) {
4982
- var _this7 = this;
4983
-
4984
- this.clearRefetchInterval();
4985
- this.currentRefetchInterval = nextInterval;
4986
-
4987
- if (isServer || this.options.enabled === false || !isValidTimeout(this.currentRefetchInterval) || this.currentRefetchInterval === 0) {
4988
- return;
4989
- }
4990
-
4991
- this.refetchIntervalId = setInterval(function () {
4992
- if (_this7.options.refetchIntervalInBackground || focusManager.isFocused()) {
4993
- _this7.executeFetch();
4994
- }
4995
- }, this.currentRefetchInterval);
4996
- };
4997
-
4998
- _proto.updateTimers = function updateTimers() {
4999
- this.updateStaleTimeout();
5000
- this.updateRefetchInterval(this.computeRefetchInterval());
5001
- };
5002
-
5003
- _proto.clearTimers = function clearTimers() {
5004
- this.clearStaleTimeout();
5005
- this.clearRefetchInterval();
5006
- };
5007
-
5008
- _proto.clearStaleTimeout = function clearStaleTimeout() {
5009
- if (this.staleTimeoutId) {
5010
- clearTimeout(this.staleTimeoutId);
5011
- this.staleTimeoutId = undefined;
5012
- }
5013
- };
5014
-
5015
- _proto.clearRefetchInterval = function clearRefetchInterval() {
5016
- if (this.refetchIntervalId) {
5017
- clearInterval(this.refetchIntervalId);
5018
- this.refetchIntervalId = undefined;
5019
- }
5020
- };
5021
-
5022
- _proto.createResult = function createResult(query, options) {
5023
- var prevQuery = this.currentQuery;
5024
- var prevOptions = this.options;
5025
- var prevResult = this.currentResult;
5026
- var prevResultState = this.currentResultState;
5027
- var prevResultOptions = this.currentResultOptions;
5028
- var queryChange = query !== prevQuery;
5029
- var queryInitialState = queryChange ? query.state : this.currentQueryInitialState;
5030
- var prevQueryResult = queryChange ? this.currentResult : this.previousQueryResult;
5031
- var state = query.state;
5032
- var dataUpdatedAt = state.dataUpdatedAt,
5033
- error = state.error,
5034
- errorUpdatedAt = state.errorUpdatedAt,
5035
- isFetching = state.isFetching,
5036
- status = state.status;
5037
- var isPreviousData = false;
5038
- var isPlaceholderData = false;
5039
- var data; // Optimistically set result in fetching state if needed
5040
-
5041
- if (options.optimisticResults) {
5042
- var mounted = this.hasListeners();
5043
- var fetchOnMount = !mounted && shouldFetchOnMount(query, options);
5044
- var fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
5045
-
5046
- if (fetchOnMount || fetchOptionally) {
5047
- isFetching = true;
5048
-
5049
- if (!dataUpdatedAt) {
5050
- status = 'loading';
5051
- }
5052
- }
5053
- } // Keep previous data if needed
5054
-
5055
-
5056
- if (options.keepPreviousData && !state.dataUpdateCount && (prevQueryResult == null ? void 0 : prevQueryResult.isSuccess) && status !== 'error') {
5057
- data = prevQueryResult.data;
5058
- dataUpdatedAt = prevQueryResult.dataUpdatedAt;
5059
- status = prevQueryResult.status;
5060
- isPreviousData = true;
5061
- } // Select data if needed
5062
- else if (options.select && typeof state.data !== 'undefined') {
5063
- // Memoize select result
5064
- if (prevResult && state.data === (prevResultState == null ? void 0 : prevResultState.data) && options.select === this.selectFn) {
5065
- data = this.selectResult;
5066
- } else {
5067
- try {
5068
- this.selectFn = options.select;
5069
- data = options.select(state.data);
5070
-
5071
- if (options.structuralSharing !== false) {
5072
- data = replaceEqualDeep(prevResult == null ? void 0 : prevResult.data, data);
5073
- }
5074
-
5075
- this.selectResult = data;
5076
- this.selectError = null;
5077
- } catch (selectError) {
5078
- getLogger().error(selectError);
5079
- this.selectError = selectError;
5080
- }
5081
- }
5082
- } // Use query data
5083
- else {
5084
- data = state.data;
5085
- } // Show placeholder data if needed
5086
-
5087
-
5088
- if (typeof options.placeholderData !== 'undefined' && typeof data === 'undefined' && (status === 'loading' || status === 'idle')) {
5089
- var placeholderData; // Memoize placeholder data
5090
-
5091
- if ((prevResult == null ? void 0 : prevResult.isPlaceholderData) && options.placeholderData === (prevResultOptions == null ? void 0 : prevResultOptions.placeholderData)) {
5092
- placeholderData = prevResult.data;
5093
- } else {
5094
- placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData() : options.placeholderData;
5095
-
5096
- if (options.select && typeof placeholderData !== 'undefined') {
5097
- try {
5098
- placeholderData = options.select(placeholderData);
5099
-
5100
- if (options.structuralSharing !== false) {
5101
- placeholderData = replaceEqualDeep(prevResult == null ? void 0 : prevResult.data, placeholderData);
5102
- }
5103
-
5104
- this.selectError = null;
5105
- } catch (selectError) {
5106
- getLogger().error(selectError);
5107
- this.selectError = selectError;
5108
- }
5109
- }
5110
- }
5111
-
5112
- if (typeof placeholderData !== 'undefined') {
5113
- status = 'success';
5114
- data = placeholderData;
5115
- isPlaceholderData = true;
5116
- }
5117
- }
5118
-
5119
- if (this.selectError) {
5120
- error = this.selectError;
5121
- data = this.selectResult;
5122
- errorUpdatedAt = Date.now();
5123
- status = 'error';
5124
- }
5125
-
5126
- var result = {
5127
- status: status,
5128
- isLoading: status === 'loading',
5129
- isSuccess: status === 'success',
5130
- isError: status === 'error',
5131
- isIdle: status === 'idle',
5132
- data: data,
5133
- dataUpdatedAt: dataUpdatedAt,
5134
- error: error,
5135
- errorUpdatedAt: errorUpdatedAt,
5136
- failureCount: state.fetchFailureCount,
5137
- errorUpdateCount: state.errorUpdateCount,
5138
- isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
5139
- isFetchedAfterMount: state.dataUpdateCount > queryInitialState.dataUpdateCount || state.errorUpdateCount > queryInitialState.errorUpdateCount,
5140
- isFetching: isFetching,
5141
- isRefetching: isFetching && status !== 'loading',
5142
- isLoadingError: status === 'error' && state.dataUpdatedAt === 0,
5143
- isPlaceholderData: isPlaceholderData,
5144
- isPreviousData: isPreviousData,
5145
- isRefetchError: status === 'error' && state.dataUpdatedAt !== 0,
5146
- isStale: isStale(query, options),
5147
- refetch: this.refetch,
5148
- remove: this.remove
5149
- };
5150
- return result;
5151
- };
5152
-
5153
- _proto.shouldNotifyListeners = function shouldNotifyListeners(result, prevResult) {
5154
- if (!prevResult) {
5155
- return true;
5156
- }
5157
-
5158
- var _this$options = this.options,
5159
- notifyOnChangeProps = _this$options.notifyOnChangeProps,
5160
- notifyOnChangePropsExclusions = _this$options.notifyOnChangePropsExclusions;
5161
-
5162
- if (!notifyOnChangeProps && !notifyOnChangePropsExclusions) {
5163
- return true;
5164
- }
5165
-
5166
- if (notifyOnChangeProps === 'tracked' && !this.trackedProps.length) {
5167
- return true;
5168
- }
5169
-
5170
- var includedProps = notifyOnChangeProps === 'tracked' ? this.trackedProps : notifyOnChangeProps;
5171
- return Object.keys(result).some(function (key) {
5172
- var typedKey = key;
5173
- var changed = result[typedKey] !== prevResult[typedKey];
5174
- var isIncluded = includedProps == null ? void 0 : includedProps.some(function (x) {
5175
- return x === key;
5176
- });
5177
- var isExcluded = notifyOnChangePropsExclusions == null ? void 0 : notifyOnChangePropsExclusions.some(function (x) {
5178
- return x === key;
5179
- });
5180
- return changed && !isExcluded && (!includedProps || isIncluded);
5181
- });
5182
- };
5183
-
5184
- _proto.updateResult = function updateResult(notifyOptions) {
5185
- var prevResult = this.currentResult;
5186
- this.currentResult = this.createResult(this.currentQuery, this.options);
5187
- this.currentResultState = this.currentQuery.state;
5188
- this.currentResultOptions = this.options; // Only notify if something has changed
5189
-
5190
- if (shallowEqualObjects(this.currentResult, prevResult)) {
5191
- return;
5192
- } // Determine which callbacks to trigger
5193
-
5194
-
5195
- var defaultNotifyOptions = {
5196
- cache: true
5197
- };
5198
-
5199
- if ((notifyOptions == null ? void 0 : notifyOptions.listeners) !== false && this.shouldNotifyListeners(this.currentResult, prevResult)) {
5200
- defaultNotifyOptions.listeners = true;
5201
- }
5202
-
5203
- this.notify(_extends({}, defaultNotifyOptions, notifyOptions));
5204
- };
5205
-
5206
- _proto.updateQuery = function updateQuery() {
5207
- var query = this.client.getQueryCache().build(this.client, this.options);
5208
-
5209
- if (query === this.currentQuery) {
5210
- return;
5211
- }
5212
-
5213
- var prevQuery = this.currentQuery;
5214
- this.currentQuery = query;
5215
- this.currentQueryInitialState = query.state;
5216
- this.previousQueryResult = this.currentResult;
5217
-
5218
- if (this.hasListeners()) {
5219
- prevQuery == null ? void 0 : prevQuery.removeObserver(this);
5220
- query.addObserver(this);
5221
- }
5222
- };
5223
-
5224
- _proto.onQueryUpdate = function onQueryUpdate(action) {
5225
- var notifyOptions = {};
5226
-
5227
- if (action.type === 'success') {
5228
- notifyOptions.onSuccess = true;
5229
- } else if (action.type === 'error' && !isCancelledError(action.error)) {
5230
- notifyOptions.onError = true;
5231
- }
5232
-
5233
- this.updateResult(notifyOptions);
5234
-
5235
- if (this.hasListeners()) {
5236
- this.updateTimers();
5237
- }
5238
- };
5239
-
5240
- _proto.notify = function notify(notifyOptions) {
5241
- var _this8 = this;
5242
-
5243
- notifyManager.batch(function () {
5244
- // First trigger the configuration callbacks
5245
- if (notifyOptions.onSuccess) {
5246
- _this8.options.onSuccess == null ? void 0 : _this8.options.onSuccess(_this8.currentResult.data);
5247
- _this8.options.onSettled == null ? void 0 : _this8.options.onSettled(_this8.currentResult.data, null);
5248
- } else if (notifyOptions.onError) {
5249
- _this8.options.onError == null ? void 0 : _this8.options.onError(_this8.currentResult.error);
5250
- _this8.options.onSettled == null ? void 0 : _this8.options.onSettled(undefined, _this8.currentResult.error);
5251
- } // Then trigger the listeners
5252
-
5253
-
5254
- if (notifyOptions.listeners) {
5255
- _this8.listeners.forEach(function (listener) {
5256
- listener(_this8.currentResult);
5257
- });
5258
- } // Then the cache listeners
5259
-
5260
-
5261
- if (notifyOptions.cache) {
5262
- _this8.client.getQueryCache().notify({
5263
- query: _this8.currentQuery,
5264
- type: 'observerResultsUpdated'
5265
- });
5266
- }
5267
- });
5268
- };
5269
-
5270
- return QueryObserver;
5271
- }(Subscribable);
5272
-
5273
- function shouldLoadOnMount(query, options) {
5274
- return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status === 'error' && options.retryOnMount === false);
5275
- }
5276
-
5277
- function shouldFetchOnMount(query, options) {
5278
- return shouldLoadOnMount(query, options) || query.state.dataUpdatedAt > 0 && shouldFetchOn(query, options, options.refetchOnMount);
5279
- }
5280
-
5281
- function shouldFetchOn(query, options, field) {
5282
- if (options.enabled !== false) {
5283
- var value = typeof field === 'function' ? field(query) : field;
5284
- return value === 'always' || value !== false && isStale(query, options);
5285
- }
5286
-
5287
- return false;
5288
- }
5289
-
5290
- function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
5291
- return options.enabled !== false && (query !== prevQuery || prevOptions.enabled === false) && (!options.suspense || query.state.status !== 'error') && isStale(query, options);
5292
- }
5293
-
5294
- function isStale(query, options) {
5295
- return query.isStaleByTime(options.staleTime);
5296
- }
5297
-
5298
- // CLASS
5299
- var MutationObserver = /*#__PURE__*/function (_Subscribable) {
5300
- _inheritsLoose(MutationObserver, _Subscribable);
5301
-
5302
- function MutationObserver(client, options) {
5303
- var _this;
5304
-
5305
- _this = _Subscribable.call(this) || this;
5306
- _this.client = client;
5307
-
5308
- _this.setOptions(options);
5309
-
5310
- _this.bindMethods();
5311
-
5312
- _this.updateResult();
5313
-
5314
- return _this;
5315
- }
5316
-
5317
- var _proto = MutationObserver.prototype;
5318
-
5319
- _proto.bindMethods = function bindMethods() {
5320
- this.mutate = this.mutate.bind(this);
5321
- this.reset = this.reset.bind(this);
5322
- };
5323
-
5324
- _proto.setOptions = function setOptions(options) {
5325
- this.options = this.client.defaultMutationOptions(options);
5326
- };
2199
+ var labelPattern = /label:\s*([^\s;\n{]+)\s*(;|$)/g;
2200
+ var sourceMapPattern;
5327
2201
 
5328
- _proto.onUnsubscribe = function onUnsubscribe() {
5329
- if (!this.listeners.length) {
5330
- var _this$currentMutation;
2202
+ if (process.env.NODE_ENV !== 'production') {
2203
+ sourceMapPattern = /\/\*#\ssourceMappingURL=data:application\/json;\S+\s+\*\//g;
2204
+ } // this is the cursor for keyframes
2205
+ // keyframes are stored on the SerializedStyles object as a linked list
5331
2206
 
5332
- (_this$currentMutation = this.currentMutation) == null ? void 0 : _this$currentMutation.removeObserver(this);
5333
- }
5334
- };
5335
2207
 
5336
- _proto.onMutationUpdate = function onMutationUpdate(action) {
5337
- this.updateResult(); // Determine which callbacks to trigger
2208
+ var cursor;
2209
+ var serializeStyles = function serializeStyles(args, registered, mergedProps) {
2210
+ if (args.length === 1 && typeof args[0] === 'object' && args[0] !== null && args[0].styles !== undefined) {
2211
+ return args[0];
2212
+ }
5338
2213
 
5339
- var notifyOptions = {
5340
- listeners: true
5341
- };
2214
+ var stringMode = true;
2215
+ var styles = '';
2216
+ cursor = undefined;
2217
+ var strings = args[0];
5342
2218
 
5343
- if (action.type === 'success') {
5344
- notifyOptions.onSuccess = true;
5345
- } else if (action.type === 'error') {
5346
- notifyOptions.onError = true;
2219
+ if (strings == null || strings.raw === undefined) {
2220
+ stringMode = false;
2221
+ styles += handleInterpolation(mergedProps, registered, strings);
2222
+ } else {
2223
+ if (process.env.NODE_ENV !== 'production' && strings[0] === undefined) {
2224
+ console.error(ILLEGAL_ESCAPE_SEQUENCE_ERROR);
5347
2225
  }
5348
2226
 
5349
- this.notify(notifyOptions);
5350
- };
2227
+ styles += strings[0];
2228
+ } // we start at 1 since we've already handled the first arg
5351
2229
 
5352
- _proto.getCurrentResult = function getCurrentResult() {
5353
- return this.currentResult;
5354
- };
5355
2230
 
5356
- _proto.reset = function reset() {
5357
- this.currentMutation = undefined;
5358
- this.updateResult();
5359
- this.notify({
5360
- listeners: true
5361
- });
5362
- };
2231
+ for (var i = 1; i < args.length; i++) {
2232
+ styles += handleInterpolation(mergedProps, registered, args[i]);
5363
2233
 
5364
- _proto.mutate = function mutate(variables, options) {
5365
- this.mutateOptions = options;
2234
+ if (stringMode) {
2235
+ if (process.env.NODE_ENV !== 'production' && strings[i] === undefined) {
2236
+ console.error(ILLEGAL_ESCAPE_SEQUENCE_ERROR);
2237
+ }
5366
2238
 
5367
- if (this.currentMutation) {
5368
- this.currentMutation.removeObserver(this);
2239
+ styles += strings[i];
5369
2240
  }
2241
+ }
5370
2242
 
5371
- this.currentMutation = this.client.getMutationCache().build(this.client, _extends({}, this.options, {
5372
- variables: typeof variables !== 'undefined' ? variables : this.options.variables
5373
- }));
5374
- this.currentMutation.addObserver(this);
5375
- return this.currentMutation.execute();
5376
- };
5377
-
5378
- _proto.updateResult = function updateResult() {
5379
- var state = this.currentMutation ? this.currentMutation.state : getDefaultState();
2243
+ var sourceMap;
5380
2244
 
5381
- var result = _extends({}, state, {
5382
- isLoading: state.status === 'loading',
5383
- isSuccess: state.status === 'success',
5384
- isError: state.status === 'error',
5385
- isIdle: state.status === 'idle',
5386
- mutate: this.mutate,
5387
- reset: this.reset
2245
+ if (process.env.NODE_ENV !== 'production') {
2246
+ styles = styles.replace(sourceMapPattern, function (match) {
2247
+ sourceMap = match;
2248
+ return '';
5388
2249
  });
2250
+ } // using a global regex with .exec is stateful so lastIndex has to be reset each time
5389
2251
 
5390
- this.currentResult = result;
5391
- };
5392
2252
 
5393
- _proto.notify = function notify(options) {
5394
- var _this2 = this;
5395
-
5396
- notifyManager.batch(function () {
5397
- // First trigger the mutate callbacks
5398
- if (_this2.mutateOptions) {
5399
- if (options.onSuccess) {
5400
- _this2.mutateOptions.onSuccess == null ? void 0 : _this2.mutateOptions.onSuccess(_this2.currentResult.data, _this2.currentResult.variables, _this2.currentResult.context);
5401
- _this2.mutateOptions.onSettled == null ? void 0 : _this2.mutateOptions.onSettled(_this2.currentResult.data, null, _this2.currentResult.variables, _this2.currentResult.context);
5402
- } else if (options.onError) {
5403
- _this2.mutateOptions.onError == null ? void 0 : _this2.mutateOptions.onError(_this2.currentResult.error, _this2.currentResult.variables, _this2.currentResult.context);
5404
- _this2.mutateOptions.onSettled == null ? void 0 : _this2.mutateOptions.onSettled(undefined, _this2.currentResult.error, _this2.currentResult.variables, _this2.currentResult.context);
5405
- }
5406
- } // Then trigger the listeners
2253
+ labelPattern.lastIndex = 0;
2254
+ var identifierName = '';
2255
+ var match; // https://esbench.com/bench/5b809c2cf2949800a0f61fb5
2256
+
2257
+ while ((match = labelPattern.exec(styles)) !== null) {
2258
+ identifierName += '-' + // $FlowFixMe we know it's not null
2259
+ match[1];
2260
+ }
5407
2261
 
2262
+ var name = murmur2(styles) + identifierName;
5408
2263
 
5409
- if (options.listeners) {
5410
- _this2.listeners.forEach(function (listener) {
5411
- listener(_this2.currentResult);
5412
- });
2264
+ if (process.env.NODE_ENV !== 'production') {
2265
+ // $FlowFixMe SerializedStyles type doesn't have toString property (and we don't want to add it)
2266
+ return {
2267
+ name: name,
2268
+ styles: styles,
2269
+ map: sourceMap,
2270
+ next: cursor,
2271
+ toString: function toString() {
2272
+ return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop).";
5413
2273
  }
5414
- });
2274
+ };
2275
+ }
2276
+
2277
+ return {
2278
+ name: name,
2279
+ styles: styles,
2280
+ next: cursor
5415
2281
  };
2282
+ };
5416
2283
 
5417
- return MutationObserver;
5418
- }(Subscribable);
2284
+ var syncFallback = function syncFallback(create) {
2285
+ return create();
2286
+ };
5419
2287
 
5420
- var unstable_batchedUpdates = ReactDOM.unstable_batchedUpdates;
2288
+ var useInsertionEffect = React__namespace['useInsertion' + 'Effect'] ? React__namespace['useInsertion' + 'Effect'] : false;
2289
+ var useInsertionEffectAlwaysWithSyncFallback = useInsertionEffect || syncFallback;
5421
2290
 
5422
- notifyManager.setBatchNotifyFunction(unstable_batchedUpdates);
2291
+ var hasOwnProperty = {}.hasOwnProperty;
5423
2292
 
5424
- var logger$2 = console;
2293
+ var EmotionCacheContext = /* #__PURE__ */React.createContext( // we're doing this to avoid preconstruct's dead code elimination in this one case
2294
+ // because this module is primarily intended for the browser and node
2295
+ // but it's also required in react native and similar environments sometimes
2296
+ // and we could have a special build just for that
2297
+ // but this is much easier and the native packages
2298
+ // might use a different theme context in the future anyway
2299
+ typeof HTMLElement !== 'undefined' ? /* #__PURE__ */createCache({
2300
+ key: 'css'
2301
+ }) : null);
5425
2302
 
5426
- setLogger(logger$2);
2303
+ if (process.env.NODE_ENV !== 'production') {
2304
+ EmotionCacheContext.displayName = 'EmotionCacheContext';
2305
+ }
5427
2306
 
5428
- var defaultContext = /*#__PURE__*/React.createContext(undefined);
5429
- var QueryClientSharingContext = /*#__PURE__*/React.createContext(false); // if contextSharing is on, we share the first and at least one
5430
- // instance of the context across the window
5431
- // to ensure that if React Query is used across
5432
- // different bundles or microfrontends they will
5433
- // all use the same **instance** of context, regardless
5434
- // of module scoping.
2307
+ EmotionCacheContext.Provider;
5435
2308
 
5436
- function getQueryClientContext(contextSharing) {
5437
- if (contextSharing && typeof window !== 'undefined') {
5438
- if (!window.ReactQueryClientContext) {
5439
- window.ReactQueryClientContext = defaultContext;
5440
- }
2309
+ var withEmotionCache = function withEmotionCache(func) {
2310
+ // $FlowFixMe
2311
+ return /*#__PURE__*/React.forwardRef(function (props, ref) {
2312
+ // the cache will never be null in the browser
2313
+ var cache = React.useContext(EmotionCacheContext);
2314
+ return func(props, cache, ref);
2315
+ });
2316
+ };
5441
2317
 
5442
- return window.ReactQueryClientContext;
5443
- }
2318
+ var ThemeContext = /* #__PURE__ */React.createContext({});
5444
2319
 
5445
- return defaultContext;
2320
+ if (process.env.NODE_ENV !== 'production') {
2321
+ ThemeContext.displayName = 'EmotionThemeContext';
5446
2322
  }
5447
2323
 
5448
- var useQueryClient = function useQueryClient() {
5449
- var queryClient = React.useContext(getQueryClientContext(React.useContext(QueryClientSharingContext)));
2324
+ var getLastPart = function getLastPart(functionName) {
2325
+ // The match may be something like 'Object.createEmotionProps' or
2326
+ // 'Loader.prototype.render'
2327
+ var parts = functionName.split('.');
2328
+ return parts[parts.length - 1];
2329
+ };
5450
2330
 
5451
- if (!queryClient) {
5452
- throw new Error('No QueryClient set, use QueryClientProvider to set one');
5453
- }
2331
+ var getFunctionNameFromStackTraceLine = function getFunctionNameFromStackTraceLine(line) {
2332
+ // V8
2333
+ var match = /^\s+at\s+([A-Za-z0-9$.]+)\s/.exec(line);
2334
+ if (match) return getLastPart(match[1]); // Safari / Firefox
5454
2335
 
5455
- return queryClient;
5456
- };
5457
- var QueryClientProvider = function QueryClientProvider(_ref) {
5458
- var client = _ref.client,
5459
- _ref$contextSharing = _ref.contextSharing,
5460
- contextSharing = _ref$contextSharing === void 0 ? false : _ref$contextSharing,
5461
- children = _ref.children;
5462
- React.useEffect(function () {
5463
- client.mount();
5464
- return function () {
5465
- client.unmount();
5466
- };
5467
- }, [client]);
5468
- var Context = getQueryClientContext(contextSharing);
5469
- return /*#__PURE__*/React.createElement(QueryClientSharingContext.Provider, {
5470
- value: contextSharing
5471
- }, /*#__PURE__*/React.createElement(Context.Provider, {
5472
- value: client
5473
- }, children));
2336
+ match = /^([A-Za-z0-9$.]+)@/.exec(line);
2337
+ if (match) return getLastPart(match[1]);
2338
+ return undefined;
5474
2339
  };
5475
2340
 
5476
- function createValue() {
5477
- var _isReset = false;
5478
- return {
5479
- clearReset: function clearReset() {
5480
- _isReset = false;
5481
- },
5482
- reset: function reset() {
5483
- _isReset = true;
5484
- },
5485
- isReset: function isReset() {
5486
- return _isReset;
5487
- }
5488
- };
5489
- }
2341
+ var internalReactFunctionNames = /* #__PURE__ */new Set(['renderWithHooks', 'processChild', 'finishClassComponent', 'renderToString']); // These identifiers come from error stacks, so they have to be valid JS
2342
+ // identifiers, thus we only need to replace what is a valid character for JS,
2343
+ // but not for CSS.
5490
2344
 
5491
- var QueryErrorResetBoundaryContext = /*#__PURE__*/React.createContext(createValue()); // HOOK
2345
+ var sanitizeIdentifier = function sanitizeIdentifier(identifier) {
2346
+ return identifier.replace(/\$/g, '-');
2347
+ };
5492
2348
 
5493
- var useQueryErrorResetBoundary = function useQueryErrorResetBoundary() {
5494
- return React.useContext(QueryErrorResetBoundaryContext);
5495
- }; // COMPONENT
2349
+ var getLabelFromStackTrace = function getLabelFromStackTrace(stackTrace) {
2350
+ if (!stackTrace) return undefined;
2351
+ var lines = stackTrace.split('\n');
5496
2352
 
5497
- function shouldThrowError(suspense, _useErrorBoundary, params) {
5498
- // Allow useErrorBoundary function to override throwing behavior on a per-error basis
5499
- if (typeof _useErrorBoundary === 'function') {
5500
- return _useErrorBoundary.apply(void 0, params);
5501
- } // Allow useErrorBoundary to override suspense's throwing behavior
2353
+ for (var i = 0; i < lines.length; i++) {
2354
+ var functionName = getFunctionNameFromStackTraceLine(lines[i]); // The first line of V8 stack traces is just "Error"
5502
2355
 
2356
+ if (!functionName) continue; // If we reach one of these, we have gone too far and should quit
5503
2357
 
5504
- if (typeof _useErrorBoundary === 'boolean') return _useErrorBoundary; // If suspense is enabled default to throwing errors
2358
+ if (internalReactFunctionNames.has(functionName)) break; // The component name is the first function in the stack that starts with an
2359
+ // uppercase letter
5505
2360
 
5506
- return !!suspense;
5507
- }
2361
+ if (/^[A-Z]/.test(functionName)) return sanitizeIdentifier(functionName);
2362
+ }
5508
2363
 
5509
- function useMutation(arg1, arg2, arg3) {
5510
- var mountedRef = React.useRef(false);
2364
+ return undefined;
2365
+ };
5511
2366
 
5512
- var _React$useState = React.useState(0),
5513
- forceUpdate = _React$useState[1];
2367
+ var typePropName = '__EMOTION_TYPE_PLEASE_DO_NOT_USE__';
2368
+ var labelPropName = '__EMOTION_LABEL_PLEASE_DO_NOT_USE__';
2369
+ var createEmotionProps = function createEmotionProps(type, props) {
2370
+ if (process.env.NODE_ENV !== 'production' && typeof props.css === 'string' && // check if there is a css declaration
2371
+ props.css.indexOf(':') !== -1) {
2372
+ throw new Error("Strings are not allowed as css prop values, please wrap it in a css template literal from '@emotion/react' like this: css`" + props.css + "`");
2373
+ }
5514
2374
 
5515
- var options = parseMutationArgs(arg1, arg2, arg3);
5516
- var queryClient = useQueryClient();
5517
- var obsRef = React.useRef();
2375
+ var newProps = {};
5518
2376
 
5519
- if (!obsRef.current) {
5520
- obsRef.current = new MutationObserver(queryClient, options);
5521
- } else {
5522
- obsRef.current.setOptions(options);
2377
+ for (var key in props) {
2378
+ if (hasOwnProperty.call(props, key)) {
2379
+ newProps[key] = props[key];
2380
+ }
5523
2381
  }
5524
2382
 
5525
- var currentResult = obsRef.current.getCurrentResult();
5526
- React.useEffect(function () {
5527
- mountedRef.current = true;
5528
- var unsubscribe = obsRef.current.subscribe(notifyManager.batchCalls(function () {
5529
- if (mountedRef.current) {
5530
- forceUpdate(function (x) {
5531
- return x + 1;
5532
- });
5533
- }
5534
- }));
5535
- return function () {
5536
- mountedRef.current = false;
5537
- unsubscribe();
5538
- };
5539
- }, []);
5540
- var mutate = React.useCallback(function (variables, mutateOptions) {
5541
- obsRef.current.mutate(variables, mutateOptions).catch(noop$1);
5542
- }, []);
2383
+ newProps[typePropName] = type; // For performance, only call getLabelFromStackTrace in development and when
2384
+ // the label hasn't already been computed
5543
2385
 
5544
- if (currentResult.error && shouldThrowError(undefined, obsRef.current.options.useErrorBoundary, [currentResult.error])) {
5545
- throw currentResult.error;
2386
+ if (process.env.NODE_ENV !== 'production' && !!props.css && (typeof props.css !== 'object' || typeof props.css.name !== 'string' || props.css.name.indexOf('-') === -1)) {
2387
+ var label = getLabelFromStackTrace(new Error().stack);
2388
+ if (label) newProps[labelPropName] = label;
5546
2389
  }
5547
2390
 
5548
- return _extends({}, currentResult, {
5549
- mutate: mutate,
5550
- mutateAsync: currentResult.mutate
5551
- });
5552
- }
5553
-
5554
- function useBaseQuery(options, Observer) {
5555
- var mountedRef = React.useRef(false);
2391
+ return newProps;
2392
+ };
5556
2393
 
5557
- var _React$useState = React.useState(0),
5558
- forceUpdate = _React$useState[1];
2394
+ var Insertion = function Insertion(_ref) {
2395
+ var cache = _ref.cache,
2396
+ serialized = _ref.serialized,
2397
+ isStringTag = _ref.isStringTag;
2398
+ registerStyles(cache, serialized, isStringTag);
2399
+ useInsertionEffectAlwaysWithSyncFallback(function () {
2400
+ return insertStyles(cache, serialized, isStringTag);
2401
+ });
5559
2402
 
5560
- var queryClient = useQueryClient();
5561
- var errorResetBoundary = useQueryErrorResetBoundary();
5562
- var defaultedOptions = queryClient.defaultQueryObserverOptions(options); // Make sure results are optimistically set in fetching state before subscribing or updating options
2403
+ return null;
2404
+ };
5563
2405
 
5564
- defaultedOptions.optimisticResults = true; // Include callbacks in batch renders
2406
+ var Emotion = /* #__PURE__ */withEmotionCache(function (props, cache, ref) {
2407
+ var cssProp = props.css; // so that using `css` from `emotion` and passing the result to the css prop works
2408
+ // not passing the registered cache to serializeStyles because it would
2409
+ // make certain babel optimisations not possible
5565
2410
 
5566
- if (defaultedOptions.onError) {
5567
- defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
2411
+ if (typeof cssProp === 'string' && cache.registered[cssProp] !== undefined) {
2412
+ cssProp = cache.registered[cssProp];
5568
2413
  }
5569
2414
 
5570
- if (defaultedOptions.onSuccess) {
5571
- defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
5572
- }
2415
+ var WrappedComponent = props[typePropName];
2416
+ var registeredStyles = [cssProp];
2417
+ var className = '';
5573
2418
 
5574
- if (defaultedOptions.onSettled) {
5575
- defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
2419
+ if (typeof props.className === 'string') {
2420
+ className = getRegisteredStyles(cache.registered, registeredStyles, props.className);
2421
+ } else if (props.className != null) {
2422
+ className = props.className + " ";
5576
2423
  }
5577
2424
 
5578
- if (defaultedOptions.suspense) {
5579
- // Always set stale time when using suspense to prevent
5580
- // fetching again when directly mounting after suspending
5581
- if (typeof defaultedOptions.staleTime !== 'number') {
5582
- defaultedOptions.staleTime = 1000;
5583
- } // Set cache time to 1 if the option has been set to 0
5584
- // when using suspense to prevent infinite loop of fetches
2425
+ var serialized = serializeStyles(registeredStyles, undefined, React.useContext(ThemeContext));
5585
2426
 
2427
+ if (process.env.NODE_ENV !== 'production' && serialized.name.indexOf('-') === -1) {
2428
+ var labelFromStack = props[labelPropName];
5586
2429
 
5587
- if (defaultedOptions.cacheTime === 0) {
5588
- defaultedOptions.cacheTime = 1;
2430
+ if (labelFromStack) {
2431
+ serialized = serializeStyles([serialized, 'label:' + labelFromStack + ';']);
5589
2432
  }
5590
2433
  }
5591
2434
 
5592
- if (defaultedOptions.suspense || defaultedOptions.useErrorBoundary) {
5593
- // Prevent retrying failed query if the error boundary has not been reset yet
5594
- if (!errorResetBoundary.isReset()) {
5595
- defaultedOptions.retryOnMount = false;
2435
+ className += cache.key + "-" + serialized.name;
2436
+ var newProps = {};
2437
+
2438
+ for (var key in props) {
2439
+ if (hasOwnProperty.call(props, key) && key !== 'css' && key !== typePropName && (process.env.NODE_ENV === 'production' || key !== labelPropName)) {
2440
+ newProps[key] = props[key];
5596
2441
  }
5597
2442
  }
5598
2443
 
5599
- var _React$useState2 = React.useState(function () {
5600
- return new Observer(queryClient, defaultedOptions);
5601
- }),
5602
- observer = _React$useState2[0];
5603
-
5604
- var result = observer.getOptimisticResult(defaultedOptions);
5605
- React.useEffect(function () {
5606
- mountedRef.current = true;
5607
- errorResetBoundary.clearReset();
5608
- var unsubscribe = observer.subscribe(notifyManager.batchCalls(function () {
5609
- if (mountedRef.current) {
5610
- forceUpdate(function (x) {
5611
- return x + 1;
5612
- });
5613
- }
5614
- })); // Update result to make sure we did not miss any query updates
5615
- // between creating the observer and subscribing to it.
5616
-
5617
- observer.updateResult();
5618
- return function () {
5619
- mountedRef.current = false;
5620
- unsubscribe();
5621
- };
5622
- }, [errorResetBoundary, observer]);
5623
- React.useEffect(function () {
5624
- // Do not notify on updates because of changes in the options because
5625
- // these changes should already be reflected in the optimistic result.
5626
- observer.setOptions(defaultedOptions, {
5627
- listeners: false
5628
- });
5629
- }, [defaultedOptions, observer]); // Handle suspense
5630
-
5631
- if (defaultedOptions.suspense && result.isLoading) {
5632
- throw observer.fetchOptimistic(defaultedOptions).then(function (_ref) {
5633
- var data = _ref.data;
5634
- defaultedOptions.onSuccess == null ? void 0 : defaultedOptions.onSuccess(data);
5635
- defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(data, null);
5636
- }).catch(function (error) {
5637
- errorResetBoundary.clearReset();
5638
- defaultedOptions.onError == null ? void 0 : defaultedOptions.onError(error);
5639
- defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(undefined, error);
5640
- });
5641
- } // Handle error boundary
5642
-
5643
-
5644
- if (result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(defaultedOptions.suspense, defaultedOptions.useErrorBoundary, [result.error, observer.getCurrentQuery()])) {
5645
- throw result.error;
5646
- } // Handle result property usage tracking
2444
+ newProps.ref = ref;
2445
+ newProps.className = className;
2446
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Insertion, {
2447
+ cache: cache,
2448
+ serialized: serialized,
2449
+ isStringTag: typeof WrappedComponent === 'string'
2450
+ }), /*#__PURE__*/React.createElement(WrappedComponent, newProps));
2451
+ });
5647
2452
 
2453
+ if (process.env.NODE_ENV !== 'production') {
2454
+ Emotion.displayName = 'EmotionCssPropInternal';
2455
+ }
5648
2456
 
5649
- if (defaultedOptions.notifyOnChangeProps === 'tracked') {
5650
- result = observer.trackResult(result, defaultedOptions);
2457
+ function jsx(type, props, key) {
2458
+ if (!hasOwnProperty.call(props, 'css')) {
2459
+ return jsxRuntime.jsx(type, props, key);
5651
2460
  }
5652
2461
 
5653
- return result;
2462
+ return jsxRuntime.jsx(Emotion, createEmotionProps(type, props), key);
5654
2463
  }
2464
+ function jsxs(type, props, key) {
2465
+ if (!hasOwnProperty.call(props, 'css')) {
2466
+ return jsxRuntime.jsxs(type, props, key);
2467
+ }
5655
2468
 
5656
- function useQuery(arg1, arg2, arg3) {
5657
- var parsedOptions = parseQueryArgs(arg1, arg2, arg3);
5658
- return useBaseQuery(parsedOptions, QueryObserver);
2469
+ return jsxRuntime.jsxs(Emotion, createEmotionProps(type, props), key);
5659
2470
  }
5660
2471
 
2472
+ var dist = {};
2473
+
2474
+ Object.defineProperty(dist, "__esModule", { value: true });
2475
+ var _default = dist.default = (function () {
2476
+ });
2477
+
5661
2478
  var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
5662
2479
  var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
5663
2480
  var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
@@ -11015,7 +7832,7 @@ const ShipEngine = ({ baseURL, children, headers, getToken }) => {
11015
7832
  );
11016
7833
  return void 0;
11017
7834
  });
11018
- const queryClient = new QueryClient();
7835
+ const queryClient = new reactQuery.QueryClient();
11019
7836
  if (!client) {
11020
7837
  return /* @__PURE__ */ jsxRuntime.jsx(
11021
7838
  "div",
@@ -11031,7 +7848,7 @@ const ShipEngine = ({ baseURL, children, headers, getToken }) => {
11031
7848
  }
11032
7849
  );
11033
7850
  }
11034
- return /* @__PURE__ */ jsxRuntime.jsx(ShipEngineContext.Provider, { value: { client }, children: /* @__PURE__ */ jsxRuntime.jsx(QueryClientProvider, { client: queryClient, children }) });
7851
+ return /* @__PURE__ */ jsxRuntime.jsx(ShipEngineContext.Provider, { value: { client }, children: /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: queryClient, children }) });
11035
7852
  };
11036
7853
  const useShipEngine = () => {
11037
7854
  const shipengine = React.useContext(ShipEngineContext);
@@ -11121,7 +7938,7 @@ var __async$j = (__this, __arguments, generator) => {
11121
7938
  };
11122
7939
  const useAddFunds = (carrierId) => {
11123
7940
  const { client } = useShipEngine();
11124
- return useMutation({
7941
+ return reactQuery.useMutation({
11125
7942
  mutationFn: (funds) => __async$j(void 0, null, function* () {
11126
7943
  const result = yield client.carriers.addFunds(carrierId, funds);
11127
7944
  return result.data;
@@ -11153,7 +7970,7 @@ var __async$i = (__this, __arguments, generator) => {
11153
7970
  };
11154
7971
  const useCalculateRates = () => {
11155
7972
  const { client } = useShipEngine();
11156
- return useMutation({
7973
+ return reactQuery.useMutation({
11157
7974
  mutationFn: (_0) => __async$i(void 0, [_0], function* ({ rateOptions, shipmentId }) {
11158
7975
  const result = yield client.rates.calculateByShipmentId(shipmentId, rateOptions);
11159
7976
  return result.data;
@@ -11185,7 +8002,7 @@ var __async$h = (__this, __arguments, generator) => {
11185
8002
  };
11186
8003
  const useConnectCarrier = () => {
11187
8004
  const { client } = useShipEngine();
11188
- return useMutation({
8005
+ return reactQuery.useMutation({
11189
8006
  mutationFn: (params) => __async$h(void 0, null, function* () {
11190
8007
  const result = yield client.carriers.connect(params);
11191
8008
  return result.data;
@@ -11232,7 +8049,7 @@ var __async$g = (__this, __arguments, generator) => {
11232
8049
  };
11233
8050
  const useCreateLabel = () => {
11234
8051
  const { client } = useShipEngine();
11235
- return useMutation({
8052
+ return reactQuery.useMutation({
11236
8053
  mutationFn: (_a) => __async$g(void 0, null, function* () {
11237
8054
  var _b = _a, { rateId } = _b, options = __objRest$5(_b, ["rateId"]);
11238
8055
  const result = yield client.labels.createByRateId(rateId, options);
@@ -11280,7 +8097,7 @@ var __async$f = (__this, __arguments, generator) => {
11280
8097
  };
11281
8098
  const useCreateSalesOrderShipment = () => {
11282
8099
  const { client } = useShipEngine();
11283
- return useMutation({
8100
+ return reactQuery.useMutation({
11284
8101
  mutationFn: (_a) => __async$f(void 0, null, function* () {
11285
8102
  var _b = _a, { salesOrderId } = _b, shipment = __objRest$4(_b, ["salesOrderId"]);
11286
8103
  const result = yield client.salesOrderShipments.create(salesOrderId, shipment);
@@ -11313,7 +8130,7 @@ var __async$e = (__this, __arguments, generator) => {
11313
8130
  };
11314
8131
  const useCreateWarehouse = () => {
11315
8132
  const { client } = useShipEngine();
11316
- return useMutation({
8133
+ return reactQuery.useMutation({
11317
8134
  mutationFn: (data) => __async$e(void 0, null, function* () {
11318
8135
  const result = yield client.warehouses.create(data);
11319
8136
  return result.data;
@@ -11345,7 +8162,7 @@ var __async$d = (__this, __arguments, generator) => {
11345
8162
  };
11346
8163
  const useDeleteWarehouse = () => {
11347
8164
  const { client } = useShipEngine();
11348
- return useMutation({
8165
+ return reactQuery.useMutation({
11349
8166
  mutationFn: (_0) => __async$d(void 0, [_0], function* ({ warehouseId }) {
11350
8167
  const result = yield client.warehouses.delete(warehouseId);
11351
8168
  return result.data;
@@ -11357,7 +8174,7 @@ const useDeleteWarehouse = () => {
11357
8174
 
11358
8175
  const useGetAccountSettings = () => {
11359
8176
  const { client } = useShipEngine();
11360
- return useQuery({
8177
+ return reactQuery.useQuery({
11361
8178
  onError,
11362
8179
  queryFn: () => client.accountSettings.get(),
11363
8180
  queryKey: ["getAccountSettings"],
@@ -11367,7 +8184,7 @@ const useGetAccountSettings = () => {
11367
8184
 
11368
8185
  const useGetAutoFundingConfiguration = (carrierId) => {
11369
8186
  const { client } = useShipEngine();
11370
- return useQuery({
8187
+ return reactQuery.useQuery({
11371
8188
  enabled: carrierId !== void 0,
11372
8189
  onError,
11373
8190
  queryFn: () => {
@@ -11382,7 +8199,7 @@ const useGetAutoFundingConfiguration = (carrierId) => {
11382
8199
 
11383
8200
  const useGetCarrierById = (carrierId) => {
11384
8201
  const { client } = useShipEngine();
11385
- return useQuery({
8202
+ return reactQuery.useQuery({
11386
8203
  enabled: !!carrierId,
11387
8204
  onError,
11388
8205
  queryFn: () => {
@@ -11399,7 +8216,7 @@ const useGetCarrierById = (carrierId) => {
11399
8216
 
11400
8217
  const useGetInsuranceAccount = (insuranceProvider) => {
11401
8218
  const { client } = useShipEngine();
11402
- return useQuery({
8219
+ return reactQuery.useQuery({
11403
8220
  enabled: insuranceProvider !== void 0,
11404
8221
  onError,
11405
8222
  queryFn: () => {
@@ -11414,7 +8231,7 @@ const useGetInsuranceAccount = (insuranceProvider) => {
11414
8231
 
11415
8232
  const useGetLabel = (labelId) => {
11416
8233
  const { client } = useShipEngine();
11417
- return useQuery({
8234
+ return reactQuery.useQuery({
11418
8235
  enabled: labelId !== void 0,
11419
8236
  onError,
11420
8237
  queryFn: () => {
@@ -11429,7 +8246,7 @@ const useGetLabel = (labelId) => {
11429
8246
 
11430
8247
  const useGetSalesOrder = (salesOrderId) => {
11431
8248
  const { client } = useShipEngine();
11432
- return useQuery({
8249
+ return reactQuery.useQuery({
11433
8250
  enabled: salesOrderId !== void 0,
11434
8251
  onError,
11435
8252
  queryFn: () => {
@@ -11444,7 +8261,7 @@ const useGetSalesOrder = (salesOrderId) => {
11444
8261
 
11445
8262
  const useGetSalesOrderShipment = (shipmentId) => {
11446
8263
  const { client } = useShipEngine();
11447
- return useQuery({
8264
+ return reactQuery.useQuery({
11448
8265
  enabled: shipmentId !== void 0,
11449
8266
  onError,
11450
8267
  queryFn: () => {
@@ -11459,7 +8276,7 @@ const useGetSalesOrderShipment = (shipmentId) => {
11459
8276
 
11460
8277
  const useGetShipment = (shipmentId) => {
11461
8278
  const { client } = useShipEngine();
11462
- return useQuery({
8279
+ return reactQuery.useQuery({
11463
8280
  enabled: shipmentId !== void 0,
11464
8281
  onError,
11465
8282
  queryFn: () => {
@@ -11480,7 +8297,7 @@ const useGetWalletHistory = ({
11480
8297
  }) => {
11481
8298
  const { client } = useShipEngine();
11482
8299
  const [startDate, endDate] = range;
11483
- return useQuery({
8300
+ return reactQuery.useQuery({
11484
8301
  enabled,
11485
8302
  keepPreviousData: true,
11486
8303
  // See https://react-query-v3.tanstack.com/guides/paginated-queries#better-paginated-queries-with-keeppreviousdata
@@ -11493,7 +8310,7 @@ const useGetWalletHistory = ({
11493
8310
 
11494
8311
  const useListCarriers = () => {
11495
8312
  const { client } = useShipEngine();
11496
- return useQuery({
8313
+ return reactQuery.useQuery({
11497
8314
  onError,
11498
8315
  queryFn: () => client.carriers.list(),
11499
8316
  queryKey: ["useListCarriers"],
@@ -11503,7 +8320,7 @@ const useListCarriers = () => {
11503
8320
 
11504
8321
  const useListCustomPackageTypes = () => {
11505
8322
  const { client } = useShipEngine();
11506
- return useQuery({
8323
+ return reactQuery.useQuery({
11507
8324
  onError,
11508
8325
  queryFn: () => client.customPackages.list(),
11509
8326
  queryKey: ["useListCustomPackageTypes"],
@@ -11513,7 +8330,7 @@ const useListCustomPackageTypes = () => {
11513
8330
 
11514
8331
  const useListLabels = (params) => {
11515
8332
  const { client } = useShipEngine();
11516
- return useQuery({
8333
+ return reactQuery.useQuery({
11517
8334
  enabled: params && Object.values(params).some((v) => v !== void 0),
11518
8335
  onError,
11519
8336
  queryFn: () => client.labels.list(params),
@@ -11524,7 +8341,7 @@ const useListLabels = (params) => {
11524
8341
 
11525
8342
  const useListOrderSources = () => {
11526
8343
  const { client } = useShipEngine();
11527
- return useQuery({
8344
+ return reactQuery.useQuery({
11528
8345
  onError,
11529
8346
  queryFn: () => client.orderSources.list(),
11530
8347
  queryKey: ["useListOrderSources"],
@@ -11534,7 +8351,7 @@ const useListOrderSources = () => {
11534
8351
 
11535
8352
  const useListSalesOrderShipments = (params) => {
11536
8353
  const { client } = useShipEngine();
11537
- return useQuery({
8354
+ return reactQuery.useQuery({
11538
8355
  enabled: params && Object.values(params).some((v) => v !== void 0),
11539
8356
  onError,
11540
8357
  queryFn: () => client.salesOrderShipments.list(params),
@@ -11545,7 +8362,7 @@ const useListSalesOrderShipments = (params) => {
11545
8362
 
11546
8363
  const useListSalesOrders = (params = {}) => {
11547
8364
  const { client } = useShipEngine();
11548
- return useQuery({
8365
+ return reactQuery.useQuery({
11549
8366
  enabled: params && Object.values(params).some((v) => v !== void 0),
11550
8367
  onError,
11551
8368
  queryFn: () => client.salesOrders.list(params),
@@ -11556,7 +8373,7 @@ const useListSalesOrders = (params = {}) => {
11556
8373
 
11557
8374
  const useListWarehouses = () => {
11558
8375
  const { client } = useShipEngine();
11559
- return useQuery({
8376
+ return reactQuery.useQuery({
11560
8377
  onError,
11561
8378
  queryFn: () => client.warehouses.list(),
11562
8379
  queryKey: ["useListWarehouses"],
@@ -11601,7 +8418,7 @@ var __async$c = (__this, __arguments, generator) => {
11601
8418
  };
11602
8419
  const useNotifySalesOrderShipped = () => {
11603
8420
  const { client } = useShipEngine();
11604
- return useMutation({
8421
+ return reactQuery.useMutation({
11605
8422
  mutationFn: (_a) => __async$c(void 0, null, function* () {
11606
8423
  var _b = _a, { salesOrderId } = _b, tracking = __objRest$3(_b, ["salesOrderId"]);
11607
8424
  const result = yield client.salesOrders.notifyShipped(salesOrderId, tracking);
@@ -11634,7 +8451,7 @@ var __async$b = (__this, __arguments, generator) => {
11634
8451
  };
11635
8452
  const useParseAddress = () => {
11636
8453
  const { client } = useShipEngine();
11637
- return useMutation({
8454
+ return reactQuery.useMutation({
11638
8455
  mutationFn: (_0) => __async$b(void 0, [_0], function* ({ address, text }) {
11639
8456
  const result = yield client.addresses.parse(text, address);
11640
8457
  return result.data;
@@ -11666,7 +8483,7 @@ var __async$a = (__this, __arguments, generator) => {
11666
8483
  };
11667
8484
  const useRefreshOrderSourceAsync = () => {
11668
8485
  const { client } = useShipEngine();
11669
- return useMutation({
8486
+ return reactQuery.useMutation({
11670
8487
  mutationFn: (orderSourceId) => __async$a(void 0, null, function* () {
11671
8488
  const result = yield client.orderSources.refresh(orderSourceId);
11672
8489
  return result.data;
@@ -11677,7 +8494,7 @@ const useRefreshOrderSourceAsync = () => {
11677
8494
  const useRefreshOrderSource = () => {
11678
8495
  const { client } = useShipEngine();
11679
8496
  const { mutateAsync: refreshOrderSourceAsync } = useRefreshOrderSourceAsync();
11680
- return useMutation({
8497
+ return reactQuery.useMutation({
11681
8498
  mutationFn: (orderSourceId) => __async$a(void 0, null, function* () {
11682
8499
  yield refreshOrderSourceAsync(orderSourceId);
11683
8500
  const waitResult = yield retryUntil(() => __async$a(void 0, null, function* () {
@@ -11715,7 +8532,7 @@ var __async$9 = (__this, __arguments, generator) => {
11715
8532
  });
11716
8533
  };
11717
8534
  const useUpdateAccountSettings = () => {
11718
- return useMutation({
8535
+ return reactQuery.useMutation({
11719
8536
  mutationFn: (_settings) => __async$9(void 0, null, function* () {
11720
8537
  const result = yield Promise.resolve({
11721
8538
  data: { defaultLabelLayout: "4x6", dimension: "inch", weight: "ounce" },
@@ -11752,8 +8569,8 @@ var __async$8 = (__this, __arguments, generator) => {
11752
8569
  };
11753
8570
  const useUpdateAutoFunding = (carrierId) => {
11754
8571
  const { client } = useShipEngine();
11755
- const queryClient = useQueryClient();
11756
- return useMutation({
8572
+ const queryClient = reactQuery.useQueryClient();
8573
+ return reactQuery.useMutation({
11757
8574
  mutationFn: (options) => __async$8(void 0, null, function* () {
11758
8575
  const result = yield client.carriers.updateAutoFunding(carrierId, options);
11759
8576
  return result.data;
@@ -11787,7 +8604,7 @@ var __async$7 = (__this, __arguments, generator) => {
11787
8604
  });
11788
8605
  };
11789
8606
  const useUpdateBilling = () => {
11790
- return useMutation({
8607
+ return reactQuery.useMutation({
11791
8608
  mutationFn: (_params) => __async$7(void 0, null, function* () {
11792
8609
  const result = yield Promise.resolve({
11793
8610
  data: {},
@@ -11839,7 +8656,7 @@ var __async$6 = (__this, __arguments, generator) => {
11839
8656
  };
11840
8657
  const useUpdateSalesOrderShipment = () => {
11841
8658
  const { client } = useShipEngine();
11842
- return useMutation({
8659
+ return reactQuery.useMutation({
11843
8660
  mutationFn: (_a) => __async$6(void 0, null, function* () {
11844
8661
  var _b = _a, { shipmentId } = _b, shipment = __objRest$2(_b, ["shipmentId"]);
11845
8662
  const result = yield client.salesOrderShipments.update(shipmentId, shipment);
@@ -11887,7 +8704,7 @@ var __async$5 = (__this, __arguments, generator) => {
11887
8704
  };
11888
8705
  const useUpdateWarehouse = () => {
11889
8706
  const { client } = useShipEngine();
11890
- return useMutation({
8707
+ return reactQuery.useMutation({
11891
8708
  mutationFn: (_a) => __async$5(void 0, null, function* () {
11892
8709
  var _b = _a, { warehouseId } = _b, warehouse = __objRest$1(_b, ["warehouseId"]);
11893
8710
  const result = yield client.warehouses.update(warehouseId, warehouse);
@@ -11920,7 +8737,7 @@ var __async$4 = (__this, __arguments, generator) => {
11920
8737
  };
11921
8738
  const useValidateAddresses = () => {
11922
8739
  const { client } = useShipEngine();
11923
- return useMutation({
8740
+ return reactQuery.useMutation({
11924
8741
  mutationFn: (addresses) => __async$4(void 0, null, function* () {
11925
8742
  const result = yield client.addresses.validate(addresses);
11926
8743
  return result.data;
@@ -11952,7 +8769,7 @@ var __async$3 = (__this, __arguments, generator) => {
11952
8769
  };
11953
8770
  const useVoidLabel = () => {
11954
8771
  const { client } = useShipEngine();
11955
- return useMutation({
8772
+ return reactQuery.useMutation({
11956
8773
  mutationFn: (labelId) => __async$3(void 0, null, function* () {
11957
8774
  const result = yield client.labels.void(labelId);
11958
8775
  return result.data;
@@ -12273,6 +9090,14 @@ function _assertThisInitialized(self) {
12273
9090
  return self;
12274
9091
  }
12275
9092
 
9093
+ function _setPrototypeOf(o, p) {
9094
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
9095
+ o.__proto__ = p;
9096
+ return o;
9097
+ };
9098
+ return _setPrototypeOf(o, p);
9099
+ }
9100
+
12276
9101
  function _inherits(subClass, superClass) {
12277
9102
  if (typeof superClass !== "function" && superClass !== null) {
12278
9103
  throw new TypeError("Super expression must either be null or a function");