memory.ts
This file
Path
apps/platform/src/auth/mailer/memory.ts
24 lines · 703 bytes · TypeScript
Last changed by
Sign people in by a proven email, with a display name, and Google's emailoscabrielbefore adoption125964c
History of this fileTake it
Sign people in by a proven email, with a display name, and Google's emailoscabrielbefore adoption125964c
lines 1–24why, one step back1import { Effect, Layer, Ref } from "effect";23import { MailFailed, Mailer } from "../mailer.ts";4import type { Mail } from "../mailer.ts";56// Keeps every mail sent, newest last; `failing` makes each send fail.7export const MailerMemory = {8 make: (options: { readonly failing?: boolean } = {}) =>9 Effect.gen(function* () {10 const sent = yield* Ref.make<readonly Mail[]>([]);1112 const layer = Layer.succeed(13 Mailer,14 Mailer.of({15 send: (mail) =>16 options.failing === true17 ? Effect.fail(new MailFailed())18 : Ref.update(sent, (all) => [...all, mail]),19 })20 );2122 return { layer, sent: Ref.get(sent) };23 }),24};