diff --git a/healthUtil.ts b/healthUtil.ts index d2b5e1d..d332fe5 100644 --- a/healthUtil.ts +++ b/healthUtil.ts @@ -1,4 +1,5 @@ -import { Effects, ExpectedExports, ResultType } from "./types.ts"; +import { Effects, ResultType } from "./types.ts"; +import { error, errorCode, ok } from "./util.ts"; export const checkWebUrl: ( url: string, @@ -19,15 +20,9 @@ export const checkWebUrl: ( }; // Ensure the starting duration is pass a minimum -const guardDurationAboveMinimum = ( +export const guardDurationAboveMinimum = ( input: { duration: number; minimumTime: number }, ) => (input.duration <= input.minimumTime) ? Promise.reject(errorCode(60, "Starting")) : null; - -const errorCode = (code: number, error: string) => ({ - "error-code": [code, error] as const, -}); -const error = (error: string) => ({ error }); -const ok = { result: null }; diff --git a/types.ts b/types.ts index c948ca5..297dced 100644 --- a/types.ts +++ b/types.ts @@ -32,6 +32,12 @@ export namespace ExpectedExports { config?: Config, ) => Promise>; }; + + /** + * This is the entrypoint for the main container. Used to start up something like the service that the + * package represents, like running a bitcoind in a bitcoind-wrapper. + */ + export type main = (effects: Effects) => Promise>; } /** Used to reach out from the pure js runtime */ @@ -58,25 +64,23 @@ export type Effects = { input: { volumeId: string; path: string }, ): Promise>; - runCommand( input: { - command: string, - args?: string[], - timeoutMillis?: number + command: string; + args?: string[]; + timeoutMillis?: number; }, ): Promise>; runDaemon( input: { - command: string, - args?: string[], + command: string; + args?: string[]; }, ): { - wait(): Promise>, - term(): Promise + wait(): Promise>; + term(): Promise; }; - sleep( timeMs: number, ): Promise; @@ -99,12 +103,12 @@ export type Effects = { fetch(url: string, options?: { method?: - | "GET" - | "POST" - | "PUT" - | "DELETE" - | "HEAD" - | "PATCH"; + | "GET" + | "POST" + | "PUT" + | "DELETE" + | "HEAD" + | "PATCH"; headers?: Record; body?: string; }): Promise<{ @@ -363,39 +367,39 @@ export type ValueSpecEnum = { export type SetResult = { /** These are the unix process signals */ signal: - | "SIGTERM" - | "SIGHUP" - | "SIGINT" - | "SIGQUIT" - | "SIGILL" - | "SIGTRAP" - | "SIGABRT" - | "SIGBUS" - | "SIGFPE" - | "SIGKILL" - | "SIGUSR1" - | "SIGSEGV" - | "SIGUSR2" - | "SIGPIPE" - | "SIGALRM" - | "SIGSTKFLT" - | "SIGCHLD" - | "SIGCONT" - | "SIGSTOP" - | "SIGTSTP" - | "SIGTTIN" - | "SIGTTOU" - | "SIGURG" - | "SIGXCPU" - | "SIGXFSZ" - | "SIGVTALRM" - | "SIGPROF" - | "SIGWINCH" - | "SIGIO" - | "SIGPWR" - | "SIGSYS" - | "SIGEMT" - | "SIGINFO"; + | "SIGTERM" + | "SIGHUP" + | "SIGINT" + | "SIGQUIT" + | "SIGILL" + | "SIGTRAP" + | "SIGABRT" + | "SIGBUS" + | "SIGFPE" + | "SIGKILL" + | "SIGUSR1" + | "SIGSEGV" + | "SIGUSR2" + | "SIGPIPE" + | "SIGALRM" + | "SIGSTKFLT" + | "SIGCHLD" + | "SIGCONT" + | "SIGSTOP" + | "SIGTSTP" + | "SIGTTIN" + | "SIGTTOU" + | "SIGURG" + | "SIGXCPU" + | "SIGXFSZ" + | "SIGVTALRM" + | "SIGPROF" + | "SIGWINCH" + | "SIGIO" + | "SIGPWR" + | "SIGSYS" + | "SIGEMT" + | "SIGINFO"; "depends-on": DependsOn; }; diff --git a/util.ts b/util.ts index 5ac30c4..24f6ac0 100644 --- a/util.ts +++ b/util.ts @@ -15,3 +15,9 @@ export const exists = ( effects: T.Effects, props: { path: string; volumeId: string }, ) => effects.metadata(props).then((_) => true, (_) => false); + +export const errorCode = (code: number, error: string) => ({ + "error-code": [code, error] as const, +}); +export const error = (error: string) => ({ error }); +export const ok = { result: null };