Skip to content
Source
Sign inSign up

HookInbox.ts

34 lines1.1 KB

1import * as Context from "effect/Context";
2import * as Effect from "effect/Effect";
3import * as Schema from "effect/Schema";
4​
5import type { HeldHook } from "./HookInboxStore.ts";
6​
7export class HookInboxError extends Schema.TaggedError<HookInboxError>()("HookInboxError", {
8 operation: Schema.Literals(["hold", "wake", "clear"]),
9 endpointKey: Schema.String,
10 cause: Schema.Defect(),
11}) {
12 override get message(): string {
13 return `Hook inbox '${this.operation}' failed for endpoint '${this.endpointKey}'`;
14 }
16​
17export class HookInbox extends Context.Service<
18 HookInbox,
19 {
20 /** False when the environment's inbox is full and nothing was stored. */
21 readonly hold: (input: {
22 readonly endpointKey: string;
23 readonly baseUrl: string;
24 readonly hook: HeldHook;
25 }) => Effect.Effect<boolean, HookInboxError>;
26 readonly wake: (input: {
27 readonly endpointKey: string;
28 readonly baseUrl: string;
29 }) => Effect.Effect<boolean, HookInboxError>;
30 readonly clear: (input: {
31 readonly endpointKey: string;
32 }) => Effect.Effect<void, HookInboxError>;
33 }
34>()("t3code-relay/hooks/HookInbox") {}