@shipengine/alchemy 0.4.9 → 0.4.11

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