@sqlitecloud/drivers 0.0.39 → 0.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.sqlitecloud=t():e.sqlitecloud=t()}(this,(()=>(()=>{var e={593:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SQLiteCloudTlsConnection=void 0;const s=n(906),o=n(480),i=n(1),a=n(73),c=n(1),l=r(n(761)),u=r(n(59));class h extends o.SQLiteCloudConnection{get connected(){return!!this.socket}connectTransport(e,t){console.assert(!this.connected,"Connection already established");const n=e=>{this.socket&&(this.socket.removeAllListeners("data"),this.socket.removeAllListeners("error"),this.socket.removeAllListeners("close"),e&&this.close()),null==t||t.call(this,e)};this.config=e;const r=(0,a.getInitializationCommands)(e);if(e.insecure){const s={host:e.host,port:e.port};this.socket=l.default.connect(s,(()=>{console.warn(`TlsConnection.connectTransport - connected to ${e.host}:${e.port} using insecure protocol`),console.assert(this.socket,"Connection already closed"),this.transportCommands(r,(e=>{e&&this.socket&&this.close(),t&&(null==t||t.call(this,e),t=void 0),n(e)}))}))}else this.socket=u.default.connect(this.config.port,this.config.host,this.config.tlsOptions,(()=>{const e=this.socket;if(null==e?void 0:e.authorized){if(null===this.socket)return void n(new s.SQLiteCloudError("Connection was closed before it was done opening"));console.assert(this.socket,"Connection already closed"),this.transportCommands(r,(e=>{e&&this.socket&&this.close(),t&&(null==t||t.call(this,e),t=void 0),n(e)}))}else{const t=(0,a.anonimizeError)(e.authorizationError);console.error("Connection was not authorized",t),this.close(),n(new s.SQLiteCloudError("Connection was not authorized",{cause:t}))}}));return this.socket.on("close",(()=>{this.socket=null,n(new s.SQLiteCloudError("Connection was closed"))})),this.socket.once("error",(e=>{console.error("Connection error",e),n(new s.SQLiteCloudError("Connection error",{cause:e}))})),this}transportCommands(e,t){var n,r,o;if(!this.socket)return null==t||t.call(this,new s.SQLiteCloudError("Connection not established",{errorCode:"ERR_CONNECTION_NOT_ESTABLISHED"})),this;e=(0,i.formatCommand)(e);let l=Buffer.alloc(0);const u=[];let h;const d=(e,n)=>{clearTimeout(h),this.socket&&(this.socket.removeAllListeners("data"),this.socket.removeAllListeners("error"),this.socket.removeAllListeners("close")),t&&(null==t||t.call(this,e,n),t=void 0)},f=e=>{var t,n;try{let r=0===l.length?e.subarray(0,1).toString():l.subarray(0,1).toString("utf8");if(l=Buffer.concat([l,e]),(0,i.hasCommandLength)(r)){const e=(0,i.parseCommandLength)(l);if(l.length-l.indexOf(" ")-1>=e){if(null===(t=this.config)||void 0===t?void 0:t.verbose){let e=l.toString("utf8");e.length>1e3&&(e=e.substring(0,100)+"..."+e.substring(e.length-40))}if(r===i.CMD_COMPRESSED&&({buffer:l,dataType:r}=(0,i.decompressBuffer)(l)),r!==i.CMD_ROWSET_CHUNK){null===(n=this.socket)||void 0===n||n.off("data",f);const{data:e}=(0,i.popData)(l);d(null,e)}else if((0,i.bufferEndsWith)(l,i.ROWSET_CHUNKS_END)){u.push(l);const e=(0,c.parseRowsetChunks)(u);null==d||d.call(this,null,e)}else u.push(l),l=Buffer.alloc(0)}}else if(" "==l.subarray(l.length-1,l.length).toString("utf8")){const{data:e}=(0,i.popData)(l);d(null,e)}}catch(e){console.assert(e instanceof Error),e instanceof Error&&d(e)}};return null===(n=this.socket)||void 0===n||n.once("close",(()=>{d(new s.SQLiteCloudError("Connection was closed",{cause:(0,a.anonimizeCommand)(e)}))})),null===(r=this.socket)||void 0===r||r.write(e,"utf8",(()=>{var t,n;h=setTimeout((()=>{const t=new s.SQLiteCloudError("Request timed out",{cause:(0,a.anonimizeCommand)(e)});d(t)}),null===(t=this.config)||void 0===t?void 0:t.timeout),null===(n=this.socket)||void 0===n||n.on("data",f)})),null===(o=this.socket)||void 0===o||o.once("error",(e=>{console.error("Socket error",e),this.close(),d(new s.SQLiteCloudError("Socket error",{cause:(0,a.anonimizeError)(e)}))})),this}close(){return console.assert(null!==this.socket,"TlsConnection.close - connection already closed"),this.operations.clear(),this.socket&&(this.socket.destroy(),this.socket=null),this.socket=void 0,this}}t.SQLiteCloudTlsConnection=h,t.default=h},363:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SQLiteCloudWebsocketConnection=void 0;const r=n(906),s=n(825),o=n(480),i=n(46);class a extends o.SQLiteCloudConnection{get connected(){return!!this.socket}connectTransport(e,t){var n;try{if(console.assert(!this.connected,"Connection already established"),!this.socket){this.config=e;const t=this.config.connectionString,r=(null===(n=this.config)||void 0===n?void 0:n.gatewayUrl)||`ws://${this.config.host}:4000`;this.socket=(0,i.io)(r,{auth:{token:t}})}null==t||t.call(this,null)}catch(e){null==t||t.call(this,e)}return this}transportCommands(e,t){return this.socket?(this.socket.emit("v1/sql",{sql:e,row:"array"},(e=>{if(null==e?void 0:e.error){const n=new r.SQLiteCloudError(e.error.detail,Object.assign({},e.error));null==t||t.call(this,n)}else{const{data:n,metadata:r}=e;if(n&&r&&void 0!==r.numberOfRows&&void 0!==r.numberOfColumns&&void 0!==r.columns){console.assert(Array.isArray(n),"SQLiteCloudWebsocketConnection.transportCommands - data is not an array");const e=new s.SQLiteCloudRowset(r,n.flat());return void(null==t||t.call(this,null,e))}null==t||t.call(this,null,null==e?void 0:e.data)}})),this):(null==t||t.call(this,new r.SQLiteCloudError("Connection not established",{errorCode:"ERR_CONNECTION_NOT_ESTABLISHED"})),this)}close(){var e;return console.assert(null!==this.socket,"SQLiteCloudWebsocketConnection.close - connection already closed"),this.socket&&(null===(e=this.socket)||void 0===e||e.close(),this.socket=void 0),this.operations.clear(),this.socket=void 0,this}}t.SQLiteCloudWebsocketConnection=a,t.default=a},480:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SQLiteCloudConnection=void 0;const r=n(906),s=n(73),o=n(39),i=n(73);t.SQLiteCloudConnection=class{constructor(e,t){this.operations=new o.OperationsQueue,this.config="string"==typeof e?(0,s.validateConfiguration)({connectionString:e}):(0,s.validateConfiguration)(e),this.connect(t)}connect(e){return this.operations.enqueue((t=>{this.connectTransport(this.config,(n=>{n&&(console.error(`SQLiteCloudConnection.connect - error connecting ${this.config.host}:${this.config.port} ${n.toString()}`,n),this.close()),null==e||e.call(this,n||null),t(n)}))})),this}log(e,...t){this.config.verbose&&(e=(0,i.anonimizeCommand)(e),console.log(`${(new Date).toISOString()} ${this.config.clientId}: ${e}`,...t))}verbose(){this.config.verbose=!0}sendCommands(e,t){return this.operations.enqueue((n=>{if(!this.connected){const e=new r.SQLiteCloudError("Connection not established",{errorCode:"ERR_CONNECTION_NOT_ESTABLISHED"});null==t||t.call(this,e),n(e)}this.transportCommands(e,((e,r)=>{null==t||t.call(this,e,r),n(e)}))})),this}}},751:function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var s=Object.getOwnPropertyDescriptor(t,n);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,s)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),s=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return s(t,e),t},i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(s,o){function i(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Database=void 0;const c=n(825),l=n(906),u=n(73),h=n(880),d=a(n(729)),f=n(73);class p extends d.default{constructor(e,t,n){super(),this.connections=[],this.config="string"==typeof e?{connectionString:e}:e,"function"==typeof t&&(n=t,t=void 0),this.getConnection(((e,t)=>{n&&n.call(this,e)}))}getConnection(e){var t,r,s;(null===(t=this.connections)||void 0===t?void 0:t.length)>0?null==e||e.call(this,null,this.connections[0]):f.isBrowser||(null===(r=this.config)||void 0===r?void 0:r.useWebsocket)||(null===(s=this.config)||void 0===s?void 0:s.gatewayUrl)?Promise.resolve().then((()=>o(n(363)))).then((t=>{this.connections.push(new t.default(this.config,(t=>{t?this.handleError(this.connections[0],t,e):(console.assert,null==e||e.call(this,null,this.connections[0]),this.emitEvent("open"))})))})).catch((t=>{this.handleError(null,t,e)})):Promise.resolve().then((()=>o(n(593)))).then((t=>{this.connections.push(new t.default(this.config,(t=>{t?this.handleError(this.connections[0],t,e):(console.assert,null==e||e.call(this,null,this.connections[0]),this.emitEvent("open"))})))})).catch((t=>{this.handleError(null,t,e)}))}handleError(e,t,n){e&&(this.connections=this.connections.filter((t=>t!==e)),e.close()),n?n.call(this,t):this.emitEvent("error",t)}processContext(e){if(e&&Array.isArray(e)&&e.length>0&&e[0]===l.SQLiteCloudArrayType.ARRAY_TYPE_SQLITE_EXEC)return{lastID:e[2],changes:e[3],totalChanges:e[4],finalized:e[5]}}emitEvent(e,...t){setTimeout((()=>{this.emit(e,...t)}),0)}getConfiguration(){return JSON.parse(JSON.stringify(this.config))}verbose(){this.config.verbose=!0;for(const e of this.connections)e.verbose();return this}configure(e,t){return this}run(e,...t){const{args:n,callback:r}=(0,u.popCallback)(t),s=(null==n?void 0:n.length)>0?(0,u.prepareSql)(e,...n):e;return this.getConnection(((e,t)=>{e||!t?this.handleError(null,e,r):t.sendCommands(s,((e,n)=>{if(e)this.handleError(t,e,r);else{const e=this.processContext(n);null==r||r.call(e||this,null,e?void 0:n)}}))})),this}get(e,...t){const{args:n,callback:r}=(0,u.popCallback)(t),s=(null==n?void 0:n.length)>0?(0,u.prepareSql)(e,...n):e;return this.getConnection(((e,t)=>{e||!t?this.handleError(null,e,r):t.sendCommands(s,((e,n)=>{e?this.handleError(t,e,r):n&&n instanceof c.SQLiteCloudRowset&&n.length>0?null==r||r.call(this,null,n[0]):null==r||r.call(this,null)}))})),this}all(e,...t){const{args:n,callback:r}=(0,u.popCallback)(t),s=(null==n?void 0:n.length)>0?(0,u.prepareSql)(e,...n):e;return this.getConnection(((e,t)=>{e||!t?this.handleError(null,e,r):t.sendCommands(s,((e,n)=>{e?this.handleError(t,e,r):n&&n instanceof c.SQLiteCloudRowset?null==r||r.call(this,null,n):null==r||r.call(this,null)}))})),this}each(e,...t){const{args:n,callback:r,complete:s}=(0,u.popCallback)(t),o=(null==n?void 0:n.length)>0?(0,u.prepareSql)(e,...n):e;return this.getConnection(((e,t)=>{e||!t?this.handleError(null,e,r):t.sendCommands(o,((e,n)=>{if(e)this.handleError(t,e,r);else if(n&&n instanceof c.SQLiteCloudRowset){if(r)for(const e of n)r.call(this,null,e);s&&s.call(this,null,n.numberOfRows)}else null==r||r.call(this,new l.SQLiteCloudError("Invalid rowset"))}))})),this}prepare(e,...t){const{args:n,callback:r}=(0,u.popCallback)(t);return new h.Statement(this,e,...n,r)}exec(e,t){return this.getConnection(((n,r)=>{n||!r?this.handleError(null,n,t):r.sendCommands(e,((e,n)=>{if(e)this.handleError(r,e,t);else{const e=this.processContext(n);null==t||t.call(e||this,null)}}))})),this}close(e){var t;if((null===(t=this.connections)||void 0===t?void 0:t.length)>0)for(const e of this.connections)e.close();null==e||e.call(this,null),this.emitEvent("close")}loadExtension(e,t){return t?t.call(this,new Error("Database.loadExtension - Not implemented")):this.emitEvent("error",new Error("Database.loadExtension - Not implemented")),this}interrupt(){}sql(e,...t){return i(this,void 0,void 0,(function*(){let n="";if(Array.isArray(e)&&"raw"in e)e.forEach(((e,r)=>{n+=e+(r<t.length?"?":"")})),n=(0,u.prepareSql)(n,...t);else{if("string"!=typeof e)throw new Error("Invalid sql");n=(null==t?void 0:t.length)>0?(0,u.prepareSql)(e,...t):e}return new Promise(((e,t)=>{this.getConnection(((r,s)=>{r||!s?t(r):s.sendCommands(n,((n,r)=>{if(n)t(n);else{const t=this.processContext(r);e(t||r)}}))}))}))}))}}t.Database=p},1:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.formatCommand=t.popData=t.parseRowsetChunks=t.bufferEndsWith=t.bufferStartsWith=t.parseRowsetHeader=t.parseArray=t.parseError=t.decompressBuffer=t.parseCommandLength=t.hasCommandLength=t.ROWSET_CHUNKS_END=t.CMD_ARRAY=t.CMD_COMMAND=t.CMD_COMPRESSED=t.CMD_BLOB=t.CMD_NULL=t.CMD_JSON=t.CMD_ROWSET_CHUNK=t.CMD_ROWSET=t.CMD_FLOAT=t.CMD_INT=t.CMD_ERROR=t.CMD_ZEROSTRING=t.CMD_STRING=void 0;const r=n(906),s=n(825),o=n(405);function i(e,t){const n=e.subarray(t+1).toString("utf8").split(" ");let s=n.shift()||"0",o="0",i="-1";const a=s.split(":");s=a[0],a.length>1&&(o=a[1],a.length>2&&(i=a[2]));const c=n.join(" "),l=parseInt(s),u=parseInt(o),h=parseInt(i);throw new r.SQLiteCloudError(c,{errorCode:l.toString(),externalErrorCode:u.toString(),offsetCode:h})}function a(e,t){const n=[],r=e.subarray(t+1,e.length),s=parseInt(r.subarray(0,t-2).toString("utf8"));let o=r.subarray(r.indexOf(" ")+1,r.length);for(let e=0;e<s;e++){const{data:e,fwdBuffer:t}=d(o);n.push(e),o=t}return n}function c(e){const t=parseInt(e.subarray(0,e.indexOf(":")+1).toString());e=e.subarray(e.indexOf(":")+1);const{data:n,fwdBuffer:r}=function(e,t=1){const n=[];for(let r=0;r<t;r++){const t=e.indexOf(" ");n[r]=parseInt(e.subarray(0,t).toString()),e=e.subarray(t+1)}return{data:n,fwdBuffer:e}}(e,3);return{index:t,metadata:{version:n[0],numberOfRows:n[1],numberOfColumns:n[2],columns:[]},fwdBuffer:r}}function l(e,t){function n(){const{data:t,fwdBuffer:n}=d(e);return e=n,t}for(let e=0;e<t.numberOfColumns;e++)t.columns.push({name:n()});if(2==t.version){for(let e=0;e<t.numberOfColumns;e++)t.columns[e].type=n();for(let e=0;e<t.numberOfColumns;e++)t.columns[e].database=n();for(let e=0;e<t.numberOfColumns;e++)t.columns[e].table=n();for(let e=0;e<t.numberOfColumns;e++)t.columns[e].column=n();for(let e=0;e<t.numberOfColumns;e++)t.columns[e].notNull=n();for(let e=0;e<t.numberOfColumns;e++)t.columns[e].primaryKey=n();for(let e=0;e<t.numberOfColumns;e++)t.columns[e].autoIncrement=n()}return e}function u(e,t){return e.length>=t.length&&e.subarray(0,t.length).toString("utf8")===t}function h(e,t){return e.length>=t.length&&e.subarray(e.length-t.length,e.length).toString("utf8")===t}function d(e){function n(t){return{data:t,fwdBuffer:e.subarray(u)}}console.assert(e&&e instanceof Buffer);const r=e.subarray(0,1).toString("utf8");console.assert(r!==t.CMD_COMPRESSED,"Compressed data shouldn't be decompressed before parsing"),console.assert(r!==t.CMD_ROWSET_CHUNK,"Chunked data should be parsed by parseRowsetChunks");let o=e.indexOf(" ");-1===o&&(o=e.length-1);let u=-1;if(r===t.CMD_INT||r===t.CMD_FLOAT||r===t.CMD_NULL)u=o+1;else{const t=parseInt(e.subarray(1,o).toString());u=o+1+t}switch(r){case t.CMD_INT:return n(parseInt(e.subarray(1,o).toString()));case t.CMD_FLOAT:return n(parseFloat(e.subarray(1,o).toString()));case t.CMD_NULL:return n(null);case t.CMD_STRING:return n(e.subarray(o+1,u).toString("utf8"));case t.CMD_ZEROSTRING:return n(e.subarray(o+1,u-1).toString("utf8"));case t.CMD_COMMAND:return n(e.subarray(o+1,u).toString("utf8"));case t.CMD_JSON:return n(JSON.parse(e.subarray(o+1,u).toString("utf8")));case t.CMD_BLOB:return n(e.subarray(o+1,u));case t.CMD_ARRAY:return n(a(e,o));case t.CMD_ROWSET:return n(function(e,t){e=e.subarray(t+1,e.length);const{metadata:n,fwdBuffer:r}=c(e);e=l(r,n);const o=[];for(let t=0;t<n.numberOfRows*n.numberOfColumns;t++){const{data:t,fwdBuffer:n}=d(e);o.push(t),e=n}return console.assert(o&&o.length===n.numberOfRows*n.numberOfColumns,"SQLiteCloudConnection.parseRowset - invalid rowset data"),new s.SQLiteCloudRowset(n,o)}(e,o));case t.CMD_ERROR:i(e,o)}throw new TypeError(`Data type: ${r} is not defined in SCSP`)}t.CMD_STRING="+",t.CMD_ZEROSTRING="!",t.CMD_ERROR="-",t.CMD_INT=":",t.CMD_FLOAT=",",t.CMD_ROWSET="*",t.CMD_ROWSET_CHUNK="/",t.CMD_JSON="#",t.CMD_NULL="_",t.CMD_BLOB="$",t.CMD_COMPRESSED="%",t.CMD_COMMAND="^",t.CMD_ARRAY="=",t.ROWSET_CHUNKS_END="/6 0 0 0 ",t.hasCommandLength=function(e){return e!=t.CMD_INT&&e!=t.CMD_FLOAT&&e!=t.CMD_NULL},t.parseCommandLength=function(e){return parseInt(e.subarray(1,e.indexOf(" ")).toString("utf8"))},t.decompressBuffer=function(e){const t=e.indexOf(" ");e=e.subarray(t+1);const n=parseInt(e.subarray(0,e.indexOf(" ")+1).toString("utf8"));e=e.subarray(e.indexOf(" ")+1);const r=parseInt(e.subarray(0,e.indexOf(" ")+1).toString("utf8")),s=(e=e.subarray(e.indexOf(" ")+1)).subarray(0,1).toString("utf8"),i=Buffer.alloc(r),a=e.subarray(e.length-n),c=o.decompressBlock(a,i,0,n,0);if(e=Buffer.concat([e.subarray(0,e.length-n),i]),c<=0||c!==r)throw new Error(`lz4 decompression error at offset ${c}`);return{buffer:e,dataType:s}},t.parseError=i,t.parseArray=a,t.parseRowsetHeader=c,t.bufferStartsWith=u,t.bufferEndsWith=h,t.parseRowsetChunks=function(e){let n=Buffer.concat(e);if(!u(n,t.CMD_ROWSET_CHUNK)||!h(n,t.ROWSET_CHUNKS_END))throw new Error("SQLiteCloudConnection.parseRowsetChunks - invalid chunks buffer");let r={version:1,numberOfColumns:0,numberOfRows:0,columns:[]};const o=[],i=n.subarray(0,1).toString();for(console.assert(i===t.CMD_ROWSET_CHUNK),n=n.subarray(n.indexOf(" ")+1);n.length>0&&!u(n,t.ROWSET_CHUNKS_END);){const{index:e,metadata:t,fwdBuffer:s}=c(n);n=s,1===e?(r=t,n=l(n,r)):r.numberOfRows+=t.numberOfRows;for(let e=0;e<t.numberOfRows*r.numberOfColumns;e++){const{data:e,fwdBuffer:t}=d(n);o.push(e),n=t}}return console.assert(o&&o.length===r.numberOfRows*r.numberOfColumns,"parseRowsetChunks - invalid rowset data"),new s.SQLiteCloudRowset(r,o)},t.popData=d,t.formatCommand=function(e){return`+${Buffer.byteLength(e,"utf-8")} ${e}`}},39:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.OperationsQueue=void 0,t.OperationsQueue=class{constructor(){this.queue=[],this.isProcessing=!1}enqueue(e){this.queue.push(e),this.isProcessing||this.processNext()}clear(){this.queue=[],this.isProcessing=!1}processNext(){if(0===this.queue.length)return void(this.isProcessing=!1);this.isProcessing=!0;const e=this.queue.shift();null==e||e((()=>{this.processNext()}))}}},825:function(e,t,n){"use strict";var r,s,o,i,a=this&&this.__classPrivateFieldSet||function(e,t,n,r,s){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?s.call(e,n):s?s.value=n:t.set(e,n),n},c=this&&this.__classPrivateFieldGet||function(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)};Object.defineProperty(t,"__esModule",{value:!0}),t.SQLiteCloudRowset=t.SQLiteCloudRow=void 0;const l=n(906);class u{constructor(e,t,n){r.set(this,void 0),s.set(this,void 0),a(this,r,e,"f"),a(this,s,n,"f");for(let e=0;e<t.length;e++)this[t[e]]=n[e]}getRowset(){return c(this,r,"f")}getData(){return c(this,s,"f")}}t.SQLiteCloudRow=u,r=new WeakMap,s=new WeakMap;class h extends Array{constructor(e,t){super(e.numberOfRows),o.set(this,void 0),i.set(this,void 0),a(this,o,e,"f"),a(this,i,t,"f");const n=this.columnsNames;for(let t=0;t<e.numberOfColumns;t++){n[t]||(n[t]=`column_${t}`);let e=0;for(;n.findIndex(((e,r)=>r!==t&&e===n[t]))>=0;)n[t]=`${n[t]}_${e}`,e++}for(let r=0,s=0;r<e.numberOfRows;r++,s+=e.numberOfColumns)this[r]=new u(this,n,t.slice(s,s+e.numberOfColumns))}get version(){return c(this,o,"f").version}get numberOfRows(){return c(this,o,"f").numberOfRows}get numberOfColumns(){return c(this,o,"f").numberOfColumns}get columnsNames(){return c(this,o,"f").columns.map((e=>e.name))}get metadata(){return c(this,o,"f")}getItem(e,t){if(e<0||e>=this.numberOfRows||t<0||t>=this.numberOfColumns)throw new l.SQLiteCloudError(`This rowset has ${this.numberOfColumns} columns by ${this.numberOfRows} rows, requested column ${t} and row ${e} is invalid.`);return c(this,i,"f")[e*this.numberOfColumns+t]}slice(e,t){e=void 0===e?0:e<0?this.numberOfRows+e:e,e=Math.min(Math.max(e,0),this.numberOfRows),t=void 0===t?this.numberOfRows:t<0?this.numberOfRows+t:t,t=Math.min(Math.max(e,t),this.numberOfRows);const n=Object.assign(Object.assign({},c(this,o,"f")),{numberOfRows:t-e}),r=c(this,i,"f").slice(e*this.numberOfColumns,t*this.numberOfColumns);return console.assert(r&&r.length===n.numberOfRows*n.numberOfColumns,"SQLiteCloudRowset.slice - invalid rowset data"),new h(n,r)}map(e){const t=[];for(let n=0;n<this.numberOfRows;n++){const r=this[n];t.push(e(r,n,this))}return t}filter(e){const t=[];for(let n=0;n<this.numberOfRows;n++)e(this[n],n,this)&&t.push(...c(this,i,"f").slice(n*this.numberOfColumns,(n+1)*this.numberOfColumns));return new h(Object.assign(Object.assign({},c(this,o,"f")),{numberOfRows:t.length/this.numberOfColumns}),t)}}t.SQLiteCloudRowset=h,o=new WeakMap,i=new WeakMap},880:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Statement=void 0;const r=n(73);t.Statement=class{constructor(e,t,...n){const{args:s,callback:o}=(0,r.popCallback)(n);this._database=e,this._sql=t,(null==s?void 0:s.length)>0?this.bind(...s,o):null==o||o.call(this,null)}bind(...e){const{args:t,callback:n}=(0,r.popCallback)(e);try{this._preparedSql=(0,r.prepareSql)(this._sql,...t),n&&n.call(this,null)}catch(e){this._preparedSql=void 0,n&&n.call(this,e)}return this}run(...e){const{args:t,callback:n}=(0,r.popCallback)(e||[]);return(null==t?void 0:t.length)>0?this.bind(...t,(e=>{e?null==n||n.call(this,e):this._database.run(this._preparedSql||"",n)})):this._database.run(this._preparedSql||"",n),this}get(...e){const{args:t,callback:n}=(0,r.popCallback)(e||[]);return(null==t?void 0:t.length)>0?this.bind(...t,(e=>{e?null==n||n.call(this,e):this._database.get(this._preparedSql||"",n)})):this._database.get(this._preparedSql||"",n),this}all(...e){const{args:t,callback:n}=(0,r.popCallback)(e||[]);return(null==t?void 0:t.length)>0?this.bind(...t,(e=>{e?null==n||n.call(this,e):this._database.all(this._preparedSql||"",n)})):this._database.all(this._preparedSql||"",n),this}each(...e){const{args:t,callback:n,complete:s}=(0,r.popCallback)(e);return(null==t?void 0:t.length)>0?this.bind(...t,(e=>{e?null==n||n.call(this,e):this._database.each(this._preparedSql||"",n,s)})):this._database.each(this._preparedSql||"",n,s),this}}},906:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SQLiteCloudArrayType=t.SQLiteCloudError=t.DEFAULT_PORT=t.DEFAULT_TIMEOUT=void 0,t.DEFAULT_TIMEOUT=3e5,t.DEFAULT_PORT=9960;class n extends Error{constructor(e,t){super(e),this.name="SQLiteCloudError",t&&Object.assign(this,t)}}var r;t.SQLiteCloudError=n,(r=t.SQLiteCloudArrayType||(t.SQLiteCloudArrayType={}))[r.ARRAY_TYPE_SQLITE_EXEC=10]="ARRAY_TYPE_SQLITE_EXEC",r[r.ARRAY_TYPE_DB_STATUS=11]="ARRAY_TYPE_DB_STATUS",r[r.ARRAY_TYPE_METADATA=12]="ARRAY_TYPE_METADATA",r[r.ARRAY_TYPE_VM_STEP=20]="ARRAY_TYPE_VM_STEP",r[r.ARRAY_TYPE_VM_COMPILE=21]="ARRAY_TYPE_VM_COMPILE",r[r.ARRAY_TYPE_VM_STEP_ONE=22]="ARRAY_TYPE_VM_STEP_ONE",r[r.ARRAY_TYPE_VM_SQL=23]="ARRAY_TYPE_VM_SQL",r[r.ARRAY_TYPE_VM_STATUS=24]="ARRAY_TYPE_VM_STATUS",r[r.ARRAY_TYPE_VM_LIST=25]="ARRAY_TYPE_VM_LIST",r[r.ARRAY_TYPE_BACKUP_INIT=40]="ARRAY_TYPE_BACKUP_INIT",r[r.ARRAY_TYPE_BACKUP_STEP=41]="ARRAY_TYPE_BACKUP_STEP",r[r.ARRAY_TYPE_BACKUP_END=42]="ARRAY_TYPE_BACKUP_END",r[r.ARRAY_TYPE_SQLITE_STATUS=50]="ARRAY_TYPE_SQLITE_STATUS"},73:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.parseBoolean=t.parseConnectionString=t.validateConfiguration=t.popCallback=t.prepareSql=t.escapeSqlParameter=t.getInitializationCommands=t.anonimizeError=t.anonimizeCommand=t.isNode=t.isBrowser=void 0;const r=n(906);function s(e){return(e=(e=e.replace(/USER \S+/,"USER ******")).replace(/PASSWORD \S+?(?=;)/,"PASSWORD ******")).replace(/HASH \S+?(?=;)/,"HASH ******")}function o(e){if(null==e)return"NULL";if("string"==typeof e)return`'${e=e.replace(/'/g,"''")}'`;if("number"==typeof e)return e.toString();if("boolean"==typeof e)return e?"1":"0";if(Buffer.isBuffer(e))return`X'${e.toString("hex")}'`;if("object"==typeof e){let t=JSON.stringify(e);return t=t.replace(/'/g,"''"),`'${t}'`}throw new r.SQLiteCloudError("Unsupported parameter type: "+typeof e)}function i(e){try{const t=e.replace("sqlitecloud:","https:"),n=new URL(t),r={};n.searchParams.forEach(((e,t)=>{r[t]=e}));const s=Object.assign({username:n.username,password:n.password,host:n.hostname,port:n.port?parseInt(n.port):void 0},r),o=n.pathname.replace("/","");return o&&(s.database=o),s}catch(t){throw new r.SQLiteCloudError(`Invalid connection string: ${e}`)}}function a(e){return"string"==typeof e?"true"===e.toLowerCase()||"1"===e:!!e}t.isBrowser="undefined"!=typeof window&&void 0!==window.document,t.isNode="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node,t.anonimizeCommand=s,t.anonimizeError=function(e){return(null==e?void 0:e.message)&&(e.message=s(e.message)),e},t.getInitializationCommands=function(e){let t=`AUTH USER ${e.username||""} ${e.passwordHashed?"HASH":"PASSWORD"} ${e.password||""}; `;return e.database&&(e.createDatabase&&!e.dbMemory&&(t+=`CREATE DATABASE ${e.database} IF NOT EXISTS; `),t+=`USE DATABASE ${e.database}; `),e.compression&&(t+="SET CLIENT KEY COMPRESSION TO 1; "),e.nonlinearizable&&(t+="SET CLIENT KEY NONLINEARIZABLE TO 1; "),e.noBlob&&(t+="SET CLIENT KEY NOBLOB TO 1; "),e.maxData&&(t+=`SET CLIENT KEY MAXDATA TO ${e.maxData}; `),e.maxRows&&(t+=`SET CLIENT KEY MAXROWS TO ${e.maxRows}; `),e.maxRowset&&(t+=`SET CLIENT KEY MAXROWSET TO ${e.maxRowset}; `),t},t.escapeSqlParameter=o,t.prepareSql=function(e,...t){1===(null==t?void 0:t.length)&&Array.isArray(t[0])&&(t=t[0]);let n=1,s=e.replace(/\?(\d+)?/g,((e,s)=>{const i=s?parseInt(s):n;let a;if(n++,!t[0]||"object"!=typeof t[0]||t[0]instanceof Buffer||(a=t[0][i]),!a){if(i>t.length)throw new r.SQLiteCloudError("Not enough parameters");a=t[i-1]}return null!=a?o(a):"NULL"}));if(1===(null==t?void 0:t.length)&&t[0]&&"object"==typeof t[0]){const e=t[0];for(const[t,n]of Object.entries(e)){const e=t.charAt(0);if("$"==e||":"==e||"@"==e){const e=o(n);s=s.replace(new RegExp(`\\${t}`,"g"),e)}}}return s},t.popCallback=function(e){const t=e;return e&&e.length>0&&"function"==typeof e[e.length-1]?e.length>1&&"function"==typeof e[e.length-2]?{args:t.slice(0,-2),callback:e[e.length-2],complete:e[e.length-1]}:{args:t.slice(0,-1),callback:e[e.length-1]}:{args:t}},t.validateConfiguration=function(e){if(console.assert(e,"SQLiteCloudConnection.validateConfiguration - missing config"),e.connectionString&&(e=Object.assign(Object.assign(Object.assign({},e),i(e.connectionString)),{connectionString:e.connectionString})),e.port||(e.port=r.DEFAULT_PORT),e.timeout=e.timeout&&e.timeout>0?e.timeout:r.DEFAULT_TIMEOUT,e.clientId||(e.clientId="SQLiteCloud"),e.verbose=a(e.verbose),e.noBlob=a(e.noBlob),e.compression=a(e.compression),e.createDatabase=a(e.createDatabase),e.nonlinearizable=a(e.nonlinearizable),e.insecure=a(e.insecure),!e.username||!e.password||!e.host)throw console.error("SQLiteCloudConnection.validateConfiguration - missing arguments",e),new r.SQLiteCloudError("The user, password and host arguments must be specified.",{errorCode:"ERR_MISSING_ARGS"});return e.connectionString||(e.connectionString=`sqlitecloud://${e.username}:${e.password}@${e.host}:${e.port}/${e.database}`),e},t.parseConnectionString=i,t.parseBoolean=a},227:(e,t,n)=>{t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,s=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(s=r))})),t.splice(s,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=n(447)(t);const{formatters:r}=e.exports;r.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}},447:(e,t,n)=>{e.exports=function(e){function t(e){let n,s,o,i=null;function a(...e){if(!a.enabled)return;const r=a,s=Number(new Date),o=s-(n||s);r.diff=o,r.prev=n,r.curr=s,n=s,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((n,s)=>{if("%%"===n)return"%";i++;const o=t.formatters[s];if("function"==typeof o){const t=e[i];n=o.call(r,t),e.splice(i,1),i--}return n})),t.formatArgs.call(r,e),(r.log||t.log).apply(r,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=r,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==i?i:(s!==t.namespaces&&(s=t.namespaces,o=t.enabled(e)),o),set:e=>{i=e}}),"function"==typeof t.init&&t.init(a),a}function r(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names.map(s),...t.skips.map(s).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(n=0;n<s;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.slice(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=n(824),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((n=>{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}},729:e=>{"use strict";var t=Object.prototype.hasOwnProperty,n="~";function r(){}function s(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,r,o,i){if("function"!=typeof r)throw new TypeError("The listener must be a function");var a=new s(r,o||e,i),c=n?n+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function a(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,r,s=[];if(0===this._eventsCount)return s;for(r in e=this._events)t.call(e,r)&&s.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(e)):s},a.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var s=0,o=r.length,i=new Array(o);s<o;s++)i[s]=r[s].fn;return i},a.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},a.prototype.emit=function(e,t,r,s,o,i){var a=n?n+e:e;if(!this._events[a])return!1;var c,l,u=this._events[a],h=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),h){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,r),!0;case 4:return u.fn.call(u.context,t,r,s),!0;case 5:return u.fn.call(u.context,t,r,s,o),!0;case 6:return u.fn.call(u.context,t,r,s,o,i),!0}for(l=1,c=new Array(h-1);l<h;l++)c[l-1]=arguments[l];u.fn.apply(u.context,c)}else{var d,f=u.length;for(l=0;l<f;l++)switch(u[l].once&&this.removeListener(e,u[l].fn,void 0,!0),h){case 1:u[l].fn.call(u[l].context);break;case 2:u[l].fn.call(u[l].context,t);break;case 3:u[l].fn.call(u[l].context,t,r);break;case 4:u[l].fn.call(u[l].context,t,r,s);break;default:if(!c)for(d=1,c=new Array(h-1);d<h;d++)c[d-1]=arguments[d];u[l].fn.apply(u[l].context,c)}}return!0},a.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,r,s){var o=n?n+e:e;if(!this._events[o])return this;if(!t)return i(this,o),this;var a=this._events[o];if(a.fn)a.fn!==t||s&&!a.once||r&&a.context!==r||i(this,o);else{for(var c=0,l=[],u=a.length;c<u;c++)(a[c].fn!==t||s&&!a[c].once||r&&a[c].context!==r)&&l.push(a[c]);l.length?this._events[o]=1===l.length?l[0]:l:i(this,o)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&i(this,t)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a},405:(e,t,n)=>{var r=n(887),s=n(325),o=65536,i=h(5<<20),a=function(){try{return new Uint32Array(o)}catch(n){for(var e=new Array(o),t=0;t<o;t++)e[t]=0;return e}}(),c=407708164,l=2147483648,u={4:65536,5:262144,6:1048576,7:4194304};function h(e){try{return new Uint8Array(e)}catch(r){for(var t=new Array(e),n=0;n<e;n++)t[n]=0;return t}}function d(e,t,n){if(void 0!==typeof e.buffer){if(Uint8Array.prototype.slice)return e.slice(t,n);var r=e.length;t=(t|=0)<0?Math.max(r+t,0):Math.min(t,r),n=(n=void 0===n?r:0|n)<0?Math.max(r+n,0):Math.min(n,r);for(var s=new Uint8Array(n-t),o=t,i=0;o<n;)s[i++]=e[o++];return s}return e.slice(t,n)}t.compressBound=function(e){return e+e/255+16|0},t.decompressBound=function(e){var t=0;if(s.readU32(e,t)!==c)throw new Error("invalid magic number");t+=4;var n=e[t++];if(64!=(192&n))throw new Error("incompatible descriptor version "+(192&n));var r=0!=(16&n),o=0!=(8&n),i=e[t++]>>4&7;if(void 0===u[i])throw new Error("invalid block size "+i);var a=u[i];if(o)return s.readU64(e,t);t++;for(var h=0;;){var d=s.readU32(e,t);if(t+=4,h+=d&l?d&=2147483647:a,0===d)return h;r&&(t+=4),t+=d}},t.makeBuffer=h,t.decompressBlock=function(e,t,n,r,s){var o,i,a,c,l;for(a=n+r;n<a;){var u=e[n++],h=u>>4;if(h>0){if(15===h)for(;h+=e[n],255===e[n++];);for(c=n+h;n<c;)t[s++]=e[n++]}if(n>=a)break;if(o=15&u,i=e[n++]|e[n++]<<8,15===o)for(;o+=e[n],255===e[n++];);for(c=(l=s-i)+(o+=4);l<c;)t[s++]=0|t[l++]}return s},t.compressBlock=function(e,t,n,r,o){var i,a,c,l,u,h,d,f;if(h=0,d=r+n,a=n,r>=13)for(var p=67;n+4<d-5;){var m=s.readU32(e,n),g=s.hashU32(m)>>>0;if(i=o[g=(g>>16^g)>>>0&65535]-1,o[g]=n+1,i<0||n-i>>>16>0||s.readU32(e,i)!==m)n+=p++>>6;else{for(p=67,u=n-a,l=n-i,i+=4,c=n+=4;n<d-5&&e[n]===e[i];)n++,i++;var y=(c=n-c)<15?c:15;if(u>=15){for(t[h++]=240+y,f=u-15;f>=255;f-=255)t[h++]=255;t[h++]=f}else t[h++]=(u<<4)+y;for(var b=0;b<u;b++)t[h++]=e[a+b];if(t[h++]=l,t[h++]=l>>8,c>=15){for(f=c-15;f>=255;f-=255)t[h++]=255;t[h++]=f}a=n}}if(0===a)return 0;if((u=d-a)>=15){for(t[h++]=240,f=u-15;f>=255;f-=255)t[h++]=255;t[h++]=f}else t[h++]=u<<4;for(n=a;n<d;)t[h++]=e[n++];return h},t.decompressFrame=function(e,n){var r,o,i,a,h=0,d=0;if(s.readU32(e,h)!==c)throw new Error("invalid magic number");if(h+=4,64!=(192&(a=e[h++])))throw new Error("incompatible descriptor version");r=0!=(16&a),o=0!=(4&a),i=0!=(8&a);var f=e[h++]>>4&7;if(void 0===u[f])throw new Error("invalid block size");for(i&&(h+=8),h++;;){var p;if(p=s.readU32(e,h),h+=4,0===p)break;if(r&&(h+=4),0!=(p&l)){p&=2147483647;for(var m=0;m<p;m++)n[d++]=e[h++]}else d=t.decompressBlock(e,n,h,p,d),h+=p}return o&&(h+=4),d},t.compressFrame=function(e,n){var l=0;s.writeU32(n,l,c),l+=4,n[l++]=64,n[l++]=112,n[l]=r.hash(0,n,4,l-4)>>8,l++;var h=u[7],d=e.length,f=0;for(function(e){for(var t=0;t<o;t++)a[t]=0}();d>0;){var p,m=d>h?h:d;if((p=t.compressBlock(e,i,f,m,a))>m||0===p){s.writeU32(n,l,2147483648|m),l+=4;for(var g=f+m;f<g;)n[l++]=e[f++];d-=m}else{s.writeU32(n,l,p),l+=4;for(var y=0;y<p;)n[l++]=i[y++];f+=m,d-=m}}return s.writeU32(n,l,0),l+4},t.decompress=function(e,n){var r,s;return void 0===n&&(n=t.decompressBound(e)),r=t.makeBuffer(n),(s=t.decompressFrame(e,r))!==n&&(r=d(r,0,s)),r},t.compress=function(e,n){var r,s;return void 0===n&&(n=t.compressBound(e.length)),r=t.makeBuffer(n),(s=t.compressFrame(e,r))!==n&&(r=d(r,0,s)),r}},325:(e,t)=>{t.hashU32=function(e){return-1252372727^(e=(e=(e=374761393+(e=-949894596^(e=2127912214+(e|=0)+(e<<12)|0)^e>>>19)+(e<<5)|0)-744332180^e<<9)-42973499+(e<<3)|0)^e>>>16|0},t.readU64=function(e,t){var n=0;return n|=e[t++]<<0,n|=e[t++]<<8,n|=e[t++]<<16,n|=e[t++]<<24,n|=e[t++]<<32,n|=e[t++]<<40,(n|=e[t++]<<48)|e[t++]<<56},t.readU32=function(e,t){var n=0;return n|=e[t++]<<0,n|=e[t++]<<8,(n|=e[t++]<<16)|e[t++]<<24},t.writeU32=function(e,t,n){e[t++]=n>>0&255,e[t++]=n>>8&255,e[t++]=n>>16&255,e[t++]=n>>24&255},t.imul=function(e,t){var n=65535&e,r=65535&t;return n*r+((e>>>16)*r+n*(t>>>16)<<16)|0}},887:(e,t,n)=>{var r=n(325),s=2654435761,o=2246822519,i=3266489917,a=374761393;function c(e,t){return(e|=0)>>>(32-(t|=0)|0)|e<<t|0}function l(e,t,n){return e|=0,t|=0,n|=0,0|r.imul(e>>>(32-t|0)|e<<t,n)}function u(e,t){return(e|=0)>>>(t|=0)^e|0}function h(e,t,n,s,o){return l(r.imul(t,n)+e,s,o)}function d(e,t,n){return l(e+r.imul(t[n],a),11,s)}function f(e,t,n){return h(e,r.readU32(t,n),i,17,668265263)}function p(e,t,n){return[h(e[0],r.readU32(t,n+0),o,13,s),h(e[1],r.readU32(t,n+4),o,13,s),h(e[2],r.readU32(t,n+8),o,13,s),h(e[3],r.readU32(t,n+12),o,13,s)]}t.hash=function(e,t,n,l){var h,m;if(m=l,l>=16){for(h=[e+s+o,e+o,e,e-s];l>=16;)h=p(h,t,n),n+=16,l-=16;h=c(h[0],1)+c(h[1],7)+c(h[2],12)+c(h[3],18)+m}else h=e+a+l>>>0;for(;l>=4;)h=f(h,t,n),n+=4,l-=4;for(;l>0;)h=d(h,t,n),n++,l--;return(h=u(r.imul(u(r.imul(u(h,15),o),13),i),16))>>>0}},824:e=>{var t=1e3,n=60*t,r=60*n,s=24*r;function o(e,t,n,r){var s=t>=1.5*n;return Math.round(e/n)+" "+r+(s?"s":"")}e.exports=function(e,i){i=i||{};var a,c,l=typeof e;if("string"===l&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var o=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(o){var i=parseFloat(o[1]);switch((o[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*i;case"weeks":case"week":case"w":return 6048e5*i;case"days":case"day":case"d":return i*s;case"hours":case"hour":case"hrs":case"hr":case"h":return i*r;case"minutes":case"minute":case"mins":case"min":case"m":return i*n;case"seconds":case"second":case"secs":case"sec":case"s":return i*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:return}}}}(e);if("number"===l&&isFinite(e))return i.long?(a=e,(c=Math.abs(a))>=s?o(a,c,s,"day"):c>=r?o(a,c,r,"hour"):c>=n?o(a,c,n,"minute"):c>=t?o(a,c,t,"second"):a+" ms"):function(e){var o=Math.abs(e);return o>=s?Math.round(e/s)+"d":o>=r?Math.round(e/r)+"h":o>=n?Math.round(e/n)+"m":o>=t?Math.round(e/t)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},761:()=>{},59:()=>{},419:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.hasCORS=void 0;let n=!1;try{n="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(e){}t.hasCORS=n},754:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.decode=t.encode=void 0,t.encode=function(e){let t="";for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t},t.decode=function(e){let t={},n=e.split("&");for(let e=0,r=n.length;e<r;e++){let r=n[e].split("=");t[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return t}},222:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.parse=void 0;const n=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,r=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];t.parse=function(e){if(e.length>2e3)throw"URI too long";const t=e,s=e.indexOf("["),o=e.indexOf("]");-1!=s&&-1!=o&&(e=e.substring(0,s)+e.substring(s,o).replace(/:/g,";")+e.substring(o,e.length));let i=n.exec(e||""),a={},c=14;for(;c--;)a[r[c]]=i[c]||"";return-1!=s&&-1!=o&&(a.source=t,a.host=a.host.substring(1,a.host.length-1).replace(/;/g,":"),a.authority=a.authority.replace("[","").replace("]","").replace(/;/g,":"),a.ipv6uri=!0),a.pathNames=function(e,t){const n=t.replace(/\/{2,9}/g,"/").split("/");return"/"!=t.slice(0,1)&&0!==t.length||n.splice(0,1),"/"==t.slice(-1)&&n.splice(n.length-1,1),n}(0,a.path),a.queryKey=function(e,t){const n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(e,t,r){t&&(n[t]=r)})),n}(0,a.query),a}},726:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.yeast=t.decode=t.encode=void 0;const n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),r={};let s,o=0,i=0;function a(e){let t="";do{t=n[e%64]+t,e=Math.floor(e/64)}while(e>0);return t}for(t.encode=a,t.decode=function(e){let t=0;for(i=0;i<e.length;i++)t=64*t+r[e.charAt(i)];return t},t.yeast=function(){const e=a(+new Date);return e!==s?(o=0,s=e):e+"."+a(o++)};i<64;i++)r[n[i]]=i},242:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.globalThisShim=void 0,t.globalThisShim="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")()},679:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.nextTick=t.parse=t.installTimerFunctions=t.transports=t.TransportError=t.Transport=t.protocol=t.Socket=void 0;const r=n(481);Object.defineProperty(t,"Socket",{enumerable:!0,get:function(){return r.Socket}}),t.protocol=r.Socket.protocol;var s=n(870);Object.defineProperty(t,"Transport",{enumerable:!0,get:function(){return s.Transport}}),Object.defineProperty(t,"TransportError",{enumerable:!0,get:function(){return s.TransportError}});var o=n(385);Object.defineProperty(t,"transports",{enumerable:!0,get:function(){return o.transports}});var i=n(622);Object.defineProperty(t,"installTimerFunctions",{enumerable:!0,get:function(){return i.installTimerFunctions}});var a=n(222);Object.defineProperty(t,"parse",{enumerable:!0,get:function(){return a.parse}});var c=n(552);Object.defineProperty(t,"nextTick",{enumerable:!0,get:function(){return c.nextTick}})},481:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Socket=void 0;const s=n(385),o=n(622),i=n(754),a=n(222),c=r(n(227)),l=n(260),u=n(373),h=n(552),d=(0,c.default)("engine.io-client:socket");class f extends l.Emitter{constructor(e,t={}){super(),this.binaryType=h.defaultBinaryType,this.writeBuffer=[],e&&"object"==typeof e&&(t=e,e=null),e?(e=(0,a.parse)(e),t.hostname=e.host,t.secure="https"===e.protocol||"wss"===e.protocol,t.port=e.port,e.query&&(t.query=e.query)):t.host&&(t.hostname=(0,a.parse)(t.host).host),(0,o.installTimerFunctions)(this,t),this.secure=null!=t.secure?t.secure:"undefined"!=typeof location&&"https:"===location.protocol,t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=t.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=t.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=(0,i.decode)(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,"function"==typeof addEventListener&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(e){d('creating transport "%s"',e);const t=Object.assign({},this.opts.query);t.EIO=u.protocol,t.transport=e,this.id&&(t.sid=this.id);const n=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return d("options: %j",n),new s.transports[e](n)}open(){let e;if(this.opts.rememberUpgrade&&f.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket"))e="websocket";else{if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);e=this.transports[0]}this.readyState="opening";try{e=this.createTransport(e)}catch(e){return d("error while creating transport: %s",e),this.transports.shift(),void this.open()}e.open(),this.setTransport(e)}setTransport(e){d("setting transport %s",e.name),this.transport&&(d("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners()),this.transport=e,e.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",(e=>this.onClose("transport close",e)))}probe(e){d('probing transport "%s"',e);let t=this.createTransport(e),n=!1;f.priorWebsocketSuccess=!1;const r=()=>{n||(d('probe transport "%s" opened',e),t.send([{type:"ping",data:"probe"}]),t.once("packet",(r=>{if(!n)if("pong"===r.type&&"probe"===r.data){if(d('probe transport "%s" pong',e),this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;f.priorWebsocketSuccess="websocket"===t.name,d('pausing current transport "%s"',this.transport.name),this.transport.pause((()=>{n||"closed"!==this.readyState&&(d("changing transport and sending upgrade packet"),l(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())}))}else{d('probe transport "%s" failed',e);const n=new Error("probe error");n.transport=t.name,this.emitReserved("upgradeError",n)}})))};function s(){n||(n=!0,l(),t.close(),t=null)}const o=n=>{const r=new Error("probe error: "+n);r.transport=t.name,s(),d('probe transport "%s" failed because of error: %s',e,n),this.emitReserved("upgradeError",r)};function i(){o("transport closed")}function a(){o("socket closed")}function c(e){t&&e.name!==t.name&&(d('"%s" works - aborting "%s"',e.name,t.name),s())}const l=()=>{t.removeListener("open",r),t.removeListener("error",o),t.removeListener("close",i),this.off("close",a),this.off("upgrading",c)};t.once("open",r),t.once("error",o),t.once("close",i),this.once("close",a),this.once("upgrading",c),-1!==this.upgrades.indexOf("webtransport")&&"webtransport"!==e?this.setTimeoutFn((()=>{n||t.open()}),200):t.open()}onOpen(){if(d("socket open"),this.readyState="open",f.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade){d("starting upgrade probes");let e=0;const t=this.upgrades.length;for(;e<t;e++)this.probe(this.upgrades[e])}}onPacket(e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(d('socket receive: type "%s", data "%s"',e.type,e.data),this.emitReserved("packet",e),this.emitReserved("heartbeat"),this.resetPingTimeout(),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const t=new Error("server error");t.code=e.data,this.onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data)}else d('packet received with socket readyState "%s"',this.readyState)}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this.upgrades=this.filterUpgrades(e.upgrades),this.pingInterval=e.pingInterval,this.pingTimeout=e.pingTimeout,this.maxPayload=e.maxPayload,this.onOpen(),"closed"!==this.readyState&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn((()=>{this.onClose("ping timeout")}),this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const e=this.getWritablePackets();d("flushing %d packets in socket",e.length),this.transport.send(e),this.prevBufferLen=e.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let e=1;for(let t=0;t<this.writeBuffer.length;t++){const n=this.writeBuffer[t].data;if(n&&(e+=(0,o.byteLength)(n)),t>0&&e>this.maxPayload)return d("only send %d out of %d packets",t,this.writeBuffer.length),this.writeBuffer.slice(0,t);e+=2}return d("payload size is %d (max: %d)",e,this.maxPayload),this.writeBuffer}write(e,t,n){return this.sendPacket("message",e,t,n),this}send(e,t,n){return this.sendPacket("message",e,t,n),this}sendPacket(e,t,n,r){if("function"==typeof t&&(r=t,t=void 0),"function"==typeof n&&(r=n,n=null),"closing"===this.readyState||"closed"===this.readyState)return;(n=n||{}).compress=!1!==n.compress;const s={type:e,data:t,options:n};this.emitReserved("packetCreate",s),this.writeBuffer.push(s),r&&this.once("flush",r),this.flush()}close(){const e=()=>{this.onClose("forced close"),d("socket closing - telling transport to close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},n=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?n():e()})):this.upgrading?n():e()),this}onError(e){d("socket error %j",e),f.priorWebsocketSuccess=!1,this.emitReserved("error",e),this.onClose("transport error",e)}onClose(e,t){"opening"!==this.readyState&&"open"!==this.readyState&&"closing"!==this.readyState||(d('socket close with reason: "%s"',e),this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),"function"==typeof removeEventListener&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(e){const t=[];let n=0;const r=e.length;for(;n<r;n++)~this.transports.indexOf(e[n])&&t.push(e[n]);return t}}t.Socket=f,f.protocol=u.protocol},870:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Transport=t.TransportError=void 0;const s=n(373),o=n(260),i=n(622),a=r(n(227)),c=n(754),l=(0,a.default)("engine.io-client:transport");class u extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type="TransportError"}}t.TransportError=u;class h extends o.Emitter{constructor(e){super(),this.writable=!1,(0,i.installTimerFunctions)(this,e),this.opts=e,this.query=e.query,this.socket=e.socket}onError(e,t,n){return super.emitReserved("error",new u(e,t,n)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(e){"open"===this.readyState?this.write(e):l("transport is not open, discarding packets")}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){const t=(0,s.decodePacket)(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,t={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){const e=this.opts.hostname;return-1===e.indexOf(":")?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(443!==this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(e){const t=(0,c.encode)(e);return t.length?"?"+t:""}}t.Transport=h},385:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.transports=void 0;const r=n(484),s=n(308),o=n(20);t.transports={websocket:s.WS,webtransport:o.WT,polling:r.Polling}},484:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Request=t.Polling=void 0;const s=n(870),o=r(n(227)),i=n(726),a=n(373),c=n(666),l=n(260),u=n(622),h=n(242),d=(0,o.default)("engine.io-client:polling");function f(){}const p=null!=new c.XHR({xdomain:!1}).responseType;class m extends s.Transport{constructor(e){if(super(e),this.polling=!1,"undefined"!=typeof location){const t="https:"===location.protocol;let n=location.port;n||(n=t?"443":"80"),this.xd="undefined"!=typeof location&&e.hostname!==location.hostname||n!==e.port}const t=e&&e.forceBase64;this.supportsBinary=p&&!t,this.opts.withCredentials&&(this.cookieJar=(0,c.createCookieJar)())}get name(){return"polling"}doOpen(){this.poll()}pause(e){this.readyState="pausing";const t=()=>{d("paused"),this.readyState="paused",e()};if(this.polling||!this.writable){let e=0;this.polling&&(d("we are currently polling - waiting to pause"),e++,this.once("pollComplete",(function(){d("pre-pause polling complete"),--e||t()}))),this.writable||(d("we are currently writing - waiting to pause"),e++,this.once("drain",(function(){d("pre-pause writing complete"),--e||t()})))}else t()}poll(){d("polling"),this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){d("polling got data %s",e),(0,a.decodePayload)(e,this.socket.binaryType).forEach((e=>{if("opening"===this.readyState&&"open"===e.type&&this.onOpen(),"close"===e.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(e)})),"closed"!==this.readyState&&(this.polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState?this.poll():d('ignoring poll - transport state "%s"',this.readyState))}doClose(){const e=()=>{d("writing close packet"),this.write([{type:"close"}])};"open"===this.readyState?(d("transport open - closing"),e()):(d("transport not open - deferring close"),this.once("open",e))}write(e){this.writable=!1,(0,a.encodePayload)(e,(e=>{this.doWrite(e,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){const e=this.opts.secure?"https":"http",t=this.query||{};return!1!==this.opts.timestampRequests&&(t[this.opts.timestampParam]=(0,i.yeast)()),this.supportsBinary||t.sid||(t.b64=1),this.createUri(e,t)}request(e={}){return Object.assign(e,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new g(this.uri(),e)}doWrite(e,t){const n=this.request({method:"POST",data:e});n.on("success",t),n.on("error",((e,t)=>{this.onError("xhr post error",e,t)}))}doPoll(){d("xhr poll");const e=this.request();e.on("data",this.onData.bind(this)),e.on("error",((e,t)=>{this.onError("xhr poll error",e,t)})),this.pollXhr=e}}t.Polling=m;class g extends l.Emitter{constructor(e,t){super(),(0,u.installTimerFunctions)(this,t),this.opts=t,this.method=t.method||"GET",this.uri=e,this.data=void 0!==t.data?t.data:null,this.create()}create(){var e;const t=(0,u.pick)(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd;const n=this.xhr=new c.XHR(t);try{d("xhr open %s: %s",this.method,this.uri),n.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(let e in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(e)&&n.setRequestHeader(e,this.opts.extraHeaders[e])}}catch(e){}if("POST"===this.method)try{n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(e){}try{n.setRequestHeader("Accept","*/*")}catch(e){}null===(e=this.opts.cookieJar)||void 0===e||e.addCookies(n),"withCredentials"in n&&(n.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(n.timeout=this.opts.requestTimeout),n.onreadystatechange=()=>{var e;3===n.readyState&&(null===(e=this.opts.cookieJar)||void 0===e||e.parseCookies(n)),4===n.readyState&&(200===n.status||1223===n.status?this.onLoad():this.setTimeoutFn((()=>{this.onError("number"==typeof n.status?n.status:0)}),0))},d("xhr data %s",this.data),n.send(this.data)}catch(e){return void this.setTimeoutFn((()=>{this.onError(e)}),0)}"undefined"!=typeof document&&(this.index=g.requestsCount++,g.requests[this.index]=this)}onError(e){this.emitReserved("error",e,this.xhr),this.cleanup(!0)}cleanup(e){if(void 0!==this.xhr&&null!==this.xhr){if(this.xhr.onreadystatechange=f,e)try{this.xhr.abort()}catch(e){}"undefined"!=typeof document&&delete g.requests[this.index],this.xhr=null}}onLoad(){const e=this.xhr.responseText;null!==e&&(this.emitReserved("data",e),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}if(t.Request=g,g.requestsCount=0,g.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",y);else if("function"==typeof addEventListener){const e="onpagehide"in h.globalThisShim?"pagehide":"unload";addEventListener(e,y,!1)}function y(){for(let e in g.requests)g.requests.hasOwnProperty(e)&&g.requests[e].abort()}},552:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.defaultBinaryType=t.usingBrowserWebSocket=t.WebSocket=t.nextTick=void 0;const r=n(242);t.nextTick="function"==typeof Promise&&"function"==typeof Promise.resolve?e=>Promise.resolve().then(e):(e,t)=>t(e,0),t.WebSocket=r.globalThisShim.WebSocket||r.globalThisShim.MozWebSocket,t.usingBrowserWebSocket=!0,t.defaultBinaryType="arraybuffer"},308:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.WS=void 0;const s=n(870),o=n(726),i=n(622),a=n(552),c=r(n(227)),l=n(373),u=(0,c.default)("engine.io-client:websocket"),h="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class d extends s.Transport{constructor(e){super(e),this.supportsBinary=!e.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const e=this.uri(),t=this.opts.protocols,n=h?{}:(0,i.pick)(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=a.usingBrowserWebSocket&&!h?t?new a.WebSocket(e,t):new a.WebSocket(e):new a.WebSocket(e,t,n)}catch(e){return this.emitReserved("error",e)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const n=e[t],r=t===e.length-1;(0,l.encodePacket)(n,this.supportsBinary,(e=>{const t={};!a.usingBrowserWebSocket&&(n.options&&(t.compress=n.options.compress),this.opts.perMessageDeflate)&&("string"==typeof e?Buffer.byteLength(e):e.length)<this.opts.perMessageDeflate.threshold&&(t.compress=!1);try{a.usingBrowserWebSocket?this.ws.send(e):this.ws.send(e,t)}catch(e){u("websocket closed before onclose event")}r&&(0,a.nextTick)((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.close(),this.ws=null)}uri(){const e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=(0,o.yeast)()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}check(){return!!a.WebSocket}}t.WS=d},20:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.WT=void 0;const s=n(870),o=n(552),i=n(373),a=(0,r(n(227)).default)("engine.io-client:webtransport");class c extends s.Transport{get name(){return"webtransport"}doOpen(){"function"==typeof WebTransport&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then((()=>{a("transport closed gracefully"),this.onClose()})).catch((e=>{a("transport closed due to %s",e),this.onError("webtransport error",e)})),this.transport.ready.then((()=>{this.transport.createBidirectionalStream().then((e=>{const t=(0,i.createPacketDecoderStream)(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),r=(0,i.createPacketEncoderStream)();r.readable.pipeTo(e.writable),this.writer=r.writable.getWriter();const s=()=>{n.read().then((({done:e,value:t})=>{e?a("session is closed"):(a("received chunk: %o",t),this.onPacket(t),s())})).catch((e=>{a("an error occurred while reading: %s",e)}))};s();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this.writer.write(o).then((()=>this.onOpen()))}))})))}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const n=e[t],r=t===e.length-1;this.writer.write(n).then((()=>{r&&(0,o.nextTick)((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var e;null===(e=this.transport)||void 0===e||e.close()}}t.WT=c},666:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createCookieJar=t.XHR=void 0;const r=n(419),s=n(242);t.XHR=function(e){const t=e.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!t||r.hasCORS))return new XMLHttpRequest}catch(e){}if(!t)try{return new(s.globalThisShim[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(e){}},t.createCookieJar=function(){}},622:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.byteLength=t.installTimerFunctions=t.pick=void 0;const r=n(242);t.pick=function(e,...t){return t.reduce(((t,n)=>(e.hasOwnProperty(n)&&(t[n]=e[n]),t)),{})};const s=r.globalThisShim.setTimeout,o=r.globalThisShim.clearTimeout;t.installTimerFunctions=function(e,t){t.useNativeTimers?(e.setTimeoutFn=s.bind(r.globalThisShim),e.clearTimeoutFn=o.bind(r.globalThisShim)):(e.setTimeoutFn=r.globalThisShim.setTimeout.bind(r.globalThisShim),e.clearTimeoutFn=r.globalThisShim.clearTimeout.bind(r.globalThisShim))},t.byteLength=function(e){return"string"==typeof e?function(e){let t=0,n=0;for(let r=0,s=e.length;r<s;r++)t=e.charCodeAt(r),t<128?n+=1:t<2048?n+=2:t<55296||t>=57344?n+=3:(r++,n+=4);return n}(e):Math.ceil(1.33*(e.byteLength||e.size))}},87:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ERROR_PACKET=t.PACKET_TYPES_REVERSE=t.PACKET_TYPES=void 0;const n=Object.create(null);t.PACKET_TYPES=n,n.open="0",n.close="1",n.ping="2",n.pong="3",n.message="4",n.upgrade="5",n.noop="6";const r=Object.create(null);t.PACKET_TYPES_REVERSE=r,Object.keys(n).forEach((e=>{r[n[e]]=e})),t.ERROR_PACKET={type:"error",data:"parser error"}},469:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.decode=t.encode=void 0;const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let e=0;e<64;e++)r[n.charCodeAt(e)]=e;t.encode=e=>{let t,r=new Uint8Array(e),s=r.length,o="";for(t=0;t<s;t+=3)o+=n[r[t]>>2],o+=n[(3&r[t])<<4|r[t+1]>>4],o+=n[(15&r[t+1])<<2|r[t+2]>>6],o+=n[63&r[t+2]];return s%3==2?o=o.substring(0,o.length-1)+"=":s%3==1&&(o=o.substring(0,o.length-2)+"=="),o},t.decode=e=>{let t,n,s,o,i,a=.75*e.length,c=e.length,l=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);const u=new ArrayBuffer(a),h=new Uint8Array(u);for(t=0;t<c;t+=4)n=r[e.charCodeAt(t)],s=r[e.charCodeAt(t+1)],o=r[e.charCodeAt(t+2)],i=r[e.charCodeAt(t+3)],h[l++]=n<<2|s>>4,h[l++]=(15&s)<<4|o>>2,h[l++]=(3&o)<<6|63&i;return u}},572:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.decodePacket=void 0;const r=n(87),s=n(469),o="function"==typeof ArrayBuffer;t.decodePacket=(e,t)=>{if("string"!=typeof e)return{type:"message",data:a(e,t)};const n=e.charAt(0);return"b"===n?{type:"message",data:i(e.substring(1),t)}:r.PACKET_TYPES_REVERSE[n]?e.length>1?{type:r.PACKET_TYPES_REVERSE[n],data:e.substring(1)}:{type:r.PACKET_TYPES_REVERSE[n]}:r.ERROR_PACKET};const i=(e,t)=>{if(o){const n=(0,s.decode)(e);return a(n,t)}return{base64:!0,data:e}},a=(e,t)=>"blob"===t?e instanceof Blob?e:new Blob([e]):e instanceof ArrayBuffer?e:e.buffer},908:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.encodePacket=t.encodePacketToBinary=void 0;const r=n(87),s="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),o="function"==typeof ArrayBuffer,i=e=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,a=({type:e,data:t},n,a)=>s&&t instanceof Blob?n?a(t):c(t,a):o&&(t instanceof ArrayBuffer||i(t))?n?a(t):c(new Blob([t]),a):a(r.PACKET_TYPES[e]+(t||""));t.encodePacket=a;const c=(e,t)=>{const n=new FileReader;return n.onload=function(){const e=n.result.split(",")[1];t("b"+(e||""))},n.readAsDataURL(e)};function l(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let u;t.encodePacketToBinary=function(e,t){return s&&e.data instanceof Blob?e.data.arrayBuffer().then(l).then(t):o&&(e.data instanceof ArrayBuffer||i(e.data))?t(l(e.data)):void a(e,!1,(e=>{u||(u=new TextEncoder),t(u.encode(e))}))}},373:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.decodePayload=t.decodePacket=t.encodePayload=t.encodePacket=t.protocol=t.createPacketDecoderStream=t.createPacketEncoderStream=void 0;const r=n(908);Object.defineProperty(t,"encodePacket",{enumerable:!0,get:function(){return r.encodePacket}});const s=n(572);Object.defineProperty(t,"decodePacket",{enumerable:!0,get:function(){return s.decodePacket}});const o=n(87),i=String.fromCharCode(30);let a;function c(e){return e.reduce(((e,t)=>e+t.length),0)}function l(e,t){if(e[0].length===t)return e.shift();const n=new Uint8Array(t);let r=0;for(let s=0;s<t;s++)n[s]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),n}t.encodePayload=(e,t)=>{const n=e.length,s=new Array(n);let o=0;e.forEach(((e,a)=>{(0,r.encodePacket)(e,!1,(e=>{s[a]=e,++o===n&&t(s.join(i))}))}))},t.decodePayload=(e,t)=>{const n=e.split(i),r=[];for(let e=0;e<n.length;e++){const o=(0,s.decodePacket)(n[e],t);if(r.push(o),"error"===o.type)break}return r},t.createPacketEncoderStream=function(){return new TransformStream({transform(e,t){(0,r.encodePacketToBinary)(e,(n=>{const r=n.length;let s;if(r<126)s=new Uint8Array(1),new DataView(s.buffer).setUint8(0,r);else if(r<65536){s=new Uint8Array(3);const e=new DataView(s.buffer);e.setUint8(0,126),e.setUint16(1,r)}else{s=new Uint8Array(9);const e=new DataView(s.buffer);e.setUint8(0,127),e.setBigUint64(1,BigInt(r))}e.data&&"string"!=typeof e.data&&(s[0]|=128),t.enqueue(s),t.enqueue(n)}))}})},t.createPacketDecoderStream=function(e,t){a||(a=new TextDecoder);const n=[];let r=0,i=-1,u=!1;return new TransformStream({transform(h,d){for(n.push(h);;){if(0===r){if(c(n)<1)break;const e=l(n,1);u=128==(128&e[0]),i=127&e[0],r=i<126?3:126===i?1:2}else if(1===r){if(c(n)<2)break;const e=l(n,2);i=new DataView(e.buffer,e.byteOffset,e.length).getUint16(0),r=3}else if(2===r){if(c(n)<8)break;const e=l(n,8),t=new DataView(e.buffer,e.byteOffset,e.length),s=t.getUint32(0);if(s>Math.pow(2,21)-1){d.enqueue(o.ERROR_PACKET);break}i=s*Math.pow(2,32)+t.getUint32(4),r=3}else{if(c(n)<i)break;const e=l(n,i);d.enqueue((0,s.decodePacket)(u?e:a.decode(e),t)),r=0}if(0===i||i>e){d.enqueue(o.ERROR_PACKET);break}}}})},t.protocol=4},159:(e,t)=>{"use strict";function n(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}Object.defineProperty(t,"__esModule",{value:!0}),t.Backoff=void 0,t.Backoff=n,n.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=0==(1&Math.floor(10*t))?e-n:e+n}return 0|Math.min(e,this.max)},n.prototype.reset=function(){this.attempts=0},n.prototype.setMin=function(e){this.ms=e},n.prototype.setMax=function(e){this.max=e},n.prototype.setJitter=function(e){this.jitter=e}},46:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.connect=t.io=t.Socket=t.Manager=t.protocol=void 0;const s=n(84),o=n(168);Object.defineProperty(t,"Manager",{enumerable:!0,get:function(){return o.Manager}});const i=n(312);Object.defineProperty(t,"Socket",{enumerable:!0,get:function(){return i.Socket}});const a=r(n(227)).default("socket.io-client"),c={};function l(e,t){"object"==typeof e&&(t=e,e=void 0),t=t||{};const n=s.url(e,t.path||"/socket.io"),r=n.source,i=n.id,l=n.path,u=c[i]&&l in c[i].nsps;let h;return t.forceNew||t["force new connection"]||!1===t.multiplex||u?(a("ignoring socket cache for %s",r),h=new o.Manager(r,t)):(c[i]||(a("new io instance for %s",r),c[i]=new o.Manager(r,t)),h=c[i]),n.query&&!t.query&&(t.query=n.queryKey),h.socket(n.path,t)}t.io=l,t.connect=l,t.default=l,Object.assign(l,{Manager:o.Manager,Socket:i.Socket,io:l,connect:l});var u=n(514);Object.defineProperty(t,"protocol",{enumerable:!0,get:function(){return u.protocol}}),e.exports=l},168:function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),s=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return s(t,e),t},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Manager=void 0;const a=n(679),c=n(312),l=o(n(514)),u=n(149),h=n(159),d=n(260),f=i(n(227)).default("socket.io-client:manager");class p extends d.Emitter{constructor(e,t){var n;super(),this.nsps={},this.subs=[],e&&"object"==typeof e&&(t=e,e=void 0),(t=t||{}).path=t.path||"/socket.io",this.opts=t,a.installTimerFunctions(this,t),this.reconnection(!1!==t.reconnection),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(n=t.randomizationFactor)&&void 0!==n?n:.5),this.backoff=new h.Backoff({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==t.timeout?2e4:t.timeout),this._readyState="closed",this.uri=e;const r=t.parser||l;this.encoder=new r.Encoder,this.decoder=new r.Decoder,this._autoConnect=!1!==t.autoConnect,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,this):this._reconnection}reconnectionAttempts(e){return void 0===e?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var t;return void 0===e?this._reconnectionDelay:(this._reconnectionDelay=e,null===(t=this.backoff)||void 0===t||t.setMin(e),this)}randomizationFactor(e){var t;return void 0===e?this._randomizationFactor:(this._randomizationFactor=e,null===(t=this.backoff)||void 0===t||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return void 0===e?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,null===(t=this.backoff)||void 0===t||t.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(e){if(f("readyState %s",this._readyState),~this._readyState.indexOf("open"))return this;f("opening %s",this.uri),this.engine=new a.Socket(this.uri,this.opts);const t=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;const r=u.on(t,"open",(function(){n.onopen(),e&&e()})),s=t=>{f("error"),this.cleanup(),this._readyState="closed",this.emitReserved("error",t),e?e(t):this.maybeReconnectOnOpen()},o=u.on(t,"error",s);if(!1!==this._timeout){const e=this._timeout;f("connect attempt will timeout after %d",e);const n=this.setTimeoutFn((()=>{f("connect attempt timed out after %d",e),r(),s(new Error("timeout")),t.close()}),e);this.opts.autoUnref&&n.unref(),this.subs.push((()=>{this.clearTimeoutFn(n)}))}return this.subs.push(r),this.subs.push(o),this}connect(e){return this.open(e)}onopen(){f("open"),this.cleanup(),this._readyState="open",this.emitReserved("open");const e=this.engine;this.subs.push(u.on(e,"ping",this.onping.bind(this)),u.on(e,"data",this.ondata.bind(this)),u.on(e,"error",this.onerror.bind(this)),u.on(e,"close",this.onclose.bind(this)),u.on(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(e){this.onclose("parse error",e)}}ondecoded(e){a.nextTick((()=>{this.emitReserved("packet",e)}),this.setTimeoutFn)}onerror(e){f("error",e),this.emitReserved("error",e)}socket(e,t){let n=this.nsps[e];return n?this._autoConnect&&!n.active&&n.connect():(n=new c.Socket(this,e,t),this.nsps[e]=n),n}_destroy(e){const t=Object.keys(this.nsps);for(const e of t)if(this.nsps[e].active)return void f("socket %s is still active, skipping close",e);this._close()}_packet(e){f("writing packet %j",e);const t=this.encoder.encode(e);for(let n=0;n<t.length;n++)this.engine.write(t[n],e.options)}cleanup(){f("cleanup"),this.subs.forEach((e=>e())),this.subs.length=0,this.decoder.destroy()}_close(){f("disconnect"),this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(e,t){f("closed due to %s",e),this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,t),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const e=this;if(this.backoff.attempts>=this._reconnectionAttempts)f("reconnect failed"),this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const t=this.backoff.duration();f("will wait %dms before reconnect attempt",t),this._reconnecting=!0;const n=this.setTimeoutFn((()=>{e.skipReconnect||(f("attempting reconnect"),this.emitReserved("reconnect_attempt",e.backoff.attempts),e.skipReconnect||e.open((t=>{t?(f("reconnect attempt error"),e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",t)):(f("reconnect success"),e.onreconnect())})))}),t);this.opts.autoUnref&&n.unref(),this.subs.push((()=>{this.clearTimeoutFn(n)}))}}onreconnect(){const e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}}t.Manager=p},149:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.on=void 0,t.on=function(e,t,n){return e.on(t,n),function(){e.off(t,n)}}},312:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Socket=void 0;const s=n(514),o=n(149),i=n(260),a=r(n(227)).default("socket.io-client:socket"),c=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class l extends i.Emitter{constructor(e,t,n){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=t,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const e=this.io;this.subs=[o.on(e,"open",this.onopen.bind(this)),o.on(e,"packet",this.onpacket.bind(this)),o.on(e,"error",this.onerror.bind(this)),o.on(e,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...t){if(c.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(t.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(t),this;const n={type:s.PacketType.EVENT,data:t,options:{}};if(n.options.compress=!1!==this.flags.compress,"function"==typeof t[t.length-1]){const e=this.ids++;a("emitting packet with ack id %d",e);const r=t.pop();this._registerAckCallback(e,r),n.id=e}const r=this.io.engine&&this.io.engine.transport&&this.io.engine.transport.writable;return!this.flags.volatile||r&&this.connected?this.connected?(this.notifyOutgoingListeners(n),this.packet(n)):this.sendBuffer.push(n):a("discard packet as the transport is not currently writable"),this.flags={},this}_registerAckCallback(e,t){var n;const r=null!==(n=this.flags.timeout)&&void 0!==n?n:this._opts.ackTimeout;if(void 0===r)return void(this.acks[e]=t);const s=this.io.setTimeoutFn((()=>{delete this.acks[e];for(let t=0;t<this.sendBuffer.length;t++)this.sendBuffer[t].id===e&&(a("removing packet with ack id %d from the buffer",e),this.sendBuffer.splice(t,1));a("event with ack id %d has timed out after %d ms",e,r),t.call(this,new Error("operation has timed out"))}),r);this.acks[e]=(...e)=>{this.io.clearTimeoutFn(s),t.apply(this,[null,...e])}}emitWithAck(e,...t){const n=void 0!==this.flags.timeout||void 0!==this._opts.ackTimeout;return new Promise(((r,s)=>{t.push(((e,t)=>n?e?s(e):r(t):r(e))),this.emit(e,...t)}))}_addToQueue(e){let t;"function"==typeof e[e.length-1]&&(t=e.pop());const n={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push(((e,...r)=>{if(n===this._queue[0])return null!==e?n.tryCount>this._opts.retries&&(a("packet [%d] is discarded after %d tries",n.id,n.tryCount),this._queue.shift(),t&&t(e)):(a("packet [%d] was successfully sent",n.id),this._queue.shift(),t&&t(null,...r)),n.pending=!1,this._drainQueue()})),this._queue.push(n),this._drainQueue()}_drainQueue(e=!1){if(a("draining queue"),!this.connected||0===this._queue.length)return;const t=this._queue[0];!t.pending||e?(t.pending=!0,t.tryCount++,a("sending packet [%d] (try n°%d)",t.id,t.tryCount),this.flags=t.flags,this.emit.apply(this,t.args)):a("packet [%d] has already been sent and is waiting for an ack",t.id)}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){a("transport is open - connecting"),"function"==typeof this.auth?this.auth((e=>{this._sendConnectPacket(e)})):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:s.PacketType.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,t){a("close (%s)",e),this.connected=!1,delete this.id,this.emitReserved("disconnect",e,t)}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case s.PacketType.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case s.PacketType.EVENT:case s.PacketType.BINARY_EVENT:this.onevent(e);break;case s.PacketType.ACK:case s.PacketType.BINARY_ACK:this.onack(e);break;case s.PacketType.DISCONNECT:this.ondisconnect();break;case s.PacketType.CONNECT_ERROR:this.destroy();const t=new Error(e.data.message);t.data=e.data.data,this.emitReserved("connect_error",t)}}onevent(e){const t=e.data||[];a("emitting event %j",t),null!=e.id&&(a("attaching ack callback to event"),t.push(this.ack(e.id))),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){const t=this._anyListeners.slice();for(const n of t)n.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&"string"==typeof e[e.length-1]&&(this._lastOffset=e[e.length-1])}ack(e){const t=this;let n=!1;return function(...r){n||(n=!0,a("sending ack %j",r),t.packet({type:s.PacketType.ACK,id:e,data:r}))}}onack(e){const t=this.acks[e.id];"function"==typeof t?(a("calling ack %s with %j",e.id,e.data),t.apply(this,e.data),delete this.acks[e.id]):a("bad ack %s",e.id)}onconnect(e,t){a("socket connected with id %s",e),this.id=e,this.recovered=t&&this._pid===t,this._pid=t,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach((e=>this.emitEvent(e))),this.receiveBuffer=[],this.sendBuffer.forEach((e=>{this.notifyOutgoingListeners(e),this.packet(e)})),this.sendBuffer=[]}ondisconnect(){a("server disconnect (%s)",this.nsp),this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach((e=>e())),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&(a("performing disconnect (%s)",this.nsp),this.packet({type:s.PacketType.DISCONNECT})),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){const t=this._anyListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){const t=this._anyOutgoingListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const t=this._anyOutgoingListeners.slice();for(const n of t)n.apply(this,e.data)}}}t.Socket=l},84:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.url=void 0;const s=n(679),o=r(n(227)).default("socket.io-client:url");t.url=function(e,t="",n){let r=e;n=n||"undefined"!=typeof location&&location,null==e&&(e=n.protocol+"//"+n.host),"string"==typeof e&&("/"===e.charAt(0)&&(e="/"===e.charAt(1)?n.protocol+e:n.host+e),/^(https?|wss?):\/\//.test(e)||(o("protocol-less url %s",e),e=void 0!==n?n.protocol+"//"+e:"https://"+e),o("parse %s",e),r=s.parse(e)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";const i=-1!==r.host.indexOf(":")?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+i+":"+r.port+t,r.href=r.protocol+"://"+i+(n&&n.port===r.port?"":":"+r.port),r}},269:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.reconstructPacket=t.deconstructPacket=void 0;const r=n(665);function s(e,t){if(!e)return e;if((0,r.isBinary)(e)){const n={_placeholder:!0,num:t.length};return t.push(e),n}if(Array.isArray(e)){const n=new Array(e.length);for(let r=0;r<e.length;r++)n[r]=s(e[r],t);return n}if("object"==typeof e&&!(e instanceof Date)){const n={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=s(e[r],t));return n}return e}function o(e,t){if(!e)return e;if(e&&!0===e._placeholder){if("number"==typeof e.num&&e.num>=0&&e.num<t.length)return t[e.num];throw new Error("illegal attachments")}if(Array.isArray(e))for(let n=0;n<e.length;n++)e[n]=o(e[n],t);else if("object"==typeof e)for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(e[n]=o(e[n],t));return e}t.deconstructPacket=function(e){const t=[],n=e.data,r=e;return r.data=s(n,t),r.attachments=t.length,{packet:r,buffers:t}},t.reconstructPacket=function(e,t){return e.data=o(e.data,t),delete e.attachments,e}},514:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Decoder=t.Encoder=t.PacketType=t.protocol=void 0;const r=n(260),s=n(269),o=n(665),i=(0,n(227).default)("socket.io-parser"),a=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var c;function l(e){return"[object Object]"===Object.prototype.toString.call(e)}t.protocol=5,function(e){e[e.CONNECT=0]="CONNECT",e[e.DISCONNECT=1]="DISCONNECT",e[e.EVENT=2]="EVENT",e[e.ACK=3]="ACK",e[e.CONNECT_ERROR=4]="CONNECT_ERROR",e[e.BINARY_EVENT=5]="BINARY_EVENT",e[e.BINARY_ACK=6]="BINARY_ACK"}(c=t.PacketType||(t.PacketType={})),t.Encoder=class{constructor(e){this.replacer=e}encode(e){return i("encoding packet %j",e),e.type!==c.EVENT&&e.type!==c.ACK||!(0,o.hasBinary)(e)?[this.encodeAsString(e)]:this.encodeAsBinary({type:e.type===c.EVENT?c.BINARY_EVENT:c.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id})}encodeAsString(e){let t=""+e.type;return e.type!==c.BINARY_EVENT&&e.type!==c.BINARY_ACK||(t+=e.attachments+"-"),e.nsp&&"/"!==e.nsp&&(t+=e.nsp+","),null!=e.id&&(t+=e.id),null!=e.data&&(t+=JSON.stringify(e.data,this.replacer)),i("encoded %j as %s",e,t),t}encodeAsBinary(e){const t=(0,s.deconstructPacket)(e),n=this.encodeAsString(t.packet),r=t.buffers;return r.unshift(n),r}};class u extends r.Emitter{constructor(e){super(),this.reviver=e}add(e){let t;if("string"==typeof e){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");t=this.decodeString(e);const n=t.type===c.BINARY_EVENT;n||t.type===c.BINARY_ACK?(t.type=n?c.EVENT:c.ACK,this.reconstructor=new h(t),0===t.attachments&&super.emitReserved("decoded",t)):super.emitReserved("decoded",t)}else{if(!(0,o.isBinary)(e)&&!e.base64)throw new Error("Unknown type: "+e);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved("decoded",t))}}decodeString(e){let t=0;const n={type:Number(e.charAt(0))};if(void 0===c[n.type])throw new Error("unknown packet type "+n.type);if(n.type===c.BINARY_EVENT||n.type===c.BINARY_ACK){const r=t+1;for(;"-"!==e.charAt(++t)&&t!=e.length;);const s=e.substring(r,t);if(s!=Number(s)||"-"!==e.charAt(t))throw new Error("Illegal attachments");n.attachments=Number(s)}if("/"===e.charAt(t+1)){const r=t+1;for(;++t&&","!==e.charAt(t)&&t!==e.length;);n.nsp=e.substring(r,t)}else n.nsp="/";const r=e.charAt(t+1);if(""!==r&&Number(r)==r){const r=t+1;for(;++t;){const n=e.charAt(t);if(null==n||Number(n)!=n){--t;break}if(t===e.length)break}n.id=Number(e.substring(r,t+1))}if(e.charAt(++t)){const r=this.tryParse(e.substr(t));if(!u.isPayloadValid(n.type,r))throw new Error("invalid payload");n.data=r}return i("decoded %s as %j",e,n),n}tryParse(e){try{return JSON.parse(e,this.reviver)}catch(e){return!1}}static isPayloadValid(e,t){switch(e){case c.CONNECT:return l(t);case c.DISCONNECT:return void 0===t;case c.CONNECT_ERROR:return"string"==typeof t||l(t);case c.EVENT:case c.BINARY_EVENT:return Array.isArray(t)&&("number"==typeof t[0]||"string"==typeof t[0]&&-1===a.indexOf(t[0]));case c.ACK:case c.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}t.Decoder=u;class h{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){const e=(0,s.reconstructPacket)(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}},665:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.hasBinary=t.isBinary=void 0;const n="function"==typeof ArrayBuffer,r=Object.prototype.toString,s="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===r.call(Blob),o="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===r.call(File);function i(e){return n&&(e instanceof ArrayBuffer||(e=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer)(e))||s&&e instanceof Blob||o&&e instanceof File}t.isBinary=i,t.hasBinary=function e(t,n){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let n=0,r=t.length;n<r;n++)if(e(t[n]))return!0;return!1}if(i(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return e(t.toJSON(),!0);for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&e(t[n]))return!0;return!1}},260:(e,t,n)=>{"use strict";function r(e){if(e)return function(e){for(var t in r.prototype)e[t]=r.prototype[t];return e}(e)}n.r(t),n.d(t,{Emitter:()=>r}),r.prototype.on=r.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},r.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},r.prototype.off=r.prototype.removeListener=r.prototype.removeAllListeners=r.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var s=0;s<r.length;s++)if((n=r[s])===t||n.fn===t){r.splice(s,1);break}return 0===r.length&&delete this._callbacks["$"+e],this},r.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),n=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){r=0;for(var s=(n=n.slice(0)).length;r<s;++r)n[r].apply(this,t)}return this},r.prototype.emitReserved=r.prototype.emit,r.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},r.prototype.hasListeners=function(e){return!!this.listeners(e).length}}},t={};function n(r){var s=t[r];if(void 0!==s)return s.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";var e=r;Object.defineProperty(e,"__esModule",{value:!0}),e.validateConfiguration=e.parseConnectionString=e.prepareSql=e.escapeSqlParameter=e.SQLiteCloudRow=e.SQLiteCloudRowset=e.SQLiteCloudError=e.SQLiteCloudConnection=e.Statement=e.Database=void 0;var t=n(751);Object.defineProperty(e,"Database",{enumerable:!0,get:function(){return t.Database}});var s=n(880);Object.defineProperty(e,"Statement",{enumerable:!0,get:function(){return s.Statement}});var o=n(480);Object.defineProperty(e,"SQLiteCloudConnection",{enumerable:!0,get:function(){return o.SQLiteCloudConnection}});var i=n(906);Object.defineProperty(e,"SQLiteCloudError",{enumerable:!0,get:function(){return i.SQLiteCloudError}});var a=n(825);Object.defineProperty(e,"SQLiteCloudRowset",{enumerable:!0,get:function(){return a.SQLiteCloudRowset}}),Object.defineProperty(e,"SQLiteCloudRow",{enumerable:!0,get:function(){return a.SQLiteCloudRow}});var c=n(73);Object.defineProperty(e,"escapeSqlParameter",{enumerable:!0,get:function(){return c.escapeSqlParameter}}),Object.defineProperty(e,"prepareSql",{enumerable:!0,get:function(){return c.prepareSql}}),Object.defineProperty(e,"parseConnectionString",{enumerable:!0,get:function(){return c.parseConnectionString}}),Object.defineProperty(e,"validateConfiguration",{enumerable:!0,get:function(){return c.validateConfiguration}})})(),r})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sqlitecloud/drivers",
3
- "version": "0.0.39",
3
+ "version": "0.0.50",
4
4
  "description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -9,12 +9,16 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "test": "jest --coverage",
12
- "build": "rm -rf ./lib/ && tsc --project tsconfig.build.json && npx webpack",
12
+ "build": "rm -rf ./lib/ && tsc --project tsconfig.build.json && npx webpack && cp ./lib/sqlitecloud.drivers.js ./public/ && cp ./lib/sqlitecloud.drivers.dev.js ./public/",
13
13
  "publish": "npm run build && npm publish --access public",
14
14
  "prettier": "prettier --write 'src/**/*'",
15
15
  "lint": "eslint ./src/ --fix && tsc --noEmit",
16
16
  "typedoc": "rm -rf ./docs/ && typedoc --out docs && typedoc --plugin typedoc-plugin-markdown --out docs/markdown",
17
- "npmgui": "npx npm-gui@latest"
17
+ "npmgui": "npx npm-gui@latest",
18
+ "gateway-dev": "bun --watch ./src/gateway/gateway.ts",
19
+ "gateway-start": "bun --smol run ./src/gateway/gateway.ts",
20
+ "gateway-test": "bun test ./src/gateway/connection-bun.test.ts --watch --coverage",
21
+ "gateway-build": "./scripts/gateway-build.sh"
18
22
  },
19
23
  "repository": {
20
24
  "type": "git",
@@ -43,16 +47,21 @@
43
47
  "homepage": "https://github.com/sqlitecloud/sqlitecloud-js#readme",
44
48
  "dependencies": {
45
49
  "eventemitter3": "^5.0.1",
50
+ "express": "^4.18.2",
46
51
  "lz4js": "^0.2.0",
52
+ "socket.io": "^4.7.4",
47
53
  "socket.io-client": "^4.7.4"
48
54
  },
49
55
  "devDependencies": {
56
+ "@types/bun": "^1.0.5",
57
+ "@types/express": "^4.17.21",
50
58
  "@types/jest": "^29.5.11",
51
59
  "@types/lz4": "^0.6.4",
52
60
  "@types/node": "^12.20.55",
53
61
  "@typescript-eslint/eslint-plugin": "^4.22.0",
54
62
  "@typescript-eslint/parser": "^4.22.0",
55
63
  "dotenv": "^16.4.1",
64
+ "dotenv-cli": "^7.3.0",
56
65
  "eslint": "^7.32.0",
57
66
  "eslint-config-prettier": "^8.10.0",
58
67
  "eslint-plugin-node": "^11.1.0",
@@ -1,65 +0,0 @@
1
- /**
2
- * connection.ts - handles low level communication with sqlitecloud server
3
- */
4
- import { SQLiteCloudConfig, ErrorCallback, ResultsCallback } from './types';
5
- /** Default timeout value for queries */
6
- export declare const DEFAULT_TIMEOUT: number;
7
- /** Default tls connection port */
8
- export declare const DEFAULT_PORT = 9960;
9
- /**
10
- * Base class for SQLiteCloudConnection handles basics and defines methods.
11
- * Actual connection management and communication with the server in concrete classes.
12
- */
13
- export declare class SQLiteCloudConnection {
14
- /** Parse and validate provided connectionString or configuration */
15
- constructor(config: SQLiteCloudConfig | string, callback?: ErrorCallback);
16
- /** Configuration passed by client or extracted from connection string */
17
- protected config: SQLiteCloudConfig;
18
- /** Transport used to communicate with server */
19
- protected transport?: ConnectionTransport;
20
- /** Operations are serialized by waiting an any pending promises */
21
- protected operations: OperationsQueue;
22
- /** True if connection is open */
23
- get connected(): boolean;
24
- /** Connect will establish a tls or websocket transport to the server based on configuration and environment */
25
- protected connect(callback?: ErrorCallback): this;
26
- /** Validate configuration, apply defaults, throw if something is missing or misconfigured */
27
- protected validateConfiguration(config: SQLiteCloudConfig): SQLiteCloudConfig;
28
- /** Will log to console if verbose mode is enabled */
29
- protected log(message: string, ...optionalParams: any[]): void;
30
- /** Enable verbose logging for debug purposes */
31
- verbose(): void;
32
- /** Will enquee a command to be executed and callback with the resulting rowset/result/error */
33
- sendCommands(commands: string, callback?: ResultsCallback): this;
34
- /** Disconnect from server, release connection. */
35
- close(): this;
36
- }
37
- type OperationCallback = (error: Error | null) => void;
38
- type Operation = (done: OperationCallback) => void;
39
- export declare class OperationsQueue {
40
- private queue;
41
- private isProcessing;
42
- /** Add operations to the queue, process immediately if possible, else wait for previous operations to complete */
43
- enqueue(operation: Operation): void;
44
- /** Clear the queue */
45
- clear(): void;
46
- /** Process the next operation in the queue */
47
- private processNext;
48
- }
49
- /** Messages going to the server are sometimes logged when error conditions occour and need to be stripped of user credentials */
50
- export declare function anonimizeCommand(message: string): string;
51
- /** Strip message code in error of user credentials */
52
- export declare function anonimizeError(error: Error): Error;
53
- /** Initialization commands sent to database when connection is established */
54
- export declare function getInitializationCommands(config: SQLiteCloudConfig): string;
55
- /** ConnectionTransport implements the underlying transport layer for the connection */
56
- export interface ConnectionTransport {
57
- /** True if connection is currently open */
58
- get connected(): boolean;
59
- connect(config: SQLiteCloudConfig, callback?: ErrorCallback): this;
60
- /** Send a command, return the rowset/result or throw an error */
61
- processCommands(commands: string, callback?: ResultsCallback): this;
62
- /** Disconnect from server, release transport. */
63
- close(): this;
64
- }
65
- export {};
package/lib/connection.js DELETED
@@ -1,260 +0,0 @@
1
- "use strict";
2
- /**
3
- * connection.ts - handles low level communication with sqlitecloud server
4
- */
5
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = { enumerable: true, get: function() { return m[k]; } };
10
- }
11
- Object.defineProperty(o, k2, desc);
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
- Object.defineProperty(o, "default", { enumerable: true, value: v });
18
- }) : function(o, v) {
19
- o["default"] = v;
20
- });
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getInitializationCommands = exports.anonimizeError = exports.anonimizeCommand = exports.OperationsQueue = exports.SQLiteCloudConnection = exports.DEFAULT_PORT = exports.DEFAULT_TIMEOUT = void 0;
30
- const types_1 = require("./types");
31
- const utilities_1 = require("./utilities");
32
- /** Default timeout value for queries */
33
- exports.DEFAULT_TIMEOUT = 300 * 1000;
34
- /** Default tls connection port */
35
- exports.DEFAULT_PORT = 9960;
36
- /**
37
- * Base class for SQLiteCloudConnection handles basics and defines methods.
38
- * Actual connection management and communication with the server in concrete classes.
39
- */
40
- class SQLiteCloudConnection {
41
- /** Parse and validate provided connectionString or configuration */
42
- constructor(config, callback) {
43
- /** Operations are serialized by waiting an any pending promises */
44
- this.operations = new OperationsQueue();
45
- if (typeof config === 'string') {
46
- this.config = this.validateConfiguration({ connectionString: config });
47
- }
48
- else {
49
- this.config = this.validateConfiguration(config);
50
- }
51
- // connect transport layer to server
52
- this.connect(callback);
53
- }
54
- //
55
- // public properties
56
- //
57
- /** True if connection is open */
58
- get connected() {
59
- var _a;
60
- return ((_a = this.transport) === null || _a === void 0 ? void 0 : _a.connected) || false;
61
- }
62
- /** Connect will establish a tls or websocket transport to the server based on configuration and environment */
63
- connect(callback) {
64
- this.operations.enqueue(done => {
65
- var _a, _b;
66
- // connect using websocket if tls is not supported or if explicitly requested
67
- if (utilities_1.isBrowser || ((_a = this.config) === null || _a === void 0 ? void 0 : _a.useWebsocket) || ((_b = this.config) === null || _b === void 0 ? void 0 : _b.gatewayUrl)) {
68
- // socket.io transport works in both node.js and browser environments and connects via SQLite Cloud Gateway
69
- Promise.resolve().then(() => __importStar(require('./transport-ws'))).then(transport => {
70
- this.transport = new transport.WebSocketTransport();
71
- this.transport.connect(this.config, error => {
72
- if (error) {
73
- console.error(`SQLiteCloudConnection.connect - error while connecting WebSocketTransport: ${error.toString()}`, this.config, error);
74
- this.close();
75
- }
76
- callback === null || callback === void 0 ? void 0 : callback.call(this, error || null);
77
- done(error);
78
- });
79
- })
80
- .catch(error => {
81
- done(error);
82
- });
83
- }
84
- else {
85
- // tls sockets work only in node.js environments
86
- Promise.resolve().then(() => __importStar(require('./transport-tls'))).then(transport => {
87
- this.transport = new transport.TlsSocketTransport();
88
- this.transport.connect(this.config, error => {
89
- if (error) {
90
- console.error(`SQLiteCloudConnection.connect - error while connecting TlsSocketTransport: ${error.toString()}`, this.config, error);
91
- this.close();
92
- }
93
- callback === null || callback === void 0 ? void 0 : callback.call(this, error || null);
94
- done(error);
95
- });
96
- })
97
- .catch(error => {
98
- done(error);
99
- });
100
- }
101
- });
102
- return this;
103
- }
104
- //
105
- // private methods
106
- //
107
- /** Validate configuration, apply defaults, throw if something is missing or misconfigured */
108
- validateConfiguration(config) {
109
- if (config.connectionString) {
110
- config = Object.assign(Object.assign(Object.assign({}, config), (0, utilities_1.parseConnectionString)(config.connectionString)), { connectionString: config.connectionString // keep original connection string
111
- });
112
- }
113
- // apply defaults where needed
114
- config.port || (config.port = exports.DEFAULT_PORT);
115
- config.timeout = config.timeout && config.timeout > 0 ? config.timeout : exports.DEFAULT_TIMEOUT;
116
- config.clientId || (config.clientId = 'SQLiteCloud');
117
- config.verbose = (0, utilities_1.parseBoolean)(config.verbose);
118
- config.noBlob = (0, utilities_1.parseBoolean)(config.noBlob);
119
- config.compression = (0, utilities_1.parseBoolean)(config.compression);
120
- config.createDatabase = (0, utilities_1.parseBoolean)(config.createDatabase);
121
- config.nonlinearizable = (0, utilities_1.parseBoolean)(config.nonlinearizable);
122
- if (!config.username || !config.password || !config.host) {
123
- console.error('SQLiteCloudConnection.validateConfiguration - missing arguments', config);
124
- throw new types_1.SQLiteCloudError('The user, password and host arguments must be specified.', { errorCode: 'ERR_MISSING_ARGS' });
125
- }
126
- if (!config.connectionString) {
127
- // build connection string from configuration, values are already validated
128
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
129
- config.connectionString = `sqlitecloud://${config.username}:${config.password}@${config.host}:${config.port}/${config.database}`;
130
- }
131
- return config;
132
- }
133
- /** Will log to console if verbose mode is enabled */
134
- log(message, ...optionalParams) {
135
- if (this.config.verbose) {
136
- message = anonimizeCommand(message);
137
- console.log(`${new Date().toISOString()} ${this.config.clientId}: ${message}`, ...optionalParams);
138
- }
139
- }
140
- //
141
- // public methods
142
- //
143
- /** Enable verbose logging for debug purposes */
144
- verbose() {
145
- this.config.verbose = true;
146
- }
147
- /** Will enquee a command to be executed and callback with the resulting rowset/result/error */
148
- sendCommands(commands, callback) {
149
- this.operations.enqueue(done => {
150
- if (this.transport) {
151
- this.transport.processCommands(commands, (error, result) => {
152
- callback === null || callback === void 0 ? void 0 : callback.call(this, error, result);
153
- done(error);
154
- });
155
- }
156
- else {
157
- const error = new types_1.SQLiteCloudError('Connection not established', { errorCode: 'ERR_CONNECTION_NOT_ESTABLISHED' });
158
- callback === null || callback === void 0 ? void 0 : callback.call(this, error);
159
- done(error);
160
- }
161
- });
162
- return this;
163
- }
164
- /** Disconnect from server, release connection. */
165
- close() {
166
- var _a;
167
- this.operations.clear();
168
- (_a = this.transport) === null || _a === void 0 ? void 0 : _a.close();
169
- this.transport = undefined;
170
- return this;
171
- }
172
- }
173
- exports.SQLiteCloudConnection = SQLiteCloudConnection;
174
- class OperationsQueue {
175
- constructor() {
176
- this.queue = [];
177
- this.isProcessing = false;
178
- }
179
- /** Add operations to the queue, process immediately if possible, else wait for previous operations to complete */
180
- enqueue(operation) {
181
- this.queue.push(operation);
182
- if (!this.isProcessing) {
183
- this.processNext();
184
- }
185
- }
186
- /** Clear the queue */
187
- clear() {
188
- this.queue = [];
189
- this.isProcessing = false;
190
- }
191
- /** Process the next operation in the queue */
192
- processNext() {
193
- if (this.queue.length === 0) {
194
- this.isProcessing = false;
195
- return;
196
- }
197
- this.isProcessing = true;
198
- const operation = this.queue.shift();
199
- operation === null || operation === void 0 ? void 0 : operation(() => {
200
- // could receive (error) => { ...
201
- // if (error) {
202
- // console.warn('OperationQueue.processNext - error in operation', error)
203
- // }
204
- // process the next operation in the queue
205
- this.processNext();
206
- });
207
- }
208
- }
209
- exports.OperationsQueue = OperationsQueue;
210
- //
211
- // utility functions
212
- //
213
- /** Messages going to the server are sometimes logged when error conditions occour and need to be stripped of user credentials */
214
- function anonimizeCommand(message) {
215
- // hide password in AUTH command if needed
216
- message = message.replace(/USER \S+/, 'USER ******');
217
- message = message.replace(/PASSWORD \S+?(?=;)/, 'PASSWORD ******');
218
- message = message.replace(/HASH \S+?(?=;)/, 'HASH ******');
219
- return message;
220
- }
221
- exports.anonimizeCommand = anonimizeCommand;
222
- /** Strip message code in error of user credentials */
223
- function anonimizeError(error) {
224
- if (error === null || error === void 0 ? void 0 : error.message) {
225
- error.message = anonimizeCommand(error.message);
226
- }
227
- return error;
228
- }
229
- exports.anonimizeError = anonimizeError;
230
- /** Initialization commands sent to database when connection is established */
231
- function getInitializationCommands(config) {
232
- // first user authentication, then all other commands
233
- let commands = `AUTH USER ${config.username || ''} ${config.passwordHashed ? 'HASH' : 'PASSWORD'} ${config.password || ''}; `;
234
- if (config.database) {
235
- if (config.createDatabase && !config.dbMemory) {
236
- commands += `CREATE DATABASE ${config.database} IF NOT EXISTS; `;
237
- }
238
- commands += `USE DATABASE ${config.database}; `;
239
- }
240
- if (config.compression) {
241
- commands += 'SET CLIENT KEY COMPRESSION TO 1; ';
242
- }
243
- if (config.nonlinearizable) {
244
- commands += 'SET CLIENT KEY NONLINEARIZABLE TO 1; ';
245
- }
246
- if (config.noBlob) {
247
- commands += 'SET CLIENT KEY NOBLOB TO 1; ';
248
- }
249
- if (config.maxData) {
250
- commands += `SET CLIENT KEY MAXDATA TO ${config.maxData}; `;
251
- }
252
- if (config.maxRows) {
253
- commands += `SET CLIENT KEY MAXROWS TO ${config.maxRows}; `;
254
- }
255
- if (config.maxRowset) {
256
- commands += `SET CLIENT KEY MAXROWSET TO ${config.maxRowset}; `;
257
- }
258
- return commands;
259
- }
260
- exports.getInitializationCommands = getInitializationCommands;