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 6, 2023
1 parent bd960ad commit 17d842f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion typescript/ws-protocol/src/FoxgloveServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ServiceCallPayload,
ServiceCallRequest,
ServiceId,
ServiceWithoutId,
SubscriptionId,
} from "./types";

Expand Down Expand Up @@ -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<Service, "id">): ServiceId {
addService(service: ServiceWithoutId): ServiceId {
const newId = ++this.#nextServiceId;
const newService: Service = { ...service, id: newId };
this.#services.set(newId, newService);
Expand Down
20 changes: 17 additions & 3 deletions typescript/ws-protocol/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServiceBase, "id"> & ServiceRequestDef & ServiceResponseDef;

export type Subscribe = {
op: "subscribe";
Expand Down

0 comments on commit 17d842f

Please sign in to comment.