@vuu-ui/vuu-data-remote 0.10.8 → 0.10.10

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
@@ -114,7 +114,6 @@ class VuuDataSource extends BaseDataSource {
114
114
  }
115
115
  async subscribe(subscribeProps, callback) {
116
116
  super.subscribe(subscribeProps, callback);
117
- console.log(`%cVuuDataSource subscribe`, "color: blue;font-weight:bold;");
118
117
  const {
119
118
  selectedIndexValues,
120
119
  viewport = this.viewport || (this.viewport = 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":[],"mappings":";;;;;;;;;;;;;;AAAA,IAAA,kBAAA,EAAA,MAAA,EAAA,KAAA,EAAA,SAAA,EAAA,kBAAA,EAAA,OAAA,EAAA,YAAA;AAoDA,MAAM,EAAE,IAAA,EAAM,WAAY,EAAA,GAAI,OAAO,eAAe,CAAA;AAK7C,MAAM,sBAAsB,cAAqC,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,IAAA,EAAA,MAAA,CAAA;AACA,IAAA,YAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AACA,IAA8B,YAAA,CAAA,IAAA,EAAA,SAAA,EAAA,UAAA,CAAA;AAC9B,IAAqB,YAAA,CAAA,IAAA,E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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":[],"mappings":";;;;;;;;;;;;;;AAAA,IAAA,kBAAA,EAAA,MAAA,EAAA,KAAA,EAAA,SAAA,EAAA,kBAAA,EAAA,OAAA,EAAA,YAAA;AAoDA,MAAM,EAAE,IAAA,EAAM,WAAY,EAAA,GAAI,OAAO,eAAe,CAAA;AAK7C,MAAM,sBAAsB,cAAqC,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,IAAA,EAAA,MAAA,CAAA;AACA,IAAA,YAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AACA,IAA8B,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AAA;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/esm/index.js CHANGED
@@ -2,7 +2,7 @@ export { authenticate } from './authenticate.js';
2
2
  export { default as ConnectionManager } from './ConnectionManager.js';
3
3
  export { connectionId, msgType } from './constants.js';
4
4
  export { isDataSourceConfigMessage, isSizeOnly, shouldMessageBeRoutedToDataSource, toDataSourceConfig } from './data-source.js';
5
- export { createSchemaFromTableMetadata, getFirstAndLastRows, groupRowsByViewport, isVuuRpcRequest, stripRequestId } from './message-utils.js';
5
+ export { createSchemaFromTableMetadata, gapBetweenLastRowSentToClient, getFirstAndLastRows, groupRowsByViewport, isVuuRpcRequest, stripRequestId } from './message-utils.js';
6
6
  export { RestDataSource } from './rest-data/RestDataSource.js';
7
7
  export { VuuDataSource } from './VuuDataSource.js';
8
8
  //# sourceMappingURL=index.js.map
@@ -474,11 +474,31 @@ var getFirstAndLastRows = (rows) => {
474
474
  const lastRow = rows.at(-1);
475
475
  return [firstRow, lastRow];
476
476
  };
477
+ var insertRow = (rows, row) => {
478
+ const lastRow = rows.at(-1);
479
+ if (lastRow === void 0 || row.rowIndex > lastRow.rowIndex) {
480
+ rows.push(row);
481
+ } else {
482
+ for (let i = 0; i < rows.length; i++) {
483
+ if (row.rowIndex < rows[i].rowIndex) {
484
+ rows.splice(i, 0, row);
485
+ return;
486
+ } else if (row.rowIndex === rows[i].rowIndex) {
487
+ if (row.ts < rows[i].ts) {
488
+ } else {
489
+ rows[i] = row;
490
+ }
491
+ return;
492
+ }
493
+ }
494
+ throw Error("don't expect to get this far");
495
+ }
496
+ };
477
497
  var groupRowsByViewport = (rows) => {
478
498
  const result = {};
479
499
  for (const row of rows) {
480
500
  const rowsForViewport = result[row.viewPortId] || (result[row.viewPortId] = []);
481
- rowsForViewport.push(row);
501
+ insertRow(rowsForViewport, row);
482
502
  }
483
503
  return result;
484
504
  };
@@ -497,6 +517,24 @@ var createSchemaFromTableMetadata = ({
497
517
  key
498
518
  };
499
519
  };
520
+ var gapBetweenLastRowSentToClient = (lastRowsReturnedToClient, pendingUpdates, clientRange) => {
521
+ const firstPendingUpdate = pendingUpdates.at(0);
522
+ const lastPendingUpdate = pendingUpdates.at(-1);
523
+ if (firstPendingUpdate && lastPendingUpdate) {
524
+ const [firstRowIndex, lastRowIndex] = lastRowsReturnedToClient;
525
+ if (lastRowIndex < firstPendingUpdate.rowIndex - 1 && clientRange.from < firstPendingUpdate.rowIndex) {
526
+ return {
527
+ from: Math.max(lastRowIndex + 1, clientRange.from),
528
+ to: firstPendingUpdate.rowIndex
529
+ };
530
+ } else if (firstRowIndex > lastPendingUpdate.rowIndex + 1 && clientRange.to > lastPendingUpdate.rowIndex) {
531
+ return {
532
+ from: lastPendingUpdate.rowIndex + 1,
533
+ to: Math.min(clientRange.to, firstRowIndex)
534
+ };
535
+ }
536
+ }
537
+ };
500
538
 
501
539
  // src/server-proxy/messages.ts
502
540
  var CHANGE_VP_SUCCESS = "CHANGE_VP_SUCCESS";
@@ -595,7 +633,7 @@ var ArrayBackedMovingWindow = class {
595
633
  get range() {
596
634
  return __privateGet(this, _range);
597
635
  }
598
- // TODO we shpuld probably have a hasAllClientRowsWithinRange
636
+ // TODO we should probably have a hasAllClientRowsWithinRange
599
637
  get hasAllRowsWithinRange() {
600
638
  return this.rowsWithinRange === this.clientRange.to - this.clientRange.from || // this.rowsWithinRange === this.range.to - this.range.from ||
601
639
  this.rowCount > 0 && this.clientRange.from + this.rowsWithinRange === this.rowCount;
@@ -781,8 +819,7 @@ var Viewport = class {
781
819
  }, postMessageToClient) {
782
820
  __privateAdd(this, _status, "");
783
821
  __publicField(this, "aggregations");
784
- /** batchMode is irrelevant for Vuu Table, it was introduced to try and improve rendering performance of AgGrid */
785
- __publicField(this, "batchMode", true);
822
+ __publicField(this, "batchMode", false);
786
823
  __publicField(this, "bufferSize");
787
824
  /**
788
825
  * clientRange is always the range requested by the client. We should assume
@@ -804,9 +841,9 @@ var Viewport = class {
804
841
  __publicField(this, "postMessageToClient");
805
842
  __publicField(this, "rowCountChanged", false);
806
843
  __publicField(this, "selectedRows", []);
807
- __publicField(this, "useBatchMode", true);
808
844
  __publicField(this, "lastUpdateStatus", NO_UPDATE_STATUS);
809
845
  __publicField(this, "updateThrottleTimer");
846
+ __publicField(this, "lastRowsReturnedToClient", [-1, -1]);
810
847
  __publicField(this, "rangeMonitor", new RangeMonitor("ViewPort"));
811
848
  __publicField(this, "clientViewportId");
812
849
  __publicField(this, "disabled", false);
@@ -1084,6 +1121,7 @@ var Viewport = class {
1084
1121
  // When not scrolling, any server data is an update
1085
1122
  // When scrolling, we are in batch mode
1086
1123
  rangeRequest(requestId, range) {
1124
+ var _a, _b;
1087
1125
  if (debugEnabled2) {
1088
1126
  this.rangeMonitor.set(range);
1089
1127
  }
@@ -1100,8 +1138,7 @@ var Viewport = class {
1100
1138
  infoEnabled && info(
1101
1139
  \`updated: window client (\${this.dataWindow.clientRange.from}:\${this.dataWindow.clientRange.to}), full (\${this.dataWindow.range.from}:\${this.dataWindow.range.to})
1102
1140
  serverDataRequired \${serverDataRequired ? "Y" : "N"}
1103
- \${clientRows.length} rows returned from local buffer
1104
- \`
1141
+ \${clientRows.length} rows returned from local buffer\`
1105
1142
  );
1106
1143
  let debounceRequest;
1107
1144
  const maxRange = this.dataWindow.rowCount || void 0;
@@ -1135,15 +1172,14 @@ var Viewport = class {
1135
1172
  }
1136
1173
  }
1137
1174
  this.pendingRangeRequests.push({ ...serverRequest, requestId });
1138
- if (this.useBatchMode) {
1139
- this.batchMode = true;
1140
- }
1141
1175
  } else if (clientRows.length > 0) {
1142
1176
  this.batchMode = false;
1143
1177
  }
1144
1178
  this.keys.reset(this.dataWindow.clientRange);
1145
1179
  const toClient = this.isTree ? toClientRowTree : toClientRow;
1146
1180
  if (clientRows.length) {
1181
+ this.lastRowsReturnedToClient[0] = clientRows[0].rowIndex;
1182
+ this.lastRowsReturnedToClient[1] = (_b = (_a = clientRows.at(-1)) == null ? void 0 : _a.rowIndex) != null ? _b : -1;
1147
1183
  return [
1148
1184
  serverRequest,
1149
1185
  clientRows.map((row) => {
@@ -1180,9 +1216,6 @@ var Viewport = class {
1180
1216
  };
1181
1217
  }
1182
1218
  openTreeNode(requestId, message) {
1183
- if (this.useBatchMode) {
1184
- this.batchMode = true;
1185
- }
1186
1219
  const treeKey = message.index === void 0 ? message.key : this.getKeyForRowAtIndex(message.index);
1187
1220
  infoEnabled && info(\`treeKey \${treeKey}\`);
1188
1221
  return {
@@ -1192,9 +1225,6 @@ var Viewport = class {
1192
1225
  };
1193
1226
  }
1194
1227
  closeTreeNode(requestId, message) {
1195
- if (this.useBatchMode) {
1196
- this.batchMode = true;
1197
- }
1198
1228
  const treeKey = message.index === void 0 ? message.key : this.getKeyForRowAtIndex(message.index);
1199
1229
  return {
1200
1230
  type: CLOSE_TREE_NODE,
@@ -1208,9 +1238,6 @@ var Viewport = class {
1208
1238
  childVpId: this.serverViewportId
1209
1239
  };
1210
1240
  this.awaitOperation(requestId, message);
1211
- if (this.useBatchMode) {
1212
- this.batchMode = true;
1213
- }
1214
1241
  return message;
1215
1242
  }
1216
1243
  removeLink(requestId) {
@@ -1267,12 +1294,11 @@ var Viewport = class {
1267
1294
  var _a;
1268
1295
  this.awaitOperation(requestId, { type: "config", data: config });
1269
1296
  const { filterSpec: filter, ...remainingConfig } = config;
1270
- if (this.useBatchMode) {
1271
- this.batchMode = true;
1272
- }
1273
1297
  debugEnabled2 ? debug2 == null ? void 0 : debug2(\`setConfig \${JSON.stringify(config)}\`) : info == null ? void 0 : info(\`setConfig\`);
1274
1298
  if (!this.isTree && config.groupBy.length > 0) {
1275
1299
  (_a = this.dataWindow) == null ? void 0 : _a.clear();
1300
+ this.lastRowsReturnedToClient[0] = -1;
1301
+ this.lastRowsReturnedToClient[1] = -1;
1276
1302
  }
1277
1303
  return this.createRequest(
1278
1304
  {
@@ -1355,6 +1381,7 @@ var Viewport = class {
1355
1381
  // This is called only after new data has been received from server - data
1356
1382
  // returned direcly from buffer does not use this.
1357
1383
  getClientRows() {
1384
+ var _a, _b, _c, _d;
1358
1385
  let out = void 0;
1359
1386
  let mode = "size-only";
1360
1387
  if (!this.hasUpdates && !this.rowCountChanged) {
@@ -1367,24 +1394,38 @@ var Viewport = class {
1367
1394
  self.clearTimeout(this.updateThrottleTimer);
1368
1395
  this.updateThrottleTimer = void 0;
1369
1396
  }
1370
- if (this.pendingUpdates.length > 0) {
1397
+ if (this.pendingUpdates.length > 0 && this.dataWindow.hasAllRowsWithinRange) {
1371
1398
  out = [];
1372
1399
  mode = "update";
1373
- for (const row of this.pendingUpdates) {
1374
- out.push(toClient(row, keys, selectedRows));
1375
- }
1376
- this.pendingUpdates.length = 0;
1377
- } else {
1378
- const records = this.dataWindow.getData();
1379
- if (this.dataWindow.hasAllRowsWithinRange) {
1380
- out = [];
1381
- mode = "batch";
1382
- for (const row of records) {
1400
+ const missingRows = gapBetweenLastRowSentToClient(
1401
+ this.lastRowsReturnedToClient,
1402
+ this.pendingUpdates,
1403
+ this.dataWindow.clientRange
1404
+ );
1405
+ if (missingRows) {
1406
+ for (let i = missingRows.from; i < missingRows.to; i++) {
1407
+ const row = this.dataWindow.getAtIndex(i);
1408
+ if (row) {
1409
+ out.push(toClient(row, keys, selectedRows));
1410
+ } else {
1411
+ throw Error("[Viewport] missing row not in data cache");
1412
+ }
1413
+ }
1414
+ for (const row of this.pendingUpdates) {
1415
+ out.push(toClient(row, keys, selectedRows));
1416
+ }
1417
+ out.sort(
1418
+ ([idx1], [idx2]) => idx1 - idx2
1419
+ );
1420
+ } else {
1421
+ for (const row of this.pendingUpdates) {
1383
1422
  out.push(toClient(row, keys, selectedRows));
1384
1423
  }
1385
- this.batchMode = false;
1386
1424
  }
1425
+ this.lastRowsReturnedToClient[0] = (_b = (_a = out.at(0)) == null ? void 0 : _a[0]) != null ? _b : -1;
1426
+ this.lastRowsReturnedToClient[1] = (_d = (_c = out.at(-1)) == null ? void 0 : _c[0]) != null ? _d : -1;
1387
1427
  }
1428
+ this.pendingUpdates.length = 0;
1388
1429
  this.hasUpdates = false;
1389
1430
  }
1390
1431
  if (this.throttleMessage(mode)) {
@@ -1712,7 +1753,7 @@ var ServerProxy = class {
1712
1753
  if (rows) {
1713
1754
  info2 == null ? void 0 : info2(\`setViewRange \${rows.length} rows returned from cache\`);
1714
1755
  this.postMessageToClient({
1715
- mode: "batch",
1756
+ mode: "update",
1716
1757
  type: "viewport-update",
1717
1758
  clientViewportId: viewport.clientViewportId,
1718
1759
  range: message.range,
@@ -1776,7 +1817,7 @@ var ServerProxy = class {
1776
1817
  debug3 == null ? void 0 : debug3(\`resumeViewport size \${size}, \${rows.length} rows sent to client\`);
1777
1818
  this.postMessageToClient({
1778
1819
  clientViewportId: viewport.clientViewportId,
1779
- mode: "batch",
1820
+ mode: "update",
1780
1821
  rows,
1781
1822
  size,
1782
1823
  type: "viewport-update"
@@ -2077,7 +2118,7 @@ var ServerProxy = class {
2077
2118
  const [size, rows] = viewport.resume();
2078
2119
  this.postMessageToClient({
2079
2120
  clientViewportId: viewport.clientViewportId,
2080
- mode: "batch",
2121
+ mode: "update",
2081
2122
  rows,
2082
2123
  size,
2083
2124
  type: "viewport-update"
@@ -2548,7 +2589,6 @@ var WebSocketConnection = class extends EventEmitter {
2548
2589
  } else {
2549
2590
  this.emit("reconnected");
2550
2591
  }
2551
- console.log("connected");
2552
2592
  };
2553
2593
  ws2.onerror = () => {
2554
2594
  clearTimeout(timer);