MCPcopy Create free account
hub / github.com/CodeForBreakfast/eventsourcing / executeCommand

Function executeCommand

examples/todo-app/src/cli.ts:112–138  ·  view source on GitHub ↗
(
  todoId: TodoId,
  command: (
    state: Readonly<Option.Option<TodoState>>
  ) => Effect.Effect<ReadonlyArray<TodoEvent>, Error>,
  successMessage: string,
  noOpMessage: string
)

Source from the content-addressed store, hash-verified

110 );
111
112const executeCommand = (
113 todoId: TodoId,
114 command: (
115 state: Readonly<Option.Option<TodoState>>
116 ) => Effect.Effect<ReadonlyArray<TodoEvent>, Error>,
117 successMessage: string,
118 noOpMessage: string
119) =>
120 pipe(
121 todoId,
122 TodoAggregateRoot.load,
123 Effect.tap((state) =>
124 Console.log(
125 `Loaded state: nextEventNumber=${state.nextEventNumber}, hasData=${Option.isSome(state.data)}`
126 )
127 ),
128 Effect.flatMap((state) =>
129 processCommand(
130 state.data,
131 command,
132 todoId,
133 state.nextEventNumber,
134 successMessage,
135 noOpMessage
136 )
137 )
138 );
139
140const completeTodo = (todoId: TodoId) =>
141 executeCommand(

Callers 3

completeTodoFunction · 0.85
uncompleteTodoFunction · 0.85
deleteTodoFunction · 0.85

Calls 1

processCommandFunction · 0.85

Tested by

no test coverage detected