From 17d842f77152f1ac3db32df774b86ae5cf7b0119 Mon Sep 17 00:00:00 2001 From: Hans-Joachim Krauch Date: Mon, 6 Nov 2023 15:53:09 -0300 Subject: [PATCH] @foxglove/ws-protocol: Update to spec changes --- typescript/ws-protocol/src/FoxgloveServer.ts | 3 ++- typescript/ws-protocol/src/types.ts | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/typescript/ws-protocol/src/FoxgloveServer.ts b/typescript/ws-protocol/src/FoxgloveServer.ts index 19fd82fe..846596a1 100644 --- a/typescript/ws-protocol/src/FoxgloveServer.ts +++ b/typescript/ws-protocol/src/FoxgloveServer.ts @@ -22,6 +22,7 @@ import { ServiceCallPayload, ServiceCallRequest, ServiceId, + ServiceWithoutId, SubscriptionId, } from "./types"; @@ -187,7 +188,7 @@ export default class FoxgloveServer { * Advertise a new service and inform any connected clients. * @returns The id of the new service */ - addService(service: Omit): ServiceId { + addService(service: ServiceWithoutId): ServiceId { const newId = ++this.#nextServiceId; const newService: Service = { ...service, id: newId }; this.#services.set(newId, newService); diff --git a/typescript/ws-protocol/src/types.ts b/typescript/ws-protocol/src/types.ts index ba871581..708d1163 100644 --- a/typescript/ws-protocol/src/types.ts +++ b/typescript/ws-protocol/src/types.ts @@ -40,13 +40,27 @@ export type Channel = { schema: string; schemaEncoding?: string; }; -export type Service = { + +type ServiceRequest = { + encoding: string; + schemaName: string; + schemaEncoding: string; + schema: string; +}; +type ServiceRequestDef = + | { requestSchema: string; request?: ServiceRequest } + | { requestSchema?: string; request: ServiceRequest }; +type ServiceResponse = ServiceRequest; +type ServiceResponseDef = + | { responseSchema: string; response?: ServiceResponse } + | { responseSchema?: string; response: ServiceResponse }; +type ServiceBase = { id: number; name: string; type: string; - requestSchema: string; - responseSchema: string; }; +export type Service = ServiceBase & ServiceRequestDef & ServiceResponseDef; +export type ServiceWithoutId = Omit & ServiceRequestDef & ServiceResponseDef; export type Subscribe = { op: "subscribe";