Skip to content

Commit

Permalink
spec: Added SubReq and PubRsp
Browse files Browse the repository at this point in the history
  • Loading branch information
lucsoft committed Apr 5, 2022
1 parent 5bf8a0b commit e450026
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions spec/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,48 @@ export type HmRequest =
| QueryRequest
| LoginRequest
| AccountRequest
| TriggerRequest;
| TriggerRequest
| SubscribeRequest;

export type HmResponse =
| SyncResponse
| ProfileResponse
| LoginResponse
| QueryResponse;
| QueryResponse
| PublishResponse;

export type PublishResponse = {
type: "pub";
id: string;
data: Record<string, string>;
};
export type QueryResponse = {
type: "query",
response: string
type: "query";
response: string;
} & Record<string, unknown>;
export type LoginResponse = {
login: true,
id: undefined,
type: "client",
login: true;
id: undefined;
type: "client";
client: {
email?: string,
id: string,
token: string
}
email?: string;
id: string;
token: string;
};
} | {
id: undefined,
id: undefined;
type: "client";
login: false,
error: "forcedClosed"
}
login: false;
error: "forcedClosed";
};
export type ProfileResponse = {
type: "profile";
id?: string;
};
export type SyncResponse = {
type: "sync";
id?: string;
data: Record<string, string>
data: Record<string, string>;
};
export type QueryRequest = {
action: MessageType.Query;
Expand All @@ -53,8 +60,8 @@ export const enum MessageType {
Account = "account",
Trigger = "trigger",
Query = "query",
Subscribe = "sub",
}

export type LoginRequest =
& {
action: MessageType.Login;
Expand Down Expand Up @@ -89,3 +96,9 @@ export type TriggerRequest = {
id?: string;
data?: unknown;
};

export type SubscribeRequest = {
action: MessageType.Subscribe;
auth?: Authentication;
id: string;
};

0 comments on commit e450026

Please sign in to comment.