@@ -3,7 +3,7 @@ import type {
33 OrchestrationEvent ,
44 OrchestrationReadModel ,
55} from "@t3tools/contracts" ;
6- import { Effect } from "effect" ;
6+ import { DateTime , Effect } from "effect" ;
77
88import { OrchestrationCommandInvariantError } from "./Errors.ts" ;
99import {
@@ -17,17 +17,7 @@ import {
1717} from "./commandInvariants.ts" ;
1818import { projectEvent } from "./projector.ts" ;
1919
20- const nowIso = ( ) => new Date ( ) . toISOString ( ) ;
21- const defaultMetadata : Omit < OrchestrationEvent , "sequence" | "type" | "payload" > = {
22- eventId : crypto . randomUUID ( ) as OrchestrationEvent [ "eventId" ] ,
23- aggregateKind : "thread" ,
24- aggregateId : "" as OrchestrationEvent [ "aggregateId" ] ,
25- occurredAt : nowIso ( ) ,
26- commandId : null ,
27- causationEventId : null ,
28- correlationId : null ,
29- metadata : { } ,
30- } ;
20+ const currentIso = DateTime . now . pipe ( Effect . map ( DateTime . formatIso ) ) ;
3121
3222function withEventBase (
3323 input : Pick < OrchestrationCommand , "commandId" > & {
@@ -38,12 +28,12 @@ function withEventBase(
3828 } ,
3929) : Omit < OrchestrationEvent , "sequence" | "type" | "payload" > {
4030 return {
41- ...defaultMetadata ,
4231 eventId : crypto . randomUUID ( ) as OrchestrationEvent [ "eventId" ] ,
4332 aggregateKind : input . aggregateKind ,
4433 aggregateId : input . aggregateId ,
4534 occurredAt : input . occurredAt ,
4635 commandId : input . commandId ,
36+ causationEventId : null ,
4737 correlationId : input . commandId ,
4838 metadata : input . metadata ?? { } ,
4939 } ;
@@ -126,7 +116,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
126116 command,
127117 projectId : command . projectId ,
128118 } ) ;
129- const occurredAt = nowIso ( ) ;
119+ const occurredAt = yield * currentIso ;
130120 return {
131121 ...withEventBase ( {
132122 aggregateKind : "project" ,
@@ -183,7 +173,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
183173 } ) ;
184174 }
185175
186- const occurredAt = nowIso ( ) ;
176+ const occurredAt = yield * currentIso ;
187177 return {
188178 ...withEventBase ( {
189179 aggregateKind : "project" ,
@@ -239,7 +229,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
239229 command,
240230 threadId : command . threadId ,
241231 } ) ;
242- const occurredAt = nowIso ( ) ;
232+ const occurredAt = yield * currentIso ;
243233 return {
244234 ...withEventBase ( {
245235 aggregateKind : "thread" ,
@@ -261,7 +251,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
261251 command,
262252 threadId : command . threadId ,
263253 } ) ;
264- const occurredAt = nowIso ( ) ;
254+ const occurredAt = yield * currentIso ;
265255 return {
266256 ...withEventBase ( {
267257 aggregateKind : "thread" ,
@@ -284,7 +274,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
284274 command,
285275 threadId : command . threadId ,
286276 } ) ;
287- const occurredAt = nowIso ( ) ;
277+ const occurredAt = yield * currentIso ;
288278 return {
289279 ...withEventBase ( {
290280 aggregateKind : "thread" ,
@@ -306,7 +296,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
306296 command,
307297 threadId : command . threadId ,
308298 } ) ;
309- const occurredAt = nowIso ( ) ;
299+ const occurredAt = yield * currentIso ;
310300 return {
311301 ...withEventBase ( {
312302 aggregateKind : "thread" ,
@@ -334,7 +324,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
334324 command,
335325 threadId : command . threadId ,
336326 } ) ;
337- const occurredAt = nowIso ( ) ;
327+ const occurredAt = yield * currentIso ;
338328 return {
339329 ...withEventBase ( {
340330 aggregateKind : "thread" ,
@@ -357,7 +347,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
357347 command,
358348 threadId : command . threadId ,
359349 } ) ;
360- const occurredAt = nowIso ( ) ;
350+ const occurredAt = yield * currentIso ;
361351 return {
362352 ...withEventBase ( {
363353 aggregateKind : "thread" ,
0 commit comments