react-qc-v
Version:
Lightweight @tanstack/react-query wrapper that provides error/loading, and more...
768 lines (764 loc) • 25.5 kB
JavaScript
import { QueryErrorResetBoundary as pr, useQuery as gr, useInfiniteQuery as yr } from "@tanstack/react-query";
import Ie, { createContext as We, useContext as $e } from "react";
import { ErrorBoundary as hr } from "react-error-boundary";
var ie = { exports: {} }, V = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var De;
function Er() {
if (De)
return V;
De = 1;
var a = Ie, o = Symbol.for("react.element"), l = Symbol.for("react.fragment"), p = Object.prototype.hasOwnProperty, h = a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, R = { key: !0, ref: !0, __self: !0, __source: !0 };
function g(d, f, T) {
var v, b = {}, P = null, j = null;
T !== void 0 && (P = "" + T), f.key !== void 0 && (P = "" + f.key), f.ref !== void 0 && (j = f.ref);
for (v in f)
p.call(f, v) && !R.hasOwnProperty(v) && (b[v] = f[v]);
if (d && d.defaultProps)
for (v in f = d.defaultProps, f)
b[v] === void 0 && (b[v] = f[v]);
return { $$typeof: o, type: d, key: P, ref: j, props: b, _owner: h.current };
}
return V.Fragment = l, V.jsx = g, V.jsxs = g, V;
}
var M = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Fe;
function mr() {
return Fe || (Fe = 1, process.env.NODE_ENV !== "production" && function() {
var a = Ie, o = Symbol.for("react.element"), l = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), h = Symbol.for("react.strict_mode"), R = Symbol.for("react.profiler"), g = Symbol.for("react.provider"), d = Symbol.for("react.context"), f = Symbol.for("react.forward_ref"), T = Symbol.for("react.suspense"), v = Symbol.for("react.suspense_list"), b = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), j = Symbol.for("react.offscreen"), A = Symbol.iterator, W = "@@iterator";
function $(e) {
if (e === null || typeof e != "object")
return null;
var r = A && e[A] || e[W];
return typeof r == "function" ? r : null;
}
var _ = a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function m(e) {
{
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
t[n - 1] = arguments[n];
N("error", e, t);
}
}
function N(e, r, t) {
{
var n = _.ReactDebugCurrentFrame, s = n.getStackAddendum();
s !== "" && (r += "%s", t = t.concat([s]));
var c = t.map(function(u) {
return String(u);
});
c.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, c);
}
}
var se = !1, Y = !1, Q = !1, B = !1, Le = !1, fe;
fe = Symbol.for("react.module.reference");
function Ue(e) {
return !!(typeof e == "string" || typeof e == "function" || e === p || e === R || Le || e === h || e === T || e === v || B || e === j || se || Y || Q || typeof e == "object" && e !== null && (e.$$typeof === P || e.$$typeof === b || e.$$typeof === g || e.$$typeof === d || e.$$typeof === f || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === fe || e.getModuleId !== void 0));
}
function Ve(e, r, t) {
var n = e.displayName;
if (n)
return n;
var s = r.displayName || r.name || "";
return s !== "" ? t + "(" + s + ")" : t;
}
function ce(e) {
return e.displayName || "Context";
}
function C(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && m("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case p:
return "Fragment";
case l:
return "Portal";
case R:
return "Profiler";
case h:
return "StrictMode";
case T:
return "Suspense";
case v:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case d:
var r = e;
return ce(r) + ".Consumer";
case g:
var t = e;
return ce(t._context) + ".Provider";
case f:
return Ve(e, e.render, "ForwardRef");
case b:
var n = e.displayName || null;
return n !== null ? n : C(e.type) || "Memo";
case P: {
var s = e, c = s._payload, u = s._init;
try {
return C(u(c));
} catch {
return null;
}
}
}
return null;
}
var S = Object.assign, L = 0, le, de, ve, pe, ge, ye, he;
function Ee() {
}
Ee.__reactDisabledLog = !0;
function Me() {
{
if (L === 0) {
le = console.log, de = console.info, ve = console.warn, pe = console.error, ge = console.group, ye = console.groupCollapsed, he = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: Ee,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
L++;
}
}
function Qe() {
{
if (L--, L === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: S({}, e, {
value: le
}),
info: S({}, e, {
value: de
}),
warn: S({}, e, {
value: ve
}),
error: S({}, e, {
value: pe
}),
group: S({}, e, {
value: ge
}),
groupCollapsed: S({}, e, {
value: ye
}),
groupEnd: S({}, e, {
value: he
})
});
}
L < 0 && m("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var X = _.ReactCurrentDispatcher, Z;
function K(e, r, t) {
{
if (Z === void 0)
try {
throw Error();
} catch (s) {
var n = s.stack.trim().match(/\n( *(at )?)/);
Z = n && n[1] || "";
}
return `
` + Z + e;
}
}
var ee = !1, q;
{
var Be = typeof WeakMap == "function" ? WeakMap : Map;
q = new Be();
}
function me(e, r) {
if (!e || ee)
return "";
{
var t = q.get(e);
if (t !== void 0)
return t;
}
var n;
ee = !0;
var s = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var c;
c = X.current, X.current = null, Me();
try {
if (r) {
var u = function() {
throw Error();
};
if (Object.defineProperty(u.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(u, []);
} catch (O) {
n = O;
}
Reflect.construct(e, [], u);
} else {
try {
u.call();
} catch (O) {
n = O;
}
e.call(u.prototype);
}
} else {
try {
throw Error();
} catch (O) {
n = O;
}
e();
}
} catch (O) {
if (O && n && typeof O.stack == "string") {
for (var i = O.stack.split(`
`), x = n.stack.split(`
`), y = i.length - 1, E = x.length - 1; y >= 1 && E >= 0 && i[y] !== x[E]; )
E--;
for (; y >= 1 && E >= 0; y--, E--)
if (i[y] !== x[E]) {
if (y !== 1 || E !== 1)
do
if (y--, E--, E < 0 || i[y] !== x[E]) {
var w = `
` + i[y].replace(" at new ", " at ");
return e.displayName && w.includes("<anonymous>") && (w = w.replace("<anonymous>", e.displayName)), typeof e == "function" && q.set(e, w), w;
}
while (y >= 1 && E >= 0);
break;
}
}
} finally {
ee = !1, X.current = c, Qe(), Error.prepareStackTrace = s;
}
var F = e ? e.displayName || e.name : "", Ae = F ? K(F) : "";
return typeof e == "function" && q.set(e, Ae), Ae;
}
function Ke(e, r, t) {
return me(e, !1);
}
function qe(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function J(e, r, t) {
if (e == null)
return "";
if (typeof e == "function")
return me(e, qe(e));
if (typeof e == "string")
return K(e);
switch (e) {
case T:
return K("Suspense");
case v:
return K("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case f:
return Ke(e.render);
case b:
return J(e.type, r, t);
case P: {
var n = e, s = n._payload, c = n._init;
try {
return J(c(s), r, t);
} catch {
}
}
}
return "";
}
var G = Object.prototype.hasOwnProperty, _e = {}, Re = _.ReactDebugCurrentFrame;
function z(e) {
if (e) {
var r = e._owner, t = J(e.type, e._source, r ? r.type : null);
Re.setExtraStackFrame(t);
} else
Re.setExtraStackFrame(null);
}
function Je(e, r, t, n, s) {
{
var c = Function.call.bind(G);
for (var u in e)
if (c(e, u)) {
var i = void 0;
try {
if (typeof e[u] != "function") {
var x = Error((n || "React class") + ": " + t + " type `" + u + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[u] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw x.name = "Invariant Violation", x;
}
i = e[u](r, u, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (y) {
i = y;
}
i && !(i instanceof Error) && (z(s), m("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, u, typeof i), z(null)), i instanceof Error && !(i.message in _e) && (_e[i.message] = !0, z(s), m("Failed %s type: %s", t, i.message), z(null));
}
}
}
var Ge = Array.isArray;
function re(e) {
return Ge(e);
}
function ze(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t;
}
}
function He(e) {
try {
return be(e), !1;
} catch {
return !0;
}
}
function be(e) {
return "" + e;
}
function xe(e) {
if (He(e))
return m("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", ze(e)), be(e);
}
var U = _.ReactCurrentOwner, Xe = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, Te, Pe, te;
te = {};
function Ze(e) {
if (G.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function er(e) {
if (G.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function rr(e, r) {
if (typeof e.ref == "string" && U.current && r && U.current.stateNode !== r) {
var t = C(U.current.type);
te[t] || (m('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', C(U.current.type), e.ref), te[t] = !0);
}
}
function tr(e, r) {
{
var t = function() {
Te || (Te = !0, m("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
}
function nr(e, r) {
{
var t = function() {
Pe || (Pe = !0, m("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: t,
configurable: !0
});
}
}
var ar = function(e, r, t, n, s, c, u) {
var i = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: o,
// Built-in properties that belong on the element
type: e,
key: r,
ref: t,
props: u,
// Record the component responsible for creating this element.
_owner: c
};
return i._store = {}, Object.defineProperty(i._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(i, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: n
}), Object.defineProperty(i, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: s
}), Object.freeze && (Object.freeze(i.props), Object.freeze(i)), i;
};
function or(e, r, t, n, s) {
{
var c, u = {}, i = null, x = null;
t !== void 0 && (xe(t), i = "" + t), er(r) && (xe(r.key), i = "" + r.key), Ze(r) && (x = r.ref, rr(r, s));
for (c in r)
G.call(r, c) && !Xe.hasOwnProperty(c) && (u[c] = r[c]);
if (e && e.defaultProps) {
var y = e.defaultProps;
for (c in y)
u[c] === void 0 && (u[c] = y[c]);
}
if (i || x) {
var E = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
i && tr(u, E), x && nr(u, E);
}
return ar(e, i, x, s, n, U.current, u);
}
}
var ne = _.ReactCurrentOwner, we = _.ReactDebugCurrentFrame;
function D(e) {
if (e) {
var r = e._owner, t = J(e.type, e._source, r ? r.type : null);
we.setExtraStackFrame(t);
} else
we.setExtraStackFrame(null);
}
var ae;
ae = !1;
function oe(e) {
return typeof e == "object" && e !== null && e.$$typeof === o;
}
function Ce() {
{
if (ne.current) {
var e = C(ne.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function ir(e) {
{
if (e !== void 0) {
var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber;
return `
Check your code at ` + r + ":" + t + ".";
}
return "";
}
}
var Oe = {};
function ur(e) {
{
var r = Ce();
if (!r) {
var t = typeof e == "string" ? e : e.displayName || e.name;
t && (r = `
Check the top-level render call using <` + t + ">.");
}
return r;
}
}
function je(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var t = ur(r);
if (Oe[t])
return;
Oe[t] = !0;
var n = "";
e && e._owner && e._owner !== ne.current && (n = " It was passed a child from " + C(e._owner.type) + "."), D(e), m('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), D(null);
}
}
function Se(e, r) {
{
if (typeof e != "object")
return;
if (re(e))
for (var t = 0; t < e.length; t++) {
var n = e[t];
oe(n) && je(n, r);
}
else if (oe(e))
e._store && (e._store.validated = !0);
else if (e) {
var s = $(e);
if (typeof s == "function" && s !== e.entries)
for (var c = s.call(e), u; !(u = c.next()).done; )
oe(u.value) && je(u.value, r);
}
}
}
function sr(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var t;
if (typeof r == "function")
t = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === f || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === b))
t = r.propTypes;
else
return;
if (t) {
var n = C(r);
Je(t, e.props, "prop", n, e);
} else if (r.PropTypes !== void 0 && !ae) {
ae = !0;
var s = C(r);
m("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", s || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && m("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function fr(e) {
{
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
var n = r[t];
if (n !== "children" && n !== "key") {
D(e), m("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), D(null);
break;
}
}
e.ref !== null && (D(e), m("Invalid attribute `ref` supplied to `React.Fragment`."), D(null));
}
}
function ke(e, r, t, n, s, c) {
{
var u = Ue(e);
if (!u) {
var i = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (i += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var x = ir(s);
x ? i += x : i += Ce();
var y;
e === null ? y = "null" : re(e) ? y = "array" : e !== void 0 && e.$$typeof === o ? (y = "<" + (C(e.type) || "Unknown") + " />", i = " Did you accidentally export a JSX literal instead of a component?") : y = typeof e, m("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", y, i);
}
var E = or(e, r, t, s, c);
if (E == null)
return E;
if (u) {
var w = r.children;
if (w !== void 0)
if (n)
if (re(w)) {
for (var F = 0; F < w.length; F++)
Se(w[F], e);
Object.freeze && Object.freeze(w);
} else
m("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
Se(w, e);
}
return e === p ? fr(E) : sr(E), E;
}
}
function cr(e, r, t) {
return ke(e, r, t, !0);
}
function lr(e, r, t) {
return ke(e, r, t, !1);
}
var dr = lr, vr = cr;
M.Fragment = p, M.jsx = dr, M.jsxs = vr;
}()), M;
}
process.env.NODE_ENV === "production" ? ie.exports = Er() : ie.exports = mr();
var k = ie.exports;
const Ne = We({
error: ({ resetErrorBoundary: a }) => /* @__PURE__ */ k.jsxs("div", { children: [
/* @__PURE__ */ k.jsx("div", { children: "an error occured!" }),
/* @__PURE__ */ k.jsx("button", { onClick: a, children: "resetErrorBoundary" })
] }),
loading: "loading..."
});
function ue() {
return $e(Ne);
}
function Or({ error: a, loading: o, children: l }) {
return /* @__PURE__ */ k.jsx(Ne.Provider, { value: { error: a, loading: o }, children: l });
}
function _r(a) {
const o = We(a);
function l() {
return $e(o);
}
function p({ extensions: h, children: R }) {
return /* @__PURE__ */ k.jsx(o.Provider, { value: h, children: R });
}
return { useQcExtensions: l, QcExtensionsProvider: p };
}
const { useQcExtensions: Ye, QcExtensionsProvider: jr } = _r({});
function Rr(a) {
return typeof a == "function" ? (o) => a({ ...o, retry: o.resetErrorBoundary }) : () => a;
}
function br(a, o = []) {
const l = a.length + o.length;
return Array.from({ length: l }, (p, h) => h % 2 === 0 ? a[h / 2] : o[(h - 1) / 2]);
}
function Sr(a, ...o) {
return ({ searchParams: l }) => {
const p = o.map((h) => {
const [R, g = R] = h.split("!");
return l.get(R) || g;
});
return br(a, p).join("");
};
}
function kr(a, o) {
if (length < 0 || typeof length != "number")
throw new Error("length must be a positive number");
if (!("fetchNextPage" in a))
throw new Error("results must be a useInfiniteQuery result");
const { status: l, isFetchingNextPage: p, hasNextPage: h, fetchNextPage: R } = a;
l === "success" && !p && h && (typeof o == "function" ? o(a) : o) && R({
cancelRefetch: !1
});
}
function Ar(a) {
const { error: o } = ue(), l = Rr("error" in a ? a.error : o);
return /* @__PURE__ */ k.jsx(pr, { children: ({ reset: p }) => /* @__PURE__ */ k.jsx(hr, { onReset: p, fallbackRender: l, children: a.children }) });
}
const H = (a, o) => typeof a == "function" ? a(o) : a.map((l) => typeof l == "function" ? l(o) : l);
let I = !1;
function Dr(a, o = H) {
return I = !0, xr(a, o);
}
function xr(a, o = H) {
const l = I;
I = !1;
function p(g) {
if (!l)
return o(g, {});
const d = Ye();
return o(g, (typeof d == "function" ? d() : d) || {});
}
function h(g, d, f) {
const v = {
queryKey: p(g),
...a,
...d
};
return gr(v, f);
}
function R({ path: g, body: d, variables: f, hasLoading: T, loading: v, render: b, children: P, client: j, ...A }) {
const { loading: W } = ue(), $ = [g, d, ...Array.isArray(f) ? f : [f]].filter(Boolean), _ = h($, { throwOnError: !0, ...A }, j), m = typeof T == "boolean" ? T : !0, N = typeof v > "u" ? W : v;
return m && _.status === "pending" ? N : b ? b(_.data, _) : P ? P(_.data, _) : null;
}
return Object.assign(R, {
use: h,
useKeyFn: p,
keyFn: o,
defaultOptions: a
});
}
function Fr(a, o = H) {
return I = !0, Tr(a, o);
}
function Tr(a, o = H) {
const l = I;
I = !1;
function p(g) {
if (!l)
return o(g, {});
const d = Ye();
return o(g, (typeof d == "function" ? d() : d) || {});
}
function h(g, d, f) {
const v = {
queryKey: p(g),
...a,
...d
};
return yr(v, f);
}
function R({ path: g, body: d, variables: f, hasLoading: T, loading: v, render: b, children: P, client: j, ...A }) {
const { loading: W } = ue(), $ = [g, d, ...Array.isArray(f) ? f : [f]].filter(Boolean), _ = h($, { throwOnError: (se, Y) => {
var Q, B;
return ((B = (Q = Y == null ? void 0 : Y.data) == null ? void 0 : Q.pages) == null ? void 0 : B.length) === 0;
}, ...A }, j), m = typeof T == "boolean" ? T : !0, N = typeof v > "u" ? W : v;
return m && _.status === "pending" ? N : b ? b(_.data, _) : P ? P(_.data, _) : null;
}
return Object.assign(R, {
use: h,
useKeyFn: p,
keyFn: o,
defaultOptions: a
});
}
export {
Ar as Catch,
jr as QcExtensionsProvider,
Or as QcProvider,
kr as dangerouslyFetchNextPage,
H as defaultKeyFn,
Rr as errorRender,
br as interlace,
Sr as s,
ue as useQcDefaults,
Ye as useQcExtensions,
Tr as wrapUseInfiniteQuery,
Fr as wrapUseInfiniteQueryWithExtensions,
xr as wrapUseQuery,
Dr as wrapUseQueryWithExtensions
};