From d631a7af87252dec5438b41e1dfa60cdd5554c2b Mon Sep 17 00:00:00 2001 From: Hans-Joachim Krauch Date: Wed, 8 Nov 2023 13:28:55 -0300 Subject: [PATCH] @foxglove/ws-protocol: Update to spec changes --- typescript/ws-protocol/src/FoxgloveServer.ts | 7 +++++++ typescript/ws-protocol/src/types.ts | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/typescript/ws-protocol/src/FoxgloveServer.ts b/typescript/ws-protocol/src/FoxgloveServer.ts index 19fd82fe..db3f2508 100644 --- a/typescript/ws-protocol/src/FoxgloveServer.ts +++ b/typescript/ws-protocol/src/FoxgloveServer.ts @@ -188,6 +188,13 @@ export default class FoxgloveServer { * @returns The id of the new service */ addService(service: Omit): ServiceId { + if (service.request == undefined && service.requestSchema == undefined) { + throw new Error("Either 'request' or 'requestSchema' has to be given."); + } + if (service.response == undefined && service.responseSchema == undefined) { + throw new Error("Either 'response' or 'responseSchema' has to be given."); + } + 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..cde7ce77 100644 --- a/typescript/ws-protocol/src/types.ts +++ b/typescript/ws-protocol/src/types.ts @@ -40,12 +40,22 @@ export type Channel = { schema: string; schemaEncoding?: string; }; + +type ServiceRequestDefinition = { + encoding: string; + schemaName: string; + schemaEncoding: string; + schema: string; +}; +type ServiceResponseDefinition = ServiceRequestDefinition; export type Service = { id: number; name: string; type: string; - requestSchema: string; - responseSchema: string; + request?: ServiceRequestDefinition; // Must be given if requestSchema is not given. + response?: ServiceResponseDefinition; // Must be given if responseSchema is not given. + requestSchema?: string; // Must be given if request is not given. + responseSchema?: string; // Must be given if response is not given. }; export type Subscribe = {