chore: Add in some more types and tools

This commit is contained in:
BluJ
2022-10-24 10:29:40 -06:00
parent bc78461423
commit 0c36649e5a
3 changed files with 61 additions and 56 deletions

View File

@@ -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: ( export const checkWebUrl: (
url: string, url: string,
@@ -19,15 +20,9 @@ export const checkWebUrl: (
}; };
// Ensure the starting duration is pass a minimum // Ensure the starting duration is pass a minimum
const guardDurationAboveMinimum = ( export const guardDurationAboveMinimum = (
input: { duration: number; minimumTime: number }, input: { duration: number; minimumTime: number },
) => ) =>
(input.duration <= input.minimumTime) (input.duration <= input.minimumTime)
? Promise.reject(errorCode(60, "Starting")) ? Promise.reject(errorCode(60, "Starting"))
: null; : null;
const errorCode = (code: number, error: string) => ({
"error-code": [code, error] as const,
});
const error = (error: string) => ({ error });
const ok = { result: null };

100
types.ts
View File

@@ -32,6 +32,12 @@ export namespace ExpectedExports {
config?: Config, config?: Config,
) => Promise<ResultType<ActionResult>>; ) => Promise<ResultType<ActionResult>>;
}; };
/**
* 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<ResultType<null | void>>;
} }
/** Used to reach out from the pure js runtime */ /** Used to reach out from the pure js runtime */
@@ -58,25 +64,23 @@ export type Effects = {
input: { volumeId: string; path: string }, input: { volumeId: string; path: string },
): Promise<Record<string, unknown>>; ): Promise<Record<string, unknown>>;
runCommand( runCommand(
input: { input: {
command: string, command: string;
args?: string[], args?: string[];
timeoutMillis?: number timeoutMillis?: number;
}, },
): Promise<ResultType<string>>; ): Promise<ResultType<string>>;
runDaemon( runDaemon(
input: { input: {
command: string, command: string;
args?: string[], args?: string[];
}, },
): { ): {
wait(): Promise<ResultType<string>>, wait(): Promise<ResultType<string>>;
term(): Promise<void> term(): Promise<void>;
}; };
sleep( sleep(
timeMs: number, timeMs: number,
): Promise<null>; ): Promise<null>;
@@ -99,12 +103,12 @@ export type Effects = {
fetch(url: string, options?: { fetch(url: string, options?: {
method?: method?:
| "GET" | "GET"
| "POST" | "POST"
| "PUT" | "PUT"
| "DELETE" | "DELETE"
| "HEAD" | "HEAD"
| "PATCH"; | "PATCH";
headers?: Record<string, string>; headers?: Record<string, string>;
body?: string; body?: string;
}): Promise<{ }): Promise<{
@@ -363,39 +367,39 @@ export type ValueSpecEnum = {
export type SetResult = { export type SetResult = {
/** These are the unix process signals */ /** These are the unix process signals */
signal: signal:
| "SIGTERM" | "SIGTERM"
| "SIGHUP" | "SIGHUP"
| "SIGINT" | "SIGINT"
| "SIGQUIT" | "SIGQUIT"
| "SIGILL" | "SIGILL"
| "SIGTRAP" | "SIGTRAP"
| "SIGABRT" | "SIGABRT"
| "SIGBUS" | "SIGBUS"
| "SIGFPE" | "SIGFPE"
| "SIGKILL" | "SIGKILL"
| "SIGUSR1" | "SIGUSR1"
| "SIGSEGV" | "SIGSEGV"
| "SIGUSR2" | "SIGUSR2"
| "SIGPIPE" | "SIGPIPE"
| "SIGALRM" | "SIGALRM"
| "SIGSTKFLT" | "SIGSTKFLT"
| "SIGCHLD" | "SIGCHLD"
| "SIGCONT" | "SIGCONT"
| "SIGSTOP" | "SIGSTOP"
| "SIGTSTP" | "SIGTSTP"
| "SIGTTIN" | "SIGTTIN"
| "SIGTTOU" | "SIGTTOU"
| "SIGURG" | "SIGURG"
| "SIGXCPU" | "SIGXCPU"
| "SIGXFSZ" | "SIGXFSZ"
| "SIGVTALRM" | "SIGVTALRM"
| "SIGPROF" | "SIGPROF"
| "SIGWINCH" | "SIGWINCH"
| "SIGIO" | "SIGIO"
| "SIGPWR" | "SIGPWR"
| "SIGSYS" | "SIGSYS"
| "SIGEMT" | "SIGEMT"
| "SIGINFO"; | "SIGINFO";
"depends-on": DependsOn; "depends-on": DependsOn;
}; };

View File

@@ -15,3 +15,9 @@ export const exists = (
effects: T.Effects, effects: T.Effects,
props: { path: string; volumeId: string }, props: { path: string; volumeId: string },
) => effects.metadata(props).then((_) => true, (_) => false); ) => 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 };