@cloudbase/js-sdk
Version:
cloudbase javascript sdk
1 lines • 64.3 kB
JavaScript
!function(){var e={8037:function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.registerRealtime=void 0;var r=n(7209);t.registerRealtime=r.registerRealtime;try{window.registerRealtime=t.registerRealtime}catch(e){}},6511:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.setRuntime=t.getRuntime=t.setWsClass=t.getWsClass=void 0;var n=null,r="web";t.getWsClass=function(){return n},t.setWsClass=function(e){n=e},t.getRuntime=function(){return r},t.setRuntime=function(e){r=e}},2917:function(e,t){"use strict";var n,r=this&&this.__extends||(n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},n(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0}),t.ERR_CODE=t.CloudSDKError=t.isCancelledError=t.CancelledError=t.isTimeoutError=t.TimeoutError=t.isRealtimeErrorMessageError=t.RealtimeErrorMessageError=void 0;var o=function(e){function t(t){var n=e.call(this,"Watch Error ".concat(JSON.stringify(t.msgData)," (requestid: ").concat(t.requestId,")"))||this;return n.isRealtimeErrorMessageError=!0,n.payload=t,n}return r(t,e),t}(Error);t.RealtimeErrorMessageError=o,t.isRealtimeErrorMessageError=function(e){return null==e?void 0:e.isRealtimeErrorMessageError};var i=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.type="timeout",t.payload=null,t.generic=!0,t}return r(t,e),t}(Error);t.TimeoutError=i,t.isTimeoutError=function(e){return"timeout"===e.type};var s=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.type="cancelled",t.payload=null,t.generic=!0,t}return r(t,e),t}(Error);t.CancelledError=s,t.isCancelledError=function(e){return"cancelled"===e.type};var a=function(e){function n(n){var r=e.call(this,n.errMsg)||this;return r.errCode="UNKNOWN_ERROR",Object.defineProperties(r,{message:{get:function(){return"errCode: ".concat(this.errCode," ").concat(t.ERR_CODE[this.errCode]||""," | errMsg: ").concat(this.errMsg)},set:function(e){this.errMsg=e}}}),r.errCode=n.errCode||"UNKNOWN_ERROR",r.errMsg=n.errMsg,r}return r(n,e),Object.defineProperty(n.prototype,"message",{get:function(){return"errCode: ".concat(this.errCode," | errMsg: ").concat(this.errMsg)},set:function(e){this.errMsg=e},enumerable:!1,configurable:!0}),n}(Error);t.CloudSDKError=a,t.ERR_CODE={UNKNOWN_ERROR:"UNKNOWN_ERROR",SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG:"SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG",SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA:"SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA",SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR:"SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR",SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED:"SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED",SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL:"SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL",SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR:"SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR"}},7209:function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.registerRealtime=void 0;var r=n(2347),o=n(6511),i={target:"database",entity:function(){var e=this.platform,t=e.adapter,n=e.runtime;(0,o.setWsClass)(t.wsClass),(0,o.setRuntime)(n)}},s={name:"realtime",IIFE:!0,entity:function(){this.prototype.wsClientClass=r.RealtimeWebSocketClient}};try{cloudbase.registerComponent(s),cloudbase.registerHook(i)}catch(e){}t.registerRealtime=function(e){try{e.registerComponent(s),e.registerHook(i)}catch(e){console.warn(e)}}},1601:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.RealtimeListener=void 0;t.RealtimeListener=function(e){this.close=e.close,this.onChange=e.onChange,this.onError=e.onError,e.debug&&Object.defineProperty(this,"virtualClient",{get:function(){return e.virtualClient}})}},3994:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isInitEventMessage=t.genRequestId=void 0,t.genRequestId=function(e){return void 0===e&&(e=""),"".concat(e?"".concat(e,"_"):"").concat(+new Date,"_").concat(Math.random())},t.isInitEventMessage=function(e){return"INIT_EVENT"===e.msgType}},9770:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Snapshot=void 0;t.Snapshot=function(e){var t,n,r=e.id,o=e.docChanges,i=e.docs,s=e.msgType,a=e.type;Object.defineProperties(this,{id:{get:function(){return r},enumerable:!0},docChanges:{get:function(){return t||(t=JSON.parse(JSON.stringify(o))),t},enumerable:!0},docs:{get:function(){return n||(n=JSON.parse(JSON.stringify(i))),n},enumerable:!0},msgType:{get:function(){return s},enumerable:!0},type:{get:function(){return a},enumerable:!0}})}},7589:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.sleep=void 0,t.sleep=function(e){return void 0===e&&(e=0),new Promise(function(t){return setTimeout(t,e)})}},4151:function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},o=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},i=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.VirtualWebSocketClient=void 0;var a,c=s(n(6765)),u=s(n(7195)),l=s(n(9850)),h=n(3994),d=n(1601),f=n(9770),p=n(2917),v=n(7589);!function(e){e.LOGGINGIN="LOGGINGIN",e.INITING="INITING",e.REBUILDING="REBUILDING",e.ACTIVE="ACTIVE",e.ERRORED="ERRORED",e.CLOSING="CLOSING",e.CLOSED="CLOSED",e.PAUSED="PAUSED",e.RESUMING="RESUMING"}(a||(a={}));var E=function(){function e(e){var t=this;this.watchStatus=a.INITING,this.wsLogin=function(e,n){return r(t,void 0,Promise,function(){var t;return o(this,function(r){switch(r.label){case 0:return this.watchStatus=a.LOGGINGIN,[4,this.login(e,n)];case 1:return t=r.sent(),this.envId||(this.envId=t.envId),[2,t]}})})},this.initWatch=function(e){return r(t,void 0,Promise,function(){var t,n=this;return o(this,function(i){switch(i.label){case 0:if(null!==this.initWatchPromise&&void 0!==this.initWatchPromise)return[2,this.initWatchPromise];this.initWatchPromise=new Promise(function(t,i){r(n,void 0,void 0,function(){var n,r,s,c,u,l,d,p,v,E;return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),this.watchStatus===a.PAUSED?(console.log("[realtime] initWatch cancelled on pause"),[2,t()]):[4,this.wsLogin(this.envId,e)];case 1:return n=o.sent().envId,this.watchStatus===a.PAUSED?(console.log("[realtime] initWatch cancelled on pause"),[2,t()]):(this.watchStatus=a.INITING,r={watchId:this.watchId,requestId:(0,h.genRequestId)(),msgType:"INIT_WATCH",msgData:{envId:n,collName:this.collectionName,query:this.query,limit:this.limit,orderBy:this.orderBy}},[4,this.send({msg:r,waitResponse:!0,skipOnMessage:!0,timeout:1e4})]);case 2:if(s=o.sent(),c=s.msgData,u=c.events,l=c.currEvent,this.sessionInfo={queryID:s.msgData.queryID,currentEventId:l-1,currentDocs:[]},u.length>0){for(d=0,p=u;d<p.length;d++)p[d].ID=l;this.handleServerEvents(s)}else this.sessionInfo.currentEventId=l,v=new f.Snapshot({id:l,docChanges:[],docs:[],type:"init"}),this.listener.onChange(v),this.scheduleSendACK();return this.onWatchStart(this,this.sessionInfo.queryID),this.watchStatus=a.ACTIVE,this.availableRetries.INIT_WATCH=2,t(),[3,4];case 3:return E=o.sent(),this.handleWatchEstablishmentError(E,{operationName:"INIT_WATCH",resolve:t,reject:i}),[3,4];case 4:return[2]}})})}),t=!1,i.label=1;case 1:return i.trys.push([1,,3,4]),[4,this.initWatchPromise];case 2:return i.sent(),t=!0,[3,4];case 3:return this.initWatchPromise=void 0,[7];case 4:return console.log("[realtime] initWatch ".concat(t?"success":"fail")),[2]}})})},this.rebuildWatch=function(e){return r(t,void 0,Promise,function(){var t,n=this;return o(this,function(i){switch(i.label){case 0:if(null!==this.rebuildWatchPromise&&void 0!==this.rebuildWatchPromise)return[2,this.rebuildWatchPromise];this.rebuildWatchPromise=new Promise(function(t,i){r(n,void 0,void 0,function(){var n,r,s,c;return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),this.watchStatus===a.PAUSED?(console.log("[realtime] rebuildWatch cancelled on pause"),[2,t()]):[4,this.wsLogin(this.envId,e)];case 1:if(n=o.sent().envId,!this.sessionInfo)throw new Error("can not rebuildWatch without a successful initWatch (lack of sessionInfo)");return this.watchStatus===a.PAUSED?(console.log("[realtime] rebuildWatch cancelled on pause"),[2,t()]):(this.watchStatus=a.REBUILDING,r={watchId:this.watchId,requestId:(0,h.genRequestId)(),msgType:"REBUILD_WATCH",msgData:{envId:n,collName:this.collectionName,queryID:this.sessionInfo.queryID,eventID:this.sessionInfo.currentEventId}},[4,this.send({msg:r,waitResponse:!0,skipOnMessage:!1,timeout:1e4})]);case 2:return s=o.sent(),this.handleServerEvents(s),this.watchStatus=a.ACTIVE,this.availableRetries.REBUILD_WATCH=2,t(),[3,4];case 3:return c=o.sent(),this.handleWatchEstablishmentError(c,{operationName:"REBUILD_WATCH",resolve:t,reject:i}),[3,4];case 4:return[2]}})})}),t=!1,i.label=1;case 1:return i.trys.push([1,,3,4]),[4,this.rebuildWatchPromise];case 2:return i.sent(),t=!0,[3,4];case 3:return this.rebuildWatchPromise=void 0,[7];case 4:return console.log("[realtime] rebuildWatch ".concat(t?"success":"fail")),[2]}})})},this.handleWatchEstablishmentError=function(e,n){return r(t,void 0,void 0,function(){var t,i,s,c=this;return o(this,function(u){return t="INIT_WATCH"===n.operationName,i=function(){c.closeWithError(new p.CloudSDKError({errCode:t?p.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL:p.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL,errMsg:e})),n.reject(e)},s=function(e){c.useRetryTicket(n.operationName)?t?(c.initWatchPromise=void 0,n.resolve(c.initWatch(e))):(c.rebuildWatchPromise=void 0,n.resolve(c.rebuildWatch(e))):i()},this.handleCommonError(e,{onSignError:function(){return s(!0)},onTimeoutError:function(){return s(!1)},onNotRetryableError:i,onCancelledError:n.reject,onUnknownError:function(){r(c,void 0,void 0,function(){var e,t=this;return o(this,function(i){switch(i.label){case 0:return i.trys.push([0,8,,9]),e=function(){return r(t,void 0,void 0,function(){return o(this,function(e){switch(e.label){case 0:return this.pause(),[4,this.onceWSConnected()];case 1:return e.sent(),s(!0),[2]}})})},this.isWSConnected()?[3,2]:[4,e()];case 1:return i.sent(),[3,7];case 2:return[4,(0,v.sleep)(100)];case 3:return i.sent(),this.watchStatus!==a.PAUSED?[3,4]:(n.reject(new p.CancelledError("".concat(n.operationName," cancelled due to pause after unknownError"))),[3,7]);case 4:return this.isWSConnected()?[3,6]:[4,e()];case 5:return i.sent(),[3,7];case 6:s(!1),i.label=7;case 7:return[3,9];case 8:return i.sent(),s(!0),[3,9];case 9:return[2]}})})}}),[2]})})},this.closeWatch=function(){return r(t,void 0,void 0,function(){var e,t,n;return o(this,function(r){switch(r.label){case 0:if(e=this.sessionInfo?this.sessionInfo.queryID:"",this.watchStatus!==a.ACTIVE)return this.watchStatus=a.CLOSED,this.onWatchClose(this,e),[2];r.label=1;case 1:return r.trys.push([1,3,4,5]),this.watchStatus=a.CLOSING,t={watchId:this.watchId,requestId:(0,h.genRequestId)(),msgType:"CLOSE_WATCH",msgData:null},[4,this.send({msg:t})];case 2:return r.sent(),this.sessionInfo=void 0,this.watchStatus=a.CLOSED,[3,5];case 3:return n=r.sent(),this.closeWithError(new p.CloudSDKError({errCode:p.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL,errMsg:n})),[3,5];case 4:return this.onWatchClose(this,e),[7];case 5:return[2]}})})},this.scheduleSendACK=function(){t.clearACKSchedule(),t.ackTimeoutId=setTimeout(function(){t.waitExpectedTimeoutId?t.scheduleSendACK():t.sendACK()},1e4)},this.clearACKSchedule=function(){t.ackTimeoutId&&clearTimeout(t.ackTimeoutId)},this.sendACK=function(){return r(t,void 0,Promise,function(){var e,t,n;return o(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.watchStatus!==a.ACTIVE?(this.scheduleSendACK(),[2]):this.sessionInfo?(e={watchId:this.watchId,requestId:(0,h.genRequestId)(),msgType:"CHECK_LAST",msgData:{queryID:this.sessionInfo.queryID,eventID:this.sessionInfo.currentEventId}},[4,this.send({msg:e})]):(console.warn("[realtime listener] can not send ack without a successful initWatch (lack of sessionInfo)"),[2]);case 1:return r.sent(),this.scheduleSendACK(),[3,3];case 2:if(t=r.sent(),(0,p.isRealtimeErrorMessageError)(t))switch((n=t.payload).msgData.code){case"CHECK_LOGIN_FAILED":case"SIGN_EXPIRED_ERROR":case"SIGN_INVALID_ERROR":case"SIGN_PARAM_INVALID":return this.rebuildWatch(),[2];case"QUERYID_INVALID_ERROR":case"SYS_ERR":case"INVALIID_ENV":case"COLLECTION_PERMISSION_DENIED":return this.closeWithError(new p.CloudSDKError({errCode:p.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL,errMsg:n.msgData.code})),[2]}return this.availableRetries.CHECK_LAST&&this.availableRetries.CHECK_LAST>0?(this.availableRetries.CHECK_LAST-=1,this.scheduleSendACK()):this.closeWithError(new p.CloudSDKError({errCode:p.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL,errMsg:t})),[3,3];case 3:return[2]}})})},this.handleCommonError=function(e,t){if((0,p.isRealtimeErrorMessageError)(e))switch(e.payload.msgData.code){case"CHECK_LOGIN_FAILED":case"SIGN_EXPIRED_ERROR":case"SIGN_INVALID_ERROR":case"SIGN_PARAM_INVALID":return void t.onSignError(e);default:return void t.onNotRetryableError(e)}else{if((0,p.isTimeoutError)(e))return void t.onTimeoutError(e);if((0,p.isCancelledError)(e))return void t.onCancelledError(e)}t.onUnknownError(e)},this.watchId="watchid_".concat(+new Date,"_").concat(Math.random()),this.envId=e.envId,this.collectionName=e.collectionName,this.query=e.query,this.limit=e.limit,this.orderBy=e.orderBy,this.send=e.send,this.login=e.login,this.isWSConnected=e.isWSConnected,this.onceWSConnected=e.onceWSConnected,this.getWaitExpectedTimeoutLength=e.getWaitExpectedTimeoutLength,this.onWatchStart=e.onWatchStart,this.onWatchClose=e.onWatchClose,this.debug=e.debug,this.availableRetries={INIT_WATCH:2,REBUILD_WATCH:2,CHECK_LAST:2},this.listener=new d.RealtimeListener({close:function(){t.closeWatch()},onChange:e.onChange,onError:e.onError,debug:this.debug,virtualClient:this}),this.initWatch()}return e.prototype.onMessage=function(e){var t=this;switch(this.watchStatus){case a.PAUSED:if("ERROR"!==e.msgType)return;break;case a.LOGGINGIN:case a.INITING:case a.REBUILDING:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received while ".concat(this.watchStatus));case a.CLOSED:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received when the watch has closed");case a.ERRORED:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received when the watch has ended with error")}if(this.sessionInfo)switch(this.scheduleSendACK(),e.msgType){case"NEXT_EVENT":console.warn("nextevent ".concat(e.msgData.currEvent," ignored"),e),this.handleServerEvents(e);break;case"CHECK_EVENT":this.sessionInfo.currentEventId<e.msgData.currEvent&&(this.sessionInfo.expectEventId=e.msgData.currEvent,this.clearWaitExpectedEvent(),this.waitExpectedTimeoutId=setTimeout(function(){t.rebuildWatch()},this.getWaitExpectedTimeoutLength()),console.log("[realtime] waitExpectedTimeoutLength ".concat(this.getWaitExpectedTimeoutLength())));break;case"ERROR":this.closeWithError(new p.CloudSDKError({errCode:p.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG,errMsg:"".concat(e.msgData.code," - ").concat(e.msgData.message)}));break;default:console.warn("[realtime listener] virtual client receive unexpected msg ".concat(e.msgType,": "),e)}else console.warn("[realtime listener] internal non-fatal error: sessionInfo not found while message is received.")},e.prototype.closeWithError=function(e){var t;this.watchStatus=a.ERRORED,this.clearACKSchedule(),this.listener.onError(e),this.onWatchClose(this,(null===(t=this.sessionInfo)||void 0===t?void 0:t.queryID)||""),console.log("[realtime] client closed (".concat(this.collectionName," ").concat(this.query,") (watchId ").concat(this.watchId,")"))},e.prototype.pause=function(){this.watchStatus=a.PAUSED,console.log("[realtime] client paused (".concat(this.collectionName," ").concat(this.query,") (watchId ").concat(this.watchId,")"))},e.prototype.resume=function(){return r(this,void 0,Promise,function(){var e;return o(this,function(t){switch(t.label){case 0:this.watchStatus=a.RESUMING,console.log("[realtime] client resuming with ".concat(this.sessionInfo?"REBUILD_WATCH":"INIT_WATCH"," (").concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")")),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.sessionInfo?this.rebuildWatch():this.initWatch()];case 2:return t.sent(),console.log("[realtime] client successfully resumed (".concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")")),[3,4];case 3:return e=t.sent(),console.error("[realtime] client resume failed (".concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")"),e),[3,4];case 4:return[2]}})})},e.prototype.useRetryTicket=function(e){return!!(this.availableRetries[e]&&this.availableRetries[e]>0)&&(this.availableRetries[e]-=1,console.log("[realtime] ".concat(e," use a retry ticket, now only ").concat(this.availableRetries[e]," retry left")),!0)},e.prototype.handleServerEvents=function(e){return r(this,void 0,void 0,function(){var t;return o(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.scheduleSendACK(),[4,this.handleServerEventsInternel(e)];case 1:return n.sent(),this.postHandleServerEventsValidityCheck(e),[3,3];case 2:throw t=n.sent(),console.error("[realtime listener] internal non-fatal error: handle server events failed with error: ",t),t;case 3:return[2]}})})},e.prototype.handleServerEventsInternel=function(e){return r(this,void 0,void 0,function(){var t,n,r,s,a,h,d,v,E,_,m,I;return o(this,function(b){switch(b.label){case 0:if(t=e.requestId,n=e.msgData.events,r=e.msgType,!n.length||!this.sessionInfo)return[2];s=this.sessionInfo;try{a=n.map(g)}catch(e){return this.closeWithError(new p.CloudSDKError({errCode:p.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA,errMsg:e})),[2]}h=i([],s.currentDocs,!0),d=!1,v=function(n,v){var g,_,m,I,b,y,w,S,T,C,R,A;return o(this,function(o){switch(o.label){case 0:return g=a[n],s.currentEventId>=g.id?(!a[n-1]||g.id>a[n-1].id?console.warn("[realtime] duplicate event received, cur ".concat(s.currentEventId," but got ").concat(g.id)):console.error("[realtime listener] server non-fatal error: events out of order (the latter event's id is smaller than that of the former) (requestId ".concat(t,")")),[2,"continue"]):[3,1];case 1:if(s.currentEventId!==g.id-1)return[3,2];switch(g.dataType){case"update":if(!g.doc)switch(g.queueType){case"update":case"dequeue":if(_=h.find(function(e){return e._id===g.docId}),_){if(m=(0,l.default)(_),g.updatedFields&&Object.keys(g.updatedFields).forEach(function(e){(0,c.default)(m,e,g.updatedFields[e])}),g.removedFields)for(I=0,b=g.removedFields;I<b.length;I++)y=b[I],(0,u.default)(m,y);g.doc=m}else console.error("[realtime listener] internal non-fatal server error: unexpected update dataType event where no doc is associated.");break;case"enqueue":throw S=new p.CloudSDKError({errCode:p.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="update" and queueType="enqueue" (requestId '.concat(e.requestId,")")}),E.closeWithError(S),S}break;case"replace":if(!g.doc)throw S=new p.CloudSDKError({errCode:p.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="replace" (requestId '.concat(e.requestId,")")}),E.closeWithError(S),S;break;case"remove":(w=h.find(function(e){return e._id===g.docId}))?g.doc=w:console.error("[realtime listener] internal non-fatal server error: unexpected remove event where no doc is associated.");break;case"limit":if(!g.doc)switch(g.queueType){case"dequeue":(w=h.find(function(e){return e._id===g.docId}))?g.doc=w:console.error("[realtime listener] internal non-fatal server error: unexpected limit dataType event where no doc is associated.");break;case"enqueue":throw S=new p.CloudSDKError({errCode:p.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="limit" and queueType="enqueue" (requestId '.concat(e.requestId,")")}),E.closeWithError(S),S}}switch(g.queueType){case"init":d?h.push(g.doc):(d=!0,h=[g.doc]);break;case"enqueue":h.push(g.doc);break;case"dequeue":T=h.findIndex(function(e){return e._id===g.docId}),T>-1?h.splice(T,1):console.error("[realtime listener] internal non-fatal server error: unexpected dequeue event where no doc is associated.");break;case"update":T=h.findIndex(function(e){return e._id===g.docId}),T>-1?h[T]=g.doc:console.error("[realtime listener] internal non-fatal server error: unexpected queueType update event where no doc is associated.")}return(n===v-1||a[n+1]&&a[n+1].id!==g.id)&&(C=i([],h,!0),R=a.slice(0,n+1).filter(function(e){return e.id===g.id}),E.sessionInfo.currentEventId=g.id,E.sessionInfo.currentDocs=h,A=new f.Snapshot({id:g.id,docChanges:R,docs:C,msgType:r}),E.listener.onChange(A)),[3,4];case 2:return console.warn("[realtime listener] event received is out of order, cur ".concat(E.sessionInfo.currentEventId," but got ").concat(g.id)),[4,E.rebuildWatch()];case 3:return o.sent(),[2,{value:void 0}];case 4:return[2]}})},E=this,_=0,m=a.length,b.label=1;case 1:return _<m?[5,v(_,m)]:[3,4];case 2:if("object"==typeof(I=b.sent()))return[2,I.value];b.label=3;case 3:return _++,[3,1];case 4:return[2]}})})},e.prototype.postHandleServerEventsValidityCheck=function(e){this.sessionInfo?(this.sessionInfo.expectEventId&&this.sessionInfo.currentEventId>=this.sessionInfo.expectEventId&&this.clearWaitExpectedEvent(),this.sessionInfo.currentEventId<e.msgData.currEvent&&console.warn("[realtime listener] internal non-fatal error: client eventId does not match with server event id after server event handling")):console.error("[realtime listener] internal non-fatal error: sessionInfo lost after server event handling, this should never occur")},e.prototype.clearWaitExpectedEvent=function(){this.waitExpectedTimeoutId&&(clearTimeout(this.waitExpectedTimeoutId),this.waitExpectedTimeoutId=void 0)},e}();function g(e){var t={id:e.ID,dataType:e.DataType,queueType:e.QueueType,docId:e.DocID,doc:e.Doc&&"{}"!==e.Doc?JSON.parse(e.Doc):void 0};return"update"===e.DataType&&(e.UpdatedFields&&(t.updatedFields=JSON.parse(e.UpdatedFields)),(e.removedFields||e.RemovedFields)&&(t.removedFields=JSON.parse(e.removedFields))),t}t.VirtualWebSocketClient=E},2347:function(e,t,n){"use strict";var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},r.apply(this,arguments)},o=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((r=r.apply(e,t||[])).next())})},i=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.RealtimeWebSocketClient=void 0;var s=n(4151),a=n(3994),c=n(636),u=n(2917),l=n(6511),h=n(7589),d=function(){function e(e){var t=this;this.virtualWSClient=new Set,this.queryIdClientMap=new Map,this.watchIdClientMap=new Map,this.pingFailed=0,this.pongMissed=0,this.logins=new Map,this.wsReadySubsribers=[],this.wsResponseWait=new Map,this.rttObserved=[],this.send=function(e){return o(t,void 0,Promise,function(){var t=this;return i(this,function(n){return[2,new Promise(function(n,r){o(t,void 0,void 0,function(){var t,s,a,c,l,d,f,p,v=this;return i(this,function(E){switch(E.label){case 0:s=!1,a=!1,c=function(e){s=!0,t&&clearTimeout(t),n(e)},l=function(e){a=!0,t&&clearTimeout(t),r(e)},e.timeout&&(t=setTimeout(function(){o(v,void 0,void 0,function(){return i(this,function(e){switch(e.label){case 0:return s&&a?[3,2]:[4,(0,h.sleep)(0)];case 1:e.sent(),s&&a||l(new u.TimeoutError("wsclient.send timedout")),e.label=2;case 2:return[2]}})})},e.timeout)),E.label=1;case 1:return E.trys.push([1,8,,9]),void 0===this.wsInitPromise&&null===this.wsInitPromise?[3,3]:[4,this.wsInitPromise];case 2:E.sent(),E.label=3;case 3:if(!this.ws)return l(new Error("invalid state: ws connection not exists, can not send message")),[2];if(1!==this.ws.readyState)return l(new Error("ws readyState invalid: ".concat(this.ws.readyState,", can not send message"))),[2];e.waitResponse&&(d={resolve:c,reject:l,skipOnMessage:e.skipOnMessage},this.wsResponseWait.set(e.msg.requestId,d)),E.label=4;case 4:return E.trys.push([4,6,,7]),[4,this.ws.send(JSON.stringify(e.msg))];case 5:return E.sent(),e.waitResponse||c(void 0),[3,7];case 6:return(f=E.sent())&&(l(f),e.waitResponse&&this.wsResponseWait.delete(e.msg.requestId)),[3,7];case 7:return[3,9];case 8:return p=E.sent(),l(p),[3,9];case 9:return[2]}})})})]})})},this.closeAllClients=function(e){t.virtualWSClient.forEach(function(t){t.closeWithError(e)})},this.pauseClients=function(e){(e||t.virtualWSClient).forEach(function(e){e.pause()})},this.resumeClients=function(e){(e||t.virtualWSClient).forEach(function(e){e.resume()})},this.initWebSocketConnection=function(e,n){return void 0===n&&(n=t.maxReconnect),o(t,void 0,Promise,function(){var t=this;return i(this,function(r){switch(r.label){case 0:if(e&&this.reconnectState)return[2];if(e&&(this.reconnectState=!0),void 0!==this.wsInitPromise&&null!==this.wsInitPromise)return[2,this.wsInitPromise];e&&this.pauseClients(),this.close(c.CloseEventCode.ReconnectWebSocket),this.wsInitPromise=new Promise(function(r,s){o(t,void 0,void 0,function(){var t,o,a=this;return i(this,function(i){switch(i.label){case 0:return i.trys.push([0,6,,11]),[4,this.getWsSign()];case 1:return t=i.sent(),[4,new Promise(function(e){var n=t.wsUrl||"wss://tcb-ws.tencentcloudapi.com",r=(0,l.getWsClass)();a.ws=r?new r(n):new WebSocket(n),e(void 0)})];case 2:return i.sent(),this.ws.connect?[4,this.ws.connect()]:[3,4];case 3:i.sent(),i.label=4;case 4:return[4,this.initWebSocketEvent()];case 5:return i.sent(),r(),e&&(this.resumeClients(),this.reconnectState=!1),[3,11];case 6:return o=i.sent(),console.error("[realtime] initWebSocketConnection connect fail",o),n>0?(this.wsInitPromise=void 0,[4,(0,h.sleep)(this.reconnectInterval)]):[3,9];case 7:i.sent(),e&&(this.reconnectState=!1),i.label=8;case 8:return r(this.initWebSocketConnection(e,n-1)),[3,10];case 9:s(o),e&&this.closeAllClients(new u.CloudSDKError({errCode:u.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL,errMsg:o})),i.label=10;case 10:return[3,11];case 11:return[2]}})})}),r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,this.wsInitPromise];case 2:return r.sent(),this.wsReadySubsribers.forEach(function(e){return(0,e.resolve)()}),[3,5];case 3:return r.sent(),this.wsReadySubsribers.forEach(function(e){return(0,e.reject)()}),[3,5];case 4:return this.wsInitPromise=void 0,this.wsReadySubsribers=[],[7];case 5:return[2]}})})},this.initWebSocketEvent=function(){return new Promise(function(e,n){if(!t.ws)throw new Error("can not initWebSocketEvent, ws not exists");var r=!1;t.ws.onopen=function(t){console.warn("[realtime] ws event: open",t),r=!0,e()},t.ws.onerror=function(e){t.logins=new Map,r?(console.error("[realtime] ws event: error",e),t.clearHeartbeat(),t.virtualWSClient.forEach(function(t){return t.closeWithError(new u.CloudSDKError({errCode:u.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR,errMsg:e}))})):(console.error("[realtime] ws open failed with ws event: error",e),n(e))},t.ws.onclose=function(e){switch(console.warn("[realtime] ws event: close",e),t.logins=new Map,t.clearHeartbeat(),e.code){case c.CloseEventCode.ReconnectWebSocket:case c.CloseEventCode.NoRealtimeListeners:break;case c.CloseEventCode.HeartbeatPingError:case c.CloseEventCode.HeartbeatPongTimeoutError:case c.CloseEventCode.NormalClosure:case c.CloseEventCode.AbnormalClosure:t.maxReconnect>0?t.initWebSocketConnection(!0,t.maxReconnect):t.closeAllClients((0,c.getWSCloseError)(e.code));break;case c.CloseEventCode.NoAuthentication:t.closeAllClients((0,c.getWSCloseError)(e.code,e.reason));break;default:t.maxReconnect>0?t.initWebSocketConnection(!0,t.maxReconnect):t.closeAllClients((0,c.getWSCloseError)(e.code))}},t.ws.onmessage=function(e){var n,r,o=(null===(n=e.data)||void 0===n?void 0:n.data)||e.data;t.heartbeat();try{r="string"==typeof o?JSON.parse(o):o}catch(e){throw new Error("[realtime] onMessage parse res.data error: ".concat(e))}if("ERROR"===r.msgType){var i=null;t.virtualWSClient.forEach(function(e){e.watchId===r.watchId&&(i=e)}),i&&i.listener.onError(r)}var s=t.wsResponseWait.get(r.requestId);if(s){try{"ERROR"===r.msgType?s.reject(new u.RealtimeErrorMessageError(r)):s.resolve(r)}catch(e){console.error("ws onMessage responseWaitSpec.resolve(msg) errored:",e)}finally{t.wsResponseWait.delete(r.requestId)}if(s.skipOnMessage)return}if("PONG"!==r.msgType){var a=r.watchId&&t.watchIdClientMap.get(r.watchId);if(a)a.onMessage(r);else switch(console.error("[realtime] no realtime listener found responsible for watchId ".concat(r.watchId,": "),r),r.msgType){case"INIT_EVENT":case"NEXT_EVENT":case"CHECK_EVENT":(a=t.queryIdClientMap.get(r.msgData.queryID))&&a.onMessage(r);break;default:for(var c=0,l=Array.from(t.watchIdClientMap.entries());c<l.length;c++){l[c][1].onMessage(r);break}}}else if(t.lastPingSendTS){var h=Date.now()-t.lastPingSendTS;if(h>1e4)return void console.warn("[realtime] untrusted rtt observed: ".concat(h));t.rttObserved.length>=3&&t.rttObserved.splice(0,t.rttObserved.length-3+1),t.rttObserved.push(h)}},t.heartbeat()})},this.isWSConnected=function(){return Boolean(t.ws&&1===t.ws.readyState)},this.onceWSConnected=function(){return o(t,void 0,Promise,function(){var e=this;return i(this,function(t){return this.isWSConnected()?[2]:null!==this.wsInitPromise&&void 0!==this.wsInitPromise?[2,this.wsInitPromise]:[2,new Promise(function(t,n){e.wsReadySubsribers.push({resolve:t,reject:n})})]})})},this.webLogin=function(e,n){return o(t,void 0,Promise,function(){var t,r,s,c,u,h,d,f,p=this;return i(this,function(v){switch(v.label){case 0:if(!n)if(e){if(t=this.logins.get(e)){if(t.loggedIn&&t.loginResult)return[2,t.loginResult];if(null!==t.loggingInPromise&&void 0!==t.loggingInPromise)return[2,t.loggingInPromise]}}else if(null!==(null==(r=this.logins.get(""))?void 0:r.loggingInPromise)&&void 0!==(null==r?void 0:r.loggingInPromise))return[2,r.loggingInPromise];s=new Promise(function(e,t){o(p,void 0,void 0,function(){var n,r,o,s,c;return i(this,function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),[4,this.getWsSign()];case 1:return n=i.sent(),r={envId:n.envId||"",accessToken:"",referrer:"web",sdkVersion:"",dataVersion:""},o={watchId:void 0,requestId:(0,a.genRequestId)(),msgType:"LOGIN",msgData:r,exMsgData:{runtime:(0,l.getRuntime)(),signStr:n.signStr,secretVersion:n.secretVersion}},[4,this.send({msg:o,waitResponse:!0,skipOnMessage:!0,timeout:5e3})];case 2:return(s=i.sent()).msgData.code?t(new Error("".concat(s.msgData.code," ").concat(s.msgData.message))):e({envId:n.envId}),[3,4];case 3:return c=i.sent(),t(c),[3,4];case 4:return[2]}})})}),c=e&&this.logins.get(e),u=Date.now(),c?(c.loggedIn=!1,c.loggingInPromise=s,c.loginStartTS=u):(c={loggedIn:!1,loggingInPromise:s,loginStartTS:u},this.logins.set(e||"",c)),v.label=1;case 1:return v.trys.push([1,3,,4]),[4,s];case 2:if(h=v.sent(),(d=e&&this.logins.get(e))&&d===c&&d.loginStartTS===u)return c.loggedIn=!0,c.loggingInPromise=void 0,c.loginStartTS=void 0,c.loginResult=h,[2,h];if(d){if(d.loggedIn&&d.loginResult)return[2,d.loginResult];if(null!==d.loggingInPromise&&void 0!==d.loggingInPromise)return[2,d.loggingInPromise];throw new Error("ws unexpected login info")}throw new Error("ws login info reset");case 3:throw f=v.sent(),c.loggedIn=!1,c.loggingInPromise=void 0,c.loginStartTS=void 0,c.loginResult=void 0,f;case 4:return[2]}})})},this.getWsSign=function(){return o(t,void 0,Promise,function(){var e,t,n,r,o,s,a;return i(this,function(i){switch(i.label){case 0:return this.wsSign&&this.wsSign.expiredTs>Date.now()?[2,this.wsSign]:(e=Date.now()+6e4,[4,this.context.appConfig.request.send("auth.wsWebSign",{runtime:(0,l.getRuntime)()})]);case 1:if((t=i.sent()).code)throw new Error("[tcb-js-sdk] 获取实时数据推送登录票据失败: ".concat(t.code));if(t.data)return n=t.data,r=n.signStr,o=n.wsUrl,s=n.secretVersion,a=n.envId,[2,{signStr:r,wsUrl:o,secretVersion:s,envId:a,expiredTs:e}];throw new Error("[tcb-js-sdk] 获取实时数据推送登录票据失败")}})})},this.getWaitExpectedTimeoutLength=function(){return t.rttObserved.length?t.rttObserved.reduce(function(e,t){return e+t})/t.rttObserved.length*1.5:5e3},this.ping=function(){return o(t,void 0,void 0,function(){var e;return i(this,function(t){switch(t.label){case 0:return e={watchId:void 0,requestId:(0,a.genRequestId)(),msgType:"PING",msgData:null},[4,this.send({msg:e})];case 1:return t.sent(),[2]}})})},this.onWatchStart=function(e,n){t.queryIdClientMap.set(n,e)},this.onWatchClose=function(e,n){n&&t.queryIdClientMap.delete(n),t.watchIdClientMap.delete(e.watchId),t.virtualWSClient.delete(e),t.virtualWSClient.size||t.close(c.CloseEventCode.NoRealtimeListeners)},this.maxReconnect=e.maxReconnect||5,this.reconnectInterval=e.reconnectInterval||1e4,this.context=e.context}return e.prototype.clearHeartbeat=function(){this.pingTimeoutId&&clearTimeout(this.pingTimeoutId),this.pongTimeoutId&&clearTimeout(this.pongTimeoutId)},e.prototype.close=function(e){this.clearHeartbeat(),this.ws&&(this.ws.close(e,c.CLOSE_EVENT_CODE_INFO[e].name),this.ws=void 0)},e.prototype.watch=function(e){this.ws||void 0!==this.wsInitPromise&&null!==this.wsInitPromise||this.initWebSocketConnection(!1);var t=new s.VirtualWebSocketClient(r(r({},e),{send:this.send,login:this.webLogin,isWSConnected:this.isWSConnected,onceWSConnected:this.onceWSConnected,getWaitExpectedTimeoutLength:this.getWaitExpectedTimeoutLength,onWatchStart:this.onWatchStart,onWatchClose:this.onWatchClose,debug:!0}));return this.virtualWSClient.add(t),this.watchIdClientMap.set(t.watchId,t),t.listener},e.prototype.heartbeat=function(e){var t=this;this.clearHeartbeat(),this.pingTimeoutId=setTimeout(function(){o(t,void 0,void 0,function(){var e=this;return i(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),this.ws&&1===this.ws.readyState?(this.lastPingSendTS=Date.now(),[4,this.ping()]):[2];case 1:return t.sent(),this.pingFailed=0,this.pongTimeoutId=setTimeout(function(){console.error("pong timed out"),e.pongMissed<2?(e.pongMissed+=1,e.heartbeat(!0)):e.initWebSocketConnection(!0)},this.context.appConfig.realtimePongWaitTimeout),[3,3];case 2:return t.sent(),this.pingFailed<2?(this.pingFailed+=1,this.heartbeat()):this.close(c.CloseEventCode.HeartbeatPingError),[3,3];case 3:return[2]}})})},e?0:this.context.appConfig.realtimePingInterval)},e}();t.RealtimeWebSocketClient=d},636:function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getWSCloseError=t.CloseEventCode=t.CLOSE_EVENT_CODE_INFO=void 0;var r,o=n(2917);t.CLOSE_EVENT_CODE_INFO={1e3:{code:1e3,name:"Normal Closure",description:"Normal closure; the connection successfully completed whatever purpose for which it was created."},1001:{code:1001,name:"Going Away",description:"The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection."},1002:{code:1002,name:"Protocol Error",description:"The endpoint is terminating the connection due to a protocol error."},1003:{code:1003,name:"Unsupported Data",description:"The connection is being terminated because the endpoint received data of a type it cannot accept (for example, a text-only endpoint received binary data)."},1005:{code:1005,name:"No Status Received",description:"Indicates that no status code was provided even though one was expected."},1006:{code:1006,name:"Abnormal Closure",description:"Used to indicate that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected."},1007:{code:1007,name:"Invalid frame payload data",description:"The endpoint is terminating the connection because a message was received that contained inconsistent data (e.g., non-UTF-8 data within a text message)."},1008:{code:1008,name:"Policy Violation",description:"The endpoint is terminating the connection because it received a message that violates its policy. This is a generic status code, used when codes 1003 and 1009 are not suitable."},1009:{code:1009,name:"Message too big",description:"The endpoint is terminating the connection because a data frame was received that is too large."},1010:{code:1010,name:"Missing Extension",description:"The client is terminating the connection because it expected the server to negotiate one or more extension, but the server didn't."},1011:{code:1011,name:"Internal Error",description:"The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request."},1012:{code:1012,name:"Service Restart",description:"The server is terminating the connection because it is restarting."},1013:{code:1013,name:"Try Again Later",description:"The server is terminating the connection due to a temporary condition, e.g. it is overloaded and is casting off some of its clients."},1014:{code:1014,name:"Bad Gateway",description:"The server was acting as a gateway or proxy and received an invalid response from the upstream server. This is similar to 502 HTTP Status Code."},1015:{code:1015,name:"TLS Handshake",description:"Indicates that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified)."},3e3:{code:3e3,name:"Reconnect WebSocket",description:"The client is terminating the connection because it wants to reconnect"},3001:{code:3001,name:"No Realtime Listeners",description:"The client is terminating the connection because no more realtime listeners exist"},3002:{code:3002,name:"Heartbeat Ping Error",description:"The client is terminating the connection due to its failure in sending heartbeat messages"},3003:{code:3003,name:"Heartbeat Pong Timeout Error",description:"The client is terminating the connection because no heartbeat response is received from the server"},3050:{code:3050,name:"Server Close",description:"The client is terminating the connection because no heartbeat response is received from the server"}},(r=t.CloseEventCode||(t.CloseEventCode={}))[r.NormalClosure=1e3]="NormalClosure",r[r.GoingAway=1001]="GoingAway",r[r.ProtocolError=1002]="ProtocolError",r[r.UnsupportedData=1003]="UnsupportedData",r[r.NoStatusReceived=1005]="NoStatusReceived",r[r.AbnormalClosure=1006]="AbnormalClosure",r[r.InvalidFramePayloadData=1007]="InvalidFramePayloadData",r[r.PolicyViolation=1008]="PolicyViolation",r[r.MessageTooBig=1009]="MessageTooBig",r[r.MissingExtension=1010]="MissingExtension",r[r.InternalError=1011]="InternalError",r[r.ServiceRestart=1012]="ServiceRestart",r[r.TryAgainLater=1013]="TryAgainLater",r[r.BadGateway=1014]="BadGateway",r[r.TLSHandshake=1015]="TLSHandshake",r[r.ReconnectWebSocket=3e3]="ReconnectWebSocket",r[r.NoRealtimeListeners=3001]="NoRealtimeListeners",r[r.HeartbeatPingError=3002]="HeartbeatPingError",r[r.HeartbeatPongTimeoutError=3003]="HeartbeatPongTimeoutError",r[r.NoAuthentication=3050]="NoAuthentication",t.getWSCloseError=function(e,n){var r=t.CLOSE_EVENT_CODE_INFO[e],i=r?"".concat(r.name,", code ").concat(e,", reason ").concat(n||r.description):"code ".concat(e);return new o.CloudSDKError({errCode:o.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED,errMsg:i})}},9515:function(e,t,n){var r=n(8761)(n(7772),"DataView");e.exports=r},9612:function(e,t,n){var r=n(2118),o=n(6909),i=n(8138),s=n(4174),a=n(7942);function c(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}c.prototype.clear=r,c.prototype.delete=o,c.prototype.get=i,c.prototype.has=s,c.prototype.set=a,e.exports=c},235:function(e,t,n){var r=n(3945),o=n(1846),i=n(8028),s=n(2344),a=n(4769);function c(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}c.prototype.clear=r,c.prototype.delete=o,c.prototype.get=i,c.prototype.has=s,c.prototype.set=a,e.exports=c},326:function(e,t,n){var r=n(8761)(n(7772),"Map");e.exports=r},6738:function(e,t,n){var r=n(2411),o=n(6417),i=n(6928),s=n(9493),a=n(4150);function c(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}c.prototype.clear=r,c.prototype.delete=o,c.prototype.get=i,c.prototype.has=s,c.prototype.set=a,e.exports=c},2760:function(e,t,n){var r=n(8761)(n(7772),"Promise");e.exports=r},2143:function(e,t,n){var r=n(8761)(n(7772),"Set");e.exports=r},6571:function(e,t,n){var r=n(235),o=n(5243),i=n(2858),s=n(4417),a=n(8605),c=n(1418);function u(e){var t=this.__data__=new r(e);this.size=t.size}u.prototype.clear=o,u.prototype.delete=i,u.prototype.get=s,u.prototype.has=a,u.prototype.set=c,e.exports=u},857:function(e,t,n){var r=n(7772).Symbol;e.exports=r},9162:function(e,t,n){var r=n(7772).Uint8Array;e.exports=r},3215:function(e,t,n){var r=n(8761)(n(7772),"WeakMap");e.exports=r},2517:function(e){e.exports=function(e,t){for(var n=-1,r=null==e?0:e.length;++n<r&&!1!==t(e[n],n,e););return e}},7552:function(e){e.exports=function(e,t){for(var n=-1,r=null==e?0:e.length,o=0,i=[];++n<r;){var s=e[n];t(s,n,e)&&(i[o++]=s)}return i}},1634:function(e,t,n){var r=n(6473),o=n(9631),i=n(6152),s=n(3226),a=n(9045),c=n(7598),u=Object.prototype.hasOwnProperty;e.exports=function(e,t){var n=i(e),l=!n&&o(e),h=!n&&!l&&s(e),d=!n&&!l&&!h&&c(e),f=n||l||h||d,p=f?r(e.length,String):[],v=p.length;for(var E in e)!t&&!u.call(e,E)||f&&("length"==E||h&&("offset"==E||"parent"==E)||d&&("buffer"==E||"byteLength"==E||"byteOffset"==E)||a(E,v))||p.push(E);return p}},343:function(e){e.exports=function(e,t){for(var n=-1,r=null==e?0:e.length,o=Array(r);++n<r;)o[n]=t(e[n],n,e);return o}},5067:function(e){e.exports=function(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e}},91:function(e,t,n){var r=n(3940),o=n(1225),i=Object.prototype.hasOwnProperty;e.exports=function(e,t,n){var s=e[t];i.call(e,t)&&o(s,n)&&(void 0!==n||t in e)||r(e,t,n)}},2218:function(e,t,n){var r=n(1225);e.exports=function(e,t){for(var n=e.length;n--;)if(r(e[n][0],t))return n;return-1}},7993:function(e,t,n){var r=n(752),o=n(249);e.exports=function(e,t){return e&&r(t,o(t),e)}},5906:function(e,t,n){var r=n(752),o=n(8582);e.exports=function(e,t){return e&&r(t,o(t),e)}},3940:function(e,t,n){var r=n(3043);e.exports=function(e,t,n){"__proto__"==t&&r?r(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}},8874:function(e,t,n){var r=n(6571),o=n(2517),i=n(91),s=n(7993),a=n(5906),c=n(2175),u=n(1522),l=n(7680),h=n(9987),d=n(3483),f=n(6939),p=n(940),v=n(9917),E=n(8222),g=n(8725),_=n(6152),m=n(3226),I=n(4714),b=n(9259),y=n(3679),w=n(249),S=n(8582),T="[object Arguments]",C="[object Function]",R="[object Object]",A={};A[T]=A["[object Array]"]=A["[object ArrayBuffer]"]=A["[object DataView]"]=A["[object Boolean]"]=A["[object Date]"]=A["[object Float32Array]"]=A["[object Float64Array]"]=A["[object Int8Array]"]=A["[object Int16Array]"]=A["[object Int32Array]"]=A["[object Map]"]=A["[object Number]"]=A[R]=A["[object RegExp]"]=A["[object Set]"]=A["[object String]"]=A["[object Symbol]"]=A["[object Uint8Array]"]=A["[object Uint8ClampedArray]"]=A["[object Uint16Array]"]=A["[object Uint32Array]"]=!0,A["[object Error]"]=A[C]=A["[object WeakMap]"]=!1,e.exports=function e(t,n,D,x,O,N){var W,L=1&n,j=2&n,P=4&n;if(D&&(W=O?D(t,x,O,N):D(t)),void 0!==W)return W;if(!b(t))return t;var M=_(t);if(M){if(W=v(t),!L)return u(t,W)}else{var k=p(t),K=k==C||"[object GeneratorFunction]"==k;if(m(t))return c(t,L);if(k==R||k==T||K&&!O){if(W=j||K?{}:g(t),!L)return j?h(t,a(W,t)):l(t,s(W,t))}else{if(!A[k])return O?t:{};W=E(t,k,L)}}N||(N=new r);var q=N.get(t);if(q)return q;N.set(t,W),y(t)?t.forEach(function(r){W.add(e(r,n,D,r,t,N))}):I(t)&&t.forEach(function(r,o){W.set(o,e(r,n,D,o,t,N))});var B=M?void 0:(P?j?f:d:j?S:w)(t);return o(B||t,function(r,o){B&&(r=t[o=r]),i(W,o,e(r,n,D,o,t,N))}),W}},9413:function(e,t,n){var r=n(9259),o=Object.create,i=function(){function e(){}return function(t){if(!r(t))return{};if(o)return o(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}();e.exports=i},3324:function(e,t,n){var r=n(7297),o=n(3812);e.exports=function(e,t){for(var n=0,i=(t=r(t,e)).length;null!=e&&n<i;)e=e[o(t[n++])];return n&&n==i?e:void 0}},1897:function(e,t,n){var r=n(5067),o=n(6152);e.exports=function(e,t,n){var i=t(e);return o(e)?i:r(i,n(e))}},3366:function(e,t,n){var r=n(857),o=n(2107),i=n(7157),s=r?r.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":s&&s in Object(e)?o(e):i(e)}},5183:function(e,t,n){var r=n(3366),o=n(5125);e.exports=function(e){return o(e)&&"[object Arguments]"==r(e)}},4511:function(e,t,n){var r=n(940),o=n(5125);e.exports=function(e){return o(e)&&"[object Map]"==r(e)}},6840:function(e,t,n){var r=n(1049),o=n(7394),i=n(9259),s=n(7035),a=/^\[object .+?Constructor\]$/,c=Function.prototype,u=Object.prototype,l=c.toString,h=u.hasOwnProperty,d=RegExp("^"+l.call(h).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");e.exports=function(e){return!(!i(e)||o(e))&&(r(e)?d:a).test(s(e))}},8436:function(e,t,n){var r=n(940),o=n(5125);e.exports=function(e){return o(e)&&"[object Set]"==r(e)}},5522:function(e,t,n){var r=n(3366),o=n(1158),i=n(5125),s={};s["[object Float32Array]"]=s["[object Float64Array]"]=s["[object Int8Array]"]=s["[object Int16Array]"]=s["[object Int32Array]"]=s["[object Uint8Array]"]=s["[object Uint8ClampedArray]"]=s["[object Uint16Array]"]=s["[object Uint32Array]"]=!0,s["[object Arguments]"]=s["[object Array]"]=s["[object ArrayBuffer]"]=s["[object Boolean]"]=s["[object DataView]"]=s["[object Date]"]=s["[object Error]"]=s["[object Function]"]=s["[object Map]"]=s["[object Number]"]=s["[object Object]"]=s["[object RegExp]"]=s["[object Set]"]=s["[object String]"]=s["[object WeakMap]"]=!1,e.exports=function(e){return i(e)&&o(e.length)&&!!s[r(e)]}},6411:function(e,t,n){var r=n(6001),o=n(4248),i=Object.prototype.hasOwnProperty;e.exports=function(e){if(!r(e))return o(e);var t=[];for(var n in Object(e))i.call(e,n)&&"constructor"!=n&&t.push(n);return t}},8390:function(e,t