summaryrefslogtreecommitdiff
path: root/u/process
diff options
context:
space:
mode:
Diffstat (limited to 'u/process')
-rw-r--r--u/process/env.ts25
-rw-r--r--u/process/run.ts31
-rw-r--r--u/process/validate_identifier.ts15
3 files changed, 34 insertions, 37 deletions
diff --git a/u/process/env.ts b/u/process/env.ts
index 0e41b4f..c0d893c 100644
--- a/u/process/env.ts
+++ b/u/process/env.ts
@@ -1,17 +1,15 @@
import { Either, type IEither } from "@emprespresso/pengueno";
export const getRequiredEnv = <V extends string>(name: V): IEither<Error, V> =>
- Either
- .fromFailable<Error, V>(() => Deno.env.get(name) as V) // could throw when no permission.
- .flatMap((v) =>
- (v && Either.right(v)) ||
- Either.left(
- new Error(`environment variable "${name}" is required D:`),
- )
+ Either.fromFailable<Error, V>(() => Deno.env.get(name) as V) // could throw when no permission.
+ .flatMap(
+ (v) =>
+ (v && Either.right(v)) ||
+ Either.left(new Error(`environment variable "${name}" is required D:`)),
);
type ObjectFromList<T extends ReadonlyArray<string>, V = string> = {
- [K in (T extends ReadonlyArray<infer U> ? U : never)]: V;
+ [K in T extends ReadonlyArray<infer U> ? U : never]: V;
};
export const getRequiredEnvVars = <V extends string>(vars: ReadonlyArray<V>) =>
@@ -24,11 +22,12 @@ export const getRequiredEnvVars = <V extends string>(vars: ReadonlyArray<V>) =>
) => {
const [envVar, eitherVal] = x;
return acc.flatMap((args) => {
- return eitherVal.mapRight((envValue) =>
- ({
- ...args,
- [envVar]: envValue,
- }) as ObjectFromList<typeof vars>
+ return eitherVal.mapRight(
+ (envValue) =>
+ ({
+ ...args,
+ [envVar]: envValue,
+ }) as ObjectFromList<typeof vars>,
);
});
},
diff --git a/u/process/run.ts b/u/process/run.ts
index 4954438..8004f75 100644
--- a/u/process/run.ts
+++ b/u/process/run.ts
@@ -17,11 +17,12 @@ export const getStdout = <Trace>(
c: ITraceable<Command, Trace>,
options: Deno.CommandOptions = {},
): Promise<IEither<Error, string>> =>
- c.bimap(TraceUtil.withFunctionTrace(getStdout))
+ c
+ .bimap(TraceUtil.withFunctionTrace(getStdout))
.map((tCmd) => {
const cmd = tCmd.get();
tCmd.trace.trace(`:> im gonna run this command! ${cmd}`);
- const [exec, ...args] = (typeof cmd === "string") ? cmd.split(" ") : cmd;
+ const [exec, ...args] = typeof cmd === "string" ? cmd.split(" ") : cmd;
return new Deno.Command(exec, {
args,
stdout: "piped",
@@ -30,35 +31,33 @@ export const getStdout = <Trace>(
}).output();
})
.map((tOut) =>
- Either.fromFailableAsync<Error, Deno.CommandOutput>(tOut.get())
+ Either.fromFailableAsync<Error, Deno.CommandOutput>(tOut.get()),
)
.map(
TraceUtil.promiseify((tEitherOut) =>
tEitherOut.get().flatMap(({ code, stderr, stdout }) =>
- Either
- .fromFailable<Error, CommandOutputDecoded>(() => {
- const stdoutText = new TextDecoder().decode(stdout);
- const stderrText = new TextDecoder().decode(stderr);
- return { code, stdoutText, stderrText };
- })
+ Either.fromFailable<Error, CommandOutputDecoded>(() => {
+ const stdoutText = new TextDecoder().decode(stdout);
+ const stderrText = new TextDecoder().decode(stderr);
+ return { code, stdoutText, stderrText };
+ })
.mapLeft((e) => {
tEitherOut.trace.addTrace(LogLevel.ERROR).trace(`o.o wat ${e}`);
return new Error(`${e}`);
})
.flatMap((decodedOutput): Either<Error, string> => {
const { code, stdoutText, stderrText } = decodedOutput;
- tEitherOut.trace.addTrace(LogLevel.DEBUG).trace(
- `stderr hehehe ${stderrText}`,
- );
+ tEitherOut.trace
+ .addTrace(LogLevel.DEBUG)
+ .trace(`stderr hehehe ${stderrText}`);
if (code !== 0) {
- const msg =
- `i weceived an exit code of ${code} i wanna zewoooo :<`;
+ const msg = `i weceived an exit code of ${code} i wanna zewoooo :<`;
tEitherOut.trace.addTrace(LogLevel.ERROR).trace(msg);
return Either.left(new Error(msg));
}
return Either.right(stdoutText);
- })
- )
+ }),
+ ),
),
)
.get();
diff --git a/u/process/validate_identifier.ts b/u/process/validate_identifier.ts
index 32952a6..4e93728 100644
--- a/u/process/validate_identifier.ts
+++ b/u/process/validate_identifier.ts
@@ -1,7 +1,7 @@
import { Either, type IEither } from "@emprespresso/pengueno";
export const validateIdentifier = (token: string) => {
- return (/^[a-zA-Z0-9_\-:. \/]+$/).test(token) && !token.includes("..");
+ return /^[a-zA-Z0-9_\-:. \/]+$/.test(token) && !token.includes("..");
};
// ensure {@param obj} is a Record<string, string> with stuff that won't
@@ -12,13 +12,12 @@ export const validateExecutionEntries = <
K extends symbol | number | string = symbol | number | string,
>(
obj: Record<K, T>,
-): IEither<
- Array<InvalidEntry<K, T>>,
- Record<string, string>
-> => {
- const invalidEntries = <Array<InvalidEntry<K, T>>> Object.entries(obj).filter(
- (e) => !e.every((x) => typeof x === "string" && validateIdentifier(x)),
+): IEither<Array<InvalidEntry<K, T>>, Record<string, string>> => {
+ const invalidEntries = <Array<InvalidEntry<K, T>>>(
+ Object.entries(obj).filter(
+ (e) => !e.every((x) => typeof x === "string" && validateIdentifier(x)),
+ )
);
if (invalidEntries.length > 0) return Either.left(invalidEntries);
- return Either.right(<Record<string, string>> obj);
+ return Either.right(<Record<string, string>>obj);
};