@apengine/react-querier
Version:
Library for apengine to help send requests from React
41 lines (40 loc) • 34 kB
JavaScript
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("react");let Z={};const N=()=>{if(!Z)throw new Error("Querier was not initialized properly!");return Z},We=e=>{Z=e};var Y=(e=>(e.DESC="desc",e.ASC="asc",e))(Y||{});const Ke=(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]})},T=e=>JSON.stringify(e).replace(/"([^"]+)":/g,"$1:"),Ge=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 Ke(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)},Xe=e=>Object.keys(e).reduce((t,r)=>({...t,[r]:e[r]==="desc"?Y.DESC:Y.ASC}),{});var _=function(){return _=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},_.apply(this,arguments)};function Ze(e){return e.toLowerCase()}var Ye=[/([a-z0-9])([A-Z])/g,/([A-Z])([A-Z][a-z])/g],et=/[^A-Z0-9]+/gi;function Te(e,t){t===void 0&&(t={});for(var r=t.splitRegexp,n=r===void 0?Ye:r,s=t.stripRegexp,o=s===void 0?et:s,i=t.transform,c=i===void 0?Ze: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 Ne(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 tt(e,t){return t===void 0&&(t={}),Te(e,_({delimiter:"",transform:Ne},t))}function rt(e,t){return t===0?e.toLowerCase():Ne(e,t)}function nt(e,t){return t===void 0&&(t={}),tt(e,_({transform:rt},t))}function st(e,t){return t===void 0&&(t={}),Te(e,_({delimiter:"."},t))}function ot(e,t){return t===void 0&&(t={}),st(e,_({delimiter:"_"},t))}const it={snake:ot,camel:nt,none:e=>e},at={snake:"_",camel:"_",none:""};class L{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),it[t](s.join(at[t]))}}function Ce(e,t){return function(){return e.apply(t,arguments)}}const{toString:xe}=Object.prototype,{getPrototypeOf:se}=Object,oe=(e=>t=>{const r=xe.call(t);return e[r]||(e[r]=r.slice(8,-1).toLowerCase())})(Object.create(null)),A=e=>(e=e.toLowerCase(),t=>oe(t)===e),V=e=>t=>typeof t===e,{isArray:D}=Array,j=V("undefined");function ct(e){return e!==null&&!j(e)&&e.constructor!==null&&!j(e.constructor)&&C(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Pe=A("ArrayBuffer");function ut(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Pe(e.buffer),t}const lt=V("string"),C=V("function"),_e=V("number"),ie=e=>e!==null&&typeof e=="object",ft=e=>e===!0||e===!1,M=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)},dt=A("Date"),ht=A("File"),pt=A("Blob"),mt=A("FileList"),yt=e=>ie(e)&&C(e.pipe),wt=e=>{const t="[object FormData]";return e&&(typeof FormData=="function"&&e instanceof FormData||xe.call(e)===t||C(e.toString)&&e.toString()===t)},Et=A("URLSearchParams"),gt=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function $(e,t,{allOwnKeys:r=!1}={}){if(e===null||typeof e>"u")return;let n,s;if(typeof e!="object"&&(e=[e]),D(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 Fe(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 De=(()=>typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global)(),Le=e=>!j(e)&&e!==De;function ee(){const{caseless:e}=Le(this)&&this||{},t={},r=(n,s)=>{const o=e&&Fe(t,s)||s;M(t[o])&&M(n)?t[o]=ee(t[o],n):M(n)?t[o]=ee({},n):D(n)?t[o]=n.slice():t[o]=n};for(let n=0,s=arguments.length;n<s;n++)arguments[n]&&$(arguments[n],r);return t}const bt=(e,t,r,{allOwnKeys:n}={})=>($(t,(s,o)=>{r&&C(s)?e[o]=Ce(s,r):e[o]=s},{allOwnKeys:n}),e),St=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Rt=(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)},At=(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},Ot=(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(D(e))return e;let t=e.length;if(!_e(t))return null;const r=new Array(t);for(;t-- >0;)r[t]=e[t];return r},Nt=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&se(Uint8Array)),Ct=(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])}},xt=(e,t)=>{let r;const n=[];for(;(r=e.exec(t))!==null;)n.push(r);return n},Pt=A("HTMLFormElement"),_t=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),Ft=A("RegExp"),Ue=(e,t)=>{const r=Object.getOwnPropertyDescriptors(e),n={};$(r,(s,o)=>{t(s,o,e)!==!1&&(n[o]=s)}),Object.defineProperties(e,n)},Dt=e=>{Ue(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+"'")})}})},Lt=(e,t)=>{const r={},n=s=>{s.forEach(o=>{r[o]=!0})};return D(e)?n(e):n(String(e).split(t)),r},Ut=()=>{},Bt=(e,t)=>(e=+e,Number.isFinite(e)?e:t),jt=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=D(n)?[]:{};return $(n,(i,c)=>{const f=r(i,s+1);!j(f)&&(o[c]=f)}),t[s]=void 0,o}}return n};return r(e,0)},a={isArray:D,isArrayBuffer:Pe,isBuffer:ct,isFormData:wt,isArrayBufferView:ut,isString:lt,isNumber:_e,isBoolean:ft,isObject:ie,isPlainObject:M,isUndefined:j,isDate:dt,isFile:ht,isBlob:pt,isRegExp:Ft,isFunction:C,isStream:yt,isURLSearchParams:Et,isTypedArray:Nt,isFileList:mt,forEach:$,merge:ee,extend:bt,trim:gt,stripBOM:St,inherits:Rt,toFlatObject:At,kindOf:oe,kindOfTest:A,endsWith:Ot,toArray:Tt,forEachEntry:Ct,matchAll:xt,isHTMLForm:Pt,hasOwnProperty:he,hasOwnProp:he,reduceDescriptors:Ue,freezeMethods:Dt,toObjectSet:Lt,toCamelCase:_t,noop:Ut,toFiniteNumber:Bt,findKey:Fe,global:De,isContextDefined:Le,toJSONObject:jt};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 Be=m.prototype,je={};["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=>{je[e]={value:e}});Object.defineProperties(m,je);Object.defineProperty(Be,"isAxiosError",{value:!0});m.from=(e,t,r,n,s,o)=>{const i=Object.create(Be);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 $t=typeof self=="object"?self.FormData:window.FormData;const kt=$t;function te(e){return a.isPlainObject(e)||a.isArray(e)}function $e(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=$e(s),!r&&o?"["+s+"]":s}).join(r?".":""):t}function qt(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(kt||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 g=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)&&qt(d)||a.isFileList(d)||a.endsWith(p,"[]")&&(g=a.toArray(d)))return p=$e(p),g.forEach(function(I,Ve){!(a.isUndefined(I)||I===null)&&t.append(i===!0?pe([p],Ve,o):i===null?p:p+"[]",u(I))}),!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(g,x){(!(a.isUndefined(g)||g===null)&&s.call(t,g,a.isString(x)?x.trim():x,p,y))===!0&&w(g,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 ke=ae.prototype;ke.append=function(t,r){this._pairs.push([t,r])};ke.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 Ht(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function qe(e,t,r){if(!t)return e;const n=r&&r.encode||Ht,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 Jt{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=Jt,Ie={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},zt=typeof URLSearchParams<"u"?URLSearchParams:ae,vt=FormData,Vt=(()=>{let e;return typeof navigator<"u"&&((e=navigator.product)==="ReactNative"||e==="NativeScript"||e==="NS")?!1:typeof window<"u"&&typeof document<"u"})(),Wt=(()=>typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function")(),b={isBrowser:!0,classes:{URLSearchParams:zt,FormData:vt,Blob},isStandardBrowserEnv:Vt,isStandardBrowserWebWorkerEnv:Wt,protocols:["http","https","file","blob","url","data"]};function Kt(e,t){return W(e,new b.classes.URLSearchParams,Object.assign({visitor:function(r,n,s,o){return b.isNode&&a.isBuffer(r)?(this.append(n,r.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)}},t))}function Gt(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(Gt(n),s,r,0)}),r}return null}const Xt={"Content-Type":void 0};function Zt(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 Kt(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),Zt(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:b.classes.FormData,Blob:b.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(Xt)});const ce=K,Yt=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"]),er=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]&&Yt[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 U(e){return e&&String(e).trim().toLowerCase()}function H(e){return e===!1||e==null?e:a.isArray(e)?e.map(H):String(e)}function tr(e){const t=Object.create(null),r=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let n;for(;n=r.exec(e);)t[n[1]]=n[2];return t}function rr(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 nr(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,r,n)=>r.toUpperCase()+n)}function sr(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=U(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]=H(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())&&!rr(t)?i(er(t),r):t!=null&&o(r,t,n),this}get(t,r){if(t=U(t),t){const n=a.findKey(this,t);if(n){const s=this[n];if(!r)return s;if(r===!0)return tr(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=U(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=U(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]=H(s),delete r[o];return}const c=t?nr(o):String(o).trim();c!==o&&delete r[o],r[c]=H(s),n[c]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const r=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=U(i);n[c]||(sr(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 Q(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 He(e){return!!(e&&e.__CANCEL__)}function k(e,t,r){m.call(this,e==null?"canceled":e,m.ERR_CANCELED,t,r),this.name="CanceledError"}a.inherits(k,m,{__CANCEL__:!0});const or=null;function ir(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 ar=b.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 cr(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function ur(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}function Je(e,t){return e&&!cr(t)?ur(e,t):t}const lr=b.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 fr(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function dr(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 ge(e,t){let r=0;const n=dr(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 hr=typeof XMLHttpRequest<"u",pr=hr&&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)&&(b.isStandardBrowserEnv||b.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=Je(e.baseURL,e.url);u.open(e.method.toUpperCase(),qe(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};ir(function(g){r(g),f()},function(g){n(g),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},b.isStandardBrowserEnv){const w=(e.withCredentials||lr(l))&&e.xsrfCookieName&&ar.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",ge(e.onDownloadProgress,!0)),typeof e.onUploadProgress=="function"&&u.upload&&u.upload.addEventListener("progress",ge(e.onUploadProgress)),(e.cancelToken||e.signal)&&(c=w=>{!u||(n(!w||w.type?new k(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=fr(l);if(y&&b.protocols.indexOf(y)===-1){n(new m("Unsupported protocol "+y+":",m.ERR_BAD_REQUEST,e));return}u.send(s||null)})},J={http:or,xhr:pr};a.forEach(J,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const mr={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)?J[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(J,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:J};function X(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new k(null,e)}function be(e){return X(e),e.headers=R.from(e.headers),e.data=Q.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),mr.getAdapter(e.adapter||ce.adapter)(e).then(function(n){return X(e),n.data=Q.call(e,e.transformResponse,n),n.headers=R.from(n.headers),n},function(n){return He(n)||(X(e),n&&n.response&&(n.response.data=Q.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 F(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 ze="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"+ze+"] 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 yr(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:yr,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=F(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=[be.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=be.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=F(this.defaults,t);const r=Je(t.baseURL,t.url);return qe(r,t.params,t.paramsSerializer)}}a.forEach(["delete","get","head","options"],function(t){v.prototype[t]=function(r,n){return this.request(F(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(F(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 z=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 k(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 wr=le;function Er(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 br=ne;function ve(e){const t=new z(e),r=Ce(z.prototype.request,t);return a.extend(r,z.prototype,t,{allOwnKeys:!0}),a.extend(r,t,null,{allOwnKeys:!0}),r.create=function(s){return ve(F(e,s))},r}const E=ve(ce);E.Axios=z;E.CanceledError=k;E.CancelToken=wr;E.isCancel=He;E.VERSION=ze;E.toFormData=W;E.AxiosError=m;E.Cancel=E.CanceledError;E.all=function(t){return Promise.all(t)};E.spread=Er;E.isAxiosError=gr;E.mergeConfig=F;E.AxiosHeaders=R;E.formToJSON=e=>Me(a.isHTMLForm(e)?new FormData(e):e);E.HttpStatusCode=br;E.default=E;const Sr=E,B=async e=>{var o,i,c,f,u;const t=Date.now(),{authorization:r,host:n}=N(),s=r?{authorization:r}:void 0;try{const{data:l}=await Sr.post(`${n}/graphql`,e,{headers:s}),h=Date.now();if((o=N().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 q{static async insert(t,r,n=["id"],s){const o=s==null?void 0:s.debug,i=L.toEngineName(N().engineCase,["insert",t]),c={query:`
mutation {
${i} ${r?`(objects: ${T(Array.isArray(r)?r:[r])} )`:""} {
${n.join(`
`)}
}
}
`};return o&&console.log(c),(await B(c)).data[i]}static async select(t,r={},n){const s=L.toEngineName(N().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: ${T(i)},`:""}
${u?`order_by: ${Qe(Xe(u))},`:""}
limit: $limit,
offset: $offset,
) {
${fe(c!=null?c:["id"])}
}
}
`,variables:{limit:f,offset:l}};o&&console.log(y);const d=(await B(y)).data[s];return h?h(d):d}static async selectAggregation(t,r,n){const s=L.toEngineName(N().engineCase,[t],{suffix:"aggregate"}),o=n==null?void 0:n.debug,{where:i,fields:c,transform:f}=r,u={query:`
query {
${s} ${i?`(where: ${T(i)})`:""} {
${fe(c)}
}
}
`};o&&console.log(u);const h=(await B(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 {
${L.toEngineName(N().engineCase,["delete",t])} ${o?`(where: ${T(o)})`:""}
}
`};s&&console.log(c),await B(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 {
${L.toEngineName(N().engineCase,["update",t])} (
${i?`where: ${T(i)},`:""}
object: ${n!=null&&n.replaceNull?T(Ge(r)):T(r)}
)
}
`};o&&console.log(f),await B(f)}}let Ae=null;try{Ae=EventSource||require("eventsource")}catch{Ae=require("eventsource")}const Oe={},Rr=()=>{if(!Oe)throw new Error("Querier was not initialized properly!");return Oe},Ar=e=>{We(e)},Or=(e,t,r,n)=>{const[s,o]=P.useState(),[i,c]=P.useState(!0),f=async()=>{c(!0);const u=await q.select(e,t,n);return o(u),c(!1),u};return P.useEffect(()=>{r!=null&&r.skip||f().catch(console.error)},[e,JSON.stringify(t),JSON.stringify(r),JSON.stringify(n)]),{data:s,loading:i,refetch:f}},Tr=(e,t,r,n)=>{const[s,o]=P.useState(),[i,c]=P.useState(!0),f=async()=>{if(r!=null&&r.skip)return;c(!0);const u=await q.selectAggregation(e,t,n);return o(u),c(!1),u};return P.useEffect(()=>{f().catch(console.error)},[e,JSON.stringify(t),JSON.stringify(r),JSON.stringify(n)]),{data:s,loading:i,refetch:f}},Nr=e=>async(r,n=["id"],s)=>await q.insert(e,r,n,s),Cr=e=>async(r,n)=>{await q.delete(e,r,n)},xr=e=>async(r,n,s)=>{await q.update(e,r,n,s)};exports.getOptions=Rr;exports.initQuerier=Ar;exports.useDelete=Cr;exports.useInsert=Nr;exports.useSelect=Or;exports.useSelectAggregation=Tr;exports.useUpdate=xr;
;