Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

DesktopWslDiagnostics.ts

36 lines1.2 KB

1import type { DesktopWslDiagnosticRecord } from "@t3tools/contracts";
2import * as Context from "effect/Context";
3import * as Effect from "effect/Effect";
4import * as Layer from "effect/Layer";
5import * as Option from "effect/Option";
6import * as Ref from "effect/Ref";
7​
8export class DesktopWslDiagnostics extends Context.Service<
9 DesktopWslDiagnostics,
10 {
11 readonly current: Effect.Effect<Option.Option<DesktopWslDiagnosticRecord>>;
12 readonly record: (
13 diagnostic: Omit<DesktopWslDiagnosticRecord, "occurredAt"> & { readonly occurredAt?: string },
14 ) => Effect.Effect<void>;
15 readonly clear: Effect.Effect<void>;
16 }
17>()("@t3tools/desktop/wsl/DesktopWslDiagnostics") {}
18​
19export const layer = Layer.effect(
20 DesktopWslDiagnostics,
21 Effect.gen(function* () {
22 const ref = yield* Ref.make(Option.none<DesktopWslDiagnosticRecord>());
23 return DesktopWslDiagnostics.of({
24 current: Ref.get(ref),
25 record: (diagnostic) =>
26 Ref.set(
27 ref,
28 Option.some({
29 ...diagnostic,
30 occurredAt: diagnostic.occurredAt ?? new Date().toISOString(),
31 }),
32 ),
33 clear: Ref.set(ref, Option.none()),
34 });
35 }),
36);