Skip to content
Myr

memory.ts

This file

Path

apps/platform/src/auth/identities/memory.ts

46 lines · 1.3 KiB · TypeScript

Last changed by

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–46why, one step back
1import { Handle } from "@repo/protocol/ids";
2import { Effect, Layer, Option, Ref } from "effect";34import { handleKey } from "../accounts.ts";5import { Identities, IdentityTaken } from "../identities.ts";67const keyOf = (provider: string, subject: string) => `${provider}\n${subject}`;89export const IdentitiesMemory = {10 layer: Layer.effect(11 Identities,12 Effect.gen(function* () {13 const links = yield* Ref.make(new Map<string, string>());1415 return Identities.of({16 handleOf: (provider, subject) =>17 Ref.get(links).pipe(18 Effect.map((linked) =>19 Option.map(20 Option.fromUndefinedOr(linked.get(keyOf(provider, subject))),21 (key) => Handle.make(key)22 )23 )24 ),25 link: (provider, subject, handle) =>26 Ref.modify(links, (linked) => {27 const key = keyOf(provider, subject);2829 const held = linked.get(key);3031 if (held === undefined) {32 return [true, new Map(linked).set(key, handleKey(handle))];33 }3435 return [held === handleKey(handle), linked];36 }).pipe(37 Effect.filterOrFail(38 (linked) => linked,39 () => new IdentityTaken({ provider, subject })40 ),41 Effect.asVoid42 ),43 });44 })45 ),46};