Skip to content

Commit c91d6f7

Browse files
committed
Add some typing
1 parent f4c6fa5 commit c91d6f7

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/blueapi/blueapi.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { useQuery, UseQueryResult } from "react-query";
22

33
const BLUEAPI_SOCKET: string = import.meta.env.VITE_BLUEAPI_SOCKET;
44

5+
type BlueApiRequestBody = {
6+
planName: string;
7+
planParams: object;
8+
};
9+
510
export type BlueApiWorkerState =
611
| "IDLE"
712
| "RUNNING"
@@ -68,13 +73,10 @@ export function getWorkerStatus(): Promise<BlueApiWorkerState> {
6873

6974
// Note. fetch only rejects a promise on network errors, but http errors
7075
// must be caught by checking the response
71-
export function submitTask(
72-
planName: string,
73-
planParams: object
74-
): Promise<string | void> {
76+
function submitTask(request: BlueApiRequestBody): Promise<string | void> {
7577
return blueApiCall("/tasks", "POST", {
76-
name: planName,
77-
params: planParams,
78+
name: request.planName,
79+
params: request.planParams,
7880
}).then((res) => {
7981
if (!res.ok) {
8082
throw new Error(
@@ -85,7 +87,7 @@ export function submitTask(
8587
});
8688
}
8789

88-
export function runTask(taskId: string): Promise<string | void> {
90+
function runTask(taskId: string): Promise<string | void> {
8991
return blueApiCall("/worker/task", "PUT", { task_id: taskId }).then((res) => {
9092
if (!res.ok) {
9193
throw new Error(`Unable to run task, response error ${res.statusText}`);
@@ -95,10 +97,9 @@ export function runTask(taskId: string): Promise<string | void> {
9597
}
9698

9799
export function submitAndRunPlanImmediately(
98-
planName: string,
99-
planParams: object
100+
request: BlueApiRequestBody
100101
): Promise<string | void> {
101-
return submitTask(planName, planParams)
102+
return submitTask(request)
102103
.then((res) => {
103104
if (res) {
104105
runTask(res);

0 commit comments

Comments
 (0)