diff --git a/src/data/durable-request/get-durable-request.ts b/src/data/durable-request/get-durable-request.ts index 9295aa6..773471b 100644 --- a/src/data/durable-request/get-durable-request.ts +++ b/src/data/durable-request/get-durable-request.ts @@ -1,16 +1,18 @@ import {getDurableRequestStore} from "./store"; -import {DurableEvent} from "../durable-event"; +import {DurableEventData} from "../durable-event"; +import {ok} from "../../is"; export function getDurableRequest(durableRequestId: string) { const store = getDurableRequestStore(); return store.get(durableRequestId); } -export function getDurableRequestIdForEvent(event: DurableEvent) { +export function getDurableRequestIdForEvent(event: DurableEventData) { + ok(event.durableEventId, "Expected durableEventId"); return `${event.type}:request:${event.durableEventId}`; } -export function getDurableRequestForEvent(event: DurableEvent) { +export function getDurableRequestForEvent(event: DurableEventData) { return getDurableRequest( getDurableRequestIdForEvent(event) ); diff --git a/src/data/durable-request/set-durable-request.ts b/src/data/durable-request/set-durable-request.ts index 6629f02..f10def0 100644 --- a/src/data/durable-request/set-durable-request.ts +++ b/src/data/durable-request/set-durable-request.ts @@ -1,7 +1,7 @@ import {v4} from "uuid"; import {DurableRequest, PartialDurableRequest} from "./types"; import {getDurableRequestStore} from "./store"; -import {DurableEvent} from "../durable-event"; +import {DurableEventData} from "../durable-event"; import {getDurableRequestIdForEvent} from "./get-durable-request"; @@ -19,7 +19,7 @@ export async function setDurableRequest(data: PartialDurableRequest) { return durableRequest; } -export function setDurableRequestForEvent(data: PartialDurableRequest, event: DurableEvent) { +export function setDurableRequestForEvent(data: PartialDurableRequest, event: DurableEventData) { return setDurableRequest({ ...data, durableRequestId: getDurableRequestIdForEvent(event) diff --git a/src/fetch/events.ts b/src/fetch/events.ts index 0583bdd..8e8eadf 100644 --- a/src/fetch/events.ts +++ b/src/fetch/events.ts @@ -1,4 +1,4 @@ -import {setDurableRequest, DurableEventData, DurableRequestData} from "../data"; +import {setDurableRequest, DurableEventData, DurableRequestData, setDurableRequestForEvent} from "../data"; import {on} from "../events"; import {dispatcher} from "../events/schedule/schedule"; import {defer} from "@virtualstate/promise"; @@ -110,10 +110,7 @@ export const removeFetchDispatcherFunction = dispatcher(FETCH, async (event, dis }); const response = await handled; const durableRequest = await fromRequestResponse(request, response); - await setDurableRequest({ - ...durableRequest, - durableRequestId: `${event.type}:request:${event.durableEventId}` - }); + await setDurableRequestForEvent(durableRequest, event); } catch (error) { if (!signal.aborted) { controller?.abort(error);