MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeRecorder

Function makeRecorder

packages/chat/telegram/test/TelegramChat.test.ts:47–72  ·  view source on GitHub ↗
(options?: {
  readonly command?: () => Effect.Effect<ChatInteraction.CommandReply>
  readonly click?: Effect.Effect<void>
  readonly handle?: Effect.Effect<void, NotAccepted>
})

Source from the content-addressed store, hash-verified

45
46/** What reached the consumer, by kind. */
47const makeRecorder = (options?: {
48 readonly command?: () => Effect.Effect<ChatInteraction.CommandReply>
49 readonly click?: Effect.Effect<void>
50 readonly handle?: Effect.Effect<void, NotAccepted>
51}) => {
52 const events: Array<ChatEvent.ChatEvent> = []
53 const clicks: Array<ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged> = []
54 const commands: Array<ChatInteraction.CommandInvoked> = []
55 const refused: Array<ChatError> = []
56 const unhandled: Array<Schema.Json> = []
57 const handler = ChatHandler.of({
58 handle: (event) => options?.handle ?? Effect.sync(() => void events.push(event))
59 })
60 const interactions = ChatInteraction.Handler.of({
61 click: (event) => Effect.as(options?.click ?? Effect.sync(() => void clicks.push(event)), ChatInteraction.ack),
62 submit: () => Effect.succeed(ChatInteraction.close),
63 command: (event) =>
64 Effect.andThen(
65 Effect.sync(() => void commands.push(event)),
66 options?.command?.() ?? Effect.succeed(ChatInteraction.ack)
67 ),
68 refused: (_, error) => Effect.sync(() => void refused.push(error))
69 })
70 const onUnhandled = (update: Schema.Json) => Effect.sync(() => void unhandled.push(update))
71 return { events, clicks, commands, refused, unhandled, handler, interactions, onUnhandled }
72}
73
74type Recorder = ReturnType<typeof makeRecorder>
75

Callers 1

Calls 5

ofMethod · 0.65
pushMethod · 0.65
commandMethod · 0.65
syncMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected