@effect-agent/storage-cloudflare 0.1.0-beta.69 → 0.1.0-beta.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DoMessageDeliveryStore.mjs +1 -1
- package/dist/{DoStorageVersion-C05M2uDX.d.mts → DoStorageVersion-x5OOurvZ.d.mts} +4 -2
- package/dist/DoStorageVersion.d.mts +1 -1
- package/dist/DoStorageVersion.mjs +2 -2
- package/dist/DoSubmissionLedger.mjs +56 -33
- package/dist/DoSubmissionLedger.mjs.map +1 -1
- package/dist/DoThreadStore.mjs +1 -1
- package/dist/PortProtocol.d.mts +45 -45
- package/dist/{do-journal-CllwJfgW.mjs → do-journal-DnzUmhPA.mjs} +58 -38
- package/dist/do-journal-DnzUmhPA.mjs.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/{migrations-BK3kMBdI.mjs → migrations-Ba_kOrSx.mjs} +9 -4
- package/dist/migrations-Ba_kOrSx.mjs.map +1 -0
- package/package.json +1 -1
- package/src/DoSubmissionLedger.ts +128 -63
- package/src/internal/do-journal.ts +54 -14
- package/src/internal/migrations.ts +10 -1
- package/dist/do-journal-CllwJfgW.mjs.map +0 -1
- package/dist/migrations-BK3kMBdI.mjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { DoStorageConfig } from "./DoStorageConfig.mjs";
|
|
3
3
|
import { DoStorageFailpoint } from "./DoStorageFailpoint.mjs";
|
|
4
|
-
import { a as initializeDoJournal } from "./do-journal-
|
|
4
|
+
import { a as initializeDoJournal } from "./do-journal-DnzUmhPA.mjs";
|
|
5
5
|
import { MessageDeliveryError, MessageDeliveryStore } from "@effect-agent/thread/MessageDelivery";
|
|
6
6
|
import { SqlMessageDeliveryTransaction, makeSqlMessageDeliveryStore } from "@effect-agent/thread/SqlMessageDeliveryStore";
|
|
7
7
|
import { Effect, Layer } from "effect";
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import "effect/unstable/sql/SqlClient";
|
|
1
3
|
import { SqliteMigrator } from "@effect/sql-sqlite-do";
|
|
2
4
|
//#region src/internal/migrations.d.ts
|
|
3
5
|
/** The current storage version recorded in `effect_agent_meta`. */
|
|
4
|
-
declare const CurrentDoStorageVersion =
|
|
6
|
+
declare const CurrentDoStorageVersion = 6;
|
|
5
7
|
declare namespace DoStorageVersion_d_exports {
|
|
6
8
|
export { CurrentDoStorageVersion };
|
|
7
9
|
}
|
|
8
10
|
//#endregion
|
|
9
11
|
export { CurrentDoStorageVersion as n, DoStorageVersion_d_exports as t };
|
|
10
|
-
//# sourceMappingURL=DoStorageVersion-
|
|
12
|
+
//# sourceMappingURL=DoStorageVersion-x5OOurvZ.d.mts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as CurrentDoStorageVersion } from "./DoStorageVersion-
|
|
1
|
+
import { n as CurrentDoStorageVersion } from "./DoStorageVersion-x5OOurvZ.mjs";
|
|
2
2
|
export { CurrentDoStorageVersion };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { t as CurrentDoStorageVersion } from "./migrations-
|
|
2
|
+
import { t as CurrentDoStorageVersion } from "./migrations-Ba_kOrSx.mjs";
|
|
3
3
|
//#region src/DoStorageVersion.ts
|
|
4
|
-
var DoStorageVersion_exports = /* @__PURE__ */ __exportAll({ CurrentDoStorageVersion: () =>
|
|
4
|
+
var DoStorageVersion_exports = /* @__PURE__ */ __exportAll({ CurrentDoStorageVersion: () => 6 });
|
|
5
5
|
//#endregion
|
|
6
6
|
export { CurrentDoStorageVersion, DoStorageVersion_exports as t };
|
|
7
7
|
|
|
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
|
2
2
|
import { DoStorageConfig } from "./DoStorageConfig.mjs";
|
|
3
3
|
import { DoStorageFailpoint } from "./DoStorageFailpoint.mjs";
|
|
4
4
|
import { DoLedgerError, DoStorageCorruptionError, DoStorageError } from "./DoStorageError.mjs";
|
|
5
|
-
import { a as initializeDoJournal, i as decodeRows } from "./do-journal-
|
|
5
|
+
import { a as initializeDoJournal, i as decodeRows } from "./do-journal-DnzUmhPA.mjs";
|
|
6
6
|
import { storageConfigLayer, storageFailpointLayer } from "./DoThreadStore.mjs";
|
|
7
7
|
import { Clock, Context, Crypto, DateTime, Effect, Layer, Option, Schema, Stream } from "effect";
|
|
8
8
|
import * as SqlClientService from "effect/unstable/sql/SqlClient";
|
|
@@ -970,39 +970,68 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
|
|
|
970
970
|
yield* hitFailpoint("ledger:reserve-settlement:after", operation);
|
|
971
971
|
return reserved;
|
|
972
972
|
});
|
|
973
|
+
const validateFinalization = Effect.fn("DoSubmissionLedger.validateFinalization")(function* (validated, reservation) {
|
|
974
|
+
const operation = "ledger finalize settlement";
|
|
975
|
+
if (Option.isNone(reservation)) return yield* LedgerError.make({
|
|
976
|
+
operation,
|
|
977
|
+
message: `No settlement reservation exists for submission ${validated.submissionId}.`
|
|
978
|
+
});
|
|
979
|
+
if (reservation.value.settlement_id !== validated.settlementId) return yield* SettlementConflict.make({
|
|
980
|
+
submissionId: validated.submissionId,
|
|
981
|
+
existingOutcome: reservation.value.outcome
|
|
982
|
+
});
|
|
983
|
+
const reservationRecord = yield* decodeRecordEnvelopeText(reservation.value.record_json).pipe(Effect.mapError((error) => corruptionFailure(operation, "effect_agent_settlement_reservations", validated.submissionId, error.message)));
|
|
984
|
+
const settlementFailure = settlementFailureFromRecord(reservationRecord);
|
|
985
|
+
if (reservation.value.outcome === "failed" !== (settlementFailure !== void 0)) return yield* corruptionFailure(operation, "effect_agent_settlement_reservations", validated.submissionId, "The reserved outcome and canonical failure diagnostic disagree.");
|
|
986
|
+
return {
|
|
987
|
+
reservation: reservation.value,
|
|
988
|
+
settlementFailure
|
|
989
|
+
};
|
|
990
|
+
});
|
|
991
|
+
const replayFinalization = Effect.fn("DoSubmissionLedger.replayFinalization")(function* (validated, submission, { reservation, settlementFailure }) {
|
|
992
|
+
const operation = "ledger finalize settlement";
|
|
993
|
+
if (reservation.finalized_at === null) return yield* corruptionFailure(operation, "effect_agent_settlement_reservations", validated.submissionId, "A settled Submission's reservation carries no finalization timestamp.");
|
|
994
|
+
return yield* decodeSettlement({
|
|
995
|
+
submissionId: validated.submissionId,
|
|
996
|
+
settlementId: validated.settlementId,
|
|
997
|
+
receiptId: submission.receipt_id,
|
|
998
|
+
outcome: reservation.outcome,
|
|
999
|
+
...settlementFailure === void 0 ? {} : { failure: settlementFailure },
|
|
1000
|
+
settledAt: reservation.finalized_at
|
|
1001
|
+
}).pipe(Effect.mapError(internalFailure(operation)));
|
|
1002
|
+
});
|
|
973
1003
|
const finalizeSettlement = Effect.fn("DoSubmissionLedger.finalizeSettlement")(function* (request) {
|
|
974
1004
|
const operation = "ledger finalize settlement";
|
|
975
1005
|
const validated = yield* Schema.decodeUnknownEffect(Schema.toType(SettlementFinalization))(request).pipe(Effect.mapError(internalFailure(operation)));
|
|
976
1006
|
yield* hitFailpoint("ledger:finalize-settlement:before", operation);
|
|
1007
|
+
const replayRows = yield* sql`
|
|
1008
|
+
SELECT submission.*, reservation.settlement_id, reservation.outcome,
|
|
1009
|
+
reservation.record_id, reservation.record_json, reservation.record_digest,
|
|
1010
|
+
reservation.reserved_at, reservation.finalized_at
|
|
1011
|
+
FROM effect_agent_submissions AS submission
|
|
1012
|
+
INNER JOIN effect_agent_settlement_reservations AS reservation
|
|
1013
|
+
ON reservation.submission_id = submission.submission_id
|
|
1014
|
+
WHERE submission.submission_id = ${validated.submissionId} AND submission.state = 'settled'
|
|
1015
|
+
`.pipe(Effect.mapError(sqlFailure(operation)));
|
|
1016
|
+
if (replayRows.length > 1) return yield* corruptionFailure(operation, "effect_agent_submissions", validated.submissionId, "A submission primary key returned more than one row.");
|
|
1017
|
+
const replayRow = replayRows[0];
|
|
1018
|
+
if (replayRow !== void 0) {
|
|
1019
|
+
const reservations = yield* decodeRows(Schema.Array(ReservationRow), "effect_agent_settlement_reservations", validated.submissionId, replayRows).pipe(Effect.mapError(internalFailure(operation)));
|
|
1020
|
+
const state = yield* validateFinalization(validated, Option.fromUndefinedOr(reservations[0]));
|
|
1021
|
+
const submission = yield* Schema.decodeUnknownEffect(SubmissionRow)(replayRow).pipe(Effect.mapError((error) => corruptionFailure(operation, "effect_agent_submissions", validated.submissionId, error.message)));
|
|
1022
|
+
const settlement = yield* replayFinalization(validated, submission, state);
|
|
1023
|
+
yield* hitFailpoint("ledger:finalize-settlement:after", operation);
|
|
1024
|
+
return settlement;
|
|
1025
|
+
}
|
|
977
1026
|
const settlement = yield* inWriteTransaction(operation, Effect.gen(function* () {
|
|
978
|
-
const
|
|
979
|
-
|
|
980
|
-
operation,
|
|
981
|
-
message: `No settlement reservation exists for submission ${validated.submissionId}.`
|
|
982
|
-
});
|
|
983
|
-
if (reservation.value.settlement_id !== validated.settlementId) return yield* SettlementConflict.make({
|
|
984
|
-
submissionId: validated.submissionId,
|
|
985
|
-
existingOutcome: reservation.value.outcome
|
|
986
|
-
});
|
|
987
|
-
const reservationRecord = yield* decodeRecordEnvelopeText(reservation.value.record_json).pipe(Effect.mapError((error) => corruptionFailure(operation, "effect_agent_settlement_reservations", validated.submissionId, error.message)));
|
|
988
|
-
const settlementFailure = settlementFailureFromRecord(reservationRecord);
|
|
989
|
-
if (reservation.value.outcome === "failed" !== (settlementFailure !== void 0)) return yield* corruptionFailure(operation, "effect_agent_settlement_reservations", validated.submissionId, "The reserved outcome and canonical failure diagnostic disagree.");
|
|
1027
|
+
const state = yield* validateFinalization(validated, yield* readReservation(operation, validated.submissionId));
|
|
1028
|
+
const { reservation, settlementFailure } = state;
|
|
990
1029
|
const submission = yield* requireSubmission(operation, validated.submissionId);
|
|
991
|
-
if (submission.state === "settled")
|
|
992
|
-
if (reservation.value.finalized_at === null) return yield* corruptionFailure(operation, "effect_agent_settlement_reservations", validated.submissionId, "A settled Submission's reservation carries no finalization timestamp.");
|
|
993
|
-
return yield* decodeSettlement({
|
|
994
|
-
submissionId: validated.submissionId,
|
|
995
|
-
settlementId: validated.settlementId,
|
|
996
|
-
receiptId: submission.receipt_id,
|
|
997
|
-
outcome: reservation.value.outcome,
|
|
998
|
-
...settlementFailure === void 0 ? {} : { failure: settlementFailure },
|
|
999
|
-
settledAt: reservation.value.finalized_at
|
|
1000
|
-
}).pipe(Effect.mapError(internalFailure(operation)));
|
|
1001
|
-
}
|
|
1030
|
+
if (submission.state === "settled") return yield* replayFinalization(validated, submission, state);
|
|
1002
1031
|
const now = yield* currentInstant;
|
|
1003
1032
|
yield* sql`
|
|
1004
1033
|
UPDATE effect_agent_submissions
|
|
1005
|
-
SET state = 'settled', settled_outcome = ${reservation.
|
|
1034
|
+
SET state = 'settled', settled_outcome = ${reservation.outcome}
|
|
1006
1035
|
WHERE submission_id = ${validated.submissionId}
|
|
1007
1036
|
`.pipe(Effect.mapError(sqlFailure(operation)));
|
|
1008
1037
|
yield* sql`
|
|
@@ -1018,7 +1047,7 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
|
|
|
1018
1047
|
submissionId: validated.submissionId,
|
|
1019
1048
|
settlementId: validated.settlementId,
|
|
1020
1049
|
receiptId: submission.receipt_id,
|
|
1021
|
-
outcome: reservation.
|
|
1050
|
+
outcome: reservation.outcome,
|
|
1022
1051
|
...settlementFailure === void 0 ? {} : { failure: settlementFailure },
|
|
1023
1052
|
settledAt: now.iso
|
|
1024
1053
|
}).pipe(Effect.mapError(internalFailure(operation)));
|
|
@@ -1609,13 +1638,7 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
|
|
|
1609
1638
|
SELECT ${sql.literal(SUBMISSION_COLUMNS)}
|
|
1610
1639
|
FROM effect_agent_submissions
|
|
1611
1640
|
WHERE state <> 'settled'
|
|
1612
|
-
AND (
|
|
1613
|
-
thread_id > ${cursor.threadId}
|
|
1614
|
-
OR (
|
|
1615
|
-
thread_id = ${cursor.threadId}
|
|
1616
|
-
AND queue_sequence > ${cursor.queueSequence}
|
|
1617
|
-
)
|
|
1618
|
-
)
|
|
1641
|
+
AND (thread_id, queue_sequence) > (${cursor.threadId}, ${cursor.queueSequence})
|
|
1619
1642
|
ORDER BY thread_id ASC, queue_sequence ASC
|
|
1620
1643
|
LIMIT ${SCAN_PAGE_SIZE}
|
|
1621
1644
|
`).pipe(Effect.mapError(sqlFailure(operation)));
|