@smthrs/flow 0.0.0-stage → 1.0.0-rc.13

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 (654) hide show
  1. package/CHANGELOG.md +161 -0
  2. package/LICENSE +21 -0
  3. package/README.md +212 -2
  4. package/THIRD_PARTY_NOTICES.md +52 -0
  5. package/dist/cjs/Action/Action.d.ts +250 -0
  6. package/dist/cjs/Action/Action.d.ts.map +1 -0
  7. package/dist/cjs/Action/Action.js +42 -0
  8. package/dist/cjs/Action/Action.js.map +7 -0
  9. package/dist/cjs/Action/AttemptTimedOut.d.ts +33 -0
  10. package/dist/cjs/Action/AttemptTimedOut.d.ts.map +1 -0
  11. package/dist/cjs/Action/AttemptTimedOut.js +51 -0
  12. package/dist/cjs/Action/AttemptTimedOut.js.map +7 -0
  13. package/dist/cjs/Action/BoundaryMode.d.ts +29 -0
  14. package/dist/cjs/Action/BoundaryMode.d.ts.map +1 -0
  15. package/dist/cjs/Action/BoundaryMode.js +36 -0
  16. package/dist/cjs/Action/BoundaryMode.js.map +7 -0
  17. package/dist/cjs/Action/CacheEnvironment.d.ts +158 -0
  18. package/dist/cjs/Action/CacheEnvironment.d.ts.map +1 -0
  19. package/dist/cjs/Action/CacheEnvironment.js +57 -0
  20. package/dist/cjs/Action/CacheEnvironment.js.map +7 -0
  21. package/dist/cjs/Action/ConcurrentKeylessDispatch.d.ts +34 -0
  22. package/dist/cjs/Action/ConcurrentKeylessDispatch.d.ts.map +1 -0
  23. package/dist/cjs/Action/ConcurrentKeylessDispatch.js +46 -0
  24. package/dist/cjs/Action/ConcurrentKeylessDispatch.js.map +7 -0
  25. package/dist/cjs/Action/Context.d.ts +131 -0
  26. package/dist/cjs/Action/Context.d.ts.map +1 -0
  27. package/dist/cjs/Action/Context.js +68 -0
  28. package/dist/cjs/Action/Context.js.map +7 -0
  29. package/dist/cjs/Action/DuplicateImplementation.d.ts +20 -0
  30. package/dist/cjs/Action/DuplicateImplementation.d.ts.map +1 -0
  31. package/dist/cjs/Action/DuplicateImplementation.js +46 -0
  32. package/dist/cjs/Action/DuplicateImplementation.js.map +7 -0
  33. package/dist/cjs/Action/FileBoundary.d.ts +59 -0
  34. package/dist/cjs/Action/FileBoundary.d.ts.map +1 -0
  35. package/dist/cjs/Action/FileBoundary.js +81 -0
  36. package/dist/cjs/Action/FileBoundary.js.map +7 -0
  37. package/dist/cjs/Action/FileInput.d.ts +28 -0
  38. package/dist/cjs/Action/FileInput.d.ts.map +1 -0
  39. package/dist/cjs/Action/FileInput.js +42 -0
  40. package/dist/cjs/Action/FileInput.js.map +7 -0
  41. package/dist/cjs/Action/Filegroup.d.ts +16 -0
  42. package/dist/cjs/Action/Filegroup.d.ts.map +1 -0
  43. package/dist/cjs/Action/Filegroup.js +27 -0
  44. package/dist/cjs/Action/Filegroup.js.map +7 -0
  45. package/dist/cjs/Action/Glob.d.ts +8 -0
  46. package/dist/cjs/Action/Glob.d.ts.map +1 -0
  47. package/dist/cjs/Action/Glob.js +28 -0
  48. package/dist/cjs/Action/Glob.js.map +7 -0
  49. package/dist/cjs/Action/ImplementationVersionMismatch.d.ts +26 -0
  50. package/dist/cjs/Action/ImplementationVersionMismatch.d.ts.map +1 -0
  51. package/dist/cjs/Action/ImplementationVersionMismatch.js +45 -0
  52. package/dist/cjs/Action/ImplementationVersionMismatch.js.map +7 -0
  53. package/dist/cjs/Action/Implementations.d.ts +114 -0
  54. package/dist/cjs/Action/Implementations.d.ts.map +1 -0
  55. package/dist/cjs/Action/Implementations.js +65 -0
  56. package/dist/cjs/Action/Implementations.js.map +7 -0
  57. package/dist/cjs/Action/InfraInterrupt.d.ts +26 -0
  58. package/dist/cjs/Action/InfraInterrupt.d.ts.map +1 -0
  59. package/dist/cjs/Action/InfraInterrupt.js +46 -0
  60. package/dist/cjs/Action/InfraInterrupt.js.map +7 -0
  61. package/dist/cjs/Action/InfraInterruptRetriesExhausted.d.ts +33 -0
  62. package/dist/cjs/Action/InfraInterruptRetriesExhausted.d.ts.map +1 -0
  63. package/dist/cjs/Action/InfraInterruptRetriesExhausted.js +54 -0
  64. package/dist/cjs/Action/InfraInterruptRetriesExhausted.js.map +7 -0
  65. package/dist/cjs/Action/IrreversibleRetryRequiresIdempotencyKey.d.ts +26 -0
  66. package/dist/cjs/Action/IrreversibleRetryRequiresIdempotencyKey.d.ts.map +1 -0
  67. package/dist/cjs/Action/IrreversibleRetryRequiresIdempotencyKey.js +47 -0
  68. package/dist/cjs/Action/IrreversibleRetryRequiresIdempotencyKey.js.map +7 -0
  69. package/dist/cjs/Action/StepIdentity.d.ts +153 -0
  70. package/dist/cjs/Action/StepIdentity.d.ts.map +1 -0
  71. package/dist/cjs/Action/StepIdentity.js +75 -0
  72. package/dist/cjs/Action/StepIdentity.js.map +7 -0
  73. package/dist/cjs/Action/TreeArtifact.d.ts +8 -0
  74. package/dist/cjs/Action/TreeArtifact.d.ts.map +1 -0
  75. package/dist/cjs/Action/TreeArtifact.js +25 -0
  76. package/dist/cjs/Action/TreeArtifact.js.map +7 -0
  77. package/dist/cjs/Action/TypeId.d.ts +8 -0
  78. package/dist/cjs/Action/TypeId.d.ts.map +1 -0
  79. package/dist/cjs/Action/TypeId.js +25 -0
  80. package/dist/cjs/Action/TypeId.js.map +7 -0
  81. package/dist/cjs/Action/UncanonicalIdempotencyKey.d.ts +32 -0
  82. package/dist/cjs/Action/UncanonicalIdempotencyKey.d.ts.map +1 -0
  83. package/dist/cjs/Action/UncanonicalIdempotencyKey.js +51 -0
  84. package/dist/cjs/Action/UncanonicalIdempotencyKey.js.map +7 -0
  85. package/dist/cjs/Action/idempotencyKey.d.ts +21 -0
  86. package/dist/cjs/Action/idempotencyKey.d.ts.map +1 -0
  87. package/dist/cjs/Action/idempotencyKey.js +59 -0
  88. package/dist/cjs/Action/idempotencyKey.js.map +7 -0
  89. package/dist/cjs/Action/index.d.ts +29 -0
  90. package/dist/cjs/Action/index.d.ts.map +1 -0
  91. package/dist/cjs/Action/index.js +60 -0
  92. package/dist/cjs/Action/index.js.map +7 -0
  93. package/dist/cjs/Action/make.d.ts +128 -0
  94. package/dist/cjs/Action/make.d.ts.map +1 -0
  95. package/dist/cjs/Action/make.js +387 -0
  96. package/dist/cjs/Action/make.js.map +7 -0
  97. package/dist/cjs/Action/raceAll.d.ts +21 -0
  98. package/dist/cjs/Action/raceAll.d.ts.map +1 -0
  99. package/dist/cjs/Action/raceAll.js +46 -0
  100. package/dist/cjs/Action/raceAll.js.map +7 -0
  101. package/dist/cjs/Action/retry.d.ts +19 -0
  102. package/dist/cjs/Action/retry.d.ts.map +1 -0
  103. package/dist/cjs/Action/retry.js +75 -0
  104. package/dist/cjs/Action/retry.js.map +7 -0
  105. package/dist/cjs/Deadline.d.ts +110 -0
  106. package/dist/cjs/Deadline.d.ts.map +1 -0
  107. package/dist/cjs/Deadline.js +112 -0
  108. package/dist/cjs/Deadline.js.map +7 -0
  109. package/dist/cjs/DurableClock.d.ts +60 -0
  110. package/dist/cjs/DurableClock.d.ts.map +1 -0
  111. package/dist/cjs/DurableClock.js +107 -0
  112. package/dist/cjs/DurableClock.js.map +7 -0
  113. package/dist/cjs/DurableDeferred.d.ts +311 -0
  114. package/dist/cjs/DurableDeferred.d.ts.map +1 -0
  115. package/dist/cjs/DurableDeferred.js +322 -0
  116. package/dist/cjs/DurableDeferred.js.map +7 -0
  117. package/dist/cjs/DurableQueue.d.ts +160 -0
  118. package/dist/cjs/DurableQueue.d.ts.map +1 -0
  119. package/dist/cjs/DurableQueue.js +229 -0
  120. package/dist/cjs/DurableQueue.js.map +7 -0
  121. package/dist/cjs/ExternalJob.d.ts +179 -0
  122. package/dist/cjs/ExternalJob.d.ts.map +1 -0
  123. package/dist/cjs/ExternalJob.js +339 -0
  124. package/dist/cjs/ExternalJob.js.map +7 -0
  125. package/dist/cjs/Fault.d.ts +131 -0
  126. package/dist/cjs/Fault.d.ts.map +1 -0
  127. package/dist/cjs/Fault.js +157 -0
  128. package/dist/cjs/Fault.js.map +7 -0
  129. package/dist/cjs/Flow/Annotations.d.ts +245 -0
  130. package/dist/cjs/Flow/Annotations.d.ts.map +1 -0
  131. package/dist/cjs/Flow/Annotations.js +72 -0
  132. package/dist/cjs/Flow/Annotations.js.map +7 -0
  133. package/dist/cjs/Flow/CapabilityCeiling.d.ts +21 -0
  134. package/dist/cjs/Flow/CapabilityCeiling.d.ts.map +1 -0
  135. package/dist/cjs/Flow/CapabilityCeiling.js +49 -0
  136. package/dist/cjs/Flow/CapabilityCeiling.js.map +7 -0
  137. package/dist/cjs/Flow/DeadlineExceeded.d.ts +33 -0
  138. package/dist/cjs/Flow/DeadlineExceeded.d.ts.map +1 -0
  139. package/dist/cjs/Flow/DeadlineExceeded.js +52 -0
  140. package/dist/cjs/Flow/DeadlineExceeded.js.map +7 -0
  141. package/dist/cjs/Flow/ExecutionIdRequired.d.ts +25 -0
  142. package/dist/cjs/Flow/ExecutionIdRequired.d.ts.map +1 -0
  143. package/dist/cjs/Flow/ExecutionIdRequired.js +46 -0
  144. package/dist/cjs/Flow/ExecutionIdRequired.js.map +7 -0
  145. package/dist/cjs/Flow/ExecutionIds.d.ts +80 -0
  146. package/dist/cjs/Flow/ExecutionIds.d.ts.map +1 -0
  147. package/dist/cjs/Flow/ExecutionIds.js +66 -0
  148. package/dist/cjs/Flow/ExecutionIds.js.map +7 -0
  149. package/dist/cjs/Flow/Flow.d.ts +422 -0
  150. package/dist/cjs/Flow/Flow.d.ts.map +1 -0
  151. package/dist/cjs/Flow/Flow.js +17 -0
  152. package/dist/cjs/Flow/Flow.js.map +7 -0
  153. package/dist/cjs/Flow/MaxRoundsExceeded.d.ts +35 -0
  154. package/dist/cjs/Flow/MaxRoundsExceeded.d.ts.map +1 -0
  155. package/dist/cjs/Flow/MaxRoundsExceeded.js +50 -0
  156. package/dist/cjs/Flow/MaxRoundsExceeded.js.map +7 -0
  157. package/dist/cjs/Flow/Outcome.d.ts +162 -0
  158. package/dist/cjs/Flow/Outcome.d.ts.map +1 -0
  159. package/dist/cjs/Flow/Outcome.js +80 -0
  160. package/dist/cjs/Flow/Outcome.js.map +7 -0
  161. package/dist/cjs/Flow/Result.d.ts +186 -0
  162. package/dist/cjs/Flow/Result.d.ts.map +1 -0
  163. package/dist/cjs/Flow/Result.js +159 -0
  164. package/dist/cjs/Flow/Result.js.map +7 -0
  165. package/dist/cjs/Flow/Runtime.d.ts +98 -0
  166. package/dist/cjs/Flow/Runtime.d.ts.map +1 -0
  167. package/dist/cjs/Flow/Runtime.js +186 -0
  168. package/dist/cjs/Flow/Runtime.js.map +7 -0
  169. package/dist/cjs/Flow/TypeId.d.ts +8 -0
  170. package/dist/cjs/Flow/TypeId.d.ts.map +1 -0
  171. package/dist/cjs/Flow/TypeId.js +25 -0
  172. package/dist/cjs/Flow/TypeId.js.map +7 -0
  173. package/dist/cjs/Flow/index.d.ts +17 -0
  174. package/dist/cjs/Flow/index.d.ts.map +1 -0
  175. package/dist/cjs/Flow/index.js +29 -0
  176. package/dist/cjs/Flow/index.js.map +7 -0
  177. package/dist/cjs/Flow/internal.d.ts +34 -0
  178. package/dist/cjs/Flow/internal.d.ts.map +1 -0
  179. package/dist/cjs/Flow/internal.js +187 -0
  180. package/dist/cjs/Flow/internal.js.map +7 -0
  181. package/dist/cjs/Flow/make.d.ts +149 -0
  182. package/dist/cjs/Flow/make.d.ts.map +1 -0
  183. package/dist/cjs/Flow/make.js +107 -0
  184. package/dist/cjs/Flow/make.js.map +7 -0
  185. package/dist/cjs/FlowRuntime/CancelRequestFailed.d.ts +55 -0
  186. package/dist/cjs/FlowRuntime/CancelRequestFailed.d.ts.map +1 -0
  187. package/dist/cjs/FlowRuntime/CancelRequestFailed.js +51 -0
  188. package/dist/cjs/FlowRuntime/CancelRequestFailed.js.map +7 -0
  189. package/dist/cjs/FlowRuntime/ExecutionIdentityConflict.d.ts +23 -0
  190. package/dist/cjs/FlowRuntime/ExecutionIdentityConflict.d.ts.map +1 -0
  191. package/dist/cjs/FlowRuntime/ExecutionIdentityConflict.js +55 -0
  192. package/dist/cjs/FlowRuntime/ExecutionIdentityConflict.js.map +7 -0
  193. package/dist/cjs/FlowRuntime/FlowCycleDetected.d.ts +28 -0
  194. package/dist/cjs/FlowRuntime/FlowCycleDetected.d.ts.map +1 -0
  195. package/dist/cjs/FlowRuntime/FlowCycleDetected.js +49 -0
  196. package/dist/cjs/FlowRuntime/FlowCycleDetected.js.map +7 -0
  197. package/dist/cjs/FlowRuntime/FlowExecutionNotFound.d.ts +38 -0
  198. package/dist/cjs/FlowRuntime/FlowExecutionNotFound.d.ts.map +1 -0
  199. package/dist/cjs/FlowRuntime/FlowExecutionNotFound.js +53 -0
  200. package/dist/cjs/FlowRuntime/FlowExecutionNotFound.js.map +7 -0
  201. package/dist/cjs/FlowRuntime/FlowInstance.d.ts +115 -0
  202. package/dist/cjs/FlowRuntime/FlowInstance.d.ts.map +1 -0
  203. package/dist/cjs/FlowRuntime/FlowInstance.js +37 -0
  204. package/dist/cjs/FlowRuntime/FlowInstance.js.map +7 -0
  205. package/dist/cjs/FlowRuntime/FlowRuntime.d.ts +204 -0
  206. package/dist/cjs/FlowRuntime/FlowRuntime.d.ts.map +1 -0
  207. package/dist/cjs/FlowRuntime/FlowRuntime.js +37 -0
  208. package/dist/cjs/FlowRuntime/FlowRuntime.js.map +7 -0
  209. package/dist/cjs/FlowRuntime/NodeRecord.d.ts +177 -0
  210. package/dist/cjs/FlowRuntime/NodeRecord.d.ts.map +1 -0
  211. package/dist/cjs/FlowRuntime/NodeRecord.js +17 -0
  212. package/dist/cjs/FlowRuntime/NodeRecord.js.map +7 -0
  213. package/dist/cjs/FlowRuntime/WaitingAnnotation.d.ts +69 -0
  214. package/dist/cjs/FlowRuntime/WaitingAnnotation.d.ts.map +1 -0
  215. package/dist/cjs/FlowRuntime/WaitingAnnotation.js +53 -0
  216. package/dist/cjs/FlowRuntime/WaitingAnnotation.js.map +7 -0
  217. package/dist/cjs/FlowRuntime/index.d.ts +14 -0
  218. package/dist/cjs/FlowRuntime/index.d.ts.map +1 -0
  219. package/dist/cjs/FlowRuntime/index.js +26 -0
  220. package/dist/cjs/FlowRuntime/index.js.map +7 -0
  221. package/dist/cjs/Graph.d.ts +325 -0
  222. package/dist/cjs/Graph.d.ts.map +1 -0
  223. package/dist/cjs/Graph.js +1020 -0
  224. package/dist/cjs/Graph.js.map +7 -0
  225. package/dist/cjs/HumanTask.d.ts +442 -0
  226. package/dist/cjs/HumanTask.d.ts.map +1 -0
  227. package/dist/cjs/HumanTask.js +422 -0
  228. package/dist/cjs/HumanTask.js.map +7 -0
  229. package/dist/cjs/Interpreter.d.ts +223 -0
  230. package/dist/cjs/Interpreter.d.ts.map +1 -0
  231. package/dist/cjs/Interpreter.js +919 -0
  232. package/dist/cjs/Interpreter.js.map +7 -0
  233. package/dist/cjs/Poll.d.ts +240 -0
  234. package/dist/cjs/Poll.d.ts.map +1 -0
  235. package/dist/cjs/Poll.js +154 -0
  236. package/dist/cjs/Poll.js.map +7 -0
  237. package/dist/cjs/RetryPolicy.d.ts +273 -0
  238. package/dist/cjs/RetryPolicy.d.ts.map +1 -0
  239. package/dist/cjs/RetryPolicy.js +251 -0
  240. package/dist/cjs/RetryPolicy.js.map +7 -0
  241. package/dist/cjs/Sleep.d.ts +98 -0
  242. package/dist/cjs/Sleep.d.ts.map +1 -0
  243. package/dist/cjs/Sleep.js +141 -0
  244. package/dist/cjs/Sleep.js.map +7 -0
  245. package/dist/cjs/Stall.d.ts +173 -0
  246. package/dist/cjs/Stall.d.ts.map +1 -0
  247. package/dist/cjs/Stall.js +92 -0
  248. package/dist/cjs/Stall.js.map +7 -0
  249. package/dist/cjs/WaitFor.d.ts +109 -0
  250. package/dist/cjs/WaitFor.d.ts.map +1 -0
  251. package/dist/cjs/WaitFor.js +117 -0
  252. package/dist/cjs/WaitFor.js.map +7 -0
  253. package/dist/cjs/index.d.ts +107 -0
  254. package/dist/cjs/index.d.ts.map +1 -0
  255. package/dist/cjs/index.js +69 -0
  256. package/dist/cjs/index.js.map +7 -0
  257. package/dist/cjs/internal/BoundedJson.d.ts +48 -0
  258. package/dist/cjs/internal/BoundedJson.d.ts.map +1 -0
  259. package/dist/cjs/internal/BoundedJson.js +96 -0
  260. package/dist/cjs/internal/BoundedJson.js.map +7 -0
  261. package/dist/cjs/internal/DeclarationSite.d.ts +135 -0
  262. package/dist/cjs/internal/DeclarationSite.d.ts.map +1 -0
  263. package/dist/cjs/internal/DeclarationSite.js +89 -0
  264. package/dist/cjs/internal/DeclarationSite.js.map +7 -0
  265. package/dist/cjs/internal/Declarations.d.ts +35 -0
  266. package/dist/cjs/internal/Declarations.d.ts.map +1 -0
  267. package/dist/cjs/internal/Declarations.js +50 -0
  268. package/dist/cjs/internal/Declarations.js.map +7 -0
  269. package/dist/cjs/internal/ExecutionMiddleware.d.ts +21 -0
  270. package/dist/cjs/internal/ExecutionMiddleware.d.ts.map +1 -0
  271. package/dist/cjs/internal/ExecutionMiddleware.js +39 -0
  272. package/dist/cjs/internal/ExecutionMiddleware.js.map +7 -0
  273. package/dist/cjs/internal/JsonSchemaSubset.d.ts +133 -0
  274. package/dist/cjs/internal/JsonSchemaSubset.d.ts.map +1 -0
  275. package/dist/cjs/internal/JsonSchemaSubset.js +229 -0
  276. package/dist/cjs/internal/JsonSchemaSubset.js.map +7 -0
  277. package/dist/cjs/internal/OutcomeMarker.d.ts +18 -0
  278. package/dist/cjs/internal/OutcomeMarker.d.ts.map +1 -0
  279. package/dist/cjs/internal/OutcomeMarker.js +27 -0
  280. package/dist/cjs/internal/OutcomeMarker.js.map +7 -0
  281. package/dist/cjs/package.json +1 -0
  282. package/dist/esm/Action/Action.d.ts +250 -0
  283. package/dist/esm/Action/Action.d.ts.map +1 -0
  284. package/dist/esm/Action/Action.js +30 -0
  285. package/dist/esm/Action/Action.js.map +1 -0
  286. package/dist/esm/Action/AttemptTimedOut.d.ts +33 -0
  287. package/dist/esm/Action/AttemptTimedOut.d.ts.map +1 -0
  288. package/dist/esm/Action/AttemptTimedOut.js +32 -0
  289. package/dist/esm/Action/AttemptTimedOut.js.map +1 -0
  290. package/dist/esm/Action/BoundaryMode.d.ts +29 -0
  291. package/dist/esm/Action/BoundaryMode.d.ts.map +1 -0
  292. package/dist/esm/Action/BoundaryMode.js +23 -0
  293. package/dist/esm/Action/BoundaryMode.js.map +1 -0
  294. package/dist/esm/Action/CacheEnvironment.d.ts +158 -0
  295. package/dist/esm/Action/CacheEnvironment.d.ts.map +1 -0
  296. package/dist/esm/Action/CacheEnvironment.js +130 -0
  297. package/dist/esm/Action/CacheEnvironment.js.map +1 -0
  298. package/dist/esm/Action/ConcurrentKeylessDispatch.d.ts +34 -0
  299. package/dist/esm/Action/ConcurrentKeylessDispatch.d.ts.map +1 -0
  300. package/dist/esm/Action/ConcurrentKeylessDispatch.js +33 -0
  301. package/dist/esm/Action/ConcurrentKeylessDispatch.js.map +1 -0
  302. package/dist/esm/Action/Context.d.ts +131 -0
  303. package/dist/esm/Action/Context.d.ts.map +1 -0
  304. package/dist/esm/Action/Context.js +99 -0
  305. package/dist/esm/Action/Context.js.map +1 -0
  306. package/dist/esm/Action/DuplicateImplementation.d.ts +20 -0
  307. package/dist/esm/Action/DuplicateImplementation.d.ts.map +1 -0
  308. package/dist/esm/Action/DuplicateImplementation.js +20 -0
  309. package/dist/esm/Action/DuplicateImplementation.js.map +1 -0
  310. package/dist/esm/Action/FileBoundary.d.ts +59 -0
  311. package/dist/esm/Action/FileBoundary.d.ts.map +1 -0
  312. package/dist/esm/Action/FileBoundary.js +60 -0
  313. package/dist/esm/Action/FileBoundary.js.map +1 -0
  314. package/dist/esm/Action/FileInput.d.ts +28 -0
  315. package/dist/esm/Action/FileInput.d.ts.map +1 -0
  316. package/dist/esm/Action/FileInput.js +32 -0
  317. package/dist/esm/Action/FileInput.js.map +1 -0
  318. package/dist/esm/Action/Filegroup.d.ts +16 -0
  319. package/dist/esm/Action/Filegroup.d.ts.map +1 -0
  320. package/dist/esm/Action/Filegroup.js +15 -0
  321. package/dist/esm/Action/Filegroup.js.map +1 -0
  322. package/dist/esm/Action/Glob.d.ts +8 -0
  323. package/dist/esm/Action/Glob.d.ts.map +1 -0
  324. package/dist/esm/Action/Glob.js +7 -0
  325. package/dist/esm/Action/Glob.js.map +1 -0
  326. package/dist/esm/Action/ImplementationVersionMismatch.d.ts +26 -0
  327. package/dist/esm/Action/ImplementationVersionMismatch.d.ts.map +1 -0
  328. package/dist/esm/Action/ImplementationVersionMismatch.js +24 -0
  329. package/dist/esm/Action/ImplementationVersionMismatch.js.map +1 -0
  330. package/dist/esm/Action/Implementations.d.ts +114 -0
  331. package/dist/esm/Action/Implementations.d.ts.map +1 -0
  332. package/dist/esm/Action/Implementations.js +94 -0
  333. package/dist/esm/Action/Implementations.js.map +1 -0
  334. package/dist/esm/Action/InfraInterrupt.d.ts +26 -0
  335. package/dist/esm/Action/InfraInterrupt.d.ts.map +1 -0
  336. package/dist/esm/Action/InfraInterrupt.js +25 -0
  337. package/dist/esm/Action/InfraInterrupt.js.map +1 -0
  338. package/dist/esm/Action/InfraInterruptRetriesExhausted.d.ts +33 -0
  339. package/dist/esm/Action/InfraInterruptRetriesExhausted.d.ts.map +1 -0
  340. package/dist/esm/Action/InfraInterruptRetriesExhausted.js +32 -0
  341. package/dist/esm/Action/InfraInterruptRetriesExhausted.js.map +1 -0
  342. package/dist/esm/Action/IrreversibleRetryRequiresIdempotencyKey.d.ts +26 -0
  343. package/dist/esm/Action/IrreversibleRetryRequiresIdempotencyKey.d.ts.map +1 -0
  344. package/dist/esm/Action/IrreversibleRetryRequiresIdempotencyKey.js +25 -0
  345. package/dist/esm/Action/IrreversibleRetryRequiresIdempotencyKey.js.map +1 -0
  346. package/dist/esm/Action/StepIdentity.d.ts +153 -0
  347. package/dist/esm/Action/StepIdentity.d.ts.map +1 -0
  348. package/dist/esm/Action/StepIdentity.js +139 -0
  349. package/dist/esm/Action/StepIdentity.js.map +1 -0
  350. package/dist/esm/Action/TreeArtifact.d.ts +8 -0
  351. package/dist/esm/Action/TreeArtifact.d.ts.map +1 -0
  352. package/dist/esm/Action/TreeArtifact.js +7 -0
  353. package/dist/esm/Action/TreeArtifact.js.map +1 -0
  354. package/dist/esm/Action/TypeId.d.ts +8 -0
  355. package/dist/esm/Action/TypeId.d.ts.map +1 -0
  356. package/dist/esm/Action/TypeId.js +9 -0
  357. package/dist/esm/Action/TypeId.js.map +1 -0
  358. package/dist/esm/Action/UncanonicalIdempotencyKey.d.ts +32 -0
  359. package/dist/esm/Action/UncanonicalIdempotencyKey.d.ts.map +1 -0
  360. package/dist/esm/Action/UncanonicalIdempotencyKey.js +31 -0
  361. package/dist/esm/Action/UncanonicalIdempotencyKey.js.map +1 -0
  362. package/dist/esm/Action/idempotencyKey.d.ts +21 -0
  363. package/dist/esm/Action/idempotencyKey.d.ts.map +1 -0
  364. package/dist/esm/Action/idempotencyKey.js +50 -0
  365. package/dist/esm/Action/idempotencyKey.js.map +1 -0
  366. package/dist/esm/Action/index.d.ts +29 -0
  367. package/dist/esm/Action/index.d.ts.map +1 -0
  368. package/dist/esm/Action/index.js +30 -0
  369. package/dist/esm/Action/index.js.map +1 -0
  370. package/dist/esm/Action/make.d.ts +128 -0
  371. package/dist/esm/Action/make.d.ts.map +1 -0
  372. package/dist/esm/Action/make.js +413 -0
  373. package/dist/esm/Action/make.js.map +1 -0
  374. package/dist/esm/Action/raceAll.d.ts +21 -0
  375. package/dist/esm/Action/raceAll.d.ts.map +1 -0
  376. package/dist/esm/Action/raceAll.js +20 -0
  377. package/dist/esm/Action/raceAll.js.map +1 -0
  378. package/dist/esm/Action/retry.d.ts +19 -0
  379. package/dist/esm/Action/retry.d.ts.map +1 -0
  380. package/dist/esm/Action/retry.js +72 -0
  381. package/dist/esm/Action/retry.js.map +1 -0
  382. package/dist/esm/Deadline.d.ts +110 -0
  383. package/dist/esm/Deadline.d.ts.map +1 -0
  384. package/dist/esm/Deadline.js +164 -0
  385. package/dist/esm/Deadline.js.map +1 -0
  386. package/dist/esm/DurableClock.d.ts +60 -0
  387. package/dist/esm/DurableClock.d.ts.map +1 -0
  388. package/dist/esm/DurableClock.js +122 -0
  389. package/dist/esm/DurableClock.js.map +1 -0
  390. package/dist/esm/DurableDeferred.d.ts +311 -0
  391. package/dist/esm/DurableDeferred.d.ts.map +1 -0
  392. package/dist/esm/DurableDeferred.js +357 -0
  393. package/dist/esm/DurableDeferred.js.map +1 -0
  394. package/dist/esm/DurableQueue.d.ts +160 -0
  395. package/dist/esm/DurableQueue.d.ts.map +1 -0
  396. package/dist/esm/DurableQueue.js +303 -0
  397. package/dist/esm/DurableQueue.js.map +1 -0
  398. package/dist/esm/ExternalJob.d.ts +179 -0
  399. package/dist/esm/ExternalJob.d.ts.map +1 -0
  400. package/dist/esm/ExternalJob.js +296 -0
  401. package/dist/esm/ExternalJob.js.map +1 -0
  402. package/dist/esm/Fault.d.ts +131 -0
  403. package/dist/esm/Fault.d.ts.map +1 -0
  404. package/dist/esm/Fault.js +198 -0
  405. package/dist/esm/Fault.js.map +1 -0
  406. package/dist/esm/Flow/Annotations.d.ts +245 -0
  407. package/dist/esm/Flow/Annotations.d.ts.map +1 -0
  408. package/dist/esm/Flow/Annotations.js +110 -0
  409. package/dist/esm/Flow/Annotations.js.map +1 -0
  410. package/dist/esm/Flow/CapabilityCeiling.d.ts +21 -0
  411. package/dist/esm/Flow/CapabilityCeiling.d.ts.map +1 -0
  412. package/dist/esm/Flow/CapabilityCeiling.js +27 -0
  413. package/dist/esm/Flow/CapabilityCeiling.js.map +1 -0
  414. package/dist/esm/Flow/DeadlineExceeded.d.ts +33 -0
  415. package/dist/esm/Flow/DeadlineExceeded.d.ts.map +1 -0
  416. package/dist/esm/Flow/DeadlineExceeded.js +34 -0
  417. package/dist/esm/Flow/DeadlineExceeded.js.map +1 -0
  418. package/dist/esm/Flow/ExecutionIdRequired.d.ts +25 -0
  419. package/dist/esm/Flow/ExecutionIdRequired.d.ts.map +1 -0
  420. package/dist/esm/Flow/ExecutionIdRequired.js +30 -0
  421. package/dist/esm/Flow/ExecutionIdRequired.js.map +1 -0
  422. package/dist/esm/Flow/ExecutionIds.d.ts +80 -0
  423. package/dist/esm/Flow/ExecutionIds.d.ts.map +1 -0
  424. package/dist/esm/Flow/ExecutionIds.js +91 -0
  425. package/dist/esm/Flow/ExecutionIds.js.map +1 -0
  426. package/dist/esm/Flow/Flow.d.ts +422 -0
  427. package/dist/esm/Flow/Flow.d.ts.map +1 -0
  428. package/dist/esm/Flow/Flow.js +3 -0
  429. package/dist/esm/Flow/Flow.js.map +1 -0
  430. package/dist/esm/Flow/MaxRoundsExceeded.d.ts +35 -0
  431. package/dist/esm/Flow/MaxRoundsExceeded.d.ts.map +1 -0
  432. package/dist/esm/Flow/MaxRoundsExceeded.js +34 -0
  433. package/dist/esm/Flow/MaxRoundsExceeded.js.map +1 -0
  434. package/dist/esm/Flow/Outcome.d.ts +162 -0
  435. package/dist/esm/Flow/Outcome.d.ts.map +1 -0
  436. package/dist/esm/Flow/Outcome.js +115 -0
  437. package/dist/esm/Flow/Outcome.js.map +1 -0
  438. package/dist/esm/Flow/Result.d.ts +186 -0
  439. package/dist/esm/Flow/Result.d.ts.map +1 -0
  440. package/dist/esm/Flow/Result.js +171 -0
  441. package/dist/esm/Flow/Result.js.map +1 -0
  442. package/dist/esm/Flow/Runtime.d.ts +98 -0
  443. package/dist/esm/Flow/Runtime.d.ts.map +1 -0
  444. package/dist/esm/Flow/Runtime.js +252 -0
  445. package/dist/esm/Flow/Runtime.js.map +1 -0
  446. package/dist/esm/Flow/TypeId.d.ts +8 -0
  447. package/dist/esm/Flow/TypeId.d.ts.map +1 -0
  448. package/dist/esm/Flow/TypeId.js +9 -0
  449. package/dist/esm/Flow/TypeId.js.map +1 -0
  450. package/dist/esm/Flow/index.d.ts +17 -0
  451. package/dist/esm/Flow/index.d.ts.map +1 -0
  452. package/dist/esm/Flow/index.js +18 -0
  453. package/dist/esm/Flow/index.js.map +1 -0
  454. package/dist/esm/Flow/internal.d.ts +34 -0
  455. package/dist/esm/Flow/internal.d.ts.map +1 -0
  456. package/dist/esm/Flow/internal.js +149 -0
  457. package/dist/esm/Flow/internal.js.map +1 -0
  458. package/dist/esm/Flow/make.d.ts +149 -0
  459. package/dist/esm/Flow/make.d.ts.map +1 -0
  460. package/dist/esm/Flow/make.js +111 -0
  461. package/dist/esm/Flow/make.js.map +1 -0
  462. package/dist/esm/FlowRuntime/CancelRequestFailed.d.ts +55 -0
  463. package/dist/esm/FlowRuntime/CancelRequestFailed.d.ts.map +1 -0
  464. package/dist/esm/FlowRuntime/CancelRequestFailed.js +53 -0
  465. package/dist/esm/FlowRuntime/CancelRequestFailed.js.map +1 -0
  466. package/dist/esm/FlowRuntime/ExecutionIdentityConflict.d.ts +23 -0
  467. package/dist/esm/FlowRuntime/ExecutionIdentityConflict.d.ts.map +1 -0
  468. package/dist/esm/FlowRuntime/ExecutionIdentityConflict.js +24 -0
  469. package/dist/esm/FlowRuntime/ExecutionIdentityConflict.js.map +1 -0
  470. package/dist/esm/FlowRuntime/FlowCycleDetected.d.ts +28 -0
  471. package/dist/esm/FlowRuntime/FlowCycleDetected.d.ts.map +1 -0
  472. package/dist/esm/FlowRuntime/FlowCycleDetected.js +35 -0
  473. package/dist/esm/FlowRuntime/FlowCycleDetected.js.map +1 -0
  474. package/dist/esm/FlowRuntime/FlowExecutionNotFound.d.ts +38 -0
  475. package/dist/esm/FlowRuntime/FlowExecutionNotFound.d.ts.map +1 -0
  476. package/dist/esm/FlowRuntime/FlowExecutionNotFound.js +40 -0
  477. package/dist/esm/FlowRuntime/FlowExecutionNotFound.js.map +1 -0
  478. package/dist/esm/FlowRuntime/FlowInstance.d.ts +115 -0
  479. package/dist/esm/FlowRuntime/FlowInstance.d.ts.map +1 -0
  480. package/dist/esm/FlowRuntime/FlowInstance.js +24 -0
  481. package/dist/esm/FlowRuntime/FlowInstance.js.map +1 -0
  482. package/dist/esm/FlowRuntime/FlowRuntime.d.ts +204 -0
  483. package/dist/esm/FlowRuntime/FlowRuntime.d.ts.map +1 -0
  484. package/dist/esm/FlowRuntime/FlowRuntime.js +34 -0
  485. package/dist/esm/FlowRuntime/FlowRuntime.js.map +1 -0
  486. package/dist/esm/FlowRuntime/NodeRecord.d.ts +177 -0
  487. package/dist/esm/FlowRuntime/NodeRecord.d.ts.map +1 -0
  488. package/dist/esm/FlowRuntime/NodeRecord.js +21 -0
  489. package/dist/esm/FlowRuntime/NodeRecord.js.map +1 -0
  490. package/dist/esm/FlowRuntime/WaitingAnnotation.d.ts +69 -0
  491. package/dist/esm/FlowRuntime/WaitingAnnotation.d.ts.map +1 -0
  492. package/dist/esm/FlowRuntime/WaitingAnnotation.js +53 -0
  493. package/dist/esm/FlowRuntime/WaitingAnnotation.js.map +1 -0
  494. package/dist/esm/FlowRuntime/index.d.ts +14 -0
  495. package/dist/esm/FlowRuntime/index.d.ts.map +1 -0
  496. package/dist/esm/FlowRuntime/index.js +15 -0
  497. package/dist/esm/FlowRuntime/index.js.map +1 -0
  498. package/dist/esm/Graph.d.ts +325 -0
  499. package/dist/esm/Graph.d.ts.map +1 -0
  500. package/dist/esm/Graph.js +1485 -0
  501. package/dist/esm/Graph.js.map +1 -0
  502. package/dist/esm/HumanTask.d.ts +442 -0
  503. package/dist/esm/HumanTask.d.ts.map +1 -0
  504. package/dist/esm/HumanTask.js +810 -0
  505. package/dist/esm/HumanTask.js.map +1 -0
  506. package/dist/esm/Interpreter.d.ts +223 -0
  507. package/dist/esm/Interpreter.d.ts.map +1 -0
  508. package/dist/esm/Interpreter.js +1301 -0
  509. package/dist/esm/Interpreter.js.map +1 -0
  510. package/dist/esm/Poll.d.ts +240 -0
  511. package/dist/esm/Poll.d.ts.map +1 -0
  512. package/dist/esm/Poll.js +289 -0
  513. package/dist/esm/Poll.js.map +1 -0
  514. package/dist/esm/RetryPolicy.d.ts +273 -0
  515. package/dist/esm/RetryPolicy.d.ts.map +1 -0
  516. package/dist/esm/RetryPolicy.js +429 -0
  517. package/dist/esm/RetryPolicy.js.map +1 -0
  518. package/dist/esm/Sleep.d.ts +98 -0
  519. package/dist/esm/Sleep.d.ts.map +1 -0
  520. package/dist/esm/Sleep.js +256 -0
  521. package/dist/esm/Sleep.js.map +1 -0
  522. package/dist/esm/Stall.d.ts +173 -0
  523. package/dist/esm/Stall.d.ts.map +1 -0
  524. package/dist/esm/Stall.js +138 -0
  525. package/dist/esm/Stall.js.map +1 -0
  526. package/dist/esm/WaitFor.d.ts +109 -0
  527. package/dist/esm/WaitFor.d.ts.map +1 -0
  528. package/dist/esm/WaitFor.js +184 -0
  529. package/dist/esm/WaitFor.js.map +1 -0
  530. package/dist/esm/index.d.ts +107 -0
  531. package/dist/esm/index.d.ts.map +1 -0
  532. package/dist/esm/index.js +108 -0
  533. package/dist/esm/index.js.map +1 -0
  534. package/dist/esm/internal/BoundedJson.d.ts +48 -0
  535. package/dist/esm/internal/BoundedJson.d.ts.map +1 -0
  536. package/dist/esm/internal/BoundedJson.js +107 -0
  537. package/dist/esm/internal/BoundedJson.js.map +1 -0
  538. package/dist/esm/internal/DeclarationSite.d.ts +135 -0
  539. package/dist/esm/internal/DeclarationSite.d.ts.map +1 -0
  540. package/dist/esm/internal/DeclarationSite.js +196 -0
  541. package/dist/esm/internal/DeclarationSite.js.map +1 -0
  542. package/dist/esm/internal/Declarations.d.ts +35 -0
  543. package/dist/esm/internal/Declarations.d.ts.map +1 -0
  544. package/dist/esm/internal/Declarations.js +43 -0
  545. package/dist/esm/internal/Declarations.js.map +1 -0
  546. package/dist/esm/internal/ExecutionMiddleware.d.ts +21 -0
  547. package/dist/esm/internal/ExecutionMiddleware.d.ts.map +1 -0
  548. package/dist/esm/internal/ExecutionMiddleware.js +13 -0
  549. package/dist/esm/internal/ExecutionMiddleware.js.map +1 -0
  550. package/dist/esm/internal/JsonSchemaSubset.d.ts +133 -0
  551. package/dist/esm/internal/JsonSchemaSubset.d.ts.map +1 -0
  552. package/dist/esm/internal/JsonSchemaSubset.js +363 -0
  553. package/dist/esm/internal/JsonSchemaSubset.js.map +1 -0
  554. package/dist/esm/internal/OutcomeMarker.d.ts +18 -0
  555. package/dist/esm/internal/OutcomeMarker.d.ts.map +1 -0
  556. package/dist/esm/internal/OutcomeMarker.js +18 -0
  557. package/dist/esm/internal/OutcomeMarker.js.map +1 -0
  558. package/docs/README.md +152 -0
  559. package/docs/api.md +440 -0
  560. package/docs/concepts/bodies-and-plans.md +167 -0
  561. package/docs/concepts/execution-identity.md +142 -0
  562. package/docs/concepts/flows-and-actions.md +129 -0
  563. package/docs/concepts/suspension-and-replay.md +130 -0
  564. package/docs/concepts/the-runtime-port.md +110 -0
  565. package/docs/concepts/trampoline-rounds.md +151 -0
  566. package/docs/guides/ask-a-person.md +184 -0
  567. package/docs/guides/build-a-body.md +164 -0
  568. package/docs/guides/cancel-and-roll-back.md +112 -0
  569. package/docs/guides/implement-an-action.md +155 -0
  570. package/docs/guides/inspect-the-plan.md +235 -0
  571. package/docs/guides/poll-until-ready.md +169 -0
  572. package/docs/guides/queue-work-to-a-worker.md +122 -0
  573. package/docs/guides/retry-a-failing-action.md +243 -0
  574. package/docs/guides/reuse-a-recorded-result.md +129 -0
  575. package/docs/guides/run-a-child-flow.md +108 -0
  576. package/docs/guides/run-an-external-job.md +86 -0
  577. package/docs/guides/use-a-prompt.md +38 -0
  578. package/docs/guides/wait-for-a-deadline.md +141 -0
  579. package/docs/guides/wait-for-an-external-signal.md +151 -0
  580. package/docs/installation.md +87 -0
  581. package/docs/quickstart.md +164 -0
  582. package/docs/reference/flow.md +1835 -0
  583. package/docs/testing.md +157 -0
  584. package/docs/troubleshooting.md +286 -0
  585. package/package.json +327 -3
  586. package/src/Action/Action.ts +333 -0
  587. package/src/Action/AttemptTimedOut.ts +37 -0
  588. package/src/Action/BoundaryMode.ts +33 -0
  589. package/src/Action/CacheEnvironment.ts +170 -0
  590. package/src/Action/ConcurrentKeylessDispatch.ts +38 -0
  591. package/src/Action/Context.ts +156 -0
  592. package/src/Action/DuplicateImplementation.ts +24 -0
  593. package/src/Action/FileBoundary.ts +77 -0
  594. package/src/Action/FileInput.ts +42 -0
  595. package/src/Action/Filegroup.ts +16 -0
  596. package/src/Action/Glob.ts +8 -0
  597. package/src/Action/ImplementationVersionMismatch.ts +27 -0
  598. package/src/Action/Implementations.ts +149 -0
  599. package/src/Action/InfraInterrupt.ts +30 -0
  600. package/src/Action/InfraInterruptRetriesExhausted.ts +37 -0
  601. package/src/Action/IrreversibleRetryRequiresIdempotencyKey.ts +32 -0
  602. package/src/Action/StepIdentity.ts +219 -0
  603. package/src/Action/TreeArtifact.ts +8 -0
  604. package/src/Action/TypeId.ts +9 -0
  605. package/src/Action/UncanonicalIdempotencyKey.ts +36 -0
  606. package/src/Action/idempotencyKey.ts +67 -0
  607. package/src/Action/index.ts +31 -0
  608. package/src/Action/make.ts +671 -0
  609. package/src/Action/raceAll.ts +48 -0
  610. package/src/Action/retry.ts +92 -0
  611. package/src/Deadline.ts +201 -0
  612. package/src/DurableClock.ts +176 -0
  613. package/src/DurableDeferred.ts +753 -0
  614. package/src/DurableQueue.ts +519 -0
  615. package/src/ExternalJob.ts +437 -0
  616. package/src/Fault.ts +279 -0
  617. package/src/Flow/Annotations.ts +151 -0
  618. package/src/Flow/CapabilityCeiling.ts +37 -0
  619. package/src/Flow/DeadlineExceeded.ts +40 -0
  620. package/src/Flow/ExecutionIdRequired.ts +36 -0
  621. package/src/Flow/ExecutionIds.ts +133 -0
  622. package/src/Flow/Flow.ts +576 -0
  623. package/src/Flow/MaxRoundsExceeded.ts +39 -0
  624. package/src/Flow/Outcome.ts +179 -0
  625. package/src/Flow/Result.ts +284 -0
  626. package/src/Flow/Runtime.ts +339 -0
  627. package/src/Flow/TypeId.ts +9 -0
  628. package/src/Flow/index.ts +19 -0
  629. package/src/Flow/internal.ts +237 -0
  630. package/src/Flow/make.ts +299 -0
  631. package/src/FlowRuntime/CancelRequestFailed.ts +56 -0
  632. package/src/FlowRuntime/ExecutionIdentityConflict.ts +32 -0
  633. package/src/FlowRuntime/FlowCycleDetected.ts +41 -0
  634. package/src/FlowRuntime/FlowExecutionNotFound.ts +46 -0
  635. package/src/FlowRuntime/FlowInstance.ts +128 -0
  636. package/src/FlowRuntime/FlowRuntime.ts +339 -0
  637. package/src/FlowRuntime/NodeRecord.ts +185 -0
  638. package/src/FlowRuntime/WaitingAnnotation.ts +85 -0
  639. package/src/FlowRuntime/index.ts +17 -0
  640. package/src/Graph.ts +1865 -0
  641. package/src/HumanTask.ts +1021 -0
  642. package/src/Interpreter.ts +1635 -0
  643. package/src/Poll.ts +420 -0
  644. package/src/RetryPolicy.ts +550 -0
  645. package/src/Sleep.ts +296 -0
  646. package/src/Stall.ts +217 -0
  647. package/src/WaitFor.ts +228 -0
  648. package/src/index.ts +125 -0
  649. package/src/internal/BoundedJson.ts +109 -0
  650. package/src/internal/DeclarationSite.ts +214 -0
  651. package/src/internal/Declarations.ts +49 -0
  652. package/src/internal/ExecutionMiddleware.ts +29 -0
  653. package/src/internal/JsonSchemaSubset.ts +392 -0
  654. package/src/internal/OutcomeMarker.ts +19 -0
@@ -0,0 +1,303 @@
1
+ // Deep reviewed and polished by a human on 2026-08-10.
2
+ /**
3
+ * Durable flow queues delegate work to persisted background workers and
4
+ * resume the waiting flow with the worker result.
5
+ *
6
+ * A flow calls `process` to encode a payload, offer it to a named
7
+ * `PersistedQueue`, attach a `DurableDeferred` token, and suspend. A worker
8
+ * created with `makeWorker` or `worker` takes the item, runs the handler, and
9
+ * records the handler's `Exit` through that token so the original flow can
10
+ * continue with the typed success or error.
11
+ *
12
+ * @since 0.1.0
13
+ */
14
+ import * as Arr from "effect/Array";
15
+ import * as Cause from "effect/Cause";
16
+ import * as Effect from "effect/Effect";
17
+ import * as Exit from "effect/Exit";
18
+ import * as Filter from "effect/Filter";
19
+ import * as Layer from "effect/Layer";
20
+ import * as PersistedQueue from "effect/persistence/PersistedQueue";
21
+ import * as Schedule from "effect/Schedule";
22
+ import * as Schema from "effect/Schema";
23
+ import * as Tracer from "effect/Tracer";
24
+ import * as Action from "./Action/index.js";
25
+ import * as DurableDeferred from "./DurableDeferred.js";
26
+ import { annotateWaiting } from "./FlowRuntime/index.js";
27
+ /**
28
+ * Runtime identifier attached to `DurableQueue` values.
29
+ *
30
+ * @category type IDs
31
+ * @since 0.1.0
32
+ */
33
+ export const TypeId = "@smthrs/flow/DurableQueue";
34
+ /**
35
+ * Creates a `DurableQueue` that waits for persisted items to finish processing
36
+ * using a `DurableDeferred`.
37
+ *
38
+ * **Example** (Defining a durable queue with workers)
39
+ *
40
+ * ```ts
41
+ * import { Action, DurableQueue, Flow, Interpreter } from "@smthrs/flow"
42
+ * import { Effect, Layer, Schema } from "effect"
43
+ *
44
+ * // Define a DurableQueue that can be used to derive workers and offer items for
45
+ * // processing.
46
+ * const ApiQueue = DurableQueue.make({
47
+ * name: "ApiQueue",
48
+ * payload: {
49
+ * id: Schema.String
50
+ * },
51
+ * success: Schema.Void,
52
+ * error: Schema.Never,
53
+ * idempotencyKey(payload) {
54
+ * return payload.id
55
+ * }
56
+ * })
57
+ *
58
+ * // Offering an item is work, so it is a declared Action: the declaration is
59
+ * // pure data, and the implementation attaches separately.
60
+ * const Offer = Action.make("MyFlow/offer", {
61
+ * payload: {
62
+ * id: Schema.String
63
+ * }
64
+ * })
65
+ *
66
+ * const OfferLive = Offer.toLayer(
67
+ * Effect.fnUntraced(function*({ id }) {
68
+ * // Add an item to the DurableQueue defined above.
69
+ * //
70
+ * // When the worker has finished processing the item, the flow will
71
+ * // resume.
72
+ * //
73
+ * yield* DurableQueue.process(ApiQueue, { id })
74
+ *
75
+ * yield* Effect.log("Flow succeeded!")
76
+ * })
77
+ * )
78
+ *
79
+ * // The flow is the composite, and its body names the step it is made of.
80
+ * const MyFlow = Flow.make("MyFlow", {
81
+ * payload: {
82
+ * id: Schema.String
83
+ * },
84
+ * idempotencyKey: ({ id }) => id,
85
+ * body: (payload) => Offer.call(payload)
86
+ * })
87
+ *
88
+ * const MyFlowLayer = Layer.mergeAll(OfferLive, Interpreter.layer(MyFlow)).pipe(
89
+ * Layer.provideMerge(Action.layerImplementations)
90
+ * )
91
+ *
92
+ * // Define a worker layer that can process items from the DurableQueue.
93
+ * const ApiWorker = DurableQueue.worker(
94
+ * ApiQueue,
95
+ * Effect.fnUntraced(function*({ id }) {
96
+ * yield* Effect.log(`Worker processing API call with id: ${id}`)
97
+ * }),
98
+ * { concurrency: 5 } // Process up to 5 items concurrently
99
+ * )
100
+ * ```
101
+ *
102
+ * @category constructors
103
+ * @since 0.1.0
104
+ */
105
+ export const make = (options) => ({
106
+ [TypeId]: TypeId,
107
+ name: options.name,
108
+ payloadSchema: Schema.isSchema(options.payload)
109
+ ? options.payload
110
+ : Schema.Struct(options.payload),
111
+ idempotencyKey: options.idempotencyKey,
112
+ deferred: DurableDeferred.make(`DurableQueue/${options.name}`, {
113
+ success: options.success,
114
+ error: options.error
115
+ })
116
+ });
117
+ const queueSchemas = new WeakMap();
118
+ const getQueueSchema = (payload) => {
119
+ let schema = queueSchemas.get(payload);
120
+ if (!schema) {
121
+ schema = Schema.Struct({
122
+ token: DurableDeferred.Token,
123
+ traceId: Schema.String,
124
+ spanId: Schema.String,
125
+ sampled: Schema.Boolean,
126
+ payload
127
+ });
128
+ queueSchemas.set(payload, schema);
129
+ }
130
+ return schema;
131
+ };
132
+ /**
133
+ * Adds an item to the queue and waits for a worker to process it.
134
+ *
135
+ * `retrySchedule` controls retries when the persisted offer fails. The default
136
+ * is unbounded, with exponential delays capped at one minute, so a transient
137
+ * store outage does not lose the item. A caller-supplied schedule may exhaust;
138
+ * its final offer failure becomes a defect to keep the public error channel
139
+ * reserved for the worker's declared error.
140
+ *
141
+ * Payload construction also becomes a defect when `fields` does not satisfy
142
+ * the queue's payload schema. The public error channel is the worker result,
143
+ * not malformed caller input.
144
+ *
145
+ * @category processing
146
+ * @since 0.1.0
147
+ */
148
+ export const process =
149
+ // Untraced because queue offer is a worker hot path.
150
+ Effect.fnUntraced(function* (self, fields, options) {
151
+ const payload = yield* self.payloadSchema.makeEffect(fields).pipe(Effect.mapError((issue) => new Schema.SchemaError(issue)), Effect.orDie);
152
+ const queueName = `DurableQueue/${self.name}`;
153
+ const queue = yield* PersistedQueue.make({
154
+ name: queueName,
155
+ schema: getQueueSchema(self.payloadSchema)
156
+ });
157
+ const key = yield* Action.idempotencyKey(queueName, {
158
+ parentScope: self.idempotencyKey(payload)
159
+ });
160
+ const deferred = DurableDeferred.make(`${self.deferred.name}/${key}`, {
161
+ success: self.deferred.successSchema,
162
+ error: self.deferred.errorSchema
163
+ });
164
+ const token = yield* DurableDeferred.token(deferred);
165
+ yield* Effect.useSpan(`DurableQueue/${self.name}/process`, {
166
+ attributes: { key }
167
+ }, (span) => queue.offer({
168
+ token,
169
+ payload,
170
+ traceId: span.traceId,
171
+ spanId: span.spanId,
172
+ sampled: span.sampled
173
+ }, { id: key }).pipe(Effect.tapCause(Effect.logWarning), Effect.catchTag("SchemaError", Effect.die), Effect.retry(options?.retrySchedule ?? defaultRetrySchedule), Effect.orDie, Effect.annotateLogs({
174
+ package: "@smthrs/flow",
175
+ module: "DurableQueue",
176
+ fiber: "process",
177
+ queueName: self.name
178
+ })));
179
+ yield* annotateWaiting({ reason: "event", token });
180
+ return yield* DurableDeferred.await(deferred);
181
+ });
182
+ const maxDeferredNameExcerptChars = 128;
183
+ /** Renders a bounded excerpt of a stored deferred name for a diagnostic. */
184
+ const deferredNameExcerpt = (name) => name.length <= maxDeferredNameExcerptChars
185
+ ? name
186
+ : `${name.slice(0, maxDeferredNameExcerptChars)} [${name.length - maxDeferredNameExcerptChars} characters dropped]`;
187
+ const traceIdPattern = /^[0-9a-f]{32}$/;
188
+ const spanIdPattern = /^[0-9a-f]{16}$/;
189
+ /**
190
+ * The offering span as the worker span's parent, when the stored ids have the
191
+ * W3C trace-context shape every Effect and OpenTelemetry tracer writes. A
192
+ * stored item is not trusted to splice arbitrary identifiers into a trace.
193
+ */
194
+ const externalParent = (item) => traceIdPattern.test(item.traceId) && spanIdPattern.test(item.spanId)
195
+ ? Tracer.externalSpan({ traceId: item.traceId, spanId: item.spanId, sampled: item.sampled })
196
+ : undefined;
197
+ const defaultRetrySchedule = Schedule.min([
198
+ Schedule.exponential(500, 1.5),
199
+ Schedule.spaced("1 minute")
200
+ ]);
201
+ const makeWorkerEffect = Effect.fnUntraced(function* (self, f, concurrency, maxAttempts) {
202
+ const queue = yield* PersistedQueue.make({
203
+ name: `DurableQueue/${self.name}`,
204
+ schema: getQueueSchema(self.payloadSchema),
205
+ maxAttempts,
206
+ // The worker owns the 500 ms retry pause below. Keep an upstream queue
207
+ // default from introducing an additional backoff after an Effect upgrade.
208
+ retrySchedule: Schedule.spaced(0)
209
+ });
210
+ const worker = Effect.suspend(() => {
211
+ let completion;
212
+ return queue.take((item_, metadata) => {
213
+ const item = item_;
214
+ return Effect.withSpan(Effect.gen(function* () {
215
+ // Parse before running the handler. A malformed completion address
216
+ // cannot strand a handler result that was already produced.
217
+ const parsed = yield* DurableDeferred.TokenParsed.parse(item.token);
218
+ // `process` offers each item under its key and addresses the
219
+ // deferred `<queue deferred>/<key>`. Anything else in this queue
220
+ // names a wait point the queue does not own (another queue's item,
221
+ // a WaitFor gate, a human task), so completing it here would settle
222
+ // a foreign wait under this queue's success schema.
223
+ const expected = `${self.deferred.name}/${metadata.id}`;
224
+ if (parsed.deferredName !== expected) {
225
+ return yield* new DurableDeferred.TokenInvalid({
226
+ code: "deferred_mismatch",
227
+ message: `The item "${metadata.id}" addresses the deferred "${deferredNameExcerpt(parsed.deferredName)}", not "${deferredNameExcerpt(expected)}".`
228
+ });
229
+ }
230
+ const deferred = DurableDeferred.make(parsed.deferredName, {
231
+ success: self.deferred.successSchema,
232
+ error: self.deferred.errorSchema
233
+ });
234
+ let exit = yield* Effect.exit(f(item.payload));
235
+ if (Exit.isFailure(exit)) {
236
+ const [interrupts, reasons] = Arr.partition(exit.cause.reasons, Filter.fromPredicate(Cause.isInterruptReason));
237
+ // Match DurableDeferred.into: interruption alone is not a durable
238
+ // outcome, and must leave the item available without an attempt.
239
+ if (interrupts.length === exit.cause.reasons.length) {
240
+ return yield* Effect.failCause(Cause.fromReasons(interrupts));
241
+ }
242
+ else if (interrupts.length > 0) {
243
+ exit = Exit.failCause(Cause.fromReasons(reasons));
244
+ }
245
+ }
246
+ completion = { token: item.token, ...metadata };
247
+ yield* DurableDeferred.done(deferred, {
248
+ token: item.token,
249
+ exit
250
+ });
251
+ }).pipe(Effect.catchTag("@smthrs/flow/DurableDeferred/TokenInvalid", (error) => Effect.logError(`DurableQueue "${self.name}" could not complete an item because its token was invalid. ${error.message}`))), `DurableQueue/${self.name}/worker`, {
252
+ captureStackTrace: false,
253
+ parent: externalParent(item)
254
+ });
255
+ }).pipe(Effect.tapCause((cause) => {
256
+ if (!completion)
257
+ return Effect.void;
258
+ return Effect.logError("DurableQueue failed to persist or acknowledge a handler result", cause).pipe(Effect.annotateLogs({
259
+ token: completion.token,
260
+ itemId: completion.id,
261
+ attempt: completion.attempts,
262
+ maxAttempts,
263
+ exhausted: !Cause.hasInterrupts(cause) && completion.attempts >= maxAttempts
264
+ }));
265
+ }));
266
+ }).pipe(
267
+ // A persistently failing take would otherwise consume a core in a tight
268
+ // loop while the queue store is unavailable.
269
+ Effect.catchCause((cause) => Effect.logWarning(cause).pipe(Effect.andThen(Effect.sleep(500)))), Effect.forever, Effect.annotateLogs({
270
+ package: "@smthrs/flow",
271
+ module: "DurableQueue",
272
+ fiber: "worker",
273
+ queueName: self.name
274
+ }));
275
+ return yield* Effect.replicateEffect(worker, concurrency, { concurrency, discard: true }).pipe(Effect.andThen(Effect.never));
276
+ });
277
+ /**
278
+ * Create a worker effect that processes items from the durable queue.
279
+ *
280
+ * `concurrency` defaults to one and must be a positive safe integer. It is
281
+ * checked before the persisted queue is opened. `maxAttempts` defaults to ten
282
+ * and is passed to the persisted queue. Completion-write failures can rerun the
283
+ * handler; side effects must be idempotent. Exhaustion leaves the flow waiting.
284
+ *
285
+ * @throws A `RangeError` when `concurrency` is not a positive safe integer.
286
+ * @category worker
287
+ * @since 0.1.0
288
+ */
289
+ export const makeWorker = (self, f, options) => {
290
+ const concurrency = options?.concurrency ?? 1;
291
+ if (!Number.isSafeInteger(concurrency) || concurrency < 1) {
292
+ throw new RangeError(`DurableQueue.makeWorker: concurrency must be a positive safe integer, and was ${concurrency}.`);
293
+ }
294
+ return makeWorkerEffect(self, f, concurrency, options?.maxAttempts ?? 10);
295
+ };
296
+ /**
297
+ * Create a layer that runs workers for the durable queue.
298
+ *
299
+ * @category worker
300
+ * @since 0.1.0
301
+ */
302
+ export const worker = (self, f, options) => Layer.effectDiscard(Effect.forkScoped(makeWorker(self, f, options)));
303
+ //# sourceMappingURL=DurableQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DurableQueue.js","sourceRoot":"","sources":["../../src/DurableQueue.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,cAAc,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAuC,MAAM,wBAAwB,CAAA;AAU7F;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAW,2BAA2B,CAAA;AAqBzD;;;;;;;;;;;;;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AI,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA","sourcesContent":["// Deep reviewed and polished by a human on 2026-08-10.\n\n/**\n * Durable flow queues delegate work to persisted background workers and\n * resume the waiting flow with the worker result.\n *\n * A flow calls `process` to encode a payload, offer it to a named\n * `PersistedQueue`, attach a `DurableDeferred` token, and suspend. A worker\n * created with `makeWorker` or `worker` takes the item, runs the handler, and\n * records the handler's `Exit` through that token so the original flow can\n * continue with the typed success or error.\n *\n * @since 0.1.0\n */\n\nimport * as Arr from \"effect/Array\"\nimport * as Cause from \"effect/Cause\"\nimport type * as Crypto from \"effect/Crypto\"\nimport * as Effect from \"effect/Effect\"\nimport * as Exit from \"effect/Exit\"\nimport * as Filter from \"effect/Filter\"\nimport * as Layer from \"effect/Layer\"\nimport * as PersistedQueue from \"effect/persistence/PersistedQueue\"\nimport * as Schedule from \"effect/Schedule\"\nimport * as Schema from \"effect/Schema\"\nimport * as Tracer from \"effect/Tracer\"\nimport * as Action from \"./Action/index.ts\"\nimport * as DurableDeferred from \"./DurableDeferred.ts\"\nimport { annotateWaiting, type FlowInstance, type FlowRuntime } from \"./FlowRuntime/index.ts\"\n\n/**\n * Type-level identifier used to recognize `DurableQueue` values.\n *\n * @category type IDs\n * @since 0.1.0\n */\nexport type TypeId = \"@smthrs/flow/DurableQueue\"\n\n/**\n * Runtime identifier attached to `DurableQueue` values.\n *\n * @category type IDs\n * @since 0.1.0\n */\nexport const TypeId: TypeId = \"@smthrs/flow/DurableQueue\"\n\n/**\n * Durable flow queue definition containing a payload schema, idempotency\n * key, and deferred used to await worker results.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface DurableQueue<\n Payload extends Schema.Top,\n Success extends Schema.Top = Schema.Void,\n Error extends Schema.Top = Schema.Never\n> {\n readonly [TypeId]: TypeId\n readonly name: string\n readonly payloadSchema: Payload\n readonly idempotencyKey: (payload: Payload[\"Type\"]) => string\n readonly deferred: DurableDeferred.DurableDeferred<Success, Error>\n}\n\n/**\n * Creates a `DurableQueue` that waits for persisted items to finish processing\n * using a `DurableDeferred`.\n *\n * **Example** (Defining a durable queue with workers)\n *\n * ```ts\n * import { Action, DurableQueue, Flow, Interpreter } from \"@smthrs/flow\"\n * import { Effect, Layer, Schema } from \"effect\"\n *\n * // Define a DurableQueue that can be used to derive workers and offer items for\n * // processing.\n * const ApiQueue = DurableQueue.make({\n * name: \"ApiQueue\",\n * payload: {\n * id: Schema.String\n * },\n * success: Schema.Void,\n * error: Schema.Never,\n * idempotencyKey(payload) {\n * return payload.id\n * }\n * })\n *\n * // Offering an item is work, so it is a declared Action: the declaration is\n * // pure data, and the implementation attaches separately.\n * const Offer = Action.make(\"MyFlow/offer\", {\n * payload: {\n * id: Schema.String\n * }\n * })\n *\n * const OfferLive = Offer.toLayer(\n * Effect.fnUntraced(function*({ id }) {\n * // Add an item to the DurableQueue defined above.\n * //\n * // When the worker has finished processing the item, the flow will\n * // resume.\n * //\n * yield* DurableQueue.process(ApiQueue, { id })\n *\n * yield* Effect.log(\"Flow succeeded!\")\n * })\n * )\n *\n * // The flow is the composite, and its body names the step it is made of.\n * const MyFlow = Flow.make(\"MyFlow\", {\n * payload: {\n * id: Schema.String\n * },\n * idempotencyKey: ({ id }) => id,\n * body: (payload) => Offer.call(payload)\n * })\n *\n * const MyFlowLayer = Layer.mergeAll(OfferLive, Interpreter.layer(MyFlow)).pipe(\n * Layer.provideMerge(Action.layerImplementations)\n * )\n *\n * // Define a worker layer that can process items from the DurableQueue.\n * const ApiWorker = DurableQueue.worker(\n * ApiQueue,\n * Effect.fnUntraced(function*({ id }) {\n * yield* Effect.log(`Worker processing API call with id: ${id}`)\n * }),\n * { concurrency: 5 } // Process up to 5 items concurrently\n * )\n * ```\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = <\n Payload extends Schema.Top | Schema.Struct.Fields,\n Success extends Schema.Top = Schema.Void,\n Error extends Schema.Top = Schema.Never\n>(options: {\n readonly name: string\n readonly payload: Payload\n readonly idempotencyKey: (\n payload: Payload extends Schema.Struct.Fields ? Schema.Struct.Type<Payload>\n : Payload[\"Type\"]\n ) => string\n readonly success?: Success | undefined\n readonly error?: Error | undefined\n}): DurableQueue<\n Payload extends Schema.Struct.Fields ? Schema.Struct<Payload> : Payload,\n Success,\n Error\n> => ({\n [TypeId]: TypeId,\n name: options.name,\n payloadSchema: Schema.isSchema(options.payload)\n ? options.payload\n : Schema.Struct(options.payload as any) as any,\n idempotencyKey: options.idempotencyKey as any,\n deferred: DurableDeferred.make(`DurableQueue/${options.name}`, {\n success: options.success,\n error: options.error\n })\n})\n\nconst queueSchemas = new WeakMap<Schema.Top, Schema.Top>()\n\nconst getQueueSchema = <Payload extends Schema.Top>(\n payload: Payload\n): Schema.Struct<{\n token: typeof DurableDeferred.Token\n payload: Payload\n traceId: typeof Schema.String\n spanId: typeof Schema.String\n sampled: typeof Schema.Boolean\n}> => {\n let schema = queueSchemas.get(payload)\n if (!schema) {\n schema = Schema.Struct({\n token: DurableDeferred.Token,\n traceId: Schema.String,\n spanId: Schema.String,\n sampled: Schema.Boolean,\n payload\n })\n queueSchemas.set(payload, schema)\n }\n return schema as any\n}\n\n/**\n * Adds an item to the queue and waits for a worker to process it.\n *\n * `retrySchedule` controls retries when the persisted offer fails. The default\n * is unbounded, with exponential delays capped at one minute, so a transient\n * store outage does not lose the item. A caller-supplied schedule may exhaust;\n * its final offer failure becomes a defect to keep the public error channel\n * reserved for the worker's declared error.\n *\n * Payload construction also becomes a defect when `fields` does not satisfy\n * the queue's payload schema. The public error channel is the worker result,\n * not malformed caller input.\n *\n * @category processing\n * @since 0.1.0\n */\nexport const process: <\n Payload extends Schema.Top,\n Success extends Schema.Top,\n Error extends Schema.Top\n>(\n self: DurableQueue<Payload, Success, Error>,\n payload: Payload[\"~type.make.in\"],\n options?: {\n readonly retrySchedule?: Schedule.Schedule<any, PersistedQueue.PersistedQueueError> | undefined\n }\n) => Effect.Effect<\n Success[\"Type\"],\n Error[\"Type\"],\n | FlowRuntime\n | FlowInstance\n | Crypto.Crypto\n | PersistedQueue.PersistedQueueFactory\n | Payload[\"EncodingServices\"]\n | Payload[\"DecodingServices\"]\n | Success[\"DecodingServices\"]\n | Error[\"DecodingServices\"]\n> =\n // Untraced because queue offer is a worker hot path.\n Effect.fnUntraced(function*<\n Payload extends Schema.Top,\n Success extends Schema.Top,\n Error extends Schema.Top\n >(self: DurableQueue<Payload, Success, Error>, fields: Payload[\"~type.make.in\"], options?: {\n readonly retrySchedule?: Schedule.Schedule<any, PersistedQueue.PersistedQueueError> | undefined\n }) {\n const payload = yield* self.payloadSchema.makeEffect(fields).pipe(\n Effect.mapError((issue) => new Schema.SchemaError(issue)),\n Effect.orDie\n )\n const queueName = `DurableQueue/${self.name}`\n const queue = yield* PersistedQueue.make({\n name: queueName,\n schema: getQueueSchema(self.payloadSchema)\n })\n const key = yield* Action.idempotencyKey(queueName, {\n parentScope: self.idempotencyKey(payload)\n })\n\n const deferred = DurableDeferred.make(`${self.deferred.name}/${key}`, {\n success: self.deferred.successSchema,\n error: self.deferred.errorSchema\n })\n const token = yield* DurableDeferred.token(deferred)\n\n yield* Effect.useSpan(`DurableQueue/${self.name}/process`, {\n attributes: { key }\n }, (span) =>\n queue.offer({\n token,\n payload,\n traceId: span.traceId,\n spanId: span.spanId,\n sampled: span.sampled\n } as any, { id: key }).pipe(\n Effect.tapCause(Effect.logWarning),\n Effect.catchTag(\"SchemaError\", Effect.die),\n Effect.retry(options?.retrySchedule ?? defaultRetrySchedule),\n Effect.orDie,\n Effect.annotateLogs({\n package: \"@smthrs/flow\",\n module: \"DurableQueue\",\n fiber: \"process\",\n queueName: self.name\n })\n ))\n\n yield* annotateWaiting({ reason: \"event\", token })\n return yield* DurableDeferred.await(deferred)\n })\n\nconst maxDeferredNameExcerptChars = 128\n\n/** Renders a bounded excerpt of a stored deferred name for a diagnostic. */\nconst deferredNameExcerpt = (name: string): string =>\n name.length <= maxDeferredNameExcerptChars\n ? name\n : `${name.slice(0, maxDeferredNameExcerptChars)} [${name.length - maxDeferredNameExcerptChars} characters dropped]`\n\nconst traceIdPattern = /^[0-9a-f]{32}$/\nconst spanIdPattern = /^[0-9a-f]{16}$/\n\n/**\n * The offering span as the worker span's parent, when the stored ids have the\n * W3C trace-context shape every Effect and OpenTelemetry tracer writes. A\n * stored item is not trusted to splice arbitrary identifiers into a trace.\n */\nconst externalParent = (item: {\n readonly traceId: string\n readonly spanId: string\n readonly sampled: boolean\n}): Tracer.ExternalSpan | undefined =>\n traceIdPattern.test(item.traceId) && spanIdPattern.test(item.spanId)\n ? Tracer.externalSpan({ traceId: item.traceId, spanId: item.spanId, sampled: item.sampled })\n : undefined\n\nconst defaultRetrySchedule = Schedule.min([\n Schedule.exponential(500, 1.5),\n Schedule.spaced(\"1 minute\")\n])\n\nconst makeWorkerEffect = Effect.fnUntraced(function*<\n Payload extends Schema.Top,\n Success extends Schema.Top,\n Error extends Schema.Top,\n R\n>(\n self: DurableQueue<Payload, Success, Error>,\n f: (payload: Payload[\"Type\"]) => Effect.Effect<Success[\"Type\"], Error[\"Type\"], R>,\n concurrency: number,\n maxAttempts: number\n) {\n const queue = yield* PersistedQueue.make({\n name: `DurableQueue/${self.name}`,\n schema: getQueueSchema(self.payloadSchema),\n maxAttempts,\n // The worker owns the 500 ms retry pause below. Keep an upstream queue\n // default from introducing an additional backoff after an Effect upgrade.\n retrySchedule: Schedule.spaced(0)\n })\n\n const worker = Effect.suspend(() => {\n let completion:\n | { readonly token: DurableDeferred.Token; readonly id: string; readonly attempts: number }\n | undefined\n return queue.take((item_, metadata) => {\n const item = item_ as {\n readonly token: DurableDeferred.Token\n readonly payload: Payload[\"Type\"]\n readonly traceId: string\n readonly spanId: string\n readonly sampled: boolean\n }\n return Effect.withSpan(\n Effect.gen(function*() {\n // Parse before running the handler. A malformed completion address\n // cannot strand a handler result that was already produced.\n const parsed = yield* DurableDeferred.TokenParsed.parse(item.token)\n // `process` offers each item under its key and addresses the\n // deferred `<queue deferred>/<key>`. Anything else in this queue\n // names a wait point the queue does not own (another queue's item,\n // a WaitFor gate, a human task), so completing it here would settle\n // a foreign wait under this queue's success schema.\n const expected = `${self.deferred.name}/${metadata.id}`\n if (parsed.deferredName !== expected) {\n return yield* new DurableDeferred.TokenInvalid({\n code: \"deferred_mismatch\",\n message: `The item \"${metadata.id}\" addresses the deferred \"${\n deferredNameExcerpt(parsed.deferredName)\n }\", not \"${deferredNameExcerpt(expected)}\".`\n })\n }\n const deferred = DurableDeferred.make(parsed.deferredName, {\n success: self.deferred.successSchema,\n error: self.deferred.errorSchema\n })\n let exit = yield* Effect.exit(f(item.payload))\n if (Exit.isFailure(exit)) {\n const [interrupts, reasons] = Arr.partition(\n exit.cause.reasons,\n Filter.fromPredicate(Cause.isInterruptReason)\n )\n // Match DurableDeferred.into: interruption alone is not a durable\n // outcome, and must leave the item available without an attempt.\n if (interrupts.length === exit.cause.reasons.length) {\n return yield* Effect.failCause(Cause.fromReasons<never>(interrupts))\n } else if (interrupts.length > 0) {\n exit = Exit.failCause(Cause.fromReasons(reasons))\n }\n }\n completion = { token: item.token, ...metadata }\n yield* DurableDeferred.done(deferred, {\n token: item.token,\n exit\n })\n }).pipe(\n Effect.catchTag(\"@smthrs/flow/DurableDeferred/TokenInvalid\", (error) =>\n Effect.logError(\n `DurableQueue \"${self.name}\" could not complete an item because its token was invalid. ${error.message}`\n ))\n ),\n `DurableQueue/${self.name}/worker`,\n {\n captureStackTrace: false,\n parent: externalParent(item)\n }\n )\n }).pipe(\n Effect.tapCause((cause) => {\n if (!completion) return Effect.void\n return Effect.logError(\"DurableQueue failed to persist or acknowledge a handler result\", cause).pipe(\n Effect.annotateLogs({\n token: completion.token,\n itemId: completion.id,\n attempt: completion.attempts,\n maxAttempts,\n exhausted: !Cause.hasInterrupts(cause) && completion.attempts >= maxAttempts\n })\n )\n })\n )\n }).pipe(\n // A persistently failing take would otherwise consume a core in a tight\n // loop while the queue store is unavailable.\n Effect.catchCause((cause) =>\n Effect.logWarning(cause).pipe(\n Effect.andThen(Effect.sleep(500))\n )\n ),\n Effect.forever,\n Effect.annotateLogs({\n package: \"@smthrs/flow\",\n module: \"DurableQueue\",\n fiber: \"worker\",\n queueName: self.name\n })\n )\n\n return yield* Effect.replicateEffect(worker, concurrency, { concurrency, discard: true }).pipe(\n Effect.andThen(Effect.never)\n )\n})\n\n/**\n * Create a worker effect that processes items from the durable queue.\n *\n * `concurrency` defaults to one and must be a positive safe integer. It is\n * checked before the persisted queue is opened. `maxAttempts` defaults to ten\n * and is passed to the persisted queue. Completion-write failures can rerun the\n * handler; side effects must be idempotent. Exhaustion leaves the flow waiting.\n *\n * @throws A `RangeError` when `concurrency` is not a positive safe integer.\n * @category worker\n * @since 0.1.0\n */\nexport const makeWorker: <\n Payload extends Schema.Top,\n Success extends Schema.Top,\n Error extends Schema.Top,\n R\n>(\n self: DurableQueue<Payload, Success, Error>,\n f: (payload: Payload[\"Type\"]) => Effect.Effect<Success[\"Type\"], Error[\"Type\"], R>,\n options?: {\n readonly concurrency?: number | undefined\n readonly maxAttempts?: number | undefined\n } | undefined\n) => Effect.Effect<\n never,\n never,\n | FlowRuntime\n | PersistedQueue.PersistedQueueFactory\n | R\n | Payload[\"EncodingServices\"]\n | Payload[\"DecodingServices\"]\n | Success[\"EncodingServices\"]\n | Error[\"EncodingServices\"]\n> = <\n Payload extends Schema.Top,\n Success extends Schema.Top,\n Error extends Schema.Top,\n R\n>(\n self: DurableQueue<Payload, Success, Error>,\n f: (payload: Payload[\"Type\"]) => Effect.Effect<Success[\"Type\"], Error[\"Type\"], R>,\n options?: {\n readonly concurrency?: number | undefined\n readonly maxAttempts?: number | undefined\n }\n) => {\n const concurrency = options?.concurrency ?? 1\n if (!Number.isSafeInteger(concurrency) || concurrency < 1) {\n throw new RangeError(\n `DurableQueue.makeWorker: concurrency must be a positive safe integer, and was ${concurrency}.`\n )\n }\n return makeWorkerEffect(self, f, concurrency, options?.maxAttempts ?? 10)\n}\n\n/**\n * Create a layer that runs workers for the durable queue.\n *\n * @category worker\n * @since 0.1.0\n */\nexport const worker: <\n Payload extends Schema.Top,\n Success extends Schema.Top,\n Error extends Schema.Top,\n R\n>(\n self: DurableQueue<Payload, Success, Error>,\n f: (payload: Payload[\"Type\"]) => Effect.Effect<Success[\"Type\"], Error[\"Type\"], R>,\n options?: {\n readonly concurrency?: number | undefined\n readonly maxAttempts?: number | undefined\n } | undefined\n) => Layer.Layer<\n never,\n never,\n | FlowRuntime\n | PersistedQueue.PersistedQueueFactory\n | R\n | Payload[\"EncodingServices\"]\n | Payload[\"DecodingServices\"]\n | Success[\"EncodingServices\"]\n | Error[\"EncodingServices\"]\n> = (self, f, options) => Layer.effectDiscard(Effect.forkScoped(makeWorker(self, f, options)))\n"]}
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Durable external work as ordinary actions, handoffs and parked timers.
3
+ *
4
+ * @since 1.0.0
5
+ */
6
+ import * as Node from "@smthrs/plan/Node";
7
+ import * as Cause from "effect/Cause";
8
+ import * as Duration from "effect/Duration";
9
+ import * as Effect from "effect/Effect";
10
+ import * as Layer from "effect/Layer";
11
+ import * as Schema from "effect/Schema";
12
+ import * as Action from "./Action/index.ts";
13
+ import * as Flow from "./Flow/index.ts";
14
+ import { FlowInstance } from "./FlowRuntime/FlowInstance.ts";
15
+ import * as Sleep from "./Sleep.ts";
16
+ /**
17
+ * External process observation.
18
+ * @category schemas
19
+ * @since 1.0.0
20
+ */
21
+ export declare const Status: Schema.Union<readonly [Schema.Struct<{
22
+ readonly _tag: Schema.Literal<"Running">;
23
+ }>, Schema.Struct<{
24
+ readonly _tag: Schema.Literal<"Exited">;
25
+ readonly exitCode: Schema.Int;
26
+ }>, Schema.Struct<{
27
+ readonly _tag: Schema.Literal<"Lost">;
28
+ }>]>;
29
+ /**
30
+ * Decoded external process observation.
31
+ * @category models
32
+ * @since 1.0.0
33
+ */
34
+ export type Status = typeof Status.Type;
35
+ /**
36
+ * Decoded external process observation.
37
+ * @category models
38
+ * @since 1.0.0
39
+ */
40
+ export type Exited = Extract<Status, {
41
+ readonly _tag: "Exited";
42
+ }>;
43
+ declare const Again_base: Schema.Class<Again, Schema.TaggedStruct<"@smthrs/flow/ExternalJobAgain", {
44
+ readonly message: Schema.String;
45
+ }>, Cause.YieldableError>;
46
+ /**
47
+ * A collected exit that can be replaced.
48
+ *
49
+ * @category errors
50
+ * @since 1.0.0
51
+ */
52
+ export declare class Again extends Again_base {
53
+ }
54
+ declare const ExternalJobLost_base: Schema.Class<ExternalJobLost, Schema.TaggedStruct<"@smthrs/flow/ExternalJobLost", {
55
+ readonly key: Schema.String;
56
+ readonly message: Schema.String;
57
+ }>, Cause.YieldableError>;
58
+ /**
59
+ * No worker or exit receipt remains.
60
+ *
61
+ * @category errors
62
+ * @since 1.0.0
63
+ */
64
+ export declare class ExternalJobLost extends ExternalJobLost_base {
65
+ }
66
+ declare const ExternalJobTimedOut_base: Schema.Class<ExternalJobTimedOut, Schema.TaggedStruct<"@smthrs/flow/ExternalJobTimedOut", {
67
+ readonly key: Schema.String;
68
+ readonly message: Schema.String;
69
+ }>, Cause.YieldableError>;
70
+ /**
71
+ * The deadline anchored before initial start elapsed.
72
+ *
73
+ * @category errors
74
+ * @since 1.0.0
75
+ */
76
+ export declare class ExternalJobTimedOut extends ExternalJobTimedOut_base {
77
+ }
78
+ /**
79
+ * The adapter's full typed failure union belongs in make's error schema.
80
+ *
81
+ * @category models
82
+ * @since 1.0.0
83
+ */
84
+ export interface Operations<P, H, A, E, R> {
85
+ readonly start: (payload: P, key: string) => Effect.Effect<H, E, R>;
86
+ readonly status: (handle: H, key: string) => Effect.Effect<Status, E, R>;
87
+ readonly collect: (handle: H, key: string, exited: Exited) => Effect.Effect<A, E | Again, R>;
88
+ readonly cancel: (handle: H, key: string) => Effect.Effect<void, never, R>;
89
+ }
90
+ /**
91
+ * Create-or-get by execution id and generation. Private ordinary flows carry
92
+ * journaled state; initial callers cannot supply a key or continuation handle.
93
+ * `restarts` counts replacement generations; zero permits only g1.
94
+ * @category constructors
95
+ * @since 1.0.0
96
+ */
97
+ export declare const make: <const Tag extends string, P extends Schema.Struct.Fields | Flow.AnyStructSchema, H extends Schema.Top, A extends Schema.Top, E extends Schema.Top = typeof Schema.Never>(tag: Tag, options: {
98
+ readonly payload: P;
99
+ readonly handle: H;
100
+ readonly success: A;
101
+ readonly error?: E;
102
+ readonly probe: {
103
+ readonly every: Duration.Input;
104
+ readonly max: Duration.Input;
105
+ };
106
+ readonly timeout: Duration.Input;
107
+ readonly restarts?: number;
108
+ }) => {
109
+ readonly call: (payload: Action.PlannedPayload<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["~type.make.in"]>) => Node.Node<A["Type"], Sleep.SleepRequestInvalid | ExternalJobLost | ExternalJobTimedOut | E["Type"], never>;
110
+ readonly toLayer: <R>(operations: Operations<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Type"], H["Type"], A["Type"], E["Type"], R>) => Layer.Layer<Layer.Success<Layer.Layer<Action.Requirement<`${Tag}/initialize`> | Action.Requirement<`${Tag}/start`> | Action.Requirement<`${Tag}/status`> | Action.Requirement<`${Tag}/collect`> | Action.Requirement<`${Tag}/cancel`> | Action.Requirement<`${Tag}/fail`> | Action.Requirement<`${Tag}/ready`> | Action.Requirement<`${Tag}/launch-timeout`>, never, import("effect/Crypto").Crypto | import("./FlowRuntime/FlowRuntime.ts").FlowRuntime | Action.Implementations | {
111
+ executionId: string;
112
+ current: {
113
+ handle: H["Type"];
114
+ key: string;
115
+ } | undefined;
116
+ } | Exclude<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["DecodingServices"], never> | Exclude<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["EncodingServices"], never> | A["DecodingServices"] | Exclude<A["DecodingServices"], never> | A["EncodingServices"] | Exclude<A["EncodingServices"], never> | E["DecodingServices"] | Exclude<E["DecodingServices"], never> | E["EncodingServices"] | Exclude<E["EncodingServices"], never> | Exclude<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["DecodingServices"], never> | Exclude<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["EncodingServices"], never> | Schema.Struct.DecodingServices<{
117
+ readonly handle: Schema.Codec<H["Type"], H["Encoded"], H["DecodingServices"], H["EncodingServices"]>;
118
+ readonly input: Schema.Codec<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Type"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Encoded"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["DecodingServices"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["EncodingServices"]>;
119
+ readonly origin: Schema.String;
120
+ readonly startedAt: Schema.Number;
121
+ readonly generation: Schema.Int;
122
+ readonly probe: Schema.Int;
123
+ }> | Schema.Struct.EncodingServices<{
124
+ readonly handle: Schema.Codec<H["Type"], H["Encoded"], H["DecodingServices"], H["EncodingServices"]>;
125
+ readonly input: Schema.Codec<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Type"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Encoded"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["DecodingServices"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["EncodingServices"]>;
126
+ readonly origin: Schema.String;
127
+ readonly startedAt: Schema.Number;
128
+ readonly generation: Schema.Int;
129
+ readonly probe: Schema.Int;
130
+ }> | Exclude<H["DecodingServices"], never> | Exclude<H["EncodingServices"], never> | Exclude<R, FlowInstance | import("effect/Scope").Scope | import("./FlowRuntime/FlowRuntime.ts").FlowRuntime> | Exclude<R, import("effect/Scope").Scope>>>, Layer.Error<Layer.Layer<Action.Requirement<`${Tag}/initialize`> | Action.Requirement<`${Tag}/start`> | Action.Requirement<`${Tag}/status`> | Action.Requirement<`${Tag}/collect`> | Action.Requirement<`${Tag}/cancel`> | Action.Requirement<`${Tag}/fail`> | Action.Requirement<`${Tag}/ready`> | Action.Requirement<`${Tag}/launch-timeout`>, never, import("effect/Crypto").Crypto | import("./FlowRuntime/FlowRuntime.ts").FlowRuntime | Action.Implementations | {
131
+ executionId: string;
132
+ current: {
133
+ handle: H["Type"];
134
+ key: string;
135
+ } | undefined;
136
+ } | Exclude<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["DecodingServices"], never> | Exclude<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["EncodingServices"], never> | A["DecodingServices"] | Exclude<A["DecodingServices"], never> | A["EncodingServices"] | Exclude<A["EncodingServices"], never> | E["DecodingServices"] | Exclude<E["DecodingServices"], never> | E["EncodingServices"] | Exclude<E["EncodingServices"], never> | Exclude<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["DecodingServices"], never> | Exclude<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["EncodingServices"], never> | Schema.Struct.DecodingServices<{
137
+ readonly handle: Schema.Codec<H["Type"], H["Encoded"], H["DecodingServices"], H["EncodingServices"]>;
138
+ readonly input: Schema.Codec<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Type"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Encoded"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["DecodingServices"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["EncodingServices"]>;
139
+ readonly origin: Schema.String;
140
+ readonly startedAt: Schema.Number;
141
+ readonly generation: Schema.Int;
142
+ readonly probe: Schema.Int;
143
+ }> | Schema.Struct.EncodingServices<{
144
+ readonly handle: Schema.Codec<H["Type"], H["Encoded"], H["DecodingServices"], H["EncodingServices"]>;
145
+ readonly input: Schema.Codec<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Type"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Encoded"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["DecodingServices"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["EncodingServices"]>;
146
+ readonly origin: Schema.String;
147
+ readonly startedAt: Schema.Number;
148
+ readonly generation: Schema.Int;
149
+ readonly probe: Schema.Int;
150
+ }> | Exclude<H["DecodingServices"], never> | Exclude<H["EncodingServices"], never> | Exclude<R, FlowInstance | import("effect/Scope").Scope | import("./FlowRuntime/FlowRuntime.ts").FlowRuntime> | Exclude<R, import("effect/Scope").Scope>>>, Exclude<Layer.Services<Layer.Layer<Action.Requirement<`${Tag}/initialize`> | Action.Requirement<`${Tag}/start`> | Action.Requirement<`${Tag}/status`> | Action.Requirement<`${Tag}/collect`> | Action.Requirement<`${Tag}/cancel`> | Action.Requirement<`${Tag}/fail`> | Action.Requirement<`${Tag}/ready`> | Action.Requirement<`${Tag}/launch-timeout`>, never, import("effect/Crypto").Crypto | import("./FlowRuntime/FlowRuntime.ts").FlowRuntime | Action.Implementations | {
151
+ executionId: string;
152
+ current: {
153
+ handle: H["Type"];
154
+ key: string;
155
+ } | undefined;
156
+ } | Exclude<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["DecodingServices"], never> | Exclude<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["EncodingServices"], never> | A["DecodingServices"] | Exclude<A["DecodingServices"], never> | A["EncodingServices"] | Exclude<A["EncodingServices"], never> | E["DecodingServices"] | Exclude<E["DecodingServices"], never> | E["EncodingServices"] | Exclude<E["EncodingServices"], never> | Exclude<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["DecodingServices"], never> | Exclude<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["EncodingServices"], never> | Schema.Struct.DecodingServices<{
157
+ readonly handle: Schema.Codec<H["Type"], H["Encoded"], H["DecodingServices"], H["EncodingServices"]>;
158
+ readonly input: Schema.Codec<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Type"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Encoded"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["DecodingServices"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["EncodingServices"]>;
159
+ readonly origin: Schema.String;
160
+ readonly startedAt: Schema.Number;
161
+ readonly generation: Schema.Int;
162
+ readonly probe: Schema.Int;
163
+ }> | Schema.Struct.EncodingServices<{
164
+ readonly handle: Schema.Codec<H["Type"], H["Encoded"], H["DecodingServices"], H["EncodingServices"]>;
165
+ readonly input: Schema.Codec<(P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Type"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["Encoded"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["DecodingServices"], (P extends Schema.Struct.Fields ? Schema.Struct<P> : P)["EncodingServices"]>;
166
+ readonly origin: Schema.String;
167
+ readonly startedAt: Schema.Number;
168
+ readonly generation: Schema.Int;
169
+ readonly probe: Schema.Int;
170
+ }> | Exclude<H["DecodingServices"], never> | Exclude<H["EncodingServices"], never> | Exclude<R, FlowInstance | import("effect/Scope").Scope | import("./FlowRuntime/FlowRuntime.ts").FlowRuntime> | Exclude<R, import("effect/Scope").Scope>>>, {
171
+ executionId: string;
172
+ current: {
173
+ handle: H["Type"];
174
+ key: string;
175
+ } | undefined;
176
+ }>>;
177
+ } & Flow.Flow<Tag, P extends Schema.Struct.Fields ? Schema.Struct<P> : P, A, Schema.Union<readonly [E, typeof ExternalJobLost, typeof ExternalJobTimedOut, typeof Sleep.SleepRequestInvalid]>, Action.Requirement<string>>;
178
+ export {};
179
+ //# sourceMappingURL=ExternalJob.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExternalJob.d.ts","sourceRoot":"","sources":["../../src/ExternalJob.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA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