@makaio/storage-pg 1.0.0-dev-1789178780636 → 1.0.0-dev-1789234461336

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.
@@ -0,0 +1,13 @@
1
+ /** Cancellation read operations for PostgreSQL execution attempts. */
2
+ import type { ExecutionAttemptRepository } from '@makaio/framework/workflow-engine';
3
+ import type { ExecutionAttemptRows } from './execution-attempt-rows.js';
4
+ import type { ExecutionAttemptTransaction } from './execution-attempt-transaction.js';
5
+ type CancellationReadOperations = Pick<Required<ExecutionAttemptRepository<never>>, 'readCancellation' | 'readAttemptCancellationControl'>;
6
+ /**
7
+ * Create cancellation state read operations.
8
+ * @param rows - Attempt and control-state row accessors.
9
+ * @param transact - Transaction boundary for consistent cancellation reads.
10
+ * @returns Cancellation state read methods.
11
+ */
12
+ export declare function createCancellationReadOperations(rows: Pick<ExecutionAttemptRows, 'readAttemptRow' | 'readCancellationInSession' | 'readControlEvidenceInSession'>, transact: ExecutionAttemptTransaction['transact']): CancellationReadOperations;
13
+ export {};
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Cancellation, control-evidence, active-attempt, and outcome transitions.
3
+ *
4
+ * This private module keeps the repository's owner-fenced control plane
5
+ * separate from provisioning and runtime-operation transitions. Its context
6
+ * is concrete: callers supply the one session transaction boundary, row
7
+ * accessors, settlement CAS, and injected outcome codec used by every method.
8
+ */
9
+ import { type SQL } from 'drizzle-orm';
10
+ import type { RawSqlSession } from '@makaio/framework/storage/drizzle';
11
+ import type { ExecutionAttemptRepository, OutcomeCodec } from '@makaio/framework/workflow-engine';
12
+ import type { ExecutionAttemptRows } from './execution-attempt-rows.js';
13
+ import type { ExecutionAttemptTransaction } from './execution-attempt-transaction.js';
14
+ type ControlMethods<TOutcome> = Pick<Required<ExecutionAttemptRepository<TOutcome>>, 'requestAttemptCancellation' | 'requestCancellation' | 'readCancellation' | 'readAttemptCancellationControl' | 'recordAttemptControlReceipt' | 'reportAttemptControl' | 'getActiveAttempt' | 'canonicalizeOutcome' | 'decodeOutcome' | 'commitOutcome' | 'abandonPendingAttempt'>;
15
+ /** Dependencies shared by the control-plane repository methods. */
16
+ export interface ExecutionAttemptControlContext<TOutcome> {
17
+ readonly codec: OutcomeCodec<TOutcome>;
18
+ readonly transaction: ExecutionAttemptTransaction;
19
+ readonly rows: ExecutionAttemptRows;
20
+ readonly settleAttempt: (session: RawSqlSession, executionAttemptId: string, settlementKind: 'outcome' | 'abandoned', guard: SQL) => Promise<{
21
+ readonly rowsAffected: number;
22
+ }>;
23
+ }
24
+ /**
25
+ * Create the control-plane portion of the PostgreSQL attempt repository.
26
+ * @param context - Codec, transaction, rows, and settlement dependencies.
27
+ * @returns Cancellation, evidence, active-attempt, and outcome methods.
28
+ */
29
+ export declare function createExecutionAttemptControlOperations<TOutcome>(context: ExecutionAttemptControlContext<TOutcome>): ControlMethods<TOutcome>;
30
+ export {};
@@ -0,0 +1,33 @@
1
+ /** Core creation, replay, allocation, and recovery operations for PostgreSQL attempts. */
2
+ import { type SQL } from 'drizzle-orm';
3
+ import type { BoundedRecoveryEvidence } from '@makaio/framework/contracts';
4
+ import type { RawSqlSession } from '@makaio/framework/storage/drizzle';
5
+ import type { AllocationRecordingDecision, ExecutionAttemptRecoveryOperations, ExecutionAttemptRepository, ExecutionAttemptSettlementKind, OutcomeCodec, ProviderOperationClaim, RecordAllocationInput } from '@makaio/framework/workflow-engine';
6
+ import { type ExecutionAttemptRows } from './execution-attempt-rows.js';
7
+ import { type ExecutionAttemptTransaction } from './execution-attempt-transaction.js';
8
+ export interface ExecutionAttemptCoreOperations<TOutcome> {
9
+ readonly methods: Pick<Required<ExecutionAttemptRepository<TOutcome>>, 'createAttempt' | 'ensureAttempt' | 'readAttemptSettlement' | 'readBootstrapStartState'>;
10
+ readonly recovery: ExecutionAttemptRecoveryOperations;
11
+ readonly applyAllocation: ApplyAllocation;
12
+ readonly settleAttempt: SettleAttempt;
13
+ readonly settleAndCompletePreallocationOperation: SettleAndCompletePreallocationOperation;
14
+ }
15
+ interface ExecutionAttemptCoreContext<TOutcome> {
16
+ readonly codec: OutcomeCodec<TOutcome>;
17
+ readonly transaction: ExecutionAttemptTransaction;
18
+ readonly rows: ExecutionAttemptRows;
19
+ }
20
+ type ApplyAllocation = (input: RecordAllocationInput, bootstrapClaimable: boolean) => Promise<AllocationRecordingDecision>;
21
+ type SettleAttempt = (session: RawSqlSession, executionAttemptId: string, settlementKind: NonNullable<ExecutionAttemptSettlementKind>, guard: SQL) => Promise<{
22
+ readonly rowsAffected: number;
23
+ }>;
24
+ type SettleAndCompletePreallocationOperation = (session: RawSqlSession, executionAttemptId: string, claim: ProviderOperationClaim, guard: SQL, evidence: BoundedRecoveryEvidence, alreadySettled: boolean) => Promise<{
25
+ readonly rowsAffected: number;
26
+ }>;
27
+ /**
28
+ * Create core attempt persistence, allocation, and recovery operations.
29
+ * @param options - Codec, transaction boundary, and row accessors to compose.
30
+ * @returns Core repository members and provider-transition dependencies.
31
+ */
32
+ export declare function createExecutionAttemptCore<TOutcome>(options: ExecutionAttemptCoreContext<TOutcome>): ExecutionAttemptCoreOperations<TOutcome>;
33
+ export {};
@@ -0,0 +1,15 @@
1
+ import { type ExecutionAttemptRepository } from '@makaio/framework/workflow-engine';
2
+ import type { ExecutionAttemptRows } from './execution-attempt-rows.js';
3
+ import type { ExecutionAttemptTransaction } from './execution-attempt-transaction.js';
4
+ type ProviderClaimOperations = Pick<Required<ExecutionAttemptRepository<never>>, 'takeOverProviderOperation' | 'handoffProviderOperation' | 'recordProviderOperationUncertainty'>;
5
+ interface ProviderClaimContext {
6
+ readonly transaction: Pick<ExecutionAttemptTransaction, 'transact'>;
7
+ readonly rows: Pick<ExecutionAttemptRows, 'readAttemptRow' | 'readOperationRow' | 'refuseUnauthorized'>;
8
+ }
9
+ /**
10
+ * Create the claim transition members of the provider-operation repository surface.
11
+ * @param context - Transaction and row access dependencies for claim-fenced changes.
12
+ * @returns Claim takeover, handoff, and uncertainty methods.
13
+ */
14
+ export declare function createProviderClaimOperations(context: ProviderClaimContext): ProviderClaimOperations;
15
+ export {};
@@ -0,0 +1,27 @@
1
+ /** Provider provisioning and allocation transitions for PostgreSQL attempts. */
2
+ import { type SQL } from 'drizzle-orm';
3
+ import { type BoundedRecoveryEvidence } from '@makaio/framework/contracts';
4
+ import { type AllocationRecordingDecision, type ExecutionAttemptRepository, type ProviderOperationClaim, type RecordAllocationInput } from '@makaio/framework/workflow-engine';
5
+ import type { RawSqlSession } from '@makaio/framework/storage/drizzle';
6
+ import type { ExecutionAttemptRows } from './execution-attempt-rows.js';
7
+ import type { ExecutionAttemptTransaction } from './execution-attempt-transaction.js';
8
+ /** Concrete dependencies shared by the provider-operation method group. */
9
+ export interface ProviderMethodContext {
10
+ readonly transaction: Pick<ExecutionAttemptTransaction, 'transact'>;
11
+ readonly rows: Pick<ExecutionAttemptRows, 'authorize' | 'readActiveAttemptId' | 'readAttemptRow' | 'readOperationRow' | 'refuseUnauthorized'>;
12
+ readonly applyAllocation: (input: RecordAllocationInput, bootstrapClaimable: boolean) => Promise<AllocationRecordingDecision>;
13
+ readonly settleAttempt: (session: RawSqlSession, executionAttemptId: string, settlementKind: 'abandoned' | 'infrastructure-failure', guard: SQL) => Promise<{
14
+ readonly rowsAffected: number;
15
+ }>;
16
+ readonly settleAndCompletePreallocationOperation: (session: RawSqlSession, executionAttemptId: string, claim: ProviderOperationClaim, guard: SQL, evidence: BoundedRecoveryEvidence, alreadySettled: boolean) => Promise<{
17
+ readonly rowsAffected: number;
18
+ }>;
19
+ }
20
+ type ProviderMethods = Pick<Required<ExecutionAttemptRepository<never>>, 'beginProvisioning' | 'getProviderOperation' | 'renewProviderOperationClaim' | 'takeOverProviderOperation' | 'handoffProviderOperation' | 'recordProviderOperationUncertainty' | 'completeProviderOperation' | 'recordAllocation' | 'recordProvisioningAbsent' | 'recordProvisionerIncarnationLost' | 'recordAllocationTerminated' | 'recordInfrastructureFailure'>;
21
+ /**
22
+ * Create the provider-operation methods of an execution-attempt repository.
23
+ * @param context - Transaction, row, allocation, and settlement dependencies.
24
+ * @returns Provider-operation members of the complete repository port.
25
+ */
26
+ export declare function createProviderMethods(context: ProviderMethodContext): ProviderMethods;
27
+ export {};
@@ -0,0 +1,13 @@
1
+ /** Transactional PostgreSQL realization of the execution-attempt repository. */
2
+ import type { MakaioDatabase } from '@makaio/framework/storage/drizzle';
3
+ import type { ExecutionAttemptRepository, OutcomeCodec } from '@makaio/framework/workflow-engine';
4
+ /**
5
+ * Create a full, owner-fenced PostgreSQL execution-attempt repository.
6
+ *
7
+ * The constructor accepts the branded database supplied by the storage layer;
8
+ * it never creates a pool or permits an unpinned transaction connection.
9
+ * @param db - Branded PostgreSQL database handle.
10
+ * @param codec - Owner-supplied canonical outcome codec.
11
+ * @returns The complete execution-attempt repository port.
12
+ */
13
+ export declare function createPostgresExecutionAttemptRepository<TOutcome>(db: MakaioDatabase, codec: OutcomeCodec<TOutcome>): Promise<Required<ExecutionAttemptRepository<TOutcome>>>;
@@ -0,0 +1,42 @@
1
+ import type { RawSqlSession } from '@makaio/framework/storage/drizzle';
2
+ import type { AttemptControlEvidence, AttemptReachabilityDecision, ExecutionAttemptCancellationIntent, ExecutionAttemptRecord, ProviderOperationClaim } from '@makaio/framework/workflow-engine';
3
+ import { type AttemptRow, type OperationRow } from './execution-attempt-types.js';
4
+ export { toAttemptRecord, toOperationRecord, type AttemptRow, type OperationRow } from './execution-attempt-types.js';
5
+ export type ClaimAuthorization = {
6
+ readonly kind: 'authorized';
7
+ readonly attempt: ExecutionAttemptRecord;
8
+ readonly attemptRow: AttemptRow;
9
+ readonly operation: OperationRow;
10
+ } | {
11
+ readonly kind: 'stale';
12
+ readonly attempt: ExecutionAttemptRecord;
13
+ } | {
14
+ readonly kind: 'resolved';
15
+ readonly attempt: ExecutionAttemptRecord;
16
+ } | {
17
+ readonly kind: 'not-found';
18
+ };
19
+ export type ClaimRefusal = {
20
+ readonly kind: 'stale' | 'resolved' | 'not-found';
21
+ };
22
+ export interface ExecutionAttemptRows {
23
+ readonly readCancellationInSession: (session: RawSqlSession, executionAttemptId: string) => Promise<ExecutionAttemptCancellationIntent | null>;
24
+ readonly readControlEvidenceInSession: (session: RawSqlSession, executionAttemptId: string) => Promise<AttemptControlEvidence[]>;
25
+ readonly writeCancellationInSession: (session: RawSqlSession, executionAttemptId: string, intent: ExecutionAttemptCancellationIntent) => Promise<void>;
26
+ readonly readAttemptRow: (session: RawSqlSession, executionAttemptId: string) => Promise<AttemptRow | undefined>;
27
+ readonly readOperationRow: (session: RawSqlSession, executionAttemptId: string) => Promise<OperationRow | undefined>;
28
+ readonly allocationTerminated: (session: RawSqlSession, executionAttemptId: string) => Promise<boolean>;
29
+ readonly readActiveAttemptId: (session: RawSqlSession, executionId: string) => Promise<string | null>;
30
+ readonly runtimeReachability: (session: RawSqlSession, row: AttemptRow) => Promise<AttemptReachabilityDecision | null>;
31
+ readonly authorize: (session: RawSqlSession, claim: ProviderOperationClaim) => Promise<ClaimAuthorization>;
32
+ readonly refuseUnauthorized: (session: RawSqlSession, claim: ProviderOperationClaim) => Promise<ClaimRefusal | undefined>;
33
+ }
34
+ interface ExecutionAttemptRowsContext {
35
+ readonly lockOwner: (session: RawSqlSession, executionId: string) => Promise<void>;
36
+ }
37
+ /**
38
+ * Create row operations bound to the transaction's execution-owner lock.
39
+ * @param context - Owner-lock operation shared by all row reads.
40
+ * @returns Session-local attempt, operation, and control-evidence accessors.
41
+ */
42
+ export declare function createExecutionAttemptRows(context: ExecutionAttemptRowsContext): ExecutionAttemptRows;
@@ -0,0 +1,29 @@
1
+ import type { ExecutionAttemptInstruction } from '@makaio/framework/contracts';
2
+ import { type AdmitOperationInput, type AttemptControlState, type CompleteOperationInput, type GetInstructionInput, type MarkRuntimeReadyInput, type OperationAdmissionDecision, type OperationCompletionDecision, type OperationReportDecision, type RegisterRuntimeInput, type ReportOperationInput, type RuntimeReadinessDecision, type RuntimeRegistrationDecision } from '@makaio/framework/workflow-engine';
3
+ import { type ExecutionAttemptRows } from './execution-attempt-rows.js';
4
+ import { decideByWrite, type ExecutionAttemptTransaction } from './execution-attempt-transaction.js';
5
+ /** Dependencies shared by the runtime method group. */
6
+ export interface ExecutionAttemptRuntimeContext {
7
+ readonly transact: ExecutionAttemptTransaction['transact'];
8
+ readonly decideByWrite: typeof decideByWrite;
9
+ readonly readAttemptRow: ExecutionAttemptRows['readAttemptRow'];
10
+ readonly readActiveAttemptId: ExecutionAttemptRows['readActiveAttemptId'];
11
+ readonly allocationTerminated: ExecutionAttemptRows['allocationTerminated'];
12
+ readonly runtimeReachability: ExecutionAttemptRows['runtimeReachability'];
13
+ }
14
+ /** Runtime/workflow-operation members of the execution-attempt repository. */
15
+ export interface ExecutionAttemptRuntimeMethods {
16
+ readonly registerRuntime: (input: RegisterRuntimeInput) => Promise<RuntimeRegistrationDecision>;
17
+ readonly admitOperation: (input: AdmitOperationInput) => Promise<OperationAdmissionDecision>;
18
+ readonly getInstruction: (input: GetInstructionInput) => Promise<ExecutionAttemptInstruction | null>;
19
+ readonly reportOperation: (input: ReportOperationInput) => Promise<OperationReportDecision>;
20
+ readonly completeOperation: (input: CompleteOperationInput) => Promise<OperationCompletionDecision>;
21
+ readonly markRuntimeReady: (input: MarkRuntimeReadyInput) => Promise<RuntimeReadinessDecision>;
22
+ readonly getAttemptControlState: (executionAttemptId: string) => Promise<AttemptControlState | null>;
23
+ }
24
+ /**
25
+ * Create the runtime and workflow-operation repository methods.
26
+ * @param context - Transaction and row operations shared by runtime transitions.
27
+ * @returns Runtime and workflow-operation repository methods.
28
+ */
29
+ export declare function createRuntimeMethods(context: ExecutionAttemptRuntimeContext): ExecutionAttemptRuntimeMethods;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * PostgreSQL transaction and compare-and-set primitives for execution attempts.
3
+ *
4
+ * This module owns the adapter's connection-scoped atomicity, owner fencing,
5
+ * and correlated write predicates. Repository operations compose these helpers
6
+ * with their port-specific reads and evaluators.
7
+ */
8
+ import { type SQL } from 'drizzle-orm';
9
+ import { type MakaioDatabase, type RawSqlSession } from '@makaio/framework/storage/drizzle';
10
+ import type { ProviderOperationClaim } from '@makaio/framework/workflow-engine';
11
+ /** A write that reports whether its complete durable guard still held. */
12
+ export type GuardedWrite = () => Promise<{
13
+ readonly rowsAffected: number;
14
+ }>;
15
+ /**
16
+ * The connection-scoped operations used by execution-attempt transitions.
17
+ *
18
+ * `transact` is intentionally the only entry point that issues PostgreSQL
19
+ * transaction control statements. `lockOwner` is parameterized through the
20
+ * shared advisory-lock expression factory and must run inside `transact`.
21
+ */
22
+ export interface ExecutionAttemptTransaction {
23
+ readonly transact: <TResult>(work: (session: RawSqlSession) => Promise<TResult>) => Promise<TResult>;
24
+ readonly lockOwner: (session: RawSqlSession, executionId: string) => Promise<void>;
25
+ }
26
+ /**
27
+ * Validate the database handle and create the execution-attempt transaction
28
+ * boundary.
29
+ *
30
+ * All control statements execute only while `withSession` has checked out one
31
+ * PostgreSQL connection. When rollback itself fails, both the original and
32
+ * rollback errors remain observable so the driver can discard the poisoned
33
+ * connection.
34
+ * @param db - Branded database handle to bind to one PostgreSQL session per transition.
35
+ * @returns Connection-pinned transaction and owner-lock operations.
36
+ */
37
+ export declare function createExecutionAttemptTransaction(db: MakaioDatabase): ExecutionAttemptTransaction;
38
+ /**
39
+ * Decide a transition from the row count of a write that repeats its guards.
40
+ *
41
+ * A zero-row write is re-evaluated. If durable state still permits the write,
42
+ * the stored row changed without producing a refusal and the caller has found
43
+ * a violated compare-and-set invariant.
44
+ * @param read - Re-evaluates durable state and returns either a refusal or guarded write.
45
+ * @param accepted - Decision to return after the guarded write succeeds.
46
+ * @returns The durable refusal or accepted transition decision.
47
+ */
48
+ export declare function decideByWrite<TDecision extends {
49
+ readonly kind: string;
50
+ }>(read: () => Promise<TDecision | GuardedWrite>, accepted: TDecision | (() => TDecision)): Promise<TDecision>;
51
+ /**
52
+ * Predicate asserting that a provider-operation claim still matches durable ownership.
53
+ * @param claim - Provider-operation ownership claim to match.
54
+ * @returns SQL predicate that verifies the exact stored claim.
55
+ */
56
+ export declare function claimHolds(claim: ProviderOperationClaim): SQL;
57
+ /**
58
+ * Predicate asserting that provider completion and attempt settlement have both converged.
59
+ * @param executionAttemptId - Attempt whose provider operation is inspected.
60
+ * @returns SQL predicate that permits unfinished provider convergence.
61
+ */
62
+ export declare function operationIsUnresolved(executionAttemptId: string): SQL;
63
+ /**
64
+ * Predicate asserting that an unresolved operation still authorizes its current claim holder.
65
+ * @param claim - Provider-operation ownership claim to authorize.
66
+ * @returns SQL predicate for an unresolved operation owned by the claim.
67
+ */
68
+ export declare function claimAuthorizes(claim: ProviderOperationClaim): SQL;
69
+ /**
70
+ * Predicate asserting that a provider operation still owes terminal convergence.
71
+ * @param executionAttemptId - Attempt whose operation obligation is inspected.
72
+ * @returns SQL predicate for a terminal-convergence obligation.
73
+ */
74
+ export declare function operationOwesTerminalConvergence(executionAttemptId: string): SQL;
75
+ /**
76
+ * Predicate asserting that the `execution_attempt` row being written remains active.
77
+ * @returns SQL predicate correlated to the row being updated.
78
+ */
79
+ export declare function isActiveAttemptRow(): SQL;
@@ -0,0 +1,164 @@
1
+ import type { ExecutionAttemptInstruction, ProviderAllocationRef } from '@makaio/framework/contracts';
2
+ import { type AllocationRefEvolution, type AttemptControlState, type AttemptOutcomeControlObservation, type ExecutionAttemptRecord, type ProviderOperationOwnershipRecord, type RecoverableAttemptRecord } from '@makaio/framework/workflow-engine';
3
+ export declare const INITIAL_ATTEMPT_CONTROL_STATE: AttemptControlState;
4
+ export declare const instantOf: (value: string) => number;
5
+ export declare const normalizeInstant: (value: string) => string;
6
+ export declare const createAttemptTiming: (bootstrapTimeoutMs: number) => {
7
+ createdAt: string;
8
+ bootstrapDeadlineAt: string;
9
+ };
10
+ export declare const parseInstruction: (value: ExecutionAttemptInstruction) => {
11
+ id: string;
12
+ revision: string;
13
+ workload: {
14
+ kind: string;
15
+ version: string;
16
+ input: import("@makaio/framework/contracts").JsonValue;
17
+ };
18
+ workspace?: {
19
+ provisioning: "bind" | "create";
20
+ custody: "disposable" | "external";
21
+ sourceRoots: {
22
+ id: string;
23
+ path: string;
24
+ source?: {
25
+ kind: string;
26
+ input: import("@makaio/framework/contracts").JsonValue;
27
+ } | undefined;
28
+ }[];
29
+ setup: {
30
+ command: string;
31
+ args: string[];
32
+ env: Record<string, string>;
33
+ timeoutMs: number;
34
+ }[];
35
+ } | undefined;
36
+ preservation: {
37
+ required: ("diagnostics" | "live-state" | "source-state" | "workspace-state")[];
38
+ };
39
+ };
40
+ export declare const parsePreparationResult: (value: unknown) => {
41
+ kind: "workspace-prepared";
42
+ binding: {
43
+ workspaceRoot: string;
44
+ sourceRoots: {
45
+ id: string;
46
+ path: string;
47
+ }[];
48
+ };
49
+ };
50
+ export declare const parsePreparationReceipts: (value: unknown) => {
51
+ operationId: string;
52
+ runtimeGeneration: number;
53
+ result: {
54
+ kind: "workspace-prepared";
55
+ binding: {
56
+ workspaceRoot: string;
57
+ sourceRoots: {
58
+ id: string;
59
+ path: string;
60
+ }[];
61
+ };
62
+ };
63
+ }[];
64
+ export declare const parseAllocationRef: (value: ProviderAllocationRef) => {
65
+ version: 1;
66
+ providerId: string;
67
+ providerData: Record<string, unknown>;
68
+ };
69
+ export declare const parseAllocationLifetime: (value: unknown) => "provider-managed" | "provisioner-process-bound";
70
+ export declare const parseAllocationRefEvolution: (input: AllocationRefEvolution) => {
71
+ currentRef: {
72
+ version: 1;
73
+ providerId: string;
74
+ providerData: Record<string, unknown>;
75
+ };
76
+ nextRef: {
77
+ version: 1;
78
+ providerId: string;
79
+ providerData: Record<string, unknown>;
80
+ };
81
+ };
82
+ export declare const requireAllocationRefProvider: (attempt: ExecutionAttemptRecord, allocationRef: ProviderAllocationRef) => void;
83
+ export declare const toRecoverableAttempt: (record: ExecutionAttemptRecord) => RecoverableAttemptRecord;
84
+ export interface AttemptRow extends Record<string, unknown> {
85
+ readonly execution_attempt_id: string;
86
+ readonly execution_id: string;
87
+ readonly instruction: string;
88
+ readonly preparation_receipts: string;
89
+ readonly status: string;
90
+ readonly provider_id: string | null;
91
+ readonly allocation_lifetime: string | null;
92
+ readonly provisioner_incarnation_id: string | null;
93
+ readonly allocation_ref: string | null;
94
+ readonly settlement_kind: string | null;
95
+ readonly outcome_text: string | null;
96
+ readonly outcome_control_observation: string | null;
97
+ readonly claimable: number;
98
+ readonly claim_expires_at: string | null;
99
+ readonly created_at: string;
100
+ readonly bootstrap_deadline_at: string | null;
101
+ readonly runtime_generation: number;
102
+ readonly runtime_incarnation_id: string | null;
103
+ readonly runtime_ready_at: string | null;
104
+ readonly operation_start_gate: string;
105
+ readonly active_operation_id: string | null;
106
+ readonly active_operation_kind: string | null;
107
+ readonly active_operation_key: string | null;
108
+ readonly active_operation_generation: number | null;
109
+ readonly active_operation_admitted_at: string | null;
110
+ readonly last_completed_operation_id: string | null;
111
+ }
112
+ export interface OperationRow extends Record<string, unknown> {
113
+ readonly execution_attempt_id: string;
114
+ readonly generation: number;
115
+ readonly owner_id: string | null;
116
+ readonly token: string | null;
117
+ readonly lease_expires_at: string | null;
118
+ readonly obligation: string;
119
+ readonly failure_count: number;
120
+ readonly last_failure: string | null;
121
+ readonly completion_evidence: string | null;
122
+ }
123
+ export interface ActiveAttemptRow extends Record<string, unknown> {
124
+ readonly execution_attempt_id: string;
125
+ }
126
+ /**
127
+ * Parse a stored enum member against the port-owned vocabulary.
128
+ * @param members - Allowed members in the port vocabulary.
129
+ * @param value - Stored database value to validate.
130
+ * @param column - Database column reported for an invalid value.
131
+ * @returns The validated vocabulary member.
132
+ */
133
+ export declare function parseMember<TMember extends string>(members: readonly TMember[], value: string, column: string): TMember;
134
+ /**
135
+ * Decode an optional JSON column through its value schema.
136
+ * @param json - Serialized column value, or null when absent.
137
+ * @param parse - Schema parser for the decoded JSON value.
138
+ * @returns The parsed value, or null when the column is null.
139
+ */
140
+ export declare function parseJsonColumn<TValue>(json: string | null, parse: (value: unknown) => TValue): TValue | null;
141
+ /**
142
+ * Decode the immutable cancellation observation stored with an outcome.
143
+ * @param json - Serialized control observation, or null when no outcome was committed.
144
+ * @returns The validated control observation, or null when absent.
145
+ */
146
+ export declare function decodeOutcomeControl(json: string | null): AttemptOutcomeControlObservation | null;
147
+ /**
148
+ * Decode the runtime and active-operation columns of an attempt row.
149
+ * @param row - Database attempt row to decode.
150
+ * @returns The port control-state projection.
151
+ */
152
+ export declare function decodeAttemptControlState(row: AttemptRow): AttemptControlState;
153
+ /**
154
+ * Decode a database attempt row into its public repository record.
155
+ * @param row - Database attempt row to decode.
156
+ * @returns Validated immutable execution-attempt record.
157
+ */
158
+ export declare function toAttemptRecord(row: AttemptRow): ExecutionAttemptRecord;
159
+ /**
160
+ * Decode a database provider-operation row into its public ownership record.
161
+ * @param row - Database operation row to decode.
162
+ * @returns Validated provider-operation ownership record.
163
+ */
164
+ export declare function toOperationRecord(row: OperationRow): ProviderOperationOwnershipRecord;
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@
14
14
  export { postgresStorageEngine } from './engine.js';
15
15
  export { isPostgresDuplicateObjectError, isPostgresUniqueViolationError } from './errors.js';
16
16
  export { postgresFtsSearchStrategy } from './fts-strategy.js';
17
+ export { createPostgresExecutionAttemptRepository } from './execution-attempt-repository.js';
17
18
  export { buildPostgresLedgerDdl, migrationAdvisoryLockKey, POSTGRES_MIGRATION_BEGIN } from './migrations.js';
18
19
  export { postgresTransactionLockExpressions, postgresTransactionLockKey, postgresTransactionLocks, } from './transaction-locks.js';
19
20
  /**