@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 36 lines 1.51 KB
Raw
1 import * as Context from "effect/Context";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as Option from "effect/Option";
5
6 import type { ConnectionCredential } from "./catalog.ts";
7 import type { ConnectionAttemptError } from "./model.ts";
8
9 export class ConnectionCredentialStore extends Context.Service<
10 ConnectionCredentialStore,
11 {
12 readonly get: (
13 connectionId: string,
14 ) => Effect.Effect<Option.Option<ConnectionCredential>, ConnectionAttemptError>;
15 readonly put: (
16 connectionId: string,
17 credential: ConnectionCredential,
18 ) => Effect.Effect<void, ConnectionAttemptError>;
19 readonly remove: (connectionId: string) => Effect.Effect<void, ConnectionAttemptError>;
20 }
21 >()("@t3tools/client-runtime/connection/credentialStore/ConnectionCredentialStore") {}
22
23 export const make = (service: ConnectionCredentialStore["Service"]) =>
24 ConnectionCredentialStore.of(service);
25
26 /** A store that lives only as long as its layer, for tests and other throwaway runtimes. */
27 export const layerMemory = (initial: Iterable<readonly [string, ConnectionCredential]> = []) =>
28 Layer.sync(ConnectionCredentialStore, () => {
29 const stored = new Map(initial);
30 return make({
31 get: (connectionId) => Effect.sync(() => Option.fromNullishOr(stored.get(connectionId))),
32 put: (connectionId, credential) =>
33 Effect.sync(() => void stored.set(connectionId, credential)),
34 remove: (connectionId) => Effect.sync(() => void stored.delete(connectionId)),
35 });
36 });