diff --git a/packages/http-client/README.md b/packages/http-client/README.md index b210e6359804bb1b764553090df98c9392e21955..539724cf0f38e4486b895c954827d4523756967f 100644 --- a/packages/http-client/README.md +++ b/packages/http-client/README.md @@ -10,7 +10,7 @@ If you need to use in node environment, then you should use [jsonql-node-client] ## How to use it -First this version **DOES NOT** distribute with the [Flyio](https://github.com/wendux/fly) module. You have to explicitly import it yourself. +First, this module **DOES NOT** distribute with the [Flyio](https://github.com/wendux/fly) module. You have to explicitly import it yourself. The reason is - we intend to support as many platform as possible, and Fly allow you to do just that, check their [documentation](https://github.com/wendux/fly) for more information. @@ -36,7 +36,7 @@ If you pass the `contract` via the config, then you don't need to call the end ```js import contract from 'some/where/contract.json' import Fly from 'flyio' -import jsonqlClient from '@jsonql/http-client' +import jsonqlClient from 'jsonql-client' let config = { contract } const client = jsonqlClient(Fly, config) @@ -123,7 +123,93 @@ See the following example (pretty close to our own test version as well) | storageKey | client side local storage key name | `String` | `CLIENT_STORAGE_KEY` | | debugOn | When enable, you will see debug message in your browser console | `Boolean` | `false` | +## Vuex module (1.5.19) + +We add a vuex store support in version 1.5.19 + +First create a new file (let say call it `jsonql.js`) + +```js +import contract from 'path/to/your/public-contract.json' +import { getJsonqlVuexModule } from 'jsonql-client/vuex' +import Fly from 'flyio' +const jsonqlModule = getJsonqlVuexModule(Fly, { contract }) + +export { jsonqlModule } +``` + +Now in your `store.js` where you define your Vuex store + +```js +import Vue from 'vue' +import Vuex from 'vuex' + +Vue.use(Vuex) + +import { jsonqlModule } from './jsonql' + +export default new Vuex.Store({ + state: {}, + mutations: {}, + actions: {}, + getters: {}, + modules: { + jsonqlModule + } +}) +``` + +This Vuex module is namespaced. In your component + +```html + + +``` + +You might be asking why the resolver name is different from the contract from `query.helloWorld` turn into `queryHelloWorld`. +We use their type to prefix each resolvers, so you might get `query`, `mutation`, `auth` etc. This is to avoid duplicated naming. +You can turn this off by passing a `prefix:false` in the `config` when you set up your store file: + +```js +// the import +const jsonqlModule = getJsonqlVuexModule(Fly, { contract, prefix: false }) +// the export +``` + +### getters getJsonqlResult + +You should notice there is a getter method call `getJsonqlResult` and you pass the resolver name (with prefix or not when you turn it off). +The reason is in the Vuex model, after we call the resolver, we store (commit) the result in our internal `result` state, and key with the resolver name. And whenever a new result return, it will get overwritten, because it's a flat object. + +Of course, you can simply call the actions and wait for the promise to resolve. You will get the same effect. + +### getters getJsonqlError + +Whenever an error happens, we do the same like success result, we commit to our internal `error` state, and you can use this getter to get it. +And after we commit, we will throw it again which wrap in a generic `Error`. So you can also catch it again. + +--- Please consult [jsonql.org](https:jsonql.js.org) for more information. diff --git a/packages/http-client/core.js b/packages/http-client/core.js index f352e269fa16a270d83d0ebae5bc6e35fbbd3b20..5c71e7af720bfba0690e2acfe946cd26ae25b702 100644 --- a/packages/http-client/core.js +++ b/packages/http-client/core.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=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),e=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),r=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 403},r.name.get=function(){return"JsonqlForbiddenError"},Object.defineProperties(e,r),e}(Error),n=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),o=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),i=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),a=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),u=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),c=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),s=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),l=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),f="application/vnd.api+json",p={Accept:f,"Content-Type":[f,"charset=utf-8"].join(";")},h=["POST","PUT"],d={desc:"y"},v=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),g=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),y=Object.freeze({__proto__:null,Jsonql406Error:t,Jsonql500Error:e,JsonqlForbiddenError:r,JsonqlAuthorisationError:n,JsonqlContractAuthError:o,JsonqlResolverAppError:i,JsonqlResolverNotFoundError:a,JsonqlEnumError:u,JsonqlTypeError:c,JsonqlCheckerError:s,JsonqlValidationError:l,JsonqlError:v,JsonqlServerError:g}),b=v;function _(t){if(function(t,e){return!!Object.keys(t).filter((function(t){return e===t})).length}(t,"error")){var e=t.error,r=e.className,n=e.name,o=r||n,i=e.message||"No message",a=e.detail||e;if(o&&y[o])throw new y[r](i,a);throw new b(i,a)}return t}function m(f){if(Array.isArray(f))throw new l("",f);var p=f.message||"No message",h=f.detail||f;switch(!0){case f instanceof t:throw new t(p,h);case f instanceof e:throw new e(p,h);case f instanceof r:throw new r(p,h);case f instanceof n:throw new n(p,h);case f instanceof o:throw new o(p,h);case f instanceof i:throw new i(p,h);case f instanceof a:throw new a(p,h);case f instanceof u:throw new u(p,h);case f instanceof c:throw new c(p,h);case f instanceof s:throw new s(p,h);case f instanceof l:throw new l(p,h);case f instanceof g:throw new g(p,h);default:throw new v(p,h)}}var w="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},j="object"==typeof w&&w&&w.Object===Object&&w,S="object"==typeof self&&self&&self.Object===Object&&self,O=j||S||Function("return this")(),k=O.Symbol;function A(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r=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);++n-1;);return r}(n,o),function(t,e){for(var r=t.length;r--&&L(e,t[r],0)>-1;);return r}(n,o)+1).join("")}var ot=function(t){return!!E(t)||null!=t&&""!==nt(t)};function it(t){return function(t){return"number"==typeof t||N(t)&&"[object Number]"==z(t)}(t)&&t!=+t}function at(t){return"string"==typeof t||!E(t)&&N(t)&&"[object String]"==z(t)}var ut=function(t){return!at(t)&&!it(parseFloat(t))},ct=function(t){return""!==nt(t)&&at(t)},st=function(t){return null!=t&&"boolean"==typeof t},lt=function(t,e){return void 0===e&&(e=!0),void 0!==t&&""!==t&&""!==nt(t)&&(!1===e||!0===e&&null!==t)},ft=function(t){switch(t){case"number":return ut;case"string":return ct;case"boolean":return st;default:return lt}},pt=function(t,e){return void 0===e&&(e=""),!!E(t)&&(""===e||""===nt(e)||!(t.filter((function(t){return!ft(e)(t)})).length>0))},ht=function(t){if(t.indexOf("array.<")>-1&&t.indexOf(">")>-1){var e=t.replace("array.<","").replace(">","");return e.indexOf("|")?e.split("|"):[e]}return!1},dt=function(t,e){var r=t.arg;return e.length>1?!r.filter((function(t){return!(e.length>e.filter((function(e){return!ft(e)(t)})).length)})).length:e.length>e.filter((function(t){return!pt(r,t)})).length};function vt(t,e){return function(r){return t(e(r))}}var gt=vt(Object.getPrototypeOf,Object),yt=Function.prototype,bt=Object.prototype,_t=yt.toString,mt=bt.hasOwnProperty,wt=_t.call(Object);function jt(t){if(!N(t)||"[object Object]"!=z(t))return!1;var e=gt(t);if(null===e)return!0;var r=mt.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&_t.call(r)==wt}var St,Ot=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),a=i.length;a--;){var u=i[St?a:++n];if(!1===e(o[u],u,o))break}return t};function kt(t){return N(t)&&"[object Arguments]"==z(t)}var At=Object.prototype,Et=At.hasOwnProperty,Tt=At.propertyIsEnumerable,xt=kt(function(){return arguments}())?kt:function(t){return N(t)&&Et.call(t,"callee")&&!Tt.call(t,"callee")};var Pt="object"==typeof exports&&exports&&!exports.nodeType&&exports,qt=Pt&&"object"==typeof module&&module&&!module.nodeType&&module,Ct=qt&&qt.exports===Pt?O.Buffer:void 0,$t=(Ct?Ct.isBuffer:void 0)||function(){return!1},zt=/^(?:0|[1-9]\d*)$/;function Nt(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&zt.test(t))&&t>-1&&t%1==0&&t-1&&t%1==0&&t<=9007199254740991}var It={};It["[object Float32Array]"]=It["[object Float64Array]"]=It["[object Int8Array]"]=It["[object Int16Array]"]=It["[object Int32Array]"]=It["[object Uint8Array]"]=It["[object Uint8ClampedArray]"]=It["[object Uint16Array]"]=It["[object Uint32Array]"]=!0,It["[object Arguments]"]=It["[object Array]"]=It["[object ArrayBuffer]"]=It["[object Boolean]"]=It["[object DataView]"]=It["[object Date]"]=It["[object Error]"]=It["[object Function]"]=It["[object Map]"]=It["[object Number]"]=It["[object Object]"]=It["[object RegExp]"]=It["[object Set]"]=It["[object String]"]=It["[object WeakMap]"]=!1;var Rt,Ft="object"==typeof exports&&exports&&!exports.nodeType&&exports,Jt=Ft&&"object"==typeof module&&module&&!module.nodeType&&module,Ut=Jt&&Jt.exports===Ft&&j.process,Lt=function(){try{var t=Jt&&Jt.require&&Jt.require("util").types;return t||Ut&&Ut.binding&&Ut.binding("util")}catch(t){}}(),Ht=Lt&&Lt.isTypedArray,Dt=Ht?(Rt=Ht,function(t){return Rt(t)}):function(t){return N(t)&&Mt(t.length)&&!!It[z(t)]},Kt=Object.prototype.hasOwnProperty;function Bt(t,e){var r=E(t),n=!r&&xt(t),o=!r&&!n&&$t(t),i=!r&&!n&&!o&&Dt(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r-1},ie.prototype.set=function(t,e){var r=this.__data__,n=ne(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var ae,ue=O["__core-js_shared__"],ce=(ae=/[^.]+$/.exec(ue&&ue.keys&&ue.keys.IE_PROTO||""))?"Symbol(src)_1."+ae:"";var se=Function.prototype.toString;function le(t){if(null!=t){try{return se.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var fe=/^\[object .+?Constructor\]$/,pe=Function.prototype,he=Object.prototype,de=pe.toString,ve=he.hasOwnProperty,ge=RegExp("^"+de.call(ve).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ye(t){return!(!Qt(t)||function(t){return!!ce&&ce in t}(t))&&(Xt(t)?ge:fe).test(le(t))}function be(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return ye(r)?r:void 0}var _e=be(O,"Map"),me=be(Object,"create");var we=Object.prototype.hasOwnProperty;var je=Object.prototype.hasOwnProperty;function Se(t){var e=-1,r=null==t?0:t.length;for(this.clear();++eu))return!1;var s=i.get(t);if(s&&i.get(e))return s==e;var l=-1,f=!0,p=2&r?new Ee:void 0;for(i.set(t,e),i.set(e,t);++le.type.filter((function(t){var e;return void 0===r||(!1!==(e=ht(t))?!dt({arg:r},e):!ft(t)(r))})).length)})).length}return!1},Sr=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),!Reflect.apply(jr,null,a);case"array"===t:return!pt(e.arg);case!1!==(r=ht(t)):return!dt(e,r);default:return!ft(t)(e.arg)}},Or=function(t,e){return void 0!==t?t:!0===e.optional&&void 0!==e.defaultvalue?e.defaultvalue:null},kr=function(t,e,r){var n;void 0===r&&(r=!1);var o=function(t,e){if(!pt(e))throw new v("params is not an array! Did something gone wrong when you generate the contract.json?");if(0===e.length)return[];if(!pt(t))throw new v("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:var n=e.length,o=["any"];return t.map((function(t,r){var i=r>=n||!!e[r].optional,a=e[r]||{type:o,name:"_"+r};return{arg:i?Or(t,a):t,index:r,param:a,optional:i}}));default:throw new v("Could not understand your arguments and parameter structure!",{args:t,params:e})}}(t,e),i=o.filter((function(t){return!0===t.optional||!0===t.param.optional?function(t){var e=t.arg,r=t.param;return!!ot(e)&&!(r.type.length>r.type.filter((function(e){return Sr(e,t)})).length)}(t):!(t.param.type.length>t.param.type.filter((function(e){return Sr(e,t)})).length)}));return r?((n={}).error=i,n.data=o.map((function(t){return t.arg})),n):i},Ar=function(){try{var t=be(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();function Er(t,e,r){"__proto__"==e&&Ar?Ar(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}function Tr(t,e,r){(void 0===r||re(t[e],r))&&(void 0!==r||e in t)||Er(t,e,r)}var xr="object"==typeof exports&&exports&&!exports.nodeType&&exports,Pr=xr&&"object"==typeof module&&module&&!module.nodeType&&module,qr=Pr&&Pr.exports===xr?O.Buffer:void 0,Cr=qr?qr.allocUnsafe:void 0;function $r(t,e){var r,n,o=e?(r=t.buffer,n=new r.constructor(r.byteLength),new Pe(n).set(new Pe(r)),n):t.buffer;return new t.constructor(o,t.byteOffset,t.length)}var zr=Object.create,Nr=function(){function t(){}return function(e){if(!Qt(e))return{};if(zr)return zr(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();function Mr(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}var Ir=Object.prototype.hasOwnProperty;function Rr(t,e,r){var n=t[e];Ir.call(t,e)&&re(n,r)&&(void 0!==r||e in t)||Er(t,e,r)}var Fr=Object.prototype.hasOwnProperty;function Jr(t){if(!Qt(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=Gt(t),r=[];for(var n in t)("constructor"!=n||!e&&Fr.call(t,n))&&r.push(n);return r}function Ur(t){return Zt(t)?Bt(t,!0):Jr(t)}function Lr(t){return function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Vr);function Yr(t,e){return Wr(function(t,e,r){return e=Br(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=Br(n.length-e,0),a=Array(i);++o1?e[n-1]:void 0,i=n>2?e[2]:void 0;for(o=Qr.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!Qt(r))return!1;var n=typeof e;return!!("number"==n?Zt(r)&&Nt(e,r.length):"string"==n&&e in r)&&re(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r0;)e[r]=arguments[r+1];return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return e.reduce((function(t,e){return Reflect.apply(e,null,yn(t))}),Reflect.apply(t,null,r))}};function mn(t,e){var r=Object.getOwnPropertyDescriptor(t,e);return void 0!==r&&r.value?r.value:r}function wn(t,e,r,n){void 0===n&&(n=!1);var o=mn(t,e);return!1===n&&void 0!==o?t:(Object.defineProperty(t,e,{value:r,writable:n}),t)}var jn=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 dn(r,i).then((function(){return t.query.apply(t,[e,a,u])})).catch(m)}},Sn=function(t,e,r,n,o){var i={},a=function(t){i=wn(i,t,(function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var i=o.query[t].params,a=i.map((function(t,e){return r[e]})),u={};return dn(a,i).then((function(){return e.query.apply(e,[t,a,u])})).catch(m)}))};for(var u in o.query)a(u);return t.query=i,t.helloWorld=i.helloWorld,[t,e,r,n,o]},On=function(t,e,r,n,o){var i={},a=function(t){i=wn(i,t,(function(r,n,i){void 0===i&&(i={});var a=[r,n],u=o.mutation[t].params;return dn(a,u).then((function(){return e.mutation.apply(e,[t,r,n,i])})).catch(m)}))};for(var u in o.mutation)a(u);return t.mutation=i,[t,e,r,n,o]},kn=function(t,e,r,n,o){if(n.enableAuth&&o.auth){var i={},a=n.loginHandlerName,u=n.logoutHandlerName;o.auth[a]&&(i[a]=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var i=jn(e,a,0,o);return i.apply(null,t).then(e.postLoginAction.bind(e)).then((function(t){var e=t.token,n=t.userdata;return r.$trigger("login",e),n}))}),o.auth[u]?i[u]=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var i=jn(e,u,0,o);return i.apply(null,t).then(e.postLogoutAction.bind(e)).then((function(t){return r.$trigger("logout",t),t}))}:i[u]=function(t){void 0===t&&(t=null),e.postLogoutAction("continue",t),r.$trigger("logout","continue")},t.auth=i}return t};var An=function(t,e,r,n){var o=function(t,e,r,n){var o=[Sn,On,kn];return Reflect.apply(_n,null,o)({},t,e,r,n)}(t,n,e,r);return e.exposeStore,o=function(t,e,r,n,o){return t.eventEmitter=r,t.contract=o,t.version="1.5.17",t.getLogger=function(t){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return Reflect.apply(e.log,e,[t].concat(r))}},n.enableAuth&&(t.userdata=function(){return e.jsonqlUserdata},t.getToken=function(t){return void 0===t&&(t=!1),e.rawAuthToken(t)},t.profileIndex=function(t){if(void 0===t&&(t=!1),!1===t)return e.profileIndex;e.profileIndex=t},t.getProfiles=function(t){return void 0===t&&(t=!1),e.getProfiles(t)}),t}(o,t,n,e,r)};function En(t){return!!function(t){return jt(t)&&(bn(t,"query")||bn(t,"mutation")||bn(t,"socket"))}(t)&&t}function Tn(t){return function(t){return t.split("").reduce((function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t}),0)}(t)+""}function xn(t){this.message=t}xn.prototype=new Error,xn.prototype.name="InvalidCharacterError";var Pn="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new xn("'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="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return a};var qn=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(Pn(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 Pn(e)}};function Cn(t){this.message=t}Cn.prototype=new Error,Cn.prototype.name="InvalidTokenError";var $n=function(t,e){if("string"!=typeof t)throw new Cn("Invalid token specified");var r=!0===(e=e||{}).header?0:1;try{return JSON.parse(qn(t.split(".")[r]))}catch(t){throw new Cn("Invalid token specified: "+t.message)}};$n.InvalidTokenError=Cn;var zn,Nn,Mn,In,Rn,Fn,Jn,Un,Ln;function Hn(t){var e=t.iat||function(t){void 0===t&&(t=!1);var e=Date.now();return t?Math.floor(e/1e3):e}(!0);if(t.exp&&e>=t.exp){var r=new Date(t.exp).toISOString();throw new v("Token has expired on "+r,t)}return t}function Dn(t){if(ct(t))return Hn($n(t));throw new v("Token must be a string!")}vn("HS256",["string"]),vn(!1,["boolean","number","string"],((zn={}).alias="exp",zn.optional=!0,zn)),vn(!1,["boolean","number","string"],((Nn={}).alias="nbf",Nn.optional=!0,Nn)),vn(!1,["boolean","string"],((Mn={}).alias="iss",Mn.optional=!0,Mn)),vn(!1,["boolean","string"],((In={}).alias="sub",In.optional=!0,In)),vn(!1,["boolean","string"],((Rn={}).alias="iss",Rn.optional=!0,Rn)),vn(!1,["boolean"],((Fn={}).optional=!0,Fn)),vn(!1,["boolean","string"],((Jn={}).optional=!0,Jn)),vn(!1,["boolean","string"],((Un={}).optional=!0,Un)),vn(!1,["boolean"],((Ln={}).optional=!0,Ln));var Kn=function(t){void 0===t&&(t=!1);var e=Date.now();return t?Math.floor(e/1e3):e};function Bn(t,e){var r;return(r={})[t]=e,r.TS=[Kn()],r}var Vn=function(t){return bn(t,"data")&&!bn(t,"error")?t.data:t},Gn="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var Wn=Object.assign?Object.assign:function(t,e,r,n){for(var o=arguments,i=1;i=0;e--){var r=bo().key(e);t(_o(r),r)}},remove:function(t){return bo().removeItem(t)},clearAll:function(){return bo().clear()}};function bo(){return go.localStorage}function _o(t){return bo().getItem(t)}var mo=Zn.trim,wo={name:"cookieStorage",read:function(t){if(!t||!ko(t))return null;var e="(?:^|.*;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(jo.cookie.replace(new RegExp(e),"$1"))},write:function(t,e){if(!t)return;jo.cookie=escape(t)+"="+escape(e)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"},each:So,remove:Oo,clearAll:function(){So((function(t,e){Oo(e)}))}},jo=Zn.Global.document;function So(t){for(var e=jo.cookie.split(/; ?/g),r=e.length-1;r>=0;r--)if(mo(e[r])){var n=e[r].split("="),o=unescape(n[0]);t(unescape(n[1]),o)}}function Oo(t){t&&ko(t)&&(jo.cookie=escape(t)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function ko(t){return new RegExp("(?:^|;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(jo.cookie)}var Ao=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 Eo=Zn.bind,To=Zn.each,xo=Zn.create,Po=Zn.slice,qo=function(){var t=xo(Co,{_id:0,_subSignals:{},_subCallbacks:{}});return{watch:function(e,r,n){return t.on(r,Eo(this,n))},unwatch:function(e,r){t.off(r)},once:function(e,r,n){t.once(r,Eo(this,n))},set:function(e,r,n){var o=this.get(r);e(),t.fire(r,n,o)},remove:function(e,r){var n=this.get(r);e(),t.fire(r,void 0,n)},clearAll:function(e){var r={};this.each((function(t,e){r[e]=t})),e(),To(r,(function(e,r){t.fire(r,void 0,e)}))}}};var Co={_id:null,_subCallbacks:null,_subSignals:null,on:function(t,e){return this._subCallbacks[t]||(this._subCallbacks[t]={}),this._id+=1,this._subCallbacks[t][this._id]=e,this._subSignals[this._id]=t,this._id},off:function(t){var e=this._subSignals[t];delete this._subCallbacks[e][t],delete this._subSignals[t]},once:function(t,e){var r=this.on(t,Eo(this,(function(){e.apply(this,arguments),this.off(r)})))},fire:function(t){var e=Po(arguments,1);To(this._subCallbacks[t],(function(t){t.apply(this,e)}))}},$o=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t){var e=function(){var t=String.fromCharCode,e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",n={};function o(t,e){if(!n[t]){n[t]={};for(var r=0;r>>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==--f&&(f=Math.pow(2,h),h++),delete u[l]}else for(o=a[l],n=0;n>=1;0==--f&&(f=Math.pow(2,h),h++),a[s]=p++,l=String(c)}if(""!==l){if(Object.prototype.hasOwnProperty.call(u,l)){if(l.charCodeAt(0)<256){for(n=0;n>=1}else{for(o=1,n=0;n>=1}0==--f&&(f=Math.pow(2,h),h++),delete u[l]}else for(o=a[l],n=0;n>=1;0==--f&&(f=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,l,f=[],p=4,h=4,d=3,v="",g=[],y={val:n(0),position:r,index:1};for(o=0;o<3;o+=1)f[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;l=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;l=t(a);break;case 2:return""}for(f[3]=l,i=l,g.push(l);;){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(l=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[h++]=t(a),l=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;f[h++]=t(a),l=h-1,p--;break;case 2:return g.join("")}if(0==p&&(p=Math.pow(2,d),d++),f[l])v=f[l];else{if(l!==h)return null;v=i+i.charAt(0)}g.push(v),f[h++]=i+v.charAt(0),i=v,0==--p&&(p=Math.pow(2,d),d++)}}};return i}();null!=t&&(t.exports=e)})),zo=function(){return{get:function(t,e){var r=t(e);if(!r)return r;var n=$o.decompress(r);return null==n?r:this._deserialize(n)},set:function(t,e,r){var n=$o.compress(this._serialize(r));t(e,n)}}};var No=[yo,wo],Mo=[Ao,qo,zo],Io=po.createStore(No,Mo),Ro=Zn.Global;function Fo(){return Ro.sessionStorage}function Jo(t){return Fo().getItem(t)}var Uo=[{name:"sessionStorage",read:Jo,write:function(t,e){return Fo().setItem(t,e)},each:function(t){for(var e=Fo().length-1;e>=0;e--){var r=Fo().key(e);t(Jo(r),r)}},remove:function(t){return Fo().removeItem(t)},clearAll:function(){return Fo().clear()}},wo],Lo=[Ao,zo],Ho=po.createStore(Uo,Lo),Do=Io,Ko=Ho,Bo=function(t){this.opts=t,this.instanceKey=Tn(this.opts.hostname),this.localStore=Do,this.sessionStore=Ko},Vo={lset:{configurable:!0},lget:{configurable:!0},sset:{configurable:!0},sget:{configurable:!0}};Bo.prototype.__setMethod=function(t,e){var r,n=this[t],o=this.__getMethod(t),i=this.opts.storageKey,a=this.instanceKey;n.set(i,((r={})[a]=o?Xr({},o,e):e,r))},Bo.prototype.__getMethod=function(t){var e=this[t].get(this.opts.storageKey);return!!e&&e[this.instanceKey]},Bo.prototype.__delMethod=function(t,e){var r=this.__getMethod(t);if(r){var n={};for(var o in r)o!==e&&(n[o]=r[o]);this.__setMethod(t,n)}},Bo.prototype.__clearMethod=function(t){var e=this.opts.storageKey,r=this[t],n=r.get(e);if(n){var o={};for(var i in n)i!==this.instanceKey&&(o[i]=n[i]);r.set(e,o)}},Vo.lset.set=function(t){return this.__setMethod("localStore",t)},Vo.lget.get=function(){return this.__getMethod("localStore")},Bo.prototype.ldel=function(t){return this.__delMethod("localStore",t)},Bo.prototype.lclear=function(){return this.__clearMethod("localStore")},Vo.sset.set=function(t){return this.__setMethod("sessionStore",t)},Vo.sget.get=function(){return this.__getMethod("sessionStore")},Bo.prototype.sdel=function(t){return this.__delMethod("sessionStore",t)},Bo.prototype.sclear=function(){return this.__clearMethod("sessionStore")},Object.defineProperties(Bo.prototype,Vo);var Go=h[0],Wo=h[1],Yo=function(t){function e(e,r){t.call(this,r),this.httpEngine=e,this.reqInterceptor(),this.resInterceptor()}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={jsonqlEndpoint:{configurable:!0}};return r.jsonqlEndpoint.get=function(){return[this.opts.hostname||"",this.opts.jsonqlPath].join("/")},e.prototype.log=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(!0===this.opts.debugOn){var r=["info","error"],n="__error__"===t[0]?1:0;t.splice(0,n),Reflect.apply(console[r[n]],console,t)}},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),e.enableAuth&&(this.setDecoder=Dn),this.__userdata__=null}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={profileIndex:{configurable:!0},setDecoder:{configurable:!0},saveProfile:{configurable:!0},readProfile:{configurable:!0},jsonqlToken:{configurable:!0},jsonqlUserdata:{configurable:!0}};return e.prototype.decoder=function(t){return t},r.profileIndex.set=function(t){var e;if(hn(t))return this.prof_idx=t,void(this.opts.persistToken&&(this.lset=((e={}).prof_idx=t,e)));throw new l("profileIndex","Expect idx to be number but got "+typeof t)},r.profileIndex.get=function(){var t="prof_idx";if(this.opts.persistToken){var e=this.lget;if(e[t])return e[t]}return this[t]?this[t]:0},e.prototype.rawAuthToken=function(t){return void 0===t&&(t=!1),!1!==t&&(this.profileIndex=t),this.jsonqlToken},r.setDecoder.set=function(t){"function"==typeof t&&(this.decoder=t)},r.saveProfile.set=function(t){this.opts.persistToken?this.lset=t:this.sset=t},r.readProfile.get=function(){return this.opts.persistToken?this.lget:this.sget},r.jsonqlToken.set=function(t){var e,r=this.readProfile,n="jsonqlcredential",o=r&&r[n]?r[n]:[];o.push(t),this.saveProfile=((e={})[n]=o,e),this.__userdata__=this.decoder(t),this.jsonqlUserdata=this.__userdata__},r.jsonqlToken.get=function(){var t=this.readProfile,e="jsonqlcredential";return!(!t||!t[e])&&(this.log("-- jsonqlToken --",t[e],this.profileIndex,t[e][this.profileIndex]),t[e][this.profileIndex])},r.jsonqlUserdata.set=function(t){var e;this.sset=((e={}).userdata=t,e)},r.jsonqlUserdata.get=function(){var t=this.sget;return!!t&&t.userdata},e.prototype.getAuthHeader=function(){var t,e=this.jsonqlToken;return e?((t={})[this.opts.AUTH_HEADER]="Bearer "+e,t):{}},e.prototype.getProfiles=function(t){void 0===t&&(t=!1);var e=this.readProfile,r="jsonqlcredential";return!(!e||!e[r])&&(!1!==t&&hn(t)?e[r][t]||!1:e[r].map(this.decoder.bind(this)))},e.prototype.postLoginAction=function(t){return this.jsonqlToken=t,{token:t,userdata:this.__userdata__}},e.prototype.postLogoutAction=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];console.info("postLogoutAction",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();return this.log("getContract first call",t),t?Promise.resolve(t):this.getRemoteContract().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){var e;if(!En(t))throw new l("Contract is malformed!");return this.lset=((e={}).contract=t,e),this.log("storeContract return result",t),t},e.prototype.readContract=function(){var t=En(this.opts.contract);if(!1!==t)return t;var e=this.lget;return!!e&&e.contract},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),this.extraHeader={},this.extraParams={}}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={headers:{configurable:!0}};return r.headers.set=function(t){this.extraHeader=t},e.prototype.request=function(t,e,r){var n;void 0===e&&(e={}),void 0===r&&(r={}),this.headers=r;var o=Xr({},{_cb:Kn()},this.extraParams);if(this.opts.enableJsonp){var i=function(t){return Object.keys(t)[0]}(t);o=Xr({},o,((n={}).jsonqlJsonpCallback=i,n)),t=t[i]}var a=Xr({},{method:Go,params:o},e);return this.log("request params",a,this.jsonqlEndpoint),this.httpEngine.request(this.jsonqlEndpoint,t,a)},e.prototype.reqInterceptor=function(){var t=this;this.httpEngine.interceptors.request.use((function(e){var r=t.getHeaders();for(var n in t.log("request interceptor call",r),r)e.headers[n]=r[n];return e}))},e.prototype.processJsonp=function(t){return Vn(t)},e.prototype.resInterceptor=function(){var t=this,e=this,r=e.opts.enableJsonp;this.httpEngine.interceptors.response.use((function(n){t.log("response interceptor call",n),e.cleanUp();var o=pn(n.data)?JSON.parse(n.data):n.data;return r?e.processJsonp(o):Vn(o)}),(function(r){throw e.cleanUp(),t.log("__error__",r),new g("Server side error",r)}))},e.prototype.getHeaders=function(){return this.opts.enableAuth?Xr({},p,this.getAuthHeader(),this.extraHeader):Xr({},p,this.extraHeader)},e.prototype.cleanUp=function(){this.extraHeader={},this.extraParams={}},e.prototype.getRemoteContract=function(){var t=this;return this.opts.showContractDesc&&(this.extraParams=Xr({},this.extraParams,d)),this.request({},{method:"GET"},this.contractHeader).then(_).then((function(e){return t.log("get contract result",e),e.cache&&e.contract?e.contract:e})).catch((function(e){throw t.log("__error__","getRemoteContract err",e),new g("getRemoteContract",e)}))},e.prototype.query=function(t,e){return void 0===e&&(e=[]),this.request(function(t,e,r){if(void 0===e&&(e=[]),void 0===r&&(r=!1),at(t)&&E(e)){var n=function(t){var e;return(e={}).args=t,e}(e);return!0===r?n:Bn(t,n)}throw new l("[createQuery] expect resolverName to be string and args to be array!",{resolverName:t,args:e})}(t,e)).then(_)},e.prototype.mutation=function(t,e,r){return void 0===e&&(e={}),void 0===r&&(r={}),this.request(function(t,e,r,n){void 0===r&&(r={}),void 0===n&&(n=!1);var o={};if(o.payload=e,o.condition=r,!0===n)return o;if(at(t))return Bn(t,o);throw new l("[createMutation] expect resolverName to be string!",{resolverName:t,payload:e,condition:r})}(t,e,r),{method:Wo}).then(_)},Object.defineProperties(e.prototype,r),e}(Bo)))),Qo={contract:!1,MUTATION_ARGS:["name","payload","conditions"],CONTENT_TYPE:f,BEARER:"Bearer",AUTH_HEADER:"Authorization"},Xo={hostname:vn(function(){try{return[window.location.protocol,window.location.host].join("//")}catch(t){return null}}(),["string"]),jsonqlPath:vn("jsonql",["string"]),loginHandlerName:vn("login",["string"]),logoutHandlerName:vn("logout",["string"]),enableJsonp:vn(!1,["boolean"]),enableAuth:vn(!1,["boolean"]),useJwt:vn(!0,["boolean"]),persistToken:vn(!1,["boolean","number"]),useLocalstorage:vn(!0,["boolean"]),storageKey:vn("jsonqlstore",["string"]),authKey:vn("jsonqlauthkey",["string"]),contractExpired:vn(0,["number"]),keepContract:vn(!0,["boolean"]),exposeContract:vn(!1,["boolean"]),exposeStore:vn(!1,["boolean"]),showContractDesc:vn(!1,["boolean"]),contractKey:vn(!1,["boolean"]),contractKeyName:vn("X-JSONQL-CV-KEY",["string"]),enableTimeout:vn(!1,["boolean"]),timeout:vn(5e3,["number"]),returnInstance:vn(!1,["boolean"]),allowReturnRawToken:vn(!1,["boolean"]),debugOn:vn(!1,["boolean"])};function Zo(t,e){for(var r=[],n=arguments.length-2;n-- >0;)r[n]=arguments[n+2];var o=function(t){return wn(t,"__checked__",Kn())};r.push(o);var i=Reflect.apply(_n,null,r);return function(r){return void 0===r&&(r={}),i(r,t,e)}}function ti(t){var e=function(t,e){for(var r=[],n=arguments.length-2;n-- >0;)r[n]=arguments[n+2];return function(n){var o;if(void 0===n&&(n={}),mn(n,"__checked__")){var i=1;return n.__passed__&&(i=++n.__passed__,delete n.__passed__),Promise.resolve(Object.assign(((o={}).__passed__=i,o),n,e))}var a=Reflect.apply(Zo,null,[t,e].concat(r));return Promise.resolve(a(n))}}(Xo,Qo,gn),r=t.contract;return e(t).then((function(t){return t.contract=r,t}))}function ei(t,e,r){return void 0===r&&(r={}),ti(r).then((function(t){return{baseClient:new Yo(e,t),opts:t}})).then((function(e){var r,n,o=e.baseClient,i=e.opts;return(r=o,n=i.contract,void 0===n&&(n={}),En(n)?Promise.resolve(n):r.getContract()).then((function(e){return An(o,i,e,t)}))}))}var ri=new WeakMap,ni=new WeakMap,oi=function(){this.__suspend__=null,this.queueStore=new Set},ii={$suspend:{configurable:!0},$queues:{configurable:!0}};ii.$suspend.set=function(t){var e=this;if("boolean"!=typeof t)throw new Error("$suspend only accept Boolean value!");var r=this.__suspend__;this.__suspend__=t,this.logger("($suspend)","Change from "+r+" --\x3e "+t),!0===r&&!1===t&&setTimeout((function(){e.release()}),1)},oi.prototype.$queue=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return!0===this.__suspend__&&(this.logger("($queue)","added to $queue",t),this.queueStore.add(t)),this.__suspend__},ii.$queues.get=function(){var t=this.queueStore.size;return this.logger("($queues)","size: "+t),t>0?Array.from(this.queueStore):[]},oi.prototype.release=function(){var t=this,e=this.queueStore.size;if(this.logger("(release)","Release was called "+e),e>0){var r=Array.from(this.queueStore);this.queueStore.clear(),this.logger("queue",r),r.forEach((function(e){t.logger(e),Reflect.apply(t.$trigger,t,e)})),this.logger("Release size "+this.queueStore.size)}},Object.defineProperties(oi.prototype,ii);var ai=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={name:{configurable:!0}};return r.name.get=function(){return"jsonql-event-emitter"},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){void 0===e&&(e={}),t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={$done:{configurable:!0}};return e.prototype.logger=function(){},e.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.logger("($on)","call run on "+t),n.run(e,a,r||u),i+=n.addToNormalStore(t,"on",e,r||u)})),i},e.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.logger("($once)","call run for "+t),this.run(e,i,r||a),this.$off(t)},e.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(o){var i=o[0],a=o[1],u=o[2];if(u&&"only"!==u)throw new Error("You are trying to register an event already been taken by other type: "+u);n.logger("($only)","call run for "+t),n.run(e,i,r||a)})));return o},e.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.logger("($onlyOnce)","call run for "+t),this.run(e,a,r||u),this.$off(t)}return n},e.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 this.logger("($replace)",t,e),Reflect.apply(o,this,[t,e,r])}throw new Error(n+" is not supported!")},e.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)","normalStore",i),i.has(t)){var a=this.$queue(t,e,r,n);if(this.logger("($trigger)",t,"found; add to queue: ",a),!0===a)return this.logger("($trigger)",t,"not executed. Exit now."),!1;for(var u=Array.from(i.get(t)),c=u.length,s=!1,l=0;l0;)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]},e.prototype.checkContentExist=function(t,e){return!!Array.from(e).filter((function(e){return e[0]===t[0]})).length},e.prototype.checkTypeInStore=function(t,e){this.validateEvt(t,e);var r=this.$get(t,!0);return!1===r||!r.filter((function(t){var r=t[3];return e!==r})).length},e.prototype.checkTypeInLazyStore=function(t,e){this.validateEvt(t,e);var r=this.lazyStore.get(t);return this.logger("(checkTypeInLazyStore)",r),!!r&&!!Array.from(r).filter((function(t){return t[2]!==e})).length},e.prototype.addToNormalStore=function(t,e,r,n){if(void 0===n&&(n=null),this.logger("(addToNormalStore)",t,e,"try to add to normal store"),this.checkTypeInStore(t,e)){this.logger("(addToNormalStore)",e+" can add to "+t+" normal 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},e.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},e.prototype.toArray=function(t){return Array.isArray(t)?t:[t]},r.normalStore.set=function(t){ri.set(this,t)},r.normalStore.get=function(){return ri.get(this)},r.lazyStore.set=function(t){ni.set(this,t)},r.lazyStore.get=function(){return ni.get(this)},e.prototype.hashFnToKey=function(t){return Tn(t.toString())},Object.defineProperties(e.prototype,r),e}(oi)));return function(t,e){var r;return ei((r=e.debugOn,new ai({logger:r?function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];t.unshift("[BUILTIN]"),console.log.apply(null,t)}:void 0})),t,e)}})); +!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=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),e=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),r=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 403},r.name.get=function(){return"JsonqlForbiddenError"},Object.defineProperties(e,r),e}(Error),n=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),o=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),i=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),a=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),u=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),c=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),s=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),l=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),f="application/vnd.api+json",p={Accept:f,"Content-Type":[f,"charset=utf-8"].join(";")},h=["POST","PUT"],d={desc:"y"},v=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),g=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),y=Object.freeze({__proto__:null,Jsonql406Error:t,Jsonql500Error:e,JsonqlForbiddenError:r,JsonqlAuthorisationError:n,JsonqlContractAuthError:o,JsonqlResolverAppError:i,JsonqlResolverNotFoundError:a,JsonqlEnumError:u,JsonqlTypeError:c,JsonqlCheckerError:s,JsonqlValidationError:l,JsonqlError:v,JsonqlServerError:g}),b=v;function _(t){if(function(t,e){return!!Object.keys(t).filter((function(t){return e===t})).length}(t,"error")){var e=t.error,r=e.className,n=e.name,o=r||n,i=e.message||"No message",a=e.detail||e;if(o&&y[o])throw new y[r](i,a);throw new b(i,a)}return t}function m(f){if(Array.isArray(f))throw new l("",f);var p=f.message||"No message",h=f.detail||f;switch(!0){case f instanceof t:throw new t(p,h);case f instanceof e:throw new e(p,h);case f instanceof r:throw new r(p,h);case f instanceof n:throw new n(p,h);case f instanceof o:throw new o(p,h);case f instanceof i:throw new i(p,h);case f instanceof a:throw new a(p,h);case f instanceof u:throw new u(p,h);case f instanceof c:throw new c(p,h);case f instanceof s:throw new s(p,h);case f instanceof l:throw new l(p,h);case f instanceof g:throw new g(p,h);default:throw new v(p,h)}}var w="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},j="object"==typeof w&&w&&w.Object===Object&&w,S="object"==typeof self&&self&&self.Object===Object&&self,O=j||S||Function("return this")(),k=O.Symbol;function A(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r=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);++n-1;);return r}(n,o),function(t,e){for(var r=t.length;r--&&L(e,t[r],0)>-1;);return r}(n,o)+1).join("")}var ot=function(t){return!!E(t)||null!=t&&""!==nt(t)};function it(t){return function(t){return"number"==typeof t||N(t)&&"[object Number]"==z(t)}(t)&&t!=+t}function at(t){return"string"==typeof t||!E(t)&&N(t)&&"[object String]"==z(t)}var ut=function(t){return!at(t)&&!it(parseFloat(t))},ct=function(t){return""!==nt(t)&&at(t)},st=function(t){return null!=t&&"boolean"==typeof t},lt=function(t,e){return void 0===e&&(e=!0),void 0!==t&&""!==t&&""!==nt(t)&&(!1===e||!0===e&&null!==t)},ft=function(t){switch(t){case"number":return ut;case"string":return ct;case"boolean":return st;default:return lt}},pt=function(t,e){return void 0===e&&(e=""),!!E(t)&&(""===e||""===nt(e)||!(t.filter((function(t){return!ft(e)(t)})).length>0))},ht=function(t){if(t.indexOf("array.<")>-1&&t.indexOf(">")>-1){var e=t.replace("array.<","").replace(">","");return e.indexOf("|")?e.split("|"):[e]}return!1},dt=function(t,e){var r=t.arg;return e.length>1?!r.filter((function(t){return!(e.length>e.filter((function(e){return!ft(e)(t)})).length)})).length:e.length>e.filter((function(t){return!pt(r,t)})).length};function vt(t,e){return function(r){return t(e(r))}}var gt=vt(Object.getPrototypeOf,Object),yt=Function.prototype,bt=Object.prototype,_t=yt.toString,mt=bt.hasOwnProperty,wt=_t.call(Object);function jt(t){if(!N(t)||"[object Object]"!=z(t))return!1;var e=gt(t);if(null===e)return!0;var r=mt.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&_t.call(r)==wt}var St,Ot=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),a=i.length;a--;){var u=i[St?a:++n];if(!1===e(o[u],u,o))break}return t};function kt(t){return N(t)&&"[object Arguments]"==z(t)}var At=Object.prototype,Et=At.hasOwnProperty,Tt=At.propertyIsEnumerable,xt=kt(function(){return arguments}())?kt:function(t){return N(t)&&Et.call(t,"callee")&&!Tt.call(t,"callee")};var Pt="object"==typeof exports&&exports&&!exports.nodeType&&exports,qt=Pt&&"object"==typeof module&&module&&!module.nodeType&&module,Ct=qt&&qt.exports===Pt?O.Buffer:void 0,$t=(Ct?Ct.isBuffer:void 0)||function(){return!1},zt=/^(?:0|[1-9]\d*)$/;function Nt(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&zt.test(t))&&t>-1&&t%1==0&&t-1&&t%1==0&&t<=9007199254740991}var It={};It["[object Float32Array]"]=It["[object Float64Array]"]=It["[object Int8Array]"]=It["[object Int16Array]"]=It["[object Int32Array]"]=It["[object Uint8Array]"]=It["[object Uint8ClampedArray]"]=It["[object Uint16Array]"]=It["[object Uint32Array]"]=!0,It["[object Arguments]"]=It["[object Array]"]=It["[object ArrayBuffer]"]=It["[object Boolean]"]=It["[object DataView]"]=It["[object Date]"]=It["[object Error]"]=It["[object Function]"]=It["[object Map]"]=It["[object Number]"]=It["[object Object]"]=It["[object RegExp]"]=It["[object Set]"]=It["[object String]"]=It["[object WeakMap]"]=!1;var Rt,Ft="object"==typeof exports&&exports&&!exports.nodeType&&exports,Jt=Ft&&"object"==typeof module&&module&&!module.nodeType&&module,Ut=Jt&&Jt.exports===Ft&&j.process,Lt=function(){try{var t=Jt&&Jt.require&&Jt.require("util").types;return t||Ut&&Ut.binding&&Ut.binding("util")}catch(t){}}(),Ht=Lt&&Lt.isTypedArray,Dt=Ht?(Rt=Ht,function(t){return Rt(t)}):function(t){return N(t)&&Mt(t.length)&&!!It[z(t)]},Kt=Object.prototype.hasOwnProperty;function Bt(t,e){var r=E(t),n=!r&&xt(t),o=!r&&!n&&$t(t),i=!r&&!n&&!o&&Dt(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r-1},ie.prototype.set=function(t,e){var r=this.__data__,n=ne(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var ae,ue=O["__core-js_shared__"],ce=(ae=/[^.]+$/.exec(ue&&ue.keys&&ue.keys.IE_PROTO||""))?"Symbol(src)_1."+ae:"";var se=Function.prototype.toString;function le(t){if(null!=t){try{return se.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var fe=/^\[object .+?Constructor\]$/,pe=Function.prototype,he=Object.prototype,de=pe.toString,ve=he.hasOwnProperty,ge=RegExp("^"+de.call(ve).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ye(t){return!(!Qt(t)||function(t){return!!ce&&ce in t}(t))&&(Xt(t)?ge:fe).test(le(t))}function be(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return ye(r)?r:void 0}var _e=be(O,"Map"),me=be(Object,"create");var we=Object.prototype.hasOwnProperty;var je=Object.prototype.hasOwnProperty;function Se(t){var e=-1,r=null==t?0:t.length;for(this.clear();++eu))return!1;var s=i.get(t);if(s&&i.get(e))return s==e;var l=-1,f=!0,p=2&r?new Ee:void 0;for(i.set(t,e),i.set(e,t);++le.type.filter((function(t){var e;return void 0===r||(!1!==(e=ht(t))?!dt({arg:r},e):!ft(t)(r))})).length)})).length}return!1},Sr=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),!Reflect.apply(jr,null,a);case"array"===t:return!pt(e.arg);case!1!==(r=ht(t)):return!dt(e,r);default:return!ft(t)(e.arg)}},Or=function(t,e){return void 0!==t?t:!0===e.optional&&void 0!==e.defaultvalue?e.defaultvalue:null},kr=function(t,e,r){var n;void 0===r&&(r=!1);var o=function(t,e){if(!pt(e))throw new v("params is not an array! Did something gone wrong when you generate the contract.json?");if(0===e.length)return[];if(!pt(t))throw new v("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:var n=e.length,o=["any"];return t.map((function(t,r){var i=r>=n||!!e[r].optional,a=e[r]||{type:o,name:"_"+r};return{arg:i?Or(t,a):t,index:r,param:a,optional:i}}));default:throw new v("Could not understand your arguments and parameter structure!",{args:t,params:e})}}(t,e),i=o.filter((function(t){return!0===t.optional||!0===t.param.optional?function(t){var e=t.arg,r=t.param;return!!ot(e)&&!(r.type.length>r.type.filter((function(e){return Sr(e,t)})).length)}(t):!(t.param.type.length>t.param.type.filter((function(e){return Sr(e,t)})).length)}));return r?((n={}).error=i,n.data=o.map((function(t){return t.arg})),n):i},Ar=function(){try{var t=be(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();function Er(t,e,r){"__proto__"==e&&Ar?Ar(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}function Tr(t,e,r){(void 0===r||re(t[e],r))&&(void 0!==r||e in t)||Er(t,e,r)}var xr="object"==typeof exports&&exports&&!exports.nodeType&&exports,Pr=xr&&"object"==typeof module&&module&&!module.nodeType&&module,qr=Pr&&Pr.exports===xr?O.Buffer:void 0,Cr=qr?qr.allocUnsafe:void 0;function $r(t,e){var r,n,o=e?(r=t.buffer,n=new r.constructor(r.byteLength),new Pe(n).set(new Pe(r)),n):t.buffer;return new t.constructor(o,t.byteOffset,t.length)}var zr=Object.create,Nr=function(){function t(){}return function(e){if(!Qt(e))return{};if(zr)return zr(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();function Mr(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}var Ir=Object.prototype.hasOwnProperty;function Rr(t,e,r){var n=t[e];Ir.call(t,e)&&re(n,r)&&(void 0!==r||e in t)||Er(t,e,r)}var Fr=Object.prototype.hasOwnProperty;function Jr(t){if(!Qt(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=Gt(t),r=[];for(var n in t)("constructor"!=n||!e&&Fr.call(t,n))&&r.push(n);return r}function Ur(t){return Zt(t)?Bt(t,!0):Jr(t)}function Lr(t){return function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Vr);function Yr(t,e){return Wr(function(t,e,r){return e=Br(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=Br(n.length-e,0),a=Array(i);++o1?e[n-1]:void 0,i=n>2?e[2]:void 0;for(o=Qr.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!Qt(r))return!1;var n=typeof e;return!!("number"==n?Zt(r)&&Nt(e,r.length):"string"==n&&e in r)&&re(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r0;)e[r]=arguments[r+1];return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return e.reduce((function(t,e){return Reflect.apply(e,null,yn(t))}),Reflect.apply(t,null,r))}};function mn(t,e){var r=Object.getOwnPropertyDescriptor(t,e);return void 0!==r&&r.value?r.value:r}function wn(t,e,r,n){void 0===n&&(n=!1);var o=mn(t,e);return!1===n&&void 0!==o?t:(Object.defineProperty(t,e,{value:r,writable:n}),t)}var jn=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 dn(r,i).then((function(){return t.query.apply(t,[e,a,u])})).catch(m)}},Sn=function(t,e,r,n,o){var i={},a=function(t){i=wn(i,t,(function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var i=o.query[t].params,a=i.map((function(t,e){return r[e]})),u={};return dn(a,i).then((function(){return e.query.apply(e,[t,a,u])})).catch(m)}))};for(var u in o.query)a(u);return t.query=i,t.helloWorld=i.helloWorld,[t,e,r,n,o]},On=function(t,e,r,n,o){var i={},a=function(t){i=wn(i,t,(function(r,n,i){void 0===i&&(i={});var a=[r,n],u=o.mutation[t].params;return dn(a,u).then((function(){return e.mutation.apply(e,[t,r,n,i])})).catch(m)}))};for(var u in o.mutation)a(u);return t.mutation=i,[t,e,r,n,o]},kn=function(t,e,r,n,o){if(n.enableAuth&&o.auth){var i={},a=n.loginHandlerName,u=n.logoutHandlerName;o.auth[a]&&(i[a]=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var i=jn(e,a,0,o);return i.apply(null,t).then(e.postLoginAction.bind(e)).then((function(t){var e=t.token,n=t.userdata;return r.$trigger("login",e),n}))}),o.auth[u]?i[u]=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var i=jn(e,u,0,o);return i.apply(null,t).then(e.postLogoutAction.bind(e)).then((function(t){return r.$trigger("logout",t),t}))}:i[u]=function(t){void 0===t&&(t=null),e.postLogoutAction("continue",t),r.$trigger("logout","continue")},t.auth=i}return t};var An=function(t,e,r,n){var o=function(t,e,r,n){var o=[Sn,On,kn];return Reflect.apply(_n,null,o)({},t,e,r,n)}(t,n,e,r);return e.exposeStore,o=function(t,e,r,n,o){return t.eventEmitter=r,t.contract=o,t.version="1.5.19",t.getLogger=function(t){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return Reflect.apply(e.log,e,[t].concat(r))}},n.enableAuth&&(t.userdata=function(){return e.jsonqlUserdata},t.getToken=function(t){return void 0===t&&(t=!1),e.rawAuthToken(t)},t.profileIndex=function(t){if(void 0===t&&(t=!1),!1===t)return e.profileIndex;e.profileIndex=t},t.getProfiles=function(t){return void 0===t&&(t=!1),e.getProfiles(t)}),t}(o,t,n,e,r)};function En(t){return!!function(t){return jt(t)&&(bn(t,"query")||bn(t,"mutation")||bn(t,"socket"))}(t)&&t}function Tn(t){return function(t){return t.split("").reduce((function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t}),0)}(t)+""}function xn(t){this.message=t}xn.prototype=new Error,xn.prototype.name="InvalidCharacterError";var Pn="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new xn("'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="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return a};var qn=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(Pn(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 Pn(e)}};function Cn(t){this.message=t}Cn.prototype=new Error,Cn.prototype.name="InvalidTokenError";var $n=function(t,e){if("string"!=typeof t)throw new Cn("Invalid token specified");var r=!0===(e=e||{}).header?0:1;try{return JSON.parse(qn(t.split(".")[r]))}catch(t){throw new Cn("Invalid token specified: "+t.message)}};$n.InvalidTokenError=Cn;var zn,Nn,Mn,In,Rn,Fn,Jn,Un,Ln;function Hn(t){var e=t.iat||function(t){void 0===t&&(t=!1);var e=Date.now();return t?Math.floor(e/1e3):e}(!0);if(t.exp&&e>=t.exp){var r=new Date(t.exp).toISOString();throw new v("Token has expired on "+r,t)}return t}function Dn(t){if(ct(t))return Hn($n(t));throw new v("Token must be a string!")}vn("HS256",["string"]),vn(!1,["boolean","number","string"],((zn={}).alias="exp",zn.optional=!0,zn)),vn(!1,["boolean","number","string"],((Nn={}).alias="nbf",Nn.optional=!0,Nn)),vn(!1,["boolean","string"],((Mn={}).alias="iss",Mn.optional=!0,Mn)),vn(!1,["boolean","string"],((In={}).alias="sub",In.optional=!0,In)),vn(!1,["boolean","string"],((Rn={}).alias="iss",Rn.optional=!0,Rn)),vn(!1,["boolean"],((Fn={}).optional=!0,Fn)),vn(!1,["boolean","string"],((Jn={}).optional=!0,Jn)),vn(!1,["boolean","string"],((Un={}).optional=!0,Un)),vn(!1,["boolean"],((Ln={}).optional=!0,Ln));var Kn=function(t){void 0===t&&(t=!1);var e=Date.now();return t?Math.floor(e/1e3):e};function Bn(t,e){var r;return(r={})[t]=e,r.TS=[Kn()],r}var Vn=function(t){return bn(t,"data")&&!bn(t,"error")?t.data:t},Gn="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var Wn=Object.assign?Object.assign:function(t,e,r,n){for(var o=arguments,i=1;i=0;e--){var r=bo().key(e);t(_o(r),r)}},remove:function(t){return bo().removeItem(t)},clearAll:function(){return bo().clear()}};function bo(){return go.localStorage}function _o(t){return bo().getItem(t)}var mo=Zn.trim,wo={name:"cookieStorage",read:function(t){if(!t||!ko(t))return null;var e="(?:^|.*;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(jo.cookie.replace(new RegExp(e),"$1"))},write:function(t,e){if(!t)return;jo.cookie=escape(t)+"="+escape(e)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"},each:So,remove:Oo,clearAll:function(){So((function(t,e){Oo(e)}))}},jo=Zn.Global.document;function So(t){for(var e=jo.cookie.split(/; ?/g),r=e.length-1;r>=0;r--)if(mo(e[r])){var n=e[r].split("="),o=unescape(n[0]);t(unescape(n[1]),o)}}function Oo(t){t&&ko(t)&&(jo.cookie=escape(t)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function ko(t){return new RegExp("(?:^|;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(jo.cookie)}var Ao=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 Eo=Zn.bind,To=Zn.each,xo=Zn.create,Po=Zn.slice,qo=function(){var t=xo(Co,{_id:0,_subSignals:{},_subCallbacks:{}});return{watch:function(e,r,n){return t.on(r,Eo(this,n))},unwatch:function(e,r){t.off(r)},once:function(e,r,n){t.once(r,Eo(this,n))},set:function(e,r,n){var o=this.get(r);e(),t.fire(r,n,o)},remove:function(e,r){var n=this.get(r);e(),t.fire(r,void 0,n)},clearAll:function(e){var r={};this.each((function(t,e){r[e]=t})),e(),To(r,(function(e,r){t.fire(r,void 0,e)}))}}};var Co={_id:null,_subCallbacks:null,_subSignals:null,on:function(t,e){return this._subCallbacks[t]||(this._subCallbacks[t]={}),this._id+=1,this._subCallbacks[t][this._id]=e,this._subSignals[this._id]=t,this._id},off:function(t){var e=this._subSignals[t];delete this._subCallbacks[e][t],delete this._subSignals[t]},once:function(t,e){var r=this.on(t,Eo(this,(function(){e.apply(this,arguments),this.off(r)})))},fire:function(t){var e=Po(arguments,1);To(this._subCallbacks[t],(function(t){t.apply(this,e)}))}},$o=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t){var e=function(){var t=String.fromCharCode,e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",n={};function o(t,e){if(!n[t]){n[t]={};for(var r=0;r>>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==--f&&(f=Math.pow(2,h),h++),delete u[l]}else for(o=a[l],n=0;n>=1;0==--f&&(f=Math.pow(2,h),h++),a[s]=p++,l=String(c)}if(""!==l){if(Object.prototype.hasOwnProperty.call(u,l)){if(l.charCodeAt(0)<256){for(n=0;n>=1}else{for(o=1,n=0;n>=1}0==--f&&(f=Math.pow(2,h),h++),delete u[l]}else for(o=a[l],n=0;n>=1;0==--f&&(f=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,l,f=[],p=4,h=4,d=3,v="",g=[],y={val:n(0),position:r,index:1};for(o=0;o<3;o+=1)f[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;l=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;l=t(a);break;case 2:return""}for(f[3]=l,i=l,g.push(l);;){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(l=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[h++]=t(a),l=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;f[h++]=t(a),l=h-1,p--;break;case 2:return g.join("")}if(0==p&&(p=Math.pow(2,d),d++),f[l])v=f[l];else{if(l!==h)return null;v=i+i.charAt(0)}g.push(v),f[h++]=i+v.charAt(0),i=v,0==--p&&(p=Math.pow(2,d),d++)}}};return i}();null!=t&&(t.exports=e)})),zo=function(){return{get:function(t,e){var r=t(e);if(!r)return r;var n=$o.decompress(r);return null==n?r:this._deserialize(n)},set:function(t,e,r){var n=$o.compress(this._serialize(r));t(e,n)}}};var No=[yo,wo],Mo=[Ao,qo,zo],Io=po.createStore(No,Mo),Ro=Zn.Global;function Fo(){return Ro.sessionStorage}function Jo(t){return Fo().getItem(t)}var Uo=[{name:"sessionStorage",read:Jo,write:function(t,e){return Fo().setItem(t,e)},each:function(t){for(var e=Fo().length-1;e>=0;e--){var r=Fo().key(e);t(Jo(r),r)}},remove:function(t){return Fo().removeItem(t)},clearAll:function(){return Fo().clear()}},wo],Lo=[Ao,zo],Ho=po.createStore(Uo,Lo),Do=Io,Ko=Ho,Bo=function(t){this.opts=t,this.instanceKey=Tn(this.opts.hostname),this.localStore=Do,this.sessionStore=Ko},Vo={lset:{configurable:!0},lget:{configurable:!0},sset:{configurable:!0},sget:{configurable:!0}};Bo.prototype.__setMethod=function(t,e){var r,n=this[t],o=this.__getMethod(t),i=this.opts.storageKey,a=this.instanceKey;n.set(i,((r={})[a]=o?Xr({},o,e):e,r))},Bo.prototype.__getMethod=function(t){var e=this[t].get(this.opts.storageKey);return!!e&&e[this.instanceKey]},Bo.prototype.__delMethod=function(t,e){var r=this.__getMethod(t);if(r){var n={};for(var o in r)o!==e&&(n[o]=r[o]);this.__setMethod(t,n)}},Bo.prototype.__clearMethod=function(t){var e=this.opts.storageKey,r=this[t],n=r.get(e);if(n){var o={};for(var i in n)i!==this.instanceKey&&(o[i]=n[i]);r.set(e,o)}},Vo.lset.set=function(t){return this.__setMethod("localStore",t)},Vo.lget.get=function(){return this.__getMethod("localStore")},Bo.prototype.ldel=function(t){return this.__delMethod("localStore",t)},Bo.prototype.lclear=function(){return this.__clearMethod("localStore")},Vo.sset.set=function(t){return this.__setMethod("sessionStore",t)},Vo.sget.get=function(){return this.__getMethod("sessionStore")},Bo.prototype.sdel=function(t){return this.__delMethod("sessionStore",t)},Bo.prototype.sclear=function(){return this.__clearMethod("sessionStore")},Object.defineProperties(Bo.prototype,Vo);var Go=h[0],Wo=h[1],Yo=function(t){function e(e,r){t.call(this,r),this.httpEngine=e,this.reqInterceptor(),this.resInterceptor()}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={jsonqlEndpoint:{configurable:!0}};return r.jsonqlEndpoint.get=function(){return[this.opts.hostname||"",this.opts.jsonqlPath].join("/")},e.prototype.log=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(!0===this.opts.debugOn){var r=["info","error"],n="__error__"===t[0]?1:0;t.splice(0,n),Reflect.apply(console[r[n]],console,t)}},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),e.enableAuth&&(this.setDecoder=Dn),this.__userdata__=null}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={profileIndex:{configurable:!0},setDecoder:{configurable:!0},saveProfile:{configurable:!0},readProfile:{configurable:!0},jsonqlToken:{configurable:!0},jsonqlUserdata:{configurable:!0}};return e.prototype.decoder=function(t){return t},r.profileIndex.set=function(t){var e;if(hn(t))return this.prof_idx=t,void(this.opts.persistToken&&(this.lset=((e={}).prof_idx=t,e)));throw new l("profileIndex","Expect idx to be number but got "+typeof t)},r.profileIndex.get=function(){var t="prof_idx";if(this.opts.persistToken){var e=this.lget;if(e[t])return e[t]}return this[t]?this[t]:0},e.prototype.rawAuthToken=function(t){return void 0===t&&(t=!1),!1!==t&&(this.profileIndex=t),this.jsonqlToken},r.setDecoder.set=function(t){"function"==typeof t&&(this.decoder=t)},r.saveProfile.set=function(t){this.opts.persistToken?this.lset=t:this.sset=t},r.readProfile.get=function(){return this.opts.persistToken?this.lget:this.sget},r.jsonqlToken.set=function(t){var e,r=this.readProfile,n="jsonqlcredential",o=r&&r[n]?r[n]:[];o.push(t),this.saveProfile=((e={})[n]=o,e),this.__userdata__=this.decoder(t),this.jsonqlUserdata=this.__userdata__},r.jsonqlToken.get=function(){var t=this.readProfile,e="jsonqlcredential";return!(!t||!t[e])&&(this.log("-- jsonqlToken --",t[e],this.profileIndex,t[e][this.profileIndex]),t[e][this.profileIndex])},r.jsonqlUserdata.set=function(t){var e;this.sset=((e={}).userdata=t,e)},r.jsonqlUserdata.get=function(){var t=this.sget;return!!t&&t.userdata},e.prototype.getAuthHeader=function(){var t,e=this.jsonqlToken;return e?((t={})[this.opts.AUTH_HEADER]="Bearer "+e,t):{}},e.prototype.getProfiles=function(t){void 0===t&&(t=!1);var e=this.readProfile,r="jsonqlcredential";return!(!e||!e[r])&&(!1!==t&&hn(t)?e[r][t]||!1:e[r].map(this.decoder.bind(this)))},e.prototype.postLoginAction=function(t){return this.jsonqlToken=t,{token:t,userdata:this.__userdata__}},e.prototype.postLogoutAction=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];console.info("postLogoutAction",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();return this.log("getContract first call",t),t?Promise.resolve(t):this.getRemoteContract().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){var e;if(!En(t))throw new l("Contract is malformed!");return this.lset=((e={}).contract=t,e),this.log("storeContract return result",t),t},e.prototype.readContract=function(){var t=En(this.opts.contract);if(!1!==t)return t;var e=this.lget;return!!e&&e.contract},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),this.extraHeader={},this.extraParams={}}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={headers:{configurable:!0}};return r.headers.set=function(t){this.extraHeader=t},e.prototype.request=function(t,e,r){var n;void 0===e&&(e={}),void 0===r&&(r={}),this.headers=r;var o=Xr({},{_cb:Kn()},this.extraParams);if(this.opts.enableJsonp){var i=function(t){return Object.keys(t)[0]}(t);o=Xr({},o,((n={}).jsonqlJsonpCallback=i,n)),t=t[i]}var a=Xr({},{method:Go,params:o},e);return this.log("request params",a,this.jsonqlEndpoint),this.httpEngine.request(this.jsonqlEndpoint,t,a)},e.prototype.reqInterceptor=function(){var t=this;this.httpEngine.interceptors.request.use((function(e){var r=t.getHeaders();for(var n in t.log("request interceptor call",r),r)e.headers[n]=r[n];return e}))},e.prototype.processJsonp=function(t){return Vn(t)},e.prototype.resInterceptor=function(){var t=this,e=this,r=e.opts.enableJsonp;this.httpEngine.interceptors.response.use((function(n){t.log("response interceptor call",n),e.cleanUp();var o=pn(n.data)?JSON.parse(n.data):n.data;return r?e.processJsonp(o):Vn(o)}),(function(r){throw e.cleanUp(),t.log("__error__",r),new g("Server side error",r)}))},e.prototype.getHeaders=function(){return this.opts.enableAuth?Xr({},p,this.getAuthHeader(),this.extraHeader):Xr({},p,this.extraHeader)},e.prototype.cleanUp=function(){this.extraHeader={},this.extraParams={}},e.prototype.getRemoteContract=function(){var t=this;return this.opts.showContractDesc&&(this.extraParams=Xr({},this.extraParams,d)),this.request({},{method:"GET"},this.contractHeader).then(_).then((function(e){return t.log("get contract result",e),e.cache&&e.contract?e.contract:e})).catch((function(e){throw t.log("__error__","getRemoteContract err",e),new g("getRemoteContract",e)}))},e.prototype.query=function(t,e){return void 0===e&&(e=[]),this.request(function(t,e,r){if(void 0===e&&(e=[]),void 0===r&&(r=!1),at(t)&&E(e)){var n=function(t){var e;return(e={}).args=t,e}(e);return!0===r?n:Bn(t,n)}throw new l("[createQuery] expect resolverName to be string and args to be array!",{resolverName:t,args:e})}(t,e)).then(_)},e.prototype.mutation=function(t,e,r){return void 0===e&&(e={}),void 0===r&&(r={}),this.request(function(t,e,r,n){void 0===r&&(r={}),void 0===n&&(n=!1);var o={};if(o.payload=e,o.condition=r,!0===n)return o;if(at(t))return Bn(t,o);throw new l("[createMutation] expect resolverName to be string!",{resolverName:t,payload:e,condition:r})}(t,e,r),{method:Wo}).then(_)},Object.defineProperties(e.prototype,r),e}(Bo)))),Qo={contract:!1,MUTATION_ARGS:["name","payload","conditions"],CONTENT_TYPE:f,BEARER:"Bearer",AUTH_HEADER:"Authorization"},Xo={hostname:vn(function(){try{return[window.location.protocol,window.location.host].join("//")}catch(t){return null}}(),["string"]),jsonqlPath:vn("jsonql",["string"]),loginHandlerName:vn("login",["string"]),logoutHandlerName:vn("logout",["string"]),enableJsonp:vn(!1,["boolean"]),enableAuth:vn(!1,["boolean"]),useJwt:vn(!0,["boolean"]),persistToken:vn(!1,["boolean","number"]),useLocalstorage:vn(!0,["boolean"]),storageKey:vn("jsonqlstore",["string"]),authKey:vn("jsonqlauthkey",["string"]),contractExpired:vn(0,["number"]),keepContract:vn(!0,["boolean"]),exposeContract:vn(!1,["boolean"]),exposeStore:vn(!1,["boolean"]),showContractDesc:vn(!1,["boolean"]),contractKey:vn(!1,["boolean"]),contractKeyName:vn("X-JSONQL-CV-KEY",["string"]),enableTimeout:vn(!1,["boolean"]),timeout:vn(5e3,["number"]),returnInstance:vn(!1,["boolean"]),allowReturnRawToken:vn(!1,["boolean"]),debugOn:vn(!1,["boolean"])};function Zo(t,e){for(var r=[],n=arguments.length-2;n-- >0;)r[n]=arguments[n+2];var o=function(t){return wn(t,"__checked__",Kn())};r.push(o);var i=Reflect.apply(_n,null,r);return function(r){return void 0===r&&(r={}),i(r,t,e)}}function ti(t){var e=function(t,e){for(var r=[],n=arguments.length-2;n-- >0;)r[n]=arguments[n+2];return function(n){var o;if(void 0===n&&(n={}),mn(n,"__checked__")){var i=1;return n.__passed__&&(i=++n.__passed__,delete n.__passed__),Promise.resolve(Object.assign(((o={}).__passed__=i,o),n,e))}var a=Reflect.apply(Zo,null,[t,e].concat(r));return Promise.resolve(a(n))}}(Xo,Qo,gn),r=t.contract;return e(t).then((function(t){return t.contract=r,t}))}function ei(t,e,r){return void 0===r&&(r={}),ti(r).then((function(t){return{baseClient:new Yo(e,t),opts:t}})).then((function(e){var r,n,o=e.baseClient,i=e.opts;return(r=o,n=i.contract,void 0===n&&(n={}),En(n)?Promise.resolve(n):r.getContract()).then((function(e){return An(o,i,e,t)}))}))}var ri=new WeakMap,ni=new WeakMap,oi=function(){this.__suspend__=null,this.queueStore=new Set},ii={$suspend:{configurable:!0},$queues:{configurable:!0}};ii.$suspend.set=function(t){var e=this;if("boolean"!=typeof t)throw new Error("$suspend only accept Boolean value!");var r=this.__suspend__;this.__suspend__=t,this.logger("($suspend)","Change from "+r+" --\x3e "+t),!0===r&&!1===t&&setTimeout((function(){e.release()}),1)},oi.prototype.$queue=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return!0===this.__suspend__&&(this.logger("($queue)","added to $queue",t),this.queueStore.add(t)),this.__suspend__},ii.$queues.get=function(){var t=this.queueStore.size;return this.logger("($queues)","size: "+t),t>0?Array.from(this.queueStore):[]},oi.prototype.release=function(){var t=this,e=this.queueStore.size;if(this.logger("(release)","Release was called "+e),e>0){var r=Array.from(this.queueStore);this.queueStore.clear(),this.logger("queue",r),r.forEach((function(e){t.logger(e),Reflect.apply(t.$trigger,t,e)})),this.logger("Release size "+this.queueStore.size)}},Object.defineProperties(oi.prototype,ii);var ai=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={name:{configurable:!0}};return r.name.get=function(){return"jsonql-event-emitter"},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){void 0===e&&(e={}),t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={$done:{configurable:!0}};return e.prototype.logger=function(){},e.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.logger("($on)","call run on "+t),n.run(e,a,r||u),i+=n.addToNormalStore(t,"on",e,r||u)})),i},e.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.logger("($once)","call run for "+t),this.run(e,i,r||a),this.$off(t)},e.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(o){var i=o[0],a=o[1],u=o[2];if(u&&"only"!==u)throw new Error("You are trying to register an event already been taken by other type: "+u);n.logger("($only)","call run for "+t),n.run(e,i,r||a)})));return o},e.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.logger("($onlyOnce)","call run for "+t),this.run(e,a,r||u),this.$off(t)}return n},e.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 this.logger("($replace)",t,e),Reflect.apply(o,this,[t,e,r])}throw new Error(n+" is not supported!")},e.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)","normalStore",i),i.has(t)){var a=this.$queue(t,e,r,n);if(this.logger("($trigger)",t,"found; add to queue: ",a),!0===a)return this.logger("($trigger)",t,"not executed. Exit now."),!1;for(var u=Array.from(i.get(t)),c=u.length,s=!1,l=0;l0;)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]},e.prototype.checkContentExist=function(t,e){return!!Array.from(e).filter((function(e){return e[0]===t[0]})).length},e.prototype.checkTypeInStore=function(t,e){this.validateEvt(t,e);var r=this.$get(t,!0);return!1===r||!r.filter((function(t){var r=t[3];return e!==r})).length},e.prototype.checkTypeInLazyStore=function(t,e){this.validateEvt(t,e);var r=this.lazyStore.get(t);return this.logger("(checkTypeInLazyStore)",r),!!r&&!!Array.from(r).filter((function(t){return t[2]!==e})).length},e.prototype.addToNormalStore=function(t,e,r,n){if(void 0===n&&(n=null),this.logger("(addToNormalStore)",t,e,"try to add to normal store"),this.checkTypeInStore(t,e)){this.logger("(addToNormalStore)",e+" can add to "+t+" normal 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},e.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},e.prototype.toArray=function(t){return Array.isArray(t)?t:[t]},r.normalStore.set=function(t){ri.set(this,t)},r.normalStore.get=function(){return ri.get(this)},r.lazyStore.set=function(t){ni.set(this,t)},r.lazyStore.get=function(){return ni.get(this)},e.prototype.hashFnToKey=function(t){return Tn(t.toString())},Object.defineProperties(e.prototype,r),e}(oi)));return function(t,e){var r;return ei((r=e.debugOn,new ai({logger:r?function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];t.unshift("[BUILTIN]"),console.log.apply(null,t)}:void 0})),t,e)}})); //# sourceMappingURL=core.js.map diff --git a/packages/http-client/dist/jsonql-client.umd.js b/packages/http-client/dist/jsonql-client.umd.js index 64382c5f430ff1cf12cba7bf066235f8dba4138c..41019c374e38bd2bab496dd24340cea8b2c0a603 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:{};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;return this.isObject(t)?(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):t},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("?")?"?":"&")+_.join("&")),a.open(r.method,t);try{a.withCredentials=!!r.withCredentials,a.timeout=r.timeout||0,"stream"!==g&&(a.responseType=g)}catch(t){}var w=r.headers["Content-Type"]||r.headers[u],j="application/x-www-form-urlencoded";for(var O in o.trim((w||"").toLowerCase())===j?e=o.formatParams(e):o.isFormData(e)||-1===["object","array"].indexOf(o.type(e))||(j="application/json;charset=utf-8",e=JSON.stringify(e)),w||y||(r.headers["Content-Type"]=j),r.headers)if("Content-Type"===O&&o.isFormData(e))delete r.headers[O];else try{a.setRequestHeader(O,r.headers[O])}catch(t){}function S(t,e,n){d(f.p,(function(){if(t){n&&(e.request=r);var o=t.call(f,e,Promise);e=void 0===o?e:o}h(e)||(e=Promise[0===n?"resolve":"reject"](e)),e.then((function(t){c(t)})).catch((function(t){p(t)}))}))}function k(t){t.engine=a,S(f.onerror,t,-1)}function E(t,e){this.message=t,this.status=e}a.onload=function(){try{var t=a.response||a.responseText;t&&r.parseJson&&-1!==(a.getResponseHeader("Content-Type")||"").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,u=a.statusText,c={data:t,headers:e,status:i,statusText:u};if(o.merge(c,a._response),i>=200&&i<300||304===i)c.engine=a,c.request=r,S(f.handler,c,0);else{var s=new E(u,i);s.response=c,k(s)}}catch(s){k(new E(s.msg,a.status))}},a.onerror=function(t){k(new E(t.msg||"Network Error",0))},a.ontimeout=function(){k(new E("timeout [ "+a.timeout+"ms ]",1))},a._options=r,setTimeout((function(){a.send(y?null:e)}),0)}(n):c(n)}),(function(t){p(t)}))}))}));return p.engine=a,p}},{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=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),a=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),u=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 403},r.name.get=function(){return"JsonqlForbiddenError"},Object.defineProperties(e,r),e}(Error),c=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),s=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),f=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),l=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),p=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),h=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),d=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),v=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),g="application/vnd.api+json",y={Accept:g,"Content-Type":[g,"charset=utf-8"].join(";")},b=["POST","PUT"],m={desc:"y"},_=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),w=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),j=Object.freeze({__proto__:null,Jsonql406Error:i,Jsonql500Error:a,JsonqlForbiddenError:u,JsonqlAuthorisationError:c,JsonqlContractAuthError:s,JsonqlResolverAppError:f,JsonqlResolverNotFoundError:l,JsonqlEnumError:p,JsonqlTypeError:h,JsonqlCheckerError:d,JsonqlValidationError:v,JsonqlError:_,JsonqlServerError:w}),O=_;function S(t){if(function(t,e){return!!Object.keys(t).filter((function(t){return e===t})).length}(t,"error")){var e=t.error,r=e.className,n=e.name,o=r||n,i=e.message||"No message",a=e.detail||e;if(o&&j[o])throw new j[r](i,a);throw new O(i,a)}return t}function k(t){if(Array.isArray(t))throw new v("",t);var e=t.message||"No message",r=t.detail||t;switch(!0){case t instanceof i:throw new i(e,r);case t instanceof a:throw new a(e,r);case t instanceof u:throw new u(e,r);case t instanceof c:throw new c(e,r);case t instanceof s:throw new s(e,r);case t instanceof f:throw new f(e,r);case t instanceof l:throw new l(e,r);case t instanceof p:throw new p(e,r);case t instanceof h:throw new h(e,r);case t instanceof d:throw new d(e,r);case t instanceof v:throw new v(e,r);case t instanceof w:throw new w(e,r);default:throw new _(e,r)}}var E="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},T="object"==typeof E&&E&&E.Object===Object&&E,A="object"==typeof self&&self&&self.Object===Object&&self,x=T||A||Function("return this")(),P=x.Symbol;function q(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r=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);++n-1;);return r}(n,o),function(t,e){for(var r=t.length;r--&&G(e,t[r],0)>-1;);return r}(n,o)+1).join("")}var st=function(t){return!!C(t)||null!=t&&""!==ct(t)};function ft(t){return function(t){return"number"==typeof t||J(t)&&"[object Number]"==F(t)}(t)&&t!=+t}function lt(t){return"string"==typeof t||!C(t)&&J(t)&&"[object String]"==F(t)}var pt=function(t){return!lt(t)&&!ft(parseFloat(t))},ht=function(t){return""!==ct(t)&<(t)},dt=function(t){return null!=t&&"boolean"==typeof t},vt=function(t,e){return void 0===e&&(e=!0),void 0!==t&&""!==t&&""!==ct(t)&&(!1===e||!0===e&&null!==t)},gt=function(t){switch(t){case"number":return pt;case"string":return ht;case"boolean":return dt;default:return vt}},yt=function(t,e){return void 0===e&&(e=""),!!C(t)&&(""===e||""===ct(e)||!(t.filter((function(t){return!gt(e)(t)})).length>0))},bt=function(t){if(t.indexOf("array.<")>-1&&t.indexOf(">")>-1){var e=t.replace("array.<","").replace(">","");return e.indexOf("|")?e.split("|"):[e]}return!1},mt=function(t,e){var r=t.arg;return e.length>1?!r.filter((function(t){return!(e.length>e.filter((function(e){return!gt(e)(t)})).length)})).length:e.length>e.filter((function(t){return!yt(r,t)})).length};function _t(t,e){return function(r){return t(e(r))}}var wt=_t(Object.getPrototypeOf,Object),jt=Function.prototype,Ot=Object.prototype,St=jt.toString,kt=Ot.hasOwnProperty,Et=St.call(Object);function Tt(t){if(!J(t)||"[object Object]"!=F(t))return!1;var e=wt(t);if(null===e)return!0;var r=kt.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&St.call(r)==Et}var At,xt=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),a=i.length;a--;){var u=i[At?a:++n];if(!1===e(o[u],u,o))break}return t};function Pt(t){return J(t)&&"[object Arguments]"==F(t)}var qt=Object.prototype,Ct=qt.hasOwnProperty,$t=qt.propertyIsEnumerable,zt=Pt(function(){return arguments}())?Pt:function(t){return J(t)&&Ct.call(t,"callee")&&!$t.call(t,"callee")};var Nt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Rt=Nt&&"object"==typeof module&&module&&!module.nodeType&&module,Mt=Rt&&Rt.exports===Nt?x.Buffer:void 0,It=(Mt?Mt.isBuffer:void 0)||function(){return!1},Ft=/^(?:0|[1-9]\d*)$/;function Jt(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&Ft.test(t))&&t>-1&&t%1==0&&t-1&&t%1==0&&t<=9007199254740991}var Dt={};Dt["[object Float32Array]"]=Dt["[object Float64Array]"]=Dt["[object Int8Array]"]=Dt["[object Int16Array]"]=Dt["[object Int32Array]"]=Dt["[object Uint8Array]"]=Dt["[object Uint8ClampedArray]"]=Dt["[object Uint16Array]"]=Dt["[object Uint32Array]"]=!0,Dt["[object Arguments]"]=Dt["[object Array]"]=Dt["[object ArrayBuffer]"]=Dt["[object Boolean]"]=Dt["[object DataView]"]=Dt["[object Date]"]=Dt["[object Error]"]=Dt["[object Function]"]=Dt["[object Map]"]=Dt["[object Number]"]=Dt["[object Object]"]=Dt["[object RegExp]"]=Dt["[object Set]"]=Dt["[object String]"]=Dt["[object WeakMap]"]=!1;var Lt,Ht="object"==typeof exports&&exports&&!exports.nodeType&&exports,Bt=Ht&&"object"==typeof module&&module&&!module.nodeType&&module,Kt=Bt&&Bt.exports===Ht&&T.process,Gt=function(){try{var t=Bt&&Bt.require&&Bt.require("util").types;return t||Kt&&Kt.binding&&Kt.binding("util")}catch(t){}}(),Vt=Gt&&Gt.isTypedArray,Wt=Vt?(Lt=Vt,function(t){return Lt(t)}):function(t){return J(t)&&Ut(t.length)&&!!Dt[F(t)]},Yt=Object.prototype.hasOwnProperty;function Qt(t,e){var r=C(t),n=!r&&zt(t),o=!r&&!n&&It(t),i=!r&&!n&&!o&&Wt(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r-1},fe.prototype.set=function(t,e){var r=this.__data__,n=ce(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var le,pe=x["__core-js_shared__"],he=(le=/[^.]+$/.exec(pe&&pe.keys&&pe.keys.IE_PROTO||""))?"Symbol(src)_1."+le:"";var de=Function.prototype.toString;function ve(t){if(null!=t){try{return de.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var ge=/^\[object .+?Constructor\]$/,ye=Function.prototype,be=Object.prototype,me=ye.toString,_e=be.hasOwnProperty,we=RegExp("^"+me.call(_e).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function je(t){return!(!re(t)||function(t){return!!he&&he in t}(t))&&(ne(t)?we:ge).test(ve(t))}function Oe(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return je(r)?r:void 0}var Se=Oe(x,"Map"),ke=Oe(Object,"create");var Ee=Object.prototype.hasOwnProperty;var Te=Object.prototype.hasOwnProperty;function Ae(t){var e=-1,r=null==t?0:t.length;for(this.clear();++eu))return!1;var s=i.get(t);if(s&&i.get(e))return s==e;var f=-1,l=!0,p=2&r?new Ce:void 0;for(i.set(t,e),i.set(e,t);++fe.type.filter((function(t){var e;return void 0===r||(!1!==(e=bt(t))?!mt({arg:r},e):!gt(t)(r))})).length)})).length}return!1},Ar=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),!Reflect.apply(Tr,null,a);case"array"===t:return!yt(e.arg);case!1!==(r=bt(t)):return!mt(e,r);default:return!gt(t)(e.arg)}},xr=function(t,e){return void 0!==t?t:!0===e.optional&&void 0!==e.defaultvalue?e.defaultvalue:null},Pr=function(t,e,r){var n;void 0===r&&(r=!1);var o=function(t,e){if(!yt(e))throw new _("params is not an array! Did something gone wrong when you generate the contract.json?");if(0===e.length)return[];if(!yt(t))throw new _("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:var n=e.length,o=["any"];return t.map((function(t,r){var i=r>=n||!!e[r].optional,a=e[r]||{type:o,name:"_"+r};return{arg:i?xr(t,a):t,index:r,param:a,optional:i}}));default:throw new _("Could not understand your arguments and parameter structure!",{args:t,params:e})}}(t,e),i=o.filter((function(t){return!0===t.optional||!0===t.param.optional?function(t){var e=t.arg,r=t.param;return!!st(e)&&!(r.type.length>r.type.filter((function(e){return Ar(e,t)})).length)}(t):!(t.param.type.length>t.param.type.filter((function(e){return Ar(e,t)})).length)}));return r?((n={}).error=i,n.data=o.map((function(t){return t.arg})),n):i},qr=function(){try{var t=Oe(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();function Cr(t,e,r){"__proto__"==e&&qr?qr(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}function $r(t,e,r){(void 0===r||ue(t[e],r))&&(void 0!==r||e in t)||Cr(t,e,r)}var zr="object"==typeof exports&&exports&&!exports.nodeType&&exports,Nr=zr&&"object"==typeof module&&module&&!module.nodeType&&module,Rr=Nr&&Nr.exports===zr?x.Buffer:void 0,Mr=Rr?Rr.allocUnsafe:void 0;function Ir(t,e){var r,n,o=e?(r=t.buffer,n=new r.constructor(r.byteLength),new Ne(n).set(new Ne(r)),n):t.buffer;return new t.constructor(o,t.byteOffset,t.length)}var Fr=Object.create,Jr=function(){function t(){}return function(e){if(!re(e))return{};if(Fr)return Fr(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();function Ur(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}var Dr=Object.prototype.hasOwnProperty;function Lr(t,e,r){var n=t[e];Dr.call(t,e)&&ue(n,r)&&(void 0!==r||e in t)||Cr(t,e,r)}var Hr=Object.prototype.hasOwnProperty;function Br(t){if(!re(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=Zt(t),r=[];for(var n in t)("constructor"!=n||!e&&Hr.call(t,n))&&r.push(n);return r}function Kr(t){return oe(t)?Qt(t,!0):Br(t)}function Gr(t){return function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Xr);function en(t,e){return tn(function(t,e,r){return e=Qr(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=Qr(n.length-e,0),a=Array(i);++o1?e[n-1]:void 0,i=n>2?e[2]:void 0;for(o=rn.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!re(r))return!1;var n=typeof e;return!!("number"==n?oe(r)&&Jt(e,r.length):"string"==n&&e in r)&&ue(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r0;)e[r]=arguments[r+1];return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return e.reduce((function(t,e){return Reflect.apply(e,null,jn(t))}),Reflect.apply(t,null,r))}};function kn(t,e){var r=Object.getOwnPropertyDescriptor(t,e);return void 0!==r&&r.value?r.value:r}function En(t,e,r,n){void 0===n&&(n=!1);var o=kn(t,e);return!1===n&&void 0!==o?t:(Object.defineProperty(t,e,{value:r,writable:n}),t)}var Tn=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 mn(r,i).then((function(){return t.query.apply(t,[e,a,u])})).catch(k)}},An=function(t,e,r,n,o){var i={},a=function(t){i=En(i,t,(function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var i=o.query[t].params,a=i.map((function(t,e){return r[e]})),u={};return mn(a,i).then((function(){return e.query.apply(e,[t,a,u])})).catch(k)}))};for(var u in o.query)a(u);return t.query=i,t.helloWorld=i.helloWorld,[t,e,r,n,o]},xn=function(t,e,r,n,o){var i={},a=function(t){i=En(i,t,(function(r,n,i){void 0===i&&(i={});var a=[r,n],u=o.mutation[t].params;return mn(a,u).then((function(){return e.mutation.apply(e,[t,r,n,i])})).catch(k)}))};for(var u in o.mutation)a(u);return t.mutation=i,[t,e,r,n,o]},Pn=function(t,e,r,n,o){if(n.enableAuth&&o.auth){var i={},a=n.loginHandlerName,u=n.logoutHandlerName;o.auth[a]&&(i[a]=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var i=Tn(e,a,0,o);return i.apply(null,t).then(e.postLoginAction.bind(e)).then((function(t){var e=t.token,n=t.userdata;return r.$trigger("login",e),n}))}),o.auth[u]?i[u]=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var i=Tn(e,u,0,o);return i.apply(null,t).then(e.postLogoutAction.bind(e)).then((function(t){return r.$trigger("logout",t),t}))}:i[u]=function(t){void 0===t&&(t=null),e.postLogoutAction("continue",t),r.$trigger("logout","continue")},t.auth=i}return t};var qn=function(t,e,r,n){var o=function(t,e,r,n){var o=[An,xn,Pn];return Reflect.apply(Sn,null,o)({},t,e,r,n)}(t,n,e,r);return e.exposeStore,o=function(t,e,r,n,o){return t.eventEmitter=r,t.contract=o,t.version="1.5.17",t.getLogger=function(t){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return Reflect.apply(e.log,e,[t].concat(r))}},n.enableAuth&&(t.userdata=function(){return e.jsonqlUserdata},t.getToken=function(t){return void 0===t&&(t=!1),e.rawAuthToken(t)},t.profileIndex=function(t){if(void 0===t&&(t=!1),!1===t)return e.profileIndex;e.profileIndex=t},t.getProfiles=function(t){return void 0===t&&(t=!1),e.getProfiles(t)}),t}(o,t,n,e,r)};function Cn(t){return!!function(t){return Tt(t)&&(On(t,"query")||On(t,"mutation")||On(t,"socket"))}(t)&&t}function $n(t){return function(t){return t.split("").reduce((function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t}),0)}(t)+""}function zn(t){this.message=t}zn.prototype=new Error,zn.prototype.name="InvalidCharacterError";var Nn="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new zn("'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="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return a};var Rn=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(Nn(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 Nn(e)}};function Mn(t){this.message=t}Mn.prototype=new Error,Mn.prototype.name="InvalidTokenError";var In=function(t,e){if("string"!=typeof t)throw new Mn("Invalid token specified");var r=!0===(e=e||{}).header?0:1;try{return JSON.parse(Rn(t.split(".")[r]))}catch(t){throw new Mn("Invalid token specified: "+t.message)}};In.InvalidTokenError=Mn;var Fn,Jn,Un,Dn,Ln,Hn,Bn,Kn,Gn;function Vn(t){var e=t.iat||function(t){void 0===t&&(t=!1);var e=Date.now();return t?Math.floor(e/1e3):e}(!0);if(t.exp&&e>=t.exp){var r=new Date(t.exp).toISOString();throw new _("Token has expired on "+r,t)}return t}function Wn(t){if(ht(t))return Vn(In(t));throw new _("Token must be a string!")}_n("HS256",["string"]),_n(!1,["boolean","number","string"],((Fn={}).alias="exp",Fn.optional=!0,Fn)),_n(!1,["boolean","number","string"],((Jn={}).alias="nbf",Jn.optional=!0,Jn)),_n(!1,["boolean","string"],((Un={}).alias="iss",Un.optional=!0,Un)),_n(!1,["boolean","string"],((Dn={}).alias="sub",Dn.optional=!0,Dn)),_n(!1,["boolean","string"],((Ln={}).alias="iss",Ln.optional=!0,Ln)),_n(!1,["boolean"],((Hn={}).optional=!0,Hn)),_n(!1,["boolean","string"],((Bn={}).optional=!0,Bn)),_n(!1,["boolean","string"],((Kn={}).optional=!0,Kn)),_n(!1,["boolean"],((Gn={}).optional=!0,Gn));var Yn=function(t){void 0===t&&(t=!1);var e=Date.now();return t?Math.floor(e/1e3):e};function Qn(t,e){var r;return(r={})[t]=e,r.TS=[Yn()],r}var Xn=function(t){return On(t,"data")&&!On(t,"error")?t.data:t},Zn=Object.assign?Object.assign:function(t,e,r,n){for(var o=arguments,i=1;i=0;e--){var r=jo().key(e);t(Oo(r),r)}},remove:function(t){return jo().removeItem(t)},clearAll:function(){return jo().clear()}};function jo(){return _o.localStorage}function Oo(t){return jo().getItem(t)}var So=no.trim,ko={name:"cookieStorage",read:function(t){if(!t||!xo(t))return null;var e="(?:^|.*;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(Eo.cookie.replace(new RegExp(e),"$1"))},write:function(t,e){if(!t)return;Eo.cookie=escape(t)+"="+escape(e)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"},each:To,remove:Ao,clearAll:function(){To((function(t,e){Ao(e)}))}},Eo=no.Global.document;function To(t){for(var e=Eo.cookie.split(/; ?/g),r=e.length-1;r>=0;r--)if(So(e[r])){var n=e[r].split("="),o=unescape(n[0]);t(unescape(n[1]),o)}}function Ao(t){t&&xo(t)&&(Eo.cookie=escape(t)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function xo(t){return new RegExp("(?:^|;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(Eo.cookie)}var Po=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 qo=no.bind,Co=no.each,$o=no.create,zo=no.slice,No=function(){var t=$o(Ro,{_id:0,_subSignals:{},_subCallbacks:{}});return{watch:function(e,r,n){return t.on(r,qo(this,n))},unwatch:function(e,r){t.off(r)},once:function(e,r,n){t.once(r,qo(this,n))},set:function(e,r,n){var o=this.get(r);e(),t.fire(r,n,o)},remove:function(e,r){var n=this.get(r);e(),t.fire(r,void 0,n)},clearAll:function(e){var r={};this.each((function(t,e){r[e]=t})),e(),Co(r,(function(e,r){t.fire(r,void 0,e)}))}}};var Ro={_id:null,_subCallbacks:null,_subSignals:null,on:function(t,e){return this._subCallbacks[t]||(this._subCallbacks[t]={}),this._id+=1,this._subCallbacks[t][this._id]=e,this._subSignals[this._id]=t,this._id},off:function(t){var e=this._subSignals[t];delete this._subCallbacks[e][t],delete this._subSignals[t]},once:function(t,e){var r=this.on(t,qo(this,(function(){e.apply(this,arguments),this.off(r)})))},fire:function(t){var e=zo(arguments,1);Co(this._subCallbacks[t],(function(t){t.apply(this,e)}))}},Mo=e((function(t){var e=function(){var t=String.fromCharCode,e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",n={};function o(t,e){if(!n[t]){n[t]={};for(var r=0;r>>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)})),Io=function(){return{get:function(t,e){var r=t(e);if(!r)return r;var n=Mo.decompress(r);return null==n?r:this._deserialize(n)},set:function(t,e,r){var n=Mo.compress(this._serialize(r));t(e,n)}}};var Fo=[wo,ko],Jo=[Po,No,Io],Uo=yo.createStore(Fo,Jo),Do=no.Global;function Lo(){return Do.sessionStorage}function Ho(t){return Lo().getItem(t)}var Bo=[{name:"sessionStorage",read:Ho,write:function(t,e){return Lo().setItem(t,e)},each:function(t){for(var e=Lo().length-1;e>=0;e--){var r=Lo().key(e);t(Ho(r),r)}},remove:function(t){return Lo().removeItem(t)},clearAll:function(){return Lo().clear()}},ko],Ko=[Po,Io],Go=yo.createStore(Bo,Ko),Vo=Uo,Wo=Go,Yo=function(t){this.opts=t,this.instanceKey=$n(this.opts.hostname),this.localStore=Vo,this.sessionStore=Wo},Qo={lset:{configurable:!0},lget:{configurable:!0},sset:{configurable:!0},sget:{configurable:!0}};Yo.prototype.__setMethod=function(t,e){var r,n=this[t],o=this.__getMethod(t),i=this.opts.storageKey,a=this.instanceKey;n.set(i,((r={})[a]=o?nn({},o,e):e,r))},Yo.prototype.__getMethod=function(t){var e=this[t].get(this.opts.storageKey);return!!e&&e[this.instanceKey]},Yo.prototype.__delMethod=function(t,e){var r=this.__getMethod(t);if(r){var n={};for(var o in r)o!==e&&(n[o]=r[o]);this.__setMethod(t,n)}},Yo.prototype.__clearMethod=function(t){var e=this.opts.storageKey,r=this[t],n=r.get(e);if(n){var o={};for(var i in n)i!==this.instanceKey&&(o[i]=n[i]);r.set(e,o)}},Qo.lset.set=function(t){return this.__setMethod("localStore",t)},Qo.lget.get=function(){return this.__getMethod("localStore")},Yo.prototype.ldel=function(t){return this.__delMethod("localStore",t)},Yo.prototype.lclear=function(){return this.__clearMethod("localStore")},Qo.sset.set=function(t){return this.__setMethod("sessionStore",t)},Qo.sget.get=function(){return this.__getMethod("sessionStore")},Yo.prototype.sdel=function(t){return this.__delMethod("sessionStore",t)},Yo.prototype.sclear=function(){return this.__clearMethod("sessionStore")},Object.defineProperties(Yo.prototype,Qo);var Xo=b[0],Zo=b[1],ti=function(t){function e(e,r){t.call(this,r),this.httpEngine=e,this.reqInterceptor(),this.resInterceptor()}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={jsonqlEndpoint:{configurable:!0}};return r.jsonqlEndpoint.get=function(){return[this.opts.hostname||"",this.opts.jsonqlPath].join("/")},e.prototype.log=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(!0===this.opts.debugOn){var r=["info","error"],n="__error__"===t[0]?1:0;t.splice(0,n),Reflect.apply(console[r[n]],console,t)}},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),e.enableAuth&&(this.setDecoder=Wn),this.__userdata__=null}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={profileIndex:{configurable:!0},setDecoder:{configurable:!0},saveProfile:{configurable:!0},readProfile:{configurable:!0},jsonqlToken:{configurable:!0},jsonqlUserdata:{configurable:!0}};return e.prototype.decoder=function(t){return t},r.profileIndex.set=function(t){var e;if(bn(t))return this.prof_idx=t,void(this.opts.persistToken&&(this.lset=((e={}).prof_idx=t,e)));throw new v("profileIndex","Expect idx to be number but got "+typeof t)},r.profileIndex.get=function(){var t="prof_idx";if(this.opts.persistToken){var e=this.lget;if(e[t])return e[t]}return this[t]?this[t]:0},e.prototype.rawAuthToken=function(t){return void 0===t&&(t=!1),!1!==t&&(this.profileIndex=t),this.jsonqlToken},r.setDecoder.set=function(t){"function"==typeof t&&(this.decoder=t)},r.saveProfile.set=function(t){this.opts.persistToken?this.lset=t:this.sset=t},r.readProfile.get=function(){return this.opts.persistToken?this.lget:this.sget},r.jsonqlToken.set=function(t){var e,r=this.readProfile,n="jsonqlcredential",o=r&&r[n]?r[n]:[];o.push(t),this.saveProfile=((e={})[n]=o,e),this.__userdata__=this.decoder(t),this.jsonqlUserdata=this.__userdata__},r.jsonqlToken.get=function(){var t=this.readProfile,e="jsonqlcredential";return!(!t||!t[e])&&(this.log("-- jsonqlToken --",t[e],this.profileIndex,t[e][this.profileIndex]),t[e][this.profileIndex])},r.jsonqlUserdata.set=function(t){var e;this.sset=((e={}).userdata=t,e)},r.jsonqlUserdata.get=function(){var t=this.sget;return!!t&&t.userdata},e.prototype.getAuthHeader=function(){var t,e=this.jsonqlToken;return e?((t={})[this.opts.AUTH_HEADER]="Bearer "+e,t):{}},e.prototype.getProfiles=function(t){void 0===t&&(t=!1);var e=this.readProfile,r="jsonqlcredential";return!(!e||!e[r])&&(!1!==t&&bn(t)?e[r][t]||!1:e[r].map(this.decoder.bind(this)))},e.prototype.postLoginAction=function(t){return this.jsonqlToken=t,{token:t,userdata:this.__userdata__}},e.prototype.postLogoutAction=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];console.info("postLogoutAction",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();return this.log("getContract first call",t),t?Promise.resolve(t):this.getRemoteContract().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){var e;if(!Cn(t))throw new v("Contract is malformed!");return this.lset=((e={}).contract=t,e),this.log("storeContract return result",t),t},e.prototype.readContract=function(){var t=Cn(this.opts.contract);if(!1!==t)return t;var e=this.lget;return!!e&&e.contract},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),this.extraHeader={},this.extraParams={}}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={headers:{configurable:!0}};return r.headers.set=function(t){this.extraHeader=t},e.prototype.request=function(t,e,r){var n;void 0===e&&(e={}),void 0===r&&(r={}),this.headers=r;var o=nn({},{_cb:Yn()},this.extraParams);if(this.opts.enableJsonp){var i=function(t){return Object.keys(t)[0]}(t);o=nn({},o,((n={}).jsonqlJsonpCallback=i,n)),t=t[i]}var a=nn({},{method:Xo,params:o},e);return this.log("request params",a,this.jsonqlEndpoint),this.httpEngine.request(this.jsonqlEndpoint,t,a)},e.prototype.reqInterceptor=function(){var t=this;this.httpEngine.interceptors.request.use((function(e){var r=t.getHeaders();for(var n in t.log("request interceptor call",r),r)e.headers[n]=r[n];return e}))},e.prototype.processJsonp=function(t){return Xn(t)},e.prototype.resInterceptor=function(){var t=this,e=this,r=e.opts.enableJsonp;this.httpEngine.interceptors.response.use((function(n){t.log("response interceptor call",n),e.cleanUp();var o=yn(n.data)?JSON.parse(n.data):n.data;return r?e.processJsonp(o):Xn(o)}),(function(r){throw e.cleanUp(),t.log("__error__",r),new w("Server side error",r)}))},e.prototype.getHeaders=function(){return this.opts.enableAuth?nn({},y,this.getAuthHeader(),this.extraHeader):nn({},y,this.extraHeader)},e.prototype.cleanUp=function(){this.extraHeader={},this.extraParams={}},e.prototype.getRemoteContract=function(){var t=this;return this.opts.showContractDesc&&(this.extraParams=nn({},this.extraParams,m)),this.request({},{method:"GET"},this.contractHeader).then(S).then((function(e){return t.log("get contract result",e),e.cache&&e.contract?e.contract:e})).catch((function(e){throw t.log("__error__","getRemoteContract err",e),new w("getRemoteContract",e)}))},e.prototype.query=function(t,e){return void 0===e&&(e=[]),this.request(function(t,e,r){if(void 0===e&&(e=[]),void 0===r&&(r=!1),lt(t)&&C(e)){var n=function(t){var e;return(e={}).args=t,e}(e);return!0===r?n:Qn(t,n)}throw new v("[createQuery] expect resolverName to be string and args to be array!",{resolverName:t,args:e})}(t,e)).then(S)},e.prototype.mutation=function(t,e,r){return void 0===e&&(e={}),void 0===r&&(r={}),this.request(function(t,e,r,n){void 0===r&&(r={}),void 0===n&&(n=!1);var o={};if(o.payload=e,o.condition=r,!0===n)return o;if(lt(t))return Qn(t,o);throw new v("[createMutation] expect resolverName to be string!",{resolverName:t,payload:e,condition:r})}(t,e,r),{method:Zo}).then(S)},Object.defineProperties(e.prototype,r),e}(Yo)))),ei={contract:!1,MUTATION_ARGS:["name","payload","conditions"],CONTENT_TYPE:g,BEARER:"Bearer",AUTH_HEADER:"Authorization"},ri={hostname:_n(function(){try{return[window.location.protocol,window.location.host].join("//")}catch(t){return null}}(),["string"]),jsonqlPath:_n("jsonql",["string"]),loginHandlerName:_n("login",["string"]),logoutHandlerName:_n("logout",["string"]),enableJsonp:_n(!1,["boolean"]),enableAuth:_n(!1,["boolean"]),useJwt:_n(!0,["boolean"]),persistToken:_n(!1,["boolean","number"]),useLocalstorage:_n(!0,["boolean"]),storageKey:_n("jsonqlstore",["string"]),authKey:_n("jsonqlauthkey",["string"]),contractExpired:_n(0,["number"]),keepContract:_n(!0,["boolean"]),exposeContract:_n(!1,["boolean"]),exposeStore:_n(!1,["boolean"]),showContractDesc:_n(!1,["boolean"]),contractKey:_n(!1,["boolean"]),contractKeyName:_n("X-JSONQL-CV-KEY",["string"]),enableTimeout:_n(!1,["boolean"]),timeout:_n(5e3,["number"]),returnInstance:_n(!1,["boolean"]),allowReturnRawToken:_n(!1,["boolean"]),debugOn:_n(!1,["boolean"])};function ni(t,e){for(var r=[],n=arguments.length-2;n-- >0;)r[n]=arguments[n+2];var o=function(t){return En(t,"__checked__",Yn())};r.push(o);var i=Reflect.apply(Sn,null,r);return function(r){return void 0===r&&(r={}),i(r,t,e)}}function oi(t){var e=function(t,e){for(var r=[],n=arguments.length-2;n-- >0;)r[n]=arguments[n+2];return function(n){var o;if(void 0===n&&(n={}),kn(n,"__checked__")){var i=1;return n.__passed__&&(i=++n.__passed__,delete n.__passed__),Promise.resolve(Object.assign(((o={}).__passed__=i,o),n,e))}var a=Reflect.apply(ni,null,[t,e].concat(r));return Promise.resolve(a(n))}}(ri,ei,wn),r=t.contract;return e(t).then((function(t){return t.contract=r,t}))}function ii(t,e,r){return void 0===r&&(r={}),oi(r).then((function(t){return{baseClient:new ti(e,t),opts:t}})).then((function(e){var r,n,o=e.baseClient,i=e.opts;return(r=o,n=i.contract,void 0===n&&(n={}),Cn(n)?Promise.resolve(n):r.getContract()).then((function(e){return qn(o,i,e,t)}))}))}var ai=new WeakMap,ui=new WeakMap,ci=function(){this.__suspend__=null,this.queueStore=new Set},si={$suspend:{configurable:!0},$queues:{configurable:!0}};si.$suspend.set=function(t){var e=this;if("boolean"!=typeof t)throw new Error("$suspend only accept Boolean value!");var r=this.__suspend__;this.__suspend__=t,this.logger("($suspend)","Change from "+r+" --\x3e "+t),!0===r&&!1===t&&setTimeout((function(){e.release()}),1)},ci.prototype.$queue=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return!0===this.__suspend__&&(this.logger("($queue)","added to $queue",t),this.queueStore.add(t)),this.__suspend__},si.$queues.get=function(){var t=this.queueStore.size;return this.logger("($queues)","size: "+t),t>0?Array.from(this.queueStore):[]},ci.prototype.release=function(){var t=this,e=this.queueStore.size;if(this.logger("(release)","Release was called "+e),e>0){var r=Array.from(this.queueStore);this.queueStore.clear(),this.logger("queue",r),r.forEach((function(e){t.logger(e),Reflect.apply(t.$trigger,t,e)})),this.logger("Release size "+this.queueStore.size)}},Object.defineProperties(ci.prototype,si);var fi=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={name:{configurable:!0}};return r.name.get=function(){return"jsonql-event-emitter"},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){void 0===e&&(e={}),t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={$done:{configurable:!0}};return e.prototype.logger=function(){},e.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.logger("($on)","call run on "+t),n.run(e,a,r||u),i+=n.addToNormalStore(t,"on",e,r||u)})),i},e.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.logger("($once)","call run for "+t),this.run(e,i,r||a),this.$off(t)},e.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(o){var i=o[0],a=o[1],u=o[2];if(u&&"only"!==u)throw new Error("You are trying to register an event already been taken by other type: "+u);n.logger("($only)","call run for "+t),n.run(e,i,r||a)})));return o},e.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.logger("($onlyOnce)","call run for "+t),this.run(e,a,r||u),this.$off(t)}return n},e.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 this.logger("($replace)",t,e),Reflect.apply(o,this,[t,e,r])}throw new Error(n+" is not supported!")},e.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)","normalStore",i),i.has(t)){var a=this.$queue(t,e,r,n);if(this.logger("($trigger)",t,"found; add to queue: ",a),!0===a)return this.logger("($trigger)",t,"not executed. Exit now."),!1;for(var u=Array.from(i.get(t)),c=u.length,s=!1,f=0;f0;)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]},e.prototype.checkContentExist=function(t,e){return!!Array.from(e).filter((function(e){return e[0]===t[0]})).length},e.prototype.checkTypeInStore=function(t,e){this.validateEvt(t,e);var r=this.$get(t,!0);return!1===r||!r.filter((function(t){var r=t[3];return e!==r})).length},e.prototype.checkTypeInLazyStore=function(t,e){this.validateEvt(t,e);var r=this.lazyStore.get(t);return this.logger("(checkTypeInLazyStore)",r),!!r&&!!Array.from(r).filter((function(t){return t[2]!==e})).length},e.prototype.addToNormalStore=function(t,e,r,n){if(void 0===n&&(n=null),this.logger("(addToNormalStore)",t,e,"try to add to normal store"),this.checkTypeInStore(t,e)){this.logger("(addToNormalStore)",e+" can add to "+t+" normal 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},e.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},e.prototype.toArray=function(t){return Array.isArray(t)?t:[t]},r.normalStore.set=function(t){ai.set(this,t)},r.normalStore.get=function(){return ai.get(this)},r.lazyStore.set=function(t){ui.set(this,t)},r.lazyStore.get=function(){return ui.get(this)},e.prototype.hashFnToKey=function(t){return $n(t.toString())},Object.defineProperties(e.prototype,r),e}(ci)));function li(t,e){var r;return ii((r=e.debugOn,new fi({logger:r?function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];t.unshift("[BUILTIN]"),console.log.apply(null,t)}:void 0})),t,e)}return function(t){return void 0===t&&(t={}),li(new o,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:{};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;return this.isObject(t)?(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):t},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("?")?"?":"&")+_.join("&")),a.open(r.method,t);try{a.withCredentials=!!r.withCredentials,a.timeout=r.timeout||0,"stream"!==g&&(a.responseType=g)}catch(t){}var w=r.headers["Content-Type"]||r.headers[u],j="application/x-www-form-urlencoded";for(var O in o.trim((w||"").toLowerCase())===j?e=o.formatParams(e):o.isFormData(e)||-1===["object","array"].indexOf(o.type(e))||(j="application/json;charset=utf-8",e=JSON.stringify(e)),w||y||(r.headers["Content-Type"]=j),r.headers)if("Content-Type"===O&&o.isFormData(e))delete r.headers[O];else try{a.setRequestHeader(O,r.headers[O])}catch(t){}function S(t,e,n){d(f.p,(function(){if(t){n&&(e.request=r);var o=t.call(f,e,Promise);e=void 0===o?e:o}h(e)||(e=Promise[0===n?"resolve":"reject"](e)),e.then((function(t){c(t)})).catch((function(t){p(t)}))}))}function k(t){t.engine=a,S(f.onerror,t,-1)}function E(t,e){this.message=t,this.status=e}a.onload=function(){try{var t=a.response||a.responseText;t&&r.parseJson&&-1!==(a.getResponseHeader("Content-Type")||"").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,u=a.statusText,c={data:t,headers:e,status:i,statusText:u};if(o.merge(c,a._response),i>=200&&i<300||304===i)c.engine=a,c.request=r,S(f.handler,c,0);else{var s=new E(u,i);s.response=c,k(s)}}catch(s){k(new E(s.msg,a.status))}},a.onerror=function(t){k(new E(t.msg||"Network Error",0))},a.ontimeout=function(){k(new E("timeout [ "+a.timeout+"ms ]",1))},a._options=r,setTimeout((function(){a.send(y?null:e)}),0)}(n):c(n)}),(function(t){p(t)}))}))}));return p.engine=a,p}},{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=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),a=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),u=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 403},r.name.get=function(){return"JsonqlForbiddenError"},Object.defineProperties(e,r),e}(Error),c=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),s=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),f=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),l=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),p=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),h=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),d=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),v=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),g="application/vnd.api+json",y={Accept:g,"Content-Type":[g,"charset=utf-8"].join(";")},b=["POST","PUT"],m={desc:"y"},_=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),w=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),j=Object.freeze({__proto__:null,Jsonql406Error:i,Jsonql500Error:a,JsonqlForbiddenError:u,JsonqlAuthorisationError:c,JsonqlContractAuthError:s,JsonqlResolverAppError:f,JsonqlResolverNotFoundError:l,JsonqlEnumError:p,JsonqlTypeError:h,JsonqlCheckerError:d,JsonqlValidationError:v,JsonqlError:_,JsonqlServerError:w}),O=_;function S(t){if(function(t,e){return!!Object.keys(t).filter((function(t){return e===t})).length}(t,"error")){var e=t.error,r=e.className,n=e.name,o=r||n,i=e.message||"No message",a=e.detail||e;if(o&&j[o])throw new j[r](i,a);throw new O(i,a)}return t}function k(t){if(Array.isArray(t))throw new v("",t);var e=t.message||"No message",r=t.detail||t;switch(!0){case t instanceof i:throw new i(e,r);case t instanceof a:throw new a(e,r);case t instanceof u:throw new u(e,r);case t instanceof c:throw new c(e,r);case t instanceof s:throw new s(e,r);case t instanceof f:throw new f(e,r);case t instanceof l:throw new l(e,r);case t instanceof p:throw new p(e,r);case t instanceof h:throw new h(e,r);case t instanceof d:throw new d(e,r);case t instanceof v:throw new v(e,r);case t instanceof w:throw new w(e,r);default:throw new _(e,r)}}var E="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},T="object"==typeof E&&E&&E.Object===Object&&E,A="object"==typeof self&&self&&self.Object===Object&&self,x=T||A||Function("return this")(),P=x.Symbol;function q(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r=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);++n-1;);return r}(n,o),function(t,e){for(var r=t.length;r--&&G(e,t[r],0)>-1;);return r}(n,o)+1).join("")}var st=function(t){return!!C(t)||null!=t&&""!==ct(t)};function ft(t){return function(t){return"number"==typeof t||J(t)&&"[object Number]"==F(t)}(t)&&t!=+t}function lt(t){return"string"==typeof t||!C(t)&&J(t)&&"[object String]"==F(t)}var pt=function(t){return!lt(t)&&!ft(parseFloat(t))},ht=function(t){return""!==ct(t)&<(t)},dt=function(t){return null!=t&&"boolean"==typeof t},vt=function(t,e){return void 0===e&&(e=!0),void 0!==t&&""!==t&&""!==ct(t)&&(!1===e||!0===e&&null!==t)},gt=function(t){switch(t){case"number":return pt;case"string":return ht;case"boolean":return dt;default:return vt}},yt=function(t,e){return void 0===e&&(e=""),!!C(t)&&(""===e||""===ct(e)||!(t.filter((function(t){return!gt(e)(t)})).length>0))},bt=function(t){if(t.indexOf("array.<")>-1&&t.indexOf(">")>-1){var e=t.replace("array.<","").replace(">","");return e.indexOf("|")?e.split("|"):[e]}return!1},mt=function(t,e){var r=t.arg;return e.length>1?!r.filter((function(t){return!(e.length>e.filter((function(e){return!gt(e)(t)})).length)})).length:e.length>e.filter((function(t){return!yt(r,t)})).length};function _t(t,e){return function(r){return t(e(r))}}var wt=_t(Object.getPrototypeOf,Object),jt=Function.prototype,Ot=Object.prototype,St=jt.toString,kt=Ot.hasOwnProperty,Et=St.call(Object);function Tt(t){if(!J(t)||"[object Object]"!=F(t))return!1;var e=wt(t);if(null===e)return!0;var r=kt.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&St.call(r)==Et}var At,xt=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),a=i.length;a--;){var u=i[At?a:++n];if(!1===e(o[u],u,o))break}return t};function Pt(t){return J(t)&&"[object Arguments]"==F(t)}var qt=Object.prototype,Ct=qt.hasOwnProperty,$t=qt.propertyIsEnumerable,zt=Pt(function(){return arguments}())?Pt:function(t){return J(t)&&Ct.call(t,"callee")&&!$t.call(t,"callee")};var Nt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Rt=Nt&&"object"==typeof module&&module&&!module.nodeType&&module,Mt=Rt&&Rt.exports===Nt?x.Buffer:void 0,It=(Mt?Mt.isBuffer:void 0)||function(){return!1},Ft=/^(?:0|[1-9]\d*)$/;function Jt(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&Ft.test(t))&&t>-1&&t%1==0&&t-1&&t%1==0&&t<=9007199254740991}var Dt={};Dt["[object Float32Array]"]=Dt["[object Float64Array]"]=Dt["[object Int8Array]"]=Dt["[object Int16Array]"]=Dt["[object Int32Array]"]=Dt["[object Uint8Array]"]=Dt["[object Uint8ClampedArray]"]=Dt["[object Uint16Array]"]=Dt["[object Uint32Array]"]=!0,Dt["[object Arguments]"]=Dt["[object Array]"]=Dt["[object ArrayBuffer]"]=Dt["[object Boolean]"]=Dt["[object DataView]"]=Dt["[object Date]"]=Dt["[object Error]"]=Dt["[object Function]"]=Dt["[object Map]"]=Dt["[object Number]"]=Dt["[object Object]"]=Dt["[object RegExp]"]=Dt["[object Set]"]=Dt["[object String]"]=Dt["[object WeakMap]"]=!1;var Lt,Ht="object"==typeof exports&&exports&&!exports.nodeType&&exports,Bt=Ht&&"object"==typeof module&&module&&!module.nodeType&&module,Kt=Bt&&Bt.exports===Ht&&T.process,Gt=function(){try{var t=Bt&&Bt.require&&Bt.require("util").types;return t||Kt&&Kt.binding&&Kt.binding("util")}catch(t){}}(),Vt=Gt&&Gt.isTypedArray,Wt=Vt?(Lt=Vt,function(t){return Lt(t)}):function(t){return J(t)&&Ut(t.length)&&!!Dt[F(t)]},Yt=Object.prototype.hasOwnProperty;function Qt(t,e){var r=C(t),n=!r&&zt(t),o=!r&&!n&&It(t),i=!r&&!n&&!o&&Wt(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r-1},fe.prototype.set=function(t,e){var r=this.__data__,n=ce(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var le,pe=x["__core-js_shared__"],he=(le=/[^.]+$/.exec(pe&&pe.keys&&pe.keys.IE_PROTO||""))?"Symbol(src)_1."+le:"";var de=Function.prototype.toString;function ve(t){if(null!=t){try{return de.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var ge=/^\[object .+?Constructor\]$/,ye=Function.prototype,be=Object.prototype,me=ye.toString,_e=be.hasOwnProperty,we=RegExp("^"+me.call(_e).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function je(t){return!(!re(t)||function(t){return!!he&&he in t}(t))&&(ne(t)?we:ge).test(ve(t))}function Oe(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return je(r)?r:void 0}var Se=Oe(x,"Map"),ke=Oe(Object,"create");var Ee=Object.prototype.hasOwnProperty;var Te=Object.prototype.hasOwnProperty;function Ae(t){var e=-1,r=null==t?0:t.length;for(this.clear();++eu))return!1;var s=i.get(t);if(s&&i.get(e))return s==e;var f=-1,l=!0,p=2&r?new Ce:void 0;for(i.set(t,e),i.set(e,t);++fe.type.filter((function(t){var e;return void 0===r||(!1!==(e=bt(t))?!mt({arg:r},e):!gt(t)(r))})).length)})).length}return!1},Ar=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),!Reflect.apply(Tr,null,a);case"array"===t:return!yt(e.arg);case!1!==(r=bt(t)):return!mt(e,r);default:return!gt(t)(e.arg)}},xr=function(t,e){return void 0!==t?t:!0===e.optional&&void 0!==e.defaultvalue?e.defaultvalue:null},Pr=function(t,e,r){var n;void 0===r&&(r=!1);var o=function(t,e){if(!yt(e))throw new _("params is not an array! Did something gone wrong when you generate the contract.json?");if(0===e.length)return[];if(!yt(t))throw new _("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:var n=e.length,o=["any"];return t.map((function(t,r){var i=r>=n||!!e[r].optional,a=e[r]||{type:o,name:"_"+r};return{arg:i?xr(t,a):t,index:r,param:a,optional:i}}));default:throw new _("Could not understand your arguments and parameter structure!",{args:t,params:e})}}(t,e),i=o.filter((function(t){return!0===t.optional||!0===t.param.optional?function(t){var e=t.arg,r=t.param;return!!st(e)&&!(r.type.length>r.type.filter((function(e){return Ar(e,t)})).length)}(t):!(t.param.type.length>t.param.type.filter((function(e){return Ar(e,t)})).length)}));return r?((n={}).error=i,n.data=o.map((function(t){return t.arg})),n):i},qr=function(){try{var t=Oe(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();function Cr(t,e,r){"__proto__"==e&&qr?qr(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}function $r(t,e,r){(void 0===r||ue(t[e],r))&&(void 0!==r||e in t)||Cr(t,e,r)}var zr="object"==typeof exports&&exports&&!exports.nodeType&&exports,Nr=zr&&"object"==typeof module&&module&&!module.nodeType&&module,Rr=Nr&&Nr.exports===zr?x.Buffer:void 0,Mr=Rr?Rr.allocUnsafe:void 0;function Ir(t,e){var r,n,o=e?(r=t.buffer,n=new r.constructor(r.byteLength),new Ne(n).set(new Ne(r)),n):t.buffer;return new t.constructor(o,t.byteOffset,t.length)}var Fr=Object.create,Jr=function(){function t(){}return function(e){if(!re(e))return{};if(Fr)return Fr(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();function Ur(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}var Dr=Object.prototype.hasOwnProperty;function Lr(t,e,r){var n=t[e];Dr.call(t,e)&&ue(n,r)&&(void 0!==r||e in t)||Cr(t,e,r)}var Hr=Object.prototype.hasOwnProperty;function Br(t){if(!re(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=Zt(t),r=[];for(var n in t)("constructor"!=n||!e&&Hr.call(t,n))&&r.push(n);return r}function Kr(t){return oe(t)?Qt(t,!0):Br(t)}function Gr(t){return function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,a=e.length;++i0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Xr);function en(t,e){return tn(function(t,e,r){return e=Qr(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=Qr(n.length-e,0),a=Array(i);++o1?e[n-1]:void 0,i=n>2?e[2]:void 0;for(o=rn.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!re(r))return!1;var n=typeof e;return!!("number"==n?oe(r)&&Jt(e,r.length):"string"==n&&e in r)&&ue(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r0;)e[r]=arguments[r+1];return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return e.reduce((function(t,e){return Reflect.apply(e,null,jn(t))}),Reflect.apply(t,null,r))}};function kn(t,e){var r=Object.getOwnPropertyDescriptor(t,e);return void 0!==r&&r.value?r.value:r}function En(t,e,r,n){void 0===n&&(n=!1);var o=kn(t,e);return!1===n&&void 0!==o?t:(Object.defineProperty(t,e,{value:r,writable:n}),t)}var Tn=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 mn(r,i).then((function(){return t.query.apply(t,[e,a,u])})).catch(k)}},An=function(t,e,r,n,o){var i={},a=function(t){i=En(i,t,(function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var i=o.query[t].params,a=i.map((function(t,e){return r[e]})),u={};return mn(a,i).then((function(){return e.query.apply(e,[t,a,u])})).catch(k)}))};for(var u in o.query)a(u);return t.query=i,t.helloWorld=i.helloWorld,[t,e,r,n,o]},xn=function(t,e,r,n,o){var i={},a=function(t){i=En(i,t,(function(r,n,i){void 0===i&&(i={});var a=[r,n],u=o.mutation[t].params;return mn(a,u).then((function(){return e.mutation.apply(e,[t,r,n,i])})).catch(k)}))};for(var u in o.mutation)a(u);return t.mutation=i,[t,e,r,n,o]},Pn=function(t,e,r,n,o){if(n.enableAuth&&o.auth){var i={},a=n.loginHandlerName,u=n.logoutHandlerName;o.auth[a]&&(i[a]=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var i=Tn(e,a,0,o);return i.apply(null,t).then(e.postLoginAction.bind(e)).then((function(t){var e=t.token,n=t.userdata;return r.$trigger("login",e),n}))}),o.auth[u]?i[u]=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];var i=Tn(e,u,0,o);return i.apply(null,t).then(e.postLogoutAction.bind(e)).then((function(t){return r.$trigger("logout",t),t}))}:i[u]=function(t){void 0===t&&(t=null),e.postLogoutAction("continue",t),r.$trigger("logout","continue")},t.auth=i}return t};var qn=function(t,e,r,n){var o=function(t,e,r,n){var o=[An,xn,Pn];return Reflect.apply(Sn,null,o)({},t,e,r,n)}(t,n,e,r);return e.exposeStore,o=function(t,e,r,n,o){return t.eventEmitter=r,t.contract=o,t.version="1.5.19",t.getLogger=function(t){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return Reflect.apply(e.log,e,[t].concat(r))}},n.enableAuth&&(t.userdata=function(){return e.jsonqlUserdata},t.getToken=function(t){return void 0===t&&(t=!1),e.rawAuthToken(t)},t.profileIndex=function(t){if(void 0===t&&(t=!1),!1===t)return e.profileIndex;e.profileIndex=t},t.getProfiles=function(t){return void 0===t&&(t=!1),e.getProfiles(t)}),t}(o,t,n,e,r)};function Cn(t){return!!function(t){return Tt(t)&&(On(t,"query")||On(t,"mutation")||On(t,"socket"))}(t)&&t}function $n(t){return function(t){return t.split("").reduce((function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t}),0)}(t)+""}function zn(t){this.message=t}zn.prototype=new Error,zn.prototype.name="InvalidCharacterError";var Nn="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new zn("'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="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return a};var Rn=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(Nn(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 Nn(e)}};function Mn(t){this.message=t}Mn.prototype=new Error,Mn.prototype.name="InvalidTokenError";var In=function(t,e){if("string"!=typeof t)throw new Mn("Invalid token specified");var r=!0===(e=e||{}).header?0:1;try{return JSON.parse(Rn(t.split(".")[r]))}catch(t){throw new Mn("Invalid token specified: "+t.message)}};In.InvalidTokenError=Mn;var Fn,Jn,Un,Dn,Ln,Hn,Bn,Kn,Gn;function Vn(t){var e=t.iat||function(t){void 0===t&&(t=!1);var e=Date.now();return t?Math.floor(e/1e3):e}(!0);if(t.exp&&e>=t.exp){var r=new Date(t.exp).toISOString();throw new _("Token has expired on "+r,t)}return t}function Wn(t){if(ht(t))return Vn(In(t));throw new _("Token must be a string!")}_n("HS256",["string"]),_n(!1,["boolean","number","string"],((Fn={}).alias="exp",Fn.optional=!0,Fn)),_n(!1,["boolean","number","string"],((Jn={}).alias="nbf",Jn.optional=!0,Jn)),_n(!1,["boolean","string"],((Un={}).alias="iss",Un.optional=!0,Un)),_n(!1,["boolean","string"],((Dn={}).alias="sub",Dn.optional=!0,Dn)),_n(!1,["boolean","string"],((Ln={}).alias="iss",Ln.optional=!0,Ln)),_n(!1,["boolean"],((Hn={}).optional=!0,Hn)),_n(!1,["boolean","string"],((Bn={}).optional=!0,Bn)),_n(!1,["boolean","string"],((Kn={}).optional=!0,Kn)),_n(!1,["boolean"],((Gn={}).optional=!0,Gn));var Yn=function(t){void 0===t&&(t=!1);var e=Date.now();return t?Math.floor(e/1e3):e};function Qn(t,e){var r;return(r={})[t]=e,r.TS=[Yn()],r}var Xn=function(t){return On(t,"data")&&!On(t,"error")?t.data:t},Zn=Object.assign?Object.assign:function(t,e,r,n){for(var o=arguments,i=1;i=0;e--){var r=jo().key(e);t(Oo(r),r)}},remove:function(t){return jo().removeItem(t)},clearAll:function(){return jo().clear()}};function jo(){return _o.localStorage}function Oo(t){return jo().getItem(t)}var So=no.trim,ko={name:"cookieStorage",read:function(t){if(!t||!xo(t))return null;var e="(?:^|.*;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";return unescape(Eo.cookie.replace(new RegExp(e),"$1"))},write:function(t,e){if(!t)return;Eo.cookie=escape(t)+"="+escape(e)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/"},each:To,remove:Ao,clearAll:function(){To((function(t,e){Ao(e)}))}},Eo=no.Global.document;function To(t){for(var e=Eo.cookie.split(/; ?/g),r=e.length-1;r>=0;r--)if(So(e[r])){var n=e[r].split("="),o=unescape(n[0]);t(unescape(n[1]),o)}}function Ao(t){t&&xo(t)&&(Eo.cookie=escape(t)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/")}function xo(t){return new RegExp("(?:^|;\\s*)"+escape(t).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(Eo.cookie)}var Po=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 qo=no.bind,Co=no.each,$o=no.create,zo=no.slice,No=function(){var t=$o(Ro,{_id:0,_subSignals:{},_subCallbacks:{}});return{watch:function(e,r,n){return t.on(r,qo(this,n))},unwatch:function(e,r){t.off(r)},once:function(e,r,n){t.once(r,qo(this,n))},set:function(e,r,n){var o=this.get(r);e(),t.fire(r,n,o)},remove:function(e,r){var n=this.get(r);e(),t.fire(r,void 0,n)},clearAll:function(e){var r={};this.each((function(t,e){r[e]=t})),e(),Co(r,(function(e,r){t.fire(r,void 0,e)}))}}};var Ro={_id:null,_subCallbacks:null,_subSignals:null,on:function(t,e){return this._subCallbacks[t]||(this._subCallbacks[t]={}),this._id+=1,this._subCallbacks[t][this._id]=e,this._subSignals[this._id]=t,this._id},off:function(t){var e=this._subSignals[t];delete this._subCallbacks[e][t],delete this._subSignals[t]},once:function(t,e){var r=this.on(t,qo(this,(function(){e.apply(this,arguments),this.off(r)})))},fire:function(t){var e=zo(arguments,1);Co(this._subCallbacks[t],(function(t){t.apply(this,e)}))}},Mo=e((function(t){var e=function(){var t=String.fromCharCode,e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",n={};function o(t,e){if(!n[t]){n[t]={};for(var r=0;r>>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)})),Io=function(){return{get:function(t,e){var r=t(e);if(!r)return r;var n=Mo.decompress(r);return null==n?r:this._deserialize(n)},set:function(t,e,r){var n=Mo.compress(this._serialize(r));t(e,n)}}};var Fo=[wo,ko],Jo=[Po,No,Io],Uo=yo.createStore(Fo,Jo),Do=no.Global;function Lo(){return Do.sessionStorage}function Ho(t){return Lo().getItem(t)}var Bo=[{name:"sessionStorage",read:Ho,write:function(t,e){return Lo().setItem(t,e)},each:function(t){for(var e=Lo().length-1;e>=0;e--){var r=Lo().key(e);t(Ho(r),r)}},remove:function(t){return Lo().removeItem(t)},clearAll:function(){return Lo().clear()}},ko],Ko=[Po,Io],Go=yo.createStore(Bo,Ko),Vo=Uo,Wo=Go,Yo=function(t){this.opts=t,this.instanceKey=$n(this.opts.hostname),this.localStore=Vo,this.sessionStore=Wo},Qo={lset:{configurable:!0},lget:{configurable:!0},sset:{configurable:!0},sget:{configurable:!0}};Yo.prototype.__setMethod=function(t,e){var r,n=this[t],o=this.__getMethod(t),i=this.opts.storageKey,a=this.instanceKey;n.set(i,((r={})[a]=o?nn({},o,e):e,r))},Yo.prototype.__getMethod=function(t){var e=this[t].get(this.opts.storageKey);return!!e&&e[this.instanceKey]},Yo.prototype.__delMethod=function(t,e){var r=this.__getMethod(t);if(r){var n={};for(var o in r)o!==e&&(n[o]=r[o]);this.__setMethod(t,n)}},Yo.prototype.__clearMethod=function(t){var e=this.opts.storageKey,r=this[t],n=r.get(e);if(n){var o={};for(var i in n)i!==this.instanceKey&&(o[i]=n[i]);r.set(e,o)}},Qo.lset.set=function(t){return this.__setMethod("localStore",t)},Qo.lget.get=function(){return this.__getMethod("localStore")},Yo.prototype.ldel=function(t){return this.__delMethod("localStore",t)},Yo.prototype.lclear=function(){return this.__clearMethod("localStore")},Qo.sset.set=function(t){return this.__setMethod("sessionStore",t)},Qo.sget.get=function(){return this.__getMethod("sessionStore")},Yo.prototype.sdel=function(t){return this.__delMethod("sessionStore",t)},Yo.prototype.sclear=function(){return this.__clearMethod("sessionStore")},Object.defineProperties(Yo.prototype,Qo);var Xo=b[0],Zo=b[1],ti=function(t){function e(e,r){t.call(this,r),this.httpEngine=e,this.reqInterceptor(),this.resInterceptor()}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={jsonqlEndpoint:{configurable:!0}};return r.jsonqlEndpoint.get=function(){return[this.opts.hostname||"",this.opts.jsonqlPath].join("/")},e.prototype.log=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(!0===this.opts.debugOn){var r=["info","error"],n="__error__"===t[0]?1:0;t.splice(0,n),Reflect.apply(console[r[n]],console,t)}},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),e.enableAuth&&(this.setDecoder=Wn),this.__userdata__=null}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={profileIndex:{configurable:!0},setDecoder:{configurable:!0},saveProfile:{configurable:!0},readProfile:{configurable:!0},jsonqlToken:{configurable:!0},jsonqlUserdata:{configurable:!0}};return e.prototype.decoder=function(t){return t},r.profileIndex.set=function(t){var e;if(bn(t))return this.prof_idx=t,void(this.opts.persistToken&&(this.lset=((e={}).prof_idx=t,e)));throw new v("profileIndex","Expect idx to be number but got "+typeof t)},r.profileIndex.get=function(){var t="prof_idx";if(this.opts.persistToken){var e=this.lget;if(e[t])return e[t]}return this[t]?this[t]:0},e.prototype.rawAuthToken=function(t){return void 0===t&&(t=!1),!1!==t&&(this.profileIndex=t),this.jsonqlToken},r.setDecoder.set=function(t){"function"==typeof t&&(this.decoder=t)},r.saveProfile.set=function(t){this.opts.persistToken?this.lset=t:this.sset=t},r.readProfile.get=function(){return this.opts.persistToken?this.lget:this.sget},r.jsonqlToken.set=function(t){var e,r=this.readProfile,n="jsonqlcredential",o=r&&r[n]?r[n]:[];o.push(t),this.saveProfile=((e={})[n]=o,e),this.__userdata__=this.decoder(t),this.jsonqlUserdata=this.__userdata__},r.jsonqlToken.get=function(){var t=this.readProfile,e="jsonqlcredential";return!(!t||!t[e])&&(this.log("-- jsonqlToken --",t[e],this.profileIndex,t[e][this.profileIndex]),t[e][this.profileIndex])},r.jsonqlUserdata.set=function(t){var e;this.sset=((e={}).userdata=t,e)},r.jsonqlUserdata.get=function(){var t=this.sget;return!!t&&t.userdata},e.prototype.getAuthHeader=function(){var t,e=this.jsonqlToken;return e?((t={})[this.opts.AUTH_HEADER]="Bearer "+e,t):{}},e.prototype.getProfiles=function(t){void 0===t&&(t=!1);var e=this.readProfile,r="jsonqlcredential";return!(!e||!e[r])&&(!1!==t&&bn(t)?e[r][t]||!1:e[r].map(this.decoder.bind(this)))},e.prototype.postLoginAction=function(t){return this.jsonqlToken=t,{token:t,userdata:this.__userdata__}},e.prototype.postLogoutAction=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];console.info("postLogoutAction",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();return this.log("getContract first call",t),t?Promise.resolve(t):this.getRemoteContract().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){var e;if(!Cn(t))throw new v("Contract is malformed!");return this.lset=((e={}).contract=t,e),this.log("storeContract return result",t),t},e.prototype.readContract=function(){var t=Cn(this.opts.contract);if(!1!==t)return t;var e=this.lget;return!!e&&e.contract},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){t.call(this,e),this.extraHeader={},this.extraParams={}}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={headers:{configurable:!0}};return r.headers.set=function(t){this.extraHeader=t},e.prototype.request=function(t,e,r){var n;void 0===e&&(e={}),void 0===r&&(r={}),this.headers=r;var o=nn({},{_cb:Yn()},this.extraParams);if(this.opts.enableJsonp){var i=function(t){return Object.keys(t)[0]}(t);o=nn({},o,((n={}).jsonqlJsonpCallback=i,n)),t=t[i]}var a=nn({},{method:Xo,params:o},e);return this.log("request params",a,this.jsonqlEndpoint),this.httpEngine.request(this.jsonqlEndpoint,t,a)},e.prototype.reqInterceptor=function(){var t=this;this.httpEngine.interceptors.request.use((function(e){var r=t.getHeaders();for(var n in t.log("request interceptor call",r),r)e.headers[n]=r[n];return e}))},e.prototype.processJsonp=function(t){return Xn(t)},e.prototype.resInterceptor=function(){var t=this,e=this,r=e.opts.enableJsonp;this.httpEngine.interceptors.response.use((function(n){t.log("response interceptor call",n),e.cleanUp();var o=yn(n.data)?JSON.parse(n.data):n.data;return r?e.processJsonp(o):Xn(o)}),(function(r){throw e.cleanUp(),t.log("__error__",r),new w("Server side error",r)}))},e.prototype.getHeaders=function(){return this.opts.enableAuth?nn({},y,this.getAuthHeader(),this.extraHeader):nn({},y,this.extraHeader)},e.prototype.cleanUp=function(){this.extraHeader={},this.extraParams={}},e.prototype.getRemoteContract=function(){var t=this;return this.opts.showContractDesc&&(this.extraParams=nn({},this.extraParams,m)),this.request({},{method:"GET"},this.contractHeader).then(S).then((function(e){return t.log("get contract result",e),e.cache&&e.contract?e.contract:e})).catch((function(e){throw t.log("__error__","getRemoteContract err",e),new w("getRemoteContract",e)}))},e.prototype.query=function(t,e){return void 0===e&&(e=[]),this.request(function(t,e,r){if(void 0===e&&(e=[]),void 0===r&&(r=!1),lt(t)&&C(e)){var n=function(t){var e;return(e={}).args=t,e}(e);return!0===r?n:Qn(t,n)}throw new v("[createQuery] expect resolverName to be string and args to be array!",{resolverName:t,args:e})}(t,e)).then(S)},e.prototype.mutation=function(t,e,r){return void 0===e&&(e={}),void 0===r&&(r={}),this.request(function(t,e,r,n){void 0===r&&(r={}),void 0===n&&(n=!1);var o={};if(o.payload=e,o.condition=r,!0===n)return o;if(lt(t))return Qn(t,o);throw new v("[createMutation] expect resolverName to be string!",{resolverName:t,payload:e,condition:r})}(t,e,r),{method:Zo}).then(S)},Object.defineProperties(e.prototype,r),e}(Yo)))),ei={contract:!1,MUTATION_ARGS:["name","payload","conditions"],CONTENT_TYPE:g,BEARER:"Bearer",AUTH_HEADER:"Authorization"},ri={hostname:_n(function(){try{return[window.location.protocol,window.location.host].join("//")}catch(t){return null}}(),["string"]),jsonqlPath:_n("jsonql",["string"]),loginHandlerName:_n("login",["string"]),logoutHandlerName:_n("logout",["string"]),enableJsonp:_n(!1,["boolean"]),enableAuth:_n(!1,["boolean"]),useJwt:_n(!0,["boolean"]),persistToken:_n(!1,["boolean","number"]),useLocalstorage:_n(!0,["boolean"]),storageKey:_n("jsonqlstore",["string"]),authKey:_n("jsonqlauthkey",["string"]),contractExpired:_n(0,["number"]),keepContract:_n(!0,["boolean"]),exposeContract:_n(!1,["boolean"]),exposeStore:_n(!1,["boolean"]),showContractDesc:_n(!1,["boolean"]),contractKey:_n(!1,["boolean"]),contractKeyName:_n("X-JSONQL-CV-KEY",["string"]),enableTimeout:_n(!1,["boolean"]),timeout:_n(5e3,["number"]),returnInstance:_n(!1,["boolean"]),allowReturnRawToken:_n(!1,["boolean"]),debugOn:_n(!1,["boolean"])};function ni(t,e){for(var r=[],n=arguments.length-2;n-- >0;)r[n]=arguments[n+2];var o=function(t){return En(t,"__checked__",Yn())};r.push(o);var i=Reflect.apply(Sn,null,r);return function(r){return void 0===r&&(r={}),i(r,t,e)}}function oi(t){var e=function(t,e){for(var r=[],n=arguments.length-2;n-- >0;)r[n]=arguments[n+2];return function(n){var o;if(void 0===n&&(n={}),kn(n,"__checked__")){var i=1;return n.__passed__&&(i=++n.__passed__,delete n.__passed__),Promise.resolve(Object.assign(((o={}).__passed__=i,o),n,e))}var a=Reflect.apply(ni,null,[t,e].concat(r));return Promise.resolve(a(n))}}(ri,ei,wn),r=t.contract;return e(t).then((function(t){return t.contract=r,t}))}function ii(t,e,r){return void 0===r&&(r={}),oi(r).then((function(t){return{baseClient:new ti(e,t),opts:t}})).then((function(e){var r,n,o=e.baseClient,i=e.opts;return(r=o,n=i.contract,void 0===n&&(n={}),Cn(n)?Promise.resolve(n):r.getContract()).then((function(e){return qn(o,i,e,t)}))}))}var ai=new WeakMap,ui=new WeakMap,ci=function(){this.__suspend__=null,this.queueStore=new Set},si={$suspend:{configurable:!0},$queues:{configurable:!0}};si.$suspend.set=function(t){var e=this;if("boolean"!=typeof t)throw new Error("$suspend only accept Boolean value!");var r=this.__suspend__;this.__suspend__=t,this.logger("($suspend)","Change from "+r+" --\x3e "+t),!0===r&&!1===t&&setTimeout((function(){e.release()}),1)},ci.prototype.$queue=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return!0===this.__suspend__&&(this.logger("($queue)","added to $queue",t),this.queueStore.add(t)),this.__suspend__},si.$queues.get=function(){var t=this.queueStore.size;return this.logger("($queues)","size: "+t),t>0?Array.from(this.queueStore):[]},ci.prototype.release=function(){var t=this,e=this.queueStore.size;if(this.logger("(release)","Release was called "+e),e>0){var r=Array.from(this.queueStore);this.queueStore.clear(),this.logger("queue",r),r.forEach((function(e){t.logger(e),Reflect.apply(t.$trigger,t,e)})),this.logger("Release size "+this.queueStore.size)}},Object.defineProperties(ci.prototype,si);var fi=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={name:{configurable:!0}};return r.name.get=function(){return"jsonql-event-emitter"},Object.defineProperties(e.prototype,r),e}(function(t){function e(e){void 0===e&&(e={}),t.call(this,e)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var r={$done:{configurable:!0}};return e.prototype.logger=function(){},e.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.logger("($on)","call run on "+t),n.run(e,a,r||u),i+=n.addToNormalStore(t,"on",e,r||u)})),i},e.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.logger("($once)","call run for "+t),this.run(e,i,r||a),this.$off(t)},e.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(o){var i=o[0],a=o[1],u=o[2];if(u&&"only"!==u)throw new Error("You are trying to register an event already been taken by other type: "+u);n.logger("($only)","call run for "+t),n.run(e,i,r||a)})));return o},e.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.logger("($onlyOnce)","call run for "+t),this.run(e,a,r||u),this.$off(t)}return n},e.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 this.logger("($replace)",t,e),Reflect.apply(o,this,[t,e,r])}throw new Error(n+" is not supported!")},e.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)","normalStore",i),i.has(t)){var a=this.$queue(t,e,r,n);if(this.logger("($trigger)",t,"found; add to queue: ",a),!0===a)return this.logger("($trigger)",t,"not executed. Exit now."),!1;for(var u=Array.from(i.get(t)),c=u.length,s=!1,f=0;f0;)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]},e.prototype.checkContentExist=function(t,e){return!!Array.from(e).filter((function(e){return e[0]===t[0]})).length},e.prototype.checkTypeInStore=function(t,e){this.validateEvt(t,e);var r=this.$get(t,!0);return!1===r||!r.filter((function(t){var r=t[3];return e!==r})).length},e.prototype.checkTypeInLazyStore=function(t,e){this.validateEvt(t,e);var r=this.lazyStore.get(t);return this.logger("(checkTypeInLazyStore)",r),!!r&&!!Array.from(r).filter((function(t){return t[2]!==e})).length},e.prototype.addToNormalStore=function(t,e,r,n){if(void 0===n&&(n=null),this.logger("(addToNormalStore)",t,e,"try to add to normal store"),this.checkTypeInStore(t,e)){this.logger("(addToNormalStore)",e+" can add to "+t+" normal 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},e.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},e.prototype.toArray=function(t){return Array.isArray(t)?t:[t]},r.normalStore.set=function(t){ai.set(this,t)},r.normalStore.get=function(){return ai.get(this)},r.lazyStore.set=function(t){ui.set(this,t)},r.lazyStore.get=function(){return ui.get(this)},e.prototype.hashFnToKey=function(t){return $n(t.toString())},Object.defineProperties(e.prototype,r),e}(ci)));function li(t,e){var r;return ii((r=e.debugOn,new fi({logger:r?function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];t.unshift("[BUILTIN]"),console.log.apply(null,t)}:void 0})),t,e)}return function(t){return void 0===t&&(t={}),li(new o,t)}})); //# sourceMappingURL=jsonql-client.umd.js.map diff --git a/packages/http-client/package.json b/packages/http-client/package.json index 267f4a00e5ca3b3b5dcb15154786119386055797..712c3c245a3550e04a4489d9b5ae30d7563e29f1 100755 --- a/packages/http-client/package.json +++ b/packages/http-client/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-client", - "version": "1.5.17", + "version": "1.5.18", "description": "jsonql http browser client using Fly.js with full user profile management with jwt and more", "main": "core.js", "module": "index.js", @@ -13,7 +13,8 @@ "index.js", "static.js", "module.js", - "sync.js" + "sync.js", + "vuex.js" ], "scripts": { "test": "ava", @@ -78,7 +79,7 @@ "debug": "^4.1.1", "esm": "^3.2.25", "glob": "^7.1.6", - "jsonql-koa": "^1.5.6", + "jsonql-koa": "^1.5.7", "koa-favicon": "^2.0.1", "nyc": "^15.0.0", "promise-polyfill": "8.1.3", diff --git a/packages/http-client/src/utils.js b/packages/http-client/src/utils.js index c6ffbaa454092cd1f448d7e3b605e8aa46461b92..9c0a9d7b5ad94aedcdb70db5379f8e64645b862c 100644 --- a/packages/http-client/src/utils.js +++ b/packages/http-client/src/utils.js @@ -37,6 +37,7 @@ const ZERO_IDX = 0 export { hashCode, getContractFromConfig, + // constants ENDPOINT_TABLE, USERDATA_TABLE, CLS_LOCAL_STORE_NAME, diff --git a/packages/http-client/vuex.js b/packages/http-client/vuex.js new file mode 100644 index 0000000000000000000000000000000000000000..68e409e3a4e9e6f5b5730c79bb42876bc0d88394 --- /dev/null +++ b/packages/http-client/vuex.js @@ -0,0 +1,76 @@ +// this is an experiemental generic module for vuex +import { jsonqlStaticClient } from './static' + +/** + * @param {string} str to upper case first word + * @return {string} uppercase first word string + */ +const ucword = str => ( + str.substr(0, 1).toUpperCase() + str.substr(1, str.length - 1) +) + +/** + * create actions on the fly + * @param {object} contract the contract object + * @param {object} jsonqlClient static version + * @param {boolean} [prefix=true] add prefix or not + */ +function getActions(contract, jsonqlClient, prefix = true) { + let actions = {} + const target = ['query', 'mutation', 'auth'] + for (let name in contract) { + if (target.indexOf(name) > -1) { + for (let resolverName in contract[name]) { + let actionName = prefix === false ? resolverName : name + ucword(resolverName) + actions[actionName] = (ctx, ...args) => { + return Reflect.apply(jsonqlClient[name], jsonqlClient, [resolverName].concat(args)) + .then(result => { + ctx.commit('addToResult', {name: actionName, result}) + return result + }) + .catch(error => { + ctx.commit('addToError', {name: actionName, error}) + throw new Error(error) + }) + } + } + } + } + return actions +} + +/** + * We export a function to generate the relevant code + * @param {object} Fly the fly object + * @param {object} config configuration with the contract + * @return {object} the Vuex store object + */ +function getJsonqlVuexModule(Fly, config) { + const { prefix, contract } = config // could be undefined but we want false boolean + const jsonqlClient = jsonqlStaticClient(Fly, config) + // just create the structure on the fly + return { + namespaced: true, + state: { + result: {}, + error: {} + }, + mutations: { + addToResult(state, { name, result }) { + state.result[name] = result + }, + addToError(state, { name, error}) { + state.error[name] = error + } + }, + // because jsonql are all async call, everything will be create as actions + actions: getActions(contract, jsonqlClient, prefix), + getters: { + getJsonqlResult: (state) => (name) => { + return state.result[name] + } + } + } +} + +export { getJsonqlVuexModule }