Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41737ab838 | ||
|
|
a36220157e | ||
|
|
d0f0d9a005 |
No files matched your search
@@ -0,0 +1,81 @@
|
|||||||
|
import { assert, it } from "@effect/vitest";
|
||||||
|
import { CommandId, MessageId, ThreadId } from "@t3tools/contracts";
|
||||||
|
import { DateTime, Effect, Layer, Option, Ref, Stream } from "effect";
|
||||||
|
import { TestClock } from "effect/testing";
|
||||||
|
|
||||||
|
import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
|
||||||
|
import {
|
||||||
|
OrchestrationCommandReceiptRepository,
|
||||||
|
type OrchestrationCommandReceipt,
|
||||||
|
} from "../../persistence/Services/OrchestrationCommandReceipts.ts";
|
||||||
|
import { OrchestrationEventStore } from "../../persistence/Services/OrchestrationEventStore.ts";
|
||||||
|
import { createEmptyReadModel } from "../projector.ts";
|
||||||
|
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
|
||||||
|
import { OrchestrationProjectionPipeline } from "../Services/ProjectionPipeline.ts";
|
||||||
|
import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
|
||||||
|
import { OrchestrationEngineLive } from "./OrchestrationEngine.ts";
|
||||||
|
|
||||||
|
it.effect("uses TestClock-backed DateTime for rejected command receipts", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const capturedReceipt = yield* Ref.make<Option.Option<OrchestrationCommandReceipt>>(
|
||||||
|
Option.none(),
|
||||||
|
);
|
||||||
|
const fixedNow = DateTime.makeUnsafe("2026-05-08T16:30:00.000Z");
|
||||||
|
const fixedNowIso = DateTime.formatIso(fixedNow);
|
||||||
|
|
||||||
|
const receiptRepositoryLayer = Layer.mock(OrchestrationCommandReceiptRepository)({
|
||||||
|
getByCommandId: () => Effect.succeed(Option.none()),
|
||||||
|
upsert: (receipt) => Ref.set(capturedReceipt, Option.some(receipt)),
|
||||||
|
});
|
||||||
|
|
||||||
|
const testLayer = OrchestrationEngineLive.pipe(
|
||||||
|
Layer.provide(
|
||||||
|
Layer.mock(ProjectionSnapshotQuery)({
|
||||||
|
getCommandReadModel: () => Effect.succeed(createEmptyReadModel(fixedNowIso)),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
Layer.provide(
|
||||||
|
Layer.mock(OrchestrationProjectionPipeline)({
|
||||||
|
bootstrap: Effect.void,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
Layer.provide(
|
||||||
|
Layer.mock(OrchestrationEventStore)({
|
||||||
|
readFromSequence: () => Stream.empty,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
Layer.provide(receiptRepositoryLayer),
|
||||||
|
Layer.provide(SqlitePersistenceMemory),
|
||||||
|
Layer.provideMerge(TestClock.layer()),
|
||||||
|
);
|
||||||
|
|
||||||
|
yield* Effect.gen(function* () {
|
||||||
|
yield* TestClock.setTime(DateTime.toEpochMillis(fixedNow));
|
||||||
|
const engine = yield* OrchestrationEngineService;
|
||||||
|
const result = yield* Effect.result(
|
||||||
|
engine.dispatch({
|
||||||
|
type: "thread.turn.start",
|
||||||
|
commandId: CommandId.make("cmd-clock-rejected"),
|
||||||
|
threadId: ThreadId.make("thread-missing-clock"),
|
||||||
|
message: {
|
||||||
|
messageId: MessageId.make("msg-clock-rejected"),
|
||||||
|
role: "user",
|
||||||
|
text: "hello",
|
||||||
|
attachments: [],
|
||||||
|
},
|
||||||
|
interactionMode: "default",
|
||||||
|
runtimeMode: "approval-required",
|
||||||
|
createdAt: fixedNowIso,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(result._tag, "Failure");
|
||||||
|
const receipt = yield* Ref.get(capturedReceipt);
|
||||||
|
assert.isTrue(Option.isSome(receipt));
|
||||||
|
if (Option.isNone(receipt)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assert.equal(receipt.value.acceptedAt, fixedNowIso);
|
||||||
|
}).pipe(Effect.provide(testLayer));
|
||||||
|
}),
|
||||||
|
);
|
||||||
@@ -7,6 +7,7 @@ import type {
|
|||||||
import { OrchestrationCommand } from "@t3tools/contracts";
|
import { OrchestrationCommand } from "@t3tools/contracts";
|
||||||
import {
|
import {
|
||||||
Cause,
|
Cause,
|
||||||
|
DateTime,
|
||||||
Deferred,
|
Deferred,
|
||||||
Duration,
|
Duration,
|
||||||
Effect,
|
Effect,
|
||||||
@@ -51,6 +52,9 @@ interface CommandEnvelope {
|
|||||||
startedAtMs: number;
|
startedAtMs: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentIso = DateTime.now.pipe(Effect.map(DateTime.formatIso));
|
||||||
|
const currentEpochMillis = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis));
|
||||||
|
|
||||||
function commandToAggregateRef(command: OrchestrationCommand): {
|
function commandToAggregateRef(command: OrchestrationCommand): {
|
||||||
readonly aggregateKind: "project" | "thread";
|
readonly aggregateKind: "project" | "thread";
|
||||||
readonly aggregateId: ProjectId | ThreadId;
|
readonly aggregateId: ProjectId | ThreadId;
|
||||||
@@ -78,7 +82,7 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
|||||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
||||||
|
|
||||||
let commandReadModel = createEmptyReadModel(new Date().toISOString());
|
let commandReadModel = createEmptyReadModel(yield* currentIso);
|
||||||
|
|
||||||
const commandQueue = yield* Queue.unbounded<CommandEnvelope>();
|
const commandQueue = yield* Queue.unbounded<CommandEnvelope>();
|
||||||
const eventPubSub = yield* PubSub.unbounded<OrchestrationEvent>();
|
const eventPubSub = yield* PubSub.unbounded<OrchestrationEvent>();
|
||||||
@@ -97,7 +101,6 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
|||||||
|
|
||||||
const processEnvelope = (envelope: CommandEnvelope): Effect.Effect<void> => {
|
const processEnvelope = (envelope: CommandEnvelope): Effect.Effect<void> => {
|
||||||
const dispatchStartSequence = commandReadModel.snapshotSequence;
|
const dispatchStartSequence = commandReadModel.snapshotSequence;
|
||||||
const processingStartedAtMs = Date.now();
|
|
||||||
const aggregateRef = commandToAggregateRef(envelope.command);
|
const aggregateRef = commandToAggregateRef(envelope.command);
|
||||||
const baseMetricAttributes = {
|
const baseMetricAttributes = {
|
||||||
commandType: envelope.command.type,
|
commandType: envelope.command.type,
|
||||||
@@ -118,164 +121,164 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return Effect.exit(
|
return Effect.gen(function* () {
|
||||||
Effect.gen(function* () {
|
const processingStartedAtMs = yield* currentEpochMillis;
|
||||||
yield* Effect.annotateCurrentSpan({
|
const exit = yield* Effect.exit(
|
||||||
"orchestration.command_id": envelope.command.commandId,
|
|
||||||
"orchestration.command_type": envelope.command.type,
|
|
||||||
"orchestration.aggregate_kind": aggregateRef.aggregateKind,
|
|
||||||
"orchestration.aggregate_id": aggregateRef.aggregateId,
|
|
||||||
});
|
|
||||||
|
|
||||||
const existingReceipt = yield* commandReceiptRepository.getByCommandId({
|
|
||||||
commandId: envelope.command.commandId,
|
|
||||||
});
|
|
||||||
if (Option.isSome(existingReceipt)) {
|
|
||||||
if (existingReceipt.value.status === "accepted") {
|
|
||||||
return {
|
|
||||||
sequence: existingReceipt.value.resultSequence,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return yield* new OrchestrationCommandPreviouslyRejectedError({
|
|
||||||
commandId: envelope.command.commandId,
|
|
||||||
detail: existingReceipt.value.error ?? "Previously rejected.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const eventBase = yield* decideOrchestrationCommand({
|
|
||||||
command: envelope.command,
|
|
||||||
readModel: commandReadModel,
|
|
||||||
});
|
|
||||||
const eventBases = Array.isArray(eventBase) ? eventBase : [eventBase];
|
|
||||||
const committedCommand = yield* sql
|
|
||||||
.withTransaction(
|
|
||||||
Effect.gen(function* () {
|
|
||||||
const committedEvents: OrchestrationEvent[] = [];
|
|
||||||
let nextCommandReadModel = commandReadModel;
|
|
||||||
|
|
||||||
for (const nextEvent of eventBases) {
|
|
||||||
const savedEvent = yield* eventStore.append(nextEvent);
|
|
||||||
nextCommandReadModel = yield* projectEvent(nextCommandReadModel, savedEvent);
|
|
||||||
yield* projectionPipeline.projectEvent(savedEvent);
|
|
||||||
committedEvents.push(savedEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
const lastSavedEvent = committedEvents.at(-1) ?? null;
|
|
||||||
if (lastSavedEvent === null) {
|
|
||||||
return yield* new OrchestrationCommandInvariantError({
|
|
||||||
commandType: envelope.command.type,
|
|
||||||
detail: "Command produced no events.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
yield* commandReceiptRepository.upsert({
|
|
||||||
commandId: envelope.command.commandId,
|
|
||||||
aggregateKind: lastSavedEvent.aggregateKind,
|
|
||||||
aggregateId: lastSavedEvent.aggregateId,
|
|
||||||
acceptedAt: lastSavedEvent.occurredAt,
|
|
||||||
resultSequence: lastSavedEvent.sequence,
|
|
||||||
status: "accepted",
|
|
||||||
error: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
committedEvents,
|
|
||||||
lastSequence: lastSavedEvent.sequence,
|
|
||||||
nextCommandReadModel,
|
|
||||||
} as const;
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.pipe(
|
|
||||||
Effect.catchTag("SqlError", (sqlError) =>
|
|
||||||
Effect.fail(
|
|
||||||
toPersistenceSqlError("OrchestrationEngine.processEnvelope:transaction")(sqlError),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
commandReadModel = committedCommand.nextCommandReadModel;
|
|
||||||
for (const [index, event] of committedCommand.committedEvents.entries()) {
|
|
||||||
yield* PubSub.publish(eventPubSub, event);
|
|
||||||
if (index === 0) {
|
|
||||||
yield* Metric.update(
|
|
||||||
Metric.withAttributes(
|
|
||||||
orchestrationCommandAckDuration,
|
|
||||||
metricAttributes({
|
|
||||||
...baseMetricAttributes,
|
|
||||||
ackEventType: event.type,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
Duration.millis(Math.max(0, Date.now() - envelope.startedAtMs)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { sequence: committedCommand.lastSequence };
|
|
||||||
}).pipe(Effect.withSpan(`orchestration.command.${envelope.command.type}`)),
|
|
||||||
).pipe(
|
|
||||||
Effect.flatMap((exit) =>
|
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const outcome = Exit.isSuccess(exit)
|
yield* Effect.annotateCurrentSpan({
|
||||||
? "success"
|
"orchestration.command_id": envelope.command.commandId,
|
||||||
: Cause.hasInterruptsOnly(exit.cause)
|
"orchestration.command_type": envelope.command.type,
|
||||||
? "interrupt"
|
"orchestration.aggregate_kind": aggregateRef.aggregateKind,
|
||||||
: "failure";
|
"orchestration.aggregate_id": aggregateRef.aggregateId,
|
||||||
yield* Metric.update(
|
});
|
||||||
Metric.withAttributes(
|
|
||||||
orchestrationCommandDuration,
|
|
||||||
metricAttributes(baseMetricAttributes),
|
|
||||||
),
|
|
||||||
Duration.millis(Math.max(0, Date.now() - processingStartedAtMs)),
|
|
||||||
);
|
|
||||||
yield* Metric.update(
|
|
||||||
Metric.withAttributes(
|
|
||||||
orchestrationCommandsTotal,
|
|
||||||
metricAttributes({
|
|
||||||
...baseMetricAttributes,
|
|
||||||
outcome,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
1,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (Exit.isSuccess(exit)) {
|
const existingReceipt = yield* commandReceiptRepository.getByCommandId({
|
||||||
yield* Deferred.succeed(envelope.result, exit.value);
|
commandId: envelope.command.commandId,
|
||||||
return;
|
});
|
||||||
|
if (Option.isSome(existingReceipt)) {
|
||||||
|
if (existingReceipt.value.status === "accepted") {
|
||||||
|
return {
|
||||||
|
sequence: existingReceipt.value.resultSequence,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return yield* new OrchestrationCommandPreviouslyRejectedError({
|
||||||
|
commandId: envelope.command.commandId,
|
||||||
|
detail: existingReceipt.value.error ?? "Previously rejected.",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const error = Cause.squash(exit.cause) as OrchestrationDispatchError;
|
const eventBase = yield* decideOrchestrationCommand({
|
||||||
if (!Schema.is(OrchestrationCommandPreviouslyRejectedError)(error)) {
|
command: envelope.command,
|
||||||
yield* reconcileReadModelAfterDispatchFailure.pipe(
|
readModel: commandReadModel,
|
||||||
Effect.catch(() =>
|
});
|
||||||
Effect.logWarning(
|
const eventBases = Array.isArray(eventBase) ? eventBase : [eventBase];
|
||||||
"failed to reconcile orchestration read model after dispatch failure",
|
const committedCommand = yield* sql
|
||||||
).pipe(
|
.withTransaction(
|
||||||
Effect.annotateLogs({
|
Effect.gen(function* () {
|
||||||
commandId: envelope.command.commandId,
|
const committedEvents: OrchestrationEvent[] = [];
|
||||||
snapshotSequence: commandReadModel.snapshotSequence,
|
let nextCommandReadModel = commandReadModel;
|
||||||
}),
|
|
||||||
|
for (const nextEvent of eventBases) {
|
||||||
|
const savedEvent = yield* eventStore.append(nextEvent);
|
||||||
|
nextCommandReadModel = yield* projectEvent(nextCommandReadModel, savedEvent);
|
||||||
|
yield* projectionPipeline.projectEvent(savedEvent);
|
||||||
|
committedEvents.push(savedEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
const lastSavedEvent = committedEvents.at(-1) ?? null;
|
||||||
|
if (lastSavedEvent === null) {
|
||||||
|
return yield* new OrchestrationCommandInvariantError({
|
||||||
|
commandType: envelope.command.type,
|
||||||
|
detail: "Command produced no events.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
yield* commandReceiptRepository.upsert({
|
||||||
|
commandId: envelope.command.commandId,
|
||||||
|
aggregateKind: lastSavedEvent.aggregateKind,
|
||||||
|
aggregateId: lastSavedEvent.aggregateId,
|
||||||
|
acceptedAt: lastSavedEvent.occurredAt,
|
||||||
|
resultSequence: lastSavedEvent.sequence,
|
||||||
|
status: "accepted",
|
||||||
|
error: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
committedEvents,
|
||||||
|
lastSequence: lastSavedEvent.sequence,
|
||||||
|
nextCommandReadModel,
|
||||||
|
} as const;
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.pipe(
|
||||||
|
Effect.catchTag("SqlError", (sqlError) =>
|
||||||
|
Effect.fail(
|
||||||
|
toPersistenceSqlError("OrchestrationEngine.processEnvelope:transaction")(
|
||||||
|
sqlError,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Schema.is(OrchestrationCommandInvariantError)(error)) {
|
commandReadModel = committedCommand.nextCommandReadModel;
|
||||||
yield* commandReceiptRepository
|
for (const [index, event] of committedCommand.committedEvents.entries()) {
|
||||||
.upsert({
|
yield* PubSub.publish(eventPubSub, event);
|
||||||
commandId: envelope.command.commandId,
|
if (index === 0) {
|
||||||
aggregateKind: aggregateRef.aggregateKind,
|
const acknowledgedAtMs = yield* currentEpochMillis;
|
||||||
aggregateId: aggregateRef.aggregateId,
|
yield* Metric.update(
|
||||||
acceptedAt: new Date().toISOString(),
|
Metric.withAttributes(
|
||||||
resultSequence: commandReadModel.snapshotSequence,
|
orchestrationCommandAckDuration,
|
||||||
status: "rejected",
|
metricAttributes({
|
||||||
error: error.message,
|
...baseMetricAttributes,
|
||||||
})
|
ackEventType: event.type,
|
||||||
.pipe(Effect.catch(() => Effect.void));
|
}),
|
||||||
|
),
|
||||||
|
Duration.millis(Math.max(0, acknowledgedAtMs - envelope.startedAtMs)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return { sequence: committedCommand.lastSequence };
|
||||||
|
}).pipe(Effect.withSpan(`orchestration.command.${envelope.command.type}`)),
|
||||||
|
);
|
||||||
|
const outcome = Exit.isSuccess(exit)
|
||||||
|
? "success"
|
||||||
|
: Cause.hasInterruptsOnly(exit.cause)
|
||||||
|
? "interrupt"
|
||||||
|
: "failure";
|
||||||
|
const processedAtMs = yield* currentEpochMillis;
|
||||||
|
yield* Metric.update(
|
||||||
|
Metric.withAttributes(orchestrationCommandDuration, metricAttributes(baseMetricAttributes)),
|
||||||
|
Duration.millis(Math.max(0, processedAtMs - processingStartedAtMs)),
|
||||||
|
);
|
||||||
|
yield* Metric.update(
|
||||||
|
Metric.withAttributes(
|
||||||
|
orchestrationCommandsTotal,
|
||||||
|
metricAttributes({
|
||||||
|
...baseMetricAttributes,
|
||||||
|
outcome,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
|
||||||
yield* Deferred.fail(envelope.result, error);
|
if (Exit.isSuccess(exit)) {
|
||||||
}),
|
yield* Deferred.succeed(envelope.result, exit.value);
|
||||||
),
|
return;
|
||||||
);
|
}
|
||||||
|
|
||||||
|
const error = Cause.squash(exit.cause) as OrchestrationDispatchError;
|
||||||
|
if (!Schema.is(OrchestrationCommandPreviouslyRejectedError)(error)) {
|
||||||
|
yield* reconcileReadModelAfterDispatchFailure.pipe(
|
||||||
|
Effect.catch(() =>
|
||||||
|
Effect.logWarning(
|
||||||
|
"failed to reconcile orchestration read model after dispatch failure",
|
||||||
|
).pipe(
|
||||||
|
Effect.annotateLogs({
|
||||||
|
commandId: envelope.command.commandId,
|
||||||
|
snapshotSequence: commandReadModel.snapshotSequence,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Schema.is(OrchestrationCommandInvariantError)(error)) {
|
||||||
|
const rejectedAt = yield* currentIso;
|
||||||
|
yield* commandReceiptRepository
|
||||||
|
.upsert({
|
||||||
|
commandId: envelope.command.commandId,
|
||||||
|
aggregateKind: aggregateRef.aggregateKind,
|
||||||
|
aggregateId: aggregateRef.aggregateId,
|
||||||
|
acceptedAt: rejectedAt,
|
||||||
|
resultSequence: commandReadModel.snapshotSequence,
|
||||||
|
status: "rejected",
|
||||||
|
error: error.message,
|
||||||
|
})
|
||||||
|
.pipe(Effect.catch(() => Effect.void));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
yield* Deferred.fail(envelope.result, error);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
yield* projectionPipeline.bootstrap;
|
yield* projectionPipeline.bootstrap;
|
||||||
@@ -293,7 +296,8 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
|||||||
const dispatch: OrchestrationEngineShape["dispatch"] = (command) =>
|
const dispatch: OrchestrationEngineShape["dispatch"] = (command) =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const result = yield* Deferred.make<{ sequence: number }, OrchestrationDispatchError>();
|
const result = yield* Deferred.make<{ sequence: number }, OrchestrationDispatchError>();
|
||||||
yield* Queue.offer(commandQueue, { command, result, startedAtMs: Date.now() });
|
const startedAtMs = yield* currentEpochMillis;
|
||||||
|
yield* Queue.offer(commandQueue, { command, result, startedAtMs });
|
||||||
return yield* Deferred.await(result);
|
return yield* Deferred.await(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { assert, it } from "@effect/vitest";
|
||||||
|
import { CommandId, ProjectId, type OrchestrationEvent } from "@t3tools/contracts";
|
||||||
|
import { Effect, Random } from "effect";
|
||||||
|
|
||||||
|
import { decideOrchestrationCommand } from "./decider.ts";
|
||||||
|
import { createEmptyReadModel } from "./projector.ts";
|
||||||
|
|
||||||
|
const createdAt = "2026-05-08T16:00:00.000Z";
|
||||||
|
type PlannedEvent = Omit<OrchestrationEvent, "sequence">;
|
||||||
|
|
||||||
|
const decideProjectCreatedEventId = decideOrchestrationCommand({
|
||||||
|
command: {
|
||||||
|
type: "project.create",
|
||||||
|
commandId: CommandId.make("cmd-deterministic-event-id"),
|
||||||
|
projectId: ProjectId.make("project-deterministic-event-id"),
|
||||||
|
title: "Deterministic",
|
||||||
|
workspaceRoot: "/tmp/deterministic",
|
||||||
|
createdAt,
|
||||||
|
},
|
||||||
|
readModel: createEmptyReadModel(createdAt),
|
||||||
|
}).pipe(
|
||||||
|
Effect.map((event) => {
|
||||||
|
const events = (Array.isArray(event) ? event : [event]) as ReadonlyArray<PlannedEvent>;
|
||||||
|
const firstEvent = events[0];
|
||||||
|
if (firstEvent) {
|
||||||
|
return firstEvent.eventId;
|
||||||
|
}
|
||||||
|
throw new Error("project.create should emit one event");
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
it.effect("uses Effect Random for deterministic event ids", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const first = yield* decideProjectCreatedEventId.pipe(Random.withSeed("decider-seed"));
|
||||||
|
const second = yield* decideProjectCreatedEventId.pipe(Random.withSeed("decider-seed"));
|
||||||
|
|
||||||
|
assert.equal(first, second);
|
||||||
|
}),
|
||||||
|
);
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import type {
|
import {
|
||||||
OrchestrationCommand,
|
EventId,
|
||||||
OrchestrationEvent,
|
type OrchestrationCommand,
|
||||||
OrchestrationReadModel,
|
type OrchestrationEvent,
|
||||||
|
type OrchestrationReadModel,
|
||||||
} from "@t3tools/contracts";
|
} from "@t3tools/contracts";
|
||||||
import { DateTime, Effect } from "effect";
|
import { DateTime, Effect, Random } from "effect";
|
||||||
|
|
||||||
import { OrchestrationCommandInvariantError } from "./Errors.ts";
|
import { OrchestrationCommandInvariantError } from "./Errors.ts";
|
||||||
import {
|
import {
|
||||||
@@ -19,16 +20,17 @@ import { projectEvent } from "./projector.ts";
|
|||||||
|
|
||||||
const currentIso = DateTime.now.pipe(Effect.map(DateTime.formatIso));
|
const currentIso = DateTime.now.pipe(Effect.map(DateTime.formatIso));
|
||||||
|
|
||||||
function withEventBase(
|
const makeEventBase = Effect.fn("orchestration.makeEventBase")(function* (
|
||||||
input: Pick<OrchestrationCommand, "commandId"> & {
|
input: Pick<OrchestrationCommand, "commandId"> & {
|
||||||
readonly aggregateKind: OrchestrationEvent["aggregateKind"];
|
readonly aggregateKind: OrchestrationEvent["aggregateKind"];
|
||||||
readonly aggregateId: OrchestrationEvent["aggregateId"];
|
readonly aggregateId: OrchestrationEvent["aggregateId"];
|
||||||
readonly occurredAt: string;
|
readonly occurredAt: string;
|
||||||
readonly metadata?: OrchestrationEvent["metadata"];
|
readonly metadata?: OrchestrationEvent["metadata"];
|
||||||
},
|
},
|
||||||
): Omit<OrchestrationEvent, "sequence" | "type" | "payload"> {
|
) {
|
||||||
|
const eventId = yield* Random.nextUUIDv4;
|
||||||
return {
|
return {
|
||||||
eventId: crypto.randomUUID() as OrchestrationEvent["eventId"],
|
eventId: EventId.make(eventId),
|
||||||
aggregateKind: input.aggregateKind,
|
aggregateKind: input.aggregateKind,
|
||||||
aggregateId: input.aggregateId,
|
aggregateId: input.aggregateId,
|
||||||
occurredAt: input.occurredAt,
|
occurredAt: input.occurredAt,
|
||||||
@@ -37,7 +39,7 @@ function withEventBase(
|
|||||||
correlationId: input.commandId,
|
correlationId: input.commandId,
|
||||||
metadata: input.metadata ?? {},
|
metadata: input.metadata ?? {},
|
||||||
};
|
};
|
||||||
}
|
});
|
||||||
|
|
||||||
type PlannedOrchestrationEvent = Omit<OrchestrationEvent, "sequence">;
|
type PlannedOrchestrationEvent = Omit<OrchestrationEvent, "sequence">;
|
||||||
|
|
||||||
@@ -91,12 +93,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "project",
|
aggregateKind: "project",
|
||||||
aggregateId: command.projectId,
|
aggregateId: command.projectId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "project.created",
|
type: "project.created",
|
||||||
payload: {
|
payload: {
|
||||||
projectId: command.projectId,
|
projectId: command.projectId,
|
||||||
@@ -118,12 +120,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
});
|
});
|
||||||
const occurredAt = yield* currentIso;
|
const occurredAt = yield* currentIso;
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "project",
|
aggregateKind: "project",
|
||||||
aggregateId: command.projectId,
|
aggregateId: command.projectId,
|
||||||
occurredAt,
|
occurredAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "project.meta-updated",
|
type: "project.meta-updated",
|
||||||
payload: {
|
payload: {
|
||||||
projectId: command.projectId,
|
projectId: command.projectId,
|
||||||
@@ -175,12 +177,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
|
|
||||||
const occurredAt = yield* currentIso;
|
const occurredAt = yield* currentIso;
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "project",
|
aggregateKind: "project",
|
||||||
aggregateId: command.projectId,
|
aggregateId: command.projectId,
|
||||||
occurredAt,
|
occurredAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "project.deleted" as const,
|
type: "project.deleted" as const,
|
||||||
payload: {
|
payload: {
|
||||||
projectId: command.projectId,
|
projectId: command.projectId,
|
||||||
@@ -201,12 +203,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.created",
|
type: "thread.created",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -231,12 +233,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
});
|
});
|
||||||
const occurredAt = yield* currentIso;
|
const occurredAt = yield* currentIso;
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt,
|
occurredAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.deleted",
|
type: "thread.deleted",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -253,12 +255,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
});
|
});
|
||||||
const occurredAt = yield* currentIso;
|
const occurredAt = yield* currentIso;
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt,
|
occurredAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.archived",
|
type: "thread.archived",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -276,12 +278,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
});
|
});
|
||||||
const occurredAt = yield* currentIso;
|
const occurredAt = yield* currentIso;
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt,
|
occurredAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.unarchived",
|
type: "thread.unarchived",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -298,12 +300,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
});
|
});
|
||||||
const occurredAt = yield* currentIso;
|
const occurredAt = yield* currentIso;
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt,
|
occurredAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.meta-updated",
|
type: "thread.meta-updated",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -326,12 +328,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
});
|
});
|
||||||
const occurredAt = yield* currentIso;
|
const occurredAt = yield* currentIso;
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt,
|
occurredAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.runtime-mode-set",
|
type: "thread.runtime-mode-set",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -349,12 +351,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
});
|
});
|
||||||
const occurredAt = yield* currentIso;
|
const occurredAt = yield* currentIso;
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt,
|
occurredAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.interaction-mode-set",
|
type: "thread.interaction-mode-set",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -395,12 +397,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const userMessageEvent: Omit<OrchestrationEvent, "sequence"> = {
|
const userMessageEvent: Omit<OrchestrationEvent, "sequence"> = {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.message-sent",
|
type: "thread.message-sent",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -415,12 +417,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
const turnStartRequestedEvent: Omit<OrchestrationEvent, "sequence"> = {
|
const turnStartRequestedEvent: Omit<OrchestrationEvent, "sequence"> = {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
causationEventId: userMessageEvent.eventId,
|
causationEventId: userMessageEvent.eventId,
|
||||||
type: "thread.turn-start-requested",
|
type: "thread.turn-start-requested",
|
||||||
payload: {
|
payload: {
|
||||||
@@ -446,12 +448,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.turn-interrupt-requested",
|
type: "thread.turn-interrupt-requested",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -468,7 +470,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
@@ -476,7 +478,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
metadata: {
|
metadata: {
|
||||||
requestId: command.requestId,
|
requestId: command.requestId,
|
||||||
},
|
},
|
||||||
}),
|
})),
|
||||||
type: "thread.approval-response-requested",
|
type: "thread.approval-response-requested",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -494,7 +496,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
@@ -502,7 +504,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
metadata: {
|
metadata: {
|
||||||
requestId: command.requestId,
|
requestId: command.requestId,
|
||||||
},
|
},
|
||||||
}),
|
})),
|
||||||
type: "thread.user-input-response-requested",
|
type: "thread.user-input-response-requested",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -520,12 +522,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.checkpoint-revert-requested",
|
type: "thread.checkpoint-revert-requested",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -542,12 +544,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.session-stop-requested",
|
type: "thread.session-stop-requested",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -563,13 +565,13 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
metadata: {},
|
metadata: {},
|
||||||
}),
|
})),
|
||||||
type: "thread.session-set",
|
type: "thread.session-set",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -585,12 +587,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.message-sent",
|
type: "thread.message-sent",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -612,12 +614,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.message-sent",
|
type: "thread.message-sent",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -639,12 +641,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.proposed-plan-upserted",
|
type: "thread.proposed-plan-upserted",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -660,12 +662,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.turn-diff-completed",
|
type: "thread.turn-diff-completed",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -687,12 +689,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
}),
|
})),
|
||||||
type: "thread.reverted",
|
type: "thread.reverted",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
@@ -716,13 +718,13 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
|||||||
.requestId as OrchestrationEvent["metadata"]["requestId"])
|
.requestId as OrchestrationEvent["metadata"]["requestId"])
|
||||||
: undefined;
|
: undefined;
|
||||||
return {
|
return {
|
||||||
...withEventBase({
|
...(yield* makeEventBase({
|
||||||
aggregateKind: "thread",
|
aggregateKind: "thread",
|
||||||
aggregateId: command.threadId,
|
aggregateId: command.threadId,
|
||||||
occurredAt: command.createdAt,
|
occurredAt: command.createdAt,
|
||||||
commandId: command.commandId,
|
commandId: command.commandId,
|
||||||
...(requestId !== undefined ? { metadata: { requestId } } : {}),
|
...(requestId !== undefined ? { metadata: { requestId } } : {}),
|
||||||
}),
|
})),
|
||||||
type: "thread.activity-appended",
|
type: "thread.activity-appended",
|
||||||
payload: {
|
payload: {
|
||||||
threadId: command.threadId,
|
threadId: command.threadId,
|
||||||
|
|||||||
Reference in new issue
Block a user