@vuu-ui/vuu-data-remote 0.8.21 → 0.8.22-debug
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.
- package/cjs/index.js +3502 -1
- package/cjs/index.js.map +3 -3
- package/esm/index.js +3501 -1
- package/esm/index.js.map +3 -3
- package/package.json +7 -7
- package/types/inlined-worker.d.ts +1 -1
- package/LICENSE +0 -201
package/cjs/index.js
CHANGED
|
@@ -1,2 +1,3503 @@
|
|
|
1
|
-
"use strict";var O=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var ee=(t,r)=>{for(var e in r)O(t,e,{get:r[e],enumerable:!0})},te=(t,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Z(r))!Y.call(t,o)&&o!==e&&O(t,o,{get:()=>r[o],enumerable:!(s=Q(r,o))||s.enumerable});return t};var se=t=>te(O({},"__esModule",{value:!0}),t);var $=(t,r,e)=>{if(!r.has(t))throw TypeError("Cannot "+e)};var i=(t,r,e)=>($(t,r,"read from private field"),e?e.call(t):r.get(t)),f=(t,r,e)=>{if(r.has(t))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(t):r.set(t,e)},a=(t,r,e,s)=>($(t,r,"write to private field"),s?s.call(t,e):r.set(t,e),e);var Ie={};ee(Ie,{ConnectionManager:()=>k,VuuDataSource:()=>B,authenticate:()=>re,connectToServer:()=>ge,connectionId:()=>ve,createSchemaFromTableMetadata:()=>_e,getFirstAndLastRows:()=>me,getServerAPI:()=>x,groupRowsByViewport:()=>Se,isDataSourceConfigMessage:()=>D,isSessionTable:()=>z,isSessionTableActionMessage:()=>le,isSizeOnly:()=>ne,isVuuMenuRpcRequest:()=>Ee,isVuuRpcRequest:()=>Ce,makeRpcCall:()=>fe,msgType:()=>Re,shouldMessageBeRoutedToDataSource:()=>N,stripRequestId:()=>Te,toDataSourceConfig:()=>oe});module.exports=se(Ie);var ie="api/authn",re=async(t,r,e=ie)=>fetch(e,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","access-control-allow-origin":location.host},body:JSON.stringify({username:t,password:r})}).then(s=>{if(s.ok){let o=s.headers.get("vuu-auth-token");if(typeof o=="string"&&o.length>0)return o;throw Error("Authentication failed auth token not returned by server")}else throw Error(`Authentication failed ${s.status} ${s.statusText}`)});var p=require("@vuu-ui/vuu-utils");var ne=t=>t.type==="viewport-update"&&t.mode==="size-only",oe=t=>{switch(t.type){case"aggregate":return{aggregations:t.aggregations};case"columns":return{columns:t.columns};case"filter":return{filter:t.filter};case"groupBy":return{groupBy:t.groupBy};case"sort":return{sort:t.sort};case"config":return t.config}},ae=["config","aggregate","viewport-update","columns","debounce-begin","disabled","enabled","filter","groupBy","vuu-link-created","vuu-link-removed","vuu-links","vuu-menu","sort","subscribed"],N=t=>{let r=t.type;return ae.includes(r)},D=t=>["config","aggregate","columns","filter","groupBy","sort"].includes(t.type),le=t=>t.type==="VIEW_PORT_MENU_RESP"&&t.action!==null&&z(t.action.table),z=t=>t!==null&&typeof t=="object"&&"table"in t&&"module"in t?t.table.startsWith("session"):!1;var G="GET_TABLE_META";var F='\nvar ie=(r,e,t)=>{if(!e.has(r))throw TypeError("Cannot "+t)};var m=(r,e,t)=>(ie(r,e,"read from private field"),t?t.call(r):e.get(r)),ae=(r,e,t)=>{if(e.has(r))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(r):e.set(r,t)},ue=(r,e,t,s)=>(ie(r,e,"write to private field"),s?s.call(r,t):e.set(r,t),t);function le(r,e,t=[],s=[]){for(let n=0,o=r.length;n<o;n++)(e(r[n],n)?t:s).push(r[n]);return[t,s]}var $={IDX:0,RENDER_IDX:1,IS_LEAF:2,IS_EXPANDED:3,DEPTH:4,COUNT:5,KEY:6,SELECTED:7,count:8,PARENT_IDX:"parent_idx",IDX_POINTER:"idx_pointer",FILTER_COUNT:"filter_count",NEXT_FILTER_IDX:"next_filter_idx"};var{DEPTH:Pt,IS_LEAF:Lt}=$;var ce=r=>{var e,t;if(((e=globalThis.document)==null?void 0:e.cookie)!==void 0)return(t=globalThis.document.cookie.split("; ").find(s=>s.startsWith(`${r}=`)))==null?void 0:t.split("=")[1]};function G({from:r,to:e},t=0,s=Number.MAX_SAFE_INTEGER){if(t===0)return s<r?{from:0,to:0}:{from:r,to:Math.min(e,s)};if(r===0)return{from:r,to:Math.min(e+t,s)};{let n=e-r,o=Math.round(t/2),i=r-o<0,u=s-(e+o)<0;return i&&u?{from:0,to:s}:i?{from:0,to:n+t}:u?{from:Math.max(0,s-(n+t)),to:s}:{from:r-o,to:e+o}}}var je=(r,{from:e,to:t})=>r>=e&&r<t;var D=class r{constructor(e,t){this.from=e,this.to=t}isWithin(e){return je(e,this)}overlap(e,t){return e>=this.to||t<this.from?[0,0]:[Math.max(e,this.from),Math.min(t,this.to)]}copy(){return new r(this.from,this.to)}};var pe=r=>r.type==="connection-status",de=r=>r.type==="connection-metrics";var ge=r=>"viewport"in r;var Qe=["error","warn","info","debug"],Ye=r=>typeof r=="string"&&Qe.includes(r),Ze="error",P=()=>{},Xe="error",{loggingLevel:L=Xe}=et(),b=r=>{let e=L==="debug",t=e||L==="info",s=t||L==="warn",n=s||L==="error",o=t?p=>console.info(`[${r}] ${p}`):P,i=s?p=>console.warn(`[${r}] ${p}`):P,u=e?p=>console.debug(`[${r}] ${p}`):P;return{errorEnabled:n,error:n?p=>console.error(`[${r}] ${p}`):P}};function et(){return typeof loggingSettings<"u"?loggingSettings:{loggingLevel:tt()}}function tt(){let r=ce("vuu-logging-level");return Ye(r)?r:Ze}var{debug:st,debugEnabled:nt}=b("range-monitor"),k=class{constructor(e){this.source=e;this.range={from:0,to:0};this.timestamp=0}isSet(){return this.timestamp!==0}set({from:e,to:t}){let{timestamp:s}=this;if(this.range.from=e,this.range.to=t,this.timestamp=performance.now(),s)nt&&st(`<${this.source}> [${e}-${t}], ${(this.timestamp-s).toFixed(0)} ms elapsed`);else return 0}};var O=class{constructor(e){this.keys=new Map,this.free=[],this.nextKeyValue=0,this.reset(e)}next(){return this.free.length>0?this.free.shift():this.nextKeyValue++}reset({from:e,to:t}){this.keys.forEach((n,o)=>{(o<e||o>=t)&&(this.free.push(n),this.keys.delete(o))});let s=t-e;this.keys.size+this.free.length>s&&(this.free.length=Math.max(0,s-this.keys.size));for(let n=e;n<t;n++)if(!this.keys.has(n)){let o=this.next();this.keys.set(n,o)}this.nextKeyValue>this.keys.size&&(this.nextKeyValue=this.keys.size)}keyFor(e){let t=this.keys.get(e);if(t===void 0)throw console.log(`key not found\n keys: ${this.toDebugString()}\n free : ${this.free.join(",")} \n `),Error(`KeySet, no key found for rowIndex ${e}`);return t}toDebugString(){return Array.from(this.keys.entries()).map(([e,t])=>`${e}=>${t}`).join(",")}};var{SELECTED:$t}=$,w={False:0,True:1,First:2,Last:4};var rt=(r,e)=>e>=r[0]&&e<=r[1],ot=w.True+w.First+w.Last,it=w.True+w.First,at=w.True+w.Last,z=(r,e)=>{for(let t of r)if(typeof t=="number"){if(t===e)return ot}else if(rt(t,e))return e===t[0]?it:e===t[1]?at:w.True;return w.False};var he=r=>{if(r.every(t=>typeof t=="number"))return r;let e=[];for(let t of r)if(typeof t=="number")e.push(t);else for(let s=t[0];s<=t[1];s++)e.push(s);return e};var fe=r=>r.type==="VIEW_PORT_MENU_RESP"&&r.action!==null&&x(r.action.table),x=r=>r!==null&&typeof r=="object"&&"table"in r&&"module"in r?r.table.startsWith("session"):!1;var ut=["VIEW_PORT_MENUS_SELECT_RPC","VIEW_PORT_MENU_TABLE_RPC","VIEW_PORT_MENU_ROW_RPC","VIEW_PORT_MENU_CELL_RPC","VP_EDIT_CELL_RPC","VP_EDIT_ROW_RPC","VP_EDIT_ADD_ROW_RPC","VP_EDIT_DELETE_CELL_RPC","VP_EDIT_DELETE_ROW_RPC","VP_EDIT_SUBMIT_FORM_RPC"],me=r=>ut.includes(r.type),Ce=r=>r.type==="VIEW_PORT_RPC_CALL",A=({requestId:r,...e})=>[r,e],Re=r=>{let e=r.at(0);if(e.updateType==="SIZE"){if(r.length===1)return r;e=r.at(1)}let t=r.at(-1);return[e,t]},Se=r=>{let e={};for(let t of r)(e[t.viewPortId]||(e[t.viewPortId]=[])).push(t);return e},H=({columns:r,dataTypes:e,key:t,table:s})=>({table:s,columns:r.map((n,o)=>({name:n,serverDataType:e[o]})),key:t});var Te="CHANGE_VP_SUCCESS";var be="CLOSE_TREE_NODE",Ee="CLOSE_TREE_SUCCESS";var we="CREATE_VP",Ve="DISABLE_VP",ve="DISABLE_VP_SUCCESS";var ye="ENABLE_VP",Me="ENABLE_VP_SUCCESS";var K="GET_VP_VISUAL_LINKS",_e="GET_VIEW_PORT_MENUS";var Ie="HB",De="HB_RESP",Pe="LOGIN",Le="OPEN_TREE_NODE",ke="OPEN_TREE_SUCCESS";var Oe="REMOVE_VP";var xe="SET_SELECTION_SUCCESS";var Ne=r=>{switch(r){case"TypeAheadRpcHandler":return"TYPEAHEAD";default:return"SIMUL"}};var Ue=[],R=b("array-backed-moving-window");function lt(r,e){if(!e||e.data.length!==r.data.length||e.sel!==r.sel)return!1;for(let t=0;t<e.data.length;t++)if(e.data[t]!==r.data[t])return!1;return!0}var h,N=class{constructor({from:e,to:t},{from:s,to:n},o){ae(this,h,void 0);this.setRowCount=e=>{var t;if((t=R.info)==null||t.call(R,`setRowCount ${e}`),e<this.internalData.length&&(this.internalData.length=e),e<this.rowCount){this.rowsWithinRange=0;let s=Math.min(e,this.clientRange.to);for(let n=this.clientRange.from;n<s;n++){let o=n-m(this,h).from;this.internalData[o]!==void 0&&(this.rowsWithinRange+=1)}}this.rowCount=e};this.bufferBreakout=(e,t)=>{let s=this.bufferSize*.25;return m(this,h).to-t<s?!0:m(this,h).from>0&&e-m(this,h).from<s};this.bufferSize=o,this.clientRange=new D(e,t),ue(this,h,new D(s,n)),this.internalData=new Array(o),this.rowsWithinRange=0,this.rowCount=0}get range(){return m(this,h)}get hasAllRowsWithinRange(){return this.rowsWithinRange===this.clientRange.to-this.clientRange.from||this.rowCount>0&&this.clientRange.from+this.rowsWithinRange===this.rowCount}outOfRange(e,t){let{from:s,to:n}=this.range;if(t<s||e>=n)return!0}setAtIndex(e){let{rowIndex:t}=e,s=t-m(this,h).from;if(lt(e,this.internalData[s]))return!1;let n=this.isWithinClientRange(t);return(n||this.isWithinRange(t))&&(!this.internalData[s]&&n&&(this.rowsWithinRange+=1),this.internalData[s]=e),n}getAtIndex(e){return m(this,h).isWithin(e)&&this.internalData[e-m(this,h).from]!=null?this.internalData[e-m(this,h).from]:void 0}isWithinRange(e){return m(this,h).isWithin(e)}isWithinClientRange(e){return this.clientRange.isWithin(e)}setClientRange(e,t){var p;(p=R.debug)==null||p.call(R,`setClientRange ${e} - ${t}`);let s=this.clientRange.from,n=Math.min(this.clientRange.to,this.rowCount);if(e===s&&t===n)return[!1,Ue];let o=this.clientRange.copy();this.clientRange.from=e,this.clientRange.to=t,this.rowsWithinRange=0;for(let a=e;a<t;a++){let l=a-m(this,h).from;this.internalData[l]&&(this.rowsWithinRange+=1)}let i=Ue,u=m(this,h).from;if(this.hasAllRowsWithinRange)if(t>o.to){let a=Math.max(e,o.to);i=this.internalData.slice(a-u,t-u)}else{let a=Math.min(o.from,t);i=this.internalData.slice(e-u,a-u)}return[this.bufferBreakout(e,t),i]}setRange(e,t){var s,n;if(e!==m(this,h).from||t!==m(this,h).to){(s=R.debug)==null||s.call(R,`setRange ${e} - ${t}`);let[o,i]=m(this,h).overlap(e,t),u=new Array(t-e);this.rowsWithinRange=0;for(let c=o;c<i;c++){let p=this.getAtIndex(c);if(p){let a=c-e;u[a]=p,this.isWithinClientRange(c)&&(this.rowsWithinRange+=1)}}this.internalData=u,m(this,h).from=e,m(this,h).to=t}else(n=R.debug)==null||n.call(R,`setRange ${e} - ${t} IGNORED because not changed`)}get data(){return this.internalData}getData(){var u;let{from:e,to:t}=m(this,h),{from:s,to:n}=this.clientRange,o=Math.max(0,s-e),i=Math.min(t-e,t,n-e,(u=this.rowCount)!=null?u:t);return this.internalData.slice(o,i)}clear(){var e;(e=R.debug)==null||e.call(R,"clear"),this.internalData.length=0,this.rowsWithinRange=0,this.setRowCount(0)}getCurrentDataRange(){let e=this.internalData,t=e.length,[s]=this.internalData,n=this.internalData[t-1];if(s&&n)return[s.rowIndex,n.rowIndex];for(let o=0;o<t;o++)if(e[o]!==void 0){s=e[o];break}for(let o=t-1;o>=0;o--)if(e[o]!==void 0){n=e[o];break}return s&&n?[s.rowIndex,n.rowIndex]:[-1,-1]}};h=new WeakMap;var ct=[],{debug:f,debugEnabled:U,error:pt,info:d,infoEnabled:dt,warn:y}=b("viewport"),gt=({rowKey:r,updateType:e})=>e==="U"&&!r.startsWith("$root"),W=[void 0,void 0],ht={count:0,mode:void 0,size:0,ts:0},q=class{constructor({aggregations:e,bufferSize:t=50,columns:s,filter:n,groupBy:o=[],table:i,range:u,sort:c,title:p,viewport:a,visualLink:l},g){this.batchMode=!0;this.hasUpdates=!1;this.pendingUpdates=[];this.pendingOperations=new Map;this.pendingRangeRequests=[];this.rowCountChanged=!1;this.selectedRows=[];this.useBatchMode=!0;this.lastUpdateStatus=ht;this.updateThrottleTimer=void 0;this.rangeMonitor=new k("ViewPort");this.disabled=!1;this.isTree=!1;this.status="";this.suspended=!1;this.suspendTimer=null;this.setLastSizeOnlyUpdateSize=e=>{this.lastUpdateStatus.size=e};this.setLastUpdate=e=>{let{ts:t,mode:s}=this.lastUpdateStatus,n=0;if(s===e){let o=Date.now();this.lastUpdateStatus.count+=1,this.lastUpdateStatus.ts=o,n=t===0?0:o-t}else this.lastUpdateStatus.count=1,this.lastUpdateStatus.ts=0,n=0;return this.lastUpdateStatus.mode=e,n};this.rangeRequestAlreadyPending=e=>{let{bufferSize:t}=this,s=t*.25,{from:n}=e;for(let{from:o,to:i}of this.pendingRangeRequests)if(n>=o&&n<i){if(e.to+s<=i)return!0;n=i}return!1};this.sendThrottledSizeMessage=()=>{this.updateThrottleTimer=void 0,this.lastUpdateStatus.count=3,this.postMessageToClient({clientViewportId:this.clientViewportId,mode:"size-only",size:this.lastUpdateStatus.size,type:"viewport-update"})};this.shouldThrottleMessage=e=>{let t=this.setLastUpdate(e);return e==="size-only"&&t>0&&t<500&&this.lastUpdateStatus.count>3};this.throttleMessage=e=>this.shouldThrottleMessage(e)?(d==null||d("throttling updates setTimeout to 2000"),this.updateThrottleTimer===void 0&&(this.updateThrottleTimer=setTimeout(this.sendThrottledSizeMessage,2e3)),!0):(this.updateThrottleTimer!==void 0&&(clearTimeout(this.updateThrottleTimer),this.updateThrottleTimer=void 0),!1);this.getNewRowCount=()=>{if(this.rowCountChanged&&this.dataWindow)return this.rowCountChanged=!1,this.dataWindow.rowCount};this.aggregations=e,this.bufferSize=t,this.clientRange=u,this.clientViewportId=a,this.columns=s,this.filter=n,this.groupBy=o,this.keys=new O(u),this.pendingLinkedParent=l,this.table=i,this.sort=c,this.title=p,dt&&(d==null||d(`constructor #${a} ${i.table} bufferSize=${t}`)),this.dataWindow=new N(this.clientRange,u,this.bufferSize),this.postMessageToClient=g}get hasUpdatesToProcess(){return this.suspended?!1:this.rowCountChanged||this.hasUpdates}get size(){var e;return(e=this.dataWindow.rowCount)!=null?e:0}subscribe(){let{filter:e}=this.filter;return this.status=this.status==="subscribed"?"resubscribing":"subscribing",{type:we,table:this.table,range:G(this.clientRange,this.bufferSize),aggregations:this.aggregations,columns:this.columns,sort:this.sort,groupBy:this.groupBy,filterSpec:{filter:e}}}handleSubscribed({viewPortId:e,aggregations:t,columns:s,filterSpec:n,range:o,sort:i,groupBy:u},c){return this.serverViewportId=e,this.status="subscribed",this.aggregations=t,this.columns=s,this.groupBy=u,this.isTree=u&&u.length>0,this.dataWindow.setRange(o.from,o.to),{aggregations:t,type:"subscribed",clientViewportId:this.clientViewportId,columns:s,filter:n,groupBy:u,range:o,sort:i,tableSchema:c}}awaitOperation(e,t){this.pendingOperations.set(e,t)}completeOperation(e,...t){var u;let{clientViewportId:s,pendingOperations:n}=this,o=n.get(e);if(!o){pt(`no matching operation found to complete for requestId ${e}`);return}let{type:i}=o;if(d==null||d(`completeOperation ${i}`),n.delete(e),i==="CHANGE_VP_RANGE"){let[c,p]=t;(u=this.dataWindow)==null||u.setRange(c,p);for(let a=this.pendingRangeRequests.length-1;a>=0;a--){let l=this.pendingRangeRequests[a];if(l.requestId===e){l.acked=!0;break}else y==null||y("range requests sent faster than they are being ACKed")}}else if(i==="config"){let{aggregations:c,columns:p,filter:a,groupBy:l,sort:g}=o.data;return this.aggregations=c,this.columns=p,this.filter=a,this.groupBy=l,this.sort=g,l.length>0?this.isTree=!0:this.isTree&&(this.isTree=!1),f==null||f(`config change confirmed, isTree : ${this.isTree}`),{clientViewportId:s,type:i,config:o.data}}else{if(i==="groupBy")return this.isTree=o.data.length>0,this.groupBy=o.data,f==null||f(`groupBy change confirmed, isTree : ${this.isTree}`),{clientViewportId:s,type:i,groupBy:o.data};if(i==="columns")return this.columns=o.data,{clientViewportId:s,type:i,columns:o.data};if(i==="filter")return this.filter=o.data,{clientViewportId:s,type:i,filter:o.data};if(i==="aggregate")return this.aggregations=o.data,{clientViewportId:s,type:"aggregate",aggregations:this.aggregations};if(i==="sort")return this.sort=o.data,{clientViewportId:s,type:i,sort:this.sort};if(i!=="selection"){if(i==="disable")return this.disabled=!0,{type:"disabled",clientViewportId:s};if(i==="enable")return this.disabled=!1,{type:"enabled",clientViewportId:s};if(i==="CREATE_VISUAL_LINK"){let[c,p,a]=t;return this.linkedParent={colName:c,parentViewportId:p,parentColName:a},this.pendingLinkedParent=void 0,{type:"vuu-link-created",clientViewportId:s,colName:c,parentViewportId:p,parentColName:a}}else if(i==="REMOVE_VISUAL_LINK")return this.linkedParent=void 0,{type:"vuu-link-removed",clientViewportId:s}}}}rangeRequest(e,t){U&&this.rangeMonitor.set(t);let s="CHANGE_VP_RANGE";if(this.dataWindow){let[n,o]=this.dataWindow.setClientRange(t.from,t.to),i,u=this.dataWindow.rowCount||void 0,c=n&&!this.rangeRequestAlreadyPending(t)?{type:s,viewPortId:this.serverViewportId,...G(t,this.bufferSize,u)}:null;if(c){U&&(f==null||f(`create CHANGE_VP_RANGE: [${c.from} - ${c.to}]`)),this.awaitOperation(e,{type:s});let a=this.pendingRangeRequests.at(-1);if(a)if(a.acked)console.warn("Range Request before previous request is filled");else{let{from:l,to:g}=a;this.dataWindow.outOfRange(l,g)?i={clientViewportId:this.clientViewportId,type:"debounce-begin"}:y==null||y("Range Request before previous request is acked")}this.pendingRangeRequests.push({...c,requestId:e}),this.useBatchMode&&(this.batchMode=!0)}else o.length>0&&(this.batchMode=!1);this.keys.reset(this.dataWindow.clientRange);let p=this.isTree?j:J;return o.length?[c,o.map(a=>p(a,this.keys,this.selectedRows))]:i?[c,void 0,i]:[c]}else return[null]}setLinks(e){return this.links=e,[{type:"vuu-links",links:e,clientViewportId:this.clientViewportId},this.pendingLinkedParent]}setMenu(e){return{type:"vuu-menu",menu:e,clientViewportId:this.clientViewportId}}openTreeNode(e,t){return this.useBatchMode&&(this.batchMode=!0),{type:Le,vpId:this.serverViewportId,treeKey:t.key}}closeTreeNode(e,t){return this.useBatchMode&&(this.batchMode=!0),{type:be,vpId:this.serverViewportId,treeKey:t.key}}createLink(e,t,s,n){let o={type:"CREATE_VISUAL_LINK",parentVpId:s,childVpId:this.serverViewportId,parentColumnName:n,childColumnName:t};return this.awaitOperation(e,o),this.useBatchMode&&(this.batchMode=!0),o}removeLink(e){let t={type:"REMOVE_VISUAL_LINK",childVpId:this.serverViewportId};return this.awaitOperation(e,t),t}suspend(){this.suspended=!0,d==null||d("suspend")}resume(){return this.suspended=!1,U&&(f==null||f(`resume: ${this.currentData()}`)),[this.size,this.currentData()]}currentData(){let e=[];if(this.dataWindow){let t=this.dataWindow.getData(),{keys:s}=this,n=this.isTree?j:J;for(let o of t)o&&e.push(n(o,s,this.selectedRows))}return e}enable(e){return this.awaitOperation(e,{type:"enable"}),d==null||d(`enable: ${this.serverViewportId}`),{type:ye,viewPortId:this.serverViewportId}}disable(e){return this.awaitOperation(e,{type:"disable"}),d==null||d(`disable: ${this.serverViewportId}`),this.suspended=!1,{type:Ve,viewPortId:this.serverViewportId}}columnRequest(e,t){return this.awaitOperation(e,{type:"columns",data:t}),f==null||f(`columnRequest: ${t}`),this.createRequest({columns:t})}filterRequest(e,t){this.awaitOperation(e,{type:"filter",data:t}),this.useBatchMode&&(this.batchMode=!0);let{filter:s}=t;return d==null||d(`filterRequest: ${s}`),this.createRequest({filterSpec:{filter:s}})}setConfig(e,t){this.awaitOperation(e,{type:"config",data:t});let{filter:s,...n}=t;return this.useBatchMode&&(this.batchMode=!0),U?f==null||f(`setConfig ${JSON.stringify(t)}`):d==null||d("setConfig"),this.createRequest({...n,filterSpec:typeof(s==null?void 0:s.filter)=="string"?{filter:s.filter}:{filter:""}},!0)}aggregateRequest(e,t){return this.awaitOperation(e,{type:"aggregate",data:t}),d==null||d(`aggregateRequest: ${t}`),this.createRequest({aggregations:t})}sortRequest(e,t){return this.awaitOperation(e,{type:"sort",data:t}),d==null||d(`sortRequest: ${JSON.stringify(t.sortDefs)}`),this.createRequest({sort:t})}groupByRequest(e,t=ct){var s;return this.awaitOperation(e,{type:"groupBy",data:t}),this.useBatchMode&&(this.batchMode=!0),this.isTree||(s=this.dataWindow)==null||s.clear(),this.createRequest({groupBy:t})}selectRequest(e,t){return this.selectedRows=t,this.awaitOperation(e,{type:"selection",data:t}),d==null||d(`selectRequest: ${t}`),{type:"SET_SELECTION",vpId:this.serverViewportId,selection:he(t)}}removePendingRangeRequest(e,t){for(let s=this.pendingRangeRequests.length-1;s>=0;s--){let{from:n,to:o}=this.pendingRangeRequests[s],i=!0;if(e>=n&&e<o||t>n&&t<o){i||console.warn("removePendingRangeRequest TABLE_ROWS are not for latest request"),this.pendingRangeRequests.splice(s,1);break}else i=!1}}updateRows(e){var n,o,i;let[t,s]=Re(e);if(t&&s&&this.removePendingRangeRequest(t.rowIndex,s.rowIndex),e.length===1)if(t.vpSize===0&&this.disabled){f==null||f(`ignore a SIZE=0 message on disabled viewport (${e.length} rows)`);return}else t.updateType==="SIZE"&&this.setLastSizeOnlyUpdateSize(t.vpSize);for(let u of e)this.isTree&>(u)||((u.updateType==="SIZE"||((n=this.dataWindow)==null?void 0:n.rowCount)!==u.vpSize)&&((o=this.dataWindow)==null||o.setRowCount(u.vpSize),this.rowCountChanged=!0),u.updateType==="U"&&(i=this.dataWindow)!=null&&i.setAtIndex(u)&&(this.hasUpdates=!0,this.batchMode||this.pendingUpdates.push(u)))}getClientRows(){let e,t="size-only";if(!this.hasUpdates&&!this.rowCountChanged)return W;if(this.hasUpdates){let{keys:s,selectedRows:n}=this,o=this.isTree?j:J;if(this.updateThrottleTimer&&(self.clearTimeout(this.updateThrottleTimer),this.updateThrottleTimer=void 0),this.pendingUpdates.length>0){e=[],t="update";for(let i of this.pendingUpdates)e.push(o(i,s,n));this.pendingUpdates.length=0}else{let i=this.dataWindow.getData();if(this.dataWindow.hasAllRowsWithinRange){e=[],t="batch";for(let u of i)e.push(o(u,s,n));this.batchMode=!1}}this.hasUpdates=!1}return this.throttleMessage(t)?W:[e,t]}createRequest(e,t=!1){return t?{type:"CHANGE_VP",viewPortId:this.serverViewportId,...e}:{type:"CHANGE_VP",viewPortId:this.serverViewportId,aggregations:this.aggregations,columns:this.columns,sort:this.sort,groupBy:this.groupBy,filterSpec:{filter:this.filter.filter},...e}}},J=({rowIndex:r,rowKey:e,sel:t,data:s},n,o)=>[r,n.keyFor(r),!0,!1,0,0,e,t?z(o,r):0].concat(s),j=({rowIndex:r,rowKey:e,sel:t,data:s},n,o)=>{let[i,u,,c,,p,...a]=s;return[r,n.keyFor(r),c,u,i,p,e,t?z(o,r):0].concat(a)};var We=1;var{debug:V,debugEnabled:Q,error:M,info:T,infoEnabled:ft,warn:Y}=b("server-proxy"),C=()=>`${We++}`,mt={},Ct=r=>r.disabled!==!0&&r.suspended!==!0,Rt={type:"NO_ACTION"},St=(r,e,t)=>r.map(s=>s.parentVpId===e?{...s,label:t}:s);function Tt(r,e){return r.map(t=>{let{parentVpId:s}=t,n=e.get(s);if(n)return{...t,parentClientVpId:n.clientViewportId,label:n.title};throw Error("addLabelsToLinks viewport not found")})}var F=class{constructor(e,t){this.authToken="";this.user="user";this.pendingRequests=new Map;this.queuedRequests=[];this.cachedTableMetaRequests=new Map;this.cachedTableSchemas=new Map;this.connection=e,this.postMessageToClient=t,this.viewports=new Map,this.mapClientToServerViewport=new Map}async reconnect(){await this.login(this.authToken);let[e,t]=le(Array.from(this.viewports.values()),Ct);this.viewports.clear(),this.mapClientToServerViewport.clear();let s=n=>{n.forEach(o=>{let{clientViewportId:i}=o;this.viewports.set(i,o),this.sendMessageToServer(o.subscribe(),i)})};s(e),setTimeout(()=>{s(t)},2e3)}async login(e,t="user"){if(e)return this.authToken=e,this.user=t,new Promise((s,n)=>{this.sendMessageToServer({type:Pe,token:this.authToken,user:t},""),this.pendingLogin={resolve:s,reject:n}});this.authToken===""&&M("login, cannot login until auth token has been obtained")}subscribe(e){if(this.mapClientToServerViewport.has(e.viewport))M(`spurious subscribe call ${e.viewport}`);else{let t=this.getTableMeta(e.table),s=new q(e,this.postMessageToClient);this.viewports.set(e.viewport,s);let n=this.awaitResponseToMessage(s.subscribe(),e.viewport);Promise.all([n,t]).then(([i,u])=>{let{viewPortId:c}=i,{status:p}=s;e.viewport!==c&&(this.viewports.delete(e.viewport),this.viewports.set(c,s)),this.mapClientToServerViewport.set(e.viewport,c);let a=s.handleSubscribed(i,u);a&&(this.postMessageToClient(a),Q&&V(`post DataSourceSubscribedMessage to client: ${JSON.stringify(a)}`)),s.disabled&&this.disableViewport(s),this.queuedRequests.length>0&&this.processQueuedRequests(),p==="subscribing"&&!x(s.table)&&(this.sendMessageToServer({type:K,vpId:c}),this.sendMessageToServer({type:_e,vpId:c}),Array.from(this.viewports.entries()).filter(([l,{disabled:g}])=>l!==c&&!g).forEach(([l])=>{this.sendMessageToServer({type:K,vpId:l})}))})}}processQueuedRequests(){let e={};for(;this.queuedRequests.length;){let t=this.queuedRequests.pop();if(t){let{clientViewportId:s,message:n,requestId:o}=t;if(n.type==="CHANGE_VP_RANGE"){if(e.CHANGE_VP_RANGE)continue;e.CHANGE_VP_RANGE=!0;let i=this.mapClientToServerViewport.get(s);i&&this.sendMessageToServer({...n,viewPortId:i},o)}}}}unsubscribe(e){let t=this.mapClientToServerViewport.get(e);t?(T==null||T(`Unsubscribe Message (Client to Server):\n ${t}`),this.sendMessageToServer({type:Oe,viewPortId:t})):M(`failed to unsubscribe client viewport ${e}, viewport not found`)}getViewportForClient(e,t=!0){let s=this.mapClientToServerViewport.get(e);if(s){let n=this.viewports.get(s);if(n)return n;if(t)throw Error(`Viewport not found for client viewport ${e}`);return null}else{if(this.viewports.has(e))return this.viewports.get(e);if(t)throw Error(`Viewport server id not found for client viewport ${e}`);return null}}setViewRange(e,t){let s=C(),[n,o,i]=e.rangeRequest(s,t.range);T==null||T(`setViewRange ${t.range.from} - ${t.range.to}`),n&&(this.sendIfReady(n,s,e.status==="subscribed")||this.queuedRequests.push({clientViewportId:t.viewport,message:n,requestId:s})),o?(T==null||T(`setViewRange ${o.length} rows returned from cache`),this.postMessageToClient({mode:"batch",type:"viewport-update",clientViewportId:e.clientViewportId,rows:o})):i&&this.postMessageToClient(i)}setConfig(e,t){let s=C(),n=e.setConfig(s,t.config);this.sendIfReady(n,s,e.status==="subscribed")}aggregate(e,t){let s=C(),n=e.aggregateRequest(s,t.aggregations);this.sendIfReady(n,s,e.status==="subscribed")}sort(e,t){let s=C(),n=e.sortRequest(s,t.sort);this.sendIfReady(n,s,e.status==="subscribed")}groupBy(e,t){let s=C(),n=e.groupByRequest(s,t.groupBy);this.sendIfReady(n,s,e.status==="subscribed")}filter(e,t){let s=C(),{filter:n}=t,o=e.filterRequest(s,n);this.sendIfReady(o,s,e.status==="subscribed")}setColumns(e,t){let s=C(),{columns:n}=t,o=e.columnRequest(s,n);this.sendIfReady(o,s,e.status==="subscribed")}setTitle(e,t){e&&(e.title=t.title,this.updateTitleOnVisualLinks(e))}select(e,t){let s=C(),{selected:n}=t,o=e.selectRequest(s,n);this.sendIfReady(o,s,e.status==="subscribed")}disableViewport(e){let t=C(),s=e.disable(t);this.sendIfReady(s,t,e.status==="subscribed")}enableViewport(e){if(e.disabled){let t=C(),s=e.enable(t);this.sendIfReady(s,t,e.status==="subscribed")}}suspendViewport(e){e.suspend(),e.suspendTimer=setTimeout(()=>{T==null||T("suspendTimer expired, escalate suspend to disable"),this.disableViewport(e)},3e3)}resumeViewport(e){e.suspendTimer&&(V==null||V("clear suspend timer"),clearTimeout(e.suspendTimer),e.suspendTimer=null);let[t,s]=e.resume();V==null||V(`resumeViewport size ${t}, ${s.length} rows sent to client`),this.postMessageToClient({clientViewportId:e.clientViewportId,mode:"batch",rows:s,size:t,type:"viewport-update"})}openTreeNode(e,t){if(e.serverViewportId){let s=C();this.sendIfReady(e.openTreeNode(s,t),s,e.status==="subscribed")}}closeTreeNode(e,t){if(e.serverViewportId){let s=C();this.sendIfReady(e.closeTreeNode(s,t),s,e.status==="subscribed")}}createLink(e,t){let{parentClientVpId:s,parentColumnName:n,childColumnName:o}=t,i=C(),u=this.mapClientToServerViewport.get(s);if(u){let c=e.createLink(i,o,u,n);this.sendMessageToServer(c,i)}else M("ServerProxy unable to create link, viewport not found")}removeLink(e){let t=C(),s=e.removeLink(t);this.sendMessageToServer(s,t)}updateTitleOnVisualLinks(e){var n;let{serverViewportId:t,title:s}=e;for(let o of this.viewports.values())if(o!==e&&o.links&&t&&s&&(n=o.links)!=null&&n.some(i=>i.parentVpId===t)){let[i]=o.setLinks(St(o.links,t,s));this.postMessageToClient(i)}}removeViewportFromVisualLinks(e){var t;for(let s of this.viewports.values())if((t=s.links)!=null&&t.some(({parentVpId:n})=>n===e)){let[n]=s.setLinks(s.links.filter(({parentVpId:o})=>o!==e));this.postMessageToClient(n)}}menuRpcCall(e){let t=this.getViewportForClient(e.vpId,!1);if(t!=null&&t.serverViewportId){let[s,n]=A(e);this.sendMessageToServer({...n,vpId:t.serverViewportId},s)}}viewportRpcCall(e){let t=this.getViewportForClient(e.vpId,!1);if(t!=null&&t.serverViewportId){let[s,n]=A(e);this.sendMessageToServer({...n,vpId:t.serverViewportId,namedParams:{}},s)}}rpcCall(e){let[t,s]=A(e),n=Ne(s.service);this.sendMessageToServer(s,t,{module:n})}handleMessageFromClient(e){var t;if(ge(e))if(e.type==="disable"){let s=this.getViewportForClient(e.viewport,!1);return s!==null?this.disableViewport(s):void 0}else{let s=this.getViewportForClient(e.viewport);switch(e.type){case"setViewRange":return this.setViewRange(s,e);case"config":return this.setConfig(s,e);case"aggregate":return this.aggregate(s,e);case"sort":return this.sort(s,e);case"groupBy":return this.groupBy(s,e);case"filter":return this.filter(s,e);case"select":return this.select(s,e);case"suspend":return this.suspendViewport(s);case"resume":return this.resumeViewport(s);case"enable":return this.enableViewport(s);case"openTreeNode":return this.openTreeNode(s,e);case"closeTreeNode":return this.closeTreeNode(s,e);case"createLink":return this.createLink(s,e);case"removeLink":return this.removeLink(s);case"setColumns":return this.setColumns(s,e);case"setTitle":return this.setTitle(s,e);default:}}else{if(Ce(e))return this.viewportRpcCall(e);if(me(e))return this.menuRpcCall(e);{let{type:s,requestId:n}=e;switch(s){case"GET_TABLE_LIST":{(t=this.tableList)!=null||(this.tableList=this.awaitResponseToMessage({type:s},n)),this.tableList.then(o=>{this.postMessageToClient({type:"TABLE_LIST_RESP",tables:o.tables,requestId:n})});return}case"GET_TABLE_META":{this.getTableMeta(e.table,n).then(o=>{o&&this.postMessageToClient({type:"TABLE_META_RESP",tableSchema:o,requestId:n})});return}case"RPC_CALL":return this.rpcCall(e);default:}}}M(`Vuu ServerProxy Unexpected message from client ${JSON.stringify(e)}`)}getTableMeta(e,t=C()){if(x(e))return Promise.resolve(void 0);let s=`${e.module}:${e.table}`,n=this.cachedTableMetaRequests.get(s);return n||(n=this.awaitResponseToMessage({type:"GET_TABLE_META",table:e},t),this.cachedTableMetaRequests.set(s,n)),n==null?void 0:n.then(o=>this.cacheTableMeta(o))}awaitResponseToMessage(e,t=C()){return new Promise((s,n)=>{this.sendMessageToServer(e,t),this.pendingRequests.set(t,{reject:n,resolve:s})})}sendIfReady(e,t,s=!0){return s&&this.sendMessageToServer(e,t),s}sendMessageToServer(e,t=`${We++}`,s=mt){let{module:n="CORE"}=s;this.authToken&&this.connection.send({requestId:t,sessionId:this.sessionId,token:this.authToken,user:this.user,module:n,body:e})}handleMessageFromServer(e){var u;let{body:t,requestId:s,sessionId:n}=e,o=this.pendingRequests.get(s);if(o){let{resolve:a}=o;this.pendingRequests.delete(s),a(t);return}let{viewports:i}=this;switch(t.type){case Ie:this.sendMessageToServer({type:De,ts:+new Date},"NA");break;case"LOGIN_SUCCESS":if(n)this.sessionId=n,(u=this.pendingLogin)==null||u.resolve(n),this.pendingLogin=void 0;else throw Error("LOGIN_SUCCESS did not provide sessionId");break;case"REMOVE_VP_SUCCESS":{let a=i.get(t.viewPortId);a&&(this.mapClientToServerViewport.delete(a.clientViewportId),i.delete(t.viewPortId),this.removeViewportFromVisualLinks(t.viewPortId))}break;case xe:{let a=this.viewports.get(t.vpId);a&&a.completeOperation(s)}break;case Te:case ve:if(i.has(t.viewPortId)){let a=this.viewports.get(t.viewPortId);if(a){let l=a.completeOperation(s);l!==void 0&&(this.postMessageToClient(l),Q&&V(`postMessageToClient ${JSON.stringify(l)}`))}}break;case Me:{let a=this.viewports.get(t.viewPortId);if(a){let l=a.completeOperation(s);if(l){this.postMessageToClient(l);let[g,S]=a.resume();this.postMessageToClient({clientViewportId:a.clientViewportId,mode:"batch",rows:S,size:g,type:"viewport-update"})}}}break;case"TABLE_ROW":{let a=Se(t.rows);for(let[l,g]of Object.entries(a)){let S=i.get(l);S?S.updateRows(g):Y==null||Y(`TABLE_ROW message received for non registered viewport ${l}`)}this.processUpdates()}break;case"CHANGE_VP_RANGE_SUCCESS":{let a=this.viewports.get(t.viewPortId);if(a){let{from:l,to:g}=t;a.completeOperation(s,l,g)}}break;case ke:case Ee:break;case"CREATE_VISUAL_LINK_SUCCESS":{let a=this.viewports.get(t.childVpId),l=this.viewports.get(t.parentVpId);if(a&&l){let{childColumnName:g,parentColumnName:S}=t,I=a.completeOperation(s,g,l.clientViewportId,S);I&&this.postMessageToClient(I)}}break;case"REMOVE_VISUAL_LINK_SUCCESS":{let a=this.viewports.get(t.childVpId);if(a){let l=a.completeOperation(s);l&&this.postMessageToClient(l)}}break;case"VP_VISUAL_LINKS_RESP":{let a=this.getActiveLinks(t.links),l=this.viewports.get(t.vpId);if(a.length&&l){let g=Tt(a,this.viewports),[S,I]=l.setLinks(g);if(this.postMessageToClient(S),I){let{link:ne,parentClientVpId:Ke}=I,re=C(),oe=this.mapClientToServerViewport.get(Ke);if(oe){let Je=l.createLink(re,ne.fromColumn,oe,ne.toColumn);this.sendMessageToServer(Je,re)}}}}break;case"VIEW_PORT_MENUS_RESP":if(t.menu.name){let a=this.viewports.get(t.vpId);if(a){let l=a.setMenu(t.menu);this.postMessageToClient(l)}}break;case"VP_EDIT_RPC_RESPONSE":this.postMessageToClient({action:t.action,requestId:s,rpcName:t.rpcName,type:"VP_EDIT_RPC_RESPONSE"});break;case"VP_EDIT_RPC_REJECT":this.viewports.get(t.vpId)&&this.postMessageToClient({requestId:s,type:"VP_EDIT_RPC_REJECT",error:t.error});break;case"VIEW_PORT_MENU_REJ":{console.log("send menu error back to client");let{error:a,rpcName:l,vpId:g}=t,S=this.viewports.get(g);S&&this.postMessageToClient({clientViewportId:S.clientViewportId,error:a,rpcName:l,type:"VIEW_PORT_MENU_REJ",requestId:s});break}case"VIEW_PORT_MENU_RESP":if(fe(t)){let{action:a,rpcName:l}=t;this.awaitResponseToMessage({type:"GET_TABLE_META",table:a.table}).then(g=>{let S=H(g);this.postMessageToClient({rpcName:l,type:"VIEW_PORT_MENU_RESP",action:{...a,tableSchema:S},tableAlreadyOpen:this.isTableOpen(a.table),requestId:s})})}else{let{action:a}=t;this.postMessageToClient({type:"VIEW_PORT_MENU_RESP",action:a||Rt,tableAlreadyOpen:a!==null&&this.isTableOpen(a.table),requestId:s})}break;case"RPC_RESP":{let{method:a,result:l}=t;this.postMessageToClient({type:"RPC_RESP",method:a,result:l,requestId:s})}break;case"VIEW_PORT_RPC_REPONSE":{let{method:a,action:l}=t;this.postMessageToClient({type:"VIEW_PORT_RPC_RESPONSE",rpcName:a,action:l,requestId:s})}break;case"ERROR":M(t.msg);break;default:ft&&T(`handleMessageFromServer ${t.type}.`)}}cacheTableMeta(e){let{module:t,table:s}=e.table,n=`${t}:${s}`,o=this.cachedTableSchemas.get(n);return o||(o=H(e),this.cachedTableSchemas.set(n,o)),o}isTableOpen(e){if(e){let t=e.table;for(let s of this.viewports.values())if(!s.suspended&&s.table.table===t)return!0}}getActiveLinks(e){return e.filter(t=>{let s=this.viewports.get(t.parentVpId);return s&&!s.suspended})}processUpdates(){this.viewports.forEach(e=>{var t;if(e.hasUpdatesToProcess){let s=e.getClientRows();if(s!==W){let[n,o]=s,i=e.getNewRowCount();(i!==void 0||n&&n.length>0)&&(Q&&V(`postMessageToClient #${e.clientViewportId} viewport-update ${o}, ${(t=n==null?void 0:n.length)!=null?t:"no"} rows, size ${i}`),o&&this.postMessageToClient({clientViewportId:e.clientViewportId,mode:o,rows:n,size:i,type:"viewport-update"}))}}})}};var{debug:us,debugEnabled:ls,error:qe,info:E,infoEnabled:bt,warn:_}=b("websocket-connection"),Fe="ws",Et=r=>r.startsWith(Fe+"://")||r.startsWith(Fe+"s://"),Ge={},X=Symbol("setWebsocket"),B=Symbol("connectionCallback");async function ze(r,e,t,s=10,n=5){return Ge[r]={status:"connecting",connect:{allowed:n,remaining:n},reconnect:{allowed:s,remaining:s}},He(r,e,t)}async function Z(r){throw Error("connection broken")}async function He(r,e,t,s){let{status:n,connect:o,reconnect:i}=Ge[r],u=n==="connecting"?o:i;try{t({type:"connection-status",status:"connecting"});let c=typeof s<"u",p=await Vt(r,e);console.info("%c\u26A1 %cconnected","font-size: 24px;color: green;font-weight: bold;","color:green; font-size: 14px;"),s!==void 0&&s[X](p);let a=s!=null?s:new ee(p,r,e,t),l=c?"reconnected":"connection-open-awaiting-session";return t({type:"connection-status",status:l}),a.status=l,u.remaining=u.allowed,a}catch{let p=--u.remaining>0;if(t({type:"connection-status",status:"disconnected",reason:"failed to connect",retry:p}),p)return wt(r,e,t,s,2e3);throw Error("Failed to establish connection")}}var wt=(r,e,t,s,n)=>new Promise(o=>{setTimeout(()=>{o(He(r,e,t,s))},n)}),Vt=(r,e)=>new Promise((t,s)=>{let n=Et(r)?r:`wss://${r}`;bt&&e!==void 0&&E(`WebSocket Protocol ${e==null?void 0:e.toString()}`);let o=new WebSocket(n,e);o.onopen=()=>t(o),o.onerror=i=>s(i)}),Be=()=>{_==null||_("Connection cannot be closed, socket not yet opened")},$e=r=>{_==null||_(`Message cannot be sent, socket closed ${r.body.type}`)},vt=r=>{try{return JSON.parse(r)}catch{throw Error(`Error parsing JSON response from server ${r}`)}},ee=class{constructor(e,t,s,n){this.close=Be;this.requiresLogin=!0;this.send=$e;this.status="ready";this.messagesCount=0;this.connectionMetricsInterval=null;this.handleWebsocketMessage=e=>{let t=vt(e.data);this.messagesCount+=1,this[B](t)};this.url=t,this.protocol=s,this[B]=n,this[X](e)}reconnect(){Z(this)}[(B,X)](e){let t=this[B];e.onmessage=o=>{this.status="connected",e.onmessage=this.handleWebsocketMessage,this.handleWebsocketMessage(o)},this.connectionMetricsInterval=setInterval(()=>{t({type:"connection-metrics",messagesLength:this.messagesCount}),this.messagesCount=0},2e3),e.onerror=()=>{qe("\u26A1 connection error"),t({type:"connection-status",status:"disconnected",reason:"error"}),this.connectionMetricsInterval&&(clearInterval(this.connectionMetricsInterval),this.connectionMetricsInterval=null),this.status==="connection-open-awaiting-session"?qe("Websocket connection lost before Vuu session established, check websocket configuration"):this.status!=="closed"&&(Z(this),this.send=n)},e.onclose=()=>{E==null||E("\u26A1 connection close"),t({type:"connection-status",status:"disconnected",reason:"close"}),this.connectionMetricsInterval&&(clearInterval(this.connectionMetricsInterval),this.connectionMetricsInterval=null),this.status!=="closed"&&(Z(this),this.send=n)};let s=o=>{e.send(JSON.stringify(o))},n=o=>{E==null||E(`TODO queue message until websocket reconnected ${o.body.type}`)};this.send=s,this.close=()=>{this.status="closed",e.close(),this.close=Be,this.send=$e,E==null||E("close websocket")}}};var v,{info:te,infoEnabled:se}=b("worker");async function yt(r,e,t,s,n,o,i){let u=await ze(r,e,c=>{de(c)?postMessage({type:"connection-metrics",messages:c}):pe(c)?(n(c),c.status==="reconnected"&&v.reconnect()):v.handleMessageFromServer(c)},o,i);v=new F(u,c=>Mt(c)),u.requiresLogin&&await v.login(t,s)}function Mt(r){postMessage(r)}var _t=async({data:r})=>{switch(r.type){case"connect":await yt(r.url,r.protocol,r.token,r.username,postMessage,r.retryLimitDisconnect,r.retryLimitStartup),postMessage({type:"connected"});break;case"subscribe":se&&te(`client subscribe: ${JSON.stringify(r)}`),v.subscribe(r);break;case"unsubscribe":se&&te(`client unsubscribe: ${JSON.stringify(r)}`),v.unsubscribe(r.viewport);break;default:se&&te(`client message: ${JSON.stringify(r)}`),v.handleMessageFromClient(r)}};self.addEventListener("message",_t);postMessage({type:"ready"});\n\n';var he=new Blob([(0,p.getLoggingConfigForWorker)()+F],{type:"text/javascript"}),ce=URL.createObjectURL(he),C,A,W=[],J,K,H=new Promise((t,r)=>{J=t,K=r}),x=()=>H,_=new Map,P=new Map,pe=async({handleConnectionStatusChange:t,protocol:r,retryLimitDisconnect:e,retryLimitStartup:s,token:o="",username:h,url:c})=>o===""&&A===void 0?new Promise(w=>{W.push({resolve:w})}):A||(A=new Promise(w=>{let g=new Worker(ce),E=window.setTimeout(()=>{console.error("timed out waiting for worker to load")},1e3);g.onmessage=S=>{let{data:R}=S;if(R.type==="ready")window.clearTimeout(E),g.postMessage({protocol:r,retryLimitDisconnect:e,retryLimitStartup:s,token:o,type:"connect",url:c,username:h});else if(R.type==="connected"){g.onmessage=j,w(g);for(let M of W)M.resolve(g);W.length=0}else(0,p.isConnectionStatusMessage)(R)?t({data:R}):console.warn("ConnectionManager: Unexpected message from the worker")}}));function j({data:t}){if(N(t)){let r=_.get(t.clientViewportId);r?r.postMessageToClientDataSource(t):console.error(`[ConnectionManager] ${t.type} message received, viewport not found`)}else if((0,p.isConnectionStatusMessage)(t))k.emit("connection-status",t);else if((0,p.isConnectionQualityMetrics)(t))k.emit("connection-metrics",t);else{let r=t.requestId;if(P.has(r)){let{resolve:e}=P.get(r);P.delete(r);let{type:s,requestId:o,...h}=t;(0,p.messageHasResult)(t)?e(t.result):t.type==="VP_EDIT_RPC_RESPONSE"||t.type==="VP_EDIT_RPC_REJECT"?e(t):(0,p.isTableSchema)(t)?e(t.tableSchema):e(h)}else console.warn("%cConnectionManager Unexpected message from the worker","color:red;font-weight:bold;")}}var U=t=>{let r=(0,p.uuid)();return C.postMessage({requestId:r,...t}),new Promise((e,s)=>{P.set(r,{resolve:e,reject:s})})},de={subscribe:(t,r)=>{if(_.get(t.viewport))throw Error("ConnectionManager attempting to subscribe with an existing viewport id");_.set(t.viewport,{status:"subscribing",request:t,postMessageToClientDataSource:r}),C.postMessage({type:"subscribe",...t})},unsubscribe:t=>{C.postMessage({type:"unsubscribe",viewport:t})},send:t=>{C.postMessage(t)},destroy:t=>{t&&_.has(t)&&_.delete(t)},rpcCall:async t=>U(t),getTableList:async()=>U({type:"GET_TABLE_LIST"}),getTableSchema:async t=>U({type:G,table:t})},q=class extends p.EventEmitter{async connect({url:r,authToken:e,username:s,protocol:o,retryLimitDisconnect:h,retryLimitStartup:c}){return C=await pe({protocol:o,url:r,token:e,username:s,retryLimitDisconnect:h,retryLimitStartup:c,handleConnectionStatusChange:j}),de}destroy(){C.terminate()}},k=new q,ge=async({url:t,protocol:r=void 0,authToken:e,username:s,retryLimitDisconnect:o,retryLimitStartup:h})=>{try{let c=await k.connect({protocol:r,url:t,authToken:e,username:s,retryLimitDisconnect:o,retryLimitStartup:h});J(c)}catch(c){console.error("Connection Error",c),K(c)}},fe=async t=>{try{return(await H).rpcCall(t)}catch{throw Error("Error accessing server api")}};var we=0,ve={get nextValue(){return we++}},Re={connect:"connect",connectionStatus:"connection-status",getFilterData:"GetFilterData",rowData:"rowData",rowSet:"rowset",select:"select",selectAll:"selectAll",selectNone:"selectNone",selected:"selected",snapshot:"snapshot",update:"update",createLink:"createLink",disable:"disable",enable:"enable",suspend:"suspend",resume:"resume",addSubscription:"AddSubscription",closeTreeNode:"closeTreeNode",columnList:"ColumnList",data:"data",openTreeNode:"openTreeNode",aggregate:"aggregate",filter:"filter",filterQuery:"filterQuery",filterData:"filterData",getSearchData:"GetSearchData",groupBy:"groupBy",modifySubscription:"ModifySubscription",searchData:"searchData",setGroupState:"setGroupState",size:"size",sort:"sort",subscribed:"Subscribed",tableList:"TableList",unsubscribe:"TerminateSubscription",viewRangeChanged:"ViewRangeChanged"};var be=["VIEW_PORT_MENUS_SELECT_RPC","VIEW_PORT_MENU_TABLE_RPC","VIEW_PORT_MENU_ROW_RPC","VIEW_PORT_MENU_CELL_RPC","VP_EDIT_CELL_RPC","VP_EDIT_ROW_RPC","VP_EDIT_ADD_ROW_RPC","VP_EDIT_DELETE_CELL_RPC","VP_EDIT_DELETE_ROW_RPC","VP_EDIT_SUBMIT_FORM_RPC"],Ee=t=>be.includes(t.type),Ce=t=>t.type==="VIEW_PORT_RPC_CALL",Te=({requestId:t,...r})=>[t,r],me=t=>{let r=t.at(0);if(r.updateType==="SIZE"){if(t.length===1)return t;r=t.at(1)}let e=t.at(-1);return[r,e]},Se=t=>{let r={};for(let e of t)(r[e.viewPortId]||(r[e.viewPortId]=[])).push(e);return r},_e=({columns:t,dataTypes:r,key:e,table:s})=>({table:s,columns:t.map((o,h)=>({name:o,serverDataType:r[h]})),key:e});var X=require("@vuu-ui/vuu-filter-parser"),u=require("@vuu-ui/vuu-utils");var{info:d}=(0,u.logger)("VuuDataSource"),{KEY:ye}=u.metadataKeys,n,L,y,I,T,v,V,m,l,b,B=class extends u.EventEmitter{constructor({bufferSize:e=100,aggregations:s,columns:o,filter:h,groupBy:c,sort:w,table:g,title:E,viewport:S,visualLink:R}){super();this.server=null;f(this,n,u.vanillaConfig);f(this,L,[]);f(this,y,void 0);f(this,I,void 0);f(this,T,"throttle");f(this,v,{from:0,to:0});f(this,V,0);f(this,m,0);f(this,l,"initialising");f(this,b,void 0);this.handleMessageFromServer=e=>{var s,o;if(e.type==="subscribed")a(this,l,"subscribed"),e.tableSchema&&(this.tableSchema=e.tableSchema),(s=this.clientCallback)==null||s.call(this,e);else if(e.type==="disabled")a(this,l,"disabled");else if(e.type==="enabled")a(this,l,"enabled");else{if(D(e))return;e.type==="debounce-begin"?this.optimize="debounce":(e.type==="viewport-update"&&e.size!==void 0&&e.size!==i(this,m)&&(a(this,m,e.size),this.emit("resize",e.size)),this.configChangePending&&this.setConfigPending(),(0,u.isViewportMenusAction)(e)?a(this,I,e.menu):(0,u.isVisualLinksAction)(e)?a(this,y,e.links):(o=this.clientCallback)==null||o.call(this,e),this.optimize==="debounce"&&this.revertDebounce())}};this.revertDebounce=(0,u.debounce)(()=>{this.optimize="throttle"},100);this.rawRangeRequest=e=>{this.viewport&&this.server&&this.server.send({viewport:this.viewport,type:"setViewRange",range:e})};this.debounceRangeRequest=(0,u.debounce)(e=>{this.viewport&&this.server&&this.server.send({viewport:this.viewport,type:"setViewRange",range:e})},50);this.throttleRangeRequest=(0,u.throttle)(e=>{this.viewport&&this.server&&this.server.send({viewport:this.viewport,type:"setViewRange",range:e})},80);if(!g)throw Error("RemoteDataSource constructor called without table");this.bufferSize=e,this.table=g,this.viewport=S,a(this,n,{...i(this,n),aggregations:s||i(this,n).aggregations,columns:o||i(this,n).columns,filter:h||i(this,n).filter,groupBy:c||i(this,n).groupBy,sort:w||i(this,n).sort,visualLink:R||i(this,n).visualLink}),a(this,b,E),this.rangeRequest=this.throttleRangeRequest}async subscribe({viewport:e=(S=>(S=this.viewport)!=null?S:this.viewport=(0,u.uuid)())(),columns:s,aggregations:o,range:h,sort:c,groupBy:w,filter:g},E){var M;if(i(this,l)==="disabled"||i(this,l)==="disabling"){this.enable(E);return}if(this.clientCallback=E,(o||s||g||w||c)&&a(this,n,{...i(this,n),aggregations:o||i(this,n).aggregations,columns:s||i(this,n).columns,filter:g||i(this,n).filter,groupBy:w||i(this,n).groupBy,sort:c||i(this,n).sort}),h&&a(this,v,h),i(this,l)!=="initialising"&&i(this,l)!=="unsubscribed")return;a(this,l,"subscribing"),this.viewport=e,this.server=await x();let{bufferSize:R}=this;(M=this.server)==null||M.subscribe({...i(this,n),bufferSize:R,viewport:e,table:this.table,range:i(this,v),title:i(this,b)},this.handleMessageFromServer)}unsubscribe(){var e,s;console.log(`unsubscribe #${this.viewport}`),d==null||d(`unsubscribe #${this.viewport}`),this.viewport&&((e=this.server)==null||e.unsubscribe(this.viewport)),(s=this.server)==null||s.destroy(this.viewport),this.server=null,this.removeAllListeners(),a(this,l,"unsubscribed"),this.viewport=void 0,this.range={from:0,to:0}}suspend(){var e;return console.log(`suspend #${this.viewport}, current status ${i(this,l)}`),d==null||d(`suspend #${this.viewport}, current status ${i(this,l)}`),this.viewport&&(a(this,l,"suspended"),(e=this.server)==null||e.send({type:"suspend",viewport:this.viewport})),this}resume(){var o;console.log(`resume #${this.viewport}, current status ${i(this,l)}`);let e=i(this,l).startsWith("disabl"),s=i(this,l)==="suspended";return d==null||d(`resume #${this.viewport}, current status ${i(this,l)}`),this.viewport&&(e?this.enable():s&&((o=this.server)==null||o.send({type:"resume",viewport:this.viewport}),a(this,l,"subscribed"))),this}disable(){var e;return d==null||d(`disable #${this.viewport}, current status ${i(this,l)}`),this.viewport&&(a(this,l,"disabling"),(e=this.server)==null||e.send({viewport:this.viewport,type:"disable"})),this}enable(e){var s;return d==null||d(`enable #${this.viewport}, current status ${i(this,l)}`),this.viewport&&(i(this,l)==="disabled"||i(this,l)==="disabling")&&(a(this,l,"enabling"),e&&(this.clientCallback=e),(s=this.server)==null||s.send({viewport:this.viewport,type:"enable"})),this}select(e){var s;a(this,V,e.length),this.viewport&&((s=this.server)==null||s.send({viewport:this.viewport,type:"select",selected:e}))}openTreeNode(e){var s;this.viewport&&((s=this.server)==null||s.send({viewport:this.viewport,type:"openTreeNode",key:e}))}closeTreeNode(e){var s;this.viewport&&((s=this.server)==null||s.send({viewport:this.viewport,type:"closeTreeNode",key:e}))}get links(){return i(this,y)}get menu(){return i(this,I)}get status(){return i(this,l)}get optimize(){return i(this,T)}set optimize(e){if(e!==i(this,T)){switch(a(this,T,e),e){case"none":this.rangeRequest=this.rawRangeRequest;break;case"debounce":this.rangeRequest=this.debounceRangeRequest;break;case"throttle":this.rangeRequest=this.throttleRangeRequest;break}this.emit("optimize",e)}}get selectedRowsCount(){return i(this,V)}get size(){return i(this,m)}get range(){return i(this,v)}set range(e){(e.from!==i(this,v).from||e.to!==i(this,v).to)&&(a(this,v,e),this.rangeRequest(e))}get config(){return i(this,n)}set config(e){var s;this.applyConfig(e)&&(i(this,n)&&this.viewport&&this.server&&e&&((s=this.server)==null||s.send({viewport:this.viewport,type:"config",config:i(this,n)})),this.emit("config",i(this,n)))}applyConfig(e){var s;if((0,u.configChanged)(i(this,n),e)&&e){let o=(s=e==null?void 0:e.filter)!=null&&s.filter&&(e==null?void 0:e.filter.filterStruct)===void 0?{...e,filter:{filter:e.filter.filter,filterStruct:(0,X.parseFilter)(e.filter.filter)}}:e;return a(this,n,(0,u.withConfigDefaults)(o)),!0}}get columns(){return i(this,n).columns}set columns(e){if(a(this,n,{...i(this,n),columns:e}),this.viewport){let s={viewport:this.viewport,type:"setColumns",columns:e};this.server&&this.server.send(s)}this.emit("config",i(this,n))}get aggregations(){return i(this,n).aggregations}set aggregations(e){var s;a(this,n,{...i(this,n),aggregations:e}),this.viewport&&((s=this.server)==null||s.send({viewport:this.viewport,type:"aggregate",aggregations:e})),this.emit("config",i(this,n))}get sort(){return i(this,n).sort}set sort(e){if(a(this,n,{...i(this,n),sort:e}),this.viewport){let s={viewport:this.viewport,type:"sort",sort:e};this.server&&this.server.send(s)}this.emit("config",i(this,n))}get filter(){return i(this,n).filter}set filter(e){if(a(this,n,{...i(this,n),filter:e}),this.viewport){let s={viewport:this.viewport,type:"filter",filter:e};this.server&&this.server.send(s)}this.emit("config",i(this,n))}get groupBy(){return i(this,n).groupBy}set groupBy(e){var s;if((0,u.itemsOrOrderChanged)(this.groupBy,e)){let o=i(this,L).length>0;if(a(this,n,{...i(this,n),groupBy:e}),this.viewport){let h={viewport:this.viewport,type:"groupBy",groupBy:i(this,n).groupBy};this.server&&this.server.send(h)}!o&&e.length>0&&this.viewport&&((s=this.clientCallback)==null||s.call(this,{clientViewportId:this.viewport,mode:"batch",type:"viewport-update",size:0,rows:[]})),this.emit("config",i(this,n)),this.setConfigPending({groupBy:e})}}get title(){return i(this,b)}set title(e){var s;a(this,b,e),this.viewport&&e&&((s=this.server)==null||s.send({type:"setTitle",title:e,viewport:this.viewport}))}get visualLink(){return i(this,n).visualLink}set visualLink(e){var s,o;if(a(this,n,{...i(this,n),visualLink:e}),e){let{parentClientVpId:h,link:{fromColumn:c,toColumn:w}}=e;this.viewport&&((s=this.server)==null||s.send({viewport:this.viewport,type:"createLink",parentClientVpId:h,parentColumnName:w,childColumnName:c}))}else this.viewport&&((o=this.server)==null||o.send({type:"removeLink",viewport:this.viewport}));this.emit("config",i(this,n))}setConfigPending(e){let s=this.configChangePending;this.configChangePending=e,e!==void 0?this.emit("config",e,!1):this.emit("config",s,!0)}async rpcCall(e){var s;if(this.viewport)return(s=this.server)==null?void 0:s.rpcCall({vpId:this.viewport,...e})}async menuRpcCall(e){var s;if(this.viewport)return(s=this.server)==null?void 0:s.rpcCall({vpId:this.viewport,...e})}applyEdit(e,s,o){return this.menuRpcCall({rowKey:e[ye],field:s,value:o,type:"VP_EDIT_CELL_RPC"}).then(h=>h!=null&&h.error?h.error:!0)}insertRow(e,s){return this.menuRpcCall({rowKey:e,data:s,type:"VP_EDIT_ADD_ROW_RPC"}).then(o=>o!=null&&o.error?o.error:!0)}deleteRow(e){return this.menuRpcCall({rowKey:e,type:"VP_EDIT_DELETE_ROW_RPC"}).then(s=>s!=null&&s.error?s.error:!0)}};n=new WeakMap,L=new WeakMap,y=new WeakMap,I=new WeakMap,T=new WeakMap,v=new WeakMap,V=new WeakMap,m=new WeakMap,l=new WeakMap,b=new WeakMap;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __accessCheck = (obj, member, msg) => {
|
|
20
|
+
if (!member.has(obj))
|
|
21
|
+
throw TypeError("Cannot " + msg);
|
|
22
|
+
};
|
|
23
|
+
var __privateGet = (obj, member, getter) => {
|
|
24
|
+
__accessCheck(obj, member, "read from private field");
|
|
25
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
26
|
+
};
|
|
27
|
+
var __privateAdd = (obj, member, value) => {
|
|
28
|
+
if (member.has(obj))
|
|
29
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
30
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
31
|
+
};
|
|
32
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
33
|
+
__accessCheck(obj, member, "write to private field");
|
|
34
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
35
|
+
return value;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/index.ts
|
|
39
|
+
var src_exports = {};
|
|
40
|
+
__export(src_exports, {
|
|
41
|
+
ConnectionManager: () => ConnectionManager,
|
|
42
|
+
VuuDataSource: () => VuuDataSource,
|
|
43
|
+
authenticate: () => authenticate,
|
|
44
|
+
connectToServer: () => connectToServer,
|
|
45
|
+
connectionId: () => connectionId,
|
|
46
|
+
createSchemaFromTableMetadata: () => createSchemaFromTableMetadata,
|
|
47
|
+
getFirstAndLastRows: () => getFirstAndLastRows,
|
|
48
|
+
getServerAPI: () => getServerAPI,
|
|
49
|
+
groupRowsByViewport: () => groupRowsByViewport,
|
|
50
|
+
isDataSourceConfigMessage: () => isDataSourceConfigMessage,
|
|
51
|
+
isSessionTable: () => isSessionTable,
|
|
52
|
+
isSessionTableActionMessage: () => isSessionTableActionMessage,
|
|
53
|
+
isSizeOnly: () => isSizeOnly,
|
|
54
|
+
isVuuMenuRpcRequest: () => isVuuMenuRpcRequest,
|
|
55
|
+
isVuuRpcRequest: () => isVuuRpcRequest,
|
|
56
|
+
makeRpcCall: () => makeRpcCall,
|
|
57
|
+
msgType: () => msgType,
|
|
58
|
+
shouldMessageBeRoutedToDataSource: () => shouldMessageBeRoutedToDataSource,
|
|
59
|
+
stripRequestId: () => stripRequestId,
|
|
60
|
+
toDataSourceConfig: () => toDataSourceConfig
|
|
61
|
+
});
|
|
62
|
+
module.exports = __toCommonJS(src_exports);
|
|
63
|
+
|
|
64
|
+
// src/authenticate.ts
|
|
65
|
+
var defaultAuthUrl = "api/authn";
|
|
66
|
+
var authenticate = async (username, password, authUrl = defaultAuthUrl) => fetch(authUrl, {
|
|
67
|
+
method: "POST",
|
|
68
|
+
credentials: "include",
|
|
69
|
+
headers: {
|
|
70
|
+
"Content-Type": "application/json",
|
|
71
|
+
"access-control-allow-origin": location.host
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify({ username, password })
|
|
74
|
+
}).then((response) => {
|
|
75
|
+
if (response.ok) {
|
|
76
|
+
const authToken = response.headers.get("vuu-auth-token");
|
|
77
|
+
if (typeof authToken === "string" && authToken.length > 0) {
|
|
78
|
+
return authToken;
|
|
79
|
+
} else {
|
|
80
|
+
throw Error(`Authentication failed auth token not returned by server`);
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
throw Error(
|
|
84
|
+
`Authentication failed ${response.status} ${response.statusText}`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// src/connection-manager.ts
|
|
90
|
+
var import_vuu_utils = require("@vuu-ui/vuu-utils");
|
|
91
|
+
|
|
92
|
+
// src/data-source.ts
|
|
93
|
+
var isSizeOnly = (message) => message.type === "viewport-update" && message.mode === "size-only";
|
|
94
|
+
var toDataSourceConfig = (message) => {
|
|
95
|
+
switch (message.type) {
|
|
96
|
+
case "aggregate":
|
|
97
|
+
return { aggregations: message.aggregations };
|
|
98
|
+
case "columns":
|
|
99
|
+
return { columns: message.columns };
|
|
100
|
+
case "filter":
|
|
101
|
+
return { filter: message.filter };
|
|
102
|
+
case "groupBy":
|
|
103
|
+
return { groupBy: message.groupBy };
|
|
104
|
+
case "sort":
|
|
105
|
+
return { sort: message.sort };
|
|
106
|
+
case "config":
|
|
107
|
+
return message.config;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
var datasourceMessages = [
|
|
111
|
+
"config",
|
|
112
|
+
"aggregate",
|
|
113
|
+
"viewport-update",
|
|
114
|
+
"columns",
|
|
115
|
+
"debounce-begin",
|
|
116
|
+
"disabled",
|
|
117
|
+
"enabled",
|
|
118
|
+
"filter",
|
|
119
|
+
"groupBy",
|
|
120
|
+
"vuu-link-created",
|
|
121
|
+
"vuu-link-removed",
|
|
122
|
+
"vuu-links",
|
|
123
|
+
"vuu-menu",
|
|
124
|
+
"sort",
|
|
125
|
+
"subscribed"
|
|
126
|
+
];
|
|
127
|
+
var shouldMessageBeRoutedToDataSource = (message) => {
|
|
128
|
+
const type = message.type;
|
|
129
|
+
return datasourceMessages.includes(type);
|
|
130
|
+
};
|
|
131
|
+
var isDataSourceConfigMessage = (message) => ["config", "aggregate", "columns", "filter", "groupBy", "sort"].includes(
|
|
132
|
+
message.type
|
|
133
|
+
);
|
|
134
|
+
var isSessionTableActionMessage = (messageBody) => messageBody.type === "VIEW_PORT_MENU_RESP" && messageBody.action !== null && isSessionTable(messageBody.action.table);
|
|
135
|
+
var isSessionTable = (table) => {
|
|
136
|
+
if (table !== null && typeof table === "object" && "table" in table && "module" in table) {
|
|
137
|
+
return table.table.startsWith("session");
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// src/server-proxy/messages.ts
|
|
143
|
+
var GET_TABLE_META = "GET_TABLE_META";
|
|
144
|
+
|
|
145
|
+
// src/inlined-worker.js
|
|
146
|
+
var workerSourceCode = `
|
|
147
|
+
var __accessCheck = (obj, member, msg) => {
|
|
148
|
+
if (!member.has(obj))
|
|
149
|
+
throw TypeError("Cannot " + msg);
|
|
150
|
+
};
|
|
151
|
+
var __privateGet = (obj, member, getter) => {
|
|
152
|
+
__accessCheck(obj, member, "read from private field");
|
|
153
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
154
|
+
};
|
|
155
|
+
var __privateAdd = (obj, member, value) => {
|
|
156
|
+
if (member.has(obj))
|
|
157
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
158
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
159
|
+
};
|
|
160
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
161
|
+
__accessCheck(obj, member, "write to private field");
|
|
162
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
163
|
+
return value;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// ../vuu-utils/src/array-utils.ts
|
|
167
|
+
function partition(array, test, pass = [], fail = []) {
|
|
168
|
+
for (let i = 0, len = array.length; i < len; i++) {
|
|
169
|
+
(test(array[i], i) ? pass : fail).push(array[i]);
|
|
170
|
+
}
|
|
171
|
+
return [pass, fail];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ../vuu-utils/src/column-utils.ts
|
|
175
|
+
var metadataKeys = {
|
|
176
|
+
IDX: 0,
|
|
177
|
+
RENDER_IDX: 1,
|
|
178
|
+
IS_LEAF: 2,
|
|
179
|
+
IS_EXPANDED: 3,
|
|
180
|
+
DEPTH: 4,
|
|
181
|
+
COUNT: 5,
|
|
182
|
+
KEY: 6,
|
|
183
|
+
SELECTED: 7,
|
|
184
|
+
count: 8,
|
|
185
|
+
// TODO following only used in datamodel
|
|
186
|
+
PARENT_IDX: "parent_idx",
|
|
187
|
+
IDX_POINTER: "idx_pointer",
|
|
188
|
+
FILTER_COUNT: "filter_count",
|
|
189
|
+
NEXT_FILTER_IDX: "next_filter_idx"
|
|
190
|
+
};
|
|
191
|
+
var { DEPTH, IS_LEAF } = metadataKeys;
|
|
192
|
+
|
|
193
|
+
// ../vuu-utils/src/cookie-utils.ts
|
|
194
|
+
var getCookieValue = (name) => {
|
|
195
|
+
var _a, _b;
|
|
196
|
+
if (((_a = globalThis.document) == null ? void 0 : _a.cookie) !== void 0) {
|
|
197
|
+
return (_b = globalThis.document.cookie.split("; ").find((row) => row.startsWith(\`\${name}=\`))) == null ? void 0 : _b.split("=")[1];
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// ../vuu-utils/src/range-utils.ts
|
|
202
|
+
function getFullRange({ from, to }, bufferSize = 0, rowCount = Number.MAX_SAFE_INTEGER) {
|
|
203
|
+
if (bufferSize === 0) {
|
|
204
|
+
if (rowCount < from) {
|
|
205
|
+
return { from: 0, to: 0 };
|
|
206
|
+
} else {
|
|
207
|
+
return { from, to: Math.min(to, rowCount) };
|
|
208
|
+
}
|
|
209
|
+
} else if (from === 0) {
|
|
210
|
+
return { from, to: Math.min(to + bufferSize, rowCount) };
|
|
211
|
+
} else {
|
|
212
|
+
const rangeSize = to - from;
|
|
213
|
+
const buff = Math.round(bufferSize / 2);
|
|
214
|
+
const shortfallBefore = from - buff < 0;
|
|
215
|
+
const shortFallAfter = rowCount - (to + buff) < 0;
|
|
216
|
+
if (shortfallBefore && shortFallAfter) {
|
|
217
|
+
return { from: 0, to: rowCount };
|
|
218
|
+
} else if (shortfallBefore) {
|
|
219
|
+
return { from: 0, to: rangeSize + bufferSize };
|
|
220
|
+
} else if (shortFallAfter) {
|
|
221
|
+
return {
|
|
222
|
+
from: Math.max(0, rowCount - (rangeSize + bufferSize)),
|
|
223
|
+
to: rowCount
|
|
224
|
+
};
|
|
225
|
+
} else {
|
|
226
|
+
return { from: from - buff, to: to + buff };
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
var withinRange = (value, { from, to }) => value >= from && value < to;
|
|
231
|
+
var WindowRange = class _WindowRange {
|
|
232
|
+
constructor(from, to) {
|
|
233
|
+
this.from = from;
|
|
234
|
+
this.to = to;
|
|
235
|
+
}
|
|
236
|
+
isWithin(index) {
|
|
237
|
+
return withinRange(index, this);
|
|
238
|
+
}
|
|
239
|
+
//find the overlap of this range and a new one
|
|
240
|
+
overlap(from, to) {
|
|
241
|
+
return from >= this.to || to < this.from ? [0, 0] : [Math.max(from, this.from), Math.min(to, this.to)];
|
|
242
|
+
}
|
|
243
|
+
copy() {
|
|
244
|
+
return new _WindowRange(this.from, this.to);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// ../vuu-utils/src/datasource-utils.ts
|
|
249
|
+
var isConnectionStatusMessage = (msg) => msg.type === "connection-status";
|
|
250
|
+
var isConnectionQualityMetrics = (msg) => msg.type === "connection-metrics";
|
|
251
|
+
var isViewporttMessage = (msg) => "viewport" in msg;
|
|
252
|
+
|
|
253
|
+
// ../vuu-utils/src/logging-utils.ts
|
|
254
|
+
var logLevels = ["error", "warn", "info", "debug"];
|
|
255
|
+
var isValidLogLevel = (value) => typeof value === "string" && logLevels.includes(value);
|
|
256
|
+
var DEFAULT_LOG_LEVEL = "error";
|
|
257
|
+
var NO_OP = () => void 0;
|
|
258
|
+
var DEFAULT_DEBUG_LEVEL = false ? "error" : "info";
|
|
259
|
+
var { loggingLevel = DEFAULT_DEBUG_LEVEL } = getLoggingSettings();
|
|
260
|
+
var logger = (category) => {
|
|
261
|
+
const debugEnabled5 = loggingLevel === "debug";
|
|
262
|
+
const infoEnabled5 = debugEnabled5 || loggingLevel === "info";
|
|
263
|
+
const warnEnabled = infoEnabled5 || loggingLevel === "warn";
|
|
264
|
+
const errorEnabled = warnEnabled || loggingLevel === "error";
|
|
265
|
+
const info5 = infoEnabled5 ? (message) => console.info(\`[\${category}] \${message}\`) : NO_OP;
|
|
266
|
+
const warn4 = warnEnabled ? (message) => console.warn(\`[\${category}] \${message}\`) : NO_OP;
|
|
267
|
+
const debug5 = debugEnabled5 ? (message) => console.debug(\`[\${category}] \${message}\`) : NO_OP;
|
|
268
|
+
const error4 = errorEnabled ? (message) => console.error(\`[\${category}] \${message}\`) : NO_OP;
|
|
269
|
+
if (false) {
|
|
270
|
+
return {
|
|
271
|
+
errorEnabled,
|
|
272
|
+
error: error4
|
|
273
|
+
};
|
|
274
|
+
} else {
|
|
275
|
+
return {
|
|
276
|
+
debugEnabled: debugEnabled5,
|
|
277
|
+
infoEnabled: infoEnabled5,
|
|
278
|
+
warnEnabled,
|
|
279
|
+
errorEnabled,
|
|
280
|
+
info: info5,
|
|
281
|
+
warn: warn4,
|
|
282
|
+
debug: debug5,
|
|
283
|
+
error: error4
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
function getLoggingSettings() {
|
|
288
|
+
if (typeof loggingSettings !== "undefined") {
|
|
289
|
+
return loggingSettings;
|
|
290
|
+
} else {
|
|
291
|
+
return {
|
|
292
|
+
loggingLevel: getLoggingLevelFromCookie()
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function getLoggingLevelFromCookie() {
|
|
297
|
+
const value = getCookieValue("vuu-logging-level");
|
|
298
|
+
if (isValidLogLevel(value)) {
|
|
299
|
+
return value;
|
|
300
|
+
} else {
|
|
301
|
+
return DEFAULT_LOG_LEVEL;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ../vuu-utils/src/debug-utils.ts
|
|
306
|
+
var { debug, debugEnabled } = logger("range-monitor");
|
|
307
|
+
var RangeMonitor = class {
|
|
308
|
+
constructor(source) {
|
|
309
|
+
this.source = source;
|
|
310
|
+
this.range = { from: 0, to: 0 };
|
|
311
|
+
this.timestamp = 0;
|
|
312
|
+
}
|
|
313
|
+
isSet() {
|
|
314
|
+
return this.timestamp !== 0;
|
|
315
|
+
}
|
|
316
|
+
set({ from, to }) {
|
|
317
|
+
const { timestamp } = this;
|
|
318
|
+
this.range.from = from;
|
|
319
|
+
this.range.to = to;
|
|
320
|
+
this.timestamp = performance.now();
|
|
321
|
+
if (timestamp) {
|
|
322
|
+
debugEnabled && debug(
|
|
323
|
+
\`<\${this.source}> [\${from}-\${to}], \${(this.timestamp - timestamp).toFixed(0)} ms elapsed\`
|
|
324
|
+
);
|
|
325
|
+
} else {
|
|
326
|
+
return 0;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// ../vuu-utils/src/keyset.ts
|
|
332
|
+
var KeySet = class {
|
|
333
|
+
constructor(range) {
|
|
334
|
+
this.keys = /* @__PURE__ */ new Map();
|
|
335
|
+
this.free = [];
|
|
336
|
+
this.nextKeyValue = 0;
|
|
337
|
+
this.reset(range);
|
|
338
|
+
}
|
|
339
|
+
next() {
|
|
340
|
+
if (this.free.length > 0) {
|
|
341
|
+
return this.free.shift();
|
|
342
|
+
} else {
|
|
343
|
+
return this.nextKeyValue++;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
reset({ from, to }) {
|
|
347
|
+
this.keys.forEach((keyValue, rowIndex) => {
|
|
348
|
+
if (rowIndex < from || rowIndex >= to) {
|
|
349
|
+
this.free.push(keyValue);
|
|
350
|
+
this.keys.delete(rowIndex);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
const size = to - from;
|
|
354
|
+
if (this.keys.size + this.free.length > size) {
|
|
355
|
+
this.free.length = Math.max(0, size - this.keys.size);
|
|
356
|
+
}
|
|
357
|
+
for (let rowIndex = from; rowIndex < to; rowIndex++) {
|
|
358
|
+
if (!this.keys.has(rowIndex)) {
|
|
359
|
+
const nextKeyValue = this.next();
|
|
360
|
+
this.keys.set(rowIndex, nextKeyValue);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (this.nextKeyValue > this.keys.size) {
|
|
364
|
+
this.nextKeyValue = this.keys.size;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
keyFor(rowIndex) {
|
|
368
|
+
const key = this.keys.get(rowIndex);
|
|
369
|
+
if (key === void 0) {
|
|
370
|
+
console.log(\`key not found
|
|
371
|
+
keys: \${this.toDebugString()}
|
|
372
|
+
free : \${this.free.join(",")}
|
|
373
|
+
\`);
|
|
374
|
+
throw Error(\`KeySet, no key found for rowIndex \${rowIndex}\`);
|
|
375
|
+
}
|
|
376
|
+
return key;
|
|
377
|
+
}
|
|
378
|
+
toDebugString() {
|
|
379
|
+
return Array.from(this.keys.entries()).map(([k, v]) => \`\${k}=>\${v}\`).join(",");
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
// ../vuu-utils/src/selection-utils.ts
|
|
384
|
+
var { SELECTED } = metadataKeys;
|
|
385
|
+
var RowSelected = {
|
|
386
|
+
False: 0,
|
|
387
|
+
True: 1,
|
|
388
|
+
First: 2,
|
|
389
|
+
Last: 4
|
|
390
|
+
};
|
|
391
|
+
var rangeIncludes = (range, index) => index >= range[0] && index <= range[1];
|
|
392
|
+
var SINGLE_SELECTED_ROW = RowSelected.True + RowSelected.First + RowSelected.Last;
|
|
393
|
+
var FIRST_SELECTED_ROW_OF_BLOCK = RowSelected.True + RowSelected.First;
|
|
394
|
+
var LAST_SELECTED_ROW_OF_BLOCK = RowSelected.True + RowSelected.Last;
|
|
395
|
+
var getSelectionStatus = (selected, itemIndex) => {
|
|
396
|
+
for (const item of selected) {
|
|
397
|
+
if (typeof item === "number") {
|
|
398
|
+
if (item === itemIndex) {
|
|
399
|
+
return SINGLE_SELECTED_ROW;
|
|
400
|
+
}
|
|
401
|
+
} else if (rangeIncludes(item, itemIndex)) {
|
|
402
|
+
if (itemIndex === item[0]) {
|
|
403
|
+
return FIRST_SELECTED_ROW_OF_BLOCK;
|
|
404
|
+
} else if (itemIndex === item[1]) {
|
|
405
|
+
return LAST_SELECTED_ROW_OF_BLOCK;
|
|
406
|
+
} else {
|
|
407
|
+
return RowSelected.True;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return RowSelected.False;
|
|
412
|
+
};
|
|
413
|
+
var expandSelection = (selected) => {
|
|
414
|
+
if (selected.every((selectedItem) => typeof selectedItem === "number")) {
|
|
415
|
+
return selected;
|
|
416
|
+
}
|
|
417
|
+
const expandedSelected = [];
|
|
418
|
+
for (const selectedItem of selected) {
|
|
419
|
+
if (typeof selectedItem === "number") {
|
|
420
|
+
expandedSelected.push(selectedItem);
|
|
421
|
+
} else {
|
|
422
|
+
for (let i = selectedItem[0]; i <= selectedItem[1]; i++) {
|
|
423
|
+
expandedSelected.push(i);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return expandedSelected;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
// src/data-source.ts
|
|
431
|
+
var isSessionTableActionMessage = (messageBody) => messageBody.type === "VIEW_PORT_MENU_RESP" && messageBody.action !== null && isSessionTable(messageBody.action.table);
|
|
432
|
+
var isSessionTable = (table) => {
|
|
433
|
+
if (table !== null && typeof table === "object" && "table" in table && "module" in table) {
|
|
434
|
+
return table.table.startsWith("session");
|
|
435
|
+
}
|
|
436
|
+
return false;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// src/message-utils.ts
|
|
440
|
+
var MENU_RPC_TYPES = [
|
|
441
|
+
"VIEW_PORT_MENUS_SELECT_RPC",
|
|
442
|
+
"VIEW_PORT_MENU_TABLE_RPC",
|
|
443
|
+
"VIEW_PORT_MENU_ROW_RPC",
|
|
444
|
+
"VIEW_PORT_MENU_CELL_RPC",
|
|
445
|
+
"VP_EDIT_CELL_RPC",
|
|
446
|
+
"VP_EDIT_ROW_RPC",
|
|
447
|
+
"VP_EDIT_ADD_ROW_RPC",
|
|
448
|
+
"VP_EDIT_DELETE_CELL_RPC",
|
|
449
|
+
"VP_EDIT_DELETE_ROW_RPC",
|
|
450
|
+
"VP_EDIT_SUBMIT_FORM_RPC"
|
|
451
|
+
];
|
|
452
|
+
var isVuuMenuRpcRequest = (message) => MENU_RPC_TYPES.includes(message["type"]);
|
|
453
|
+
var isVuuRpcRequest = (message) => message["type"] === "VIEW_PORT_RPC_CALL";
|
|
454
|
+
var stripRequestId = ({
|
|
455
|
+
requestId,
|
|
456
|
+
...rest
|
|
457
|
+
}) => [requestId, rest];
|
|
458
|
+
var getFirstAndLastRows = (rows) => {
|
|
459
|
+
let firstRow = rows.at(0);
|
|
460
|
+
if (firstRow.updateType === "SIZE") {
|
|
461
|
+
if (rows.length === 1) {
|
|
462
|
+
return rows;
|
|
463
|
+
} else {
|
|
464
|
+
firstRow = rows.at(1);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
const lastRow = rows.at(-1);
|
|
468
|
+
return [firstRow, lastRow];
|
|
469
|
+
};
|
|
470
|
+
var groupRowsByViewport = (rows) => {
|
|
471
|
+
const result = {};
|
|
472
|
+
for (const row of rows) {
|
|
473
|
+
const rowsForViewport = result[row.viewPortId] || (result[row.viewPortId] = []);
|
|
474
|
+
rowsForViewport.push(row);
|
|
475
|
+
}
|
|
476
|
+
return result;
|
|
477
|
+
};
|
|
478
|
+
var createSchemaFromTableMetadata = ({
|
|
479
|
+
columns,
|
|
480
|
+
dataTypes,
|
|
481
|
+
key,
|
|
482
|
+
table
|
|
483
|
+
}) => {
|
|
484
|
+
return {
|
|
485
|
+
table,
|
|
486
|
+
columns: columns.map((col, idx) => ({
|
|
487
|
+
name: col,
|
|
488
|
+
serverDataType: dataTypes[idx]
|
|
489
|
+
})),
|
|
490
|
+
key
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
// src/server-proxy/messages.ts
|
|
495
|
+
var CHANGE_VP_SUCCESS = "CHANGE_VP_SUCCESS";
|
|
496
|
+
var CLOSE_TREE_NODE = "CLOSE_TREE_NODE";
|
|
497
|
+
var CLOSE_TREE_SUCCESS = "CLOSE_TREE_SUCCESS";
|
|
498
|
+
var CREATE_VP = "CREATE_VP";
|
|
499
|
+
var DISABLE_VP = "DISABLE_VP";
|
|
500
|
+
var DISABLE_VP_SUCCESS = "DISABLE_VP_SUCCESS";
|
|
501
|
+
var ENABLE_VP = "ENABLE_VP";
|
|
502
|
+
var ENABLE_VP_SUCCESS = "ENABLE_VP_SUCCESS";
|
|
503
|
+
var GET_VP_VISUAL_LINKS = "GET_VP_VISUAL_LINKS";
|
|
504
|
+
var GET_VIEW_PORT_MENUS = "GET_VIEW_PORT_MENUS";
|
|
505
|
+
var HB = "HB";
|
|
506
|
+
var HB_RESP = "HB_RESP";
|
|
507
|
+
var LOGIN = "LOGIN";
|
|
508
|
+
var OPEN_TREE_NODE = "OPEN_TREE_NODE";
|
|
509
|
+
var OPEN_TREE_SUCCESS = "OPEN_TREE_SUCCESS";
|
|
510
|
+
var REMOVE_VP = "REMOVE_VP";
|
|
511
|
+
var SET_SELECTION_SUCCESS = "SET_SELECTION_SUCCESS";
|
|
512
|
+
|
|
513
|
+
// src/server-proxy/rpc-services.ts
|
|
514
|
+
var getRpcServiceModule = (service) => {
|
|
515
|
+
switch (service) {
|
|
516
|
+
case "TypeAheadRpcHandler":
|
|
517
|
+
return "TYPEAHEAD";
|
|
518
|
+
default:
|
|
519
|
+
return "SIMUL";
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
// src/server-proxy/array-backed-moving-window.ts
|
|
524
|
+
var EMPTY_ARRAY = [];
|
|
525
|
+
var log = logger("array-backed-moving-window");
|
|
526
|
+
function dataIsUnchanged(newRow, existingRow) {
|
|
527
|
+
if (!existingRow) {
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
if (existingRow.data.length !== newRow.data.length) {
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
if (existingRow.sel !== newRow.sel) {
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
for (let i = 0; i < existingRow.data.length; i++) {
|
|
537
|
+
if (existingRow.data[i] !== newRow.data[i]) {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
543
|
+
var _range;
|
|
544
|
+
var ArrayBackedMovingWindow = class {
|
|
545
|
+
// Note, the buffer is already accounted for in the range passed in here
|
|
546
|
+
constructor({ from: clientFrom, to: clientTo }, { from, to }, bufferSize) {
|
|
547
|
+
__privateAdd(this, _range, void 0);
|
|
548
|
+
this.setRowCount = (rowCount) => {
|
|
549
|
+
var _a;
|
|
550
|
+
(_a = log.info) == null ? void 0 : _a.call(log, \`setRowCount \${rowCount}\`);
|
|
551
|
+
if (rowCount < this.internalData.length) {
|
|
552
|
+
this.internalData.length = rowCount;
|
|
553
|
+
}
|
|
554
|
+
if (rowCount < this.rowCount) {
|
|
555
|
+
this.rowsWithinRange = 0;
|
|
556
|
+
const end = Math.min(rowCount, this.clientRange.to);
|
|
557
|
+
for (let i = this.clientRange.from; i < end; i++) {
|
|
558
|
+
const rowIndex = i - __privateGet(this, _range).from;
|
|
559
|
+
if (this.internalData[rowIndex] !== void 0) {
|
|
560
|
+
this.rowsWithinRange += 1;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
this.rowCount = rowCount;
|
|
565
|
+
};
|
|
566
|
+
this.bufferBreakout = (from, to) => {
|
|
567
|
+
const bufferPerimeter = this.bufferSize * 0.25;
|
|
568
|
+
if (__privateGet(this, _range).to - to < bufferPerimeter) {
|
|
569
|
+
return true;
|
|
570
|
+
} else if (__privateGet(this, _range).from > 0 && from - __privateGet(this, _range).from < bufferPerimeter) {
|
|
571
|
+
return true;
|
|
572
|
+
} else {
|
|
573
|
+
return false;
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
this.bufferSize = bufferSize;
|
|
577
|
+
this.clientRange = new WindowRange(clientFrom, clientTo);
|
|
578
|
+
__privateSet(this, _range, new WindowRange(from, to));
|
|
579
|
+
this.internalData = new Array(bufferSize);
|
|
580
|
+
this.rowsWithinRange = 0;
|
|
581
|
+
this.rowCount = 0;
|
|
582
|
+
}
|
|
583
|
+
get range() {
|
|
584
|
+
return __privateGet(this, _range);
|
|
585
|
+
}
|
|
586
|
+
// TODO we shpuld probably have a hasAllClientRowsWithinRange
|
|
587
|
+
get hasAllRowsWithinRange() {
|
|
588
|
+
return this.rowsWithinRange === this.clientRange.to - this.clientRange.from || // this.rowsWithinRange === this.range.to - this.range.from ||
|
|
589
|
+
this.rowCount > 0 && this.clientRange.from + this.rowsWithinRange === this.rowCount;
|
|
590
|
+
}
|
|
591
|
+
// Check to see if set of rows is outside the current viewport range, indicating
|
|
592
|
+
// that veiwport is being scrolled quickly and server is not able to keep up.
|
|
593
|
+
outOfRange(firstIndex, lastIndex) {
|
|
594
|
+
const { from, to } = this.range;
|
|
595
|
+
if (lastIndex < from) {
|
|
596
|
+
return true;
|
|
597
|
+
}
|
|
598
|
+
if (firstIndex >= to) {
|
|
599
|
+
return true;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
setAtIndex(row) {
|
|
603
|
+
const { rowIndex: index } = row;
|
|
604
|
+
const internalIndex = index - __privateGet(this, _range).from;
|
|
605
|
+
if (dataIsUnchanged(row, this.internalData[internalIndex])) {
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
const isWithinClientRange = this.isWithinClientRange(index);
|
|
609
|
+
if (isWithinClientRange || this.isWithinRange(index)) {
|
|
610
|
+
if (!this.internalData[internalIndex] && isWithinClientRange) {
|
|
611
|
+
this.rowsWithinRange += 1;
|
|
612
|
+
}
|
|
613
|
+
this.internalData[internalIndex] = row;
|
|
614
|
+
}
|
|
615
|
+
return isWithinClientRange;
|
|
616
|
+
}
|
|
617
|
+
getAtIndex(index) {
|
|
618
|
+
return __privateGet(this, _range).isWithin(index) && this.internalData[index - __privateGet(this, _range).from] != null ? this.internalData[index - __privateGet(this, _range).from] : void 0;
|
|
619
|
+
}
|
|
620
|
+
isWithinRange(index) {
|
|
621
|
+
return __privateGet(this, _range).isWithin(index);
|
|
622
|
+
}
|
|
623
|
+
isWithinClientRange(index) {
|
|
624
|
+
return this.clientRange.isWithin(index);
|
|
625
|
+
}
|
|
626
|
+
// Returns [false] or [serverDataRequired, clientRows, holdingRows]
|
|
627
|
+
setClientRange(from, to) {
|
|
628
|
+
var _a;
|
|
629
|
+
(_a = log.debug) == null ? void 0 : _a.call(log, \`setClientRange \${from} - \${to}\`);
|
|
630
|
+
const currentFrom = this.clientRange.from;
|
|
631
|
+
const currentTo = Math.min(this.clientRange.to, this.rowCount);
|
|
632
|
+
if (from === currentFrom && to === currentTo) {
|
|
633
|
+
return [
|
|
634
|
+
false,
|
|
635
|
+
EMPTY_ARRAY
|
|
636
|
+
/*, EMPTY_ARRAY*/
|
|
637
|
+
];
|
|
638
|
+
}
|
|
639
|
+
const originalRange = this.clientRange.copy();
|
|
640
|
+
this.clientRange.from = from;
|
|
641
|
+
this.clientRange.to = to;
|
|
642
|
+
this.rowsWithinRange = 0;
|
|
643
|
+
for (let i = from; i < to; i++) {
|
|
644
|
+
const internalIndex = i - __privateGet(this, _range).from;
|
|
645
|
+
if (this.internalData[internalIndex]) {
|
|
646
|
+
this.rowsWithinRange += 1;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
let clientRows = EMPTY_ARRAY;
|
|
650
|
+
const offset = __privateGet(this, _range).from;
|
|
651
|
+
if (this.hasAllRowsWithinRange) {
|
|
652
|
+
if (to > originalRange.to) {
|
|
653
|
+
const start = Math.max(from, originalRange.to);
|
|
654
|
+
clientRows = this.internalData.slice(start - offset, to - offset);
|
|
655
|
+
} else {
|
|
656
|
+
const end = Math.min(originalRange.from, to);
|
|
657
|
+
clientRows = this.internalData.slice(from - offset, end - offset);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
const serverDataRequired = this.bufferBreakout(from, to);
|
|
661
|
+
return [serverDataRequired, clientRows];
|
|
662
|
+
}
|
|
663
|
+
setRange(from, to) {
|
|
664
|
+
var _a, _b;
|
|
665
|
+
if (from !== __privateGet(this, _range).from || to !== __privateGet(this, _range).to) {
|
|
666
|
+
(_a = log.debug) == null ? void 0 : _a.call(log, \`setRange \${from} - \${to}\`);
|
|
667
|
+
const [overlapFrom, overlapTo] = __privateGet(this, _range).overlap(from, to);
|
|
668
|
+
const newData = new Array(to - from);
|
|
669
|
+
this.rowsWithinRange = 0;
|
|
670
|
+
for (let i = overlapFrom; i < overlapTo; i++) {
|
|
671
|
+
const data = this.getAtIndex(i);
|
|
672
|
+
if (data) {
|
|
673
|
+
const index = i - from;
|
|
674
|
+
newData[index] = data;
|
|
675
|
+
if (this.isWithinClientRange(i)) {
|
|
676
|
+
this.rowsWithinRange += 1;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
this.internalData = newData;
|
|
681
|
+
__privateGet(this, _range).from = from;
|
|
682
|
+
__privateGet(this, _range).to = to;
|
|
683
|
+
} else {
|
|
684
|
+
(_b = log.debug) == null ? void 0 : _b.call(log, \`setRange \${from} - \${to} IGNORED because not changed\`);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
//TODO temp
|
|
688
|
+
get data() {
|
|
689
|
+
return this.internalData;
|
|
690
|
+
}
|
|
691
|
+
getData() {
|
|
692
|
+
var _a;
|
|
693
|
+
const { from, to } = __privateGet(this, _range);
|
|
694
|
+
const { from: clientFrom, to: clientTo } = this.clientRange;
|
|
695
|
+
const startOffset = Math.max(0, clientFrom - from);
|
|
696
|
+
const endOffset = Math.min(
|
|
697
|
+
to - from,
|
|
698
|
+
to,
|
|
699
|
+
clientTo - from,
|
|
700
|
+
(_a = this.rowCount) != null ? _a : to
|
|
701
|
+
);
|
|
702
|
+
return this.internalData.slice(startOffset, endOffset);
|
|
703
|
+
}
|
|
704
|
+
clear() {
|
|
705
|
+
var _a;
|
|
706
|
+
(_a = log.debug) == null ? void 0 : _a.call(log, "clear");
|
|
707
|
+
this.internalData.length = 0;
|
|
708
|
+
this.rowsWithinRange = 0;
|
|
709
|
+
this.setRowCount(0);
|
|
710
|
+
}
|
|
711
|
+
// used only for debugging
|
|
712
|
+
getCurrentDataRange() {
|
|
713
|
+
const rows = this.internalData;
|
|
714
|
+
const len = rows.length;
|
|
715
|
+
let [firstRow] = this.internalData;
|
|
716
|
+
let lastRow = this.internalData[len - 1];
|
|
717
|
+
if (firstRow && lastRow) {
|
|
718
|
+
return [firstRow.rowIndex, lastRow.rowIndex];
|
|
719
|
+
} else {
|
|
720
|
+
for (let i = 0; i < len; i++) {
|
|
721
|
+
if (rows[i] !== void 0) {
|
|
722
|
+
firstRow = rows[i];
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
727
|
+
if (rows[i] !== void 0) {
|
|
728
|
+
lastRow = rows[i];
|
|
729
|
+
break;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
if (firstRow && lastRow) {
|
|
733
|
+
return [firstRow.rowIndex, lastRow.rowIndex];
|
|
734
|
+
} else {
|
|
735
|
+
return [-1, -1];
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
_range = new WeakMap();
|
|
741
|
+
|
|
742
|
+
// src/server-proxy/viewport.ts
|
|
743
|
+
var EMPTY_GROUPBY = [];
|
|
744
|
+
var { debug: debug2, debugEnabled: debugEnabled2, error, info, infoEnabled, warn } = logger("viewport");
|
|
745
|
+
var isLeafUpdate = ({ rowKey, updateType }) => updateType === "U" && !rowKey.startsWith("$root");
|
|
746
|
+
var NO_DATA_UPDATE = [
|
|
747
|
+
void 0,
|
|
748
|
+
void 0
|
|
749
|
+
];
|
|
750
|
+
var NO_UPDATE_STATUS = {
|
|
751
|
+
count: 0,
|
|
752
|
+
mode: void 0,
|
|
753
|
+
size: 0,
|
|
754
|
+
ts: 0
|
|
755
|
+
};
|
|
756
|
+
var Viewport = class {
|
|
757
|
+
constructor({
|
|
758
|
+
aggregations,
|
|
759
|
+
bufferSize = 50,
|
|
760
|
+
columns,
|
|
761
|
+
filter,
|
|
762
|
+
groupBy = [],
|
|
763
|
+
table,
|
|
764
|
+
range,
|
|
765
|
+
sort,
|
|
766
|
+
title,
|
|
767
|
+
viewport,
|
|
768
|
+
visualLink
|
|
769
|
+
}, postMessageToClient) {
|
|
770
|
+
/** batchMode is irrelevant for Vuu Table, it was introduced to try and improve rendering performance of AgGrid */
|
|
771
|
+
this.batchMode = true;
|
|
772
|
+
this.hasUpdates = false;
|
|
773
|
+
this.pendingUpdates = [];
|
|
774
|
+
this.pendingOperations = /* @__PURE__ */ new Map();
|
|
775
|
+
this.pendingRangeRequests = [];
|
|
776
|
+
this.rowCountChanged = false;
|
|
777
|
+
this.selectedRows = [];
|
|
778
|
+
this.useBatchMode = true;
|
|
779
|
+
this.lastUpdateStatus = NO_UPDATE_STATUS;
|
|
780
|
+
this.updateThrottleTimer = void 0;
|
|
781
|
+
this.rangeMonitor = new RangeMonitor("ViewPort");
|
|
782
|
+
this.disabled = false;
|
|
783
|
+
this.isTree = false;
|
|
784
|
+
// TODO roll disabled/suspended into status
|
|
785
|
+
this.status = "";
|
|
786
|
+
this.suspended = false;
|
|
787
|
+
this.suspendTimer = null;
|
|
788
|
+
// Records SIZE only updates
|
|
789
|
+
this.setLastSizeOnlyUpdateSize = (size) => {
|
|
790
|
+
this.lastUpdateStatus.size = size;
|
|
791
|
+
};
|
|
792
|
+
this.setLastUpdate = (mode) => {
|
|
793
|
+
const { ts: lastTS, mode: lastMode } = this.lastUpdateStatus;
|
|
794
|
+
let elapsedTime = 0;
|
|
795
|
+
if (lastMode === mode) {
|
|
796
|
+
const ts = Date.now();
|
|
797
|
+
this.lastUpdateStatus.count += 1;
|
|
798
|
+
this.lastUpdateStatus.ts = ts;
|
|
799
|
+
elapsedTime = lastTS === 0 ? 0 : ts - lastTS;
|
|
800
|
+
} else {
|
|
801
|
+
this.lastUpdateStatus.count = 1;
|
|
802
|
+
this.lastUpdateStatus.ts = 0;
|
|
803
|
+
elapsedTime = 0;
|
|
804
|
+
}
|
|
805
|
+
this.lastUpdateStatus.mode = mode;
|
|
806
|
+
return elapsedTime;
|
|
807
|
+
};
|
|
808
|
+
this.rangeRequestAlreadyPending = (range) => {
|
|
809
|
+
const { bufferSize } = this;
|
|
810
|
+
const bufferThreshold = bufferSize * 0.25;
|
|
811
|
+
let { from: stillPendingFrom } = range;
|
|
812
|
+
for (const { from, to } of this.pendingRangeRequests) {
|
|
813
|
+
if (stillPendingFrom >= from && stillPendingFrom < to) {
|
|
814
|
+
if (range.to + bufferThreshold <= to) {
|
|
815
|
+
return true;
|
|
816
|
+
} else {
|
|
817
|
+
stillPendingFrom = to;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
return false;
|
|
822
|
+
};
|
|
823
|
+
this.sendThrottledSizeMessage = () => {
|
|
824
|
+
this.updateThrottleTimer = void 0;
|
|
825
|
+
this.lastUpdateStatus.count = 3;
|
|
826
|
+
this.postMessageToClient({
|
|
827
|
+
clientViewportId: this.clientViewportId,
|
|
828
|
+
mode: "size-only",
|
|
829
|
+
size: this.lastUpdateStatus.size,
|
|
830
|
+
type: "viewport-update"
|
|
831
|
+
});
|
|
832
|
+
};
|
|
833
|
+
// If we are receiving multiple SIZE updates but no data, table is loading rows
|
|
834
|
+
// outside of our viewport. We can safely throttle these requests. Doing so will
|
|
835
|
+
// alleviate pressure on UI DataTable.
|
|
836
|
+
this.shouldThrottleMessage = (mode) => {
|
|
837
|
+
const elapsedTime = this.setLastUpdate(mode);
|
|
838
|
+
return mode === "size-only" && elapsedTime > 0 && elapsedTime < 500 && this.lastUpdateStatus.count > 3;
|
|
839
|
+
};
|
|
840
|
+
this.throttleMessage = (mode) => {
|
|
841
|
+
if (this.shouldThrottleMessage(mode)) {
|
|
842
|
+
info == null ? void 0 : info("throttling updates setTimeout to 2000");
|
|
843
|
+
if (this.updateThrottleTimer === void 0) {
|
|
844
|
+
this.updateThrottleTimer = setTimeout(
|
|
845
|
+
this.sendThrottledSizeMessage,
|
|
846
|
+
2e3
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
return true;
|
|
850
|
+
} else if (this.updateThrottleTimer !== void 0) {
|
|
851
|
+
clearTimeout(this.updateThrottleTimer);
|
|
852
|
+
this.updateThrottleTimer = void 0;
|
|
853
|
+
}
|
|
854
|
+
return false;
|
|
855
|
+
};
|
|
856
|
+
this.getNewRowCount = () => {
|
|
857
|
+
if (this.rowCountChanged && this.dataWindow) {
|
|
858
|
+
this.rowCountChanged = false;
|
|
859
|
+
return this.dataWindow.rowCount;
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
this.aggregations = aggregations;
|
|
863
|
+
this.bufferSize = bufferSize;
|
|
864
|
+
this.clientRange = range;
|
|
865
|
+
this.clientViewportId = viewport;
|
|
866
|
+
this.columns = columns;
|
|
867
|
+
this.filter = filter;
|
|
868
|
+
this.groupBy = groupBy;
|
|
869
|
+
this.keys = new KeySet(range);
|
|
870
|
+
this.pendingLinkedParent = visualLink;
|
|
871
|
+
this.table = table;
|
|
872
|
+
this.sort = sort;
|
|
873
|
+
this.title = title;
|
|
874
|
+
infoEnabled && (info == null ? void 0 : info(
|
|
875
|
+
\`constructor #\${viewport} \${table.table} bufferSize=\${bufferSize}\`
|
|
876
|
+
));
|
|
877
|
+
this.dataWindow = new ArrayBackedMovingWindow(
|
|
878
|
+
this.clientRange,
|
|
879
|
+
range,
|
|
880
|
+
this.bufferSize
|
|
881
|
+
);
|
|
882
|
+
this.postMessageToClient = postMessageToClient;
|
|
883
|
+
}
|
|
884
|
+
get hasUpdatesToProcess() {
|
|
885
|
+
if (this.suspended) {
|
|
886
|
+
return false;
|
|
887
|
+
}
|
|
888
|
+
return this.rowCountChanged || this.hasUpdates;
|
|
889
|
+
}
|
|
890
|
+
get size() {
|
|
891
|
+
var _a;
|
|
892
|
+
return (_a = this.dataWindow.rowCount) != null ? _a : 0;
|
|
893
|
+
}
|
|
894
|
+
subscribe() {
|
|
895
|
+
const { filter } = this.filter;
|
|
896
|
+
this.status = this.status === "subscribed" ? "resubscribing" : "subscribing";
|
|
897
|
+
return {
|
|
898
|
+
type: CREATE_VP,
|
|
899
|
+
table: this.table,
|
|
900
|
+
range: getFullRange(this.clientRange, this.bufferSize),
|
|
901
|
+
aggregations: this.aggregations,
|
|
902
|
+
columns: this.columns,
|
|
903
|
+
sort: this.sort,
|
|
904
|
+
groupBy: this.groupBy,
|
|
905
|
+
filterSpec: { filter }
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
handleSubscribed({
|
|
909
|
+
viewPortId,
|
|
910
|
+
aggregations,
|
|
911
|
+
columns,
|
|
912
|
+
filterSpec: filter,
|
|
913
|
+
range,
|
|
914
|
+
sort,
|
|
915
|
+
groupBy
|
|
916
|
+
}, tableSchema) {
|
|
917
|
+
this.serverViewportId = viewPortId;
|
|
918
|
+
this.status = "subscribed";
|
|
919
|
+
this.aggregations = aggregations;
|
|
920
|
+
this.columns = columns;
|
|
921
|
+
this.groupBy = groupBy;
|
|
922
|
+
this.isTree = groupBy && groupBy.length > 0;
|
|
923
|
+
this.dataWindow.setRange(range.from, range.to);
|
|
924
|
+
return {
|
|
925
|
+
aggregations,
|
|
926
|
+
type: "subscribed",
|
|
927
|
+
clientViewportId: this.clientViewportId,
|
|
928
|
+
columns,
|
|
929
|
+
filter,
|
|
930
|
+
groupBy,
|
|
931
|
+
range,
|
|
932
|
+
sort,
|
|
933
|
+
tableSchema
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
awaitOperation(requestId, msg) {
|
|
937
|
+
this.pendingOperations.set(requestId, msg);
|
|
938
|
+
}
|
|
939
|
+
// Return a message if we need to communicate this to client UI
|
|
940
|
+
completeOperation(requestId, ...params) {
|
|
941
|
+
var _a;
|
|
942
|
+
const { clientViewportId, pendingOperations } = this;
|
|
943
|
+
const pendingOperation = pendingOperations.get(requestId);
|
|
944
|
+
if (!pendingOperation) {
|
|
945
|
+
error(
|
|
946
|
+
\`no matching operation found to complete for requestId \${requestId}\`
|
|
947
|
+
);
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
const { type } = pendingOperation;
|
|
951
|
+
info == null ? void 0 : info(\`completeOperation \${type}\`);
|
|
952
|
+
pendingOperations.delete(requestId);
|
|
953
|
+
if (type === "CHANGE_VP_RANGE") {
|
|
954
|
+
const [from, to] = params;
|
|
955
|
+
(_a = this.dataWindow) == null ? void 0 : _a.setRange(from, to);
|
|
956
|
+
for (let i = this.pendingRangeRequests.length - 1; i >= 0; i--) {
|
|
957
|
+
const pendingRangeRequest = this.pendingRangeRequests[i];
|
|
958
|
+
if (pendingRangeRequest.requestId === requestId) {
|
|
959
|
+
pendingRangeRequest.acked = true;
|
|
960
|
+
break;
|
|
961
|
+
} else {
|
|
962
|
+
warn == null ? void 0 : warn("range requests sent faster than they are being ACKed");
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
} else if (type === "config") {
|
|
966
|
+
const { aggregations, columns, filter, groupBy, sort } = pendingOperation.data;
|
|
967
|
+
this.aggregations = aggregations;
|
|
968
|
+
this.columns = columns;
|
|
969
|
+
this.filter = filter;
|
|
970
|
+
this.groupBy = groupBy;
|
|
971
|
+
this.sort = sort;
|
|
972
|
+
if (groupBy.length > 0) {
|
|
973
|
+
this.isTree = true;
|
|
974
|
+
} else if (this.isTree) {
|
|
975
|
+
this.isTree = false;
|
|
976
|
+
}
|
|
977
|
+
debug2 == null ? void 0 : debug2(\`config change confirmed, isTree : \${this.isTree}\`);
|
|
978
|
+
return {
|
|
979
|
+
clientViewportId,
|
|
980
|
+
type,
|
|
981
|
+
config: pendingOperation.data
|
|
982
|
+
};
|
|
983
|
+
} else if (type === "groupBy") {
|
|
984
|
+
this.isTree = pendingOperation.data.length > 0;
|
|
985
|
+
this.groupBy = pendingOperation.data;
|
|
986
|
+
debug2 == null ? void 0 : debug2(\`groupBy change confirmed, isTree : \${this.isTree}\`);
|
|
987
|
+
return {
|
|
988
|
+
clientViewportId,
|
|
989
|
+
type,
|
|
990
|
+
groupBy: pendingOperation.data
|
|
991
|
+
};
|
|
992
|
+
} else if (type === "columns") {
|
|
993
|
+
this.columns = pendingOperation.data;
|
|
994
|
+
return {
|
|
995
|
+
clientViewportId,
|
|
996
|
+
type,
|
|
997
|
+
columns: pendingOperation.data
|
|
998
|
+
};
|
|
999
|
+
} else if (type === "filter") {
|
|
1000
|
+
this.filter = pendingOperation.data;
|
|
1001
|
+
return {
|
|
1002
|
+
clientViewportId,
|
|
1003
|
+
type,
|
|
1004
|
+
filter: pendingOperation.data
|
|
1005
|
+
};
|
|
1006
|
+
} else if (type === "aggregate") {
|
|
1007
|
+
this.aggregations = pendingOperation.data;
|
|
1008
|
+
return {
|
|
1009
|
+
clientViewportId,
|
|
1010
|
+
type: "aggregate",
|
|
1011
|
+
aggregations: this.aggregations
|
|
1012
|
+
};
|
|
1013
|
+
} else if (type === "sort") {
|
|
1014
|
+
this.sort = pendingOperation.data;
|
|
1015
|
+
return {
|
|
1016
|
+
clientViewportId,
|
|
1017
|
+
type,
|
|
1018
|
+
sort: this.sort
|
|
1019
|
+
};
|
|
1020
|
+
} else if (type === "selection") {
|
|
1021
|
+
} else if (type === "disable") {
|
|
1022
|
+
this.disabled = true;
|
|
1023
|
+
return {
|
|
1024
|
+
type: "disabled",
|
|
1025
|
+
clientViewportId
|
|
1026
|
+
};
|
|
1027
|
+
} else if (type === "enable") {
|
|
1028
|
+
this.disabled = false;
|
|
1029
|
+
return {
|
|
1030
|
+
type: "enabled",
|
|
1031
|
+
clientViewportId
|
|
1032
|
+
};
|
|
1033
|
+
} else if (type === "CREATE_VISUAL_LINK") {
|
|
1034
|
+
const [colName, parentViewportId, parentColName] = params;
|
|
1035
|
+
this.linkedParent = {
|
|
1036
|
+
colName,
|
|
1037
|
+
parentViewportId,
|
|
1038
|
+
parentColName
|
|
1039
|
+
};
|
|
1040
|
+
this.pendingLinkedParent = void 0;
|
|
1041
|
+
return {
|
|
1042
|
+
type: "vuu-link-created",
|
|
1043
|
+
clientViewportId,
|
|
1044
|
+
colName,
|
|
1045
|
+
parentViewportId,
|
|
1046
|
+
parentColName
|
|
1047
|
+
};
|
|
1048
|
+
} else if (type === "REMOVE_VISUAL_LINK") {
|
|
1049
|
+
this.linkedParent = void 0;
|
|
1050
|
+
return {
|
|
1051
|
+
type: "vuu-link-removed",
|
|
1052
|
+
clientViewportId
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
// TODO when a range request arrives, consider the viewport to be scrolling
|
|
1057
|
+
// until data arrives and we have the full range.
|
|
1058
|
+
// When not scrolling, any server data is an update
|
|
1059
|
+
// When scrolling, we are in batch mode
|
|
1060
|
+
rangeRequest(requestId, range) {
|
|
1061
|
+
if (debugEnabled2) {
|
|
1062
|
+
this.rangeMonitor.set(range);
|
|
1063
|
+
}
|
|
1064
|
+
const type = "CHANGE_VP_RANGE";
|
|
1065
|
+
if (this.dataWindow) {
|
|
1066
|
+
const [serverDataRequired, clientRows] = this.dataWindow.setClientRange(
|
|
1067
|
+
range.from,
|
|
1068
|
+
range.to
|
|
1069
|
+
);
|
|
1070
|
+
let debounceRequest;
|
|
1071
|
+
const maxRange = this.dataWindow.rowCount || void 0;
|
|
1072
|
+
const serverRequest = serverDataRequired && !this.rangeRequestAlreadyPending(range) ? {
|
|
1073
|
+
type,
|
|
1074
|
+
viewPortId: this.serverViewportId,
|
|
1075
|
+
...getFullRange(range, this.bufferSize, maxRange)
|
|
1076
|
+
} : null;
|
|
1077
|
+
if (serverRequest) {
|
|
1078
|
+
debugEnabled2 && (debug2 == null ? void 0 : debug2(
|
|
1079
|
+
\`create CHANGE_VP_RANGE: [\${serverRequest.from} - \${serverRequest.to}]\`
|
|
1080
|
+
));
|
|
1081
|
+
this.awaitOperation(requestId, { type });
|
|
1082
|
+
const pendingRequest = this.pendingRangeRequests.at(-1);
|
|
1083
|
+
if (pendingRequest) {
|
|
1084
|
+
if (pendingRequest.acked) {
|
|
1085
|
+
console.warn("Range Request before previous request is filled");
|
|
1086
|
+
} else {
|
|
1087
|
+
const { from, to } = pendingRequest;
|
|
1088
|
+
if (this.dataWindow.outOfRange(from, to)) {
|
|
1089
|
+
debounceRequest = {
|
|
1090
|
+
clientViewportId: this.clientViewportId,
|
|
1091
|
+
type: "debounce-begin"
|
|
1092
|
+
};
|
|
1093
|
+
} else {
|
|
1094
|
+
warn == null ? void 0 : warn("Range Request before previous request is acked");
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
this.pendingRangeRequests.push({ ...serverRequest, requestId });
|
|
1099
|
+
if (this.useBatchMode) {
|
|
1100
|
+
this.batchMode = true;
|
|
1101
|
+
}
|
|
1102
|
+
} else if (clientRows.length > 0) {
|
|
1103
|
+
this.batchMode = false;
|
|
1104
|
+
}
|
|
1105
|
+
this.keys.reset(this.dataWindow.clientRange);
|
|
1106
|
+
const toClient = this.isTree ? toClientRowTree : toClientRow;
|
|
1107
|
+
if (clientRows.length) {
|
|
1108
|
+
return [
|
|
1109
|
+
serverRequest,
|
|
1110
|
+
clientRows.map((row) => {
|
|
1111
|
+
return toClient(row, this.keys, this.selectedRows);
|
|
1112
|
+
})
|
|
1113
|
+
];
|
|
1114
|
+
} else if (debounceRequest) {
|
|
1115
|
+
return [serverRequest, void 0, debounceRequest];
|
|
1116
|
+
} else {
|
|
1117
|
+
return [serverRequest];
|
|
1118
|
+
}
|
|
1119
|
+
} else {
|
|
1120
|
+
return [null];
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
setLinks(links) {
|
|
1124
|
+
this.links = links;
|
|
1125
|
+
return [
|
|
1126
|
+
{
|
|
1127
|
+
type: "vuu-links",
|
|
1128
|
+
links,
|
|
1129
|
+
clientViewportId: this.clientViewportId
|
|
1130
|
+
},
|
|
1131
|
+
this.pendingLinkedParent
|
|
1132
|
+
];
|
|
1133
|
+
}
|
|
1134
|
+
setMenu(menu) {
|
|
1135
|
+
return {
|
|
1136
|
+
type: "vuu-menu",
|
|
1137
|
+
menu,
|
|
1138
|
+
clientViewportId: this.clientViewportId
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
openTreeNode(requestId, message) {
|
|
1142
|
+
if (this.useBatchMode) {
|
|
1143
|
+
this.batchMode = true;
|
|
1144
|
+
}
|
|
1145
|
+
return {
|
|
1146
|
+
type: OPEN_TREE_NODE,
|
|
1147
|
+
vpId: this.serverViewportId,
|
|
1148
|
+
treeKey: message.key
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
closeTreeNode(requestId, message) {
|
|
1152
|
+
if (this.useBatchMode) {
|
|
1153
|
+
this.batchMode = true;
|
|
1154
|
+
}
|
|
1155
|
+
return {
|
|
1156
|
+
type: CLOSE_TREE_NODE,
|
|
1157
|
+
vpId: this.serverViewportId,
|
|
1158
|
+
treeKey: message.key
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
createLink(requestId, colName, parentVpId, parentColumnName) {
|
|
1162
|
+
const message = {
|
|
1163
|
+
type: "CREATE_VISUAL_LINK",
|
|
1164
|
+
parentVpId,
|
|
1165
|
+
childVpId: this.serverViewportId,
|
|
1166
|
+
parentColumnName,
|
|
1167
|
+
childColumnName: colName
|
|
1168
|
+
};
|
|
1169
|
+
this.awaitOperation(requestId, message);
|
|
1170
|
+
if (this.useBatchMode) {
|
|
1171
|
+
this.batchMode = true;
|
|
1172
|
+
}
|
|
1173
|
+
return message;
|
|
1174
|
+
}
|
|
1175
|
+
removeLink(requestId) {
|
|
1176
|
+
const message = {
|
|
1177
|
+
type: "REMOVE_VISUAL_LINK",
|
|
1178
|
+
childVpId: this.serverViewportId
|
|
1179
|
+
};
|
|
1180
|
+
this.awaitOperation(requestId, message);
|
|
1181
|
+
return message;
|
|
1182
|
+
}
|
|
1183
|
+
suspend() {
|
|
1184
|
+
this.suspended = true;
|
|
1185
|
+
info == null ? void 0 : info("suspend");
|
|
1186
|
+
}
|
|
1187
|
+
resume() {
|
|
1188
|
+
this.suspended = false;
|
|
1189
|
+
if (debugEnabled2) {
|
|
1190
|
+
debug2 == null ? void 0 : debug2(\`resume: \${this.currentData()}\`);
|
|
1191
|
+
}
|
|
1192
|
+
return [this.size, this.currentData()];
|
|
1193
|
+
}
|
|
1194
|
+
currentData() {
|
|
1195
|
+
const out = [];
|
|
1196
|
+
if (this.dataWindow) {
|
|
1197
|
+
const records = this.dataWindow.getData();
|
|
1198
|
+
const { keys } = this;
|
|
1199
|
+
const toClient = this.isTree ? toClientRowTree : toClientRow;
|
|
1200
|
+
for (const row of records) {
|
|
1201
|
+
if (row) {
|
|
1202
|
+
out.push(toClient(row, keys, this.selectedRows));
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
return out;
|
|
1207
|
+
}
|
|
1208
|
+
enable(requestId) {
|
|
1209
|
+
this.awaitOperation(requestId, { type: "enable" });
|
|
1210
|
+
info == null ? void 0 : info(\`enable: \${this.serverViewportId}\`);
|
|
1211
|
+
return {
|
|
1212
|
+
type: ENABLE_VP,
|
|
1213
|
+
viewPortId: this.serverViewportId
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
disable(requestId) {
|
|
1217
|
+
this.awaitOperation(requestId, { type: "disable" });
|
|
1218
|
+
info == null ? void 0 : info(\`disable: \${this.serverViewportId}\`);
|
|
1219
|
+
this.suspended = false;
|
|
1220
|
+
return {
|
|
1221
|
+
type: DISABLE_VP,
|
|
1222
|
+
viewPortId: this.serverViewportId
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
columnRequest(requestId, columns) {
|
|
1226
|
+
this.awaitOperation(requestId, {
|
|
1227
|
+
type: "columns",
|
|
1228
|
+
data: columns
|
|
1229
|
+
});
|
|
1230
|
+
debug2 == null ? void 0 : debug2(\`columnRequest: \${columns}\`);
|
|
1231
|
+
return this.createRequest({ columns });
|
|
1232
|
+
}
|
|
1233
|
+
filterRequest(requestId, dataSourceFilter) {
|
|
1234
|
+
this.awaitOperation(requestId, {
|
|
1235
|
+
type: "filter",
|
|
1236
|
+
data: dataSourceFilter
|
|
1237
|
+
});
|
|
1238
|
+
if (this.useBatchMode) {
|
|
1239
|
+
this.batchMode = true;
|
|
1240
|
+
}
|
|
1241
|
+
const { filter } = dataSourceFilter;
|
|
1242
|
+
info == null ? void 0 : info(\`filterRequest: \${filter}\`);
|
|
1243
|
+
return this.createRequest({ filterSpec: { filter } });
|
|
1244
|
+
}
|
|
1245
|
+
setConfig(requestId, config) {
|
|
1246
|
+
this.awaitOperation(requestId, { type: "config", data: config });
|
|
1247
|
+
const { filter, ...remainingConfig } = config;
|
|
1248
|
+
if (this.useBatchMode) {
|
|
1249
|
+
this.batchMode = true;
|
|
1250
|
+
}
|
|
1251
|
+
debugEnabled2 ? debug2 == null ? void 0 : debug2(\`setConfig \${JSON.stringify(config)}\`) : info == null ? void 0 : info(\`setConfig\`);
|
|
1252
|
+
return this.createRequest(
|
|
1253
|
+
{
|
|
1254
|
+
...remainingConfig,
|
|
1255
|
+
filterSpec: typeof (filter == null ? void 0 : filter.filter) === "string" ? {
|
|
1256
|
+
filter: filter.filter
|
|
1257
|
+
} : {
|
|
1258
|
+
filter: ""
|
|
1259
|
+
}
|
|
1260
|
+
},
|
|
1261
|
+
true
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1264
|
+
aggregateRequest(requestId, aggregations) {
|
|
1265
|
+
this.awaitOperation(requestId, { type: "aggregate", data: aggregations });
|
|
1266
|
+
info == null ? void 0 : info(\`aggregateRequest: \${aggregations}\`);
|
|
1267
|
+
return this.createRequest({ aggregations });
|
|
1268
|
+
}
|
|
1269
|
+
sortRequest(requestId, sort) {
|
|
1270
|
+
this.awaitOperation(requestId, { type: "sort", data: sort });
|
|
1271
|
+
info == null ? void 0 : info(\`sortRequest: \${JSON.stringify(sort.sortDefs)}\`);
|
|
1272
|
+
return this.createRequest({ sort });
|
|
1273
|
+
}
|
|
1274
|
+
groupByRequest(requestId, groupBy = EMPTY_GROUPBY) {
|
|
1275
|
+
var _a;
|
|
1276
|
+
this.awaitOperation(requestId, { type: "groupBy", data: groupBy });
|
|
1277
|
+
if (this.useBatchMode) {
|
|
1278
|
+
this.batchMode = true;
|
|
1279
|
+
}
|
|
1280
|
+
if (!this.isTree) {
|
|
1281
|
+
(_a = this.dataWindow) == null ? void 0 : _a.clear();
|
|
1282
|
+
}
|
|
1283
|
+
return this.createRequest({ groupBy });
|
|
1284
|
+
}
|
|
1285
|
+
selectRequest(requestId, selected) {
|
|
1286
|
+
this.selectedRows = selected;
|
|
1287
|
+
this.awaitOperation(requestId, { type: "selection", data: selected });
|
|
1288
|
+
info == null ? void 0 : info(\`selectRequest: \${selected}\`);
|
|
1289
|
+
return {
|
|
1290
|
+
type: "SET_SELECTION",
|
|
1291
|
+
vpId: this.serverViewportId,
|
|
1292
|
+
selection: expandSelection(selected)
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
removePendingRangeRequest(firstIndex, lastIndex) {
|
|
1296
|
+
for (let i = this.pendingRangeRequests.length - 1; i >= 0; i--) {
|
|
1297
|
+
const { from, to } = this.pendingRangeRequests[i];
|
|
1298
|
+
let isLast = true;
|
|
1299
|
+
if (firstIndex >= from && firstIndex < to || lastIndex > from && lastIndex < to) {
|
|
1300
|
+
if (!isLast) {
|
|
1301
|
+
console.warn(
|
|
1302
|
+
"removePendingRangeRequest TABLE_ROWS are not for latest request"
|
|
1303
|
+
);
|
|
1304
|
+
}
|
|
1305
|
+
this.pendingRangeRequests.splice(i, 1);
|
|
1306
|
+
break;
|
|
1307
|
+
} else {
|
|
1308
|
+
isLast = false;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
updateRows(rows) {
|
|
1313
|
+
var _a, _b, _c;
|
|
1314
|
+
const [firstRow, lastRow] = getFirstAndLastRows(rows);
|
|
1315
|
+
if (firstRow && lastRow) {
|
|
1316
|
+
this.removePendingRangeRequest(firstRow.rowIndex, lastRow.rowIndex);
|
|
1317
|
+
}
|
|
1318
|
+
if (rows.length === 1) {
|
|
1319
|
+
if (firstRow.vpSize === 0 && this.disabled) {
|
|
1320
|
+
debug2 == null ? void 0 : debug2(
|
|
1321
|
+
\`ignore a SIZE=0 message on disabled viewport (\${rows.length} rows)\`
|
|
1322
|
+
);
|
|
1323
|
+
return;
|
|
1324
|
+
} else if (firstRow.updateType === "SIZE") {
|
|
1325
|
+
this.setLastSizeOnlyUpdateSize(firstRow.vpSize);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
for (const row of rows) {
|
|
1329
|
+
if (this.isTree && isLeafUpdate(row)) {
|
|
1330
|
+
continue;
|
|
1331
|
+
} else {
|
|
1332
|
+
if (row.updateType === "SIZE" || ((_a = this.dataWindow) == null ? void 0 : _a.rowCount) !== row.vpSize) {
|
|
1333
|
+
(_b = this.dataWindow) == null ? void 0 : _b.setRowCount(row.vpSize);
|
|
1334
|
+
this.rowCountChanged = true;
|
|
1335
|
+
}
|
|
1336
|
+
if (row.updateType === "U") {
|
|
1337
|
+
if ((_c = this.dataWindow) == null ? void 0 : _c.setAtIndex(row)) {
|
|
1338
|
+
this.hasUpdates = true;
|
|
1339
|
+
if (!this.batchMode) {
|
|
1340
|
+
this.pendingUpdates.push(row);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
// This is called only after new data has been received from server - data
|
|
1348
|
+
// returned direcly from buffer does not use this.
|
|
1349
|
+
getClientRows() {
|
|
1350
|
+
let out = void 0;
|
|
1351
|
+
let mode = "size-only";
|
|
1352
|
+
if (!this.hasUpdates && !this.rowCountChanged) {
|
|
1353
|
+
return NO_DATA_UPDATE;
|
|
1354
|
+
}
|
|
1355
|
+
if (this.hasUpdates) {
|
|
1356
|
+
const { keys, selectedRows } = this;
|
|
1357
|
+
const toClient = this.isTree ? toClientRowTree : toClientRow;
|
|
1358
|
+
if (this.updateThrottleTimer) {
|
|
1359
|
+
self.clearTimeout(this.updateThrottleTimer);
|
|
1360
|
+
this.updateThrottleTimer = void 0;
|
|
1361
|
+
}
|
|
1362
|
+
if (this.pendingUpdates.length > 0) {
|
|
1363
|
+
out = [];
|
|
1364
|
+
mode = "update";
|
|
1365
|
+
for (const row of this.pendingUpdates) {
|
|
1366
|
+
out.push(toClient(row, keys, selectedRows));
|
|
1367
|
+
}
|
|
1368
|
+
this.pendingUpdates.length = 0;
|
|
1369
|
+
} else {
|
|
1370
|
+
const records = this.dataWindow.getData();
|
|
1371
|
+
if (this.dataWindow.hasAllRowsWithinRange) {
|
|
1372
|
+
out = [];
|
|
1373
|
+
mode = "batch";
|
|
1374
|
+
for (const row of records) {
|
|
1375
|
+
out.push(toClient(row, keys, selectedRows));
|
|
1376
|
+
}
|
|
1377
|
+
this.batchMode = false;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
this.hasUpdates = false;
|
|
1381
|
+
}
|
|
1382
|
+
if (this.throttleMessage(mode)) {
|
|
1383
|
+
return NO_DATA_UPDATE;
|
|
1384
|
+
} else {
|
|
1385
|
+
return [out, mode];
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
createRequest(params, overWrite = false) {
|
|
1389
|
+
if (overWrite) {
|
|
1390
|
+
return {
|
|
1391
|
+
type: "CHANGE_VP",
|
|
1392
|
+
viewPortId: this.serverViewportId,
|
|
1393
|
+
...params
|
|
1394
|
+
};
|
|
1395
|
+
} else {
|
|
1396
|
+
return {
|
|
1397
|
+
type: "CHANGE_VP",
|
|
1398
|
+
viewPortId: this.serverViewportId,
|
|
1399
|
+
aggregations: this.aggregations,
|
|
1400
|
+
columns: this.columns,
|
|
1401
|
+
sort: this.sort,
|
|
1402
|
+
groupBy: this.groupBy,
|
|
1403
|
+
filterSpec: {
|
|
1404
|
+
filter: this.filter.filter
|
|
1405
|
+
},
|
|
1406
|
+
...params
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
};
|
|
1411
|
+
var toClientRow = ({ rowIndex, rowKey, sel: isSelected, data }, keys, selectedRows) => {
|
|
1412
|
+
return [
|
|
1413
|
+
rowIndex,
|
|
1414
|
+
keys.keyFor(rowIndex),
|
|
1415
|
+
true,
|
|
1416
|
+
false,
|
|
1417
|
+
0,
|
|
1418
|
+
0,
|
|
1419
|
+
rowKey,
|
|
1420
|
+
isSelected ? getSelectionStatus(selectedRows, rowIndex) : 0
|
|
1421
|
+
].concat(data);
|
|
1422
|
+
};
|
|
1423
|
+
var toClientRowTree = ({ rowIndex, rowKey, sel: isSelected, data }, keys, selectedRows) => {
|
|
1424
|
+
const [depth, isExpanded, , isLeaf, , count, ...rest] = data;
|
|
1425
|
+
return [
|
|
1426
|
+
rowIndex,
|
|
1427
|
+
keys.keyFor(rowIndex),
|
|
1428
|
+
isLeaf,
|
|
1429
|
+
isExpanded,
|
|
1430
|
+
depth,
|
|
1431
|
+
count,
|
|
1432
|
+
rowKey,
|
|
1433
|
+
isSelected ? getSelectionStatus(selectedRows, rowIndex) : 0
|
|
1434
|
+
].concat(rest);
|
|
1435
|
+
};
|
|
1436
|
+
|
|
1437
|
+
// src/server-proxy/server-proxy.ts
|
|
1438
|
+
var _requestId = 1;
|
|
1439
|
+
var { debug: debug3, debugEnabled: debugEnabled3, error: error2, info: info2, infoEnabled: infoEnabled2, warn: warn2 } = logger("server-proxy");
|
|
1440
|
+
var nextRequestId = () => \`\${_requestId++}\`;
|
|
1441
|
+
var DEFAULT_OPTIONS = {};
|
|
1442
|
+
var isActiveViewport = (viewPort) => viewPort.disabled !== true && viewPort.suspended !== true;
|
|
1443
|
+
var NO_ACTION = {
|
|
1444
|
+
type: "NO_ACTION"
|
|
1445
|
+
};
|
|
1446
|
+
var addTitleToLinks = (links, serverViewportId, label) => links.map(
|
|
1447
|
+
(link) => link.parentVpId === serverViewportId ? { ...link, label } : link
|
|
1448
|
+
);
|
|
1449
|
+
function addLabelsToLinks(links, viewports) {
|
|
1450
|
+
return links.map((linkDescriptor) => {
|
|
1451
|
+
const { parentVpId } = linkDescriptor;
|
|
1452
|
+
const viewport = viewports.get(parentVpId);
|
|
1453
|
+
if (viewport) {
|
|
1454
|
+
return {
|
|
1455
|
+
...linkDescriptor,
|
|
1456
|
+
parentClientVpId: viewport.clientViewportId,
|
|
1457
|
+
label: viewport.title
|
|
1458
|
+
};
|
|
1459
|
+
} else {
|
|
1460
|
+
throw Error("addLabelsToLinks viewport not found");
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
var ServerProxy = class {
|
|
1465
|
+
constructor(connection, callback) {
|
|
1466
|
+
this.authToken = "";
|
|
1467
|
+
this.user = "user";
|
|
1468
|
+
this.pendingRequests = /* @__PURE__ */ new Map();
|
|
1469
|
+
this.queuedRequests = [];
|
|
1470
|
+
this.cachedTableMetaRequests = /* @__PURE__ */ new Map();
|
|
1471
|
+
this.cachedTableSchemas = /* @__PURE__ */ new Map();
|
|
1472
|
+
this.connection = connection;
|
|
1473
|
+
this.postMessageToClient = callback;
|
|
1474
|
+
this.viewports = /* @__PURE__ */ new Map();
|
|
1475
|
+
this.mapClientToServerViewport = /* @__PURE__ */ new Map();
|
|
1476
|
+
}
|
|
1477
|
+
async reconnect() {
|
|
1478
|
+
await this.login(this.authToken);
|
|
1479
|
+
const [activeViewports, inactiveViewports] = partition(
|
|
1480
|
+
Array.from(this.viewports.values()),
|
|
1481
|
+
isActiveViewport
|
|
1482
|
+
);
|
|
1483
|
+
this.viewports.clear();
|
|
1484
|
+
this.mapClientToServerViewport.clear();
|
|
1485
|
+
const reconnectViewports = (viewports) => {
|
|
1486
|
+
viewports.forEach((viewport) => {
|
|
1487
|
+
const { clientViewportId } = viewport;
|
|
1488
|
+
this.viewports.set(clientViewportId, viewport);
|
|
1489
|
+
this.sendMessageToServer(viewport.subscribe(), clientViewportId);
|
|
1490
|
+
});
|
|
1491
|
+
};
|
|
1492
|
+
reconnectViewports(activeViewports);
|
|
1493
|
+
setTimeout(() => {
|
|
1494
|
+
reconnectViewports(inactiveViewports);
|
|
1495
|
+
}, 2e3);
|
|
1496
|
+
}
|
|
1497
|
+
async login(authToken, user = "user") {
|
|
1498
|
+
if (authToken) {
|
|
1499
|
+
this.authToken = authToken;
|
|
1500
|
+
this.user = user;
|
|
1501
|
+
return new Promise((resolve, reject) => {
|
|
1502
|
+
this.sendMessageToServer(
|
|
1503
|
+
{ type: LOGIN, token: this.authToken, user },
|
|
1504
|
+
""
|
|
1505
|
+
);
|
|
1506
|
+
this.pendingLogin = { resolve, reject };
|
|
1507
|
+
});
|
|
1508
|
+
} else if (this.authToken === "") {
|
|
1509
|
+
error2("login, cannot login until auth token has been obtained");
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
subscribe(message) {
|
|
1513
|
+
if (!this.mapClientToServerViewport.has(message.viewport)) {
|
|
1514
|
+
const pendingTableSchema = this.getTableMeta(message.table);
|
|
1515
|
+
const viewport = new Viewport(message, this.postMessageToClient);
|
|
1516
|
+
this.viewports.set(message.viewport, viewport);
|
|
1517
|
+
const pendingSubscription = this.awaitResponseToMessage(
|
|
1518
|
+
viewport.subscribe(),
|
|
1519
|
+
message.viewport
|
|
1520
|
+
);
|
|
1521
|
+
const awaitPendingReponses = Promise.all([
|
|
1522
|
+
pendingSubscription,
|
|
1523
|
+
pendingTableSchema
|
|
1524
|
+
]);
|
|
1525
|
+
awaitPendingReponses.then(([subscribeResponse, tableSchema]) => {
|
|
1526
|
+
const { viewPortId: serverViewportId } = subscribeResponse;
|
|
1527
|
+
const { status: previousViewportStatus } = viewport;
|
|
1528
|
+
if (message.viewport !== serverViewportId) {
|
|
1529
|
+
this.viewports.delete(message.viewport);
|
|
1530
|
+
this.viewports.set(serverViewportId, viewport);
|
|
1531
|
+
}
|
|
1532
|
+
this.mapClientToServerViewport.set(message.viewport, serverViewportId);
|
|
1533
|
+
const clientResponse = viewport.handleSubscribed(
|
|
1534
|
+
subscribeResponse,
|
|
1535
|
+
tableSchema
|
|
1536
|
+
);
|
|
1537
|
+
if (clientResponse) {
|
|
1538
|
+
this.postMessageToClient(clientResponse);
|
|
1539
|
+
if (debugEnabled3) {
|
|
1540
|
+
debug3(
|
|
1541
|
+
\`post DataSourceSubscribedMessage to client: \${JSON.stringify(
|
|
1542
|
+
clientResponse
|
|
1543
|
+
)}\`
|
|
1544
|
+
);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
if (viewport.disabled) {
|
|
1548
|
+
this.disableViewport(viewport);
|
|
1549
|
+
}
|
|
1550
|
+
if (this.queuedRequests.length > 0) {
|
|
1551
|
+
this.processQueuedRequests();
|
|
1552
|
+
}
|
|
1553
|
+
if (previousViewportStatus === "subscribing" && // A session table will never have Visual Links, nor Context Menus
|
|
1554
|
+
!isSessionTable(viewport.table)) {
|
|
1555
|
+
this.sendMessageToServer({
|
|
1556
|
+
type: GET_VP_VISUAL_LINKS,
|
|
1557
|
+
vpId: serverViewportId
|
|
1558
|
+
});
|
|
1559
|
+
this.sendMessageToServer({
|
|
1560
|
+
type: GET_VIEW_PORT_MENUS,
|
|
1561
|
+
vpId: serverViewportId
|
|
1562
|
+
});
|
|
1563
|
+
Array.from(this.viewports.entries()).filter(
|
|
1564
|
+
([id, { disabled }]) => id !== serverViewportId && !disabled
|
|
1565
|
+
).forEach(([vpId]) => {
|
|
1566
|
+
this.sendMessageToServer({
|
|
1567
|
+
type: GET_VP_VISUAL_LINKS,
|
|
1568
|
+
vpId
|
|
1569
|
+
});
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
});
|
|
1573
|
+
} else {
|
|
1574
|
+
error2(\`spurious subscribe call \${message.viewport}\`);
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
processQueuedRequests() {
|
|
1578
|
+
const messageTypesProcessed = {};
|
|
1579
|
+
while (this.queuedRequests.length) {
|
|
1580
|
+
const queuedRequest = this.queuedRequests.pop();
|
|
1581
|
+
if (queuedRequest) {
|
|
1582
|
+
const { clientViewportId, message, requestId } = queuedRequest;
|
|
1583
|
+
if (message.type === "CHANGE_VP_RANGE") {
|
|
1584
|
+
if (messageTypesProcessed.CHANGE_VP_RANGE) {
|
|
1585
|
+
continue;
|
|
1586
|
+
}
|
|
1587
|
+
messageTypesProcessed.CHANGE_VP_RANGE = true;
|
|
1588
|
+
const serverViewportId = this.mapClientToServerViewport.get(clientViewportId);
|
|
1589
|
+
if (serverViewportId) {
|
|
1590
|
+
this.sendMessageToServer(
|
|
1591
|
+
{
|
|
1592
|
+
...message,
|
|
1593
|
+
viewPortId: serverViewportId
|
|
1594
|
+
},
|
|
1595
|
+
requestId
|
|
1596
|
+
);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
unsubscribe(clientViewportId) {
|
|
1603
|
+
const serverViewportId = this.mapClientToServerViewport.get(clientViewportId);
|
|
1604
|
+
if (serverViewportId) {
|
|
1605
|
+
info2 == null ? void 0 : info2(
|
|
1606
|
+
\`Unsubscribe Message (Client to Server):
|
|
1607
|
+
\${serverViewportId}\`
|
|
1608
|
+
);
|
|
1609
|
+
this.sendMessageToServer({
|
|
1610
|
+
type: REMOVE_VP,
|
|
1611
|
+
viewPortId: serverViewportId
|
|
1612
|
+
});
|
|
1613
|
+
} else {
|
|
1614
|
+
error2(
|
|
1615
|
+
\`failed to unsubscribe client viewport \${clientViewportId}, viewport not found\`
|
|
1616
|
+
);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
getViewportForClient(clientViewportId, throws = true) {
|
|
1620
|
+
const serverViewportId = this.mapClientToServerViewport.get(clientViewportId);
|
|
1621
|
+
if (serverViewportId) {
|
|
1622
|
+
const viewport = this.viewports.get(serverViewportId);
|
|
1623
|
+
if (viewport) {
|
|
1624
|
+
return viewport;
|
|
1625
|
+
} else if (throws) {
|
|
1626
|
+
throw Error(
|
|
1627
|
+
\`Viewport not found for client viewport \${clientViewportId}\`
|
|
1628
|
+
);
|
|
1629
|
+
} else {
|
|
1630
|
+
return null;
|
|
1631
|
+
}
|
|
1632
|
+
} else if (this.viewports.has(clientViewportId)) {
|
|
1633
|
+
return this.viewports.get(clientViewportId);
|
|
1634
|
+
} else if (throws) {
|
|
1635
|
+
throw Error(
|
|
1636
|
+
\`Viewport server id not found for client viewport \${clientViewportId}\`
|
|
1637
|
+
);
|
|
1638
|
+
} else {
|
|
1639
|
+
return null;
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
/**********************************************************************/
|
|
1643
|
+
/* Handle messages from client */
|
|
1644
|
+
/**********************************************************************/
|
|
1645
|
+
setViewRange(viewport, message) {
|
|
1646
|
+
const requestId = nextRequestId();
|
|
1647
|
+
const [serverRequest, rows, debounceRequest] = viewport.rangeRequest(
|
|
1648
|
+
requestId,
|
|
1649
|
+
message.range
|
|
1650
|
+
);
|
|
1651
|
+
info2 == null ? void 0 : info2(\`setViewRange \${message.range.from} - \${message.range.to}\`);
|
|
1652
|
+
if (serverRequest) {
|
|
1653
|
+
if (true) {
|
|
1654
|
+
info2 == null ? void 0 : info2(
|
|
1655
|
+
\`CHANGE_VP_RANGE [\${message.range.from}-\${message.range.to}] => [\${serverRequest.from}-\${serverRequest.to}]\`
|
|
1656
|
+
);
|
|
1657
|
+
}
|
|
1658
|
+
const sentToServer = this.sendIfReady(
|
|
1659
|
+
serverRequest,
|
|
1660
|
+
requestId,
|
|
1661
|
+
viewport.status === "subscribed"
|
|
1662
|
+
);
|
|
1663
|
+
if (!sentToServer) {
|
|
1664
|
+
this.queuedRequests.push({
|
|
1665
|
+
clientViewportId: message.viewport,
|
|
1666
|
+
message: serverRequest,
|
|
1667
|
+
requestId
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
if (rows) {
|
|
1672
|
+
info2 == null ? void 0 : info2(\`setViewRange \${rows.length} rows returned from cache\`);
|
|
1673
|
+
this.postMessageToClient({
|
|
1674
|
+
mode: "batch",
|
|
1675
|
+
type: "viewport-update",
|
|
1676
|
+
clientViewportId: viewport.clientViewportId,
|
|
1677
|
+
rows
|
|
1678
|
+
});
|
|
1679
|
+
} else if (debounceRequest) {
|
|
1680
|
+
this.postMessageToClient(debounceRequest);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
setConfig(viewport, message) {
|
|
1684
|
+
const requestId = nextRequestId();
|
|
1685
|
+
const request = viewport.setConfig(requestId, message.config);
|
|
1686
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1687
|
+
}
|
|
1688
|
+
aggregate(viewport, message) {
|
|
1689
|
+
const requestId = nextRequestId();
|
|
1690
|
+
const request = viewport.aggregateRequest(requestId, message.aggregations);
|
|
1691
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1692
|
+
}
|
|
1693
|
+
sort(viewport, message) {
|
|
1694
|
+
const requestId = nextRequestId();
|
|
1695
|
+
const request = viewport.sortRequest(requestId, message.sort);
|
|
1696
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1697
|
+
}
|
|
1698
|
+
groupBy(viewport, message) {
|
|
1699
|
+
const requestId = nextRequestId();
|
|
1700
|
+
const request = viewport.groupByRequest(requestId, message.groupBy);
|
|
1701
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1702
|
+
}
|
|
1703
|
+
filter(viewport, message) {
|
|
1704
|
+
const requestId = nextRequestId();
|
|
1705
|
+
const { filter } = message;
|
|
1706
|
+
const request = viewport.filterRequest(requestId, filter);
|
|
1707
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1708
|
+
}
|
|
1709
|
+
setColumns(viewport, message) {
|
|
1710
|
+
const requestId = nextRequestId();
|
|
1711
|
+
const { columns } = message;
|
|
1712
|
+
const request = viewport.columnRequest(requestId, columns);
|
|
1713
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1714
|
+
}
|
|
1715
|
+
setTitle(viewport, message) {
|
|
1716
|
+
if (viewport) {
|
|
1717
|
+
viewport.title = message.title;
|
|
1718
|
+
this.updateTitleOnVisualLinks(viewport);
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
select(viewport, message) {
|
|
1722
|
+
const requestId = nextRequestId();
|
|
1723
|
+
const { selected } = message;
|
|
1724
|
+
const request = viewport.selectRequest(requestId, selected);
|
|
1725
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1726
|
+
}
|
|
1727
|
+
disableViewport(viewport) {
|
|
1728
|
+
const requestId = nextRequestId();
|
|
1729
|
+
const request = viewport.disable(requestId);
|
|
1730
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1731
|
+
}
|
|
1732
|
+
enableViewport(viewport) {
|
|
1733
|
+
if (viewport.disabled) {
|
|
1734
|
+
const requestId = nextRequestId();
|
|
1735
|
+
const request = viewport.enable(requestId);
|
|
1736
|
+
this.sendIfReady(request, requestId, viewport.status === "subscribed");
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
suspendViewport(viewport) {
|
|
1740
|
+
viewport.suspend();
|
|
1741
|
+
viewport.suspendTimer = setTimeout(() => {
|
|
1742
|
+
info2 == null ? void 0 : info2("suspendTimer expired, escalate suspend to disable");
|
|
1743
|
+
this.disableViewport(viewport);
|
|
1744
|
+
}, 3e3);
|
|
1745
|
+
}
|
|
1746
|
+
resumeViewport(viewport) {
|
|
1747
|
+
if (viewport.suspendTimer) {
|
|
1748
|
+
debug3 == null ? void 0 : debug3("clear suspend timer");
|
|
1749
|
+
clearTimeout(viewport.suspendTimer);
|
|
1750
|
+
viewport.suspendTimer = null;
|
|
1751
|
+
}
|
|
1752
|
+
const [size, rows] = viewport.resume();
|
|
1753
|
+
debug3 == null ? void 0 : debug3(\`resumeViewport size \${size}, \${rows.length} rows sent to client\`);
|
|
1754
|
+
this.postMessageToClient({
|
|
1755
|
+
clientViewportId: viewport.clientViewportId,
|
|
1756
|
+
mode: "batch",
|
|
1757
|
+
rows,
|
|
1758
|
+
size,
|
|
1759
|
+
type: "viewport-update"
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
openTreeNode(viewport, message) {
|
|
1763
|
+
if (viewport.serverViewportId) {
|
|
1764
|
+
const requestId = nextRequestId();
|
|
1765
|
+
this.sendIfReady(
|
|
1766
|
+
viewport.openTreeNode(requestId, message),
|
|
1767
|
+
requestId,
|
|
1768
|
+
viewport.status === "subscribed"
|
|
1769
|
+
);
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
closeTreeNode(viewport, message) {
|
|
1773
|
+
if (viewport.serverViewportId) {
|
|
1774
|
+
const requestId = nextRequestId();
|
|
1775
|
+
this.sendIfReady(
|
|
1776
|
+
viewport.closeTreeNode(requestId, message),
|
|
1777
|
+
requestId,
|
|
1778
|
+
viewport.status === "subscribed"
|
|
1779
|
+
);
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
createLink(viewport, message) {
|
|
1783
|
+
const { parentClientVpId, parentColumnName, childColumnName } = message;
|
|
1784
|
+
const requestId = nextRequestId();
|
|
1785
|
+
const parentVpId = this.mapClientToServerViewport.get(parentClientVpId);
|
|
1786
|
+
if (parentVpId) {
|
|
1787
|
+
const request = viewport.createLink(
|
|
1788
|
+
requestId,
|
|
1789
|
+
childColumnName,
|
|
1790
|
+
parentVpId,
|
|
1791
|
+
parentColumnName
|
|
1792
|
+
);
|
|
1793
|
+
this.sendMessageToServer(request, requestId);
|
|
1794
|
+
} else {
|
|
1795
|
+
error2("ServerProxy unable to create link, viewport not found");
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
removeLink(viewport) {
|
|
1799
|
+
const requestId = nextRequestId();
|
|
1800
|
+
const request = viewport.removeLink(requestId);
|
|
1801
|
+
this.sendMessageToServer(request, requestId);
|
|
1802
|
+
}
|
|
1803
|
+
updateTitleOnVisualLinks(viewport) {
|
|
1804
|
+
var _a;
|
|
1805
|
+
const { serverViewportId, title } = viewport;
|
|
1806
|
+
for (const vp of this.viewports.values()) {
|
|
1807
|
+
if (vp !== viewport && vp.links && serverViewportId && title) {
|
|
1808
|
+
if ((_a = vp.links) == null ? void 0 : _a.some((link) => link.parentVpId === serverViewportId)) {
|
|
1809
|
+
const [messageToClient] = vp.setLinks(
|
|
1810
|
+
addTitleToLinks(vp.links, serverViewportId, title)
|
|
1811
|
+
);
|
|
1812
|
+
this.postMessageToClient(messageToClient);
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
removeViewportFromVisualLinks(serverViewportId) {
|
|
1818
|
+
var _a;
|
|
1819
|
+
for (const vp of this.viewports.values()) {
|
|
1820
|
+
if ((_a = vp.links) == null ? void 0 : _a.some(({ parentVpId }) => parentVpId === serverViewportId)) {
|
|
1821
|
+
const [messageToClient] = vp.setLinks(
|
|
1822
|
+
vp.links.filter(({ parentVpId }) => parentVpId !== serverViewportId)
|
|
1823
|
+
);
|
|
1824
|
+
this.postMessageToClient(messageToClient);
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
menuRpcCall(message) {
|
|
1829
|
+
const viewport = this.getViewportForClient(message.vpId, false);
|
|
1830
|
+
if (viewport == null ? void 0 : viewport.serverViewportId) {
|
|
1831
|
+
const [requestId, rpcRequest] = stripRequestId(message);
|
|
1832
|
+
this.sendMessageToServer(
|
|
1833
|
+
{
|
|
1834
|
+
...rpcRequest,
|
|
1835
|
+
vpId: viewport.serverViewportId
|
|
1836
|
+
},
|
|
1837
|
+
requestId
|
|
1838
|
+
);
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
viewportRpcCall(message) {
|
|
1842
|
+
const viewport = this.getViewportForClient(message.vpId, false);
|
|
1843
|
+
if (viewport == null ? void 0 : viewport.serverViewportId) {
|
|
1844
|
+
const [requestId, rpcRequest] = stripRequestId(message);
|
|
1845
|
+
this.sendMessageToServer(
|
|
1846
|
+
{
|
|
1847
|
+
...rpcRequest,
|
|
1848
|
+
vpId: viewport.serverViewportId,
|
|
1849
|
+
namedParams: {}
|
|
1850
|
+
},
|
|
1851
|
+
requestId
|
|
1852
|
+
);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
rpcCall(message) {
|
|
1856
|
+
const [requestId, rpcRequest] = stripRequestId(message);
|
|
1857
|
+
const module = getRpcServiceModule(rpcRequest.service);
|
|
1858
|
+
this.sendMessageToServer(rpcRequest, requestId, { module });
|
|
1859
|
+
}
|
|
1860
|
+
handleMessageFromClient(message) {
|
|
1861
|
+
var _a;
|
|
1862
|
+
if (isViewporttMessage(message)) {
|
|
1863
|
+
if (message.type === "disable") {
|
|
1864
|
+
const viewport = this.getViewportForClient(message.viewport, false);
|
|
1865
|
+
if (viewport !== null) {
|
|
1866
|
+
return this.disableViewport(viewport);
|
|
1867
|
+
} else {
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
} else {
|
|
1871
|
+
const viewport = this.getViewportForClient(message.viewport);
|
|
1872
|
+
switch (message.type) {
|
|
1873
|
+
case "setViewRange":
|
|
1874
|
+
return this.setViewRange(viewport, message);
|
|
1875
|
+
case "config":
|
|
1876
|
+
return this.setConfig(viewport, message);
|
|
1877
|
+
case "aggregate":
|
|
1878
|
+
return this.aggregate(viewport, message);
|
|
1879
|
+
case "sort":
|
|
1880
|
+
return this.sort(viewport, message);
|
|
1881
|
+
case "groupBy":
|
|
1882
|
+
return this.groupBy(viewport, message);
|
|
1883
|
+
case "filter":
|
|
1884
|
+
return this.filter(viewport, message);
|
|
1885
|
+
case "select":
|
|
1886
|
+
return this.select(viewport, message);
|
|
1887
|
+
case "suspend":
|
|
1888
|
+
return this.suspendViewport(viewport);
|
|
1889
|
+
case "resume":
|
|
1890
|
+
return this.resumeViewport(viewport);
|
|
1891
|
+
case "enable":
|
|
1892
|
+
return this.enableViewport(viewport);
|
|
1893
|
+
case "openTreeNode":
|
|
1894
|
+
return this.openTreeNode(viewport, message);
|
|
1895
|
+
case "closeTreeNode":
|
|
1896
|
+
return this.closeTreeNode(viewport, message);
|
|
1897
|
+
case "createLink":
|
|
1898
|
+
return this.createLink(viewport, message);
|
|
1899
|
+
case "removeLink":
|
|
1900
|
+
return this.removeLink(viewport);
|
|
1901
|
+
case "setColumns":
|
|
1902
|
+
return this.setColumns(viewport, message);
|
|
1903
|
+
case "setTitle":
|
|
1904
|
+
return this.setTitle(viewport, message);
|
|
1905
|
+
default:
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
} else if (isVuuRpcRequest(message)) {
|
|
1909
|
+
return this.viewportRpcCall(
|
|
1910
|
+
message
|
|
1911
|
+
);
|
|
1912
|
+
} else if (isVuuMenuRpcRequest(message)) {
|
|
1913
|
+
return this.menuRpcCall(message);
|
|
1914
|
+
} else {
|
|
1915
|
+
const { type, requestId } = message;
|
|
1916
|
+
switch (type) {
|
|
1917
|
+
case "GET_TABLE_LIST": {
|
|
1918
|
+
(_a = this.tableList) != null ? _a : this.tableList = this.awaitResponseToMessage(
|
|
1919
|
+
{ type },
|
|
1920
|
+
requestId
|
|
1921
|
+
);
|
|
1922
|
+
this.tableList.then((response) => {
|
|
1923
|
+
this.postMessageToClient({
|
|
1924
|
+
type: "TABLE_LIST_RESP",
|
|
1925
|
+
tables: response.tables,
|
|
1926
|
+
requestId
|
|
1927
|
+
});
|
|
1928
|
+
});
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
case "GET_TABLE_META": {
|
|
1932
|
+
this.getTableMeta(message.table, requestId).then((tableSchema) => {
|
|
1933
|
+
if (tableSchema) {
|
|
1934
|
+
this.postMessageToClient({
|
|
1935
|
+
type: "TABLE_META_RESP",
|
|
1936
|
+
tableSchema,
|
|
1937
|
+
requestId
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
});
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
case "RPC_CALL":
|
|
1944
|
+
return this.rpcCall(message);
|
|
1945
|
+
default:
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
error2(
|
|
1949
|
+
\`Vuu ServerProxy Unexpected message from client \${JSON.stringify(
|
|
1950
|
+
message
|
|
1951
|
+
)}\`
|
|
1952
|
+
);
|
|
1953
|
+
}
|
|
1954
|
+
getTableMeta(table, requestId = nextRequestId()) {
|
|
1955
|
+
if (isSessionTable(table)) {
|
|
1956
|
+
return Promise.resolve(void 0);
|
|
1957
|
+
}
|
|
1958
|
+
const key = \`\${table.module}:\${table.table}\`;
|
|
1959
|
+
let tableMetaRequest = this.cachedTableMetaRequests.get(key);
|
|
1960
|
+
if (!tableMetaRequest) {
|
|
1961
|
+
tableMetaRequest = this.awaitResponseToMessage(
|
|
1962
|
+
{ type: "GET_TABLE_META", table },
|
|
1963
|
+
requestId
|
|
1964
|
+
);
|
|
1965
|
+
this.cachedTableMetaRequests.set(key, tableMetaRequest);
|
|
1966
|
+
}
|
|
1967
|
+
return tableMetaRequest == null ? void 0 : tableMetaRequest.then((response) => this.cacheTableMeta(response));
|
|
1968
|
+
}
|
|
1969
|
+
awaitResponseToMessage(message, requestId = nextRequestId()) {
|
|
1970
|
+
return new Promise((resolve, reject) => {
|
|
1971
|
+
this.sendMessageToServer(message, requestId);
|
|
1972
|
+
this.pendingRequests.set(requestId, { reject, resolve });
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
sendIfReady(message, requestId, isReady = true) {
|
|
1976
|
+
if (isReady) {
|
|
1977
|
+
this.sendMessageToServer(message, requestId);
|
|
1978
|
+
}
|
|
1979
|
+
return isReady;
|
|
1980
|
+
}
|
|
1981
|
+
sendMessageToServer(body, requestId = \`\${_requestId++}\`, options = DEFAULT_OPTIONS) {
|
|
1982
|
+
const { module = "CORE" } = options;
|
|
1983
|
+
if (this.authToken) {
|
|
1984
|
+
this.connection.send({
|
|
1985
|
+
requestId,
|
|
1986
|
+
sessionId: this.sessionId,
|
|
1987
|
+
token: this.authToken,
|
|
1988
|
+
user: this.user,
|
|
1989
|
+
module,
|
|
1990
|
+
body
|
|
1991
|
+
});
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
handleMessageFromServer(message) {
|
|
1995
|
+
var _a, _b, _c;
|
|
1996
|
+
const { body, requestId, sessionId } = message;
|
|
1997
|
+
const pendingRequest = this.pendingRequests.get(requestId);
|
|
1998
|
+
if (pendingRequest) {
|
|
1999
|
+
const { resolve } = pendingRequest;
|
|
2000
|
+
this.pendingRequests.delete(requestId);
|
|
2001
|
+
resolve(body);
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
2004
|
+
const { viewports } = this;
|
|
2005
|
+
switch (body.type) {
|
|
2006
|
+
case HB:
|
|
2007
|
+
this.sendMessageToServer(
|
|
2008
|
+
{ type: HB_RESP, ts: +/* @__PURE__ */ new Date() },
|
|
2009
|
+
"NA"
|
|
2010
|
+
);
|
|
2011
|
+
break;
|
|
2012
|
+
case "LOGIN_SUCCESS":
|
|
2013
|
+
if (sessionId) {
|
|
2014
|
+
this.sessionId = sessionId;
|
|
2015
|
+
(_a = this.pendingLogin) == null ? void 0 : _a.resolve(sessionId);
|
|
2016
|
+
this.pendingLogin = void 0;
|
|
2017
|
+
} else {
|
|
2018
|
+
throw Error("LOGIN_SUCCESS did not provide sessionId");
|
|
2019
|
+
}
|
|
2020
|
+
break;
|
|
2021
|
+
case "REMOVE_VP_SUCCESS":
|
|
2022
|
+
{
|
|
2023
|
+
const viewport = viewports.get(body.viewPortId);
|
|
2024
|
+
if (viewport) {
|
|
2025
|
+
this.mapClientToServerViewport.delete(viewport.clientViewportId);
|
|
2026
|
+
viewports.delete(body.viewPortId);
|
|
2027
|
+
this.removeViewportFromVisualLinks(body.viewPortId);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
break;
|
|
2031
|
+
case SET_SELECTION_SUCCESS:
|
|
2032
|
+
{
|
|
2033
|
+
const viewport = this.viewports.get(body.vpId);
|
|
2034
|
+
if (viewport) {
|
|
2035
|
+
viewport.completeOperation(requestId);
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
break;
|
|
2039
|
+
case CHANGE_VP_SUCCESS:
|
|
2040
|
+
case DISABLE_VP_SUCCESS:
|
|
2041
|
+
if (viewports.has(body.viewPortId)) {
|
|
2042
|
+
const viewport = this.viewports.get(body.viewPortId);
|
|
2043
|
+
if (viewport) {
|
|
2044
|
+
const response = viewport.completeOperation(requestId);
|
|
2045
|
+
if (response !== void 0) {
|
|
2046
|
+
this.postMessageToClient(response);
|
|
2047
|
+
if (debugEnabled3) {
|
|
2048
|
+
debug3(\`postMessageToClient \${JSON.stringify(response)}\`);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
break;
|
|
2054
|
+
case ENABLE_VP_SUCCESS:
|
|
2055
|
+
{
|
|
2056
|
+
const viewport = this.viewports.get(body.viewPortId);
|
|
2057
|
+
if (viewport) {
|
|
2058
|
+
const response = viewport.completeOperation(requestId);
|
|
2059
|
+
if (response) {
|
|
2060
|
+
this.postMessageToClient(response);
|
|
2061
|
+
const [size, rows] = viewport.resume();
|
|
2062
|
+
this.postMessageToClient({
|
|
2063
|
+
clientViewportId: viewport.clientViewportId,
|
|
2064
|
+
mode: "batch",
|
|
2065
|
+
rows,
|
|
2066
|
+
size,
|
|
2067
|
+
type: "viewport-update"
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
break;
|
|
2073
|
+
case "TABLE_ROW":
|
|
2074
|
+
{
|
|
2075
|
+
const viewportRowMap = groupRowsByViewport(body.rows);
|
|
2076
|
+
if (debugEnabled3) {
|
|
2077
|
+
const [firstRow, secondRow] = body.rows;
|
|
2078
|
+
if (body.rows.length === 0) {
|
|
2079
|
+
debug3("handleMessageFromServer TABLE_ROW 0 rows");
|
|
2080
|
+
} else if ((firstRow == null ? void 0 : firstRow.rowIndex) === -1) {
|
|
2081
|
+
if (body.rows.length === 1) {
|
|
2082
|
+
if (firstRow.updateType === "SIZE") {
|
|
2083
|
+
debug3(
|
|
2084
|
+
\`handleMessageFromServer [\${firstRow.viewPortId}] TABLE_ROW SIZE ONLY \${firstRow.vpSize}\`
|
|
2085
|
+
);
|
|
2086
|
+
} else {
|
|
2087
|
+
debug3(
|
|
2088
|
+
\`handleMessageFromServer [\${firstRow.viewPortId}] TABLE_ROW SIZE \${firstRow.vpSize} rowIdx \${firstRow.rowIndex}\`
|
|
2089
|
+
);
|
|
2090
|
+
}
|
|
2091
|
+
} else {
|
|
2092
|
+
debug3(
|
|
2093
|
+
\`handleMessageFromServer TABLE_ROW \${body.rows.length} rows, SIZE \${firstRow.vpSize}, [\${secondRow == null ? void 0 : secondRow.rowIndex}] - [\${(_b = body.rows[body.rows.length - 1]) == null ? void 0 : _b.rowIndex}]\`
|
|
2094
|
+
);
|
|
2095
|
+
}
|
|
2096
|
+
} else {
|
|
2097
|
+
debug3(
|
|
2098
|
+
\`handleMessageFromServer TABLE_ROW \${body.rows.length} rows [\${firstRow == null ? void 0 : firstRow.rowIndex}] - [\${(_c = body.rows[body.rows.length - 1]) == null ? void 0 : _c.rowIndex}]\`
|
|
2099
|
+
);
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
for (const [viewportId, rows] of Object.entries(viewportRowMap)) {
|
|
2103
|
+
const viewport = viewports.get(viewportId);
|
|
2104
|
+
if (viewport) {
|
|
2105
|
+
viewport.updateRows(rows);
|
|
2106
|
+
} else {
|
|
2107
|
+
warn2 == null ? void 0 : warn2(
|
|
2108
|
+
\`TABLE_ROW message received for non registered viewport \${viewportId}\`
|
|
2109
|
+
);
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
this.processUpdates();
|
|
2113
|
+
}
|
|
2114
|
+
break;
|
|
2115
|
+
case "CHANGE_VP_RANGE_SUCCESS":
|
|
2116
|
+
{
|
|
2117
|
+
const viewport = this.viewports.get(body.viewPortId);
|
|
2118
|
+
if (viewport) {
|
|
2119
|
+
const { from, to } = body;
|
|
2120
|
+
if (true) {
|
|
2121
|
+
info2 == null ? void 0 : info2(\`CHANGE_VP_RANGE_SUCCESS \${from} - \${to}\`);
|
|
2122
|
+
}
|
|
2123
|
+
viewport.completeOperation(requestId, from, to);
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
break;
|
|
2127
|
+
case OPEN_TREE_SUCCESS:
|
|
2128
|
+
case CLOSE_TREE_SUCCESS:
|
|
2129
|
+
break;
|
|
2130
|
+
case "CREATE_VISUAL_LINK_SUCCESS":
|
|
2131
|
+
{
|
|
2132
|
+
const viewport = this.viewports.get(body.childVpId);
|
|
2133
|
+
const parentViewport = this.viewports.get(body.parentVpId);
|
|
2134
|
+
if (viewport && parentViewport) {
|
|
2135
|
+
const { childColumnName, parentColumnName } = body;
|
|
2136
|
+
const response = viewport.completeOperation(
|
|
2137
|
+
requestId,
|
|
2138
|
+
childColumnName,
|
|
2139
|
+
parentViewport.clientViewportId,
|
|
2140
|
+
parentColumnName
|
|
2141
|
+
);
|
|
2142
|
+
if (response) {
|
|
2143
|
+
this.postMessageToClient(response);
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
break;
|
|
2148
|
+
case "REMOVE_VISUAL_LINK_SUCCESS":
|
|
2149
|
+
{
|
|
2150
|
+
const viewport = this.viewports.get(body.childVpId);
|
|
2151
|
+
if (viewport) {
|
|
2152
|
+
const response = viewport.completeOperation(
|
|
2153
|
+
requestId
|
|
2154
|
+
);
|
|
2155
|
+
if (response) {
|
|
2156
|
+
this.postMessageToClient(response);
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
break;
|
|
2161
|
+
case "VP_VISUAL_LINKS_RESP":
|
|
2162
|
+
{
|
|
2163
|
+
const activeLinkDescriptors = this.getActiveLinks(body.links);
|
|
2164
|
+
const viewport = this.viewports.get(body.vpId);
|
|
2165
|
+
if (activeLinkDescriptors.length && viewport) {
|
|
2166
|
+
const linkDescriptorsWithLabels = addLabelsToLinks(
|
|
2167
|
+
activeLinkDescriptors,
|
|
2168
|
+
this.viewports
|
|
2169
|
+
);
|
|
2170
|
+
const [clientMessage, pendingLink] = viewport.setLinks(
|
|
2171
|
+
linkDescriptorsWithLabels
|
|
2172
|
+
);
|
|
2173
|
+
this.postMessageToClient(clientMessage);
|
|
2174
|
+
if (pendingLink) {
|
|
2175
|
+
const { link, parentClientVpId } = pendingLink;
|
|
2176
|
+
const requestId2 = nextRequestId();
|
|
2177
|
+
const serverViewportId = this.mapClientToServerViewport.get(parentClientVpId);
|
|
2178
|
+
if (serverViewportId) {
|
|
2179
|
+
const message2 = viewport.createLink(
|
|
2180
|
+
requestId2,
|
|
2181
|
+
link.fromColumn,
|
|
2182
|
+
serverViewportId,
|
|
2183
|
+
link.toColumn
|
|
2184
|
+
);
|
|
2185
|
+
this.sendMessageToServer(message2, requestId2);
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
break;
|
|
2191
|
+
case "VIEW_PORT_MENUS_RESP":
|
|
2192
|
+
if (body.menu.name) {
|
|
2193
|
+
const viewport = this.viewports.get(body.vpId);
|
|
2194
|
+
if (viewport) {
|
|
2195
|
+
const clientMessage = viewport.setMenu(body.menu);
|
|
2196
|
+
this.postMessageToClient(clientMessage);
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
break;
|
|
2200
|
+
case "VP_EDIT_RPC_RESPONSE":
|
|
2201
|
+
{
|
|
2202
|
+
this.postMessageToClient({
|
|
2203
|
+
action: body.action,
|
|
2204
|
+
requestId,
|
|
2205
|
+
rpcName: body.rpcName,
|
|
2206
|
+
type: "VP_EDIT_RPC_RESPONSE"
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
break;
|
|
2210
|
+
case "VP_EDIT_RPC_REJECT":
|
|
2211
|
+
{
|
|
2212
|
+
const viewport = this.viewports.get(body.vpId);
|
|
2213
|
+
if (viewport) {
|
|
2214
|
+
this.postMessageToClient({
|
|
2215
|
+
requestId,
|
|
2216
|
+
type: "VP_EDIT_RPC_REJECT",
|
|
2217
|
+
error: body.error
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
break;
|
|
2222
|
+
case "VIEW_PORT_MENU_REJ": {
|
|
2223
|
+
console.log(\`send menu error back to client\`);
|
|
2224
|
+
const { error: error4, rpcName, vpId } = body;
|
|
2225
|
+
const viewport = this.viewports.get(vpId);
|
|
2226
|
+
if (viewport) {
|
|
2227
|
+
this.postMessageToClient({
|
|
2228
|
+
clientViewportId: viewport.clientViewportId,
|
|
2229
|
+
error: error4,
|
|
2230
|
+
rpcName,
|
|
2231
|
+
type: "VIEW_PORT_MENU_REJ",
|
|
2232
|
+
requestId
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2235
|
+
break;
|
|
2236
|
+
}
|
|
2237
|
+
case "VIEW_PORT_MENU_RESP":
|
|
2238
|
+
{
|
|
2239
|
+
if (isSessionTableActionMessage(body)) {
|
|
2240
|
+
const { action, rpcName } = body;
|
|
2241
|
+
this.awaitResponseToMessage({
|
|
2242
|
+
type: "GET_TABLE_META",
|
|
2243
|
+
table: action.table
|
|
2244
|
+
}).then((response) => {
|
|
2245
|
+
const tableSchema = createSchemaFromTableMetadata(
|
|
2246
|
+
response
|
|
2247
|
+
);
|
|
2248
|
+
this.postMessageToClient({
|
|
2249
|
+
rpcName,
|
|
2250
|
+
type: "VIEW_PORT_MENU_RESP",
|
|
2251
|
+
action: {
|
|
2252
|
+
...action,
|
|
2253
|
+
tableSchema
|
|
2254
|
+
},
|
|
2255
|
+
tableAlreadyOpen: this.isTableOpen(action.table),
|
|
2256
|
+
requestId
|
|
2257
|
+
});
|
|
2258
|
+
});
|
|
2259
|
+
} else {
|
|
2260
|
+
const { action } = body;
|
|
2261
|
+
this.postMessageToClient({
|
|
2262
|
+
type: "VIEW_PORT_MENU_RESP",
|
|
2263
|
+
action: action || NO_ACTION,
|
|
2264
|
+
tableAlreadyOpen: action !== null && this.isTableOpen(action.table),
|
|
2265
|
+
requestId
|
|
2266
|
+
});
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
break;
|
|
2270
|
+
case "RPC_RESP":
|
|
2271
|
+
{
|
|
2272
|
+
const { method, result } = body;
|
|
2273
|
+
this.postMessageToClient({
|
|
2274
|
+
type: "RPC_RESP",
|
|
2275
|
+
method,
|
|
2276
|
+
result,
|
|
2277
|
+
requestId
|
|
2278
|
+
});
|
|
2279
|
+
}
|
|
2280
|
+
break;
|
|
2281
|
+
case "VIEW_PORT_RPC_REPONSE":
|
|
2282
|
+
{
|
|
2283
|
+
const { method, action } = body;
|
|
2284
|
+
this.postMessageToClient({
|
|
2285
|
+
type: "VIEW_PORT_RPC_RESPONSE",
|
|
2286
|
+
rpcName: method,
|
|
2287
|
+
action,
|
|
2288
|
+
requestId
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
break;
|
|
2292
|
+
case "ERROR":
|
|
2293
|
+
error2(body.msg);
|
|
2294
|
+
break;
|
|
2295
|
+
default:
|
|
2296
|
+
infoEnabled2 && info2(\`handleMessageFromServer \${body["type"]}.\`);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
cacheTableMeta(messageBody) {
|
|
2300
|
+
const { module, table } = messageBody.table;
|
|
2301
|
+
const key = \`\${module}:\${table}\`;
|
|
2302
|
+
let tableSchema = this.cachedTableSchemas.get(key);
|
|
2303
|
+
if (!tableSchema) {
|
|
2304
|
+
tableSchema = createSchemaFromTableMetadata(messageBody);
|
|
2305
|
+
this.cachedTableSchemas.set(key, tableSchema);
|
|
2306
|
+
}
|
|
2307
|
+
return tableSchema;
|
|
2308
|
+
}
|
|
2309
|
+
isTableOpen(table) {
|
|
2310
|
+
if (table) {
|
|
2311
|
+
const tableName = table.table;
|
|
2312
|
+
for (const viewport of this.viewports.values()) {
|
|
2313
|
+
if (!viewport.suspended && viewport.table.table === tableName) {
|
|
2314
|
+
return true;
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
// Eliminate links to suspended viewports
|
|
2320
|
+
getActiveLinks(linkDescriptors) {
|
|
2321
|
+
return linkDescriptors.filter((linkDescriptor) => {
|
|
2322
|
+
const viewport = this.viewports.get(linkDescriptor.parentVpId);
|
|
2323
|
+
return viewport && !viewport.suspended;
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2326
|
+
processUpdates() {
|
|
2327
|
+
this.viewports.forEach((viewport) => {
|
|
2328
|
+
var _a;
|
|
2329
|
+
if (viewport.hasUpdatesToProcess) {
|
|
2330
|
+
const result = viewport.getClientRows();
|
|
2331
|
+
if (result !== NO_DATA_UPDATE) {
|
|
2332
|
+
const [rows, mode] = result;
|
|
2333
|
+
const size = viewport.getNewRowCount();
|
|
2334
|
+
if (size !== void 0 || rows && rows.length > 0) {
|
|
2335
|
+
debugEnabled3 && debug3(
|
|
2336
|
+
\`postMessageToClient #\${viewport.clientViewportId} viewport-update \${mode}, \${(_a = rows == null ? void 0 : rows.length) != null ? _a : "no"} rows, size \${size}\`
|
|
2337
|
+
);
|
|
2338
|
+
if (mode) {
|
|
2339
|
+
this.postMessageToClient({
|
|
2340
|
+
clientViewportId: viewport.clientViewportId,
|
|
2341
|
+
mode,
|
|
2342
|
+
rows,
|
|
2343
|
+
size,
|
|
2344
|
+
type: "viewport-update"
|
|
2345
|
+
});
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
});
|
|
2351
|
+
}
|
|
2352
|
+
};
|
|
2353
|
+
|
|
2354
|
+
// src/websocket-connection.ts
|
|
2355
|
+
var { debug: debug4, debugEnabled: debugEnabled4, error: error3, info: info3, infoEnabled: infoEnabled3, warn: warn3 } = logger(
|
|
2356
|
+
"websocket-connection"
|
|
2357
|
+
);
|
|
2358
|
+
var WS = "ws";
|
|
2359
|
+
var isWebsocketUrl = (url) => url.startsWith(WS + "://") || url.startsWith(WS + "s://");
|
|
2360
|
+
var connectionAttemptStatus = {};
|
|
2361
|
+
var setWebsocket = Symbol("setWebsocket");
|
|
2362
|
+
var connectionCallback = Symbol("connectionCallback");
|
|
2363
|
+
async function connect(connectionString, protocol, callback, retryLimitDisconnect = 10, retryLimitStartup = 5) {
|
|
2364
|
+
connectionAttemptStatus[connectionString] = {
|
|
2365
|
+
status: "connecting",
|
|
2366
|
+
connect: {
|
|
2367
|
+
allowed: retryLimitStartup,
|
|
2368
|
+
remaining: retryLimitStartup
|
|
2369
|
+
},
|
|
2370
|
+
reconnect: {
|
|
2371
|
+
allowed: retryLimitDisconnect,
|
|
2372
|
+
remaining: retryLimitDisconnect
|
|
2373
|
+
}
|
|
2374
|
+
};
|
|
2375
|
+
return makeConnection(connectionString, protocol, callback);
|
|
2376
|
+
}
|
|
2377
|
+
async function reconnect(connection) {
|
|
2378
|
+
throw Error("connection broken");
|
|
2379
|
+
}
|
|
2380
|
+
async function makeConnection(url, protocol, callback, connection) {
|
|
2381
|
+
const {
|
|
2382
|
+
status: currentStatus,
|
|
2383
|
+
connect: connectStatus,
|
|
2384
|
+
reconnect: reconnectStatus
|
|
2385
|
+
} = connectionAttemptStatus[url];
|
|
2386
|
+
const trackedStatus = currentStatus === "connecting" ? connectStatus : reconnectStatus;
|
|
2387
|
+
try {
|
|
2388
|
+
callback({ type: "connection-status", status: "connecting" });
|
|
2389
|
+
const reconnecting = typeof connection !== "undefined";
|
|
2390
|
+
const ws = await createWebsocket(url, protocol);
|
|
2391
|
+
console.info(
|
|
2392
|
+
"%c\u26A1 %cconnected",
|
|
2393
|
+
"font-size: 24px;color: green;font-weight: bold;",
|
|
2394
|
+
"color:green; font-size: 14px;"
|
|
2395
|
+
);
|
|
2396
|
+
if (connection !== void 0) {
|
|
2397
|
+
connection[setWebsocket](ws);
|
|
2398
|
+
}
|
|
2399
|
+
const websocketConnection = connection != null ? connection : new WebsocketConnection(ws, url, protocol, callback);
|
|
2400
|
+
const status = reconnecting ? "reconnected" : "connection-open-awaiting-session";
|
|
2401
|
+
callback({ type: "connection-status", status });
|
|
2402
|
+
websocketConnection.status = status;
|
|
2403
|
+
trackedStatus.remaining = trackedStatus.allowed;
|
|
2404
|
+
return websocketConnection;
|
|
2405
|
+
} catch (err) {
|
|
2406
|
+
const retry = --trackedStatus.remaining > 0;
|
|
2407
|
+
callback({
|
|
2408
|
+
type: "connection-status",
|
|
2409
|
+
status: "disconnected",
|
|
2410
|
+
reason: "failed to connect",
|
|
2411
|
+
retry
|
|
2412
|
+
});
|
|
2413
|
+
if (retry) {
|
|
2414
|
+
return makeConnectionIn(url, protocol, callback, connection, 2e3);
|
|
2415
|
+
} else {
|
|
2416
|
+
throw Error("Failed to establish connection");
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
var makeConnectionIn = (url, protocol, callback, connection, delay) => new Promise((resolve) => {
|
|
2421
|
+
setTimeout(() => {
|
|
2422
|
+
resolve(makeConnection(url, protocol, callback, connection));
|
|
2423
|
+
}, delay);
|
|
2424
|
+
});
|
|
2425
|
+
var createWebsocket = (connectionString, protocol) => new Promise((resolve, reject) => {
|
|
2426
|
+
const websocketUrl = isWebsocketUrl(connectionString) ? connectionString : \`wss://\${connectionString}\`;
|
|
2427
|
+
if (infoEnabled3 && protocol !== void 0) {
|
|
2428
|
+
info3(\`WebSocket Protocol \${protocol == null ? void 0 : protocol.toString()}\`);
|
|
2429
|
+
}
|
|
2430
|
+
const ws = new WebSocket(websocketUrl, protocol);
|
|
2431
|
+
ws.onopen = () => resolve(ws);
|
|
2432
|
+
ws.onerror = (evt) => reject(evt);
|
|
2433
|
+
});
|
|
2434
|
+
var closeWarn = () => {
|
|
2435
|
+
warn3 == null ? void 0 : warn3(\`Connection cannot be closed, socket not yet opened\`);
|
|
2436
|
+
};
|
|
2437
|
+
var sendWarn = (msg) => {
|
|
2438
|
+
warn3 == null ? void 0 : warn3(\`Message cannot be sent, socket closed \${msg.body.type}\`);
|
|
2439
|
+
};
|
|
2440
|
+
var parseMessage = (message) => {
|
|
2441
|
+
try {
|
|
2442
|
+
return JSON.parse(message);
|
|
2443
|
+
} catch (e) {
|
|
2444
|
+
throw Error(\`Error parsing JSON response from server \${message}\`);
|
|
2445
|
+
}
|
|
2446
|
+
};
|
|
2447
|
+
var WebsocketConnection = class {
|
|
2448
|
+
constructor(ws, url, protocol, callback) {
|
|
2449
|
+
this.close = closeWarn;
|
|
2450
|
+
this.requiresLogin = true;
|
|
2451
|
+
this.send = sendWarn;
|
|
2452
|
+
this.status = "ready";
|
|
2453
|
+
this.messagesCount = 0;
|
|
2454
|
+
this.connectionMetricsInterval = null;
|
|
2455
|
+
this.handleWebsocketMessage = (evt) => {
|
|
2456
|
+
const vuuMessageFromServer = parseMessage(evt.data);
|
|
2457
|
+
this.messagesCount += 1;
|
|
2458
|
+
if (true) {
|
|
2459
|
+
if (debugEnabled4 && vuuMessageFromServer.body.type !== "HB") {
|
|
2460
|
+
debug4 == null ? void 0 : debug4(\`<<< \${vuuMessageFromServer.body.type}\`);
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
this[connectionCallback](vuuMessageFromServer);
|
|
2464
|
+
};
|
|
2465
|
+
this.url = url;
|
|
2466
|
+
this.protocol = protocol;
|
|
2467
|
+
this[connectionCallback] = callback;
|
|
2468
|
+
this[setWebsocket](ws);
|
|
2469
|
+
}
|
|
2470
|
+
reconnect() {
|
|
2471
|
+
reconnect(this);
|
|
2472
|
+
}
|
|
2473
|
+
[(connectionCallback, setWebsocket)](ws) {
|
|
2474
|
+
const callback = this[connectionCallback];
|
|
2475
|
+
ws.onmessage = (evt) => {
|
|
2476
|
+
this.status = "connected";
|
|
2477
|
+
ws.onmessage = this.handleWebsocketMessage;
|
|
2478
|
+
this.handleWebsocketMessage(evt);
|
|
2479
|
+
};
|
|
2480
|
+
this.connectionMetricsInterval = setInterval(() => {
|
|
2481
|
+
callback({
|
|
2482
|
+
type: "connection-metrics",
|
|
2483
|
+
messagesLength: this.messagesCount
|
|
2484
|
+
});
|
|
2485
|
+
this.messagesCount = 0;
|
|
2486
|
+
}, 2e3);
|
|
2487
|
+
ws.onerror = () => {
|
|
2488
|
+
error3(\`\u26A1 connection error\`);
|
|
2489
|
+
callback({
|
|
2490
|
+
type: "connection-status",
|
|
2491
|
+
status: "disconnected",
|
|
2492
|
+
reason: "error"
|
|
2493
|
+
});
|
|
2494
|
+
if (this.connectionMetricsInterval) {
|
|
2495
|
+
clearInterval(this.connectionMetricsInterval);
|
|
2496
|
+
this.connectionMetricsInterval = null;
|
|
2497
|
+
}
|
|
2498
|
+
if (this.status === "connection-open-awaiting-session") {
|
|
2499
|
+
error3(
|
|
2500
|
+
\`Websocket connection lost before Vuu session established, check websocket configuration\`
|
|
2501
|
+
);
|
|
2502
|
+
} else if (this.status !== "closed") {
|
|
2503
|
+
reconnect(this);
|
|
2504
|
+
this.send = queue;
|
|
2505
|
+
}
|
|
2506
|
+
};
|
|
2507
|
+
ws.onclose = () => {
|
|
2508
|
+
info3 == null ? void 0 : info3(\`\u26A1 connection close\`);
|
|
2509
|
+
callback({
|
|
2510
|
+
type: "connection-status",
|
|
2511
|
+
status: "disconnected",
|
|
2512
|
+
reason: "close"
|
|
2513
|
+
});
|
|
2514
|
+
if (this.connectionMetricsInterval) {
|
|
2515
|
+
clearInterval(this.connectionMetricsInterval);
|
|
2516
|
+
this.connectionMetricsInterval = null;
|
|
2517
|
+
}
|
|
2518
|
+
if (this.status !== "closed") {
|
|
2519
|
+
reconnect(this);
|
|
2520
|
+
this.send = queue;
|
|
2521
|
+
}
|
|
2522
|
+
};
|
|
2523
|
+
const send = (msg) => {
|
|
2524
|
+
if (true) {
|
|
2525
|
+
if (debugEnabled4 && msg.body.type !== "HB_RESP") {
|
|
2526
|
+
debug4 == null ? void 0 : debug4(\`>>> \${msg.body.type}\`);
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
ws.send(JSON.stringify(msg));
|
|
2530
|
+
};
|
|
2531
|
+
const queue = (msg) => {
|
|
2532
|
+
info3 == null ? void 0 : info3(\`TODO queue message until websocket reconnected \${msg.body.type}\`);
|
|
2533
|
+
};
|
|
2534
|
+
this.send = send;
|
|
2535
|
+
this.close = () => {
|
|
2536
|
+
this.status = "closed";
|
|
2537
|
+
ws.close();
|
|
2538
|
+
this.close = closeWarn;
|
|
2539
|
+
this.send = sendWarn;
|
|
2540
|
+
info3 == null ? void 0 : info3("close websocket");
|
|
2541
|
+
};
|
|
2542
|
+
}
|
|
2543
|
+
};
|
|
2544
|
+
|
|
2545
|
+
// src/worker.ts
|
|
2546
|
+
var server;
|
|
2547
|
+
var { info: info4, infoEnabled: infoEnabled4 } = logger("worker");
|
|
2548
|
+
async function connectToServer(url, protocol, token, username, onConnectionStatusChange, retryLimitDisconnect, retryLimitStartup) {
|
|
2549
|
+
const connection = await connect(
|
|
2550
|
+
url,
|
|
2551
|
+
protocol,
|
|
2552
|
+
// if this was called during connect, we would get a ReferenceError, but it will
|
|
2553
|
+
// never be called until subscriptions have been made, so this is safe.
|
|
2554
|
+
//TODO do we need to listen in to the connection messages here so we can lock back in, in the event of a reconnenct ?
|
|
2555
|
+
(msg) => {
|
|
2556
|
+
if (isConnectionQualityMetrics(msg)) {
|
|
2557
|
+
postMessage({ type: "connection-metrics", messages: msg });
|
|
2558
|
+
} else if (isConnectionStatusMessage(msg)) {
|
|
2559
|
+
onConnectionStatusChange(msg);
|
|
2560
|
+
if (msg.status === "reconnected") {
|
|
2561
|
+
server.reconnect();
|
|
2562
|
+
}
|
|
2563
|
+
} else {
|
|
2564
|
+
server.handleMessageFromServer(msg);
|
|
2565
|
+
}
|
|
2566
|
+
},
|
|
2567
|
+
retryLimitDisconnect,
|
|
2568
|
+
retryLimitStartup
|
|
2569
|
+
);
|
|
2570
|
+
server = new ServerProxy(connection, (msg) => sendMessageToClient(msg));
|
|
2571
|
+
if (connection.requiresLogin) {
|
|
2572
|
+
await server.login(token, username);
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
function sendMessageToClient(message) {
|
|
2576
|
+
postMessage(message);
|
|
2577
|
+
}
|
|
2578
|
+
var handleMessageFromClient = async ({
|
|
2579
|
+
data: message
|
|
2580
|
+
}) => {
|
|
2581
|
+
switch (message.type) {
|
|
2582
|
+
case "connect":
|
|
2583
|
+
await connectToServer(
|
|
2584
|
+
message.url,
|
|
2585
|
+
message.protocol,
|
|
2586
|
+
message.token,
|
|
2587
|
+
message.username,
|
|
2588
|
+
postMessage,
|
|
2589
|
+
message.retryLimitDisconnect,
|
|
2590
|
+
message.retryLimitStartup
|
|
2591
|
+
);
|
|
2592
|
+
postMessage({ type: "connected" });
|
|
2593
|
+
break;
|
|
2594
|
+
case "subscribe":
|
|
2595
|
+
infoEnabled4 && info4(\`client subscribe: \${JSON.stringify(message)}\`);
|
|
2596
|
+
server.subscribe(message);
|
|
2597
|
+
break;
|
|
2598
|
+
case "unsubscribe":
|
|
2599
|
+
infoEnabled4 && info4(\`client unsubscribe: \${JSON.stringify(message)}\`);
|
|
2600
|
+
server.unsubscribe(message.viewport);
|
|
2601
|
+
break;
|
|
2602
|
+
default:
|
|
2603
|
+
infoEnabled4 && info4(\`client message: \${JSON.stringify(message)}\`);
|
|
2604
|
+
server.handleMessageFromClient(message);
|
|
2605
|
+
}
|
|
2606
|
+
};
|
|
2607
|
+
self.addEventListener("message", handleMessageFromClient);
|
|
2608
|
+
postMessage({ type: "ready" });
|
|
2609
|
+
|
|
2610
|
+
`;
|
|
2611
|
+
|
|
2612
|
+
// src/connection-manager.ts
|
|
2613
|
+
var workerBlob = new Blob([(0, import_vuu_utils.getLoggingConfigForWorker)() + workerSourceCode], {
|
|
2614
|
+
type: "text/javascript"
|
|
2615
|
+
});
|
|
2616
|
+
var workerBlobUrl = URL.createObjectURL(workerBlob);
|
|
2617
|
+
var worker;
|
|
2618
|
+
var pendingWorker;
|
|
2619
|
+
var pendingWorkerNoToken = [];
|
|
2620
|
+
var resolveServer;
|
|
2621
|
+
var rejectServer;
|
|
2622
|
+
var serverAPI = new Promise((resolve, reject) => {
|
|
2623
|
+
resolveServer = resolve;
|
|
2624
|
+
rejectServer = reject;
|
|
2625
|
+
});
|
|
2626
|
+
var getServerAPI = () => serverAPI;
|
|
2627
|
+
var viewports = /* @__PURE__ */ new Map();
|
|
2628
|
+
var pendingRequests = /* @__PURE__ */ new Map();
|
|
2629
|
+
var getWorker = async ({
|
|
2630
|
+
handleConnectionStatusChange,
|
|
2631
|
+
protocol,
|
|
2632
|
+
retryLimitDisconnect,
|
|
2633
|
+
retryLimitStartup,
|
|
2634
|
+
token = "",
|
|
2635
|
+
username,
|
|
2636
|
+
url
|
|
2637
|
+
}) => {
|
|
2638
|
+
if (token === "" && pendingWorker === void 0) {
|
|
2639
|
+
return new Promise((resolve) => {
|
|
2640
|
+
pendingWorkerNoToken.push({ resolve });
|
|
2641
|
+
});
|
|
2642
|
+
}
|
|
2643
|
+
return pendingWorker || // we get this far when we receive the first request with auth token
|
|
2644
|
+
(pendingWorker = new Promise((resolve) => {
|
|
2645
|
+
const worker2 = new Worker(workerBlobUrl);
|
|
2646
|
+
const timer = window.setTimeout(() => {
|
|
2647
|
+
console.error("timed out waiting for worker to load");
|
|
2648
|
+
}, 1e3);
|
|
2649
|
+
worker2.onmessage = (msg) => {
|
|
2650
|
+
const { data: message } = msg;
|
|
2651
|
+
if (message.type === "ready") {
|
|
2652
|
+
window.clearTimeout(timer);
|
|
2653
|
+
worker2.postMessage({
|
|
2654
|
+
protocol,
|
|
2655
|
+
retryLimitDisconnect,
|
|
2656
|
+
retryLimitStartup,
|
|
2657
|
+
token,
|
|
2658
|
+
type: "connect",
|
|
2659
|
+
url,
|
|
2660
|
+
username
|
|
2661
|
+
});
|
|
2662
|
+
} else if (message.type === "connected") {
|
|
2663
|
+
worker2.onmessage = handleMessageFromWorker;
|
|
2664
|
+
resolve(worker2);
|
|
2665
|
+
for (const pendingWorkerRequest of pendingWorkerNoToken) {
|
|
2666
|
+
pendingWorkerRequest.resolve(worker2);
|
|
2667
|
+
}
|
|
2668
|
+
pendingWorkerNoToken.length = 0;
|
|
2669
|
+
} else if ((0, import_vuu_utils.isConnectionStatusMessage)(message)) {
|
|
2670
|
+
handleConnectionStatusChange({ data: message });
|
|
2671
|
+
} else {
|
|
2672
|
+
console.warn("ConnectionManager: Unexpected message from the worker");
|
|
2673
|
+
}
|
|
2674
|
+
};
|
|
2675
|
+
}));
|
|
2676
|
+
};
|
|
2677
|
+
function handleMessageFromWorker({
|
|
2678
|
+
data: message
|
|
2679
|
+
}) {
|
|
2680
|
+
if (shouldMessageBeRoutedToDataSource(message)) {
|
|
2681
|
+
const viewport = viewports.get(message.clientViewportId);
|
|
2682
|
+
if (viewport) {
|
|
2683
|
+
viewport.postMessageToClientDataSource(message);
|
|
2684
|
+
} else {
|
|
2685
|
+
console.error(
|
|
2686
|
+
`[ConnectionManager] ${message.type} message received, viewport not found`
|
|
2687
|
+
);
|
|
2688
|
+
}
|
|
2689
|
+
} else if ((0, import_vuu_utils.isConnectionStatusMessage)(message)) {
|
|
2690
|
+
ConnectionManager.emit("connection-status", message);
|
|
2691
|
+
} else if ((0, import_vuu_utils.isConnectionQualityMetrics)(message)) {
|
|
2692
|
+
ConnectionManager.emit("connection-metrics", message);
|
|
2693
|
+
} else {
|
|
2694
|
+
const requestId = message.requestId;
|
|
2695
|
+
if (pendingRequests.has(requestId)) {
|
|
2696
|
+
const { resolve } = pendingRequests.get(requestId);
|
|
2697
|
+
pendingRequests.delete(requestId);
|
|
2698
|
+
const {
|
|
2699
|
+
type: _1,
|
|
2700
|
+
requestId: _2,
|
|
2701
|
+
...rest
|
|
2702
|
+
} = message;
|
|
2703
|
+
if ((0, import_vuu_utils.messageHasResult)(message)) {
|
|
2704
|
+
resolve(message.result);
|
|
2705
|
+
} else if (message.type === "VP_EDIT_RPC_RESPONSE" || message.type === "VP_EDIT_RPC_REJECT") {
|
|
2706
|
+
resolve(message);
|
|
2707
|
+
} else if ((0, import_vuu_utils.isTableSchema)(message)) {
|
|
2708
|
+
resolve(message.tableSchema);
|
|
2709
|
+
} else {
|
|
2710
|
+
resolve(rest);
|
|
2711
|
+
}
|
|
2712
|
+
} else {
|
|
2713
|
+
console.warn(
|
|
2714
|
+
"%cConnectionManager Unexpected message from the worker",
|
|
2715
|
+
"color:red;font-weight:bold;"
|
|
2716
|
+
);
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
var asyncRequest = (msg) => {
|
|
2721
|
+
const requestId = (0, import_vuu_utils.uuid)();
|
|
2722
|
+
worker.postMessage({
|
|
2723
|
+
requestId,
|
|
2724
|
+
...msg
|
|
2725
|
+
});
|
|
2726
|
+
return new Promise((resolve, reject) => {
|
|
2727
|
+
pendingRequests.set(requestId, { resolve, reject });
|
|
2728
|
+
});
|
|
2729
|
+
};
|
|
2730
|
+
var connectedServerAPI = {
|
|
2731
|
+
subscribe: (message, callback) => {
|
|
2732
|
+
if (viewports.get(message.viewport)) {
|
|
2733
|
+
throw Error(
|
|
2734
|
+
`ConnectionManager attempting to subscribe with an existing viewport id`
|
|
2735
|
+
);
|
|
2736
|
+
}
|
|
2737
|
+
viewports.set(message.viewport, {
|
|
2738
|
+
status: "subscribing",
|
|
2739
|
+
request: message,
|
|
2740
|
+
postMessageToClientDataSource: callback
|
|
2741
|
+
});
|
|
2742
|
+
worker.postMessage({ type: "subscribe", ...message });
|
|
2743
|
+
},
|
|
2744
|
+
unsubscribe: (viewport) => {
|
|
2745
|
+
worker.postMessage({ type: "unsubscribe", viewport });
|
|
2746
|
+
},
|
|
2747
|
+
send: (message) => {
|
|
2748
|
+
worker.postMessage(message);
|
|
2749
|
+
},
|
|
2750
|
+
destroy: (viewportId) => {
|
|
2751
|
+
if (viewportId && viewports.has(viewportId)) {
|
|
2752
|
+
viewports.delete(viewportId);
|
|
2753
|
+
}
|
|
2754
|
+
},
|
|
2755
|
+
rpcCall: async (message) => asyncRequest(message),
|
|
2756
|
+
getTableList: async () => asyncRequest({ type: "GET_TABLE_LIST" }),
|
|
2757
|
+
getTableSchema: async (table) => asyncRequest({
|
|
2758
|
+
type: GET_TABLE_META,
|
|
2759
|
+
table
|
|
2760
|
+
})
|
|
2761
|
+
};
|
|
2762
|
+
var _ConnectionManager = class extends import_vuu_utils.EventEmitter {
|
|
2763
|
+
// The first request must have the token. We can change this to block others until
|
|
2764
|
+
// the request with token is received.
|
|
2765
|
+
async connect({
|
|
2766
|
+
url,
|
|
2767
|
+
authToken,
|
|
2768
|
+
username,
|
|
2769
|
+
protocol,
|
|
2770
|
+
retryLimitDisconnect,
|
|
2771
|
+
retryLimitStartup
|
|
2772
|
+
}) {
|
|
2773
|
+
worker = await getWorker({
|
|
2774
|
+
protocol,
|
|
2775
|
+
url,
|
|
2776
|
+
token: authToken,
|
|
2777
|
+
username,
|
|
2778
|
+
retryLimitDisconnect,
|
|
2779
|
+
retryLimitStartup,
|
|
2780
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2781
|
+
// @ts-ignore
|
|
2782
|
+
handleConnectionStatusChange: handleMessageFromWorker
|
|
2783
|
+
});
|
|
2784
|
+
return connectedServerAPI;
|
|
2785
|
+
}
|
|
2786
|
+
destroy() {
|
|
2787
|
+
worker.terminate();
|
|
2788
|
+
}
|
|
2789
|
+
};
|
|
2790
|
+
var ConnectionManager = new _ConnectionManager();
|
|
2791
|
+
var connectToServer = async ({
|
|
2792
|
+
url,
|
|
2793
|
+
protocol = void 0,
|
|
2794
|
+
authToken,
|
|
2795
|
+
username,
|
|
2796
|
+
retryLimitDisconnect,
|
|
2797
|
+
retryLimitStartup
|
|
2798
|
+
}) => {
|
|
2799
|
+
try {
|
|
2800
|
+
const serverAPI2 = await ConnectionManager.connect({
|
|
2801
|
+
protocol,
|
|
2802
|
+
url,
|
|
2803
|
+
authToken,
|
|
2804
|
+
username,
|
|
2805
|
+
retryLimitDisconnect,
|
|
2806
|
+
retryLimitStartup
|
|
2807
|
+
});
|
|
2808
|
+
resolveServer(serverAPI2);
|
|
2809
|
+
} catch (err) {
|
|
2810
|
+
console.error("Connection Error", err);
|
|
2811
|
+
rejectServer(err);
|
|
2812
|
+
}
|
|
2813
|
+
};
|
|
2814
|
+
var makeRpcCall = async (rpcRequest) => {
|
|
2815
|
+
try {
|
|
2816
|
+
return (await serverAPI).rpcCall(rpcRequest);
|
|
2817
|
+
} catch (err) {
|
|
2818
|
+
throw Error("Error accessing server api");
|
|
2819
|
+
}
|
|
2820
|
+
};
|
|
2821
|
+
|
|
2822
|
+
// src/constants.ts
|
|
2823
|
+
var _connectionId = 0;
|
|
2824
|
+
var connectionId = {
|
|
2825
|
+
get nextValue() {
|
|
2826
|
+
return _connectionId++;
|
|
2827
|
+
}
|
|
2828
|
+
};
|
|
2829
|
+
var msgType = {
|
|
2830
|
+
connect: "connect",
|
|
2831
|
+
connectionStatus: "connection-status",
|
|
2832
|
+
getFilterData: "GetFilterData",
|
|
2833
|
+
rowData: "rowData",
|
|
2834
|
+
rowSet: "rowset",
|
|
2835
|
+
select: "select",
|
|
2836
|
+
selectAll: "selectAll",
|
|
2837
|
+
selectNone: "selectNone",
|
|
2838
|
+
selected: "selected",
|
|
2839
|
+
snapshot: "snapshot",
|
|
2840
|
+
update: "update",
|
|
2841
|
+
createLink: "createLink",
|
|
2842
|
+
disable: "disable",
|
|
2843
|
+
enable: "enable",
|
|
2844
|
+
suspend: "suspend",
|
|
2845
|
+
resume: "resume",
|
|
2846
|
+
addSubscription: "AddSubscription",
|
|
2847
|
+
closeTreeNode: "closeTreeNode",
|
|
2848
|
+
columnList: "ColumnList",
|
|
2849
|
+
data: "data",
|
|
2850
|
+
openTreeNode: "openTreeNode",
|
|
2851
|
+
aggregate: "aggregate",
|
|
2852
|
+
filter: "filter",
|
|
2853
|
+
filterQuery: "filterQuery",
|
|
2854
|
+
filterData: "filterData",
|
|
2855
|
+
getSearchData: "GetSearchData",
|
|
2856
|
+
groupBy: "groupBy",
|
|
2857
|
+
modifySubscription: "ModifySubscription",
|
|
2858
|
+
searchData: "searchData",
|
|
2859
|
+
setGroupState: "setGroupState",
|
|
2860
|
+
size: "size",
|
|
2861
|
+
sort: "sort",
|
|
2862
|
+
subscribed: "Subscribed",
|
|
2863
|
+
tableList: "TableList",
|
|
2864
|
+
unsubscribe: "TerminateSubscription",
|
|
2865
|
+
viewRangeChanged: "ViewRangeChanged"
|
|
2866
|
+
};
|
|
2867
|
+
|
|
2868
|
+
// src/message-utils.ts
|
|
2869
|
+
var MENU_RPC_TYPES = [
|
|
2870
|
+
"VIEW_PORT_MENUS_SELECT_RPC",
|
|
2871
|
+
"VIEW_PORT_MENU_TABLE_RPC",
|
|
2872
|
+
"VIEW_PORT_MENU_ROW_RPC",
|
|
2873
|
+
"VIEW_PORT_MENU_CELL_RPC",
|
|
2874
|
+
"VP_EDIT_CELL_RPC",
|
|
2875
|
+
"VP_EDIT_ROW_RPC",
|
|
2876
|
+
"VP_EDIT_ADD_ROW_RPC",
|
|
2877
|
+
"VP_EDIT_DELETE_CELL_RPC",
|
|
2878
|
+
"VP_EDIT_DELETE_ROW_RPC",
|
|
2879
|
+
"VP_EDIT_SUBMIT_FORM_RPC"
|
|
2880
|
+
];
|
|
2881
|
+
var isVuuMenuRpcRequest = (message) => MENU_RPC_TYPES.includes(message["type"]);
|
|
2882
|
+
var isVuuRpcRequest = (message) => message["type"] === "VIEW_PORT_RPC_CALL";
|
|
2883
|
+
var stripRequestId = ({
|
|
2884
|
+
requestId,
|
|
2885
|
+
...rest
|
|
2886
|
+
}) => [requestId, rest];
|
|
2887
|
+
var getFirstAndLastRows = (rows) => {
|
|
2888
|
+
let firstRow = rows.at(0);
|
|
2889
|
+
if (firstRow.updateType === "SIZE") {
|
|
2890
|
+
if (rows.length === 1) {
|
|
2891
|
+
return rows;
|
|
2892
|
+
} else {
|
|
2893
|
+
firstRow = rows.at(1);
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
const lastRow = rows.at(-1);
|
|
2897
|
+
return [firstRow, lastRow];
|
|
2898
|
+
};
|
|
2899
|
+
var groupRowsByViewport = (rows) => {
|
|
2900
|
+
const result = {};
|
|
2901
|
+
for (const row of rows) {
|
|
2902
|
+
const rowsForViewport = result[row.viewPortId] || (result[row.viewPortId] = []);
|
|
2903
|
+
rowsForViewport.push(row);
|
|
2904
|
+
}
|
|
2905
|
+
return result;
|
|
2906
|
+
};
|
|
2907
|
+
var createSchemaFromTableMetadata = ({
|
|
2908
|
+
columns,
|
|
2909
|
+
dataTypes,
|
|
2910
|
+
key,
|
|
2911
|
+
table
|
|
2912
|
+
}) => {
|
|
2913
|
+
return {
|
|
2914
|
+
table,
|
|
2915
|
+
columns: columns.map((col, idx) => ({
|
|
2916
|
+
name: col,
|
|
2917
|
+
serverDataType: dataTypes[idx]
|
|
2918
|
+
})),
|
|
2919
|
+
key
|
|
2920
|
+
};
|
|
2921
|
+
};
|
|
2922
|
+
|
|
2923
|
+
// src/vuu-data-source.ts
|
|
2924
|
+
var import_vuu_filter_parser = require("@vuu-ui/vuu-filter-parser");
|
|
2925
|
+
var import_vuu_utils2 = require("@vuu-ui/vuu-utils");
|
|
2926
|
+
var { info } = (0, import_vuu_utils2.logger)("VuuDataSource");
|
|
2927
|
+
var { KEY } = import_vuu_utils2.metadataKeys;
|
|
2928
|
+
var _config, _groupBy, _links, _menu, _optimize, _range, _selectedRowsCount, _size, _status, _title;
|
|
2929
|
+
var VuuDataSource = class extends import_vuu_utils2.EventEmitter {
|
|
2930
|
+
constructor({
|
|
2931
|
+
bufferSize = 100,
|
|
2932
|
+
aggregations,
|
|
2933
|
+
columns,
|
|
2934
|
+
filter,
|
|
2935
|
+
groupBy,
|
|
2936
|
+
sort,
|
|
2937
|
+
table,
|
|
2938
|
+
title,
|
|
2939
|
+
viewport,
|
|
2940
|
+
visualLink
|
|
2941
|
+
}) {
|
|
2942
|
+
super();
|
|
2943
|
+
this.server = null;
|
|
2944
|
+
__privateAdd(this, _config, import_vuu_utils2.vanillaConfig);
|
|
2945
|
+
__privateAdd(this, _groupBy, []);
|
|
2946
|
+
__privateAdd(this, _links, void 0);
|
|
2947
|
+
__privateAdd(this, _menu, void 0);
|
|
2948
|
+
__privateAdd(this, _optimize, "throttle");
|
|
2949
|
+
__privateAdd(this, _range, { from: 0, to: 0 });
|
|
2950
|
+
__privateAdd(this, _selectedRowsCount, 0);
|
|
2951
|
+
__privateAdd(this, _size, 0);
|
|
2952
|
+
__privateAdd(this, _status, "initialising");
|
|
2953
|
+
__privateAdd(this, _title, void 0);
|
|
2954
|
+
this.handleMessageFromServer = (message) => {
|
|
2955
|
+
var _a, _b;
|
|
2956
|
+
if (message.type === "subscribed") {
|
|
2957
|
+
__privateSet(this, _status, "subscribed");
|
|
2958
|
+
if (message.tableSchema) {
|
|
2959
|
+
this.tableSchema = message.tableSchema;
|
|
2960
|
+
}
|
|
2961
|
+
(_a = this.clientCallback) == null ? void 0 : _a.call(this, message);
|
|
2962
|
+
} else if (message.type === "disabled") {
|
|
2963
|
+
__privateSet(this, _status, "disabled");
|
|
2964
|
+
} else if (message.type === "enabled") {
|
|
2965
|
+
__privateSet(this, _status, "enabled");
|
|
2966
|
+
} else if (isDataSourceConfigMessage(message)) {
|
|
2967
|
+
return;
|
|
2968
|
+
} else if (message.type === "debounce-begin") {
|
|
2969
|
+
this.optimize = "debounce";
|
|
2970
|
+
} else {
|
|
2971
|
+
if (message.type === "viewport-update" && message.size !== void 0 && message.size !== __privateGet(this, _size)) {
|
|
2972
|
+
__privateSet(this, _size, message.size);
|
|
2973
|
+
this.emit("resize", message.size);
|
|
2974
|
+
}
|
|
2975
|
+
if (this.configChangePending) {
|
|
2976
|
+
this.setConfigPending();
|
|
2977
|
+
}
|
|
2978
|
+
if ((0, import_vuu_utils2.isViewportMenusAction)(message)) {
|
|
2979
|
+
__privateSet(this, _menu, message.menu);
|
|
2980
|
+
} else if ((0, import_vuu_utils2.isVisualLinksAction)(message)) {
|
|
2981
|
+
__privateSet(this, _links, message.links);
|
|
2982
|
+
} else {
|
|
2983
|
+
(_b = this.clientCallback) == null ? void 0 : _b.call(this, message);
|
|
2984
|
+
}
|
|
2985
|
+
if (this.optimize === "debounce") {
|
|
2986
|
+
this.revertDebounce();
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
};
|
|
2990
|
+
this.revertDebounce = (0, import_vuu_utils2.debounce)(() => {
|
|
2991
|
+
this.optimize = "throttle";
|
|
2992
|
+
}, 100);
|
|
2993
|
+
this.rawRangeRequest = (range) => {
|
|
2994
|
+
if (this.viewport && this.server) {
|
|
2995
|
+
this.server.send({
|
|
2996
|
+
viewport: this.viewport,
|
|
2997
|
+
type: "setViewRange",
|
|
2998
|
+
range
|
|
2999
|
+
});
|
|
3000
|
+
}
|
|
3001
|
+
};
|
|
3002
|
+
this.debounceRangeRequest = (0, import_vuu_utils2.debounce)((range) => {
|
|
3003
|
+
if (this.viewport && this.server) {
|
|
3004
|
+
this.server.send({
|
|
3005
|
+
viewport: this.viewport,
|
|
3006
|
+
type: "setViewRange",
|
|
3007
|
+
range
|
|
3008
|
+
});
|
|
3009
|
+
}
|
|
3010
|
+
}, 50);
|
|
3011
|
+
this.throttleRangeRequest = (0, import_vuu_utils2.throttle)((range) => {
|
|
3012
|
+
if (this.viewport && this.server) {
|
|
3013
|
+
this.server.send({
|
|
3014
|
+
viewport: this.viewport,
|
|
3015
|
+
type: "setViewRange",
|
|
3016
|
+
range
|
|
3017
|
+
});
|
|
3018
|
+
}
|
|
3019
|
+
}, 80);
|
|
3020
|
+
if (!table)
|
|
3021
|
+
throw Error("RemoteDataSource constructor called without table");
|
|
3022
|
+
this.bufferSize = bufferSize;
|
|
3023
|
+
this.table = table;
|
|
3024
|
+
this.viewport = viewport;
|
|
3025
|
+
__privateSet(this, _config, {
|
|
3026
|
+
...__privateGet(this, _config),
|
|
3027
|
+
aggregations: aggregations || __privateGet(this, _config).aggregations,
|
|
3028
|
+
columns: columns || __privateGet(this, _config).columns,
|
|
3029
|
+
filter: filter || __privateGet(this, _config).filter,
|
|
3030
|
+
groupBy: groupBy || __privateGet(this, _config).groupBy,
|
|
3031
|
+
sort: sort || __privateGet(this, _config).sort,
|
|
3032
|
+
visualLink: visualLink || __privateGet(this, _config).visualLink
|
|
3033
|
+
});
|
|
3034
|
+
__privateSet(this, _title, title);
|
|
3035
|
+
this.rangeRequest = this.throttleRangeRequest;
|
|
3036
|
+
}
|
|
3037
|
+
async subscribe({
|
|
3038
|
+
viewport = ((_a) => (_a = this.viewport) != null ? _a : this.viewport = (0, import_vuu_utils2.uuid)())(),
|
|
3039
|
+
columns,
|
|
3040
|
+
aggregations,
|
|
3041
|
+
range,
|
|
3042
|
+
sort,
|
|
3043
|
+
groupBy,
|
|
3044
|
+
filter
|
|
3045
|
+
}, callback) {
|
|
3046
|
+
var _a2;
|
|
3047
|
+
if (__privateGet(this, _status) === "disabled" || __privateGet(this, _status) === "disabling") {
|
|
3048
|
+
this.enable(callback);
|
|
3049
|
+
return;
|
|
3050
|
+
}
|
|
3051
|
+
this.clientCallback = callback;
|
|
3052
|
+
if (aggregations || columns || filter || groupBy || sort) {
|
|
3053
|
+
__privateSet(this, _config, {
|
|
3054
|
+
...__privateGet(this, _config),
|
|
3055
|
+
aggregations: aggregations || __privateGet(this, _config).aggregations,
|
|
3056
|
+
columns: columns || __privateGet(this, _config).columns,
|
|
3057
|
+
filter: filter || __privateGet(this, _config).filter,
|
|
3058
|
+
groupBy: groupBy || __privateGet(this, _config).groupBy,
|
|
3059
|
+
sort: sort || __privateGet(this, _config).sort
|
|
3060
|
+
});
|
|
3061
|
+
}
|
|
3062
|
+
if (range) {
|
|
3063
|
+
__privateSet(this, _range, range);
|
|
3064
|
+
}
|
|
3065
|
+
if (__privateGet(this, _status) !== "initialising" && __privateGet(this, _status) !== "unsubscribed") {
|
|
3066
|
+
return;
|
|
3067
|
+
}
|
|
3068
|
+
__privateSet(this, _status, "subscribing");
|
|
3069
|
+
this.viewport = viewport;
|
|
3070
|
+
this.server = await getServerAPI();
|
|
3071
|
+
const { bufferSize } = this;
|
|
3072
|
+
(_a2 = this.server) == null ? void 0 : _a2.subscribe(
|
|
3073
|
+
{
|
|
3074
|
+
...__privateGet(this, _config),
|
|
3075
|
+
bufferSize,
|
|
3076
|
+
viewport,
|
|
3077
|
+
table: this.table,
|
|
3078
|
+
range: __privateGet(this, _range),
|
|
3079
|
+
title: __privateGet(this, _title)
|
|
3080
|
+
},
|
|
3081
|
+
this.handleMessageFromServer
|
|
3082
|
+
);
|
|
3083
|
+
}
|
|
3084
|
+
unsubscribe() {
|
|
3085
|
+
var _a, _b;
|
|
3086
|
+
console.log(`unsubscribe #${this.viewport}`);
|
|
3087
|
+
info == null ? void 0 : info(`unsubscribe #${this.viewport}`);
|
|
3088
|
+
if (this.viewport) {
|
|
3089
|
+
(_a = this.server) == null ? void 0 : _a.unsubscribe(this.viewport);
|
|
3090
|
+
}
|
|
3091
|
+
(_b = this.server) == null ? void 0 : _b.destroy(this.viewport);
|
|
3092
|
+
this.server = null;
|
|
3093
|
+
this.removeAllListeners();
|
|
3094
|
+
__privateSet(this, _status, "unsubscribed");
|
|
3095
|
+
this.viewport = void 0;
|
|
3096
|
+
this.range = { from: 0, to: 0 };
|
|
3097
|
+
}
|
|
3098
|
+
suspend() {
|
|
3099
|
+
var _a;
|
|
3100
|
+
console.log(`suspend #${this.viewport}, current status ${__privateGet(this, _status)}`);
|
|
3101
|
+
info == null ? void 0 : info(`suspend #${this.viewport}, current status ${__privateGet(this, _status)}`);
|
|
3102
|
+
if (this.viewport) {
|
|
3103
|
+
__privateSet(this, _status, "suspended");
|
|
3104
|
+
(_a = this.server) == null ? void 0 : _a.send({
|
|
3105
|
+
type: "suspend",
|
|
3106
|
+
viewport: this.viewport
|
|
3107
|
+
});
|
|
3108
|
+
}
|
|
3109
|
+
return this;
|
|
3110
|
+
}
|
|
3111
|
+
resume() {
|
|
3112
|
+
var _a;
|
|
3113
|
+
console.log(`resume #${this.viewport}, current status ${__privateGet(this, _status)}`);
|
|
3114
|
+
const isDisabled = __privateGet(this, _status).startsWith("disabl");
|
|
3115
|
+
const isSuspended = __privateGet(this, _status) === "suspended";
|
|
3116
|
+
info == null ? void 0 : info(`resume #${this.viewport}, current status ${__privateGet(this, _status)}`);
|
|
3117
|
+
if (this.viewport) {
|
|
3118
|
+
if (isDisabled) {
|
|
3119
|
+
this.enable();
|
|
3120
|
+
} else if (isSuspended) {
|
|
3121
|
+
(_a = this.server) == null ? void 0 : _a.send({
|
|
3122
|
+
type: "resume",
|
|
3123
|
+
viewport: this.viewport
|
|
3124
|
+
});
|
|
3125
|
+
__privateSet(this, _status, "subscribed");
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
3128
|
+
return this;
|
|
3129
|
+
}
|
|
3130
|
+
disable() {
|
|
3131
|
+
var _a;
|
|
3132
|
+
info == null ? void 0 : info(`disable #${this.viewport}, current status ${__privateGet(this, _status)}`);
|
|
3133
|
+
if (this.viewport) {
|
|
3134
|
+
__privateSet(this, _status, "disabling");
|
|
3135
|
+
(_a = this.server) == null ? void 0 : _a.send({
|
|
3136
|
+
viewport: this.viewport,
|
|
3137
|
+
type: "disable"
|
|
3138
|
+
});
|
|
3139
|
+
}
|
|
3140
|
+
return this;
|
|
3141
|
+
}
|
|
3142
|
+
enable(callback) {
|
|
3143
|
+
var _a;
|
|
3144
|
+
info == null ? void 0 : info(`enable #${this.viewport}, current status ${__privateGet(this, _status)}`);
|
|
3145
|
+
if (this.viewport && (__privateGet(this, _status) === "disabled" || __privateGet(this, _status) === "disabling")) {
|
|
3146
|
+
__privateSet(this, _status, "enabling");
|
|
3147
|
+
if (callback) {
|
|
3148
|
+
this.clientCallback = callback;
|
|
3149
|
+
}
|
|
3150
|
+
(_a = this.server) == null ? void 0 : _a.send({
|
|
3151
|
+
viewport: this.viewport,
|
|
3152
|
+
type: "enable"
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3155
|
+
return this;
|
|
3156
|
+
}
|
|
3157
|
+
select(selected) {
|
|
3158
|
+
var _a;
|
|
3159
|
+
__privateSet(this, _selectedRowsCount, selected.length);
|
|
3160
|
+
if (this.viewport) {
|
|
3161
|
+
(_a = this.server) == null ? void 0 : _a.send({
|
|
3162
|
+
viewport: this.viewport,
|
|
3163
|
+
type: "select",
|
|
3164
|
+
selected
|
|
3165
|
+
});
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
openTreeNode(key) {
|
|
3169
|
+
var _a;
|
|
3170
|
+
if (this.viewport) {
|
|
3171
|
+
(_a = this.server) == null ? void 0 : _a.send({
|
|
3172
|
+
viewport: this.viewport,
|
|
3173
|
+
type: "openTreeNode",
|
|
3174
|
+
key
|
|
3175
|
+
});
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
closeTreeNode(key) {
|
|
3179
|
+
var _a;
|
|
3180
|
+
if (this.viewport) {
|
|
3181
|
+
(_a = this.server) == null ? void 0 : _a.send({
|
|
3182
|
+
viewport: this.viewport,
|
|
3183
|
+
type: "closeTreeNode",
|
|
3184
|
+
key
|
|
3185
|
+
});
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
get links() {
|
|
3189
|
+
return __privateGet(this, _links);
|
|
3190
|
+
}
|
|
3191
|
+
get menu() {
|
|
3192
|
+
return __privateGet(this, _menu);
|
|
3193
|
+
}
|
|
3194
|
+
get status() {
|
|
3195
|
+
return __privateGet(this, _status);
|
|
3196
|
+
}
|
|
3197
|
+
get optimize() {
|
|
3198
|
+
return __privateGet(this, _optimize);
|
|
3199
|
+
}
|
|
3200
|
+
set optimize(optimize) {
|
|
3201
|
+
if (optimize !== __privateGet(this, _optimize)) {
|
|
3202
|
+
__privateSet(this, _optimize, optimize);
|
|
3203
|
+
switch (optimize) {
|
|
3204
|
+
case "none":
|
|
3205
|
+
this.rangeRequest = this.rawRangeRequest;
|
|
3206
|
+
break;
|
|
3207
|
+
case "debounce":
|
|
3208
|
+
this.rangeRequest = this.debounceRangeRequest;
|
|
3209
|
+
break;
|
|
3210
|
+
case "throttle":
|
|
3211
|
+
this.rangeRequest = this.throttleRangeRequest;
|
|
3212
|
+
break;
|
|
3213
|
+
}
|
|
3214
|
+
this.emit("optimize", optimize);
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
get selectedRowsCount() {
|
|
3218
|
+
return __privateGet(this, _selectedRowsCount);
|
|
3219
|
+
}
|
|
3220
|
+
get size() {
|
|
3221
|
+
return __privateGet(this, _size);
|
|
3222
|
+
}
|
|
3223
|
+
get range() {
|
|
3224
|
+
return __privateGet(this, _range);
|
|
3225
|
+
}
|
|
3226
|
+
set range(range) {
|
|
3227
|
+
if (range.from !== __privateGet(this, _range).from || range.to !== __privateGet(this, _range).to) {
|
|
3228
|
+
__privateSet(this, _range, range);
|
|
3229
|
+
this.rangeRequest(range);
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3232
|
+
get config() {
|
|
3233
|
+
return __privateGet(this, _config);
|
|
3234
|
+
}
|
|
3235
|
+
set config(config) {
|
|
3236
|
+
var _a;
|
|
3237
|
+
if (this.applyConfig(config)) {
|
|
3238
|
+
if (__privateGet(this, _config) && this.viewport && this.server) {
|
|
3239
|
+
if (config) {
|
|
3240
|
+
(_a = this.server) == null ? void 0 : _a.send({
|
|
3241
|
+
viewport: this.viewport,
|
|
3242
|
+
type: "config",
|
|
3243
|
+
config: __privateGet(this, _config)
|
|
3244
|
+
});
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
this.emit("config", __privateGet(this, _config));
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
applyConfig(config) {
|
|
3251
|
+
var _a;
|
|
3252
|
+
if ((0, import_vuu_utils2.configChanged)(__privateGet(this, _config), config)) {
|
|
3253
|
+
if (config) {
|
|
3254
|
+
const newConfig = ((_a = config == null ? void 0 : config.filter) == null ? void 0 : _a.filter) && (config == null ? void 0 : config.filter.filterStruct) === void 0 ? {
|
|
3255
|
+
...config,
|
|
3256
|
+
filter: {
|
|
3257
|
+
filter: config.filter.filter,
|
|
3258
|
+
filterStruct: (0, import_vuu_filter_parser.parseFilter)(config.filter.filter)
|
|
3259
|
+
}
|
|
3260
|
+
} : config;
|
|
3261
|
+
__privateSet(this, _config, (0, import_vuu_utils2.withConfigDefaults)(newConfig));
|
|
3262
|
+
return true;
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
//TODO replace all these individual server calls with calls to setConfig
|
|
3267
|
+
get columns() {
|
|
3268
|
+
return __privateGet(this, _config).columns;
|
|
3269
|
+
}
|
|
3270
|
+
set columns(columns) {
|
|
3271
|
+
__privateSet(this, _config, {
|
|
3272
|
+
...__privateGet(this, _config),
|
|
3273
|
+
columns
|
|
3274
|
+
});
|
|
3275
|
+
if (this.viewport) {
|
|
3276
|
+
const message = {
|
|
3277
|
+
viewport: this.viewport,
|
|
3278
|
+
type: "setColumns",
|
|
3279
|
+
columns
|
|
3280
|
+
};
|
|
3281
|
+
if (this.server) {
|
|
3282
|
+
this.server.send(message);
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
this.emit("config", __privateGet(this, _config));
|
|
3286
|
+
}
|
|
3287
|
+
get aggregations() {
|
|
3288
|
+
return __privateGet(this, _config).aggregations;
|
|
3289
|
+
}
|
|
3290
|
+
set aggregations(aggregations) {
|
|
3291
|
+
var _a;
|
|
3292
|
+
__privateSet(this, _config, {
|
|
3293
|
+
...__privateGet(this, _config),
|
|
3294
|
+
aggregations
|
|
3295
|
+
});
|
|
3296
|
+
if (this.viewport) {
|
|
3297
|
+
(_a = this.server) == null ? void 0 : _a.send({
|
|
3298
|
+
viewport: this.viewport,
|
|
3299
|
+
type: "aggregate",
|
|
3300
|
+
aggregations
|
|
3301
|
+
});
|
|
3302
|
+
}
|
|
3303
|
+
this.emit("config", __privateGet(this, _config));
|
|
3304
|
+
}
|
|
3305
|
+
get sort() {
|
|
3306
|
+
return __privateGet(this, _config).sort;
|
|
3307
|
+
}
|
|
3308
|
+
set sort(sort) {
|
|
3309
|
+
__privateSet(this, _config, {
|
|
3310
|
+
...__privateGet(this, _config),
|
|
3311
|
+
sort
|
|
3312
|
+
});
|
|
3313
|
+
if (this.viewport) {
|
|
3314
|
+
const message = {
|
|
3315
|
+
viewport: this.viewport,
|
|
3316
|
+
type: "sort",
|
|
3317
|
+
sort
|
|
3318
|
+
};
|
|
3319
|
+
if (this.server) {
|
|
3320
|
+
this.server.send(message);
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3323
|
+
this.emit("config", __privateGet(this, _config));
|
|
3324
|
+
}
|
|
3325
|
+
get filter() {
|
|
3326
|
+
return __privateGet(this, _config).filter;
|
|
3327
|
+
}
|
|
3328
|
+
set filter(filter) {
|
|
3329
|
+
__privateSet(this, _config, {
|
|
3330
|
+
...__privateGet(this, _config),
|
|
3331
|
+
filter
|
|
3332
|
+
});
|
|
3333
|
+
if (this.viewport) {
|
|
3334
|
+
const message = {
|
|
3335
|
+
viewport: this.viewport,
|
|
3336
|
+
type: "filter",
|
|
3337
|
+
filter
|
|
3338
|
+
};
|
|
3339
|
+
if (this.server) {
|
|
3340
|
+
this.server.send(message);
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
this.emit("config", __privateGet(this, _config));
|
|
3344
|
+
}
|
|
3345
|
+
get groupBy() {
|
|
3346
|
+
return __privateGet(this, _config).groupBy;
|
|
3347
|
+
}
|
|
3348
|
+
set groupBy(groupBy) {
|
|
3349
|
+
var _a;
|
|
3350
|
+
if ((0, import_vuu_utils2.itemsOrOrderChanged)(this.groupBy, groupBy)) {
|
|
3351
|
+
const wasGrouped = __privateGet(this, _groupBy).length > 0;
|
|
3352
|
+
__privateSet(this, _config, {
|
|
3353
|
+
...__privateGet(this, _config),
|
|
3354
|
+
groupBy
|
|
3355
|
+
});
|
|
3356
|
+
if (this.viewport) {
|
|
3357
|
+
const message = {
|
|
3358
|
+
viewport: this.viewport,
|
|
3359
|
+
type: "groupBy",
|
|
3360
|
+
groupBy: __privateGet(this, _config).groupBy
|
|
3361
|
+
};
|
|
3362
|
+
if (this.server) {
|
|
3363
|
+
this.server.send(message);
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
if (!wasGrouped && groupBy.length > 0 && this.viewport) {
|
|
3367
|
+
(_a = this.clientCallback) == null ? void 0 : _a.call(this, {
|
|
3368
|
+
clientViewportId: this.viewport,
|
|
3369
|
+
mode: "batch",
|
|
3370
|
+
type: "viewport-update",
|
|
3371
|
+
size: 0,
|
|
3372
|
+
rows: []
|
|
3373
|
+
});
|
|
3374
|
+
}
|
|
3375
|
+
this.emit("config", __privateGet(this, _config));
|
|
3376
|
+
this.setConfigPending({ groupBy });
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
get title() {
|
|
3380
|
+
return __privateGet(this, _title);
|
|
3381
|
+
}
|
|
3382
|
+
set title(title) {
|
|
3383
|
+
var _a;
|
|
3384
|
+
__privateSet(this, _title, title);
|
|
3385
|
+
if (this.viewport && title) {
|
|
3386
|
+
(_a = this.server) == null ? void 0 : _a.send({
|
|
3387
|
+
type: "setTitle",
|
|
3388
|
+
title,
|
|
3389
|
+
viewport: this.viewport
|
|
3390
|
+
});
|
|
3391
|
+
}
|
|
3392
|
+
}
|
|
3393
|
+
get visualLink() {
|
|
3394
|
+
return __privateGet(this, _config).visualLink;
|
|
3395
|
+
}
|
|
3396
|
+
set visualLink(visualLink) {
|
|
3397
|
+
var _a, _b;
|
|
3398
|
+
__privateSet(this, _config, {
|
|
3399
|
+
...__privateGet(this, _config),
|
|
3400
|
+
visualLink
|
|
3401
|
+
});
|
|
3402
|
+
if (visualLink) {
|
|
3403
|
+
const {
|
|
3404
|
+
parentClientVpId,
|
|
3405
|
+
link: { fromColumn, toColumn }
|
|
3406
|
+
} = visualLink;
|
|
3407
|
+
if (this.viewport) {
|
|
3408
|
+
(_a = this.server) == null ? void 0 : _a.send({
|
|
3409
|
+
viewport: this.viewport,
|
|
3410
|
+
type: "createLink",
|
|
3411
|
+
parentClientVpId,
|
|
3412
|
+
parentColumnName: toColumn,
|
|
3413
|
+
childColumnName: fromColumn
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3416
|
+
} else {
|
|
3417
|
+
if (this.viewport) {
|
|
3418
|
+
(_b = this.server) == null ? void 0 : _b.send({
|
|
3419
|
+
type: "removeLink",
|
|
3420
|
+
viewport: this.viewport
|
|
3421
|
+
});
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
this.emit("config", __privateGet(this, _config));
|
|
3425
|
+
}
|
|
3426
|
+
setConfigPending(config) {
|
|
3427
|
+
const pendingConfig = this.configChangePending;
|
|
3428
|
+
this.configChangePending = config;
|
|
3429
|
+
if (config !== void 0) {
|
|
3430
|
+
this.emit("config", config, false);
|
|
3431
|
+
} else {
|
|
3432
|
+
this.emit("config", pendingConfig, true);
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
async rpcCall(rpcRequest) {
|
|
3436
|
+
var _a;
|
|
3437
|
+
if (this.viewport) {
|
|
3438
|
+
return (_a = this.server) == null ? void 0 : _a.rpcCall({
|
|
3439
|
+
vpId: this.viewport,
|
|
3440
|
+
...rpcRequest
|
|
3441
|
+
});
|
|
3442
|
+
}
|
|
3443
|
+
}
|
|
3444
|
+
async menuRpcCall(rpcRequest) {
|
|
3445
|
+
var _a;
|
|
3446
|
+
if (this.viewport) {
|
|
3447
|
+
return (_a = this.server) == null ? void 0 : _a.rpcCall({
|
|
3448
|
+
vpId: this.viewport,
|
|
3449
|
+
...rpcRequest
|
|
3450
|
+
});
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
applyEdit(row, columnName, value) {
|
|
3454
|
+
return this.menuRpcCall({
|
|
3455
|
+
rowKey: row[KEY],
|
|
3456
|
+
field: columnName,
|
|
3457
|
+
value,
|
|
3458
|
+
type: "VP_EDIT_CELL_RPC"
|
|
3459
|
+
}).then((response) => {
|
|
3460
|
+
if (response == null ? void 0 : response.error) {
|
|
3461
|
+
return response.error;
|
|
3462
|
+
} else {
|
|
3463
|
+
return true;
|
|
3464
|
+
}
|
|
3465
|
+
});
|
|
3466
|
+
}
|
|
3467
|
+
insertRow(key, data) {
|
|
3468
|
+
return this.menuRpcCall({
|
|
3469
|
+
rowKey: key,
|
|
3470
|
+
data,
|
|
3471
|
+
type: "VP_EDIT_ADD_ROW_RPC"
|
|
3472
|
+
}).then((response) => {
|
|
3473
|
+
if (response == null ? void 0 : response.error) {
|
|
3474
|
+
return response.error;
|
|
3475
|
+
} else {
|
|
3476
|
+
return true;
|
|
3477
|
+
}
|
|
3478
|
+
});
|
|
3479
|
+
}
|
|
3480
|
+
deleteRow(rowKey) {
|
|
3481
|
+
return this.menuRpcCall({
|
|
3482
|
+
rowKey,
|
|
3483
|
+
type: "VP_EDIT_DELETE_ROW_RPC"
|
|
3484
|
+
}).then((response) => {
|
|
3485
|
+
if (response == null ? void 0 : response.error) {
|
|
3486
|
+
return response.error;
|
|
3487
|
+
} else {
|
|
3488
|
+
return true;
|
|
3489
|
+
}
|
|
3490
|
+
});
|
|
3491
|
+
}
|
|
3492
|
+
};
|
|
3493
|
+
_config = new WeakMap();
|
|
3494
|
+
_groupBy = new WeakMap();
|
|
3495
|
+
_links = new WeakMap();
|
|
3496
|
+
_menu = new WeakMap();
|
|
3497
|
+
_optimize = new WeakMap();
|
|
3498
|
+
_range = new WeakMap();
|
|
3499
|
+
_selectedRowsCount = new WeakMap();
|
|
3500
|
+
_size = new WeakMap();
|
|
3501
|
+
_status = new WeakMap();
|
|
3502
|
+
_title = new WeakMap();
|
|
2
3503
|
//# sourceMappingURL=index.js.map
|