UNPKG

@harishreddym/baqend

Version:

Baqend JavaScript SDK

3 lines (2 loc) 145 kB
/*! @harishreddym/baqend 2.14.1 | Copyright (c) 2015 Baqend GmbH | MIT */ !function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).DB=t()}}(function(){var g={};return g.typeof="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},g.classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},g.createClass=function(){function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}}(),g.defaults=function(t,e){for(var n=Object.getOwnPropertyNames(e),r=0;r<n.length;r++){var i=n[r],o=Object.getOwnPropertyDescriptor(e,i);o&&o.configurable&&void 0===t[i]&&Object.defineProperty(t,i,o)}return t},g.inherits=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):g.defaults(t,e))},g.possibleConstructorReturn=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},function o(s,a,u){function c(e,t){if(!a[e]){if(!s[e]){var n="function"==typeof require&&require;if(!t&&n)return n(e,!0);if(h)return h(e,!0);var r=new Error("Cannot find module '"+e+"'");throw r.code="MODULE_NOT_FOUND",r}var i=a[e]={exports:{}};s[e][0].call(i.exports,function(t){return c(s[e][1][t]||t)},i,i.exports,o,s,a,u)}return a[e].exports}for(var h="function"==typeof require&&require,t=0;t<u.length;t++)c(u[t]);return c}({1:[function(t,e,n){"use strict";var r=t(67),i=function(){function e(t){g.classCallCheck(this,e),this.read=new r(t),this.write=new r(t)}return e.prototype.clear=function(){this.read.clear(),this.write.clear()},e.prototype.copy=function(t){return this.read.copy(t.read),this.write.copy(t.write),this},e.prototype.isPublicReadAllowed=function(){return this.read.isPublicAllowed()},e.prototype.setPublicReadAllowed=function(){return this.read.setPublicAllowed()},e.prototype.isReadAllowed=function(t){return this.read.isAllowed(t)},e.prototype.isReadDenied=function(t){return this.read.isDenied(t)},e.prototype.allowReadAccess=function(){return r.prototype.allowAccess.apply(this.read,arguments),this},e.prototype.denyReadAccess=function(){return r.prototype.denyAccess.apply(this.read,arguments),this},e.prototype.deleteReadAccess=function(){return r.prototype.deleteAccess.apply(this.read,arguments),this},e.prototype.isPublicWriteAllowed=function(){return this.write.isPublicAllowed()},e.prototype.setPublicWriteAllowed=function(){return this.write.setPublicAllowed()},e.prototype.isWriteAllowed=function(t){return this.write.isAllowed(t)},e.prototype.isWriteDenied=function(t){return this.write.isDenied(t)},e.prototype.allowWriteAccess=function(){return r.prototype.allowAccess.apply(this.write,arguments),this},e.prototype.denyWriteAccess=function(){return r.prototype.denyAccess.apply(this.write,arguments),this},e.prototype.deleteWriteAccess=function(){return r.prototype.deleteAccess.apply(this.write,arguments),this},e.prototype.toJSON=function(){return{read:this.read.toJSON(),write:this.write.toJSON()}},e.prototype.fromJSON=function(t){this.read.fromJSON(t.read||{}),this.write.fromJSON(t.write||{})},e}();e.exports=i},{67:67}],2:[function(t,e,n){"use strict";var u=t(34),c=t(33),i=t(19),a=t(75),o=t(61),s=t(18),d=t(65),h=t(25),l=t(21),r=t(73),p=h.StatusCode,f="/db/",y=function(n){function r(t){g.classCallCheck(this,r);var e=g.possibleConstructorReturn(this,n.call(this));return e.log=a.Logger.create(e),e.connection=null,e.entities=null,e.entityManagerFactory=t,e.metamodel=t.metamodel,e.code=t.code,e.modules=null,e.me=null,e.deviceMe=null,e.tokenStorage=null,e.bloomFilter=null,e.cacheWhiteList=null,e.cacheBlackList=null,e.bloomFilterRefresh=60,e.bloomFilterLock=new a.Lockable,e}return g.inherits(r,n),g.createClass(r,[{key:"isOpen",get:function(){return!!this.connection}},{key:"token",get:function(){return this.tokenStorage.token},set:function(t){this.tokenStorage.update(t)}},{key:"isCachingDisabled",get:function(){return!this.bloomFilter}},{key:"isDeviceRegistered",get:function(){return!!this.deviceMe}}]),r.prototype.connected=function(t,e,n){this.connection=t,this.tokenStorage=n,this.bloomFilterRefresh=this.entityManagerFactory.staleness,this.entities={},this.File=i.FileFactory.create(this),this._createObjectFactory(this.metamodel.embeddables),this._createObjectFactory(this.metamodel.entities),this.transaction={},this.modules=new a.Modules(this,t),e&&(e.device&&this.updateDevice(e.device),e.user&&n.token&&this._updateUser(e.user,!0),0<this.bloomFilterRefresh&&e.bloomFilter&&a.atob&&!a.isNode&&this.updateBloomFilter(e.bloomFilter))},r.prototype._createObjectFactory=function(t){var r=this;Object.keys(t).forEach(function(t){var e=r.metamodel.managedType(t),n=e.name;r[n]?(e.typeConstructor=r[n],Object.defineProperty(r,n,{value:e.createObjectFactory(r)})):Object.defineProperty(r,n,{get:function(){return Object.defineProperty(this,n,{value:e.createObjectFactory(this)}),this[n]},set:function(t){e.typeConstructor=t},configurable:!0})},this)},r.prototype.send=function(t,e){var n=this,r=t;r.tokenStorage=this.tokenStorage;var i=this.connection.send(r);return e||(i=i.catch(function(t){throw t.status===p.BAD_CREDENTIALS&&n._logout(),t})),i},r.prototype.getReference=function(t,e){var n=void 0,r=void 0;if(e){var i=e;r=this.metamodel.entity(t),n=0===i.indexOf(f)?i:r.ref+"/"+encodeURIComponent(i)}else if("string"==typeof t){var o=t.indexOf("/",f.length);-1!==o&&(n=t),r=this.metamodel.entity(-1===o?t:n.substring(0,o))}else r=this.metamodel.entity(t);var s=this.entities[n];if(!s){s=r.create();var a=d.get(s);n&&(a.id=n),a.setUnavailable(),this._attach(s)}return s},r.prototype.createQueryBuilder=function(t){return new o.Builder(this,t)},r.prototype.clear=function(){this.entities={}},r.prototype.close=function(){return this.connection=null,this.clear()},r.prototype.contains=function(t){return!!t&&this.entities[t.id]===t},r.prototype.containsById=function(t){return!(!t||!this.entities[t.id])},r.prototype.detach=function(t){var e=this;return d.get(t).withLock(function(){return e.removeReference(t),Promise.resolve(t)})},r.prototype.resolveDepth=function(t,e){var n=this;if(!e||!e.depth)return Promise.resolve(t);e.resolved=e.resolved||[];var r=[],i=Object.assign({},e,{depth:!0===e.depth||e.depth-1});return this.getSubEntities(t,1).forEach(function(t){null!==t&&-1===e.resolved.indexOf(t)&&(e.resolved.push(t),r.push(n.load(t.id,null,i)))}),Promise.all(r).then(function(){return t})},r.prototype.load=function(e,n,t){var r=this,i=t||{},o=this.getReference(e,n),s=d.get(o);if(!i.refresh&&i.local&&s.isAvailable)return this.resolveDepth(o,i);var a=new u.GetObject(s.bucket,s.key);return this.ensureCacheHeader(o.id,a,i.refresh),this.send(a).then(function(t){return o.version>t.entity.version?(i.refresh=!0,r.load(e,n,i)):(r.addToWhiteList(t.entity.id),t.status!==p.NOT_MODIFIED&&s.setJson(t.entity,{persisting:!0}),r.resolveDepth(o,i))},function(t){if(t.status===p.OBJECT_NOT_FOUND)return r.removeReference(o),s.setRemoved(),null;throw t})},r.prototype.insert=function(e,t){var n=this,r=t||{},i=void 0;return this._save(e,r,function(t,e){if(t.version)throw new c.PersistentError("Existing objects can't be inserted.");return i=!t.id,new u.CreateObject(t.bucket,e)}).then(function(t){return i&&n._attach(e),t})},r.prototype.update=function(t,e){var n=e||{};return this._save(t,n,function(t,e){if(!t.version)throw new c.PersistentError("New objects can't be inserted.");return n.force?(delete e.version,new u.ReplaceObject(t.bucket,t.key,e).ifMatch("*")):new u.ReplaceObject(t.bucket,t.key,e).ifMatch(t.version)})},r.prototype.save=function(t,e,n){var r=e||{},i=function(t,e){if(r.force){if(!t.id)throw new c.PersistentError("New special objects can't be forcedly saved.");return delete e.version,new u.ReplaceObject(t.bucket,t.key,e)}return t.version?new u.ReplaceObject(t.bucket,t.key,e).ifMatch(t.version):new u.CreateObject(t.bucket,e)};return n?this._locklessSave(t,r,i):this._save(t,r,i)},r.prototype.optimisticSave=function(t,e){var n=this;return d.get(t).withLock(function(){return n._optimisticSave(t,e)})},r.prototype._optimisticSave=function(e,n){var r=this,t=!1,i=Promise.resolve(n(e,function(){t=!0}));return t?Promise.resolve(e):i.then(function(){return r.save(e,{},!0).catch(function(t){if(412===t.status)return r.refresh(e,{}).then(function(){return r._optimisticSave(e,n)});throw t})})},r.prototype._locklessSave=function(e,n,r){var i=this;this.attach(e);var o=d.get(e),s=void 0,t=void 0;if(o.isAvailable&&(t=o.getJson({persisting:!0})),o.isDirty){n.refresh||o.setPersistent();var a=this.send(r(o,t)).then(function(t){return o.id&&o.id!==t.entity.id&&(i.removeReference(e),o.id=t.entity.id,i._attach(e)),o.setJson(t.entity,{persisting:n.refresh,onlyMetadata:!n.refresh}),e},function(t){if(t.status===p.OBJECT_NOT_FOUND)return i.removeReference(e),o.setRemoved(),null;throw o.setDirty(),t});s=[a]}else s=[Promise.resolve(e)];var u=Object.assign({},n);return u.depth=0,this.getSubEntities(e,n.depth).forEach(function(t){s.push(i._save(t,u,r))}),Promise.all(s).then(function(){return e})},r.prototype._save=function(t,e,n){var r=this;this.ensureBloomFilterFreshness();var i=d.get(t);return i.version&&this.addToBlackList(t.id),i.withLock(function(){return r._locklessSave(t,e,n)})},r.prototype.getSubEntities=function(t,e,n,r){var i=n||[];if(!e)return i;for(var o=r||t,s=d.get(t).type.references(),a=s.next();!a.done;a=s.next())for(var u=a.value,c=this.getSubEntitiesByPath(t,u.path),h=0,l=c.length;h<l;h+=1){var p=c[h];-1===i.indexOf(p)&&p!==o&&(i.push(p),i=this.getSubEntities(p,!0===e?e:e-1,i,o))}return i},r.prototype.getSubEntitiesByPath=function(t,e){var u=this,n=[t];return e.forEach(function(s){var a=[];n.forEach(function(t){var e=t[s];if(e){var n=u.metamodel.managedType(t.constructor).getAttribute(s);if(n.isCollection)for(var r=e.entries(),i=r.next();!i.done;i=r.next()){var o=i.value;a.push(o[1]),n.keyType&&n.keyType.isEntity&&a.push(o[0])}else a.push(e)}}),n=a}),n},r.prototype.delete=function(r,t){var i=this,o=t||{};this.attach(r);var s=d.get(r);return s.withLock(function(){if(!s.version&&!o.force)throw new c.IllegalEntityError(r);var t=new u.DeleteObject(s.bucket,s.key);i.addToBlackList(r.id),o.force||t.ifMatch(s.version);var e=[i.send(t).then(function(){return i.removeReference(r),s.setRemoved(),r})],n=Object.assign({},o);return n.depth=0,i.getSubEntities(r,o.depth).forEach(function(t){e.push(i.delete(t,n))}),Promise.all(e).then(function(){return r})})},r.prototype.flush=function(){},r.prototype.persist=function(t){this.attach(t)},r.prototype.refresh=function(t,e){var n=e||{};return n.refresh=!0,this.load(t.id,null,n)},r.prototype.attach=function(t){if(!this.contains(t)){if(!this.metamodel.entity(t.constructor))throw new c.IllegalEntityError(t);if(this.containsById(t))throw new c.EntityExistsError(t);this._attach(t)}},r.prototype._attach=function(t){var e=d.get(t);if(e.isAttached){if(e.db!==this)throw new c.EntityExistsError(t)}else e.db=this;e.id||"User"!==e.type.name&&"Role"!==e.type.name&&"logs.AppLog"!==e.type.name&&(e.id=f+e.type.name+"/"+a.uuid()),e.id&&(this.entities[e.id]=t)},r.prototype.removeReference=function(t){var e=d.get(t);if(!e)throw new c.IllegalEntityError(t);delete this.entities[e.id]},r.prototype.register=function(e,n,r){var i=this,o=r>s.LoginOption.NO_LOGIN;if(this.me&&o)throw new c.PersistentError("User is already logged in.");return this.withLock(function(){var t=new u.Register({user:e,password:n,login:o});return i._userRequest(t,r)})},r.prototype.login=function(e,n,r){var i=this;if(this.me)throw new c.PersistentError("User is already logged in.");return this.withLock(function(){var t=new u.Login({username:e,password:n});return i._userRequest(t,r)})},r.prototype.logout=function(){var t=this;return this.withLock(function(){return t.send(new u.Logout).then(t._logout.bind(t))})},r.prototype.loginWithOAuth=function(t,e,n){if(this.me)throw new c.PersistentError("User is already logged in.");var r=Object.assign({title:"Login with "+t,timeout:3e5,state:{},loginOption:!0},n);r.redirect&&Object.assign(r.state,{redirect:r.redirect,loginOption:r.loginOption});var i=void 0;if(!h[t+"OAuth"])throw new Error("OAuth provider "+t+" not supported.");(i=new h[t+"OAuth"](e,r.scope,JSON.stringify(r.state))).addRedirectOrigin(this.connection.origin+this.connection.basePath);var o={width:r.width,height:r.height};if(r.redirect){var s=-1!==document.URL.indexOf("http://")||-1!==document.URL.indexOf("https://");return this.openOAuthWindow(i.request.path,s?"_self":"_system",o),new Promise(function(){})}var a=this._userRequest(i,r.loginOption);return this.openOAuthWindow(i.request.path,r.title,o),new Promise(function(t,e){var n=setTimeout(function(){e(new c.PersistentError("OAuth login timeout."))},r.timeout);a.then(t,e).then(function(){clearTimeout(n)})})},r.prototype.openOAuthWindow=function(t,e,n){var r=Object.keys(n).filter(function(t){return void 0!==n[t]}).map(function(t){return t+"="+n[t]}).join(",");open(t,e,r)},r.prototype.renew=function(e){var n=this;return this.withLock(function(){var t=new u.Me;return n._userRequest(t,e)})},r.prototype.newPassword=function(e,n,r){var i=this;return this.withLock(function(){var t=new u.NewPassword({username:e,password:n,newPassword:r});return i.send(t,!0).then(function(t){return i._updateUser(t.entity)})})},r.prototype.newPasswordWithToken=function(t,e,n){var r=this;return this.withLock(function(){return r._userRequest(new u.NewPassword({token:t,newPassword:e}),n)})},r.prototype.resetPassword=function(t){return this.send(new u.ResetPassword({username:t}))},r.prototype.changeUsername=function(t,e,n){return this.send(new u.ChangeUsername({username:t,newUsername:e,password:n}))},r.prototype._updateUser=function(t,e){var n=this.getReference(t.id);return d.get(n).setJson(t,{persisting:!0}),e&&(this.me=n),n},r.prototype._logout=function(){this.me=null,this.token=null},r.prototype._userRequest=function(t,e){var n=this,r=void 0===e||e,i=r>s.LoginOption.NO_LOGIN;return i&&(this.tokenStorage.temporary=r<s.LoginOption.PERSIST_LOGIN),this.send(t,!i).then(function(t){return t.entity?n._updateUser(t.entity,i):null},function(t){if(t.status===p.OBJECT_NOT_FOUND)return i&&n._logout(),null;throw t})},r.prototype.registerDevice=function(t,e,n){var r=this,i=new u.DeviceRegister({devicetype:t,subscription:e,device:n});return i.withCredentials=!0,this.send(i).then(function(t){return r.updateDevice(t.entity)})},r.prototype.updateDevice=function(t){var e=this.getReference(t.id);return d.get(e).setJson(t,{persisting:!0}),this.deviceMe=e},r.prototype.checkDeviceRegistration=function(){var e=this;return this.send(new u.DeviceRegistered).then(function(){return e.isDeviceRegistered=!0},function(t){if(t.status===p.OBJECT_NOT_FOUND)return e.isDeviceRegistered=!1;throw t})},r.prototype.pushDevice=function(t){return this.send(new u.DevicePush(t))},r.prototype.validate=function(t){for(var e=d.get(t).type,n=new a.ValidationResult,r=e.attributes(),i=r.next();!i.done;i=r.next()){var o=new a.Validator(i.value.name,t);n.fields[o.key]=o}var s=e.validationCode;return s&&s(n.fields),n},r.prototype.addToWhiteList=function(t){this.isCachingDisabled||(this.bloomFilter.contains(t)&&this.cacheWhiteList.add(t),this.cacheBlackList.delete(t))},r.prototype.addToBlackList=function(t){this.isCachingDisabled||(this.bloomFilter.contains(t)||this.cacheBlackList.add(t),this.cacheWhiteList.delete(t))},r.prototype.refreshBloomFilter=function(){var e=this;if(this.isCachingDisabled)return Promise.resolve();var t=new u.GetBloomFilter;return t.noCache(),this.send(t).then(function(t){return e.updateBloomFilter(t.entity),e.bloomFilter})},r.prototype.updateBloomFilter=function(t){this.bloomFilter=new l(t),this.cacheWhiteList=new Set,this.cacheBlackList=new Set},r.prototype.ensureBloomFilterFreshness=function(){var t=this;if(!this.isCachingDisabled){var e=(new Date).getTime(),n=1e3*this.bloomFilterRefresh;this.bloomFilterLock.isReady&&e-this.bloomFilter.creation>n&&this.bloomFilterLock.withLock(function(){return t.refreshBloomFilter()})}},r.prototype.mustRevalidate=function(t){if(a.isNode)return!1;this.ensureBloomFilterFreshness();var e=this.isCachingDisabled||!this.bloomFilterLock.isReady;return e=e||!this.cacheWhiteList.has(t)&&(this.cacheBlackList.has(t)||this.bloomFilter.contains(t))},r.prototype.ensureCacheHeader=function(t,e,n){(n||this.mustRevalidate(t))&&e.noCache()},r.prototype.createURL=function(t,e){var n=this.connection.basePath+t,r=!1;return e&&this.me?(n=this.tokenStorage.signPath(n),r=!0):n=n.split("/").map(encodeURIComponent).join("/"),this.mustRevalidate(t)&&(n=n+(r?"&":"?")+"BCB"),this.connection.origin+n},r.prototype.requestAPIToken=function(t,e){var n=this._getUserReference(t,e),r=new u.UserToken(n.key);return this.send(r).then(function(t){return t.entity})},r.prototype.revokeAllTokens=function(t,e){var n=this._getUserReference(t,e),r=new u.RevokeUserToken(n.key);return this.send(r)},r.prototype._getUserReference=function(t,e){return"string"==typeof e?this.getReference(t,e):e},r}(a.Lockable);y.prototype.List=Array,y.prototype.Set=Set,y.prototype.Map=Map,y.prototype.GeoPoint=t(4),r(y.prototype,"_connector","connection"),r(y.prototype,"_entities","entities"),r(y.prototype,"_bloomFilterLock","bloomFilterLock"),e.exports=y},{18:18,19:19,21:21,25:25,33:33,34:34,4:4,61:61,65:65,73:73,75:75}],3:[function(t,e,n){"use strict";var a=t(34),r=t(50),u=t(75),i=t(73),c=t(23),h=t(2),l=Symbol("Connected"),o=function(o){function s(t){g.classCallCheck(this,s);var e=g.possibleConstructorReturn(this,o.call(this)),n=Object(t)instanceof String?{host:t}:t||{};e.connection=null,e.metamodel=e.createMetamodel(),e.code=new u.Code(e.metamodel,e),e.tokenStorageFactory=u.TokenStorage.WEB_STORAGE||u.TokenStorage.GLOBAL,e.configure(n);var r=!0,i=new Promise(function(t){e[l]=t});return n.host?e.connect(n.host,n.port,n.secure,n.basePath):r=!1,e.tokenStorage||(r=!1,i=i.then(function(){return e.tokenStorageFactory.create(e.connection.origin)}).then(function(t){e.tokenStorage=t})),n.schema?(e.connectData=n,e.metamodel.init(n.schema)):(r=!1,i=i.then(function(){var t=new a.Connect;return t.withCredentials=!0,0===e.staleness&&t.noCache(),e.send(t)}).then(function(t){e.connectData=t.entity,void 0===e.staleness&&(e.staleness=e.connectData.bloomFilterRefresh||60),e.metamodel.isInitialized||e.metamodel.init(e.connectData.schema),e.tokenStorage.update(e.connectData.token)})),r||e.withLock(function(){return i},!0),e}return g.inherits(s,o),s.prototype.configure=function(t){if(this.connection)throw new Error("The EntityManagerFactory can only be configured before is is connected.");t.tokenStorage&&(this.tokenStorage=t.tokenStorage),t.tokenStorageFactory&&(this.tokenStorageFactory=t.tokenStorageFactory),void 0!==t.staleness&&(this.staleness=t.staleness)},s.prototype.connect=function(t,e,n,r){if(this.connection)throw new Error("The EntityManagerFactory is already connected.");return Object(e)instanceof Boolean?this.connect(t,0,e,n):(this.connection=c.create(t,e,n,r),this[l](),this.ready())},s.prototype.createMetamodel=function(){return new r.Metamodel(this)},s.prototype.createEntityManager=function(t){var e=this,n=new h(this);return this.isReady?n.connected(this.connection,this.connectData,t?this.tokenStorage:new u.TokenStorage(this.connection.origin)):n.withLock(function(){return e.ready().then(function(){n.connected(e.connection,e.connectData,t?e.tokenStorage:new u.TokenStorage(e.connection.origin))})},!0),n},s.prototype.send=function(t){return t.tokenStorage||(t.tokenStorage=this.tokenStorage),this.connection.send(t)},s}(u.Lockable);i(o.prototype,"_connector","connection"),i(o.prototype,"_connected",l),e.exports=o},{2:2,23:23,34:34,50:50,73:73,75:75}],4:[function(t,e,n){"use strict";var r=function(){function o(t,e){g.classCallCheck(this,o);var n=void 0,r=void 0;if(Object(t)instanceof String){var i=t.indexOf(";");n=t.substring(0,i),r=t.substring(i+1)}else r=Object(t)instanceof Number?(n=t,e):Object(t)instanceof Array?(n=t[0],t[1]):t instanceof Object?(n=t.latitude,t.longitude):n=0;if(this.longitude=r,this.latitude=n,this.latitude<-90||90<this.latitude)throw new Error("Latitude "+this.latitude+" is not in bound of -90 <= latitude <= 90");if(this.longitude<-180||180<this.longitude)throw new Error("Longitude "+this.longitude+" is not in bound of -180 <= longitude <= 180")}return o.current=function(){return new Promise(function(e,n){navigator||n(new Error("This seems not to be a browser context.")),navigator.geolocation||n(new Error("This browser does not support geolocation.")),navigator.geolocation.getCurrentPosition(function(t){e(new o(t.coords.latitude,t.coords.longitude))},function(t){n(t)})})},o.prototype.kilometersTo=function(t){return Number((o.EARTH_RADIUS_IN_KILOMETERS*this.radiansTo(t)).toFixed(3))},o.prototype.milesTo=function(t){return Number((o.EARTH_RADIUS_IN_MILES*this.radiansTo(t)).toFixed(3))},o.prototype.radiansTo=function(t){var e=t,n=this.latitude*o.DEG_TO_RAD,r=e.latitude*o.DEG_TO_RAD,i=(e.longitude-this.longitude)*o.DEG_TO_RAD;return Math.acos(Math.sin(n)*Math.sin(r)+Math.cos(n)*Math.cos(r)*Math.cos(i))},o.prototype.toString=function(){return this.latitude+";"+this.longitude},o.prototype.toJSON=function(){return{latitude:this.latitude,longitude:this.longitude}},o}();r.DEG_TO_RAD=Math.PI/180,r.EARTH_RADIUS_IN_KILOMETERS=6371,r.EARTH_RADIUS_IN_MILES=3956,e.exports=r},{}],5:[function(t,e,n){"use strict";var r=t(3),i=t(2);i.prototype.binding=t(19),i.prototype.connector=t(27),i.prototype.error=t(33),i.prototype.message=t(34),i.prototype.metamodel=t(50),i.prototype.util=t(75),i.prototype.caching=t(22),i.prototype.query=t(61),i.prototype.partialupdate=t(54),i.prototype.EntityManager=t(2),i.prototype.EntityManagerFactory=t(3),i.prototype.Acl=t(1);var o=new r,s=o.createEntityManager(!0);s.configure=function(t){return o.configure(t),this},s.connect=function(t,e,n,r){return e instanceof Function?this.connect(t,void 0,e,n):(o.connect(t,e),this.ready(n,r))},(n=s).db=s,n.default=s,e.exports=n},{1:1,19:19,2:2,22:22,27:27,3:3,33:33,34:34,50:50,54:54,61:61,75:75}],6:[function(t,e,n){"use strict";var r=function(){function t(){g.classCallCheck(this,t)}return t.prototype.getValue=function(t,e){return t[e.name]},t.prototype.setValue=function(t,e,n){t[e.name]=n},t}();e.exports=r},{}],7:[function(t,e,n){"use strict";var r=t(10),i=t(34),o=r.extend({get me(){return this.db.deviceMe},get isRegistered(){return this.db.isDeviceRegistered},loadWebPushKey:function(){var t=new i.VAPIDPublicKey;return t.responseType("arraybuffer"),this.db.send(t).then(function(t){return t.entity})},register:function(t,e,n,r,i){if(n instanceof Function)return this.register(t,e,null,n,r);var o="string"==typeof e?{token:e}:e;return this.db.registerDevice(t,o,n).then(r,i)},push:function(t,e,n){return this.db.pushDevice(t).then(e,n)}});o.PushMessage=t(68),e.exports=o},{10:10,34:34,68:68}],8:[function(t,e,n){"use strict";var r=Symbol("BaqendId"),i=Symbol("BaqendType"),o=function(){function n(){g.classCallCheck(this,n)}return n.prototype.createProxy=function(t){return function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,t.apply(this,arguments))}return g.inherits(e,t),e}(t)},n.getBaqendType=function(t){return t[i]},n.getIdentifier=function(t){return t[r]},n.setIdentifier=function(t,e){t[r]=e},n.prototype.enhance=function(t,e){if(e[i]!==t){if(Object.prototype.hasOwnProperty.call(e,i))throw new Error("Type is already used by a different manager");e[i]=t,n.setIdentifier(e,t.ref),this.enhancePrototype(e.prototype,t)}},n.prototype.enhancePrototype=function(e,t){var n=this;e.toString===Object.prototype.toString&&Object.defineProperty(e,"toString",{value:function(){return this._metadata.id||this._metadata.bucket},enumerable:!1}),t.superType&&"Object"===t.superType.name&&t.superType.declaredAttributes.forEach(function(t){t.isMetadata||n.enhanceProperty(e,t)}),t.declaredAttributes.forEach(function(t){n.enhanceProperty(e,t)})},n.prototype.enhanceProperty=function(t,e){var n="$"+e.name;Object.defineProperty(t,e.name,{get:function(){var t=this._metadata;return t.readAccess(),t[n]},set:function(t){var e=this._metadata;e.writeAccess(),e[n]=t},configurable:!0,enumerable:!0})},n}();e.exports=o},{}],9:[function(t,e,n){"use strict";var r=t(14),i=t(51),o=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,t.apply(this,arguments))}return g.inherits(e,t),e}(r);Object.defineProperties(o.prototype,{id:{get:function(){return this._metadata.id},set:function(t){if(this._metadata.id)throw new Error("The id can't be set twice: "+t);0===(t+"").indexOf("/db/"+this._metadata.bucket+"/")?this._metadata.id=t:this.key=t},enumerable:!0},key:{get:function(){return this._metadata.key},set:function(t){this._metadata.key=t}},version:{get:function(){return this._metadata.version},enumerable:!0},acl:{get:function(){return this._metadata.acl},enumerable:!0},ready:{value:function(t){return this._metadata.ready(t)}},attach:{value:function(t){t.attach(this)}},save:{value:function(t,e,n){return t instanceof Function?this.save({},t,e):this._metadata.db.save(this,t).then(e,n)}},insert:{value:function(t,e,n){return t instanceof Function?this.insert({},t,e):this._metadata.db.insert(this,t).then(e,n)}},update:{value:function(t,e,n){return t instanceof Function?this.update({},t,e):this._metadata.db.update(this,t).then(e,n)}},load:{value:function(t,e,n){if(t instanceof Function)return this.load({},t,e);var r=t||{};return r.local=!0,this._metadata.db.load(this.id,null,r).then(e,n)}},delete:{value:function(t,e,n){return t instanceof Function?this.delete({},t,e):this._metadata.db.delete(this,t).then(e,n)}},optimisticSave:{value:function(t,e,n){return this._metadata.db.optimisticSave(this,t).then(e,n)}},attr:{value:function(){throw new Error("Attr is not yet implemented.")}},validate:{value:function(){return this._metadata.db.validate(this)}},partialUpdate:{value:function(t){return new i(this,t)}},getReferencing:{value:function(t){var o=this,s=this._metadata.db,e=this._metadata.type.getReferencing(s,t),n=Array.from(e).map(function(t){var e=t[0],n=s.createQueryBuilder(e.typeConstructor),r=t[1],i=[];return r.forEach(function(t){i.push(n.equal(t,o))}),(1===i.length?i[0]:n.or(i)).resultList()});return Promise.all(n).then(function(t){return t.filter(function(t){return!!t.length})}).then(function(t){return[].concat.apply([],t)})}},toJSON:{value:function(t){var e=t;return"boolean"==typeof e&&(e={excludeMetadata:e}),"object"!==(void 0===e?"undefined":g.typeof(e))&&(e={}),this._metadata.getJson(e)}}}),e.exports=o},{14:14,51:51}],10:[function(t,e,n){"use strict";var r=t(15).extend({load:function(t,e,n,r){return e instanceof Function?this.load(t,{},e,n):this.db.load(this.managedType.typeConstructor,t,e).then(n,r)},ref:function(t){return this.db.getReference(this.managedType.ref,t)},fromJSON:function(t){var e=this.ref(t.id);return this.managedType.fromJsonValue(null,t,e)},find:function(){return this.db.createQueryBuilder(this.managedType.typeConstructor)},partialUpdate:function(t,e){return this.ref(t).partialUpdate(e)}});e.exports=r},{15:15}],11:[function(t,e,n){"use strict";var r=t(73);function i(t){for(var e=1,n=arguments.length;e<n;e+=1)for(var r=arguments[e],i=Object.getOwnPropertyNames(r),o=0,s=i.length;o<s;o+=1){var a=i[o];Object.defineProperty(t,a,Object.getOwnPropertyDescriptor(r,a))}return t}var o=i({extend:function(t){return i({},this,t)},create:function(t){var e=function(t){return e.newInstance(arguments)};return i(e,this),e.prototype=t.prototype,e.type=t,e},new:function(){return this.newInstance(arguments)},newInstance:function(t){if(!t||0===t.length)return new this.type;var e=[null];return Array.prototype.push.apply(e,t),new(Function.prototype.bind.apply(this.type,e))}});r(o,"_type","type"),e.exports=o},{73:73}],12:[function(t,e,n){"use strict";var r=t(33),i=t(1),o=t(77).uuid,a=t(34),u=t(25).StatusCode,s=t(73),c=t(20).trailingSlashIt,h="/file".length,l=Symbol("Id"),p=Symbol("Metadata"),d=Symbol("Data"),f=function(){function n(t){g.classCallCheck(this,n);var e="string"==typeof t?{id:t}:t||{};if(e.id){if(-1===e.id.indexOf("/","/file/".length)||0!==e.id.indexOf("/file/"))throw new Error("Invalid file reference "+e.id);this[l]=e.id}else this[l]=this.createIdFromOptions(e);this.setDataOptions(e),this.isFolder="/"===this.id.charAt(this.id.length-1)}return g.createClass(n,[{key:"id",get:function(){return this[l]}},{key:"url",get:function(){if(this.isFolder)throw new Error("Url can not be created for folders.");return this.db.createURL(this.id,"www"!==this.bucket)}},{key:"name",get:function(){return this.id.substring(this.id.lastIndexOf("/",this.id.length-2)+1)}},{key:"mimeType",get:function(){if(this.isFolder)throw new Error("A folder has no mimeType");return this.checkAvailable(),this[p].mimeType}},{key:"acl",get:function(){return this.checkAvailable(),this[p].acl}},{key:"lastModified",get:function(){if(this.isFolder)throw new Error("A folder has no lastModified");return this.checkAvailable(),this[p].lastModified}},{key:"createdAt",get:function(){if(this.isFolder)throw new Error("A folder has no creation date");return this.checkAvailable(),this[p].createdAt}},{key:"eTag",get:function(){if(this.isFolder)throw new Error("A folder has no eTag");return this.checkAvailable(),this[p].eTag}},{key:"headers",get:function(){if(this.isFolder)throw new Error("A folder has no custom headers");return this.checkAvailable(),this[p].headers}},{key:"size",get:function(){if(this.isFolder)throw new Error("A folder has no size");return this.checkAvailable(),this[p].size}},{key:"bucket",get:function(){return this.id.substring(h+1,this.id.indexOf("/",h+1))}},{key:"key",get:function(){return this.id.substring(this.id.indexOf("/",h+1)+1)}},{key:"path",get:function(){return this.id.substring(h)}},{key:"parent",get:function(){return this.id.substring(h,this.id.lastIndexOf("/",this.id.length-2))}},{key:"isMetadataLoaded",get:function(){return!!this[p]}}]),n.parseETag=function(t){if(!t)return null;var e=t.match(/^(?:[wW]\/)?["'](.*)["']$/);return e?e[1]:null},n.prototype.upload=function(t,e,n){var r=this,i=t||{};if(this.isFolder)throw new Error("A folder cannot be uploaded");this.setDataOptions(i);var o=new a.UploadFile(this.bucket,this.key).entity(this[d].data,this[d].type),s=this[p];return s&&(o.acl(s.acl),o.contentLength(s.size),o.mimeType(s.mimeType),o.customHeaders(s.headers)),o.progress(i.progress),this.conditional(o,i),this.db.addToBlackList(this.id),this.db.send(o).then(function(t){return r[d]=null,r.fromJSON(t.entity),r}).then(e,n)},n.prototype.download=function(t,e,n){var r=this,i=t||{};if(this.isFolder)throw new Error("A folder cannot be downloaded");var o=i.type||"blob",s=new a.DownloadFile(this.bucket,this.key).responseType(o);return this.db.ensureCacheHeader(this.id,s,i.refresh),this.db.send(s).then(function(t){return r.db.addToWhiteList(r.id),r.fromHeaders(t.headers),t.entity},function(t){if(t.status===u.OBJECT_NOT_FOUND)return null;throw t}).then(e,n)},n.prototype.delete=function(t,e,n){var r=this,i=t||{},o=new a.DeleteFile(this.bucket,this.key);return this.conditional(o,i),this.isFolder||this.db.addToBlackList(this.id),this.db.send(o).then(function(t){return r.isFolder?t.entity.map(function(t){return r.db.File(t)}):r}).then(e,n)},n.prototype.createIdFromOptions=function(t){var e=void 0;if(t.path)e=t.path;else{var n=c(t.parent||"/www");if(n.length<3)throw new Error("Invalid parent name: "+n);e=n+(t.name||t.data&&t.data.name||o())}if("/"!==e.charAt(0)&&(e="/"+e),-1!==e.indexOf("//")||e.length<3)throw new Error("Invalid path: "+e);return"/file"+e},n.prototype.conditional=function(t,e){if(!e.force){var n=this[p];n&&(n.lastModified||n.eTag)?(t.ifUnmodifiedSince(n.lastModified),t.ifMatch(n.eTag)):t.ifNoneMatch("*")}},n.prototype.loadMetadata=function(t,e,n){var r=this,i=t||{};if(this.isFolder)throw new Error("A folder has no matadata.");var o=new a.GetFileMetadata(this.bucket,this.key);return this.db.ensureCacheHeader(this.id,o,i.refresh),this.db.send(o).then(function(t){return r.fromHeaders(t.headers),r},function(t){if(t.status===u.OBJECT_NOT_FOUND)return null;throw t}).then(e,n)},n.prototype.saveMetadata=function(t,e,n){var r=this,i=t||{},o=this.toJSON(),s=new a.UpdateFileMetadata(this.bucket,this.key).entity(o);return this.conditional(s,i),this.db.send(s).then(function(t){return r.fromJSON(t.entity),r}).then(e,n)},n.prototype.setDataOptions=function(t){var e=t.data,n=t.type;if(e){this[d]={type:n,data:e};var r=this.guessMimeType(t);this.fromJSON(Object.assign({},t,{mimeType:r}))}},n.prototype.guessMimeType=function(t){var e=t.mimeType;return e||("undefined"!=typeof Blob&&t.data instanceof Blob?t.data.type:"data-url"!==t.type?null:t.data.match(/^data:(.+?)(;base64)?,.*$/)[1])},n.prototype.fromHeaders=function(t){this.fromJSON({eTag:n.parseETag(t.etag),lastModified:t["last-modified"],createdAt:t["baqend-created-at"],mimeType:t["content-type"],acl:t["baqend-acl"]&&JSON.parse(t["baqend-acl"]),size:+t["baqend-size"],headers:t["baqend-custom-headers"]&&JSON.parse(t["baqend-custom-headers"])})},n.prototype.fromJSON=function(t){if(t.id&&this.id!==t.id)throw new Error("This file id "+this.id+" does not match the given json id "+t.id);var e=this[p]||{},n=void 0;t.acl instanceof i?n=t.acl:(n=e.acl||new i,t.acl&&n.fromJSON(t.acl)),this[p]=Object.assign({},this[p],{mimeType:t.mimeType,lastModified:t.lastModified&&new Date(t.lastModified)||e.lastModified,createdAt:t.createdAt&&new Date(t.createdAt)||e.createdAt,eTag:t.eTag||e.eTag,acl:n,size:"number"==typeof t.size?t.size:t.contentLength,headers:t.headers||e.headers||{}})},n.prototype.toJSON=function(){this.checkAvailable();var t=this[p];return{id:this.id,mimeType:t.mimeType,eTag:t.eTag,acl:t.acl.toJSON(),size:t.size,lastModified:t.lastModified&&t.lastModified.toISOString(),createdAt:t.createdAt&&t.createdAt.toISOString(),headers:t.headers}},n.prototype.checkAvailable=function(){if(!this.isMetadataLoaded)throw new r.PersistentError("The file metadata of "+this.id+" is not available.")},n}();s(f.prototype,"_db","db"),s(f.prototype,"_conditional","conditional"),s(f.prototype,"_setMetadata","setDataOptions"),s(f.prototype,"_checkAvailable","checkAvailable"),e.exports=f},{1:1,20:20,25:25,33:33,34:34,73:73,77:77}],13:[function(t,e,n){"use strict";var r=t(11),i=t(12),h=t(20).trailingSlashIt,l=t(34),o=t(67),s=t(25).StatusCode,a=t(73),u=r.extend({create:function(t){var e=r.create.call(this,i);return e.db=t,e},newInstance:function(t){var e=r.newInstance.call(this,t);return e.db=this.db,e},fromJSON:function(t){var e=this.newInstance([t.id]);return e.fromJSON(t),e},saveMetadata:function(t,e,n,r){var i=new l.SetFileBucketMetadata(t,e);return this.db.send(i).then(n,r)},loadMetadata:function(t,e,n,r){var i=new l.GetFileBucketMetadata(t);return this.db.send(i).then(function(e){var n={};return o.BASE_PERMISSIONS.forEach(function(t){n[t]=o.fromJSON(e.entity[t]||{})}),n},function(t){if(t.status===s.OBJECT_NOT_FOUND)return null;throw t}).then(n,r)},listBuckets:function(t,e){var n=this;return this.db.send(new l.ListBuckets).then(function(t){return t.entity.map(function(t){return n.new(t+"/")})}).then(t,e)},listFiles:function(t,e,n,r,i){var o=this,s=void 0;if(Object(t)instanceof String){var a=h(t);s=this.new({path:a})}else s=t;var u=s.key,c=s.bucket;return this.db.send(new l.ListFiles(c,u,e?e.key:null,n)).then(function(t){return t.entity.map(function(t){return o.new(t)})}).then(r,i)}});a(u,"_db","db"),e.exports=u},{11:11,12:12,20:20,25:25,34:34,67:67,73:73}],14:[function(t,e,n){"use strict";var r=t(8),i=t(65),o=function(){function e(t){g.classCallCheck(this,e),e.init(this,t)}return e.init=function(t,e){var n=r.getBaqendType(t.constructor);n&&Object.defineProperty(t,"_metadata",{value:i.create(n,t),configurable:!0}),e&&Object.assign(t,e)},e.extend=function(t){return t.prototype=Object.create(this.prototype,{constructor:{value:t,configurable:!0,writable:!0}}),t.extend=e.extend,t},e}();Object.defineProperties(o.prototype,{toJSON:{value:function(){return this._metadata.type.toJsonValue(this._metadata,this,{})}}}),e.exports=o},{65:65,8:8}],15:[function(t,e,n){"use strict";var r=t(11),i=t(73),o=r.extend({create:function(t,e){var n=r.create.call(this,t.typeConstructor);return n.methods=n.prototype,n.managedType=t,n.db=e,n},newInstance:function(t){var e=r.newInstance.call(this,t);return e._metadata.db=this.db,e},fromJSON:function(t){var e=this.newInstance(),n=e._metadata;return this.managedType.fromJsonValue(n,t,e,{})},addMethods:function(t){Object.assign(this.methods,t)},addMethod:function(t,e){this.methods[t]=e}});i(o,"_db","db"),i(o,"_managedType","managedType"),e.exports=o},{11:11,73:73}],16:[function(t,e,n){"use strict";var r=t(9),i=t(17),o=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,t.apply(this,arguments))}return g.inherits(e,t),e}(r);Object.defineProperties(o.prototype,{hasUser:{value:function(t){return this.users&&this.users.has(t)}},addUser:{value:function(t){if(!(t instanceof i))throw new Error("Only user instances can be added to a role.");this.users||(this.users=new Set),this.users.add(t)}},removeUser:{value:function(t){if(!(t instanceof i))throw new Error("Only user instances can be removed from a role.");this.users&&this.users.delete(t)}}}),e.exports=o},{17:17,9:9}],17:[function(t,e,n){"use strict";var r=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,t.apply(this,arguments))}return g.inherits(e,t),e}(t(9));Object.defineProperties(r.prototype,{newPassword:{value:function(t,e,n,r){return this._metadata.db.newPassword(this.username,t,e).then(n,r)}},changeUsername:{value:function(t,e,n,r){return this._metadata.db.changeUsername(this.username,t,e).then(n,r)}},requestAPIToken:{value:function(t,e){return this._metadata.db.requestAPIToken(this.constructor,this).then(t,e)}}}),e.exports=r},{9:9}],18:[function(t,e,n){"use strict";var a=t(10).extend({get me(){return this.db.me},register:function(t,e,n,r,i){if(n instanceof Function)return this.register(t,e,!0,n,r);var o="string"==typeof t?this.fromJSON({username:t}):t;return this.db.register(o,e,void 0===n||n).then(r,i)},login:function(t,e,n,r,i){return n instanceof Function?this.login(t,e,!0,n,r):this.db.login(t,e,void 0===n||n).then(r,i)},loginWithToken:function(t,e,n,r){return e instanceof Function?this.loginWithToken(t,!0,e,n):(this.db.token=t,this.db.renew(e).then(n,r))},logout:function(t,e){return this.db.logout().then(t,e)},newPassword:function(t,e,n,r,i){if("string"==typeof n)return this.db.newPassword(t,e,n).then(r,i);var o=arguments,s=o[0],a=o[1],u=o[2],c=o[3],h=o[4];return u instanceof Function&&(h=c,c=u,u=!0),this.db.newPasswordWithToken(s,a,u).then(c,h)},resetPassword:function(t,e,n){return this.db.resetPassword(t).then(e,n)},changeUsername:function(t,e,n,r,i){return this.db.changeUsername(t,e,n,r,i)},requestAPIToken:function(t,e,n){return this.db.requestAPIToken(this.managedType.typeConstructor,t).then(e,n)},revokeAllTokens:function(t,e,n){return this.db.revokeAllTokens(this.managedType.typeConstructor,t).then(e,n)}});a.LoginOption={NO_LOGIN:-1,SESSION_LOGIN:0,PERSIST_LOGIN:1},a.DefaultOptions={google:{width:585,height:545,scope:"email"},facebook:{width:1140,height:640,scope:"email"},github:{width:1040,height:580,scope:"user:email"},twitter:{width:740,height:730},linkedin:{width:630,height:530,scope:""}},["Google","Facebook","GitHub","Twitter","LinkedIn"].forEach(function(o){var s="loginWith"+o;a[s]=function(t,e,n,r){if(e instanceof Function)return this[s](t,{},e,n);var i=Object.assign({},a.DefaultOptions[o.toLowerCase()],e||{});return this.db.loginWithOAuth(o,t,i).then(n,r)}}),e.exports=a},{10:10}],19:[function(t,e,n){"use strict";n.trailingSlashIt=t(20),n.Accessor=t(6),n.Enhancer=t(8),n.Factory=t(11),n.ManagedFactory=t(15),n.EntityFactory=t(10),n.UserFactory=t(18),n.DeviceFactory=t(7),n.FileFactory=t(13),n.Managed=t(14),n.Entity=t(9),n.Role=t(16),n.User=t(17),n.File=t(12)},{10:10,11:11,12:12,13:13,14:14,15:15,16:16,17:17,18:18,20:20,6:6,7:7,8:8,9:9}],20:[function(t,e,n){"use strict";n.trailingSlashIt=function(t){return"/"!==t.charAt(t.length-1)?t+"/":t}},{}],21:[function(t,e,n){"use strict";var r=t(72).atob,i=function(){function a(t){g.classCallCheck(this,a),this.bytes=r(t.b),this.bits=t.m,this.hashes=t.h,this.creation=Date.now()}return a.prototype.contains=function(t){for(var e=a.getHashes(t,this.bits,this.hashes),n=0,r=e.length;n<r;n+=1)if(!this.isSet(e[n]))return!1;return!0},a.prototype.isSet=function(t){var e=Math.floor(t/8),n=1<<t%8;return 0!=(this.bytes.charCodeAt(e)&n)},a.getHashes=function(t,e,n){for(var r=new Array(this.hashes),i=a.murmur3(0,t),o=a.murmur3(i,t),s=0;s<n;s+=1)r[s]=(i+s*o)%e;return r},a.murmur3=function(t,e){var n=3&e.length,r=e.length-n,i=3432918353,o=461845907,s=void 0,a=void 0,u=void 0,c=void 0;for(s=t,c=0;c<r;)u=255&e.charCodeAt(c)|(255&e.charCodeAt(c+=1))<<8|(255&e.charCodeAt(c+=1))<<16|(255&e.charCodeAt(c+=1))<<24,c+=1,s=27492+(65535&(a=5*(65535&(s=(s^=u=(65535&(u=(u=(65535&u)*i+(((u>>>16)*i&65535)<<16)&4294967295)<<15|u>>>17))*o+(((u>>>16)*o&65535)<<16)&4294967295)<<13|s>>>19))+((5*(s>>>16)&65535)<<16)&4294967295))+((58964+(a>>>16)&65535)<<16);switch(u=0,n){case 3:u^=(255&e.charCodeAt(c+2))<<16;case 2:u^=(255&e.charCodeAt(c+1))<<8;case 1:s^=u=(65535&(u=(u=(65535&(u^=255&e.charCodeAt(c)))*i+(((u>>>16)*i&65535)<<16)&4294967295)<<15|u>>>17))*o+(((u>>>16)*o&65535)<<16)&4294967295}return s^=e.length,s=2246822507*(65535&(s^=s>>>16))+((2246822507*(s>>>16)&65535)<<16)&4294967295,s=3266489909*(65535&(s^=s>>>13))+((3266489909*(s>>>16)&65535)<<16)&4294967295,(s^=s>>>16)>>>0},a}();e.exports=i},{72:72}],22:[function(t,e,n){"use strict";n.BloomFilter=t(21)},{21:21}],23:[function(t,e,n){"use strict";var i=t(31),r=function(){function d(t,e,n,r){g.classCallCheck(this,d),this.host=t,this.port=e,this.secure=n,this.basePath=r,this.origin=d.toUri(t,e,n,"")}return d.create=function(t,e,n,r){var i=t,o=e,s=n,a=r;if("undefined"!=typeof location&&(i||(i=location.hostname,o=Number(location.port)),void 0===s&&(s="https:"===location.protocol)),s=!!s,void 0===a&&(a=d.DEFAULT_BASE_PATH),-1!==i.indexOf("/")){var u=/^(https?):\/\/([^/:]+|\[[^\]]+\])(:(\d*))?(\/\w+)?\/?$/.exec(i);if(!u)throw new Error("The connection uri host "+i+" seems not to be valid");s="https"===u[1],i=u[2].replace(/(\[|])/g,""),o=u[4],a=u[5]||""}else"localhost"!==i&&/^[a-z0-9-]*$/.test(i)&&(i+=d.HTTP_DOMAIN);o||(o=s?443:80);var c=d.toUri(i,o,s,a),h=this.connections[c];if(!h){for(var l=this.connectors.length-1;0<=l;l-=1){var p=this.connectors[l];if(p.isUsable&&p.isUsable(i,o,s,a)){h=new p(i,o,s,a);break}}if(!h)throw new Error("No connector is usable for the requested connection.");this.connections[c]=h}return h},d.toUri=function(t,e,n,r){var i=(n?"https://":"http://")+(-1!==t.indexOf(":")?"["+t+"]":t);return i+=n&&443!==e||!n&&80!==e?":"+e:"",i+=r},d.prototype.send=function(e){var n=this,r={status:0};return new Promise(function(t){n.prepareRequest(e),n.doSend(e,e.request,t)}).then(function(t){r=t}).then(function(){return n.prepareResponse(e,r)}).then(function(){return e.doReceive(r),r}).catch(function(t){throw r.entity=null,i.of(t)})},d.prototype.prepareRequest=function(t){if(!t.mimeType()){var e=t.request.type;"json"===e?t.mimeType("application/json;charset=utf-8"):"text"===e&&t.mimeType("text/plain;charset=utf-8")}this.toFormat(t);var n=void 0;switch(t.responseType()){case"json":n="application/json";break;case"text":n="text/*";break;default:n="application/json,text/*;q=0.5,*/*;q=0.1"}if(t.accept()||t.accept(n),this.gzip){var r=t.ifNoneMatch();r&&'""'!==r&&"*"!==r&&t.ifNoneMatch(r.slice(0,-1)+'--gzip"')}if("/connect"===t.request.path)t.request.path=t.tokenStorage.signPath(this.basePath+t.request.path).substring(this.basePath.length),t.cacheControl()&&(t.request.path+=(t.tokenStorage.token?"&":"?")+"BCB");else if(t.tokenStorage){var i=t.tokenStorage.token;i&&t.header("authorization","BAT "+i)}},d.prototype.toFormat=function(t){},d.prototype.prepareResponse=function(e,n){var r=this;n.status=1223===n.status?204:n.status;var i=void 0,t=n.headers||{},o=204===n.status?null:n.entity;if(o&&(!(i=e.responseType())||400<=n.status)){var s=t["content-type"]||t["Content-Type"];s&&-1<s.indexOf("application/json")&&(i="json")}if(t.etag&&(t.etag=t.etag.replace("--gzip","")),e.tokenStorage){var a=t["baqend-authorization-token"]||t["Baqend-Authorization-Token"];a&&e.tokenStorage.update(a)}return new Promise(function(t){t(o&&r.fromFormat(n,o,i))}).then(function(t){n.entity=t,-1!==e.request.path.indexOf("/connect")&&t&&(r.gzip=!!t.gzip)},function(t){throw new Error("Response was not valid "+i+": "+t.message)})},d.prototype.fromFormat=function(t,e,n){},d}();Object.assign(r,{DEFAULT_BASE_PATH:"/v1",HTTP_DOMAIN:".app.baqend.com",RESPONSE_HEADERS:["baqend-authorization-token","content-type","baqend-size","baqend-acl","etag","last-modified","baqend-created-at","baqend-custom-headers"],connectors:[],connections:{},gzip:!1}),e.exports=r},{31:31}],24:[function(t,e,n){"use strict";var a=t(23),r=function(s){function o(t,e,n,r){g.classCallCheck(this,o);var i=g.possibleConstructorReturn(this,s.call(this,t,e,n,r));return i.mid=0,i.messages={},i.doReceive=i.doReceive.bind(i),addEventListener("message",i.doReceive,!1),i}return g.inherits(o,s),o.isUsable=function(t,e,n){if("undefined"==typeof location||"undefined"==typeof document)return!1;var r="https:"===location.protocol,i=location.port||(r?443:80);return location.hostname!==t||i!==e||r!==n},o.prototype.load=function(t){this.iframe=document.createElement("iframe"),this.iframe.src=this.origin+this.basePath+t,this.iframe.setAttribute("style",o.style),document.body.appendChild(this.iframe),this.queue=[],this.iframe.addEventListener("load",this.onLoad.bind(this),!1)},o.prototype.onLoad=function(){for(var t=this.queue,e=0;e<t.length;e+=1)this.postMessage(t[e]);this.queue=null},o.prototype.doSend=function(t,e,n){var r=this;if(t.isBinary)s.prototype.doSend.call(this,t,e,n);else{this.iframe||(this.load(t.request.path),t.request.path="/connect");var i={mid:this.mid+=1,method:e.method,path:e.path,headers:e.headers,entity:e.entity,responseHeaders:a.RESPONSE_HEADERS};this.messages[i.mid]=n;var o=JSON.stringify(i);this.queue?this.queue.push(o):this.postMessage(o),this.connected||setTimeout(function(){r.messages[i.mid]&&(delete r.messages[i.mid],n({status:0,error:new Error("Connection refused.")}))},1e4)}},o.prototype.postMessage=function(t){this.iframe.contentWindow.postMessage(t,this.origin)},o.prototype.doReceive=function(t){if(t.origin===this.origin&&"{"===t.data[0]){var e=JSON.parse(t.data),n=this.messages[e.mid];n&&(delete this.messages[e.mid],this.connected=!0,n({status:e.status,headers:e.headers,entity:e.entity}))}},o}(t(26));r.style="width:1px;height:1px;position:absolute;top:-10px;left:-10px;",a.connectors.push(r),e.exports=r},{23:23,26:26}],25:[function(t,e,n){"use strict";var r=t(28),i="undefined"==typeof navigator||"undefined"!=typeof chrome&&/google/i.test(navigator.vendor)||/cros i686/i.test(navigator.platform),o=Symbol("ResponseType"),s=function(){function u(){g.classCallCheck(this,u),this.withCredentials=!1,this.tokenStorage=null,this.progressCallback=null;var t=arguments,e=0,n=this.spec.path;if(Object(n)instanceof Array){n=this.spec.path[0];for(var r=this.spec.path.length,i=1;i<r;i+=1)this.spec.dynamic&&r-1===i?n+=t[e].split("/").map(encodeURIComponent).join("/"):n+=encodeURIComponent(t[e])+this.spec.path[i],e+=1}for(var o="",s=0;s<this.spec.query.length;s+=1){var a=t[e];e+=1,null!=a&&(o+=o||-1!==n.indexOf("?")?"&":"?",o+=this.spec.query[s]+"="+encodeURIComponent(a))}this.request={method:this.spec.method,path:n+o,entity:null,headers:{}},t[e]&&this.entity(t[e],"json"),this.responseType("json")}return u.create=function(n){var t=n.path.split("?"),e=t[0].split(/[:*]\w*/),r=[];return t[1]&&t[1].split("&").forEach(function(t){var e=t.split("=");r.push(e[0])}),n.dynamic=-1!==n.path.indexOf("*"),n.path=e,n.query=r,function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,t.apply(this,arguments))}return g.inherits(e,t),g.createClass(e,[{key:"spec",get:function(){return n}}]),e}(u)},u.createExternal=function(n,t){n.path=[n.path];var e=function(t){function e(){return g.classCallCheck(this,e),g.possibleConstructorReturn(this,t.apply(this,arguments))}return g.inherits(e,t),g.createClass(e,[{key:"spec",get:function(){return n}}]),e}(u);return Object.assign(e.prototype,t),e},g.createClass(u,[{key:"isBinary",get:function(){return this.request.type in u.BINARY||this[o]in u.BINARY}}]),u.prototype.header=function(t,e){return void 0!==e?(this.request.headers[t]=e,this):this.request.headers[t]},u.prototype.entity=function(t,e){var n=e;return n||(n="string"==typeof t?/^data:(.+?)(;base64)?,.*$/.test(t)?"data-url":"text":"undefined"!=typeof Blob&&t instanceof Blob?"blob":"undefined"!=typeof Buffer&&t instanceof Buffer?"buffer":"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?"arraybuffer":"undefined"!=typeof FormData&&t instanceof FormData?"form":"json"),this.request.type=n,this.request.entity=t,this},u.prototype.mimeType=function(t){return this.header("content-type",t)},u.prototype.contentLength=function(t){return this.header("content-length",t)},u.prototype.ifMatch=function(t){return this.header("If-Match",this.formatETag(t))},u.prototype.ifNoneMatch=function(t){return this.header("If-