From 8717e3178a143f40ae83e1ff1368754eb87f0346 Mon Sep 17 00:00:00 2001 From: Joel Chu Date: Fri, 26 Jul 2019 12:15:58 +0800 Subject: [PATCH 1/5] Make fly as an external dependecies --- packages/http-client/package.json | 2 +- packages/http-client/src/lib/base/base-cls.js | 2 +- packages/http-client/src/lib/base/http-cls.js | 11 +---------- packages/web-console/package.json | 16 ++++++++-------- packages/web-console/src/plugin/client.js | 5 +++-- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/packages/http-client/package.json b/packages/http-client/package.json index e339498c..b1fb4d91 100755 --- a/packages/http-client/package.json +++ b/packages/http-client/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-client", - "version": "1.2.5", + "version": "1.2.6", "description": "jsonql browser client using Fly.js", "main": "index.js", "module": "src/index.js", diff --git a/packages/http-client/src/lib/base/base-cls.js b/packages/http-client/src/lib/base/base-cls.js index 8383c4c9..643fd103 100644 --- a/packages/http-client/src/lib/base/base-cls.js +++ b/packages/http-client/src/lib/base/base-cls.js @@ -14,7 +14,7 @@ export default class JsonqlBaseClient extends AuthCls { constructor(opts, Fly) { super(opts) if (Fly!==null) { - this.fly = new Fly(); + this.fly = new Fly() } } diff --git a/packages/http-client/src/lib/base/http-cls.js b/packages/http-client/src/lib/base/http-cls.js index fbe192d2..60c9d20c 100644 --- a/packages/http-client/src/lib/base/http-cls.js +++ b/packages/http-client/src/lib/base/http-cls.js @@ -1,7 +1,7 @@ // base HttpClass // import Fly from 'flyio/dist/npm/fly' import { merge } from 'lodash-es' -import Fly from 'flyio' + import { createQuery, createMutation, @@ -38,15 +38,6 @@ export default class HttpClass { // change the way how we init Fly // flyio now become external depedencies and it makes it easier to switch // to a different environment like WeChat mini app - try { - if (!this.fly) { - this.fly = new Fly() - } - } catch(e) { - console.error('Init fly error!', e) - throw e; - } - this.opts = opts; this.extraHeader = {}; // @1.2.1 for adding query to the call on the fly diff --git a/packages/web-console/package.json b/packages/web-console/package.json index 714b2d0d..03535356 100644 --- a/packages/web-console/package.json +++ b/packages/web-console/package.json @@ -10,19 +10,19 @@ "dev": "npm run jsonql & npm run serve" }, "dependencies": { - "core-js": "^2.6.5", - "jsonql-client": "^1.2.4", + "core-js": "^3.1.4", + "jsonql-client": "^1.2.5", "jsonql-ws-client": "^1.0.0-beta.1", "vue": "^2.6.10", "vuex": "^3.1.1" }, "devDependencies": { - "@vue/cli-plugin-babel": "^3.9.0", - "@vue/cli-plugin-eslint": "^3.9.0", - "@vue/cli-service": "^3.9.0", - "babel-eslint": "^10.0.1", - "eslint": "^5.16.0", - "eslint-plugin-vue": "^5.0.0", + "@vue/cli-plugin-babel": "^3.9.2", + "@vue/cli-plugin-eslint": "^3.9.2", + "@vue/cli-service": "^3.9.3", + "babel-eslint": "^10.0.2", + "eslint": "^6.1.0", + "eslint-plugin-vue": "^5.2.3", "jsonql-koa": "^1.3.4", "server-io-core": "^1.2.0-beta.2", "vue-template-compiler": "^2.6.10" diff --git a/packages/web-console/src/plugin/client.js b/packages/web-console/src/plugin/client.js index 8e41a28f..3eeedbad 100644 --- a/packages/web-console/src/plugin/client.js +++ b/packages/web-console/src/plugin/client.js @@ -1,5 +1,5 @@ -import Fly from 'flyio' // this is completely uselesss +import Fly from 'flyio' import jsonqlClient from 'jsonql-client' console.info('Fly', Fly) @@ -9,7 +9,8 @@ const createClient = async (contract, options) => await jsonqlClient( hostname: 'http://localhost:8081', keepContract: false, showContractDesc: true - }, options) + }, options), + Fly ) export default createClient -- Gitee From 5b4136efe7a9ff0e7ae9b76b8d2b049b88e6ef3c Mon Sep 17 00:00:00 2001 From: Joel Chu Date: Fri, 26 Jul 2019 13:49:09 +0800 Subject: [PATCH 2/5] build success --- packages/http-client/dist/full.js | 2 + packages/http-client/dist/full.js.map | 1 + .../http-client/dist/jsonql-client.umd.js | 2 +- .../http-client/dist/jsonql-client.umd.js.map | 2 +- packages/http-client/package.json | 2 +- packages/http-client/rollup.full.config.js | 66 +++++++++++++++++++ packages/http-client/src/full.js | 9 +++ packages/web-console/src/plugin/client.js | 6 +- 8 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 packages/http-client/dist/full.js create mode 100644 packages/http-client/dist/full.js.map create mode 100644 packages/http-client/rollup.full.config.js create mode 100644 packages/http-client/src/full.js diff --git a/packages/http-client/dist/full.js b/packages/http-client/dist/full.js new file mode 100644 index 00000000..b6d2c4ca --- /dev/null +++ b/packages/http-client/dist/full.js @@ -0,0 +1,2 @@ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).jsonqlClient=e()}(this,function(){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t,e){return t(e={exports:{}},e.exports),e.exports}var r,n=e(function(t,e){var r;r=function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(t,e,r){var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};t.exports={type:function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},isObject:function(t,e){return e?"object"===this.type(t):t&&"object"===(void 0===t?"undefined":n(t))},isFormData:function(t){return"undefined"!=typeof FormData&&t instanceof FormData},trim:function(t){return t.replace(/(^\s*)|(\s*$)/g,"")},encode:function(t){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")},formatParams:function(t){var e="",r=!0,n=this;if(!this.isObject(t))return t;return function t(o,i){var a=n.encode,u=n.type(o);if("array"==u)o.forEach(function(e,r){n.isObject(e)||(r=""),t(e,i+"%5B"+r+"%5D")});else if("object"==u)for(var c in o)t(o[c],i?i+"%5B"+a(c)+"%5D":a(c));else r||(e+="&"),r=!1,e+=i+"="+a(o)}(t,""),e},merge:function(t,e){for(var r in e)t.hasOwnProperty(r)?this.isObject(e[r],1)&&this.isObject(t[r],1)&&this.merge(t[r],e[r]):t[r]=e[r];return t}}},,function(t,e,r){var n=function(){function t(t,e){for(var r=0;r0&&(t+=(-1===t.indexOf("?")?"?":"&")+w.join("&")),a.open(r.method,t);try{a.withCredentials=!!r.withCredentials,a.timeout=r.timeout||0,"stream"!==y&&(a.responseType=y)}catch(t){}var j=r.headers[u]||r.headers[c],O="application/x-www-form-urlencoded";for(var S in o.trim((j||"").toLowerCase())===O?e=o.formatParams(e):o.isFormData(e)||-1===["object","array"].indexOf(o.type(e))||(O="application/json;charset=utf-8",e=JSON.stringify(e)),j||b||(r.headers[u]=O),r.headers)if(S===u&&o.isFormData(e))delete r.headers[S];else try{a.setRequestHeader(S,r.headers[S])}catch(t){}function k(t,e,n){v(l.p,function(){if(t){n&&(e.request=r);var o=t.call(l,e,Promise);e=void 0===o?e:o}d(e)||(e=Promise[0===n?"resolve":"reject"](e)),e.then(function(t){s(t)}).catch(function(t){h(t)})})}function E(t){t.engine=a,k(l.onerror,t,-1)}function A(t,e){this.message=t,this.status=e}a.onload=function(){try{var t=a.response||a.responseText;t&&r.parseJson&&-1!==(a.getResponseHeader(u)||"").indexOf("json")&&!o.isObject(t)&&(t=JSON.parse(t));var e=a.responseHeaders;if(!e){e={};var n=(a.getAllResponseHeaders()||"").split("\r\n");n.pop(),n.forEach(function(t){if(t){var r=t.split(":")[0];e[r]=a.getResponseHeader(r)}})}var i=a.status,c=a.statusText,s={data:t,headers:e,status:i,statusText:c};if(o.merge(s,a._response),i>=200&&i<300||304===i)s.engine=a,s.request=r,k(l.handler,s,0);else{var f=new A(c,i);f.response=s,E(f)}}catch(f){E(new A(f.msg,a.status))}},a.onerror=function(t){E(new A(t.msg||"Network Error",0))},a.ontimeout=function(){E(new A("timeout [ "+a.timeout+"ms ]",1))},a._options=r,setTimeout(function(){a.send(b?null:e)},0)}(n):s(n)},function(t){h(t)})})});return h.engine=a,h}},{key:"all",value:function(t){return Promise.all(t)}},{key:"spread",value:function(t){return function(e){return t.apply(null,e)}}}]),t}();a.default=a,["get","post","put","patch","head","delete"].forEach(function(t){a.prototype[t]=function(e,r,n){return this.request(e,r,o.merge({method:t},n))}}),["lock","unlock","clear"].forEach(function(t){a.prototype[t]=function(){this.interceptors.request[t]()}}),t.exports=a}])},t.exports=r()}),o=(r=n)&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,i=Object.assign?Object.assign:function(t,e,r,n){for(var o=arguments,i=1;i=0;e--){var r=A().key(e);t(x(r),r)}},remove:function(t){return A().removeItem(t)},clearAll:function(){return A().clear()}};function A(){return k.localStorage}function x(t){return A().getItem(t)}var T=s.trim,P={name:"cookieStorage",read:function(t){if(!t||!z(t))return null;var e="(?:^|.*;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(C.cookie.replace(new RegExp(e),"$1"))},write:function(t,e){if(!t)return;C.cookie=escape(t)+"="+escape(e)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"},each:q,remove:N,clearAll:function(){q(function(t,e){N(e)})}},C=s.Global.document;function q(t){for(var e=C.cookie.split(/; ?/g),r=e.length-1;r>=0;r--)if(T(e[r])){var n=e[r].split("="),o=unescape(n[0]);t(unescape(n[1]),o)}}function N(t){t&&z(t)&&(C.cookie=escape(t)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function z(t){return new RegExp("(?:^|;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(C.cookie)}var I=function(){var t={};return{defaults:function(e,r){t=r},get:function(e,r){var n=e();return void 0!==n?n:t[r]}}};var $="expire_mixin",F=function(){var t=this.createStore(this.storage,null,this._namespacePrefix+$);return{set:function(e,r,n,o){this.hasNamespace($)||t.set(r,o);return e()},get:function(t,r){this.hasNamespace($)||e.call(this,r);return t()},remove:function(e,r){this.hasNamespace($)||t.remove(r);return e()},getExpiration:function(e,r){return t.get(r)},removeExpiredKeys:function(t){var r=[];this.each(function(t,e){r.push(e)});for(var n=0;n>>8,r[2*n+1]=a%256}return r},decompressFromUint8Array:function(e){if(null==e)return i.decompress(e);for(var r=new Array(e.length/2),n=0,o=r.length;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=a[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++),a[s]=p++,f=String(c)}if(""!==f){if(Object.prototype.hasOwnProperty.call(u,f)){if(f.charCodeAt(0)<256){for(n=0;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=a[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++)}for(o=2,n=0;n>=1;for(;;){if(v<<=1,g==e-1){d.push(r(v));break}g++}return d.join("")},decompress:function(t){return null==t?"":""==t?null:i._decompress(t.length,32768,function(e){return t.charCodeAt(e)})},_decompress:function(e,r,n){var o,i,a,u,c,s,f,l=[],p=4,h=4,d=3,v="",g=[],y={val:n(0),position:r,index:1};for(o=0;o<3;o+=1)l[o]=o;for(a=0,c=Math.pow(2,2),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;switch(a){case 0:for(a=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;f=t(a);break;case 1:for(a=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;f=t(a);break;case 2:return""}for(l[3]=f,i=f,g.push(f);;){if(y.index>e)return"";for(a=0,c=Math.pow(2,d),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;switch(f=a){case 0:for(a=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;l[h++]=t(a),f=h-1,p--;break;case 1:for(a=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;l[h++]=t(a),f=h-1,p--;break;case 2:return g.join("")}if(0==p&&(p=Math.pow(2,d),d++),l[f])v=l[f];else{if(f!==h)return null;v=i+i.charAt(0)}g.push(v),l[h++]=i+v.charAt(0),i=v,0==--p&&(p=Math.pow(2,d),d++)}}};return i}();null!=t&&(t.exports=e)});var B=[E,P],K=[I,F,D,function(){return{get:function(t,e){var r=t(e);if(!r)return r;var n=L.decompress(r);return null==n?r:this._deserialize(n)},set:function(t,e,r){var n=L.compress(this._serialize(r));t(e,n)}}}],W=j.createStore(B,K),G=s.Global;function V(){return G.sessionStorage}function Y(t){return V().getItem(t)}var X=[{name:"sessionStorage",read:Y,write:function(t,e){return V().setItem(t,e)},each:function(t){for(var e=V().length-1;e>=0;e--){var r=V().key(e);t(Y(r),r)}},remove:function(t){return V().removeItem(t)},clearAll:function(){return V().clear()}},P],Q=[I,F],Z=j.createStore(X,Q),tt=W,et=Z,rt="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},nt="object"==typeof rt&&rt&&rt.Object===Object&&rt,ot="object"==typeof self&&self&&self.Object===Object&&self,it=nt||ot||Function("return this")(),at=it.Symbol,ut=Object.prototype,ct=ut.hasOwnProperty,st=ut.toString,ft=at?at.toStringTag:void 0;var lt=Object.prototype.toString;var pt="[object Null]",ht="[object Undefined]",dt=at?at.toStringTag:void 0;function vt(t){return null==t?void 0===t?ht:pt:dt&&dt in Object(t)?function(t){var e=ct.call(t,ft),r=t[ft];try{t[ft]=void 0;var n=!0}catch(t){}var o=st.call(t);return n&&(e?t[ft]=r:delete t[ft]),o}(t):function(t){return lt.call(t)}(t)}function gt(t){return null!=t&&"object"==typeof t}var yt="[object Symbol]";function bt(t){return"symbol"==typeof t||gt(t)&&vt(t)==yt}function mt(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r0){if(++Zt>=Vt)return arguments[0]}else Zt=0;return Qt.apply(void 0,arguments)});function ne(t){return t!=t}function oe(t,e,r){return e==e?function(t,e,r){for(var n=r-1,o=t.length;++n-1&&t%1==0&&t-1&&t%1==0&&t<=de}function ge(t){return null!=t&&ve(t.length)&&!Ct(t)}var ye=Object.prototype;function be(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||ye)}var me="[object Arguments]";function _e(t){return gt(t)&&vt(t)==me}var we=Object.prototype,je=we.hasOwnProperty,Oe=we.propertyIsEnumerable,Se=_e(function(){return arguments}())?_e:function(t){return gt(t)&&je.call(t,"callee")&&!Oe.call(t,"callee")};var ke="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ee=ke&&"object"==typeof module&&module&&!module.nodeType&&module,Ae=Ee&&Ee.exports===ke?it.Buffer:void 0,xe=(Ae?Ae.isBuffer:void 0)||function(){return!1},Te={};Te["[object Float32Array]"]=Te["[object Float64Array]"]=Te["[object Int8Array]"]=Te["[object Int16Array]"]=Te["[object Int32Array]"]=Te["[object Uint8Array]"]=Te["[object Uint8ClampedArray]"]=Te["[object Uint16Array]"]=Te["[object Uint32Array]"]=!0,Te["[object Arguments]"]=Te["[object Array]"]=Te["[object ArrayBuffer]"]=Te["[object Boolean]"]=Te["[object DataView]"]=Te["[object Date]"]=Te["[object Error]"]=Te["[object Function]"]=Te["[object Map]"]=Te["[object Number]"]=Te["[object Object]"]=Te["[object RegExp]"]=Te["[object Set]"]=Te["[object String]"]=Te["[object WeakMap]"]=!1;var Pe="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ce=Pe&&"object"==typeof module&&module&&!module.nodeType&&module,qe=Ce&&Ce.exports===Pe&&nt.process,Ne=function(){try{var t=Ce&&Ce.require&&Ce.require("util").types;return t||qe&&qe.binding&&qe.binding("util")}catch(t){}}(),ze=Ne&&Ne.isTypedArray,Ie=ze?function(t){return function(e){return t(e)}}(ze):function(t){return gt(t)&&ve(t.length)&&!!Te[vt(t)]},$e=Object.prototype.hasOwnProperty;function Fe(t,e){var r=_t(t),n=!r&&Se(t),o=!r&&!n&&xe(t),i=!r&&!n&&!o&&Ie(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r-1},rr.prototype.set=function(t,e){var r=this.__data__,n=tr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var nr=Lt(it,"Map");function or(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function ir(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e=n?t:function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++nu))return!1;var s=i.get(t);if(s&&i.get(e))return s==e;var f=-1,l=!0,p=r&vn?new pn:void 0;for(i.set(t,e),i.set(e,t);++f1?e[n-1]:void 0,i=n>2?e[2]:void 0;for(o=yo.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!kt(r))return!1;var n=typeof e;return!!("number"==n?ge(r)&&ue(e,r.length):"string"==n&&e in r)&&se(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r-1;);return r}(n,o),function(t,e){for(var r=t.length;r--&&oe(e,t[r],0)>-1;);return r}(n,o)+1).join("")}function ko(t){return!!_t(t)||null!=t&&""!==So(t)}var Eo=function(t){return!fo(t)&&!ho(parseFloat(t))},Ao=function(t){return""!==So(t)&&fo(t)},xo=function(t){return function(t){return!0===t||!1===t||gt(t)&&vt(t)==lo}(t)},To=function(t,e){return void 0===e&&(e=!0),!vo(t)&&""!==t&&""!==So(t)&&(!1===e||!0===e&&!function(t){return null===t}(t))},Po="application/vnd.api+json",Co={Accept:Po,"Content-Type":[Po,"charset=utf-8"].join(";")},qo="payload",No="condition",zo="args",Io=["POST","PUT"],$o="type",Fo="optional",Jo="enumv",Ro="args",Mo="checker",Uo="alias",Do={desc:"y"},Ho="No message",Lo=$o,Bo=Fo,Ko=Jo,Wo=Ro,Go=Mo,Vo=Uo,Yo="continue",Xo=function(t){switch(t){case"number":return Eo;case"string":return Ao;case"boolean":return xo;default:return To}},Qo=function(t,e){return void 0===e&&(e=""),!!_t(t)&&(""===e||""===So(e)||!(t.filter(function(t){return!Xo(e)(t)}).length>0))},Zo=function(t){if(t.indexOf("array.<")>-1&&t.indexOf(">")>-1){var e=t.replace("array.<","").replace(">","");return e.indexOf("|")?e.split("|"):[e]}return!1},ti=function(t,e){var r=t.arg;return e.length>1?!r.filter(function(t){return!(e.length>e.filter(function(e){return!Xo(e)(t)}).length)}).length:e.length>e.filter(function(t){return!Qo(r,t)}).length},ei=function(t,e){if(void 0===e&&(e=null),kr(t)){if(!e)return!0;if(Qo(e))return!e.filter(function(e){var r=t[e.name];return!(e.type.length>e.type.filter(function(t){var e;return!!vo(r)||(!1!==(e=Zo(t))?!ti({arg:r},e):!Xo(t)(r))}).length)}).length}return!1},ri=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 406},r.name.get=function(){return"Jsonql406Error"},Object.defineProperties(e,r),e}(Error),ni=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"Jsonql500Error"},Object.defineProperties(e,r),e}(Error),oi=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(e,r),e}(Error),ii=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(e,r),e}(Error),ai=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(e,r),e}(Error),ui=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 404},r.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(e,r),e}(Error),ci=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(e,r),e}(Error),si=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(e,r),e}(Error),fi=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(e,r),e}(Error),li=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(e,r),e}(Error),pi=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0},statusCode:{configurable:!0}};return r.name.get=function(){return"JsonqlError"},r.statusCode.get=function(){return-1},Object.defineProperties(e,r),e}(Error),hi=function(t){function e(r,n){t.call(this,n),this.statusCode=r,this.className=e.name}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlServerError"},Object.defineProperties(e,r),e}(Error),di=Object.freeze({Jsonql406Error:ri,Jsonql500Error:ni,JsonqlAuthorisationError:oi,JsonqlContractAuthError:ii,JsonqlResolverAppError:ai,JsonqlResolverNotFoundError:ui,JsonqlEnumError:ci,JsonqlTypeError:si,JsonqlCheckerError:fi,JsonqlValidationError:li,JsonqlError:pi,JsonqlServerError:hi}),vi=pi,gi=function(t,e){return!!Object.keys(t).filter(function(t){return e===t}).length};function yi(t){if(gi(t,"error")){var e=t.error,r=e.className,n=e.name,o=r||n,i=e.message||Ho,a=e.detail||e;if(o&&di[o])throw new di[r](i,a);throw new vi(i,a)}return t}function bi(t){if(Array.isArray(t))throw new li("",t);var e=t.message||Ho,r=t.detail||t;switch(!0){case t instanceof ri:throw new ri(e,r);case t instanceof ni:throw new ni(e,r);case t instanceof oi:throw new oi(e,r);case t instanceof ii:throw new ii(e,r);case t instanceof ai:throw new ai(e,r);case t instanceof ui:throw new ui(e,r);case t instanceof ci:throw new ci(e,r);case t instanceof si:throw new si(e,r);case t instanceof fi:throw new fi(e,r);case t instanceof li:throw new li(e,r);case t instanceof hi:throw new hi(e,r);default:throw new pi(e,r)}}var mi=function(t,e){var r,n,o,i,a;switch(!0){case"object"===t:return o=(n=e).arg,i=n.param,a=[o],Array.isArray(i.keys)&&i.keys.length&&a.push(i.keys),!ei.apply(null,a);case"array"===t:return!Qo(e.arg);case!1!==(r=Zo(t)):return!ti(e,r);default:return!Xo(t)(e.arg)}},_i=function(t,e){return vo(t)?!0!==e.optional||vo(e.defaultvalue)?null:e.defaultvalue:t},wi=function(t,e,r){var n;void 0===r&&(r=!1);var o=function(t,e){if(!Qo(e))throw new pi("params is not an array! Did something gone wrong when you generate the contract.json?");if(0===e.length)return[];if(!Qo(t))throw new pi("args is not an array! You might want to do: ES6 Array.from(arguments) or ES5 Array.prototype.slice.call(arguments)");switch(!0){case t.length==e.length:return t.map(function(t,r){return{arg:t,index:r,param:e[r]}});case!0===e[0].variable:var r=e[0].type;return t.map(function(t,n){return{arg:t,index:n,param:e[n]||{type:r,name:"_"}}});case t.lengthe.length&&1===e.length:var n,o=["any"];return!1!==(n=Zo(e[0].type[0]))&&(o=n),t.map(function(t,r){return{arg:t,index:r,param:e[r]||{type:o,name:"_"}}});default:throw new pi("Could not understand your arguments and parameter structure!",{args:t,params:e})}}(t,e),i=o.filter(function(t){return!0===t.param.optional?function(t){var e=t.arg,r=t.param;return!(!ko(e)||r.type.length>r.type.filter(function(e){return mi(e,t)}).length)}(t):!(t.param.type.length>t.param.type.filter(function(e){return mi(e,t)}).length)});return r?((n={}).error=i,n.data=o.map(function(t){return t.arg}),n):i},ji=function(t,e){return!!t.filter(function(t){return t===e}).length},Oi=function(t,e){var r=Object.keys(t);return ji(r,e)},Si=function(t){return!ko(t)};function ki(t,e){var r=jo(e,function(t,e){return!t[Vo]});return Dn(r,{})?t:function(t,e){var r={};return e=to(e),no(t,function(t,n,o){ce(r,e(t,n,o),t)}),r}(t,function(t,e){return function(t,e,r){var n;return r(t,function(t,r,o){if(e(t,r,o))return n=r,!1}),n}(r,to(function(t){return t.alias===e}),no)||e})}function Ei(t,e){return go(e,function(e,r){var n,o;return vo(t[r])||!0===e[Bo]&&Si(t[r])?bo({},e,((n={})[Yo]=!0,n)):((o={})[Wo]=t[r],o[Lo]=e[Lo],o[Bo]=e[Bo]||!1,o[Ko]=e[Ko]||!1,o[Go]=e[Go]||!1,o)})}function Ai(t,e){var r=function(t,e){var r=ki(t,e);return{pristineValues:go(jo(e,function(t,e){return Oi(r,e)}),function(t){return t.args}),checkAgainstAppProps:jo(e,function(t,e){return!Oi(r,e)}),config:r}}(t,e),n=r.config,o=r.pristineValues;return[Ei(n,r.checkAgainstAppProps),o]}var xi=function(t){return Qo(t)?t:[t]};var Ti=function(t,e){return!Qo(e)||function(t,e){return!!t.filter(function(t){return t===e}).length}(e,t)},Pi=function(t,e){try{return!!Ct(e)&&e.apply(null,[t])}catch(t){return!1}};function Ci(t){return function(e,r){if(e[Yo])return e[Wo];var n=function(t,e){var r,n=[[t[Wo]],[(r={},r[Lo]=xi(t[Lo]),r[Bo]=t[Bo],r)]];return Reflect.apply(e,null,n)}(e,t);if(n.length)throw new si(r,n);if(!1!==e[Ko]&&!Ti(e[Wo],e[Ko]))throw new ci(r);if(!1!==e[Go]&&!Pi(e[Wo],e[Go]))throw new fi(r);return e[Wo]}}var qi=function(t,e){return Promise.resolve(Ai(t,e))};function Ni(t,e,r,n){return void 0===t&&(t={}),qi(t,e).then(function(t){return function(t,e){var r=t[0],n=t[1],o=go(r,Ci(e));return bo(o,n)}(t,n)}).then(function(t){return bo({},t,r)})}var zi=ei,Ii=Ao,$i=Qo,Fi=function(t,e,r){return void 0===r&&(r=!1),new Promise(function(n,o){var i=wi(t,e,r);return r?i.error.length?o(i.error):n(i.data):i.length?o(i):n([])})},Ji=function(t,e,r){void 0===r&&(r={});var n=r[Fo],o=r[Jo],i=r[Mo],a=r[Uo];return function(t,e,r,n,o,i){void 0===r&&(r=!1),void 0===n&&(n=!1),void 0===o&&(o=!1),void 0===i&&(i=!1);var a={};return a[Ro]=t,a[$o]=e,!0===r&&(a[Fo]=!0),Qo(n)&&(a[Jo]=n),Ct(o)&&(a[Mo]=o),fo(i)&&(a[Uo]=i),a}.apply(null,[t,e,n,o,i,a])},Ri=function(t){return function(e,r,n){return void 0===n&&(n={}),Ni(e,r,n,t)}}(wi),Mi=ji,Ui=Oi,Di=function(t,e,r){var n;if(void 0===e&&(e=[]),void 0===r&&(r=!1),Ao(t)&&Qo(e)){var o={};return o[zo]=e,!0===r?o:((n={})[t]=o,n)}throw new li("[createQuery] expect resolverName to be string and args to be array!",{resolverName:t,args:e})},Hi=function(t,e,r,n){var o;void 0===r&&(r={}),void 0===n&&(n=!1);var i={};if(i[qo]=e,i[No]=r,!0===n)return i;if(Ao(t))return(o={})[t]=i,o;throw new li("[createMutation] expect resolverName to be string!",{resolverName:t,payload:e,condition:r})},Li=function(t){return Object.keys(t)[0]},Bi=function(){return Math.floor(Date.now()/1e3)},Ki=function(t,e){return void 0===e&&(e={}),Gi(e)?Promise.resolve(e):t.getContract()},Wi=function(t){return Ui(t,"data")&&!Ui(t,"error")?t.data:t},Gi=function(t){return t&&zi(t)&&(Ui(t,"query")||Ui(t,"mutation"))},Vi="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function Yi(t){this.message=t}Yi.prototype=new Error,Yi.prototype.name="InvalidCharacterError";var Xi="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new Yi("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,n,o=0,i=0,a="";n=e.charAt(i++);~n&&(r=o%4?64*r+n:n,o++%4)?a+=String.fromCharCode(255&r>>(-2*o&6)):0)n=Vi.indexOf(n);return a};var Qi=function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(Xi(t).replace(/(.)/g,function(t,e){var r=e.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}(e)}catch(t){return Xi(e)}};function Zi(t){this.message=t}Zi.prototype=new Error,Zi.prototype.name="InvalidTokenError";var ta,ea,ra,na,oa,ia,aa,ua,ca,sa=function(t,e){if("string"!=typeof t)throw new Zi("Invalid token specified");var r=!0===(e=e||{}).header?0:1;try{return JSON.parse(Qi(t.split(".")[r]))}catch(t){throw new Zi("Invalid token specified: "+t.message)}},fa=Zi;function la(t){if(Ii(t))return function(t){var e=t.iat||Math.floor(Date.now()/1e3);if(t.exp&&e>=t.exp){var r=new Date(t.exp).toISOString();throw new pi("Token has expired on "+r,t)}return t}(sa(t));throw new pi("Token must be a string!")}sa.InvalidTokenError=fa;Ji("HS256",["string"]),Ji(!1,["boolean","number","string"],((ta={})[Uo]="exp",ta[Fo]=!0,ta)),Ji(!1,["boolean","number","string"],((ea={})[Uo]="nbf",ea[Fo]=!0,ea)),Ji(!1,["boolean","string"],((ra={})[Uo]="iss",ra[Fo]=!0,ra)),Ji(!1,["boolean","string"],((na={})[Uo]="sub",na[Fo]=!0,na)),Ji(!1,["boolean","string"],((oa={})[Uo]="iss",oa[Fo]=!0,oa)),Ji(!1,["boolean"],((ia={})[Fo]=!0,ia)),Ji(!1,["boolean","string"],((aa={})[Fo]=!0,aa)),Ji(!1,["boolean","string"],((ua={})[Fo]=!0,ua)),Ji(!1,["boolean"],((ca={})[Fo]=!0,ca));!function(){switch(!0){case"undefined"!=typeof WebSocket:return WebSocket;case"undefined"!=typeof MozWebSocket:return MozWebSocket;case"undefined"!=typeof window:return window.WebSocket||window.MozWebSocket;default:throw new li("WebSocket is NOT SUPPORTED!")}}();var pa=Io[0],ha=Io[1],da=function(t){this.opts=t,this.extraHeader={},this.extraParams={},this.reqInterceptor(),this.resInterceptor()},va={headers:{configurable:!0}};va.headers.set=function(t){this.extraHeader=t},da.prototype.request=function(t,e,r){var n;void 0===e&&(e={}),void 0===r&&(r={}),this.headers=r;var o=bo({},{_cb:Bi()},this.extraParams);if(this.opts.enableJsonp){var i=Li(t);o=bo({},o,((n={}).jsonqlJsonpCallback=i,n)),t=t[i]}return this.fly.request(this.jsonqlEndpoint,t,bo({},{method:pa,params:o},e))},da.prototype.reqInterceptor=function(){var t=this;this.fly.interceptors.request.use(function(e){console.info("request interceptor call");var r=t.getHeaders();for(var n in r)e.headers[n]=r[n];return e})},da.prototype.processJsonp=function(t){return Wi(t)},da.prototype.resInterceptor=function(){var t=this,e=t.opts.enableJsonp;this.fly.interceptors.response.use(function(r){console.info("response interceptor call"),t.cleanUp();var n=Ii(r.data)?JSON.parse(r.data):r.data;return e?t.processJsonp(n):Wi(n)},function(e){throw t.cleanUp(),console.error(e),new hi("Server side error",e)})},da.prototype.getHeaders=function(){return this.opts.enableAuth?bo({},Co,this.getAuthHeader(),this.extraHeader):bo({},Co,this.extraHeader)},da.prototype.cleanUp=function(){this.extraHeader={},this.extraParams={}},da.prototype.get=function(){return this.opts.showContractDesc&&(this.extraParams=bo({},this.extraParams,Do)),this.request({},{method:"GET"},this.contractHeader).then(yi).then(function(t){return console.info("144 get contract result",t),t.cache&&t.contract?t.contract:t})},da.prototype.query=function(t,e){return void 0===e&&(e=[]),this.request(Di(t,e)).then(yi)},da.prototype.mutation=function(t,e,r){return void 0===e&&(e={}),void 0===r&&(r={}),this.request(Hi(t,e,r),{method:ha}).then(yi)},Object.defineProperties(da.prototype,va);var ga=function(t){function e(e,r){t.call(this,e),null!==r&&(this.fly=new r)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={storeIt:{configurable:!0},jsonqlEndpoint:{configurable:!0},jsonqlContract:{configurable:!0},jsonqlToken:{configurable:!0},jsonqlUserdata:{configurable:!0}};return r.storeIt.set=function(t){throw console.info("storeIt",t),$i(t)&&t.length>=2&&Reflect.apply(tt.set,tt,t),new li("Expect argument to be array and least 2 items!")},r.jsonqlEndpoint.set=function(t){var e=tt.get("endpoint")||[];Mi(e,t)||(e.push(t),this.storeId=["endpoint",e],this.endpointIndex=e.length-1)},r.jsonqlContract.set=function(t){var e=this.opts.storageKey,r=[e],n=t[0],o=t[1],i=tt.get(e)||[];i[this.endpointIndex||0]=n,r.push(i),o&&r.push(o),this.opts.keepContract&&(this.storeIt=r)},r.jsonqlToken.set=function(t){var e="credential",r=localStorage.get(e)||[];if(!Mi(r,t)){var n=r.length-1;r[n]=t,this[e+"Index"]=n;var o=[e,r];if(this.opts.tokenExpired){var i=parseFloat(this.opts.tokenExpired);if(!isNaN(i)&&i>0){var a=Bi();o.push(a+parseFloat(i))}}return this.storeIt=o,this.jsonqlUserdata=this.decoder(t),t}return!1},r.jsonqlUserdata.set=function(t){var e=["userdata",t];return t.exp&&e.push(t.exp),Reflect.apply(tt.set,tt,e)},r.jsonqlEndpoint.get=function(){var t=tt.get("endpoint");if(!t){var e=this.opts,r=[e.hostname,e.jsonqlPath].join("/");return this.jsonqlEndpoint=r,r}return t[this.endpointIndex]},r.jsonqlContract.get=function(){var t=this.opts.storageKey;return(tt.get(t)||[])[this.endpointIndex]||!1},r.jsonqlToken.get=function(){var t="credential",e=localStorage.get(t);return!!e&&e[this[t+"Index"]]},r.jsonqlUserdata.get=function(){return et.get("userdata")},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),e.enableAuth&&e.useJwt&&(this.setDecoder=la)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={userdata:{configurable:!0},rawAuthToken:{configurable:!0},setDecoder:{configurable:!0}};return r.userdata.get=function(){return this.jsonqlUserdata},r.rawAuthToken.get=function(){return this.jsonqlToken},r.setDecoder.set=function(t){"function"==typeof t&&(this.decoder=t)},e.prototype.storeToken=function(t){return this.jsonqlToken=t},e.prototype.decoder=function(t){return t},e.prototype.getAuthHeader=function(){var t,e=this.rawAuthToken;return e?((t={})[this.opts.AUTH_HEADER]="Bearer "+e,t):{}},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={contractHeader:{configurable:!0}};return e.prototype.getContract=function(){var t=this.readContract();if(console.info("getContract first call",t),t&&Array.isArray(t)){var e=t[this.endpointIndex||0];if(e)return Promise.resolve(e)}return this.get().then(this.storeContract.bind(this))},r.contractHeader.get=function(){var t={};return!1!==this.opts.contractKey&&(t[this.opts.contractKeyName]=this.opts.contractKey),t},e.prototype.storeContract=function(t){if(!Gi(t))throw new li("Contract is malformed!");var e=[t];if(this.opts.contractExpired){var r=parseFloat(this.opts.contractExpired);!isNaN(r)&&r>0&&e.push(r)}return this.jsonqlContract=e,console.info("storeContract return result",t),t},e.prototype.readContract=function(){return Gi(this.opts.contract)?this.opts.contract:tt.get(this.opts.storageKey)},Object.defineProperties(e.prototype,r),e}(da))),ya=new WeakMap,ba=new WeakMap;var ma=function(t){void 0===t&&(t={}),t.logger&&"function"==typeof t.logger&&(this.logger=t.logger),this.keep=t.keep,this.result=t.keep?[]:null,this.normalStore=new Map,this.lazyStore=new Map},_a={$done:{configurable:!0},normalStore:{configurable:!0},lazyStore:{configurable:!0}};ma.prototype.logger=function(){},ma.prototype.$on=function(t,e,r){var n=this;void 0===r&&(r=null);this.validate(t,e);var o=this.takeFromStore(t);if(!1===o)return this.logger("$on",t+" callback is not in lazy store"),this.addToNormalStore(t,"on",e,r);this.logger("$on",t+" found in lazy store");var i=0;return o.forEach(function(o){var a=o[0],u=o[1],c=o[2];if(c&&"on"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);n.run(e,a,r||u),i+=n.addToNormalStore(t,"on",e,r||u)}),i},ma.prototype.$once=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=this.takeFromStore(t);this.normalStore;if(!1===n)return this.logger("$once",t+" not in the lazy store"),this.addToNormalStore(t,"once",e,r);this.logger("$once",n);var o=Array.from(n)[0],i=o[0],a=o[1],u=o[2];if(u&&"once"!==u)throw new Error("You are trying to register an event already been taken by other type: "+u);this.run(e,i,r||a),this.$off(t)},ma.prototype.$only=function(t,e,r){var n=this;void 0===r&&(r=null),this.validate(t,e);var o=!1,i=this.takeFromStore(t);(this.normalStore.has(t)||(this.logger("$only",t+" add to store"),o=this.addToNormalStore(t,"only",e,r)),!1!==i)&&(this.logger("$only",t+" found data in lazy store to execute"),Array.from(i).forEach(function(t){var o=t[0],i=t[1],a=t[2];if(a&&"only"!==a)throw new Error("You are trying to register an event already been taken by other type: "+a);n.run(e,o,r||i)}));return o},ma.prototype.$onlyOnce=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=!1,o=this.takeFromStore(t);if(this.normalStore.has(t)||(this.logger("$onlyOnce",t+" add to store"),n=this.addToNormalStore(t,"onlyOnce",e,r)),!1!==o){this.logger("$onlyOnce",o);var i=Array.from(o)[0],a=i[0],u=i[1],c=i[2];if(c&&"onlyOnce"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);this.run(e,a,r||u),this.$off(t)}return n},ma.prototype.$replace=function(t,e,r,n){if(void 0===r&&(r=null),void 0===n&&(n="on"),this.validateType(n)){this.$off(t);var o=this["$"+n];return Reflect.apply(o,this,[t,e,r])}throw new Error(n+" is not supported!")},ma.prototype.$trigger=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1),this.validateEvt(t);var o=0,i=this.normalStore;if(this.logger("$trigger",i),i.has(t)){this.logger("$trigger",t,"found");for(var a=Array.from(i.get(t)),u=a.length,c=!1,s=0;s0;)n[o]=arguments[o+2];if(t.has(e)?(this.logger("addToStore",e+" existed"),r=t.get(e)):(this.logger("addToStore","create new Set for "+e),r=new Set),n.length>2)if(Array.isArray(n[0])){var i=n[2];this.checkTypeInLazyStore(e,i)||r.add(n)}else this.checkContentExist(n,r)||(this.logger("addToStore","insert new",n),r.add(n));else r.add(n);return t.set(e,r),[t,r.size]},ma.prototype.checkContentExist=function(t,e){return!!Array.from(e).filter(function(e){return e[0]===t[0]}).length},ma.prototype.checkTypeInStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.$get(t,!0);return!1===r||!r.filter(function(t){var r=t[3];return e!==r}).length},ma.prototype.checkTypeInLazyStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.lazyStore.get(t);return this.logger("checkTypeInLazyStore",r),!!r&&!!Array.from(r).filter(function(t){return t[2]!==e}).length},ma.prototype.addToNormalStore=function(t,e,r,n){if(void 0===n&&(n=null),this.logger("addToNormalStore",t,e,"add to normal store"),this.checkTypeInStore(t,e)){this.logger(e+" can add to "+t+" store");var o=this.hashFnToKey(r),i=[this.normalStore,t,o,r,n,e],a=Reflect.apply(this.addToStore,this,i),u=a[0],c=a[1];return this.normalStore=u,c}return!1},ma.prototype.addToLazyStore=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1);var o=[this.lazyStore,t,this.toArray(e),r];n&&o.push(n);var i=Reflect.apply(this.addToStore,this,o),a=i[0],u=i[1];return this.lazyStore=a,u},ma.prototype.toArray=function(t){return Array.isArray(t)?t:[t]},_a.normalStore.set=function(t){ya.set(this,t)},_a.normalStore.get=function(){return ya.get(this)},_a.lazyStore.set=function(t){ba.set(this,t)},_a.lazyStore.get=function(){return ba.get(this)},ma.prototype.hashFnToKey=function(t){return t.toString().split("").reduce(function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t},0)+""},Object.defineProperties(ma.prototype,_a);var wa=new ma,ja=function(t,e,r,n){return function(){for(var r=[],o=arguments.length;o--;)r[o]=arguments[o];var i=n.auth[e].params,a=i.map(function(t,e){return r[e]}),u=r[i.length]||{};return Fi(r,i).then(function(){return t.query.apply(t,[e,a,u])}).catch(bi)}},Oa=function(t,e,r){var n={query:{},mutation:{},auth:{}},o=function(e){n.query[e]=function(){for(var n=[],o=arguments.length;o--;)n[o]=arguments[o];var i=r.query[e].params,a=i.map(function(t,e){return n[e]}),u=n[i.length]||{};return Fi(a,i).then(function(){return t.query.apply(t,[e,a,u])}).catch(bi)}};for(var i in r.query)o(i);var a=function(e){n.mutation[e]=function(n,o,i){void 0===i&&(i={});var a=[n,o],u=r.mutation[e].params;return Fi(a,u).then(function(){return t.mutation.apply(t,[e,n,o,i])}).catch(bi)}};for(var u in r.mutation)a(u);if(e.enableAuth&&r.auth){var c=e.loginHandlerName,s=e.logoutHandlerName;r.auth[c]&&(n[c]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=ja(t,c,0,r);return o.apply(null,e).then(t.postLoginAction).then(function(t){return wa.$trigger("login",t),t})}),r.auth[s]?n[s]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=ja(t,s,0,r);return o.apply(null,e).then(t.postLogoutAction).then(function(t){return wa.$trigger("logout",t),t})}:n[s]=function(){t.postLogoutAction("continue"),wa.$trigger("logout","continue")},n.userdata=function(){return t.userdata}}return n.returnInstance&&(n.jsonqlClientInstance=t),n.getToken=function(){return t.rawAuthToken},n.eventEmitter=wa,n},Sa={contract:!1,MUTATION_ARGS:["name","payload","conditions"],CONTENT_TYPE:Po,BEARER:"Bearer",AUTH_HEADER:"Authorization"},ka={hostname:Ji([window.location.protocol,window.location.host].join("//"),["string"]),jsonqlPath:Ji("jsonql",["string"]),loginHandlerName:Ji("login",["string"]),logoutHandlerName:Ji("logout",["string"]),enableJsonp:Ji(!1,["boolean"]),enableAuth:Ji(!1,["boolean"]),useJwt:Ji(!0,["boolean"]),useLocalstorage:Ji(!0,["boolean"]),storageKey:Ji("storageKey",["string"]),authKey:Ji("authKey",["string"]),contractExpired:Ji(0,["number"]),keepContract:Ji(!0,["boolean"]),showContractDesc:Ji(!1,["boolean"]),contractKey:Ji(!1,["boolean"]),contractKeyName:Ji("X-JSONQL-CV-KEY",["string"]),enableTimeout:Ji(!1,["boolean"]),timeout:Ji(5e3,["number"]),returnInstance:Ji(!1,["boolean"]),allowReturnRawToken:Ji(!1,["boolean"]),debugOn:Ji(!1,["boolean"])};function Ea(t,e){return void 0===t&&(t={}),void 0===e&&(e=null),function(t){var e=t.contract;return Ri(t,ka,Sa).then(function(t){return t.contract=e,t})}(t).then(function(t){return{baseClient:new ga(t,e),opts:t}}).then(function(t){var e=t.baseClient,r=t.opts;return Ki(e,r.contract).then(function(t){return Oa(e,r,t)})})}return function(t){return void 0===t&&(t={}),Ea(t,new o)}}); +//# sourceMappingURL=full.js.map diff --git a/packages/http-client/dist/full.js.map b/packages/http-client/dist/full.js.map new file mode 100644 index 00000000..f5647ad9 --- /dev/null +++ b/packages/http-client/dist/full.js.map @@ -0,0 +1 @@ +{"version":3,"file":"full.js","sources":["../node_modules/store/plugins/defaults.js","../node_modules/store/plugins/expire.js"],"sourcesContent":["module.exports = defaultsPlugin\n\nfunction defaultsPlugin() {\n\tvar defaultValues = {}\n\t\n\treturn {\n\t\tdefaults: defaults,\n\t\tget: get\n\t}\n\t\n\tfunction defaults(_, values) {\n\t\tdefaultValues = values\n\t}\n\t\n\tfunction get(super_fn, key) {\n\t\tvar val = super_fn()\n\t\treturn (val !== undefined ? val : defaultValues[key])\n\t}\n}\n","var namespace = 'expire_mixin'\n\nmodule.exports = expirePlugin\n\nfunction expirePlugin() {\n\tvar expirations = this.createStore(this.storage, null, this._namespacePrefix+namespace)\n\t\n\treturn {\n\t\tset: expire_set,\n\t\tget: expire_get,\n\t\tremove: expire_remove,\n\t\tgetExpiration: getExpiration,\n\t\tremoveExpiredKeys: removeExpiredKeys\n\t}\n\t\n\tfunction expire_set(super_fn, key, val, expiration) {\n\t\tif (!this.hasNamespace(namespace)) {\n\t\t\texpirations.set(key, expiration)\n\t\t}\n\t\treturn super_fn()\n\t}\n\t\n\tfunction expire_get(super_fn, key) {\n\t\tif (!this.hasNamespace(namespace)) {\n\t\t\t_checkExpiration.call(this, key)\n\t\t}\n\t\treturn super_fn()\n\t}\n\t\n\tfunction expire_remove(super_fn, key) {\n\t\tif (!this.hasNamespace(namespace)) {\n\t\t\texpirations.remove(key)\n\t\t}\n\t\treturn super_fn()\n\t}\n\t\n\tfunction getExpiration(_, key) {\n\t\treturn expirations.get(key)\n\t}\n\t\n\tfunction removeExpiredKeys(_) {\n\t\tvar keys = []\n\t\tthis.each(function(val, key) {\n\t\t\tkeys.push(key)\n\t\t})\n\t\tfor (var i=0; i=0;e--){var r=O().key(e);t(k(r),r)}},remove:function(t){return O().removeItem(t)},clearAll:function(){return O().clear()}};function O(){return j.localStorage}function k(t){return O().getItem(t)}var A=a.trim,E={name:"cookieStorage",read:function(t){if(!t||!C(t))return null;var e="(?:^|.*;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(T.cookie.replace(new RegExp(e),"$1"))},write:function(t,e){if(!t)return;T.cookie=escape(t)+"="+escape(e)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"},each:x,remove:P,clearAll:function(){x(function(t,e){P(e)})}},T=a.Global.document;function x(t){for(var e=T.cookie.split(/; ?/g),r=e.length-1;r>=0;r--)if(A(e[r])){var n=e[r].split("="),o=unescape(n[0]);t(unescape(n[1]),o)}}function P(t){t&&C(t)&&(T.cookie=escape(t)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function C(t){return new RegExp("(?:^|;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(T.cookie)}var q=function(){var t={};return{defaults:function(e,r){t=r},get:function(e,r){var n=e();return void 0!==n?n:t[r]}}};var z="expire_mixin",N=function(){var t=this.createStore(this.storage,null,this._namespacePrefix+z);return{set:function(e,r,n,o){this.hasNamespace(z)||t.set(r,o);return e()},get:function(t,r){this.hasNamespace(z)||e.call(this,r);return t()},remove:function(e,r){this.hasNamespace(z)||t.remove(r);return e()},getExpiration:function(e,r){return t.get(r)},removeExpiredKeys:function(t){var r=[];this.each(function(t,e){r.push(e)});for(var n=0;n>>8,r[2*n+1]=a%256}return r},decompressFromUint8Array:function(e){if(null==e)return i.decompress(e);for(var r=new Array(e.length/2),n=0,o=r.length;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=a[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++),a[s]=p++,f=String(c)}if(""!==f){if(Object.prototype.hasOwnProperty.call(u,f)){if(f.charCodeAt(0)<256){for(n=0;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=a[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++)}for(o=2,n=0;n>=1;for(;;){if(v<<=1,g==e-1){d.push(r(v));break}g++}return d.join("")},decompress:function(t){return null==t?"":""==t?null:i._decompress(t.length,32768,function(e){return t.charCodeAt(e)})},_decompress:function(e,r,n){var o,i,a,u,c,s,f,l=[],p=4,h=4,d=3,v="",g=[],y={val:n(0),position:r,index:1};for(o=0;o<3;o+=1)l[o]=o;for(a=0,c=Math.pow(2,2),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;switch(a){case 0:for(a=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;f=t(a);break;case 1:for(a=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;f=t(a);break;case 2:return""}for(l[3]=f,i=f,g.push(f);;){if(y.index>e)return"";for(a=0,c=Math.pow(2,d),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;switch(f=a){case 0:for(a=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;l[h++]=t(a),f=h-1,p--;break;case 1:for(a=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;l[h++]=t(a),f=h-1,p--;break;case 2:return g.join("")}if(0==p&&(p=Math.pow(2,d),d++),l[f])v=l[f];else{if(f!==h)return null;v=i+i.charAt(0)}g.push(v),l[h++]=i+v.charAt(0),i=v,0==--p&&(p=Math.pow(2,d),d++)}}};return i}();null!=t&&(t.exports=e)});var D=[S,E],H=[q,N,M,function(){return{get:function(t,e){var r=t(e);if(!r)return r;var n=U.decompress(r);return null==n?r:this._deserialize(n)},set:function(t,e,r){var n=U.compress(this._serialize(r));t(e,n)}}}],L=m.createStore(D,H),K=a.Global;function B(){return K.sessionStorage}function W(t){return B().getItem(t)}var V=[{name:"sessionStorage",read:W,write:function(t,e){return B().setItem(t,e)},each:function(t){for(var e=B().length-1;e>=0;e--){var r=B().key(e);t(W(r),r)}},remove:function(t){return B().removeItem(t)},clearAll:function(){return B().clear()}},E],G=[q,N],Y=m.createStore(V,G),Q=L,X=Y,Z="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},tt="object"==typeof Z&&Z&&Z.Object===Object&&Z,et="object"==typeof self&&self&&self.Object===Object&&self,rt=tt||et||Function("return this")(),nt=rt.Symbol,ot=Object.prototype,it=ot.hasOwnProperty,at=ot.toString,ut=nt?nt.toStringTag:void 0;var ct=Object.prototype.toString;var st="[object Null]",ft="[object Undefined]",lt=nt?nt.toStringTag:void 0;function pt(t){return null==t?void 0===t?ft:st:lt&< in Object(t)?function(t){var e=it.call(t,ut),r=t[ut];try{t[ut]=void 0;var n=!0}catch(t){}var o=at.call(t);return n&&(e?t[ut]=r:delete t[ut]),o}(t):function(t){return ct.call(t)}(t)}function ht(t){return null!=t&&"object"==typeof t}var dt="[object Symbol]";function vt(t){return"symbol"==typeof t||ht(t)&&pt(t)==dt}function gt(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r0){if(++Yt>=Bt)return arguments[0]}else Yt=0;return Gt.apply(void 0,arguments)});function te(t){return t!=t}function ee(t,e,r){return e==e?function(t,e,r){for(var n=r-1,o=t.length;++n-1&&t%1==0&&t-1&&t%1==0&&t<=le}function he(t){return null!=t&&pe(t.length)&&!Tt(t)}var de=Object.prototype;function ve(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||de)}var ge="[object Arguments]";function ye(t){return ht(t)&&pt(t)==ge}var be=Object.prototype,me=be.hasOwnProperty,_e=be.propertyIsEnumerable,we=ye(function(){return arguments}())?ye:function(t){return ht(t)&&me.call(t,"callee")&&!_e.call(t,"callee")};var je="object"==typeof exports&&exports&&!exports.nodeType&&exports,Se=je&&"object"==typeof module&&module&&!module.nodeType&&module,Oe=Se&&Se.exports===je?rt.Buffer:void 0,ke=(Oe?Oe.isBuffer:void 0)||function(){return!1},Ae={};Ae["[object Float32Array]"]=Ae["[object Float64Array]"]=Ae["[object Int8Array]"]=Ae["[object Int16Array]"]=Ae["[object Int32Array]"]=Ae["[object Uint8Array]"]=Ae["[object Uint8ClampedArray]"]=Ae["[object Uint16Array]"]=Ae["[object Uint32Array]"]=!0,Ae["[object Arguments]"]=Ae["[object Array]"]=Ae["[object ArrayBuffer]"]=Ae["[object Boolean]"]=Ae["[object DataView]"]=Ae["[object Date]"]=Ae["[object Error]"]=Ae["[object Function]"]=Ae["[object Map]"]=Ae["[object Number]"]=Ae["[object Object]"]=Ae["[object RegExp]"]=Ae["[object Set]"]=Ae["[object String]"]=Ae["[object WeakMap]"]=!1;var Ee="object"==typeof exports&&exports&&!exports.nodeType&&exports,Te=Ee&&"object"==typeof module&&module&&!module.nodeType&&module,xe=Te&&Te.exports===Ee&&tt.process,Pe=function(){try{var t=Te&&Te.require&&Te.require("util").types;return t||xe&&xe.binding&&xe.binding("util")}catch(t){}}(),Ce=Pe&&Pe.isTypedArray,qe=Ce?function(t){return function(e){return t(e)}}(Ce):function(t){return ht(t)&&pe(t.length)&&!!Ae[pt(t)]},ze=Object.prototype.hasOwnProperty;function Ne(t,e){var r=yt(t),n=!r&&we(t),o=!r&&!n&&ke(t),i=!r&&!n&&!o&&qe(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r-1},Ze.prototype.set=function(t,e){var r=this.__data__,n=Qe(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var tr=Ut(rt,"Map");function er(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function rr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e=n?t:function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++nu))return!1;var s=i.get(t);if(s&&i.get(e))return s==e;var f=-1,l=!0,p=r&pn?new sn:void 0;for(i.set(t,e),i.set(e,t);++f1?e[n-1]:void 0,i=n>2?e[2]:void 0;for(o=ho.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!jt(r))return!1;var n=typeof e;return!!("number"==n?he(r)&&oe(e,r.length):"string"==n&&e in r)&&ae(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r-1;);return r}(n,o),function(t,e){for(var r=t.length;r--&&ee(e,t[r],0)>-1;);return r}(n,o)+1).join("")}function jo(t){return!!yt(t)||null!=t&&""!==wo(t)}var So=function(t){return!uo(t)&&!fo(parseFloat(t))},Oo=function(t){return""!==wo(t)&&uo(t)},ko=function(t){return function(t){return!0===t||!1===t||ht(t)&&pt(t)==co}(t)},Ao=function(t,e){return void 0===e&&(e=!0),!lo(t)&&""!==t&&""!==wo(t)&&(!1===e||!0===e&&!function(t){return null===t}(t))},Eo="application/vnd.api+json",To={Accept:Eo,"Content-Type":[Eo,"charset=utf-8"].join(";")},xo="payload",Po="condition",Co="args",qo=["POST","PUT"],zo="type",No="optional",Io="enumv",$o="args",Fo="checker",Jo="alias",Mo={desc:"y"},Ro="No message",Uo=zo,Do=No,Ho=Io,Lo=$o,Ko=Fo,Bo=Jo,Wo="continue",Vo=function(t){switch(t){case"number":return So;case"string":return Oo;case"boolean":return ko;default:return Ao}},Go=function(t,e){return void 0===e&&(e=""),!!yt(t)&&(""===e||""===wo(e)||!(t.filter(function(t){return!Vo(e)(t)}).length>0))},Yo=function(t){if(t.indexOf("array.<")>-1&&t.indexOf(">")>-1){var e=t.replace("array.<","").replace(">","");return e.indexOf("|")?e.split("|"):[e]}return!1},Qo=function(t,e){var r=t.arg;return e.length>1?!r.filter(function(t){return!(e.length>e.filter(function(e){return!Vo(e)(t)}).length)}).length:e.length>e.filter(function(t){return!Go(r,t)}).length},Xo=function(t,e){if(void 0===e&&(e=null),jr(t)){if(!e)return!0;if(Go(e))return!e.filter(function(e){var r=t[e.name];return!(e.type.length>e.type.filter(function(t){var e;return!!lo(r)||(!1!==(e=Yo(t))?!Qo({arg:r},e):!Vo(t)(r))}).length)}).length}return!1},Zo=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 406},r.name.get=function(){return"Jsonql406Error"},Object.defineProperties(e,r),e}(Error),ti=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"Jsonql500Error"},Object.defineProperties(e,r),e}(Error),ei=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(e,r),e}(Error),ri=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(e,r),e}(Error),ni=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(e,r),e}(Error),oi=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 404},r.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(e,r),e}(Error),ii=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(e,r),e}(Error),ai=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(e,r),e}(Error),ui=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(e,r),e}(Error),ci=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(e,r),e}(Error),si=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0},statusCode:{configurable:!0}};return r.name.get=function(){return"JsonqlError"},r.statusCode.get=function(){return-1},Object.defineProperties(e,r),e}(Error),fi=function(t){function e(r,n){t.call(this,n),this.statusCode=r,this.className=e.name}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlServerError"},Object.defineProperties(e,r),e}(Error),li=Object.freeze({Jsonql406Error:Zo,Jsonql500Error:ti,JsonqlAuthorisationError:ei,JsonqlContractAuthError:ri,JsonqlResolverAppError:ni,JsonqlResolverNotFoundError:oi,JsonqlEnumError:ii,JsonqlTypeError:ai,JsonqlCheckerError:ui,JsonqlValidationError:ci,JsonqlError:si,JsonqlServerError:fi}),pi=si,hi=function(t,e){return!!Object.keys(t).filter(function(t){return e===t}).length};function di(t){if(hi(t,"error")){var e=t.error,r=e.className,n=e.name,o=r||n,i=e.message||Ro,a=e.detail||e;if(o&&li[o])throw new li[r](i,a);throw new pi(i,a)}return t}function vi(t){if(Array.isArray(t))throw new ci("",t);var e=t.message||Ro,r=t.detail||t;switch(!0){case t instanceof Zo:throw new Zo(e,r);case t instanceof ti:throw new ti(e,r);case t instanceof ei:throw new ei(e,r);case t instanceof ri:throw new ri(e,r);case t instanceof ni:throw new ni(e,r);case t instanceof oi:throw new oi(e,r);case t instanceof ii:throw new ii(e,r);case t instanceof ai:throw new ai(e,r);case t instanceof ui:throw new ui(e,r);case t instanceof ci:throw new ci(e,r);case t instanceof fi:throw new fi(e,r);default:throw new si(e,r)}}var gi=function(t,e){var r,n,o,i,a;switch(!0){case"object"===t:return o=(n=e).arg,i=n.param,a=[o],Array.isArray(i.keys)&&i.keys.length&&a.push(i.keys),!Xo.apply(null,a);case"array"===t:return!Go(e.arg);case!1!==(r=Yo(t)):return!Qo(e,r);default:return!Vo(t)(e.arg)}},yi=function(t,e){return lo(t)?!0!==e.optional||lo(e.defaultvalue)?null:e.defaultvalue:t},bi=function(t,e,r){var n;void 0===r&&(r=!1);var o=function(t,e){if(!Go(e))throw new si("params is not an array! Did something gone wrong when you generate the contract.json?");if(0===e.length)return[];if(!Go(t))throw new si("args is not an array! You might want to do: ES6 Array.from(arguments) or ES5 Array.prototype.slice.call(arguments)");switch(!0){case t.length==e.length:return t.map(function(t,r){return{arg:t,index:r,param:e[r]}});case!0===e[0].variable:var r=e[0].type;return t.map(function(t,n){return{arg:t,index:n,param:e[n]||{type:r,name:"_"}}});case t.lengthe.length&&1===e.length:var n,o=["any"];return!1!==(n=Yo(e[0].type[0]))&&(o=n),t.map(function(t,r){return{arg:t,index:r,param:e[r]||{type:o,name:"_"}}});default:throw new si("Could not understand your arguments and parameter structure!",{args:t,params:e})}}(t,e),i=o.filter(function(t){return!0===t.param.optional?function(t){var e=t.arg,r=t.param;return!(!jo(e)||r.type.length>r.type.filter(function(e){return gi(e,t)}).length)}(t):!(t.param.type.length>t.param.type.filter(function(e){return gi(e,t)}).length)});return r?((n={}).error=i,n.data=o.map(function(t){return t.arg}),n):i},mi=function(t,e){return!!t.filter(function(t){return t===e}).length},_i=function(t,e){var r=Object.keys(t);return mi(r,e)},wi=function(t){return!jo(t)};function ji(t,e){var r=mo(e,function(t,e){return!t[Bo]});return Mn(r,{})?t:function(t,e){var r={};return e=Qn(e),to(t,function(t,n,o){ie(r,e(t,n,o),t)}),r}(t,function(t,e){return function(t,e,r){var n;return r(t,function(t,r,o){if(e(t,r,o))return n=r,!1}),n}(r,Qn(function(t){return t.alias===e}),to)||e})}function Si(t,e){return po(e,function(e,r){var n,o;return lo(t[r])||!0===e[Do]&&wi(t[r])?vo({},e,((n={})[Wo]=!0,n)):((o={})[Lo]=t[r],o[Uo]=e[Uo],o[Do]=e[Do]||!1,o[Ho]=e[Ho]||!1,o[Ko]=e[Ko]||!1,o)})}function Oi(t,e){var r=function(t,e){var r=ji(t,e);return{pristineValues:po(mo(e,function(t,e){return _i(r,e)}),function(t){return t.args}),checkAgainstAppProps:mo(e,function(t,e){return!_i(r,e)}),config:r}}(t,e),n=r.config,o=r.pristineValues;return[Si(n,r.checkAgainstAppProps),o]}var ki=function(t){return Go(t)?t:[t]};var Ai=function(t,e){return!Go(e)||function(t,e){return!!t.filter(function(t){return t===e}).length}(e,t)},Ei=function(t,e){try{return!!Tt(e)&&e.apply(null,[t])}catch(t){return!1}};function Ti(t){return function(e,r){if(e[Wo])return e[Lo];var n=function(t,e){var r,n=[[t[Lo]],[(r={},r[Uo]=ki(t[Uo]),r[Do]=t[Do],r)]];return Reflect.apply(e,null,n)}(e,t);if(n.length)throw new ai(r,n);if(!1!==e[Ho]&&!Ai(e[Lo],e[Ho]))throw new ii(r);if(!1!==e[Ko]&&!Ei(e[Lo],e[Ko]))throw new ui(r);return e[Lo]}}var xi=function(t,e){return Promise.resolve(Oi(t,e))};function Pi(t,e,r,n){return void 0===t&&(t={}),xi(t,e).then(function(t){return function(t,e){var r=t[0],n=t[1],o=po(r,Ti(e));return vo(o,n)}(t,n)}).then(function(t){return vo({},t,r)})}var Ci=Xo,qi=Oo,zi=Go,Ni=function(t,e,r){return void 0===r&&(r=!1),new Promise(function(n,o){var i=bi(t,e,r);return r?i.error.length?o(i.error):n(i.data):i.length?o(i):n([])})},Ii=function(t,e,r){void 0===r&&(r={});var n=r[No],o=r[Io],i=r[Fo],a=r[Jo];return function(t,e,r,n,o,i){void 0===r&&(r=!1),void 0===n&&(n=!1),void 0===o&&(o=!1),void 0===i&&(i=!1);var a={};return a[$o]=t,a[zo]=e,!0===r&&(a[No]=!0),Go(n)&&(a[Io]=n),Tt(o)&&(a[Fo]=o),uo(i)&&(a[Jo]=i),a}.apply(null,[t,e,n,o,i,a])},$i=function(t){return function(e,r,n){return void 0===n&&(n={}),Pi(e,r,n,t)}}(bi),Fi=mi,Ji=_i,Mi=function(t,e,r){var n;if(void 0===e&&(e=[]),void 0===r&&(r=!1),Oo(t)&&Go(e)){var o={};return o[Co]=e,!0===r?o:((n={})[t]=o,n)}throw new ci("[createQuery] expect resolverName to be string and args to be array!",{resolverName:t,args:e})},Ri=function(t,e,r,n){var o;void 0===r&&(r={}),void 0===n&&(n=!1);var i={};if(i[xo]=e,i[Po]=r,!0===n)return i;if(Oo(t))return(o={})[t]=i,o;throw new ci("[createMutation] expect resolverName to be string!",{resolverName:t,payload:e,condition:r})},Ui=function(t){return Object.keys(t)[0]},Di=function(){return Math.floor(Date.now()/1e3)},Hi=function(t,e){return void 0===e&&(e={}),Ki(e)?Promise.resolve(e):t.getContract()},Li=function(t){return Ji(t,"data")&&!Ji(t,"error")?t.data:t},Ki=function(t){return t&&Ci(t)&&(Ji(t,"query")||Ji(t,"mutation"))},Bi="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function Wi(t){this.message=t}Wi.prototype=new Error,Wi.prototype.name="InvalidCharacterError";var Vi="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new Wi("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,n,o=0,i=0,a="";n=e.charAt(i++);~n&&(r=o%4?64*r+n:n,o++%4)?a+=String.fromCharCode(255&r>>(-2*o&6)):0)n=Bi.indexOf(n);return a};var Gi=function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(Vi(t).replace(/(.)/g,function(t,e){var r=e.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}(e)}catch(t){return Vi(e)}};function Yi(t){this.message=t}Yi.prototype=new Error,Yi.prototype.name="InvalidTokenError";var Qi,Xi,Zi,ta,ea,ra,na,oa,ia,aa=function(t,e){if("string"!=typeof t)throw new Yi("Invalid token specified");var r=!0===(e=e||{}).header?0:1;try{return JSON.parse(Gi(t.split(".")[r]))}catch(t){throw new Yi("Invalid token specified: "+t.message)}},ua=Yi;function ca(t){if(qi(t))return function(t){var e=t.iat||Math.floor(Date.now()/1e3);if(t.exp&&e>=t.exp){var r=new Date(t.exp).toISOString();throw new si("Token has expired on "+r,t)}return t}(aa(t));throw new si("Token must be a string!")}aa.InvalidTokenError=ua;Ii("HS256",["string"]),Ii(!1,["boolean","number","string"],((Qi={})[Jo]="exp",Qi[No]=!0,Qi)),Ii(!1,["boolean","number","string"],((Xi={})[Jo]="nbf",Xi[No]=!0,Xi)),Ii(!1,["boolean","string"],((Zi={})[Jo]="iss",Zi[No]=!0,Zi)),Ii(!1,["boolean","string"],((ta={})[Jo]="sub",ta[No]=!0,ta)),Ii(!1,["boolean","string"],((ea={})[Jo]="iss",ea[No]=!0,ea)),Ii(!1,["boolean"],((ra={})[No]=!0,ra)),Ii(!1,["boolean","string"],((na={})[No]=!0,na)),Ii(!1,["boolean","string"],((oa={})[No]=!0,oa)),Ii(!1,["boolean"],((ia={})[No]=!0,ia));!function(){switch(!0){case"undefined"!=typeof WebSocket:return WebSocket;case"undefined"!=typeof MozWebSocket:return MozWebSocket;case"undefined"!=typeof window:return window.WebSocket||window.MozWebSocket;default:throw new ci("WebSocket is NOT SUPPORTED!")}}();var sa=qo[0],fa=qo[1],la=function(e){try{this.fly||(this.fly=new t)}catch(t){throw console.error("Init fly error!",t),t}this.opts=e,this.extraHeader={},this.extraParams={},this.reqInterceptor(),this.resInterceptor()},pa={headers:{configurable:!0}};pa.headers.set=function(t){this.extraHeader=t},la.prototype.request=function(t,e,r){var n;void 0===e&&(e={}),void 0===r&&(r={}),this.headers=r;var o=vo({},{_cb:Di()},this.extraParams);if(this.opts.enableJsonp){var i=Ui(t);o=vo({},o,((n={}).jsonqlJsonpCallback=i,n)),t=t[i]}return this.fly.request(this.jsonqlEndpoint,t,vo({},{method:sa,params:o},e))},la.prototype.reqInterceptor=function(){var t=this;this.fly.interceptors.request.use(function(e){console.info("request interceptor call");var r=t.getHeaders();for(var n in r)e.headers[n]=r[n];return e})},la.prototype.processJsonp=function(t){return Li(t)},la.prototype.resInterceptor=function(){var t=this,e=t.opts.enableJsonp;this.fly.interceptors.response.use(function(r){console.info("response interceptor call"),t.cleanUp();var n=qi(r.data)?JSON.parse(r.data):r.data;return e?t.processJsonp(n):Li(n)},function(e){throw t.cleanUp(),console.error(e),new fi("Server side error",e)})},la.prototype.getHeaders=function(){return this.opts.enableAuth?vo({},To,this.getAuthHeader(),this.extraHeader):vo({},To,this.extraHeader)},la.prototype.cleanUp=function(){this.extraHeader={},this.extraParams={}},la.prototype.get=function(){return this.opts.showContractDesc&&(this.extraParams=vo({},this.extraParams,Mo)),this.request({},{method:"GET"},this.contractHeader).then(di).then(function(t){return console.info("144 get contract result",t),t.cache&&t.contract?t.contract:t})},la.prototype.query=function(t,e){return void 0===e&&(e=[]),this.request(Mi(t,e)).then(di)},la.prototype.mutation=function(t,e,r){return void 0===e&&(e={}),void 0===r&&(r={}),this.request(Ri(t,e,r),{method:fa}).then(di)},Object.defineProperties(la.prototype,pa);var ha=function(t){function e(e,r){t.call(this,e),null!==r&&(this.fly=new r)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={storeIt:{configurable:!0},jsonqlEndpoint:{configurable:!0},jsonqlContract:{configurable:!0},jsonqlToken:{configurable:!0},jsonqlUserdata:{configurable:!0}};return r.storeIt.set=function(t){throw console.info("storeIt",t),zi(t)&&t.length>=2&&Reflect.apply(Q.set,Q,t),new ci("Expect argument to be array and least 2 items!")},r.jsonqlEndpoint.set=function(t){var e=Q.get("endpoint")||[];Fi(e,t)||(e.push(t),this.storeId=["endpoint",e],this.endpointIndex=e.length-1)},r.jsonqlContract.set=function(t){var e=this.opts.storageKey,r=[e],n=t[0],o=t[1],i=Q.get(e)||[];i[this.endpointIndex||0]=n,r.push(i),o&&r.push(o),this.opts.keepContract&&(this.storeIt=r)},r.jsonqlToken.set=function(t){var e="credential",r=localStorage.get(e)||[];if(!Fi(r,t)){var n=r.length-1;r[n]=t,this[e+"Index"]=n;var o=[e,r];if(this.opts.tokenExpired){var i=parseFloat(this.opts.tokenExpired);if(!isNaN(i)&&i>0){var a=Di();o.push(a+parseFloat(i))}}return this.storeIt=o,this.jsonqlUserdata=this.decoder(t),t}return!1},r.jsonqlUserdata.set=function(t){var e=["userdata",t];return t.exp&&e.push(t.exp),Reflect.apply(Q.set,Q,e)},r.jsonqlEndpoint.get=function(){var t=Q.get("endpoint");if(!t){var e=this.opts,r=[e.hostname,e.jsonqlPath].join("/");return this.jsonqlEndpoint=r,r}return t[this.endpointIndex]},r.jsonqlContract.get=function(){var t=this.opts.storageKey;return(Q.get(t)||[])[this.endpointIndex]||!1},r.jsonqlToken.get=function(){var t="credential",e=localStorage.get(t);return!!e&&e[this[t+"Index"]]},r.jsonqlUserdata.get=function(){return X.get("userdata")},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),e.enableAuth&&e.useJwt&&(this.setDecoder=ca)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={userdata:{configurable:!0},rawAuthToken:{configurable:!0},setDecoder:{configurable:!0}};return r.userdata.get=function(){return this.jsonqlUserdata},r.rawAuthToken.get=function(){return this.jsonqlToken},r.setDecoder.set=function(t){"function"==typeof t&&(this.decoder=t)},e.prototype.storeToken=function(t){return this.jsonqlToken=t},e.prototype.decoder=function(t){return t},e.prototype.getAuthHeader=function(){var t,e=this.rawAuthToken;return e?((t={})[this.opts.AUTH_HEADER]="Bearer "+e,t):{}},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={contractHeader:{configurable:!0}};return e.prototype.getContract=function(){var t=this.readContract();if(console.info("getContract first call",t),t&&Array.isArray(t)){var e=t[this.endpointIndex||0];if(e)return Promise.resolve(e)}return this.get().then(this.storeContract.bind(this))},r.contractHeader.get=function(){var t={};return!1!==this.opts.contractKey&&(t[this.opts.contractKeyName]=this.opts.contractKey),t},e.prototype.storeContract=function(t){if(!Ki(t))throw new ci("Contract is malformed!");var e=[t];if(this.opts.contractExpired){var r=parseFloat(this.opts.contractExpired);!isNaN(r)&&r>0&&e.push(r)}return this.jsonqlContract=e,console.info("storeContract return result",t),t},e.prototype.readContract=function(){return Ki(this.opts.contract)?this.opts.contract:Q.get(this.opts.storageKey)},Object.defineProperties(e.prototype,r),e}(la))),da=new WeakMap,va=new WeakMap;var ga=function(t){void 0===t&&(t={}),t.logger&&"function"==typeof t.logger&&(this.logger=t.logger),this.keep=t.keep,this.result=t.keep?[]:null,this.normalStore=new Map,this.lazyStore=new Map},ya={$done:{configurable:!0},normalStore:{configurable:!0},lazyStore:{configurable:!0}};ga.prototype.logger=function(){},ga.prototype.$on=function(t,e,r){var n=this;void 0===r&&(r=null);this.validate(t,e);var o=this.takeFromStore(t);if(!1===o)return this.logger("$on",t+" callback is not in lazy store"),this.addToNormalStore(t,"on",e,r);this.logger("$on",t+" found in lazy store");var i=0;return o.forEach(function(o){var a=o[0],u=o[1],c=o[2];if(c&&"on"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);n.run(e,a,r||u),i+=n.addToNormalStore(t,"on",e,r||u)}),i},ga.prototype.$once=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=this.takeFromStore(t);this.normalStore;if(!1===n)return this.logger("$once",t+" not in the lazy store"),this.addToNormalStore(t,"once",e,r);this.logger("$once",n);var o=Array.from(n)[0],i=o[0],a=o[1],u=o[2];if(u&&"once"!==u)throw new Error("You are trying to register an event already been taken by other type: "+u);this.run(e,i,r||a),this.$off(t)},ga.prototype.$only=function(t,e,r){var n=this;void 0===r&&(r=null),this.validate(t,e);var o=!1,i=this.takeFromStore(t);(this.normalStore.has(t)||(this.logger("$only",t+" add to store"),o=this.addToNormalStore(t,"only",e,r)),!1!==i)&&(this.logger("$only",t+" found data in lazy store to execute"),Array.from(i).forEach(function(t){var o=t[0],i=t[1],a=t[2];if(a&&"only"!==a)throw new Error("You are trying to register an event already been taken by other type: "+a);n.run(e,o,r||i)}));return o},ga.prototype.$onlyOnce=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=!1,o=this.takeFromStore(t);if(this.normalStore.has(t)||(this.logger("$onlyOnce",t+" add to store"),n=this.addToNormalStore(t,"onlyOnce",e,r)),!1!==o){this.logger("$onlyOnce",o);var i=Array.from(o)[0],a=i[0],u=i[1],c=i[2];if(c&&"onlyOnce"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);this.run(e,a,r||u),this.$off(t)}return n},ga.prototype.$replace=function(t,e,r,n){if(void 0===r&&(r=null),void 0===n&&(n="on"),this.validateType(n)){this.$off(t);var o=this["$"+n];return Reflect.apply(o,this,[t,e,r])}throw new Error(n+" is not supported!")},ga.prototype.$trigger=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1),this.validateEvt(t);var o=0,i=this.normalStore;if(this.logger("$trigger",i),i.has(t)){this.logger("$trigger",t,"found");for(var a=Array.from(i.get(t)),u=a.length,c=!1,s=0;s0;)n[o]=arguments[o+2];if(t.has(e)?(this.logger("addToStore",e+" existed"),r=t.get(e)):(this.logger("addToStore","create new Set for "+e),r=new Set),n.length>2)if(Array.isArray(n[0])){var i=n[2];this.checkTypeInLazyStore(e,i)||r.add(n)}else this.checkContentExist(n,r)||(this.logger("addToStore","insert new",n),r.add(n));else r.add(n);return t.set(e,r),[t,r.size]},ga.prototype.checkContentExist=function(t,e){return!!Array.from(e).filter(function(e){return e[0]===t[0]}).length},ga.prototype.checkTypeInStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.$get(t,!0);return!1===r||!r.filter(function(t){var r=t[3];return e!==r}).length},ga.prototype.checkTypeInLazyStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.lazyStore.get(t);return this.logger("checkTypeInLazyStore",r),!!r&&!!Array.from(r).filter(function(t){return t[2]!==e}).length},ga.prototype.addToNormalStore=function(t,e,r,n){if(void 0===n&&(n=null),this.logger("addToNormalStore",t,e,"add to normal store"),this.checkTypeInStore(t,e)){this.logger(e+" can add to "+t+" store");var o=this.hashFnToKey(r),i=[this.normalStore,t,o,r,n,e],a=Reflect.apply(this.addToStore,this,i),u=a[0],c=a[1];return this.normalStore=u,c}return!1},ga.prototype.addToLazyStore=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1);var o=[this.lazyStore,t,this.toArray(e),r];n&&o.push(n);var i=Reflect.apply(this.addToStore,this,o),a=i[0],u=i[1];return this.lazyStore=a,u},ga.prototype.toArray=function(t){return Array.isArray(t)?t:[t]},ya.normalStore.set=function(t){da.set(this,t)},ya.normalStore.get=function(){return da.get(this)},ya.lazyStore.set=function(t){va.set(this,t)},ya.lazyStore.get=function(){return va.get(this)},ga.prototype.hashFnToKey=function(t){return t.toString().split("").reduce(function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t},0)+""},Object.defineProperties(ga.prototype,ya);var ba=new ga,ma=function(t,e,r,n){return function(){for(var r=[],o=arguments.length;o--;)r[o]=arguments[o];var i=n.auth[e].params,a=i.map(function(t,e){return r[e]}),u=r[i.length]||{};return Ni(r,i).then(function(){return t.query.apply(t,[e,a,u])}).catch(vi)}},_a=function(t,e,r){var n={query:{},mutation:{},auth:{}},o=function(e){n.query[e]=function(){for(var n=[],o=arguments.length;o--;)n[o]=arguments[o];var i=r.query[e].params,a=i.map(function(t,e){return n[e]}),u=n[i.length]||{};return Ni(a,i).then(function(){return t.query.apply(t,[e,a,u])}).catch(vi)}};for(var i in r.query)o(i);var a=function(e){n.mutation[e]=function(n,o,i){void 0===i&&(i={});var a=[n,o],u=r.mutation[e].params;return Ni(a,u).then(function(){return t.mutation.apply(t,[e,n,o,i])}).catch(vi)}};for(var u in r.mutation)a(u);if(e.enableAuth&&r.auth){var c=e.loginHandlerName,s=e.logoutHandlerName;r.auth[c]&&(n[c]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=ma(t,c,0,r);return o.apply(null,e).then(t.postLoginAction).then(function(t){return ba.$trigger("login",t),t})}),r.auth[s]?n[s]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=ma(t,s,0,r);return o.apply(null,e).then(t.postLogoutAction).then(function(t){return ba.$trigger("logout",t),t})}:n[s]=function(){t.postLogoutAction("continue"),ba.$trigger("logout","continue")},n.userdata=function(){return t.userdata}}return n.returnInstance&&(n.jsonqlClientInstance=t),n.getToken=function(){return t.rawAuthToken},n.eventEmitter=ba,n},wa={contract:!1,MUTATION_ARGS:["name","payload","conditions"],CONTENT_TYPE:Eo,BEARER:"Bearer",AUTH_HEADER:"Authorization"},ja={hostname:Ii([window.location.protocol,window.location.host].join("//"),["string"]),jsonqlPath:Ii("jsonql",["string"]),loginHandlerName:Ii("login",["string"]),logoutHandlerName:Ii("logout",["string"]),enableJsonp:Ii(!1,["boolean"]),enableAuth:Ii(!1,["boolean"]),useJwt:Ii(!0,["boolean"]),useLocalstorage:Ii(!0,["boolean"]),storageKey:Ii("storageKey",["string"]),authKey:Ii("authKey",["string"]),contractExpired:Ii(0,["number"]),keepContract:Ii(!0,["boolean"]),showContractDesc:Ii(!1,["boolean"]),contractKey:Ii(!1,["boolean"]),contractKeyName:Ii("X-JSONQL-CV-KEY",["string"]),enableTimeout:Ii(!1,["boolean"]),timeout:Ii(5e3,["number"]),returnInstance:Ii(!1,["boolean"]),allowReturnRawToken:Ii(!1,["boolean"]),debugOn:Ii(!1,["boolean"])};return function(t,e){return void 0===t&&(t={}),void 0===e&&(e=null),function(t){var e=t.contract;return $i(t,ja,wa).then(function(t){return t.contract=e,t})}(t).then(function(t){return{baseClient:new ha(t,e),opts:t}}).then(function(t){var e=t.baseClient,r=t.opts;return Hi(e,r.contract).then(function(t){return _a(e,r,t)})})}}); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).jsonqlClient=e()}(this,function(){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var e=Object.assign?Object.assign:function(t,e,r,n){for(var o=arguments,a=1;a=0;e--){var r=S().key(e);t(O(r),r)}},remove:function(t){return S().removeItem(t)},clearAll:function(){return S().clear()}};function S(){return w.localStorage}function O(t){return S().getItem(t)}var k=a.trim,A={name:"cookieStorage",read:function(t){if(!t||!P(t))return null;var e="(?:^|.*;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(E.cookie.replace(new RegExp(e),"$1"))},write:function(t,e){if(!t)return;E.cookie=escape(t)+"="+escape(e)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"},each:T,remove:x,clearAll:function(){T(function(t,e){x(e)})}},E=a.Global.document;function T(t){for(var e=E.cookie.split(/; ?/g),r=e.length-1;r>=0;r--)if(k(e[r])){var n=e[r].split("="),o=unescape(n[0]);t(unescape(n[1]),o)}}function x(t){t&&P(t)&&(E.cookie=escape(t)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function P(t){return new RegExp("(?:^|;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(E.cookie)}var C=function(){var t={};return{defaults:function(e,r){t=r},get:function(e,r){var n=e();return void 0!==n?n:t[r]}}};var q="expire_mixin",z=function(){var t=this.createStore(this.storage,null,this._namespacePrefix+q);return{set:function(e,r,n,o){this.hasNamespace(q)||t.set(r,o);return e()},get:function(t,r){this.hasNamespace(q)||e.call(this,r);return t()},remove:function(e,r){this.hasNamespace(q)||t.remove(r);return e()},getExpiration:function(e,r){return t.get(r)},removeExpiredKeys:function(t){var r=[];this.each(function(t,e){r.push(e)});for(var n=0;n>>8,r[2*n+1]=i%256}return r},decompressFromUint8Array:function(e){if(null==e)return a.decompress(e);for(var r=new Array(e.length/2),n=0,o=r.length;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=i[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++),i[s]=p++,f=String(c)}if(""!==f){if(Object.prototype.hasOwnProperty.call(u,f)){if(f.charCodeAt(0)<256){for(n=0;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=i[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++)}for(o=2,n=0;n>=1;for(;;){if(v<<=1,g==e-1){d.push(r(v));break}g++}return d.join("")},decompress:function(t){return null==t?"":""==t?null:a._decompress(t.length,32768,function(e){return t.charCodeAt(e)})},_decompress:function(e,r,n){var o,a,i,u,c,s,f,l=[],p=4,h=4,d=3,v="",g=[],y={val:n(0),position:r,index:1};for(o=0;o<3;o+=1)l[o]=o;for(i=0,c=Math.pow(2,2),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;switch(i){case 0:for(i=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;f=t(i);break;case 1:for(i=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;f=t(i);break;case 2:return""}for(l[3]=f,a=f,g.push(f);;){if(y.index>e)return"";for(i=0,c=Math.pow(2,d),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;switch(f=i){case 0:for(i=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;l[h++]=t(i),f=h-1,p--;break;case 1:for(i=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;l[h++]=t(i),f=h-1,p--;break;case 2:return g.join("")}if(0==p&&(p=Math.pow(2,d),d++),l[f])v=l[f];else{if(f!==h)return null;v=a+a.charAt(0)}g.push(v),l[h++]=a+v.charAt(0),a=v,0==--p&&(p=Math.pow(2,d),d++)}}};return a}();null!=t&&(t.exports=e)});var U=[j,A],D=[C,z,J,function(){return{get:function(t,e){var r=t(e);if(!r)return r;var n=R.decompress(r);return null==n?r:this._deserialize(n)},set:function(t,e,r){var n=R.compress(this._serialize(r));t(e,n)}}}],H=b.createStore(U,D),L=a.Global;function K(){return L.sessionStorage}function B(t){return K().getItem(t)}var W=[{name:"sessionStorage",read:B,write:function(t,e){return K().setItem(t,e)},each:function(t){for(var e=K().length-1;e>=0;e--){var r=K().key(e);t(B(r),r)}},remove:function(t){return K().removeItem(t)},clearAll:function(){return K().clear()}},A],V=[C,z],G=b.createStore(W,V),Y=H,Q=G,X="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},Z="object"==typeof X&&X&&X.Object===Object&&X,tt="object"==typeof self&&self&&self.Object===Object&&self,et=Z||tt||Function("return this")(),rt=et.Symbol,nt=Object.prototype,ot=nt.hasOwnProperty,at=nt.toString,it=rt?rt.toStringTag:void 0;var ut=Object.prototype.toString;var ct="[object Null]",st="[object Undefined]",ft=rt?rt.toStringTag:void 0;function lt(t){return null==t?void 0===t?st:ct:ft&&ft in Object(t)?function(t){var e=ot.call(t,it),r=t[it];try{t[it]=void 0;var n=!0}catch(t){}var o=at.call(t);return n&&(e?t[it]=r:delete t[it]),o}(t):function(t){return ut.call(t)}(t)}function pt(t){return null!=t&&"object"==typeof t}var ht="[object Symbol]";function dt(t){return"symbol"==typeof t||pt(t)&<(t)==ht}function vt(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r0){if(++Gt>=Kt)return arguments[0]}else Gt=0;return Vt.apply(void 0,arguments)});function Zt(t){return t!=t}function te(t,e,r){return e==e?function(t,e,r){for(var n=r-1,o=t.length;++n-1&&t%1==0&&t-1&&t%1==0&&t<=fe}function pe(t){return null!=t&&le(t.length)&&!Et(t)}var he=Object.prototype;function de(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||he)}var ve="[object Arguments]";function ge(t){return pt(t)&<(t)==ve}var ye=Object.prototype,be=ye.hasOwnProperty,me=ye.propertyIsEnumerable,_e=ge(function(){return arguments}())?ge:function(t){return pt(t)&&be.call(t,"callee")&&!me.call(t,"callee")};var we="object"==typeof exports&&exports&&!exports.nodeType&&exports,je=we&&"object"==typeof module&&module&&!module.nodeType&&module,Se=je&&je.exports===we?et.Buffer:void 0,Oe=(Se?Se.isBuffer:void 0)||function(){return!1},ke={};ke["[object Float32Array]"]=ke["[object Float64Array]"]=ke["[object Int8Array]"]=ke["[object Int16Array]"]=ke["[object Int32Array]"]=ke["[object Uint8Array]"]=ke["[object Uint8ClampedArray]"]=ke["[object Uint16Array]"]=ke["[object Uint32Array]"]=!0,ke["[object Arguments]"]=ke["[object Array]"]=ke["[object ArrayBuffer]"]=ke["[object Boolean]"]=ke["[object DataView]"]=ke["[object Date]"]=ke["[object Error]"]=ke["[object Function]"]=ke["[object Map]"]=ke["[object Number]"]=ke["[object Object]"]=ke["[object RegExp]"]=ke["[object Set]"]=ke["[object String]"]=ke["[object WeakMap]"]=!1;var Ae="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ee=Ae&&"object"==typeof module&&module&&!module.nodeType&&module,Te=Ee&&Ee.exports===Ae&&Z.process,xe=function(){try{var t=Ee&&Ee.require&&Ee.require("util").types;return t||Te&&Te.binding&&Te.binding("util")}catch(t){}}(),Pe=xe&&xe.isTypedArray,Ce=Pe?function(t){return function(e){return t(e)}}(Pe):function(t){return pt(t)&&le(t.length)&&!!ke[lt(t)]},qe=Object.prototype.hasOwnProperty;function ze(t,e){var r=gt(t),n=!r&&_e(t),o=!r&&!n&&Oe(t),a=!r&&!n&&!o&&Ce(t),i=r||n||o||a,u=i?function(t,e){for(var r=-1,n=Array(t);++r-1},Xe.prototype.set=function(t,e){var r=this.__data__,n=Ye(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var Ze=Rt(et,"Map");function tr(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function er(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e=n?t:function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var a=Array(o);++nu))return!1;var s=a.get(t);if(s&&a.get(e))return s==e;var f=-1,l=!0,p=r&ln?new cn:void 0;for(a.set(t,e),a.set(e,t);++f1?e[n-1]:void 0,a=n>2?e[2]:void 0;for(o=po.length>3&&"function"==typeof o?(n--,o):void 0,a&&function(t,e,r){if(!wt(r))return!1;var n=typeof e;return!!("number"==n?pe(r)&&ne(e,r.length):"string"==n&&e in r)&&ae(r[e],t)}(e[0],e[1],a)&&(o=n<3?void 0:o,n=1),t=Object(t);++r-1;);return r}(n,o),function(t,e){for(var r=t.length;r--&&te(e,t[r],0)>-1;);return r}(n,o)+1).join("")}function wo(t){return!!gt(t)||null!=t&&""!==_o(t)}var jo=function(t){return!io(t)&&!so(parseFloat(t))},So=function(t){return""!==_o(t)&&io(t)},Oo=function(t){return function(t){return!0===t||!1===t||pt(t)&<(t)==uo}(t)},ko=function(t,e){return void 0===e&&(e=!0),!fo(t)&&""!==t&&""!==_o(t)&&(!1===e||!0===e&&!function(t){return null===t}(t))},Ao="application/vnd.api+json",Eo={Accept:Ao,"Content-Type":[Ao,"charset=utf-8"].join(";")},To="payload",xo="condition",Po="args",Co=["POST","PUT"],qo="type",zo="optional",No="enumv",Io="args",$o="checker",Fo="alias",Jo={desc:"y"},Mo="No message",Ro=qo,Uo=zo,Do=No,Ho=Io,Lo=$o,Ko=Fo,Bo="continue",Wo=function(t){switch(t){case"number":return jo;case"string":return So;case"boolean":return Oo;default:return ko}},Vo=function(t,e){return void 0===e&&(e=""),!!gt(t)&&(""===e||""===_o(e)||!(t.filter(function(t){return!Wo(e)(t)}).length>0))},Go=function(t){if(t.indexOf("array.<")>-1&&t.indexOf(">")>-1){var e=t.replace("array.<","").replace(">","");return e.indexOf("|")?e.split("|"):[e]}return!1},Yo=function(t,e){var r=t.arg;return e.length>1?!r.filter(function(t){return!(e.length>e.filter(function(e){return!Wo(e)(t)}).length)}).length:e.length>e.filter(function(t){return!Vo(r,t)}).length},Qo=function(t,e){if(void 0===e&&(e=null),wr(t)){if(!e)return!0;if(Vo(e))return!e.filter(function(e){var r=t[e.name];return!(e.type.length>e.type.filter(function(t){var e;return!!fo(r)||(!1!==(e=Go(t))?!Yo({arg:r},e):!Wo(t)(r))}).length)}).length}return!1},Xo=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 406},r.name.get=function(){return"Jsonql406Error"},Object.defineProperties(e,r),e}(Error),Zo=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"Jsonql500Error"},Object.defineProperties(e,r),e}(Error),ta=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(e,r),e}(Error),ea=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(e,r),e}(Error),ra=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(e,r),e}(Error),na=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 404},r.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(e,r),e}(Error),oa=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(e,r),e}(Error),aa=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(e,r),e}(Error),ia=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(e,r),e}(Error),ua=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(e,r),e}(Error),ca=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0},statusCode:{configurable:!0}};return r.name.get=function(){return"JsonqlError"},r.statusCode.get=function(){return-1},Object.defineProperties(e,r),e}(Error),sa=function(t){function e(r,n){t.call(this,n),this.statusCode=r,this.className=e.name}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlServerError"},Object.defineProperties(e,r),e}(Error),fa=Object.freeze({Jsonql406Error:Xo,Jsonql500Error:Zo,JsonqlAuthorisationError:ta,JsonqlContractAuthError:ea,JsonqlResolverAppError:ra,JsonqlResolverNotFoundError:na,JsonqlEnumError:oa,JsonqlTypeError:aa,JsonqlCheckerError:ia,JsonqlValidationError:ua,JsonqlError:ca,JsonqlServerError:sa}),la=ca,pa=function(t,e){return!!Object.keys(t).filter(function(t){return e===t}).length};function ha(t){if(pa(t,"error")){var e=t.error,r=e.className,n=e.name,o=r||n,a=e.message||Mo,i=e.detail||e;if(o&&fa[o])throw new fa[r](a,i);throw new la(a,i)}return t}function da(t){if(Array.isArray(t))throw new ua("",t);var e=t.message||Mo,r=t.detail||t;switch(!0){case t instanceof Xo:throw new Xo(e,r);case t instanceof Zo:throw new Zo(e,r);case t instanceof ta:throw new ta(e,r);case t instanceof ea:throw new ea(e,r);case t instanceof ra:throw new ra(e,r);case t instanceof na:throw new na(e,r);case t instanceof oa:throw new oa(e,r);case t instanceof aa:throw new aa(e,r);case t instanceof ia:throw new ia(e,r);case t instanceof ua:throw new ua(e,r);case t instanceof sa:throw new sa(e,r);default:throw new ca(e,r)}}var va=function(t,e){var r,n,o,a,i;switch(!0){case"object"===t:return o=(n=e).arg,a=n.param,i=[o],Array.isArray(a.keys)&&a.keys.length&&i.push(a.keys),!Qo.apply(null,i);case"array"===t:return!Vo(e.arg);case!1!==(r=Go(t)):return!Yo(e,r);default:return!Wo(t)(e.arg)}},ga=function(t,e){return fo(t)?!0!==e.optional||fo(e.defaultvalue)?null:e.defaultvalue:t},ya=function(t,e,r){var n;void 0===r&&(r=!1);var o=function(t,e){if(!Vo(e))throw new ca("params is not an array! Did something gone wrong when you generate the contract.json?");if(0===e.length)return[];if(!Vo(t))throw new ca("args is not an array! You might want to do: ES6 Array.from(arguments) or ES5 Array.prototype.slice.call(arguments)");switch(!0){case t.length==e.length:return t.map(function(t,r){return{arg:t,index:r,param:e[r]}});case!0===e[0].variable:var r=e[0].type;return t.map(function(t,n){return{arg:t,index:n,param:e[n]||{type:r,name:"_"}}});case t.lengthe.length&&1===e.length:var n,o=["any"];return!1!==(n=Go(e[0].type[0]))&&(o=n),t.map(function(t,r){return{arg:t,index:r,param:e[r]||{type:o,name:"_"}}});default:throw new ca("Could not understand your arguments and parameter structure!",{args:t,params:e})}}(t,e),a=o.filter(function(t){return!0===t.param.optional?function(t){var e=t.arg,r=t.param;return!(!wo(e)||r.type.length>r.type.filter(function(e){return va(e,t)}).length)}(t):!(t.param.type.length>t.param.type.filter(function(e){return va(e,t)}).length)});return r?((n={}).error=a,n.data=o.map(function(t){return t.arg}),n):a},ba=function(t,e){return!!t.filter(function(t){return t===e}).length},ma=function(t,e){var r=Object.keys(t);return ba(r,e)},_a=function(t){return!wo(t)};function wa(t,e){var r=bo(e,function(t,e){return!t[Ko]});return Jn(r,{})?t:function(t,e){var r={};return e=Yn(e),Zn(t,function(t,n,o){oe(r,e(t,n,o),t)}),r}(t,function(t,e){return function(t,e,r){var n;return r(t,function(t,r,o){if(e(t,r,o))return n=r,!1}),n}(r,Yn(function(t){return t.alias===e}),Zn)||e})}function ja(t,e){return lo(e,function(e,r){var n,o;return fo(t[r])||!0===e[Uo]&&_a(t[r])?ho({},e,((n={})[Bo]=!0,n)):((o={})[Ho]=t[r],o[Ro]=e[Ro],o[Uo]=e[Uo]||!1,o[Do]=e[Do]||!1,o[Lo]=e[Lo]||!1,o)})}function Sa(t,e){var r=function(t,e){var r=wa(t,e);return{pristineValues:lo(bo(e,function(t,e){return ma(r,e)}),function(t){return t.args}),checkAgainstAppProps:bo(e,function(t,e){return!ma(r,e)}),config:r}}(t,e),n=r.config,o=r.pristineValues;return[ja(n,r.checkAgainstAppProps),o]}var Oa=function(t){return Vo(t)?t:[t]};var ka=function(t,e){return!Vo(e)||function(t,e){return!!t.filter(function(t){return t===e}).length}(e,t)},Aa=function(t,e){try{return!!Et(e)&&e.apply(null,[t])}catch(t){return!1}};function Ea(t){return function(e,r){if(e[Bo])return e[Ho];var n=function(t,e){var r,n=[[t[Ho]],[(r={},r[Ro]=Oa(t[Ro]),r[Uo]=t[Uo],r)]];return Reflect.apply(e,null,n)}(e,t);if(n.length)throw new aa(r,n);if(!1!==e[Do]&&!ka(e[Ho],e[Do]))throw new oa(r);if(!1!==e[Lo]&&!Aa(e[Ho],e[Lo]))throw new ia(r);return e[Ho]}}var Ta=function(t,e){return Promise.resolve(Sa(t,e))};function xa(t,e,r,n){return void 0===t&&(t={}),Ta(t,e).then(function(t){return function(t,e){var r=t[0],n=t[1],o=lo(r,Ea(e));return ho(o,n)}(t,n)}).then(function(t){return ho({},t,r)})}var Pa=Qo,Ca=So,qa=Vo,za=function(t,e,r){return void 0===r&&(r=!1),new Promise(function(n,o){var a=ya(t,e,r);return r?a.error.length?o(a.error):n(a.data):a.length?o(a):n([])})},Na=function(t,e,r){void 0===r&&(r={});var n=r[zo],o=r[No],a=r[$o],i=r[Fo];return function(t,e,r,n,o,a){void 0===r&&(r=!1),void 0===n&&(n=!1),void 0===o&&(o=!1),void 0===a&&(a=!1);var i={};return i[Io]=t,i[qo]=e,!0===r&&(i[zo]=!0),Vo(n)&&(i[No]=n),Et(o)&&(i[$o]=o),io(a)&&(i[Fo]=a),i}.apply(null,[t,e,n,o,a,i])},Ia=function(t){return function(e,r,n){return void 0===n&&(n={}),xa(e,r,n,t)}}(ya),$a=ba,Fa=ma,Ja=function(t,e,r){var n;if(void 0===e&&(e=[]),void 0===r&&(r=!1),So(t)&&Vo(e)){var o={};return o[Po]=e,!0===r?o:((n={})[t]=o,n)}throw new ua("[createQuery] expect resolverName to be string and args to be array!",{resolverName:t,args:e})},Ma=function(t,e,r,n){var o;void 0===r&&(r={}),void 0===n&&(n=!1);var a={};if(a[To]=e,a[xo]=r,!0===n)return a;if(So(t))return(o={})[t]=a,o;throw new ua("[createMutation] expect resolverName to be string!",{resolverName:t,payload:e,condition:r})},Ra=function(t){return Object.keys(t)[0]},Ua=function(){return Math.floor(Date.now()/1e3)},Da=function(t,e){return void 0===e&&(e={}),La(e)?Promise.resolve(e):t.getContract()},Ha=function(t){return Fa(t,"data")&&!Fa(t,"error")?t.data:t},La=function(t){return t&&Pa(t)&&(Fa(t,"query")||Fa(t,"mutation"))},Ka="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function Ba(t){this.message=t}Ba.prototype=new Error,Ba.prototype.name="InvalidCharacterError";var Wa="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new Ba("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,n,o=0,a=0,i="";n=e.charAt(a++);~n&&(r=o%4?64*r+n:n,o++%4)?i+=String.fromCharCode(255&r>>(-2*o&6)):0)n=Ka.indexOf(n);return i};var Va=function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(Wa(t).replace(/(.)/g,function(t,e){var r=e.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}(e)}catch(t){return Wa(e)}};function Ga(t){this.message=t}Ga.prototype=new Error,Ga.prototype.name="InvalidTokenError";var Ya,Qa,Xa,Za,ti,ei,ri,ni,oi,ai=function(t,e){if("string"!=typeof t)throw new Ga("Invalid token specified");var r=!0===(e=e||{}).header?0:1;try{return JSON.parse(Va(t.split(".")[r]))}catch(t){throw new Ga("Invalid token specified: "+t.message)}},ii=Ga;function ui(t){if(Ca(t))return function(t){var e=t.iat||Math.floor(Date.now()/1e3);if(t.exp&&e>=t.exp){var r=new Date(t.exp).toISOString();throw new ca("Token has expired on "+r,t)}return t}(ai(t));throw new ca("Token must be a string!")}ai.InvalidTokenError=ii;Na("HS256",["string"]),Na(!1,["boolean","number","string"],((Ya={})[Fo]="exp",Ya[zo]=!0,Ya)),Na(!1,["boolean","number","string"],((Qa={})[Fo]="nbf",Qa[zo]=!0,Qa)),Na(!1,["boolean","string"],((Xa={})[Fo]="iss",Xa[zo]=!0,Xa)),Na(!1,["boolean","string"],((Za={})[Fo]="sub",Za[zo]=!0,Za)),Na(!1,["boolean","string"],((ti={})[Fo]="iss",ti[zo]=!0,ti)),Na(!1,["boolean"],((ei={})[zo]=!0,ei)),Na(!1,["boolean","string"],((ri={})[zo]=!0,ri)),Na(!1,["boolean","string"],((ni={})[zo]=!0,ni)),Na(!1,["boolean"],((oi={})[zo]=!0,oi));!function(){switch(!0){case"undefined"!=typeof WebSocket:return WebSocket;case"undefined"!=typeof MozWebSocket:return MozWebSocket;case"undefined"!=typeof window:return window.WebSocket||window.MozWebSocket;default:throw new ua("WebSocket is NOT SUPPORTED!")}}();var ci=Co[0],si=Co[1],fi=function(t){this.opts=t,this.extraHeader={},this.extraParams={},this.reqInterceptor(),this.resInterceptor()},li={headers:{configurable:!0}};li.headers.set=function(t){this.extraHeader=t},fi.prototype.request=function(t,e,r){var n;void 0===e&&(e={}),void 0===r&&(r={}),this.headers=r;var o=ho({},{_cb:Ua()},this.extraParams);if(this.opts.enableJsonp){var a=Ra(t);o=ho({},o,((n={}).jsonqlJsonpCallback=a,n)),t=t[a]}return this.fly.request(this.jsonqlEndpoint,t,ho({},{method:ci,params:o},e))},fi.prototype.reqInterceptor=function(){var t=this;this.fly.interceptors.request.use(function(e){console.info("request interceptor call");var r=t.getHeaders();for(var n in r)e.headers[n]=r[n];return e})},fi.prototype.processJsonp=function(t){return Ha(t)},fi.prototype.resInterceptor=function(){var t=this,e=t.opts.enableJsonp;this.fly.interceptors.response.use(function(r){console.info("response interceptor call"),t.cleanUp();var n=Ca(r.data)?JSON.parse(r.data):r.data;return e?t.processJsonp(n):Ha(n)},function(e){throw t.cleanUp(),console.error(e),new sa("Server side error",e)})},fi.prototype.getHeaders=function(){return this.opts.enableAuth?ho({},Eo,this.getAuthHeader(),this.extraHeader):ho({},Eo,this.extraHeader)},fi.prototype.cleanUp=function(){this.extraHeader={},this.extraParams={}},fi.prototype.get=function(){return this.opts.showContractDesc&&(this.extraParams=ho({},this.extraParams,Jo)),this.request({},{method:"GET"},this.contractHeader).then(ha).then(function(t){return console.info("144 get contract result",t),t.cache&&t.contract?t.contract:t})},fi.prototype.query=function(t,e){return void 0===e&&(e=[]),this.request(Ja(t,e)).then(ha)},fi.prototype.mutation=function(t,e,r){return void 0===e&&(e={}),void 0===r&&(r={}),this.request(Ma(t,e,r),{method:si}).then(ha)},Object.defineProperties(fi.prototype,li);var pi=function(t){function e(e,r){t.call(this,e),null!==r&&(this.fly=new r)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={storeIt:{configurable:!0},jsonqlEndpoint:{configurable:!0},jsonqlContract:{configurable:!0},jsonqlToken:{configurable:!0},jsonqlUserdata:{configurable:!0}};return r.storeIt.set=function(t){throw console.info("storeIt",t),qa(t)&&t.length>=2&&Reflect.apply(Y.set,Y,t),new ua("Expect argument to be array and least 2 items!")},r.jsonqlEndpoint.set=function(t){var e=Y.get("endpoint")||[];$a(e,t)||(e.push(t),this.storeId=["endpoint",e],this.endpointIndex=e.length-1)},r.jsonqlContract.set=function(t){var e=this.opts.storageKey,r=[e],n=t[0],o=t[1],a=Y.get(e)||[];a[this.endpointIndex||0]=n,r.push(a),o&&r.push(o),this.opts.keepContract&&(this.storeIt=r)},r.jsonqlToken.set=function(t){var e="credential",r=localStorage.get(e)||[];if(!$a(r,t)){var n=r.length-1;r[n]=t,this[e+"Index"]=n;var o=[e,r];if(this.opts.tokenExpired){var a=parseFloat(this.opts.tokenExpired);if(!isNaN(a)&&a>0){var i=Ua();o.push(i+parseFloat(a))}}return this.storeIt=o,this.jsonqlUserdata=this.decoder(t),t}return!1},r.jsonqlUserdata.set=function(t){var e=["userdata",t];return t.exp&&e.push(t.exp),Reflect.apply(Y.set,Y,e)},r.jsonqlEndpoint.get=function(){var t=Y.get("endpoint");if(!t){var e=this.opts,r=[e.hostname,e.jsonqlPath].join("/");return this.jsonqlEndpoint=r,r}return t[this.endpointIndex]},r.jsonqlContract.get=function(){var t=this.opts.storageKey;return(Y.get(t)||[])[this.endpointIndex]||!1},r.jsonqlToken.get=function(){var t="credential",e=localStorage.get(t);return!!e&&e[this[t+"Index"]]},r.jsonqlUserdata.get=function(){return Q.get("userdata")},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),e.enableAuth&&e.useJwt&&(this.setDecoder=ui)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={userdata:{configurable:!0},rawAuthToken:{configurable:!0},setDecoder:{configurable:!0}};return r.userdata.get=function(){return this.jsonqlUserdata},r.rawAuthToken.get=function(){return this.jsonqlToken},r.setDecoder.set=function(t){"function"==typeof t&&(this.decoder=t)},e.prototype.storeToken=function(t){return this.jsonqlToken=t},e.prototype.decoder=function(t){return t},e.prototype.getAuthHeader=function(){var t,e=this.rawAuthToken;return e?((t={})[this.opts.AUTH_HEADER]="Bearer "+e,t):{}},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={contractHeader:{configurable:!0}};return e.prototype.getContract=function(){var t=this.readContract();if(console.info("getContract first call",t),t&&Array.isArray(t)){var e=t[this.endpointIndex||0];if(e)return Promise.resolve(e)}return this.get().then(this.storeContract.bind(this))},r.contractHeader.get=function(){var t={};return!1!==this.opts.contractKey&&(t[this.opts.contractKeyName]=this.opts.contractKey),t},e.prototype.storeContract=function(t){if(!La(t))throw new ua("Contract is malformed!");var e=[t];if(this.opts.contractExpired){var r=parseFloat(this.opts.contractExpired);!isNaN(r)&&r>0&&e.push(r)}return this.jsonqlContract=e,console.info("storeContract return result",t),t},e.prototype.readContract=function(){return La(this.opts.contract)?this.opts.contract:Y.get(this.opts.storageKey)},Object.defineProperties(e.prototype,r),e}(fi))),hi=new WeakMap,di=new WeakMap;var vi=function(t){void 0===t&&(t={}),t.logger&&"function"==typeof t.logger&&(this.logger=t.logger),this.keep=t.keep,this.result=t.keep?[]:null,this.normalStore=new Map,this.lazyStore=new Map},gi={$done:{configurable:!0},normalStore:{configurable:!0},lazyStore:{configurable:!0}};vi.prototype.logger=function(){},vi.prototype.$on=function(t,e,r){var n=this;void 0===r&&(r=null);this.validate(t,e);var o=this.takeFromStore(t);if(!1===o)return this.logger("$on",t+" callback is not in lazy store"),this.addToNormalStore(t,"on",e,r);this.logger("$on",t+" found in lazy store");var a=0;return o.forEach(function(o){var i=o[0],u=o[1],c=o[2];if(c&&"on"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);n.run(e,i,r||u),a+=n.addToNormalStore(t,"on",e,r||u)}),a},vi.prototype.$once=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=this.takeFromStore(t);this.normalStore;if(!1===n)return this.logger("$once",t+" not in the lazy store"),this.addToNormalStore(t,"once",e,r);this.logger("$once",n);var o=Array.from(n)[0],a=o[0],i=o[1],u=o[2];if(u&&"once"!==u)throw new Error("You are trying to register an event already been taken by other type: "+u);this.run(e,a,r||i),this.$off(t)},vi.prototype.$only=function(t,e,r){var n=this;void 0===r&&(r=null),this.validate(t,e);var o=!1,a=this.takeFromStore(t);(this.normalStore.has(t)||(this.logger("$only",t+" add to store"),o=this.addToNormalStore(t,"only",e,r)),!1!==a)&&(this.logger("$only",t+" found data in lazy store to execute"),Array.from(a).forEach(function(t){var o=t[0],a=t[1],i=t[2];if(i&&"only"!==i)throw new Error("You are trying to register an event already been taken by other type: "+i);n.run(e,o,r||a)}));return o},vi.prototype.$onlyOnce=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=!1,o=this.takeFromStore(t);if(this.normalStore.has(t)||(this.logger("$onlyOnce",t+" add to store"),n=this.addToNormalStore(t,"onlyOnce",e,r)),!1!==o){this.logger("$onlyOnce",o);var a=Array.from(o)[0],i=a[0],u=a[1],c=a[2];if(c&&"onlyOnce"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);this.run(e,i,r||u),this.$off(t)}return n},vi.prototype.$replace=function(t,e,r,n){if(void 0===r&&(r=null),void 0===n&&(n="on"),this.validateType(n)){this.$off(t);var o=this["$"+n];return Reflect.apply(o,this,[t,e,r])}throw new Error(n+" is not supported!")},vi.prototype.$trigger=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1),this.validateEvt(t);var o=0,a=this.normalStore;if(this.logger("$trigger",a),a.has(t)){this.logger("$trigger",t,"found");for(var i=Array.from(a.get(t)),u=i.length,c=!1,s=0;s0;)n[o]=arguments[o+2];if(t.has(e)?(this.logger("addToStore",e+" existed"),r=t.get(e)):(this.logger("addToStore","create new Set for "+e),r=new Set),n.length>2)if(Array.isArray(n[0])){var a=n[2];this.checkTypeInLazyStore(e,a)||r.add(n)}else this.checkContentExist(n,r)||(this.logger("addToStore","insert new",n),r.add(n));else r.add(n);return t.set(e,r),[t,r.size]},vi.prototype.checkContentExist=function(t,e){return!!Array.from(e).filter(function(e){return e[0]===t[0]}).length},vi.prototype.checkTypeInStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.$get(t,!0);return!1===r||!r.filter(function(t){var r=t[3];return e!==r}).length},vi.prototype.checkTypeInLazyStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.lazyStore.get(t);return this.logger("checkTypeInLazyStore",r),!!r&&!!Array.from(r).filter(function(t){return t[2]!==e}).length},vi.prototype.addToNormalStore=function(t,e,r,n){if(void 0===n&&(n=null),this.logger("addToNormalStore",t,e,"add to normal store"),this.checkTypeInStore(t,e)){this.logger(e+" can add to "+t+" store");var o=this.hashFnToKey(r),a=[this.normalStore,t,o,r,n,e],i=Reflect.apply(this.addToStore,this,a),u=i[0],c=i[1];return this.normalStore=u,c}return!1},vi.prototype.addToLazyStore=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1);var o=[this.lazyStore,t,this.toArray(e),r];n&&o.push(n);var a=Reflect.apply(this.addToStore,this,o),i=a[0],u=a[1];return this.lazyStore=i,u},vi.prototype.toArray=function(t){return Array.isArray(t)?t:[t]},gi.normalStore.set=function(t){hi.set(this,t)},gi.normalStore.get=function(){return hi.get(this)},gi.lazyStore.set=function(t){di.set(this,t)},gi.lazyStore.get=function(){return di.get(this)},vi.prototype.hashFnToKey=function(t){return t.toString().split("").reduce(function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t},0)+""},Object.defineProperties(vi.prototype,gi);var yi=new vi,bi=function(t,e,r,n){return function(){for(var r=[],o=arguments.length;o--;)r[o]=arguments[o];var a=n.auth[e].params,i=a.map(function(t,e){return r[e]}),u=r[a.length]||{};return za(r,a).then(function(){return t.query.apply(t,[e,i,u])}).catch(da)}},mi=function(t,e,r){var n={query:{},mutation:{},auth:{}},o=function(e){n.query[e]=function(){for(var n=[],o=arguments.length;o--;)n[o]=arguments[o];var a=r.query[e].params,i=a.map(function(t,e){return n[e]}),u=n[a.length]||{};return za(i,a).then(function(){return t.query.apply(t,[e,i,u])}).catch(da)}};for(var a in r.query)o(a);var i=function(e){n.mutation[e]=function(n,o,a){void 0===a&&(a={});var i=[n,o],u=r.mutation[e].params;return za(i,u).then(function(){return t.mutation.apply(t,[e,n,o,a])}).catch(da)}};for(var u in r.mutation)i(u);if(e.enableAuth&&r.auth){var c=e.loginHandlerName,s=e.logoutHandlerName;r.auth[c]&&(n[c]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=bi(t,c,0,r);return o.apply(null,e).then(t.postLoginAction).then(function(t){return yi.$trigger("login",t),t})}),r.auth[s]?n[s]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=bi(t,s,0,r);return o.apply(null,e).then(t.postLogoutAction).then(function(t){return yi.$trigger("logout",t),t})}:n[s]=function(){t.postLogoutAction("continue"),yi.$trigger("logout","continue")},n.userdata=function(){return t.userdata}}return n.returnInstance&&(n.jsonqlClientInstance=t),n.getToken=function(){return t.rawAuthToken},n.eventEmitter=yi,n},_i={contract:!1,MUTATION_ARGS:["name","payload","conditions"],CONTENT_TYPE:Ao,BEARER:"Bearer",AUTH_HEADER:"Authorization"},wi={hostname:Na([window.location.protocol,window.location.host].join("//"),["string"]),jsonqlPath:Na("jsonql",["string"]),loginHandlerName:Na("login",["string"]),logoutHandlerName:Na("logout",["string"]),enableJsonp:Na(!1,["boolean"]),enableAuth:Na(!1,["boolean"]),useJwt:Na(!0,["boolean"]),useLocalstorage:Na(!0,["boolean"]),storageKey:Na("storageKey",["string"]),authKey:Na("authKey",["string"]),contractExpired:Na(0,["number"]),keepContract:Na(!0,["boolean"]),showContractDesc:Na(!1,["boolean"]),contractKey:Na(!1,["boolean"]),contractKeyName:Na("X-JSONQL-CV-KEY",["string"]),enableTimeout:Na(!1,["boolean"]),timeout:Na(5e3,["number"]),returnInstance:Na(!1,["boolean"]),allowReturnRawToken:Na(!1,["boolean"]),debugOn:Na(!1,["boolean"])};return function(t,e){return void 0===t&&(t={}),void 0===e&&(e=null),function(t){var e=t.contract;return Ia(t,wi,_i).then(function(t){return t.contract=e,t})}(t).then(function(t){return{baseClient:new pi(t,e),opts:t}}).then(function(t){var e=t.baseClient,r=t.opts;return Da(e,r.contract).then(function(t){return mi(e,r,t)})})}}); //# sourceMappingURL=jsonql-client.umd.js.map diff --git a/packages/http-client/dist/jsonql-client.umd.js.map b/packages/http-client/dist/jsonql-client.umd.js.map index 900b7c83..d2673b6b 100644 --- a/packages/http-client/dist/jsonql-client.umd.js.map +++ b/packages/http-client/dist/jsonql-client.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"jsonql-client.umd.js","sources":["../node_modules/store/plugins/defaults.js","../node_modules/store/plugins/expire.js"],"sourcesContent":["module.exports = defaultsPlugin\n\nfunction defaultsPlugin() {\n\tvar defaultValues = {}\n\t\n\treturn {\n\t\tdefaults: defaults,\n\t\tget: get\n\t}\n\t\n\tfunction defaults(_, values) {\n\t\tdefaultValues = values\n\t}\n\t\n\tfunction get(super_fn, key) {\n\t\tvar val = super_fn()\n\t\treturn (val !== undefined ? val : defaultValues[key])\n\t}\n}\n","var namespace = 'expire_mixin'\n\nmodule.exports = expirePlugin\n\nfunction expirePlugin() {\n\tvar expirations = this.createStore(this.storage, null, this._namespacePrefix+namespace)\n\t\n\treturn {\n\t\tset: expire_set,\n\t\tget: expire_get,\n\t\tremove: expire_remove,\n\t\tgetExpiration: getExpiration,\n\t\tremoveExpiredKeys: removeExpiredKeys\n\t}\n\t\n\tfunction expire_set(super_fn, key, val, expiration) {\n\t\tif (!this.hasNamespace(namespace)) {\n\t\t\texpirations.set(key, expiration)\n\t\t}\n\t\treturn super_fn()\n\t}\n\t\n\tfunction expire_get(super_fn, key) {\n\t\tif (!this.hasNamespace(namespace)) {\n\t\t\t_checkExpiration.call(this, key)\n\t\t}\n\t\treturn super_fn()\n\t}\n\t\n\tfunction expire_remove(super_fn, key) {\n\t\tif (!this.hasNamespace(namespace)) {\n\t\t\texpirations.remove(key)\n\t\t}\n\t\treturn super_fn()\n\t}\n\t\n\tfunction getExpiration(_, key) {\n\t\treturn expirations.get(key)\n\t}\n\t\n\tfunction removeExpiredKeys(_) {\n\t\tvar keys = []\n\t\tthis.each(function(val, key) {\n\t\t\tkeys.push(key)\n\t\t})\n\t\tfor (var i=0; i await jsonqlClient( Object.assign({ -- Gitee From 79c9186028c8ab424de42daca8614c8b1393388c Mon Sep 17 00:00:00 2001 From: Joel Chu Date: Fri, 26 Jul 2019 14:07:30 +0800 Subject: [PATCH 3/5] Rebuild --- packages/http-client/dist/full.js | 2 +- packages/http-client/dist/jsonql-client.umd.js | 2 +- packages/http-client/src/full.js | 2 +- packages/http-client/src/lib/base/base-cls.js | 6 +++--- packages/http-client/src/lib/base/http-cls.js | 3 +-- packages/http-client/tests/qunit/tests/base-test.js | 2 -- packages/http-client/tests/qunit/webroot/index.html | 4 ++-- 7 files changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/http-client/dist/full.js b/packages/http-client/dist/full.js index b6d2c4ca..b45007b5 100644 --- a/packages/http-client/dist/full.js +++ b/packages/http-client/dist/full.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).jsonqlClient=e()}(this,function(){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t,e){return t(e={exports:{}},e.exports),e.exports}var r,n=e(function(t,e){var r;r=function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(t,e,r){var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};t.exports={type:function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},isObject:function(t,e){return e?"object"===this.type(t):t&&"object"===(void 0===t?"undefined":n(t))},isFormData:function(t){return"undefined"!=typeof FormData&&t instanceof FormData},trim:function(t){return t.replace(/(^\s*)|(\s*$)/g,"")},encode:function(t){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")},formatParams:function(t){var e="",r=!0,n=this;if(!this.isObject(t))return t;return function t(o,i){var a=n.encode,u=n.type(o);if("array"==u)o.forEach(function(e,r){n.isObject(e)||(r=""),t(e,i+"%5B"+r+"%5D")});else if("object"==u)for(var c in o)t(o[c],i?i+"%5B"+a(c)+"%5D":a(c));else r||(e+="&"),r=!1,e+=i+"="+a(o)}(t,""),e},merge:function(t,e){for(var r in e)t.hasOwnProperty(r)?this.isObject(e[r],1)&&this.isObject(t[r],1)&&this.merge(t[r],e[r]):t[r]=e[r];return t}}},,function(t,e,r){var n=function(){function t(t,e){for(var r=0;r0&&(t+=(-1===t.indexOf("?")?"?":"&")+w.join("&")),a.open(r.method,t);try{a.withCredentials=!!r.withCredentials,a.timeout=r.timeout||0,"stream"!==y&&(a.responseType=y)}catch(t){}var j=r.headers[u]||r.headers[c],O="application/x-www-form-urlencoded";for(var S in o.trim((j||"").toLowerCase())===O?e=o.formatParams(e):o.isFormData(e)||-1===["object","array"].indexOf(o.type(e))||(O="application/json;charset=utf-8",e=JSON.stringify(e)),j||b||(r.headers[u]=O),r.headers)if(S===u&&o.isFormData(e))delete r.headers[S];else try{a.setRequestHeader(S,r.headers[S])}catch(t){}function k(t,e,n){v(l.p,function(){if(t){n&&(e.request=r);var o=t.call(l,e,Promise);e=void 0===o?e:o}d(e)||(e=Promise[0===n?"resolve":"reject"](e)),e.then(function(t){s(t)}).catch(function(t){h(t)})})}function E(t){t.engine=a,k(l.onerror,t,-1)}function A(t,e){this.message=t,this.status=e}a.onload=function(){try{var t=a.response||a.responseText;t&&r.parseJson&&-1!==(a.getResponseHeader(u)||"").indexOf("json")&&!o.isObject(t)&&(t=JSON.parse(t));var e=a.responseHeaders;if(!e){e={};var n=(a.getAllResponseHeaders()||"").split("\r\n");n.pop(),n.forEach(function(t){if(t){var r=t.split(":")[0];e[r]=a.getResponseHeader(r)}})}var i=a.status,c=a.statusText,s={data:t,headers:e,status:i,statusText:c};if(o.merge(s,a._response),i>=200&&i<300||304===i)s.engine=a,s.request=r,k(l.handler,s,0);else{var f=new A(c,i);f.response=s,E(f)}}catch(f){E(new A(f.msg,a.status))}},a.onerror=function(t){E(new A(t.msg||"Network Error",0))},a.ontimeout=function(){E(new A("timeout [ "+a.timeout+"ms ]",1))},a._options=r,setTimeout(function(){a.send(b?null:e)},0)}(n):s(n)},function(t){h(t)})})});return h.engine=a,h}},{key:"all",value:function(t){return Promise.all(t)}},{key:"spread",value:function(t){return function(e){return t.apply(null,e)}}}]),t}();a.default=a,["get","post","put","patch","head","delete"].forEach(function(t){a.prototype[t]=function(e,r,n){return this.request(e,r,o.merge({method:t},n))}}),["lock","unlock","clear"].forEach(function(t){a.prototype[t]=function(){this.interceptors.request[t]()}}),t.exports=a}])},t.exports=r()}),o=(r=n)&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,i=Object.assign?Object.assign:function(t,e,r,n){for(var o=arguments,i=1;i=0;e--){var r=A().key(e);t(x(r),r)}},remove:function(t){return A().removeItem(t)},clearAll:function(){return A().clear()}};function A(){return k.localStorage}function x(t){return A().getItem(t)}var T=s.trim,P={name:"cookieStorage",read:function(t){if(!t||!z(t))return null;var e="(?:^|.*;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(C.cookie.replace(new RegExp(e),"$1"))},write:function(t,e){if(!t)return;C.cookie=escape(t)+"="+escape(e)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"},each:q,remove:N,clearAll:function(){q(function(t,e){N(e)})}},C=s.Global.document;function q(t){for(var e=C.cookie.split(/; ?/g),r=e.length-1;r>=0;r--)if(T(e[r])){var n=e[r].split("="),o=unescape(n[0]);t(unescape(n[1]),o)}}function N(t){t&&z(t)&&(C.cookie=escape(t)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function z(t){return new RegExp("(?:^|;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(C.cookie)}var I=function(){var t={};return{defaults:function(e,r){t=r},get:function(e,r){var n=e();return void 0!==n?n:t[r]}}};var $="expire_mixin",F=function(){var t=this.createStore(this.storage,null,this._namespacePrefix+$);return{set:function(e,r,n,o){this.hasNamespace($)||t.set(r,o);return e()},get:function(t,r){this.hasNamespace($)||e.call(this,r);return t()},remove:function(e,r){this.hasNamespace($)||t.remove(r);return e()},getExpiration:function(e,r){return t.get(r)},removeExpiredKeys:function(t){var r=[];this.each(function(t,e){r.push(e)});for(var n=0;n>>8,r[2*n+1]=a%256}return r},decompressFromUint8Array:function(e){if(null==e)return i.decompress(e);for(var r=new Array(e.length/2),n=0,o=r.length;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=a[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++),a[s]=p++,f=String(c)}if(""!==f){if(Object.prototype.hasOwnProperty.call(u,f)){if(f.charCodeAt(0)<256){for(n=0;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=a[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++)}for(o=2,n=0;n>=1;for(;;){if(v<<=1,g==e-1){d.push(r(v));break}g++}return d.join("")},decompress:function(t){return null==t?"":""==t?null:i._decompress(t.length,32768,function(e){return t.charCodeAt(e)})},_decompress:function(e,r,n){var o,i,a,u,c,s,f,l=[],p=4,h=4,d=3,v="",g=[],y={val:n(0),position:r,index:1};for(o=0;o<3;o+=1)l[o]=o;for(a=0,c=Math.pow(2,2),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;switch(a){case 0:for(a=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;f=t(a);break;case 1:for(a=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;f=t(a);break;case 2:return""}for(l[3]=f,i=f,g.push(f);;){if(y.index>e)return"";for(a=0,c=Math.pow(2,d),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;switch(f=a){case 0:for(a=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;l[h++]=t(a),f=h-1,p--;break;case 1:for(a=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;l[h++]=t(a),f=h-1,p--;break;case 2:return g.join("")}if(0==p&&(p=Math.pow(2,d),d++),l[f])v=l[f];else{if(f!==h)return null;v=i+i.charAt(0)}g.push(v),l[h++]=i+v.charAt(0),i=v,0==--p&&(p=Math.pow(2,d),d++)}}};return i}();null!=t&&(t.exports=e)});var B=[E,P],K=[I,F,D,function(){return{get:function(t,e){var r=t(e);if(!r)return r;var n=L.decompress(r);return null==n?r:this._deserialize(n)},set:function(t,e,r){var n=L.compress(this._serialize(r));t(e,n)}}}],W=j.createStore(B,K),G=s.Global;function V(){return G.sessionStorage}function Y(t){return V().getItem(t)}var X=[{name:"sessionStorage",read:Y,write:function(t,e){return V().setItem(t,e)},each:function(t){for(var e=V().length-1;e>=0;e--){var r=V().key(e);t(Y(r),r)}},remove:function(t){return V().removeItem(t)},clearAll:function(){return V().clear()}},P],Q=[I,F],Z=j.createStore(X,Q),tt=W,et=Z,rt="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},nt="object"==typeof rt&&rt&&rt.Object===Object&&rt,ot="object"==typeof self&&self&&self.Object===Object&&self,it=nt||ot||Function("return this")(),at=it.Symbol,ut=Object.prototype,ct=ut.hasOwnProperty,st=ut.toString,ft=at?at.toStringTag:void 0;var lt=Object.prototype.toString;var pt="[object Null]",ht="[object Undefined]",dt=at?at.toStringTag:void 0;function vt(t){return null==t?void 0===t?ht:pt:dt&&dt in Object(t)?function(t){var e=ct.call(t,ft),r=t[ft];try{t[ft]=void 0;var n=!0}catch(t){}var o=st.call(t);return n&&(e?t[ft]=r:delete t[ft]),o}(t):function(t){return lt.call(t)}(t)}function gt(t){return null!=t&&"object"==typeof t}var yt="[object Symbol]";function bt(t){return"symbol"==typeof t||gt(t)&&vt(t)==yt}function mt(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r0){if(++Zt>=Vt)return arguments[0]}else Zt=0;return Qt.apply(void 0,arguments)});function ne(t){return t!=t}function oe(t,e,r){return e==e?function(t,e,r){for(var n=r-1,o=t.length;++n-1&&t%1==0&&t-1&&t%1==0&&t<=de}function ge(t){return null!=t&&ve(t.length)&&!Ct(t)}var ye=Object.prototype;function be(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||ye)}var me="[object Arguments]";function _e(t){return gt(t)&&vt(t)==me}var we=Object.prototype,je=we.hasOwnProperty,Oe=we.propertyIsEnumerable,Se=_e(function(){return arguments}())?_e:function(t){return gt(t)&&je.call(t,"callee")&&!Oe.call(t,"callee")};var ke="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ee=ke&&"object"==typeof module&&module&&!module.nodeType&&module,Ae=Ee&&Ee.exports===ke?it.Buffer:void 0,xe=(Ae?Ae.isBuffer:void 0)||function(){return!1},Te={};Te["[object Float32Array]"]=Te["[object Float64Array]"]=Te["[object Int8Array]"]=Te["[object Int16Array]"]=Te["[object Int32Array]"]=Te["[object Uint8Array]"]=Te["[object Uint8ClampedArray]"]=Te["[object Uint16Array]"]=Te["[object Uint32Array]"]=!0,Te["[object Arguments]"]=Te["[object Array]"]=Te["[object ArrayBuffer]"]=Te["[object Boolean]"]=Te["[object DataView]"]=Te["[object Date]"]=Te["[object Error]"]=Te["[object Function]"]=Te["[object Map]"]=Te["[object Number]"]=Te["[object Object]"]=Te["[object RegExp]"]=Te["[object Set]"]=Te["[object String]"]=Te["[object WeakMap]"]=!1;var Pe="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ce=Pe&&"object"==typeof module&&module&&!module.nodeType&&module,qe=Ce&&Ce.exports===Pe&&nt.process,Ne=function(){try{var t=Ce&&Ce.require&&Ce.require("util").types;return t||qe&&qe.binding&&qe.binding("util")}catch(t){}}(),ze=Ne&&Ne.isTypedArray,Ie=ze?function(t){return function(e){return t(e)}}(ze):function(t){return gt(t)&&ve(t.length)&&!!Te[vt(t)]},$e=Object.prototype.hasOwnProperty;function Fe(t,e){var r=_t(t),n=!r&&Se(t),o=!r&&!n&&xe(t),i=!r&&!n&&!o&&Ie(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r-1},rr.prototype.set=function(t,e){var r=this.__data__,n=tr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var nr=Lt(it,"Map");function or(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function ir(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e=n?t:function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++nu))return!1;var s=i.get(t);if(s&&i.get(e))return s==e;var f=-1,l=!0,p=r&vn?new pn:void 0;for(i.set(t,e),i.set(e,t);++f1?e[n-1]:void 0,i=n>2?e[2]:void 0;for(o=yo.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!kt(r))return!1;var n=typeof e;return!!("number"==n?ge(r)&&ue(e,r.length):"string"==n&&e in r)&&se(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r-1;);return r}(n,o),function(t,e){for(var r=t.length;r--&&oe(e,t[r],0)>-1;);return r}(n,o)+1).join("")}function ko(t){return!!_t(t)||null!=t&&""!==So(t)}var Eo=function(t){return!fo(t)&&!ho(parseFloat(t))},Ao=function(t){return""!==So(t)&&fo(t)},xo=function(t){return function(t){return!0===t||!1===t||gt(t)&&vt(t)==lo}(t)},To=function(t,e){return void 0===e&&(e=!0),!vo(t)&&""!==t&&""!==So(t)&&(!1===e||!0===e&&!function(t){return null===t}(t))},Po="application/vnd.api+json",Co={Accept:Po,"Content-Type":[Po,"charset=utf-8"].join(";")},qo="payload",No="condition",zo="args",Io=["POST","PUT"],$o="type",Fo="optional",Jo="enumv",Ro="args",Mo="checker",Uo="alias",Do={desc:"y"},Ho="No message",Lo=$o,Bo=Fo,Ko=Jo,Wo=Ro,Go=Mo,Vo=Uo,Yo="continue",Xo=function(t){switch(t){case"number":return Eo;case"string":return Ao;case"boolean":return xo;default:return To}},Qo=function(t,e){return void 0===e&&(e=""),!!_t(t)&&(""===e||""===So(e)||!(t.filter(function(t){return!Xo(e)(t)}).length>0))},Zo=function(t){if(t.indexOf("array.<")>-1&&t.indexOf(">")>-1){var e=t.replace("array.<","").replace(">","");return e.indexOf("|")?e.split("|"):[e]}return!1},ti=function(t,e){var r=t.arg;return e.length>1?!r.filter(function(t){return!(e.length>e.filter(function(e){return!Xo(e)(t)}).length)}).length:e.length>e.filter(function(t){return!Qo(r,t)}).length},ei=function(t,e){if(void 0===e&&(e=null),kr(t)){if(!e)return!0;if(Qo(e))return!e.filter(function(e){var r=t[e.name];return!(e.type.length>e.type.filter(function(t){var e;return!!vo(r)||(!1!==(e=Zo(t))?!ti({arg:r},e):!Xo(t)(r))}).length)}).length}return!1},ri=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 406},r.name.get=function(){return"Jsonql406Error"},Object.defineProperties(e,r),e}(Error),ni=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"Jsonql500Error"},Object.defineProperties(e,r),e}(Error),oi=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(e,r),e}(Error),ii=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(e,r),e}(Error),ai=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(e,r),e}(Error),ui=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 404},r.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(e,r),e}(Error),ci=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(e,r),e}(Error),si=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(e,r),e}(Error),fi=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(e,r),e}(Error),li=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(e,r),e}(Error),pi=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0},statusCode:{configurable:!0}};return r.name.get=function(){return"JsonqlError"},r.statusCode.get=function(){return-1},Object.defineProperties(e,r),e}(Error),hi=function(t){function e(r,n){t.call(this,n),this.statusCode=r,this.className=e.name}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlServerError"},Object.defineProperties(e,r),e}(Error),di=Object.freeze({Jsonql406Error:ri,Jsonql500Error:ni,JsonqlAuthorisationError:oi,JsonqlContractAuthError:ii,JsonqlResolverAppError:ai,JsonqlResolverNotFoundError:ui,JsonqlEnumError:ci,JsonqlTypeError:si,JsonqlCheckerError:fi,JsonqlValidationError:li,JsonqlError:pi,JsonqlServerError:hi}),vi=pi,gi=function(t,e){return!!Object.keys(t).filter(function(t){return e===t}).length};function yi(t){if(gi(t,"error")){var e=t.error,r=e.className,n=e.name,o=r||n,i=e.message||Ho,a=e.detail||e;if(o&&di[o])throw new di[r](i,a);throw new vi(i,a)}return t}function bi(t){if(Array.isArray(t))throw new li("",t);var e=t.message||Ho,r=t.detail||t;switch(!0){case t instanceof ri:throw new ri(e,r);case t instanceof ni:throw new ni(e,r);case t instanceof oi:throw new oi(e,r);case t instanceof ii:throw new ii(e,r);case t instanceof ai:throw new ai(e,r);case t instanceof ui:throw new ui(e,r);case t instanceof ci:throw new ci(e,r);case t instanceof si:throw new si(e,r);case t instanceof fi:throw new fi(e,r);case t instanceof li:throw new li(e,r);case t instanceof hi:throw new hi(e,r);default:throw new pi(e,r)}}var mi=function(t,e){var r,n,o,i,a;switch(!0){case"object"===t:return o=(n=e).arg,i=n.param,a=[o],Array.isArray(i.keys)&&i.keys.length&&a.push(i.keys),!ei.apply(null,a);case"array"===t:return!Qo(e.arg);case!1!==(r=Zo(t)):return!ti(e,r);default:return!Xo(t)(e.arg)}},_i=function(t,e){return vo(t)?!0!==e.optional||vo(e.defaultvalue)?null:e.defaultvalue:t},wi=function(t,e,r){var n;void 0===r&&(r=!1);var o=function(t,e){if(!Qo(e))throw new pi("params is not an array! Did something gone wrong when you generate the contract.json?");if(0===e.length)return[];if(!Qo(t))throw new pi("args is not an array! You might want to do: ES6 Array.from(arguments) or ES5 Array.prototype.slice.call(arguments)");switch(!0){case t.length==e.length:return t.map(function(t,r){return{arg:t,index:r,param:e[r]}});case!0===e[0].variable:var r=e[0].type;return t.map(function(t,n){return{arg:t,index:n,param:e[n]||{type:r,name:"_"}}});case t.lengthe.length&&1===e.length:var n,o=["any"];return!1!==(n=Zo(e[0].type[0]))&&(o=n),t.map(function(t,r){return{arg:t,index:r,param:e[r]||{type:o,name:"_"}}});default:throw new pi("Could not understand your arguments and parameter structure!",{args:t,params:e})}}(t,e),i=o.filter(function(t){return!0===t.param.optional?function(t){var e=t.arg,r=t.param;return!(!ko(e)||r.type.length>r.type.filter(function(e){return mi(e,t)}).length)}(t):!(t.param.type.length>t.param.type.filter(function(e){return mi(e,t)}).length)});return r?((n={}).error=i,n.data=o.map(function(t){return t.arg}),n):i},ji=function(t,e){return!!t.filter(function(t){return t===e}).length},Oi=function(t,e){var r=Object.keys(t);return ji(r,e)},Si=function(t){return!ko(t)};function ki(t,e){var r=jo(e,function(t,e){return!t[Vo]});return Dn(r,{})?t:function(t,e){var r={};return e=to(e),no(t,function(t,n,o){ce(r,e(t,n,o),t)}),r}(t,function(t,e){return function(t,e,r){var n;return r(t,function(t,r,o){if(e(t,r,o))return n=r,!1}),n}(r,to(function(t){return t.alias===e}),no)||e})}function Ei(t,e){return go(e,function(e,r){var n,o;return vo(t[r])||!0===e[Bo]&&Si(t[r])?bo({},e,((n={})[Yo]=!0,n)):((o={})[Wo]=t[r],o[Lo]=e[Lo],o[Bo]=e[Bo]||!1,o[Ko]=e[Ko]||!1,o[Go]=e[Go]||!1,o)})}function Ai(t,e){var r=function(t,e){var r=ki(t,e);return{pristineValues:go(jo(e,function(t,e){return Oi(r,e)}),function(t){return t.args}),checkAgainstAppProps:jo(e,function(t,e){return!Oi(r,e)}),config:r}}(t,e),n=r.config,o=r.pristineValues;return[Ei(n,r.checkAgainstAppProps),o]}var xi=function(t){return Qo(t)?t:[t]};var Ti=function(t,e){return!Qo(e)||function(t,e){return!!t.filter(function(t){return t===e}).length}(e,t)},Pi=function(t,e){try{return!!Ct(e)&&e.apply(null,[t])}catch(t){return!1}};function Ci(t){return function(e,r){if(e[Yo])return e[Wo];var n=function(t,e){var r,n=[[t[Wo]],[(r={},r[Lo]=xi(t[Lo]),r[Bo]=t[Bo],r)]];return Reflect.apply(e,null,n)}(e,t);if(n.length)throw new si(r,n);if(!1!==e[Ko]&&!Ti(e[Wo],e[Ko]))throw new ci(r);if(!1!==e[Go]&&!Pi(e[Wo],e[Go]))throw new fi(r);return e[Wo]}}var qi=function(t,e){return Promise.resolve(Ai(t,e))};function Ni(t,e,r,n){return void 0===t&&(t={}),qi(t,e).then(function(t){return function(t,e){var r=t[0],n=t[1],o=go(r,Ci(e));return bo(o,n)}(t,n)}).then(function(t){return bo({},t,r)})}var zi=ei,Ii=Ao,$i=Qo,Fi=function(t,e,r){return void 0===r&&(r=!1),new Promise(function(n,o){var i=wi(t,e,r);return r?i.error.length?o(i.error):n(i.data):i.length?o(i):n([])})},Ji=function(t,e,r){void 0===r&&(r={});var n=r[Fo],o=r[Jo],i=r[Mo],a=r[Uo];return function(t,e,r,n,o,i){void 0===r&&(r=!1),void 0===n&&(n=!1),void 0===o&&(o=!1),void 0===i&&(i=!1);var a={};return a[Ro]=t,a[$o]=e,!0===r&&(a[Fo]=!0),Qo(n)&&(a[Jo]=n),Ct(o)&&(a[Mo]=o),fo(i)&&(a[Uo]=i),a}.apply(null,[t,e,n,o,i,a])},Ri=function(t){return function(e,r,n){return void 0===n&&(n={}),Ni(e,r,n,t)}}(wi),Mi=ji,Ui=Oi,Di=function(t,e,r){var n;if(void 0===e&&(e=[]),void 0===r&&(r=!1),Ao(t)&&Qo(e)){var o={};return o[zo]=e,!0===r?o:((n={})[t]=o,n)}throw new li("[createQuery] expect resolverName to be string and args to be array!",{resolverName:t,args:e})},Hi=function(t,e,r,n){var o;void 0===r&&(r={}),void 0===n&&(n=!1);var i={};if(i[qo]=e,i[No]=r,!0===n)return i;if(Ao(t))return(o={})[t]=i,o;throw new li("[createMutation] expect resolverName to be string!",{resolverName:t,payload:e,condition:r})},Li=function(t){return Object.keys(t)[0]},Bi=function(){return Math.floor(Date.now()/1e3)},Ki=function(t,e){return void 0===e&&(e={}),Gi(e)?Promise.resolve(e):t.getContract()},Wi=function(t){return Ui(t,"data")&&!Ui(t,"error")?t.data:t},Gi=function(t){return t&&zi(t)&&(Ui(t,"query")||Ui(t,"mutation"))},Vi="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function Yi(t){this.message=t}Yi.prototype=new Error,Yi.prototype.name="InvalidCharacterError";var Xi="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new Yi("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,n,o=0,i=0,a="";n=e.charAt(i++);~n&&(r=o%4?64*r+n:n,o++%4)?a+=String.fromCharCode(255&r>>(-2*o&6)):0)n=Vi.indexOf(n);return a};var Qi=function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(Xi(t).replace(/(.)/g,function(t,e){var r=e.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}(e)}catch(t){return Xi(e)}};function Zi(t){this.message=t}Zi.prototype=new Error,Zi.prototype.name="InvalidTokenError";var ta,ea,ra,na,oa,ia,aa,ua,ca,sa=function(t,e){if("string"!=typeof t)throw new Zi("Invalid token specified");var r=!0===(e=e||{}).header?0:1;try{return JSON.parse(Qi(t.split(".")[r]))}catch(t){throw new Zi("Invalid token specified: "+t.message)}},fa=Zi;function la(t){if(Ii(t))return function(t){var e=t.iat||Math.floor(Date.now()/1e3);if(t.exp&&e>=t.exp){var r=new Date(t.exp).toISOString();throw new pi("Token has expired on "+r,t)}return t}(sa(t));throw new pi("Token must be a string!")}sa.InvalidTokenError=fa;Ji("HS256",["string"]),Ji(!1,["boolean","number","string"],((ta={})[Uo]="exp",ta[Fo]=!0,ta)),Ji(!1,["boolean","number","string"],((ea={})[Uo]="nbf",ea[Fo]=!0,ea)),Ji(!1,["boolean","string"],((ra={})[Uo]="iss",ra[Fo]=!0,ra)),Ji(!1,["boolean","string"],((na={})[Uo]="sub",na[Fo]=!0,na)),Ji(!1,["boolean","string"],((oa={})[Uo]="iss",oa[Fo]=!0,oa)),Ji(!1,["boolean"],((ia={})[Fo]=!0,ia)),Ji(!1,["boolean","string"],((aa={})[Fo]=!0,aa)),Ji(!1,["boolean","string"],((ua={})[Fo]=!0,ua)),Ji(!1,["boolean"],((ca={})[Fo]=!0,ca));!function(){switch(!0){case"undefined"!=typeof WebSocket:return WebSocket;case"undefined"!=typeof MozWebSocket:return MozWebSocket;case"undefined"!=typeof window:return window.WebSocket||window.MozWebSocket;default:throw new li("WebSocket is NOT SUPPORTED!")}}();var pa=Io[0],ha=Io[1],da=function(t){this.opts=t,this.extraHeader={},this.extraParams={},this.reqInterceptor(),this.resInterceptor()},va={headers:{configurable:!0}};va.headers.set=function(t){this.extraHeader=t},da.prototype.request=function(t,e,r){var n;void 0===e&&(e={}),void 0===r&&(r={}),this.headers=r;var o=bo({},{_cb:Bi()},this.extraParams);if(this.opts.enableJsonp){var i=Li(t);o=bo({},o,((n={}).jsonqlJsonpCallback=i,n)),t=t[i]}return this.fly.request(this.jsonqlEndpoint,t,bo({},{method:pa,params:o},e))},da.prototype.reqInterceptor=function(){var t=this;this.fly.interceptors.request.use(function(e){console.info("request interceptor call");var r=t.getHeaders();for(var n in r)e.headers[n]=r[n];return e})},da.prototype.processJsonp=function(t){return Wi(t)},da.prototype.resInterceptor=function(){var t=this,e=t.opts.enableJsonp;this.fly.interceptors.response.use(function(r){console.info("response interceptor call"),t.cleanUp();var n=Ii(r.data)?JSON.parse(r.data):r.data;return e?t.processJsonp(n):Wi(n)},function(e){throw t.cleanUp(),console.error(e),new hi("Server side error",e)})},da.prototype.getHeaders=function(){return this.opts.enableAuth?bo({},Co,this.getAuthHeader(),this.extraHeader):bo({},Co,this.extraHeader)},da.prototype.cleanUp=function(){this.extraHeader={},this.extraParams={}},da.prototype.get=function(){return this.opts.showContractDesc&&(this.extraParams=bo({},this.extraParams,Do)),this.request({},{method:"GET"},this.contractHeader).then(yi).then(function(t){return console.info("144 get contract result",t),t.cache&&t.contract?t.contract:t})},da.prototype.query=function(t,e){return void 0===e&&(e=[]),this.request(Di(t,e)).then(yi)},da.prototype.mutation=function(t,e,r){return void 0===e&&(e={}),void 0===r&&(r={}),this.request(Hi(t,e,r),{method:ha}).then(yi)},Object.defineProperties(da.prototype,va);var ga=function(t){function e(e,r){t.call(this,e),null!==r&&(this.fly=new r)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={storeIt:{configurable:!0},jsonqlEndpoint:{configurable:!0},jsonqlContract:{configurable:!0},jsonqlToken:{configurable:!0},jsonqlUserdata:{configurable:!0}};return r.storeIt.set=function(t){throw console.info("storeIt",t),$i(t)&&t.length>=2&&Reflect.apply(tt.set,tt,t),new li("Expect argument to be array and least 2 items!")},r.jsonqlEndpoint.set=function(t){var e=tt.get("endpoint")||[];Mi(e,t)||(e.push(t),this.storeId=["endpoint",e],this.endpointIndex=e.length-1)},r.jsonqlContract.set=function(t){var e=this.opts.storageKey,r=[e],n=t[0],o=t[1],i=tt.get(e)||[];i[this.endpointIndex||0]=n,r.push(i),o&&r.push(o),this.opts.keepContract&&(this.storeIt=r)},r.jsonqlToken.set=function(t){var e="credential",r=localStorage.get(e)||[];if(!Mi(r,t)){var n=r.length-1;r[n]=t,this[e+"Index"]=n;var o=[e,r];if(this.opts.tokenExpired){var i=parseFloat(this.opts.tokenExpired);if(!isNaN(i)&&i>0){var a=Bi();o.push(a+parseFloat(i))}}return this.storeIt=o,this.jsonqlUserdata=this.decoder(t),t}return!1},r.jsonqlUserdata.set=function(t){var e=["userdata",t];return t.exp&&e.push(t.exp),Reflect.apply(tt.set,tt,e)},r.jsonqlEndpoint.get=function(){var t=tt.get("endpoint");if(!t){var e=this.opts,r=[e.hostname,e.jsonqlPath].join("/");return this.jsonqlEndpoint=r,r}return t[this.endpointIndex]},r.jsonqlContract.get=function(){var t=this.opts.storageKey;return(tt.get(t)||[])[this.endpointIndex]||!1},r.jsonqlToken.get=function(){var t="credential",e=localStorage.get(t);return!!e&&e[this[t+"Index"]]},r.jsonqlUserdata.get=function(){return et.get("userdata")},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),e.enableAuth&&e.useJwt&&(this.setDecoder=la)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={userdata:{configurable:!0},rawAuthToken:{configurable:!0},setDecoder:{configurable:!0}};return r.userdata.get=function(){return this.jsonqlUserdata},r.rawAuthToken.get=function(){return this.jsonqlToken},r.setDecoder.set=function(t){"function"==typeof t&&(this.decoder=t)},e.prototype.storeToken=function(t){return this.jsonqlToken=t},e.prototype.decoder=function(t){return t},e.prototype.getAuthHeader=function(){var t,e=this.rawAuthToken;return e?((t={})[this.opts.AUTH_HEADER]="Bearer "+e,t):{}},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={contractHeader:{configurable:!0}};return e.prototype.getContract=function(){var t=this.readContract();if(console.info("getContract first call",t),t&&Array.isArray(t)){var e=t[this.endpointIndex||0];if(e)return Promise.resolve(e)}return this.get().then(this.storeContract.bind(this))},r.contractHeader.get=function(){var t={};return!1!==this.opts.contractKey&&(t[this.opts.contractKeyName]=this.opts.contractKey),t},e.prototype.storeContract=function(t){if(!Gi(t))throw new li("Contract is malformed!");var e=[t];if(this.opts.contractExpired){var r=parseFloat(this.opts.contractExpired);!isNaN(r)&&r>0&&e.push(r)}return this.jsonqlContract=e,console.info("storeContract return result",t),t},e.prototype.readContract=function(){return Gi(this.opts.contract)?this.opts.contract:tt.get(this.opts.storageKey)},Object.defineProperties(e.prototype,r),e}(da))),ya=new WeakMap,ba=new WeakMap;var ma=function(t){void 0===t&&(t={}),t.logger&&"function"==typeof t.logger&&(this.logger=t.logger),this.keep=t.keep,this.result=t.keep?[]:null,this.normalStore=new Map,this.lazyStore=new Map},_a={$done:{configurable:!0},normalStore:{configurable:!0},lazyStore:{configurable:!0}};ma.prototype.logger=function(){},ma.prototype.$on=function(t,e,r){var n=this;void 0===r&&(r=null);this.validate(t,e);var o=this.takeFromStore(t);if(!1===o)return this.logger("$on",t+" callback is not in lazy store"),this.addToNormalStore(t,"on",e,r);this.logger("$on",t+" found in lazy store");var i=0;return o.forEach(function(o){var a=o[0],u=o[1],c=o[2];if(c&&"on"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);n.run(e,a,r||u),i+=n.addToNormalStore(t,"on",e,r||u)}),i},ma.prototype.$once=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=this.takeFromStore(t);this.normalStore;if(!1===n)return this.logger("$once",t+" not in the lazy store"),this.addToNormalStore(t,"once",e,r);this.logger("$once",n);var o=Array.from(n)[0],i=o[0],a=o[1],u=o[2];if(u&&"once"!==u)throw new Error("You are trying to register an event already been taken by other type: "+u);this.run(e,i,r||a),this.$off(t)},ma.prototype.$only=function(t,e,r){var n=this;void 0===r&&(r=null),this.validate(t,e);var o=!1,i=this.takeFromStore(t);(this.normalStore.has(t)||(this.logger("$only",t+" add to store"),o=this.addToNormalStore(t,"only",e,r)),!1!==i)&&(this.logger("$only",t+" found data in lazy store to execute"),Array.from(i).forEach(function(t){var o=t[0],i=t[1],a=t[2];if(a&&"only"!==a)throw new Error("You are trying to register an event already been taken by other type: "+a);n.run(e,o,r||i)}));return o},ma.prototype.$onlyOnce=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=!1,o=this.takeFromStore(t);if(this.normalStore.has(t)||(this.logger("$onlyOnce",t+" add to store"),n=this.addToNormalStore(t,"onlyOnce",e,r)),!1!==o){this.logger("$onlyOnce",o);var i=Array.from(o)[0],a=i[0],u=i[1],c=i[2];if(c&&"onlyOnce"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);this.run(e,a,r||u),this.$off(t)}return n},ma.prototype.$replace=function(t,e,r,n){if(void 0===r&&(r=null),void 0===n&&(n="on"),this.validateType(n)){this.$off(t);var o=this["$"+n];return Reflect.apply(o,this,[t,e,r])}throw new Error(n+" is not supported!")},ma.prototype.$trigger=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1),this.validateEvt(t);var o=0,i=this.normalStore;if(this.logger("$trigger",i),i.has(t)){this.logger("$trigger",t,"found");for(var a=Array.from(i.get(t)),u=a.length,c=!1,s=0;s0;)n[o]=arguments[o+2];if(t.has(e)?(this.logger("addToStore",e+" existed"),r=t.get(e)):(this.logger("addToStore","create new Set for "+e),r=new Set),n.length>2)if(Array.isArray(n[0])){var i=n[2];this.checkTypeInLazyStore(e,i)||r.add(n)}else this.checkContentExist(n,r)||(this.logger("addToStore","insert new",n),r.add(n));else r.add(n);return t.set(e,r),[t,r.size]},ma.prototype.checkContentExist=function(t,e){return!!Array.from(e).filter(function(e){return e[0]===t[0]}).length},ma.prototype.checkTypeInStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.$get(t,!0);return!1===r||!r.filter(function(t){var r=t[3];return e!==r}).length},ma.prototype.checkTypeInLazyStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.lazyStore.get(t);return this.logger("checkTypeInLazyStore",r),!!r&&!!Array.from(r).filter(function(t){return t[2]!==e}).length},ma.prototype.addToNormalStore=function(t,e,r,n){if(void 0===n&&(n=null),this.logger("addToNormalStore",t,e,"add to normal store"),this.checkTypeInStore(t,e)){this.logger(e+" can add to "+t+" store");var o=this.hashFnToKey(r),i=[this.normalStore,t,o,r,n,e],a=Reflect.apply(this.addToStore,this,i),u=a[0],c=a[1];return this.normalStore=u,c}return!1},ma.prototype.addToLazyStore=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1);var o=[this.lazyStore,t,this.toArray(e),r];n&&o.push(n);var i=Reflect.apply(this.addToStore,this,o),a=i[0],u=i[1];return this.lazyStore=a,u},ma.prototype.toArray=function(t){return Array.isArray(t)?t:[t]},_a.normalStore.set=function(t){ya.set(this,t)},_a.normalStore.get=function(){return ya.get(this)},_a.lazyStore.set=function(t){ba.set(this,t)},_a.lazyStore.get=function(){return ba.get(this)},ma.prototype.hashFnToKey=function(t){return t.toString().split("").reduce(function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t},0)+""},Object.defineProperties(ma.prototype,_a);var wa=new ma,ja=function(t,e,r,n){return function(){for(var r=[],o=arguments.length;o--;)r[o]=arguments[o];var i=n.auth[e].params,a=i.map(function(t,e){return r[e]}),u=r[i.length]||{};return Fi(r,i).then(function(){return t.query.apply(t,[e,a,u])}).catch(bi)}},Oa=function(t,e,r){var n={query:{},mutation:{},auth:{}},o=function(e){n.query[e]=function(){for(var n=[],o=arguments.length;o--;)n[o]=arguments[o];var i=r.query[e].params,a=i.map(function(t,e){return n[e]}),u=n[i.length]||{};return Fi(a,i).then(function(){return t.query.apply(t,[e,a,u])}).catch(bi)}};for(var i in r.query)o(i);var a=function(e){n.mutation[e]=function(n,o,i){void 0===i&&(i={});var a=[n,o],u=r.mutation[e].params;return Fi(a,u).then(function(){return t.mutation.apply(t,[e,n,o,i])}).catch(bi)}};for(var u in r.mutation)a(u);if(e.enableAuth&&r.auth){var c=e.loginHandlerName,s=e.logoutHandlerName;r.auth[c]&&(n[c]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=ja(t,c,0,r);return o.apply(null,e).then(t.postLoginAction).then(function(t){return wa.$trigger("login",t),t})}),r.auth[s]?n[s]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=ja(t,s,0,r);return o.apply(null,e).then(t.postLogoutAction).then(function(t){return wa.$trigger("logout",t),t})}:n[s]=function(){t.postLogoutAction("continue"),wa.$trigger("logout","continue")},n.userdata=function(){return t.userdata}}return n.returnInstance&&(n.jsonqlClientInstance=t),n.getToken=function(){return t.rawAuthToken},n.eventEmitter=wa,n},Sa={contract:!1,MUTATION_ARGS:["name","payload","conditions"],CONTENT_TYPE:Po,BEARER:"Bearer",AUTH_HEADER:"Authorization"},ka={hostname:Ji([window.location.protocol,window.location.host].join("//"),["string"]),jsonqlPath:Ji("jsonql",["string"]),loginHandlerName:Ji("login",["string"]),logoutHandlerName:Ji("logout",["string"]),enableJsonp:Ji(!1,["boolean"]),enableAuth:Ji(!1,["boolean"]),useJwt:Ji(!0,["boolean"]),useLocalstorage:Ji(!0,["boolean"]),storageKey:Ji("storageKey",["string"]),authKey:Ji("authKey",["string"]),contractExpired:Ji(0,["number"]),keepContract:Ji(!0,["boolean"]),showContractDesc:Ji(!1,["boolean"]),contractKey:Ji(!1,["boolean"]),contractKeyName:Ji("X-JSONQL-CV-KEY",["string"]),enableTimeout:Ji(!1,["boolean"]),timeout:Ji(5e3,["number"]),returnInstance:Ji(!1,["boolean"]),allowReturnRawToken:Ji(!1,["boolean"]),debugOn:Ji(!1,["boolean"])};function Ea(t,e){return void 0===t&&(t={}),void 0===e&&(e=null),function(t){var e=t.contract;return Ri(t,ka,Sa).then(function(t){return t.contract=e,t})}(t).then(function(t){return{baseClient:new ga(t,e),opts:t}}).then(function(t){var e=t.baseClient,r=t.opts;return Ki(e,r.contract).then(function(t){return Oa(e,r,t)})})}return function(t){return void 0===t&&(t={}),Ea(t,new o)}}); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).jsonqlClient=e()}(this,function(){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t,e){return t(e={exports:{}},e.exports),e.exports}var r,n=e(function(t,e){var r;r=function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(t,e,r){var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};t.exports={type:function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},isObject:function(t,e){return e?"object"===this.type(t):t&&"object"===(void 0===t?"undefined":n(t))},isFormData:function(t){return"undefined"!=typeof FormData&&t instanceof FormData},trim:function(t){return t.replace(/(^\s*)|(\s*$)/g,"")},encode:function(t){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")},formatParams:function(t){var e="",r=!0,n=this;if(!this.isObject(t))return t;return function t(o,i){var a=n.encode,u=n.type(o);if("array"==u)o.forEach(function(e,r){n.isObject(e)||(r=""),t(e,i+"%5B"+r+"%5D")});else if("object"==u)for(var c in o)t(o[c],i?i+"%5B"+a(c)+"%5D":a(c));else r||(e+="&"),r=!1,e+=i+"="+a(o)}(t,""),e},merge:function(t,e){for(var r in e)t.hasOwnProperty(r)?this.isObject(e[r],1)&&this.isObject(t[r],1)&&this.merge(t[r],e[r]):t[r]=e[r];return t}}},,function(t,e,r){var n=function(){function t(t,e){for(var r=0;r0&&(t+=(-1===t.indexOf("?")?"?":"&")+w.join("&")),a.open(r.method,t);try{a.withCredentials=!!r.withCredentials,a.timeout=r.timeout||0,"stream"!==y&&(a.responseType=y)}catch(t){}var j=r.headers[u]||r.headers[c],O="application/x-www-form-urlencoded";for(var S in o.trim((j||"").toLowerCase())===O?e=o.formatParams(e):o.isFormData(e)||-1===["object","array"].indexOf(o.type(e))||(O="application/json;charset=utf-8",e=JSON.stringify(e)),j||b||(r.headers[u]=O),r.headers)if(S===u&&o.isFormData(e))delete r.headers[S];else try{a.setRequestHeader(S,r.headers[S])}catch(t){}function k(t,e,n){v(l.p,function(){if(t){n&&(e.request=r);var o=t.call(l,e,Promise);e=void 0===o?e:o}d(e)||(e=Promise[0===n?"resolve":"reject"](e)),e.then(function(t){s(t)}).catch(function(t){h(t)})})}function E(t){t.engine=a,k(l.onerror,t,-1)}function A(t,e){this.message=t,this.status=e}a.onload=function(){try{var t=a.response||a.responseText;t&&r.parseJson&&-1!==(a.getResponseHeader(u)||"").indexOf("json")&&!o.isObject(t)&&(t=JSON.parse(t));var e=a.responseHeaders;if(!e){e={};var n=(a.getAllResponseHeaders()||"").split("\r\n");n.pop(),n.forEach(function(t){if(t){var r=t.split(":")[0];e[r]=a.getResponseHeader(r)}})}var i=a.status,c=a.statusText,s={data:t,headers:e,status:i,statusText:c};if(o.merge(s,a._response),i>=200&&i<300||304===i)s.engine=a,s.request=r,k(l.handler,s,0);else{var f=new A(c,i);f.response=s,E(f)}}catch(f){E(new A(f.msg,a.status))}},a.onerror=function(t){E(new A(t.msg||"Network Error",0))},a.ontimeout=function(){E(new A("timeout [ "+a.timeout+"ms ]",1))},a._options=r,setTimeout(function(){a.send(b?null:e)},0)}(n):s(n)},function(t){h(t)})})});return h.engine=a,h}},{key:"all",value:function(t){return Promise.all(t)}},{key:"spread",value:function(t){return function(e){return t.apply(null,e)}}}]),t}();a.default=a,["get","post","put","patch","head","delete"].forEach(function(t){a.prototype[t]=function(e,r,n){return this.request(e,r,o.merge({method:t},n))}}),["lock","unlock","clear"].forEach(function(t){a.prototype[t]=function(){this.interceptors.request[t]()}}),t.exports=a}])},t.exports=r()}),o=(r=n)&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,i=Object.assign?Object.assign:function(t,e,r,n){for(var o=arguments,i=1;i=0;e--){var r=A().key(e);t(x(r),r)}},remove:function(t){return A().removeItem(t)},clearAll:function(){return A().clear()}};function A(){return k.localStorage}function x(t){return A().getItem(t)}var T=s.trim,P={name:"cookieStorage",read:function(t){if(!t||!z(t))return null;var e="(?:^|.*;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(C.cookie.replace(new RegExp(e),"$1"))},write:function(t,e){if(!t)return;C.cookie=escape(t)+"="+escape(e)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"},each:q,remove:N,clearAll:function(){q(function(t,e){N(e)})}},C=s.Global.document;function q(t){for(var e=C.cookie.split(/; ?/g),r=e.length-1;r>=0;r--)if(T(e[r])){var n=e[r].split("="),o=unescape(n[0]);t(unescape(n[1]),o)}}function N(t){t&&z(t)&&(C.cookie=escape(t)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function z(t){return new RegExp("(?:^|;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(C.cookie)}var F=function(){var t={};return{defaults:function(e,r){t=r},get:function(e,r){var n=e();return void 0!==n?n:t[r]}}};var I="expire_mixin",$=function(){var t=this.createStore(this.storage,null,this._namespacePrefix+I);return{set:function(e,r,n,o){this.hasNamespace(I)||t.set(r,o);return e()},get:function(t,r){this.hasNamespace(I)||e.call(this,r);return t()},remove:function(e,r){this.hasNamespace(I)||t.remove(r);return e()},getExpiration:function(e,r){return t.get(r)},removeExpiredKeys:function(t){var r=[];this.each(function(t,e){r.push(e)});for(var n=0;n>>8,r[2*n+1]=a%256}return r},decompressFromUint8Array:function(e){if(null==e)return i.decompress(e);for(var r=new Array(e.length/2),n=0,o=r.length;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=a[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++),a[s]=p++,f=String(c)}if(""!==f){if(Object.prototype.hasOwnProperty.call(u,f)){if(f.charCodeAt(0)<256){for(n=0;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=a[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++)}for(o=2,n=0;n>=1;for(;;){if(v<<=1,g==e-1){d.push(r(v));break}g++}return d.join("")},decompress:function(t){return null==t?"":""==t?null:i._decompress(t.length,32768,function(e){return t.charCodeAt(e)})},_decompress:function(e,r,n){var o,i,a,u,c,s,f,l=[],p=4,h=4,d=3,v="",g=[],y={val:n(0),position:r,index:1};for(o=0;o<3;o+=1)l[o]=o;for(a=0,c=Math.pow(2,2),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;switch(a){case 0:for(a=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;f=t(a);break;case 1:for(a=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;f=t(a);break;case 2:return""}for(l[3]=f,i=f,g.push(f);;){if(y.index>e)return"";for(a=0,c=Math.pow(2,d),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;switch(f=a){case 0:for(a=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;l[h++]=t(a),f=h-1,p--;break;case 1:for(a=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),a|=(u>0?1:0)*s,s<<=1;l[h++]=t(a),f=h-1,p--;break;case 2:return g.join("")}if(0==p&&(p=Math.pow(2,d),d++),l[f])v=l[f];else{if(f!==h)return null;v=i+i.charAt(0)}g.push(v),l[h++]=i+v.charAt(0),i=v,0==--p&&(p=Math.pow(2,d),d++)}}};return i}();null!=t&&(t.exports=e)});var B=[E,P],K=[F,$,D,function(){return{get:function(t,e){var r=t(e);if(!r)return r;var n=L.decompress(r);return null==n?r:this._deserialize(n)},set:function(t,e,r){var n=L.compress(this._serialize(r));t(e,n)}}}],W=j.createStore(B,K),G=s.Global;function V(){return G.sessionStorage}function Y(t){return V().getItem(t)}var X=[{name:"sessionStorage",read:Y,write:function(t,e){return V().setItem(t,e)},each:function(t){for(var e=V().length-1;e>=0;e--){var r=V().key(e);t(Y(r),r)}},remove:function(t){return V().removeItem(t)},clearAll:function(){return V().clear()}},P],Q=[F,$],Z=j.createStore(X,Q),tt=W,et=Z,rt="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},nt="object"==typeof rt&&rt&&rt.Object===Object&&rt,ot="object"==typeof self&&self&&self.Object===Object&&self,it=nt||ot||Function("return this")(),at=it.Symbol,ut=Object.prototype,ct=ut.hasOwnProperty,st=ut.toString,ft=at?at.toStringTag:void 0;var lt=Object.prototype.toString;var pt="[object Null]",ht="[object Undefined]",dt=at?at.toStringTag:void 0;function vt(t){return null==t?void 0===t?ht:pt:dt&&dt in Object(t)?function(t){var e=ct.call(t,ft),r=t[ft];try{t[ft]=void 0;var n=!0}catch(t){}var o=st.call(t);return n&&(e?t[ft]=r:delete t[ft]),o}(t):function(t){return lt.call(t)}(t)}function gt(t){return null!=t&&"object"==typeof t}var yt="[object Symbol]";function bt(t){return"symbol"==typeof t||gt(t)&&vt(t)==yt}function mt(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r0){if(++Zt>=Vt)return arguments[0]}else Zt=0;return Qt.apply(void 0,arguments)});function ne(t){return t!=t}function oe(t,e,r){return e==e?function(t,e,r){for(var n=r-1,o=t.length;++n-1&&t%1==0&&t-1&&t%1==0&&t<=de}function ge(t){return null!=t&&ve(t.length)&&!Ct(t)}var ye=Object.prototype;function be(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||ye)}var me="[object Arguments]";function _e(t){return gt(t)&&vt(t)==me}var we=Object.prototype,je=we.hasOwnProperty,Oe=we.propertyIsEnumerable,Se=_e(function(){return arguments}())?_e:function(t){return gt(t)&&je.call(t,"callee")&&!Oe.call(t,"callee")};var ke="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ee=ke&&"object"==typeof module&&module&&!module.nodeType&&module,Ae=Ee&&Ee.exports===ke?it.Buffer:void 0,xe=(Ae?Ae.isBuffer:void 0)||function(){return!1},Te={};Te["[object Float32Array]"]=Te["[object Float64Array]"]=Te["[object Int8Array]"]=Te["[object Int16Array]"]=Te["[object Int32Array]"]=Te["[object Uint8Array]"]=Te["[object Uint8ClampedArray]"]=Te["[object Uint16Array]"]=Te["[object Uint32Array]"]=!0,Te["[object Arguments]"]=Te["[object Array]"]=Te["[object ArrayBuffer]"]=Te["[object Boolean]"]=Te["[object DataView]"]=Te["[object Date]"]=Te["[object Error]"]=Te["[object Function]"]=Te["[object Map]"]=Te["[object Number]"]=Te["[object Object]"]=Te["[object RegExp]"]=Te["[object Set]"]=Te["[object String]"]=Te["[object WeakMap]"]=!1;var Pe="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ce=Pe&&"object"==typeof module&&module&&!module.nodeType&&module,qe=Ce&&Ce.exports===Pe&&nt.process,Ne=function(){try{var t=Ce&&Ce.require&&Ce.require("util").types;return t||qe&&qe.binding&&qe.binding("util")}catch(t){}}(),ze=Ne&&Ne.isTypedArray,Fe=ze?function(t){return function(e){return t(e)}}(ze):function(t){return gt(t)&&ve(t.length)&&!!Te[vt(t)]},Ie=Object.prototype.hasOwnProperty;function $e(t,e){var r=_t(t),n=!r&&Se(t),o=!r&&!n&&xe(t),i=!r&&!n&&!o&&Fe(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r-1},rr.prototype.set=function(t,e){var r=this.__data__,n=tr(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var nr=Lt(it,"Map");function or(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function ir(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e=n?t:function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++nu))return!1;var s=i.get(t);if(s&&i.get(e))return s==e;var f=-1,l=!0,p=r&vn?new pn:void 0;for(i.set(t,e),i.set(e,t);++f1?e[n-1]:void 0,i=n>2?e[2]:void 0;for(o=yo.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!kt(r))return!1;var n=typeof e;return!!("number"==n?ge(r)&&ue(e,r.length):"string"==n&&e in r)&&se(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r-1;);return r}(n,o),function(t,e){for(var r=t.length;r--&&oe(e,t[r],0)>-1;);return r}(n,o)+1).join("")}function ko(t){return!!_t(t)||null!=t&&""!==So(t)}var Eo=function(t){return!fo(t)&&!ho(parseFloat(t))},Ao=function(t){return""!==So(t)&&fo(t)},xo=function(t){return function(t){return!0===t||!1===t||gt(t)&&vt(t)==lo}(t)},To=function(t,e){return void 0===e&&(e=!0),!vo(t)&&""!==t&&""!==So(t)&&(!1===e||!0===e&&!function(t){return null===t}(t))},Po="application/vnd.api+json",Co={Accept:Po,"Content-Type":[Po,"charset=utf-8"].join(";")},qo="payload",No="condition",zo="args",Fo=["POST","PUT"],Io="type",$o="optional",Jo="enumv",Ro="args",Mo="checker",Uo="alias",Do={desc:"y"},Ho="No message",Lo=Io,Bo=$o,Ko=Jo,Wo=Ro,Go=Mo,Vo=Uo,Yo="continue",Xo=function(t){switch(t){case"number":return Eo;case"string":return Ao;case"boolean":return xo;default:return To}},Qo=function(t,e){return void 0===e&&(e=""),!!_t(t)&&(""===e||""===So(e)||!(t.filter(function(t){return!Xo(e)(t)}).length>0))},Zo=function(t){if(t.indexOf("array.<")>-1&&t.indexOf(">")>-1){var e=t.replace("array.<","").replace(">","");return e.indexOf("|")?e.split("|"):[e]}return!1},ti=function(t,e){var r=t.arg;return e.length>1?!r.filter(function(t){return!(e.length>e.filter(function(e){return!Xo(e)(t)}).length)}).length:e.length>e.filter(function(t){return!Qo(r,t)}).length},ei=function(t,e){if(void 0===e&&(e=null),kr(t)){if(!e)return!0;if(Qo(e))return!e.filter(function(e){var r=t[e.name];return!(e.type.length>e.type.filter(function(t){var e;return!!vo(r)||(!1!==(e=Zo(t))?!ti({arg:r},e):!Xo(t)(r))}).length)}).length}return!1},ri=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 406},r.name.get=function(){return"Jsonql406Error"},Object.defineProperties(e,r),e}(Error),ni=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"Jsonql500Error"},Object.defineProperties(e,r),e}(Error),oi=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(e,r),e}(Error),ii=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(e,r),e}(Error),ai=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(e,r),e}(Error),ui=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 404},r.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(e,r),e}(Error),ci=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(e,r),e}(Error),si=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(e,r),e}(Error),fi=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(e,r),e}(Error),li=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(e,r),e}(Error),pi=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0},statusCode:{configurable:!0}};return r.name.get=function(){return"JsonqlError"},r.statusCode.get=function(){return-1},Object.defineProperties(e,r),e}(Error),hi=function(t){function e(r,n){t.call(this,n),this.statusCode=r,this.className=e.name}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlServerError"},Object.defineProperties(e,r),e}(Error),di=Object.freeze({Jsonql406Error:ri,Jsonql500Error:ni,JsonqlAuthorisationError:oi,JsonqlContractAuthError:ii,JsonqlResolverAppError:ai,JsonqlResolverNotFoundError:ui,JsonqlEnumError:ci,JsonqlTypeError:si,JsonqlCheckerError:fi,JsonqlValidationError:li,JsonqlError:pi,JsonqlServerError:hi}),vi=pi,gi=function(t,e){return!!Object.keys(t).filter(function(t){return e===t}).length};function yi(t){if(gi(t,"error")){var e=t.error,r=e.className,n=e.name,o=r||n,i=e.message||Ho,a=e.detail||e;if(o&&di[o])throw new di[r](i,a);throw new vi(i,a)}return t}function bi(t){if(Array.isArray(t))throw new li("",t);var e=t.message||Ho,r=t.detail||t;switch(!0){case t instanceof ri:throw new ri(e,r);case t instanceof ni:throw new ni(e,r);case t instanceof oi:throw new oi(e,r);case t instanceof ii:throw new ii(e,r);case t instanceof ai:throw new ai(e,r);case t instanceof ui:throw new ui(e,r);case t instanceof ci:throw new ci(e,r);case t instanceof si:throw new si(e,r);case t instanceof fi:throw new fi(e,r);case t instanceof li:throw new li(e,r);case t instanceof hi:throw new hi(e,r);default:throw new pi(e,r)}}var mi=function(t,e){var r,n,o,i,a;switch(!0){case"object"===t:return o=(n=e).arg,i=n.param,a=[o],Array.isArray(i.keys)&&i.keys.length&&a.push(i.keys),!ei.apply(null,a);case"array"===t:return!Qo(e.arg);case!1!==(r=Zo(t)):return!ti(e,r);default:return!Xo(t)(e.arg)}},_i=function(t,e){return vo(t)?!0!==e.optional||vo(e.defaultvalue)?null:e.defaultvalue:t},wi=function(t,e,r){var n;void 0===r&&(r=!1);var o=function(t,e){if(!Qo(e))throw new pi("params is not an array! Did something gone wrong when you generate the contract.json?");if(0===e.length)return[];if(!Qo(t))throw new pi("args is not an array! You might want to do: ES6 Array.from(arguments) or ES5 Array.prototype.slice.call(arguments)");switch(!0){case t.length==e.length:return t.map(function(t,r){return{arg:t,index:r,param:e[r]}});case!0===e[0].variable:var r=e[0].type;return t.map(function(t,n){return{arg:t,index:n,param:e[n]||{type:r,name:"_"}}});case t.lengthe.length&&1===e.length:var n,o=["any"];return!1!==(n=Zo(e[0].type[0]))&&(o=n),t.map(function(t,r){return{arg:t,index:r,param:e[r]||{type:o,name:"_"}}});default:throw new pi("Could not understand your arguments and parameter structure!",{args:t,params:e})}}(t,e),i=o.filter(function(t){return!0===t.param.optional?function(t){var e=t.arg,r=t.param;return!(!ko(e)||r.type.length>r.type.filter(function(e){return mi(e,t)}).length)}(t):!(t.param.type.length>t.param.type.filter(function(e){return mi(e,t)}).length)});return r?((n={}).error=i,n.data=o.map(function(t){return t.arg}),n):i},ji=function(t,e){return!!t.filter(function(t){return t===e}).length},Oi=function(t,e){var r=Object.keys(t);return ji(r,e)},Si=function(t){return!ko(t)};function ki(t,e){var r=jo(e,function(t,e){return!t[Vo]});return Dn(r,{})?t:function(t,e){var r={};return e=to(e),no(t,function(t,n,o){ce(r,e(t,n,o),t)}),r}(t,function(t,e){return function(t,e,r){var n;return r(t,function(t,r,o){if(e(t,r,o))return n=r,!1}),n}(r,to(function(t){return t.alias===e}),no)||e})}function Ei(t,e){return go(e,function(e,r){var n,o;return vo(t[r])||!0===e[Bo]&&Si(t[r])?bo({},e,((n={})[Yo]=!0,n)):((o={})[Wo]=t[r],o[Lo]=e[Lo],o[Bo]=e[Bo]||!1,o[Ko]=e[Ko]||!1,o[Go]=e[Go]||!1,o)})}function Ai(t,e){var r=function(t,e){var r=ki(t,e);return{pristineValues:go(jo(e,function(t,e){return Oi(r,e)}),function(t){return t.args}),checkAgainstAppProps:jo(e,function(t,e){return!Oi(r,e)}),config:r}}(t,e),n=r.config,o=r.pristineValues;return[Ei(n,r.checkAgainstAppProps),o]}var xi=function(t){return Qo(t)?t:[t]};var Ti=function(t,e){return!Qo(e)||function(t,e){return!!t.filter(function(t){return t===e}).length}(e,t)},Pi=function(t,e){try{return!!Ct(e)&&e.apply(null,[t])}catch(t){return!1}};function Ci(t){return function(e,r){if(e[Yo])return e[Wo];var n=function(t,e){var r,n=[[t[Wo]],[(r={},r[Lo]=xi(t[Lo]),r[Bo]=t[Bo],r)]];return Reflect.apply(e,null,n)}(e,t);if(n.length)throw new si(r,n);if(!1!==e[Ko]&&!Ti(e[Wo],e[Ko]))throw new ci(r);if(!1!==e[Go]&&!Pi(e[Wo],e[Go]))throw new fi(r);return e[Wo]}}var qi=function(t,e){return Promise.resolve(Ai(t,e))};function Ni(t,e,r,n){return void 0===t&&(t={}),qi(t,e).then(function(t){return function(t,e){var r=t[0],n=t[1],o=go(r,Ci(e));return bo(o,n)}(t,n)}).then(function(t){return bo({},t,r)})}var zi=ei,Fi=Ao,Ii=Qo,$i=function(t,e,r){return void 0===r&&(r=!1),new Promise(function(n,o){var i=wi(t,e,r);return r?i.error.length?o(i.error):n(i.data):i.length?o(i):n([])})},Ji=function(t,e,r){void 0===r&&(r={});var n=r[$o],o=r[Jo],i=r[Mo],a=r[Uo];return function(t,e,r,n,o,i){void 0===r&&(r=!1),void 0===n&&(n=!1),void 0===o&&(o=!1),void 0===i&&(i=!1);var a={};return a[Ro]=t,a[Io]=e,!0===r&&(a[$o]=!0),Qo(n)&&(a[Jo]=n),Ct(o)&&(a[Mo]=o),fo(i)&&(a[Uo]=i),a}.apply(null,[t,e,n,o,i,a])},Ri=function(t){return function(e,r,n){return void 0===n&&(n={}),Ni(e,r,n,t)}}(wi),Mi=ji,Ui=Oi,Di=function(t,e,r){var n;if(void 0===e&&(e=[]),void 0===r&&(r=!1),Ao(t)&&Qo(e)){var o={};return o[zo]=e,!0===r?o:((n={})[t]=o,n)}throw new li("[createQuery] expect resolverName to be string and args to be array!",{resolverName:t,args:e})},Hi=function(t,e,r,n){var o;void 0===r&&(r={}),void 0===n&&(n=!1);var i={};if(i[qo]=e,i[No]=r,!0===n)return i;if(Ao(t))return(o={})[t]=i,o;throw new li("[createMutation] expect resolverName to be string!",{resolverName:t,payload:e,condition:r})},Li=function(t){return Object.keys(t)[0]},Bi=function(){return Math.floor(Date.now()/1e3)},Ki=function(t,e){return void 0===e&&(e={}),Gi(e)?Promise.resolve(e):t.getContract()},Wi=function(t){return Ui(t,"data")&&!Ui(t,"error")?t.data:t},Gi=function(t){return t&&zi(t)&&(Ui(t,"query")||Ui(t,"mutation"))},Vi="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function Yi(t){this.message=t}Yi.prototype=new Error,Yi.prototype.name="InvalidCharacterError";var Xi="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new Yi("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,n,o=0,i=0,a="";n=e.charAt(i++);~n&&(r=o%4?64*r+n:n,o++%4)?a+=String.fromCharCode(255&r>>(-2*o&6)):0)n=Vi.indexOf(n);return a};var Qi=function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(Xi(t).replace(/(.)/g,function(t,e){var r=e.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}(e)}catch(t){return Xi(e)}};function Zi(t){this.message=t}Zi.prototype=new Error,Zi.prototype.name="InvalidTokenError";var ta,ea,ra,na,oa,ia,aa,ua,ca,sa=function(t,e){if("string"!=typeof t)throw new Zi("Invalid token specified");var r=!0===(e=e||{}).header?0:1;try{return JSON.parse(Qi(t.split(".")[r]))}catch(t){throw new Zi("Invalid token specified: "+t.message)}},fa=Zi;function la(t){if(Fi(t))return function(t){var e=t.iat||Math.floor(Date.now()/1e3);if(t.exp&&e>=t.exp){var r=new Date(t.exp).toISOString();throw new pi("Token has expired on "+r,t)}return t}(sa(t));throw new pi("Token must be a string!")}sa.InvalidTokenError=fa;Ji("HS256",["string"]),Ji(!1,["boolean","number","string"],((ta={})[Uo]="exp",ta[$o]=!0,ta)),Ji(!1,["boolean","number","string"],((ea={})[Uo]="nbf",ea[$o]=!0,ea)),Ji(!1,["boolean","string"],((ra={})[Uo]="iss",ra[$o]=!0,ra)),Ji(!1,["boolean","string"],((na={})[Uo]="sub",na[$o]=!0,na)),Ji(!1,["boolean","string"],((oa={})[Uo]="iss",oa[$o]=!0,oa)),Ji(!1,["boolean"],((ia={})[$o]=!0,ia)),Ji(!1,["boolean","string"],((aa={})[$o]=!0,aa)),Ji(!1,["boolean","string"],((ua={})[$o]=!0,ua)),Ji(!1,["boolean"],((ca={})[$o]=!0,ca));!function(){switch(!0){case"undefined"!=typeof WebSocket:return WebSocket;case"undefined"!=typeof MozWebSocket:return MozWebSocket;case"undefined"!=typeof window:return window.WebSocket||window.MozWebSocket;default:throw new li("WebSocket is NOT SUPPORTED!")}}();var pa=Fo[0],ha=Fo[1],da=function(t){this.fly=t.Fly?new t.Fly:new Fly,this.opts=t,this.extraHeader={},this.extraParams={},this.reqInterceptor(),this.resInterceptor()},va={headers:{configurable:!0}};va.headers.set=function(t){this.extraHeader=t},da.prototype.request=function(t,e,r){var n;void 0===e&&(e={}),void 0===r&&(r={}),this.headers=r;var o=bo({},{_cb:Bi()},this.extraParams);if(this.opts.enableJsonp){var i=Li(t);o=bo({},o,((n={}).jsonqlJsonpCallback=i,n)),t=t[i]}return this.fly.request(this.jsonqlEndpoint,t,bo({},{method:pa,params:o},e))},da.prototype.reqInterceptor=function(){var t=this;this.fly.interceptors.request.use(function(e){console.info("request interceptor call");var r=t.getHeaders();for(var n in r)e.headers[n]=r[n];return e})},da.prototype.processJsonp=function(t){return Wi(t)},da.prototype.resInterceptor=function(){var t=this,e=t.opts.enableJsonp;this.fly.interceptors.response.use(function(r){console.info("response interceptor call"),t.cleanUp();var n=Fi(r.data)?JSON.parse(r.data):r.data;return e?t.processJsonp(n):Wi(n)},function(e){throw t.cleanUp(),console.error(e),new hi("Server side error",e)})},da.prototype.getHeaders=function(){return this.opts.enableAuth?bo({},Co,this.getAuthHeader(),this.extraHeader):bo({},Co,this.extraHeader)},da.prototype.cleanUp=function(){this.extraHeader={},this.extraParams={}},da.prototype.get=function(){return this.opts.showContractDesc&&(this.extraParams=bo({},this.extraParams,Do)),this.request({},{method:"GET"},this.contractHeader).then(yi).then(function(t){return console.info("144 get contract result",t),t.cache&&t.contract?t.contract:t})},da.prototype.query=function(t,e){return void 0===e&&(e=[]),this.request(Di(t,e)).then(yi)},da.prototype.mutation=function(t,e,r){return void 0===e&&(e={}),void 0===r&&(r={}),this.request(Hi(t,e,r),{method:ha}).then(yi)},Object.defineProperties(da.prototype,va);var ga=function(t){function e(e,r){r&&(e.Fly=r),t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={storeIt:{configurable:!0},jsonqlEndpoint:{configurable:!0},jsonqlContract:{configurable:!0},jsonqlToken:{configurable:!0},jsonqlUserdata:{configurable:!0}};return r.storeIt.set=function(t){throw console.info("storeIt",t),Ii(t)&&t.length>=2&&Reflect.apply(tt.set,tt,t),new li("Expect argument to be array and least 2 items!")},r.jsonqlEndpoint.set=function(t){var e=tt.get("endpoint")||[];Mi(e,t)||(e.push(t),this.storeId=["endpoint",e],this.endpointIndex=e.length-1)},r.jsonqlContract.set=function(t){var e=this.opts.storageKey,r=[e],n=t[0],o=t[1],i=tt.get(e)||[];i[this.endpointIndex||0]=n,r.push(i),o&&r.push(o),this.opts.keepContract&&(this.storeIt=r)},r.jsonqlToken.set=function(t){var e="credential",r=localStorage.get(e)||[];if(!Mi(r,t)){var n=r.length-1;r[n]=t,this[e+"Index"]=n;var o=[e,r];if(this.opts.tokenExpired){var i=parseFloat(this.opts.tokenExpired);if(!isNaN(i)&&i>0){var a=Bi();o.push(a+parseFloat(i))}}return this.storeIt=o,this.jsonqlUserdata=this.decoder(t),t}return!1},r.jsonqlUserdata.set=function(t){var e=["userdata",t];return t.exp&&e.push(t.exp),Reflect.apply(tt.set,tt,e)},r.jsonqlEndpoint.get=function(){var t=tt.get("endpoint");if(!t){var e=this.opts,r=[e.hostname,e.jsonqlPath].join("/");return this.jsonqlEndpoint=r,r}return t[this.endpointIndex]},r.jsonqlContract.get=function(){var t=this.opts.storageKey;return(tt.get(t)||[])[this.endpointIndex]||!1},r.jsonqlToken.get=function(){var t="credential",e=localStorage.get(t);return!!e&&e[this[t+"Index"]]},r.jsonqlUserdata.get=function(){return et.get("userdata")},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),e.enableAuth&&e.useJwt&&(this.setDecoder=la)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={userdata:{configurable:!0},rawAuthToken:{configurable:!0},setDecoder:{configurable:!0}};return r.userdata.get=function(){return this.jsonqlUserdata},r.rawAuthToken.get=function(){return this.jsonqlToken},r.setDecoder.set=function(t){"function"==typeof t&&(this.decoder=t)},e.prototype.storeToken=function(t){return this.jsonqlToken=t},e.prototype.decoder=function(t){return t},e.prototype.getAuthHeader=function(){var t,e=this.rawAuthToken;return e?((t={})[this.opts.AUTH_HEADER]="Bearer "+e,t):{}},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={contractHeader:{configurable:!0}};return e.prototype.getContract=function(){var t=this.readContract();if(console.info("getContract first call",t),t&&Array.isArray(t)){var e=t[this.endpointIndex||0];if(e)return Promise.resolve(e)}return this.get().then(this.storeContract.bind(this))},r.contractHeader.get=function(){var t={};return!1!==this.opts.contractKey&&(t[this.opts.contractKeyName]=this.opts.contractKey),t},e.prototype.storeContract=function(t){if(!Gi(t))throw new li("Contract is malformed!");var e=[t];if(this.opts.contractExpired){var r=parseFloat(this.opts.contractExpired);!isNaN(r)&&r>0&&e.push(r)}return this.jsonqlContract=e,console.info("storeContract return result",t),t},e.prototype.readContract=function(){return Gi(this.opts.contract)?this.opts.contract:tt.get(this.opts.storageKey)},Object.defineProperties(e.prototype,r),e}(da))),ya=new WeakMap,ba=new WeakMap;var ma=function(t){void 0===t&&(t={}),t.logger&&"function"==typeof t.logger&&(this.logger=t.logger),this.keep=t.keep,this.result=t.keep?[]:null,this.normalStore=new Map,this.lazyStore=new Map},_a={$done:{configurable:!0},normalStore:{configurable:!0},lazyStore:{configurable:!0}};ma.prototype.logger=function(){},ma.prototype.$on=function(t,e,r){var n=this;void 0===r&&(r=null);this.validate(t,e);var o=this.takeFromStore(t);if(!1===o)return this.logger("$on",t+" callback is not in lazy store"),this.addToNormalStore(t,"on",e,r);this.logger("$on",t+" found in lazy store");var i=0;return o.forEach(function(o){var a=o[0],u=o[1],c=o[2];if(c&&"on"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);n.run(e,a,r||u),i+=n.addToNormalStore(t,"on",e,r||u)}),i},ma.prototype.$once=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=this.takeFromStore(t);this.normalStore;if(!1===n)return this.logger("$once",t+" not in the lazy store"),this.addToNormalStore(t,"once",e,r);this.logger("$once",n);var o=Array.from(n)[0],i=o[0],a=o[1],u=o[2];if(u&&"once"!==u)throw new Error("You are trying to register an event already been taken by other type: "+u);this.run(e,i,r||a),this.$off(t)},ma.prototype.$only=function(t,e,r){var n=this;void 0===r&&(r=null),this.validate(t,e);var o=!1,i=this.takeFromStore(t);(this.normalStore.has(t)||(this.logger("$only",t+" add to store"),o=this.addToNormalStore(t,"only",e,r)),!1!==i)&&(this.logger("$only",t+" found data in lazy store to execute"),Array.from(i).forEach(function(t){var o=t[0],i=t[1],a=t[2];if(a&&"only"!==a)throw new Error("You are trying to register an event already been taken by other type: "+a);n.run(e,o,r||i)}));return o},ma.prototype.$onlyOnce=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=!1,o=this.takeFromStore(t);if(this.normalStore.has(t)||(this.logger("$onlyOnce",t+" add to store"),n=this.addToNormalStore(t,"onlyOnce",e,r)),!1!==o){this.logger("$onlyOnce",o);var i=Array.from(o)[0],a=i[0],u=i[1],c=i[2];if(c&&"onlyOnce"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);this.run(e,a,r||u),this.$off(t)}return n},ma.prototype.$replace=function(t,e,r,n){if(void 0===r&&(r=null),void 0===n&&(n="on"),this.validateType(n)){this.$off(t);var o=this["$"+n];return Reflect.apply(o,this,[t,e,r])}throw new Error(n+" is not supported!")},ma.prototype.$trigger=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1),this.validateEvt(t);var o=0,i=this.normalStore;if(this.logger("$trigger",i),i.has(t)){this.logger("$trigger",t,"found");for(var a=Array.from(i.get(t)),u=a.length,c=!1,s=0;s0;)n[o]=arguments[o+2];if(t.has(e)?(this.logger("addToStore",e+" existed"),r=t.get(e)):(this.logger("addToStore","create new Set for "+e),r=new Set),n.length>2)if(Array.isArray(n[0])){var i=n[2];this.checkTypeInLazyStore(e,i)||r.add(n)}else this.checkContentExist(n,r)||(this.logger("addToStore","insert new",n),r.add(n));else r.add(n);return t.set(e,r),[t,r.size]},ma.prototype.checkContentExist=function(t,e){return!!Array.from(e).filter(function(e){return e[0]===t[0]}).length},ma.prototype.checkTypeInStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.$get(t,!0);return!1===r||!r.filter(function(t){var r=t[3];return e!==r}).length},ma.prototype.checkTypeInLazyStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.lazyStore.get(t);return this.logger("checkTypeInLazyStore",r),!!r&&!!Array.from(r).filter(function(t){return t[2]!==e}).length},ma.prototype.addToNormalStore=function(t,e,r,n){if(void 0===n&&(n=null),this.logger("addToNormalStore",t,e,"add to normal store"),this.checkTypeInStore(t,e)){this.logger(e+" can add to "+t+" store");var o=this.hashFnToKey(r),i=[this.normalStore,t,o,r,n,e],a=Reflect.apply(this.addToStore,this,i),u=a[0],c=a[1];return this.normalStore=u,c}return!1},ma.prototype.addToLazyStore=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1);var o=[this.lazyStore,t,this.toArray(e),r];n&&o.push(n);var i=Reflect.apply(this.addToStore,this,o),a=i[0],u=i[1];return this.lazyStore=a,u},ma.prototype.toArray=function(t){return Array.isArray(t)?t:[t]},_a.normalStore.set=function(t){ya.set(this,t)},_a.normalStore.get=function(){return ya.get(this)},_a.lazyStore.set=function(t){ba.set(this,t)},_a.lazyStore.get=function(){return ba.get(this)},ma.prototype.hashFnToKey=function(t){return t.toString().split("").reduce(function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t},0)+""},Object.defineProperties(ma.prototype,_a);var wa=new ma,ja=function(t,e,r,n){return function(){for(var r=[],o=arguments.length;o--;)r[o]=arguments[o];var i=n.auth[e].params,a=i.map(function(t,e){return r[e]}),u=r[i.length]||{};return $i(r,i).then(function(){return t.query.apply(t,[e,a,u])}).catch(bi)}},Oa=function(t,e,r){var n={query:{},mutation:{},auth:{}},o=function(e){n.query[e]=function(){for(var n=[],o=arguments.length;o--;)n[o]=arguments[o];var i=r.query[e].params,a=i.map(function(t,e){return n[e]}),u=n[i.length]||{};return $i(a,i).then(function(){return t.query.apply(t,[e,a,u])}).catch(bi)}};for(var i in r.query)o(i);var a=function(e){n.mutation[e]=function(n,o,i){void 0===i&&(i={});var a=[n,o],u=r.mutation[e].params;return $i(a,u).then(function(){return t.mutation.apply(t,[e,n,o,i])}).catch(bi)}};for(var u in r.mutation)a(u);if(e.enableAuth&&r.auth){var c=e.loginHandlerName,s=e.logoutHandlerName;r.auth[c]&&(n[c]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=ja(t,c,0,r);return o.apply(null,e).then(t.postLoginAction).then(function(t){return wa.$trigger("login",t),t})}),r.auth[s]?n[s]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=ja(t,s,0,r);return o.apply(null,e).then(t.postLogoutAction).then(function(t){return wa.$trigger("logout",t),t})}:n[s]=function(){t.postLogoutAction("continue"),wa.$trigger("logout","continue")},n.userdata=function(){return t.userdata}}return n.returnInstance&&(n.jsonqlClientInstance=t),n.getToken=function(){return t.rawAuthToken},n.eventEmitter=wa,n},Sa={contract:!1,MUTATION_ARGS:["name","payload","conditions"],CONTENT_TYPE:Po,BEARER:"Bearer",AUTH_HEADER:"Authorization"},ka={hostname:Ji([window.location.protocol,window.location.host].join("//"),["string"]),jsonqlPath:Ji("jsonql",["string"]),loginHandlerName:Ji("login",["string"]),logoutHandlerName:Ji("logout",["string"]),enableJsonp:Ji(!1,["boolean"]),enableAuth:Ji(!1,["boolean"]),useJwt:Ji(!0,["boolean"]),useLocalstorage:Ji(!0,["boolean"]),storageKey:Ji("storageKey",["string"]),authKey:Ji("authKey",["string"]),contractExpired:Ji(0,["number"]),keepContract:Ji(!0,["boolean"]),showContractDesc:Ji(!1,["boolean"]),contractKey:Ji(!1,["boolean"]),contractKeyName:Ji("X-JSONQL-CV-KEY",["string"]),enableTimeout:Ji(!1,["boolean"]),timeout:Ji(5e3,["number"]),returnInstance:Ji(!1,["boolean"]),allowReturnRawToken:Ji(!1,["boolean"]),debugOn:Ji(!1,["boolean"])};function Ea(t,e){return void 0===t&&(t={}),void 0===e&&(e=null),function(t){var e=t.contract;return Ri(t,ka,Sa).then(function(t){return t.contract=e,t})}(t).then(function(t){return{baseClient:new ga(t,e),opts:t}}).then(function(t){var e=t.baseClient,r=t.opts;return Ki(e,r.contract).then(function(t){return Oa(e,r,t)})})}return function(t){return void 0===t&&(t={}),Ea(t,o)}}); //# sourceMappingURL=full.js.map diff --git a/packages/http-client/dist/jsonql-client.umd.js b/packages/http-client/dist/jsonql-client.umd.js index c631325f..5e20cec8 100644 --- a/packages/http-client/dist/jsonql-client.umd.js +++ b/packages/http-client/dist/jsonql-client.umd.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).jsonqlClient=e()}(this,function(){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var e=Object.assign?Object.assign:function(t,e,r,n){for(var o=arguments,a=1;a=0;e--){var r=S().key(e);t(O(r),r)}},remove:function(t){return S().removeItem(t)},clearAll:function(){return S().clear()}};function S(){return w.localStorage}function O(t){return S().getItem(t)}var k=a.trim,A={name:"cookieStorage",read:function(t){if(!t||!P(t))return null;var e="(?:^|.*;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(E.cookie.replace(new RegExp(e),"$1"))},write:function(t,e){if(!t)return;E.cookie=escape(t)+"="+escape(e)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"},each:T,remove:x,clearAll:function(){T(function(t,e){x(e)})}},E=a.Global.document;function T(t){for(var e=E.cookie.split(/; ?/g),r=e.length-1;r>=0;r--)if(k(e[r])){var n=e[r].split("="),o=unescape(n[0]);t(unescape(n[1]),o)}}function x(t){t&&P(t)&&(E.cookie=escape(t)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function P(t){return new RegExp("(?:^|;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(E.cookie)}var C=function(){var t={};return{defaults:function(e,r){t=r},get:function(e,r){var n=e();return void 0!==n?n:t[r]}}};var q="expire_mixin",z=function(){var t=this.createStore(this.storage,null,this._namespacePrefix+q);return{set:function(e,r,n,o){this.hasNamespace(q)||t.set(r,o);return e()},get:function(t,r){this.hasNamespace(q)||e.call(this,r);return t()},remove:function(e,r){this.hasNamespace(q)||t.remove(r);return e()},getExpiration:function(e,r){return t.get(r)},removeExpiredKeys:function(t){var r=[];this.each(function(t,e){r.push(e)});for(var n=0;n>>8,r[2*n+1]=i%256}return r},decompressFromUint8Array:function(e){if(null==e)return a.decompress(e);for(var r=new Array(e.length/2),n=0,o=r.length;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=i[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++),i[s]=p++,f=String(c)}if(""!==f){if(Object.prototype.hasOwnProperty.call(u,f)){if(f.charCodeAt(0)<256){for(n=0;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=i[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++)}for(o=2,n=0;n>=1;for(;;){if(v<<=1,g==e-1){d.push(r(v));break}g++}return d.join("")},decompress:function(t){return null==t?"":""==t?null:a._decompress(t.length,32768,function(e){return t.charCodeAt(e)})},_decompress:function(e,r,n){var o,a,i,u,c,s,f,l=[],p=4,h=4,d=3,v="",g=[],y={val:n(0),position:r,index:1};for(o=0;o<3;o+=1)l[o]=o;for(i=0,c=Math.pow(2,2),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;switch(i){case 0:for(i=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;f=t(i);break;case 1:for(i=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;f=t(i);break;case 2:return""}for(l[3]=f,a=f,g.push(f);;){if(y.index>e)return"";for(i=0,c=Math.pow(2,d),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;switch(f=i){case 0:for(i=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;l[h++]=t(i),f=h-1,p--;break;case 1:for(i=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;l[h++]=t(i),f=h-1,p--;break;case 2:return g.join("")}if(0==p&&(p=Math.pow(2,d),d++),l[f])v=l[f];else{if(f!==h)return null;v=a+a.charAt(0)}g.push(v),l[h++]=a+v.charAt(0),a=v,0==--p&&(p=Math.pow(2,d),d++)}}};return a}();null!=t&&(t.exports=e)});var U=[j,A],D=[C,z,J,function(){return{get:function(t,e){var r=t(e);if(!r)return r;var n=R.decompress(r);return null==n?r:this._deserialize(n)},set:function(t,e,r){var n=R.compress(this._serialize(r));t(e,n)}}}],H=b.createStore(U,D),L=a.Global;function K(){return L.sessionStorage}function B(t){return K().getItem(t)}var W=[{name:"sessionStorage",read:B,write:function(t,e){return K().setItem(t,e)},each:function(t){for(var e=K().length-1;e>=0;e--){var r=K().key(e);t(B(r),r)}},remove:function(t){return K().removeItem(t)},clearAll:function(){return K().clear()}},A],V=[C,z],G=b.createStore(W,V),Y=H,Q=G,X="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},Z="object"==typeof X&&X&&X.Object===Object&&X,tt="object"==typeof self&&self&&self.Object===Object&&self,et=Z||tt||Function("return this")(),rt=et.Symbol,nt=Object.prototype,ot=nt.hasOwnProperty,at=nt.toString,it=rt?rt.toStringTag:void 0;var ut=Object.prototype.toString;var ct="[object Null]",st="[object Undefined]",ft=rt?rt.toStringTag:void 0;function lt(t){return null==t?void 0===t?st:ct:ft&&ft in Object(t)?function(t){var e=ot.call(t,it),r=t[it];try{t[it]=void 0;var n=!0}catch(t){}var o=at.call(t);return n&&(e?t[it]=r:delete t[it]),o}(t):function(t){return ut.call(t)}(t)}function pt(t){return null!=t&&"object"==typeof t}var ht="[object Symbol]";function dt(t){return"symbol"==typeof t||pt(t)&<(t)==ht}function vt(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r0){if(++Gt>=Kt)return arguments[0]}else Gt=0;return Vt.apply(void 0,arguments)});function Zt(t){return t!=t}function te(t,e,r){return e==e?function(t,e,r){for(var n=r-1,o=t.length;++n-1&&t%1==0&&t-1&&t%1==0&&t<=fe}function pe(t){return null!=t&&le(t.length)&&!Et(t)}var he=Object.prototype;function de(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||he)}var ve="[object Arguments]";function ge(t){return pt(t)&<(t)==ve}var ye=Object.prototype,be=ye.hasOwnProperty,me=ye.propertyIsEnumerable,_e=ge(function(){return arguments}())?ge:function(t){return pt(t)&&be.call(t,"callee")&&!me.call(t,"callee")};var we="object"==typeof exports&&exports&&!exports.nodeType&&exports,je=we&&"object"==typeof module&&module&&!module.nodeType&&module,Se=je&&je.exports===we?et.Buffer:void 0,Oe=(Se?Se.isBuffer:void 0)||function(){return!1},ke={};ke["[object Float32Array]"]=ke["[object Float64Array]"]=ke["[object Int8Array]"]=ke["[object Int16Array]"]=ke["[object Int32Array]"]=ke["[object Uint8Array]"]=ke["[object Uint8ClampedArray]"]=ke["[object Uint16Array]"]=ke["[object Uint32Array]"]=!0,ke["[object Arguments]"]=ke["[object Array]"]=ke["[object ArrayBuffer]"]=ke["[object Boolean]"]=ke["[object DataView]"]=ke["[object Date]"]=ke["[object Error]"]=ke["[object Function]"]=ke["[object Map]"]=ke["[object Number]"]=ke["[object Object]"]=ke["[object RegExp]"]=ke["[object Set]"]=ke["[object String]"]=ke["[object WeakMap]"]=!1;var Ae="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ee=Ae&&"object"==typeof module&&module&&!module.nodeType&&module,Te=Ee&&Ee.exports===Ae&&Z.process,xe=function(){try{var t=Ee&&Ee.require&&Ee.require("util").types;return t||Te&&Te.binding&&Te.binding("util")}catch(t){}}(),Pe=xe&&xe.isTypedArray,Ce=Pe?function(t){return function(e){return t(e)}}(Pe):function(t){return pt(t)&&le(t.length)&&!!ke[lt(t)]},qe=Object.prototype.hasOwnProperty;function ze(t,e){var r=gt(t),n=!r&&_e(t),o=!r&&!n&&Oe(t),a=!r&&!n&&!o&&Ce(t),i=r||n||o||a,u=i?function(t,e){for(var r=-1,n=Array(t);++r-1},Xe.prototype.set=function(t,e){var r=this.__data__,n=Ye(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var Ze=Rt(et,"Map");function tr(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function er(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e=n?t:function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var a=Array(o);++nu))return!1;var s=a.get(t);if(s&&a.get(e))return s==e;var f=-1,l=!0,p=r&ln?new cn:void 0;for(a.set(t,e),a.set(e,t);++f1?e[n-1]:void 0,a=n>2?e[2]:void 0;for(o=po.length>3&&"function"==typeof o?(n--,o):void 0,a&&function(t,e,r){if(!wt(r))return!1;var n=typeof e;return!!("number"==n?pe(r)&&ne(e,r.length):"string"==n&&e in r)&&ae(r[e],t)}(e[0],e[1],a)&&(o=n<3?void 0:o,n=1),t=Object(t);++r-1;);return r}(n,o),function(t,e){for(var r=t.length;r--&&te(e,t[r],0)>-1;);return r}(n,o)+1).join("")}function wo(t){return!!gt(t)||null!=t&&""!==_o(t)}var jo=function(t){return!io(t)&&!so(parseFloat(t))},So=function(t){return""!==_o(t)&&io(t)},Oo=function(t){return function(t){return!0===t||!1===t||pt(t)&<(t)==uo}(t)},ko=function(t,e){return void 0===e&&(e=!0),!fo(t)&&""!==t&&""!==_o(t)&&(!1===e||!0===e&&!function(t){return null===t}(t))},Ao="application/vnd.api+json",Eo={Accept:Ao,"Content-Type":[Ao,"charset=utf-8"].join(";")},To="payload",xo="condition",Po="args",Co=["POST","PUT"],qo="type",zo="optional",No="enumv",Io="args",$o="checker",Fo="alias",Jo={desc:"y"},Mo="No message",Ro=qo,Uo=zo,Do=No,Ho=Io,Lo=$o,Ko=Fo,Bo="continue",Wo=function(t){switch(t){case"number":return jo;case"string":return So;case"boolean":return Oo;default:return ko}},Vo=function(t,e){return void 0===e&&(e=""),!!gt(t)&&(""===e||""===_o(e)||!(t.filter(function(t){return!Wo(e)(t)}).length>0))},Go=function(t){if(t.indexOf("array.<")>-1&&t.indexOf(">")>-1){var e=t.replace("array.<","").replace(">","");return e.indexOf("|")?e.split("|"):[e]}return!1},Yo=function(t,e){var r=t.arg;return e.length>1?!r.filter(function(t){return!(e.length>e.filter(function(e){return!Wo(e)(t)}).length)}).length:e.length>e.filter(function(t){return!Vo(r,t)}).length},Qo=function(t,e){if(void 0===e&&(e=null),wr(t)){if(!e)return!0;if(Vo(e))return!e.filter(function(e){var r=t[e.name];return!(e.type.length>e.type.filter(function(t){var e;return!!fo(r)||(!1!==(e=Go(t))?!Yo({arg:r},e):!Wo(t)(r))}).length)}).length}return!1},Xo=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 406},r.name.get=function(){return"Jsonql406Error"},Object.defineProperties(e,r),e}(Error),Zo=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"Jsonql500Error"},Object.defineProperties(e,r),e}(Error),ta=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(e,r),e}(Error),ea=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(e,r),e}(Error),ra=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(e,r),e}(Error),na=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 404},r.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(e,r),e}(Error),oa=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(e,r),e}(Error),aa=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(e,r),e}(Error),ia=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(e,r),e}(Error),ua=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(e,r),e}(Error),ca=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0},statusCode:{configurable:!0}};return r.name.get=function(){return"JsonqlError"},r.statusCode.get=function(){return-1},Object.defineProperties(e,r),e}(Error),sa=function(t){function e(r,n){t.call(this,n),this.statusCode=r,this.className=e.name}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlServerError"},Object.defineProperties(e,r),e}(Error),fa=Object.freeze({Jsonql406Error:Xo,Jsonql500Error:Zo,JsonqlAuthorisationError:ta,JsonqlContractAuthError:ea,JsonqlResolverAppError:ra,JsonqlResolverNotFoundError:na,JsonqlEnumError:oa,JsonqlTypeError:aa,JsonqlCheckerError:ia,JsonqlValidationError:ua,JsonqlError:ca,JsonqlServerError:sa}),la=ca,pa=function(t,e){return!!Object.keys(t).filter(function(t){return e===t}).length};function ha(t){if(pa(t,"error")){var e=t.error,r=e.className,n=e.name,o=r||n,a=e.message||Mo,i=e.detail||e;if(o&&fa[o])throw new fa[r](a,i);throw new la(a,i)}return t}function da(t){if(Array.isArray(t))throw new ua("",t);var e=t.message||Mo,r=t.detail||t;switch(!0){case t instanceof Xo:throw new Xo(e,r);case t instanceof Zo:throw new Zo(e,r);case t instanceof ta:throw new ta(e,r);case t instanceof ea:throw new ea(e,r);case t instanceof ra:throw new ra(e,r);case t instanceof na:throw new na(e,r);case t instanceof oa:throw new oa(e,r);case t instanceof aa:throw new aa(e,r);case t instanceof ia:throw new ia(e,r);case t instanceof ua:throw new ua(e,r);case t instanceof sa:throw new sa(e,r);default:throw new ca(e,r)}}var va=function(t,e){var r,n,o,a,i;switch(!0){case"object"===t:return o=(n=e).arg,a=n.param,i=[o],Array.isArray(a.keys)&&a.keys.length&&i.push(a.keys),!Qo.apply(null,i);case"array"===t:return!Vo(e.arg);case!1!==(r=Go(t)):return!Yo(e,r);default:return!Wo(t)(e.arg)}},ga=function(t,e){return fo(t)?!0!==e.optional||fo(e.defaultvalue)?null:e.defaultvalue:t},ya=function(t,e,r){var n;void 0===r&&(r=!1);var o=function(t,e){if(!Vo(e))throw new ca("params is not an array! Did something gone wrong when you generate the contract.json?");if(0===e.length)return[];if(!Vo(t))throw new ca("args is not an array! You might want to do: ES6 Array.from(arguments) or ES5 Array.prototype.slice.call(arguments)");switch(!0){case t.length==e.length:return t.map(function(t,r){return{arg:t,index:r,param:e[r]}});case!0===e[0].variable:var r=e[0].type;return t.map(function(t,n){return{arg:t,index:n,param:e[n]||{type:r,name:"_"}}});case t.lengthe.length&&1===e.length:var n,o=["any"];return!1!==(n=Go(e[0].type[0]))&&(o=n),t.map(function(t,r){return{arg:t,index:r,param:e[r]||{type:o,name:"_"}}});default:throw new ca("Could not understand your arguments and parameter structure!",{args:t,params:e})}}(t,e),a=o.filter(function(t){return!0===t.param.optional?function(t){var e=t.arg,r=t.param;return!(!wo(e)||r.type.length>r.type.filter(function(e){return va(e,t)}).length)}(t):!(t.param.type.length>t.param.type.filter(function(e){return va(e,t)}).length)});return r?((n={}).error=a,n.data=o.map(function(t){return t.arg}),n):a},ba=function(t,e){return!!t.filter(function(t){return t===e}).length},ma=function(t,e){var r=Object.keys(t);return ba(r,e)},_a=function(t){return!wo(t)};function wa(t,e){var r=bo(e,function(t,e){return!t[Ko]});return Jn(r,{})?t:function(t,e){var r={};return e=Yn(e),Zn(t,function(t,n,o){oe(r,e(t,n,o),t)}),r}(t,function(t,e){return function(t,e,r){var n;return r(t,function(t,r,o){if(e(t,r,o))return n=r,!1}),n}(r,Yn(function(t){return t.alias===e}),Zn)||e})}function ja(t,e){return lo(e,function(e,r){var n,o;return fo(t[r])||!0===e[Uo]&&_a(t[r])?ho({},e,((n={})[Bo]=!0,n)):((o={})[Ho]=t[r],o[Ro]=e[Ro],o[Uo]=e[Uo]||!1,o[Do]=e[Do]||!1,o[Lo]=e[Lo]||!1,o)})}function Sa(t,e){var r=function(t,e){var r=wa(t,e);return{pristineValues:lo(bo(e,function(t,e){return ma(r,e)}),function(t){return t.args}),checkAgainstAppProps:bo(e,function(t,e){return!ma(r,e)}),config:r}}(t,e),n=r.config,o=r.pristineValues;return[ja(n,r.checkAgainstAppProps),o]}var Oa=function(t){return Vo(t)?t:[t]};var ka=function(t,e){return!Vo(e)||function(t,e){return!!t.filter(function(t){return t===e}).length}(e,t)},Aa=function(t,e){try{return!!Et(e)&&e.apply(null,[t])}catch(t){return!1}};function Ea(t){return function(e,r){if(e[Bo])return e[Ho];var n=function(t,e){var r,n=[[t[Ho]],[(r={},r[Ro]=Oa(t[Ro]),r[Uo]=t[Uo],r)]];return Reflect.apply(e,null,n)}(e,t);if(n.length)throw new aa(r,n);if(!1!==e[Do]&&!ka(e[Ho],e[Do]))throw new oa(r);if(!1!==e[Lo]&&!Aa(e[Ho],e[Lo]))throw new ia(r);return e[Ho]}}var Ta=function(t,e){return Promise.resolve(Sa(t,e))};function xa(t,e,r,n){return void 0===t&&(t={}),Ta(t,e).then(function(t){return function(t,e){var r=t[0],n=t[1],o=lo(r,Ea(e));return ho(o,n)}(t,n)}).then(function(t){return ho({},t,r)})}var Pa=Qo,Ca=So,qa=Vo,za=function(t,e,r){return void 0===r&&(r=!1),new Promise(function(n,o){var a=ya(t,e,r);return r?a.error.length?o(a.error):n(a.data):a.length?o(a):n([])})},Na=function(t,e,r){void 0===r&&(r={});var n=r[zo],o=r[No],a=r[$o],i=r[Fo];return function(t,e,r,n,o,a){void 0===r&&(r=!1),void 0===n&&(n=!1),void 0===o&&(o=!1),void 0===a&&(a=!1);var i={};return i[Io]=t,i[qo]=e,!0===r&&(i[zo]=!0),Vo(n)&&(i[No]=n),Et(o)&&(i[$o]=o),io(a)&&(i[Fo]=a),i}.apply(null,[t,e,n,o,a,i])},Ia=function(t){return function(e,r,n){return void 0===n&&(n={}),xa(e,r,n,t)}}(ya),$a=ba,Fa=ma,Ja=function(t,e,r){var n;if(void 0===e&&(e=[]),void 0===r&&(r=!1),So(t)&&Vo(e)){var o={};return o[Po]=e,!0===r?o:((n={})[t]=o,n)}throw new ua("[createQuery] expect resolverName to be string and args to be array!",{resolverName:t,args:e})},Ma=function(t,e,r,n){var o;void 0===r&&(r={}),void 0===n&&(n=!1);var a={};if(a[To]=e,a[xo]=r,!0===n)return a;if(So(t))return(o={})[t]=a,o;throw new ua("[createMutation] expect resolverName to be string!",{resolverName:t,payload:e,condition:r})},Ra=function(t){return Object.keys(t)[0]},Ua=function(){return Math.floor(Date.now()/1e3)},Da=function(t,e){return void 0===e&&(e={}),La(e)?Promise.resolve(e):t.getContract()},Ha=function(t){return Fa(t,"data")&&!Fa(t,"error")?t.data:t},La=function(t){return t&&Pa(t)&&(Fa(t,"query")||Fa(t,"mutation"))},Ka="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function Ba(t){this.message=t}Ba.prototype=new Error,Ba.prototype.name="InvalidCharacterError";var Wa="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new Ba("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,n,o=0,a=0,i="";n=e.charAt(a++);~n&&(r=o%4?64*r+n:n,o++%4)?i+=String.fromCharCode(255&r>>(-2*o&6)):0)n=Ka.indexOf(n);return i};var Va=function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(Wa(t).replace(/(.)/g,function(t,e){var r=e.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}(e)}catch(t){return Wa(e)}};function Ga(t){this.message=t}Ga.prototype=new Error,Ga.prototype.name="InvalidTokenError";var Ya,Qa,Xa,Za,ti,ei,ri,ni,oi,ai=function(t,e){if("string"!=typeof t)throw new Ga("Invalid token specified");var r=!0===(e=e||{}).header?0:1;try{return JSON.parse(Va(t.split(".")[r]))}catch(t){throw new Ga("Invalid token specified: "+t.message)}},ii=Ga;function ui(t){if(Ca(t))return function(t){var e=t.iat||Math.floor(Date.now()/1e3);if(t.exp&&e>=t.exp){var r=new Date(t.exp).toISOString();throw new ca("Token has expired on "+r,t)}return t}(ai(t));throw new ca("Token must be a string!")}ai.InvalidTokenError=ii;Na("HS256",["string"]),Na(!1,["boolean","number","string"],((Ya={})[Fo]="exp",Ya[zo]=!0,Ya)),Na(!1,["boolean","number","string"],((Qa={})[Fo]="nbf",Qa[zo]=!0,Qa)),Na(!1,["boolean","string"],((Xa={})[Fo]="iss",Xa[zo]=!0,Xa)),Na(!1,["boolean","string"],((Za={})[Fo]="sub",Za[zo]=!0,Za)),Na(!1,["boolean","string"],((ti={})[Fo]="iss",ti[zo]=!0,ti)),Na(!1,["boolean"],((ei={})[zo]=!0,ei)),Na(!1,["boolean","string"],((ri={})[zo]=!0,ri)),Na(!1,["boolean","string"],((ni={})[zo]=!0,ni)),Na(!1,["boolean"],((oi={})[zo]=!0,oi));!function(){switch(!0){case"undefined"!=typeof WebSocket:return WebSocket;case"undefined"!=typeof MozWebSocket:return MozWebSocket;case"undefined"!=typeof window:return window.WebSocket||window.MozWebSocket;default:throw new ua("WebSocket is NOT SUPPORTED!")}}();var ci=Co[0],si=Co[1],fi=function(t){this.opts=t,this.extraHeader={},this.extraParams={},this.reqInterceptor(),this.resInterceptor()},li={headers:{configurable:!0}};li.headers.set=function(t){this.extraHeader=t},fi.prototype.request=function(t,e,r){var n;void 0===e&&(e={}),void 0===r&&(r={}),this.headers=r;var o=ho({},{_cb:Ua()},this.extraParams);if(this.opts.enableJsonp){var a=Ra(t);o=ho({},o,((n={}).jsonqlJsonpCallback=a,n)),t=t[a]}return this.fly.request(this.jsonqlEndpoint,t,ho({},{method:ci,params:o},e))},fi.prototype.reqInterceptor=function(){var t=this;this.fly.interceptors.request.use(function(e){console.info("request interceptor call");var r=t.getHeaders();for(var n in r)e.headers[n]=r[n];return e})},fi.prototype.processJsonp=function(t){return Ha(t)},fi.prototype.resInterceptor=function(){var t=this,e=t.opts.enableJsonp;this.fly.interceptors.response.use(function(r){console.info("response interceptor call"),t.cleanUp();var n=Ca(r.data)?JSON.parse(r.data):r.data;return e?t.processJsonp(n):Ha(n)},function(e){throw t.cleanUp(),console.error(e),new sa("Server side error",e)})},fi.prototype.getHeaders=function(){return this.opts.enableAuth?ho({},Eo,this.getAuthHeader(),this.extraHeader):ho({},Eo,this.extraHeader)},fi.prototype.cleanUp=function(){this.extraHeader={},this.extraParams={}},fi.prototype.get=function(){return this.opts.showContractDesc&&(this.extraParams=ho({},this.extraParams,Jo)),this.request({},{method:"GET"},this.contractHeader).then(ha).then(function(t){return console.info("144 get contract result",t),t.cache&&t.contract?t.contract:t})},fi.prototype.query=function(t,e){return void 0===e&&(e=[]),this.request(Ja(t,e)).then(ha)},fi.prototype.mutation=function(t,e,r){return void 0===e&&(e={}),void 0===r&&(r={}),this.request(Ma(t,e,r),{method:si}).then(ha)},Object.defineProperties(fi.prototype,li);var pi=function(t){function e(e,r){t.call(this,e),null!==r&&(this.fly=new r)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={storeIt:{configurable:!0},jsonqlEndpoint:{configurable:!0},jsonqlContract:{configurable:!0},jsonqlToken:{configurable:!0},jsonqlUserdata:{configurable:!0}};return r.storeIt.set=function(t){throw console.info("storeIt",t),qa(t)&&t.length>=2&&Reflect.apply(Y.set,Y,t),new ua("Expect argument to be array and least 2 items!")},r.jsonqlEndpoint.set=function(t){var e=Y.get("endpoint")||[];$a(e,t)||(e.push(t),this.storeId=["endpoint",e],this.endpointIndex=e.length-1)},r.jsonqlContract.set=function(t){var e=this.opts.storageKey,r=[e],n=t[0],o=t[1],a=Y.get(e)||[];a[this.endpointIndex||0]=n,r.push(a),o&&r.push(o),this.opts.keepContract&&(this.storeIt=r)},r.jsonqlToken.set=function(t){var e="credential",r=localStorage.get(e)||[];if(!$a(r,t)){var n=r.length-1;r[n]=t,this[e+"Index"]=n;var o=[e,r];if(this.opts.tokenExpired){var a=parseFloat(this.opts.tokenExpired);if(!isNaN(a)&&a>0){var i=Ua();o.push(i+parseFloat(a))}}return this.storeIt=o,this.jsonqlUserdata=this.decoder(t),t}return!1},r.jsonqlUserdata.set=function(t){var e=["userdata",t];return t.exp&&e.push(t.exp),Reflect.apply(Y.set,Y,e)},r.jsonqlEndpoint.get=function(){var t=Y.get("endpoint");if(!t){var e=this.opts,r=[e.hostname,e.jsonqlPath].join("/");return this.jsonqlEndpoint=r,r}return t[this.endpointIndex]},r.jsonqlContract.get=function(){var t=this.opts.storageKey;return(Y.get(t)||[])[this.endpointIndex]||!1},r.jsonqlToken.get=function(){var t="credential",e=localStorage.get(t);return!!e&&e[this[t+"Index"]]},r.jsonqlUserdata.get=function(){return Q.get("userdata")},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),e.enableAuth&&e.useJwt&&(this.setDecoder=ui)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={userdata:{configurable:!0},rawAuthToken:{configurable:!0},setDecoder:{configurable:!0}};return r.userdata.get=function(){return this.jsonqlUserdata},r.rawAuthToken.get=function(){return this.jsonqlToken},r.setDecoder.set=function(t){"function"==typeof t&&(this.decoder=t)},e.prototype.storeToken=function(t){return this.jsonqlToken=t},e.prototype.decoder=function(t){return t},e.prototype.getAuthHeader=function(){var t,e=this.rawAuthToken;return e?((t={})[this.opts.AUTH_HEADER]="Bearer "+e,t):{}},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={contractHeader:{configurable:!0}};return e.prototype.getContract=function(){var t=this.readContract();if(console.info("getContract first call",t),t&&Array.isArray(t)){var e=t[this.endpointIndex||0];if(e)return Promise.resolve(e)}return this.get().then(this.storeContract.bind(this))},r.contractHeader.get=function(){var t={};return!1!==this.opts.contractKey&&(t[this.opts.contractKeyName]=this.opts.contractKey),t},e.prototype.storeContract=function(t){if(!La(t))throw new ua("Contract is malformed!");var e=[t];if(this.opts.contractExpired){var r=parseFloat(this.opts.contractExpired);!isNaN(r)&&r>0&&e.push(r)}return this.jsonqlContract=e,console.info("storeContract return result",t),t},e.prototype.readContract=function(){return La(this.opts.contract)?this.opts.contract:Y.get(this.opts.storageKey)},Object.defineProperties(e.prototype,r),e}(fi))),hi=new WeakMap,di=new WeakMap;var vi=function(t){void 0===t&&(t={}),t.logger&&"function"==typeof t.logger&&(this.logger=t.logger),this.keep=t.keep,this.result=t.keep?[]:null,this.normalStore=new Map,this.lazyStore=new Map},gi={$done:{configurable:!0},normalStore:{configurable:!0},lazyStore:{configurable:!0}};vi.prototype.logger=function(){},vi.prototype.$on=function(t,e,r){var n=this;void 0===r&&(r=null);this.validate(t,e);var o=this.takeFromStore(t);if(!1===o)return this.logger("$on",t+" callback is not in lazy store"),this.addToNormalStore(t,"on",e,r);this.logger("$on",t+" found in lazy store");var a=0;return o.forEach(function(o){var i=o[0],u=o[1],c=o[2];if(c&&"on"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);n.run(e,i,r||u),a+=n.addToNormalStore(t,"on",e,r||u)}),a},vi.prototype.$once=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=this.takeFromStore(t);this.normalStore;if(!1===n)return this.logger("$once",t+" not in the lazy store"),this.addToNormalStore(t,"once",e,r);this.logger("$once",n);var o=Array.from(n)[0],a=o[0],i=o[1],u=o[2];if(u&&"once"!==u)throw new Error("You are trying to register an event already been taken by other type: "+u);this.run(e,a,r||i),this.$off(t)},vi.prototype.$only=function(t,e,r){var n=this;void 0===r&&(r=null),this.validate(t,e);var o=!1,a=this.takeFromStore(t);(this.normalStore.has(t)||(this.logger("$only",t+" add to store"),o=this.addToNormalStore(t,"only",e,r)),!1!==a)&&(this.logger("$only",t+" found data in lazy store to execute"),Array.from(a).forEach(function(t){var o=t[0],a=t[1],i=t[2];if(i&&"only"!==i)throw new Error("You are trying to register an event already been taken by other type: "+i);n.run(e,o,r||a)}));return o},vi.prototype.$onlyOnce=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=!1,o=this.takeFromStore(t);if(this.normalStore.has(t)||(this.logger("$onlyOnce",t+" add to store"),n=this.addToNormalStore(t,"onlyOnce",e,r)),!1!==o){this.logger("$onlyOnce",o);var a=Array.from(o)[0],i=a[0],u=a[1],c=a[2];if(c&&"onlyOnce"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);this.run(e,i,r||u),this.$off(t)}return n},vi.prototype.$replace=function(t,e,r,n){if(void 0===r&&(r=null),void 0===n&&(n="on"),this.validateType(n)){this.$off(t);var o=this["$"+n];return Reflect.apply(o,this,[t,e,r])}throw new Error(n+" is not supported!")},vi.prototype.$trigger=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1),this.validateEvt(t);var o=0,a=this.normalStore;if(this.logger("$trigger",a),a.has(t)){this.logger("$trigger",t,"found");for(var i=Array.from(a.get(t)),u=i.length,c=!1,s=0;s0;)n[o]=arguments[o+2];if(t.has(e)?(this.logger("addToStore",e+" existed"),r=t.get(e)):(this.logger("addToStore","create new Set for "+e),r=new Set),n.length>2)if(Array.isArray(n[0])){var a=n[2];this.checkTypeInLazyStore(e,a)||r.add(n)}else this.checkContentExist(n,r)||(this.logger("addToStore","insert new",n),r.add(n));else r.add(n);return t.set(e,r),[t,r.size]},vi.prototype.checkContentExist=function(t,e){return!!Array.from(e).filter(function(e){return e[0]===t[0]}).length},vi.prototype.checkTypeInStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.$get(t,!0);return!1===r||!r.filter(function(t){var r=t[3];return e!==r}).length},vi.prototype.checkTypeInLazyStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.lazyStore.get(t);return this.logger("checkTypeInLazyStore",r),!!r&&!!Array.from(r).filter(function(t){return t[2]!==e}).length},vi.prototype.addToNormalStore=function(t,e,r,n){if(void 0===n&&(n=null),this.logger("addToNormalStore",t,e,"add to normal store"),this.checkTypeInStore(t,e)){this.logger(e+" can add to "+t+" store");var o=this.hashFnToKey(r),a=[this.normalStore,t,o,r,n,e],i=Reflect.apply(this.addToStore,this,a),u=i[0],c=i[1];return this.normalStore=u,c}return!1},vi.prototype.addToLazyStore=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1);var o=[this.lazyStore,t,this.toArray(e),r];n&&o.push(n);var a=Reflect.apply(this.addToStore,this,o),i=a[0],u=a[1];return this.lazyStore=i,u},vi.prototype.toArray=function(t){return Array.isArray(t)?t:[t]},gi.normalStore.set=function(t){hi.set(this,t)},gi.normalStore.get=function(){return hi.get(this)},gi.lazyStore.set=function(t){di.set(this,t)},gi.lazyStore.get=function(){return di.get(this)},vi.prototype.hashFnToKey=function(t){return t.toString().split("").reduce(function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t},0)+""},Object.defineProperties(vi.prototype,gi);var yi=new vi,bi=function(t,e,r,n){return function(){for(var r=[],o=arguments.length;o--;)r[o]=arguments[o];var a=n.auth[e].params,i=a.map(function(t,e){return r[e]}),u=r[a.length]||{};return za(r,a).then(function(){return t.query.apply(t,[e,i,u])}).catch(da)}},mi=function(t,e,r){var n={query:{},mutation:{},auth:{}},o=function(e){n.query[e]=function(){for(var n=[],o=arguments.length;o--;)n[o]=arguments[o];var a=r.query[e].params,i=a.map(function(t,e){return n[e]}),u=n[a.length]||{};return za(i,a).then(function(){return t.query.apply(t,[e,i,u])}).catch(da)}};for(var a in r.query)o(a);var i=function(e){n.mutation[e]=function(n,o,a){void 0===a&&(a={});var i=[n,o],u=r.mutation[e].params;return za(i,u).then(function(){return t.mutation.apply(t,[e,n,o,a])}).catch(da)}};for(var u in r.mutation)i(u);if(e.enableAuth&&r.auth){var c=e.loginHandlerName,s=e.logoutHandlerName;r.auth[c]&&(n[c]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=bi(t,c,0,r);return o.apply(null,e).then(t.postLoginAction).then(function(t){return yi.$trigger("login",t),t})}),r.auth[s]?n[s]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=bi(t,s,0,r);return o.apply(null,e).then(t.postLogoutAction).then(function(t){return yi.$trigger("logout",t),t})}:n[s]=function(){t.postLogoutAction("continue"),yi.$trigger("logout","continue")},n.userdata=function(){return t.userdata}}return n.returnInstance&&(n.jsonqlClientInstance=t),n.getToken=function(){return t.rawAuthToken},n.eventEmitter=yi,n},_i={contract:!1,MUTATION_ARGS:["name","payload","conditions"],CONTENT_TYPE:Ao,BEARER:"Bearer",AUTH_HEADER:"Authorization"},wi={hostname:Na([window.location.protocol,window.location.host].join("//"),["string"]),jsonqlPath:Na("jsonql",["string"]),loginHandlerName:Na("login",["string"]),logoutHandlerName:Na("logout",["string"]),enableJsonp:Na(!1,["boolean"]),enableAuth:Na(!1,["boolean"]),useJwt:Na(!0,["boolean"]),useLocalstorage:Na(!0,["boolean"]),storageKey:Na("storageKey",["string"]),authKey:Na("authKey",["string"]),contractExpired:Na(0,["number"]),keepContract:Na(!0,["boolean"]),showContractDesc:Na(!1,["boolean"]),contractKey:Na(!1,["boolean"]),contractKeyName:Na("X-JSONQL-CV-KEY",["string"]),enableTimeout:Na(!1,["boolean"]),timeout:Na(5e3,["number"]),returnInstance:Na(!1,["boolean"]),allowReturnRawToken:Na(!1,["boolean"]),debugOn:Na(!1,["boolean"])};return function(t,e){return void 0===t&&(t={}),void 0===e&&(e=null),function(t){var e=t.contract;return Ia(t,wi,_i).then(function(t){return t.contract=e,t})}(t).then(function(t){return{baseClient:new pi(t,e),opts:t}}).then(function(t){var e=t.baseClient,r=t.opts;return Da(e,r.contract).then(function(t){return mi(e,r,t)})})}}); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).jsonqlClient=e()}(this,function(){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var e=Object.assign?Object.assign:function(t,e,r,n){for(var o=arguments,a=1;a=0;e--){var r=S().key(e);t(O(r),r)}},remove:function(t){return S().removeItem(t)},clearAll:function(){return S().clear()}};function S(){return w.localStorage}function O(t){return S().getItem(t)}var k=a.trim,A={name:"cookieStorage",read:function(t){if(!t||!P(t))return null;var e="(?:^|.*;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(E.cookie.replace(new RegExp(e),"$1"))},write:function(t,e){if(!t)return;E.cookie=escape(t)+"="+escape(e)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"},each:T,remove:x,clearAll:function(){T(function(t,e){x(e)})}},E=a.Global.document;function T(t){for(var e=E.cookie.split(/; ?/g),r=e.length-1;r>=0;r--)if(k(e[r])){var n=e[r].split("="),o=unescape(n[0]);t(unescape(n[1]),o)}}function x(t){t&&P(t)&&(E.cookie=escape(t)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function P(t){return new RegExp("(?:^|;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(E.cookie)}var C=function(){var t={};return{defaults:function(e,r){t=r},get:function(e,r){var n=e();return void 0!==n?n:t[r]}}};var q="expire_mixin",z=function(){var t=this.createStore(this.storage,null,this._namespacePrefix+q);return{set:function(e,r,n,o){this.hasNamespace(q)||t.set(r,o);return e()},get:function(t,r){this.hasNamespace(q)||e.call(this,r);return t()},remove:function(e,r){this.hasNamespace(q)||t.remove(r);return e()},getExpiration:function(e,r){return t.get(r)},removeExpiredKeys:function(t){var r=[];this.each(function(t,e){r.push(e)});for(var n=0;n>>8,r[2*n+1]=i%256}return r},decompressFromUint8Array:function(e){if(null==e)return a.decompress(e);for(var r=new Array(e.length/2),n=0,o=r.length;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=i[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++),i[s]=p++,f=String(c)}if(""!==f){if(Object.prototype.hasOwnProperty.call(u,f)){if(f.charCodeAt(0)<256){for(n=0;n>=1}else{for(o=1,n=0;n>=1}0==--l&&(l=Math.pow(2,h),h++),delete u[f]}else for(o=i[f],n=0;n>=1;0==--l&&(l=Math.pow(2,h),h++)}for(o=2,n=0;n>=1;for(;;){if(v<<=1,g==e-1){d.push(r(v));break}g++}return d.join("")},decompress:function(t){return null==t?"":""==t?null:a._decompress(t.length,32768,function(e){return t.charCodeAt(e)})},_decompress:function(e,r,n){var o,a,i,u,c,s,f,l=[],p=4,h=4,d=3,v="",g=[],y={val:n(0),position:r,index:1};for(o=0;o<3;o+=1)l[o]=o;for(i=0,c=Math.pow(2,2),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;switch(i){case 0:for(i=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;f=t(i);break;case 1:for(i=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;f=t(i);break;case 2:return""}for(l[3]=f,a=f,g.push(f);;){if(y.index>e)return"";for(i=0,c=Math.pow(2,d),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;switch(f=i){case 0:for(i=0,c=Math.pow(2,8),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;l[h++]=t(i),f=h-1,p--;break;case 1:for(i=0,c=Math.pow(2,16),s=1;s!=c;)u=y.val&y.position,y.position>>=1,0==y.position&&(y.position=r,y.val=n(y.index++)),i|=(u>0?1:0)*s,s<<=1;l[h++]=t(i),f=h-1,p--;break;case 2:return g.join("")}if(0==p&&(p=Math.pow(2,d),d++),l[f])v=l[f];else{if(f!==h)return null;v=a+a.charAt(0)}g.push(v),l[h++]=a+v.charAt(0),a=v,0==--p&&(p=Math.pow(2,d),d++)}}};return a}();null!=t&&(t.exports=e)});var U=[j,A],D=[C,z,J,function(){return{get:function(t,e){var r=t(e);if(!r)return r;var n=R.decompress(r);return null==n?r:this._deserialize(n)},set:function(t,e,r){var n=R.compress(this._serialize(r));t(e,n)}}}],H=b.createStore(U,D),L=a.Global;function K(){return L.sessionStorage}function B(t){return K().getItem(t)}var W=[{name:"sessionStorage",read:B,write:function(t,e){return K().setItem(t,e)},each:function(t){for(var e=K().length-1;e>=0;e--){var r=K().key(e);t(B(r),r)}},remove:function(t){return K().removeItem(t)},clearAll:function(){return K().clear()}},A],V=[C,z],G=b.createStore(W,V),Y=H,Q=G,X="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},Z="object"==typeof X&&X&&X.Object===Object&&X,tt="object"==typeof self&&self&&self.Object===Object&&self,et=Z||tt||Function("return this")(),rt=et.Symbol,nt=Object.prototype,ot=nt.hasOwnProperty,at=nt.toString,it=rt?rt.toStringTag:void 0;var ut=Object.prototype.toString;var ct="[object Null]",st="[object Undefined]",ft=rt?rt.toStringTag:void 0;function lt(t){return null==t?void 0===t?st:ct:ft&&ft in Object(t)?function(t){var e=ot.call(t,it),r=t[it];try{t[it]=void 0;var n=!0}catch(t){}var o=at.call(t);return n&&(e?t[it]=r:delete t[it]),o}(t):function(t){return ut.call(t)}(t)}function pt(t){return null!=t&&"object"==typeof t}var ht="[object Symbol]";function dt(t){return"symbol"==typeof t||pt(t)&<(t)==ht}function vt(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r0){if(++Gt>=Kt)return arguments[0]}else Gt=0;return Vt.apply(void 0,arguments)});function Zt(t){return t!=t}function te(t,e,r){return e==e?function(t,e,r){for(var n=r-1,o=t.length;++n-1&&t%1==0&&t-1&&t%1==0&&t<=fe}function pe(t){return null!=t&&le(t.length)&&!Et(t)}var he=Object.prototype;function de(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||he)}var ve="[object Arguments]";function ge(t){return pt(t)&<(t)==ve}var ye=Object.prototype,be=ye.hasOwnProperty,me=ye.propertyIsEnumerable,_e=ge(function(){return arguments}())?ge:function(t){return pt(t)&&be.call(t,"callee")&&!me.call(t,"callee")};var we="object"==typeof exports&&exports&&!exports.nodeType&&exports,je=we&&"object"==typeof module&&module&&!module.nodeType&&module,Se=je&&je.exports===we?et.Buffer:void 0,Oe=(Se?Se.isBuffer:void 0)||function(){return!1},ke={};ke["[object Float32Array]"]=ke["[object Float64Array]"]=ke["[object Int8Array]"]=ke["[object Int16Array]"]=ke["[object Int32Array]"]=ke["[object Uint8Array]"]=ke["[object Uint8ClampedArray]"]=ke["[object Uint16Array]"]=ke["[object Uint32Array]"]=!0,ke["[object Arguments]"]=ke["[object Array]"]=ke["[object ArrayBuffer]"]=ke["[object Boolean]"]=ke["[object DataView]"]=ke["[object Date]"]=ke["[object Error]"]=ke["[object Function]"]=ke["[object Map]"]=ke["[object Number]"]=ke["[object Object]"]=ke["[object RegExp]"]=ke["[object Set]"]=ke["[object String]"]=ke["[object WeakMap]"]=!1;var Ae="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ee=Ae&&"object"==typeof module&&module&&!module.nodeType&&module,Te=Ee&&Ee.exports===Ae&&Z.process,xe=function(){try{var t=Ee&&Ee.require&&Ee.require("util").types;return t||Te&&Te.binding&&Te.binding("util")}catch(t){}}(),Pe=xe&&xe.isTypedArray,Ce=Pe?function(t){return function(e){return t(e)}}(Pe):function(t){return pt(t)&&le(t.length)&&!!ke[lt(t)]},qe=Object.prototype.hasOwnProperty;function ze(t,e){var r=gt(t),n=!r&&_e(t),o=!r&&!n&&Oe(t),a=!r&&!n&&!o&&Ce(t),i=r||n||o||a,u=i?function(t,e){for(var r=-1,n=Array(t);++r-1},Xe.prototype.set=function(t,e){var r=this.__data__,n=Ye(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var Ze=Rt(et,"Map");function tr(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function er(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e=n?t:function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var a=Array(o);++nu))return!1;var s=a.get(t);if(s&&a.get(e))return s==e;var f=-1,l=!0,p=r&ln?new cn:void 0;for(a.set(t,e),a.set(e,t);++f1?e[n-1]:void 0,a=n>2?e[2]:void 0;for(o=po.length>3&&"function"==typeof o?(n--,o):void 0,a&&function(t,e,r){if(!wt(r))return!1;var n=typeof e;return!!("number"==n?pe(r)&&ne(e,r.length):"string"==n&&e in r)&&ae(r[e],t)}(e[0],e[1],a)&&(o=n<3?void 0:o,n=1),t=Object(t);++r-1;);return r}(n,o),function(t,e){for(var r=t.length;r--&&te(e,t[r],0)>-1;);return r}(n,o)+1).join("")}function wo(t){return!!gt(t)||null!=t&&""!==_o(t)}var jo=function(t){return!io(t)&&!so(parseFloat(t))},So=function(t){return""!==_o(t)&&io(t)},Oo=function(t){return function(t){return!0===t||!1===t||pt(t)&<(t)==uo}(t)},ko=function(t,e){return void 0===e&&(e=!0),!fo(t)&&""!==t&&""!==_o(t)&&(!1===e||!0===e&&!function(t){return null===t}(t))},Ao="application/vnd.api+json",Eo={Accept:Ao,"Content-Type":[Ao,"charset=utf-8"].join(";")},To="payload",xo="condition",Po="args",Co=["POST","PUT"],qo="type",zo="optional",No="enumv",Io="args",$o="checker",Fo="alias",Jo={desc:"y"},Mo="No message",Ro=qo,Uo=zo,Do=No,Ho=Io,Lo=$o,Ko=Fo,Bo="continue",Wo=function(t){switch(t){case"number":return jo;case"string":return So;case"boolean":return Oo;default:return ko}},Vo=function(t,e){return void 0===e&&(e=""),!!gt(t)&&(""===e||""===_o(e)||!(t.filter(function(t){return!Wo(e)(t)}).length>0))},Go=function(t){if(t.indexOf("array.<")>-1&&t.indexOf(">")>-1){var e=t.replace("array.<","").replace(">","");return e.indexOf("|")?e.split("|"):[e]}return!1},Yo=function(t,e){var r=t.arg;return e.length>1?!r.filter(function(t){return!(e.length>e.filter(function(e){return!Wo(e)(t)}).length)}).length:e.length>e.filter(function(t){return!Vo(r,t)}).length},Qo=function(t,e){if(void 0===e&&(e=null),wr(t)){if(!e)return!0;if(Vo(e))return!e.filter(function(e){var r=t[e.name];return!(e.type.length>e.type.filter(function(t){var e;return!!fo(r)||(!1!==(e=Go(t))?!Yo({arg:r},e):!Wo(t)(r))}).length)}).length}return!1},Xo=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 406},r.name.get=function(){return"Jsonql406Error"},Object.defineProperties(e,r),e}(Error),Zo=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"Jsonql500Error"},Object.defineProperties(e,r),e}(Error),ta=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(e,r),e}(Error),ea=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 401},r.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(e,r),e}(Error),ra=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 500},r.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(e,r),e}(Error),na=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={statusCode:{configurable:!0},name:{configurable:!0}};return r.statusCode.get=function(){return 404},r.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(e,r),e}(Error),oa=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(e,r),e}(Error),aa=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(e,r),e}(Error),ia=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(e,r),e}(Error),ua=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(e,r),e}(Error),ca=function(t){function e(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];t.apply(this,r),this.message=r[0],this.detail=r[1],this.className=e.name,t.captureStackTrace&&t.captureStackTrace(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0},statusCode:{configurable:!0}};return r.name.get=function(){return"JsonqlError"},r.statusCode.get=function(){return-1},Object.defineProperties(e,r),e}(Error),sa=function(t){function e(r,n){t.call(this,n),this.statusCode=r,this.className=e.name}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={name:{configurable:!0}};return r.name.get=function(){return"JsonqlServerError"},Object.defineProperties(e,r),e}(Error),fa=Object.freeze({Jsonql406Error:Xo,Jsonql500Error:Zo,JsonqlAuthorisationError:ta,JsonqlContractAuthError:ea,JsonqlResolverAppError:ra,JsonqlResolverNotFoundError:na,JsonqlEnumError:oa,JsonqlTypeError:aa,JsonqlCheckerError:ia,JsonqlValidationError:ua,JsonqlError:ca,JsonqlServerError:sa}),la=ca,pa=function(t,e){return!!Object.keys(t).filter(function(t){return e===t}).length};function ha(t){if(pa(t,"error")){var e=t.error,r=e.className,n=e.name,o=r||n,a=e.message||Mo,i=e.detail||e;if(o&&fa[o])throw new fa[r](a,i);throw new la(a,i)}return t}function da(t){if(Array.isArray(t))throw new ua("",t);var e=t.message||Mo,r=t.detail||t;switch(!0){case t instanceof Xo:throw new Xo(e,r);case t instanceof Zo:throw new Zo(e,r);case t instanceof ta:throw new ta(e,r);case t instanceof ea:throw new ea(e,r);case t instanceof ra:throw new ra(e,r);case t instanceof na:throw new na(e,r);case t instanceof oa:throw new oa(e,r);case t instanceof aa:throw new aa(e,r);case t instanceof ia:throw new ia(e,r);case t instanceof ua:throw new ua(e,r);case t instanceof sa:throw new sa(e,r);default:throw new ca(e,r)}}var va=function(t,e){var r,n,o,a,i;switch(!0){case"object"===t:return o=(n=e).arg,a=n.param,i=[o],Array.isArray(a.keys)&&a.keys.length&&i.push(a.keys),!Qo.apply(null,i);case"array"===t:return!Vo(e.arg);case!1!==(r=Go(t)):return!Yo(e,r);default:return!Wo(t)(e.arg)}},ga=function(t,e){return fo(t)?!0!==e.optional||fo(e.defaultvalue)?null:e.defaultvalue:t},ya=function(t,e,r){var n;void 0===r&&(r=!1);var o=function(t,e){if(!Vo(e))throw new ca("params is not an array! Did something gone wrong when you generate the contract.json?");if(0===e.length)return[];if(!Vo(t))throw new ca("args is not an array! You might want to do: ES6 Array.from(arguments) or ES5 Array.prototype.slice.call(arguments)");switch(!0){case t.length==e.length:return t.map(function(t,r){return{arg:t,index:r,param:e[r]}});case!0===e[0].variable:var r=e[0].type;return t.map(function(t,n){return{arg:t,index:n,param:e[n]||{type:r,name:"_"}}});case t.lengthe.length&&1===e.length:var n,o=["any"];return!1!==(n=Go(e[0].type[0]))&&(o=n),t.map(function(t,r){return{arg:t,index:r,param:e[r]||{type:o,name:"_"}}});default:throw new ca("Could not understand your arguments and parameter structure!",{args:t,params:e})}}(t,e),a=o.filter(function(t){return!0===t.param.optional?function(t){var e=t.arg,r=t.param;return!(!wo(e)||r.type.length>r.type.filter(function(e){return va(e,t)}).length)}(t):!(t.param.type.length>t.param.type.filter(function(e){return va(e,t)}).length)});return r?((n={}).error=a,n.data=o.map(function(t){return t.arg}),n):a},ba=function(t,e){return!!t.filter(function(t){return t===e}).length},ma=function(t,e){var r=Object.keys(t);return ba(r,e)},_a=function(t){return!wo(t)};function wa(t,e){var r=bo(e,function(t,e){return!t[Ko]});return Jn(r,{})?t:function(t,e){var r={};return e=Yn(e),Zn(t,function(t,n,o){oe(r,e(t,n,o),t)}),r}(t,function(t,e){return function(t,e,r){var n;return r(t,function(t,r,o){if(e(t,r,o))return n=r,!1}),n}(r,Yn(function(t){return t.alias===e}),Zn)||e})}function ja(t,e){return lo(e,function(e,r){var n,o;return fo(t[r])||!0===e[Uo]&&_a(t[r])?ho({},e,((n={})[Bo]=!0,n)):((o={})[Ho]=t[r],o[Ro]=e[Ro],o[Uo]=e[Uo]||!1,o[Do]=e[Do]||!1,o[Lo]=e[Lo]||!1,o)})}function Sa(t,e){var r=function(t,e){var r=wa(t,e);return{pristineValues:lo(bo(e,function(t,e){return ma(r,e)}),function(t){return t.args}),checkAgainstAppProps:bo(e,function(t,e){return!ma(r,e)}),config:r}}(t,e),n=r.config,o=r.pristineValues;return[ja(n,r.checkAgainstAppProps),o]}var Oa=function(t){return Vo(t)?t:[t]};var ka=function(t,e){return!Vo(e)||function(t,e){return!!t.filter(function(t){return t===e}).length}(e,t)},Aa=function(t,e){try{return!!Et(e)&&e.apply(null,[t])}catch(t){return!1}};function Ea(t){return function(e,r){if(e[Bo])return e[Ho];var n=function(t,e){var r,n=[[t[Ho]],[(r={},r[Ro]=Oa(t[Ro]),r[Uo]=t[Uo],r)]];return Reflect.apply(e,null,n)}(e,t);if(n.length)throw new aa(r,n);if(!1!==e[Do]&&!ka(e[Ho],e[Do]))throw new oa(r);if(!1!==e[Lo]&&!Aa(e[Ho],e[Lo]))throw new ia(r);return e[Ho]}}var Ta=function(t,e){return Promise.resolve(Sa(t,e))};function xa(t,e,r,n){return void 0===t&&(t={}),Ta(t,e).then(function(t){return function(t,e){var r=t[0],n=t[1],o=lo(r,Ea(e));return ho(o,n)}(t,n)}).then(function(t){return ho({},t,r)})}var Pa=Qo,Ca=So,qa=Vo,za=function(t,e,r){return void 0===r&&(r=!1),new Promise(function(n,o){var a=ya(t,e,r);return r?a.error.length?o(a.error):n(a.data):a.length?o(a):n([])})},Na=function(t,e,r){void 0===r&&(r={});var n=r[zo],o=r[No],a=r[$o],i=r[Fo];return function(t,e,r,n,o,a){void 0===r&&(r=!1),void 0===n&&(n=!1),void 0===o&&(o=!1),void 0===a&&(a=!1);var i={};return i[Io]=t,i[qo]=e,!0===r&&(i[zo]=!0),Vo(n)&&(i[No]=n),Et(o)&&(i[$o]=o),io(a)&&(i[Fo]=a),i}.apply(null,[t,e,n,o,a,i])},Ia=function(t){return function(e,r,n){return void 0===n&&(n={}),xa(e,r,n,t)}}(ya),$a=ba,Fa=ma,Ja=function(t,e,r){var n;if(void 0===e&&(e=[]),void 0===r&&(r=!1),So(t)&&Vo(e)){var o={};return o[Po]=e,!0===r?o:((n={})[t]=o,n)}throw new ua("[createQuery] expect resolverName to be string and args to be array!",{resolverName:t,args:e})},Ma=function(t,e,r,n){var o;void 0===r&&(r={}),void 0===n&&(n=!1);var a={};if(a[To]=e,a[xo]=r,!0===n)return a;if(So(t))return(o={})[t]=a,o;throw new ua("[createMutation] expect resolverName to be string!",{resolverName:t,payload:e,condition:r})},Ra=function(t){return Object.keys(t)[0]},Ua=function(){return Math.floor(Date.now()/1e3)},Da=function(t,e){return void 0===e&&(e={}),La(e)?Promise.resolve(e):t.getContract()},Ha=function(t){return Fa(t,"data")&&!Fa(t,"error")?t.data:t},La=function(t){return t&&Pa(t)&&(Fa(t,"query")||Fa(t,"mutation"))},Ka="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function Ba(t){this.message=t}Ba.prototype=new Error,Ba.prototype.name="InvalidCharacterError";var Wa="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new Ba("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,n,o=0,a=0,i="";n=e.charAt(a++);~n&&(r=o%4?64*r+n:n,o++%4)?i+=String.fromCharCode(255&r>>(-2*o&6)):0)n=Ka.indexOf(n);return i};var Va=function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(Wa(t).replace(/(.)/g,function(t,e){var r=e.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}(e)}catch(t){return Wa(e)}};function Ga(t){this.message=t}Ga.prototype=new Error,Ga.prototype.name="InvalidTokenError";var Ya,Qa,Xa,Za,ti,ei,ri,ni,oi,ai=function(t,e){if("string"!=typeof t)throw new Ga("Invalid token specified");var r=!0===(e=e||{}).header?0:1;try{return JSON.parse(Va(t.split(".")[r]))}catch(t){throw new Ga("Invalid token specified: "+t.message)}},ii=Ga;function ui(t){if(Ca(t))return function(t){var e=t.iat||Math.floor(Date.now()/1e3);if(t.exp&&e>=t.exp){var r=new Date(t.exp).toISOString();throw new ca("Token has expired on "+r,t)}return t}(ai(t));throw new ca("Token must be a string!")}ai.InvalidTokenError=ii;Na("HS256",["string"]),Na(!1,["boolean","number","string"],((Ya={})[Fo]="exp",Ya[zo]=!0,Ya)),Na(!1,["boolean","number","string"],((Qa={})[Fo]="nbf",Qa[zo]=!0,Qa)),Na(!1,["boolean","string"],((Xa={})[Fo]="iss",Xa[zo]=!0,Xa)),Na(!1,["boolean","string"],((Za={})[Fo]="sub",Za[zo]=!0,Za)),Na(!1,["boolean","string"],((ti={})[Fo]="iss",ti[zo]=!0,ti)),Na(!1,["boolean"],((ei={})[zo]=!0,ei)),Na(!1,["boolean","string"],((ri={})[zo]=!0,ri)),Na(!1,["boolean","string"],((ni={})[zo]=!0,ni)),Na(!1,["boolean"],((oi={})[zo]=!0,oi));!function(){switch(!0){case"undefined"!=typeof WebSocket:return WebSocket;case"undefined"!=typeof MozWebSocket:return MozWebSocket;case"undefined"!=typeof window:return window.WebSocket||window.MozWebSocket;default:throw new ua("WebSocket is NOT SUPPORTED!")}}();var ci=Co[0],si=Co[1],fi=function(t){this.fly=t.Fly?new t.Fly:new Fly,this.opts=t,this.extraHeader={},this.extraParams={},this.reqInterceptor(),this.resInterceptor()},li={headers:{configurable:!0}};li.headers.set=function(t){this.extraHeader=t},fi.prototype.request=function(t,e,r){var n;void 0===e&&(e={}),void 0===r&&(r={}),this.headers=r;var o=ho({},{_cb:Ua()},this.extraParams);if(this.opts.enableJsonp){var a=Ra(t);o=ho({},o,((n={}).jsonqlJsonpCallback=a,n)),t=t[a]}return this.fly.request(this.jsonqlEndpoint,t,ho({},{method:ci,params:o},e))},fi.prototype.reqInterceptor=function(){var t=this;this.fly.interceptors.request.use(function(e){console.info("request interceptor call");var r=t.getHeaders();for(var n in r)e.headers[n]=r[n];return e})},fi.prototype.processJsonp=function(t){return Ha(t)},fi.prototype.resInterceptor=function(){var t=this,e=t.opts.enableJsonp;this.fly.interceptors.response.use(function(r){console.info("response interceptor call"),t.cleanUp();var n=Ca(r.data)?JSON.parse(r.data):r.data;return e?t.processJsonp(n):Ha(n)},function(e){throw t.cleanUp(),console.error(e),new sa("Server side error",e)})},fi.prototype.getHeaders=function(){return this.opts.enableAuth?ho({},Eo,this.getAuthHeader(),this.extraHeader):ho({},Eo,this.extraHeader)},fi.prototype.cleanUp=function(){this.extraHeader={},this.extraParams={}},fi.prototype.get=function(){return this.opts.showContractDesc&&(this.extraParams=ho({},this.extraParams,Jo)),this.request({},{method:"GET"},this.contractHeader).then(ha).then(function(t){return console.info("144 get contract result",t),t.cache&&t.contract?t.contract:t})},fi.prototype.query=function(t,e){return void 0===e&&(e=[]),this.request(Ja(t,e)).then(ha)},fi.prototype.mutation=function(t,e,r){return void 0===e&&(e={}),void 0===r&&(r={}),this.request(Ma(t,e,r),{method:si}).then(ha)},Object.defineProperties(fi.prototype,li);var pi=function(t){function e(e,r){r&&(e.Fly=r),t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={storeIt:{configurable:!0},jsonqlEndpoint:{configurable:!0},jsonqlContract:{configurable:!0},jsonqlToken:{configurable:!0},jsonqlUserdata:{configurable:!0}};return r.storeIt.set=function(t){throw console.info("storeIt",t),qa(t)&&t.length>=2&&Reflect.apply(Y.set,Y,t),new ua("Expect argument to be array and least 2 items!")},r.jsonqlEndpoint.set=function(t){var e=Y.get("endpoint")||[];$a(e,t)||(e.push(t),this.storeId=["endpoint",e],this.endpointIndex=e.length-1)},r.jsonqlContract.set=function(t){var e=this.opts.storageKey,r=[e],n=t[0],o=t[1],a=Y.get(e)||[];a[this.endpointIndex||0]=n,r.push(a),o&&r.push(o),this.opts.keepContract&&(this.storeIt=r)},r.jsonqlToken.set=function(t){var e="credential",r=localStorage.get(e)||[];if(!$a(r,t)){var n=r.length-1;r[n]=t,this[e+"Index"]=n;var o=[e,r];if(this.opts.tokenExpired){var a=parseFloat(this.opts.tokenExpired);if(!isNaN(a)&&a>0){var i=Ua();o.push(i+parseFloat(a))}}return this.storeIt=o,this.jsonqlUserdata=this.decoder(t),t}return!1},r.jsonqlUserdata.set=function(t){var e=["userdata",t];return t.exp&&e.push(t.exp),Reflect.apply(Y.set,Y,e)},r.jsonqlEndpoint.get=function(){var t=Y.get("endpoint");if(!t){var e=this.opts,r=[e.hostname,e.jsonqlPath].join("/");return this.jsonqlEndpoint=r,r}return t[this.endpointIndex]},r.jsonqlContract.get=function(){var t=this.opts.storageKey;return(Y.get(t)||[])[this.endpointIndex]||!1},r.jsonqlToken.get=function(){var t="credential",e=localStorage.get(t);return!!e&&e[this[t+"Index"]]},r.jsonqlUserdata.get=function(){return Q.get("userdata")},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),e.enableAuth&&e.useJwt&&(this.setDecoder=ui)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={userdata:{configurable:!0},rawAuthToken:{configurable:!0},setDecoder:{configurable:!0}};return r.userdata.get=function(){return this.jsonqlUserdata},r.rawAuthToken.get=function(){return this.jsonqlToken},r.setDecoder.set=function(t){"function"==typeof t&&(this.decoder=t)},e.prototype.storeToken=function(t){return this.jsonqlToken=t},e.prototype.decoder=function(t){return t},e.prototype.getAuthHeader=function(){var t,e=this.rawAuthToken;return e?((t={})[this.opts.AUTH_HEADER]="Bearer "+e,t):{}},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={contractHeader:{configurable:!0}};return e.prototype.getContract=function(){var t=this.readContract();if(console.info("getContract first call",t),t&&Array.isArray(t)){var e=t[this.endpointIndex||0];if(e)return Promise.resolve(e)}return this.get().then(this.storeContract.bind(this))},r.contractHeader.get=function(){var t={};return!1!==this.opts.contractKey&&(t[this.opts.contractKeyName]=this.opts.contractKey),t},e.prototype.storeContract=function(t){if(!La(t))throw new ua("Contract is malformed!");var e=[t];if(this.opts.contractExpired){var r=parseFloat(this.opts.contractExpired);!isNaN(r)&&r>0&&e.push(r)}return this.jsonqlContract=e,console.info("storeContract return result",t),t},e.prototype.readContract=function(){return La(this.opts.contract)?this.opts.contract:Y.get(this.opts.storageKey)},Object.defineProperties(e.prototype,r),e}(fi))),hi=new WeakMap,di=new WeakMap;var vi=function(t){void 0===t&&(t={}),t.logger&&"function"==typeof t.logger&&(this.logger=t.logger),this.keep=t.keep,this.result=t.keep?[]:null,this.normalStore=new Map,this.lazyStore=new Map},gi={$done:{configurable:!0},normalStore:{configurable:!0},lazyStore:{configurable:!0}};vi.prototype.logger=function(){},vi.prototype.$on=function(t,e,r){var n=this;void 0===r&&(r=null);this.validate(t,e);var o=this.takeFromStore(t);if(!1===o)return this.logger("$on",t+" callback is not in lazy store"),this.addToNormalStore(t,"on",e,r);this.logger("$on",t+" found in lazy store");var a=0;return o.forEach(function(o){var i=o[0],u=o[1],c=o[2];if(c&&"on"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);n.run(e,i,r||u),a+=n.addToNormalStore(t,"on",e,r||u)}),a},vi.prototype.$once=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=this.takeFromStore(t);this.normalStore;if(!1===n)return this.logger("$once",t+" not in the lazy store"),this.addToNormalStore(t,"once",e,r);this.logger("$once",n);var o=Array.from(n)[0],a=o[0],i=o[1],u=o[2];if(u&&"once"!==u)throw new Error("You are trying to register an event already been taken by other type: "+u);this.run(e,a,r||i),this.$off(t)},vi.prototype.$only=function(t,e,r){var n=this;void 0===r&&(r=null),this.validate(t,e);var o=!1,a=this.takeFromStore(t);(this.normalStore.has(t)||(this.logger("$only",t+" add to store"),o=this.addToNormalStore(t,"only",e,r)),!1!==a)&&(this.logger("$only",t+" found data in lazy store to execute"),Array.from(a).forEach(function(t){var o=t[0],a=t[1],i=t[2];if(i&&"only"!==i)throw new Error("You are trying to register an event already been taken by other type: "+i);n.run(e,o,r||a)}));return o},vi.prototype.$onlyOnce=function(t,e,r){void 0===r&&(r=null),this.validate(t,e);var n=!1,o=this.takeFromStore(t);if(this.normalStore.has(t)||(this.logger("$onlyOnce",t+" add to store"),n=this.addToNormalStore(t,"onlyOnce",e,r)),!1!==o){this.logger("$onlyOnce",o);var a=Array.from(o)[0],i=a[0],u=a[1],c=a[2];if(c&&"onlyOnce"!==c)throw new Error("You are trying to register an event already been taken by other type: "+c);this.run(e,i,r||u),this.$off(t)}return n},vi.prototype.$replace=function(t,e,r,n){if(void 0===r&&(r=null),void 0===n&&(n="on"),this.validateType(n)){this.$off(t);var o=this["$"+n];return Reflect.apply(o,this,[t,e,r])}throw new Error(n+" is not supported!")},vi.prototype.$trigger=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1),this.validateEvt(t);var o=0,a=this.normalStore;if(this.logger("$trigger",a),a.has(t)){this.logger("$trigger",t,"found");for(var i=Array.from(a.get(t)),u=i.length,c=!1,s=0;s0;)n[o]=arguments[o+2];if(t.has(e)?(this.logger("addToStore",e+" existed"),r=t.get(e)):(this.logger("addToStore","create new Set for "+e),r=new Set),n.length>2)if(Array.isArray(n[0])){var a=n[2];this.checkTypeInLazyStore(e,a)||r.add(n)}else this.checkContentExist(n,r)||(this.logger("addToStore","insert new",n),r.add(n));else r.add(n);return t.set(e,r),[t,r.size]},vi.prototype.checkContentExist=function(t,e){return!!Array.from(e).filter(function(e){return e[0]===t[0]}).length},vi.prototype.checkTypeInStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.$get(t,!0);return!1===r||!r.filter(function(t){var r=t[3];return e!==r}).length},vi.prototype.checkTypeInLazyStore=function(t,e){this.validateEvt(t),this.validateEvt(e);var r=this.lazyStore.get(t);return this.logger("checkTypeInLazyStore",r),!!r&&!!Array.from(r).filter(function(t){return t[2]!==e}).length},vi.prototype.addToNormalStore=function(t,e,r,n){if(void 0===n&&(n=null),this.logger("addToNormalStore",t,e,"add to normal store"),this.checkTypeInStore(t,e)){this.logger(e+" can add to "+t+" store");var o=this.hashFnToKey(r),a=[this.normalStore,t,o,r,n,e],i=Reflect.apply(this.addToStore,this,a),u=i[0],c=i[1];return this.normalStore=u,c}return!1},vi.prototype.addToLazyStore=function(t,e,r,n){void 0===e&&(e=[]),void 0===r&&(r=null),void 0===n&&(n=!1);var o=[this.lazyStore,t,this.toArray(e),r];n&&o.push(n);var a=Reflect.apply(this.addToStore,this,o),i=a[0],u=a[1];return this.lazyStore=i,u},vi.prototype.toArray=function(t){return Array.isArray(t)?t:[t]},gi.normalStore.set=function(t){hi.set(this,t)},gi.normalStore.get=function(){return hi.get(this)},gi.lazyStore.set=function(t){di.set(this,t)},gi.lazyStore.get=function(){return di.get(this)},vi.prototype.hashFnToKey=function(t){return t.toString().split("").reduce(function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t},0)+""},Object.defineProperties(vi.prototype,gi);var yi=new vi,bi=function(t,e,r,n){return function(){for(var r=[],o=arguments.length;o--;)r[o]=arguments[o];var a=n.auth[e].params,i=a.map(function(t,e){return r[e]}),u=r[a.length]||{};return za(r,a).then(function(){return t.query.apply(t,[e,i,u])}).catch(da)}},mi=function(t,e,r){var n={query:{},mutation:{},auth:{}},o=function(e){n.query[e]=function(){for(var n=[],o=arguments.length;o--;)n[o]=arguments[o];var a=r.query[e].params,i=a.map(function(t,e){return n[e]}),u=n[a.length]||{};return za(i,a).then(function(){return t.query.apply(t,[e,i,u])}).catch(da)}};for(var a in r.query)o(a);var i=function(e){n.mutation[e]=function(n,o,a){void 0===a&&(a={});var i=[n,o],u=r.mutation[e].params;return za(i,u).then(function(){return t.mutation.apply(t,[e,n,o,a])}).catch(da)}};for(var u in r.mutation)i(u);if(e.enableAuth&&r.auth){var c=e.loginHandlerName,s=e.logoutHandlerName;r.auth[c]&&(n[c]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=bi(t,c,0,r);return o.apply(null,e).then(t.postLoginAction).then(function(t){return yi.$trigger("login",t),t})}),r.auth[s]?n[s]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var o=bi(t,s,0,r);return o.apply(null,e).then(t.postLogoutAction).then(function(t){return yi.$trigger("logout",t),t})}:n[s]=function(){t.postLogoutAction("continue"),yi.$trigger("logout","continue")},n.userdata=function(){return t.userdata}}return n.returnInstance&&(n.jsonqlClientInstance=t),n.getToken=function(){return t.rawAuthToken},n.eventEmitter=yi,n},_i={contract:!1,MUTATION_ARGS:["name","payload","conditions"],CONTENT_TYPE:Ao,BEARER:"Bearer",AUTH_HEADER:"Authorization"},wi={hostname:Na([window.location.protocol,window.location.host].join("//"),["string"]),jsonqlPath:Na("jsonql",["string"]),loginHandlerName:Na("login",["string"]),logoutHandlerName:Na("logout",["string"]),enableJsonp:Na(!1,["boolean"]),enableAuth:Na(!1,["boolean"]),useJwt:Na(!0,["boolean"]),useLocalstorage:Na(!0,["boolean"]),storageKey:Na("storageKey",["string"]),authKey:Na("authKey",["string"]),contractExpired:Na(0,["number"]),keepContract:Na(!0,["boolean"]),showContractDesc:Na(!1,["boolean"]),contractKey:Na(!1,["boolean"]),contractKeyName:Na("X-JSONQL-CV-KEY",["string"]),enableTimeout:Na(!1,["boolean"]),timeout:Na(5e3,["number"]),returnInstance:Na(!1,["boolean"]),allowReturnRawToken:Na(!1,["boolean"]),debugOn:Na(!1,["boolean"])};return function(t,e){return void 0===t&&(t={}),void 0===e&&(e=null),function(t){var e=t.contract;return Ia(t,wi,_i).then(function(t){return t.contract=e,t})}(t).then(function(t){return{baseClient:new pi(t,e),opts:t}}).then(function(t){var e=t.baseClient,r=t.opts;return Da(e,r.contract).then(function(t){return mi(e,r,t)})})}}); //# sourceMappingURL=jsonql-client.umd.js.map diff --git a/packages/http-client/src/full.js b/packages/http-client/src/full.js index 32586b39..9bd9248a 100644 --- a/packages/http-client/src/full.js +++ b/packages/http-client/src/full.js @@ -5,5 +5,5 @@ import Fly from 'flyio/dist/npm/fly' import jsonqlApi from './index' export default function(config = {}) { - return jsonqlApi(config, new Fly()) + return jsonqlApi(config, Fly) } diff --git a/packages/http-client/src/lib/base/base-cls.js b/packages/http-client/src/lib/base/base-cls.js index 643fd103..24a8de78 100644 --- a/packages/http-client/src/lib/base/base-cls.js +++ b/packages/http-client/src/lib/base/base-cls.js @@ -12,10 +12,10 @@ import AuthCls from './auth-cls' export default class JsonqlBaseClient extends AuthCls { constructor(opts, Fly) { - super(opts) - if (Fly!==null) { - this.fly = new Fly() + if (Fly) { + opts.Fly = Fly; } + super(opts) } // @TODO diff --git a/packages/http-client/src/lib/base/http-cls.js b/packages/http-client/src/lib/base/http-cls.js index 60c9d20c..c0bdea6f 100644 --- a/packages/http-client/src/lib/base/http-cls.js +++ b/packages/http-client/src/lib/base/http-cls.js @@ -1,7 +1,5 @@ // base HttpClass -// import Fly from 'flyio/dist/npm/fly' import { merge } from 'lodash-es' - import { createQuery, createMutation, @@ -37,6 +35,7 @@ export default class HttpClass { constructor(opts) { // change the way how we init Fly // flyio now become external depedencies and it makes it easier to switch + this.fly = opts.Fly ? new opts.Fly() : new Fly() // to a different environment like WeChat mini app this.opts = opts; this.extraHeader = {}; diff --git a/packages/http-client/tests/qunit/tests/base-test.js b/packages/http-client/tests/qunit/tests/base-test.js index 5a942548..84e30521 100644 --- a/packages/http-client/tests/qunit/tests/base-test.js +++ b/packages/http-client/tests/qunit/tests/base-test.js @@ -16,8 +16,6 @@ QUnit.test('It should able to use the client to contact the server with static c client.query.helloWorld().then(function(result) { assert.equal('Hello world!', result, "Hello world test done") - - done1() }) diff --git a/packages/http-client/tests/qunit/webroot/index.html b/packages/http-client/tests/qunit/webroot/index.html index ba45ff5f..d6410628 100644 --- a/packages/http-client/tests/qunit/webroot/index.html +++ b/packages/http-client/tests/qunit/webroot/index.html @@ -12,9 +12,9 @@ - + - + -- Gitee From 4a39171c90d374c915f9cdf51d05c9a4fb61c0ea Mon Sep 17 00:00:00 2001 From: Joel Chu Date: Fri, 26 Jul 2019 14:13:41 +0800 Subject: [PATCH 4/5] update README with the correct configuration options --- packages/http-client/README.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/http-client/README.md b/packages/http-client/README.md index c29db7a3..8cf3a858 100755 --- a/packages/http-client/README.md +++ b/packages/http-client/README.md @@ -23,23 +23,27 @@ $ yarn add jsonql-client V.1.2.2 - we have included a type definition for Typescript `jsonql-client/jsonql-client.d.ts` If you need one (we will add this to `@types` in the future) -## Example - -### V1.1.0 we add a JsonqlClient (class) version +**BREAKING CHANGE** -You will have to include the file manually in the `dist/jsonql-client.cls.js` into your build chain or HTML page. +Since version 1.2.x we move to use [Fly](https://github.com/wendux/fly) as our core http engine, +and because it support multiple platform, we completely move the Reference of Fly out of the import (And Fly has a huge problem with bundler in the first place anyway). So when you use the core `jsonql-client` core package, you need to init it like this ```js -var client = new JsonqlClient() +var client = jsonqlClient(config, Fly).then() +``` -client.ready(function(cls) { - cls.query.helloWorld().then(function(msg) { - console.log(msg); - }) -}) +Or if you are using build tool, you can import the complete version (built with Fly for browser) instead +```js +import jsonqlClient from 'jsonql-client/dist/full' ``` +For other platforms (such as WeChat, Baidu etc) import the version of Fly you require and pass it during the init.s + +## Example + +The following example assume you use the full browser version as shown above. + ### Using the singleton jsonqlClient version We recommend you use the latest ES6+ with module bundler tools like [rollup](https://rollupjs.org/guide/en). -- Gitee From e4526d95518f3c24ec8ce5904d31b2eabe4fb7e9 Mon Sep 17 00:00:00 2001 From: Joel Chu Date: Fri, 26 Jul 2019 14:19:56 +0800 Subject: [PATCH 5/5] Verify both of the build version works in browser --- packages/http-client/tests/qunit/webroot/index.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/http-client/tests/qunit/webroot/index.html b/packages/http-client/tests/qunit/webroot/index.html index d6410628..3d806057 100644 --- a/packages/http-client/tests/qunit/webroot/index.html +++ b/packages/http-client/tests/qunit/webroot/index.html @@ -12,9 +12,11 @@ - + + - + + -- Gitee