From 1ab20482ab37d7962c8e69701163270e687df3ca Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Thu, 15 May 2025 23:39:29 -0700 Subject: more snapshot --- u/fn/either.ts | 31 +++++++++++++++++++++++++------ u/process/run.ts | 4 ++-- u/server/activity/health.ts | 18 ++++++++++-------- u/server/activity/mod.ts | 2 ++ u/server/filter/json.ts | 3 ++- u/server/filter/method.ts | 3 ++- u/server/mod.ts | 1 + 7 files changed, 44 insertions(+), 18 deletions(-) (limited to 'u') diff --git a/u/fn/either.ts b/u/fn/either.ts index 12240d0..916bb71 100644 --- a/u/fn/either.ts +++ b/u/fn/either.ts @@ -5,37 +5,56 @@ export interface IEither { errBranch: Mapper, okBranch: Mapper, ) => IEither; - flatMap: (mapper: Mapper>) => IEither; + moveRight: (t: Tt) => IEither; mapRight: (mapper: Mapper) => IEither; mapLeft: (mapper: Mapper) => IEither; + flatMap: (mapper: Mapper>) => IEither; + flatMapAsync: ( + mapper: Mapper>>, + ) => Promise>; } export class Either implements IEither { private constructor(private readonly err?: E, private readonly ok?: T) {} + public moveRight( + t: Tt, + ) { + return this.mapRight(() => t); + } + public mapBoth( errBranch: Mapper, okBranch: Mapper, ): Either { - if (this.err) return Either.left(errBranch(this.err)); + if (this.err !== undefined) return Either.left(errBranch(this.err)); return Either.right(okBranch(this.ok!)); } public flatMap(mapper: Mapper>): Either { - if (this.ok) return mapper(this.ok); + if (this.ok !== undefined) return mapper(this.ok); return Either.left(this.err!); } public mapRight(mapper: Mapper): IEither { - if (this.ok) return Either.right(mapper(this.ok)); + if (this.ok !== undefined) return Either.right(mapper(this.ok)); return Either.left(this.err!); } - public mapLeft(mapper: Mapper) { - if (this.err) return Either.left(mapper(this.err)); + public mapLeft(mapper: Mapper): IEither { + if (this.err !== undefined) return Either.left(mapper(this.err)); return Either.right(this.ok!); } + public async flatMapAsync( + mapper: Mapper>>, + ): Promise> { + if (this.err !== undefined) { + return Promise.resolve(Either.left(this.err)); + } + return await mapper(this.ok!).catch((err) => Either.left(err as E)); + } + static left(e: E) { return new Either(e); } diff --git a/u/process/run.ts b/u/process/run.ts index 670f567..cbf8c65 100644 --- a/u/process/run.ts +++ b/u/process/run.ts @@ -14,8 +14,8 @@ type CommandOutputDecoded = { }; export class ProcessError extends Error {} -export const getStdout = ( - c: ITraceable, +export const getStdout = ( + c: ITraceable, options: Deno.CommandOptions = {}, ): Promise> => c.bimap(TraceUtil.withFunctionTrace(getStdout)) diff --git a/u/server/activity/health.ts b/u/server/activity/health.ts index bf1f52c..7ee6629 100644 --- a/u/server/activity/health.ts +++ b/u/server/activity/health.ts @@ -1,25 +1,27 @@ import { - Either, - getRequiredEnv, - getStdout, + type IEither, type ITraceable, LogLevel, type Mapper, TraceUtil, } from "@emprespresso/pengueno"; -type HealthCheckInput = "healthy?"; -type HealthCheckOutput = "healthy!"; +export enum HealthCheckInput { + CHECK, +} +export enum HealthCheckOutput { + YAASQUEEN, +} -const HealthCheckActivity = ( +export const HealthCheckActivity = ( check: Mapper< ITraceable, - Promise> + Promise> >, ) => (req: ITraceable) => req.bimap(TraceUtil.withFunctionTrace(HealthCheckActivity)) - .flatMap((r) => r.move( "healthy?")) + .flatMap((r) => r.move(HealthCheckInput.CHECK)) .map(check) .map(TraceUtil.promiseify(({ item: health, trace }) => { health.mapBoth((e) => { diff --git a/u/server/activity/mod.ts b/u/server/activity/mod.ts index 6908c26..9d05d3c 100644 --- a/u/server/activity/mod.ts +++ b/u/server/activity/mod.ts @@ -6,3 +6,5 @@ export class r200 extends Response { export interface IActivity extends RequestFilter { } + +export * from "./health.ts"; diff --git a/u/server/filter/json.ts b/u/server/filter/json.ts index 3f11915..f8e4607 100644 --- a/u/server/filter/json.ts +++ b/u/server/filter/json.ts @@ -29,4 +29,5 @@ export const json = ( return new Response(err.message, { status: 400 }); }) ), - ).item; + ) + .item; diff --git a/u/server/filter/method.ts b/u/server/filter/method.ts index 2bf45a0..a1401b4 100644 --- a/u/server/filter/method.ts +++ b/u/server/filter/method.ts @@ -34,4 +34,5 @@ export const requireMethod = } return Either.right(method); - })).item; + })) + .item; diff --git a/u/server/mod.ts b/u/server/mod.ts index 556771d..52b26e2 100644 --- a/u/server/mod.ts +++ b/u/server/mod.ts @@ -1 +1,2 @@ export * from "./filter/mod.ts"; +export * from "./activity/mod.ts"; -- cgit v1.2.3-70-g09d2