From c36b2f7bee2f8d8b9eccca568a681df5c701c0a8 Mon Sep 17 00:00:00 2001 From: heswell Date: Mon, 1 Jul 2024 12:42:47 +0100 Subject: [PATCH] #1409 preserve message type on response to UI --- .../vuu-data-remote/src/connection-manager.ts | 19 +++++----------- vuu-ui/packages/vuu-data-types/index.d.ts | 22 +++++++++++-------- .../vuu-utils/src/protocol-message-utils.ts | 7 +++++- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/vuu-ui/packages/vuu-data-remote/src/connection-manager.ts b/vuu-ui/packages/vuu-data-remote/src/connection-manager.ts index 953148fcf..aadd10a85 100644 --- a/vuu-ui/packages/vuu-data-remote/src/connection-manager.ts +++ b/vuu-ui/packages/vuu-data-remote/src/connection-manager.ts @@ -4,9 +4,6 @@ import { ServerProxySubscribeMessage, TableSchema, VuuUIMessageIn, - VuuUIMessageInRPC, - VuuUIMessageInTableList, - VuuUIMessageInTableMeta, VuuUIMessageOut, WebSocketProtocol, } from "@finos/vuu-data-types"; @@ -24,6 +21,7 @@ import { getLoggingConfigForWorker, isConnectionQualityMetrics, isConnectionStatusMessage, + isRequestResponse, isTableSchemaMessage, messageHasResult, uuid, @@ -176,19 +174,12 @@ function handleMessageFromWorker({ ConnectionManager.emit("connection-status", message); } else if (isConnectionQualityMetrics(message)) { ConnectionManager.emit("connection-metrics", message); - } else { - const requestId = (message as VuuUIMessageInRPC).requestId; + } else if (isRequestResponse(message)) { + const { requestId } = message; if (pendingRequests.has(requestId)) { const { resolve } = pendingRequests.get(requestId); pendingRequests.delete(requestId); - const { - type: _1, - requestId: _2, - ...rest - } = message as - | VuuUIMessageInRPC - | VuuUIMessageInTableList - | VuuUIMessageInTableMeta; + const { requestId: _, ...messageWithoutRequestId } = message; if (messageHasResult(message)) { resolve(message.result); @@ -200,7 +191,7 @@ function handleMessageFromWorker({ } else if (isTableSchemaMessage(message)) { resolve(message.tableSchema); } else { - resolve(rest); + resolve(messageWithoutRequestId); } } else { console.warn( diff --git a/vuu-ui/packages/vuu-data-types/index.d.ts b/vuu-ui/packages/vuu-data-types/index.d.ts index 1adf33404..e148e5125 100644 --- a/vuu-ui/packages/vuu-data-types/index.d.ts +++ b/vuu-ui/packages/vuu-data-types/index.d.ts @@ -625,18 +625,22 @@ export interface VuuUIMessageInMenuRej { type: "VIEW_PORT_MENU_REJ"; } -export type VuuUIMessageIn = - | VuuUIMessageInConnected - | VuuUIMessageInConnectionFailed - | VuuUIMessageInWorkerReady - | VuuUIMessageInRPC - | ViewportRpcResponse +export type VuuUiMessageInRequestResponse = + | VuuUIMessageInMenuRej | MenuRpcResponse | MenuRpcReject - | VuuUIMessageInTableList - | VuuUIMessageInTableMeta + | VuuUIMessageInRPC | VuuUIMessageInRPCEditReject - | VuuUIMessageInRPCEditResponse; + | VuuUIMessageInRPCEditResponse + | ViewportRpcResponse + | VuuUIMessageInTableList + | VuuUIMessageInTableMeta; + +export type VuuUIMessageIn = + | VuuUiMessageInRequestResponse + | VuuUIMessageInConnected + | VuuUIMessageInConnectionFailed + | VuuUIMessageInWorkerReady; export type WebSocketProtocol = string | string[] | undefined; diff --git a/vuu-ui/packages/vuu-utils/src/protocol-message-utils.ts b/vuu-ui/packages/vuu-utils/src/protocol-message-utils.ts index 11db4d771..e26f972e9 100644 --- a/vuu-ui/packages/vuu-utils/src/protocol-message-utils.ts +++ b/vuu-ui/packages/vuu-utils/src/protocol-message-utils.ts @@ -1,9 +1,10 @@ -import { +import type { MenuRpcAction, MenuRpcResponse, OpenDialogActionWithSchema, RpcResponse, VuuUIMessageOut, + VuuUiMessageInRequestResponse, } from "@finos/vuu-data-types"; import { ClientToServerMenuRPC, @@ -28,6 +29,10 @@ export const isVuuMenuRpcRequest = ( message: VuuUIMessageOut | VuuRpcRequest | ClientToServerMenuRPC ): message is ClientToServerMenuRPC => MENU_RPC_TYPES.includes(message["type"]); +export const isRequestResponse = ( + message: object +): message is VuuUiMessageInRequestResponse => "requestId" in message; + export const isOpenSessionTableDialogMessage = ( rpcResponse: RpcResponse ): rpcResponse is MenuRpcResponse =>