@effect-agent/storage-cloudflare 0.1.0-beta.48 → 0.1.0-beta.50

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.
@@ -12,6 +12,7 @@ import {
12
12
  import {
13
13
  AbortCommand,
14
14
  AbortIntent,
15
+ AbortIntentRequest,
15
16
  AdmissionAdmitted,
16
17
  AdmissionConflict,
17
18
  AdmissionNotAdmitted,
@@ -217,6 +218,15 @@ class MaxQueueSequenceRow extends Schema.Class<MaxQueueSequenceRow>("MaxQueueSeq
217
218
  max_queue_sequence: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
218
219
  }) {}
219
220
 
221
+ class AbortIntentLookupRow extends Schema.Class<AbortIntentLookupRow>("AbortIntentLookupRow")({
222
+ submission_id: BoundedIdentifier,
223
+ abort_submission_id: Schema.NullOr(BoundedIdentifier),
224
+ author: Schema.NullOr(BoundedIdentifier),
225
+ reason: Schema.NullOr(BoundedStoredText),
226
+ requested_at: Schema.NullOr(BoundedTimestamp),
227
+ canonical_record_id: Schema.NullOr(BoundedIdentifier),
228
+ }) {}
229
+
220
230
  class CanonicalRecordIdRow extends Schema.Class<CanonicalRecordIdRow>("CanonicalRecordIdRow")({
221
231
  record_id: BoundedIdentifier,
222
232
  }) {}
@@ -3012,6 +3022,77 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
3012
3022
  LedgerError
3013
3023
  >(undefined, scanPage);
3014
3024
 
3025
+ const readAbortIntentForSubmission: SubmissionLedger["Service"]["readAbortIntent"] = Effect.fn(
3026
+ "DoSubmissionLedger.readAbortIntentForSubmission",
3027
+ )(function* (request) {
3028
+ const operation = "ledger read abort intent";
3029
+
3030
+ const validated = yield* Schema.decodeUnknownEffect(Schema.toType(AbortIntentRequest))(
3031
+ request,
3032
+ ).pipe(Effect.mapError(internalFailure(operation)));
3033
+
3034
+ const recordId = submissionAbortRecordId(validated.submissionId);
3035
+
3036
+ const rows = yield* sql<Record<string, unknown>>`
3037
+ SELECT
3038
+ submission.submission_id,
3039
+ abort.submission_id AS abort_submission_id,
3040
+ abort.author,
3041
+ abort.reason,
3042
+ abort.requested_at,
3043
+ canonical.record_id AS canonical_record_id
3044
+ FROM effect_agent_submissions AS submission
3045
+ LEFT JOIN effect_agent_abort_intents AS abort
3046
+ ON abort.submission_id = submission.submission_id
3047
+ LEFT JOIN effect_agent_canonical_records AS canonical
3048
+ ON canonical.thread_id = submission.thread_id
3049
+ AND canonical.record_id = ${recordId}
3050
+ WHERE submission.submission_id = ${validated.submissionId}
3051
+ `.pipe(Effect.mapError(sqlFailure(operation)));
3052
+
3053
+ const decoded = yield* decodeRows(
3054
+ Schema.Array(AbortIntentLookupRow),
3055
+ "effect_agent_abort_intents",
3056
+ validated.submissionId,
3057
+ rows,
3058
+ ).pipe(Effect.mapError(internalFailure(operation)));
3059
+
3060
+ if (decoded.length === 0) {
3061
+ return yield* LedgerError.make({
3062
+ operation,
3063
+ message: `Unknown submission ${validated.submissionId}.`,
3064
+ });
3065
+ }
3066
+ if (decoded.length !== 1) {
3067
+ return yield* corruptionFailure(
3068
+ operation,
3069
+ "effect_agent_abort_intents",
3070
+ validated.submissionId,
3071
+ "An abort intent lookup returned more than one row.",
3072
+ );
3073
+ }
3074
+ const row = decoded[0];
3075
+
3076
+ if (row.abort_submission_id === null) return undefined;
3077
+
3078
+ return yield* decodeAbortIntent({
3079
+ submissionId: row.abort_submission_id,
3080
+ author: row.author,
3081
+ reason: row.reason,
3082
+ requestedAt: row.requested_at,
3083
+ ...(row.canonical_record_id === null ? {} : { canonicalRecordId: row.canonical_record_id }),
3084
+ }).pipe(
3085
+ Effect.mapError((error) =>
3086
+ corruptionFailure(
3087
+ operation,
3088
+ "effect_agent_abort_intents",
3089
+ validated.submissionId,
3090
+ error.message,
3091
+ ),
3092
+ ),
3093
+ );
3094
+ });
3095
+
3015
3096
  const loadRecoverySnapshot: SubmissionLedger["Service"]["loadRecoverySnapshot"] = Effect.fn(
3016
3097
  "DoSubmissionLedger.loadRecoverySnapshot",
3017
3098
  )(function* (request: RecoverySnapshotRequest) {
@@ -3281,6 +3362,7 @@ const makeServices = Effect.fn("DoSubmissionLedger.makeServices")(function* () {
3281
3362
  releaseChildBudget,
3282
3363
  scanNonterminal,
3283
3364
  loadRecoverySnapshot,
3365
+ readAbortIntent: readAbortIntentForSubmission,
3284
3366
  }),
3285
3367
  );
3286
3368
  });