UNPKG

@apengine/react-querier

Version:

Library for apengine to help send requests from React

1,544 lines (1,543 loc) 45.1 kB
import { useState as z, useEffect as Ne } from "react"; let Z = {}; const T = () => { if (!Z) throw new Error("Querier was not initialized properly!"); return Z; }, Ke = (e) => { Z = e; }; var Y = /* @__PURE__ */ ((e) => (e.DESC = "desc", e.ASC = "asc", e))(Y || {}); const Ge = (e, t, r) => { const n = t.split("."); let s = e; n.forEach((o, i) => { s[o] || (s[o] = {}), i === n.length - 1 && (s[o] = r), s = s[o]; }); }, N = (e) => JSON.stringify(e).replace(/"([^"]+)":/g, "$1:"), Xe = (e) => JSON.parse(JSON.stringify(e, (t, r) => r === void 0 ? null : r)), Qe = (e) => JSON.stringify(e).replace(/"([^"]+)":/g, "$1:").replace(/"/g, ""), fe = (e) => { const t = e.reduce((n, s) => { const o = { ...n }; return Ge(o, s, !0), o; }, {}), r = (n) => { let s = ""; return Object.entries(n).forEach(([o, i]) => { if (i === !0) { s += ` ${o} `; return; } s += ` ${o} { ${r(i)} } `; }), s; }; return r(t); }, Ze = (e) => Object.keys(e).reduce( (t, r) => ({ ...t, [r]: e[r] === "desc" ? Y.DESC : Y.ASC }), {} ); var P = function() { return P = Object.assign || function(t) { for (var r, n = 1, s = arguments.length; n < s; n++) { r = arguments[n]; for (var o in r) Object.prototype.hasOwnProperty.call(r, o) && (t[o] = r[o]); } return t; }, P.apply(this, arguments); }; function Ye(e) { return e.toLowerCase(); } var et = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g], tt = /[^A-Z0-9]+/gi; function Te(e, t) { t === void 0 && (t = {}); for (var r = t.splitRegexp, n = r === void 0 ? et : r, s = t.stripRegexp, o = s === void 0 ? tt : s, i = t.transform, c = i === void 0 ? Ye : i, f = t.delimiter, u = f === void 0 ? " " : f, l = de(de(e, n, "$1\0$2"), o, "\0"), h = 0, y = l.length; l.charAt(h) === "\0"; ) h++; for (; l.charAt(y - 1) === "\0"; ) y--; return l.slice(h, y).split("\0").map(c).join(u); } function de(e, t, r) { return t instanceof RegExp ? e.replace(t, r) : t.reduce(function(n, s) { return n.replace(s, r); }, e); } function Ce(e, t) { var r = e.charAt(0), n = e.substr(1).toLowerCase(); return t > 0 && r >= "0" && r <= "9" ? "_" + r + n : "" + r.toUpperCase() + n; } function rt(e, t) { return t === void 0 && (t = {}), Te(e, P({ delimiter: "", transform: Ce }, t)); } function nt(e, t) { return t === 0 ? e.toLowerCase() : Ce(e, t); } function st(e, t) { return t === void 0 && (t = {}), rt(e, P({ transform: nt }, t)); } function ot(e, t) { return t === void 0 && (t = {}), Te(e, P({ delimiter: "." }, t)); } function it(e, t) { return t === void 0 && (t = {}), ot(e, P({ delimiter: "_" }, t)); } const at = { snake: it, camel: st, none: (e) => e }, ct = { snake: "_", camel: "_", none: "" }; class D { static toEngineName(t, r, n) { const s = Array.isArray(r) ? [...r] : [r]; return n != null && n.prefix && s.unshift(n.prefix), n != null && n.suffix && s.push(n.suffix), at[t](s.join(ct[t])); } } function xe(e, t) { return function() { return e.apply(t, arguments); }; } const { toString: Pe } = Object.prototype, { getPrototypeOf: se } = Object, oe = ((e) => (t) => { const r = Pe.call(t); return e[r] || (e[r] = r.slice(8, -1).toLowerCase()); })(/* @__PURE__ */ Object.create(null)), A = (e) => (e = e.toLowerCase(), (t) => oe(t) === e), V = (e) => (t) => typeof t === e, { isArray: F } = Array, B = V("undefined"); function ut(e) { return e !== null && !B(e) && e.constructor !== null && !B(e.constructor) && C(e.constructor.isBuffer) && e.constructor.isBuffer(e); } const _e = A("ArrayBuffer"); function lt(e) { let t; return typeof ArrayBuffer < "u" && ArrayBuffer.isView ? t = ArrayBuffer.isView(e) : t = e && e.buffer && _e(e.buffer), t; } const ft = V("string"), C = V("function"), Fe = V("number"), ie = (e) => e !== null && typeof e == "object", dt = (e) => e === !0 || e === !1, H = (e) => { if (oe(e) !== "object") return !1; const t = se(e); return (t === null || t === Object.prototype || Object.getPrototypeOf(t) === null) && !(Symbol.toStringTag in e) && !(Symbol.iterator in e); }, ht = A("Date"), pt = A("File"), mt = A("Blob"), yt = A("FileList"), wt = (e) => ie(e) && C(e.pipe), Et = (e) => { const t = "[object FormData]"; return e && (typeof FormData == "function" && e instanceof FormData || Pe.call(e) === t || C(e.toString) && e.toString() === t); }, bt = A("URLSearchParams"), gt = (e) => e.trim ? e.trim() : e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""); function j(e, t, { allOwnKeys: r = !1 } = {}) { if (e === null || typeof e > "u") return; let n, s; if (typeof e != "object" && (e = [e]), F(e)) for (n = 0, s = e.length; n < s; n++) t.call(null, e[n], n, e); else { const o = r ? Object.getOwnPropertyNames(e) : Object.keys(e), i = o.length; let c; for (n = 0; n < i; n++) c = o[n], t.call(null, e[c], c, e); } } function De(e, t) { t = t.toLowerCase(); const r = Object.keys(e); let n = r.length, s; for (; n-- > 0; ) if (s = r[n], t === s.toLowerCase()) return s; return null; } const Le = (() => typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : global)(), Ue = (e) => !B(e) && e !== Le; function ee() { const { caseless: e } = Ue(this) && this || {}, t = {}, r = (n, s) => { const o = e && De(t, s) || s; H(t[o]) && H(n) ? t[o] = ee(t[o], n) : H(n) ? t[o] = ee({}, n) : F(n) ? t[o] = n.slice() : t[o] = n; }; for (let n = 0, s = arguments.length; n < s; n++) arguments[n] && j(arguments[n], r); return t; } const St = (e, t, r, { allOwnKeys: n } = {}) => (j(t, (s, o) => { r && C(s) ? e[o] = xe(s, r) : e[o] = s; }, { allOwnKeys: n }), e), Rt = (e) => (e.charCodeAt(0) === 65279 && (e = e.slice(1)), e), At = (e, t, r, n) => { e.prototype = Object.create(t.prototype, n), e.prototype.constructor = e, Object.defineProperty(e, "super", { value: t.prototype }), r && Object.assign(e.prototype, r); }, Ot = (e, t, r, n) => { let s, o, i; const c = {}; if (t = t || {}, e == null) return t; do { for (s = Object.getOwnPropertyNames(e), o = s.length; o-- > 0; ) i = s[o], (!n || n(i, e, t)) && !c[i] && (t[i] = e[i], c[i] = !0); e = r !== !1 && se(e); } while (e && (!r || r(e, t)) && e !== Object.prototype); return t; }, Nt = (e, t, r) => { e = String(e), (r === void 0 || r > e.length) && (r = e.length), r -= t.length; const n = e.indexOf(t, r); return n !== -1 && n === r; }, Tt = (e) => { if (!e) return null; if (F(e)) return e; let t = e.length; if (!Fe(t)) return null; const r = new Array(t); for (; t-- > 0; ) r[t] = e[t]; return r; }, Ct = ((e) => (t) => e && t instanceof e)(typeof Uint8Array < "u" && se(Uint8Array)), xt = (e, t) => { const n = (e && e[Symbol.iterator]).call(e); let s; for (; (s = n.next()) && !s.done; ) { const o = s.value; t.call(e, o[0], o[1]); } }, Pt = (e, t) => { let r; const n = []; for (; (r = e.exec(t)) !== null; ) n.push(r); return n; }, _t = A("HTMLFormElement"), Ft = (e) => e.toLowerCase().replace( /[_-\s]([a-z\d])(\w*)/g, function(r, n, s) { return n.toUpperCase() + s; } ), he = (({ hasOwnProperty: e }) => (t, r) => e.call(t, r))(Object.prototype), Dt = A("RegExp"), Be = (e, t) => { const r = Object.getOwnPropertyDescriptors(e), n = {}; j(r, (s, o) => { t(s, o, e) !== !1 && (n[o] = s); }), Object.defineProperties(e, n); }, Lt = (e) => { Be(e, (t, r) => { if (C(e) && ["arguments", "caller", "callee"].indexOf(r) !== -1) return !1; const n = e[r]; if (!!C(n)) { if (t.enumerable = !1, "writable" in t) { t.writable = !1; return; } t.set || (t.set = () => { throw Error("Can not rewrite read-only method '" + r + "'"); }); } }); }, Ut = (e, t) => { const r = {}, n = (s) => { s.forEach((o) => { r[o] = !0; }); }; return F(e) ? n(e) : n(String(e).split(t)), r; }, Bt = () => { }, jt = (e, t) => (e = +e, Number.isFinite(e) ? e : t), $t = (e) => { const t = new Array(10), r = (n, s) => { if (ie(n)) { if (t.indexOf(n) >= 0) return; if (!("toJSON" in n)) { t[s] = n; const o = F(n) ? [] : {}; return j(n, (i, c) => { const f = r(i, s + 1); !B(f) && (o[c] = f); }), t[s] = void 0, o; } } return n; }; return r(e, 0); }, a = { isArray: F, isArrayBuffer: _e, isBuffer: ut, isFormData: Et, isArrayBufferView: lt, isString: ft, isNumber: Fe, isBoolean: dt, isObject: ie, isPlainObject: H, isUndefined: B, isDate: ht, isFile: pt, isBlob: mt, isRegExp: Dt, isFunction: C, isStream: wt, isURLSearchParams: bt, isTypedArray: Ct, isFileList: yt, forEach: j, merge: ee, extend: St, trim: gt, stripBOM: Rt, inherits: At, toFlatObject: Ot, kindOf: oe, kindOfTest: A, endsWith: Nt, toArray: Tt, forEachEntry: xt, matchAll: Pt, isHTMLForm: _t, hasOwnProperty: he, hasOwnProp: he, reduceDescriptors: Be, freezeMethods: Lt, toObjectSet: Ut, toCamelCase: Ft, noop: Bt, toFiniteNumber: jt, findKey: De, global: Le, isContextDefined: Ue, toJSONObject: $t }; function m(e, t, r, n, s) { Error.call(this), Error.captureStackTrace ? Error.captureStackTrace(this, this.constructor) : this.stack = new Error().stack, this.message = e, this.name = "AxiosError", t && (this.code = t), r && (this.config = r), n && (this.request = n), s && (this.response = s); } a.inherits(m, Error, { toJSON: function() { return { message: this.message, name: this.name, description: this.description, number: this.number, fileName: this.fileName, lineNumber: this.lineNumber, columnNumber: this.columnNumber, stack: this.stack, config: a.toJSONObject(this.config), code: this.code, status: this.response && this.response.status ? this.response.status : null }; } }); const je = m.prototype, $e = {}; [ "ERR_BAD_OPTION_VALUE", "ERR_BAD_OPTION", "ECONNABORTED", "ETIMEDOUT", "ERR_NETWORK", "ERR_FR_TOO_MANY_REDIRECTS", "ERR_DEPRECATED", "ERR_BAD_RESPONSE", "ERR_BAD_REQUEST", "ERR_CANCELED", "ERR_NOT_SUPPORT", "ERR_INVALID_URL" ].forEach((e) => { $e[e] = { value: e }; }); Object.defineProperties(m, $e); Object.defineProperty(je, "isAxiosError", { value: !0 }); m.from = (e, t, r, n, s, o) => { const i = Object.create(je); return a.toFlatObject(e, i, function(f) { return f !== Error.prototype; }, (c) => c !== "isAxiosError"), m.call(i, e.message, t, r, n, s), i.cause = e, i.name = e.name, o && Object.assign(i, o), i; }; var kt = typeof self == "object" ? self.FormData : window.FormData; const qt = kt; function te(e) { return a.isPlainObject(e) || a.isArray(e); } function ke(e) { return a.endsWith(e, "[]") ? e.slice(0, -2) : e; } function pe(e, t, r) { return e ? e.concat(t).map(function(s, o) { return s = ke(s), !r && o ? "[" + s + "]" : s; }).join(r ? "." : "") : t; } function Ht(e) { return a.isArray(e) && !e.some(te); } const It = a.toFlatObject(a, {}, null, function(t) { return /^is[A-Z]/.test(t); }); function Mt(e) { return e && a.isFunction(e.append) && e[Symbol.toStringTag] === "FormData" && e[Symbol.iterator]; } function W(e, t, r) { if (!a.isObject(e)) throw new TypeError("target must be an object"); t = t || new (qt || FormData)(), r = a.toFlatObject(r, { metaTokens: !0, dots: !1, indexes: !1 }, !1, function(p, S) { return !a.isUndefined(S[p]); }); const n = r.metaTokens, s = r.visitor || l, o = r.dots, i = r.indexes, f = (r.Blob || typeof Blob < "u" && Blob) && Mt(t); if (!a.isFunction(s)) throw new TypeError("visitor must be a function"); function u(d) { if (d === null) return ""; if (a.isDate(d)) return d.toISOString(); if (!f && a.isBlob(d)) throw new m("Blob is not supported. Use a Buffer instead."); return a.isArrayBuffer(d) || a.isTypedArray(d) ? f && typeof Blob == "function" ? new Blob([d]) : Buffer.from(d) : d; } function l(d, p, S) { let b = d; if (d && !S && typeof d == "object") { if (a.endsWith(p, "{}")) p = n ? p : p.slice(0, -2), d = JSON.stringify(d); else if (a.isArray(d) && Ht(d) || a.isFileList(d) || a.endsWith(p, "[]") && (b = a.toArray(d))) return p = ke(p), b.forEach(function(q, We) { !(a.isUndefined(q) || q === null) && t.append( i === !0 ? pe([p], We, o) : i === null ? p : p + "[]", u(q) ); }), !1; } return te(d) ? !0 : (t.append(pe(S, p, o), u(d)), !1); } const h = [], y = Object.assign(It, { defaultVisitor: l, convertValue: u, isVisitable: te }); function w(d, p) { if (!a.isUndefined(d)) { if (h.indexOf(d) !== -1) throw Error("Circular reference detected in " + p.join(".")); h.push(d), a.forEach(d, function(b, x) { (!(a.isUndefined(b) || b === null) && s.call( t, b, a.isString(x) ? x.trim() : x, p, y )) === !0 && w(b, p ? p.concat(x) : [x]); }), h.pop(); } } if (!a.isObject(e)) throw new TypeError("data must be an object"); return w(e), t; } function me(e) { const t = { "!": "%21", "'": "%27", "(": "%28", ")": "%29", "~": "%7E", "%20": "+", "%00": "\0" }; return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g, function(n) { return t[n]; }); } function ae(e, t) { this._pairs = [], e && W(e, this, t); } const qe = ae.prototype; qe.append = function(t, r) { this._pairs.push([t, r]); }; qe.toString = function(t) { const r = t ? function(n) { return t.call(this, n, me); } : me; return this._pairs.map(function(s) { return r(s[0]) + "=" + r(s[1]); }, "").join("&"); }; function Jt(e) { return encodeURIComponent(e).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+").replace(/%5B/gi, "[").replace(/%5D/gi, "]"); } function He(e, t, r) { if (!t) return e; const n = r && r.encode || Jt, s = r && r.serialize; let o; if (s ? o = s(t, r) : o = a.isURLSearchParams(t) ? t.toString() : new ae(t, r).toString(n), o) { const i = e.indexOf("#"); i !== -1 && (e = e.slice(0, i)), e += (e.indexOf("?") === -1 ? "?" : "&") + o; } return e; } class zt { constructor() { this.handlers = []; } use(t, r, n) { return this.handlers.push({ fulfilled: t, rejected: r, synchronous: n ? n.synchronous : !1, runWhen: n ? n.runWhen : null }), this.handlers.length - 1; } eject(t) { this.handlers[t] && (this.handlers[t] = null); } clear() { this.handlers && (this.handlers = []); } forEach(t) { a.forEach(this.handlers, function(n) { n !== null && t(n); }); } } const ye = zt, Ie = { silentJSONParsing: !0, forcedJSONParsing: !0, clarifyTimeoutError: !1 }, vt = typeof URLSearchParams < "u" ? URLSearchParams : ae, Vt = FormData, Wt = (() => { let e; return typeof navigator < "u" && ((e = navigator.product) === "ReactNative" || e === "NativeScript" || e === "NS") ? !1 : typeof window < "u" && typeof document < "u"; })(), Kt = (() => typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope && typeof self.importScripts == "function")(), g = { isBrowser: !0, classes: { URLSearchParams: vt, FormData: Vt, Blob }, isStandardBrowserEnv: Wt, isStandardBrowserWebWorkerEnv: Kt, protocols: ["http", "https", "file", "blob", "url", "data"] }; function Gt(e, t) { return W(e, new g.classes.URLSearchParams(), Object.assign({ visitor: function(r, n, s, o) { return g.isNode && a.isBuffer(r) ? (this.append(n, r.toString("base64")), !1) : o.defaultVisitor.apply(this, arguments); } }, t)); } function Xt(e) { return a.matchAll(/\w+|\[(\w*)]/g, e).map((t) => t[0] === "[]" ? "" : t[1] || t[0]); } function Qt(e) { const t = {}, r = Object.keys(e); let n; const s = r.length; let o; for (n = 0; n < s; n++) o = r[n], t[o] = e[o]; return t; } function Me(e) { function t(r, n, s, o) { let i = r[o++]; const c = Number.isFinite(+i), f = o >= r.length; return i = !i && a.isArray(s) ? s.length : i, f ? (a.hasOwnProp(s, i) ? s[i] = [s[i], n] : s[i] = n, !c) : ((!s[i] || !a.isObject(s[i])) && (s[i] = []), t(r, n, s[i], o) && a.isArray(s[i]) && (s[i] = Qt(s[i])), !c); } if (a.isFormData(e) && a.isFunction(e.entries)) { const r = {}; return a.forEachEntry(e, (n, s) => { t(Xt(n), s, r, 0); }), r; } return null; } const Zt = { "Content-Type": void 0 }; function Yt(e, t, r) { if (a.isString(e)) try { return (t || JSON.parse)(e), a.trim(e); } catch (n) { if (n.name !== "SyntaxError") throw n; } return (r || JSON.stringify)(e); } const K = { transitional: Ie, adapter: ["xhr", "http"], transformRequest: [function(t, r) { const n = r.getContentType() || "", s = n.indexOf("application/json") > -1, o = a.isObject(t); if (o && a.isHTMLForm(t) && (t = new FormData(t)), a.isFormData(t)) return s && s ? JSON.stringify(Me(t)) : t; if (a.isArrayBuffer(t) || a.isBuffer(t) || a.isStream(t) || a.isFile(t) || a.isBlob(t)) return t; if (a.isArrayBufferView(t)) return t.buffer; if (a.isURLSearchParams(t)) return r.setContentType("application/x-www-form-urlencoded;charset=utf-8", !1), t.toString(); let c; if (o) { if (n.indexOf("application/x-www-form-urlencoded") > -1) return Gt(t, this.formSerializer).toString(); if ((c = a.isFileList(t)) || n.indexOf("multipart/form-data") > -1) { const f = this.env && this.env.FormData; return W( c ? { "files[]": t } : t, f && new f(), this.formSerializer ); } } return o || s ? (r.setContentType("application/json", !1), Yt(t)) : t; }], transformResponse: [function(t) { const r = this.transitional || K.transitional, n = r && r.forcedJSONParsing, s = this.responseType === "json"; if (t && a.isString(t) && (n && !this.responseType || s)) { const i = !(r && r.silentJSONParsing) && s; try { return JSON.parse(t); } catch (c) { if (i) throw c.name === "SyntaxError" ? m.from(c, m.ERR_BAD_RESPONSE, this, null, this.response) : c; } } return t; }], timeout: 0, xsrfCookieName: "XSRF-TOKEN", xsrfHeaderName: "X-XSRF-TOKEN", maxContentLength: -1, maxBodyLength: -1, env: { FormData: g.classes.FormData, Blob: g.classes.Blob }, validateStatus: function(t) { return t >= 200 && t < 300; }, headers: { common: { Accept: "application/json, text/plain, */*" } } }; a.forEach(["delete", "get", "head"], function(t) { K.headers[t] = {}; }); a.forEach(["post", "put", "patch"], function(t) { K.headers[t] = a.merge(Zt); }); const ce = K, er = a.toObjectSet([ "age", "authorization", "content-length", "content-type", "etag", "expires", "from", "host", "if-modified-since", "if-unmodified-since", "last-modified", "location", "max-forwards", "proxy-authorization", "referer", "retry-after", "user-agent" ]), tr = (e) => { const t = {}; let r, n, s; return e && e.split(` `).forEach(function(i) { s = i.indexOf(":"), r = i.substring(0, s).trim().toLowerCase(), n = i.substring(s + 1).trim(), !(!r || t[r] && er[r]) && (r === "set-cookie" ? t[r] ? t[r].push(n) : t[r] = [n] : t[r] = t[r] ? t[r] + ", " + n : n); }), t; }, we = Symbol("internals"); function L(e) { return e && String(e).trim().toLowerCase(); } function I(e) { return e === !1 || e == null ? e : a.isArray(e) ? e.map(I) : String(e); } function rr(e) { const t = /* @__PURE__ */ Object.create(null), r = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g; let n; for (; n = r.exec(e); ) t[n[1]] = n[2]; return t; } function nr(e) { return /^[-_a-zA-Z]+$/.test(e.trim()); } function Ee(e, t, r, n) { if (a.isFunction(n)) return n.call(this, t, r); if (!!a.isString(t)) { if (a.isString(n)) return t.indexOf(n) !== -1; if (a.isRegExp(n)) return n.test(t); } } function sr(e) { return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g, (t, r, n) => r.toUpperCase() + n); } function or(e, t) { const r = a.toCamelCase(" " + t); ["get", "set", "has"].forEach((n) => { Object.defineProperty(e, n + r, { value: function(s, o, i) { return this[n].call(this, t, s, o, i); }, configurable: !0 }); }); } class G { constructor(t) { t && this.set(t); } set(t, r, n) { const s = this; function o(c, f, u) { const l = L(f); if (!l) throw new Error("header name must be a non-empty string"); const h = a.findKey(s, l); (!h || s[h] === void 0 || u === !0 || u === void 0 && s[h] !== !1) && (s[h || f] = I(c)); } const i = (c, f) => a.forEach(c, (u, l) => o(u, l, f)); return a.isPlainObject(t) || t instanceof this.constructor ? i(t, r) : a.isString(t) && (t = t.trim()) && !nr(t) ? i(tr(t), r) : t != null && o(r, t, n), this; } get(t, r) { if (t = L(t), t) { const n = a.findKey(this, t); if (n) { const s = this[n]; if (!r) return s; if (r === !0) return rr(s); if (a.isFunction(r)) return r.call(this, s, n); if (a.isRegExp(r)) return r.exec(s); throw new TypeError("parser must be boolean|regexp|function"); } } } has(t, r) { if (t = L(t), t) { const n = a.findKey(this, t); return !!(n && (!r || Ee(this, this[n], n, r))); } return !1; } delete(t, r) { const n = this; let s = !1; function o(i) { if (i = L(i), i) { const c = a.findKey(n, i); c && (!r || Ee(n, n[c], c, r)) && (delete n[c], s = !0); } } return a.isArray(t) ? t.forEach(o) : o(t), s; } clear() { return Object.keys(this).forEach(this.delete.bind(this)); } normalize(t) { const r = this, n = {}; return a.forEach(this, (s, o) => { const i = a.findKey(n, o); if (i) { r[i] = I(s), delete r[o]; return; } const c = t ? sr(o) : String(o).trim(); c !== o && delete r[o], r[c] = I(s), n[c] = !0; }), this; } concat(...t) { return this.constructor.concat(this, ...t); } toJSON(t) { const r = /* @__PURE__ */ Object.create(null); return a.forEach(this, (n, s) => { n != null && n !== !1 && (r[s] = t && a.isArray(n) ? n.join(", ") : n); }), r; } [Symbol.iterator]() { return Object.entries(this.toJSON())[Symbol.iterator](); } toString() { return Object.entries(this.toJSON()).map(([t, r]) => t + ": " + r).join(` `); } get [Symbol.toStringTag]() { return "AxiosHeaders"; } static from(t) { return t instanceof this ? t : new this(t); } static concat(t, ...r) { const n = new this(t); return r.forEach((s) => n.set(s)), n; } static accessor(t) { const n = (this[we] = this[we] = { accessors: {} }).accessors, s = this.prototype; function o(i) { const c = L(i); n[c] || (or(s, i), n[c] = !0); } return a.isArray(t) ? t.forEach(o) : o(t), this; } } G.accessor(["Content-Type", "Content-Length", "Accept", "Accept-Encoding", "User-Agent"]); a.freezeMethods(G.prototype); a.freezeMethods(G); const R = G; function X(e, t) { const r = this || ce, n = t || r, s = R.from(n.headers); let o = n.data; return a.forEach(e, function(c) { o = c.call(r, o, s.normalize(), t ? t.status : void 0); }), s.normalize(), o; } function Je(e) { return !!(e && e.__CANCEL__); } function $(e, t, r) { m.call(this, e == null ? "canceled" : e, m.ERR_CANCELED, t, r), this.name = "CanceledError"; } a.inherits($, m, { __CANCEL__: !0 }); const ir = null; function ar(e, t, r) { const n = r.config.validateStatus; !r.status || !n || n(r.status) ? e(r) : t(new m( "Request failed with status code " + r.status, [m.ERR_BAD_REQUEST, m.ERR_BAD_RESPONSE][Math.floor(r.status / 100) - 4], r.config, r.request, r )); } const cr = g.isStandardBrowserEnv ? function() { return { write: function(r, n, s, o, i, c) { const f = []; f.push(r + "=" + encodeURIComponent(n)), a.isNumber(s) && f.push("expires=" + new Date(s).toGMTString()), a.isString(o) && f.push("path=" + o), a.isString(i) && f.push("domain=" + i), c === !0 && f.push("secure"), document.cookie = f.join("; "); }, read: function(r) { const n = document.cookie.match(new RegExp("(^|;\\s*)(" + r + ")=([^;]*)")); return n ? decodeURIComponent(n[3]) : null; }, remove: function(r) { this.write(r, "", Date.now() - 864e5); } }; }() : function() { return { write: function() { }, read: function() { return null; }, remove: function() { } }; }(); function ur(e) { return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(e); } function lr(e, t) { return t ? e.replace(/\/+$/, "") + "/" + t.replace(/^\/+/, "") : e; } function ze(e, t) { return e && !ur(t) ? lr(e, t) : t; } const fr = g.isStandardBrowserEnv ? function() { const t = /(msie|trident)/i.test(navigator.userAgent), r = document.createElement("a"); let n; function s(o) { let i = o; return t && (r.setAttribute("href", i), i = r.href), r.setAttribute("href", i), { href: r.href, protocol: r.protocol ? r.protocol.replace(/:$/, "") : "", host: r.host, search: r.search ? r.search.replace(/^\?/, "") : "", hash: r.hash ? r.hash.replace(/^#/, "") : "", hostname: r.hostname, port: r.port, pathname: r.pathname.charAt(0) === "/" ? r.pathname : "/" + r.pathname }; } return n = s(window.location.href), function(i) { const c = a.isString(i) ? s(i) : i; return c.protocol === n.protocol && c.host === n.host; }; }() : function() { return function() { return !0; }; }(); function dr(e) { const t = /^([-+\w]{1,25})(:?\/\/|:)/.exec(e); return t && t[1] || ""; } function hr(e, t) { e = e || 10; const r = new Array(e), n = new Array(e); let s = 0, o = 0, i; return t = t !== void 0 ? t : 1e3, function(f) { const u = Date.now(), l = n[o]; i || (i = u), r[s] = f, n[s] = u; let h = o, y = 0; for (; h !== s; ) y += r[h++], h = h % e; if (s = (s + 1) % e, s === o && (o = (o + 1) % e), u - i < t) return; const w = l && u - l; return w ? Math.round(y * 1e3 / w) : void 0; }; } function be(e, t) { let r = 0; const n = hr(50, 250); return (s) => { const o = s.loaded, i = s.lengthComputable ? s.total : void 0, c = o - r, f = n(c), u = o <= i; r = o; const l = { loaded: o, total: i, progress: i ? o / i : void 0, bytes: c, rate: f || void 0, estimated: f && i && u ? (i - o) / f : void 0, event: s }; l[t ? "download" : "upload"] = !0, e(l); }; } const pr = typeof XMLHttpRequest < "u", mr = pr && function(e) { return new Promise(function(r, n) { let s = e.data; const o = R.from(e.headers).normalize(), i = e.responseType; let c; function f() { e.cancelToken && e.cancelToken.unsubscribe(c), e.signal && e.signal.removeEventListener("abort", c); } a.isFormData(s) && (g.isStandardBrowserEnv || g.isStandardBrowserWebWorkerEnv) && o.setContentType(!1); let u = new XMLHttpRequest(); if (e.auth) { const w = e.auth.username || "", d = e.auth.password ? unescape(encodeURIComponent(e.auth.password)) : ""; o.set("Authorization", "Basic " + btoa(w + ":" + d)); } const l = ze(e.baseURL, e.url); u.open(e.method.toUpperCase(), He(l, e.params, e.paramsSerializer), !0), u.timeout = e.timeout; function h() { if (!u) return; const w = R.from( "getAllResponseHeaders" in u && u.getAllResponseHeaders() ), p = { data: !i || i === "text" || i === "json" ? u.responseText : u.response, status: u.status, statusText: u.statusText, headers: w, config: e, request: u }; ar(function(b) { r(b), f(); }, function(b) { n(b), f(); }, p), u = null; } if ("onloadend" in u ? u.onloadend = h : u.onreadystatechange = function() { !u || u.readyState !== 4 || u.status === 0 && !(u.responseURL && u.responseURL.indexOf("file:") === 0) || setTimeout(h); }, u.onabort = function() { !u || (n(new m("Request aborted", m.ECONNABORTED, e, u)), u = null); }, u.onerror = function() { n(new m("Network Error", m.ERR_NETWORK, e, u)), u = null; }, u.ontimeout = function() { let d = e.timeout ? "timeout of " + e.timeout + "ms exceeded" : "timeout exceeded"; const p = e.transitional || Ie; e.timeoutErrorMessage && (d = e.timeoutErrorMessage), n(new m( d, p.clarifyTimeoutError ? m.ETIMEDOUT : m.ECONNABORTED, e, u )), u = null; }, g.isStandardBrowserEnv) { const w = (e.withCredentials || fr(l)) && e.xsrfCookieName && cr.read(e.xsrfCookieName); w && o.set(e.xsrfHeaderName, w); } s === void 0 && o.setContentType(null), "setRequestHeader" in u && a.forEach(o.toJSON(), function(d, p) { u.setRequestHeader(p, d); }), a.isUndefined(e.withCredentials) || (u.withCredentials = !!e.withCredentials), i && i !== "json" && (u.responseType = e.responseType), typeof e.onDownloadProgress == "function" && u.addEventListener("progress", be(e.onDownloadProgress, !0)), typeof e.onUploadProgress == "function" && u.upload && u.upload.addEventListener("progress", be(e.onUploadProgress)), (e.cancelToken || e.signal) && (c = (w) => { !u || (n(!w || w.type ? new $(null, e, u) : w), u.abort(), u = null); }, e.cancelToken && e.cancelToken.subscribe(c), e.signal && (e.signal.aborted ? c() : e.signal.addEventListener("abort", c))); const y = dr(l); if (y && g.protocols.indexOf(y) === -1) { n(new m("Unsupported protocol " + y + ":", m.ERR_BAD_REQUEST, e)); return; } u.send(s || null); }); }, M = { http: ir, xhr: mr }; a.forEach(M, (e, t) => { if (e) { try { Object.defineProperty(e, "name", { value: t }); } catch { } Object.defineProperty(e, "adapterName", { value: t }); } }); const yr = { getAdapter: (e) => { e = a.isArray(e) ? e : [e]; const { length: t } = e; let r, n; for (let s = 0; s < t && (r = e[s], !(n = a.isString(r) ? M[r.toLowerCase()] : r)); s++) ; if (!n) throw n === !1 ? new m( `Adapter ${r} is not supported by the environment`, "ERR_NOT_SUPPORT" ) : new Error( a.hasOwnProp(M, r) ? `Adapter '${r}' is not available in the build` : `Unknown adapter '${r}'` ); if (!a.isFunction(n)) throw new TypeError("adapter is not a function"); return n; }, adapters: M }; function Q(e) { if (e.cancelToken && e.cancelToken.throwIfRequested(), e.signal && e.signal.aborted) throw new $(null, e); } function ge(e) { return Q(e), e.headers = R.from(e.headers), e.data = X.call( e, e.transformRequest ), ["post", "put", "patch"].indexOf(e.method) !== -1 && e.headers.setContentType("application/x-www-form-urlencoded", !1), yr.getAdapter(e.adapter || ce.adapter)(e).then(function(n) { return Q(e), n.data = X.call( e, e.transformResponse, n ), n.headers = R.from(n.headers), n; }, function(n) { return Je(n) || (Q(e), n && n.response && (n.response.data = X.call( e, e.transformResponse, n.response ), n.response.headers = R.from(n.response.headers))), Promise.reject(n); }); } const Se = (e) => e instanceof R ? e.toJSON() : e; function _(e, t) { t = t || {}; const r = {}; function n(u, l, h) { return a.isPlainObject(u) && a.isPlainObject(l) ? a.merge.call({ caseless: h }, u, l) : a.isPlainObject(l) ? a.merge({}, l) : a.isArray(l) ? l.slice() : l; } function s(u, l, h) { if (a.isUndefined(l)) { if (!a.isUndefined(u)) return n(void 0, u, h); } else return n(u, l, h); } function o(u, l) { if (!a.isUndefined(l)) return n(void 0, l); } function i(u, l) { if (a.isUndefined(l)) { if (!a.isUndefined(u)) return n(void 0, u); } else return n(void 0, l); } function c(u, l, h) { if (h in t) return n(u, l); if (h in e) return n(void 0, u); } const f = { url: o, method: o, data: o, baseURL: i, transformRequest: i, transformResponse: i, paramsSerializer: i, timeout: i, timeoutMessage: i, withCredentials: i, adapter: i, responseType: i, xsrfCookieName: i, xsrfHeaderName: i, onUploadProgress: i, onDownloadProgress: i, decompress: i, maxContentLength: i, maxBodyLength: i, beforeRedirect: i, transport: i, httpAgent: i, httpsAgent: i, cancelToken: i, socketPath: i, responseEncoding: i, validateStatus: c, headers: (u, l) => s(Se(u), Se(l), !0) }; return a.forEach(Object.keys(e).concat(Object.keys(t)), function(l) { const h = f[l] || s, y = h(e[l], t[l], l); a.isUndefined(y) && h !== c || (r[l] = y); }), r; } const ve = "1.2.2", ue = {}; ["object", "boolean", "number", "function", "string", "symbol"].forEach((e, t) => { ue[e] = function(n) { return typeof n === e || "a" + (t < 1 ? "n " : " ") + e; }; }); const Re = {}; ue.transitional = function(t, r, n) { function s(o, i) { return "[Axios v" + ve + "] Transitional option '" + o + "'" + i + (n ? ". " + n : ""); } return (o, i, c) => { if (t === !1) throw new m( s(i, " has been removed" + (r ? " in " + r : "")), m.ERR_DEPRECATED ); return r && !Re[i] && (Re[i] = !0, console.warn( s( i, " has been deprecated since v" + r + " and will be removed in the near future" ) )), t ? t(o, i, c) : !0; }; }; function wr(e, t, r) { if (typeof e != "object") throw new m("options must be an object", m.ERR_BAD_OPTION_VALUE); const n = Object.keys(e); let s = n.length; for (; s-- > 0; ) { const o = n[s], i = t[o]; if (i) { const c = e[o], f = c === void 0 || i(c, o, e); if (f !== !0) throw new m("option " + o + " must be " + f, m.ERR_BAD_OPTION_VALUE); continue; } if (r !== !0) throw new m("Unknown option " + o, m.ERR_BAD_OPTION); } } const re = { assertOptions: wr, validators: ue }, O = re.validators; class v { constructor(t) { this.defaults = t, this.interceptors = { request: new ye(), response: new ye() }; } request(t, r) { typeof t == "string" ? (r = r || {}, r.url = t) : r = t || {}, r = _(this.defaults, r); const { transitional: n, paramsSerializer: s, headers: o } = r; n !== void 0 && re.assertOptions(n, { silentJSONParsing: O.transitional(O.boolean), forcedJSONParsing: O.transitional(O.boolean), clarifyTimeoutError: O.transitional(O.boolean) }, !1), s !== void 0 && re.assertOptions(s, { encode: O.function, serialize: O.function }, !0), r.method = (r.method || this.defaults.method || "get").toLowerCase(); let i; i = o && a.merge( o.common, o[r.method] ), i && a.forEach( ["delete", "get", "head", "post", "put", "patch", "common"], (d) => { delete o[d]; } ), r.headers = R.concat(i, o); const c = []; let f = !0; this.interceptors.request.forEach(function(p) { typeof p.runWhen == "function" && p.runWhen(r) === !1 || (f = f && p.synchronous, c.unshift(p.fulfilled, p.rejected)); }); const u = []; this.interceptors.response.forEach(function(p) { u.push(p.fulfilled, p.rejected); }); let l, h = 0, y; if (!f) { const d = [ge.bind(this), void 0]; for (d.unshift.apply(d, c), d.push.apply(d, u), y = d.length, l = Promise.resolve(r); h < y; ) l = l.then(d[h++], d[h++]); return l; } y = c.length; let w = r; for (h = 0; h < y; ) { const d = c[h++], p = c[h++]; try { w = d(w); } catch (S) { p.call(this, S); break; } } try { l = ge.call(this, w); } catch (d) { return Promise.reject(d); } for (h = 0, y = u.length; h < y; ) l = l.then(u[h++], u[h++]); return l; } getUri(t) { t = _(this.defaults, t); const r = ze(t.baseURL, t.url); return He(r, t.params, t.paramsSerializer); } } a.forEach(["delete", "get", "head", "options"], function(t) { v.prototype[t] = function(r, n) { return this.request(_(n || {}, { method: t, url: r, data: (n || {}).data })); }; }); a.forEach(["post", "put", "patch"], function(t) { function r(n) { return function(o, i, c) { return this.request(_(c || {}, { method: t, headers: n ? { "Content-Type": "multipart/form-data" } : {}, url: o, data: i })); }; } v.prototype[t] = r(), v.prototype[t + "Form"] = r(!0); }); const J = v; class le { constructor(t) { if (typeof t != "function") throw new TypeError("executor must be a function."); let r; this.promise = new Promise(function(o) { r = o; }); const n = this; this.promise.then((s) => { if (!n._listeners) return; let o = n._listeners.length; for (; o-- > 0; ) n._listeners[o](s); n._listeners = null; }), this.promise.then = (s) => { let o; const i = new Promise((c) => { n.subscribe(c), o = c; }).then(s); return i.cancel = function() { n.unsubscribe(o); }, i; }, t(function(o, i, c) { n.reason || (n.reason = new $(o, i, c), r(n.reason)); }); } throwIfRequested() { if (this.reason) throw this.reason; } subscribe(t) { if (this.reason) { t(this.reason); return; } this._listeners ? this._listeners.push(t) : this._listeners = [t]; } unsubscribe(t) { if (!this._listeners) return; const r = this._listeners.indexOf(t); r !== -1 && this._listeners.splice(r, 1); } static source() { let t; return { token: new le(function(s) { t = s; }), cancel: t }; } } const Er = le; function br(e) { return function(r) { return e.apply(null, r); }; } function gr(e) { return a.isObject(e) && e.isAxiosError === !0; } const ne = { Continue: 100, SwitchingProtocols: 101, Processing: 102, EarlyHints: 103, Ok: 200, Created: 201, Accepted: 202, NonAuthoritativeInformation: 203, NoContent: 204, ResetContent: 205, PartialContent: 206, MultiStatus: 207, AlreadyReported: 208, ImUsed: 226, MultipleChoices: 300, MovedPermanently: 301, Found: 302, SeeOther: 303, NotModified: 304, UseProxy: 305, Unused: 306, TemporaryRedirect: 307, PermanentRedirect: 308, BadRequest: 400, Unauthorized: 401, PaymentRequired: 402, Forbidden: 403, NotFound: 404, MethodNotAllowed: 405, NotAcceptable: 406, ProxyAuthenticationRequired: 407, RequestTimeout: 408, Conflict: 409, Gone: 410, LengthRequired: 411, PreconditionFailed: 412, PayloadTooLarge: 413, UriTooLong: 414, UnsupportedMediaType: 415, RangeNotSatisfiable: 416, ExpectationFailed: 417, ImATeapot: 418, MisdirectedRequest: 421, UnprocessableEntity: 422, Locked: 423, FailedDependency: 424, TooEarly: 425, UpgradeRequired: 426, PreconditionRequired: 428, TooManyRequests: 429, RequestHeaderFieldsTooLarge: 431, UnavailableForLegalReasons: 451, InternalServerError: 500, NotImplemented: 501, BadGateway: 502, ServiceUnavailable: 503, GatewayTimeout: 504, HttpVersionNotSupported: 505, VariantAlsoNegotiates: 506, InsufficientStorage: 507, LoopDetected: 508, NotExtended: 510, NetworkAuthenticationRequired: 511 }; Object.entries(ne).forEach(([e, t]) => { ne[t] = e; }); const Sr = ne; function Ve(e) { const t = new J(e), r = xe(J.prototype.request, t); return a.extend(r, J.prototype, t, { allOwnKeys: !0 }), a.extend(r, t, null, { allOwnKeys: !0 }), r.create = function(s) { return Ve(_(e, s)); }, r; } const E = Ve(ce); E.Axios = J; E.CanceledError = $; E.CancelToken = Er; E.isCancel = Je; E.VERSION = ve; E.toFormData = W; E.AxiosError = m; E.Cancel = E.CanceledError; E.all = function(t) { return Promise.all(t); }; E.spread = br; E.isAxiosError = gr; E.mergeConfig = _; E.AxiosHeaders = R; E.formToJSON = (e) => Me(a.isHTMLForm(e) ? new FormData(e) : e); E.HttpStatusCode = Sr; E.default = E; const Rr = E, U = async (e) => { var o, i, c, f, u; const t = Date.now(), { authorization: r, host: n } = T(), s = r ? { authorization: r } : void 0; try { const { data: l } = await Rr.post(`${n}/graphql`, e, { headers: s }), h = Date.now(); if ((o = T().debug) != null && o.logTime && console.log(`Req took ${h - t}ms`), Array.isArray(l.errors)) throw l.errors.map(({ message: w }) => w).join(` `); return l; } catch (l) { throw Array.isArray((c = (i = l.response) == null ? void 0 : i.data) == null ? void 0 : c.errors) ? (u = (f = l.response) == null ? void 0 : f.data) == null ? void 0 : u.errors.map(({ message: y }) => y).join(` `) : new Error(l); } }; class k { static async insert(t, r, n = ["id"], s) { const o = s == null ? void 0 : s.debug, i = D.toEngineName(T().engineCase, ["insert", t]), c = { query: ` mutation { ${i} ${r ? `(objects: ${N(Array.isArray(r) ? r : [r])} )` : ""} { ${n.join(` `)} } } ` }; return o && console.log(c), (await U(c)).data[i]; } static async select(t, r = {}, n) { const s = D.toEngineName(T().engineCase, [t]), o = n == null ? void 0 : n.debug, { where: i, fields: c, limit: f, orderBy: u, offset: l, transform: h } = r, y = { query: ` query ($limit: Int, $offset: Int) { ${s} ( ${i ? `where: ${N(i)},` : ""} ${u ? `order_by: ${Qe(Ze(u))},` : ""} limit: $limit, offset: $offset, ) { ${fe(c != null ? c : ["id"])} } } `, variables: { limit: f, offset: l } }; o && console.log(y); const d = (await U(y)).data[s]; return h ? h(d) : d; } static async selectAggregation(t, r, n) { const s = D.toEngineName(T().engineCase, [t], { suffix: "aggregate" }), o = n == null ? void 0 : n.debug, { where: i, fields: c, transform: f } = r, u = { query: ` query { ${s} ${i ? `(where: ${N(i)})` : ""} { ${fe(c)} } } ` }; o && console.log(u); const h = (await U(u)).data[s]; return f ? f(h) : h; } static async delete(t, r, n) { const s = n == null ? void 0 : n.debug, o = r == null ? void 0 : r.where, c = { query: ` mutation { ${D.toEngineName(T().engineCase, ["delete", t])} ${o ? `(where: ${N(o)})` : ""} } ` }; s && console.log(c), await U(c); } static async update(t, r, n, s) { const o = s == null ? void 0 : s.debug, i = n == null ? void 0 : n.where, f = { query: ` mutation { ${D.toEngineName(T().engineCase, ["update", t])} ( ${i ? `where: ${N(i)},` : ""} object: ${n != null && n.replaceNull ? N(Xe(r)) : N(r)} ) } ` }; o && console.log(f), await U(f); } } let Ae = null; try { Ae = EventSource || require("eventsource"); } catch { Ae = require("eventsource"); } const Oe = {}, Or = () => { if (!Oe) throw new Error("Querier was not initialized properly!"); return Oe; }, Nr = (e) => { Ke(e); }, Tr = (e, t, r, n) => { const [s, o] = z(), [i, c] = z(!0), f = async () => { c(!0); const u = await k.select(e, t, n); return o(u), c(!1), u; }; return Ne(() => { r != null && r.skip || f().catch(console.error); }, [e, JSON.stringify(t), JSON.stringify(r), JSON.stringify(n)]), { data: s, loading: i, refetch: f }; }, Cr = (e, t, r, n) => { const [s, o] = z(), [i, c] = z(!0), f = async () => { if (r != null && r.skip) return; c(!0); const u = await k.selectAggregation(e, t, n); return o(u), c(!1), u; }; return Ne(() => { f().catch(console.error); }, [e, JSON.stringify(t), JSON.stringify(r), JSON.stringify(n)]), { data: s, loading: i, refetch: f }; }, xr = (e) => async (r, n = ["id"], s) => await k.insert(e, r, n, s), Pr = (e) => async (r, n) => { await k.delete(e, r, n); }, _r = (e) => async (r, n, s) => { await k.update(e, r, n, s); }; export { Or as getOptions, Nr as initQuerier, Pr as useDelete, xr as useInsert, Tr as useSelect, Cr as useSelectAggregation, _r as useUpdate };