Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@foxglove/ws-protocol: Update to spec changes #579

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫠

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that bad practice?

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.
achim-k marked this conversation as resolved.
Show resolved Hide resolved
};

export type Subscribe = {
Expand Down
Loading