sprinklers3/common/sprinklersRpc/deviceRequests.ts

68 lines
1.8 KiB
TypeScript
Raw Normal View History

export interface WithType<Type extends string = string> {
2018-09-02 02:57:55 -06:00
type: Type;
}
2018-09-02 02:57:55 -06:00
export interface WithProgram {
programId: number;
}
export type RunProgramRequest = WithProgram & WithType<"runProgram">;
export type CancelProgramRequest = WithProgram & WithType<"cancelProgram">;
export type UpdateProgramData = WithProgram & { data: any };
2018-09-02 02:57:55 -06:00
export type UpdateProgramRequest = UpdateProgramData &
WithType<"updateProgram">;
export type UpdateProgramResponse = Response<"updateProgram", { data: any }>;
2018-09-02 02:57:55 -06:00
export interface WithSection {
sectionId: number;
}
2017-10-10 16:34:02 -06:00
export type RunSectionData = WithSection & { duration: number };
2018-07-25 12:53:33 -06:00
export type RunSectionRequest = RunSectionData & WithType<"runSection">;
export type RunSectionResponse = Response<"runSection", { runId: number }>;
export type CancelSectionRequest = WithSection & WithType<"cancelSection">;
2018-09-02 02:57:55 -06:00
export interface CancelSectionRunIdData {
runId: number;
}
export type CancelSectionRunIdRequest = CancelSectionRunIdData &
WithType<"cancelSectionRunId">;
2018-09-02 02:57:55 -06:00
export interface PauseSectionRunnerData {
paused: boolean;
}
export type PauseSectionRunnerRequest = PauseSectionRunnerData &
WithType<"pauseSectionRunner">;
2018-09-02 02:57:55 -06:00
export type Request =
| RunProgramRequest
| CancelProgramRequest
| UpdateProgramRequest
| RunSectionRequest
| CancelSectionRequest
| CancelSectionRunIdRequest
| PauseSectionRunnerRequest;
export type RequestType = Request["type"];
2018-09-02 02:57:55 -06:00
export interface SuccessResponseData<Type extends string = string>
extends WithType<Type> {
result: "success";
message: string;
}
2018-09-02 02:57:55 -06:00
export interface ErrorResponseData<Type extends string = string>
extends WithType<Type> {
result: "error";
message: string;
code: number;
name?: string;
cause?: any;
}
export type Response<Type extends string = string, Res = {}> =
2018-09-02 02:57:55 -06:00
| (SuccessResponseData<Type> & Res)
| (ErrorResponseData<Type>);