@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,146 @@
|
|
|
1
|
+
import type { IEventDefinition } from "../../../../types/event";
|
|
2
|
+
import type { IDurableStore } from "./store";
|
|
3
|
+
import type { IDurableQueue } from "./queue";
|
|
4
|
+
import type { IEventBus } from "./bus";
|
|
5
|
+
import type { IDurableContext } from "./context";
|
|
6
|
+
import type { Schedule } from "../types";
|
|
7
|
+
import type { DurableAuditEmitter } from "../audit";
|
|
8
|
+
export interface DurableTask<TInput = unknown, TResult = unknown> {
|
|
9
|
+
id: string;
|
|
10
|
+
run(input: TInput, ...args: any[]): Promise<TResult>;
|
|
11
|
+
}
|
|
12
|
+
export interface ITaskExecutor {
|
|
13
|
+
run<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput): Promise<TResult>;
|
|
14
|
+
}
|
|
15
|
+
export interface ScheduleConfig<TInput = unknown> {
|
|
16
|
+
id: string;
|
|
17
|
+
task: DurableTask<TInput, unknown>;
|
|
18
|
+
cron?: string;
|
|
19
|
+
interval?: number;
|
|
20
|
+
input: TInput;
|
|
21
|
+
}
|
|
22
|
+
export interface DurableServiceConfig {
|
|
23
|
+
store: IDurableStore;
|
|
24
|
+
queue?: IDurableQueue;
|
|
25
|
+
eventBus?: IEventBus;
|
|
26
|
+
taskExecutor?: ITaskExecutor;
|
|
27
|
+
determinism?: {
|
|
28
|
+
/**
|
|
29
|
+
* Internal step IDs for `sleep()`/`emit()`/`waitForSignal()` default to call-order based IDs.
|
|
30
|
+
* In production this can be a replay/versioning footgun when refactors change call order.
|
|
31
|
+
*
|
|
32
|
+
* - "allow" (default): do nothing
|
|
33
|
+
* - "warn": emit a warning on first implicit internal step per kind
|
|
34
|
+
* - "error": throw when an implicit internal step id would be used
|
|
35
|
+
*/
|
|
36
|
+
implicitInternalStepIds?: "allow" | "warn" | "error";
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Unique identifier for this worker instance.
|
|
40
|
+
* Used for distributed timer coordination to ensure only one worker processes each timer.
|
|
41
|
+
* If not provided, a random UUID is generated.
|
|
42
|
+
*/
|
|
43
|
+
workerId?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Runs a callback with the given durable context available.
|
|
46
|
+
* In Runner environments this is typically implemented via AsyncLocalStorage
|
|
47
|
+
* so tasks can call `durable.use()`.
|
|
48
|
+
*/
|
|
49
|
+
contextProvider?: <R>(context: IDurableContext, fn: () => Promise<R> | R) => Promise<R> | R;
|
|
50
|
+
/**
|
|
51
|
+
* Resolves tasks by id for resuming/recovering executions.
|
|
52
|
+
* Useful in Runner environments where tasks are registered in the Store registry.
|
|
53
|
+
*/
|
|
54
|
+
taskResolver?: (taskId: string) => DurableTask<any, any> | undefined;
|
|
55
|
+
audit?: {
|
|
56
|
+
enabled?: boolean;
|
|
57
|
+
emitter?: DurableAuditEmitter;
|
|
58
|
+
};
|
|
59
|
+
polling?: {
|
|
60
|
+
enabled?: boolean;
|
|
61
|
+
interval?: number;
|
|
62
|
+
/** Time-to-live for timer claims in milliseconds. Default: 30000. */
|
|
63
|
+
claimTtlMs?: number;
|
|
64
|
+
};
|
|
65
|
+
execution?: {
|
|
66
|
+
maxAttempts?: number;
|
|
67
|
+
timeout?: number;
|
|
68
|
+
/**
|
|
69
|
+
* When a queue is configured, `startExecution()` persists the execution and then enqueues it.
|
|
70
|
+
* If enqueue fails (eg. broker outage), the execution would otherwise remain "pending" forever.
|
|
71
|
+
*
|
|
72
|
+
* This delay arms a small store-backed timer as a failsafe so workers can retry resuming it
|
|
73
|
+
* via the poller. Default: 10000 (10s). Set to 0 to disable.
|
|
74
|
+
*/
|
|
75
|
+
kickoffFailsafeDelayMs?: number;
|
|
76
|
+
};
|
|
77
|
+
schedules?: ScheduleConfig[];
|
|
78
|
+
tasks?: Array<DurableTask<any, any>>;
|
|
79
|
+
}
|
|
80
|
+
export interface ExecuteOptions {
|
|
81
|
+
timeout?: number;
|
|
82
|
+
priority?: number;
|
|
83
|
+
waitPollIntervalMs?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Optional workflow-level idempotency key.
|
|
86
|
+
* When supported by the store, multiple concurrent callers using the same key will receive the same executionId.
|
|
87
|
+
*/
|
|
88
|
+
idempotencyKey?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface ScheduleOptions {
|
|
91
|
+
id?: string;
|
|
92
|
+
at?: Date;
|
|
93
|
+
delay?: number;
|
|
94
|
+
cron?: string;
|
|
95
|
+
interval?: number;
|
|
96
|
+
}
|
|
97
|
+
export interface IDurableService {
|
|
98
|
+
startExecution<TInput>(task: DurableTask<TInput, unknown>, input?: TInput, options?: ExecuteOptions): Promise<string>;
|
|
99
|
+
/**
|
|
100
|
+
* Request cancellation for an execution.
|
|
101
|
+
* Cancellation is cooperative: it marks the execution as cancelled and unblocks waiters,
|
|
102
|
+
* but cannot preempt arbitrary in-process async work.
|
|
103
|
+
*/
|
|
104
|
+
cancelExecution(executionId: string, reason?: string): Promise<void>;
|
|
105
|
+
wait<TResult>(executionId: string, options?: {
|
|
106
|
+
timeout?: number;
|
|
107
|
+
waitPollIntervalMs?: number;
|
|
108
|
+
}): Promise<TResult>;
|
|
109
|
+
execute<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
110
|
+
/**
|
|
111
|
+
* A stricter alternative to `execute()` that rejects tasks whose result type
|
|
112
|
+
* includes `undefined` (including `void`, `unknown`, and `any`).
|
|
113
|
+
*
|
|
114
|
+
* This mirrors the runtime contract where `wait()`/`execute()` treat
|
|
115
|
+
* "completed without result" as an error.
|
|
116
|
+
*/
|
|
117
|
+
executeStrict<TInput, TResult>(task: undefined extends TResult ? never : DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
118
|
+
schedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions): Promise<string>;
|
|
119
|
+
/**
|
|
120
|
+
* Idempotently create (or update) a recurring schedule (cron/interval) with a stable id.
|
|
121
|
+
* Safe to call concurrently from multiple processes.
|
|
122
|
+
*/
|
|
123
|
+
ensureSchedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions & {
|
|
124
|
+
id: string;
|
|
125
|
+
}): Promise<string>;
|
|
126
|
+
recover(): Promise<void>;
|
|
127
|
+
start(): void;
|
|
128
|
+
stop(): Promise<void>;
|
|
129
|
+
pauseSchedule(scheduleId: string): Promise<void>;
|
|
130
|
+
resumeSchedule(scheduleId: string): Promise<void>;
|
|
131
|
+
getSchedule(scheduleId: string): Promise<Schedule | null>;
|
|
132
|
+
listSchedules(): Promise<Schedule[]>;
|
|
133
|
+
updateSchedule(scheduleId: string, updates: {
|
|
134
|
+
cron?: string;
|
|
135
|
+
interval?: number;
|
|
136
|
+
input?: unknown;
|
|
137
|
+
}): Promise<void>;
|
|
138
|
+
removeSchedule(scheduleId: string): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Deliver a signal payload to a waiting workflow execution and resume it.
|
|
141
|
+
*/
|
|
142
|
+
signal<TPayload>(executionId: string, signal: IEventDefinition<TPayload>, payload: TPayload): Promise<void>;
|
|
143
|
+
}
|
|
144
|
+
export interface IDurableExecutionProcessor {
|
|
145
|
+
processExecution(executionId: string): Promise<void>;
|
|
146
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Execution, ExecutionStatus, StepResult, Timer, Schedule } from "../types";
|
|
2
|
+
import type { DurableAuditEntry } from "../audit";
|
|
3
|
+
export interface ListExecutionsOptions {
|
|
4
|
+
status?: ExecutionStatus[];
|
|
5
|
+
taskId?: string;
|
|
6
|
+
limit?: number;
|
|
7
|
+
offset?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface IDurableStore {
|
|
10
|
+
saveExecution(execution: Execution): Promise<void>;
|
|
11
|
+
getExecution(id: string): Promise<Execution | null>;
|
|
12
|
+
updateExecution(id: string, updates: Partial<Execution>): Promise<void>;
|
|
13
|
+
listIncompleteExecutions(): Promise<Execution[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Optional execution-level idempotency mapping.
|
|
16
|
+
* If supported, allows `startExecution(..., { idempotencyKey })` to dedupe workflow starts.
|
|
17
|
+
*/
|
|
18
|
+
getExecutionIdByIdempotencyKey?(params: {
|
|
19
|
+
taskId: string;
|
|
20
|
+
idempotencyKey: string;
|
|
21
|
+
}): Promise<string | null>;
|
|
22
|
+
setExecutionIdByIdempotencyKey?(params: {
|
|
23
|
+
taskId: string;
|
|
24
|
+
idempotencyKey: string;
|
|
25
|
+
executionId: string;
|
|
26
|
+
}): Promise<boolean>;
|
|
27
|
+
listExecutions?(options?: ListExecutionsOptions): Promise<Execution[]>;
|
|
28
|
+
listStepResults?(executionId: string): Promise<StepResult[]>;
|
|
29
|
+
appendAuditEntry?(entry: DurableAuditEntry): Promise<void>;
|
|
30
|
+
listAuditEntries?(executionId: string, options?: {
|
|
31
|
+
limit?: number;
|
|
32
|
+
offset?: number;
|
|
33
|
+
}): Promise<DurableAuditEntry[]>;
|
|
34
|
+
retryRollback?(executionId: string): Promise<void>;
|
|
35
|
+
skipStep?(executionId: string, stepId: string): Promise<void>;
|
|
36
|
+
forceFail?(executionId: string, error: {
|
|
37
|
+
message: string;
|
|
38
|
+
stack?: string;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
editStepResult?(executionId: string, stepId: string, newResult: unknown): Promise<void>;
|
|
41
|
+
getStepResult(executionId: string, stepId: string): Promise<StepResult | null>;
|
|
42
|
+
saveStepResult(result: StepResult): Promise<void>;
|
|
43
|
+
createTimer(timer: Timer): Promise<void>;
|
|
44
|
+
getReadyTimers(now?: Date): Promise<Timer[]>;
|
|
45
|
+
markTimerFired(timerId: string): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Atomically claim a timer for processing. Returns true if claimed, false if already claimed.
|
|
48
|
+
* Used for distributed timer coordination to ensure only one worker processes each timer.
|
|
49
|
+
* @param timerId The ID of the timer to claim
|
|
50
|
+
* @param workerId A unique identifier for the worker claiming the timer
|
|
51
|
+
* @param ttlMs Time-to-live in milliseconds for the claim (in case worker dies)
|
|
52
|
+
*/
|
|
53
|
+
claimTimer?(timerId: string, workerId: string, ttlMs: number): Promise<boolean>;
|
|
54
|
+
deleteTimer(timerId: string): Promise<void>;
|
|
55
|
+
createSchedule(schedule: Schedule): Promise<void>;
|
|
56
|
+
getSchedule(id: string): Promise<Schedule | null>;
|
|
57
|
+
updateSchedule(id: string, updates: Partial<Schedule>): Promise<void>;
|
|
58
|
+
deleteSchedule(id: string): Promise<void>;
|
|
59
|
+
listSchedules(): Promise<Schedule[]>;
|
|
60
|
+
listActiveSchedules(): Promise<Schedule[]>;
|
|
61
|
+
listStuckExecutions?(): Promise<Execution[]>;
|
|
62
|
+
init?(): Promise<void>;
|
|
63
|
+
dispose?(): Promise<void>;
|
|
64
|
+
acquireLock?(resource: string, ttlMs: number): Promise<string | null>;
|
|
65
|
+
releaseLock?(resource: string, lockId: string): Promise<void>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IDurableStore } from "../interfaces/store";
|
|
2
|
+
import type { DurableAuditEntryInput, DurableAuditEmitter } from "../audit";
|
|
3
|
+
export interface AuditConfig {
|
|
4
|
+
/**
|
|
5
|
+
* When enabled, attempts to persist audit entries to the store (if supported).
|
|
6
|
+
* This is separate from event emission via `emitter`.
|
|
7
|
+
*/
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Optional emitter for streaming audit entries (e.g. Runner events, logging, mirroring).
|
|
11
|
+
* Emissions must be best-effort and never affect workflow correctness.
|
|
12
|
+
*/
|
|
13
|
+
emitter?: DurableAuditEmitter;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Durable audit trail sink.
|
|
17
|
+
*
|
|
18
|
+
* Used across the durable subsystem (service/managers/context) to record lifecycle
|
|
19
|
+
* events in a best-effort way. Persistence and emission are explicitly non-critical:
|
|
20
|
+
* failures must never affect workflow correctness (the store remains the source of truth).
|
|
21
|
+
*/
|
|
22
|
+
export declare class AuditLogger {
|
|
23
|
+
private readonly config;
|
|
24
|
+
private readonly store;
|
|
25
|
+
constructor(config: AuditConfig, store: IDurableStore);
|
|
26
|
+
log(params: DurableAuditEntryInput & {
|
|
27
|
+
at?: Date;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { IDurableStore } from "../interfaces/store";
|
|
2
|
+
import type { IDurableQueue } from "../interfaces/queue";
|
|
3
|
+
import type { IEventBus } from "../interfaces/bus";
|
|
4
|
+
import type { DurableServiceConfig, DurableTask, ExecuteOptions, ITaskExecutor } from "../interfaces/service";
|
|
5
|
+
import { type Execution } from "../types";
|
|
6
|
+
import type { TaskRegistry } from "./TaskRegistry";
|
|
7
|
+
import type { AuditLogger } from "./AuditLogger";
|
|
8
|
+
import type { WaitManager } from "./WaitManager";
|
|
9
|
+
export interface ExecutionManagerConfig {
|
|
10
|
+
store: IDurableStore;
|
|
11
|
+
queue?: IDurableQueue;
|
|
12
|
+
eventBus?: IEventBus;
|
|
13
|
+
taskExecutor?: ITaskExecutor;
|
|
14
|
+
contextProvider?: DurableServiceConfig["contextProvider"];
|
|
15
|
+
audit?: DurableServiceConfig["audit"];
|
|
16
|
+
determinism?: DurableServiceConfig["determinism"];
|
|
17
|
+
execution?: {
|
|
18
|
+
maxAttempts?: number;
|
|
19
|
+
timeout?: number;
|
|
20
|
+
kickoffFailsafeDelayMs?: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Runs durable executions (the "workflow engine" for attempts).
|
|
25
|
+
*
|
|
26
|
+
* Responsibilities:
|
|
27
|
+
* - persist new executions (including optional idempotency keys)
|
|
28
|
+
* - enqueue work (queue mode) or run directly (embedded mode)
|
|
29
|
+
* - execute a workflow attempt via `taskExecutor.run(...)`
|
|
30
|
+
* - inject a per-attempt `DurableContext` (via `contextProvider` / ALS wrapper)
|
|
31
|
+
* - interpret `SuspensionSignal` as "pause + reschedule" rather than failure
|
|
32
|
+
* - update execution status/result/error and notify waiters (`WaitManager`)
|
|
33
|
+
*/
|
|
34
|
+
export declare class ExecutionManager {
|
|
35
|
+
private readonly config;
|
|
36
|
+
private readonly taskRegistry;
|
|
37
|
+
private readonly auditLogger;
|
|
38
|
+
private readonly waitManager;
|
|
39
|
+
constructor(config: ExecutionManagerConfig, taskRegistry: TaskRegistry, auditLogger: AuditLogger, waitManager: WaitManager);
|
|
40
|
+
startExecution<TInput>(task: DurableTask<TInput, unknown>, input?: TInput, options?: ExecuteOptions): Promise<string>;
|
|
41
|
+
cancelExecution(executionId: string, reason?: string): Promise<void>;
|
|
42
|
+
execute<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
43
|
+
executeStrict<TInput, TResult>(task: undefined extends TResult ? never : DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
44
|
+
processExecution(executionId: string): Promise<void>;
|
|
45
|
+
kickoffExecution(executionId: string): Promise<void>;
|
|
46
|
+
notifyExecutionFinished(execution: Execution): Promise<void>;
|
|
47
|
+
private runExecutionAttempt;
|
|
48
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { IDurableStore } from "../interfaces/store";
|
|
2
|
+
import type { IDurableQueue } from "../interfaces/queue";
|
|
3
|
+
import { type Timer } from "../types";
|
|
4
|
+
import type { AuditLogger } from "./AuditLogger";
|
|
5
|
+
import type { TaskRegistry } from "./TaskRegistry";
|
|
6
|
+
import type { ScheduleManager } from "./ScheduleManager";
|
|
7
|
+
export interface PollingConfig {
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
interval?: number;
|
|
10
|
+
claimTtlMs?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface PollingManagerCallbacks {
|
|
13
|
+
processExecution: (executionId: string) => Promise<void>;
|
|
14
|
+
kickoffExecution: (executionId: string) => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Timer/tick driver for durable workflows.
|
|
18
|
+
*
|
|
19
|
+
* The durable store is the source of truth, but time needs an active driver:
|
|
20
|
+
* `PollingManager` periodically scans ready timers and performs the appropriate action:
|
|
21
|
+
*
|
|
22
|
+
* - complete `sleep()` steps by marking their step result as completed
|
|
23
|
+
* - resume executions after signal timeouts / scheduled kickoffs / retries
|
|
24
|
+
* - coordinate multi-worker polling via optional `store.claimTimer(...)`
|
|
25
|
+
*
|
|
26
|
+
* In production topologies you typically enable polling on worker nodes only.
|
|
27
|
+
*/
|
|
28
|
+
export declare class PollingManager {
|
|
29
|
+
private readonly workerId;
|
|
30
|
+
private readonly config;
|
|
31
|
+
private readonly store;
|
|
32
|
+
private readonly queue;
|
|
33
|
+
private readonly maxAttempts;
|
|
34
|
+
private readonly defaultTimeout;
|
|
35
|
+
private readonly taskRegistry;
|
|
36
|
+
private readonly auditLogger;
|
|
37
|
+
private readonly scheduleManager;
|
|
38
|
+
private readonly callbacks;
|
|
39
|
+
private isRunning;
|
|
40
|
+
private pollingTimer;
|
|
41
|
+
private pollingWake;
|
|
42
|
+
constructor(workerId: string, config: PollingConfig, store: IDurableStore, queue: IDurableQueue | undefined, maxAttempts: number, defaultTimeout: number | undefined, taskRegistry: TaskRegistry, auditLogger: AuditLogger, scheduleManager: ScheduleManager, callbacks: PollingManagerCallbacks);
|
|
43
|
+
start(): void;
|
|
44
|
+
stop(): Promise<void>;
|
|
45
|
+
private poll;
|
|
46
|
+
/** @internal - public for testing */
|
|
47
|
+
handleTimer(timer: Timer): Promise<void>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { IDurableStore } from "../interfaces/store";
|
|
2
|
+
import type { DurableTask, ScheduleOptions } from "../interfaces/service";
|
|
3
|
+
import { type Schedule } from "../types";
|
|
4
|
+
import type { TaskRegistry } from "./TaskRegistry";
|
|
5
|
+
/**
|
|
6
|
+
* Creates and maintains durable schedules.
|
|
7
|
+
*
|
|
8
|
+
* A schedule is persisted in the store and translated into durable timers that
|
|
9
|
+
* `PollingManager` will later process to kick off executions. This keeps scheduling
|
|
10
|
+
* crash-safe and horizontally scalable: schedules aren't owned by in-memory timers.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ScheduleManager {
|
|
13
|
+
private readonly store;
|
|
14
|
+
private readonly taskRegistry;
|
|
15
|
+
constructor(store: IDurableStore, taskRegistry: TaskRegistry);
|
|
16
|
+
ensureSchedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions & {
|
|
17
|
+
id: string;
|
|
18
|
+
}): Promise<string>;
|
|
19
|
+
schedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions): Promise<string>;
|
|
20
|
+
reschedule(schedule: Schedule, options?: {
|
|
21
|
+
lastRunAt?: Date;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
pause(id: string): Promise<void>;
|
|
24
|
+
resume(id: string): Promise<void>;
|
|
25
|
+
get(id: string): Promise<Schedule | null>;
|
|
26
|
+
list(): Promise<Schedule[]>;
|
|
27
|
+
update(id: string, updates: {
|
|
28
|
+
cron?: string;
|
|
29
|
+
interval?: number;
|
|
30
|
+
input?: unknown;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
remove(id: string): Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IDurableStore } from "../interfaces/store";
|
|
2
|
+
import type { IDurableQueue } from "../interfaces/queue";
|
|
3
|
+
import type { IEventDefinition } from "../../../../types/event";
|
|
4
|
+
import type { AuditLogger } from "./AuditLogger";
|
|
5
|
+
export interface SignalHandlerCallbacks {
|
|
6
|
+
processExecution: (executionId: string) => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Delivers external signals to durable executions waiting in `DurableContext.waitForSignal()`.
|
|
10
|
+
*
|
|
11
|
+
* Signal delivery is store-centric:
|
|
12
|
+
* - find the earliest waiting signal step for the given `signalId`
|
|
13
|
+
* - persist a "completed" signal payload into the step result
|
|
14
|
+
* - optionally clean up timeout timers
|
|
15
|
+
* - trigger execution resumption (queue message or direct processing)
|
|
16
|
+
*/
|
|
17
|
+
export declare class SignalHandler {
|
|
18
|
+
private readonly store;
|
|
19
|
+
private readonly auditLogger;
|
|
20
|
+
private readonly queue;
|
|
21
|
+
private readonly maxAttempts;
|
|
22
|
+
private readonly callbacks;
|
|
23
|
+
constructor(store: IDurableStore, auditLogger: AuditLogger, queue: IDurableQueue | undefined, maxAttempts: number, callbacks: SignalHandlerCallbacks);
|
|
24
|
+
signal<TPayload>(executionId: string, signal: IEventDefinition<TPayload>, payload: TPayload): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DurableTask } from "../interfaces/service";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory durable task registry.
|
|
4
|
+
*
|
|
5
|
+
* Durable executions persist only a `taskId` in the store, so the runtime needs a way
|
|
6
|
+
* to resolve `taskId -> DurableTask` when resuming. This registry holds tasks that
|
|
7
|
+
* were registered on the current process and optionally delegates to an external
|
|
8
|
+
* resolver for tasks defined elsewhere (useful for modular apps).
|
|
9
|
+
*/
|
|
10
|
+
export declare class TaskRegistry {
|
|
11
|
+
private readonly externalResolver?;
|
|
12
|
+
private readonly tasks;
|
|
13
|
+
constructor(externalResolver?: ((taskId: string) => DurableTask<any, any> | undefined) | undefined);
|
|
14
|
+
register<TInput, TResult>(task: DurableTask<TInput, TResult>): void;
|
|
15
|
+
find(taskId: string): DurableTask<any, any> | undefined;
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IDurableStore } from "../interfaces/store";
|
|
2
|
+
import type { IEventBus } from "../interfaces/bus";
|
|
3
|
+
export interface WaitConfig {
|
|
4
|
+
defaultTimeout?: number;
|
|
5
|
+
defaultPollIntervalMs?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Waits for an execution to reach a terminal state and returns/throws accordingly.
|
|
9
|
+
*
|
|
10
|
+
* Strategy:
|
|
11
|
+
* - if an event bus is configured, subscribe to `execution:<executionId>` for low-latency completion
|
|
12
|
+
* - otherwise (or on bus issues) fall back to polling the store
|
|
13
|
+
*
|
|
14
|
+
* The durable store remains the source of truth; this manager is purely a convenience layer
|
|
15
|
+
* for callers that want `await durable.wait(...)` / `await durable.execute(...)`.
|
|
16
|
+
*/
|
|
17
|
+
export declare class WaitManager {
|
|
18
|
+
private readonly store;
|
|
19
|
+
private readonly eventBus?;
|
|
20
|
+
private readonly config?;
|
|
21
|
+
constructor(store: IDurableStore, eventBus?: IEventBus | undefined, config?: WaitConfig | undefined);
|
|
22
|
+
waitForResult<TResult>(executionId: string, options?: {
|
|
23
|
+
timeout?: number;
|
|
24
|
+
waitPollIntervalMs?: number;
|
|
25
|
+
}): Promise<TResult>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { TaskRegistry } from "./TaskRegistry";
|
|
2
|
+
export { AuditLogger, type AuditConfig } from "./AuditLogger";
|
|
3
|
+
export { WaitManager, type WaitConfig } from "./WaitManager";
|
|
4
|
+
export { ScheduleManager } from "./ScheduleManager";
|
|
5
|
+
export { SignalHandler, type SignalHandlerCallbacks } from "./SignalHandler";
|
|
6
|
+
export { ExecutionManager, type ExecutionManagerConfig, } from "./ExecutionManager";
|
|
7
|
+
export { PollingManager, type PollingConfig, type PollingManagerCallbacks, } from "./PollingManager";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RunnerDurableRuntimeConfig } from "./createRunnerDurableRuntime";
|
|
2
|
+
export type DurableResourceRuntimeConfig = RunnerDurableRuntimeConfig;
|
|
3
|
+
/**
|
|
4
|
+
* A reusable durable resource template.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* - `const durable = durableResource.fork("app.durable");`
|
|
8
|
+
* - Register it via `durable.with({ store, queue, eventBus, ... })`
|
|
9
|
+
*/
|
|
10
|
+
export declare const durableResource: import("../..").IResource<RunnerDurableRuntimeConfig, Promise<import("./DurableResource").DurableResource>, {
|
|
11
|
+
taskRunner: import("../..").IResource<void, Promise<import("../..").TaskRunner>, {}, any, any, import("../..").TagType[], import("../..").ResourceMiddlewareAttachmentType[]>;
|
|
12
|
+
eventManager: import("../..").IResource<void, Promise<import("../..").EventManager>, {}, any, any, import("../..").TagType[], import("../..").ResourceMiddlewareAttachmentType[]>;
|
|
13
|
+
runnerStore: import("../..").IResource<void, Promise<import("../..").Store>, {}, any, any, import("../..").TagType[], import("../..").ResourceMiddlewareAttachmentType[]>;
|
|
14
|
+
}, any, import("../..").IResourceMeta, import("../..").TagType[], import("../..").ResourceMiddlewareAttachmentType[]>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export declare const ExecutionStatus: {
|
|
2
|
+
readonly Pending: "pending";
|
|
3
|
+
readonly Running: "running";
|
|
4
|
+
readonly Retrying: "retrying";
|
|
5
|
+
readonly Sleeping: "sleeping";
|
|
6
|
+
readonly Completed: "completed";
|
|
7
|
+
readonly CompensationFailed: "compensation_failed";
|
|
8
|
+
readonly Failed: "failed";
|
|
9
|
+
readonly Cancelled: "cancelled";
|
|
10
|
+
};
|
|
11
|
+
export type ExecutionStatus = (typeof ExecutionStatus)[keyof typeof ExecutionStatus];
|
|
12
|
+
export interface Execution<TInput = unknown, TResult = unknown> {
|
|
13
|
+
id: string;
|
|
14
|
+
taskId: string;
|
|
15
|
+
input: TInput | undefined;
|
|
16
|
+
status: ExecutionStatus;
|
|
17
|
+
result?: TResult;
|
|
18
|
+
error?: {
|
|
19
|
+
message: string;
|
|
20
|
+
stack?: string;
|
|
21
|
+
};
|
|
22
|
+
/** Optional cancellation metadata (cooperative cancellation). */
|
|
23
|
+
cancelledAt?: Date;
|
|
24
|
+
cancelRequestedAt?: Date;
|
|
25
|
+
attempt: number;
|
|
26
|
+
maxAttempts: number;
|
|
27
|
+
timeout?: number;
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
updatedAt: Date;
|
|
30
|
+
completedAt?: Date;
|
|
31
|
+
}
|
|
32
|
+
export interface StepResult<T = unknown> {
|
|
33
|
+
executionId: string;
|
|
34
|
+
stepId: string;
|
|
35
|
+
result: T;
|
|
36
|
+
completedAt: Date;
|
|
37
|
+
}
|
|
38
|
+
export declare const TimerType: {
|
|
39
|
+
readonly Sleep: "sleep";
|
|
40
|
+
readonly Timeout: "timeout";
|
|
41
|
+
readonly Scheduled: "scheduled";
|
|
42
|
+
readonly Cron: "cron";
|
|
43
|
+
readonly Retry: "retry";
|
|
44
|
+
readonly SignalTimeout: "signal_timeout";
|
|
45
|
+
};
|
|
46
|
+
export type TimerType = (typeof TimerType)[keyof typeof TimerType];
|
|
47
|
+
export declare const TimerStatus: {
|
|
48
|
+
readonly Pending: "pending";
|
|
49
|
+
readonly Fired: "fired";
|
|
50
|
+
};
|
|
51
|
+
export type TimerStatus = (typeof TimerStatus)[keyof typeof TimerStatus];
|
|
52
|
+
export interface Timer {
|
|
53
|
+
id: string;
|
|
54
|
+
executionId?: string;
|
|
55
|
+
stepId?: string;
|
|
56
|
+
scheduleId?: string;
|
|
57
|
+
taskId?: string;
|
|
58
|
+
input?: unknown;
|
|
59
|
+
type: TimerType;
|
|
60
|
+
fireAt: Date;
|
|
61
|
+
status: TimerStatus;
|
|
62
|
+
}
|
|
63
|
+
export declare const ScheduleType: {
|
|
64
|
+
readonly Cron: "cron";
|
|
65
|
+
readonly Interval: "interval";
|
|
66
|
+
};
|
|
67
|
+
export type ScheduleType = (typeof ScheduleType)[keyof typeof ScheduleType];
|
|
68
|
+
export declare const ScheduleStatus: {
|
|
69
|
+
readonly Active: "active";
|
|
70
|
+
readonly Paused: "paused";
|
|
71
|
+
};
|
|
72
|
+
export type ScheduleStatus = (typeof ScheduleStatus)[keyof typeof ScheduleStatus];
|
|
73
|
+
export interface Schedule<TInput = unknown> {
|
|
74
|
+
id: string;
|
|
75
|
+
taskId: string;
|
|
76
|
+
type: ScheduleType;
|
|
77
|
+
pattern: string;
|
|
78
|
+
input: TInput | undefined;
|
|
79
|
+
status: ScheduleStatus;
|
|
80
|
+
lastRun?: Date;
|
|
81
|
+
nextRun?: Date;
|
|
82
|
+
createdAt: Date;
|
|
83
|
+
updatedAt: Date;
|
|
84
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
2
|
+
export declare function sleepMs(ms: number): Promise<void>;
|
|
3
|
+
export declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, message: string): Promise<T>;
|
|
4
|
+
export declare function createExecutionId(): string;
|
|
5
|
+
export declare function parseSignalState(value: unknown): {
|
|
6
|
+
state: "waiting" | "completed" | "timed_out";
|
|
7
|
+
timerId?: string;
|
|
8
|
+
} | null;
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown to consumers waiting on an execution (`DurableService.wait/execute*`).
|
|
11
|
+
*
|
|
12
|
+
* Distinguishes durable execution failures/timeouts/cancellations from ordinary
|
|
13
|
+
* task errors by carrying execution metadata and a (serialized) cause payload.
|
|
14
|
+
* `WaitManager` is the primary producer of this error.
|
|
15
|
+
*/
|
|
16
|
+
export declare class DurableExecutionError extends Error {
|
|
17
|
+
readonly executionId: string;
|
|
18
|
+
readonly taskId: string;
|
|
19
|
+
readonly attempt: number;
|
|
20
|
+
readonly causeInfo?: {
|
|
21
|
+
message: string;
|
|
22
|
+
stack?: string;
|
|
23
|
+
} | undefined;
|
|
24
|
+
constructor(message: string, executionId: string, taskId: string, attempt: number, causeInfo?: {
|
|
25
|
+
message: string;
|
|
26
|
+
stack?: string;
|
|
27
|
+
} | undefined);
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Request, Router } from "express";
|
|
2
|
+
import { IDurableService } from "../core/interfaces/service";
|
|
3
|
+
import { DurableOperator } from "../core/DurableOperator";
|
|
4
|
+
export type DashboardMiddlewareOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Override where the dashboard UI is served from.
|
|
7
|
+
* Useful for tests or custom deployments.
|
|
8
|
+
*/
|
|
9
|
+
uiDistPath?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Authorization hook for operator actions (retry/skip/force/edit).
|
|
12
|
+
* Return true to allow, false to deny.
|
|
13
|
+
*/
|
|
14
|
+
operatorAuth?: (req: Request) => boolean | Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Opt out of operator auth checks (not recommended).
|
|
17
|
+
*/
|
|
18
|
+
dangerouslyAllowUnauthenticatedOperator?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare function createDashboardMiddleware(_service: IDurableService, operator: DurableOperator, options?: DashboardMiddlewareOptions): Router;
|