@smthrs/engine-store 0.0.0-stage → 1.0.0-rc.3
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/CHANGELOG.md +247 -0
- package/LICENSE +21 -0
- package/README.md +146 -2
- package/dist/cjs/ArtifactGc.d.ts +235 -0
- package/dist/cjs/ArtifactGc.d.ts.map +1 -0
- package/dist/cjs/ArtifactGc.js +183 -0
- package/dist/cjs/ArtifactGc.js.map +7 -0
- package/dist/cjs/ArtifactSync.d.ts +164 -0
- package/dist/cjs/ArtifactSync.d.ts.map +1 -0
- package/dist/cjs/ArtifactSync.js +144 -0
- package/dist/cjs/ArtifactSync.js.map +7 -0
- package/dist/cjs/CacheSync.d.ts +112 -0
- package/dist/cjs/CacheSync.d.ts.map +1 -0
- package/dist/cjs/CacheSync.js +64 -0
- package/dist/cjs/CacheSync.js.map +7 -0
- package/dist/cjs/DeferredClockFold.d.ts +354 -0
- package/dist/cjs/DeferredClockFold.d.ts.map +1 -0
- package/dist/cjs/DeferredClockFold.js +335 -0
- package/dist/cjs/DeferredClockFold.js.map +7 -0
- package/dist/cjs/DisasterRecovery.d.ts +431 -0
- package/dist/cjs/DisasterRecovery.d.ts.map +1 -0
- package/dist/cjs/DisasterRecovery.js +453 -0
- package/dist/cjs/DisasterRecovery.js.map +7 -0
- package/dist/cjs/DurableEngineState.d.ts +776 -0
- package/dist/cjs/DurableEngineState.d.ts.map +1 -0
- package/dist/cjs/DurableEngineState.js +1536 -0
- package/dist/cjs/DurableEngineState.js.map +7 -0
- package/dist/cjs/EngineStore.d.ts +158 -0
- package/dist/cjs/EngineStore.d.ts.map +1 -0
- package/dist/cjs/EngineStore.js +398 -0
- package/dist/cjs/EngineStore.js.map +7 -0
- package/dist/cjs/EngineStoreMetrics.d.ts +276 -0
- package/dist/cjs/EngineStoreMetrics.d.ts.map +1 -0
- package/dist/cjs/EngineStoreMetrics.js +135 -0
- package/dist/cjs/EngineStoreMetrics.js.map +7 -0
- package/dist/cjs/Errors.d.ts +22 -0
- package/dist/cjs/Errors.d.ts.map +1 -0
- package/dist/cjs/Errors.js +39 -0
- package/dist/cjs/Errors.js.map +7 -0
- package/dist/cjs/EventTypes.d.ts +27 -0
- package/dist/cjs/EventTypes.d.ts.map +1 -0
- package/dist/cjs/EventTypes.js +37 -0
- package/dist/cjs/EventTypes.js.map +7 -0
- package/dist/cjs/ExecutionFacts.d.ts +59 -0
- package/dist/cjs/ExecutionFacts.d.ts.map +1 -0
- package/dist/cjs/ExecutionFacts.js +123 -0
- package/dist/cjs/ExecutionFacts.js.map +7 -0
- package/dist/cjs/ExecutionSnapshot.d.ts +117 -0
- package/dist/cjs/ExecutionSnapshot.d.ts.map +1 -0
- package/dist/cjs/ExecutionSnapshot.js +111 -0
- package/dist/cjs/ExecutionSnapshot.js.map +7 -0
- package/dist/cjs/Inconsistency.d.ts +154 -0
- package/dist/cjs/Inconsistency.d.ts.map +1 -0
- package/dist/cjs/Inconsistency.js +135 -0
- package/dist/cjs/Inconsistency.js.map +7 -0
- package/dist/cjs/Migrations.d.ts +56 -0
- package/dist/cjs/Migrations.d.ts.map +1 -0
- package/dist/cjs/Migrations.js +78 -0
- package/dist/cjs/Migrations.js.map +7 -0
- package/dist/cjs/OwnerIdentity.d.ts +91 -0
- package/dist/cjs/OwnerIdentity.d.ts.map +1 -0
- package/dist/cjs/OwnerIdentity.js +65 -0
- package/dist/cjs/OwnerIdentity.js.map +7 -0
- package/dist/cjs/PlanInputStore.d.ts +110 -0
- package/dist/cjs/PlanInputStore.d.ts.map +1 -0
- package/dist/cjs/PlanInputStore.js +224 -0
- package/dist/cjs/PlanInputStore.js.map +7 -0
- package/dist/cjs/PlanMergeStore.d.ts +113 -0
- package/dist/cjs/PlanMergeStore.d.ts.map +1 -0
- package/dist/cjs/PlanMergeStore.js +255 -0
- package/dist/cjs/PlanMergeStore.js.map +7 -0
- package/dist/cjs/PlanScheduler.d.ts +363 -0
- package/dist/cjs/PlanScheduler.d.ts.map +1 -0
- package/dist/cjs/PlanScheduler.js +1090 -0
- package/dist/cjs/PlanScheduler.js.map +7 -0
- package/dist/cjs/Reconciliation.d.ts +175 -0
- package/dist/cjs/Reconciliation.d.ts.map +1 -0
- package/dist/cjs/Reconciliation.js +119 -0
- package/dist/cjs/Reconciliation.js.map +7 -0
- package/dist/cjs/ReplayOnly.d.ts +91 -0
- package/dist/cjs/ReplayOnly.d.ts.map +1 -0
- package/dist/cjs/ReplayOnly.js +52 -0
- package/dist/cjs/ReplayOnly.js.map +7 -0
- package/dist/cjs/Retention.d.ts +113 -0
- package/dist/cjs/Retention.d.ts.map +1 -0
- package/dist/cjs/Retention.js +99 -0
- package/dist/cjs/Retention.js.map +7 -0
- package/dist/cjs/RunCatalogRead.d.ts +17 -0
- package/dist/cjs/RunCatalogRead.d.ts.map +1 -0
- package/dist/cjs/RunCatalogRead.js +33 -0
- package/dist/cjs/RunCatalogRead.js.map +7 -0
- package/dist/cjs/RunChangeFeed.d.ts +75 -0
- package/dist/cjs/RunChangeFeed.d.ts.map +1 -0
- package/dist/cjs/RunChangeFeed.js +96 -0
- package/dist/cjs/RunChangeFeed.js.map +7 -0
- package/dist/cjs/RunState.d.ts +116 -0
- package/dist/cjs/RunState.d.ts.map +1 -0
- package/dist/cjs/RunState.js +76 -0
- package/dist/cjs/RunState.js.map +7 -0
- package/dist/cjs/Selection.d.ts +495 -0
- package/dist/cjs/Selection.d.ts.map +1 -0
- package/dist/cjs/Selection.js +288 -0
- package/dist/cjs/Selection.js.map +7 -0
- package/dist/cjs/SelectionStore.d.ts +141 -0
- package/dist/cjs/SelectionStore.d.ts.map +1 -0
- package/dist/cjs/SelectionStore.js +229 -0
- package/dist/cjs/SelectionStore.js.map +7 -0
- package/dist/cjs/StepBoundary.d.ts +501 -0
- package/dist/cjs/StepBoundary.d.ts.map +1 -0
- package/dist/cjs/StepBoundary.js +619 -0
- package/dist/cjs/StepBoundary.js.map +7 -0
- package/dist/cjs/StepCacheFold.d.ts +148 -0
- package/dist/cjs/StepCacheFold.d.ts.map +1 -0
- package/dist/cjs/StepCacheFold.js +131 -0
- package/dist/cjs/StepCacheFold.js.map +7 -0
- package/dist/cjs/StepSandbox.d.ts +78 -0
- package/dist/cjs/StepSandbox.d.ts.map +1 -0
- package/dist/cjs/StepSandbox.js +75 -0
- package/dist/cjs/StepSandbox.js.map +7 -0
- package/dist/cjs/WakeBus.d.ts +116 -0
- package/dist/cjs/WakeBus.d.ts.map +1 -0
- package/dist/cjs/WakeBus.js +89 -0
- package/dist/cjs/WakeBus.js.map +7 -0
- package/dist/cjs/WorkspaceSandbox.d.ts +619 -0
- package/dist/cjs/WorkspaceSandbox.d.ts.map +1 -0
- package/dist/cjs/WorkspaceSandbox.js +711 -0
- package/dist/cjs/WorkspaceSandbox.js.map +7 -0
- package/dist/cjs/index.d.ts +157 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +95 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/ActionPersistence.d.ts +276 -0
- package/dist/cjs/internal/ActionPersistence.d.ts.map +1 -0
- package/dist/cjs/internal/ActionPersistence.js +1395 -0
- package/dist/cjs/internal/ActionPersistence.js.map +7 -0
- package/dist/cjs/internal/ArtifactRoots.d.ts +38 -0
- package/dist/cjs/internal/ArtifactRoots.d.ts.map +1 -0
- package/dist/cjs/internal/ArtifactRoots.js +89 -0
- package/dist/cjs/internal/ArtifactRoots.js.map +7 -0
- package/dist/cjs/internal/AttemptAdmission.d.ts +53 -0
- package/dist/cjs/internal/AttemptAdmission.d.ts.map +1 -0
- package/dist/cjs/internal/AttemptAdmission.js +52 -0
- package/dist/cjs/internal/AttemptAdmission.js.map +7 -0
- package/dist/cjs/internal/AttemptLifecycle.d.ts +245 -0
- package/dist/cjs/internal/AttemptLifecycle.d.ts.map +1 -0
- package/dist/cjs/internal/AttemptLifecycle.js +112 -0
- package/dist/cjs/internal/AttemptLifecycle.js.map +7 -0
- package/dist/cjs/internal/AttemptProbe.d.ts +53 -0
- package/dist/cjs/internal/AttemptProbe.d.ts.map +1 -0
- package/dist/cjs/internal/AttemptProbe.js +66 -0
- package/dist/cjs/internal/AttemptProbe.js.map +7 -0
- package/dist/cjs/internal/CacheAdmission.d.ts +79 -0
- package/dist/cjs/internal/CacheAdmission.d.ts.map +1 -0
- package/dist/cjs/internal/CacheAdmission.js +71 -0
- package/dist/cjs/internal/CacheAdmission.js.map +7 -0
- package/dist/cjs/internal/CacheAgeHistory.d.ts +27 -0
- package/dist/cjs/internal/CacheAgeHistory.d.ts.map +1 -0
- package/dist/cjs/internal/CacheAgeHistory.js +61 -0
- package/dist/cjs/internal/CacheAgeHistory.js.map +7 -0
- package/dist/cjs/internal/CacheAgeVerdicts.d.ts +15 -0
- package/dist/cjs/internal/CacheAgeVerdicts.d.ts.map +1 -0
- package/dist/cjs/internal/CacheAgeVerdicts.js +73 -0
- package/dist/cjs/internal/CacheAgeVerdicts.js.map +7 -0
- package/dist/cjs/internal/CacheOutputPolicy.d.ts +24 -0
- package/dist/cjs/internal/CacheOutputPolicy.d.ts.map +1 -0
- package/dist/cjs/internal/CacheOutputPolicy.js +75 -0
- package/dist/cjs/internal/CacheOutputPolicy.js.map +7 -0
- package/dist/cjs/internal/CachePublication.d.ts +97 -0
- package/dist/cjs/internal/CachePublication.d.ts.map +1 -0
- package/dist/cjs/internal/CachePublication.js +80 -0
- package/dist/cjs/internal/CachePublication.js.map +7 -0
- package/dist/cjs/internal/CallFacts.d.ts +15 -0
- package/dist/cjs/internal/CallFacts.d.ts.map +1 -0
- package/dist/cjs/internal/CallFacts.js +97 -0
- package/dist/cjs/internal/CallFacts.js.map +7 -0
- package/dist/cjs/internal/CopiedRecord.d.ts +61 -0
- package/dist/cjs/internal/CopiedRecord.d.ts.map +1 -0
- package/dist/cjs/internal/CopiedRecord.js +134 -0
- package/dist/cjs/internal/CopiedRecord.js.map +7 -0
- package/dist/cjs/internal/DeferredPersistence.d.ts +108 -0
- package/dist/cjs/internal/DeferredPersistence.d.ts.map +1 -0
- package/dist/cjs/internal/DeferredPersistence.js +270 -0
- package/dist/cjs/internal/DeferredPersistence.js.map +7 -0
- package/dist/cjs/internal/EffectRecords.d.ts +92 -0
- package/dist/cjs/internal/EffectRecords.d.ts.map +1 -0
- package/dist/cjs/internal/EffectRecords.js +63 -0
- package/dist/cjs/internal/EffectRecords.js.map +7 -0
- package/dist/cjs/internal/EngineJj.d.ts +30 -0
- package/dist/cjs/internal/EngineJj.d.ts.map +1 -0
- package/dist/cjs/internal/EngineJj.js +42 -0
- package/dist/cjs/internal/EngineJj.js.map +7 -0
- package/dist/cjs/internal/EngineStateSchema.d.ts +68 -0
- package/dist/cjs/internal/EngineStateSchema.d.ts.map +1 -0
- package/dist/cjs/internal/EngineStateSchema.js +58 -0
- package/dist/cjs/internal/EngineStateSchema.js.map +7 -0
- package/dist/cjs/internal/ExecutionSnapshotRead.d.ts +162 -0
- package/dist/cjs/internal/ExecutionSnapshotRead.d.ts.map +1 -0
- package/dist/cjs/internal/ExecutionSnapshotRead.js +199 -0
- package/dist/cjs/internal/ExecutionSnapshotRead.js.map +7 -0
- package/dist/cjs/internal/ExecutionSnapshotRelations.d.ts +39 -0
- package/dist/cjs/internal/ExecutionSnapshotRelations.d.ts.map +1 -0
- package/dist/cjs/internal/ExecutionSnapshotRelations.js +105 -0
- package/dist/cjs/internal/ExecutionSnapshotRelations.js.map +7 -0
- package/dist/cjs/internal/ExitEncoding.d.ts +180 -0
- package/dist/cjs/internal/ExitEncoding.d.ts.map +1 -0
- package/dist/cjs/internal/ExitEncoding.js +236 -0
- package/dist/cjs/internal/ExitEncoding.js.map +7 -0
- package/dist/cjs/internal/FileBoundarySnapshot.d.ts +14 -0
- package/dist/cjs/internal/FileBoundarySnapshot.d.ts.map +1 -0
- package/dist/cjs/internal/FileBoundarySnapshot.js +51 -0
- package/dist/cjs/internal/FileBoundarySnapshot.js.map +7 -0
- package/dist/cjs/internal/FileEnumeration.d.ts +127 -0
- package/dist/cjs/internal/FileEnumeration.d.ts.map +1 -0
- package/dist/cjs/internal/FileEnumeration.js +194 -0
- package/dist/cjs/internal/FileEnumeration.js.map +7 -0
- package/dist/cjs/internal/HostReflection.d.ts +80 -0
- package/dist/cjs/internal/HostReflection.d.ts.map +1 -0
- package/dist/cjs/internal/HostReflection.js +43 -0
- package/dist/cjs/internal/HostReflection.js.map +7 -0
- package/dist/cjs/internal/JournalRecords.d.ts +325 -0
- package/dist/cjs/internal/JournalRecords.d.ts.map +1 -0
- package/dist/cjs/internal/JournalRecords.js +122 -0
- package/dist/cjs/internal/JournalRecords.js.map +7 -0
- package/dist/cjs/internal/NodeJournal.d.ts +157 -0
- package/dist/cjs/internal/NodeJournal.d.ts.map +1 -0
- package/dist/cjs/internal/NodeJournal.js +192 -0
- package/dist/cjs/internal/NodeJournal.js.map +7 -0
- package/dist/cjs/internal/Ordering.d.ts +14 -0
- package/dist/cjs/internal/Ordering.d.ts.map +1 -0
- package/dist/cjs/internal/Ordering.js +25 -0
- package/dist/cjs/internal/Ordering.js.map +7 -0
- package/dist/cjs/internal/PlanInputs.d.ts +14 -0
- package/dist/cjs/internal/PlanInputs.d.ts.map +1 -0
- package/dist/cjs/internal/PlanInputs.js +78 -0
- package/dist/cjs/internal/PlanInputs.js.map +7 -0
- package/dist/cjs/internal/PlanMerges.d.ts +178 -0
- package/dist/cjs/internal/PlanMerges.d.ts.map +1 -0
- package/dist/cjs/internal/PlanMerges.js +125 -0
- package/dist/cjs/internal/PlanMerges.js.map +7 -0
- package/dist/cjs/internal/ProvenanceSlot.d.ts +30 -0
- package/dist/cjs/internal/ProvenanceSlot.d.ts.map +1 -0
- package/dist/cjs/internal/ProvenanceSlot.js +53 -0
- package/dist/cjs/internal/ProvenanceSlot.js.map +7 -0
- package/dist/cjs/internal/ResultEnvelope.d.ts +88 -0
- package/dist/cjs/internal/ResultEnvelope.d.ts.map +1 -0
- package/dist/cjs/internal/ResultEnvelope.js +90 -0
- package/dist/cjs/internal/ResultEnvelope.js.map +7 -0
- package/dist/cjs/internal/RetentionOps.d.ts +414 -0
- package/dist/cjs/internal/RetentionOps.d.ts.map +1 -0
- package/dist/cjs/internal/RetentionOps.js +354 -0
- package/dist/cjs/internal/RetentionOps.js.map +7 -0
- package/dist/cjs/internal/RunCatalogOps.d.ts +118 -0
- package/dist/cjs/internal/RunCatalogOps.d.ts.map +1 -0
- package/dist/cjs/internal/RunCatalogOps.js +85 -0
- package/dist/cjs/internal/RunCatalogOps.js.map +7 -0
- package/dist/cjs/internal/RunCoordinator.d.ts +78 -0
- package/dist/cjs/internal/RunCoordinator.d.ts.map +1 -0
- package/dist/cjs/internal/RunCoordinator.js +123 -0
- package/dist/cjs/internal/RunCoordinator.js.map +7 -0
- package/dist/cjs/internal/RunDriver.d.ts +192 -0
- package/dist/cjs/internal/RunDriver.d.ts.map +1 -0
- package/dist/cjs/internal/RunDriver.js +1584 -0
- package/dist/cjs/internal/RunDriver.js.map +7 -0
- package/dist/cjs/internal/RunLifecycle.d.ts +22 -0
- package/dist/cjs/internal/RunLifecycle.d.ts.map +1 -0
- package/dist/cjs/internal/RunLifecycle.js +63 -0
- package/dist/cjs/internal/RunLifecycle.js.map +7 -0
- package/dist/cjs/internal/RunListing.d.ts +78 -0
- package/dist/cjs/internal/RunListing.d.ts.map +1 -0
- package/dist/cjs/internal/RunListing.js +171 -0
- package/dist/cjs/internal/RunListing.js.map +7 -0
- package/dist/cjs/internal/RunListingError.d.ts +35 -0
- package/dist/cjs/internal/RunListingError.d.ts.map +1 -0
- package/dist/cjs/internal/RunListingError.js +47 -0
- package/dist/cjs/internal/RunListingError.js.map +7 -0
- package/dist/cjs/internal/RuntimeGraph.d.ts +73 -0
- package/dist/cjs/internal/RuntimeGraph.d.ts.map +1 -0
- package/dist/cjs/internal/RuntimeGraph.js +180 -0
- package/dist/cjs/internal/RuntimeGraph.js.map +7 -0
- package/dist/cjs/internal/SandboxedExecution.d.ts +80 -0
- package/dist/cjs/internal/SandboxedExecution.d.ts.map +1 -0
- package/dist/cjs/internal/SandboxedExecution.js +104 -0
- package/dist/cjs/internal/SandboxedExecution.js.map +7 -0
- package/dist/cjs/internal/StateTransaction.d.ts +44 -0
- package/dist/cjs/internal/StateTransaction.d.ts.map +1 -0
- package/dist/cjs/internal/StateTransaction.js +52 -0
- package/dist/cjs/internal/StateTransaction.js.map +7 -0
- package/dist/cjs/internal/StepFacts.d.ts +14 -0
- package/dist/cjs/internal/StepFacts.d.ts.map +1 -0
- package/dist/cjs/internal/StepFacts.js +58 -0
- package/dist/cjs/internal/StepFacts.js.map +7 -0
- package/dist/cjs/internal/TypedEvents.d.ts +14 -0
- package/dist/cjs/internal/TypedEvents.d.ts.map +1 -0
- package/dist/cjs/internal/TypedEvents.js +37 -0
- package/dist/cjs/internal/TypedEvents.js.map +7 -0
- package/dist/cjs/migrations/0001_initial.d.ts +17 -0
- package/dist/cjs/migrations/0001_initial.d.ts.map +1 -0
- package/dist/cjs/migrations/0001_initial.js +61 -0
- package/dist/cjs/migrations/0001_initial.js.map +7 -0
- package/dist/cjs/migrations/0002_selection_store.d.ts +15 -0
- package/dist/cjs/migrations/0002_selection_store.d.ts.map +1 -0
- package/dist/cjs/migrations/0002_selection_store.js +56 -0
- package/dist/cjs/migrations/0002_selection_store.js.map +7 -0
- package/dist/cjs/migrations/0003_plan_inputs.d.ts +13 -0
- package/dist/cjs/migrations/0003_plan_inputs.d.ts.map +1 -0
- package/dist/cjs/migrations/0003_plan_inputs.js +90 -0
- package/dist/cjs/migrations/0003_plan_inputs.js.map +7 -0
- package/dist/cjs/migrations/0004_plan_environment.d.ts +14 -0
- package/dist/cjs/migrations/0004_plan_environment.d.ts.map +1 -0
- package/dist/cjs/migrations/0004_plan_environment.js +56 -0
- package/dist/cjs/migrations/0004_plan_environment.js.map +7 -0
- package/dist/cjs/migrations/0005_plan_merges.d.ts +14 -0
- package/dist/cjs/migrations/0005_plan_merges.d.ts.map +1 -0
- package/dist/cjs/migrations/0005_plan_merges.js +82 -0
- package/dist/cjs/migrations/0005_plan_merges.js.map +7 -0
- package/dist/cjs/migrations/0006_execution_listing.d.ts +15 -0
- package/dist/cjs/migrations/0006_execution_listing.d.ts.map +1 -0
- package/dist/cjs/migrations/0006_execution_listing.js +101 -0
- package/dist/cjs/migrations/0006_execution_listing.js.map +7 -0
- package/dist/cjs/migrations/0007_run_parent_sequence.d.ts +15 -0
- package/dist/cjs/migrations/0007_run_parent_sequence.d.ts.map +1 -0
- package/dist/cjs/migrations/0007_run_parent_sequence.js +40 -0
- package/dist/cjs/migrations/0007_run_parent_sequence.js.map +7 -0
- package/dist/cjs/migrations/0008_deferred_consumption.d.ts +16 -0
- package/dist/cjs/migrations/0008_deferred_consumption.d.ts.map +1 -0
- package/dist/cjs/migrations/0008_deferred_consumption.js +45 -0
- package/dist/cjs/migrations/0008_deferred_consumption.js.map +7 -0
- package/dist/cjs/migrations/0009_deferred_clock_facts.d.ts +24 -0
- package/dist/cjs/migrations/0009_deferred_clock_facts.d.ts.map +1 -0
- package/dist/cjs/migrations/0009_deferred_clock_facts.js +141 -0
- package/dist/cjs/migrations/0009_deferred_clock_facts.js.map +7 -0
- package/dist/cjs/migrations/0010_pending_cancellation.d.ts +15 -0
- package/dist/cjs/migrations/0010_pending_cancellation.d.ts.map +1 -0
- package/dist/cjs/migrations/0010_pending_cancellation.js +41 -0
- package/dist/cjs/migrations/0010_pending_cancellation.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/test/TestStores.d.ts +89 -0
- package/dist/cjs/test/TestStores.d.ts.map +1 -0
- package/dist/cjs/test/TestStores.js +98 -0
- package/dist/cjs/test/TestStores.js.map +7 -0
- package/dist/esm/ArtifactGc.d.ts +235 -0
- package/dist/esm/ArtifactGc.d.ts.map +1 -0
- package/dist/esm/ArtifactGc.js +268 -0
- package/dist/esm/ArtifactGc.js.map +1 -0
- package/dist/esm/ArtifactSync.d.ts +164 -0
- package/dist/esm/ArtifactSync.d.ts.map +1 -0
- package/dist/esm/ArtifactSync.js +176 -0
- package/dist/esm/ArtifactSync.js.map +1 -0
- package/dist/esm/CacheSync.d.ts +112 -0
- package/dist/esm/CacheSync.d.ts.map +1 -0
- package/dist/esm/CacheSync.js +94 -0
- package/dist/esm/CacheSync.js.map +1 -0
- package/dist/esm/DeferredClockFold.d.ts +354 -0
- package/dist/esm/DeferredClockFold.d.ts.map +1 -0
- package/dist/esm/DeferredClockFold.js +472 -0
- package/dist/esm/DeferredClockFold.js.map +1 -0
- package/dist/esm/DisasterRecovery.d.ts +431 -0
- package/dist/esm/DisasterRecovery.d.ts.map +1 -0
- package/dist/esm/DisasterRecovery.js +523 -0
- package/dist/esm/DisasterRecovery.js.map +1 -0
- package/dist/esm/DurableEngineState.d.ts +776 -0
- package/dist/esm/DurableEngineState.d.ts.map +1 -0
- package/dist/esm/DurableEngineState.js +1648 -0
- package/dist/esm/DurableEngineState.js.map +1 -0
- package/dist/esm/EngineStore.d.ts +158 -0
- package/dist/esm/EngineStore.d.ts.map +1 -0
- package/dist/esm/EngineStore.js +403 -0
- package/dist/esm/EngineStore.js.map +1 -0
- package/dist/esm/EngineStoreMetrics.d.ts +276 -0
- package/dist/esm/EngineStoreMetrics.d.ts.map +1 -0
- package/dist/esm/EngineStoreMetrics.js +260 -0
- package/dist/esm/EngineStoreMetrics.js.map +1 -0
- package/dist/esm/Errors.d.ts +22 -0
- package/dist/esm/Errors.d.ts.map +1 -0
- package/dist/esm/Errors.js +22 -0
- package/dist/esm/Errors.js.map +1 -0
- package/dist/esm/EventTypes.d.ts +27 -0
- package/dist/esm/EventTypes.d.ts.map +1 -0
- package/dist/esm/EventTypes.js +27 -0
- package/dist/esm/EventTypes.js.map +1 -0
- package/dist/esm/ExecutionFacts.d.ts +59 -0
- package/dist/esm/ExecutionFacts.d.ts.map +1 -0
- package/dist/esm/ExecutionFacts.js +96 -0
- package/dist/esm/ExecutionFacts.js.map +1 -0
- package/dist/esm/ExecutionSnapshot.d.ts +117 -0
- package/dist/esm/ExecutionSnapshot.d.ts.map +1 -0
- package/dist/esm/ExecutionSnapshot.js +95 -0
- package/dist/esm/ExecutionSnapshot.js.map +1 -0
- package/dist/esm/Inconsistency.d.ts +154 -0
- package/dist/esm/Inconsistency.d.ts.map +1 -0
- package/dist/esm/Inconsistency.js +133 -0
- package/dist/esm/Inconsistency.js.map +1 -0
- package/dist/esm/Migrations.d.ts +56 -0
- package/dist/esm/Migrations.d.ts.map +1 -0
- package/dist/esm/Migrations.js +91 -0
- package/dist/esm/Migrations.js.map +1 -0
- package/dist/esm/OwnerIdentity.d.ts +91 -0
- package/dist/esm/OwnerIdentity.d.ts.map +1 -0
- package/dist/esm/OwnerIdentity.js +99 -0
- package/dist/esm/OwnerIdentity.js.map +1 -0
- package/dist/esm/PlanInputStore.d.ts +110 -0
- package/dist/esm/PlanInputStore.d.ts.map +1 -0
- package/dist/esm/PlanInputStore.js +207 -0
- package/dist/esm/PlanInputStore.js.map +1 -0
- package/dist/esm/PlanMergeStore.d.ts +113 -0
- package/dist/esm/PlanMergeStore.d.ts.map +1 -0
- package/dist/esm/PlanMergeStore.js +244 -0
- package/dist/esm/PlanMergeStore.js.map +1 -0
- package/dist/esm/PlanScheduler.d.ts +363 -0
- package/dist/esm/PlanScheduler.d.ts.map +1 -0
- package/dist/esm/PlanScheduler.js +1321 -0
- package/dist/esm/PlanScheduler.js.map +1 -0
- package/dist/esm/Reconciliation.d.ts +175 -0
- package/dist/esm/Reconciliation.d.ts.map +1 -0
- package/dist/esm/Reconciliation.js +175 -0
- package/dist/esm/Reconciliation.js.map +1 -0
- package/dist/esm/ReplayOnly.d.ts +91 -0
- package/dist/esm/ReplayOnly.d.ts.map +1 -0
- package/dist/esm/ReplayOnly.js +59 -0
- package/dist/esm/ReplayOnly.js.map +1 -0
- package/dist/esm/Retention.d.ts +113 -0
- package/dist/esm/Retention.d.ts.map +1 -0
- package/dist/esm/Retention.js +139 -0
- package/dist/esm/Retention.js.map +1 -0
- package/dist/esm/RunCatalogRead.d.ts +17 -0
- package/dist/esm/RunCatalogRead.d.ts.map +1 -0
- package/dist/esm/RunCatalogRead.js +17 -0
- package/dist/esm/RunCatalogRead.js.map +1 -0
- package/dist/esm/RunChangeFeed.d.ts +75 -0
- package/dist/esm/RunChangeFeed.d.ts.map +1 -0
- package/dist/esm/RunChangeFeed.js +81 -0
- package/dist/esm/RunChangeFeed.js.map +1 -0
- package/dist/esm/RunState.d.ts +116 -0
- package/dist/esm/RunState.d.ts.map +1 -0
- package/dist/esm/RunState.js +109 -0
- package/dist/esm/RunState.js.map +1 -0
- package/dist/esm/Selection.d.ts +495 -0
- package/dist/esm/Selection.d.ts.map +1 -0
- package/dist/esm/Selection.js +482 -0
- package/dist/esm/Selection.js.map +1 -0
- package/dist/esm/SelectionStore.d.ts +141 -0
- package/dist/esm/SelectionStore.d.ts.map +1 -0
- package/dist/esm/SelectionStore.js +215 -0
- package/dist/esm/SelectionStore.js.map +1 -0
- package/dist/esm/StepBoundary.d.ts +501 -0
- package/dist/esm/StepBoundary.d.ts.map +1 -0
- package/dist/esm/StepBoundary.js +919 -0
- package/dist/esm/StepBoundary.js.map +1 -0
- package/dist/esm/StepCacheFold.d.ts +148 -0
- package/dist/esm/StepCacheFold.d.ts.map +1 -0
- package/dist/esm/StepCacheFold.js +201 -0
- package/dist/esm/StepCacheFold.js.map +1 -0
- package/dist/esm/StepSandbox.d.ts +78 -0
- package/dist/esm/StepSandbox.d.ts.map +1 -0
- package/dist/esm/StepSandbox.js +70 -0
- package/dist/esm/StepSandbox.js.map +1 -0
- package/dist/esm/WakeBus.d.ts +116 -0
- package/dist/esm/WakeBus.d.ts.map +1 -0
- package/dist/esm/WakeBus.js +121 -0
- package/dist/esm/WakeBus.js.map +1 -0
- package/dist/esm/WorkspaceSandbox.d.ts +619 -0
- package/dist/esm/WorkspaceSandbox.d.ts.map +1 -0
- package/dist/esm/WorkspaceSandbox.js +985 -0
- package/dist/esm/WorkspaceSandbox.js.map +1 -0
- package/dist/esm/index.d.ts +157 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +157 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/ActionPersistence.d.ts +276 -0
- package/dist/esm/internal/ActionPersistence.d.ts.map +1 -0
- package/dist/esm/internal/ActionPersistence.js +2306 -0
- package/dist/esm/internal/ActionPersistence.js.map +1 -0
- package/dist/esm/internal/ArtifactRoots.d.ts +38 -0
- package/dist/esm/internal/ArtifactRoots.d.ts.map +1 -0
- package/dist/esm/internal/ArtifactRoots.js +76 -0
- package/dist/esm/internal/ArtifactRoots.js.map +1 -0
- package/dist/esm/internal/AttemptAdmission.d.ts +53 -0
- package/dist/esm/internal/AttemptAdmission.d.ts.map +1 -0
- package/dist/esm/internal/AttemptAdmission.js +52 -0
- package/dist/esm/internal/AttemptAdmission.js.map +1 -0
- package/dist/esm/internal/AttemptLifecycle.d.ts +245 -0
- package/dist/esm/internal/AttemptLifecycle.d.ts.map +1 -0
- package/dist/esm/internal/AttemptLifecycle.js +104 -0
- package/dist/esm/internal/AttemptLifecycle.js.map +1 -0
- package/dist/esm/internal/AttemptProbe.d.ts +53 -0
- package/dist/esm/internal/AttemptProbe.d.ts.map +1 -0
- package/dist/esm/internal/AttemptProbe.js +83 -0
- package/dist/esm/internal/AttemptProbe.js.map +1 -0
- package/dist/esm/internal/CacheAdmission.d.ts +79 -0
- package/dist/esm/internal/CacheAdmission.d.ts.map +1 -0
- package/dist/esm/internal/CacheAdmission.js +72 -0
- package/dist/esm/internal/CacheAdmission.js.map +1 -0
- package/dist/esm/internal/CacheAgeHistory.d.ts +27 -0
- package/dist/esm/internal/CacheAgeHistory.d.ts.map +1 -0
- package/dist/esm/internal/CacheAgeHistory.js +49 -0
- package/dist/esm/internal/CacheAgeHistory.js.map +1 -0
- package/dist/esm/internal/CacheAgeVerdicts.d.ts +15 -0
- package/dist/esm/internal/CacheAgeVerdicts.d.ts.map +1 -0
- package/dist/esm/internal/CacheAgeVerdicts.js +54 -0
- package/dist/esm/internal/CacheAgeVerdicts.js.map +1 -0
- package/dist/esm/internal/CacheOutputPolicy.d.ts +24 -0
- package/dist/esm/internal/CacheOutputPolicy.d.ts.map +1 -0
- package/dist/esm/internal/CacheOutputPolicy.js +73 -0
- package/dist/esm/internal/CacheOutputPolicy.js.map +1 -0
- package/dist/esm/internal/CachePublication.d.ts +97 -0
- package/dist/esm/internal/CachePublication.d.ts.map +1 -0
- package/dist/esm/internal/CachePublication.js +116 -0
- package/dist/esm/internal/CachePublication.js.map +1 -0
- package/dist/esm/internal/CallFacts.d.ts +15 -0
- package/dist/esm/internal/CallFacts.d.ts.map +1 -0
- package/dist/esm/internal/CallFacts.js +83 -0
- package/dist/esm/internal/CallFacts.js.map +1 -0
- package/dist/esm/internal/CopiedRecord.d.ts +61 -0
- package/dist/esm/internal/CopiedRecord.d.ts.map +1 -0
- package/dist/esm/internal/CopiedRecord.js +165 -0
- package/dist/esm/internal/CopiedRecord.js.map +1 -0
- package/dist/esm/internal/DeferredPersistence.d.ts +108 -0
- package/dist/esm/internal/DeferredPersistence.d.ts.map +1 -0
- package/dist/esm/internal/DeferredPersistence.js +240 -0
- package/dist/esm/internal/DeferredPersistence.js.map +1 -0
- package/dist/esm/internal/EffectRecords.d.ts +92 -0
- package/dist/esm/internal/EffectRecords.d.ts.map +1 -0
- package/dist/esm/internal/EffectRecords.js +94 -0
- package/dist/esm/internal/EffectRecords.js.map +1 -0
- package/dist/esm/internal/EngineJj.d.ts +30 -0
- package/dist/esm/internal/EngineJj.d.ts.map +1 -0
- package/dist/esm/internal/EngineJj.js +29 -0
- package/dist/esm/internal/EngineJj.js.map +1 -0
- package/dist/esm/internal/EngineStateSchema.d.ts +68 -0
- package/dist/esm/internal/EngineStateSchema.d.ts.map +1 -0
- package/dist/esm/internal/EngineStateSchema.js +53 -0
- package/dist/esm/internal/EngineStateSchema.js.map +1 -0
- package/dist/esm/internal/ExecutionSnapshotRead.d.ts +162 -0
- package/dist/esm/internal/ExecutionSnapshotRead.d.ts.map +1 -0
- package/dist/esm/internal/ExecutionSnapshotRead.js +218 -0
- package/dist/esm/internal/ExecutionSnapshotRead.js.map +1 -0
- package/dist/esm/internal/ExecutionSnapshotRelations.d.ts +39 -0
- package/dist/esm/internal/ExecutionSnapshotRelations.d.ts.map +1 -0
- package/dist/esm/internal/ExecutionSnapshotRelations.js +81 -0
- package/dist/esm/internal/ExecutionSnapshotRelations.js.map +1 -0
- package/dist/esm/internal/ExitEncoding.d.ts +180 -0
- package/dist/esm/internal/ExitEncoding.d.ts.map +1 -0
- package/dist/esm/internal/ExitEncoding.js +361 -0
- package/dist/esm/internal/ExitEncoding.js.map +1 -0
- package/dist/esm/internal/FileBoundarySnapshot.d.ts +14 -0
- package/dist/esm/internal/FileBoundarySnapshot.d.ts.map +1 -0
- package/dist/esm/internal/FileBoundarySnapshot.js +29 -0
- package/dist/esm/internal/FileBoundarySnapshot.js.map +1 -0
- package/dist/esm/internal/FileEnumeration.d.ts +127 -0
- package/dist/esm/internal/FileEnumeration.d.ts.map +1 -0
- package/dist/esm/internal/FileEnumeration.js +236 -0
- package/dist/esm/internal/FileEnumeration.js.map +1 -0
- package/dist/esm/internal/HostReflection.d.ts +80 -0
- package/dist/esm/internal/HostReflection.d.ts.map +1 -0
- package/dist/esm/internal/HostReflection.js +98 -0
- package/dist/esm/internal/HostReflection.js.map +1 -0
- package/dist/esm/internal/JournalRecords.d.ts +325 -0
- package/dist/esm/internal/JournalRecords.d.ts.map +1 -0
- package/dist/esm/internal/JournalRecords.js +306 -0
- package/dist/esm/internal/JournalRecords.js.map +1 -0
- package/dist/esm/internal/NodeJournal.d.ts +157 -0
- package/dist/esm/internal/NodeJournal.d.ts.map +1 -0
- package/dist/esm/internal/NodeJournal.js +298 -0
- package/dist/esm/internal/NodeJournal.js.map +1 -0
- package/dist/esm/internal/Ordering.d.ts +14 -0
- package/dist/esm/internal/Ordering.d.ts.map +1 -0
- package/dist/esm/internal/Ordering.js +14 -0
- package/dist/esm/internal/Ordering.js.map +1 -0
- package/dist/esm/internal/PlanInputs.d.ts +14 -0
- package/dist/esm/internal/PlanInputs.d.ts.map +1 -0
- package/dist/esm/internal/PlanInputs.js +57 -0
- package/dist/esm/internal/PlanInputs.js.map +1 -0
- package/dist/esm/internal/PlanMerges.d.ts +178 -0
- package/dist/esm/internal/PlanMerges.d.ts.map +1 -0
- package/dist/esm/internal/PlanMerges.js +113 -0
- package/dist/esm/internal/PlanMerges.js.map +1 -0
- package/dist/esm/internal/ProvenanceSlot.d.ts +30 -0
- package/dist/esm/internal/ProvenanceSlot.d.ts.map +1 -0
- package/dist/esm/internal/ProvenanceSlot.js +39 -0
- package/dist/esm/internal/ProvenanceSlot.js.map +1 -0
- package/dist/esm/internal/ResultEnvelope.d.ts +88 -0
- package/dist/esm/internal/ResultEnvelope.d.ts.map +1 -0
- package/dist/esm/internal/ResultEnvelope.js +83 -0
- package/dist/esm/internal/ResultEnvelope.js.map +1 -0
- package/dist/esm/internal/RetentionOps.d.ts +414 -0
- package/dist/esm/internal/RetentionOps.d.ts.map +1 -0
- package/dist/esm/internal/RetentionOps.js +576 -0
- package/dist/esm/internal/RetentionOps.js.map +1 -0
- package/dist/esm/internal/RunCatalogOps.d.ts +118 -0
- package/dist/esm/internal/RunCatalogOps.d.ts.map +1 -0
- package/dist/esm/internal/RunCatalogOps.js +120 -0
- package/dist/esm/internal/RunCatalogOps.js.map +1 -0
- package/dist/esm/internal/RunCoordinator.d.ts +78 -0
- package/dist/esm/internal/RunCoordinator.d.ts.map +1 -0
- package/dist/esm/internal/RunCoordinator.js +115 -0
- package/dist/esm/internal/RunCoordinator.js.map +1 -0
- package/dist/esm/internal/RunDriver.d.ts +192 -0
- package/dist/esm/internal/RunDriver.d.ts.map +1 -0
- package/dist/esm/internal/RunDriver.js +2334 -0
- package/dist/esm/internal/RunDriver.js.map +1 -0
- package/dist/esm/internal/RunLifecycle.d.ts +22 -0
- package/dist/esm/internal/RunLifecycle.d.ts.map +1 -0
- package/dist/esm/internal/RunLifecycle.js +49 -0
- package/dist/esm/internal/RunLifecycle.js.map +1 -0
- package/dist/esm/internal/RunListing.d.ts +78 -0
- package/dist/esm/internal/RunListing.d.ts.map +1 -0
- package/dist/esm/internal/RunListing.js +146 -0
- package/dist/esm/internal/RunListing.js.map +1 -0
- package/dist/esm/internal/RunListingError.d.ts +35 -0
- package/dist/esm/internal/RunListingError.d.ts.map +1 -0
- package/dist/esm/internal/RunListingError.js +27 -0
- package/dist/esm/internal/RunListingError.js.map +1 -0
- package/dist/esm/internal/RuntimeGraph.d.ts +73 -0
- package/dist/esm/internal/RuntimeGraph.d.ts.map +1 -0
- package/dist/esm/internal/RuntimeGraph.js +182 -0
- package/dist/esm/internal/RuntimeGraph.js.map +1 -0
- package/dist/esm/internal/SandboxedExecution.d.ts +80 -0
- package/dist/esm/internal/SandboxedExecution.d.ts.map +1 -0
- package/dist/esm/internal/SandboxedExecution.js +107 -0
- package/dist/esm/internal/SandboxedExecution.js.map +1 -0
- package/dist/esm/internal/StateTransaction.d.ts +44 -0
- package/dist/esm/internal/StateTransaction.d.ts.map +1 -0
- package/dist/esm/internal/StateTransaction.js +54 -0
- package/dist/esm/internal/StateTransaction.js.map +1 -0
- package/dist/esm/internal/StepFacts.d.ts +14 -0
- package/dist/esm/internal/StepFacts.d.ts.map +1 -0
- package/dist/esm/internal/StepFacts.js +35 -0
- package/dist/esm/internal/StepFacts.js.map +1 -0
- package/dist/esm/internal/TypedEvents.d.ts +14 -0
- package/dist/esm/internal/TypedEvents.d.ts.map +1 -0
- package/dist/esm/internal/TypedEvents.js +14 -0
- package/dist/esm/internal/TypedEvents.js.map +1 -0
- package/dist/esm/migrations/0001_initial.d.ts +17 -0
- package/dist/esm/migrations/0001_initial.d.ts.map +1 -0
- package/dist/esm/migrations/0001_initial.js +41 -0
- package/dist/esm/migrations/0001_initial.js.map +1 -0
- package/dist/esm/migrations/0002_selection_store.d.ts +15 -0
- package/dist/esm/migrations/0002_selection_store.d.ts.map +1 -0
- package/dist/esm/migrations/0002_selection_store.js +34 -0
- package/dist/esm/migrations/0002_selection_store.js.map +1 -0
- package/dist/esm/migrations/0003_plan_inputs.d.ts +13 -0
- package/dist/esm/migrations/0003_plan_inputs.d.ts.map +1 -0
- package/dist/esm/migrations/0003_plan_inputs.js +70 -0
- package/dist/esm/migrations/0003_plan_inputs.js.map +1 -0
- package/dist/esm/migrations/0004_plan_environment.d.ts +14 -0
- package/dist/esm/migrations/0004_plan_environment.d.ts.map +1 -0
- package/dist/esm/migrations/0004_plan_environment.js +33 -0
- package/dist/esm/migrations/0004_plan_environment.js.map +1 -0
- package/dist/esm/migrations/0005_plan_merges.d.ts +14 -0
- package/dist/esm/migrations/0005_plan_merges.d.ts.map +1 -0
- package/dist/esm/migrations/0005_plan_merges.js +59 -0
- package/dist/esm/migrations/0005_plan_merges.js.map +1 -0
- package/dist/esm/migrations/0006_execution_listing.d.ts +15 -0
- package/dist/esm/migrations/0006_execution_listing.d.ts.map +1 -0
- package/dist/esm/migrations/0006_execution_listing.js +81 -0
- package/dist/esm/migrations/0006_execution_listing.js.map +1 -0
- package/dist/esm/migrations/0007_run_parent_sequence.d.ts +15 -0
- package/dist/esm/migrations/0007_run_parent_sequence.d.ts.map +1 -0
- package/dist/esm/migrations/0007_run_parent_sequence.js +18 -0
- package/dist/esm/migrations/0007_run_parent_sequence.js.map +1 -0
- package/dist/esm/migrations/0008_deferred_consumption.d.ts +16 -0
- package/dist/esm/migrations/0008_deferred_consumption.d.ts.map +1 -0
- package/dist/esm/migrations/0008_deferred_consumption.js +24 -0
- package/dist/esm/migrations/0008_deferred_consumption.js.map +1 -0
- package/dist/esm/migrations/0009_deferred_clock_facts.d.ts +24 -0
- package/dist/esm/migrations/0009_deferred_clock_facts.d.ts.map +1 -0
- package/dist/esm/migrations/0009_deferred_clock_facts.js +127 -0
- package/dist/esm/migrations/0009_deferred_clock_facts.js.map +1 -0
- package/dist/esm/migrations/0010_pending_cancellation.d.ts +15 -0
- package/dist/esm/migrations/0010_pending_cancellation.d.ts.map +1 -0
- package/dist/esm/migrations/0010_pending_cancellation.js +19 -0
- package/dist/esm/migrations/0010_pending_cancellation.js.map +1 -0
- package/dist/esm/test/TestStores.d.ts +89 -0
- package/dist/esm/test/TestStores.d.ts.map +1 -0
- package/dist/esm/test/TestStores.js +103 -0
- package/dist/esm/test/TestStores.js.map +1 -0
- package/docs/README.md +113 -0
- package/docs/api.md +1494 -0
- package/docs/concepts/attempts-and-replay.md +149 -0
- package/docs/concepts/cache-admission.md +265 -0
- package/docs/concepts/call-facts.md +86 -0
- package/docs/concepts/durable-waits.md +175 -0
- package/docs/concepts/execution-facts.md +90 -0
- package/docs/concepts/ownership-and-fencing.md +128 -0
- package/docs/concepts/step-boundaries.md +148 -0
- package/docs/concepts/workspace-transactions.md +199 -0
- package/docs/event-types.md +14 -0
- package/docs/guides/back-up-and-restore.md +164 -0
- package/docs/guides/collect-unreferenced-artifacts.md +128 -0
- package/docs/guides/compose-a-durable-engine.md +146 -0
- package/docs/guides/coordinate-two-processes.md +120 -0
- package/docs/guides/defer-work-with-selection.md +171 -0
- package/docs/guides/delete-old-run-history.md +154 -0
- package/docs/guides/drive-a-plan.md +314 -0
- package/docs/guides/observe-engine-metrics.md +98 -0
- package/docs/guides/observe-executions.md +187 -0
- package/docs/guides/reclaim-runs-from-a-dead-host.md +133 -0
- package/docs/guides/share-a-cache-across-machines.md +134 -0
- package/docs/guides/testing.md +123 -0
- package/docs/installation.md +102 -0
- package/docs/quickstart.md +215 -0
- package/docs/troubleshooting.md +347 -0
- package/package.json +438 -3
- package/src/ArtifactGc.ts +408 -0
- package/src/ArtifactSync.ts +278 -0
- package/src/CacheSync.ts +131 -0
- package/src/DeferredClockFold.ts +586 -0
- package/src/DisasterRecovery.ts +888 -0
- package/src/DurableEngineState.ts +2656 -0
- package/src/EngineStore.ts +656 -0
- package/src/EngineStoreMetrics.ts +331 -0
- package/src/Errors.ts +28 -0
- package/src/EventTypes.ts +27 -0
- package/src/ExecutionFacts.ts +125 -0
- package/src/ExecutionSnapshot.ts +186 -0
- package/src/Inconsistency.ts +253 -0
- package/src/Migrations.ts +95 -0
- package/src/OwnerIdentity.ts +125 -0
- package/src/PlanInputStore.ts +292 -0
- package/src/PlanMergeStore.ts +330 -0
- package/src/PlanScheduler.ts +1806 -0
- package/src/Reconciliation.ts +224 -0
- package/src/ReplayOnly.ts +95 -0
- package/src/Retention.ts +214 -0
- package/src/RunCatalogRead.ts +27 -0
- package/src/RunChangeFeed.ts +125 -0
- package/src/RunState.ts +137 -0
- package/src/Selection.ts +683 -0
- package/src/SelectionStore.ts +353 -0
- package/src/StepBoundary.ts +1165 -0
- package/src/StepCacheFold.ts +244 -0
- package/src/StepSandbox.ts +110 -0
- package/src/WakeBus.ts +167 -0
- package/src/WorkspaceSandbox.ts +1604 -0
- package/src/index.ts +185 -0
- package/src/internal/ActionPersistence.ts +2687 -0
- package/src/internal/ArtifactRoots.ts +92 -0
- package/src/internal/AttemptAdmission.ts +76 -0
- package/src/internal/AttemptLifecycle.ts +163 -0
- package/src/internal/AttemptProbe.ts +90 -0
- package/src/internal/CacheAdmission.ts +133 -0
- package/src/internal/CacheAgeHistory.ts +58 -0
- package/src/internal/CacheAgeVerdicts.ts +61 -0
- package/src/internal/CacheOutputPolicy.ts +82 -0
- package/src/internal/CachePublication.ts +153 -0
- package/src/internal/CallFacts.ts +87 -0
- package/src/internal/CopiedRecord.ts +201 -0
- package/src/internal/DeferredPersistence.ts +459 -0
- package/src/internal/EffectRecords.ts +136 -0
- package/src/internal/EngineJj.ts +30 -0
- package/src/internal/EngineStateSchema.ts +92 -0
- package/src/internal/ExecutionSnapshotRead.ts +298 -0
- package/src/internal/ExecutionSnapshotRelations.ts +121 -0
- package/src/internal/ExitEncoding.ts +453 -0
- package/src/internal/FileBoundarySnapshot.ts +39 -0
- package/src/internal/FileEnumeration.ts +334 -0
- package/src/internal/HostReflection.ts +128 -0
- package/src/internal/JournalRecords.ts +396 -0
- package/src/internal/NodeJournal.ts +340 -0
- package/src/internal/Ordering.ts +14 -0
- package/src/internal/PlanInputs.ts +62 -0
- package/src/internal/PlanMerges.ts +123 -0
- package/src/internal/ProvenanceSlot.ts +52 -0
- package/src/internal/ResultEnvelope.ts +118 -0
- package/src/internal/RetentionOps.ts +865 -0
- package/src/internal/RunCatalogOps.ts +174 -0
- package/src/internal/RunCoordinator.ts +215 -0
- package/src/internal/RunDriver.ts +3152 -0
- package/src/internal/RunLifecycle.ts +53 -0
- package/src/internal/RunListing.ts +210 -0
- package/src/internal/RunListingError.ts +37 -0
- package/src/internal/RuntimeGraph.ts +253 -0
- package/src/internal/SandboxedExecution.ts +165 -0
- package/src/internal/StateTransaction.ts +71 -0
- package/src/internal/StepFacts.ts +36 -0
- package/src/internal/TypedEvents.ts +29 -0
- package/src/migrations/0001_initial.ts +51 -0
- package/src/migrations/0002_selection_store.ts +38 -0
- package/src/migrations/0003_plan_inputs.ts +75 -0
- package/src/migrations/0004_plan_environment.ts +34 -0
- package/src/migrations/0005_plan_merges.ts +60 -0
- package/src/migrations/0006_execution_listing.ts +86 -0
- package/src/migrations/0007_run_parent_sequence.ts +19 -0
- package/src/migrations/0008_deferred_consumption.ts +27 -0
- package/src/migrations/0009_deferred_clock_facts.ts +163 -0
- package/src/migrations/0010_pending_cancellation.ts +20 -0
- package/src/test/TestStores.ts +145 -0
|
@@ -0,0 +1,888 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hot backup, verified restore, and restore-time fencing for the durable
|
|
3
|
+
* flows store.
|
|
4
|
+
*
|
|
5
|
+
* A backup captures the whole SQLite database — journal, run store, step
|
|
6
|
+
* cache, engine state, and the out-of-ladder objects created by
|
|
7
|
+
* `internal/EngineStateSchema.ts` — with `VACUUM INTO`, which reads one
|
|
8
|
+
* consistent snapshot under WAL while writers stay live. The content-addressed
|
|
9
|
+
* artifact blobs are copied beside it, digest-verified, after the database
|
|
10
|
+
* snapshot: results reference artifacts only after publication
|
|
11
|
+
* (`packages/smithers/flows/step-cache/docs/api.md`), so a blob walk taken after the
|
|
12
|
+
* database snapshot is a superset of every digest the snapshot references.
|
|
13
|
+
* A manifest written last records the digests a restore must verify, so a
|
|
14
|
+
* partial backup is detectable by its missing manifest.
|
|
15
|
+
*
|
|
16
|
+
* Restore never lets a pre-backup owner resurrect. The fencing token is the
|
|
17
|
+
* `OwnerId` triple mirrored on `flows_runs` and arbitrated by the journal's
|
|
18
|
+
* `flows_consensus_leases` — Temporal's shard `rangeID` equality check reduced
|
|
19
|
+
* to one SQL predicate (`reference/temporal`
|
|
20
|
+
* `service/history/shard/context_impl.go`, `renewRangeLocked`). Temporal
|
|
21
|
+
* fences a restored shard by bumping the persisted epoch above anything a
|
|
22
|
+
* surviving owner could hold; the equivalent bump for an identity fence is
|
|
23
|
+
* {@link fence}: clear every persisted claim, owner, and consensus lease in
|
|
24
|
+
* one serialized write transaction, so every pre-backup `OwnerId` fails its
|
|
25
|
+
* equality compare-and-swap (`FenceLost`, journal `fence_lost`) and the
|
|
26
|
+
* restored runs are claimable immediately instead of after the heartbeat
|
|
27
|
+
* staleness cutoff.
|
|
28
|
+
*
|
|
29
|
+
* Host access arrives through Effect's `FileSystem` and `SqlClient` tags and
|
|
30
|
+
* hashing through the injected `Crypto` service, so the module carries no
|
|
31
|
+
* platform binding. The SQL dialect is SQLite — a non-SQLite backend fails
|
|
32
|
+
* with the `sql` code rather than pretending to snapshot. Every file is
|
|
33
|
+
* stat-checked before it is buffered for hashing or copying. The configurable
|
|
34
|
+
* ceiling defaults to {@link defaultMaxFileSizeBytes}; an oversized file fails
|
|
35
|
+
* with the typed `io` code instead of reaching the host's allocation limit.
|
|
36
|
+
*
|
|
37
|
+
* @since 0.1.0
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
import * as ArtifactBackupLease from "@smthrs/artifacts/ArtifactBackupLease"
|
|
41
|
+
import { Sha256 } from "@smthrs/crypto"
|
|
42
|
+
import { DurableWriter } from "@smthrs/database/DurableWriter"
|
|
43
|
+
import * as Clock from "effect/Clock"
|
|
44
|
+
import type * as Crypto from "effect/Crypto"
|
|
45
|
+
import * as Effect from "effect/Effect"
|
|
46
|
+
import * as FileSystem from "effect/FileSystem"
|
|
47
|
+
import type * as Layer from "effect/Layer"
|
|
48
|
+
import * as Schema from "effect/Schema"
|
|
49
|
+
import * as SqlClient from "effect/unstable/sql/SqlClient"
|
|
50
|
+
import * as ArtifactRoots from "./internal/ArtifactRoots.ts"
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The database file name inside a backup directory and a restored store
|
|
54
|
+
* directory.
|
|
55
|
+
*
|
|
56
|
+
* @since 0.1.0
|
|
57
|
+
* @category constants
|
|
58
|
+
*/
|
|
59
|
+
export const databaseFileName = "store.sqlite3"
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The manifest file name inside a backup directory. It is written last, so
|
|
63
|
+
* its presence marks a complete backup.
|
|
64
|
+
*
|
|
65
|
+
* @since 0.1.0
|
|
66
|
+
* @category constants
|
|
67
|
+
*/
|
|
68
|
+
export const manifestFileName = "manifest.json"
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The artifact blob directory name inside a backup directory and a restored
|
|
72
|
+
* store directory, laid out with the store's own two-hex-prefix fanout.
|
|
73
|
+
*
|
|
74
|
+
* @since 0.1.0
|
|
75
|
+
* @category constants
|
|
76
|
+
*/
|
|
77
|
+
export const objectsDirectoryName = "objects"
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The marker file a restore writes into the target directory, recording when
|
|
81
|
+
* the restore happened and which backup it came from.
|
|
82
|
+
*
|
|
83
|
+
* @since 0.1.0
|
|
84
|
+
* @category constants
|
|
85
|
+
*/
|
|
86
|
+
export const restoredMarkerFileName = "restored.json"
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Default ceiling for one backup file read into memory: 512 MiB.
|
|
90
|
+
*
|
|
91
|
+
* @since 1.0.0
|
|
92
|
+
* @category constants
|
|
93
|
+
*/
|
|
94
|
+
export const defaultMaxFileSizeBytes = 512 * 1024 * 1024
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* One applied row of the shared `flows_migrations` table, recorded at backup
|
|
98
|
+
* time and re-verified at fence time as the schema version of the snapshot.
|
|
99
|
+
*
|
|
100
|
+
* @since 0.1.0
|
|
101
|
+
* @category schemas
|
|
102
|
+
*/
|
|
103
|
+
export const AppliedMigration = Schema.Struct({
|
|
104
|
+
migrationId: Schema.Number,
|
|
105
|
+
name: Schema.String
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* One applied row of the shared `flows_migrations` table.
|
|
110
|
+
*
|
|
111
|
+
* @since 0.1.0
|
|
112
|
+
* @category models
|
|
113
|
+
*/
|
|
114
|
+
export type AppliedMigration = typeof AppliedMigration.Type
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* One captured artifact blob. `sizeBytes` is informational for operators; the
|
|
118
|
+
* digest is the integrity check.
|
|
119
|
+
*
|
|
120
|
+
* @since 0.1.0
|
|
121
|
+
* @category schemas
|
|
122
|
+
*/
|
|
123
|
+
export const ArtifactEntry = Schema.Struct({
|
|
124
|
+
digest: Sha256.Digest,
|
|
125
|
+
sizeBytes: Schema.Number
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* One captured artifact blob.
|
|
130
|
+
*
|
|
131
|
+
* @since 0.1.0
|
|
132
|
+
* @category models
|
|
133
|
+
*/
|
|
134
|
+
export type ArtifactEntry = typeof ArtifactEntry.Type
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The verification contract of a backup: the database snapshot's digest and
|
|
138
|
+
* schema version, and the digest of every captured artifact blob.
|
|
139
|
+
*
|
|
140
|
+
* @since 0.1.0
|
|
141
|
+
* @category schemas
|
|
142
|
+
*/
|
|
143
|
+
export const BackupManifest = Schema.Struct({
|
|
144
|
+
formatVersion: Schema.Literal(1),
|
|
145
|
+
createdAtMs: Schema.Number,
|
|
146
|
+
database: Schema.Struct({
|
|
147
|
+
file: Schema.Literal(databaseFileName),
|
|
148
|
+
sha256: Sha256.Digest,
|
|
149
|
+
sizeBytes: Schema.Number,
|
|
150
|
+
migrations: Schema.Array(AppliedMigration)
|
|
151
|
+
}),
|
|
152
|
+
artifacts: Schema.Array(ArtifactEntry)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The verification contract of a backup.
|
|
157
|
+
*
|
|
158
|
+
* @since 0.1.0
|
|
159
|
+
* @category models
|
|
160
|
+
*/
|
|
161
|
+
export type BackupManifest = typeof BackupManifest.Type
|
|
162
|
+
|
|
163
|
+
/** JSON text carrying a decoded backup manifest. */
|
|
164
|
+
const ManifestFromJsonString = Schema.fromJsonString(BackupManifest)
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Stable failure codes surfaced by backup, verify, restore, and fence.
|
|
168
|
+
* `invalid_options` reports a public option that cannot be admitted safely.
|
|
169
|
+
*
|
|
170
|
+
* @since 0.1.0
|
|
171
|
+
* @category errors
|
|
172
|
+
*/
|
|
173
|
+
export const DisasterRecoveryErrorCode = Schema.Literals([
|
|
174
|
+
"invalid_options",
|
|
175
|
+
"not_empty",
|
|
176
|
+
"invalid_manifest",
|
|
177
|
+
"missing_file",
|
|
178
|
+
"digest_mismatch",
|
|
179
|
+
"artifact_corruption",
|
|
180
|
+
"snapshot_incomplete",
|
|
181
|
+
"schema_mismatch",
|
|
182
|
+
"io",
|
|
183
|
+
"sql"
|
|
184
|
+
])
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* A stable disaster-recovery failure code.
|
|
188
|
+
*
|
|
189
|
+
* @since 0.1.0
|
|
190
|
+
* @category errors
|
|
191
|
+
*/
|
|
192
|
+
export type DisasterRecoveryErrorCode = typeof DisasterRecoveryErrorCode.Type
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* A normalized backup or restore failure. The identity string equals this
|
|
196
|
+
* module's package path, per the house rule that a new identity is the
|
|
197
|
+
* defining module path.
|
|
198
|
+
*
|
|
199
|
+
* @since 0.1.0
|
|
200
|
+
* @category errors
|
|
201
|
+
*/
|
|
202
|
+
export class DisasterRecoveryError extends Schema.TaggedError<DisasterRecoveryError>()(
|
|
203
|
+
"@smthrs/engine-store/DisasterRecoveryError",
|
|
204
|
+
{
|
|
205
|
+
code: DisasterRecoveryErrorCode,
|
|
206
|
+
method: Schema.String,
|
|
207
|
+
message: Schema.String,
|
|
208
|
+
cause: Schema.Unknown
|
|
209
|
+
}
|
|
210
|
+
) {}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Shared buffering limit for backup, verification, and restore operations.
|
|
214
|
+
*
|
|
215
|
+
* @since 1.0.0
|
|
216
|
+
* @category models
|
|
217
|
+
*/
|
|
218
|
+
export interface FileSizeOptions {
|
|
219
|
+
/**
|
|
220
|
+
* Largest file, in bytes, that backup, verification, or restore may buffer.
|
|
221
|
+
* The value must be a finite non-negative safe integer. Defaults to
|
|
222
|
+
* {@link defaultMaxFileSizeBytes}.
|
|
223
|
+
*/
|
|
224
|
+
readonly maxFileSizeBytes?: number | undefined
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Where a backup is written and which artifact store it captures.
|
|
229
|
+
*
|
|
230
|
+
* @since 0.1.0
|
|
231
|
+
* @category models
|
|
232
|
+
*/
|
|
233
|
+
export interface BackupOptions<R = never, E = never> extends FileSizeOptions {
|
|
234
|
+
/** The directory the backup is written into. Created when absent; must be empty when present. */
|
|
235
|
+
readonly directory: string
|
|
236
|
+
/**
|
|
237
|
+
* The live store's content-addressed objects directory (the
|
|
238
|
+
* `ArtifactStore.layerFileSystem` directory). When set, the whole capture
|
|
239
|
+
* holds the cross-process artifact backup lease, so a concurrent
|
|
240
|
+
* `ArtifactGc.gc` sweep cannot delete a blob between the database snapshot
|
|
241
|
+
* and its copy. Absent means the composition has no filesystem artifact
|
|
242
|
+
* tier: the backup carries no blobs and takes no lease, because there is
|
|
243
|
+
* no objects directory to fence, and a frozen snapshot that references any
|
|
244
|
+
* artifact digest fails with `snapshot_incomplete` instead of reporting
|
|
245
|
+
* success. A filesystem-backed composition must therefore pass the same
|
|
246
|
+
* directory it gives `ArtifactStore.layerFileSystem`.
|
|
247
|
+
*/
|
|
248
|
+
readonly objectsDirectory?: string | undefined
|
|
249
|
+
/**
|
|
250
|
+
* Opens the frozen `VACUUM INTO` file so backup can enumerate artifact
|
|
251
|
+
* roots and migrations from that exact snapshot, independently of the live
|
|
252
|
+
* connection. The host should open this file without applying migrations.
|
|
253
|
+
*/
|
|
254
|
+
readonly snapshotDatabaseLayer: (databaseFile: string) => Layer.Layer<SqlClient.SqlClient, E, R>
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Which backup to restore and where the restored store lands.
|
|
259
|
+
*
|
|
260
|
+
* @since 0.1.0
|
|
261
|
+
* @category models
|
|
262
|
+
*/
|
|
263
|
+
export interface RestoreOptions extends FileSizeOptions {
|
|
264
|
+
/** The directory a previous {@link backup} wrote. */
|
|
265
|
+
readonly backupDirectory: string
|
|
266
|
+
/** The fresh directory the restored store is written into. Created when absent; must be empty when present. */
|
|
267
|
+
readonly targetDirectory: string
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Which backup to restore and how to open the freshly restored SQLite file
|
|
272
|
+
* for restore-time fencing.
|
|
273
|
+
*
|
|
274
|
+
* @since 0.1.0
|
|
275
|
+
* @category models
|
|
276
|
+
*/
|
|
277
|
+
export interface RestoreAndFenceOptions<R = never, E = never> extends RestoreOptions {
|
|
278
|
+
/**
|
|
279
|
+
* Builds the database and durable-writer layer for the newly restored file.
|
|
280
|
+
* This keeps database opening as the caller's host composition rather than
|
|
281
|
+
* importing a Node-only driver into this browser-safe module.
|
|
282
|
+
*/
|
|
283
|
+
readonly databaseLayer: (databaseFile: string) => Layer.Layer<DurableWriter | SqlClient.SqlClient, E, R>
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* The restored store's on-disk locations, ready to compose database and
|
|
288
|
+
* artifact layers over.
|
|
289
|
+
*
|
|
290
|
+
* @since 0.1.0
|
|
291
|
+
* @category models
|
|
292
|
+
*/
|
|
293
|
+
export interface RestoredStore {
|
|
294
|
+
readonly databaseFile: string
|
|
295
|
+
readonly objectsDirectory: string
|
|
296
|
+
readonly manifest: BackupManifest
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* A restored store after restore-time fencing has invalidated pre-backup
|
|
301
|
+
* owners.
|
|
302
|
+
*
|
|
303
|
+
* @since 0.1.0
|
|
304
|
+
* @category models
|
|
305
|
+
*/
|
|
306
|
+
export interface FencedRestoredStore extends RestoredStore {
|
|
307
|
+
readonly fence: FenceSummary
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* What {@link fence} invalidated on the restored store.
|
|
312
|
+
*
|
|
313
|
+
* @since 0.1.0
|
|
314
|
+
* @category models
|
|
315
|
+
*/
|
|
316
|
+
export interface FenceSummary {
|
|
317
|
+
/** Runs whose pending claim columns were cleared. */
|
|
318
|
+
readonly clearedClaims: number
|
|
319
|
+
/** Runs that were `running` at backup time, now suspended with their owner fence cleared. */
|
|
320
|
+
readonly suspendedRuns: number
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const error = (
|
|
324
|
+
method: string,
|
|
325
|
+
code: DisasterRecoveryErrorCode,
|
|
326
|
+
message: string,
|
|
327
|
+
cause: unknown
|
|
328
|
+
): DisasterRecoveryError =>
|
|
329
|
+
new DisasterRecoveryError({
|
|
330
|
+
code,
|
|
331
|
+
method,
|
|
332
|
+
message: `${code}: DisasterRecovery.${method}: ${message}`,
|
|
333
|
+
cause
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* One mapper per failure family, shared across every call site so the
|
|
338
|
+
* vocabulary stays uniform.
|
|
339
|
+
*/
|
|
340
|
+
const ioFailure = (method: string, subject: string) => (cause: unknown): DisasterRecoveryError =>
|
|
341
|
+
error(method, "io", `the host filesystem refused ${subject}`, cause)
|
|
342
|
+
|
|
343
|
+
const sqlFailure = (method: string, subject: string) => (cause: unknown): DisasterRecoveryError =>
|
|
344
|
+
error(method, "sql", `the database refused ${subject}`, cause)
|
|
345
|
+
|
|
346
|
+
/** Hashes bytes with the injected crypto service; a broken host is a defect. */
|
|
347
|
+
const measure = (bytes: Uint8Array): Effect.Effect<typeof Sha256.Digest.Type, never, Crypto.Crypto> =>
|
|
348
|
+
Schema.decodeUnknownEffect(Sha256)(bytes).pipe(Effect.orDie)
|
|
349
|
+
|
|
350
|
+
/** Resolves and validates the shared whole-file buffering ceiling. */
|
|
351
|
+
const fileSizeLimit = (
|
|
352
|
+
method: string,
|
|
353
|
+
options: FileSizeOptions
|
|
354
|
+
): number | DisasterRecoveryError => {
|
|
355
|
+
const limit = options.maxFileSizeBytes
|
|
356
|
+
if (limit === undefined) return defaultMaxFileSizeBytes
|
|
357
|
+
if (Number.isSafeInteger(limit) && limit >= 0) return limit
|
|
358
|
+
return error(
|
|
359
|
+
method,
|
|
360
|
+
"invalid_options",
|
|
361
|
+
`maxFileSizeBytes must be a finite non-negative safe integer; received ${String(limit)}`,
|
|
362
|
+
limit
|
|
363
|
+
)
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Refuses an oversized file before a whole-file read allocates its buffer.
|
|
368
|
+
* Every caller admits `limit` through `fileSizeLimit`, so `BigInt` cannot
|
|
369
|
+
* reject it.
|
|
370
|
+
*/
|
|
371
|
+
const checkFileSize = (
|
|
372
|
+
fs: FileSystem.FileSystem,
|
|
373
|
+
method: string,
|
|
374
|
+
path: string,
|
|
375
|
+
limit: number
|
|
376
|
+
): Effect.Effect<void, DisasterRecoveryError> =>
|
|
377
|
+
Effect.gen(function*() {
|
|
378
|
+
const info = yield* fs.stat(path).pipe(Effect.mapError(ioFailure(method, `stating ${path}`)))
|
|
379
|
+
if (info.size <= BigInt(limit)) return
|
|
380
|
+
const message = `${path} is ${info.size} bytes, which exceeds the ${limit}-byte file limit`
|
|
381
|
+
return yield* Effect.fail(error(method, "io", message, new RangeError(message)))
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Admits a target directory that does not exist yet — created recursively —
|
|
386
|
+
* or exists empty. Anything else is refused rather than merged over.
|
|
387
|
+
*/
|
|
388
|
+
const ensureEmptyDirectory = (
|
|
389
|
+
fs: FileSystem.FileSystem,
|
|
390
|
+
method: string,
|
|
391
|
+
directory: string
|
|
392
|
+
): Effect.Effect<void, DisasterRecoveryError> =>
|
|
393
|
+
Effect.gen(function*() {
|
|
394
|
+
const present = yield* fs.exists(directory).pipe(Effect.mapError(ioFailure(method, `probing ${directory}`)))
|
|
395
|
+
if (!present) {
|
|
396
|
+
return yield* fs.makeDirectory(directory, { recursive: true }).pipe(
|
|
397
|
+
Effect.mapError(ioFailure(method, `creating ${directory}`))
|
|
398
|
+
)
|
|
399
|
+
}
|
|
400
|
+
const entries = yield* fs.readDirectory(directory).pipe(
|
|
401
|
+
Effect.mapError(ioFailure(method, `listing ${directory}`))
|
|
402
|
+
)
|
|
403
|
+
if (entries.length > 0) {
|
|
404
|
+
return yield* Effect.fail(
|
|
405
|
+
error(method, "not_empty", `${directory} already holds ${entries.length} entries`, directory)
|
|
406
|
+
)
|
|
407
|
+
}
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* A relative blob path in the store's fanout layout: a two-hex directory
|
|
412
|
+
* holding a 64-hex digest that begins with it. Anything else under the
|
|
413
|
+
* objects directory — a scratch `.tmp-*` file, the fanout directory itself —
|
|
414
|
+
* is not part of the store's address space.
|
|
415
|
+
*/
|
|
416
|
+
const blobEntry = (entry: string): string | undefined => {
|
|
417
|
+
const match = entry.match(/^([0-9a-f]{2})[/\\]([0-9a-f]{64})$/)
|
|
418
|
+
if (match === null || !match[2]!.startsWith(match[1]!)) return undefined
|
|
419
|
+
return match[2]
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const blobPath = (directory: string, digest: string): string => `${directory}/${digest.slice(0, 2)}/${digest}`
|
|
423
|
+
|
|
424
|
+
/** The applied rows of the shared migrations table, in ladder order. */
|
|
425
|
+
const appliedMigrations = (
|
|
426
|
+
sql: SqlClient.SqlClient,
|
|
427
|
+
method: string
|
|
428
|
+
): Effect.Effect<Array<AppliedMigration>, DisasterRecoveryError> =>
|
|
429
|
+
sql<{ readonly migration_id: number; readonly name: string }>`
|
|
430
|
+
SELECT migration_id, name FROM flows_migrations ORDER BY migration_id ASC
|
|
431
|
+
`.withoutTransform.pipe(
|
|
432
|
+
Effect.mapError(sqlFailure(method, "reading flows_migrations")),
|
|
433
|
+
Effect.map((rows) => rows.map((row) => ({ migrationId: Number(row.migration_id), name: row.name })))
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
interface SnapshotState {
|
|
437
|
+
readonly migrations: Array<AppliedMigration>
|
|
438
|
+
readonly artifactRoots: ReadonlySet<string>
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** Reads every artifact root from the frozen database, never the live one. */
|
|
442
|
+
const inspectSnapshot = (
|
|
443
|
+
sql: SqlClient.SqlClient
|
|
444
|
+
): Effect.Effect<SnapshotState, DisasterRecoveryError> =>
|
|
445
|
+
Effect.gen(function*() {
|
|
446
|
+
const migrations = yield* appliedMigrations(sql, "backup")
|
|
447
|
+
const cacheRows = yield* sql<{ readonly meta_json: string }>`
|
|
448
|
+
SELECT meta_json FROM flows_step_cache
|
|
449
|
+
`.withoutTransform.pipe(
|
|
450
|
+
Effect.mapError(sqlFailure("backup", "reading artifact roots from snapshot step cache"))
|
|
451
|
+
)
|
|
452
|
+
const attemptRows = yield* sql<{
|
|
453
|
+
readonly checkpoint_json: string | null
|
|
454
|
+
readonly meta_json: string
|
|
455
|
+
}>`
|
|
456
|
+
SELECT checkpoint_json, meta_json FROM flows_attempts
|
|
457
|
+
`.withoutTransform.pipe(
|
|
458
|
+
Effect.mapError(sqlFailure("backup", "reading artifact roots from snapshot attempts"))
|
|
459
|
+
)
|
|
460
|
+
const artifactRoots = new Set<string>()
|
|
461
|
+
const decodeFailure = (cause: ArtifactRoots.ArtifactRootDecodeError): DisasterRecoveryError =>
|
|
462
|
+
error("backup", "snapshot_incomplete", cause.message, cause.cause)
|
|
463
|
+
for (const row of cacheRows) {
|
|
464
|
+
for (
|
|
465
|
+
const digest of yield* ArtifactRoots.rootDigests("flows_step_cache", row.meta_json).pipe(
|
|
466
|
+
Effect.mapError(decodeFailure)
|
|
467
|
+
)
|
|
468
|
+
) artifactRoots.add(digest)
|
|
469
|
+
}
|
|
470
|
+
for (const row of attemptRows) {
|
|
471
|
+
for (
|
|
472
|
+
const digest of yield* ArtifactRoots.rootDigests("flows_attempts", row.meta_json).pipe(
|
|
473
|
+
Effect.mapError(decodeFailure)
|
|
474
|
+
)
|
|
475
|
+
) artifactRoots.add(digest)
|
|
476
|
+
for (
|
|
477
|
+
const digest of yield* ArtifactRoots.checkpointDigests(row.checkpoint_json).pipe(
|
|
478
|
+
Effect.mapError(decodeFailure)
|
|
479
|
+
)
|
|
480
|
+
) artifactRoots.add(digest)
|
|
481
|
+
}
|
|
482
|
+
return { migrations, artifactRoots }
|
|
483
|
+
})
|
|
484
|
+
|
|
485
|
+
/** Reads and decodes the manifest a backup directory must carry. */
|
|
486
|
+
const readManifest = (
|
|
487
|
+
fs: FileSystem.FileSystem,
|
|
488
|
+
method: string,
|
|
489
|
+
backupDirectory: string,
|
|
490
|
+
maxFileSizeBytes: number
|
|
491
|
+
): Effect.Effect<BackupManifest, DisasterRecoveryError, Crypto.Crypto> =>
|
|
492
|
+
Effect.gen(function*() {
|
|
493
|
+
const path = `${backupDirectory}/${manifestFileName}`
|
|
494
|
+
const present = yield* fs.exists(path).pipe(Effect.mapError(ioFailure(method, `probing ${path}`)))
|
|
495
|
+
if (!present) {
|
|
496
|
+
return yield* Effect.fail(
|
|
497
|
+
error(method, "missing_file", `${path} does not exist — the backup is incomplete or not a backup`, path)
|
|
498
|
+
)
|
|
499
|
+
}
|
|
500
|
+
yield* checkFileSize(fs, method, path, maxFileSizeBytes)
|
|
501
|
+
const text = yield* fs.readFileString(path).pipe(Effect.mapError(ioFailure(method, `reading ${path}`)))
|
|
502
|
+
return yield* Schema.decodeUnknownEffect(ManifestFromJsonString)(text).pipe(
|
|
503
|
+
Effect.mapError((cause) =>
|
|
504
|
+
error(method, "invalid_manifest", `${path} does not decode as a backup manifest`, cause)
|
|
505
|
+
)
|
|
506
|
+
)
|
|
507
|
+
})
|
|
508
|
+
|
|
509
|
+
/** Reads a backup file and refuses bytes that no longer hash to the manifest. */
|
|
510
|
+
const checkedFile = (
|
|
511
|
+
fs: FileSystem.FileSystem,
|
|
512
|
+
method: string,
|
|
513
|
+
path: string,
|
|
514
|
+
expected: string,
|
|
515
|
+
maxFileSizeBytes: number
|
|
516
|
+
): Effect.Effect<Uint8Array, DisasterRecoveryError, Crypto.Crypto> =>
|
|
517
|
+
Effect.gen(function*() {
|
|
518
|
+
const present = yield* fs.exists(path).pipe(Effect.mapError(ioFailure(method, `probing ${path}`)))
|
|
519
|
+
if (!present) {
|
|
520
|
+
return yield* Effect.fail(error(method, "missing_file", `${path} does not exist`, path))
|
|
521
|
+
}
|
|
522
|
+
yield* checkFileSize(fs, method, path, maxFileSizeBytes)
|
|
523
|
+
const bytes = yield* fs.readFile(path).pipe(Effect.mapError(ioFailure(method, `reading ${path}`)))
|
|
524
|
+
const measured = yield* measure(bytes)
|
|
525
|
+
if (measured !== expected) {
|
|
526
|
+
return yield* Effect.fail(
|
|
527
|
+
error(method, "digest_mismatch", `${path} hashes to ${measured}, the manifest records ${expected}`, path)
|
|
528
|
+
)
|
|
529
|
+
}
|
|
530
|
+
return bytes
|
|
531
|
+
})
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Captures a hot backup of the live store into an empty directory.
|
|
535
|
+
*
|
|
536
|
+
* The database is snapshotted first with `VACUUM INTO` — a read transaction
|
|
537
|
+
* under WAL, so live writers are never blocked and the copy is one consistent
|
|
538
|
+
* point in time. The artifact walk runs after it, so every digest the
|
|
539
|
+
* snapshot references is captured (publication precedes reference). Blobs are
|
|
540
|
+
* digest-verified as they are copied; a blob whose bytes no longer hash to
|
|
541
|
+
* its address fails the backup loudly rather than capturing corruption. The
|
|
542
|
+
* manifest is encoded and admitted under the same file-size ceiling before it
|
|
543
|
+
* is written last, so a successful backup remains readable with its own
|
|
544
|
+
* options.
|
|
545
|
+
*
|
|
546
|
+
* With an `objectsDirectory`, the whole capture holds the artifact backup
|
|
547
|
+
* lease, so concurrent sweep deletion cannot remove a referenced blob
|
|
548
|
+
* mid-copy. Without one, no lease is taken; the frozen-root verification
|
|
549
|
+
* still fails the backup loudly when the snapshot references any blob, so an
|
|
550
|
+
* unfenced capture can never report success while missing artifact bytes.
|
|
551
|
+
*
|
|
552
|
+
* @since 0.1.0
|
|
553
|
+
* @category operations
|
|
554
|
+
*/
|
|
555
|
+
export const backup = <R = never, E = never>(
|
|
556
|
+
options: BackupOptions<R, E>
|
|
557
|
+
): Effect.Effect<
|
|
558
|
+
BackupManifest,
|
|
559
|
+
DisasterRecoveryError | E,
|
|
560
|
+
SqlClient.SqlClient | FileSystem.FileSystem | Crypto.Crypto | R
|
|
561
|
+
> =>
|
|
562
|
+
Effect.gen(function*() {
|
|
563
|
+
const limit = fileSizeLimit("backup", options)
|
|
564
|
+
if (typeof limit !== "number") return yield* Effect.fail(limit)
|
|
565
|
+
const maxFileSizeBytes = limit
|
|
566
|
+
const sql = yield* Effect.service(SqlClient.SqlClient)
|
|
567
|
+
const fs = yield* FileSystem.FileSystem
|
|
568
|
+
const createdAtMs = yield* Clock.currentTimeMillis.pipe(Effect.map(Math.floor))
|
|
569
|
+
yield* ensureEmptyDirectory(fs, "backup", options.directory)
|
|
570
|
+
|
|
571
|
+
const capture = Effect.gen(function*() {
|
|
572
|
+
const databasePath = `${options.directory}/${databaseFileName}`
|
|
573
|
+
yield* sql`VACUUM INTO ${databasePath}`.pipe(
|
|
574
|
+
Effect.mapError(sqlFailure("backup", `snapshotting the database into ${databasePath}`))
|
|
575
|
+
)
|
|
576
|
+
const snapshot = yield* Effect.flatMap(
|
|
577
|
+
Effect.service(SqlClient.SqlClient),
|
|
578
|
+
inspectSnapshot
|
|
579
|
+
).pipe(Effect.provide(options.snapshotDatabaseLayer(databasePath)))
|
|
580
|
+
// Opening the frozen file may normalize SQLite journal metadata, so its
|
|
581
|
+
// manifest digest is measured only after the inspection connection closes.
|
|
582
|
+
yield* checkFileSize(fs, "backup", databasePath, maxFileSizeBytes)
|
|
583
|
+
const databaseBytes = yield* fs.readFile(databasePath).pipe(
|
|
584
|
+
Effect.mapError(ioFailure("backup", `reading ${databasePath} back`))
|
|
585
|
+
)
|
|
586
|
+
const sha256 = yield* measure(databaseBytes)
|
|
587
|
+
|
|
588
|
+
const artifacts: Array<ArtifactEntry> = []
|
|
589
|
+
const captured = new Set<string>()
|
|
590
|
+
if (options.objectsDirectory !== undefined) {
|
|
591
|
+
const objectsDirectory = options.objectsDirectory
|
|
592
|
+
const entries = yield* fs.readDirectory(objectsDirectory, { recursive: true }).pipe(
|
|
593
|
+
Effect.mapError(ioFailure("backup", `listing ${objectsDirectory}`))
|
|
594
|
+
)
|
|
595
|
+
for (const entry of [...entries].sort()) {
|
|
596
|
+
const digest = blobEntry(entry)
|
|
597
|
+
if (digest === undefined) continue
|
|
598
|
+
const source = blobPath(objectsDirectory, digest)
|
|
599
|
+
yield* checkFileSize(fs, "backup", source, maxFileSizeBytes)
|
|
600
|
+
const bytes = yield* fs.readFile(source).pipe(
|
|
601
|
+
Effect.mapError(ioFailure("backup", `reading ${source}`))
|
|
602
|
+
)
|
|
603
|
+
const measured = yield* measure(bytes)
|
|
604
|
+
if (measured !== digest) {
|
|
605
|
+
return yield* Effect.fail(
|
|
606
|
+
error(
|
|
607
|
+
"backup",
|
|
608
|
+
"artifact_corruption",
|
|
609
|
+
`${source} hashes to ${measured}; repair the store before backing it up`,
|
|
610
|
+
source
|
|
611
|
+
)
|
|
612
|
+
)
|
|
613
|
+
}
|
|
614
|
+
const target = blobPath(`${options.directory}/${objectsDirectoryName}`, digest)
|
|
615
|
+
yield* fs.makeDirectory(`${options.directory}/${objectsDirectoryName}/${digest.slice(0, 2)}`, {
|
|
616
|
+
recursive: true
|
|
617
|
+
}).pipe(Effect.mapError(ioFailure("backup", `creating the objects directory for ${digest}`)))
|
|
618
|
+
yield* fs.writeFile(target, bytes).pipe(Effect.mapError(ioFailure("backup", `writing ${target}`)))
|
|
619
|
+
artifacts.push({ digest: measured, sizeBytes: bytes.length })
|
|
620
|
+
captured.add(measured)
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const missing = [...snapshot.artifactRoots].filter((digest) => !captured.has(digest)).sort()
|
|
625
|
+
if (missing.length > 0) {
|
|
626
|
+
return yield* Effect.fail(
|
|
627
|
+
error(
|
|
628
|
+
"backup",
|
|
629
|
+
"snapshot_incomplete",
|
|
630
|
+
`the frozen database references ${missing.length} artifact blobs absent from the backup`,
|
|
631
|
+
{ missing }
|
|
632
|
+
)
|
|
633
|
+
)
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
const manifest: BackupManifest = {
|
|
637
|
+
formatVersion: 1,
|
|
638
|
+
createdAtMs,
|
|
639
|
+
database: {
|
|
640
|
+
file: databaseFileName,
|
|
641
|
+
sha256,
|
|
642
|
+
sizeBytes: databaseBytes.length,
|
|
643
|
+
migrations: snapshot.migrations
|
|
644
|
+
},
|
|
645
|
+
artifacts
|
|
646
|
+
}
|
|
647
|
+
const manifestPath = `${options.directory}/${manifestFileName}`
|
|
648
|
+
const manifestBytes = new TextEncoder().encode(`${JSON.stringify(manifest, null, 2)}\n`)
|
|
649
|
+
if (manifestBytes.byteLength > maxFileSizeBytes) {
|
|
650
|
+
const message =
|
|
651
|
+
`${manifestPath} is ${manifestBytes.byteLength} bytes, which exceeds the ${maxFileSizeBytes}-byte file limit`
|
|
652
|
+
return yield* Effect.fail(error("backup", "io", message, new RangeError(message)))
|
|
653
|
+
}
|
|
654
|
+
yield* fs.writeFile(manifestPath, manifestBytes).pipe(
|
|
655
|
+
Effect.mapError(ioFailure("backup", `writing ${manifestFileName}`))
|
|
656
|
+
)
|
|
657
|
+
return manifest
|
|
658
|
+
})
|
|
659
|
+
|
|
660
|
+
// The directory was empty when the capture began, so everything in it is
|
|
661
|
+
// this capture's: the snapshot, any SQLite sidecar the inspection
|
|
662
|
+
// connection left, and the copied blobs. A failed capture removes them and
|
|
663
|
+
// leaves the directory reusable for a retry. Cleanup is best effort; the
|
|
664
|
+
// original failure is the one reported.
|
|
665
|
+
const discardPartial = fs.readDirectory(options.directory).pipe(
|
|
666
|
+
Effect.flatMap((entries) =>
|
|
667
|
+
Effect.forEach(
|
|
668
|
+
entries,
|
|
669
|
+
(entry) => fs.remove(`${options.directory}/${entry}`, { recursive: true, force: true }),
|
|
670
|
+
{ discard: true }
|
|
671
|
+
)
|
|
672
|
+
),
|
|
673
|
+
Effect.ignore
|
|
674
|
+
)
|
|
675
|
+
|
|
676
|
+
return yield* (options.objectsDirectory === undefined
|
|
677
|
+
? capture
|
|
678
|
+
: ArtifactBackupLease.withLease(
|
|
679
|
+
fs,
|
|
680
|
+
options.objectsDirectory,
|
|
681
|
+
capture,
|
|
682
|
+
ioFailure("backup", `coordinating artifact backup in ${options.objectsDirectory}`)
|
|
683
|
+
)).pipe(Effect.onError(() => discardPartial))
|
|
684
|
+
}).pipe(Effect.withSpan("DisasterRecovery.backup"))
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Verifies a backup directory against its manifest without restoring it:
|
|
688
|
+
* the manifest decodes, the database snapshot hashes to its recorded digest,
|
|
689
|
+
* and every listed artifact blob is present and hashes to its address.
|
|
690
|
+
*
|
|
691
|
+
* @since 0.1.0
|
|
692
|
+
* @category operations
|
|
693
|
+
*/
|
|
694
|
+
export const verify = Effect.fn("DisasterRecovery.verify")(function*(
|
|
695
|
+
backupDirectory: string,
|
|
696
|
+
options: FileSizeOptions = {}
|
|
697
|
+
) {
|
|
698
|
+
const limit = fileSizeLimit("verify", options)
|
|
699
|
+
if (typeof limit !== "number") return yield* Effect.fail(limit)
|
|
700
|
+
const maxFileSizeBytes = limit
|
|
701
|
+
const fs = yield* FileSystem.FileSystem
|
|
702
|
+
const manifest = yield* readManifest(fs, "verify", backupDirectory, maxFileSizeBytes)
|
|
703
|
+
yield* checkedFile(
|
|
704
|
+
fs,
|
|
705
|
+
"verify",
|
|
706
|
+
`${backupDirectory}/${manifest.database.file}`,
|
|
707
|
+
manifest.database.sha256,
|
|
708
|
+
maxFileSizeBytes
|
|
709
|
+
)
|
|
710
|
+
for (const entry of manifest.artifacts) {
|
|
711
|
+
yield* checkedFile(
|
|
712
|
+
fs,
|
|
713
|
+
"verify",
|
|
714
|
+
blobPath(`${backupDirectory}/${objectsDirectoryName}`, entry.digest),
|
|
715
|
+
entry.digest,
|
|
716
|
+
maxFileSizeBytes
|
|
717
|
+
)
|
|
718
|
+
}
|
|
719
|
+
return manifest
|
|
720
|
+
})
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Restores a verified backup into an empty target directory.
|
|
724
|
+
*
|
|
725
|
+
* Every byte is re-verified against the manifest as it is copied, so a backup
|
|
726
|
+
* that rotted in storage is refused rather than restored. The target holds
|
|
727
|
+
* the database file, the objects directory, and a `restored.json` marker; it
|
|
728
|
+
* is a fresh store directory to compose `NodeDatabase.layer` and
|
|
729
|
+
* `ArtifactStore.layerFileSystem` over. The database is restored with the
|
|
730
|
+
* pre-backup owner fences still in place — run {@link fence} against it
|
|
731
|
+
* before any engine adopts it.
|
|
732
|
+
*
|
|
733
|
+
* @since 0.1.0
|
|
734
|
+
* @category operations
|
|
735
|
+
*/
|
|
736
|
+
export const restore = Effect.fn("DisasterRecovery.restore")(function*(options: RestoreOptions) {
|
|
737
|
+
const limit = fileSizeLimit("restore", options)
|
|
738
|
+
if (typeof limit !== "number") return yield* Effect.fail(limit)
|
|
739
|
+
const maxFileSizeBytes = limit
|
|
740
|
+
const fs = yield* FileSystem.FileSystem
|
|
741
|
+
const manifest = yield* readManifest(fs, "restore", options.backupDirectory, maxFileSizeBytes)
|
|
742
|
+
yield* ensureEmptyDirectory(fs, "restore", options.targetDirectory)
|
|
743
|
+
|
|
744
|
+
const databaseBytes = yield* checkedFile(
|
|
745
|
+
fs,
|
|
746
|
+
"restore",
|
|
747
|
+
`${options.backupDirectory}/${manifest.database.file}`,
|
|
748
|
+
manifest.database.sha256,
|
|
749
|
+
maxFileSizeBytes
|
|
750
|
+
)
|
|
751
|
+
const databaseFile = `${options.targetDirectory}/${databaseFileName}`
|
|
752
|
+
yield* fs.writeFile(databaseFile, databaseBytes).pipe(
|
|
753
|
+
Effect.mapError(ioFailure("restore", `writing ${databaseFile}`))
|
|
754
|
+
)
|
|
755
|
+
|
|
756
|
+
const objectsDirectory = `${options.targetDirectory}/${objectsDirectoryName}`
|
|
757
|
+
for (const entry of manifest.artifacts) {
|
|
758
|
+
const bytes = yield* checkedFile(
|
|
759
|
+
fs,
|
|
760
|
+
"restore",
|
|
761
|
+
blobPath(`${options.backupDirectory}/${objectsDirectoryName}`, entry.digest),
|
|
762
|
+
entry.digest,
|
|
763
|
+
maxFileSizeBytes
|
|
764
|
+
)
|
|
765
|
+
yield* fs.makeDirectory(`${objectsDirectory}/${entry.digest.slice(0, 2)}`, { recursive: true }).pipe(
|
|
766
|
+
Effect.mapError(ioFailure("restore", `creating the objects directory for ${entry.digest}`))
|
|
767
|
+
)
|
|
768
|
+
yield* fs.writeFile(blobPath(objectsDirectory, entry.digest), bytes).pipe(
|
|
769
|
+
Effect.mapError(ioFailure("restore", `writing the blob for ${entry.digest}`))
|
|
770
|
+
)
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
const restoredAtMs = yield* Clock.currentTimeMillis.pipe(Effect.map(Math.floor))
|
|
774
|
+
const marker = {
|
|
775
|
+
formatVersion: 1,
|
|
776
|
+
restoredAtMs,
|
|
777
|
+
backupCreatedAtMs: manifest.createdAtMs,
|
|
778
|
+
databaseSha256: manifest.database.sha256
|
|
779
|
+
}
|
|
780
|
+
yield* fs.writeFileString(
|
|
781
|
+
`${options.targetDirectory}/${restoredMarkerFileName}`,
|
|
782
|
+
`${JSON.stringify(marker, null, 2)}\n`
|
|
783
|
+
).pipe(Effect.mapError(ioFailure("restore", `writing ${restoredMarkerFileName}`)))
|
|
784
|
+
return { databaseFile, objectsDirectory, manifest } satisfies RestoredStore
|
|
785
|
+
})
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Bumps the restored store's fencing epoch so pre-backup owners are fenced
|
|
789
|
+
* out.
|
|
790
|
+
*
|
|
791
|
+
* The store's fence is `OwnerId` equality, so the epoch bump is fence
|
|
792
|
+
* invalidation: in one serialized write transaction every pending claim is
|
|
793
|
+
* cleared, every run that was `running` at backup time is suspended with its
|
|
794
|
+
* owner and heartbeat cleared, and every consensus lease is deleted. A
|
|
795
|
+
* surviving pre-backup owner then fails every fenced operation against the
|
|
796
|
+
* restored store — `heartbeat` and `transitionOwned` report `FenceLost`,
|
|
797
|
+
* fenced journal appends fail `fence_lost` — exactly as a stale Temporal owner
|
|
798
|
+
* fails its `rangeID` compare-and-swap. The suspended runs are claimable
|
|
799
|
+
* immediately, without waiting out the heartbeat staleness cutoff and without
|
|
800
|
+
* liveness evidence.
|
|
801
|
+
*
|
|
802
|
+
* Every migration recorded in the manifest must remain applied with the same
|
|
803
|
+
* ID and namespaced name. Forward additions within any installed block are
|
|
804
|
+
* compatible, including engine-store `3006` below an existing plan `4003`;
|
|
805
|
+
* the current database layer applies them on open. A missing or renamed
|
|
806
|
+
* historical entry fails `schema_mismatch` before ownership is cleared.
|
|
807
|
+
*
|
|
808
|
+
* In-flight attempt rows are deliberately untouched: attempt writes are
|
|
809
|
+
* fenced on the run row's ownership, and the resuming engine adopts or
|
|
810
|
+
* retries them under its own fresh owner.
|
|
811
|
+
*
|
|
812
|
+
* @since 0.1.0
|
|
813
|
+
* @category operations
|
|
814
|
+
*/
|
|
815
|
+
export const fence = Effect.fn("DisasterRecovery.fence")(function*(manifest: BackupManifest) {
|
|
816
|
+
const sql = yield* Effect.service(SqlClient.SqlClient)
|
|
817
|
+
const writer = yield* DurableWriter
|
|
818
|
+
const applied = yield* appliedMigrations(sql, "fence")
|
|
819
|
+
const expected = manifest.database.migrations
|
|
820
|
+
const key = (migration: AppliedMigration): string => `${migration.migrationId}:${migration.name}`
|
|
821
|
+
// IDs identify migrations within their reserved blocks. Compare historical
|
|
822
|
+
// identities independently so additions in lower blocks cannot shift them.
|
|
823
|
+
const appliedById = new Map(applied.map((migration) => [migration.migrationId, migration.name]))
|
|
824
|
+
if (expected.some((migration) => appliedById.get(migration.migrationId) !== migration.name)) {
|
|
825
|
+
return yield* Effect.fail(
|
|
826
|
+
error(
|
|
827
|
+
"fence",
|
|
828
|
+
"schema_mismatch",
|
|
829
|
+
`the restored database applied [${applied.map(key).join(", ")}] but the manifest records [${
|
|
830
|
+
expected.map(key).join(", ")
|
|
831
|
+
}]`,
|
|
832
|
+
{ applied, expected }
|
|
833
|
+
)
|
|
834
|
+
)
|
|
835
|
+
}
|
|
836
|
+
return yield* writer.write(
|
|
837
|
+
Effect.gen(function*() {
|
|
838
|
+
const claims = yield* sql<{ readonly run_id: string }>`
|
|
839
|
+
UPDATE flows_runs
|
|
840
|
+
SET
|
|
841
|
+
claim_host_id = NULL,
|
|
842
|
+
claim_pid = NULL,
|
|
843
|
+
claim_nonce = NULL,
|
|
844
|
+
claimed_at_ms = NULL
|
|
845
|
+
WHERE claim_host_id IS NOT NULL
|
|
846
|
+
RETURNING run_id
|
|
847
|
+
`.withoutTransform
|
|
848
|
+
const running = yield* sql<{ readonly run_id: string }>`
|
|
849
|
+
UPDATE flows_runs
|
|
850
|
+
SET
|
|
851
|
+
status = 'suspended',
|
|
852
|
+
owner_host_id = NULL,
|
|
853
|
+
owner_pid = NULL,
|
|
854
|
+
owner_nonce = NULL,
|
|
855
|
+
heartbeat_at_ms = NULL,
|
|
856
|
+
waiting_reason = 'released',
|
|
857
|
+
waiting_wake_at_ms = NULL,
|
|
858
|
+
waiting_token = NULL
|
|
859
|
+
WHERE status = 'running'
|
|
860
|
+
RETURNING run_id
|
|
861
|
+
`.withoutTransform
|
|
862
|
+
yield* sql`DELETE FROM flows_consensus_leases`.withoutTransform
|
|
863
|
+
return { clearedClaims: claims.length, suspendedRuns: running.length } satisfies FenceSummary
|
|
864
|
+
})
|
|
865
|
+
).pipe(Effect.mapError(sqlFailure("fence", "invalidating the persisted fences")))
|
|
866
|
+
})
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* Restores a backup and immediately fences the restored database.
|
|
870
|
+
*
|
|
871
|
+
* This is the one-shot operator API for disaster recovery. The database
|
|
872
|
+
* driver itself still arrives through a caller-supplied Layer so this module
|
|
873
|
+
* remains host-neutral and browser-bundleable; the bundled Node script passes
|
|
874
|
+
* `NodeDatabase.layer` for the restored file.
|
|
875
|
+
*
|
|
876
|
+
* @since 0.1.0
|
|
877
|
+
* @category operations
|
|
878
|
+
*/
|
|
879
|
+
export const restoreAndFence = <R = never, E = never>(
|
|
880
|
+
options: RestoreAndFenceOptions<R, E>
|
|
881
|
+
): Effect.Effect<FencedRestoredStore, DisasterRecoveryError | E, FileSystem.FileSystem | Crypto.Crypto | R> =>
|
|
882
|
+
Effect.gen(function*() {
|
|
883
|
+
const restored = yield* restore(options)
|
|
884
|
+
const summary = yield* fence(restored.manifest).pipe(
|
|
885
|
+
Effect.provide(options.databaseLayer(restored.databaseFile))
|
|
886
|
+
)
|
|
887
|
+
return { ...restored, fence: summary } satisfies FencedRestoredStore
|
|
888
|
+
})
|