@smthrs/engine-store 1.0.0-rc.5 → 1.0.0-rc.7

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.
Files changed (262) hide show
  1. package/README.md +15 -15
  2. package/dist/cjs/ArtifactGc.d.ts +1 -1
  3. package/dist/cjs/ArtifactGc.d.ts.map +1 -1
  4. package/dist/cjs/ArtifactGc.js +1 -1
  5. package/dist/cjs/ArtifactGc.js.map +1 -1
  6. package/dist/cjs/DeferredClockFold.d.ts +4 -4
  7. package/dist/cjs/DeferredClockFold.d.ts.map +1 -1
  8. package/dist/cjs/DeferredClockFold.js +1 -1
  9. package/dist/cjs/DeferredClockFold.js.map +1 -1
  10. package/dist/cjs/DisasterRecovery.d.ts +1 -1
  11. package/dist/cjs/DisasterRecovery.d.ts.map +1 -1
  12. package/dist/cjs/DisasterRecovery.js +1 -1
  13. package/dist/cjs/DisasterRecovery.js.map +1 -1
  14. package/dist/cjs/DurableEngineState.d.ts +1 -1
  15. package/dist/cjs/DurableEngineState.d.ts.map +1 -1
  16. package/dist/cjs/DurableEngineState.js +1 -1
  17. package/dist/cjs/DurableEngineState.js.map +1 -1
  18. package/dist/cjs/ExecutionSnapshot.d.ts +2 -2
  19. package/dist/cjs/ExecutionSnapshot.d.ts.map +1 -1
  20. package/dist/cjs/ExecutionSnapshot.js +1 -1
  21. package/dist/cjs/ExecutionSnapshot.js.map +1 -1
  22. package/dist/cjs/Migrations.d.ts +2 -2
  23. package/dist/cjs/Migrations.d.ts.map +1 -1
  24. package/dist/cjs/OwnerIdentity.js +1 -1
  25. package/dist/cjs/OwnerIdentity.js.map +2 -2
  26. package/dist/cjs/PlanInputStore.d.ts +1 -1
  27. package/dist/cjs/PlanInputStore.d.ts.map +1 -1
  28. package/dist/cjs/PlanInputStore.js +1 -1
  29. package/dist/cjs/PlanInputStore.js.map +1 -1
  30. package/dist/cjs/PlanMergeStore.d.ts +1 -1
  31. package/dist/cjs/PlanMergeStore.d.ts.map +1 -1
  32. package/dist/cjs/PlanMergeStore.js +1 -1
  33. package/dist/cjs/PlanMergeStore.js.map +1 -1
  34. package/dist/cjs/Retention.d.ts +2 -2
  35. package/dist/cjs/Retention.d.ts.map +1 -1
  36. package/dist/cjs/Retention.js +1 -1
  37. package/dist/cjs/Retention.js.map +1 -1
  38. package/dist/cjs/RunChangeFeed.d.ts +1 -1
  39. package/dist/cjs/RunChangeFeed.d.ts.map +1 -1
  40. package/dist/cjs/RunChangeFeed.js +1 -1
  41. package/dist/cjs/RunChangeFeed.js.map +1 -1
  42. package/dist/cjs/SelectionStore.d.ts +1 -1
  43. package/dist/cjs/SelectionStore.d.ts.map +1 -1
  44. package/dist/cjs/SelectionStore.js +1 -1
  45. package/dist/cjs/SelectionStore.js.map +1 -1
  46. package/dist/cjs/StepBoundary.d.ts +8 -6
  47. package/dist/cjs/StepBoundary.d.ts.map +1 -1
  48. package/dist/cjs/StepBoundary.js +13 -10
  49. package/dist/cjs/StepBoundary.js.map +2 -2
  50. package/dist/cjs/StepCacheFold.d.ts +2 -2
  51. package/dist/cjs/StepCacheFold.d.ts.map +1 -1
  52. package/dist/cjs/StepCacheFold.js +1 -1
  53. package/dist/cjs/StepCacheFold.js.map +1 -1
  54. package/dist/cjs/internal/EngineStateSchema.d.ts +1 -1
  55. package/dist/cjs/internal/EngineStateSchema.d.ts.map +1 -1
  56. package/dist/cjs/internal/EngineStateSchema.js.map +1 -1
  57. package/dist/cjs/internal/ExecutionSnapshotRead.d.ts +3 -3
  58. package/dist/cjs/internal/ExecutionSnapshotRead.d.ts.map +1 -1
  59. package/dist/cjs/internal/ExecutionSnapshotRead.js.map +1 -1
  60. package/dist/cjs/internal/ExecutionSnapshotRelations.d.ts +1 -1
  61. package/dist/cjs/internal/ExecutionSnapshotRelations.d.ts.map +1 -1
  62. package/dist/cjs/internal/ExecutionSnapshotRelations.js.map +1 -1
  63. package/dist/cjs/internal/RetentionOps.d.ts +2 -2
  64. package/dist/cjs/internal/RetentionOps.d.ts.map +1 -1
  65. package/dist/cjs/internal/RetentionOps.js +1 -1
  66. package/dist/cjs/internal/RetentionOps.js.map +1 -1
  67. package/dist/cjs/internal/RunCatalogOps.d.ts +1 -1
  68. package/dist/cjs/internal/RunCatalogOps.d.ts.map +1 -1
  69. package/dist/cjs/internal/RunCatalogOps.js +1 -1
  70. package/dist/cjs/internal/RunCatalogOps.js.map +1 -1
  71. package/dist/cjs/internal/RunListing.d.ts +1 -1
  72. package/dist/cjs/internal/RunListing.d.ts.map +1 -1
  73. package/dist/cjs/internal/RunListing.js +1 -1
  74. package/dist/cjs/internal/RunListing.js.map +1 -1
  75. package/dist/cjs/migrations/0001_initial.d.ts +1 -1
  76. package/dist/cjs/migrations/0001_initial.d.ts.map +1 -1
  77. package/dist/cjs/migrations/0001_initial.js +1 -1
  78. package/dist/cjs/migrations/0001_initial.js.map +1 -1
  79. package/dist/cjs/migrations/0002_selection_store.d.ts +1 -1
  80. package/dist/cjs/migrations/0002_selection_store.d.ts.map +1 -1
  81. package/dist/cjs/migrations/0002_selection_store.js +1 -1
  82. package/dist/cjs/migrations/0002_selection_store.js.map +1 -1
  83. package/dist/cjs/migrations/0003_plan_inputs.d.ts +1 -1
  84. package/dist/cjs/migrations/0003_plan_inputs.d.ts.map +1 -1
  85. package/dist/cjs/migrations/0003_plan_inputs.js +1 -1
  86. package/dist/cjs/migrations/0003_plan_inputs.js.map +1 -1
  87. package/dist/cjs/migrations/0004_plan_environment.d.ts +1 -1
  88. package/dist/cjs/migrations/0004_plan_environment.d.ts.map +1 -1
  89. package/dist/cjs/migrations/0004_plan_environment.js +1 -1
  90. package/dist/cjs/migrations/0004_plan_environment.js.map +1 -1
  91. package/dist/cjs/migrations/0005_plan_merges.d.ts +1 -1
  92. package/dist/cjs/migrations/0005_plan_merges.d.ts.map +1 -1
  93. package/dist/cjs/migrations/0005_plan_merges.js +1 -1
  94. package/dist/cjs/migrations/0005_plan_merges.js.map +1 -1
  95. package/dist/cjs/migrations/0006_execution_listing.d.ts +1 -1
  96. package/dist/cjs/migrations/0006_execution_listing.d.ts.map +1 -1
  97. package/dist/cjs/migrations/0006_execution_listing.js +1 -1
  98. package/dist/cjs/migrations/0006_execution_listing.js.map +1 -1
  99. package/dist/cjs/migrations/0007_run_parent_sequence.d.ts +1 -1
  100. package/dist/cjs/migrations/0007_run_parent_sequence.d.ts.map +1 -1
  101. package/dist/cjs/migrations/0007_run_parent_sequence.js +1 -1
  102. package/dist/cjs/migrations/0007_run_parent_sequence.js.map +1 -1
  103. package/dist/cjs/migrations/0008_deferred_consumption.d.ts +1 -1
  104. package/dist/cjs/migrations/0008_deferred_consumption.d.ts.map +1 -1
  105. package/dist/cjs/migrations/0008_deferred_consumption.js +1 -1
  106. package/dist/cjs/migrations/0008_deferred_consumption.js.map +1 -1
  107. package/dist/cjs/migrations/0009_deferred_clock_facts.d.ts +1 -1
  108. package/dist/cjs/migrations/0009_deferred_clock_facts.d.ts.map +1 -1
  109. package/dist/cjs/migrations/0009_deferred_clock_facts.js +1 -1
  110. package/dist/cjs/migrations/0009_deferred_clock_facts.js.map +1 -1
  111. package/dist/cjs/migrations/0010_pending_cancellation.d.ts +1 -1
  112. package/dist/cjs/migrations/0010_pending_cancellation.d.ts.map +1 -1
  113. package/dist/cjs/migrations/0010_pending_cancellation.js +1 -1
  114. package/dist/cjs/migrations/0010_pending_cancellation.js.map +1 -1
  115. package/dist/cjs/test/TestStores.d.ts +4 -4
  116. package/dist/cjs/test/TestStores.d.ts.map +1 -1
  117. package/dist/esm/ArtifactGc.d.ts +1 -1
  118. package/dist/esm/ArtifactGc.d.ts.map +1 -1
  119. package/dist/esm/ArtifactGc.js +1 -1
  120. package/dist/esm/ArtifactGc.js.map +1 -1
  121. package/dist/esm/DeferredClockFold.d.ts +4 -4
  122. package/dist/esm/DeferredClockFold.d.ts.map +1 -1
  123. package/dist/esm/DeferredClockFold.js +1 -1
  124. package/dist/esm/DeferredClockFold.js.map +1 -1
  125. package/dist/esm/DisasterRecovery.d.ts +1 -1
  126. package/dist/esm/DisasterRecovery.d.ts.map +1 -1
  127. package/dist/esm/DisasterRecovery.js +1 -1
  128. package/dist/esm/DisasterRecovery.js.map +1 -1
  129. package/dist/esm/DurableEngineState.d.ts +1 -1
  130. package/dist/esm/DurableEngineState.d.ts.map +1 -1
  131. package/dist/esm/DurableEngineState.js +1 -1
  132. package/dist/esm/DurableEngineState.js.map +1 -1
  133. package/dist/esm/ExecutionSnapshot.d.ts +2 -2
  134. package/dist/esm/ExecutionSnapshot.d.ts.map +1 -1
  135. package/dist/esm/ExecutionSnapshot.js +1 -1
  136. package/dist/esm/ExecutionSnapshot.js.map +1 -1
  137. package/dist/esm/Migrations.d.ts +2 -2
  138. package/dist/esm/Migrations.d.ts.map +1 -1
  139. package/dist/esm/OwnerIdentity.js +1 -1
  140. package/dist/esm/OwnerIdentity.js.map +1 -1
  141. package/dist/esm/PlanInputStore.d.ts +1 -1
  142. package/dist/esm/PlanInputStore.d.ts.map +1 -1
  143. package/dist/esm/PlanInputStore.js +1 -1
  144. package/dist/esm/PlanInputStore.js.map +1 -1
  145. package/dist/esm/PlanMergeStore.d.ts +1 -1
  146. package/dist/esm/PlanMergeStore.d.ts.map +1 -1
  147. package/dist/esm/PlanMergeStore.js +1 -1
  148. package/dist/esm/PlanMergeStore.js.map +1 -1
  149. package/dist/esm/Retention.d.ts +2 -2
  150. package/dist/esm/Retention.d.ts.map +1 -1
  151. package/dist/esm/Retention.js +1 -1
  152. package/dist/esm/Retention.js.map +1 -1
  153. package/dist/esm/RunChangeFeed.d.ts +1 -1
  154. package/dist/esm/RunChangeFeed.d.ts.map +1 -1
  155. package/dist/esm/RunChangeFeed.js +1 -1
  156. package/dist/esm/RunChangeFeed.js.map +1 -1
  157. package/dist/esm/SelectionStore.d.ts +1 -1
  158. package/dist/esm/SelectionStore.d.ts.map +1 -1
  159. package/dist/esm/SelectionStore.js +1 -1
  160. package/dist/esm/SelectionStore.js.map +1 -1
  161. package/dist/esm/StepBoundary.d.ts +8 -6
  162. package/dist/esm/StepBoundary.d.ts.map +1 -1
  163. package/dist/esm/StepBoundary.js +20 -11
  164. package/dist/esm/StepBoundary.js.map +1 -1
  165. package/dist/esm/StepCacheFold.d.ts +2 -2
  166. package/dist/esm/StepCacheFold.d.ts.map +1 -1
  167. package/dist/esm/StepCacheFold.js +1 -1
  168. package/dist/esm/StepCacheFold.js.map +1 -1
  169. package/dist/esm/internal/EngineStateSchema.d.ts +1 -1
  170. package/dist/esm/internal/EngineStateSchema.d.ts.map +1 -1
  171. package/dist/esm/internal/EngineStateSchema.js.map +1 -1
  172. package/dist/esm/internal/ExecutionSnapshotRead.d.ts +3 -3
  173. package/dist/esm/internal/ExecutionSnapshotRead.d.ts.map +1 -1
  174. package/dist/esm/internal/ExecutionSnapshotRead.js.map +1 -1
  175. package/dist/esm/internal/ExecutionSnapshotRelations.d.ts +1 -1
  176. package/dist/esm/internal/ExecutionSnapshotRelations.d.ts.map +1 -1
  177. package/dist/esm/internal/ExecutionSnapshotRelations.js.map +1 -1
  178. package/dist/esm/internal/RetentionOps.d.ts +2 -2
  179. package/dist/esm/internal/RetentionOps.d.ts.map +1 -1
  180. package/dist/esm/internal/RetentionOps.js +1 -1
  181. package/dist/esm/internal/RetentionOps.js.map +1 -1
  182. package/dist/esm/internal/RunCatalogOps.d.ts +1 -1
  183. package/dist/esm/internal/RunCatalogOps.d.ts.map +1 -1
  184. package/dist/esm/internal/RunCatalogOps.js +1 -1
  185. package/dist/esm/internal/RunCatalogOps.js.map +1 -1
  186. package/dist/esm/internal/RunListing.d.ts +1 -1
  187. package/dist/esm/internal/RunListing.d.ts.map +1 -1
  188. package/dist/esm/internal/RunListing.js +1 -1
  189. package/dist/esm/internal/RunListing.js.map +1 -1
  190. package/dist/esm/migrations/0001_initial.d.ts +1 -1
  191. package/dist/esm/migrations/0001_initial.d.ts.map +1 -1
  192. package/dist/esm/migrations/0001_initial.js +1 -1
  193. package/dist/esm/migrations/0001_initial.js.map +1 -1
  194. package/dist/esm/migrations/0002_selection_store.d.ts +1 -1
  195. package/dist/esm/migrations/0002_selection_store.d.ts.map +1 -1
  196. package/dist/esm/migrations/0002_selection_store.js +1 -1
  197. package/dist/esm/migrations/0002_selection_store.js.map +1 -1
  198. package/dist/esm/migrations/0003_plan_inputs.d.ts +1 -1
  199. package/dist/esm/migrations/0003_plan_inputs.d.ts.map +1 -1
  200. package/dist/esm/migrations/0003_plan_inputs.js +1 -1
  201. package/dist/esm/migrations/0003_plan_inputs.js.map +1 -1
  202. package/dist/esm/migrations/0004_plan_environment.d.ts +1 -1
  203. package/dist/esm/migrations/0004_plan_environment.d.ts.map +1 -1
  204. package/dist/esm/migrations/0004_plan_environment.js +1 -1
  205. package/dist/esm/migrations/0004_plan_environment.js.map +1 -1
  206. package/dist/esm/migrations/0005_plan_merges.d.ts +1 -1
  207. package/dist/esm/migrations/0005_plan_merges.d.ts.map +1 -1
  208. package/dist/esm/migrations/0005_plan_merges.js +1 -1
  209. package/dist/esm/migrations/0005_plan_merges.js.map +1 -1
  210. package/dist/esm/migrations/0006_execution_listing.d.ts +1 -1
  211. package/dist/esm/migrations/0006_execution_listing.d.ts.map +1 -1
  212. package/dist/esm/migrations/0006_execution_listing.js +1 -1
  213. package/dist/esm/migrations/0006_execution_listing.js.map +1 -1
  214. package/dist/esm/migrations/0007_run_parent_sequence.d.ts +1 -1
  215. package/dist/esm/migrations/0007_run_parent_sequence.d.ts.map +1 -1
  216. package/dist/esm/migrations/0007_run_parent_sequence.js +1 -1
  217. package/dist/esm/migrations/0007_run_parent_sequence.js.map +1 -1
  218. package/dist/esm/migrations/0008_deferred_consumption.d.ts +1 -1
  219. package/dist/esm/migrations/0008_deferred_consumption.d.ts.map +1 -1
  220. package/dist/esm/migrations/0008_deferred_consumption.js +1 -1
  221. package/dist/esm/migrations/0008_deferred_consumption.js.map +1 -1
  222. package/dist/esm/migrations/0009_deferred_clock_facts.d.ts +1 -1
  223. package/dist/esm/migrations/0009_deferred_clock_facts.d.ts.map +1 -1
  224. package/dist/esm/migrations/0009_deferred_clock_facts.js +1 -1
  225. package/dist/esm/migrations/0009_deferred_clock_facts.js.map +1 -1
  226. package/dist/esm/migrations/0010_pending_cancellation.d.ts +1 -1
  227. package/dist/esm/migrations/0010_pending_cancellation.d.ts.map +1 -1
  228. package/dist/esm/migrations/0010_pending_cancellation.js +1 -1
  229. package/dist/esm/migrations/0010_pending_cancellation.js.map +1 -1
  230. package/dist/esm/test/TestStores.d.ts +4 -4
  231. package/dist/esm/test/TestStores.d.ts.map +1 -1
  232. package/docs/api.md +19 -16
  233. package/package.json +22 -22
  234. package/src/ArtifactGc.ts +1 -1
  235. package/src/DeferredClockFold.ts +1 -1
  236. package/src/DisasterRecovery.ts +1 -1
  237. package/src/DurableEngineState.ts +1 -1
  238. package/src/ExecutionSnapshot.ts +1 -1
  239. package/src/OwnerIdentity.ts +1 -1
  240. package/src/PlanInputStore.ts +1 -1
  241. package/src/PlanMergeStore.ts +1 -1
  242. package/src/Retention.ts +2 -2
  243. package/src/RunChangeFeed.ts +1 -1
  244. package/src/SelectionStore.ts +1 -1
  245. package/src/StepBoundary.ts +32 -17
  246. package/src/StepCacheFold.ts +1 -1
  247. package/src/internal/EngineStateSchema.ts +1 -1
  248. package/src/internal/ExecutionSnapshotRead.ts +1 -1
  249. package/src/internal/ExecutionSnapshotRelations.ts +1 -1
  250. package/src/internal/RetentionOps.ts +2 -2
  251. package/src/internal/RunCatalogOps.ts +1 -1
  252. package/src/internal/RunListing.ts +1 -1
  253. package/src/migrations/0001_initial.ts +1 -1
  254. package/src/migrations/0002_selection_store.ts +1 -1
  255. package/src/migrations/0003_plan_inputs.ts +1 -1
  256. package/src/migrations/0004_plan_environment.ts +1 -1
  257. package/src/migrations/0005_plan_merges.ts +1 -1
  258. package/src/migrations/0006_execution_listing.ts +1 -1
  259. package/src/migrations/0007_run_parent_sequence.ts +1 -1
  260. package/src/migrations/0008_deferred_consumption.ts +1 -1
  261. package/src/migrations/0009_deferred_clock_facts.ts +1 -1
  262. package/src/migrations/0010_pending_cancellation.ts +1 -1
package/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Release candidate scope, host requirements and compatibility review are defined in the [library support policy](https://github.com/smithersai/smithers/blob/main/RELEASE_SUPPORT.md).
4
4
 
5
- This package declares `effect` as an exact
6
- `4.0.0-rc.115` peer dependency. Keep the application on that version so
7
- all Smithers packages share one Effect runtime.
5
+ This package declares `effect` as a `^4.0.4` peer dependency. Install one
6
+ `effect` release in that range so all Smithers packages share one Effect
7
+ runtime.
8
8
 
9
- **Documentation:** https://engine-store.smithers.sh
9
+ **Documentation:** https://github.com/smithersai/smithers/tree/main/packages/smithers/flows/engine-store/docs
10
10
 
11
11
  The durable half of the Smithers flow engine. It persists every step a flow
12
12
  takes to a SQLite database, so a flow that crashes, is killed, or waits for a
@@ -67,11 +67,11 @@ than at run time. Run the schema migrations before any SQL-backed service reads
67
67
  the database, and provide `OwnerIdentity.layer` unless the host mints its own
68
68
  owner tokens.
69
69
 
70
- [The quickstart](https://engine-store.smithers.sh/quickstart/) wires all of it
70
+ [The quickstart](https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/engine-store/docs/quickstart.md) wires all of it
71
71
  over one SQLite file and watches a sealed step replay after a restart.
72
72
 
73
73
  If you want the wiring rather than control over it, reach for
74
- [`@smthrs/flows`](https://flows.smithers.sh) instead. It ships `NodeRuntime`,
74
+ [`@smthrs/flows`](https://github.com/smithersai/smithers/tree/main/packages/smithers/flows/docs) instead. It ships `NodeRuntime`,
75
75
  which composes this package with the flow language, the journal, the run and
76
76
  cache stores, and the artifact tier over one file.
77
77
 
@@ -124,24 +124,24 @@ runtime.
124
124
 
125
125
  ## Documentation
126
126
 
127
- The full documentation is at <https://engine-store.smithers.sh>:
127
+ The full documentation is at <https://github.com/smithersai/smithers/tree/main/packages/smithers/flows/engine-store/docs>:
128
128
 
129
- - [Installation](https://engine-store.smithers.sh/installation/): runtime
129
+ - [Installation](https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/engine-store/docs/installation.md): runtime
130
130
  requirements, import forms, and the storage packages a runnable composition
131
131
  adds.
132
- - [Quickstart](https://engine-store.smithers.sh/quickstart/): compose a durable
132
+ - [Quickstart](https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/engine-store/docs/quickstart.md): compose a durable
133
133
  engine over SQLite and watch a step replay after a restart.
134
- - [Compose a durable engine](https://engine-store.smithers.sh/guides/compose-a-durable-engine/):
134
+ - [Compose a durable engine](https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/engine-store/docs/guides/compose-a-durable-engine.md):
135
135
  the required and optional services, and what each one changes.
136
- - [API reference](https://engine-store.smithers.sh/reference/api/): every public
136
+ - [API reference](https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/engine-store/docs/api.md): every public
137
137
  export, with signatures and error codes.
138
- - [Observe executions and page runs](https://engine-store.smithers.sh/guides/observe-executions/):
138
+ - [Observe executions and page runs](https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/engine-store/docs/guides/observe-executions.md):
139
139
  coherent snapshots, filtered keyset pages, durable children and revisioned catch-up.
140
- - [Troubleshooting](https://engine-store.smithers.sh/troubleshooting/): each
140
+ - [Troubleshooting](https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/engine-store/docs/troubleshooting.md): each
141
141
  typed failure, its cause, and its fix.
142
142
 
143
- See also [durable execution](https://smithers.sh/docs/concepts/durable-execution/)
144
- and [content addressing](https://smithers.sh/docs/concepts/content-addressing/)
143
+ See also [durable execution](https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/engine/docs/README.md)
144
+ and [content addressing](https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/plan/docs/concepts/step-keys.md)
145
145
  on smithers.sh.
146
146
 
147
147
  List reads of durable wait state skip corrupt rows and log storage-integrity warnings; point reads still fail for an invalid row.
@@ -43,7 +43,7 @@ import * as Effect from "effect/Effect";
43
43
  import type * as FileSystem from "effect/FileSystem";
44
44
  import * as Layer from "effect/Layer";
45
45
  import * as Schema from "effect/Schema";
46
- import * as SqlClient from "effect/unstable/sql/SqlClient";
46
+ import * as SqlClient from "effect/sql/SqlClient";
47
47
  /**
48
48
  * Stable error codes returned by artifact garbage collection.
49
49
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ArtifactGc.d.ts","sourceRoot":"","sources":["../../src/ArtifactGc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,KAAK,aAAa,MAAM,iCAAiC,CAAA;AAEhE,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,UAAU,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAA;AAG1D;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,8EAAsE,CAAA;AAEtG;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAC,IAAI,CAAA;;;;;;AAEjE;;;;;;;;GAQG;AACH,qBAAa,eAAgB,SAAQ,oBAOpC;CAAG;AAEJ;;;;;;GAMG;AACH,MAAM,WAAW,MAAM;IACrB,gEAAgE;IAChE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACrC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAA;CACjE;;AAED;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,qBAErC;CAAG;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,KAAG,KAAK,CAAC,KAAK,CAAC,gBAAgB,C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;CAAG;AAE5G;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,QAA2B,CAAA;AAEtD;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,iDAAiD;IACjD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACvC;AA4BD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,IAAI,GACf,UAAS,WAAgB,KACxB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,SAAS,GAAG,aAAa,CAAC,aAAa,CAyH9E,CAAA;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,GAChB,UAAS,WAAgB,KACxB,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,SAAS,GAAG,aAAa,CAAC,aAAa,CAC1C,CAAA;AAEzC;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAS,WAAW,GAAG,aAAa,CAAC,YAAiB,KACrD,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,SAAS,GAAG,UAAU,CAAC,UAAU,CAG1E,CAAA"}
@@ -46,7 +46,7 @@ var Effect = __toESM(require("effect/Effect"), 1);
46
46
  var Layer = __toESM(require("effect/Layer"), 1);
47
47
  var Option = __toESM(require("effect/Option"), 1);
48
48
  var Schema = __toESM(require("effect/Schema"), 1);
49
- var SqlClient = __toESM(require("effect/unstable/sql/SqlClient"), 1);
49
+ var SqlClient = __toESM(require("effect/sql/SqlClient"), 1);
50
50
  var ArtifactRoots = __toESM(require("./internal/ArtifactRoots.js"), 1);
51
51
  const ArtifactGcErrorCode = Schema.Literals(["invalid_options", "mark_failed", "sweep_failed"]);
52
52
  class ArtifactGcError extends Schema.TaggedError()(
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/ArtifactGc.ts"],
4
- "sourcesContent": ["/**\n * Mark/sweep garbage collection for the content-addressed artifact store.\n *\n * The artifact tier is the one store in the composition with true *garbage*:\n * every output over the inline bound is spilled to `.flows/objects` by digest\n * (`StepBoundary`), nothing ever deletes a published blob, and a blob whose\n * every referencing row is gone is unreachable forever. The step cache is\n * deliberately NOT collected here \u2014 its rows are the *roots* of this graph,\n * they never become unreachable, and removing one is the policy decision\n * `CacheStore.evict` already serves.\n *\n * The design combines the two prior arts on the shelf:\n *\n * - **Reachability from durable roots** \u2014 git's `git gc` marks from refs;\n * Skyframe deletes what a keyed graph walk cannot reach. Here the roots are\n * every attempt row of every existing (never-deleted) run and every step\n * cache entry; each carries boundary evidence, and\n * `StepBoundary.referencedDigests` names the blobs that evidence needs.\n * Attempt checkpoints are roots too: they are opaque executable state, so\n * the mark keeps digest-shaped strings found in their JSON.\n * - **A grace period over mtime** \u2014 git refuses to prune unreachable objects\n * younger than `gc.pruneExpire` (two weeks), jj keeps operations newer than\n * its keep bound, and Bazel's disk-cache collector\n * (`reference/bazel/.../remote/disk/DiskCacheGarbageCollector.java`) fences\n * on mtime. The cutoff is the collection start time minus the grace period,\n * sampled before resolving policy pins or scanning roots and held fixed\n * through inventory and deletion. Only mtimes strictly before it are\n * eligible: a blob published \u2014 or freshened by a dedupe `put` \u2014 at or after\n * collection start survives, including same-millisecond writes at zero\n * grace, no lock required.\n *\n * Collection NEVER runs automatically. `gc()` is an explicit verb because\n * deletion is irreversible, and a human approving a plan must approve the\n * deletions too. The opt-in {@link ArtifactGcPolicy} layer\n * configures *how* an invocation collects (grace bound, pinned digests); it\n * does not schedule anything.\n *\n * @since 0.1.0\n */\n\nimport * as ArtifactSweep from \"@smthrs/artifacts/ArtifactSweep\"\nimport * as Clock from \"effect/Clock\"\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport type * as FileSystem from \"effect/FileSystem\"\nimport * as Layer from \"effect/Layer\"\nimport * as Option from \"effect/Option\"\nimport * as Schema from \"effect/Schema\"\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\"\nimport * as ArtifactRoots from \"./internal/ArtifactRoots.ts\"\n\n/**\n * Stable error codes returned by artifact garbage collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport const ArtifactGcErrorCode = Schema.Literals([\"invalid_options\", \"mark_failed\", \"sweep_failed\"])\n\n/**\n * Stable error codes returned by artifact garbage collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport type ArtifactGcErrorCode = typeof ArtifactGcErrorCode.Type\n\n/**\n * A collection that could not complete. `mark_failed` means the live set\n * could not be computed \u2014 nothing was deleted. `sweep_failed` means the live\n * set held but a deletion refused; everything already swept was garbage, so a\n * re-run converges from wherever the failure stopped it.\n *\n * @category errors\n * @since 0.1.0\n */\nexport class ArtifactGcError extends Schema.TaggedError<ArtifactGcError>()(\n \"@smthrs/engine-store/ArtifactGcError\",\n {\n code: ArtifactGcErrorCode,\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown)\n }\n) {}\n\n/**\n * The opt-in collection policy. Explicit {@link GcOptions} on a `gc()` call\n * override the installed policy; the policy overrides the defaults.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Policy {\n /** Grace bound applied when a `gc()` call does not name one. */\n readonly graceMs?: number | undefined\n /**\n * Digests held live regardless of reachability \u2014 the seam for references\n * this composition's tables cannot see (an external index, an export a\n * human wants kept). Resolved fresh on every collection.\n */\n readonly pins?: Effect.Effect<ReadonlyArray<string>> | undefined\n}\n\n/**\n * Service tag for the opt-in collection policy.\n *\n * @category services\n * @since 0.1.0\n */\nexport class ArtifactGcPolicy extends Context.Service<ArtifactGcPolicy, Policy>()(\n \"@smthrs/engine-store/ArtifactGcPolicy\"\n) {}\n\n/**\n * Installs a collection policy.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerPolicy = (policy: Policy): Layer.Layer<ArtifactGcPolicy> => Layer.succeed(ArtifactGcPolicy)(policy)\n\n/**\n * Options for one explicit collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface GcOptions {\n /**\n * How recently a blob must have been written or freshened to survive\n * unreferenced. Defaults to the installed {@link ArtifactGcPolicy}'s bound,\n * then to {@link defaultGraceMs}.\n */\n readonly graceMs?: number | undefined\n /** Digests held live for this collection, unioned with the policy's pins. */\n readonly pins?: ReadonlyArray<string> | undefined\n /** Compute and report without deleting anything. */\n readonly dryRun?: boolean | undefined\n}\n\n/**\n * What one collection did.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface GcReport {\n /** Blobs the inventory enumerated. */\n readonly scannedBlobs: number\n /** Distinct digests the mark phase proved live, pins included. */\n readonly liveDigests: number\n /** Digests deleted \u2014 or, under `dryRun`, the ones a real run would delete. */\n readonly sweptDigests: ReadonlyArray<string>\n /** Bytes the swept blobs held. */\n readonly reclaimedBytes: number\n /** Unreferenced blobs retained by the grace bound or a freshen race. */\n readonly keptByGrace: number\n readonly dryRun: boolean\n}\n\n/**\n * Explicit artifact garbage collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Service {\n /**\n * Marks the live set from the durable roots, then sweeps every blob that\n * is both outside it and older than the grace bound. Explicit only \u2014\n * nothing in the engine composition ever calls this.\n */\n readonly gc: (options?: GcOptions) => Effect.Effect<GcReport, ArtifactGcError>\n}\n\n/**\n * Service tag for artifact garbage collection.\n *\n * @category services\n * @since 0.1.0\n */\nexport class ArtifactGc extends Context.Service<ArtifactGc, Service>()(\"@smthrs/engine-store/ArtifactGc\") {}\n\n/**\n * Two weeks, git's `gc.pruneExpire` default. The bound is deliberately far\n * beyond any live attempt's duration: a blob spilled by a running step is\n * unreferenced until its attempt row finishes, and the grace period is the\n * only thing protecting it in that window.\n *\n * @category constants\n * @since 0.1.0\n */\nexport const defaultGraceMs = 14 * 24 * 60 * 60 * 1000\n\n/**\n * Construction options.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface MakeOptions {\n /** Rows per mark-phase page. Defaults to 500. */\n readonly pageSize?: number | undefined\n}\n\nconst markFailed = (message: string, cause: unknown): ArtifactGcError =>\n new ArtifactGcError({ code: \"mark_failed\", message, cause })\n\nconst sweepFailed = (message: string, cause: unknown): ArtifactGcError =>\n new ArtifactGcError({ code: \"sweep_failed\", message, cause })\n\nconst invalidOptions = (message: string): ArtifactGcError => new ArtifactGcError({ code: \"invalid_options\", message })\n\n/**\n * Extracts the digests one root row keeps live, FAIL-SAFE: a row whose\n * metadata carries a `boundary` this build cannot decode aborts the\n * collection rather than contributing nothing. Silently reading such a row as\n * \"references no artifacts\" is exactly how a live blob gets collected; a\n * metadata shape with no `boundary` key at all is the ordinary\n * foreign-evidence case `referencedDigests` already defines as empty.\n */\nconst rootDigests = (table: string, metaJson: string): Effect.Effect<ReadonlyArray<string>, ArtifactGcError> =>\n ArtifactRoots.rootDigests(table, metaJson).pipe(\n Effect.mapError((cause) => markFailed(cause.message, cause.cause))\n )\n\nconst checkpointDigests = (checkpointJson: string | null): Effect.Effect<ReadonlyArray<string>, ArtifactGcError> =>\n ArtifactRoots.checkpointDigests(checkpointJson).pipe(\n Effect.mapError((cause) => markFailed(cause.message, cause.cause))\n )\n\n/**\n * Builds the collector over the composition's own durable tables and the\n * host-local sweep surface.\n *\n * The mark phase reads `flows_step_cache` and `flows_attempts` directly, the\n * same way `DurableEngineState` range-scans `flows_runs`: this package\n * composes every one of those migrations, so the schema is its own. Every run\n * present in `flows_runs` is a live root \u2014 there is no deleted state, and the\n * attempt table's foreign key guarantees each attempt's run exists \u2014 so the\n * scan is simply *all* attempt rows plus *all* cache entries, paged by\n * primary key so no page holds more than `pageSize` rows in memory.\n *\n * Ordering is the safety argument. The live set is computed BEFORE the\n * inventory, so a root recorded during the sweep can only be missed, never\n * half-seen \u2014 and the blob such a root references is protected anyway: a\n * fresh publication carries a fresh mtime, a re-publication of existing bytes\n * freshens the blob's mtime (`ArtifactStore.put`), and the sweep's deletion\n * is fenced on that mtime (`ArtifactSweep.remove`'s `ifUnmodifiedSinceMs`).\n * A crash mid-sweep deletes some garbage and no live blobs; re-running\n * converges.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = (\n options: MakeOptions = {}\n): Effect.Effect<Service, never, SqlClient.SqlClient | ArtifactSweep.ArtifactSweep> =>\n Effect.gen(function*() {\n const sql = yield* Effect.service(SqlClient.SqlClient)\n const sweeper = yield* ArtifactSweep.ArtifactSweep\n const policy = yield* Effect.serviceOption(ArtifactGcPolicy)\n const pageSize = options.pageSize ?? 500\n\n const markCacheEntries = (live: Set<string>) =>\n Effect.gen(function*() {\n let after = \"\"\n for (;;) {\n const rows = yield* sql<{ readonly key_digest: string; readonly meta_json: string }>`\n SELECT key_digest, meta_json FROM flows_step_cache\n WHERE key_digest > ${after}\n ORDER BY key_digest\n LIMIT ${pageSize}\n `.pipe(Effect.mapError((cause) => markFailed(\"the step cache could not be scanned\", cause)))\n for (const row of rows) {\n for (const digest of yield* rootDigests(\"flows_step_cache\", row.meta_json)) {\n live.add(digest)\n }\n }\n if (rows.length < pageSize) return\n after = rows[rows.length - 1]!.key_digest\n }\n })\n\n const markAttempts = (live: Set<string>) =>\n Effect.gen(function*() {\n let after = { runId: \"\", stepKeyDigest: \"\", attempt: -1 }\n for (;;) {\n const rows = yield* sql<{\n readonly run_id: string\n readonly step_key_digest: string\n readonly attempt: number\n readonly checkpoint_json: string | null\n readonly meta_json: string\n }>`\n SELECT run_id, step_key_digest, attempt, checkpoint_json, meta_json FROM flows_attempts\n WHERE (run_id, step_key_digest, attempt) > (${after.runId}, ${after.stepKeyDigest}, ${after.attempt})\n ORDER BY run_id, step_key_digest, attempt\n LIMIT ${pageSize}\n `.pipe(Effect.mapError((cause) => markFailed(\"the attempt table could not be scanned\", cause)))\n for (const row of rows) {\n for (const digest of yield* rootDigests(\"flows_attempts\", row.meta_json)) {\n live.add(digest)\n }\n for (const digest of yield* checkpointDigests(row.checkpoint_json)) {\n live.add(digest)\n }\n }\n if (rows.length < pageSize) return\n const last = rows[rows.length - 1]!\n after = { runId: last.run_id, stepKeyDigest: last.step_key_digest, attempt: last.attempt }\n }\n })\n\n const gc: Service[\"gc\"] = Effect.fn(\"ArtifactGc.gc\")((gcOptions) =>\n Effect.gen(function*() {\n if (!Number.isSafeInteger(pageSize) || pageSize < 1) {\n return yield* Effect.fail(invalidOptions(\"artifact GC pageSize must be a positive safe integer\"))\n }\n const grace = gcOptions?.graceMs ??\n (Option.isSome(policy) ? policy.value.graceMs : undefined) ??\n defaultGraceMs\n if (!Number.isSafeInteger(grace) || grace < 0) {\n return yield* Effect.fail(invalidOptions(\"artifact GC graceMs must be a non-negative safe integer\"))\n }\n const startedAtMs = yield* Clock.currentTimeMillis.pipe(Effect.map(Math.floor))\n const bound = startedAtMs - grace\n const live = new Set<string>(gcOptions?.pins ?? [])\n if (Option.isSome(policy) && policy.value.pins !== undefined) {\n for (const digest of yield* policy.value.pins) live.add(digest)\n }\n yield* markCacheEntries(live)\n yield* markAttempts(live)\n const blobs = yield* sweeper.inventory.pipe(\n Effect.mapError((cause) => sweepFailed(`the blob inventory refused: ${cause.message}`, cause))\n )\n const swept: Array<string> = []\n let reclaimedBytes = 0\n let keptByGrace = 0\n for (const blob of blobs) {\n if (live.has(blob.digest)) continue\n if (blob.modifiedAtMs >= bound) {\n keptByGrace++\n continue\n }\n if (gcOptions?.dryRun === true) {\n swept.push(blob.digest)\n reclaimedBytes += blob.sizeBytes\n continue\n }\n // The fence re-reads the blob's age inside the deletion: an\n // unreferenced-at-mark blob a concurrent `put` freshened since the\n // inventory fails the fence and is retained, exactly as a fresher\n // cache row survives a laggard's fenced evict (issue #119).\n // remove's fence is inclusive; mtimes have millisecond resolution,\n // so exclude cutoff equality there just as in the inventory check.\n const removed = yield* sweeper.remove(blob.digest, { ifUnmodifiedSinceMs: bound - 1 }).pipe(\n Effect.mapError((cause) => sweepFailed(`sweeping ${blob.digest} refused: ${cause.message}`, cause))\n )\n if (removed) {\n swept.push(blob.digest)\n reclaimedBytes += blob.sizeBytes\n } else {\n keptByGrace++\n }\n }\n return {\n scannedBlobs: blobs.length,\n liveDigests: live.size,\n sweptDigests: swept,\n reclaimedBytes,\n keptByGrace,\n dryRun: gcOptions?.dryRun === true\n }\n })\n )\n\n return { gc }\n })\n\n/**\n * Provides the artifact garbage collector. Install {@link layerPolicy} into\n * this layer's inputs to configure collection; nothing schedules `gc()` \u2014\n * invoking it stays an explicit caller decision.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer = (\n options: MakeOptions = {}\n): Layer.Layer<ArtifactGc, never, SqlClient.SqlClient | ArtifactSweep.ArtifactSweep> =>\n Layer.effect(ArtifactGc)(make(options))\n\n/**\n * Provides the artifact garbage collector over a filesystem objects directory:\n * {@link layer} with `ArtifactSweep.layerFileSystem` beneath it. Pass the same\n * `directory` and `coordination` the paired `ArtifactStore.layerFileSystem`\n * publishes with.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layerFileSystem = (\n options: MakeOptions & ArtifactSweep.SweepOptions = {}\n): Layer.Layer<ArtifactGc, never, SqlClient.SqlClient | FileSystem.FileSystem> =>\n layer(options).pipe(\n Layer.provide(ArtifactSweep.layerFileSystem({ directory: options.directory, coordination: options.coordination }))\n )\n"],
4
+ "sourcesContent": ["/**\n * Mark/sweep garbage collection for the content-addressed artifact store.\n *\n * The artifact tier is the one store in the composition with true *garbage*:\n * every output over the inline bound is spilled to `.flows/objects` by digest\n * (`StepBoundary`), nothing ever deletes a published blob, and a blob whose\n * every referencing row is gone is unreachable forever. The step cache is\n * deliberately NOT collected here \u2014 its rows are the *roots* of this graph,\n * they never become unreachable, and removing one is the policy decision\n * `CacheStore.evict` already serves.\n *\n * The design combines the two prior arts on the shelf:\n *\n * - **Reachability from durable roots** \u2014 git's `git gc` marks from refs;\n * Skyframe deletes what a keyed graph walk cannot reach. Here the roots are\n * every attempt row of every existing (never-deleted) run and every step\n * cache entry; each carries boundary evidence, and\n * `StepBoundary.referencedDigests` names the blobs that evidence needs.\n * Attempt checkpoints are roots too: they are opaque executable state, so\n * the mark keeps digest-shaped strings found in their JSON.\n * - **A grace period over mtime** \u2014 git refuses to prune unreachable objects\n * younger than `gc.pruneExpire` (two weeks), jj keeps operations newer than\n * its keep bound, and Bazel's disk-cache collector\n * (`reference/bazel/.../remote/disk/DiskCacheGarbageCollector.java`) fences\n * on mtime. The cutoff is the collection start time minus the grace period,\n * sampled before resolving policy pins or scanning roots and held fixed\n * through inventory and deletion. Only mtimes strictly before it are\n * eligible: a blob published \u2014 or freshened by a dedupe `put` \u2014 at or after\n * collection start survives, including same-millisecond writes at zero\n * grace, no lock required.\n *\n * Collection NEVER runs automatically. `gc()` is an explicit verb because\n * deletion is irreversible, and a human approving a plan must approve the\n * deletions too. The opt-in {@link ArtifactGcPolicy} layer\n * configures *how* an invocation collects (grace bound, pinned digests); it\n * does not schedule anything.\n *\n * @since 0.1.0\n */\n\nimport * as ArtifactSweep from \"@smthrs/artifacts/ArtifactSweep\"\nimport * as Clock from \"effect/Clock\"\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport type * as FileSystem from \"effect/FileSystem\"\nimport * as Layer from \"effect/Layer\"\nimport * as Option from \"effect/Option\"\nimport * as Schema from \"effect/Schema\"\nimport * as SqlClient from \"effect/sql/SqlClient\"\nimport * as ArtifactRoots from \"./internal/ArtifactRoots.ts\"\n\n/**\n * Stable error codes returned by artifact garbage collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport const ArtifactGcErrorCode = Schema.Literals([\"invalid_options\", \"mark_failed\", \"sweep_failed\"])\n\n/**\n * Stable error codes returned by artifact garbage collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport type ArtifactGcErrorCode = typeof ArtifactGcErrorCode.Type\n\n/**\n * A collection that could not complete. `mark_failed` means the live set\n * could not be computed \u2014 nothing was deleted. `sweep_failed` means the live\n * set held but a deletion refused; everything already swept was garbage, so a\n * re-run converges from wherever the failure stopped it.\n *\n * @category errors\n * @since 0.1.0\n */\nexport class ArtifactGcError extends Schema.TaggedError<ArtifactGcError>()(\n \"@smthrs/engine-store/ArtifactGcError\",\n {\n code: ArtifactGcErrorCode,\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown)\n }\n) {}\n\n/**\n * The opt-in collection policy. Explicit {@link GcOptions} on a `gc()` call\n * override the installed policy; the policy overrides the defaults.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Policy {\n /** Grace bound applied when a `gc()` call does not name one. */\n readonly graceMs?: number | undefined\n /**\n * Digests held live regardless of reachability \u2014 the seam for references\n * this composition's tables cannot see (an external index, an export a\n * human wants kept). Resolved fresh on every collection.\n */\n readonly pins?: Effect.Effect<ReadonlyArray<string>> | undefined\n}\n\n/**\n * Service tag for the opt-in collection policy.\n *\n * @category services\n * @since 0.1.0\n */\nexport class ArtifactGcPolicy extends Context.Service<ArtifactGcPolicy, Policy>()(\n \"@smthrs/engine-store/ArtifactGcPolicy\"\n) {}\n\n/**\n * Installs a collection policy.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerPolicy = (policy: Policy): Layer.Layer<ArtifactGcPolicy> => Layer.succeed(ArtifactGcPolicy)(policy)\n\n/**\n * Options for one explicit collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface GcOptions {\n /**\n * How recently a blob must have been written or freshened to survive\n * unreferenced. Defaults to the installed {@link ArtifactGcPolicy}'s bound,\n * then to {@link defaultGraceMs}.\n */\n readonly graceMs?: number | undefined\n /** Digests held live for this collection, unioned with the policy's pins. */\n readonly pins?: ReadonlyArray<string> | undefined\n /** Compute and report without deleting anything. */\n readonly dryRun?: boolean | undefined\n}\n\n/**\n * What one collection did.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface GcReport {\n /** Blobs the inventory enumerated. */\n readonly scannedBlobs: number\n /** Distinct digests the mark phase proved live, pins included. */\n readonly liveDigests: number\n /** Digests deleted \u2014 or, under `dryRun`, the ones a real run would delete. */\n readonly sweptDigests: ReadonlyArray<string>\n /** Bytes the swept blobs held. */\n readonly reclaimedBytes: number\n /** Unreferenced blobs retained by the grace bound or a freshen race. */\n readonly keptByGrace: number\n readonly dryRun: boolean\n}\n\n/**\n * Explicit artifact garbage collection.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Service {\n /**\n * Marks the live set from the durable roots, then sweeps every blob that\n * is both outside it and older than the grace bound. Explicit only \u2014\n * nothing in the engine composition ever calls this.\n */\n readonly gc: (options?: GcOptions) => Effect.Effect<GcReport, ArtifactGcError>\n}\n\n/**\n * Service tag for artifact garbage collection.\n *\n * @category services\n * @since 0.1.0\n */\nexport class ArtifactGc extends Context.Service<ArtifactGc, Service>()(\"@smthrs/engine-store/ArtifactGc\") {}\n\n/**\n * Two weeks, git's `gc.pruneExpire` default. The bound is deliberately far\n * beyond any live attempt's duration: a blob spilled by a running step is\n * unreferenced until its attempt row finishes, and the grace period is the\n * only thing protecting it in that window.\n *\n * @category constants\n * @since 0.1.0\n */\nexport const defaultGraceMs = 14 * 24 * 60 * 60 * 1000\n\n/**\n * Construction options.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface MakeOptions {\n /** Rows per mark-phase page. Defaults to 500. */\n readonly pageSize?: number | undefined\n}\n\nconst markFailed = (message: string, cause: unknown): ArtifactGcError =>\n new ArtifactGcError({ code: \"mark_failed\", message, cause })\n\nconst sweepFailed = (message: string, cause: unknown): ArtifactGcError =>\n new ArtifactGcError({ code: \"sweep_failed\", message, cause })\n\nconst invalidOptions = (message: string): ArtifactGcError => new ArtifactGcError({ code: \"invalid_options\", message })\n\n/**\n * Extracts the digests one root row keeps live, FAIL-SAFE: a row whose\n * metadata carries a `boundary` this build cannot decode aborts the\n * collection rather than contributing nothing. Silently reading such a row as\n * \"references no artifacts\" is exactly how a live blob gets collected; a\n * metadata shape with no `boundary` key at all is the ordinary\n * foreign-evidence case `referencedDigests` already defines as empty.\n */\nconst rootDigests = (table: string, metaJson: string): Effect.Effect<ReadonlyArray<string>, ArtifactGcError> =>\n ArtifactRoots.rootDigests(table, metaJson).pipe(\n Effect.mapError((cause) => markFailed(cause.message, cause.cause))\n )\n\nconst checkpointDigests = (checkpointJson: string | null): Effect.Effect<ReadonlyArray<string>, ArtifactGcError> =>\n ArtifactRoots.checkpointDigests(checkpointJson).pipe(\n Effect.mapError((cause) => markFailed(cause.message, cause.cause))\n )\n\n/**\n * Builds the collector over the composition's own durable tables and the\n * host-local sweep surface.\n *\n * The mark phase reads `flows_step_cache` and `flows_attempts` directly, the\n * same way `DurableEngineState` range-scans `flows_runs`: this package\n * composes every one of those migrations, so the schema is its own. Every run\n * present in `flows_runs` is a live root \u2014 there is no deleted state, and the\n * attempt table's foreign key guarantees each attempt's run exists \u2014 so the\n * scan is simply *all* attempt rows plus *all* cache entries, paged by\n * primary key so no page holds more than `pageSize` rows in memory.\n *\n * Ordering is the safety argument. The live set is computed BEFORE the\n * inventory, so a root recorded during the sweep can only be missed, never\n * half-seen \u2014 and the blob such a root references is protected anyway: a\n * fresh publication carries a fresh mtime, a re-publication of existing bytes\n * freshens the blob's mtime (`ArtifactStore.put`), and the sweep's deletion\n * is fenced on that mtime (`ArtifactSweep.remove`'s `ifUnmodifiedSinceMs`).\n * A crash mid-sweep deletes some garbage and no live blobs; re-running\n * converges.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = (\n options: MakeOptions = {}\n): Effect.Effect<Service, never, SqlClient.SqlClient | ArtifactSweep.ArtifactSweep> =>\n Effect.gen(function*() {\n const sql = yield* Effect.service(SqlClient.SqlClient)\n const sweeper = yield* ArtifactSweep.ArtifactSweep\n const policy = yield* Effect.serviceOption(ArtifactGcPolicy)\n const pageSize = options.pageSize ?? 500\n\n const markCacheEntries = (live: Set<string>) =>\n Effect.gen(function*() {\n let after = \"\"\n for (;;) {\n const rows = yield* sql<{ readonly key_digest: string; readonly meta_json: string }>`\n SELECT key_digest, meta_json FROM flows_step_cache\n WHERE key_digest > ${after}\n ORDER BY key_digest\n LIMIT ${pageSize}\n `.pipe(Effect.mapError((cause) => markFailed(\"the step cache could not be scanned\", cause)))\n for (const row of rows) {\n for (const digest of yield* rootDigests(\"flows_step_cache\", row.meta_json)) {\n live.add(digest)\n }\n }\n if (rows.length < pageSize) return\n after = rows[rows.length - 1]!.key_digest\n }\n })\n\n const markAttempts = (live: Set<string>) =>\n Effect.gen(function*() {\n let after = { runId: \"\", stepKeyDigest: \"\", attempt: -1 }\n for (;;) {\n const rows = yield* sql<{\n readonly run_id: string\n readonly step_key_digest: string\n readonly attempt: number\n readonly checkpoint_json: string | null\n readonly meta_json: string\n }>`\n SELECT run_id, step_key_digest, attempt, checkpoint_json, meta_json FROM flows_attempts\n WHERE (run_id, step_key_digest, attempt) > (${after.runId}, ${after.stepKeyDigest}, ${after.attempt})\n ORDER BY run_id, step_key_digest, attempt\n LIMIT ${pageSize}\n `.pipe(Effect.mapError((cause) => markFailed(\"the attempt table could not be scanned\", cause)))\n for (const row of rows) {\n for (const digest of yield* rootDigests(\"flows_attempts\", row.meta_json)) {\n live.add(digest)\n }\n for (const digest of yield* checkpointDigests(row.checkpoint_json)) {\n live.add(digest)\n }\n }\n if (rows.length < pageSize) return\n const last = rows[rows.length - 1]!\n after = { runId: last.run_id, stepKeyDigest: last.step_key_digest, attempt: last.attempt }\n }\n })\n\n const gc: Service[\"gc\"] = Effect.fn(\"ArtifactGc.gc\")((gcOptions) =>\n Effect.gen(function*() {\n if (!Number.isSafeInteger(pageSize) || pageSize < 1) {\n return yield* Effect.fail(invalidOptions(\"artifact GC pageSize must be a positive safe integer\"))\n }\n const grace = gcOptions?.graceMs ??\n (Option.isSome(policy) ? policy.value.graceMs : undefined) ??\n defaultGraceMs\n if (!Number.isSafeInteger(grace) || grace < 0) {\n return yield* Effect.fail(invalidOptions(\"artifact GC graceMs must be a non-negative safe integer\"))\n }\n const startedAtMs = yield* Clock.currentTimeMillis.pipe(Effect.map(Math.floor))\n const bound = startedAtMs - grace\n const live = new Set<string>(gcOptions?.pins ?? [])\n if (Option.isSome(policy) && policy.value.pins !== undefined) {\n for (const digest of yield* policy.value.pins) live.add(digest)\n }\n yield* markCacheEntries(live)\n yield* markAttempts(live)\n const blobs = yield* sweeper.inventory.pipe(\n Effect.mapError((cause) => sweepFailed(`the blob inventory refused: ${cause.message}`, cause))\n )\n const swept: Array<string> = []\n let reclaimedBytes = 0\n let keptByGrace = 0\n for (const blob of blobs) {\n if (live.has(blob.digest)) continue\n if (blob.modifiedAtMs >= bound) {\n keptByGrace++\n continue\n }\n if (gcOptions?.dryRun === true) {\n swept.push(blob.digest)\n reclaimedBytes += blob.sizeBytes\n continue\n }\n // The fence re-reads the blob's age inside the deletion: an\n // unreferenced-at-mark blob a concurrent `put` freshened since the\n // inventory fails the fence and is retained, exactly as a fresher\n // cache row survives a laggard's fenced evict (issue #119).\n // remove's fence is inclusive; mtimes have millisecond resolution,\n // so exclude cutoff equality there just as in the inventory check.\n const removed = yield* sweeper.remove(blob.digest, { ifUnmodifiedSinceMs: bound - 1 }).pipe(\n Effect.mapError((cause) => sweepFailed(`sweeping ${blob.digest} refused: ${cause.message}`, cause))\n )\n if (removed) {\n swept.push(blob.digest)\n reclaimedBytes += blob.sizeBytes\n } else {\n keptByGrace++\n }\n }\n return {\n scannedBlobs: blobs.length,\n liveDigests: live.size,\n sweptDigests: swept,\n reclaimedBytes,\n keptByGrace,\n dryRun: gcOptions?.dryRun === true\n }\n })\n )\n\n return { gc }\n })\n\n/**\n * Provides the artifact garbage collector. Install {@link layerPolicy} into\n * this layer's inputs to configure collection; nothing schedules `gc()` \u2014\n * invoking it stays an explicit caller decision.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer = (\n options: MakeOptions = {}\n): Layer.Layer<ArtifactGc, never, SqlClient.SqlClient | ArtifactSweep.ArtifactSweep> =>\n Layer.effect(ArtifactGc)(make(options))\n\n/**\n * Provides the artifact garbage collector over a filesystem objects directory:\n * {@link layer} with `ArtifactSweep.layerFileSystem` beneath it. Pass the same\n * `directory` and `coordination` the paired `ArtifactStore.layerFileSystem`\n * publishes with.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layerFileSystem = (\n options: MakeOptions & ArtifactSweep.SweepOptions = {}\n): Layer.Layer<ArtifactGc, never, SqlClient.SqlClient | FileSystem.FileSystem> =>\n layer(options).pipe(\n Layer.provide(ArtifactSweep.layerFileSystem({ directory: options.directory, coordination: options.coordination }))\n )\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwCA,oBAA+B;AAC/B,YAAuB;AACvB,cAAyB;AACzB,aAAwB;AAExB,YAAuB;AACvB,aAAwB;AACxB,aAAwB;AACxB,gBAA2B;AAC3B,oBAA+B;AAQxB,MAAM,sBAAsB,OAAO,SAAS,CAAC,mBAAmB,eAAe,cAAc,CAAC;AAmB9F,MAAM,wBAAwB,OAAO,YAA6B;AAAA,EACvE;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,SAAS,OAAO;AAAA,IAChB,OAAO,OAAO,SAAS,OAAO,OAAO;AAAA,EACvC;AACF,EAAE;AAAC;AA0BI,MAAM,yBAAyB,QAAQ,QAAkC;AAAA,EAC9E;AACF,EAAE;AAAC;AAQI,MAAM,cAAc,CAAC,WAAkD,MAAM,QAAQ,gBAAgB,EAAE,MAAM;AA8D7G,MAAM,mBAAmB,QAAQ,QAA6B,EAAE,iCAAiC,EAAE;AAAC;AAWpG,MAAM,iBAAiB,KAAK,KAAK,KAAK,KAAK;AAalD,MAAM,aAAa,CAAC,SAAiB,UACnC,IAAI,gBAAgB,EAAE,MAAM,eAAe,SAAS,MAAM,CAAC;AAE7D,MAAM,cAAc,CAAC,SAAiB,UACpC,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,SAAS,MAAM,CAAC;AAE9D,MAAM,iBAAiB,CAAC,YAAqC,IAAI,gBAAgB,EAAE,MAAM,mBAAmB,QAAQ,CAAC;AAUrH,MAAM,cAAc,CAAC,OAAe,aAClC,cAAc,YAAY,OAAO,QAAQ,EAAE;AAAA,EACzC,OAAO,SAAS,CAAC,UAAU,WAAW,MAAM,SAAS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AAI,iBAAiB;AACrB,UAAI,cAAc;AAClB,iBAAW,QAAQ,OAAO;AACxB,YAAI,KAAK,IAAI,KAAK,MAAM,EAAG;AAC3B,YAAI,KAAK,gBAAgB,OAAO;AAC9B;AACA;AAAA,QACF;AACA,YAAI,WAAW,WAAW,MAAM;AAC9B,gBAAM,KAAK,KAAK,MAAM;AACtB,4BAAkB,KAAK;AACvB;AAAA,QACF;AAOA,cAAM,UAAU,OAAO,QAAQ,OAAO,KAAK,QAAQ,EAAE,qBAAqB,QAAQ,EAAE,CAAC,EAAE;AAAA,UACrF,OAAO,SAAS,CAAC,UAAU,YAAY,YAAY,KAAK,MAAM,aAAa,MAAM,OAAO,IAAI,KAAK,CAAC;AAAA,QACpG;AACA,YAAI,SAAS;AACX,gBAAM,KAAK,KAAK,MAAM;AACtB,4BAAkB,KAAK;AAAA,QACzB,OAAO;AACL;AAAA,QACF;AAAA,MACF;AACA,aAAO;AAAA,QACL,cAAc,MAAM;AAAA,QACpB,aAAa,KAAK;AAAA,QAClB,cAAc;AAAA,QACd;AAAA,QACA;AAAA,QACA,QAAQ,WAAW,WAAW;AAAA,MAChC;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO,EAAE,GAAG;AACd,CAAC;AAUI,MAAM,QAAQ,CACnB,UAAuB,CAAC,MAExB,MAAM,OAAO,UAAU,EAAE,KAAK,OAAO,CAAC;AAWjC,MAAM,kBAAkB,CAC7B,UAAoD,CAAC,MAErD,MAAM,OAAO,EAAE;AAAA,EACb,MAAM,QAAQ,cAAc,gBAAgB,EAAE,WAAW,QAAQ,WAAW,cAAc,QAAQ,aAAa,CAAC,CAAC;AACnH;",
6
6
  "names": []
7
7
  }
@@ -36,7 +36,7 @@ import { Journal, JournalEvent, Projection } from "@smthrs/journal";
36
36
  import * as Effect from "effect/Effect";
37
37
  import * as Option from "effect/Option";
38
38
  import * as Schema from "effect/Schema";
39
- import * as SqlClient from "effect/unstable/sql/SqlClient";
39
+ import * as SqlClient from "effect/sql/SqlClient";
40
40
  /**
41
41
  * The journal event types the fold reads.
42
42
  *
@@ -276,7 +276,7 @@ export declare const capture: (runId: string, upTo: number) => Effect.Effect<{
276
276
  readonly exitDigest?: string;
277
277
  readonly metadataDigest?: string | null;
278
278
  }[];
279
- }, import("effect/unstable/sql/SqlError").SqlError | Journal.JournalError | FoldIncomplete, SqlClient.SqlClient | Journal.Journal>;
279
+ }, import("effect/sql/SqlError").SqlError | Journal.JournalError | FoldIncomplete, SqlClient.SqlClient | Journal.Journal>;
280
280
  /**
281
281
  * A checkpoint state that keeps the fold: `base` (an object, or nothing) with
282
282
  * the run's fold up to `upTo` under {@link checkpointKey}. A composition that
@@ -306,7 +306,7 @@ export declare const checkpointState: (runId: string, upTo: number, base?: Reado
306
306
  readonly metadataDigest?: string | null;
307
307
  }[];
308
308
  };
309
- }, import("effect/unstable/sql/SqlError").SqlError | Journal.JournalError | FoldIncomplete, SqlClient.SqlClient | Journal.Journal>;
309
+ }, import("effect/sql/SqlError").SqlError | Journal.JournalError | FoldIncomplete, SqlClient.SqlClient | Journal.Journal>;
310
310
  /**
311
311
  * What a {@link rebuild} read and wrote.
312
312
  *
@@ -349,6 +349,6 @@ export declare const rebuild: () => Effect.Effect<{
349
349
  clocks: number;
350
350
  deferreds: number;
351
351
  unexplained: number;
352
- }, import("effect/unstable/sql/SqlError").SqlError | import("@smthrs/database/DurableWriter").DatabaseError | Journal.JournalError | FoldIncomplete, SqlClient.SqlClient | DurableWriter | Journal.Journal>;
352
+ }, import("effect/sql/SqlError").SqlError | import("@smthrs/database/DurableWriter").DatabaseError | Journal.JournalError | FoldIncomplete, SqlClient.SqlClient | DurableWriter | Journal.Journal>;
353
353
  export {};
354
354
  //# sourceMappingURL=DeferredClockFold.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DeferredClockFold.d.ts","sourceRoot":"","sources":["../../src/DeferredClockFold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG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AAC,IAAI,CAAA;;;;;;;;;;;AAE3C;;;;;;GAMG;AACH,qBAAa,cAAe,SAAQ,mBAOnC;CAAG;AA8DJ;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;yHAElB,CAAA;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;yHAM1B,CAAA;AAEF;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,0BAA0B;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,uEAAuE;IACvE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,mEAAmE;IACnE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B;AAUD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,OAAO;;;;;kMAkGlB,CAAA"}
@@ -53,7 +53,7 @@ var import_journal = require("@smthrs/journal");
53
53
  var Effect = __toESM(require("effect/Effect"), 1);
54
54
  var Option = __toESM(require("effect/Option"), 1);
55
55
  var Schema = __toESM(require("effect/Schema"), 1);
56
- var SqlClient = __toESM(require("effect/unstable/sql/SqlClient"), 1);
56
+ var SqlClient = __toESM(require("effect/sql/SqlClient"), 1);
57
57
  var import_EventTypes = require("./EventTypes.js");
58
58
  const eventTypes = [
59
59
  import_EventTypes.EventTypes.clockScheduled,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/DeferredClockFold.ts"],
4
- "sourcesContent": ["/**\n * The deferred/clock fold: `flows_clock_deadlines` and the mutable half of\n * `flows_deferred_completions` rebuilt from the journal.\n *\n * Every change to either table is journalled on the run's own stream in the\n * transaction that makes it:\n *\n * - `flows.engine.clock-scheduled` when a clock row is inserted;\n * - `flows.engine.clock-completed` when a clock fires or its run settles\n * first (`completeClock`, `completeRunClocks`);\n * - `flows.engine.deferred-completed` when the first completion wins, naming\n * the row and the {@link JournalEvent.contentDigest} of its encoded `exit`\n * and `metadata`;\n * - `flows.engine.deferred-consumed` when a run first observes a result.\n *\n * The journal is redacted and replayed to sync subscribers, so it never\n * carries a completion's value (issue #72). A clock row holds no value at\n * all, so the fold rebuilds it whole. A completion row's value stays in the\n * row: the fold rebuilds its `completed_at_ms` and `consumed_at_ms`, and a\n * rebuild checks the stored text against the recorded digests. A completion\n * the journal names but no row holds, or holds with other bytes, is a typed\n * {@link FoldIncomplete}, never a silent gap.\n *\n * Compaction deletes a run's entries below its floor, so the fold's state at\n * the floor has to survive in the floor's checkpoint: {@link checkpointState}\n * adds it under {@link checkpointKey}, and a rebuild of a compacted run whose\n * floor checkpoint lacks it fails {@link FoldIncomplete} with reason\n * `checkpoint_missing`. A rewind archives the suffix and removes the rows it\n * explains (`@smthrs/time-travel`), so the remaining journal still explains\n * the remaining rows.\n *\n * @since 1.0.0\n */\n\nimport { DurableWriter } from \"@smthrs/database/DurableWriter\"\nimport { Journal, JournalEvent, Projection } from \"@smthrs/journal\"\nimport * as Effect from \"effect/Effect\"\nimport * as Option from \"effect/Option\"\nimport * as Schema from \"effect/Schema\"\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\"\nimport { EventTypes } from \"./EventTypes.ts\"\n\n/**\n * The journal event types the fold reads.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const eventTypes: ReadonlyArray<string> = [\n EventTypes.clockScheduled,\n EventTypes.clockCompleted,\n EventTypes.deferredCompleted,\n EventTypes.deferredConsumed\n]\n\n/**\n * The key a checkpoint's state keeps the fold under.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const checkpointKey = \"flows.engine.deferred-clock\"\n\nconst NonNegativeSafeInt = Schema.Int.check(\n Schema.isGreaterThanOrEqualTo(0),\n Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)\n)\nconst Digest = Schema.String.check(Schema.isPattern(/^[0-9a-f]{64}$/))\n\n/**\n * A clock as the journal records it.\n *\n * @category models\n * @since 1.0.0\n */\nexport const Clock = Schema.Struct({\n flowName: Schema.NonEmptyString,\n executionId: Schema.NonEmptyString,\n clockName: Schema.NonEmptyString,\n deferredName: Schema.NonEmptyString,\n dueAtMs: NonNegativeSafeInt,\n completedAtMs: Schema.NullOr(NonNegativeSafeInt)\n})\n\n/**\n * A clock as the journal records it.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Clock = typeof Clock.Type\n\n/**\n * A deferred completion as the journal records it. A completion journalled\n * before the fold existed carried its (redacted) value instead of digests and\n * no completion time: `exitDigest` and `metadataDigest` are then absent and\n * `completedAtMs` is `null`, and a rebuild keeps the row's own stamp.\n *\n * @category models\n * @since 1.0.0\n */\nexport const Deferred = Schema.Struct({\n flowName: Schema.NonEmptyString,\n executionId: Schema.NonEmptyString,\n deferredName: Schema.NonEmptyString,\n completedAtMs: Schema.NullOr(NonNegativeSafeInt),\n exitDigest: Schema.optionalKey(Digest),\n metadataDigest: Schema.optionalKey(Schema.NullOr(Digest)),\n consumedAtMs: Schema.NullOr(NonNegativeSafeInt)\n})\n\n/**\n * A deferred completion as the journal records it.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Deferred = typeof Deferred.Type\n\n/**\n * The folded clocks and completions, keyed by their row address.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface State {\n readonly clocks: ReadonlyMap<string, Clock>\n readonly deferreds: ReadonlyMap<string, Deferred>\n}\n\n/**\n * The empty fold.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const initial: State = { clocks: new Map(), deferreds: new Map() }\n\n/**\n * The key of a clock row.\n *\n * @category models\n * @since 1.0.0\n */\nexport const clockKey = (\n address: { readonly flowName: string; readonly executionId: string; readonly clockName: string }\n) => JSON.stringify([address.flowName, address.executionId, address.clockName])\n\n/**\n * The key of a completion row.\n *\n * @category models\n * @since 1.0.0\n */\nexport const deferredKey = (\n address: { readonly flowName: string; readonly executionId: string; readonly deferredName: string }\n) => JSON.stringify([address.flowName, address.executionId, address.deferredName])\n\nconst record = (value: unknown): Readonly<Record<string, unknown>> | undefined =>\n typeof value === \"object\" && value !== null && !Array.isArray(value)\n ? value as Readonly<Record<string, unknown>>\n : undefined\n\nconst text = (value: unknown): value is string => typeof value === \"string\" && value.length > 0\nconst time = (value: unknown): value is number => typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0\nconst digest = (value: unknown): value is string => typeof value === \"string\" && /^[0-9a-f]{64}$/.test(value)\n\n/**\n * Folds one committed journal entry. First writes win: a clock keeps its first\n * schedule and first completion, and a completion its first recording and\n * first consumption, exactly as the rows do. An entry of another type, or one\n * whose payload names no row, leaves the state unchanged.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const reduce = (state: State, entry: JournalEvent.Entry): State => {\n const payload = record(entry.payload)\n if (payload === undefined || !text(payload.flowName) || !text(payload.executionId)) return state\n const flowName = payload.flowName\n const executionId = payload.executionId\n switch (entry.eventType) {\n case EventTypes.clockScheduled: {\n if (!text(payload.clockName) || !text(payload.deferredName) || !time(payload.dueAtMs)) return state\n const key = clockKey({ flowName, executionId, clockName: payload.clockName })\n if (state.clocks.has(key)) return state\n const clocks = new Map(state.clocks)\n clocks.set(key, {\n flowName,\n executionId,\n clockName: payload.clockName,\n deferredName: payload.deferredName,\n dueAtMs: payload.dueAtMs,\n completedAtMs: null\n })\n return { ...state, clocks }\n }\n case EventTypes.clockCompleted: {\n if (!text(payload.clockName) || !time(payload.completedAtMs)) return state\n const key = clockKey({ flowName, executionId, clockName: payload.clockName })\n const clock = state.clocks.get(key)\n if (clock === undefined || clock.completedAtMs !== null) return state\n const clocks = new Map(state.clocks)\n clocks.set(key, { ...clock, completedAtMs: payload.completedAtMs })\n return { ...state, clocks }\n }\n case EventTypes.deferredCompleted: {\n if (!text(payload.deferredName)) return state\n const key = deferredKey({ flowName, executionId, deferredName: payload.deferredName })\n if (state.deferreds.has(key)) return state\n const deferreds = new Map(state.deferreds)\n deferreds.set(key, {\n flowName,\n executionId,\n deferredName: payload.deferredName,\n completedAtMs: time(payload.completedAtMs) ? payload.completedAtMs : null,\n ...(digest(payload.exitDigest) ? { exitDigest: payload.exitDigest } : {}),\n ...(digest(payload.exitDigest) && (payload.metadataDigest === null || digest(payload.metadataDigest))\n ? { metadataDigest: payload.metadataDigest }\n : {}),\n consumedAtMs: null\n })\n return { ...state, deferreds }\n }\n case EventTypes.deferredConsumed: {\n if (!text(payload.deferredName) || !time(payload.consumedAtMs)) return state\n const key = deferredKey({ flowName, executionId, deferredName: payload.deferredName })\n const deferred = state.deferreds.get(key)\n if (deferred === undefined || deferred.consumedAtMs !== null) return state\n const deferreds = new Map(state.deferreds)\n deferreds.set(key, { ...deferred, consumedAtMs: payload.consumedAtMs })\n return { ...state, deferreds }\n }\n default:\n return state\n }\n}\n\n/**\n * The fold as a journal projection, for `Journal.project` over one run.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const projection: Projection.Projection<State> = Projection.make({\n name: \"flows.engine.deferred-clock\",\n initial,\n reduce: (state, entry) => Effect.succeed(reduce(state, entry))\n})\n\n/**\n * The checkpoint encoding of the fold.\n *\n * @category models\n * @since 1.0.0\n */\nexport const Encoded = Schema.Struct({\n clocks: Schema.Array(Clock),\n deferreds: Schema.Array(Deferred)\n})\n\n/**\n * The checkpoint encoding of the fold.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Encoded = typeof Encoded.Type\n\n/**\n * Encodes the fold for a checkpoint.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const encode = (state: State): Encoded => ({\n clocks: [...state.clocks.values()],\n deferreds: [...state.deferreds.values()]\n})\n\n/**\n * Decodes the fold a checkpoint kept, or `None` when the checkpoint state\n * holds none under {@link checkpointKey}.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const fromCheckpoint = (checkpointState: unknown): Option.Option<State> => {\n const kept = record(checkpointState)?.[checkpointKey]\n if (kept === undefined) return Option.none()\n const decoded = Schema.decodeUnknownOption(Encoded)(kept)\n return Option.map(decoded, (encoded) => ({\n clocks: new Map(encoded.clocks.map((clock) => [clockKey(clock), clock])),\n deferreds: new Map(encoded.deferreds.map((deferred) => [deferredKey(deferred), deferred]))\n }))\n}\n\n/**\n * Why a rebuild could not reconstruct the tables.\n *\n * - `row_missing`: the journal names a completion no row holds.\n * - `digest_mismatch`: the row holds other bytes than the journal recorded.\n * - `run_missing`: a clock's run has no `flows_runs` row to hang it on.\n * - `checkpoint_missing`: a compacted run's floor checkpoint keeps no fold.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const FoldIncompleteReason = Schema.Literals([\n \"row_missing\",\n \"digest_mismatch\",\n \"run_missing\",\n \"checkpoint_missing\"\n])\n\n/**\n * One reference a rebuild could not join.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const Unjoined = Schema.Struct({\n reason: FoldIncompleteReason,\n executionId: Schema.String,\n flowName: Schema.optionalKey(Schema.String),\n name: Schema.optionalKey(Schema.String)\n})\n\n/**\n * One reference a rebuild could not join.\n *\n * @category errors\n * @since 1.0.0\n */\nexport type Unjoined = typeof Unjoined.Type\n\n/**\n * The journal references state the store no longer holds. The rebuild wrote\n * nothing.\n *\n * @category errors\n * @since 1.0.0\n */\nexport class FoldIncomplete extends Schema.TaggedError<FoldIncomplete>()(\n \"@smthrs/engine-store/DeferredClockFold/FoldIncomplete\",\n {\n code: Schema.Literal(\"fold_incomplete\"),\n message: Schema.String,\n unjoined: Schema.Array(Unjoined)\n }\n) {}\n\nconst pageSize = 512\n\n/** Folds one run's entries after `after` into `start`, in sequence order. */\nconst foldEntries = (\n journal: Journal.Service,\n runId: string,\n start: State,\n after: JournalEvent.Seq | undefined,\n upTo?: number | undefined\n) =>\n Effect.gen(function*() {\n let state = start\n let cursor = after\n while (true) {\n const page = yield* journal.entries({\n runId: runId as JournalEvent.RunId,\n eventTypes,\n limit: pageSize,\n ...(cursor === undefined ? {} : { after: cursor })\n })\n for (const entry of page.entries) {\n if (upTo !== undefined && entry.seq > upTo) return state\n state = reduce(state, entry)\n cursor = entry.seq\n }\n if (!page.hasMore) return state\n }\n })\n\n/** The run's compaction floor checkpoint, if compaction ever ran. */\nconst floorOf = (sql: SqlClient.SqlClient, runId: string) =>\n sql<{ readonly seq: number | string; readonly state_json: string }>`\n SELECT seq, state_json FROM flows_journal_checkpoints\n WHERE run_id = ${runId} AND compacted_at_ms IS NOT NULL\n ORDER BY seq DESC LIMIT 1\n `.pipe(Effect.map((rows) => rows[0]))\n\n/**\n * Folds one run: its floor checkpoint's fold, if it was compacted, then every\n * entry above the floor, up to and including `upTo` when given.\n */\nconst foldRun = (runId: string, upTo?: number | undefined) =>\n Effect.gen(function*() {\n const journal = yield* Journal.Journal\n const sql = yield* SqlClient.SqlClient\n const floor = yield* floorOf(sql, runId)\n if (floor === undefined) return yield* foldEntries(journal, runId, initial, undefined, upTo)\n const kept = fromCheckpoint(JSON.parse(floor.state_json) as unknown)\n if (Option.isNone(kept)) {\n return yield* Effect.fail(\n new FoldIncomplete({\n code: \"fold_incomplete\",\n message: `run ${runId} was compacted below a checkpoint that keeps no deferred/clock fold`,\n unjoined: [{ reason: \"checkpoint_missing\", executionId: runId }]\n })\n )\n }\n return yield* foldEntries(journal, runId, kept.value, Number(floor.seq) as JournalEvent.Seq, upTo)\n })\n\n/**\n * The fold of one run's entries up to and including `upTo`, for the state of\n * a checkpoint at `upTo`. It starts from the run's floor checkpoint when the\n * run was compacted before.\n *\n * @category operations\n * @since 1.0.0\n */\nexport const capture = Effect.fn(\"DeferredClockFold.capture\")(function*(runId: string, upTo: number) {\n return encode(yield* foldRun(runId, upTo))\n})\n\n/**\n * A checkpoint state that keeps the fold: `base` (an object, or nothing) with\n * the run's fold up to `upTo` under {@link checkpointKey}. A composition that\n * compacts runs writes its checkpoints through this, so compaction cannot\n * lose the deferred/clock history.\n *\n * @category operations\n * @since 1.0.0\n */\nexport const checkpointState = Effect.fn(\"DeferredClockFold.checkpointState\")(function*(\n runId: string,\n upTo: number,\n base?: Readonly<Record<string, unknown>> | undefined\n) {\n return { ...base, [checkpointKey]: yield* capture(runId, upTo) }\n})\n\n/**\n * What a {@link rebuild} read and wrote.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Rebuilt {\n /** Runs with deferred or clock entries, or with a compaction floor. */\n readonly runs: number\n /** Clock rows written. */\n readonly clocks: number\n /** Completion rows whose completion and consumption were rewritten. */\n readonly deferreds: number\n /** Completion rows no journal entry explains, left as they are. */\n readonly unexplained: number\n}\n\ninterface StoredDeferred {\n readonly flow_name: string\n readonly execution_id: string\n readonly deferred_name: string\n readonly exit_json: string\n readonly metadata_json: string | null\n}\n\n/**\n * Rebuilds `flows_clock_deadlines` and the completion and consumption stamps\n * of `flows_deferred_completions` from the journal.\n *\n * Every run with deferred or clock entries, and every compacted run, is\n * folded in sequence order, from its floor checkpoint when it was compacted;\n * a compacted run whose floor keeps no fold fails, even one that never had a\n * clock, because the journal can no longer say. Every reference is joined\n * before anything is written: a completion with no row or with other bytes,\n * a clock whose run is gone, or a compacted run whose floor keeps no fold\n * fails {@link FoldIncomplete} listing each one, and nothing is written.\n * Otherwise, in one writer transaction, the clock table is replaced by the\n * fold's clocks and each folded completion row gets the fold's\n * `completed_at_ms` and `consumed_at_ms`. A completion row the journal does\n * not explain is left alone and counted.\n *\n * Run it on a quiescent store, as a restore does.\n *\n * @category operations\n * @since 1.0.0\n */\nexport const rebuild = Effect.fn(\"DeferredClockFold.rebuild\")(function*() {\n const sql = yield* SqlClient.SqlClient\n const writer = yield* DurableWriter\n // A compacted run may have no fold entry left above its floor, so every run\n // with a compaction floor is folded too.\n const runs = yield* sql<{ readonly run_id: string }>`\n SELECT run_id FROM flows_journal_events WHERE ${sql.in(\"event_type\", eventTypes)}\n UNION\n SELECT run_id FROM flows_journal_checkpoints WHERE compacted_at_ms IS NOT NULL\n ORDER BY run_id\n `\n const unjoined: Array<Unjoined> = []\n const clocks: Array<Clock> = []\n const deferreds: Array<Deferred> = []\n for (const { run_id } of runs) {\n const state = yield* foldRun(run_id).pipe(\n Effect.catchTag(\"@smthrs/engine-store/DeferredClockFold/FoldIncomplete\", (error) => {\n unjoined.push(...error.unjoined)\n return Effect.succeed(initial)\n })\n )\n clocks.push(...state.clocks.values())\n deferreds.push(...state.deferreds.values())\n }\n const liveRuns = new Set(\n (yield* sql<{ readonly run_id: string }>`SELECT run_id FROM flows_runs`).map((row) => row.run_id)\n )\n for (const clock of clocks) {\n if (!liveRuns.has(clock.executionId)) {\n unjoined.push({\n reason: \"run_missing\",\n executionId: clock.executionId,\n flowName: clock.flowName,\n name: clock.clockName\n })\n }\n }\n const stored = new Map(\n (yield* sql<StoredDeferred>`\n SELECT flow_name, execution_id, deferred_name, exit_json, metadata_json\n FROM flows_deferred_completions\n `).map((row) => [\n deferredKey({ flowName: row.flow_name, executionId: row.execution_id, deferredName: row.deferred_name }),\n row\n ])\n )\n for (const deferred of deferreds) {\n const row = stored.get(deferredKey(deferred))\n const reference = { executionId: deferred.executionId, flowName: deferred.flowName, name: deferred.deferredName }\n if (row === undefined) {\n unjoined.push({ reason: \"row_missing\", ...reference })\n } else if (\n (deferred.exitDigest !== undefined && JournalEvent.contentDigest(row.exit_json) !== deferred.exitDigest) ||\n (deferred.metadataDigest !== undefined &&\n (row.metadata_json === null ? null : JournalEvent.contentDigest(row.metadata_json)) !==\n deferred.metadataDigest)\n ) {\n unjoined.push({ reason: \"digest_mismatch\", ...reference })\n }\n }\n if (unjoined.length > 0) {\n return yield* Effect.fail(\n new FoldIncomplete({\n code: \"fold_incomplete\",\n message: `the journal references ${unjoined.length} deferred/clock rows the store cannot join`,\n unjoined\n })\n )\n }\n yield* writer.write(Effect.gen(function*() {\n yield* sql`DELETE FROM flows_clock_deadlines`\n for (const clock of clocks) {\n yield* sql`\n INSERT INTO flows_clock_deadlines (\n flow_name, execution_id, clock_name, deferred_name, due_at_ms, completed_at_ms\n ) VALUES (\n ${clock.flowName}, ${clock.executionId}, ${clock.clockName}, ${clock.deferredName},\n ${clock.dueAtMs}, ${clock.completedAtMs}\n )\n `\n }\n for (const deferred of deferreds) {\n yield* sql`\n UPDATE flows_deferred_completions\n SET completed_at_ms = COALESCE(${deferred.completedAtMs}, completed_at_ms),\n consumed_at_ms = ${deferred.consumedAtMs}\n WHERE flow_name = ${deferred.flowName}\n AND execution_id = ${deferred.executionId}\n AND deferred_name = ${deferred.deferredName}\n `\n }\n }))\n return {\n runs: runs.length,\n clocks: clocks.length,\n deferreds: deferreds.length,\n unexplained: stored.size - deferreds.length\n } satisfies Rebuilt\n})\n"],
4
+ "sourcesContent": ["/**\n * The deferred/clock fold: `flows_clock_deadlines` and the mutable half of\n * `flows_deferred_completions` rebuilt from the journal.\n *\n * Every change to either table is journalled on the run's own stream in the\n * transaction that makes it:\n *\n * - `flows.engine.clock-scheduled` when a clock row is inserted;\n * - `flows.engine.clock-completed` when a clock fires or its run settles\n * first (`completeClock`, `completeRunClocks`);\n * - `flows.engine.deferred-completed` when the first completion wins, naming\n * the row and the {@link JournalEvent.contentDigest} of its encoded `exit`\n * and `metadata`;\n * - `flows.engine.deferred-consumed` when a run first observes a result.\n *\n * The journal is redacted and replayed to sync subscribers, so it never\n * carries a completion's value (issue #72). A clock row holds no value at\n * all, so the fold rebuilds it whole. A completion row's value stays in the\n * row: the fold rebuilds its `completed_at_ms` and `consumed_at_ms`, and a\n * rebuild checks the stored text against the recorded digests. A completion\n * the journal names but no row holds, or holds with other bytes, is a typed\n * {@link FoldIncomplete}, never a silent gap.\n *\n * Compaction deletes a run's entries below its floor, so the fold's state at\n * the floor has to survive in the floor's checkpoint: {@link checkpointState}\n * adds it under {@link checkpointKey}, and a rebuild of a compacted run whose\n * floor checkpoint lacks it fails {@link FoldIncomplete} with reason\n * `checkpoint_missing`. A rewind archives the suffix and removes the rows it\n * explains (`@smthrs/time-travel`), so the remaining journal still explains\n * the remaining rows.\n *\n * @since 1.0.0\n */\n\nimport { DurableWriter } from \"@smthrs/database/DurableWriter\"\nimport { Journal, JournalEvent, Projection } from \"@smthrs/journal\"\nimport * as Effect from \"effect/Effect\"\nimport * as Option from \"effect/Option\"\nimport * as Schema from \"effect/Schema\"\nimport * as SqlClient from \"effect/sql/SqlClient\"\nimport { EventTypes } from \"./EventTypes.ts\"\n\n/**\n * The journal event types the fold reads.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const eventTypes: ReadonlyArray<string> = [\n EventTypes.clockScheduled,\n EventTypes.clockCompleted,\n EventTypes.deferredCompleted,\n EventTypes.deferredConsumed\n]\n\n/**\n * The key a checkpoint's state keeps the fold under.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const checkpointKey = \"flows.engine.deferred-clock\"\n\nconst NonNegativeSafeInt = Schema.Int.check(\n Schema.isGreaterThanOrEqualTo(0),\n Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)\n)\nconst Digest = Schema.String.check(Schema.isPattern(/^[0-9a-f]{64}$/))\n\n/**\n * A clock as the journal records it.\n *\n * @category models\n * @since 1.0.0\n */\nexport const Clock = Schema.Struct({\n flowName: Schema.NonEmptyString,\n executionId: Schema.NonEmptyString,\n clockName: Schema.NonEmptyString,\n deferredName: Schema.NonEmptyString,\n dueAtMs: NonNegativeSafeInt,\n completedAtMs: Schema.NullOr(NonNegativeSafeInt)\n})\n\n/**\n * A clock as the journal records it.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Clock = typeof Clock.Type\n\n/**\n * A deferred completion as the journal records it. A completion journalled\n * before the fold existed carried its (redacted) value instead of digests and\n * no completion time: `exitDigest` and `metadataDigest` are then absent and\n * `completedAtMs` is `null`, and a rebuild keeps the row's own stamp.\n *\n * @category models\n * @since 1.0.0\n */\nexport const Deferred = Schema.Struct({\n flowName: Schema.NonEmptyString,\n executionId: Schema.NonEmptyString,\n deferredName: Schema.NonEmptyString,\n completedAtMs: Schema.NullOr(NonNegativeSafeInt),\n exitDigest: Schema.optionalKey(Digest),\n metadataDigest: Schema.optionalKey(Schema.NullOr(Digest)),\n consumedAtMs: Schema.NullOr(NonNegativeSafeInt)\n})\n\n/**\n * A deferred completion as the journal records it.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Deferred = typeof Deferred.Type\n\n/**\n * The folded clocks and completions, keyed by their row address.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface State {\n readonly clocks: ReadonlyMap<string, Clock>\n readonly deferreds: ReadonlyMap<string, Deferred>\n}\n\n/**\n * The empty fold.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const initial: State = { clocks: new Map(), deferreds: new Map() }\n\n/**\n * The key of a clock row.\n *\n * @category models\n * @since 1.0.0\n */\nexport const clockKey = (\n address: { readonly flowName: string; readonly executionId: string; readonly clockName: string }\n) => JSON.stringify([address.flowName, address.executionId, address.clockName])\n\n/**\n * The key of a completion row.\n *\n * @category models\n * @since 1.0.0\n */\nexport const deferredKey = (\n address: { readonly flowName: string; readonly executionId: string; readonly deferredName: string }\n) => JSON.stringify([address.flowName, address.executionId, address.deferredName])\n\nconst record = (value: unknown): Readonly<Record<string, unknown>> | undefined =>\n typeof value === \"object\" && value !== null && !Array.isArray(value)\n ? value as Readonly<Record<string, unknown>>\n : undefined\n\nconst text = (value: unknown): value is string => typeof value === \"string\" && value.length > 0\nconst time = (value: unknown): value is number => typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0\nconst digest = (value: unknown): value is string => typeof value === \"string\" && /^[0-9a-f]{64}$/.test(value)\n\n/**\n * Folds one committed journal entry. First writes win: a clock keeps its first\n * schedule and first completion, and a completion its first recording and\n * first consumption, exactly as the rows do. An entry of another type, or one\n * whose payload names no row, leaves the state unchanged.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const reduce = (state: State, entry: JournalEvent.Entry): State => {\n const payload = record(entry.payload)\n if (payload === undefined || !text(payload.flowName) || !text(payload.executionId)) return state\n const flowName = payload.flowName\n const executionId = payload.executionId\n switch (entry.eventType) {\n case EventTypes.clockScheduled: {\n if (!text(payload.clockName) || !text(payload.deferredName) || !time(payload.dueAtMs)) return state\n const key = clockKey({ flowName, executionId, clockName: payload.clockName })\n if (state.clocks.has(key)) return state\n const clocks = new Map(state.clocks)\n clocks.set(key, {\n flowName,\n executionId,\n clockName: payload.clockName,\n deferredName: payload.deferredName,\n dueAtMs: payload.dueAtMs,\n completedAtMs: null\n })\n return { ...state, clocks }\n }\n case EventTypes.clockCompleted: {\n if (!text(payload.clockName) || !time(payload.completedAtMs)) return state\n const key = clockKey({ flowName, executionId, clockName: payload.clockName })\n const clock = state.clocks.get(key)\n if (clock === undefined || clock.completedAtMs !== null) return state\n const clocks = new Map(state.clocks)\n clocks.set(key, { ...clock, completedAtMs: payload.completedAtMs })\n return { ...state, clocks }\n }\n case EventTypes.deferredCompleted: {\n if (!text(payload.deferredName)) return state\n const key = deferredKey({ flowName, executionId, deferredName: payload.deferredName })\n if (state.deferreds.has(key)) return state\n const deferreds = new Map(state.deferreds)\n deferreds.set(key, {\n flowName,\n executionId,\n deferredName: payload.deferredName,\n completedAtMs: time(payload.completedAtMs) ? payload.completedAtMs : null,\n ...(digest(payload.exitDigest) ? { exitDigest: payload.exitDigest } : {}),\n ...(digest(payload.exitDigest) && (payload.metadataDigest === null || digest(payload.metadataDigest))\n ? { metadataDigest: payload.metadataDigest }\n : {}),\n consumedAtMs: null\n })\n return { ...state, deferreds }\n }\n case EventTypes.deferredConsumed: {\n if (!text(payload.deferredName) || !time(payload.consumedAtMs)) return state\n const key = deferredKey({ flowName, executionId, deferredName: payload.deferredName })\n const deferred = state.deferreds.get(key)\n if (deferred === undefined || deferred.consumedAtMs !== null) return state\n const deferreds = new Map(state.deferreds)\n deferreds.set(key, { ...deferred, consumedAtMs: payload.consumedAtMs })\n return { ...state, deferreds }\n }\n default:\n return state\n }\n}\n\n/**\n * The fold as a journal projection, for `Journal.project` over one run.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const projection: Projection.Projection<State> = Projection.make({\n name: \"flows.engine.deferred-clock\",\n initial,\n reduce: (state, entry) => Effect.succeed(reduce(state, entry))\n})\n\n/**\n * The checkpoint encoding of the fold.\n *\n * @category models\n * @since 1.0.0\n */\nexport const Encoded = Schema.Struct({\n clocks: Schema.Array(Clock),\n deferreds: Schema.Array(Deferred)\n})\n\n/**\n * The checkpoint encoding of the fold.\n *\n * @category models\n * @since 1.0.0\n */\nexport type Encoded = typeof Encoded.Type\n\n/**\n * Encodes the fold for a checkpoint.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const encode = (state: State): Encoded => ({\n clocks: [...state.clocks.values()],\n deferreds: [...state.deferreds.values()]\n})\n\n/**\n * Decodes the fold a checkpoint kept, or `None` when the checkpoint state\n * holds none under {@link checkpointKey}.\n *\n * @category folds\n * @since 1.0.0\n */\nexport const fromCheckpoint = (checkpointState: unknown): Option.Option<State> => {\n const kept = record(checkpointState)?.[checkpointKey]\n if (kept === undefined) return Option.none()\n const decoded = Schema.decodeUnknownOption(Encoded)(kept)\n return Option.map(decoded, (encoded) => ({\n clocks: new Map(encoded.clocks.map((clock) => [clockKey(clock), clock])),\n deferreds: new Map(encoded.deferreds.map((deferred) => [deferredKey(deferred), deferred]))\n }))\n}\n\n/**\n * Why a rebuild could not reconstruct the tables.\n *\n * - `row_missing`: the journal names a completion no row holds.\n * - `digest_mismatch`: the row holds other bytes than the journal recorded.\n * - `run_missing`: a clock's run has no `flows_runs` row to hang it on.\n * - `checkpoint_missing`: a compacted run's floor checkpoint keeps no fold.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const FoldIncompleteReason = Schema.Literals([\n \"row_missing\",\n \"digest_mismatch\",\n \"run_missing\",\n \"checkpoint_missing\"\n])\n\n/**\n * One reference a rebuild could not join.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const Unjoined = Schema.Struct({\n reason: FoldIncompleteReason,\n executionId: Schema.String,\n flowName: Schema.optionalKey(Schema.String),\n name: Schema.optionalKey(Schema.String)\n})\n\n/**\n * One reference a rebuild could not join.\n *\n * @category errors\n * @since 1.0.0\n */\nexport type Unjoined = typeof Unjoined.Type\n\n/**\n * The journal references state the store no longer holds. The rebuild wrote\n * nothing.\n *\n * @category errors\n * @since 1.0.0\n */\nexport class FoldIncomplete extends Schema.TaggedError<FoldIncomplete>()(\n \"@smthrs/engine-store/DeferredClockFold/FoldIncomplete\",\n {\n code: Schema.Literal(\"fold_incomplete\"),\n message: Schema.String,\n unjoined: Schema.Array(Unjoined)\n }\n) {}\n\nconst pageSize = 512\n\n/** Folds one run's entries after `after` into `start`, in sequence order. */\nconst foldEntries = (\n journal: Journal.Service,\n runId: string,\n start: State,\n after: JournalEvent.Seq | undefined,\n upTo?: number | undefined\n) =>\n Effect.gen(function*() {\n let state = start\n let cursor = after\n while (true) {\n const page = yield* journal.entries({\n runId: runId as JournalEvent.RunId,\n eventTypes,\n limit: pageSize,\n ...(cursor === undefined ? {} : { after: cursor })\n })\n for (const entry of page.entries) {\n if (upTo !== undefined && entry.seq > upTo) return state\n state = reduce(state, entry)\n cursor = entry.seq\n }\n if (!page.hasMore) return state\n }\n })\n\n/** The run's compaction floor checkpoint, if compaction ever ran. */\nconst floorOf = (sql: SqlClient.SqlClient, runId: string) =>\n sql<{ readonly seq: number | string; readonly state_json: string }>`\n SELECT seq, state_json FROM flows_journal_checkpoints\n WHERE run_id = ${runId} AND compacted_at_ms IS NOT NULL\n ORDER BY seq DESC LIMIT 1\n `.pipe(Effect.map((rows) => rows[0]))\n\n/**\n * Folds one run: its floor checkpoint's fold, if it was compacted, then every\n * entry above the floor, up to and including `upTo` when given.\n */\nconst foldRun = (runId: string, upTo?: number | undefined) =>\n Effect.gen(function*() {\n const journal = yield* Journal.Journal\n const sql = yield* SqlClient.SqlClient\n const floor = yield* floorOf(sql, runId)\n if (floor === undefined) return yield* foldEntries(journal, runId, initial, undefined, upTo)\n const kept = fromCheckpoint(JSON.parse(floor.state_json) as unknown)\n if (Option.isNone(kept)) {\n return yield* Effect.fail(\n new FoldIncomplete({\n code: \"fold_incomplete\",\n message: `run ${runId} was compacted below a checkpoint that keeps no deferred/clock fold`,\n unjoined: [{ reason: \"checkpoint_missing\", executionId: runId }]\n })\n )\n }\n return yield* foldEntries(journal, runId, kept.value, Number(floor.seq) as JournalEvent.Seq, upTo)\n })\n\n/**\n * The fold of one run's entries up to and including `upTo`, for the state of\n * a checkpoint at `upTo`. It starts from the run's floor checkpoint when the\n * run was compacted before.\n *\n * @category operations\n * @since 1.0.0\n */\nexport const capture = Effect.fn(\"DeferredClockFold.capture\")(function*(runId: string, upTo: number) {\n return encode(yield* foldRun(runId, upTo))\n})\n\n/**\n * A checkpoint state that keeps the fold: `base` (an object, or nothing) with\n * the run's fold up to `upTo` under {@link checkpointKey}. A composition that\n * compacts runs writes its checkpoints through this, so compaction cannot\n * lose the deferred/clock history.\n *\n * @category operations\n * @since 1.0.0\n */\nexport const checkpointState = Effect.fn(\"DeferredClockFold.checkpointState\")(function*(\n runId: string,\n upTo: number,\n base?: Readonly<Record<string, unknown>> | undefined\n) {\n return { ...base, [checkpointKey]: yield* capture(runId, upTo) }\n})\n\n/**\n * What a {@link rebuild} read and wrote.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Rebuilt {\n /** Runs with deferred or clock entries, or with a compaction floor. */\n readonly runs: number\n /** Clock rows written. */\n readonly clocks: number\n /** Completion rows whose completion and consumption were rewritten. */\n readonly deferreds: number\n /** Completion rows no journal entry explains, left as they are. */\n readonly unexplained: number\n}\n\ninterface StoredDeferred {\n readonly flow_name: string\n readonly execution_id: string\n readonly deferred_name: string\n readonly exit_json: string\n readonly metadata_json: string | null\n}\n\n/**\n * Rebuilds `flows_clock_deadlines` and the completion and consumption stamps\n * of `flows_deferred_completions` from the journal.\n *\n * Every run with deferred or clock entries, and every compacted run, is\n * folded in sequence order, from its floor checkpoint when it was compacted;\n * a compacted run whose floor keeps no fold fails, even one that never had a\n * clock, because the journal can no longer say. Every reference is joined\n * before anything is written: a completion with no row or with other bytes,\n * a clock whose run is gone, or a compacted run whose floor keeps no fold\n * fails {@link FoldIncomplete} listing each one, and nothing is written.\n * Otherwise, in one writer transaction, the clock table is replaced by the\n * fold's clocks and each folded completion row gets the fold's\n * `completed_at_ms` and `consumed_at_ms`. A completion row the journal does\n * not explain is left alone and counted.\n *\n * Run it on a quiescent store, as a restore does.\n *\n * @category operations\n * @since 1.0.0\n */\nexport const rebuild = Effect.fn(\"DeferredClockFold.rebuild\")(function*() {\n const sql = yield* SqlClient.SqlClient\n const writer = yield* DurableWriter\n // A compacted run may have no fold entry left above its floor, so every run\n // with a compaction floor is folded too.\n const runs = yield* sql<{ readonly run_id: string }>`\n SELECT run_id FROM flows_journal_events WHERE ${sql.in(\"event_type\", eventTypes)}\n UNION\n SELECT run_id FROM flows_journal_checkpoints WHERE compacted_at_ms IS NOT NULL\n ORDER BY run_id\n `\n const unjoined: Array<Unjoined> = []\n const clocks: Array<Clock> = []\n const deferreds: Array<Deferred> = []\n for (const { run_id } of runs) {\n const state = yield* foldRun(run_id).pipe(\n Effect.catchTag(\"@smthrs/engine-store/DeferredClockFold/FoldIncomplete\", (error) => {\n unjoined.push(...error.unjoined)\n return Effect.succeed(initial)\n })\n )\n clocks.push(...state.clocks.values())\n deferreds.push(...state.deferreds.values())\n }\n const liveRuns = new Set(\n (yield* sql<{ readonly run_id: string }>`SELECT run_id FROM flows_runs`).map((row) => row.run_id)\n )\n for (const clock of clocks) {\n if (!liveRuns.has(clock.executionId)) {\n unjoined.push({\n reason: \"run_missing\",\n executionId: clock.executionId,\n flowName: clock.flowName,\n name: clock.clockName\n })\n }\n }\n const stored = new Map(\n (yield* sql<StoredDeferred>`\n SELECT flow_name, execution_id, deferred_name, exit_json, metadata_json\n FROM flows_deferred_completions\n `).map((row) => [\n deferredKey({ flowName: row.flow_name, executionId: row.execution_id, deferredName: row.deferred_name }),\n row\n ])\n )\n for (const deferred of deferreds) {\n const row = stored.get(deferredKey(deferred))\n const reference = { executionId: deferred.executionId, flowName: deferred.flowName, name: deferred.deferredName }\n if (row === undefined) {\n unjoined.push({ reason: \"row_missing\", ...reference })\n } else if (\n (deferred.exitDigest !== undefined && JournalEvent.contentDigest(row.exit_json) !== deferred.exitDigest) ||\n (deferred.metadataDigest !== undefined &&\n (row.metadata_json === null ? null : JournalEvent.contentDigest(row.metadata_json)) !==\n deferred.metadataDigest)\n ) {\n unjoined.push({ reason: \"digest_mismatch\", ...reference })\n }\n }\n if (unjoined.length > 0) {\n return yield* Effect.fail(\n new FoldIncomplete({\n code: \"fold_incomplete\",\n message: `the journal references ${unjoined.length} deferred/clock rows the store cannot join`,\n unjoined\n })\n )\n }\n yield* writer.write(Effect.gen(function*() {\n yield* sql`DELETE FROM flows_clock_deadlines`\n for (const clock of clocks) {\n yield* sql`\n INSERT INTO flows_clock_deadlines (\n flow_name, execution_id, clock_name, deferred_name, due_at_ms, completed_at_ms\n ) VALUES (\n ${clock.flowName}, ${clock.executionId}, ${clock.clockName}, ${clock.deferredName},\n ${clock.dueAtMs}, ${clock.completedAtMs}\n )\n `\n }\n for (const deferred of deferreds) {\n yield* sql`\n UPDATE flows_deferred_completions\n SET completed_at_ms = COALESCE(${deferred.completedAtMs}, completed_at_ms),\n consumed_at_ms = ${deferred.consumedAtMs}\n WHERE flow_name = ${deferred.flowName}\n AND execution_id = ${deferred.executionId}\n AND deferred_name = ${deferred.deferredName}\n `\n }\n }))\n return {\n runs: runs.length,\n clocks: clocks.length,\n deferreds: deferreds.length,\n unexplained: stored.size - deferreds.length\n } satisfies Rebuilt\n})\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkCA,2BAA8B;AAC9B,qBAAkD;AAClD,aAAwB;AACxB,aAAwB;AACxB,aAAwB;AACxB,gBAA2B;AAC3B,wBAA2B;AAQpB,MAAM,aAAoC;AAAA,EAC/C,6BAAW;AAAA,EACX,6BAAW;AAAA,EACX,6BAAW;AAAA,EACX,6BAAW;AACb;AAQO,MAAM,gBAAgB;AAE7B,M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AAAA;AAAA,IAEjD;AAAA,EACF,CAAC,CAAC;AACF,SAAO;AAAA,IACL,MAAM,KAAK;AAAA,IACX,QAAQ,OAAO;AAAA,IACf,WAAW,UAAU;AAAA,IACrB,aAAa,OAAO,OAAO,UAAU;AAAA,EACvC;AACF,CAAC;",
6
6
  "names": ["checkpointState"]
7
7
  }
@@ -42,7 +42,7 @@ import * as Effect from "effect/Effect";
42
42
  import * as FileSystem from "effect/FileSystem";
43
43
  import type * as Layer from "effect/Layer";
44
44
  import * as Schema from "effect/Schema";
45
- import * as SqlClient from "effect/unstable/sql/SqlClient";
45
+ import * as SqlClient from "effect/sql/SqlClient";
46
46
  /**
47
47
  * The database file name inside a backup directory and a restored store
48
48
  * directory.
@@ -1 +1 @@
1
- {"version":3,"file":"DisasterRecovery.d.ts","sourceRoot":"","sources":["../../src/DisasterRecovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AAE9D,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAA;AAG1D;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,kBAAkB,CAAA;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,kBAAkB,CAAA;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,YAAY,CAAA;AAE7C;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,kBAAkB,CAAA;AAErD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,QAAoB,CAAA;AAExD;;;;;;G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jB,CAAA;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;gEAiDlB,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;8DAmDhB,CAAA;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,EAClD,SAAS,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,KACpC,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,qBAAqB,GAAG,CAAC,EAAE,UAAU,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAOtG,CAAA"}
@@ -52,7 +52,7 @@ var Clock = __toESM(require("effect/Clock"), 1);
52
52
  var Effect = __toESM(require("effect/Effect"), 1);
53
53
  var FileSystem = __toESM(require("effect/FileSystem"), 1);
54
54
  var Schema = __toESM(require("effect/Schema"), 1);
55
- var SqlClient = __toESM(require("effect/unstable/sql/SqlClient"), 1);
55
+ var SqlClient = __toESM(require("effect/sql/SqlClient"), 1);
56
56
  var ArtifactRoots = __toESM(require("./internal/ArtifactRoots.js"), 1);
57
57
  const databaseFileName = "store.sqlite3";
58
58
  const manifestFileName = "manifest.json";