@smthrs/flow 0.0.0-stage → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +160 -0
- package/LICENSE +21 -0
- package/README.md +210 -2
- package/THIRD_PARTY_NOTICES.md +52 -0
- package/dist/cjs/Action/Action.d.ts +250 -0
- package/dist/cjs/Action/Action.d.ts.map +1 -0
- package/dist/cjs/Action/Action.js +42 -0
- package/dist/cjs/Action/Action.js.map +7 -0
- package/dist/cjs/Action/AttemptTimedOut.d.ts +33 -0
- package/dist/cjs/Action/AttemptTimedOut.d.ts.map +1 -0
- package/dist/cjs/Action/AttemptTimedOut.js +51 -0
- package/dist/cjs/Action/AttemptTimedOut.js.map +7 -0
- package/dist/cjs/Action/BoundaryMode.d.ts +29 -0
- package/dist/cjs/Action/BoundaryMode.d.ts.map +1 -0
- package/dist/cjs/Action/BoundaryMode.js +36 -0
- package/dist/cjs/Action/BoundaryMode.js.map +7 -0
- package/dist/cjs/Action/CacheEnvironment.d.ts +158 -0
- package/dist/cjs/Action/CacheEnvironment.d.ts.map +1 -0
- package/dist/cjs/Action/CacheEnvironment.js +57 -0
- package/dist/cjs/Action/CacheEnvironment.js.map +7 -0
- package/dist/cjs/Action/ConcurrentKeylessDispatch.d.ts +34 -0
- package/dist/cjs/Action/ConcurrentKeylessDispatch.d.ts.map +1 -0
- package/dist/cjs/Action/ConcurrentKeylessDispatch.js +46 -0
- package/dist/cjs/Action/ConcurrentKeylessDispatch.js.map +7 -0
- package/dist/cjs/Action/Context.d.ts +131 -0
- package/dist/cjs/Action/Context.d.ts.map +1 -0
- package/dist/cjs/Action/Context.js +68 -0
- package/dist/cjs/Action/Context.js.map +7 -0
- package/dist/cjs/Action/DuplicateImplementation.d.ts +20 -0
- package/dist/cjs/Action/DuplicateImplementation.d.ts.map +1 -0
- package/dist/cjs/Action/DuplicateImplementation.js +46 -0
- package/dist/cjs/Action/DuplicateImplementation.js.map +7 -0
- package/dist/cjs/Action/FileBoundary.d.ts +59 -0
- package/dist/cjs/Action/FileBoundary.d.ts.map +1 -0
- package/dist/cjs/Action/FileBoundary.js +81 -0
- package/dist/cjs/Action/FileBoundary.js.map +7 -0
- package/dist/cjs/Action/FileInput.d.ts +28 -0
- package/dist/cjs/Action/FileInput.d.ts.map +1 -0
- package/dist/cjs/Action/FileInput.js +42 -0
- package/dist/cjs/Action/FileInput.js.map +7 -0
- package/dist/cjs/Action/Filegroup.d.ts +16 -0
- package/dist/cjs/Action/Filegroup.d.ts.map +1 -0
- package/dist/cjs/Action/Filegroup.js +27 -0
- package/dist/cjs/Action/Filegroup.js.map +7 -0
- package/dist/cjs/Action/Glob.d.ts +8 -0
- package/dist/cjs/Action/Glob.d.ts.map +1 -0
- package/dist/cjs/Action/Glob.js +28 -0
- package/dist/cjs/Action/Glob.js.map +7 -0
- package/dist/cjs/Action/ImplementationVersionMismatch.d.ts +26 -0
- package/dist/cjs/Action/ImplementationVersionMismatch.d.ts.map +1 -0
- package/dist/cjs/Action/ImplementationVersionMismatch.js +45 -0
- package/dist/cjs/Action/ImplementationVersionMismatch.js.map +7 -0
- package/dist/cjs/Action/Implementations.d.ts +114 -0
- package/dist/cjs/Action/Implementations.d.ts.map +1 -0
- package/dist/cjs/Action/Implementations.js +65 -0
- package/dist/cjs/Action/Implementations.js.map +7 -0
- package/dist/cjs/Action/InfraInterrupt.d.ts +26 -0
- package/dist/cjs/Action/InfraInterrupt.d.ts.map +1 -0
- package/dist/cjs/Action/InfraInterrupt.js +46 -0
- package/dist/cjs/Action/InfraInterrupt.js.map +7 -0
- package/dist/cjs/Action/InfraInterruptRetriesExhausted.d.ts +33 -0
- package/dist/cjs/Action/InfraInterruptRetriesExhausted.d.ts.map +1 -0
- package/dist/cjs/Action/InfraInterruptRetriesExhausted.js +54 -0
- package/dist/cjs/Action/InfraInterruptRetriesExhausted.js.map +7 -0
- package/dist/cjs/Action/IrreversibleRetryRequiresIdempotencyKey.d.ts +26 -0
- package/dist/cjs/Action/IrreversibleRetryRequiresIdempotencyKey.d.ts.map +1 -0
- package/dist/cjs/Action/IrreversibleRetryRequiresIdempotencyKey.js +47 -0
- package/dist/cjs/Action/IrreversibleRetryRequiresIdempotencyKey.js.map +7 -0
- package/dist/cjs/Action/StepIdentity.d.ts +153 -0
- package/dist/cjs/Action/StepIdentity.d.ts.map +1 -0
- package/dist/cjs/Action/StepIdentity.js +75 -0
- package/dist/cjs/Action/StepIdentity.js.map +7 -0
- package/dist/cjs/Action/TreeArtifact.d.ts +8 -0
- package/dist/cjs/Action/TreeArtifact.d.ts.map +1 -0
- package/dist/cjs/Action/TreeArtifact.js +25 -0
- package/dist/cjs/Action/TreeArtifact.js.map +7 -0
- package/dist/cjs/Action/TypeId.d.ts +8 -0
- package/dist/cjs/Action/TypeId.d.ts.map +1 -0
- package/dist/cjs/Action/TypeId.js +25 -0
- package/dist/cjs/Action/TypeId.js.map +7 -0
- package/dist/cjs/Action/UncanonicalIdempotencyKey.d.ts +32 -0
- package/dist/cjs/Action/UncanonicalIdempotencyKey.d.ts.map +1 -0
- package/dist/cjs/Action/UncanonicalIdempotencyKey.js +51 -0
- package/dist/cjs/Action/UncanonicalIdempotencyKey.js.map +7 -0
- package/dist/cjs/Action/idempotencyKey.d.ts +21 -0
- package/dist/cjs/Action/idempotencyKey.d.ts.map +1 -0
- package/dist/cjs/Action/idempotencyKey.js +59 -0
- package/dist/cjs/Action/idempotencyKey.js.map +7 -0
- package/dist/cjs/Action/index.d.ts +29 -0
- package/dist/cjs/Action/index.d.ts.map +1 -0
- package/dist/cjs/Action/index.js +60 -0
- package/dist/cjs/Action/index.js.map +7 -0
- package/dist/cjs/Action/make.d.ts +128 -0
- package/dist/cjs/Action/make.d.ts.map +1 -0
- package/dist/cjs/Action/make.js +373 -0
- package/dist/cjs/Action/make.js.map +7 -0
- package/dist/cjs/Action/raceAll.d.ts +21 -0
- package/dist/cjs/Action/raceAll.d.ts.map +1 -0
- package/dist/cjs/Action/raceAll.js +46 -0
- package/dist/cjs/Action/raceAll.js.map +7 -0
- package/dist/cjs/Action/retry.d.ts +19 -0
- package/dist/cjs/Action/retry.d.ts.map +1 -0
- package/dist/cjs/Action/retry.js +75 -0
- package/dist/cjs/Action/retry.js.map +7 -0
- package/dist/cjs/Deadline.d.ts +105 -0
- package/dist/cjs/Deadline.d.ts.map +1 -0
- package/dist/cjs/Deadline.js +104 -0
- package/dist/cjs/Deadline.js.map +7 -0
- package/dist/cjs/DurableClock.d.ts +61 -0
- package/dist/cjs/DurableClock.d.ts.map +1 -0
- package/dist/cjs/DurableClock.js +90 -0
- package/dist/cjs/DurableClock.js.map +7 -0
- package/dist/cjs/DurableDeferred.d.ts +311 -0
- package/dist/cjs/DurableDeferred.d.ts.map +1 -0
- package/dist/cjs/DurableDeferred.js +322 -0
- package/dist/cjs/DurableDeferred.js.map +7 -0
- package/dist/cjs/DurableQueue.d.ts +160 -0
- package/dist/cjs/DurableQueue.d.ts.map +1 -0
- package/dist/cjs/DurableQueue.js +229 -0
- package/dist/cjs/DurableQueue.js.map +7 -0
- package/dist/cjs/ExternalJob.d.ts +179 -0
- package/dist/cjs/ExternalJob.d.ts.map +1 -0
- package/dist/cjs/ExternalJob.js +338 -0
- package/dist/cjs/ExternalJob.js.map +7 -0
- package/dist/cjs/Fault.d.ts +131 -0
- package/dist/cjs/Fault.d.ts.map +1 -0
- package/dist/cjs/Fault.js +157 -0
- package/dist/cjs/Fault.js.map +7 -0
- package/dist/cjs/Flow/Annotations.d.ts +245 -0
- package/dist/cjs/Flow/Annotations.d.ts.map +1 -0
- package/dist/cjs/Flow/Annotations.js +72 -0
- package/dist/cjs/Flow/Annotations.js.map +7 -0
- package/dist/cjs/Flow/CapabilityCeiling.d.ts +21 -0
- package/dist/cjs/Flow/CapabilityCeiling.d.ts.map +1 -0
- package/dist/cjs/Flow/CapabilityCeiling.js +49 -0
- package/dist/cjs/Flow/CapabilityCeiling.js.map +7 -0
- package/dist/cjs/Flow/DeadlineExceeded.d.ts +33 -0
- package/dist/cjs/Flow/DeadlineExceeded.d.ts.map +1 -0
- package/dist/cjs/Flow/DeadlineExceeded.js +52 -0
- package/dist/cjs/Flow/DeadlineExceeded.js.map +7 -0
- package/dist/cjs/Flow/ExecutionIdRequired.d.ts +25 -0
- package/dist/cjs/Flow/ExecutionIdRequired.d.ts.map +1 -0
- package/dist/cjs/Flow/ExecutionIdRequired.js +46 -0
- package/dist/cjs/Flow/ExecutionIdRequired.js.map +7 -0
- package/dist/cjs/Flow/ExecutionIds.d.ts +80 -0
- package/dist/cjs/Flow/ExecutionIds.d.ts.map +1 -0
- package/dist/cjs/Flow/ExecutionIds.js +66 -0
- package/dist/cjs/Flow/ExecutionIds.js.map +7 -0
- package/dist/cjs/Flow/Flow.d.ts +422 -0
- package/dist/cjs/Flow/Flow.d.ts.map +1 -0
- package/dist/cjs/Flow/Flow.js +17 -0
- package/dist/cjs/Flow/Flow.js.map +7 -0
- package/dist/cjs/Flow/MaxRoundsExceeded.d.ts +35 -0
- package/dist/cjs/Flow/MaxRoundsExceeded.d.ts.map +1 -0
- package/dist/cjs/Flow/MaxRoundsExceeded.js +50 -0
- package/dist/cjs/Flow/MaxRoundsExceeded.js.map +7 -0
- package/dist/cjs/Flow/Outcome.d.ts +162 -0
- package/dist/cjs/Flow/Outcome.d.ts.map +1 -0
- package/dist/cjs/Flow/Outcome.js +80 -0
- package/dist/cjs/Flow/Outcome.js.map +7 -0
- package/dist/cjs/Flow/Result.d.ts +186 -0
- package/dist/cjs/Flow/Result.d.ts.map +1 -0
- package/dist/cjs/Flow/Result.js +159 -0
- package/dist/cjs/Flow/Result.js.map +7 -0
- package/dist/cjs/Flow/Runtime.d.ts +98 -0
- package/dist/cjs/Flow/Runtime.d.ts.map +1 -0
- package/dist/cjs/Flow/Runtime.js +160 -0
- package/dist/cjs/Flow/Runtime.js.map +7 -0
- package/dist/cjs/Flow/TypeId.d.ts +8 -0
- package/dist/cjs/Flow/TypeId.d.ts.map +1 -0
- package/dist/cjs/Flow/TypeId.js +25 -0
- package/dist/cjs/Flow/TypeId.js.map +7 -0
- package/dist/cjs/Flow/index.d.ts +17 -0
- package/dist/cjs/Flow/index.d.ts.map +1 -0
- package/dist/cjs/Flow/index.js +29 -0
- package/dist/cjs/Flow/index.js.map +7 -0
- package/dist/cjs/Flow/internal.d.ts +34 -0
- package/dist/cjs/Flow/internal.d.ts.map +1 -0
- package/dist/cjs/Flow/internal.js +187 -0
- package/dist/cjs/Flow/internal.js.map +7 -0
- package/dist/cjs/Flow/make.d.ts +134 -0
- package/dist/cjs/Flow/make.d.ts.map +1 -0
- package/dist/cjs/Flow/make.js +104 -0
- package/dist/cjs/Flow/make.js.map +7 -0
- package/dist/cjs/FlowRuntime/CancelRequestFailed.d.ts +55 -0
- package/dist/cjs/FlowRuntime/CancelRequestFailed.d.ts.map +1 -0
- package/dist/cjs/FlowRuntime/CancelRequestFailed.js +51 -0
- package/dist/cjs/FlowRuntime/CancelRequestFailed.js.map +7 -0
- package/dist/cjs/FlowRuntime/ExecutionIdentityConflict.d.ts +23 -0
- package/dist/cjs/FlowRuntime/ExecutionIdentityConflict.d.ts.map +1 -0
- package/dist/cjs/FlowRuntime/ExecutionIdentityConflict.js +55 -0
- package/dist/cjs/FlowRuntime/ExecutionIdentityConflict.js.map +7 -0
- package/dist/cjs/FlowRuntime/FlowCycleDetected.d.ts +28 -0
- package/dist/cjs/FlowRuntime/FlowCycleDetected.d.ts.map +1 -0
- package/dist/cjs/FlowRuntime/FlowCycleDetected.js +49 -0
- package/dist/cjs/FlowRuntime/FlowCycleDetected.js.map +7 -0
- package/dist/cjs/FlowRuntime/FlowExecutionNotFound.d.ts +38 -0
- package/dist/cjs/FlowRuntime/FlowExecutionNotFound.d.ts.map +1 -0
- package/dist/cjs/FlowRuntime/FlowExecutionNotFound.js +53 -0
- package/dist/cjs/FlowRuntime/FlowExecutionNotFound.js.map +7 -0
- package/dist/cjs/FlowRuntime/FlowInstance.d.ts +115 -0
- package/dist/cjs/FlowRuntime/FlowInstance.d.ts.map +1 -0
- package/dist/cjs/FlowRuntime/FlowInstance.js +37 -0
- package/dist/cjs/FlowRuntime/FlowInstance.js.map +7 -0
- package/dist/cjs/FlowRuntime/FlowRuntime.d.ts +198 -0
- package/dist/cjs/FlowRuntime/FlowRuntime.d.ts.map +1 -0
- package/dist/cjs/FlowRuntime/FlowRuntime.js +37 -0
- package/dist/cjs/FlowRuntime/FlowRuntime.js.map +7 -0
- package/dist/cjs/FlowRuntime/NodeRecord.d.ts +175 -0
- package/dist/cjs/FlowRuntime/NodeRecord.d.ts.map +1 -0
- package/dist/cjs/FlowRuntime/NodeRecord.js +17 -0
- package/dist/cjs/FlowRuntime/NodeRecord.js.map +7 -0
- package/dist/cjs/FlowRuntime/WaitingAnnotation.d.ts +69 -0
- package/dist/cjs/FlowRuntime/WaitingAnnotation.d.ts.map +1 -0
- package/dist/cjs/FlowRuntime/WaitingAnnotation.js +53 -0
- package/dist/cjs/FlowRuntime/WaitingAnnotation.js.map +7 -0
- package/dist/cjs/FlowRuntime/index.d.ts +14 -0
- package/dist/cjs/FlowRuntime/index.d.ts.map +1 -0
- package/dist/cjs/FlowRuntime/index.js +26 -0
- package/dist/cjs/FlowRuntime/index.js.map +7 -0
- package/dist/cjs/Graph.d.ts +325 -0
- package/dist/cjs/Graph.d.ts.map +1 -0
- package/dist/cjs/Graph.js +1022 -0
- package/dist/cjs/Graph.js.map +7 -0
- package/dist/cjs/HumanTask.d.ts +440 -0
- package/dist/cjs/HumanTask.d.ts.map +1 -0
- package/dist/cjs/HumanTask.js +413 -0
- package/dist/cjs/HumanTask.js.map +7 -0
- package/dist/cjs/Interpreter.d.ts +222 -0
- package/dist/cjs/Interpreter.d.ts.map +1 -0
- package/dist/cjs/Interpreter.js +888 -0
- package/dist/cjs/Interpreter.js.map +7 -0
- package/dist/cjs/Poll.d.ts +238 -0
- package/dist/cjs/Poll.d.ts.map +1 -0
- package/dist/cjs/Poll.js +150 -0
- package/dist/cjs/Poll.js.map +7 -0
- package/dist/cjs/RetryPolicy.d.ts +273 -0
- package/dist/cjs/RetryPolicy.d.ts.map +1 -0
- package/dist/cjs/RetryPolicy.js +251 -0
- package/dist/cjs/RetryPolicy.js.map +7 -0
- package/dist/cjs/Sleep.d.ts +98 -0
- package/dist/cjs/Sleep.d.ts.map +1 -0
- package/dist/cjs/Sleep.js +133 -0
- package/dist/cjs/Sleep.js.map +7 -0
- package/dist/cjs/Stall.d.ts +173 -0
- package/dist/cjs/Stall.d.ts.map +1 -0
- package/dist/cjs/Stall.js +92 -0
- package/dist/cjs/Stall.js.map +7 -0
- package/dist/cjs/WaitFor.d.ts +109 -0
- package/dist/cjs/WaitFor.d.ts.map +1 -0
- package/dist/cjs/WaitFor.js +117 -0
- package/dist/cjs/WaitFor.js.map +7 -0
- package/dist/cjs/index.d.ts +107 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +69 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/BoundedJson.d.ts +48 -0
- package/dist/cjs/internal/BoundedJson.d.ts.map +1 -0
- package/dist/cjs/internal/BoundedJson.js +96 -0
- package/dist/cjs/internal/BoundedJson.js.map +7 -0
- package/dist/cjs/internal/DeclarationSite.d.ts +135 -0
- package/dist/cjs/internal/DeclarationSite.d.ts.map +1 -0
- package/dist/cjs/internal/DeclarationSite.js +89 -0
- package/dist/cjs/internal/DeclarationSite.js.map +7 -0
- package/dist/cjs/internal/Declarations.d.ts +35 -0
- package/dist/cjs/internal/Declarations.d.ts.map +1 -0
- package/dist/cjs/internal/Declarations.js +50 -0
- package/dist/cjs/internal/Declarations.js.map +7 -0
- package/dist/cjs/internal/ExecutionMiddleware.d.ts +21 -0
- package/dist/cjs/internal/ExecutionMiddleware.d.ts.map +1 -0
- package/dist/cjs/internal/ExecutionMiddleware.js +39 -0
- package/dist/cjs/internal/ExecutionMiddleware.js.map +7 -0
- package/dist/cjs/internal/JsonSchemaSubset.d.ts +133 -0
- package/dist/cjs/internal/JsonSchemaSubset.d.ts.map +1 -0
- package/dist/cjs/internal/JsonSchemaSubset.js +229 -0
- package/dist/cjs/internal/JsonSchemaSubset.js.map +7 -0
- package/dist/cjs/internal/OutcomeMarker.d.ts +18 -0
- package/dist/cjs/internal/OutcomeMarker.d.ts.map +1 -0
- package/dist/cjs/internal/OutcomeMarker.js +27 -0
- package/dist/cjs/internal/OutcomeMarker.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/Action/Action.d.ts +250 -0
- package/dist/esm/Action/Action.d.ts.map +1 -0
- package/dist/esm/Action/Action.js +30 -0
- package/dist/esm/Action/Action.js.map +1 -0
- package/dist/esm/Action/AttemptTimedOut.d.ts +33 -0
- package/dist/esm/Action/AttemptTimedOut.d.ts.map +1 -0
- package/dist/esm/Action/AttemptTimedOut.js +32 -0
- package/dist/esm/Action/AttemptTimedOut.js.map +1 -0
- package/dist/esm/Action/BoundaryMode.d.ts +29 -0
- package/dist/esm/Action/BoundaryMode.d.ts.map +1 -0
- package/dist/esm/Action/BoundaryMode.js +23 -0
- package/dist/esm/Action/BoundaryMode.js.map +1 -0
- package/dist/esm/Action/CacheEnvironment.d.ts +158 -0
- package/dist/esm/Action/CacheEnvironment.d.ts.map +1 -0
- package/dist/esm/Action/CacheEnvironment.js +130 -0
- package/dist/esm/Action/CacheEnvironment.js.map +1 -0
- package/dist/esm/Action/ConcurrentKeylessDispatch.d.ts +34 -0
- package/dist/esm/Action/ConcurrentKeylessDispatch.d.ts.map +1 -0
- package/dist/esm/Action/ConcurrentKeylessDispatch.js +33 -0
- package/dist/esm/Action/ConcurrentKeylessDispatch.js.map +1 -0
- package/dist/esm/Action/Context.d.ts +131 -0
- package/dist/esm/Action/Context.d.ts.map +1 -0
- package/dist/esm/Action/Context.js +99 -0
- package/dist/esm/Action/Context.js.map +1 -0
- package/dist/esm/Action/DuplicateImplementation.d.ts +20 -0
- package/dist/esm/Action/DuplicateImplementation.d.ts.map +1 -0
- package/dist/esm/Action/DuplicateImplementation.js +20 -0
- package/dist/esm/Action/DuplicateImplementation.js.map +1 -0
- package/dist/esm/Action/FileBoundary.d.ts +59 -0
- package/dist/esm/Action/FileBoundary.d.ts.map +1 -0
- package/dist/esm/Action/FileBoundary.js +60 -0
- package/dist/esm/Action/FileBoundary.js.map +1 -0
- package/dist/esm/Action/FileInput.d.ts +28 -0
- package/dist/esm/Action/FileInput.d.ts.map +1 -0
- package/dist/esm/Action/FileInput.js +32 -0
- package/dist/esm/Action/FileInput.js.map +1 -0
- package/dist/esm/Action/Filegroup.d.ts +16 -0
- package/dist/esm/Action/Filegroup.d.ts.map +1 -0
- package/dist/esm/Action/Filegroup.js +15 -0
- package/dist/esm/Action/Filegroup.js.map +1 -0
- package/dist/esm/Action/Glob.d.ts +8 -0
- package/dist/esm/Action/Glob.d.ts.map +1 -0
- package/dist/esm/Action/Glob.js +7 -0
- package/dist/esm/Action/Glob.js.map +1 -0
- package/dist/esm/Action/ImplementationVersionMismatch.d.ts +26 -0
- package/dist/esm/Action/ImplementationVersionMismatch.d.ts.map +1 -0
- package/dist/esm/Action/ImplementationVersionMismatch.js +24 -0
- package/dist/esm/Action/ImplementationVersionMismatch.js.map +1 -0
- package/dist/esm/Action/Implementations.d.ts +114 -0
- package/dist/esm/Action/Implementations.d.ts.map +1 -0
- package/dist/esm/Action/Implementations.js +94 -0
- package/dist/esm/Action/Implementations.js.map +1 -0
- package/dist/esm/Action/InfraInterrupt.d.ts +26 -0
- package/dist/esm/Action/InfraInterrupt.d.ts.map +1 -0
- package/dist/esm/Action/InfraInterrupt.js +25 -0
- package/dist/esm/Action/InfraInterrupt.js.map +1 -0
- package/dist/esm/Action/InfraInterruptRetriesExhausted.d.ts +33 -0
- package/dist/esm/Action/InfraInterruptRetriesExhausted.d.ts.map +1 -0
- package/dist/esm/Action/InfraInterruptRetriesExhausted.js +32 -0
- package/dist/esm/Action/InfraInterruptRetriesExhausted.js.map +1 -0
- package/dist/esm/Action/IrreversibleRetryRequiresIdempotencyKey.d.ts +26 -0
- package/dist/esm/Action/IrreversibleRetryRequiresIdempotencyKey.d.ts.map +1 -0
- package/dist/esm/Action/IrreversibleRetryRequiresIdempotencyKey.js +25 -0
- package/dist/esm/Action/IrreversibleRetryRequiresIdempotencyKey.js.map +1 -0
- package/dist/esm/Action/StepIdentity.d.ts +153 -0
- package/dist/esm/Action/StepIdentity.d.ts.map +1 -0
- package/dist/esm/Action/StepIdentity.js +139 -0
- package/dist/esm/Action/StepIdentity.js.map +1 -0
- package/dist/esm/Action/TreeArtifact.d.ts +8 -0
- package/dist/esm/Action/TreeArtifact.d.ts.map +1 -0
- package/dist/esm/Action/TreeArtifact.js +7 -0
- package/dist/esm/Action/TreeArtifact.js.map +1 -0
- package/dist/esm/Action/TypeId.d.ts +8 -0
- package/dist/esm/Action/TypeId.d.ts.map +1 -0
- package/dist/esm/Action/TypeId.js +9 -0
- package/dist/esm/Action/TypeId.js.map +1 -0
- package/dist/esm/Action/UncanonicalIdempotencyKey.d.ts +32 -0
- package/dist/esm/Action/UncanonicalIdempotencyKey.d.ts.map +1 -0
- package/dist/esm/Action/UncanonicalIdempotencyKey.js +31 -0
- package/dist/esm/Action/UncanonicalIdempotencyKey.js.map +1 -0
- package/dist/esm/Action/idempotencyKey.d.ts +21 -0
- package/dist/esm/Action/idempotencyKey.d.ts.map +1 -0
- package/dist/esm/Action/idempotencyKey.js +50 -0
- package/dist/esm/Action/idempotencyKey.js.map +1 -0
- package/dist/esm/Action/index.d.ts +29 -0
- package/dist/esm/Action/index.d.ts.map +1 -0
- package/dist/esm/Action/index.js +30 -0
- package/dist/esm/Action/index.js.map +1 -0
- package/dist/esm/Action/make.d.ts +128 -0
- package/dist/esm/Action/make.d.ts.map +1 -0
- package/dist/esm/Action/make.js +405 -0
- package/dist/esm/Action/make.js.map +1 -0
- package/dist/esm/Action/raceAll.d.ts +21 -0
- package/dist/esm/Action/raceAll.d.ts.map +1 -0
- package/dist/esm/Action/raceAll.js +20 -0
- package/dist/esm/Action/raceAll.js.map +1 -0
- package/dist/esm/Action/retry.d.ts +19 -0
- package/dist/esm/Action/retry.d.ts.map +1 -0
- package/dist/esm/Action/retry.js +72 -0
- package/dist/esm/Action/retry.js.map +1 -0
- package/dist/esm/Deadline.d.ts +105 -0
- package/dist/esm/Deadline.d.ts.map +1 -0
- package/dist/esm/Deadline.js +152 -0
- package/dist/esm/Deadline.js.map +1 -0
- package/dist/esm/DurableClock.d.ts +61 -0
- package/dist/esm/DurableClock.d.ts.map +1 -0
- package/dist/esm/DurableClock.js +75 -0
- package/dist/esm/DurableClock.js.map +1 -0
- package/dist/esm/DurableDeferred.d.ts +311 -0
- package/dist/esm/DurableDeferred.d.ts.map +1 -0
- package/dist/esm/DurableDeferred.js +357 -0
- package/dist/esm/DurableDeferred.js.map +1 -0
- package/dist/esm/DurableQueue.d.ts +160 -0
- package/dist/esm/DurableQueue.d.ts.map +1 -0
- package/dist/esm/DurableQueue.js +303 -0
- package/dist/esm/DurableQueue.js.map +1 -0
- package/dist/esm/ExternalJob.d.ts +179 -0
- package/dist/esm/ExternalJob.d.ts.map +1 -0
- package/dist/esm/ExternalJob.js +296 -0
- package/dist/esm/ExternalJob.js.map +1 -0
- package/dist/esm/Fault.d.ts +131 -0
- package/dist/esm/Fault.d.ts.map +1 -0
- package/dist/esm/Fault.js +198 -0
- package/dist/esm/Fault.js.map +1 -0
- package/dist/esm/Flow/Annotations.d.ts +245 -0
- package/dist/esm/Flow/Annotations.d.ts.map +1 -0
- package/dist/esm/Flow/Annotations.js +110 -0
- package/dist/esm/Flow/Annotations.js.map +1 -0
- package/dist/esm/Flow/CapabilityCeiling.d.ts +21 -0
- package/dist/esm/Flow/CapabilityCeiling.d.ts.map +1 -0
- package/dist/esm/Flow/CapabilityCeiling.js +27 -0
- package/dist/esm/Flow/CapabilityCeiling.js.map +1 -0
- package/dist/esm/Flow/DeadlineExceeded.d.ts +33 -0
- package/dist/esm/Flow/DeadlineExceeded.d.ts.map +1 -0
- package/dist/esm/Flow/DeadlineExceeded.js +34 -0
- package/dist/esm/Flow/DeadlineExceeded.js.map +1 -0
- package/dist/esm/Flow/ExecutionIdRequired.d.ts +25 -0
- package/dist/esm/Flow/ExecutionIdRequired.d.ts.map +1 -0
- package/dist/esm/Flow/ExecutionIdRequired.js +30 -0
- package/dist/esm/Flow/ExecutionIdRequired.js.map +1 -0
- package/dist/esm/Flow/ExecutionIds.d.ts +80 -0
- package/dist/esm/Flow/ExecutionIds.d.ts.map +1 -0
- package/dist/esm/Flow/ExecutionIds.js +91 -0
- package/dist/esm/Flow/ExecutionIds.js.map +1 -0
- package/dist/esm/Flow/Flow.d.ts +422 -0
- package/dist/esm/Flow/Flow.d.ts.map +1 -0
- package/dist/esm/Flow/Flow.js +3 -0
- package/dist/esm/Flow/Flow.js.map +1 -0
- package/dist/esm/Flow/MaxRoundsExceeded.d.ts +35 -0
- package/dist/esm/Flow/MaxRoundsExceeded.d.ts.map +1 -0
- package/dist/esm/Flow/MaxRoundsExceeded.js +34 -0
- package/dist/esm/Flow/MaxRoundsExceeded.js.map +1 -0
- package/dist/esm/Flow/Outcome.d.ts +162 -0
- package/dist/esm/Flow/Outcome.d.ts.map +1 -0
- package/dist/esm/Flow/Outcome.js +115 -0
- package/dist/esm/Flow/Outcome.js.map +1 -0
- package/dist/esm/Flow/Result.d.ts +186 -0
- package/dist/esm/Flow/Result.d.ts.map +1 -0
- package/dist/esm/Flow/Result.js +171 -0
- package/dist/esm/Flow/Result.js.map +1 -0
- package/dist/esm/Flow/Runtime.d.ts +98 -0
- package/dist/esm/Flow/Runtime.d.ts.map +1 -0
- package/dist/esm/Flow/Runtime.js +231 -0
- package/dist/esm/Flow/Runtime.js.map +1 -0
- package/dist/esm/Flow/TypeId.d.ts +8 -0
- package/dist/esm/Flow/TypeId.d.ts.map +1 -0
- package/dist/esm/Flow/TypeId.js +9 -0
- package/dist/esm/Flow/TypeId.js.map +1 -0
- package/dist/esm/Flow/index.d.ts +17 -0
- package/dist/esm/Flow/index.d.ts.map +1 -0
- package/dist/esm/Flow/index.js +18 -0
- package/dist/esm/Flow/index.js.map +1 -0
- package/dist/esm/Flow/internal.d.ts +34 -0
- package/dist/esm/Flow/internal.d.ts.map +1 -0
- package/dist/esm/Flow/internal.js +149 -0
- package/dist/esm/Flow/internal.js.map +1 -0
- package/dist/esm/Flow/make.d.ts +134 -0
- package/dist/esm/Flow/make.d.ts.map +1 -0
- package/dist/esm/Flow/make.js +106 -0
- package/dist/esm/Flow/make.js.map +1 -0
- package/dist/esm/FlowRuntime/CancelRequestFailed.d.ts +55 -0
- package/dist/esm/FlowRuntime/CancelRequestFailed.d.ts.map +1 -0
- package/dist/esm/FlowRuntime/CancelRequestFailed.js +53 -0
- package/dist/esm/FlowRuntime/CancelRequestFailed.js.map +1 -0
- package/dist/esm/FlowRuntime/ExecutionIdentityConflict.d.ts +23 -0
- package/dist/esm/FlowRuntime/ExecutionIdentityConflict.d.ts.map +1 -0
- package/dist/esm/FlowRuntime/ExecutionIdentityConflict.js +24 -0
- package/dist/esm/FlowRuntime/ExecutionIdentityConflict.js.map +1 -0
- package/dist/esm/FlowRuntime/FlowCycleDetected.d.ts +28 -0
- package/dist/esm/FlowRuntime/FlowCycleDetected.d.ts.map +1 -0
- package/dist/esm/FlowRuntime/FlowCycleDetected.js +35 -0
- package/dist/esm/FlowRuntime/FlowCycleDetected.js.map +1 -0
- package/dist/esm/FlowRuntime/FlowExecutionNotFound.d.ts +38 -0
- package/dist/esm/FlowRuntime/FlowExecutionNotFound.d.ts.map +1 -0
- package/dist/esm/FlowRuntime/FlowExecutionNotFound.js +40 -0
- package/dist/esm/FlowRuntime/FlowExecutionNotFound.js.map +1 -0
- package/dist/esm/FlowRuntime/FlowInstance.d.ts +115 -0
- package/dist/esm/FlowRuntime/FlowInstance.d.ts.map +1 -0
- package/dist/esm/FlowRuntime/FlowInstance.js +24 -0
- package/dist/esm/FlowRuntime/FlowInstance.js.map +1 -0
- package/dist/esm/FlowRuntime/FlowRuntime.d.ts +198 -0
- package/dist/esm/FlowRuntime/FlowRuntime.d.ts.map +1 -0
- package/dist/esm/FlowRuntime/FlowRuntime.js +34 -0
- package/dist/esm/FlowRuntime/FlowRuntime.js.map +1 -0
- package/dist/esm/FlowRuntime/NodeRecord.d.ts +175 -0
- package/dist/esm/FlowRuntime/NodeRecord.d.ts.map +1 -0
- package/dist/esm/FlowRuntime/NodeRecord.js +21 -0
- package/dist/esm/FlowRuntime/NodeRecord.js.map +1 -0
- package/dist/esm/FlowRuntime/WaitingAnnotation.d.ts +69 -0
- package/dist/esm/FlowRuntime/WaitingAnnotation.d.ts.map +1 -0
- package/dist/esm/FlowRuntime/WaitingAnnotation.js +53 -0
- package/dist/esm/FlowRuntime/WaitingAnnotation.js.map +1 -0
- package/dist/esm/FlowRuntime/index.d.ts +14 -0
- package/dist/esm/FlowRuntime/index.d.ts.map +1 -0
- package/dist/esm/FlowRuntime/index.js +15 -0
- package/dist/esm/FlowRuntime/index.js.map +1 -0
- package/dist/esm/Graph.d.ts +325 -0
- package/dist/esm/Graph.d.ts.map +1 -0
- package/dist/esm/Graph.js +1482 -0
- package/dist/esm/Graph.js.map +1 -0
- package/dist/esm/HumanTask.d.ts +440 -0
- package/dist/esm/HumanTask.d.ts.map +1 -0
- package/dist/esm/HumanTask.js +794 -0
- package/dist/esm/HumanTask.js.map +1 -0
- package/dist/esm/Interpreter.d.ts +222 -0
- package/dist/esm/Interpreter.d.ts.map +1 -0
- package/dist/esm/Interpreter.js +1269 -0
- package/dist/esm/Interpreter.js.map +1 -0
- package/dist/esm/Poll.d.ts +238 -0
- package/dist/esm/Poll.d.ts.map +1 -0
- package/dist/esm/Poll.js +282 -0
- package/dist/esm/Poll.js.map +1 -0
- package/dist/esm/RetryPolicy.d.ts +273 -0
- package/dist/esm/RetryPolicy.d.ts.map +1 -0
- package/dist/esm/RetryPolicy.js +429 -0
- package/dist/esm/RetryPolicy.js.map +1 -0
- package/dist/esm/Sleep.d.ts +98 -0
- package/dist/esm/Sleep.d.ts.map +1 -0
- package/dist/esm/Sleep.js +230 -0
- package/dist/esm/Sleep.js.map +1 -0
- package/dist/esm/Stall.d.ts +173 -0
- package/dist/esm/Stall.d.ts.map +1 -0
- package/dist/esm/Stall.js +138 -0
- package/dist/esm/Stall.js.map +1 -0
- package/dist/esm/WaitFor.d.ts +109 -0
- package/dist/esm/WaitFor.d.ts.map +1 -0
- package/dist/esm/WaitFor.js +184 -0
- package/dist/esm/WaitFor.js.map +1 -0
- package/dist/esm/index.d.ts +107 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +108 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/BoundedJson.d.ts +48 -0
- package/dist/esm/internal/BoundedJson.d.ts.map +1 -0
- package/dist/esm/internal/BoundedJson.js +107 -0
- package/dist/esm/internal/BoundedJson.js.map +1 -0
- package/dist/esm/internal/DeclarationSite.d.ts +135 -0
- package/dist/esm/internal/DeclarationSite.d.ts.map +1 -0
- package/dist/esm/internal/DeclarationSite.js +196 -0
- package/dist/esm/internal/DeclarationSite.js.map +1 -0
- package/dist/esm/internal/Declarations.d.ts +35 -0
- package/dist/esm/internal/Declarations.d.ts.map +1 -0
- package/dist/esm/internal/Declarations.js +43 -0
- package/dist/esm/internal/Declarations.js.map +1 -0
- package/dist/esm/internal/ExecutionMiddleware.d.ts +21 -0
- package/dist/esm/internal/ExecutionMiddleware.d.ts.map +1 -0
- package/dist/esm/internal/ExecutionMiddleware.js +13 -0
- package/dist/esm/internal/ExecutionMiddleware.js.map +1 -0
- package/dist/esm/internal/JsonSchemaSubset.d.ts +133 -0
- package/dist/esm/internal/JsonSchemaSubset.d.ts.map +1 -0
- package/dist/esm/internal/JsonSchemaSubset.js +363 -0
- package/dist/esm/internal/JsonSchemaSubset.js.map +1 -0
- package/dist/esm/internal/OutcomeMarker.d.ts +18 -0
- package/dist/esm/internal/OutcomeMarker.d.ts.map +1 -0
- package/dist/esm/internal/OutcomeMarker.js +18 -0
- package/dist/esm/internal/OutcomeMarker.js.map +1 -0
- package/docs/README.md +150 -0
- package/docs/api.md +436 -0
- package/docs/concepts/bodies-and-plans.md +157 -0
- package/docs/concepts/execution-identity.md +142 -0
- package/docs/concepts/flows-and-actions.md +129 -0
- package/docs/concepts/suspension-and-replay.md +130 -0
- package/docs/concepts/the-runtime-port.md +110 -0
- package/docs/concepts/trampoline-rounds.md +151 -0
- package/docs/guides/ask-a-person.md +184 -0
- package/docs/guides/build-a-body.md +161 -0
- package/docs/guides/cancel-and-roll-back.md +112 -0
- package/docs/guides/implement-an-action.md +147 -0
- package/docs/guides/inspect-the-plan.md +154 -0
- package/docs/guides/poll-until-ready.md +167 -0
- package/docs/guides/queue-work-to-a-worker.md +122 -0
- package/docs/guides/retry-a-failing-action.md +243 -0
- package/docs/guides/reuse-a-recorded-result.md +122 -0
- package/docs/guides/run-a-child-flow.md +108 -0
- package/docs/guides/run-an-external-job.md +86 -0
- package/docs/guides/use-a-prompt.md +38 -0
- package/docs/guides/wait-for-a-deadline.md +141 -0
- package/docs/guides/wait-for-an-external-signal.md +151 -0
- package/docs/installation.md +82 -0
- package/docs/quickstart.md +155 -0
- package/docs/reference/flow.md +1831 -0
- package/docs/testing.md +157 -0
- package/docs/troubleshooting.md +286 -0
- package/package.json +327 -3
- package/src/Action/Action.ts +333 -0
- package/src/Action/AttemptTimedOut.ts +37 -0
- package/src/Action/BoundaryMode.ts +33 -0
- package/src/Action/CacheEnvironment.ts +170 -0
- package/src/Action/ConcurrentKeylessDispatch.ts +38 -0
- package/src/Action/Context.ts +156 -0
- package/src/Action/DuplicateImplementation.ts +24 -0
- package/src/Action/FileBoundary.ts +77 -0
- package/src/Action/FileInput.ts +42 -0
- package/src/Action/Filegroup.ts +16 -0
- package/src/Action/Glob.ts +8 -0
- package/src/Action/ImplementationVersionMismatch.ts +27 -0
- package/src/Action/Implementations.ts +149 -0
- package/src/Action/InfraInterrupt.ts +30 -0
- package/src/Action/InfraInterruptRetriesExhausted.ts +37 -0
- package/src/Action/IrreversibleRetryRequiresIdempotencyKey.ts +32 -0
- package/src/Action/StepIdentity.ts +219 -0
- package/src/Action/TreeArtifact.ts +8 -0
- package/src/Action/TypeId.ts +9 -0
- package/src/Action/UncanonicalIdempotencyKey.ts +36 -0
- package/src/Action/idempotencyKey.ts +67 -0
- package/src/Action/index.ts +31 -0
- package/src/Action/make.ts +657 -0
- package/src/Action/raceAll.ts +48 -0
- package/src/Action/retry.ts +92 -0
- package/src/Deadline.ts +185 -0
- package/src/DurableClock.ts +133 -0
- package/src/DurableDeferred.ts +753 -0
- package/src/DurableQueue.ts +519 -0
- package/src/ExternalJob.ts +432 -0
- package/src/Fault.ts +279 -0
- package/src/Flow/Annotations.ts +151 -0
- package/src/Flow/CapabilityCeiling.ts +37 -0
- package/src/Flow/DeadlineExceeded.ts +40 -0
- package/src/Flow/ExecutionIdRequired.ts +36 -0
- package/src/Flow/ExecutionIds.ts +133 -0
- package/src/Flow/Flow.ts +576 -0
- package/src/Flow/MaxRoundsExceeded.ts +39 -0
- package/src/Flow/Outcome.ts +179 -0
- package/src/Flow/Result.ts +284 -0
- package/src/Flow/Runtime.ts +309 -0
- package/src/Flow/TypeId.ts +9 -0
- package/src/Flow/index.ts +19 -0
- package/src/Flow/internal.ts +237 -0
- package/src/Flow/make.ts +279 -0
- package/src/FlowRuntime/CancelRequestFailed.ts +56 -0
- package/src/FlowRuntime/ExecutionIdentityConflict.ts +32 -0
- package/src/FlowRuntime/FlowCycleDetected.ts +41 -0
- package/src/FlowRuntime/FlowExecutionNotFound.ts +46 -0
- package/src/FlowRuntime/FlowInstance.ts +128 -0
- package/src/FlowRuntime/FlowRuntime.ts +333 -0
- package/src/FlowRuntime/NodeRecord.ts +183 -0
- package/src/FlowRuntime/WaitingAnnotation.ts +85 -0
- package/src/FlowRuntime/index.ts +17 -0
- package/src/Graph.ts +1860 -0
- package/src/HumanTask.ts +1003 -0
- package/src/Interpreter.ts +1593 -0
- package/src/Poll.ts +414 -0
- package/src/RetryPolicy.ts +550 -0
- package/src/Sleep.ts +267 -0
- package/src/Stall.ts +217 -0
- package/src/WaitFor.ts +228 -0
- package/src/index.ts +125 -0
- package/src/internal/BoundedJson.ts +109 -0
- package/src/internal/DeclarationSite.ts +214 -0
- package/src/internal/Declarations.ts +49 -0
- package/src/internal/ExecutionMiddleware.ts +29 -0
- package/src/internal/JsonSchemaSubset.ts +392 -0
- package/src/internal/OutcomeMarker.ts +19 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DurableDeferred.js","sourceRoot":"","sources":["../../src/DurableDeferred.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAGnC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,YAAY,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAE1D,MAAM,MAAM,GAAG,8BAA8B,CAAA;AAgD7C,6EAA6E;AAC7E,+EAA+E;AAC/E,oEAAoE;AACpE,MAAM,eAAe,GAAG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O,CAAC,IAAI;KACnB,CAAC,CAAA;AACJ,CAAC,CAAC,CACH,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAchB,IAAI,CACN,CAAC,EACD,CACE,IAAqC,EACrC,OAGC,EAC6E,EAAE,CAChF,IAAI,CAAC,IAAI,EAAE;IACT,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;CAClC,CAAC,CACL,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAcb,IAAI,CACN,CAAC,EACD,CACE,IAAqC,EACrC,OAGC,EAC2E,EAAE,CAC9E,IAAI,CAAC,IAAI,EAAE;IACT,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;CAC/B,CAAC,CACL,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAclB,IAAI,CACN,CAAC,EACD,CACE,IAAqC,EACrC,OAGC,EAC2E,EAAE,CAC9E,IAAI,CAAC,IAAI,EAAE;IACT,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC;CACpC,CAAC,CACL,CAAA","sourcesContent":["// Deep reviewed and polished by a human on 2026-08-10.\n\n/**\n * Defines named wait points for durable flow executions.\n *\n * A `DurableDeferred` has a stable name and schemas for the value that will be\n * recorded later. Flows can await it, suspend when no result exists yet, and\n * resume after its result is recorded. Tokens identify the flow name,\n * execution id, and deferred name so external code can complete the correct\n * wait point later.\n *\n * @since 0.1.0\n */\n\nimport * as Arr from \"effect/Array\"\nimport type { NonEmptyReadonlyArray } from \"effect/Array\"\nimport type * as Brand from \"effect/Brand\"\nimport * as Cause from \"effect/Cause\"\nimport * as Context from \"effect/Context\"\nimport type * as Crypto from \"effect/Crypto\"\nimport * as Effect from \"effect/Effect\"\nimport * as Encoding from \"effect/Encoding\"\nimport * as Exit from \"effect/Exit\"\nimport * as Filter from \"effect/Filter\"\nimport { dual } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport * as Schema from \"effect/Schema\"\nimport * as SchemaGetter from \"effect/SchemaGetter\"\nimport { CurrentAttempt } from \"./Action/Context.ts\"\nimport * as Flow from \"./Flow/index.ts\"\nimport { FlowInstance } from \"./FlowRuntime/FlowInstance.ts\"\nimport { FlowRuntime } from \"./FlowRuntime/FlowRuntime.ts\"\n\nconst TypeId = \"@smthrs/flow/DurableDeferred\"\n\n/**\n * Named durable deferred value whose completion is persisted by the flow\n * engine and encoded with success and error schemas.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface DurableDeferred<\n Success extends Schema.Constraint,\n Error extends Schema.Constraint = Schema.Never\n> {\n readonly [TypeId]: typeof TypeId\n readonly name: string\n readonly successSchema: Success\n readonly errorSchema: Error\n readonly exitSchema: Schema.Exit<Schema.Top, Schema.Top, Schema.Top>\n readonly withActionAttempt: Effect.Effect<DurableDeferred<Success, Error>>\n}\n\n/**\n * Type-erased durable deferred shape for APIs that only need the deferred\n * identity and name.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Any {\n readonly [TypeId]: typeof TypeId\n readonly name: string\n}\n\n/**\n * Type-erased durable deferred shape that also exposes success, error, and\n * exit schemas.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface AnyWithProps {\n readonly [TypeId]: typeof TypeId\n readonly name: string\n readonly successSchema: Schema.Top\n readonly errorSchema: Schema.Top\n readonly exitSchema: Schema.Exit<any, any, any>\n}\n\n// Queues, human tasks and clocks mint a deferred per item, attempt or sleep.\n// Effect caches compiled parsers by AST identity, so the exit schema is shared\n// per (success, error) pair rather than rebuilt for every deferred.\nconst exitSchemaCache = new WeakMap<object, WeakMap<object, Schema.Exit<any, any, any>>>()\n\nconst exitSchemaFor = (success: Schema.Constraint, error: Schema.Constraint): Schema.Exit<any, any, any> => {\n let byError = exitSchemaCache.get(success)\n if (byError === undefined) {\n byError = new WeakMap()\n exitSchemaCache.set(success, byError)\n }\n let cached = byError.get(error)\n if (cached === undefined) {\n cached = Schema.Exit(\n Schema.toCodecJson(success),\n Schema.toCodecJson(error),\n Schema.toCodecJson(Schema.Defect())\n )\n byError.set(error, cached)\n }\n return cached\n}\n\n/**\n * Creates a named durable deferred with optional success and error schemas for\n * persisted completion.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = <\n Success extends Schema.Constraint = Schema.Void,\n Error extends Schema.Constraint = Schema.Never\n>(\n name: string,\n options?: {\n readonly success?: Success | undefined\n readonly error?: Error | undefined\n }\n): DurableDeferred<Success, Error> => {\n const successSchema = options?.success ?? (Schema.Void as any as Success)\n const errorSchema = options?.error ?? (Schema.Never as any as Error)\n return {\n [TypeId]: TypeId as typeof TypeId,\n name,\n successSchema,\n errorSchema,\n exitSchema: exitSchemaFor(successSchema, errorSchema) as any,\n withActionAttempt: Effect.gen(function*() {\n const attempt = yield* CurrentAttempt\n return make(`${name}/${attempt}`, {\n success: successSchema,\n error: errorSchema\n })\n })\n }\n}\n\nconst await_: <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>\n) => Effect.Effect<\n Success[\"Type\"],\n Error[\"Type\"],\n | FlowRuntime\n | FlowInstance\n | Success[\"DecodingServices\"]\n | Error[\"DecodingServices\"]\n> =\n // Untraced because deferred polling participates in the flow scheduler hot path.\n Effect.fnUntraced(function*<\n Success extends Schema.Constraint,\n Error extends Schema.Constraint\n >(self: DurableDeferred<Success, Error>) {\n const engine = yield* FlowRuntime\n const instance = yield* FlowInstance\n const exit = yield* Flow.wrapActionResult(\n engine.deferredResult(self),\n Option.isNone\n )\n if (Option.isNone(exit)) {\n return yield* Flow.suspend(instance)\n }\n const value = exit.value as Exit.Exit<any, any>\n // A recorded interruption is a durable *outcome*, not a request to\n // suspend: mark the instance interrupted before re-raising so\n // `Flow.intoResult` classifies the interrupt-only cause as a `Complete`\n // failure. Without this the driver mistakes the cause for an external\n // suspension interrupt, aborts without a terminal transition, and the\n // run spins in the suspended-retry loop forever.\n if (Exit.isFailure(value) && Cause.hasInterruptsOnly(value.cause)) {\n instance.interrupted = true\n }\n return yield* value\n })\n\nexport {\n /**\n * Waits for the durable deferred, suspending the current flow when no\n * persisted completion is available.\n *\n * @category combinators\n * @since 0.1.0\n */\n await_ as await\n}\n\n/**\n * Runs an effect and records its exit into the durable deferred, resuming\n * flows that are waiting on that deferred.\n *\n * @category combinators\n * @since 0.1.0\n */\nexport const into: {\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>\n ): <R>(\n effect: Effect.Effect<Success[\"Type\"], Error[\"Type\"], R>\n ) => Effect.Effect<\n Success[\"Type\"],\n Error[\"Type\"],\n | R\n | FlowRuntime\n | FlowInstance\n | Success[\"DecodingServices\"]\n | Success[\"EncodingServices\"]\n | Error[\"DecodingServices\"]\n | Error[\"EncodingServices\"]\n >\n <Success extends Schema.Constraint, Error extends Schema.Constraint, R>(\n effect: Effect.Effect<Success[\"Type\"], Error[\"Type\"], R>,\n self: DurableDeferred<Success, Error>\n ): Effect.Effect<\n Success[\"Type\"],\n Error[\"Type\"],\n | R\n | FlowRuntime\n | FlowInstance\n | Success[\"DecodingServices\"]\n | Success[\"EncodingServices\"]\n | Error[\"DecodingServices\"]\n | Error[\"EncodingServices\"]\n >\n} = dual(\n 2,\n <Success extends Schema.Constraint, Error extends Schema.Constraint, R>(\n effect: Effect.Effect<Success[\"Type\"], Error[\"Type\"], R>,\n self: DurableDeferred<Success, Error>\n ): Effect.Effect<\n Success[\"Type\"],\n Error[\"Type\"],\n | R\n | FlowRuntime\n | FlowInstance\n | Success[\"DecodingServices\"]\n | Success[\"EncodingServices\"]\n | Error[\"DecodingServices\"]\n | Error[\"EncodingServices\"]\n > =>\n Effect.contextWith(\n (context: Context.Context<FlowRuntime | FlowInstance>) => {\n const engine = Context.get(context, FlowRuntime)\n const instance = Context.get(context, FlowInstance)\n // Keep the original instance: action regions identify their ancestors\n // by reference, and suspension metadata belongs to the enclosing flow.\n return Effect.onExit(\n effect,\n // Untraced because completion encoding is called for each deferred result.\n Effect.fnUntraced(function*(exit) {\n if (Exit.isFailure(exit)) {\n const [reasons, interrupts] = Arr.partition(\n exit.cause.reasons,\n Filter.fromPredicate(Cause.isInterruptReason)\n )\n const hasInterruptsOnly = interrupts.length === exit.cause.reasons.length\n if (hasInterruptsOnly) {\n // An interrupt-only exit is never a result: the effect was\n // suspended, preempted, or interrupted, so record nothing.\n // Recording here would durably persist the empty non-interrupt\n // partition, and first-writer-wins would replay that empty\n // cause forever instead of the real completion.\n return\n } else if (interrupts.length > 0) {\n exit = Exit.failCause(Cause.fromReasons(reasons))\n }\n }\n yield* engine.deferredDone(self, {\n flowName: instance.flow._tag,\n executionId: instance.executionId,\n deferredName: self.name,\n exit\n })\n })\n )\n }\n )\n)\n\n/**\n * Runs effects as a durable race, returning a previously persisted result when\n * present or completing a named deferred with the first success. The race\n * fails only when every effect fails.\n *\n * @category racing\n * @since 0.1.0\n */\nexport const raceAll = <\n const Effects extends NonEmptyReadonlyArray<Effect.Effect<any, any, any>>,\n Success extends Schema.Schema<Effect.Success<Effects[number]>>,\n Error extends Schema.Schema<Effect.Error<Effects[number]>>\n>(options: {\n name: string\n success: Success\n error: Error\n effects: Effects\n}): Effect.Effect<\n Effect.Success<Effects[number]>,\n Effect.Error<Effects[number]>,\n | Effect.Services<Effects[number]>\n | Success[\"DecodingServices\"]\n | Success[\"EncodingServices\"]\n | Error[\"DecodingServices\"]\n | Error[\"EncodingServices\"]\n | FlowRuntime\n | FlowInstance\n> => {\n const deferred = make<any, any>(`raceAll/${options.name}`, {\n success: options.success,\n error: options.error\n })\n return Effect.gen(function*() {\n const engine = yield* FlowRuntime\n const exit = yield* engine.deferredResult(deferred)\n if (Option.isSome(exit)) {\n return yield* exit.value\n }\n return yield* into(\n Effect.raceAll(options.effects),\n deferred\n )\n })\n}\n\n/**\n * Runtime brand identifier for durable deferred tokens.\n *\n * @category type IDs\n * @since 0.1.0\n */\nexport const TokenTypeId = \"@smthrs/flow/DurableDeferred/Token\"\n\n/**\n * Type-level brand identifier for `Token` values.\n *\n * @category type IDs\n * @since 0.1.0\n */\nexport type TokenTypeId = typeof TokenTypeId\n\n/**\n * Branded string token identifying a durable deferred for a flow\n * execution.\n *\n * A token is an address, not a credential. It is unsigned base64url JSON of\n * the flow name, execution id, and deferred name, and `tokenFromExecutionId`\n * and `tokenFromPayload` rebuild it from those values alone. Anyone who can\n * call `done`, `succeed`, `fail`, `failCause`, or `HumanTask.answer` against\n * the run's `FlowRuntime` can complete an open wait whose address they know or\n * derive. A host that exposes completion to other parties must authorize the\n * caller before it calls one of them.\n *\n * @category token\n * @since 0.1.0\n */\nexport type Token = Brand.Branded<string, TokenTypeId>\n\n/**\n * Schema for branded durable deferred tokens.\n *\n * @category token\n * @since 0.1.0\n */\nexport const Token: Schema.brand<Schema.String, TokenTypeId> = Schema.String.pipe(Schema.brand(TokenTypeId))\n\n/**\n * A completion token could not be decoded into its durable address.\n *\n * @category errors\n * @since 0.1.0\n */\nexport class TokenInvalid extends Schema.TaggedError<TokenInvalid>()(\"@smthrs/flow/DurableDeferred/TokenInvalid\", {\n code: Schema.Literals([\"malformed_token\", \"deferred_mismatch\"]).pipe(\n Schema.withConstructorDefault(Effect.succeed(\"malformed_token\"))\n ),\n message: Schema.String\n}) {}\n\n/**\n * Schema for a decoded durable deferred token containing the flow\n * name, execution ID, and deferred name.\n *\n * @category token\n * @since 0.1.0\n */\nexport class TokenParsed extends Schema.Class<TokenParsed>(\n \"@smthrs/flow/DurableDeferred/TokenParsed\"\n)({\n flowName: Schema.String,\n executionId: Schema.String,\n deferredName: Schema.String\n}) {\n /**\n * Encodes the parsed flow, execution, and deferred names back into a token.\n *\n * @since 0.1.0\n */\n get asToken(): Token {\n return Encoding.encodeBase64Url(\n JSON.stringify([this.flowName, this.executionId, this.deferredName])\n ) as Token\n }\n\n /**\n * Schema for decoding and encoding durable deferred tokens as strings.\n *\n * @since 0.1.0\n */\n static readonly FromString = Schema.String.pipe(\n Schema.decodeTo(\n Schema.fromJsonString(\n Schema.Tuple([Schema.String, Schema.String, Schema.String])\n ),\n {\n decode: SchemaGetter.decodeBase64UrlString(),\n encode: SchemaGetter.encodeBase64Url()\n }\n ),\n Schema.decodeTo(TokenParsed, {\n decode: SchemaGetter.transform(\n ([flowName, executionId, deferredName]) =>\n new TokenParsed({\n flowName,\n executionId,\n deferredName\n })\n ),\n encode: SchemaGetter.transform(\n (parsed) =>\n [\n parsed.flowName,\n parsed.executionId,\n parsed.deferredName\n ] as const\n )\n })\n )\n\n /**\n * Decodes a durable deferred token string into its parsed components.\n *\n * @since 0.1.0\n */\n static readonly fromString = Schema.decodeSync(TokenParsed.FromString)\n\n /**\n * Encodes parsed durable deferred token components into a token string.\n *\n * @since 0.1.0\n */\n static readonly encode = Schema.encodeSync(TokenParsed.FromString)\n\n /**\n * Parses an untrusted token into its durable address with a typed,\n * bounded diagnostic on failure.\n *\n * @category token\n * @since 1.0.0\n */\n static readonly parse = (token: string): Effect.Effect<TokenParsed, TokenInvalid> =>\n Effect.mapError(\n Schema.decodeEffect(TokenParsed.FromString)(token),\n (issue) =>\n new TokenInvalid({\n message: `The supplied token \"${tokenExcerpt(token)}\" is not a durable deferred token: ${issue.message}`\n })\n )\n}\n\nconst maxTokenExcerptChars = 64\n\n/** Renders a bounded excerpt of untrusted token content for a diagnostic. */\nconst tokenExcerpt = (token: string): string =>\n token.length <= maxTokenExcerptChars\n ? token\n : `${token.slice(0, maxTokenExcerptChars)} [${token.length - maxTokenExcerptChars} characters dropped]`\n\n/**\n * Creates a token for a durable deferred using the current flow instance's\n * flow name and execution ID.\n *\n * @category token\n * @since 0.1.0\n */\nexport const token: <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>\n) => Effect.Effect<Token, never, FlowInstance> =\n // Untraced because token allocation is on the durable-deferred hot path.\n Effect.fnUntraced(\n function*<Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>\n ) {\n const instance = yield* FlowInstance\n return tokenFromExecutionId(self, instance)\n }\n )\n\n/**\n * Creates a durable deferred token from an explicit flow, execution ID,\n * and deferred name.\n *\n * @category token\n * @since 0.1.0\n */\nexport const tokenFromExecutionId: {\n (options: {\n readonly flow: Flow.Any\n readonly executionId: string\n }): <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>\n ) => Token\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>,\n options: { readonly flow: Flow.Any; readonly executionId: string }\n ): Token\n} = dual(\n 2,\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>,\n options: {\n readonly flow: Flow.Any\n readonly executionId: string\n }\n ): Token =>\n new TokenParsed({\n flowName: options.flow._tag,\n executionId: options.executionId,\n deferredName: self.name\n }).asToken\n)\n\n/**\n * Creates a durable deferred token by deriving the flow execution ID from\n * the supplied flow payload.\n *\n * The payload identifies a previously started execution only when the flow\n * declares `idempotencyKey` or the host installs the opt-in `derived`\n * execution-id source. Otherwise the default `fresh` source mints a new\n * execution ID on every call, so the token addresses no earlier run. To\n * complete an existing execution without stable identity, keep its execution\n * ID and use {@link tokenFromExecutionId}.\n *\n * @category token\n * @since 0.1.0\n */\nexport const tokenFromPayload: {\n <W extends Flow.Any>(options: {\n readonly flow: W\n readonly payload: Flow.PayloadSchema<W>[\"~type.make.in\"]\n }): <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>\n ) => Effect.Effect<Token, never, Crypto.Crypto | Flow.PayloadSchema<W>[\"EncodingServices\"]>\n <\n Success extends Schema.Constraint,\n Error extends Schema.Constraint,\n W extends Flow.Any\n >(\n self: DurableDeferred<Success, Error>,\n options: {\n readonly flow: W\n readonly payload: Flow.PayloadSchema<W>[\"~type.make.in\"]\n }\n ): Effect.Effect<Token, never, Crypto.Crypto | Flow.PayloadSchema<W>[\"EncodingServices\"]>\n} = dual(\n 2,\n <\n Success extends Schema.Constraint,\n Error extends Schema.Constraint,\n W extends Flow.Any\n >(\n self: DurableDeferred<Success, Error>,\n options: {\n readonly flow: W\n readonly payload: Flow.PayloadSchema<W>[\"~type.make.in\"]\n }\n ): Effect.Effect<Token, never, Crypto.Crypto | Flow.PayloadSchema<W>[\"EncodingServices\"]> =>\n Effect.map(options.flow.executionId(options.payload), (executionId) =>\n tokenFromExecutionId(self, {\n flow: options.flow,\n executionId\n }))\n)\n\n/**\n * Completes the durable deferred identified by a token with the supplied exit,\n * encoding the result through the deferred schemas.\n *\n * The token is not a credential (see {@link Token}): authorize the caller\n * before completing a wait on its behalf.\n *\n * @category combinators\n * @since 0.1.0\n */\nexport const done: {\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(options: {\n readonly token: Token\n readonly exit: Exit.Exit<Success[\"Type\"], Error[\"Type\"]>\n }): (\n self: DurableDeferred<Success, Error>\n ) => Effect.Effect<\n void,\n TokenInvalid,\n FlowRuntime | Success[\"EncodingServices\"] | Error[\"EncodingServices\"]\n >\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>,\n options: {\n readonly token: Token\n readonly exit: Exit.Exit<Success[\"Type\"], Error[\"Type\"]>\n }\n ): Effect.Effect<\n void,\n TokenInvalid,\n FlowRuntime | Success[\"EncodingServices\"] | Error[\"EncodingServices\"]\n >\n} = dual(\n 2,\n // Untraced because awaiting a deferred re-enters the scheduler recursively.\n Effect.fnUntraced(function*<\n Success extends Schema.Constraint,\n Error extends Schema.Constraint\n >(\n self: DurableDeferred<Success, Error>,\n options: {\n readonly token: Token\n readonly exit: Exit.Exit<Success[\"Type\"], Error[\"Type\"]>\n }\n ) {\n const token = yield* TokenParsed.parse(options.token)\n if (token.deferredName !== self.name) {\n return yield* Effect.fail(\n new TokenInvalid({\n code: \"deferred_mismatch\",\n message: `The token addresses deferred \"${tokenExcerpt(token.deferredName)}\", but it was submitted through ` +\n `deferred \"${self.name}\".`\n })\n )\n }\n const engine = yield* FlowRuntime\n yield* engine.deferredDone(self, {\n flowName: token.flowName,\n executionId: token.executionId,\n deferredName: token.deferredName,\n exit: options.exit\n })\n })\n)\n\n/**\n * Completes the durable deferred identified by a token with a successful\n * value.\n *\n * @category combinators\n * @since 0.1.0\n */\nexport const succeed: {\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(options: {\n readonly token: Token\n readonly value: Success[\"Type\"]\n }): (\n self: DurableDeferred<Success, Error>\n ) => Effect.Effect<void, TokenInvalid, FlowRuntime | Success[\"EncodingServices\"]>\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>,\n options: {\n readonly token: Token\n readonly value: Success[\"Type\"]\n }\n ): Effect.Effect<void, TokenInvalid, FlowRuntime | Success[\"EncodingServices\"]>\n} = dual(\n 2,\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>,\n options: {\n readonly token: Token\n readonly value: Success[\"Type\"]\n }\n ): Effect.Effect<void, TokenInvalid, FlowRuntime | Success[\"EncodingServices\"]> =>\n done(self, {\n token: options.token,\n exit: Exit.succeed(options.value)\n })\n)\n\n/**\n * Completes the durable deferred identified by a token with a typed failure.\n *\n * @category combinators\n * @since 0.1.0\n */\nexport const fail: {\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(options: {\n readonly token: Token\n readonly error: Error[\"Type\"]\n }): (\n self: DurableDeferred<Success, Error>\n ) => Effect.Effect<void, TokenInvalid, FlowRuntime | Error[\"EncodingServices\"]>\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>,\n options: {\n readonly token: Token\n readonly error: Error[\"Type\"]\n }\n ): Effect.Effect<void, TokenInvalid, FlowRuntime | Error[\"EncodingServices\"]>\n} = dual(\n 2,\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>,\n options: {\n readonly token: Token\n readonly error: Error[\"Type\"]\n }\n ): Effect.Effect<void, TokenInvalid, FlowRuntime | Error[\"EncodingServices\"]> =>\n done(self, {\n token: options.token,\n exit: Exit.fail(options.error)\n })\n)\n\n/**\n * Completes the durable deferred identified by a token with a failure cause.\n *\n * @category combinators\n * @since 0.1.0\n */\nexport const failCause: {\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(options: {\n readonly token: Token\n readonly cause: Cause.Cause<Error[\"Type\"]>\n }): (\n self: DurableDeferred<Success, Error>\n ) => Effect.Effect<void, TokenInvalid, FlowRuntime | Error[\"EncodingServices\"]>\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>,\n options: {\n readonly token: Token\n readonly cause: Cause.Cause<Error[\"Type\"]>\n }\n ): Effect.Effect<void, TokenInvalid, FlowRuntime | Error[\"EncodingServices\"]>\n} = dual(\n 2,\n <Success extends Schema.Constraint, Error extends Schema.Constraint>(\n self: DurableDeferred<Success, Error>,\n options: {\n readonly token: Token\n readonly cause: Cause.Cause<Error[\"Type\"]>\n }\n ): Effect.Effect<void, TokenInvalid, FlowRuntime | Error[\"EncodingServices\"]> =>\n done(self, {\n token: options.token,\n exit: Exit.failCause(options.cause)\n })\n)\n"]}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type * as Crypto from "effect/Crypto";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Schedule from "effect/Schedule";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import * as PersistedQueue from "effect/unstable/persistence/PersistedQueue";
|
|
7
|
+
import * as DurableDeferred from "./DurableDeferred.ts";
|
|
8
|
+
import { type FlowInstance, type FlowRuntime } from "./FlowRuntime/index.ts";
|
|
9
|
+
/**
|
|
10
|
+
* Type-level identifier used to recognize `DurableQueue` values.
|
|
11
|
+
*
|
|
12
|
+
* @category type IDs
|
|
13
|
+
* @since 0.1.0
|
|
14
|
+
*/
|
|
15
|
+
export type TypeId = "@smthrs/flow/DurableQueue";
|
|
16
|
+
/**
|
|
17
|
+
* Runtime identifier attached to `DurableQueue` values.
|
|
18
|
+
*
|
|
19
|
+
* @category type IDs
|
|
20
|
+
* @since 0.1.0
|
|
21
|
+
*/
|
|
22
|
+
export declare const TypeId: TypeId;
|
|
23
|
+
/**
|
|
24
|
+
* Durable flow queue definition containing a payload schema, idempotency
|
|
25
|
+
* key, and deferred used to await worker results.
|
|
26
|
+
*
|
|
27
|
+
* @category models
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
*/
|
|
30
|
+
export interface DurableQueue<Payload extends Schema.Top, Success extends Schema.Top = Schema.Void, Error extends Schema.Top = Schema.Never> {
|
|
31
|
+
readonly [TypeId]: TypeId;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly payloadSchema: Payload;
|
|
34
|
+
readonly idempotencyKey: (payload: Payload["Type"]) => string;
|
|
35
|
+
readonly deferred: DurableDeferred.DurableDeferred<Success, Error>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a `DurableQueue` that waits for persisted items to finish processing
|
|
39
|
+
* using a `DurableDeferred`.
|
|
40
|
+
*
|
|
41
|
+
* **Example** (Defining a durable queue with workers)
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { Action, DurableQueue, Flow, Interpreter } from "@smthrs/flow"
|
|
45
|
+
* import { Effect, Layer, Schema } from "effect"
|
|
46
|
+
*
|
|
47
|
+
* // Define a DurableQueue that can be used to derive workers and offer items for
|
|
48
|
+
* // processing.
|
|
49
|
+
* const ApiQueue = DurableQueue.make({
|
|
50
|
+
* name: "ApiQueue",
|
|
51
|
+
* payload: {
|
|
52
|
+
* id: Schema.String
|
|
53
|
+
* },
|
|
54
|
+
* success: Schema.Void,
|
|
55
|
+
* error: Schema.Never,
|
|
56
|
+
* idempotencyKey(payload) {
|
|
57
|
+
* return payload.id
|
|
58
|
+
* }
|
|
59
|
+
* })
|
|
60
|
+
*
|
|
61
|
+
* // Offering an item is work, so it is a declared Action: the declaration is
|
|
62
|
+
* // pure data, and the implementation attaches separately.
|
|
63
|
+
* const Offer = Action.make("MyFlow/offer", {
|
|
64
|
+
* payload: {
|
|
65
|
+
* id: Schema.String
|
|
66
|
+
* }
|
|
67
|
+
* })
|
|
68
|
+
*
|
|
69
|
+
* const OfferLive = Offer.toLayer(
|
|
70
|
+
* Effect.fnUntraced(function*({ id }) {
|
|
71
|
+
* // Add an item to the DurableQueue defined above.
|
|
72
|
+
* //
|
|
73
|
+
* // When the worker has finished processing the item, the flow will
|
|
74
|
+
* // resume.
|
|
75
|
+
* //
|
|
76
|
+
* yield* DurableQueue.process(ApiQueue, { id })
|
|
77
|
+
*
|
|
78
|
+
* yield* Effect.log("Flow succeeded!")
|
|
79
|
+
* })
|
|
80
|
+
* )
|
|
81
|
+
*
|
|
82
|
+
* // The flow is the composite, and its body names the step it is made of.
|
|
83
|
+
* const MyFlow = Flow.make("MyFlow", {
|
|
84
|
+
* payload: {
|
|
85
|
+
* id: Schema.String
|
|
86
|
+
* },
|
|
87
|
+
* idempotencyKey: ({ id }) => id,
|
|
88
|
+
* body: (payload) => Offer.call(payload)
|
|
89
|
+
* })
|
|
90
|
+
*
|
|
91
|
+
* const MyFlowLayer = Layer.mergeAll(OfferLive, Interpreter.layer(MyFlow)).pipe(
|
|
92
|
+
* Layer.provideMerge(Action.layerImplementations)
|
|
93
|
+
* )
|
|
94
|
+
*
|
|
95
|
+
* // Define a worker layer that can process items from the DurableQueue.
|
|
96
|
+
* const ApiWorker = DurableQueue.worker(
|
|
97
|
+
* ApiQueue,
|
|
98
|
+
* Effect.fnUntraced(function*({ id }) {
|
|
99
|
+
* yield* Effect.log(`Worker processing API call with id: ${id}`)
|
|
100
|
+
* }),
|
|
101
|
+
* { concurrency: 5 } // Process up to 5 items concurrently
|
|
102
|
+
* )
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @category constructors
|
|
106
|
+
* @since 0.1.0
|
|
107
|
+
*/
|
|
108
|
+
export declare const make: <Payload extends Schema.Top | Schema.Struct.Fields, Success extends Schema.Top = Schema.Void, Error extends Schema.Top = Schema.Never>(options: {
|
|
109
|
+
readonly name: string;
|
|
110
|
+
readonly payload: Payload;
|
|
111
|
+
readonly idempotencyKey: (payload: Payload extends Schema.Struct.Fields ? Schema.Struct.Type<Payload> : Payload["Type"]) => string;
|
|
112
|
+
readonly success?: Success | undefined;
|
|
113
|
+
readonly error?: Error | undefined;
|
|
114
|
+
}) => DurableQueue<Payload extends Schema.Struct.Fields ? Schema.Struct<Payload> : Payload, Success, Error>;
|
|
115
|
+
/**
|
|
116
|
+
* Adds an item to the queue and waits for a worker to process it.
|
|
117
|
+
*
|
|
118
|
+
* `retrySchedule` controls retries when the persisted offer fails. The default
|
|
119
|
+
* is unbounded, with exponential delays capped at one minute, so a transient
|
|
120
|
+
* store outage does not lose the item. A caller-supplied schedule may exhaust;
|
|
121
|
+
* its final offer failure becomes a defect to keep the public error channel
|
|
122
|
+
* reserved for the worker's declared error.
|
|
123
|
+
*
|
|
124
|
+
* Payload construction also becomes a defect when `fields` does not satisfy
|
|
125
|
+
* the queue's payload schema. The public error channel is the worker result,
|
|
126
|
+
* not malformed caller input.
|
|
127
|
+
*
|
|
128
|
+
* @category processing
|
|
129
|
+
* @since 0.1.0
|
|
130
|
+
*/
|
|
131
|
+
export declare const process: <Payload extends Schema.Top, Success extends Schema.Top, Error extends Schema.Top>(self: DurableQueue<Payload, Success, Error>, payload: Payload["~type.make.in"], options?: {
|
|
132
|
+
readonly retrySchedule?: Schedule.Schedule<any, PersistedQueue.PersistedQueueError> | undefined;
|
|
133
|
+
}) => Effect.Effect<Success["Type"], Error["Type"], FlowRuntime | FlowInstance | Crypto.Crypto | PersistedQueue.PersistedQueueFactory | Payload["EncodingServices"] | Payload["DecodingServices"] | Success["DecodingServices"] | Error["DecodingServices"]>;
|
|
134
|
+
/**
|
|
135
|
+
* Create a worker effect that processes items from the durable queue.
|
|
136
|
+
*
|
|
137
|
+
* `concurrency` defaults to one and must be a positive safe integer. It is
|
|
138
|
+
* checked before the persisted queue is opened. `maxAttempts` defaults to ten
|
|
139
|
+
* and is passed to the persisted queue. Completion-write failures can rerun the
|
|
140
|
+
* handler; side effects must be idempotent. Exhaustion leaves the flow waiting.
|
|
141
|
+
*
|
|
142
|
+
* @throws A `RangeError` when `concurrency` is not a positive safe integer.
|
|
143
|
+
* @category worker
|
|
144
|
+
* @since 0.1.0
|
|
145
|
+
*/
|
|
146
|
+
export declare const makeWorker: <Payload extends Schema.Top, Success extends Schema.Top, Error extends Schema.Top, R>(self: DurableQueue<Payload, Success, Error>, f: (payload: Payload["Type"]) => Effect.Effect<Success["Type"], Error["Type"], R>, options?: {
|
|
147
|
+
readonly concurrency?: number | undefined;
|
|
148
|
+
readonly maxAttempts?: number | undefined;
|
|
149
|
+
} | undefined) => Effect.Effect<never, never, FlowRuntime | PersistedQueue.PersistedQueueFactory | R | Payload["EncodingServices"] | Payload["DecodingServices"] | Success["EncodingServices"] | Error["EncodingServices"]>;
|
|
150
|
+
/**
|
|
151
|
+
* Create a layer that runs workers for the durable queue.
|
|
152
|
+
*
|
|
153
|
+
* @category worker
|
|
154
|
+
* @since 0.1.0
|
|
155
|
+
*/
|
|
156
|
+
export declare const worker: <Payload extends Schema.Top, Success extends Schema.Top, Error extends Schema.Top, R>(self: DurableQueue<Payload, Success, Error>, f: (payload: Payload["Type"]) => Effect.Effect<Success["Type"], Error["Type"], R>, options?: {
|
|
157
|
+
readonly concurrency?: number | undefined;
|
|
158
|
+
readonly maxAttempts?: number | undefined;
|
|
159
|
+
} | undefined) => Layer.Layer<never, never, FlowRuntime | PersistedQueue.PersistedQueueFactory | R | Payload["EncodingServices"] | Payload["DecodingServices"] | Success["EncodingServices"] | Error["EncodingServices"]>;
|
|
160
|
+
//# sourceMapp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M,CAAC,GAAG,EAC1B,KAAK,SAAS,MAAM,CAAC,GAAG,EACxB,CAAC,EAED,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,EAC3C,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EACjF,OAAO,CAAC,EAAE;IACR,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1C,GAAG,SAAS,KACV,KAAK,CAAC,KAAK,CACd,KAAK,EACL,KAAK,EACH,WAAW,GACX,cAAc,CAAC,qBAAqB,GACpC,CAAC,GACD,OAAO,CAAC,kBAAkB,CAAC,GAC3B,OAAO,CAAC,kBAAkB,CAAC,GAC3B,OAAO,CAAC,kBAAkB,CAAC,GAC3B,KAAK,CAAC,kBAAkB,CAAC,CACiE,CAAA"}
|
|
@@ -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 Schedule from "effect/Schedule";
|
|
21
|
+
import * as Schema from "effect/Schema";
|
|
22
|
+
import * as Tracer from "effect/Tracer";
|
|
23
|
+
import * as PersistedQueue from "effect/unstable/persistence/PersistedQueue";
|
|
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 [reasons, interrupts] = 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,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,cAAc,MAAM,4CAA4C,CAAA;AAC5E,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAIlB,OASD,EAIC,EAAE,CAAC,CAAC;IACJ,CAAC,MAAM,CAAC,EAAE,MAAM;IAChB,IAAI,EAAE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\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 Schedule from \"effect/Schedule\"\nimport * as Schema from \"effect/Schema\"\nimport * as Tracer from \"effect/Tracer\"\nimport * as PersistedQueue from \"effect/unstable/persistence/PersistedQueue\"\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 [reasons, interrupts] = 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"]}
|