@vuu-ui/vuu-data-remote 0.10.9 → 0.11.0

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.
Files changed (37) hide show
  1. package/cjs/VuuDataSource.js +0 -1
  2. package/cjs/VuuDataSource.js.map +1 -1
  3. package/cjs/WebSocketConnection.js.map +1 -1
  4. package/cjs/index.js +1 -0
  5. package/cjs/index.js.map +1 -1
  6. package/cjs/inlined-worker.js +78 -38
  7. package/cjs/inlined-worker.js.map +1 -1
  8. package/cjs/message-utils.js +39 -1
  9. package/cjs/message-utils.js.map +1 -1
  10. package/esm/VuuDataSource.js +0 -1
  11. package/esm/VuuDataSource.js.map +1 -1
  12. package/esm/WebSocketConnection.js.map +1 -1
  13. package/esm/index.js +1 -1
  14. package/esm/inlined-worker.js +78 -38
  15. package/esm/inlined-worker.js.map +1 -1
  16. package/esm/message-utils.js +39 -2
  17. package/esm/message-utils.js.map +1 -1
  18. package/package.json +10 -13
  19. package/types/ConnectionManager.d.ts +0 -33
  20. package/types/DedicatedWorker.d.ts +0 -9
  21. package/types/VuuDataSource.d.ts +0 -53
  22. package/types/WebSocketConnection.d.ts +0 -68
  23. package/types/authenticate.d.ts +0 -1
  24. package/types/constants.d.ts +0 -41
  25. package/types/data-source.d.ts +0 -5
  26. package/types/index.d.ts +0 -9
  27. package/types/inlined-worker.d.ts +0 -1
  28. package/types/message-utils.d.ts +0 -10
  29. package/types/rest-data/RestDataSource.d.ts +0 -42
  30. package/types/rest-data/moving-window.d.ts +0 -14
  31. package/types/rest-data/rest-utils.d.ts +0 -14
  32. package/types/server-proxy/array-backed-moving-window.d.ts +0 -28
  33. package/types/server-proxy/messages.d.ts +0 -38
  34. package/types/server-proxy/rpc-services.d.ts +0 -2
  35. package/types/server-proxy/server-proxy.d.ts +0 -64
  36. package/types/server-proxy/viewport.d.ts +0 -118
  37. package/types/worker.d.ts +0 -1
@@ -116,7 +116,6 @@ class VuuDataSource extends vuuUtils.BaseDataSource {
116
116
  }
117
117
  async subscribe(subscribeProps, callback) {
118
118
  super.subscribe(subscribeProps, callback);
119
- console.log(`%cVuuDataSource subscribe`, "color: blue;font-weight:bold;");
120
119
  const {
121
120
  selectedIndexValues,
122
121
  viewport = this.viewport || (this.viewport = vuuUtils.uuid())
@@ -1 +1 @@
1
- {"version":3,"file":"VuuDataSource.js","sources":["../src/VuuDataSource.ts"],"sourcesContent":["import {\n DataSource,\n DataSourceCallbackMessage,\n DataSourceConstructorProps,\n DataSourceStatus,\n DataSourceVisualLinkCreatedMessage,\n OptimizeStrategy,\n Selection,\n ServerAPI,\n SubscribeCallback,\n SubscribeProps,\n TableSchema,\n WithBaseFilter,\n WithFullConfig,\n} from \"@vuu-ui/vuu-data-types\";\nimport {\n LinkDescriptorWithLabel,\n VuuCreateVisualLink,\n VuuDataRowDto,\n VuuGroupBy,\n VuuMenu,\n VuuRange,\n VuuRowDataItemType,\n VuuRpcMenuRequest,\n VuuRpcRequest,\n VuuRpcResponse,\n VuuRpcViewportRequest,\n VuuTable,\n} from \"@vuu-ui/vuu-protocol-types\";\n\nimport {\n BaseDataSource,\n combineFilters,\n debounce,\n isViewportMenusAction,\n isVisualLinksAction,\n itemsOrOrderChanged,\n logger,\n selectionCount,\n throttle,\n uuid,\n vuuAddRowRequest,\n vuuDeleteRowRequest,\n vuuEditCellRequest,\n} from \"@vuu-ui/vuu-utils\";\nimport ConnectionManager from \"./ConnectionManager\";\nimport { isDataSourceConfigMessage } from \"./data-source\";\n\nimport { MenuRpcResponse } from \"@vuu-ui/vuu-data-types\";\n\ntype RangeRequest = (range: VuuRange) => void;\n\nconst { info, infoEnabled } = logger(\"VuuDataSource\");\n\n/*---------------------------------------------------------------------\n A VuuDataSource manages a single subscription via the ServerProxy\n ---------------------------------------------------------------------*/\nexport class VuuDataSource extends BaseDataSource implements DataSource {\n private bufferSize: number;\n private server: ServerAPI | null = null;\n rangeRequest: RangeRequest;\n\n #pendingVisualLink?: LinkDescriptorWithLabel;\n #links: LinkDescriptorWithLabel[] | undefined;\n #menu: VuuMenu | undefined;\n #optimize: OptimizeStrategy = \"throttle\";\n #selectedRowsCount = 0;\n #status: DataSourceStatus = \"initialising\";\n #tableSchema: TableSchema | undefined;\n\n public table: VuuTable;\n\n constructor(props: DataSourceConstructorProps) {\n super(props);\n\n const { bufferSize = 100, table, visualLink } = props;\n\n if (!table)\n throw Error(\"RemoteDataSource constructor called without table\");\n\n this.bufferSize = bufferSize;\n this.table = table;\n\n this.#pendingVisualLink = visualLink;\n\n // this.rangeRequest = this.throttleRangeRequest;\n this.rangeRequest = this.rawRangeRequest;\n }\n\n async subscribe(subscribeProps: SubscribeProps, callback: SubscribeCallback) {\n super.subscribe(subscribeProps, callback);\n console.log(`%cVuuDataSource subscribe`, \"color: blue;font-weight:bold;\");\n const {\n selectedIndexValues,\n viewport = this.viewport || (this.viewport = uuid()),\n } = subscribeProps;\n\n if (this.#status === \"disabled\" || this.#status === \"disabling\") {\n this.enable(callback);\n return;\n }\n\n if (\n this.#status !== \"initialising\" &&\n this.#status !== \"unsubscribed\"\n // We can subscribe to a disabled dataSource. No request will be\n // sent to server to create a new VP, just to enable the existing one.\n // The current subscribing client becomes the subscription owner\n ) {\n return;\n }\n\n this.#status = \"subscribing\";\n this.#selectedRowsCount = selectionCount(selectedIndexValues);\n\n this.server = await ConnectionManager.serverAPI;\n\n const { bufferSize } = this;\n\n // TODO and await response here\n\n const dataSourceConfig = combineFilters(this.config);\n\n this.server?.subscribe(\n {\n ...dataSourceConfig,\n bufferSize,\n range: this._range,\n selectedIndexValues: selectedIndexValues,\n table: this.table,\n title: this._title,\n viewport,\n },\n this.handleMessageFromServer,\n );\n }\n\n handleMessageFromServer = (message: DataSourceCallbackMessage) => {\n if (message.type === \"subscribed\") {\n this.#status = \"subscribed\";\n this.tableSchema = message.tableSchema;\n this._clientCallback?.(message);\n if (this.#pendingVisualLink) {\n this.visualLink = this.#pendingVisualLink;\n this.#pendingVisualLink = undefined;\n }\n this.emit(\"subscribed\", message);\n } else if (message.type === \"disabled\") {\n this.#status = \"disabled\";\n } else if (message.type === \"enabled\") {\n this.#status = \"enabled\";\n } else if (isDataSourceConfigMessage(message)) {\n // This is an ACK for a CHANGE_VP message. Nothing to do here. We need\n // to wait for data to be returned before we can consider the change\n // to be in effect.\n return;\n } else if (message.type === \"debounce-begin\") {\n this.optimize = \"debounce\";\n } else {\n if (\n message.type === \"viewport-update\" &&\n message.size !== undefined &&\n message.size !== this.size\n ) {\n this.size = message.size;\n this.emit(\"resize\", message.size);\n } else if (message.type === \"viewport-clear\") {\n this.size = 0;\n this.emit(\"resize\", 0);\n }\n // This is used to remove any progress indication from the UI. We wait for actual data rather than\n // just the CHANGE_VP_SUCCESS ack as there is often a delay between receiving the ack and the data.\n // It may be a SIZE only message, eg in the case of removing a groupBy column from a multi-column\n // groupby, where no tree nodes are expanded.\n if (this.isAwaitingConfirmationOfConfigChange) {\n this.confirmConfigChange();\n }\n\n if (isViewportMenusAction(message)) {\n this.#menu = message.menu;\n } else if (isVisualLinksAction(message)) {\n this.#links = message.links as LinkDescriptorWithLabel[];\n } else {\n if (infoEnabled && message.type === \"viewport-update\") {\n info(\n `handleMessageFromServer<viewport-update> range (${message.range?.from}:${message.range?.to}) rows ${message.rows?.at(0)?.[0]} - ${message.rows?.at(-1)?.[0]}`,\n );\n }\n this._clientCallback?.(message);\n }\n\n if (this.optimize === \"debounce\") {\n this.revertDebounce();\n }\n }\n };\n\n unsubscribe() {\n if (this.#status !== \"unsubscribed\") {\n info?.(`unsubscribe #${this.viewport}`);\n if (this.viewport) {\n this.server?.unsubscribe(this.viewport);\n this.emit(\"unsubscribed\", this.viewport);\n }\n this.server?.destroy(this.viewport);\n this.server = null;\n this.removeAllListeners();\n this.#status = \"unsubscribed\";\n this.viewport = \"\";\n this.range = { from: 0, to: 0 };\n }\n }\n\n suspend() {\n if (this.#status !== \"unsubscribed\") {\n info?.(`suspend #${this.viewport}, current status ${this.#status}`);\n if (this.viewport) {\n this.#status = \"suspended\";\n this.server?.send({\n type: \"suspend\",\n viewport: this.viewport,\n });\n this.emit(\"suspended\", this.viewport);\n }\n }\n }\n\n resume(callback?: SubscribeCallback) {\n const isDisabled = this.#status.startsWith(\"disabl\");\n const isSuspended = this.#status === \"suspended\";\n info?.(`resume #${this.viewport}, current status ${this.#status}`);\n if (callback) {\n this._clientCallback = callback;\n }\n if (this.viewport) {\n if (isDisabled) {\n this.enable();\n } else if (isSuspended) {\n this.server?.send({\n type: \"resume\",\n viewport: this.viewport,\n });\n this.#status = \"subscribed\";\n this.emit(\"resumed\", this.viewport);\n }\n }\n }\n\n disable() {\n info?.(`disable #${this.viewport}, current status ${this.#status}`);\n if (this.viewport) {\n this.#status = \"disabling\";\n this.server?.send({\n viewport: this.viewport,\n type: \"disable\",\n });\n this.emit(\"disabled\", this.viewport);\n }\n }\n\n enable(callback?: SubscribeCallback) {\n info?.(`enable #${this.viewport}, current status ${this.#status}`);\n if (\n this.viewport &&\n (this.#status === \"disabled\" || this.#status === \"disabling\")\n ) {\n this.#status = \"enabling\";\n if (callback) {\n this._clientCallback = callback;\n }\n this.server?.send({\n viewport: this.viewport,\n type: \"enable\",\n });\n this.emit(\"enabled\", this.viewport);\n }\n }\n\n select(selected: Selection) {\n this.#selectedRowsCount = selectionCount(selected);\n if (this.viewport) {\n this.server?.send({\n viewport: this.viewport,\n type: \"select\",\n selected,\n });\n this.emit(\"row-selection\", selected, this.#selectedRowsCount);\n }\n }\n\n openTreeNode(keyOrIndex: string | number) {\n if (this.viewport) {\n const [key, index] =\n typeof keyOrIndex === \"string\" ? [keyOrIndex] : [undefined, keyOrIndex];\n this.server?.send({\n index,\n key,\n type: \"openTreeNode\",\n viewport: this.viewport,\n });\n }\n }\n\n closeTreeNode(keyOrIndex: string | number) {\n if (this.viewport) {\n const [key, index] =\n typeof keyOrIndex === \"string\" ? [keyOrIndex] : [undefined, keyOrIndex];\n this.server?.send({\n index,\n key,\n type: \"closeTreeNode\",\n viewport: this.viewport,\n });\n }\n }\n\n get tableSchema() {\n return this.#tableSchema;\n }\n\n set tableSchema(tableSchema: TableSchema | undefined) {\n this.#tableSchema = tableSchema;\n // TOSO emit an event\n }\n\n get links() {\n return this.#links;\n }\n\n get menu() {\n return this.#menu;\n }\n\n get status() {\n return this.#status;\n }\n\n get optimize() {\n return this.#optimize;\n }\n\n set optimize(optimize: OptimizeStrategy) {\n if (optimize !== this.#optimize) {\n this.#optimize = optimize;\n switch (optimize) {\n case \"none\":\n this.rangeRequest = this.rawRangeRequest;\n break;\n case \"debounce\":\n this.rangeRequest = this.debounceRangeRequest;\n break;\n case \"throttle\":\n this.rangeRequest = this.throttleRangeRequest;\n break;\n }\n this.emit(\"optimize\", optimize);\n }\n }\n\n private revertDebounce = debounce(() => {\n this.optimize = \"throttle\";\n }, 100);\n\n get selectedRowsCount() {\n return this.#selectedRowsCount;\n }\n\n private rawRangeRequest: RangeRequest = (range) => {\n if (this.viewport && this.server) {\n this.server.send({\n viewport: this.viewport,\n type: \"setViewRange\",\n range,\n });\n }\n };\n\n private debounceRangeRequest: RangeRequest = debounce((range: VuuRange) => {\n if (this.viewport && this.server) {\n this.server.send({\n viewport: this.viewport,\n type: \"setViewRange\",\n range,\n });\n }\n }, 50);\n\n private throttleRangeRequest: RangeRequest = throttle((range: VuuRange) => {\n if (this.viewport && this.server) {\n this.server.send({\n viewport: this.viewport,\n type: \"setViewRange\",\n range,\n });\n }\n }, 80);\n\n get config() {\n return super.config;\n }\n\n set config(config: WithBaseFilter<WithFullConfig>) {\n if (config !== this.config) {\n super.config = config;\n this.server?.send({\n viewport: this.viewport,\n type: \"config\",\n config: combineFilters(this._config),\n });\n }\n }\n\n set impendingConfig(config: WithBaseFilter<WithFullConfig>) {\n if (config !== this.config) {\n super.impendingConfig = config;\n this.server?.send({\n viewport: this.viewport,\n type: \"config\",\n config: combineFilters(this.config),\n });\n }\n }\n\n get groupBy() {\n return this._config.groupBy;\n }\n\n set groupBy(groupBy: VuuGroupBy) {\n if (itemsOrOrderChanged(this.groupBy, groupBy)) {\n const wasGrouped = this.groupBy.length > 0;\n\n this.impendingConfig = {\n ...this._config,\n groupBy,\n };\n\n if (!wasGrouped && groupBy.length > 0 && this.viewport) {\n this._clientCallback?.({\n clientViewportId: this.viewport,\n mode: \"batch\",\n type: \"viewport-update\",\n size: 0,\n rows: [],\n });\n }\n }\n }\n\n get title() {\n return super.title || `${this.table.module} ${this.table.table}`;\n }\n\n set title(title: string) {\n super.title = title;\n if (this.viewport && title) {\n // This message doesn't actually trigger a message to Vuu server\n // it will be used to recompute visual link labels\n this.server?.send({\n type: \"setTitle\",\n title,\n viewport: this.viewport,\n });\n }\n }\n\n get visualLink() {\n return this._config.visualLink;\n }\n\n set visualLink(visualLink: LinkDescriptorWithLabel | undefined) {\n this._config = {\n ...this._config,\n visualLink,\n };\n\n if (visualLink) {\n const {\n parentClientVpId,\n link: { fromColumn, toColumn },\n } = visualLink;\n\n if (this.viewport) {\n this.server\n ?.rpcCall<DataSourceVisualLinkCreatedMessage>({\n childColumnName: fromColumn,\n childVpId: this.viewport,\n parentColumnName: toColumn,\n parentVpId: parentClientVpId,\n type: \"CREATE_VISUAL_LINK\",\n } as VuuCreateVisualLink)\n .then((response) => {\n this.emit(\"visual-link-created\", response);\n });\n }\n } else {\n if (this.viewport) {\n this.server\n ?.rpcCall({\n type: \"REMOVE_VISUAL_LINK\",\n childVpId: this.viewport,\n })\n .then(() => {\n this.emit(\"visual-link-removed\");\n });\n }\n }\n\n this.emit(\"config\", this._config, this.range);\n }\n\n async remoteProcedureCall<T extends VuuRpcResponse = VuuRpcResponse>() {\n return Promise.reject<T>();\n }\n\n /** @deprecated */\n async rpcCall<T extends VuuRpcResponse = VuuRpcResponse>(\n rpcRequest: Omit<VuuRpcRequest, \"vpId\">,\n ) {\n if (this.viewport && this.server) {\n return this.server?.rpcCall<T>({\n ...rpcRequest,\n vpId: this.viewport,\n } as VuuRpcViewportRequest);\n } else {\n throw Error(`rpcCall server or viewport are undefined`);\n }\n }\n\n /** @deprecated */\n async menuRpcCall(rpcRequest: Omit<VuuRpcRequest, \"vpId\">) {\n if (this.viewport) {\n return this.server?.rpcCall<MenuRpcResponse>({\n ...rpcRequest,\n vpId: this.viewport,\n } as VuuRpcMenuRequest);\n }\n }\n\n applyEdit(rowKey: string, columnName: string, value: VuuRowDataItemType) {\n return this.menuRpcCall(vuuEditCellRequest(rowKey, columnName, value)).then(\n (response) => {\n if (response?.error) {\n return response.error;\n } else {\n return true;\n }\n },\n );\n }\n\n insertRow(rowKey: string, data: VuuDataRowDto) {\n return this.menuRpcCall(vuuAddRowRequest(rowKey, data)).then((response) => {\n if (response?.error) {\n return response.error;\n } else {\n return true;\n }\n });\n }\n deleteRow(rowKey: string) {\n return this.menuRpcCall(vuuDeleteRowRequest(rowKey)).then((response) => {\n if (response?.error) {\n return response.error;\n } else {\n return true;\n }\n });\n }\n}\n"],"names":["logger","BaseDataSource","isDataSourceConfigMessage","isViewportMenusAction","isVisualLinksAction","debounce","throttle","uuid","selectionCount","combineFilters","itemsOrOrderChanged","vuuEditCellRequest","vuuAddRowRequest","vuuDeleteRowRequest"],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAA,kBAAA,EAAA,MAAA,EAAA,KAAA,EAAA,SAAA,EAAA,kBAAA,EAAA,OAAA,EAAA,YAAA;AAoDA,MAAM,EAAE,IAAA,EAAM,WAAY,EAAA,GAAIA,gBAAO,eAAe,CAAA;AAK7C,MAAM,sBAAsBC,uBAAqC,CAAA;AAAA,EAetE,YAAY,KAAmC,EAAA;AAC7C,IAAA,KAAA,CAAM,KAAK,CAAA;AAfb,IAAQ,aAAA,CAAA,IAAA,EAAA,YAAA,CAAA;AACR,IAAA,aAAA,CAAA,IAAA,EAAQ,QAA2B,EAAA,IAAA,CAAA;AACnC,IAAA,aAAA,CAAA,IAAA,EAAA,cAAA,CAAA;AAEA,IAAA,YAAA,CAAA,IAAA,EAAA,kBAAA,CAAA;AACA,IAAA,YAAA,CAAA,IA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IAAO,OAAA,IAAA,CAAK,YAAYC,4BAAoB,CAAA,MAAM,CAAC,CAAE,CAAA,IAAA,CAAK,CAAC,QAAa,KAAA;AACtE,MAAA,IAAI,UAAU,KAAO,EAAA;AACnB,QAAA,OAAO,QAAS,CAAA,KAAA;AAAA,OACX,MAAA;AACL,QAAO,OAAA,IAAA;AAAA;AACT,KACD,CAAA;AAAA;AAEL;AA1fE,kBAAA,GAAA,IAAA,OAAA,EAAA;AACA,MAAA,GAAA,IAAA,OAAA,EAAA;AACA,KAAA,GAAA,IAAA,OAAA,EAAA;AACA,SAAA,GAAA,IAAA,OAAA,EAAA;AACA,kBAAA,GAAA,IAAA,OAAA,EAAA;AACA,OAAA,GAAA,IAAA,OAAA,EAAA;AACA,YAAA,GAAA,IAAA,OAAA,EAAA;;;;"}
1
+ {"version":3,"file":"VuuDataSource.js","sources":["../src/VuuDataSource.ts"],"sourcesContent":["import {\n DataSource,\n DataSourceCallbackMessage,\n DataSourceConstructorProps,\n DataSourceStatus,\n DataSourceVisualLinkCreatedMessage,\n OptimizeStrategy,\n Selection,\n ServerAPI,\n SubscribeCallback,\n SubscribeProps,\n TableSchema,\n WithBaseFilter,\n WithFullConfig,\n} from \"@vuu-ui/vuu-data-types\";\nimport {\n LinkDescriptorWithLabel,\n VuuCreateVisualLink,\n VuuDataRowDto,\n VuuGroupBy,\n VuuMenu,\n VuuRange,\n VuuRowDataItemType,\n VuuRpcMenuRequest,\n VuuRpcRequest,\n VuuRpcResponse,\n VuuRpcViewportRequest,\n VuuTable,\n} from \"@vuu-ui/vuu-protocol-types\";\n\nimport {\n BaseDataSource,\n combineFilters,\n debounce,\n isViewportMenusAction,\n isVisualLinksAction,\n itemsOrOrderChanged,\n logger,\n selectionCount,\n throttle,\n uuid,\n vuuAddRowRequest,\n vuuDeleteRowRequest,\n vuuEditCellRequest,\n} from \"@vuu-ui/vuu-utils\";\nimport ConnectionManager from \"./ConnectionManager\";\nimport { isDataSourceConfigMessage } from \"./data-source\";\n\nimport { MenuRpcResponse } from \"@vuu-ui/vuu-data-types\";\n\ntype RangeRequest = (range: VuuRange) => void;\n\nconst { info, infoEnabled } = logger(\"VuuDataSource\");\n\n/*---------------------------------------------------------------------\n A VuuDataSource manages a single subscription via the ServerProxy\n ---------------------------------------------------------------------*/\nexport class VuuDataSource extends BaseDataSource implements DataSource {\n private bufferSize: number;\n private server: ServerAPI | null = null;\n rangeRequest: RangeRequest;\n\n #pendingVisualLink?: LinkDescriptorWithLabel;\n #links: LinkDescriptorWithLabel[] | undefined;\n #menu: VuuMenu | undefined;\n #optimize: OptimizeStrategy = \"throttle\";\n #selectedRowsCount = 0;\n #status: DataSourceStatus = \"initialising\";\n #tableSchema: TableSchema | undefined;\n\n public table: VuuTable;\n\n constructor(props: DataSourceConstructorProps) {\n super(props);\n\n const { bufferSize = 100, table, visualLink } = props;\n\n if (!table)\n throw Error(\"RemoteDataSource constructor called without table\");\n\n this.bufferSize = bufferSize;\n this.table = table;\n\n this.#pendingVisualLink = visualLink;\n\n // this.rangeRequest = this.throttleRangeRequest;\n this.rangeRequest = this.rawRangeRequest;\n }\n\n async subscribe(subscribeProps: SubscribeProps, callback: SubscribeCallback) {\n super.subscribe(subscribeProps, callback);\n const {\n selectedIndexValues,\n viewport = this.viewport || (this.viewport = uuid()),\n } = subscribeProps;\n\n if (this.#status === \"disabled\" || this.#status === \"disabling\") {\n this.enable(callback);\n return;\n }\n\n if (\n this.#status !== \"initialising\" &&\n this.#status !== \"unsubscribed\"\n // We can subscribe to a disabled dataSource. No request will be\n // sent to server to create a new VP, just to enable the existing one.\n // The current subscribing client becomes the subscription owner\n ) {\n return;\n }\n\n this.#status = \"subscribing\";\n this.#selectedRowsCount = selectionCount(selectedIndexValues);\n\n this.server = await ConnectionManager.serverAPI;\n\n const { bufferSize } = this;\n\n // TODO and await response here\n\n const dataSourceConfig = combineFilters(this.config);\n\n this.server?.subscribe(\n {\n ...dataSourceConfig,\n bufferSize,\n range: this._range,\n selectedIndexValues: selectedIndexValues,\n table: this.table,\n title: this._title,\n viewport,\n },\n this.handleMessageFromServer,\n );\n }\n\n handleMessageFromServer = (message: DataSourceCallbackMessage) => {\n if (message.type === \"subscribed\") {\n this.#status = \"subscribed\";\n this.tableSchema = message.tableSchema;\n this._clientCallback?.(message);\n if (this.#pendingVisualLink) {\n this.visualLink = this.#pendingVisualLink;\n this.#pendingVisualLink = undefined;\n }\n this.emit(\"subscribed\", message);\n } else if (message.type === \"disabled\") {\n this.#status = \"disabled\";\n } else if (message.type === \"enabled\") {\n this.#status = \"enabled\";\n } else if (isDataSourceConfigMessage(message)) {\n // This is an ACK for a CHANGE_VP message. Nothing to do here. We need\n // to wait for data to be returned before we can consider the change\n // to be in effect.\n return;\n } else if (message.type === \"debounce-begin\") {\n this.optimize = \"debounce\";\n } else {\n if (\n message.type === \"viewport-update\" &&\n message.size !== undefined &&\n message.size !== this.size\n ) {\n this.size = message.size;\n this.emit(\"resize\", message.size);\n } else if (message.type === \"viewport-clear\") {\n this.size = 0;\n this.emit(\"resize\", 0);\n }\n // This is used to remove any progress indication from the UI. We wait for actual data rather than\n // just the CHANGE_VP_SUCCESS ack as there is often a delay between receiving the ack and the data.\n // It may be a SIZE only message, eg in the case of removing a groupBy column from a multi-column\n // groupby, where no tree nodes are expanded.\n if (this.isAwaitingConfirmationOfConfigChange) {\n this.confirmConfigChange();\n }\n\n if (isViewportMenusAction(message)) {\n this.#menu = message.menu;\n } else if (isVisualLinksAction(message)) {\n this.#links = message.links as LinkDescriptorWithLabel[];\n } else {\n if (infoEnabled && message.type === \"viewport-update\") {\n info(\n `handleMessageFromServer<viewport-update> range (${message.range?.from}:${message.range?.to}) rows ${message.rows?.at(0)?.[0]} - ${message.rows?.at(-1)?.[0]}`,\n );\n }\n this._clientCallback?.(message);\n }\n\n if (this.optimize === \"debounce\") {\n this.revertDebounce();\n }\n }\n };\n\n unsubscribe() {\n if (this.#status !== \"unsubscribed\") {\n info?.(`unsubscribe #${this.viewport}`);\n if (this.viewport) {\n this.server?.unsubscribe(this.viewport);\n this.emit(\"unsubscribed\", this.viewport);\n }\n this.server?.destroy(this.viewport);\n this.server = null;\n this.removeAllListeners();\n this.#status = \"unsubscribed\";\n this.viewport = \"\";\n this.range = { from: 0, to: 0 };\n }\n }\n\n suspend() {\n if (this.#status !== \"unsubscribed\") {\n info?.(`suspend #${this.viewport}, current status ${this.#status}`);\n if (this.viewport) {\n this.#status = \"suspended\";\n this.server?.send({\n type: \"suspend\",\n viewport: this.viewport,\n });\n this.emit(\"suspended\", this.viewport);\n }\n }\n }\n\n resume(callback?: SubscribeCallback) {\n const isDisabled = this.#status.startsWith(\"disabl\");\n const isSuspended = this.#status === \"suspended\";\n info?.(`resume #${this.viewport}, current status ${this.#status}`);\n if (callback) {\n this._clientCallback = callback;\n }\n if (this.viewport) {\n if (isDisabled) {\n this.enable();\n } else if (isSuspended) {\n this.server?.send({\n type: \"resume\",\n viewport: this.viewport,\n });\n this.#status = \"subscribed\";\n this.emit(\"resumed\", this.viewport);\n }\n }\n }\n\n disable() {\n info?.(`disable #${this.viewport}, current status ${this.#status}`);\n if (this.viewport) {\n this.#status = \"disabling\";\n this.server?.send({\n viewport: this.viewport,\n type: \"disable\",\n });\n this.emit(\"disabled\", this.viewport);\n }\n }\n\n enable(callback?: SubscribeCallback) {\n info?.(`enable #${this.viewport}, current status ${this.#status}`);\n if (\n this.viewport &&\n (this.#status === \"disabled\" || this.#status === \"disabling\")\n ) {\n this.#status = \"enabling\";\n if (callback) {\n this._clientCallback = callback;\n }\n this.server?.send({\n viewport: this.viewport,\n type: \"enable\",\n });\n this.emit(\"enabled\", this.viewport);\n }\n }\n\n select(selected: Selection) {\n this.#selectedRowsCount = selectionCount(selected);\n if (this.viewport) {\n this.server?.send({\n viewport: this.viewport,\n type: \"select\",\n selected,\n });\n this.emit(\"row-selection\", selected, this.#selectedRowsCount);\n }\n }\n\n openTreeNode(keyOrIndex: string | number) {\n if (this.viewport) {\n const [key, index] =\n typeof keyOrIndex === \"string\" ? [keyOrIndex] : [undefined, keyOrIndex];\n this.server?.send({\n index,\n key,\n type: \"openTreeNode\",\n viewport: this.viewport,\n });\n }\n }\n\n closeTreeNode(keyOrIndex: string | number) {\n if (this.viewport) {\n const [key, index] =\n typeof keyOrIndex === \"string\" ? [keyOrIndex] : [undefined, keyOrIndex];\n this.server?.send({\n index,\n key,\n type: \"closeTreeNode\",\n viewport: this.viewport,\n });\n }\n }\n\n get tableSchema() {\n return this.#tableSchema;\n }\n\n set tableSchema(tableSchema: TableSchema | undefined) {\n this.#tableSchema = tableSchema;\n // TOSO emit an event\n }\n\n get links() {\n return this.#links;\n }\n\n get menu() {\n return this.#menu;\n }\n\n get status() {\n return this.#status;\n }\n\n get optimize() {\n return this.#optimize;\n }\n\n set optimize(optimize: OptimizeStrategy) {\n if (optimize !== this.#optimize) {\n this.#optimize = optimize;\n switch (optimize) {\n case \"none\":\n this.rangeRequest = this.rawRangeRequest;\n break;\n case \"debounce\":\n this.rangeRequest = this.debounceRangeRequest;\n break;\n case \"throttle\":\n this.rangeRequest = this.throttleRangeRequest;\n break;\n }\n this.emit(\"optimize\", optimize);\n }\n }\n\n private revertDebounce = debounce(() => {\n this.optimize = \"throttle\";\n }, 100);\n\n get selectedRowsCount() {\n return this.#selectedRowsCount;\n }\n\n private rawRangeRequest: RangeRequest = (range) => {\n if (this.viewport && this.server) {\n this.server.send({\n viewport: this.viewport,\n type: \"setViewRange\",\n range,\n });\n }\n };\n\n private debounceRangeRequest: RangeRequest = debounce((range: VuuRange) => {\n if (this.viewport && this.server) {\n this.server.send({\n viewport: this.viewport,\n type: \"setViewRange\",\n range,\n });\n }\n }, 50);\n\n private throttleRangeRequest: RangeRequest = throttle((range: VuuRange) => {\n if (this.viewport && this.server) {\n this.server.send({\n viewport: this.viewport,\n type: \"setViewRange\",\n range,\n });\n }\n }, 80);\n\n get config() {\n return super.config;\n }\n\n set config(config: WithBaseFilter<WithFullConfig>) {\n if (config !== this.config) {\n super.config = config;\n this.server?.send({\n viewport: this.viewport,\n type: \"config\",\n config: combineFilters(this._config),\n });\n }\n }\n\n set impendingConfig(config: WithBaseFilter<WithFullConfig>) {\n if (config !== this.config) {\n super.impendingConfig = config;\n this.server?.send({\n viewport: this.viewport,\n type: \"config\",\n config: combineFilters(this.config),\n });\n }\n }\n\n get groupBy() {\n return this._config.groupBy;\n }\n\n set groupBy(groupBy: VuuGroupBy) {\n if (itemsOrOrderChanged(this.groupBy, groupBy)) {\n const wasGrouped = this.groupBy.length > 0;\n\n this.impendingConfig = {\n ...this._config,\n groupBy,\n };\n\n if (!wasGrouped && groupBy.length > 0 && this.viewport) {\n this._clientCallback?.({\n clientViewportId: this.viewport,\n mode: \"batch\",\n type: \"viewport-update\",\n size: 0,\n rows: [],\n });\n }\n }\n }\n\n get title() {\n return super.title || `${this.table.module} ${this.table.table}`;\n }\n\n set title(title: string) {\n super.title = title;\n if (this.viewport && title) {\n // This message doesn't actually trigger a message to Vuu server\n // it will be used to recompute visual link labels\n this.server?.send({\n type: \"setTitle\",\n title,\n viewport: this.viewport,\n });\n }\n }\n\n get visualLink() {\n return this._config.visualLink;\n }\n\n set visualLink(visualLink: LinkDescriptorWithLabel | undefined) {\n this._config = {\n ...this._config,\n visualLink,\n };\n\n if (visualLink) {\n const {\n parentClientVpId,\n link: { fromColumn, toColumn },\n } = visualLink;\n\n if (this.viewport) {\n this.server\n ?.rpcCall<DataSourceVisualLinkCreatedMessage>({\n childColumnName: fromColumn,\n childVpId: this.viewport,\n parentColumnName: toColumn,\n parentVpId: parentClientVpId,\n type: \"CREATE_VISUAL_LINK\",\n } as VuuCreateVisualLink)\n .then((response) => {\n this.emit(\"visual-link-created\", response);\n });\n }\n } else {\n if (this.viewport) {\n this.server\n ?.rpcCall({\n type: \"REMOVE_VISUAL_LINK\",\n childVpId: this.viewport,\n })\n .then(() => {\n this.emit(\"visual-link-removed\");\n });\n }\n }\n\n this.emit(\"config\", this._config, this.range);\n }\n\n async remoteProcedureCall<T extends VuuRpcResponse = VuuRpcResponse>() {\n return Promise.reject<T>();\n }\n\n /** @deprecated */\n async rpcCall<T extends VuuRpcResponse = VuuRpcResponse>(\n rpcRequest: Omit<VuuRpcRequest, \"vpId\">,\n ) {\n if (this.viewport && this.server) {\n return this.server?.rpcCall<T>({\n ...rpcRequest,\n vpId: this.viewport,\n } as VuuRpcViewportRequest);\n } else {\n throw Error(`rpcCall server or viewport are undefined`);\n }\n }\n\n /** @deprecated */\n async menuRpcCall(rpcRequest: Omit<VuuRpcRequest, \"vpId\">) {\n if (this.viewport) {\n return this.server?.rpcCall<MenuRpcResponse>({\n ...rpcRequest,\n vpId: this.viewport,\n } as VuuRpcMenuRequest);\n }\n }\n\n applyEdit(rowKey: string, columnName: string, value: VuuRowDataItemType) {\n return this.menuRpcCall(vuuEditCellRequest(rowKey, columnName, value)).then(\n (response) => {\n if (response?.error) {\n return response.error;\n } else {\n return true;\n }\n },\n );\n }\n\n insertRow(rowKey: string, data: VuuDataRowDto) {\n return this.menuRpcCall(vuuAddRowRequest(rowKey, data)).then((response) => {\n if (response?.error) {\n return response.error;\n } else {\n return true;\n }\n });\n }\n deleteRow(rowKey: string) {\n return this.menuRpcCall(vuuDeleteRowRequest(rowKey)).then((response) => {\n if (response?.error) {\n return response.error;\n } else {\n return true;\n }\n });\n }\n}\n"],"names":["logger","BaseDataSource","isDataSourceConfigMessage","isViewportMenusAction","isVisualLinksAction","debounce","throttle","uuid","selectionCount","combineFilters","itemsOrOrderChanged","vuuEditCellRequest","vuuAddRowRequest","vuuDeleteRowRequest"],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAA,kBAAA,EAAA,MAAA,EAAA,KAAA,EAAA,SAAA,EAAA,kBAAA,EAAA,OAAA,EAAA,YAAA;AAoDA,MAAM,EAAE,IAAA,EAAM,WAAY,EAAA,GAAIA,gBAAO,eAAe,CAAA;AAK7C,MAAM,sBAAsBC,uBAAqC,CAAA;AAAA,EAetE,YAAY,KAAmC,EAAA;AAC7C,IAAA,KAA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,CAAC,QAAa,KAAA;AACzE,MAAA,IAAI,UAAU,KAAO,EAAA;AACnB,QAAA,OAAO,QAAS,CAAA,KAAA;AAAA,OACX,MAAA;AACL,QAAO,OAAA,IAAA;AAAA;AACT,KACD,CAAA;AAAA;AACH,EACA,UAAU,MAAgB,EAAA;AACxB,IAAO,OAAA,IAAA,CAAK,YAAYC,4BAAoB,CAAA,MAAM,CAAC,CAAE,CAAA,IAAA,CAAK,CAAC,QAAa,KAAA;AACtE,MAAA,IAAI,UAAU,KAAO,EAAA;AACnB,QAAA,OAAO,QAAS,CAAA,KAAA;AAAA,OACX,MAAA;AACL,QAAO,OAAA,IAAA;AAAA;AACT,KACD,CAAA;AAAA;AAEL;AAzfE,kBAAA,GAAA,IAAA,OAAA,EAAA;AACA,MAAA,GAAA,IAAA,OAAA,EAAA;AACA,KAAA,GAAA,IAAA,OAAA,EAAA;AACA,SAAA,GAAA,IAAA,OAAA,EAAA;AACA,kBAAA,GAAA,IAAA,OAAA,EAAA;AACA,OAAA,GAAA,IAAA,OAAA,EAAA;AACA,YAAA,GAAA,IAAA,OAAA,EAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketConnection.js","sources":["../src/WebSocketConnection.ts"],"sourcesContent":["import { WebSocketProtocol } from \"@vuu-ui/vuu-data-types\";\nimport { VuuClientMessage, VuuServerMessage } from \"@vuu-ui/vuu-protocol-types\";\nimport { DeferredPromise, EventEmitter } from \"@vuu-ui/vuu-utils\";\n\nexport type ConnectingStatus = \"connecting\" | \"reconnecting\";\nexport type ConnectedStatus = \"connected\" | \"reconnected\";\nexport type ConnectionStatus =\n | ConnectedStatus\n | \"closed\"\n | \"connection-open-awaiting-session\"\n | \"disconnected\"\n | \"failed\"\n | \"inactive\";\n\ntype InternalConnectionStatus = ConnectionStatus | ConnectingStatus;\n\ntype ReconnectAttempts = {\n retryAttemptsTotal: number;\n retryAttemptsRemaining: number;\n secondsToNextRetry: number;\n};\n\nexport interface WebSocketConnectionState<\n T extends InternalConnectionStatus = ConnectionStatus,\n> extends ReconnectAttempts {\n connectionPhase: ConnectingStatus;\n connectionStatus: T;\n}\n\nconst isNotConnecting = (\n connectionState: WebSocketConnectionState<InternalConnectionStatus>,\n): connectionState is WebSocketConnectionState<ConnectionStatus> =>\n connectionState.connectionStatus !== \"connecting\" &&\n connectionState.connectionStatus !== \"reconnecting\";\n\nexport const isWebSocketConnectionMessage = (\n msg: object | WebSocketConnectionState,\n): msg is WebSocketConnectionState => {\n if (\"connectionStatus\" in msg) {\n return [\n \"connecting\",\n \"connected\",\n \"connection-open-awaiting-session\",\n \"reconnecting\",\n \"reconnected\",\n \"disconnected\",\n \"closed\",\n \"failed\",\n ].includes(msg.connectionStatus);\n } else {\n return false;\n }\n};\n\nexport type VuuServerMessageCallback = (msg: VuuServerMessage) => void;\n\nexport type RetryLimits = {\n connect: number;\n reconnect: number;\n};\n\nexport type WebSocketConnectionConfig = {\n url: string;\n protocols: WebSocketProtocol;\n callback: VuuServerMessageCallback;\n connectionTimeout?: number;\n retryLimits?: RetryLimits;\n};\n\nconst DEFAULT_RETRY_LIMITS: RetryLimits = {\n connect: 5,\n reconnect: 8,\n};\n\nconst DEFAULT_CONNECTION_TIMEOUT = 10000;\n\nconst ConnectingEndState: Record<ConnectingStatus, ConnectedStatus> = {\n connecting: \"connected\",\n reconnecting: \"reconnected\",\n} as const;\n\nconst parseWebSocketMessage = (message: string): VuuServerMessage => {\n try {\n return JSON.parse(message) as VuuServerMessage;\n } catch (e) {\n throw Error(`Error parsing JSON response from server ${message}`);\n }\n};\n\nexport type WebSocketConnectionCloseReason = \"failure\" | \"shutdown\";\nexport type WebSocketConnectionEvents = {\n closed: (reason: WebSocketConnectionCloseReason) => void;\n connected: () => void;\n \"connection-status\": (message: WebSocketConnectionState) => void;\n reconnected: () => void;\n};\n\nexport class WebSocketConnection extends EventEmitter<WebSocketConnectionEvents> {\n #callback;\n /**\n We are not confirmedOpen until we receive the first message from the\n server. If we get an unexpected close event before that, we consider\n the reconnect attempts as still within the connection phase, not true\n reconnection. This can happen e.g. when connecting to remote host via\n a proxy.\n */\n #confirmedOpen = false;\n #connectionState: WebSocketConnectionState<InternalConnectionStatus>;\n #connectionTimeout;\n #deferredConnection?: DeferredPromise;\n #protocols;\n #reconnectAttempts: ReconnectAttempts;\n #requiresLogin = true;\n #url;\n #ws?: WebSocket;\n\n constructor({\n callback,\n connectionTimeout = DEFAULT_CONNECTION_TIMEOUT,\n protocols,\n retryLimits = DEFAULT_RETRY_LIMITS,\n url,\n }: WebSocketConnectionConfig) {\n super();\n\n this.#callback = callback;\n this.#connectionTimeout = connectionTimeout;\n this.#url = url;\n this.#protocols = protocols;\n\n this.#reconnectAttempts = {\n retryAttemptsTotal: retryLimits.reconnect,\n retryAttemptsRemaining: retryLimits.reconnect,\n secondsToNextRetry: 1,\n };\n\n /**\n * Initial retryAttempts are for the 'connecting' phase. These will\n * be replaced with 'reconnecting' phase retry attempts only once\n * initial connection succeeds.\n */\n this.#connectionState = {\n connectionPhase: \"connecting\",\n connectionStatus: \"closed\",\n retryAttemptsTotal: retryLimits.connect,\n retryAttemptsRemaining: retryLimits.connect,\n secondsToNextRetry: 1,\n };\n }\n\n get connectionTimeout() {\n return this.#connectionTimeout;\n }\n\n get protocols() {\n return this.#protocols;\n }\n\n get requiresLogin() {\n return this.#requiresLogin;\n }\n\n get isClosed() {\n return this.status === \"closed\";\n }\n get isDisconnected() {\n return this.status === \"disconnected\";\n }\n\n get isConnecting() {\n return this.#connectionState.connectionPhase === \"connecting\";\n }\n\n get status() {\n return this.#connectionState.connectionStatus;\n }\n\n private set status(connectionStatus: InternalConnectionStatus) {\n this.#connectionState = {\n ...this.#connectionState,\n connectionStatus,\n };\n // we don't publish the connecting states. They have little meaning for clients\n // and are will generally be very short-lived.\n if (isNotConnecting(this.#connectionState)) {\n this.emit(\"connection-status\", this.#connectionState);\n }\n }\n\n get connectionState() {\n return this.#connectionState;\n }\n\n private get hasConnectionAttemptsRemaining() {\n return this.#connectionState.retryAttemptsRemaining > 0;\n }\n\n private get confirmedOpen() {\n return this.#confirmedOpen;\n }\n\n /**\n * We are 'confirmedOpen' when we see the first message transmitted\n * from the server. This ensures that even if we have one or more\n * proxies in our route to the endPoint, all connections have been\n * opened successfully.\n * First time in here (on our initial successful connection) we switch\n * from 'connect' phase to 'reconnect' phase. We may have different\n * retry configurations for these two phases.\n */\n private set confirmedOpen(confirmedOpen: boolean) {\n this.#confirmedOpen = confirmedOpen;\n\n if (confirmedOpen && this.isConnecting) {\n this.#connectionState = {\n ...this.#connectionState,\n connectionPhase: \"reconnecting\",\n ...this.#reconnectAttempts,\n };\n } else if (confirmedOpen) {\n // we have successfully reconnected after a failure.\n // Reset the retry attempts, ready for next failure\n // Note: this retry is shared with 'disconnected' status\n this.#connectionState = {\n ...this.#connectionState,\n ...this.#reconnectAttempts,\n };\n }\n }\n\n get url() {\n return this.#url;\n }\n\n async connect(clientCall = true) {\n const state = this.#connectionState;\n if (this.isConnecting && this.#deferredConnection === undefined) {\n // We block on the first connecting call, this will be the\n // initial connect call from app. Any other calls will be\n // reconnect attempts. The initial connecting call returns a promise.\n // This promise is resolved either on that initial call or on a\n // subsequent successful retry attempt within nthat same initial\n // connecting phase.\n this.#deferredConnection = new DeferredPromise();\n }\n const { connectionTimeout, protocols, url } = this;\n this.status = state.connectionPhase;\n const timer = setTimeout(() => {\n throw Error(\n `Failed to open WebSocket connection to ${url}, timed out after ${connectionTimeout}ms`,\n );\n }, connectionTimeout);\n\n const ws = (this.#ws = new WebSocket(url, protocols));\n\n ws.onopen = () => {\n const connectedStatus = ConnectingEndState[state.connectionPhase];\n this.status = connectedStatus;\n clearTimeout(timer);\n if (this.#deferredConnection) {\n this.#deferredConnection.resolve(undefined);\n this.#deferredConnection = undefined;\n }\n if (this.isConnecting) {\n this.emit(\"connected\");\n } else {\n this.emit(\"reconnected\");\n }\n console.log(\"connected\");\n };\n ws.onerror = () => {\n clearTimeout(timer);\n };\n\n ws.onclose = () => {\n if (!this.isClosed) {\n this.confirmedOpen = false;\n this.status = \"disconnected\";\n if (this.hasConnectionAttemptsRemaining) {\n this.reconnect();\n } else {\n this.close(\"failure\");\n }\n }\n };\n\n ws.onmessage = (evt) => {\n if (!this.confirmedOpen) {\n // Now that we are confirmedOpen any subsequent close events\n // will be treated as part of a reconnection phase.\n this.confirmedOpen = true;\n }\n this.receive(evt);\n };\n\n if (clientCall) {\n return this.#deferredConnection?.promise;\n }\n }\n\n private reconnect() {\n const { retryAttemptsRemaining, secondsToNextRetry } =\n this.#connectionState;\n setTimeout(() => {\n this.#connectionState = {\n ...this.#connectionState,\n retryAttemptsRemaining: retryAttemptsRemaining - 1,\n secondsToNextRetry: secondsToNextRetry * 2,\n };\n this.connect(false);\n }, secondsToNextRetry * 1000);\n }\n\n private receive = (evt: MessageEvent) => {\n const vuuMessageFromServer = parseWebSocketMessage(evt.data);\n this.#callback(vuuMessageFromServer);\n };\n\n send = (msg: VuuClientMessage) => {\n this.#ws?.send(JSON.stringify(msg));\n };\n\n close(reason: WebSocketConnectionCloseReason = \"shutdown\") {\n this.status = \"closed\";\n if (reason === \"failure\") {\n if (this.#deferredConnection) {\n this.#deferredConnection.reject(Error(\"connection failed\"));\n this.#deferredConnection = undefined;\n }\n } else {\n this.#ws?.close();\n }\n this.emit(\"closed\", reason);\n this.#ws = undefined;\n }\n}\n"],"names":[],"mappings":";;;;AAmCa,MAAA,4BAAA,GAA+B,CAC1C,GACoC,KAAA;AACpC,EAAA,IAAI,sBAAsB,GAAK,EAAA;AAC7B,IAAO,OAAA;AAAA,MACL,YAAA;AAAA,MACA,WAAA;AAAA,MACA,kCAAA;AAAA,MACA,cAAA;AAAA,MACA,aAAA;AAAA,MACA,cAAA;AAAA,MACA,QAAA;AAAA,MACA;AAAA,KACF,CAAE,QAAS,CAAA,GAAA,CAAI,gBAAgB,CAAA;AAAA,GAC1B,MAAA;AACL,IAAO,OAAA,KAAA;AAAA;AAEX;;;;"}
1
+ {"version":3,"file":"WebSocketConnection.js","sources":["../src/WebSocketConnection.ts"],"sourcesContent":["import { WebSocketProtocol } from \"@vuu-ui/vuu-data-types\";\nimport { VuuClientMessage, VuuServerMessage } from \"@vuu-ui/vuu-protocol-types\";\nimport { DeferredPromise, EventEmitter } from \"@vuu-ui/vuu-utils\";\n\nexport type ConnectingStatus = \"connecting\" | \"reconnecting\";\nexport type ConnectedStatus = \"connected\" | \"reconnected\";\nexport type ConnectionStatus =\n | ConnectedStatus\n | \"closed\"\n | \"connection-open-awaiting-session\"\n | \"disconnected\"\n | \"failed\"\n | \"inactive\";\n\ntype InternalConnectionStatus = ConnectionStatus | ConnectingStatus;\n\ntype ReconnectAttempts = {\n retryAttemptsTotal: number;\n retryAttemptsRemaining: number;\n secondsToNextRetry: number;\n};\n\nexport interface WebSocketConnectionState<\n T extends InternalConnectionStatus = ConnectionStatus,\n> extends ReconnectAttempts {\n connectionPhase: ConnectingStatus;\n connectionStatus: T;\n}\n\nconst isNotConnecting = (\n connectionState: WebSocketConnectionState<InternalConnectionStatus>,\n): connectionState is WebSocketConnectionState<ConnectionStatus> =>\n connectionState.connectionStatus !== \"connecting\" &&\n connectionState.connectionStatus !== \"reconnecting\";\n\nexport const isWebSocketConnectionMessage = (\n msg: object | WebSocketConnectionState,\n): msg is WebSocketConnectionState => {\n if (\"connectionStatus\" in msg) {\n return [\n \"connecting\",\n \"connected\",\n \"connection-open-awaiting-session\",\n \"reconnecting\",\n \"reconnected\",\n \"disconnected\",\n \"closed\",\n \"failed\",\n ].includes(msg.connectionStatus);\n } else {\n return false;\n }\n};\n\nexport type VuuServerMessageCallback = (msg: VuuServerMessage) => void;\n\nexport type RetryLimits = {\n connect: number;\n reconnect: number;\n};\n\nexport type WebSocketConnectionConfig = {\n url: string;\n protocols: WebSocketProtocol;\n callback: VuuServerMessageCallback;\n connectionTimeout?: number;\n retryLimits?: RetryLimits;\n};\n\nconst DEFAULT_RETRY_LIMITS: RetryLimits = {\n connect: 5,\n reconnect: 8,\n};\n\nconst DEFAULT_CONNECTION_TIMEOUT = 10000;\n\nconst ConnectingEndState: Record<ConnectingStatus, ConnectedStatus> = {\n connecting: \"connected\",\n reconnecting: \"reconnected\",\n} as const;\n\nconst parseWebSocketMessage = (message: string): VuuServerMessage => {\n try {\n return JSON.parse(message) as VuuServerMessage;\n } catch (e) {\n throw Error(`Error parsing JSON response from server ${message}`);\n }\n};\n\nexport type WebSocketConnectionCloseReason = \"failure\" | \"shutdown\";\nexport type WebSocketConnectionEvents = {\n closed: (reason: WebSocketConnectionCloseReason) => void;\n connected: () => void;\n \"connection-status\": (message: WebSocketConnectionState) => void;\n reconnected: () => void;\n};\n\nexport class WebSocketConnection extends EventEmitter<WebSocketConnectionEvents> {\n #callback;\n /**\n We are not confirmedOpen until we receive the first message from the\n server. If we get an unexpected close event before that, we consider\n the reconnect attempts as still within the connection phase, not true\n reconnection. This can happen e.g. when connecting to remote host via\n a proxy.\n */\n #confirmedOpen = false;\n #connectionState: WebSocketConnectionState<InternalConnectionStatus>;\n #connectionTimeout;\n #deferredConnection?: DeferredPromise;\n #protocols;\n #reconnectAttempts: ReconnectAttempts;\n #requiresLogin = true;\n #url;\n #ws?: WebSocket;\n\n constructor({\n callback,\n connectionTimeout = DEFAULT_CONNECTION_TIMEOUT,\n protocols,\n retryLimits = DEFAULT_RETRY_LIMITS,\n url,\n }: WebSocketConnectionConfig) {\n super();\n\n this.#callback = callback;\n this.#connectionTimeout = connectionTimeout;\n this.#url = url;\n this.#protocols = protocols;\n\n this.#reconnectAttempts = {\n retryAttemptsTotal: retryLimits.reconnect,\n retryAttemptsRemaining: retryLimits.reconnect,\n secondsToNextRetry: 1,\n };\n\n /**\n * Initial retryAttempts are for the 'connecting' phase. These will\n * be replaced with 'reconnecting' phase retry attempts only once\n * initial connection succeeds.\n */\n this.#connectionState = {\n connectionPhase: \"connecting\",\n connectionStatus: \"closed\",\n retryAttemptsTotal: retryLimits.connect,\n retryAttemptsRemaining: retryLimits.connect,\n secondsToNextRetry: 1,\n };\n }\n\n get connectionTimeout() {\n return this.#connectionTimeout;\n }\n\n get protocols() {\n return this.#protocols;\n }\n\n get requiresLogin() {\n return this.#requiresLogin;\n }\n\n get isClosed() {\n return this.status === \"closed\";\n }\n get isDisconnected() {\n return this.status === \"disconnected\";\n }\n\n get isConnecting() {\n return this.#connectionState.connectionPhase === \"connecting\";\n }\n\n get status() {\n return this.#connectionState.connectionStatus;\n }\n\n private set status(connectionStatus: InternalConnectionStatus) {\n this.#connectionState = {\n ...this.#connectionState,\n connectionStatus,\n };\n // we don't publish the connecting states. They have little meaning for clients\n // and are will generally be very short-lived.\n if (isNotConnecting(this.#connectionState)) {\n this.emit(\"connection-status\", this.#connectionState);\n }\n }\n\n get connectionState() {\n return this.#connectionState;\n }\n\n private get hasConnectionAttemptsRemaining() {\n return this.#connectionState.retryAttemptsRemaining > 0;\n }\n\n private get confirmedOpen() {\n return this.#confirmedOpen;\n }\n\n /**\n * We are 'confirmedOpen' when we see the first message transmitted\n * from the server. This ensures that even if we have one or more\n * proxies in our route to the endPoint, all connections have been\n * opened successfully.\n * First time in here (on our initial successful connection) we switch\n * from 'connect' phase to 'reconnect' phase. We may have different\n * retry configurations for these two phases.\n */\n private set confirmedOpen(confirmedOpen: boolean) {\n this.#confirmedOpen = confirmedOpen;\n\n if (confirmedOpen && this.isConnecting) {\n this.#connectionState = {\n ...this.#connectionState,\n connectionPhase: \"reconnecting\",\n ...this.#reconnectAttempts,\n };\n } else if (confirmedOpen) {\n // we have successfully reconnected after a failure.\n // Reset the retry attempts, ready for next failure\n // Note: this retry is shared with 'disconnected' status\n this.#connectionState = {\n ...this.#connectionState,\n ...this.#reconnectAttempts,\n };\n }\n }\n\n get url() {\n return this.#url;\n }\n\n async connect(clientCall = true) {\n const state = this.#connectionState;\n if (this.isConnecting && this.#deferredConnection === undefined) {\n // We block on the first connecting call, this will be the\n // initial connect call from app. Any other calls will be\n // reconnect attempts. The initial connecting call returns a promise.\n // This promise is resolved either on that initial call or on a\n // subsequent successful retry attempt within nthat same initial\n // connecting phase.\n this.#deferredConnection = new DeferredPromise();\n }\n const { connectionTimeout, protocols, url } = this;\n this.status = state.connectionPhase;\n const timer = setTimeout(() => {\n throw Error(\n `Failed to open WebSocket connection to ${url}, timed out after ${connectionTimeout}ms`,\n );\n }, connectionTimeout);\n\n const ws = (this.#ws = new WebSocket(url, protocols));\n\n ws.onopen = () => {\n const connectedStatus = ConnectingEndState[state.connectionPhase];\n this.status = connectedStatus;\n clearTimeout(timer);\n if (this.#deferredConnection) {\n this.#deferredConnection.resolve(undefined);\n this.#deferredConnection = undefined;\n }\n if (this.isConnecting) {\n this.emit(\"connected\");\n } else {\n this.emit(\"reconnected\");\n }\n };\n ws.onerror = () => {\n clearTimeout(timer);\n };\n\n ws.onclose = () => {\n if (!this.isClosed) {\n this.confirmedOpen = false;\n this.status = \"disconnected\";\n if (this.hasConnectionAttemptsRemaining) {\n this.reconnect();\n } else {\n this.close(\"failure\");\n }\n }\n };\n\n ws.onmessage = (evt) => {\n if (!this.confirmedOpen) {\n // Now that we are confirmedOpen any subsequent close events\n // will be treated as part of a reconnection phase.\n this.confirmedOpen = true;\n }\n this.receive(evt);\n };\n\n if (clientCall) {\n return this.#deferredConnection?.promise;\n }\n }\n\n private reconnect() {\n const { retryAttemptsRemaining, secondsToNextRetry } =\n this.#connectionState;\n setTimeout(() => {\n this.#connectionState = {\n ...this.#connectionState,\n retryAttemptsRemaining: retryAttemptsRemaining - 1,\n secondsToNextRetry: secondsToNextRetry * 2,\n };\n this.connect(false);\n }, secondsToNextRetry * 1000);\n }\n\n private receive = (evt: MessageEvent) => {\n const vuuMessageFromServer = parseWebSocketMessage(evt.data);\n this.#callback(vuuMessageFromServer);\n };\n\n send = (msg: VuuClientMessage) => {\n this.#ws?.send(JSON.stringify(msg));\n };\n\n close(reason: WebSocketConnectionCloseReason = \"shutdown\") {\n this.status = \"closed\";\n if (reason === \"failure\") {\n if (this.#deferredConnection) {\n this.#deferredConnection.reject(Error(\"connection failed\"));\n this.#deferredConnection = undefined;\n }\n } else {\n this.#ws?.close();\n }\n this.emit(\"closed\", reason);\n this.#ws = undefined;\n }\n}\n"],"names":[],"mappings":";;;;AAmCa,MAAA,4BAAA,GAA+B,CAC1C,GACoC,KAAA;AACpC,EAAA,IAAI,sBAAsB,GAAK,EAAA;AAC7B,IAAO,OAAA;AAAA,MACL,YAAA;AAAA,MACA,WAAA;AAAA,MACA,kCAAA;AAAA,MACA,cAAA;AAAA,MACA,aAAA;AAAA,MACA,cAAA;AAAA,MACA,QAAA;AAAA,MACA;AAAA,KACF,CAAE,QAAS,CAAA,GAAA,CAAI,gBAAgB,CAAA;AAAA,GAC1B,MAAA;AACL,IAAO,OAAA,KAAA;AAAA;AAEX;;;;"}
package/cjs/index.js CHANGED
@@ -19,6 +19,7 @@ exports.isSizeOnly = dataSource.isSizeOnly;
19
19
  exports.shouldMessageBeRoutedToDataSource = dataSource.shouldMessageBeRoutedToDataSource;
20
20
  exports.toDataSourceConfig = dataSource.toDataSourceConfig;
21
21
  exports.createSchemaFromTableMetadata = messageUtils.createSchemaFromTableMetadata;
22
+ exports.gapBetweenLastRowSentToClient = messageUtils.gapBetweenLastRowSentToClient;
22
23
  exports.getFirstAndLastRows = messageUtils.getFirstAndLastRows;
23
24
  exports.groupRowsByViewport = messageUtils.groupRowsByViewport;
24
25
  exports.isVuuRpcRequest = messageUtils.isVuuRpcRequest;
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -476,11 +476,31 @@ var getFirstAndLastRows = (rows) => {
476
476
  const lastRow = rows.at(-1);
477
477
  return [firstRow, lastRow];
478
478
  };
479
+ var insertRow = (rows, row) => {
480
+ const lastRow = rows.at(-1);
481
+ if (lastRow === void 0 || row.rowIndex > lastRow.rowIndex) {
482
+ rows.push(row);
483
+ } else {
484
+ for (let i = 0; i < rows.length; i++) {
485
+ if (row.rowIndex < rows[i].rowIndex) {
486
+ rows.splice(i, 0, row);
487
+ return;
488
+ } else if (row.rowIndex === rows[i].rowIndex) {
489
+ if (row.ts < rows[i].ts) {
490
+ } else {
491
+ rows[i] = row;
492
+ }
493
+ return;
494
+ }
495
+ }
496
+ throw Error("don't expect to get this far");
497
+ }
498
+ };
479
499
  var groupRowsByViewport = (rows) => {
480
500
  const result = {};
481
501
  for (const row of rows) {
482
502
  const rowsForViewport = result[row.viewPortId] || (result[row.viewPortId] = []);
483
- rowsForViewport.push(row);
503
+ insertRow(rowsForViewport, row);
484
504
  }
485
505
  return result;
486
506
  };
@@ -499,6 +519,24 @@ var createSchemaFromTableMetadata = ({
499
519
  key
500
520
  };
501
521
  };
522
+ var gapBetweenLastRowSentToClient = (lastRowsReturnedToClient, pendingUpdates, clientRange) => {
523
+ const firstPendingUpdate = pendingUpdates.at(0);
524
+ const lastPendingUpdate = pendingUpdates.at(-1);
525
+ if (firstPendingUpdate && lastPendingUpdate) {
526
+ const [firstRowIndex, lastRowIndex] = lastRowsReturnedToClient;
527
+ if (lastRowIndex < firstPendingUpdate.rowIndex - 1 && clientRange.from < firstPendingUpdate.rowIndex) {
528
+ return {
529
+ from: Math.max(lastRowIndex + 1, clientRange.from),
530
+ to: firstPendingUpdate.rowIndex
531
+ };
532
+ } else if (firstRowIndex > lastPendingUpdate.rowIndex + 1 && clientRange.to > lastPendingUpdate.rowIndex) {
533
+ return {
534
+ from: lastPendingUpdate.rowIndex + 1,
535
+ to: Math.min(clientRange.to, firstRowIndex)
536
+ };
537
+ }
538
+ }
539
+ };
502
540
 
503
541
  // src/server-proxy/messages.ts
504
542
  var CHANGE_VP_SUCCESS = "CHANGE_VP_SUCCESS";
@@ -597,7 +635,7 @@ var ArrayBackedMovingWindow = class {
597
635
  get range() {
598
636
  return __privateGet(this, _range);
599
637
  }
600
- // TODO we shpuld probably have a hasAllClientRowsWithinRange
638
+ // TODO we should probably have a hasAllClientRowsWithinRange
601
639
  get hasAllRowsWithinRange() {
602
640
  return this.rowsWithinRange === this.clientRange.to - this.clientRange.from || // this.rowsWithinRange === this.range.to - this.range.from ||
603
641
  this.rowCount > 0 && this.clientRange.from + this.rowsWithinRange === this.rowCount;
@@ -783,8 +821,7 @@ var Viewport = class {
783
821
  }, postMessageToClient) {
784
822
  __privateAdd(this, _status, "");
785
823
  __publicField(this, "aggregations");
786
- /** batchMode is irrelevant for Vuu Table, it was introduced to try and improve rendering performance of AgGrid */
787
- __publicField(this, "batchMode", true);
824
+ __publicField(this, "batchMode", false);
788
825
  __publicField(this, "bufferSize");
789
826
  /**
790
827
  * clientRange is always the range requested by the client. We should assume
@@ -806,9 +843,9 @@ var Viewport = class {
806
843
  __publicField(this, "postMessageToClient");
807
844
  __publicField(this, "rowCountChanged", false);
808
845
  __publicField(this, "selectedRows", []);
809
- __publicField(this, "useBatchMode", true);
810
846
  __publicField(this, "lastUpdateStatus", NO_UPDATE_STATUS);
811
847
  __publicField(this, "updateThrottleTimer");
848
+ __publicField(this, "lastRowsReturnedToClient", [-1, -1]);
812
849
  __publicField(this, "rangeMonitor", new RangeMonitor("ViewPort"));
813
850
  __publicField(this, "clientViewportId");
814
851
  __publicField(this, "disabled", false);
@@ -1086,6 +1123,7 @@ var Viewport = class {
1086
1123
  // When not scrolling, any server data is an update
1087
1124
  // When scrolling, we are in batch mode
1088
1125
  rangeRequest(requestId, range) {
1126
+ var _a, _b;
1089
1127
  if (debugEnabled2) {
1090
1128
  this.rangeMonitor.set(range);
1091
1129
  }
@@ -1102,8 +1140,7 @@ var Viewport = class {
1102
1140
  infoEnabled && info(
1103
1141
  \`updated: window client (\${this.dataWindow.clientRange.from}:\${this.dataWindow.clientRange.to}), full (\${this.dataWindow.range.from}:\${this.dataWindow.range.to})
1104
1142
  serverDataRequired \${serverDataRequired ? "Y" : "N"}
1105
- \${clientRows.length} rows returned from local buffer
1106
- \`
1143
+ \${clientRows.length} rows returned from local buffer\`
1107
1144
  );
1108
1145
  let debounceRequest;
1109
1146
  const maxRange = this.dataWindow.rowCount || void 0;
@@ -1137,15 +1174,14 @@ var Viewport = class {
1137
1174
  }
1138
1175
  }
1139
1176
  this.pendingRangeRequests.push({ ...serverRequest, requestId });
1140
- if (this.useBatchMode) {
1141
- this.batchMode = true;
1142
- }
1143
1177
  } else if (clientRows.length > 0) {
1144
1178
  this.batchMode = false;
1145
1179
  }
1146
1180
  this.keys.reset(this.dataWindow.clientRange);
1147
1181
  const toClient = this.isTree ? toClientRowTree : toClientRow;
1148
1182
  if (clientRows.length) {
1183
+ this.lastRowsReturnedToClient[0] = clientRows[0].rowIndex;
1184
+ this.lastRowsReturnedToClient[1] = (_b = (_a = clientRows.at(-1)) == null ? void 0 : _a.rowIndex) != null ? _b : -1;
1149
1185
  return [
1150
1186
  serverRequest,
1151
1187
  clientRows.map((row) => {
@@ -1182,9 +1218,6 @@ var Viewport = class {
1182
1218
  };
1183
1219
  }
1184
1220
  openTreeNode(requestId, message) {
1185
- if (this.useBatchMode) {
1186
- this.batchMode = true;
1187
- }
1188
1221
  const treeKey = message.index === void 0 ? message.key : this.getKeyForRowAtIndex(message.index);
1189
1222
  infoEnabled && info(\`treeKey \${treeKey}\`);
1190
1223
  return {
@@ -1194,9 +1227,6 @@ var Viewport = class {
1194
1227
  };
1195
1228
  }
1196
1229
  closeTreeNode(requestId, message) {
1197
- if (this.useBatchMode) {
1198
- this.batchMode = true;
1199
- }
1200
1230
  const treeKey = message.index === void 0 ? message.key : this.getKeyForRowAtIndex(message.index);
1201
1231
  return {
1202
1232
  type: CLOSE_TREE_NODE,
@@ -1210,9 +1240,6 @@ var Viewport = class {
1210
1240
  childVpId: this.serverViewportId
1211
1241
  };
1212
1242
  this.awaitOperation(requestId, message);
1213
- if (this.useBatchMode) {
1214
- this.batchMode = true;
1215
- }
1216
1243
  return message;
1217
1244
  }
1218
1245
  removeLink(requestId) {
@@ -1269,12 +1296,11 @@ var Viewport = class {
1269
1296
  var _a;
1270
1297
  this.awaitOperation(requestId, { type: "config", data: config });
1271
1298
  const { filterSpec: filter, ...remainingConfig } = config;
1272
- if (this.useBatchMode) {
1273
- this.batchMode = true;
1274
- }
1275
1299
  debugEnabled2 ? debug2 == null ? void 0 : debug2(\`setConfig \${JSON.stringify(config)}\`) : info == null ? void 0 : info(\`setConfig\`);
1276
1300
  if (!this.isTree && config.groupBy.length > 0) {
1277
1301
  (_a = this.dataWindow) == null ? void 0 : _a.clear();
1302
+ this.lastRowsReturnedToClient[0] = -1;
1303
+ this.lastRowsReturnedToClient[1] = -1;
1278
1304
  }
1279
1305
  return this.createRequest(
1280
1306
  {
@@ -1357,6 +1383,7 @@ var Viewport = class {
1357
1383
  // This is called only after new data has been received from server - data
1358
1384
  // returned direcly from buffer does not use this.
1359
1385
  getClientRows() {
1386
+ var _a, _b, _c, _d;
1360
1387
  let out = void 0;
1361
1388
  let mode = "size-only";
1362
1389
  if (!this.hasUpdates && !this.rowCountChanged) {
@@ -1369,24 +1396,38 @@ var Viewport = class {
1369
1396
  self.clearTimeout(this.updateThrottleTimer);
1370
1397
  this.updateThrottleTimer = void 0;
1371
1398
  }
1372
- if (this.pendingUpdates.length > 0) {
1399
+ if (this.pendingUpdates.length > 0 && this.dataWindow.hasAllRowsWithinRange) {
1373
1400
  out = [];
1374
1401
  mode = "update";
1375
- for (const row of this.pendingUpdates) {
1376
- out.push(toClient(row, keys, selectedRows));
1377
- }
1378
- this.pendingUpdates.length = 0;
1379
- } else {
1380
- const records = this.dataWindow.getData();
1381
- if (this.dataWindow.hasAllRowsWithinRange) {
1382
- out = [];
1383
- mode = "batch";
1384
- for (const row of records) {
1402
+ const missingRows = gapBetweenLastRowSentToClient(
1403
+ this.lastRowsReturnedToClient,
1404
+ this.pendingUpdates,
1405
+ this.dataWindow.clientRange
1406
+ );
1407
+ if (missingRows) {
1408
+ for (let i = missingRows.from; i < missingRows.to; i++) {
1409
+ const row = this.dataWindow.getAtIndex(i);
1410
+ if (row) {
1411
+ out.push(toClient(row, keys, selectedRows));
1412
+ } else {
1413
+ throw Error("[Viewport] missing row not in data cache");
1414
+ }
1415
+ }
1416
+ for (const row of this.pendingUpdates) {
1417
+ out.push(toClient(row, keys, selectedRows));
1418
+ }
1419
+ out.sort(
1420
+ ([idx1], [idx2]) => idx1 - idx2
1421
+ );
1422
+ } else {
1423
+ for (const row of this.pendingUpdates) {
1385
1424
  out.push(toClient(row, keys, selectedRows));
1386
1425
  }
1387
- this.batchMode = false;
1388
1426
  }
1427
+ this.lastRowsReturnedToClient[0] = (_b = (_a = out.at(0)) == null ? void 0 : _a[0]) != null ? _b : -1;
1428
+ this.lastRowsReturnedToClient[1] = (_d = (_c = out.at(-1)) == null ? void 0 : _c[0]) != null ? _d : -1;
1389
1429
  }
1430
+ this.pendingUpdates.length = 0;
1390
1431
  this.hasUpdates = false;
1391
1432
  }
1392
1433
  if (this.throttleMessage(mode)) {
@@ -1714,7 +1755,7 @@ var ServerProxy = class {
1714
1755
  if (rows) {
1715
1756
  info2 == null ? void 0 : info2(\`setViewRange \${rows.length} rows returned from cache\`);
1716
1757
  this.postMessageToClient({
1717
- mode: "batch",
1758
+ mode: "update",
1718
1759
  type: "viewport-update",
1719
1760
  clientViewportId: viewport.clientViewportId,
1720
1761
  range: message.range,
@@ -1778,7 +1819,7 @@ var ServerProxy = class {
1778
1819
  debug3 == null ? void 0 : debug3(\`resumeViewport size \${size}, \${rows.length} rows sent to client\`);
1779
1820
  this.postMessageToClient({
1780
1821
  clientViewportId: viewport.clientViewportId,
1781
- mode: "batch",
1822
+ mode: "update",
1782
1823
  rows,
1783
1824
  size,
1784
1825
  type: "viewport-update"
@@ -2079,7 +2120,7 @@ var ServerProxy = class {
2079
2120
  const [size, rows] = viewport.resume();
2080
2121
  this.postMessageToClient({
2081
2122
  clientViewportId: viewport.clientViewportId,
2082
- mode: "batch",
2123
+ mode: "update",
2083
2124
  rows,
2084
2125
  size,
2085
2126
  type: "viewport-update"
@@ -2550,7 +2591,6 @@ var WebSocketConnection = class extends EventEmitter {
2550
2591
  } else {
2551
2592
  this.emit("reconnected");
2552
2593
  }
2553
- console.log("connected");
2554
2594
  };
2555
2595
  ws2.onerror = () => {
2556
2596
  clearTimeout(timer);