課題1〜3を解決する処理を、1本の流れにつなぎます。図の関数は、startExamination.ts の startExaminationWithEffects です(同じファイルにある S04 の startExamination とは別の関数です)。診察開始は、予約を取得し、確認し、イベントを生成し、保存します。保存の工程だけ andThrough でつなぎます。保存の結果を捨てて、event を次の工程へ渡すためです。
値がワークフローを流れる
成功
resolveAppointmentが予約を取得します。値はCheckedInの予約です。ensureFoundの中でensureAppointmentFoundが予約の有無を検証します。予約があるためokを返し、値をそのまま次へ渡します。ensureCheckedInはkindを検証します。ここから値の型はCheckedInに絞られます。- 時刻と ID はイベントを作る時点で必要なため、
startExaminationEventの中でcreateEventContextが port から取得します。取得は1回だけで、この1回の値を状態と監査記録の両方が使用します。 startExaminationEventの中でAppointment.startExaminationがExaminationStartedを生成します。Errを返さない処理であるためmapでつなぎます。andThroughがstoreを呼びます。結果のokは破棄し、保存後も必要なeventをそのまま次の行へ渡します。- 最後の
mapがevent.aggregateStateを取り出します。呼び出し元にはInExaminationが返ります。
examples/
resolveAppointment(deps)(input.appointmentId) 実行されない
Ok AppointmentState | undefined { kind: "CheckedIn", … }
.andThen(ensureFound(input.appointmentId)) 実行されない
Ok Appointment { kind: "CheckedIn", … }
.andThen(ensureCheckedIn) 実行されない
Ok CheckedIn { kind: "CheckedIn", … }
.map(startExaminationEvent(deps, input.veterinarianId)) 実行されない
Ok ExaminationStarted { kind: "ExaminationStarted", … }
.andThrough(deps.examinationStartedStore.store) 実行されない
Ok ExaminationStarted { kind: "ExaminationStarted", … }
Err AppointmentConflict { kind: "AppointmentConflict", … }
reject AppointmentPersistenceError append-audit の
examinationStartedStore.ts:186-188
ResultAsync. fromSafePromise(
Promise.resolve(). then(() => storeAtomically(event)),
). andThen((result) => result), .map((event) => event.aggregateState); 実行されない
Ok InExamination { kind: "InExamination", … }
examples/
error.kind === "AppointmentConflict"
? "conflict"
: toStartExaminationNoticeCode(error); 実行されない
応答 Response 303 /?notice=conflict
獣医師の画面
操作のお知らせ
予約が
examples/
app. onError((_error, context) => context. text("Internal Server Error", 500)); 実行されない
応答 Response 500 Internal Server Error
右の札は、その行から次の行へ渡される値です。札「Ok」は成功の Result です。