UNPKG

jamsocket

Version:

A CLI for the Jamsocket platform

72 lines (71 loc) 2.38 kB
import { type ChildProcessWithoutNullStreams } from 'child_process'; import { HTTPError } from '../api'; import type { PlaneTerminationKind, PlaneTerminationReason, V2Status, JamsocketConnectRequestBody } from '../api'; import type { Logger } from './logger'; export type PlaneConnectResponse = { backend_id: string; spawned: boolean; token: string; url: string; secret_token: string; status_url: string; status: V2Status; }; export type PlaneV2StatusMessage = { status: 'scheduled'; time: number; } | { status: 'loading'; time: number; } | { status: 'starting'; time: number; } | { status: 'waiting'; time: number; } | { status: 'ready'; time: number; } | { status: 'terminating'; time: number; termination_reason: PlaneTerminationReason; } | { status: 'hard-terminating'; time: number; termination_reason: PlaneTerminationReason; } | { status: 'terminated'; time: number; termination_reason?: PlaneTerminationReason | null; termination_kind?: PlaneTerminationKind | null; exit_error?: boolean; }; export type StreamHandle = { closed: Promise<void>; close: () => void; }; export declare class LocalPlane { private url; private process; private containerName; private logger; private _readyPromise; onExit: Promise<void>; constructor(url: string, process: ChildProcessWithoutNullStreams, containerName: string, logger: Logger); kill(): void; ready(): Promise<void>; streamLogs(backend: string, callback: (logLine: string) => void): Promise<StreamHandle>; terminate(backend: string, hard?: boolean): Promise<void | HTTPError>; streamStatus(backend: string, callback: (statusMessage: PlaneV2StatusMessage) => void): StreamHandle; spawn(image: string, connectReq: JamsocketConnectRequestBody, useStaticToken?: boolean, dockerNetwork?: string): Promise<PlaneConnectResponse | HTTPError>; } export declare function dockerKillPlaneBackends(backendNames: string[]): void; export declare function isV2StatusAlive(v2Status: V2Status): boolean; export declare function isV2ErrorStatus(v2StatusMsg: PlaneV2StatusMessage): boolean; export declare function runPlane(): { url: string; process: ChildProcessWithoutNullStreams; containerName: string; }; export declare function ensurePlaneImage(): Promise<void>;