Skip to content

Commit 50e8295

Browse files
committed
fix(ci): simplify terminal codec decoding
1 parent dc26d75 commit 50e8295

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

packages/app/src/docker-git/api-terminal-codec.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ export type ApiTerminalSession = {
1212
readonly signal?: number | undefined
1313
}
1414

15+
type RawTerminalSession = {
16+
readonly id: string | null
17+
readonly projectId: string | null
18+
readonly sshCommand: string | null
19+
readonly status: string | null
20+
readonly createdAt: string | null
21+
readonly startedAt: string | undefined
22+
readonly closedAt: string | undefined
23+
readonly exitCode: number | undefined
24+
readonly signal: number | undefined
25+
}
26+
1527
const isTerminalSessionStatus = (
1628
value: string
1729
): value is ApiTerminalSession["status"] =>
@@ -20,13 +32,13 @@ const isTerminalSessionStatus = (
2032
const readOptionalNumber = (value: JsonValue | undefined): number | undefined =>
2133
typeof value === "number" ? value : undefined
2234

23-
export const decodeTerminalSession = (payload: JsonValue): ApiTerminalSession | null => {
35+
const readTerminalSession = (payload: JsonValue): RawTerminalSession | null => {
2436
const object = asObject(payload)
2537
if (object === null) {
2638
return null
2739
}
2840

29-
const session = {
41+
return {
3042
id: asString(object["id"]),
3143
projectId: asString(object["projectId"]),
3244
sshCommand: asString(object["sshCommand"]),
@@ -37,6 +49,13 @@ export const decodeTerminalSession = (payload: JsonValue): ApiTerminalSession |
3749
exitCode: readOptionalNumber(object["exitCode"]),
3850
signal: readOptionalNumber(object["signal"])
3951
}
52+
}
53+
54+
export const decodeTerminalSession = (payload: JsonValue): ApiTerminalSession | null => {
55+
const session = readTerminalSession(payload)
56+
if (session === null) {
57+
return null
58+
}
4059

4160
if (
4261
session.id === null ||

0 commit comments

Comments
 (0)