Skip to content

Commit

Permalink
@foxglove/ws-protocol: Update to spec changes
Browse files Browse the repository at this point in the history
  • Loading branch information
achim-k committed Nov 8, 2023
1 parent bd960ad commit d631a7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions typescript/ws-protocol/src/FoxgloveServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ export default class FoxgloveServer {
* @returns The id of the new service
*/
addService(service: Omit<Service, "id">): 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);
Expand Down
14 changes: 12 additions & 2 deletions typescript/ws-protocol/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit d631a7a

Please sign in to comment.