diff options
Diffstat (limited to 'u/server/activity')
-rw-r--r-- | u/server/activity/fourohfour.ts | 37 | ||||
-rw-r--r-- | u/server/activity/health.ts | 108 | ||||
-rw-r--r-- | u/server/activity/index.ts | 8 | ||||
-rw-r--r-- | u/server/activity/mod.ts | 13 |
4 files changed, 78 insertions, 88 deletions
diff --git a/u/server/activity/fourohfour.ts b/u/server/activity/fourohfour.ts index 33cfe5f..cd90ba0 100644 --- a/u/server/activity/fourohfour.ts +++ b/u/server/activity/fourohfour.ts @@ -1,29 +1,28 @@ import { - type IActivity, - type ITraceable, - JsonResponse, - type PenguenoRequest, - type ServerTrace, -} from "@emprespresso/pengueno"; + type IActivity, + type ITraceable, + JsonResponse, + type PenguenoRequest, + type ServerTrace, +} from '@emprespresso/pengueno'; const messages = [ - "D: meow-t found! your api call ran away!", - "404-bidden! but like...in a cute way >:3 !", - ":< your data went on a paw-sible vacation!", - "uwu~ not found, but found our hearts instead!", + 'D: meow-t found! your api call ran away!', + '404-bidden! but like...in a cute way >:3 !', + ':< your data went on a paw-sible vacation!', + 'uwu~ not found, but found our hearts instead!', ]; -const randomFourOhFour = () => - messages[Math.floor(Math.random() * messages.length)]; +const randomFourOhFour = () => messages[Math.floor(Math.random() * messages.length)]!; export interface IFourOhFourActivity { - fourOhFour: IActivity; + fourOhFour: IActivity; } export class FourOhFourActivityImpl implements IFourOhFourActivity { - public fourOhFour(req: ITraceable<PenguenoRequest, ServerTrace>) { - return req - .move(new JsonResponse(req, randomFourOhFour(), { status: 404 })) - .map((resp) => Promise.resolve(resp.get())) - .get(); - } + public fourOhFour(req: ITraceable<PenguenoRequest, ServerTrace>) { + return req + .move(new JsonResponse(req, randomFourOhFour(), { status: 404 })) + .map((resp) => Promise.resolve(resp.get())) + .get(); + } } diff --git a/u/server/activity/health.ts b/u/server/activity/health.ts index 95dfa97..b3ae559 100644 --- a/u/server/activity/health.ts +++ b/u/server/activity/health.ts @@ -1,71 +1,67 @@ import { - type IActivity, - type IEither, - type ITraceable, - JsonResponse, - LogLevel, - type Mapper, - Metric, - type PenguenoRequest, - type ServerTrace, - TraceUtil, -} from "@emprespresso/pengueno"; + type IActivity, + type IEither, + IMetric, + type ITraceable, + JsonResponse, + LogLevel, + type Mapper, + Metric, + type PenguenoRequest, + type ServerTrace, + TraceUtil, +} from '@emprespresso/pengueno'; export enum HealthCheckInput { - CHECK, + CHECK, } export enum HealthCheckOutput { - YAASSSLAYQUEEN, + YAASSSLAYQUEEN, } export interface IHealthCheckActivity { - checkHealth: IActivity; + checkHealth: IActivity; } -const healthCheckMetric = Metric.fromName("Health"); +const healthCheckMetric: IMetric = Metric.fromName('Health'); export interface HealthChecker - extends Mapper< - ITraceable<HealthCheckInput, ServerTrace>, - Promise<IEither<Error, HealthCheckOutput>> - > {} + extends Mapper<ITraceable<HealthCheckInput, ServerTrace>, Promise<IEither<Error, HealthCheckOutput>>> {} export class HealthCheckActivityImpl implements IHealthCheckActivity { - constructor(private readonly check: HealthChecker) {} + constructor(private readonly check: HealthChecker) {} - public checkHealth(req: ITraceable<PenguenoRequest, ServerTrace>) { - return req - .bimap(TraceUtil.withFunctionTrace(this.checkHealth)) - .bimap(TraceUtil.withMetricTrace(healthCheckMetric)) - .flatMap((r) => - r.move(HealthCheckInput.CHECK).map((input) => this.check(input)), - ) - .peek( - TraceUtil.promiseify((h) => - h.get().fold(({ isLeft, value }) => { - if (!isLeft) { - h.trace.trace(healthCheckMetric.success); - return; - } - h.trace.trace(healthCheckMetric.failure); - h.trace.addTrace(LogLevel.ERROR).trace(value); - }), - ), - ) - .map( - TraceUtil.promiseify((h) => - h - .get() - .mapBoth( - () => "oh no, i need to eat more vegetables (。•́︿•̀。)...", - () => "think im healthy!! (✿˘◡˘) ready to do work~", + public checkHealth(req: ITraceable<PenguenoRequest, ServerTrace>) { + return req + .bimap(TraceUtil.withFunctionTrace(this.checkHealth)) + .bimap(TraceUtil.withMetricTrace(healthCheckMetric)) + .flatMap((r) => r.move(HealthCheckInput.CHECK).map((input) => this.check(input))) + .peek( + TraceUtil.promiseify((h) => + h.get().fold(({ isLeft, value }) => { + if (!isLeft) { + h.trace.trace(healthCheckMetric.success); + return; + } + h.trace.trace(healthCheckMetric.failure); + h.trace.addTrace(LogLevel.ERROR).trace(value); + }), + ), ) - .fold( - ({ isLeft, value: message }) => - new JsonResponse(req, message, { - status: isLeft ? 500 : 200, - }), - ), - ), - ) - .get(); - } + .map( + TraceUtil.promiseify((h) => + h + .get() + .mapBoth( + () => 'oh no, i need to eat more vegetables (。•́︿•̀。)...', + () => 'think im healthy!! (✿˘◡˘) ready to do work~', + ) + .fold( + ({ isLeft, value: message }) => + new JsonResponse(req, message, { + status: isLeft ? 500 : 200, + }), + ), + ), + ) + .get(); + } } diff --git a/u/server/activity/index.ts b/u/server/activity/index.ts new file mode 100644 index 0000000..fa0a6b2 --- /dev/null +++ b/u/server/activity/index.ts @@ -0,0 +1,8 @@ +import type { ITraceable, PenguenoRequest, PenguenoResponse, ServerTrace } from '@emprespresso/pengueno'; + +export interface IActivity { + (req: ITraceable<PenguenoRequest, ServerTrace>): Promise<PenguenoResponse>; +} + +export * from './health.js'; +export * from './fourohfour.js'; diff --git a/u/server/activity/mod.ts b/u/server/activity/mod.ts deleted file mode 100644 index 82d8ec4..0000000 --- a/u/server/activity/mod.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { - ITraceable, - PenguenoRequest, - PenguenoResponse, - ServerTrace, -} from "@emprespresso/pengueno"; - -export interface IActivity { - (req: ITraceable<PenguenoRequest, ServerTrace>): Promise<PenguenoResponse>; -} - -export * from "./health.ts"; -export * from "./fourohfour.ts"; |