@bluelibs/runner 5.1.0 → 5.2.1
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/README.md +25 -15
- package/dist/browser/index.cjs +851 -478
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.mjs +849 -478
- package/dist/browser/index.mjs.map +1 -1
- package/dist/edge/index.cjs +851 -478
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.mjs +849 -478
- package/dist/edge/index.mjs.map +1 -1
- package/dist/node/node.cjs +1305 -583
- package/dist/node/node.cjs.map +1 -1
- package/dist/node/node.mjs +1299 -583
- package/dist/node/node.mjs.map +1 -1
- package/dist/types/define.d.ts +9 -0
- package/dist/types/definers/builders/asyncContext/fluent-builder.d.ts +6 -0
- package/dist/types/definers/builders/asyncContext/fluent-builder.interface.d.ts +9 -0
- package/dist/types/definers/builders/asyncContext/index.d.ts +10 -0
- package/dist/types/definers/builders/asyncContext/types.d.ts +13 -0
- package/dist/types/definers/builders/asyncContext/utils.d.ts +5 -0
- package/dist/types/definers/builders/asyncContext.d.ts +1 -0
- package/dist/types/definers/builders/core.d.ts +30 -0
- package/dist/types/definers/builders/error/fluent-builder.d.ts +7 -0
- package/dist/types/definers/builders/error/fluent-builder.interface.d.ts +10 -0
- package/dist/types/definers/builders/error/index.d.ts +11 -0
- package/dist/types/definers/builders/error/types.d.ts +14 -0
- package/dist/types/definers/builders/error/utils.d.ts +6 -0
- package/dist/types/definers/builders/error.d.ts +1 -0
- package/dist/types/definers/builders/event/fluent-builder.d.ts +7 -0
- package/dist/types/definers/builders/event/fluent-builder.interface.d.ts +18 -0
- package/dist/types/definers/builders/event/index.d.ts +10 -0
- package/dist/types/definers/builders/event/types.d.ts +8 -0
- package/dist/types/definers/builders/event/utils.d.ts +9 -0
- package/dist/types/definers/builders/event.d.ts +1 -0
- package/dist/types/definers/builders/hook/fluent-builder.d.ts +8 -0
- package/dist/types/definers/builders/hook/fluent-builder.interface.d.ts +27 -0
- package/dist/types/definers/builders/hook/index.d.ts +12 -0
- package/dist/types/definers/builders/hook/types.d.ts +14 -0
- package/dist/types/definers/builders/hook/utils.d.ts +14 -0
- package/dist/types/definers/builders/hook.d.ts +1 -0
- package/dist/types/definers/builders/middleware/index.d.ts +19 -0
- package/dist/types/definers/builders/middleware/resource.d.ts +7 -0
- package/dist/types/definers/builders/middleware/resource.interface.d.ts +18 -0
- package/dist/types/definers/builders/middleware/task.d.ts +7 -0
- package/dist/types/definers/builders/middleware/task.interface.d.ts +18 -0
- package/dist/types/definers/builders/middleware/types.d.ts +13 -0
- package/dist/types/definers/builders/middleware/utils.d.ts +18 -0
- package/dist/types/definers/builders/middleware.d.ts +1 -0
- package/dist/types/definers/builders/override/hook.d.ts +16 -0
- package/dist/types/definers/builders/override/index.d.ts +11 -0
- package/dist/types/definers/builders/override/resource-middleware.d.ts +3 -0
- package/dist/types/definers/builders/override/resource.d.ts +3 -0
- package/dist/types/definers/builders/override/task-middleware.d.ts +3 -0
- package/dist/types/definers/builders/override/task.d.ts +3 -0
- package/dist/types/definers/builders/resource/fluent-builder.d.ts +8 -0
- package/dist/types/definers/builders/resource/fluent-builder.interface.d.ts +42 -0
- package/dist/types/definers/builders/resource/index.d.ts +13 -0
- package/dist/types/definers/builders/resource/types.d.ts +37 -0
- package/dist/types/definers/builders/resource/utils.d.ts +26 -0
- package/dist/types/definers/builders/resource.d.ts +1 -0
- package/dist/types/definers/builders/tag/fluent-builder.d.ts +6 -0
- package/dist/types/definers/builders/tag/fluent-builder.interface.d.ts +8 -0
- package/dist/types/definers/builders/tag/index.d.ts +10 -0
- package/dist/types/definers/builders/tag/types.d.ts +12 -0
- package/dist/types/definers/builders/tag/utils.d.ts +5 -0
- package/dist/types/definers/builders/tag.d.ts +1 -0
- package/dist/types/definers/builders/task/fluent-builder.d.ts +8 -0
- package/dist/types/definers/builders/task/fluent-builder.interface.d.ts +33 -0
- package/dist/types/definers/builders/task/index.d.ts +21 -0
- package/dist/types/definers/builders/task/phantom-builder.d.ts +8 -0
- package/dist/types/definers/builders/task/phantom-builder.interface.d.ts +31 -0
- package/dist/types/definers/builders/task/types.d.ts +34 -0
- package/dist/types/definers/builders/task/utils.d.ts +14 -0
- package/dist/types/definers/builders/task.d.ts +1 -0
- package/dist/types/definers/builders/task.phantom.d.ts +1 -0
- package/dist/types/definers/builders/utils.d.ts +4 -0
- package/dist/types/definers/defineAsyncContext.d.ts +15 -0
- package/dist/types/definers/defineError.d.ts +27 -0
- package/dist/types/definers/defineEvent.d.ts +2 -0
- package/dist/types/definers/defineHook.d.ts +6 -0
- package/dist/types/definers/defineOverride.d.ts +12 -0
- package/dist/types/definers/defineResource.d.ts +2 -0
- package/dist/types/definers/defineResourceMiddleware.d.ts +2 -0
- package/dist/types/definers/defineTag.d.ts +12 -0
- package/dist/types/definers/defineTask.d.ts +18 -0
- package/dist/types/definers/defineTaskMiddleware.d.ts +2 -0
- package/dist/types/definers/middlewareConfig.d.ts +1 -0
- package/dist/types/definers/resourceFork.d.ts +13 -0
- package/dist/types/definers/tools.d.ts +53 -0
- package/dist/types/defs.d.ts +33 -0
- package/dist/types/errors.d.ts +75 -0
- package/dist/types/globals/debug.d.ts +10 -0
- package/dist/types/globals/globalEvents.d.ts +8 -0
- package/dist/types/globals/globalMiddleware.d.ts +97 -0
- package/dist/types/globals/globalResources.d.ts +64 -0
- package/dist/types/globals/globalTags.d.ts +12 -0
- package/dist/types/globals/middleware/cache.middleware.d.ts +36 -0
- package/dist/types/globals/middleware/circuitBreaker.middleware.d.ts +56 -0
- package/dist/types/globals/middleware/concurrency.middleware.d.ts +47 -0
- package/dist/types/globals/middleware/fallback.middleware.d.ts +23 -0
- package/dist/types/globals/middleware/rateLimit.middleware.d.ts +47 -0
- package/dist/types/globals/middleware/requireContext.middleware.d.ts +5 -0
- package/dist/types/globals/middleware/retry.middleware.d.ts +31 -0
- package/dist/types/globals/middleware/temporal.middleware.d.ts +48 -0
- package/dist/types/globals/middleware/timeout.middleware.d.ts +24 -0
- package/dist/types/globals/middleware/tunnel.middleware.d.ts +3 -0
- package/dist/types/globals/resources/debug/debug.resource.d.ts +7 -0
- package/dist/types/globals/resources/debug/debug.tag.d.ts +2 -0
- package/dist/types/globals/resources/debug/debugConfig.resource.d.ts +22 -0
- package/dist/types/globals/resources/debug/executionTracker.middleware.d.ts +50 -0
- package/dist/types/globals/resources/debug/globalEvent.hook.d.ts +27 -0
- package/dist/types/globals/resources/debug/hook.hook.d.ts +30 -0
- package/dist/types/globals/resources/debug/index.d.ts +6 -0
- package/dist/types/globals/resources/debug/middleware.hook.d.ts +30 -0
- package/dist/types/globals/resources/debug/types.d.ts +25 -0
- package/dist/types/globals/resources/debug/utils.d.ts +2 -0
- package/dist/types/globals/resources/httpClientFactory.resource.d.ts +28 -0
- package/dist/types/globals/resources/queue.resource.d.ts +10 -0
- package/dist/types/globals/resources/tunnel/error-utils.d.ts +1 -0
- package/dist/types/globals/resources/tunnel/plan.d.ts +19 -0
- package/dist/types/globals/resources/tunnel/protocol.d.ts +48 -0
- package/dist/types/globals/resources/tunnel/tunnel.policy.tag.d.ts +26 -0
- package/dist/types/globals/resources/tunnel/tunnel.tag.d.ts +2 -0
- package/dist/types/globals/resources/tunnel/types.d.ts +48 -0
- package/dist/types/globals/tunnels/index.d.ts +23 -0
- package/dist/types/globals/types.d.ts +15 -0
- package/dist/types/http-client.d.ts +26 -0
- package/dist/types/http-fetch-tunnel.resource.d.ts +11 -0
- package/dist/types/index.d.ts +44 -0
- package/dist/types/models/DependencyProcessor.d.ts +46 -0
- package/dist/types/models/EventManager.d.ts +115 -0
- package/dist/types/models/ExecutionJournal.d.ts +35 -0
- package/dist/types/models/LogPrinter.d.ts +56 -0
- package/dist/types/models/Logger.d.ts +85 -0
- package/dist/types/models/MiddlewareManager.d.ts +73 -0
- package/dist/types/models/OverrideManager.d.ts +13 -0
- package/dist/types/models/Queue.d.ts +40 -0
- package/dist/types/models/ResourceInitializer.d.ts +20 -0
- package/dist/types/models/RunResult.d.ts +41 -0
- package/dist/types/models/Semaphore.d.ts +80 -0
- package/dist/types/models/Store.d.ts +76 -0
- package/dist/types/models/StoreRegistry.d.ts +49 -0
- package/dist/types/models/StoreValidator.d.ts +8 -0
- package/dist/types/models/TaskRunner.d.ts +28 -0
- package/dist/types/models/UnhandledError.d.ts +11 -0
- package/dist/types/models/event/CycleContext.d.ts +9 -0
- package/dist/types/models/event/EmissionExecutor.d.ts +11 -0
- package/dist/types/models/event/InterceptorPipeline.d.ts +5 -0
- package/dist/types/models/event/ListenerRegistry.d.ts +31 -0
- package/dist/types/models/event/types.d.ts +50 -0
- package/dist/types/models/index.d.ts +13 -0
- package/dist/types/models/middleware/InterceptorRegistry.d.ts +56 -0
- package/dist/types/models/middleware/MiddlewareResolver.d.ts +31 -0
- package/dist/types/models/middleware/ResourceMiddlewareComposer.d.ts +34 -0
- package/dist/types/models/middleware/TaskMiddlewareComposer.d.ts +44 -0
- package/dist/types/models/middleware/ValidationHelper.d.ts +20 -0
- package/dist/types/models/middleware/index.d.ts +6 -0
- package/dist/types/models/middleware/types.d.ts +10 -0
- package/dist/types/models/utils/findCircularDependencies.d.ts +16 -0
- package/dist/types/models/utils/safeStringify.d.ts +3 -0
- package/dist/types/node/durable/bus/MemoryEventBus.d.ts +7 -0
- package/dist/types/node/durable/bus/NoopEventBus.d.ts +6 -0
- package/dist/types/node/durable/bus/RedisEventBus.d.ts +30 -0
- package/dist/types/node/durable/core/CronParser.d.ts +15 -0
- package/dist/types/node/durable/core/DurableContext.d.ts +64 -0
- package/dist/types/node/durable/core/DurableOperator.d.ts +47 -0
- package/dist/types/node/durable/core/DurableResource.d.ts +80 -0
- package/dist/types/node/durable/core/DurableService.d.ts +73 -0
- package/dist/types/node/durable/core/DurableWorker.d.ts +19 -0
- package/dist/types/node/durable/core/StepBuilder.d.ts +23 -0
- package/dist/types/node/durable/core/audit.d.ts +152 -0
- package/dist/types/node/durable/core/createRunnerDurableRuntime.d.ts +18 -0
- package/dist/types/node/durable/core/durable-context/DurableContext.audit.d.ts +14 -0
- package/dist/types/node/durable/core/durable-context/DurableContext.determinism.d.ts +13 -0
- package/dist/types/node/durable/core/durable-context/DurableContext.emit.d.ts +16 -0
- package/dist/types/node/durable/core/durable-context/DurableContext.sleep.d.ts +16 -0
- package/dist/types/node/durable/core/durable-context/DurableContext.steps.d.ts +25 -0
- package/dist/types/node/durable/core/durable-context/DurableContext.switch.d.ts +22 -0
- package/dist/types/node/durable/core/durable-context/DurableContext.waitForSignal.d.ts +23 -0
- package/dist/types/node/durable/core/flowShape.d.ts +50 -0
- package/dist/types/node/durable/core/ids.d.ts +11 -0
- package/dist/types/node/durable/core/index.d.ts +11 -0
- package/dist/types/node/durable/core/interfaces/bus.d.ts +13 -0
- package/dist/types/node/durable/core/interfaces/context.d.ts +105 -0
- package/dist/types/node/durable/core/interfaces/queue.d.ts +17 -0
- package/dist/types/node/durable/core/interfaces/service.d.ts +146 -0
- package/dist/types/node/durable/core/interfaces/store.d.ts +66 -0
- package/dist/types/node/durable/core/managers/AuditLogger.d.ts +29 -0
- package/dist/types/node/durable/core/managers/ExecutionManager.d.ts +48 -0
- package/dist/types/node/durable/core/managers/PollingManager.d.ts +48 -0
- package/dist/types/node/durable/core/managers/ScheduleManager.d.ts +33 -0
- package/dist/types/node/durable/core/managers/SignalHandler.d.ts +25 -0
- package/dist/types/node/durable/core/managers/TaskRegistry.d.ts +16 -0
- package/dist/types/node/durable/core/managers/WaitManager.d.ts +26 -0
- package/dist/types/node/durable/core/managers/index.d.ts +7 -0
- package/dist/types/node/durable/core/resource.d.ts +14 -0
- package/dist/types/node/durable/core/types.d.ts +84 -0
- package/dist/types/node/durable/core/utils.d.ts +28 -0
- package/dist/types/node/durable/dashboard/server.d.ts +20 -0
- package/dist/types/node/durable/emitters/runnerAuditEmitter.d.ts +6 -0
- package/dist/types/node/durable/events.d.ts +76 -0
- package/dist/types/node/durable/index.d.ts +34 -0
- package/dist/types/node/durable/optionalDeps/amqplib.d.ts +1 -0
- package/dist/types/node/durable/optionalDeps/ioredis.d.ts +1 -0
- package/dist/types/node/durable/queue/MemoryQueue.d.ts +12 -0
- package/dist/types/node/durable/queue/RabbitMQQueue.d.ts +30 -0
- package/dist/types/node/durable/resources/isolation.d.ts +15 -0
- package/dist/types/node/durable/resources/memoryDurableResource.d.ts +21 -0
- package/dist/types/node/durable/resources/redisDurableResource.d.ts +35 -0
- package/dist/types/node/durable/store/MemoryStore.d.ts +56 -0
- package/dist/types/node/durable/store/RedisStore.d.ts +89 -0
- package/dist/types/node/durable/test-utils.d.ts +29 -0
- package/dist/types/node/exposure/allowList.d.ts +3 -0
- package/dist/types/node/exposure/authenticator.d.ts +16 -0
- package/dist/types/node/exposure/cors.d.ts +4 -0
- package/dist/types/node/exposure/createNodeExposure.d.ts +2 -0
- package/dist/types/node/exposure/exposureServer.d.ts +18 -0
- package/dist/types/node/exposure/handlers/contextWrapper.d.ts +18 -0
- package/dist/types/node/exposure/handlers/errorHandlers.d.ts +23 -0
- package/dist/types/node/exposure/handlers/eventHandler.d.ts +20 -0
- package/dist/types/node/exposure/handlers/taskHandler.d.ts +24 -0
- package/dist/types/node/exposure/httpResponse.d.ts +10 -0
- package/dist/types/node/exposure/index.d.ts +3 -0
- package/dist/types/node/exposure/logging.d.ts +4 -0
- package/dist/types/node/exposure/multipart.d.ts +36 -0
- package/dist/types/node/exposure/requestBody.d.ts +11 -0
- package/dist/types/node/exposure/requestContext.d.ts +17 -0
- package/dist/types/node/exposure/requestHandlers.d.ts +29 -0
- package/dist/types/node/exposure/resource.d.ts +12 -0
- package/dist/types/node/exposure/resourceTypes.d.ts +73 -0
- package/dist/types/node/exposure/router.d.ts +17 -0
- package/dist/types/node/exposure/serverLifecycle.d.ts +13 -0
- package/dist/types/node/exposure/types.d.ts +45 -0
- package/dist/types/node/exposure/utils.d.ts +17 -0
- package/dist/types/node/files/createNodeFile.d.ts +9 -0
- package/dist/types/node/files/index.d.ts +4 -0
- package/dist/types/node/files/inputFile.model.d.ts +22 -0
- package/dist/types/node/files/inputFile.utils.d.ts +14 -0
- package/dist/types/node/http/http-mixed-client.d.ts +45 -0
- package/dist/types/node/http/http-mixed-client.factory.resource.d.ts +17 -0
- package/dist/types/node/http/http-smart-client.factory.resource.d.ts +16 -0
- package/dist/types/node/http/http-smart-client.model.d.ts +27 -0
- package/dist/types/node/http/index.d.ts +4 -0
- package/dist/types/node/index.d.ts +1 -0
- package/dist/types/node/node.d.ts +193 -0
- package/dist/types/node/platform/createFile.d.ts +9 -0
- package/dist/types/node/tunnel/allowlist.d.ts +7 -0
- package/dist/types/node/tunnel/index.d.ts +2 -0
- package/dist/types/node/upload/manifest.d.ts +23 -0
- package/dist/types/platform/adapters/browser.d.ts +14 -0
- package/dist/types/platform/adapters/edge.d.ts +5 -0
- package/dist/types/platform/adapters/node-als.d.ts +1 -0
- package/dist/types/platform/adapters/node.d.ts +15 -0
- package/dist/types/platform/adapters/universal-generic.d.ts +14 -0
- package/dist/types/platform/adapters/universal.d.ts +18 -0
- package/dist/types/platform/createFile.d.ts +10 -0
- package/dist/types/platform/createWebFile.d.ts +11 -0
- package/dist/types/platform/factory.d.ts +2 -0
- package/dist/types/platform/index.d.ts +27 -0
- package/dist/types/platform/types.d.ts +31 -0
- package/dist/types/processHooks.d.ts +2 -0
- package/dist/types/public-types.d.ts +13 -0
- package/dist/types/public.d.ts +210 -0
- package/dist/types/run.d.ts +14 -0
- package/dist/types/serializer/Serializer.d.ts +84 -0
- package/dist/types/serializer/binary-builtins.d.ts +5 -0
- package/dist/types/serializer/builtins.d.ts +47 -0
- package/dist/types/serializer/deserializer.d.ts +27 -0
- package/dist/types/serializer/error-url-builtins.d.ts +13 -0
- package/dist/types/serializer/graph-serializer.d.ts +27 -0
- package/dist/types/serializer/index.d.ts +6 -0
- package/dist/types/serializer/option-normalizers.d.ts +2 -0
- package/dist/types/serializer/regexp-validator.d.ts +34 -0
- package/dist/types/serializer/serialize-utils.d.ts +15 -0
- package/dist/types/serializer/special-values.d.ts +20 -0
- package/dist/types/serializer/tree-serializer.d.ts +20 -0
- package/dist/types/serializer/type-registry.d.ts +58 -0
- package/dist/types/serializer/types.d.ts +126 -0
- package/dist/types/serializer/validation.d.ts +34 -0
- package/dist/types/testing.d.ts +19 -0
- package/dist/types/tools/detectRunnerMode.d.ts +9 -0
- package/dist/types/tools/getCallerFile.d.ts +1 -0
- package/dist/types/tools/throws.d.ts +7 -0
- package/dist/types/tunnels/buildUniversalManifest.d.ts +24 -0
- package/dist/types/types/asyncContext.d.ts +41 -0
- package/dist/types/types/contracts.d.ts +62 -0
- package/dist/types/types/error.d.ts +39 -0
- package/dist/types/types/event.d.ts +79 -0
- package/dist/types/types/executionJournal.d.ts +29 -0
- package/dist/types/types/hook.d.ts +23 -0
- package/dist/types/types/inputFile.d.ts +34 -0
- package/dist/types/types/meta.d.ts +22 -0
- package/dist/types/types/resource.d.ts +133 -0
- package/dist/types/types/resourceMiddleware.d.ts +48 -0
- package/dist/types/types/runner.d.ts +68 -0
- package/dist/types/types/storeTypes.d.ts +46 -0
- package/dist/types/types/symbols.d.ts +34 -0
- package/dist/types/types/tag.d.ts +45 -0
- package/dist/types/types/task.d.ts +76 -0
- package/dist/types/types/taskMiddleware.d.ts +55 -0
- package/dist/types/types/utilities.d.ts +125 -0
- package/dist/universal/index.cjs +851 -476
- package/dist/universal/index.cjs.map +1 -1
- package/dist/universal/index.mjs +849 -476
- package/dist/universal/index.mjs.map +1 -1
- package/package.json +15 -14
- package/readmes/AI.md +30 -9
- package/dist/browser/index.d.mts +0 -2919
- package/dist/browser/index.d.ts +0 -2919
- package/dist/edge/index.d.mts +0 -2919
- package/dist/edge/index.d.ts +0 -2919
- package/dist/node/node.d.mts +0 -4622
- package/dist/node/node.d.ts +0 -4622
- package/dist/universal/index.d.mts +0 -2919
- package/dist/universal/index.d.ts +0 -2919
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { IStepBuilder, StepOptions } from "./interfaces/context";
|
|
2
|
+
import type { DurableContext } from "./DurableContext";
|
|
3
|
+
/**
|
|
4
|
+
* Fluent helper for building a durable step.
|
|
5
|
+
*
|
|
6
|
+
* This is the ergonomic layer behind `ctx.step("id")`:
|
|
7
|
+
* - `up()` defines the memoized computation
|
|
8
|
+
* - `down()` registers a compensation to be invoked by `ctx.rollback()`
|
|
9
|
+
*
|
|
10
|
+
* It is `PromiseLike`, so users can `await ctx.step("x").up(...).down(...)`.
|
|
11
|
+
*/
|
|
12
|
+
export declare class StepBuilder<T> implements IStepBuilder<T> {
|
|
13
|
+
private readonly context;
|
|
14
|
+
private readonly stepId;
|
|
15
|
+
private readonly options;
|
|
16
|
+
private upFn?;
|
|
17
|
+
private downFn?;
|
|
18
|
+
constructor(context: DurableContext, stepId: string, options?: StepOptions);
|
|
19
|
+
up(fn: () => Promise<T>): this;
|
|
20
|
+
down(fn: (result: T) => Promise<void>): this;
|
|
21
|
+
private execute;
|
|
22
|
+
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { ExecutionStatus } from "./types";
|
|
2
|
+
export declare const DurableAuditEntryKind: {
|
|
3
|
+
readonly ExecutionStatusChanged: "execution_status_changed";
|
|
4
|
+
readonly StepCompleted: "step_completed";
|
|
5
|
+
readonly SleepScheduled: "sleep_scheduled";
|
|
6
|
+
readonly SleepCompleted: "sleep_completed";
|
|
7
|
+
readonly SignalWaiting: "signal_waiting";
|
|
8
|
+
readonly SignalDelivered: "signal_delivered";
|
|
9
|
+
readonly SignalTimedOut: "signal_timed_out";
|
|
10
|
+
readonly EmitPublished: "emit_published";
|
|
11
|
+
readonly SwitchEvaluated: "switch_evaluated";
|
|
12
|
+
readonly Note: "note";
|
|
13
|
+
};
|
|
14
|
+
export type DurableAuditEntryKind = (typeof DurableAuditEntryKind)[keyof typeof DurableAuditEntryKind];
|
|
15
|
+
export interface DurableAuditEntryBase {
|
|
16
|
+
id: string;
|
|
17
|
+
executionId: string;
|
|
18
|
+
at: Date;
|
|
19
|
+
kind: DurableAuditEntryKind;
|
|
20
|
+
attempt: number;
|
|
21
|
+
taskId?: string;
|
|
22
|
+
}
|
|
23
|
+
export type DurableAuditEntry = (DurableAuditEntryBase & {
|
|
24
|
+
kind: typeof DurableAuditEntryKind.ExecutionStatusChanged;
|
|
25
|
+
from: ExecutionStatus | null;
|
|
26
|
+
to: ExecutionStatus;
|
|
27
|
+
reason?: string;
|
|
28
|
+
}) | (DurableAuditEntryBase & {
|
|
29
|
+
kind: typeof DurableAuditEntryKind.StepCompleted;
|
|
30
|
+
stepId: string;
|
|
31
|
+
durationMs: number;
|
|
32
|
+
isInternal: boolean;
|
|
33
|
+
}) | (DurableAuditEntryBase & {
|
|
34
|
+
kind: typeof DurableAuditEntryKind.SleepScheduled;
|
|
35
|
+
stepId: string;
|
|
36
|
+
timerId: string;
|
|
37
|
+
durationMs: number;
|
|
38
|
+
fireAt: Date;
|
|
39
|
+
}) | (DurableAuditEntryBase & {
|
|
40
|
+
kind: typeof DurableAuditEntryKind.SleepCompleted;
|
|
41
|
+
stepId: string;
|
|
42
|
+
timerId: string;
|
|
43
|
+
}) | (DurableAuditEntryBase & {
|
|
44
|
+
kind: typeof DurableAuditEntryKind.SignalWaiting;
|
|
45
|
+
stepId: string;
|
|
46
|
+
signalId: string;
|
|
47
|
+
timeoutMs?: number;
|
|
48
|
+
timeoutAtMs?: number;
|
|
49
|
+
timerId?: string;
|
|
50
|
+
reason?: "initial" | "timeout_armed";
|
|
51
|
+
}) | (DurableAuditEntryBase & {
|
|
52
|
+
kind: typeof DurableAuditEntryKind.SignalDelivered;
|
|
53
|
+
stepId: string;
|
|
54
|
+
signalId: string;
|
|
55
|
+
}) | (DurableAuditEntryBase & {
|
|
56
|
+
kind: typeof DurableAuditEntryKind.SignalTimedOut;
|
|
57
|
+
stepId: string;
|
|
58
|
+
signalId: string;
|
|
59
|
+
timerId: string;
|
|
60
|
+
}) | (DurableAuditEntryBase & {
|
|
61
|
+
kind: typeof DurableAuditEntryKind.EmitPublished;
|
|
62
|
+
stepId: string;
|
|
63
|
+
eventId: string;
|
|
64
|
+
}) | (DurableAuditEntryBase & {
|
|
65
|
+
kind: typeof DurableAuditEntryKind.SwitchEvaluated;
|
|
66
|
+
stepId: string;
|
|
67
|
+
branchId: string;
|
|
68
|
+
durationMs: number;
|
|
69
|
+
}) | (DurableAuditEntryBase & {
|
|
70
|
+
kind: typeof DurableAuditEntryKind.Note;
|
|
71
|
+
message: string;
|
|
72
|
+
meta?: Record<string, unknown>;
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* Input type for appendAuditEntry - omits auto-generated fields (id, at).
|
|
76
|
+
* Preserves the discriminated union for proper type checking at call sites.
|
|
77
|
+
* executionId and attempt are required for service-level entries but filled by context.
|
|
78
|
+
*/
|
|
79
|
+
export type DurableAuditEntryInput = {
|
|
80
|
+
kind: typeof DurableAuditEntryKind.ExecutionStatusChanged;
|
|
81
|
+
executionId: string;
|
|
82
|
+
attempt: number;
|
|
83
|
+
from: ExecutionStatus | null;
|
|
84
|
+
to: ExecutionStatus;
|
|
85
|
+
reason?: string;
|
|
86
|
+
taskId?: string;
|
|
87
|
+
} | {
|
|
88
|
+
kind: typeof DurableAuditEntryKind.StepCompleted;
|
|
89
|
+
stepId: string;
|
|
90
|
+
durationMs: number;
|
|
91
|
+
isInternal: boolean;
|
|
92
|
+
taskId?: string;
|
|
93
|
+
} | {
|
|
94
|
+
kind: typeof DurableAuditEntryKind.SleepScheduled;
|
|
95
|
+
stepId: string;
|
|
96
|
+
timerId: string;
|
|
97
|
+
durationMs: number;
|
|
98
|
+
fireAt: Date;
|
|
99
|
+
taskId?: string;
|
|
100
|
+
} | {
|
|
101
|
+
kind: typeof DurableAuditEntryKind.SleepCompleted;
|
|
102
|
+
executionId: string;
|
|
103
|
+
attempt: number;
|
|
104
|
+
stepId: string;
|
|
105
|
+
timerId: string;
|
|
106
|
+
taskId?: string;
|
|
107
|
+
} | {
|
|
108
|
+
kind: typeof DurableAuditEntryKind.SignalWaiting;
|
|
109
|
+
stepId: string;
|
|
110
|
+
signalId: string;
|
|
111
|
+
timeoutMs?: number;
|
|
112
|
+
timeoutAtMs?: number;
|
|
113
|
+
timerId?: string;
|
|
114
|
+
reason?: "initial" | "timeout_armed";
|
|
115
|
+
taskId?: string;
|
|
116
|
+
} | {
|
|
117
|
+
kind: typeof DurableAuditEntryKind.SignalDelivered;
|
|
118
|
+
executionId: string;
|
|
119
|
+
attempt: number;
|
|
120
|
+
stepId: string;
|
|
121
|
+
signalId: string;
|
|
122
|
+
taskId?: string;
|
|
123
|
+
} | {
|
|
124
|
+
kind: typeof DurableAuditEntryKind.SignalTimedOut;
|
|
125
|
+
executionId: string;
|
|
126
|
+
attempt: number;
|
|
127
|
+
stepId: string;
|
|
128
|
+
signalId: string;
|
|
129
|
+
timerId: string;
|
|
130
|
+
taskId?: string;
|
|
131
|
+
} | {
|
|
132
|
+
kind: typeof DurableAuditEntryKind.EmitPublished;
|
|
133
|
+
stepId: string;
|
|
134
|
+
eventId: string;
|
|
135
|
+
taskId?: string;
|
|
136
|
+
} | {
|
|
137
|
+
kind: typeof DurableAuditEntryKind.SwitchEvaluated;
|
|
138
|
+
stepId: string;
|
|
139
|
+
branchId: string;
|
|
140
|
+
durationMs: number;
|
|
141
|
+
taskId?: string;
|
|
142
|
+
} | {
|
|
143
|
+
kind: typeof DurableAuditEntryKind.Note;
|
|
144
|
+
message: string;
|
|
145
|
+
meta?: Record<string, unknown>;
|
|
146
|
+
taskId?: string;
|
|
147
|
+
};
|
|
148
|
+
export interface DurableAuditEmitter {
|
|
149
|
+
emit(entry: DurableAuditEntry): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
export declare function isDurableInternalStepId(stepId: string): boolean;
|
|
152
|
+
export declare function createDurableAuditEntryId(atMs?: number): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DurableServiceConfig } from "./interfaces/service";
|
|
2
|
+
import { DurableResource } from "./DurableResource";
|
|
3
|
+
import type { EventManager } from "../../../models/EventManager";
|
|
4
|
+
import type { TaskRunner } from "../../../models/TaskRunner";
|
|
5
|
+
import type { Store } from "../../../models/Store";
|
|
6
|
+
export type RunnerDurableRuntimeConfig = Omit<DurableServiceConfig, "taskExecutor" | "tasks" | "taskResolver" | "contextProvider"> & {
|
|
7
|
+
/**
|
|
8
|
+
* Starts an embedded worker (queue consumer) in this process.
|
|
9
|
+
* Has effect only when `queue` is configured.
|
|
10
|
+
*/
|
|
11
|
+
worker?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export interface RunnerDurableDeps {
|
|
14
|
+
taskRunner: TaskRunner;
|
|
15
|
+
eventManager: EventManager;
|
|
16
|
+
runnerStore: Store;
|
|
17
|
+
}
|
|
18
|
+
export declare function createRunnerDurableRuntime(config: RunnerDurableRuntimeConfig, deps: RunnerDurableDeps): Promise<DurableResource>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IDurableStore } from "../interfaces/store";
|
|
2
|
+
import { type DurableAuditEmitter, type DurableAuditEntryInput } from "../audit";
|
|
3
|
+
export type DurableContextAudit = {
|
|
4
|
+
/** True if we have at least one sink (store persistence and/or emitter). */
|
|
5
|
+
isEnabled: () => boolean;
|
|
6
|
+
append: (entry: DurableAuditEntryInput) => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export declare function createDurableContextAudit(params: {
|
|
9
|
+
store: IDurableStore;
|
|
10
|
+
executionId: string;
|
|
11
|
+
attempt: number;
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
emitter: DurableAuditEmitter | null;
|
|
14
|
+
}): DurableContextAudit;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ImplicitInternalStepIdKind = "sleep" | "emit" | "waitForSignal";
|
|
2
|
+
export type ImplicitInternalStepIdsPolicy = "allow" | "warn" | "error";
|
|
3
|
+
export type DurableContextDeterminism = {
|
|
4
|
+
assertOrWarnImplicitInternalStepId: (kind: ImplicitInternalStepIdKind) => void;
|
|
5
|
+
assertUniqueStepId: (stepId: string) => void;
|
|
6
|
+
assertUserStepId: (stepId: string) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function createDurableContextDeterminism(params: {
|
|
9
|
+
policy: ImplicitInternalStepIdsPolicy;
|
|
10
|
+
warnedKinds: Set<ImplicitInternalStepIdKind>;
|
|
11
|
+
seenStepIds: Set<string>;
|
|
12
|
+
warn: (message: string) => void;
|
|
13
|
+
}): DurableContextDeterminism;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IEventBus } from "../interfaces/bus";
|
|
2
|
+
import type { EmitOptions, IStepBuilder, StepOptions } from "../interfaces/context";
|
|
3
|
+
import type { IEventDefinition } from "../../../../types/event";
|
|
4
|
+
import { type DurableAuditEntryInput } from "../audit";
|
|
5
|
+
export declare function emitDurably<TPayload>(params: {
|
|
6
|
+
bus: IEventBus;
|
|
7
|
+
assertNotCancelled: () => Promise<void>;
|
|
8
|
+
appendAuditEntry: (entry: DurableAuditEntryInput) => Promise<void>;
|
|
9
|
+
assertUniqueStepId: (stepId: string) => void;
|
|
10
|
+
assertOrWarnImplicitInternalStepId: (kind: "sleep" | "emit" | "waitForSignal") => void;
|
|
11
|
+
emitIndexes: Map<string, number>;
|
|
12
|
+
internalStep: <T>(stepId: string, options?: StepOptions) => IStepBuilder<T>;
|
|
13
|
+
event: IEventDefinition<TPayload>;
|
|
14
|
+
payload: TPayload;
|
|
15
|
+
options?: EmitOptions;
|
|
16
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SleepOptions } from "../interfaces/context";
|
|
2
|
+
import type { IDurableStore } from "../interfaces/store";
|
|
3
|
+
import { type DurableAuditEntryInput } from "../audit";
|
|
4
|
+
export declare function sleepDurably(params: {
|
|
5
|
+
store: IDurableStore;
|
|
6
|
+
executionId: string;
|
|
7
|
+
assertNotCancelled: () => Promise<void>;
|
|
8
|
+
appendAuditEntry: (entry: DurableAuditEntryInput) => Promise<void>;
|
|
9
|
+
assertUniqueStepId: (stepId: string) => void;
|
|
10
|
+
assertOrWarnImplicitInternalStepId: (kind: "sleep" | "emit" | "waitForSignal") => void;
|
|
11
|
+
sleepIndexRef: {
|
|
12
|
+
current: number;
|
|
13
|
+
};
|
|
14
|
+
durationMs: number;
|
|
15
|
+
options?: SleepOptions;
|
|
16
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DurableAuditEntryInput } from "../audit";
|
|
2
|
+
import type { IStepBuilder, StepOptions } from "../interfaces/context";
|
|
3
|
+
import type { IDurableStore } from "../interfaces/store";
|
|
4
|
+
export type DurableCompensation = {
|
|
5
|
+
stepId: string;
|
|
6
|
+
action: () => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export declare function executeDurableStep<T>(params: {
|
|
9
|
+
store: IDurableStore;
|
|
10
|
+
executionId: string;
|
|
11
|
+
assertNotCancelled: () => Promise<void>;
|
|
12
|
+
appendAuditEntry: (entry: DurableAuditEntryInput) => Promise<void>;
|
|
13
|
+
stepId: string;
|
|
14
|
+
options: StepOptions;
|
|
15
|
+
upFn: () => Promise<T>;
|
|
16
|
+
downFn?: (result: T) => Promise<void>;
|
|
17
|
+
compensations: DurableCompensation[];
|
|
18
|
+
}): Promise<T>;
|
|
19
|
+
export declare function rollbackDurableCompensations(params: {
|
|
20
|
+
store: IDurableStore;
|
|
21
|
+
executionId: string;
|
|
22
|
+
compensations: DurableCompensation[];
|
|
23
|
+
assertUniqueStepId: (stepId: string) => void;
|
|
24
|
+
internalStep: <T>(stepId: string, options?: StepOptions) => IStepBuilder<T>;
|
|
25
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SwitchBranch } from "../interfaces/context";
|
|
2
|
+
import type { IDurableStore } from "../interfaces/store";
|
|
3
|
+
import { type DurableAuditEntryInput } from "../audit";
|
|
4
|
+
/**
|
|
5
|
+
* Replay-safe switch implementation for durable workflows.
|
|
6
|
+
*
|
|
7
|
+
* On first execution the matchers are evaluated in order; the first matching
|
|
8
|
+
* branch's `run()` is invoked and the `{ branchId, result }` pair is persisted.
|
|
9
|
+
* On replay the cached branch result is returned immediately — matchers and
|
|
10
|
+
* `run()` are never re-executed.
|
|
11
|
+
*/
|
|
12
|
+
export declare function switchDurably<TValue, TResult>(params: {
|
|
13
|
+
store: IDurableStore;
|
|
14
|
+
executionId: string;
|
|
15
|
+
assertNotCancelled: () => Promise<void>;
|
|
16
|
+
appendAuditEntry: (entry: DurableAuditEntryInput) => Promise<void>;
|
|
17
|
+
assertUniqueStepId: (stepId: string) => void;
|
|
18
|
+
stepId: string;
|
|
19
|
+
value: TValue;
|
|
20
|
+
branches: SwitchBranch<TValue, TResult>[];
|
|
21
|
+
defaultBranch?: Omit<SwitchBranch<TValue, TResult>, "match">;
|
|
22
|
+
}): Promise<TResult>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SignalOptions } from "../interfaces/context";
|
|
2
|
+
import type { IDurableStore } from "../interfaces/store";
|
|
3
|
+
import type { IEventDefinition } from "../../../../types/event";
|
|
4
|
+
import { type DurableAuditEntryInput } from "../audit";
|
|
5
|
+
export type WaitForSignalOutcome<TPayload> = {
|
|
6
|
+
kind: "signal";
|
|
7
|
+
payload: TPayload;
|
|
8
|
+
} | {
|
|
9
|
+
kind: "timeout";
|
|
10
|
+
};
|
|
11
|
+
type SignalInput<TPayload> = IEventDefinition<TPayload>;
|
|
12
|
+
export declare function waitForSignalDurably<TPayload>(params: {
|
|
13
|
+
store: IDurableStore;
|
|
14
|
+
executionId: string;
|
|
15
|
+
assertNotCancelled: () => Promise<void>;
|
|
16
|
+
appendAuditEntry: (entry: DurableAuditEntryInput) => Promise<void>;
|
|
17
|
+
assertUniqueStepId: (stepId: string) => void;
|
|
18
|
+
assertOrWarnImplicitInternalStepId: (kind: "sleep" | "emit" | "waitForSignal") => void;
|
|
19
|
+
signalIndexes: Map<string, number>;
|
|
20
|
+
signal: SignalInput<TPayload>;
|
|
21
|
+
options?: SignalOptions;
|
|
22
|
+
}): Promise<TPayload | WaitForSignalOutcome<TPayload>>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { IDurableContext } from "./interfaces/context";
|
|
2
|
+
/** Discriminated union describing a single node in a durable workflow. */
|
|
3
|
+
export type FlowNode = FlowStepNode | FlowSleepNode | FlowSignalNode | FlowEmitNode | FlowSwitchNode | FlowNoteNode;
|
|
4
|
+
export interface FlowStepNode {
|
|
5
|
+
kind: "step";
|
|
6
|
+
stepId: string;
|
|
7
|
+
hasCompensation: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface FlowSleepNode {
|
|
10
|
+
kind: "sleep";
|
|
11
|
+
durationMs: number;
|
|
12
|
+
stepId?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface FlowSignalNode {
|
|
15
|
+
kind: "waitForSignal";
|
|
16
|
+
signalId: string;
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
stepId?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface FlowEmitNode {
|
|
21
|
+
kind: "emit";
|
|
22
|
+
eventId: string;
|
|
23
|
+
stepId?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface FlowSwitchNode {
|
|
26
|
+
kind: "switch";
|
|
27
|
+
stepId: string;
|
|
28
|
+
branchIds: string[];
|
|
29
|
+
hasDefault: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface FlowNoteNode {
|
|
32
|
+
kind: "note";
|
|
33
|
+
message: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Serializable description of a durable workflow's structure.
|
|
37
|
+
*
|
|
38
|
+
* Produced by `recordFlowShape()` without actually executing the workflow.
|
|
39
|
+
* Useful for documentation, visualization dashboards, and tooling.
|
|
40
|
+
*/
|
|
41
|
+
export interface DurableFlowShape {
|
|
42
|
+
nodes: FlowNode[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Record a durable workflow flow-shape without executing it.
|
|
46
|
+
*
|
|
47
|
+
* This runs the descriptor against a recording `IDurableContext` that captures
|
|
48
|
+
* `ctx.*` calls into a serializable shape.
|
|
49
|
+
*/
|
|
50
|
+
export declare function recordFlowShape(descriptor: (ctx: IDurableContext) => Promise<void>): Promise<DurableFlowShape>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IEventDefinition } from "../../../types/event";
|
|
2
|
+
export type DurableSignalId<TPayload = unknown> = IEventDefinition<TPayload>;
|
|
3
|
+
export interface DurableStepId<TResult = unknown> {
|
|
4
|
+
id: string;
|
|
5
|
+
/**
|
|
6
|
+
* Phantom field used only for type inference. Not present at runtime.
|
|
7
|
+
* The result type is carried through the object type.
|
|
8
|
+
*/
|
|
9
|
+
readonly __result?: TResult;
|
|
10
|
+
}
|
|
11
|
+
export declare function createDurableStepId<TResult>(id: string): DurableStepId<TResult>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./interfaces/bus";
|
|
3
|
+
export * from "./interfaces/queue";
|
|
4
|
+
export * from "./interfaces/store";
|
|
5
|
+
export * from "./interfaces/context";
|
|
6
|
+
export * from "./interfaces/service";
|
|
7
|
+
export * from "./CronParser";
|
|
8
|
+
export * from "./DurableContext";
|
|
9
|
+
export * from "./DurableService";
|
|
10
|
+
export * from "./DurableWorker";
|
|
11
|
+
export * from "./flowShape";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface BusEvent {
|
|
2
|
+
type: string;
|
|
3
|
+
payload: unknown;
|
|
4
|
+
timestamp: Date;
|
|
5
|
+
}
|
|
6
|
+
export type BusEventHandler = (event: BusEvent) => Promise<void>;
|
|
7
|
+
export interface IEventBus {
|
|
8
|
+
publish(channel: string, event: BusEvent): Promise<void>;
|
|
9
|
+
subscribe(channel: string, handler: BusEventHandler): Promise<void>;
|
|
10
|
+
unsubscribe(channel: string): Promise<void>;
|
|
11
|
+
init?(): Promise<void>;
|
|
12
|
+
dispose?(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { IEventDefinition } from "../../../../types/event";
|
|
2
|
+
import type { DurableStepId } from "../ids";
|
|
3
|
+
export interface StepOptions {
|
|
4
|
+
retries?: number;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Options for sleep operations.
|
|
9
|
+
* Use `stepId` to provide a stable identifier that survives code refactoring.
|
|
10
|
+
*/
|
|
11
|
+
export interface SleepOptions {
|
|
12
|
+
/** Explicit step ID for replay stability. If not provided, an auto-indexed ID is used. */
|
|
13
|
+
stepId?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Options for waitForSignal operations.
|
|
17
|
+
*/
|
|
18
|
+
export interface SignalOptions {
|
|
19
|
+
/** Timeout in milliseconds. If provided, returns a discriminated union with kind. */
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
/** Explicit step ID for replay stability. If not provided, an auto-indexed ID is used. */
|
|
22
|
+
stepId?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Options for emit operations.
|
|
26
|
+
*/
|
|
27
|
+
export interface EmitOptions {
|
|
28
|
+
/** Explicit step ID for replay stability. If not provided, an auto-indexed ID is used. */
|
|
29
|
+
stepId?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A single branch in a durable switch expression.
|
|
33
|
+
*
|
|
34
|
+
* `id` identifies the branch for replay; `match` tests whether this branch applies;
|
|
35
|
+
* `run` executes the branch logic (only on first evaluation, cached on replay).
|
|
36
|
+
*/
|
|
37
|
+
export interface SwitchBranch<TValue, TResult> {
|
|
38
|
+
/** Stable identifier for this branch. Persisted for replay. */
|
|
39
|
+
id: string;
|
|
40
|
+
/** Predicate that selects this branch based on the switch value. */
|
|
41
|
+
match: (value: TValue) => boolean;
|
|
42
|
+
/** Logic to execute when this branch is selected. */
|
|
43
|
+
run: (value: TValue) => Promise<TResult>;
|
|
44
|
+
}
|
|
45
|
+
export interface IStepBuilder<T> extends PromiseLike<T> {
|
|
46
|
+
up(fn: () => Promise<T>): this;
|
|
47
|
+
down(fn: (result: T) => Promise<void>): this;
|
|
48
|
+
}
|
|
49
|
+
export interface IDurableContext {
|
|
50
|
+
readonly executionId: string;
|
|
51
|
+
readonly attempt: number;
|
|
52
|
+
step<T>(stepId: string): IStepBuilder<T>;
|
|
53
|
+
step<T>(stepId: DurableStepId<T>): IStepBuilder<T>;
|
|
54
|
+
step<T>(stepId: string, fn: () => Promise<T>): Promise<T>;
|
|
55
|
+
step<T>(stepId: DurableStepId<T>, fn: () => Promise<T>): Promise<T>;
|
|
56
|
+
step<T>(stepId: string, options: StepOptions, fn: () => Promise<T>): Promise<T>;
|
|
57
|
+
step<T>(stepId: DurableStepId<T>, options: StepOptions, fn: () => Promise<T>): Promise<T>;
|
|
58
|
+
sleep(durationMs: number, options?: SleepOptions): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Suspend until an external signal is delivered via DurableService.signal().
|
|
61
|
+
* The signal is memoized as a durable step under `__signal:<signalId>[:index]`.
|
|
62
|
+
* Use options.stepId to provide a stable identifier for replay safety.
|
|
63
|
+
*/
|
|
64
|
+
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>): Promise<TPayload>;
|
|
65
|
+
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>, options: SignalOptions & {
|
|
66
|
+
timeoutMs: number;
|
|
67
|
+
}): Promise<{
|
|
68
|
+
kind: "signal";
|
|
69
|
+
payload: TPayload;
|
|
70
|
+
} | {
|
|
71
|
+
kind: "timeout";
|
|
72
|
+
}>;
|
|
73
|
+
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>, options: SignalOptions): Promise<TPayload>;
|
|
74
|
+
emit<TPayload>(event: IEventDefinition<TPayload>, payload: TPayload, options?: EmitOptions): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Append a custom audit entry for observability and debugging.
|
|
77
|
+
* This is a no-op if audit is disabled or the store does not support it.
|
|
78
|
+
*/
|
|
79
|
+
note(message: string, meta?: Record<string, unknown>): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Replay-safe branching primitive.
|
|
82
|
+
*
|
|
83
|
+
* Evaluates `branches` against `value` to find the first matching branch.
|
|
84
|
+
* The matched branch's `id` and result are persisted; on replay the matchers
|
|
85
|
+
* are skipped and the cached result is returned directly.
|
|
86
|
+
*
|
|
87
|
+
* Throws if no branch matches and no `defaultBranch` is provided.
|
|
88
|
+
*/
|
|
89
|
+
switch<TValue, TResult>(stepId: string, value: TValue, branches: SwitchBranch<TValue, TResult>[], defaultBranch?: Omit<SwitchBranch<TValue, TResult>, "match">): Promise<TResult>;
|
|
90
|
+
rollback(): Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Internal control-flow signal used to suspend a durable execution without failing it.
|
|
94
|
+
*
|
|
95
|
+
* `DurableContext` throws this error to indicate "pause here and resume later":
|
|
96
|
+
* - `"sleep"`: durable sleep timer was scheduled
|
|
97
|
+
* - `"yield"`: waiting for a signal (or signal-timeout timer) to complete
|
|
98
|
+
*
|
|
99
|
+
* `ExecutionManager` treats this as a normal suspension and will not mark the execution
|
|
100
|
+
* as failed; instead it schedules a resume via timers/queue depending on configuration.
|
|
101
|
+
*/
|
|
102
|
+
export declare class SuspensionSignal extends Error {
|
|
103
|
+
readonly reason: "sleep" | "yield" | "timeout";
|
|
104
|
+
constructor(reason: "sleep" | "yield" | "timeout");
|
|
105
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface QueueMessage<T = unknown> {
|
|
2
|
+
id: string;
|
|
3
|
+
type: "execute" | "resume" | "schedule";
|
|
4
|
+
payload: T;
|
|
5
|
+
attempts: number;
|
|
6
|
+
maxAttempts: number;
|
|
7
|
+
createdAt: Date;
|
|
8
|
+
}
|
|
9
|
+
export type MessageHandler<T = unknown> = (message: QueueMessage<T>) => Promise<void>;
|
|
10
|
+
export interface IDurableQueue {
|
|
11
|
+
enqueue<T>(message: Omit<QueueMessage<T>, "id" | "createdAt" | "attempts">): Promise<string>;
|
|
12
|
+
consume<T>(handler: MessageHandler<T>): Promise<void>;
|
|
13
|
+
ack(messageId: string): Promise<void>;
|
|
14
|
+
nack(messageId: string, requeue?: boolean): Promise<void>;
|
|
15
|
+
init?(): Promise<void>;
|
|
16
|
+
dispose?(): Promise<void>;
|
|
17
|
+
}
|