@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
package/dist/node/node.d.mts
DELETED
|
@@ -1,4622 +0,0 @@
|
|
|
1
|
-
import * as lru_cache from 'lru-cache';
|
|
2
|
-
import { Readable } from 'stream';
|
|
3
|
-
export { Readable } from 'stream';
|
|
4
|
-
import * as http from 'http';
|
|
5
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
6
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
7
|
-
import { Request, Router } from 'express';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Type definitions for the Serializer class
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Definition for a custom type that can be serialized/deserialized
|
|
14
|
-
*/
|
|
15
|
-
interface TypeDefinition<TInstance = unknown, TSerialized = unknown> {
|
|
16
|
-
/** Unique identifier for the type */
|
|
17
|
-
id: string;
|
|
18
|
-
/** Predicate function to check if an object matches this type */
|
|
19
|
-
is: (obj: unknown) => obj is TInstance;
|
|
20
|
-
/** Function to serialize the object */
|
|
21
|
-
serialize: (obj: TInstance) => TSerialized;
|
|
22
|
-
/** Function to deserialize the data back to the original object */
|
|
23
|
-
deserialize: (data: TSerialized) => TInstance;
|
|
24
|
-
/** Optional factory used to create a placeholder during deserialization */
|
|
25
|
-
create?: () => TInstance;
|
|
26
|
-
/** Serialization strategy: 'value' (inline, no identity) or 'ref' (graph node, identity preserved). Default: 'ref' */
|
|
27
|
-
strategy?: "value" | "ref";
|
|
28
|
-
}
|
|
29
|
-
/** Reference to another object in the serialization */
|
|
30
|
-
interface ObjectReference {
|
|
31
|
-
/** Reference to object ID */
|
|
32
|
-
__ref: string;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Discriminated union describing the serialized graph payload.
|
|
36
|
-
* Each node captures either an array, plain object, or typed payload.
|
|
37
|
-
*/
|
|
38
|
-
type SerializedNode = {
|
|
39
|
-
kind: "array";
|
|
40
|
-
value: SerializedValue[];
|
|
41
|
-
} | {
|
|
42
|
-
kind: "object";
|
|
43
|
-
value: Record<string, SerializedValue>;
|
|
44
|
-
} | {
|
|
45
|
-
kind: "type";
|
|
46
|
-
type: string;
|
|
47
|
-
value: SerializedValue;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Serialization context for tracking object references
|
|
51
|
-
*/
|
|
52
|
-
interface SerializationContext {
|
|
53
|
-
/** Map of objects to their IDs */
|
|
54
|
-
objectIds: WeakMap<object, string>;
|
|
55
|
-
/** Counter for generating unique IDs */
|
|
56
|
-
idCounter: number;
|
|
57
|
-
/** Number of graph nodes recorded */
|
|
58
|
-
nodeCount: number;
|
|
59
|
-
/** Nodes collected during serialization (id -> serialized node) */
|
|
60
|
-
nodes: Record<string, SerializedNode>;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Deserialization context used when materialising a graph payload.
|
|
64
|
-
*/
|
|
65
|
-
interface DeserializationContext {
|
|
66
|
-
nodes: Record<string, SerializedNode>;
|
|
67
|
-
resolved: Map<string, unknown>;
|
|
68
|
-
resolving: Set<string>;
|
|
69
|
-
/**
|
|
70
|
-
* Tracks reference ids that were requested while still being resolved.
|
|
71
|
-
* Used to detect circular references that rely on placeholders.
|
|
72
|
-
*/
|
|
73
|
-
resolvingRefs: Set<string>;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Union type for serialized values
|
|
77
|
-
*/
|
|
78
|
-
type JsonPrimitive = string | number | boolean | null;
|
|
79
|
-
interface SerializedTypeRecord {
|
|
80
|
-
__type: string;
|
|
81
|
-
value: SerializedValue;
|
|
82
|
-
}
|
|
83
|
-
type SerializedValue = JsonPrimitive | ObjectReference | SerializedTypeRecord | SerializedValue[] | {
|
|
84
|
-
[key: string]: SerializedValue;
|
|
85
|
-
};
|
|
86
|
-
declare enum SymbolPolicy {
|
|
87
|
-
AllowAll = "AllowAll",
|
|
88
|
-
WellKnownOnly = "WellKnownOnly",
|
|
89
|
-
Disabled = "Disabled"
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Main serializer options
|
|
93
|
-
*/
|
|
94
|
-
interface SerializerOptions {
|
|
95
|
-
/** Whether to pretty-print JSON (for debugging) */
|
|
96
|
-
pretty?: boolean;
|
|
97
|
-
/** Maximum recursion depth allowed during serialize/deserialize */
|
|
98
|
-
maxDepth?: number;
|
|
99
|
-
/** Restrict deserialization to this list of type IDs */
|
|
100
|
-
allowedTypes?: readonly string[];
|
|
101
|
-
/** Controls which Symbol payloads may be deserialized */
|
|
102
|
-
symbolPolicy?: SymbolPolicy;
|
|
103
|
-
/** Maximum accepted RegExp pattern length during deserialization */
|
|
104
|
-
maxRegExpPatternLength?: number;
|
|
105
|
-
/** Allow RegExp patterns that fail the safety heuristic */
|
|
106
|
-
allowUnsafeRegExp?: boolean;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Minimal serializer contract used across transports and persistence.
|
|
110
|
-
* Implementations must be able to round-trip JSON-compatible payloads and
|
|
111
|
-
* should support custom value types via `addType`.
|
|
112
|
-
*/
|
|
113
|
-
interface SerializerLike {
|
|
114
|
-
stringify(value: unknown): string;
|
|
115
|
-
parse<T = unknown>(text: string): T;
|
|
116
|
-
addType?<TJson = unknown, TInstance = unknown>(name: string, factory: (json: TJson) => TInstance): void;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Graph-aware serializer/deserializer with circular reference
|
|
121
|
-
* handling and pluggable type support.
|
|
122
|
-
*
|
|
123
|
-
* Internal protocol reference: `readmes/SERIALIZER_PROTOCOL.md`.
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
|
-
declare class Serializer {
|
|
127
|
-
/** Type registry for managing custom types */
|
|
128
|
-
private readonly typeRegistry;
|
|
129
|
-
private readonly runtimeOptions;
|
|
130
|
-
/** JSON indentation width when pretty printing is enabled */
|
|
131
|
-
private readonly indent;
|
|
132
|
-
/** Maximum recursion depth allowed */
|
|
133
|
-
private readonly maxDepth;
|
|
134
|
-
/** Maximum allowed RegExp pattern length during deserialization */
|
|
135
|
-
private readonly maxRegExpPatternLength;
|
|
136
|
-
/** Allow RegExp patterns that fail the safety heuristic */
|
|
137
|
-
private readonly allowUnsafeRegExp;
|
|
138
|
-
/** Disallowed keys that can lead to prototype pollution */
|
|
139
|
-
private readonly unsafeKeys;
|
|
140
|
-
constructor(options?: SerializerOptions);
|
|
141
|
-
/**
|
|
142
|
-
* Alias of `serialize()` to match the historical tunnel serializer surface.
|
|
143
|
-
*/
|
|
144
|
-
stringify<T>(value: T): string;
|
|
145
|
-
/**
|
|
146
|
-
* Alias of `deserialize()` to match the historical tunnel serializer surface.
|
|
147
|
-
*/
|
|
148
|
-
parse<T = unknown>(payload: string): T;
|
|
149
|
-
/**
|
|
150
|
-
* Serialize an arbitrary value into a JSON string.
|
|
151
|
-
*/
|
|
152
|
-
serialize<T>(value: T, context?: SerializationContext): string;
|
|
153
|
-
/**
|
|
154
|
-
* Deserialize a JSON string back to its original value.
|
|
155
|
-
*/
|
|
156
|
-
deserialize<T = unknown>(payload: string): T;
|
|
157
|
-
/**
|
|
158
|
-
* Register a custom type for serialization/deserialization.
|
|
159
|
-
*/
|
|
160
|
-
addType<TInstance, TSerialized>(typeDef: TypeDefinition<TInstance, TSerialized>): void;
|
|
161
|
-
addType<TJson = unknown, TInstance = unknown>(name: string, factory: (json: TJson) => TInstance): void;
|
|
162
|
-
/**
|
|
163
|
-
* @internal - Exposed for testing RegExp safety validation
|
|
164
|
-
*/
|
|
165
|
-
readonly isRegExpPatternSafe: (pattern: string) => boolean;
|
|
166
|
-
/**
|
|
167
|
-
* @internal - Exposed for testing quantifier detection
|
|
168
|
-
*/
|
|
169
|
-
readonly isQuantifierAt: (pattern: string, index: number) => boolean;
|
|
170
|
-
/**
|
|
171
|
-
* @internal - Exposed for testing quantifier character detection
|
|
172
|
-
*/
|
|
173
|
-
readonly isQuantifierChar: (char: string, pattern: string, index: number) => boolean;
|
|
174
|
-
/**
|
|
175
|
-
* @internal - Exposed for testing bounded quantifier detection
|
|
176
|
-
*/
|
|
177
|
-
readonly isBoundedQuantifier: (pattern: string, index: number) => boolean;
|
|
178
|
-
/**
|
|
179
|
-
* @internal - Exposed for test compatibility
|
|
180
|
-
*/
|
|
181
|
-
toNodeRecord(nodes: Record<string, SerializedNode>): Record<string, SerializedNode>;
|
|
182
|
-
/**
|
|
183
|
-
* @internal - Exposed for test compatibility
|
|
184
|
-
*/
|
|
185
|
-
deserializeValue(value: SerializedValue, context: DeserializationContext, depth?: number): unknown;
|
|
186
|
-
/**
|
|
187
|
-
* @internal - Exposed for test compatibility
|
|
188
|
-
*/
|
|
189
|
-
resolveReference(id: string, context: DeserializationContext, depth?: number): unknown;
|
|
190
|
-
/**
|
|
191
|
-
* @internal - Exposed for test compatibility
|
|
192
|
-
*/
|
|
193
|
-
mergePlaceholder(placeholder: unknown, result: unknown): unknown;
|
|
194
|
-
/**
|
|
195
|
-
* @internal - Exposed for test compatibility
|
|
196
|
-
*/
|
|
197
|
-
isSerializedTypeRecord(value: unknown): value is {
|
|
198
|
-
__type: string;
|
|
199
|
-
value: unknown;
|
|
200
|
-
};
|
|
201
|
-
private jsonStringify;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Main export module for the Serializer
|
|
206
|
-
*/
|
|
207
|
-
|
|
208
|
-
declare function getDefaultSerializer(): Serializer;
|
|
209
|
-
|
|
210
|
-
declare const CONTRACT: unique symbol;
|
|
211
|
-
type CONTRACT = typeof CONTRACT;
|
|
212
|
-
interface IContractable<TConfig = any, TInput = void, TOutput = void> {
|
|
213
|
-
readonly __containsContract: true;
|
|
214
|
-
readonly [CONTRACT]: {
|
|
215
|
-
config: TConfig;
|
|
216
|
-
input: TInput;
|
|
217
|
-
output: TOutput;
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
type NonVoid<T> = [T] extends [void] ? never : T;
|
|
221
|
-
type IsTuple<T extends readonly unknown[]> = number extends T["length"] ? false : true;
|
|
222
|
-
type UnionToIntersection$1<U> = (U extends any ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
|
|
223
|
-
type Simplify<T> = {
|
|
224
|
-
[K in keyof T]: T[K];
|
|
225
|
-
} & {};
|
|
226
|
-
type IsUnknown<T> = unknown extends T ? [T] extends [unknown] ? true : false : false;
|
|
227
|
-
type UnknownToNever<T> = IsUnknown<T> extends true ? never : T;
|
|
228
|
-
type ExtractContractOf<T, Kind extends "input" | "output"> = T extends IContractable<any, infer I, infer O> ? UnknownToNever<Kind extends "input" ? NonVoid<I> : NonVoid<O>> : never;
|
|
229
|
-
type FilterContractsKind<TItems extends readonly unknown[], Kind extends "input" | "output", Acc extends readonly unknown[] = []> = TItems extends readonly [infer H, ...infer R] ? ExtractContractOf<H, Kind> extends never ? FilterContractsKind<R, Kind, Acc> : FilterContractsKind<R, Kind, [...Acc, ExtractContractOf<H, Kind>]> : Acc;
|
|
230
|
-
type ExtractContractsFromCollection<TItems extends readonly unknown[], Kind extends "input" | "output"> = IsTuple<TItems> extends true ? FilterContractsKind<TItems, Kind> : Array<ExtractContractOf<TItems[number], Kind>>;
|
|
231
|
-
type ExtractInputTypeFromContracts<TItems extends readonly unknown[]> = ExtractContractsFromCollection<TItems, "input">;
|
|
232
|
-
type ExtractOutputTypeFromContracts<TItems extends readonly unknown[]> = ExtractContractsFromCollection<TItems, "output">;
|
|
233
|
-
type ContractsUnionInputs<TItems extends readonly unknown[]> = ExtractInputTypeFromContracts<TItems> extends readonly (infer U)[] ? U : never;
|
|
234
|
-
type ContractsUnionOutputs<TItems extends readonly unknown[]> = ExtractOutputTypeFromContracts<TItems> extends readonly (infer U)[] ? U : never;
|
|
235
|
-
type ContractsIntersectionInputs<TItems extends readonly unknown[]> = UnionToIntersection$1<ContractsUnionInputs<TItems>>;
|
|
236
|
-
type ContractsIntersectionOutputs<TItems extends readonly unknown[]> = UnionToIntersection$1<ContractsUnionOutputs<TItems>>;
|
|
237
|
-
type HasInputContracts<TItems extends readonly unknown[]> = [
|
|
238
|
-
ContractsUnionInputs<TItems>
|
|
239
|
-
] extends [never] ? false : true;
|
|
240
|
-
type HasOutputContracts<TItems extends readonly unknown[]> = [
|
|
241
|
-
ContractsUnionOutputs<TItems>
|
|
242
|
-
] extends [never] ? false : true;
|
|
243
|
-
type IsNever<T> = [T] extends [never] ? true : false;
|
|
244
|
-
type KeysWithNever<T> = T extends object ? {
|
|
245
|
-
[K in keyof T]-?: [T[K]] extends [never] ? K : never;
|
|
246
|
-
}[keyof T] : never;
|
|
247
|
-
type HasNeverProperty<T> = KeysWithNever<T> extends never ? false : true;
|
|
248
|
-
type IsImpossibleIntersection<T> = IsNever<T> extends true ? true : HasNeverProperty<T> extends true ? true : false;
|
|
249
|
-
type InputContractViolationError<TItems extends readonly unknown[], TActual> = {
|
|
250
|
-
message: "Value does not satisfy all input contracts";
|
|
251
|
-
expected: Simplify<ContractsIntersectionInputs<TItems>>;
|
|
252
|
-
received: TActual;
|
|
253
|
-
};
|
|
254
|
-
type OutputContractViolationError<TItems extends readonly unknown[], TActual> = {
|
|
255
|
-
message: "Value does not satisfy all output contracts";
|
|
256
|
-
expected: Simplify<ContractsIntersectionOutputs<TItems>>;
|
|
257
|
-
received: TActual;
|
|
258
|
-
};
|
|
259
|
-
type EnsureInputSatisfiesContracts<TItems extends readonly unknown[], TValue> = [ContractsUnionInputs<TItems>] extends [never] ? TValue : TValue extends Promise<infer U> ? Promise<U extends ContractsIntersectionInputs<TItems> ? U : InputContractViolationError<TItems, U>> : TValue extends ContractsIntersectionInputs<TItems> ? TValue : InputContractViolationError<TItems, TValue>;
|
|
260
|
-
type EnsureOutputSatisfiesContracts<TItems extends readonly unknown[], TResponse> = [ContractsUnionOutputs<TItems>] extends [never] ? TResponse : TResponse extends Promise<infer U> ? Promise<U extends ContractsIntersectionOutputs<TItems> ? U : OutputContractViolationError<TItems, U>> : TResponse extends ContractsIntersectionOutputs<TItems> ? TResponse : OutputContractViolationError<TItems, TResponse>;
|
|
261
|
-
type InferInputOrViolationFromContracts<TItems extends readonly unknown[]> = HasInputContracts<TItems> extends false ? void : ContractsIntersectionInputs<TItems> extends infer I ? IsImpossibleIntersection<I> extends true ? InputContractViolationError<TItems, Simplify<I extends never ? never : I>> : Simplify<I> : never;
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Common metadata you can attach to tasks/resources/events/middleware.
|
|
265
|
-
* Useful for docs, filtering and middleware decisions.
|
|
266
|
-
*/
|
|
267
|
-
interface IMeta {
|
|
268
|
-
title?: string;
|
|
269
|
-
description?: string;
|
|
270
|
-
}
|
|
271
|
-
interface ITaskMeta extends IMeta {
|
|
272
|
-
}
|
|
273
|
-
interface IResourceMeta extends IMeta {
|
|
274
|
-
}
|
|
275
|
-
interface IEventMeta extends IMeta {
|
|
276
|
-
}
|
|
277
|
-
interface IMiddlewareMeta extends IMeta {
|
|
278
|
-
}
|
|
279
|
-
interface ITagMeta extends IMeta {
|
|
280
|
-
}
|
|
281
|
-
interface IErrorMeta extends IMeta {
|
|
282
|
-
}
|
|
283
|
-
interface IAsyncContextMeta extends IMeta {
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
interface ITaggable {
|
|
287
|
-
tags: TagType[];
|
|
288
|
-
}
|
|
289
|
-
interface ITagDefinition<TConfig = void, _TEnforceInputContract = void, _TEnforceOutputContract = void> {
|
|
290
|
-
id: string;
|
|
291
|
-
meta?: ITagMeta;
|
|
292
|
-
configSchema?: IValidationSchema<TConfig>;
|
|
293
|
-
/**
|
|
294
|
-
* Utilizing config at definition level stores its defaults
|
|
295
|
-
*/
|
|
296
|
-
config?: TConfig;
|
|
297
|
-
}
|
|
298
|
-
interface ITag<TConfig = void, TEnforceInputContract = void, TEnforceOutputContract = void> extends ITagDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract>, IContractable<TConfig, TEnforceInputContract, TEnforceOutputContract> {
|
|
299
|
-
/**
|
|
300
|
-
* A special validation property.
|
|
301
|
-
* It resolves to `true` if TConfig only has optional keys, otherwise `false`.
|
|
302
|
-
*/
|
|
303
|
-
readonly __configHasOnlyOptionalKeys: RequiredKeys<TConfig> extends never ? true : false;
|
|
304
|
-
config?: TConfig;
|
|
305
|
-
/**
|
|
306
|
-
* Checks if the tag exists in a taggable or a list of tags.
|
|
307
|
-
*/
|
|
308
|
-
exists(target: ITaggable | TagType[]): boolean;
|
|
309
|
-
/**
|
|
310
|
-
* Creates a configured instance of the tag.
|
|
311
|
-
*/
|
|
312
|
-
with(config: TConfig): ITagConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract>;
|
|
313
|
-
/**
|
|
314
|
-
* Extracts the configuration of the tag from a taggable or a list of tags.
|
|
315
|
-
*/
|
|
316
|
-
extract(target: ITaggable | TagType[]): TConfig | undefined;
|
|
317
|
-
[symbolFilePath]: string;
|
|
318
|
-
[symbolTag]: true;
|
|
319
|
-
}
|
|
320
|
-
type ITagWithOptionalConfig<_TValue, TEnforceInputContract, TEnforceOutputContract> = ITag<any, TEnforceInputContract, TEnforceOutputContract> & {
|
|
321
|
-
readonly __configHasOnlyOptionalKeys: true;
|
|
322
|
-
};
|
|
323
|
-
interface ITagConfigured<TConfig = void, TEnforceInputContract = void, TEnforceOutputContract = void> extends ITag<TConfig, TEnforceInputContract, TEnforceOutputContract> {
|
|
324
|
-
[symbolTagConfigured]: true;
|
|
325
|
-
config: TConfig;
|
|
326
|
-
}
|
|
327
|
-
type TagType = ITag<void, any, any> | ITagWithOptionalConfig<any, any, any> | ITagConfigured<any, any, any>;
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Internal brand symbols used to tag created objects at runtime and help with
|
|
331
|
-
* type‑narrowing. Prefer the `isTask`/`isResource`/`isEvent`/`isMiddleware`
|
|
332
|
-
* helpers instead of touching these directly.
|
|
333
|
-
* @internal
|
|
334
|
-
*/
|
|
335
|
-
declare const symbolTask: unique symbol;
|
|
336
|
-
/** Marks a task as a phantom task (no-op run; meant to be tunneled/routed). */
|
|
337
|
-
declare const symbolPhantomTask: unique symbol;
|
|
338
|
-
declare const symbolResource: unique symbol;
|
|
339
|
-
/** @internal Marks forked resources and records fork provenance */
|
|
340
|
-
declare const symbolResourceForkedFrom: unique symbol;
|
|
341
|
-
declare const symbolResourceWithConfig: unique symbol;
|
|
342
|
-
declare const symbolEvent: unique symbol;
|
|
343
|
-
/** @internal Marks an error helper definition */
|
|
344
|
-
declare const symbolError: unique symbol;
|
|
345
|
-
declare const symbolMiddleware: unique symbol;
|
|
346
|
-
/** New brands for separated middleware kinds */
|
|
347
|
-
declare const symbolTaskMiddleware: unique symbol;
|
|
348
|
-
declare const symbolResourceMiddleware: unique symbol;
|
|
349
|
-
declare const symbolMiddlewareConfigured: unique symbol;
|
|
350
|
-
/** Records which tunnel resource owns the task patching (exclusivity). */
|
|
351
|
-
declare const symbolTunneledBy: unique symbol;
|
|
352
|
-
/** @internal Marks hook definitions (event listeners without middleware) */
|
|
353
|
-
declare const symbolHook: unique symbol;
|
|
354
|
-
/** @internal Marks a tag definition */
|
|
355
|
-
declare const symbolTag: unique symbol;
|
|
356
|
-
declare const symbolTagConfigured: unique symbol;
|
|
357
|
-
/** @internal Marks an optional dependency wrapper */
|
|
358
|
-
declare const symbolOptionalDependency: unique symbol;
|
|
359
|
-
/** @internal Path to aid anonymous id generation and error messages */
|
|
360
|
-
declare const symbolFilePath: unique symbol;
|
|
361
|
-
/** @internal Marks an async context definition */
|
|
362
|
-
declare const symbolAsyncContext: unique symbol;
|
|
363
|
-
|
|
364
|
-
interface IResourceMiddlewareDefinition<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> {
|
|
365
|
-
id: string;
|
|
366
|
-
/** Static or lazy dependency map. */
|
|
367
|
-
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
368
|
-
/**
|
|
369
|
-
* Optional validation schema for runtime config validation.
|
|
370
|
-
* When provided, middleware config will be validated when .with() is called.
|
|
371
|
-
*/
|
|
372
|
-
configSchema?: IValidationSchema<TConfig>;
|
|
373
|
-
/**
|
|
374
|
-
* The middleware body, called with resource execution input.
|
|
375
|
-
*/
|
|
376
|
-
run: (input: IResourceMiddlewareExecutionInput<TEnforceInputContract extends void ? any : TEnforceInputContract, TEnforceOutputContract extends void ? any : TEnforceOutputContract>, dependencies: DependencyValuesType<TDependencies>, config: TConfig) => Promise<any>;
|
|
377
|
-
meta?: IMiddlewareMeta;
|
|
378
|
-
tags?: TagType[];
|
|
379
|
-
everywhere?: boolean | ((resource: IResource<any, any, any, any, any>) => boolean);
|
|
380
|
-
}
|
|
381
|
-
interface IResourceMiddleware<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends IResourceMiddlewareDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>, IContractable<TConfig, TEnforceInputContract, TEnforceOutputContract> {
|
|
382
|
-
[symbolResourceMiddleware]: true;
|
|
383
|
-
id: string;
|
|
384
|
-
dependencies: TDependencies | ((config: TConfig) => TDependencies);
|
|
385
|
-
/** Current configuration object (empty by default). */
|
|
386
|
-
config: TConfig;
|
|
387
|
-
/** Configure the middleware and return a marked, configured instance. */
|
|
388
|
-
with: (config: TConfig) => IResourceMiddlewareConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
389
|
-
[symbolFilePath]: string;
|
|
390
|
-
tags: TagType[];
|
|
391
|
-
}
|
|
392
|
-
interface IResourceMiddlewareConfigured<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends IResourceMiddleware<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies> {
|
|
393
|
-
[symbolMiddlewareConfigured]: true;
|
|
394
|
-
}
|
|
395
|
-
interface IResourceMiddlewareExecutionInput<TResourceConfig = any, TResourceOutput = any> {
|
|
396
|
-
/** Resource hook */
|
|
397
|
-
resource: {
|
|
398
|
-
definition: IResource<TResourceConfig, any, any, any, any>;
|
|
399
|
-
config: TResourceConfig;
|
|
400
|
-
};
|
|
401
|
-
next: (resourceConfig?: TResourceConfig) => Promise<TResourceOutput>;
|
|
402
|
-
}
|
|
403
|
-
type ResourceMiddlewareAttachmentType = IResourceMiddleware<void, any, any, any> | IResourceMiddleware<{
|
|
404
|
-
[K in any]?: any;
|
|
405
|
-
}, any, any, any> | IResourceMiddlewareConfigured<any, any, any, any>;
|
|
406
|
-
|
|
407
|
-
type ErrorReference = string | IErrorHelper<any>;
|
|
408
|
-
type ThrowsList = ReadonlyArray<ErrorReference>;
|
|
409
|
-
interface IErrorDefinition<TData extends DefaultErrorType = DefaultErrorType> {
|
|
410
|
-
id: string;
|
|
411
|
-
serialize?: (data: TData) => string;
|
|
412
|
-
parse?: (data: string) => TData;
|
|
413
|
-
format?: (data: TData) => string;
|
|
414
|
-
/**
|
|
415
|
-
* Validate error data on throw(). If provided, data is parsed first.
|
|
416
|
-
*/
|
|
417
|
-
dataSchema?: IValidationSchema<TData>;
|
|
418
|
-
meta?: IErrorMeta;
|
|
419
|
-
}
|
|
420
|
-
interface IErrorDefinitionFinal<TData extends DefaultErrorType> extends IErrorDefinition<TData> {
|
|
421
|
-
format: (data: TData) => string;
|
|
422
|
-
}
|
|
423
|
-
type DefaultErrorType = Record<string, unknown>;
|
|
424
|
-
/**
|
|
425
|
-
* Runtime helper returned by defineError()/r.error().
|
|
426
|
-
* Contains helpers to throw typed errors and perform type-safe checks.
|
|
427
|
-
*/
|
|
428
|
-
interface IErrorHelper<TData extends DefaultErrorType = DefaultErrorType> {
|
|
429
|
-
/** Unique id for registration and DI */
|
|
430
|
-
id: string;
|
|
431
|
-
/** Throw a typed error with the given data */
|
|
432
|
-
throw(data: TData): never;
|
|
433
|
-
/** Type guard for checking if an unknown error is this error */
|
|
434
|
-
is(error: unknown): boolean;
|
|
435
|
-
/** Brand symbol for runtime detection */
|
|
436
|
-
[symbolError]: true;
|
|
437
|
-
/** Return an optional dependency wrapper for this error */
|
|
438
|
-
optional(): IOptionalDependency<IErrorHelper<TData>>;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
type ResourceForkRegisterMode = "keep" | "drop" | "deep";
|
|
442
|
-
interface ResourceForkOptions {
|
|
443
|
-
/**
|
|
444
|
-
* Control whether the fork keeps the base `register` list.
|
|
445
|
-
* - "keep" (default) keeps registration items
|
|
446
|
-
* - "drop" clears registration items
|
|
447
|
-
* - "deep" deep-forks registered resources with new ids (resource tree)
|
|
448
|
-
*/
|
|
449
|
-
register?: ResourceForkRegisterMode;
|
|
450
|
-
/**
|
|
451
|
-
* Used with `register: "deep"` to derive ids for deep-forked resources.
|
|
452
|
-
* Defaults to `(id) => \`\${newId}.\${id}\``.
|
|
453
|
-
*/
|
|
454
|
-
reId?: (id: string) => string;
|
|
455
|
-
}
|
|
456
|
-
interface ResourceForkInfo {
|
|
457
|
-
/** The id of the resource that was forked. */
|
|
458
|
-
readonly fromId: string;
|
|
459
|
-
/** Best-effort call-site file path for the fork operation. */
|
|
460
|
-
readonly forkedAtFilePath: string;
|
|
461
|
-
}
|
|
462
|
-
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
463
|
-
type IsUnspecified<T> = [T] extends [undefined] ? true : [T] extends [void] ? true : IsAny<T> extends true ? true : false;
|
|
464
|
-
interface IResourceDefinition<TConfig = any, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = {}, TContext = any, _THooks = any, _TRegisterableItems = any, TMeta extends IResourceMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[] = ResourceMiddlewareAttachmentType[]> {
|
|
465
|
-
/** Stable identifier. */
|
|
466
|
-
id: string;
|
|
467
|
-
/** Static or lazy dependency map. Receives `config` when provided. */
|
|
468
|
-
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
469
|
-
/**
|
|
470
|
-
* Register other registerables (resources/tasks/middleware/events). Accepts a
|
|
471
|
-
* static array or a function of `config` to support dynamic wiring.
|
|
472
|
-
*/
|
|
473
|
-
register?: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
474
|
-
/**
|
|
475
|
-
* Initialize and return the resource value. Called once during boot.
|
|
476
|
-
*/
|
|
477
|
-
init?: (config: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? IsUnspecified<TConfig> extends true ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : EnsureInputSatisfiesContracts<[...TTags, ...TMiddleware], TConfig> : TConfig, dependencies: ResourceDependencyValuesType<TDependencies>, context: TContext) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TValue> : TValue;
|
|
478
|
-
/**
|
|
479
|
-
* Optional validation schema for the resource's resolved value.
|
|
480
|
-
* When provided, the value will be validated immediately after `init` resolves,
|
|
481
|
-
* without considering middleware.
|
|
482
|
-
*/
|
|
483
|
-
resultSchema?: IValidationSchema<TValue extends Promise<infer U> ? U : TValue>;
|
|
484
|
-
/**
|
|
485
|
-
* Clean-up function for the resource. This is called when the resource is no longer needed.
|
|
486
|
-
*
|
|
487
|
-
* @param value The value of the resource (undefined if no init method)
|
|
488
|
-
* @param config The configuration it received
|
|
489
|
-
* @param dependencies The dependencies it needed
|
|
490
|
-
* @returns Promise<void>
|
|
491
|
-
*/
|
|
492
|
-
dispose?: (this: any, value: TValue extends Promise<infer U> ? U : TValue, config: TConfig, dependencies: ResourceDependencyValuesType<TDependencies>, context: TContext) => Promise<void>;
|
|
493
|
-
meta?: TMeta;
|
|
494
|
-
/**
|
|
495
|
-
* Declares which typed errors are part of this resource's contract.
|
|
496
|
-
*
|
|
497
|
-
* This is a declarative contract only:
|
|
498
|
-
* - It does not imply dependency injection
|
|
499
|
-
* - It does not enforce that only these errors can be thrown
|
|
500
|
-
*
|
|
501
|
-
* Use string ids or Error helpers.
|
|
502
|
-
*/
|
|
503
|
-
throws?: ThrowsList;
|
|
504
|
-
/**
|
|
505
|
-
* Optional validation schema for runtime config validation.
|
|
506
|
-
* When provided, resource config will be validated when .with() is called.
|
|
507
|
-
*/
|
|
508
|
-
configSchema?: IValidationSchema<TConfig>;
|
|
509
|
-
/**
|
|
510
|
-
* Safe overrides to swap behavior while preserving identities. See
|
|
511
|
-
* README: Overrides.
|
|
512
|
-
*/
|
|
513
|
-
overrides?: Array<OverridableElements>;
|
|
514
|
-
/** Middleware applied around init/dispose. */
|
|
515
|
-
middleware?: TMiddleware;
|
|
516
|
-
/**
|
|
517
|
-
* Create a private, mutable context shared between `init` and `dispose`.
|
|
518
|
-
*/
|
|
519
|
-
context?: () => TContext;
|
|
520
|
-
/**
|
|
521
|
-
* This is optional and used from an index resource to get the correct caller.
|
|
522
|
-
* This is the reason we allow it here as well.
|
|
523
|
-
*/
|
|
524
|
-
[symbolFilePath]?: string;
|
|
525
|
-
tags?: TTags;
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Helper alias describing the canonical resource init call signature.
|
|
529
|
-
* Shared with fluent builders to keep init typing consistent.
|
|
530
|
-
*/
|
|
531
|
-
type ResourceInitFn<TConfig, TValue extends Promise<any>, TDependencies extends DependencyMapType, TContext, TMeta extends IResourceMeta, TTags extends TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[]> = NonNullable<IResourceDefinition<TConfig, TValue, TDependencies, TContext, any, any, TMeta, TTags, TMiddleware>["init"]>;
|
|
532
|
-
interface IResource<TConfig = void, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = any, TContext = any, TMeta extends IResourceMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[] = ResourceMiddlewareAttachmentType[]> extends IResourceDefinition<TConfig, TValue, TDependencies, TContext, any, any, TMeta, TTags, TMiddleware> {
|
|
533
|
-
id: string;
|
|
534
|
-
with(config: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? IsUnspecified<TConfig> extends true ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : TConfig : TConfig): IResourceWithConfig<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
535
|
-
register: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
536
|
-
overrides: Array<OverridableElements>;
|
|
537
|
-
middleware: TMiddleware;
|
|
538
|
-
[symbolFilePath]: string;
|
|
539
|
-
[symbolResource]: true;
|
|
540
|
-
/** Present only on forked resources. */
|
|
541
|
-
[symbolResourceForkedFrom]?: ResourceForkInfo;
|
|
542
|
-
/** Normalized list of error ids declared via `throws`. */
|
|
543
|
-
throws?: readonly string[];
|
|
544
|
-
/** Return an optional dependency wrapper for this resource. */
|
|
545
|
-
optional: () => IOptionalDependency<IResource<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>>;
|
|
546
|
-
tags: TTags;
|
|
547
|
-
/**
|
|
548
|
-
* Create a new resource with a different id but the same definition.
|
|
549
|
-
* Useful for creating multiple instances of a "template" resource.
|
|
550
|
-
* The forked resource should be exported and used as a dependency.
|
|
551
|
-
*/
|
|
552
|
-
fork(newId: string, options?: ResourceForkOptions): IResource<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
553
|
-
}
|
|
554
|
-
interface IResourceWithConfig<TConfig = any, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = any, TContext = any, TMeta extends IResourceMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends IResourceMiddleware<any, any, any, any>[] = IResourceMiddleware[]> {
|
|
555
|
-
[symbolResourceWithConfig]: true;
|
|
556
|
-
/** The id of the underlying resource. */
|
|
557
|
-
id: string;
|
|
558
|
-
/** The underlying resource definition. */
|
|
559
|
-
resource: IResource<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
560
|
-
/** The configuration captured by `.with(config)`. */
|
|
561
|
-
config: TConfig;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
/**
|
|
565
|
-
* Typed key used to store/retrieve values from an ExecutionJournal.
|
|
566
|
-
* The `id` is used as the storage slot.
|
|
567
|
-
*/
|
|
568
|
-
declare const journalKeyBrand: unique symbol;
|
|
569
|
-
type JournalKey<T> = {
|
|
570
|
-
readonly id: string;
|
|
571
|
-
readonly [journalKeyBrand]?: (value: T) => T;
|
|
572
|
-
};
|
|
573
|
-
/**
|
|
574
|
-
* Options for setting values in the journal.
|
|
575
|
-
*/
|
|
576
|
-
interface JournalSetOptions {
|
|
577
|
-
/**
|
|
578
|
-
* If true, allows overwriting an existing value.
|
|
579
|
-
* By default, attempting to set a key that already exists will throw an error.
|
|
580
|
-
*/
|
|
581
|
-
override?: boolean;
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Per-execution registry that allows middleware and tasks to share state.
|
|
585
|
-
* A new journal is created for each top-level task execution unless explicitly forwarded.
|
|
586
|
-
*/
|
|
587
|
-
interface ExecutionJournal {
|
|
588
|
-
set<T>(key: JournalKey<T>, value: T, options?: JournalSetOptions): void;
|
|
589
|
-
get<T>(key: JournalKey<T>): T | undefined;
|
|
590
|
-
has<T>(key: JournalKey<T>): boolean;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
interface ITaskMiddlewareDefinition<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> {
|
|
594
|
-
id: string;
|
|
595
|
-
/** Static or lazy dependency map. */
|
|
596
|
-
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
597
|
-
/**
|
|
598
|
-
* Optional validation schema for runtime config validation.
|
|
599
|
-
* When provided, middleware config will be validated when .with() is called.
|
|
600
|
-
*/
|
|
601
|
-
configSchema?: IValidationSchema<TConfig>;
|
|
602
|
-
/**
|
|
603
|
-
* The middleware body, called with task execution input.
|
|
604
|
-
*/
|
|
605
|
-
run: (input: ITaskMiddlewareExecutionInput<TEnforceInputContract extends void ? any : TEnforceInputContract, TEnforceOutputContract extends void ? any : TEnforceOutputContract>, dependencies: DependencyValuesType<TDependencies>, config: TConfig) => Promise<any>;
|
|
606
|
-
meta?: IMiddlewareMeta;
|
|
607
|
-
tags?: TagType[];
|
|
608
|
-
everywhere?: boolean | ((task: ITask<any, any, any, any>) => boolean);
|
|
609
|
-
}
|
|
610
|
-
interface ITaskMiddleware<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends ITaskMiddlewareDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>, IContractable<TConfig, TEnforceInputContract, TEnforceOutputContract> {
|
|
611
|
-
[symbolTaskMiddleware]: true;
|
|
612
|
-
[symbolFilePath]: string;
|
|
613
|
-
id: string;
|
|
614
|
-
dependencies: TDependencies | ((config: TConfig) => TDependencies);
|
|
615
|
-
/** Current configuration object (empty by default). */
|
|
616
|
-
config: TConfig;
|
|
617
|
-
/** Configure the middleware and return a marked, configured instance. */
|
|
618
|
-
with: (config: TConfig) => ITaskMiddlewareConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
619
|
-
tags: TagType[];
|
|
620
|
-
}
|
|
621
|
-
interface ITaskMiddlewareConfigured<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends ITaskMiddleware<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies> {
|
|
622
|
-
[symbolMiddlewareConfigured]: true;
|
|
623
|
-
config: TConfig;
|
|
624
|
-
}
|
|
625
|
-
interface ITaskMiddlewareExecutionInput<TTaskInput = any, TTaskOutput = any> {
|
|
626
|
-
/** Task hook */
|
|
627
|
-
task: {
|
|
628
|
-
definition: ITask<TTaskInput, any, any, any>;
|
|
629
|
-
input: TTaskInput;
|
|
630
|
-
};
|
|
631
|
-
next: (taskInput?: TTaskInput) => Promise<TTaskOutput>;
|
|
632
|
-
/** Per-execution registry for sharing state between middleware and task */
|
|
633
|
-
journal: ExecutionJournal;
|
|
634
|
-
}
|
|
635
|
-
type TaskMiddlewareAttachmentType = ITaskMiddleware<void, any, any, any> | ITaskMiddleware<{
|
|
636
|
-
[K in any]?: any;
|
|
637
|
-
}, any, any, any> | ITaskMiddlewareConfigured<any, any, any, any>;
|
|
638
|
-
|
|
639
|
-
interface ITaskDefinition<TInput = undefined, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> {
|
|
640
|
-
id: string;
|
|
641
|
-
/**
|
|
642
|
-
* Access other tasks/resources/events. Can be an object or a function when
|
|
643
|
-
* you need late or config‑dependent resolution.
|
|
644
|
-
*/
|
|
645
|
-
dependencies?: TDependencies | (() => TDependencies);
|
|
646
|
-
/** Middleware applied around task execution. */
|
|
647
|
-
middleware?: TMiddleware;
|
|
648
|
-
/** Optional metadata used for docs, filtering and tooling. */
|
|
649
|
-
meta?: TMeta;
|
|
650
|
-
/**
|
|
651
|
-
* Optional validation schema for runtime input validation.
|
|
652
|
-
* When provided, task input will be validated before execution.
|
|
653
|
-
*/
|
|
654
|
-
inputSchema?: IValidationSchema<TInput>;
|
|
655
|
-
/**
|
|
656
|
-
* Optional validation schema for the task result.
|
|
657
|
-
* When provided, the result will be validated immediately after the task's
|
|
658
|
-
* `run` resolves, without considering middleware.
|
|
659
|
-
*/
|
|
660
|
-
resultSchema?: IValidationSchema<TOutput extends Promise<infer U> ? U : never>;
|
|
661
|
-
/**
|
|
662
|
-
* Declares which typed errors are part of this task's contract.
|
|
663
|
-
*
|
|
664
|
-
* This is a declarative contract only:
|
|
665
|
-
* - It does not imply dependency injection
|
|
666
|
-
* - It does not enforce that only these errors can be thrown
|
|
667
|
-
*
|
|
668
|
-
* Use string ids or Error helpers.
|
|
669
|
-
*/
|
|
670
|
-
throws?: ThrowsList;
|
|
671
|
-
run: (input: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? [TInput] extends [undefined] ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : EnsureInputSatisfiesContracts<[...TTags, ...TMiddleware], TInput> : TInput, dependencies: DependencyValuesType<TDependencies>, context?: {
|
|
672
|
-
journal: ExecutionJournal;
|
|
673
|
-
}) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TOutput> : TOutput;
|
|
674
|
-
/**
|
|
675
|
-
* Tags applied to the task that might define its behvaiour or impact the systems.
|
|
676
|
-
*/
|
|
677
|
-
tags?: TTags;
|
|
678
|
-
}
|
|
679
|
-
interface ITask<TInput = any, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> extends ITaskDefinition<TInput, TOutput, TDependencies, TMeta, TTags, TMiddleware> {
|
|
680
|
-
[symbolFilePath]: string;
|
|
681
|
-
[symbolTask]: true;
|
|
682
|
-
/** Present only for phantom tasks. */
|
|
683
|
-
[symbolPhantomTask]?: true;
|
|
684
|
-
/** Indicates if the task is tunneled through a tunnel client. */
|
|
685
|
-
isTunneled?: boolean;
|
|
686
|
-
/** Records which tunnel resource owns the task (exclusivity). */
|
|
687
|
-
[symbolTunneledBy]?: string;
|
|
688
|
-
id: string;
|
|
689
|
-
dependencies: TDependencies | (() => TDependencies);
|
|
690
|
-
computedDependencies?: DependencyValuesType<TDependencies>;
|
|
691
|
-
middleware: TMiddleware;
|
|
692
|
-
/** Normalized list of error ids declared via `throws`. */
|
|
693
|
-
throws?: readonly string[];
|
|
694
|
-
/** Return an optional dependency wrapper for this task. */
|
|
695
|
-
optional: () => IOptionalDependency<ITask<TInput, TOutput, TDependencies, TMeta, TTags, TMiddleware>>;
|
|
696
|
-
tags: TTags;
|
|
697
|
-
}
|
|
698
|
-
/** Narrowed type for phantom tasks (no-op run by default). */
|
|
699
|
-
type IPhantomTask<TInput = any, TResolved = any, TDependencies extends DependencyMapType = {}, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> = ITask<TInput, Promise<TResolved>, TDependencies, TMeta, TTags, TMiddleware> & {
|
|
700
|
-
[symbolPhantomTask]: true;
|
|
701
|
-
};
|
|
702
|
-
|
|
703
|
-
type EventHandlerType<T = any> = (event: IEventEmission<T>) => any | Promise<any>;
|
|
704
|
-
declare function onAnyOf<T extends readonly IEventDefinition<any>[]>(...defs: T): T;
|
|
705
|
-
/**
|
|
706
|
-
* Runtime guard that checks if an emission belongs to one of the given event defs.
|
|
707
|
-
* Narrows payload type to the intersection of the provided events' payloads.
|
|
708
|
-
*/
|
|
709
|
-
declare function isOneOf<TDefs extends readonly IEventDefinition<any>[]>(emission: IEventEmission<any>, defs: TDefs): emission is IEventEmission<CommonPayload<TDefs>>;
|
|
710
|
-
interface IEventDefinition<TPayload = void> {
|
|
711
|
-
id: string;
|
|
712
|
-
meta?: IEventMeta;
|
|
713
|
-
/**
|
|
714
|
-
* Optional validation schema for runtime payload validation.
|
|
715
|
-
* When provided, event payload will be validated when emitted.
|
|
716
|
-
*/
|
|
717
|
-
payloadSchema?: IValidationSchema<TPayload>;
|
|
718
|
-
tags?: TagType[];
|
|
719
|
-
/**
|
|
720
|
-
* If true, listeners with the same priority run concurrently within a batch.
|
|
721
|
-
* Batches (grouped by order) still execute sequentially in priority order.
|
|
722
|
-
*/
|
|
723
|
-
parallel?: boolean;
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* The definioten of the event.
|
|
727
|
-
* This is different from the event emission.
|
|
728
|
-
*/
|
|
729
|
-
interface IEvent<TPayload = any> extends IEventDefinition<TPayload> {
|
|
730
|
-
id: string;
|
|
731
|
-
/**
|
|
732
|
-
* We use this event to discriminate between resources with just 'id' and 'events' as they collide. This is a workaround, should be redone using classes and instanceof.
|
|
733
|
-
*/
|
|
734
|
-
[symbolEvent]: true;
|
|
735
|
-
[symbolFilePath]: string;
|
|
736
|
-
/** Return an optional dependency wrapper for this event. */
|
|
737
|
-
optional: () => IOptionalDependency<IEvent<TPayload>>;
|
|
738
|
-
tags: TagType[];
|
|
739
|
-
}
|
|
740
|
-
/**
|
|
741
|
-
* This represents the object that is passed to event handlers
|
|
742
|
-
*/
|
|
743
|
-
interface IEventEmission<TPayload = any> {
|
|
744
|
-
/**
|
|
745
|
-
* The ID of the event. This is the same as the event's ID.
|
|
746
|
-
* This is useful for global event listeners.
|
|
747
|
-
*/
|
|
748
|
-
id: string;
|
|
749
|
-
/**
|
|
750
|
-
* The data that the event carries. It can be anything.
|
|
751
|
-
*/
|
|
752
|
-
data: TPayload;
|
|
753
|
-
/**
|
|
754
|
-
* The timestamp when the event was created.
|
|
755
|
-
*/
|
|
756
|
-
timestamp: Date;
|
|
757
|
-
/**
|
|
758
|
-
* The source of the event. This can be useful for debugging.
|
|
759
|
-
*/
|
|
760
|
-
source: string;
|
|
761
|
-
/**
|
|
762
|
-
* Metadata associated with the event definition.
|
|
763
|
-
*/
|
|
764
|
-
meta: IEventMeta;
|
|
765
|
-
/**
|
|
766
|
-
* Stops propagation to remaining event listeners.
|
|
767
|
-
*/
|
|
768
|
-
stopPropagation(): void;
|
|
769
|
-
/**
|
|
770
|
-
* Returns true if propagation has been stopped.
|
|
771
|
-
*/
|
|
772
|
-
isPropagationStopped(): boolean;
|
|
773
|
-
/**
|
|
774
|
-
* The tags that the event carries.
|
|
775
|
-
*/
|
|
776
|
-
tags: TagType[];
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
type OnType = "*" | IEventDefinition<any> | readonly IEventDefinition<any>[];
|
|
780
|
-
interface IHookDefinition<TDependencies extends DependencyMapType = {}, TOn extends OnType = any, TMeta extends ITaskMeta = any> {
|
|
781
|
-
id: string;
|
|
782
|
-
dependencies?: TDependencies | (() => TDependencies);
|
|
783
|
-
on: TOn;
|
|
784
|
-
/** Listener execution order. Lower numbers run first. */
|
|
785
|
-
order?: number;
|
|
786
|
-
meta?: TMeta;
|
|
787
|
-
run: (event: IEventEmission<TOn extends "*" ? any : TOn extends readonly IEventDefinition<any>[] ? CommonPayload<TOn> : ExtractEventPayload<TOn>>, dependencies: DependencyValuesType<TDependencies>) => Promise<any>;
|
|
788
|
-
tags?: TagType[];
|
|
789
|
-
}
|
|
790
|
-
interface IHook<TDependencies extends DependencyMapType = {}, TOn extends OnType = any, TMeta extends ITaskMeta = any> extends IHookDefinition<TDependencies, TOn, TMeta> {
|
|
791
|
-
id: string;
|
|
792
|
-
dependencies: TDependencies | (() => TDependencies);
|
|
793
|
-
[symbolFilePath]: string;
|
|
794
|
-
[symbolHook]: true;
|
|
795
|
-
tags: TagType[];
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
interface IAsyncContextDefinition<T> {
|
|
799
|
-
id: string;
|
|
800
|
-
serialize?(data: T): string;
|
|
801
|
-
parse?(data: string): T;
|
|
802
|
-
/**
|
|
803
|
-
* When provided, context values will be validated when provide() is called.
|
|
804
|
-
*/
|
|
805
|
-
configSchema?: IValidationSchema<T>;
|
|
806
|
-
meta?: IAsyncContextMeta;
|
|
807
|
-
}
|
|
808
|
-
/**
|
|
809
|
-
* The generic AsyncContext object returned by `defineAsyncContext`.
|
|
810
|
-
*/
|
|
811
|
-
interface IAsyncContext<T> {
|
|
812
|
-
/** unique symbol used as key in the AsyncLocalStorage map */
|
|
813
|
-
readonly id: string;
|
|
814
|
-
/** Brand marker for registration and runtime checks */
|
|
815
|
-
[symbolAsyncContext]: true;
|
|
816
|
-
/** Retrieve the current context value or throw */
|
|
817
|
-
use(): T;
|
|
818
|
-
/**
|
|
819
|
-
* Provide a value for this context during the lifetime of `fn()`
|
|
820
|
-
*/
|
|
821
|
-
provide<R>(value: T, fn: () => Promise<R> | R): Promise<R> | R;
|
|
822
|
-
/**
|
|
823
|
-
* Generates a middleware that guarantees the context exists (and optionally
|
|
824
|
-
* enforces that certain keys are present on the context object).
|
|
825
|
-
*/
|
|
826
|
-
require<K extends keyof T = never>(keys?: K[]): ITaskMiddlewareConfigured<{
|
|
827
|
-
context: IAsyncContext<T>;
|
|
828
|
-
}>;
|
|
829
|
-
serialize(data: T): string;
|
|
830
|
-
parse(data: string): T;
|
|
831
|
-
/** Return an optional dependency wrapper for this context */
|
|
832
|
-
optional(): IOptionalDependency<IAsyncContext<T>>;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
/**
|
|
836
|
-
* Generic validation schema interface that can be implemented by any validation library.
|
|
837
|
-
* Compatible with Zod, Yup, Joi, and other validation libraries.
|
|
838
|
-
*/
|
|
839
|
-
interface IValidationSchema<T = any> {
|
|
840
|
-
/**
|
|
841
|
-
* Parse and validate the input data.
|
|
842
|
-
* Should throw an error if validation fails.
|
|
843
|
-
* Can transform the data if the schema supports transformations.
|
|
844
|
-
*/
|
|
845
|
-
parse(input: unknown): T;
|
|
846
|
-
}
|
|
847
|
-
/**
|
|
848
|
-
* Core public TypeScript types for BlueLibs Runner.
|
|
849
|
-
*
|
|
850
|
-
* This file contains the strongly-typed contract for tasks, resources, events
|
|
851
|
-
* and middleware. It mirrors the mental model described in the README:
|
|
852
|
-
* - Tasks are functions
|
|
853
|
-
* - Resources are singletons (with init/dispose hooks)
|
|
854
|
-
* - Events are simple, strongly-typed emissions
|
|
855
|
-
* - Middleware can target both tasks and resources
|
|
856
|
-
*
|
|
857
|
-
* DX goals:
|
|
858
|
-
* - Crystal‑clear generics and helper types that infer dependency shapes
|
|
859
|
-
* - Friendly JSDoc you can hover in editors to understand usage instantly
|
|
860
|
-
* - Safe overrides and strong typing around config and register mechanics
|
|
861
|
-
*/
|
|
862
|
-
type RequiredKeys<T> = {
|
|
863
|
-
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
864
|
-
}[keyof T];
|
|
865
|
-
/**
|
|
866
|
-
* The reason we accept null and undefined is because we want to be able to offer beautiful DX:
|
|
867
|
-
* overrides: [
|
|
868
|
-
* process.env.NODE_ENV === 'production' ? prodEmailer : null,
|
|
869
|
-
* ]
|
|
870
|
-
*/
|
|
871
|
-
type OverridableElements = IResource<any, any, any, any, any> | ITask<any, any, any, any> | ITaskMiddleware<any> | IResourceMiddleware<any, any> | IResourceWithConfig<any, any, any> | IHook<any, any> | undefined | null;
|
|
872
|
-
/**
|
|
873
|
-
* A mapping of dependency keys to Runner definitions. Used in `dependencies`
|
|
874
|
-
* for tasks and resources. Values are later transformed into the actual
|
|
875
|
-
* callable/value shape by `DependencyValuesType`.
|
|
876
|
-
*/
|
|
877
|
-
type DependencyMapType = Record<string, ITask<any, any, any, any, any, any> | IResource<any, any, any, any, any, any, any> | IEvent<any> | IErrorHelper<any> | IAsyncContext<any> | IOptionalDependency<ITask<any, any, any, any, any, any>> | IOptionalDependency<IResource<any, any, any, any, any, any, any>> | IOptionalDependency<IEvent<any>> | IOptionalDependency<IErrorHelper<any>> | IOptionalDependency<IAsyncContext<any>>>;
|
|
878
|
-
/** Wrapper type marking a dependency as optional at wiring time */
|
|
879
|
-
interface IOptionalDependency<T> {
|
|
880
|
-
/** The wrapped dependency definition */
|
|
881
|
-
inner: T;
|
|
882
|
-
/** Brand symbol for optional dependency */
|
|
883
|
-
[symbolOptionalDependency]: true;
|
|
884
|
-
}
|
|
885
|
-
type ExtractTaskInput<T> = T extends ITask<infer I, any, infer _D> ? I : never;
|
|
886
|
-
type ExtractTaskOutput<T> = T extends ITask<any, infer O, infer _D> ? O : never;
|
|
887
|
-
type ExtractResourceConfig<T> = T extends IResource<infer C, any, any> ? C : never;
|
|
888
|
-
type ExtractResourceValue<T> = T extends IResource<any, infer V, infer _D> ? V extends Promise<infer U> ? U : V : never;
|
|
889
|
-
type ExtractEventPayload<T> = T extends IEventDefinition<infer P> ? P : T extends IEvent<infer P> ? P : never;
|
|
890
|
-
type UnionToIntersection<U> = (U extends any ? (x: U) => any : never) extends (x: infer I) => any ? I : never;
|
|
891
|
-
type CommonPayload<T extends readonly IEventDefinition<any>[] | IEventDefinition<any>> = T extends readonly IEventDefinition<any>[] ? {
|
|
892
|
-
[K in keyof ExtractEventPayload<T[number]>]: UnionToIntersection<ExtractEventPayload<T[number]> extends any ? ExtractEventPayload<T[number]>[K] : never>;
|
|
893
|
-
} : ExtractEventPayload<T>;
|
|
894
|
-
/**
|
|
895
|
-
* Options that can be passed when calling a task dependency.
|
|
896
|
-
* Allows forwarding the execution journal to nested task calls.
|
|
897
|
-
*/
|
|
898
|
-
interface TaskCallOptions {
|
|
899
|
-
/** Optional journal to forward to the nested task */
|
|
900
|
-
journal?: ExecutionJournal;
|
|
901
|
-
}
|
|
902
|
-
/**
|
|
903
|
-
* Task dependencies transform into callable functions: call with the task input
|
|
904
|
-
* and you receive the task output. Optionally accepts TaskCallOptions for journal forwarding.
|
|
905
|
-
*/
|
|
906
|
-
type TaskDependency<I, O> = I extends null | void ? {
|
|
907
|
-
(options?: TaskCallOptions): O;
|
|
908
|
-
(input?: I, options?: TaskCallOptions): O;
|
|
909
|
-
} : (input: I, options?: TaskCallOptions) => O;
|
|
910
|
-
/**
|
|
911
|
-
* Resource dependencies resolve to the resource's value directly.
|
|
912
|
-
*/
|
|
913
|
-
type ResourceDependency<V> = V;
|
|
914
|
-
/**
|
|
915
|
-
* Event dependencies resolve to an emitter function. If the payload type is
|
|
916
|
-
* `void`, the function can be called with zero args (or an empty object).
|
|
917
|
-
*/
|
|
918
|
-
type EventDependency<P> = P extends void ? (() => Promise<void>) & ((input?: Record<string, never>) => Promise<void>) : (input: P) => Promise<void>;
|
|
919
|
-
/**
|
|
920
|
-
* Transforms a dependency definition into the usable shape inside `run`/`init`:
|
|
921
|
-
* - Task -> callable function
|
|
922
|
-
* - Resource -> resolved value
|
|
923
|
-
* - Event -> emit function
|
|
924
|
-
*/
|
|
925
|
-
type DependencyValueType<T> = T extends ITask<any, any, any> ? TaskDependency<ExtractTaskInput<T>, ExtractTaskOutput<T>> : T extends IResource<any, any> ? ResourceDependency<ExtractResourceValue<T>> : T extends IErrorHelper<any> ? T : T extends IAsyncContext<any> ? T : T extends IEventDefinition<any> ? EventDependency<ExtractEventPayload<T>> : T extends IOptionalDependency<infer U> ? DependencyValueType<U> | undefined : never;
|
|
926
|
-
type DependencyValuesType<T extends DependencyMapType> = {
|
|
927
|
-
[K in keyof T]: DependencyValueType<T[K]>;
|
|
928
|
-
};
|
|
929
|
-
type TaskLocalInterceptor<TInput, TOutput> = (next: (input: TInput) => TOutput, input: TInput) => TOutput;
|
|
930
|
-
type TaskDependencyWithIntercept<TInput, TOutput> = TaskDependency<TInput, TOutput> & {
|
|
931
|
-
intercept: (middleware: TaskLocalInterceptor<TInput, TOutput>) => void;
|
|
932
|
-
};
|
|
933
|
-
/** Resource-context dependency typing where tasks expose intercept() */
|
|
934
|
-
type ResourceDependencyValueType<T> = T extends ITask<any, any, any> ? TaskDependencyWithIntercept<ExtractTaskInput<T>, ExtractTaskOutput<T>> : T extends IResource<any, any> ? ResourceDependency<ExtractResourceValue<T>> : T extends IErrorHelper<any> ? T : T extends IAsyncContext<any> ? T : T extends IEventDefinition<any> ? EventDependency<ExtractEventPayload<T>> : T extends IOptionalDependency<infer U> ? ResourceDependencyValueType<U> | undefined : never;
|
|
935
|
-
type ResourceDependencyValuesType<T extends DependencyMapType> = {
|
|
936
|
-
[K in keyof T]: ResourceDependencyValueType<T[K]>;
|
|
937
|
-
};
|
|
938
|
-
/**
|
|
939
|
-
* Anything you can put inside a resource's `register: []`.
|
|
940
|
-
* - Resources (with or without `.with()`)
|
|
941
|
-
* - Tasks
|
|
942
|
-
* - Middleware
|
|
943
|
-
* - Events
|
|
944
|
-
*/
|
|
945
|
-
type RegisterableItems = IResourceWithConfig<any, any, any, any, any, any, any> | IResource<void, any, any, any, any, any, any> | IResource<{
|
|
946
|
-
[K in any]?: any;
|
|
947
|
-
}, any, any, any, any, any, any> | ITask<any, any, any, any, any, any> | IHook<any, any> | ITaskMiddleware<any, any, any, any> | IResourceMiddleware<any, any, any, any> | IEvent<any> | IAsyncContext<any> | IErrorHelper<any> | ITag<any, any, any>;
|
|
948
|
-
|
|
949
|
-
interface TaskMiddlewareFluentBuilder<C = any, In = void, Out = void, D extends DependencyMapType = {}> {
|
|
950
|
-
id: string;
|
|
951
|
-
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | ((config: C) => TNewDeps), options?: {
|
|
952
|
-
override?: false;
|
|
953
|
-
}): TaskMiddlewareFluentBuilder<C, In, Out, D & TNewDeps>;
|
|
954
|
-
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | ((config: C) => TNewDeps), options: {
|
|
955
|
-
override: true;
|
|
956
|
-
}): TaskMiddlewareFluentBuilder<C, In, Out, TNewDeps>;
|
|
957
|
-
configSchema<TNew>(schema: IValidationSchema<TNew>): TaskMiddlewareFluentBuilder<TNew, In, Out, D>;
|
|
958
|
-
run(fn: ITaskMiddlewareDefinition<C, In, Out, D>["run"]): TaskMiddlewareFluentBuilder<C, In, Out, D>;
|
|
959
|
-
meta<TNewMeta extends IMiddlewareMeta>(m: TNewMeta): TaskMiddlewareFluentBuilder<C, In, Out, D>;
|
|
960
|
-
tags<TNewTags extends TagType[]>(t: TNewTags, options?: {
|
|
961
|
-
override?: boolean;
|
|
962
|
-
}): TaskMiddlewareFluentBuilder<C, In, Out, D>;
|
|
963
|
-
everywhere(flag: boolean | ((task: ITask<any, any, any, any>) => boolean)): TaskMiddlewareFluentBuilder<C, In, Out, D>;
|
|
964
|
-
build(): ITaskMiddleware<C, In, Out, D>;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
interface ResourceMiddlewareFluentBuilder<C = any, In = void, Out = void, D extends DependencyMapType = {}> {
|
|
968
|
-
id: string;
|
|
969
|
-
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | ((config: C) => TNewDeps), options?: {
|
|
970
|
-
override?: false;
|
|
971
|
-
}): ResourceMiddlewareFluentBuilder<C, In, Out, D & TNewDeps>;
|
|
972
|
-
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | ((config: C) => TNewDeps), options: {
|
|
973
|
-
override: true;
|
|
974
|
-
}): ResourceMiddlewareFluentBuilder<C, In, Out, TNewDeps>;
|
|
975
|
-
configSchema<TNew>(schema: IValidationSchema<TNew>): ResourceMiddlewareFluentBuilder<TNew, In, Out, D>;
|
|
976
|
-
run(fn: IResourceMiddlewareDefinition<C, In, Out, D>["run"]): ResourceMiddlewareFluentBuilder<C, In, Out, D>;
|
|
977
|
-
meta<TNewMeta extends IMiddlewareMeta>(m: TNewMeta): ResourceMiddlewareFluentBuilder<C, In, Out, D>;
|
|
978
|
-
tags<TNewTags extends TagType[]>(t: TNewTags, options?: {
|
|
979
|
-
override?: boolean;
|
|
980
|
-
}): ResourceMiddlewareFluentBuilder<C, In, Out, D>;
|
|
981
|
-
everywhere(flag: boolean | ((resource: IResource<any, any, any, any, any>) => boolean)): ResourceMiddlewareFluentBuilder<C, In, Out, D>;
|
|
982
|
-
build(): IResourceMiddleware<C, In, Out, D>;
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
/**
|
|
986
|
-
* Entry point for creating a task middleware builder.
|
|
987
|
-
*/
|
|
988
|
-
declare function taskMiddlewareBuilder<C = void, In = void, Out = void, D extends DependencyMapType = {}>(id: string): TaskMiddlewareFluentBuilder<C, In, Out, D>;
|
|
989
|
-
/**
|
|
990
|
-
* Entry point for creating a resource middleware builder.
|
|
991
|
-
*/
|
|
992
|
-
declare function resourceMiddlewareBuilder<C = void, In = void, Out = void, D extends DependencyMapType = {}>(id: string): ResourceMiddlewareFluentBuilder<C, In, Out, D>;
|
|
993
|
-
|
|
994
|
-
interface ErrorFluentBuilder<TData extends DefaultErrorType = DefaultErrorType> {
|
|
995
|
-
id: string;
|
|
996
|
-
serialize(fn: (data: TData) => string): ErrorFluentBuilder<TData>;
|
|
997
|
-
parse(fn: (raw: string) => TData): ErrorFluentBuilder<TData>;
|
|
998
|
-
dataSchema(schema: IValidationSchema<TData>): ErrorFluentBuilder<TData>;
|
|
999
|
-
build(): IErrorHelper<TData>;
|
|
1000
|
-
format(fn: (data: TData) => string): ErrorFluentBuilder<TData>;
|
|
1001
|
-
meta<TNewMeta extends IErrorMeta>(m: TNewMeta): ErrorFluentBuilder<TData>;
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
/**
|
|
1005
|
-
* Entry point for creating an error builder.
|
|
1006
|
-
*/
|
|
1007
|
-
declare function errorBuilder<TData extends DefaultErrorType = DefaultErrorType>(id: string): ErrorFluentBuilder<TData>;
|
|
1008
|
-
|
|
1009
|
-
interface AsyncContextFluentBuilder<T = unknown> {
|
|
1010
|
-
id: string;
|
|
1011
|
-
serialize(fn: (data: T) => string): AsyncContextFluentBuilder<T>;
|
|
1012
|
-
parse(fn: (raw: string) => T): AsyncContextFluentBuilder<T>;
|
|
1013
|
-
configSchema(schema: IValidationSchema<T>): AsyncContextFluentBuilder<T>;
|
|
1014
|
-
meta<TNewMeta extends IAsyncContextMeta>(m: TNewMeta): AsyncContextFluentBuilder<T>;
|
|
1015
|
-
build(): IAsyncContext<T>;
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
/**
|
|
1019
|
-
* Entry point for creating an async context builder.
|
|
1020
|
-
*/
|
|
1021
|
-
declare function asyncContextBuilder<T = unknown>(id: string): AsyncContextFluentBuilder<T>;
|
|
1022
|
-
|
|
1023
|
-
interface TagFluentBuilder<TConfig = void, TEnforceIn = void, TEnforceOut = void> {
|
|
1024
|
-
id: string;
|
|
1025
|
-
meta<TNewMeta extends ITagMeta>(m: TNewMeta): TagFluentBuilder<TConfig, TEnforceIn, TEnforceOut>;
|
|
1026
|
-
configSchema<TNewConfig>(schema: IValidationSchema<TNewConfig>): TagFluentBuilder<TNewConfig, TEnforceIn, TEnforceOut>;
|
|
1027
|
-
config<TNewConfig>(config: TNewConfig): TagFluentBuilder<TNewConfig, TEnforceIn, TEnforceOut>;
|
|
1028
|
-
build(): ITag<TConfig, TEnforceIn, TEnforceOut>;
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
/**
|
|
1032
|
-
* Entry point for creating a tag builder.
|
|
1033
|
-
*/
|
|
1034
|
-
declare function tagBuilder<TConfig = void, TEnforceIn = void, TEnforceOut = void>(id: string): TagFluentBuilder<TConfig, TEnforceIn, TEnforceOut>;
|
|
1035
|
-
|
|
1036
|
-
/** Valid event targets for hook's .on() method */
|
|
1037
|
-
type ValidOnTarget = "*" | IEventDefinition<any> | readonly IEventDefinition<any>[];
|
|
1038
|
-
/** Resolved TOn when valid, or `any` when undefined (build will throw at runtime) */
|
|
1039
|
-
type ResolvedOn<TOn> = TOn extends ValidOnTarget ? TOn : any;
|
|
1040
|
-
interface HookFluentBuilder<TDeps extends DependencyMapType = {}, TOn extends ValidOnTarget | undefined = undefined, TMeta extends ITaskMeta = ITaskMeta> {
|
|
1041
|
-
id: string;
|
|
1042
|
-
on<TNewOn extends ValidOnTarget>(on: TNewOn): HookFluentBuilder<TDeps, TNewOn, TMeta>;
|
|
1043
|
-
order(order: number): HookFluentBuilder<TDeps, TOn, TMeta>;
|
|
1044
|
-
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | (() => TNewDeps), options?: {
|
|
1045
|
-
override?: false;
|
|
1046
|
-
}): HookFluentBuilder<TDeps & TNewDeps, TOn, TMeta>;
|
|
1047
|
-
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | (() => TNewDeps), options: {
|
|
1048
|
-
override: true;
|
|
1049
|
-
}): HookFluentBuilder<TNewDeps, TOn, TMeta>;
|
|
1050
|
-
tags<TNewTags extends TagType[]>(t: TNewTags, options?: {
|
|
1051
|
-
override?: boolean;
|
|
1052
|
-
}): HookFluentBuilder<TDeps, TOn, TMeta>;
|
|
1053
|
-
meta<TNewMeta extends ITaskMeta>(m: TNewMeta): HookFluentBuilder<TDeps, TOn, TNewMeta>;
|
|
1054
|
-
/** Set the hook's run handler. Required before build(). */
|
|
1055
|
-
run(fn: IHookDefinition<TDeps, ResolvedOn<TOn>, TMeta>["run"]): HookFluentBuilder<TDeps, TOn, TMeta>;
|
|
1056
|
-
/**
|
|
1057
|
-
* Build the hook definition. Requires .on() and .run() to be called first.
|
|
1058
|
-
* @throws {Error} if on or run are not set
|
|
1059
|
-
*/
|
|
1060
|
-
build(): IHook<TDeps, ResolvedOn<TOn>, TMeta>;
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
/**
|
|
1064
|
-
* Entry point for creating a hook builder.
|
|
1065
|
-
* Requires calling .on() and .run() before .build().
|
|
1066
|
-
*/
|
|
1067
|
-
declare function hookBuilder(id: string): HookFluentBuilder<{}, undefined, ITaskMeta>;
|
|
1068
|
-
|
|
1069
|
-
interface EventFluentBuilder<TPayload = void> {
|
|
1070
|
-
id: string;
|
|
1071
|
-
payloadSchema<TNew>(schema: IValidationSchema<TNew>): EventFluentBuilder<TNew>;
|
|
1072
|
-
tags<TNewTags extends TagType[]>(t: TNewTags, options?: {
|
|
1073
|
-
override?: boolean;
|
|
1074
|
-
}): EventFluentBuilder<TPayload>;
|
|
1075
|
-
meta<TNewMeta extends IEventMeta>(m: TNewMeta): EventFluentBuilder<TPayload>;
|
|
1076
|
-
/**
|
|
1077
|
-
* Enable parallel execution for this event's listeners.
|
|
1078
|
-
* When enabled, listeners with the same `order` run concurrently within a batch.
|
|
1079
|
-
* Batches execute sequentially in ascending order priority.
|
|
1080
|
-
*
|
|
1081
|
-
* @param enabled - Whether to enable parallel execution (default: true)
|
|
1082
|
-
*/
|
|
1083
|
-
parallel(enabled?: boolean): EventFluentBuilder<TPayload>;
|
|
1084
|
-
build(): IEvent<TPayload>;
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
/**
|
|
1088
|
-
* Entry point for creating an event builder.
|
|
1089
|
-
*/
|
|
1090
|
-
declare function eventBuilder<TPayload = void>(id: string): EventFluentBuilder<TPayload>;
|
|
1091
|
-
|
|
1092
|
-
type ShouldReplaceInput<T> = [T] extends [undefined] ? true : [T] extends [void] ? true : 0 extends 1 & T ? true : false;
|
|
1093
|
-
type ResolveInput<TExisting, TProposed> = ShouldReplaceInput<TExisting> extends true ? TProposed : TExisting;
|
|
1094
|
-
|
|
1095
|
-
/**
|
|
1096
|
-
* Fluent builder interface for constructing tasks.
|
|
1097
|
-
*/
|
|
1098
|
-
interface TaskFluentBuilder<TInput = undefined, TOutput extends Promise<any> = Promise<any>, TDeps extends DependencyMapType = {}, TMeta extends ITaskMeta = ITaskMeta, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> {
|
|
1099
|
-
id: string;
|
|
1100
|
-
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | (() => TNewDeps), options?: {
|
|
1101
|
-
override?: false;
|
|
1102
|
-
}): TaskFluentBuilder<TInput, TOutput, TDeps & TNewDeps, TMeta, TTags, TMiddleware>;
|
|
1103
|
-
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | (() => TNewDeps), options: {
|
|
1104
|
-
override: true;
|
|
1105
|
-
}): TaskFluentBuilder<TInput, TOutput, TNewDeps, TMeta, TTags, TMiddleware>;
|
|
1106
|
-
middleware<TNewMw extends TaskMiddlewareAttachmentType[]>(mw: TNewMw, options?: {
|
|
1107
|
-
override?: boolean;
|
|
1108
|
-
}): TaskFluentBuilder<TInput, TOutput, TDeps, TMeta, TTags, TNewMw>;
|
|
1109
|
-
tags<TNewTags extends TagType[]>(t: TNewTags, options?: {
|
|
1110
|
-
override?: false;
|
|
1111
|
-
}): TaskFluentBuilder<TInput, TOutput, TDeps, TMeta, [
|
|
1112
|
-
...TTags,
|
|
1113
|
-
...TNewTags
|
|
1114
|
-
], TMiddleware>;
|
|
1115
|
-
tags<TNewTags extends TagType[]>(t: TNewTags, options: {
|
|
1116
|
-
override: true;
|
|
1117
|
-
}): TaskFluentBuilder<TInput, TOutput, TDeps, TMeta, TNewTags, TMiddleware>;
|
|
1118
|
-
inputSchema<TNewInput>(schema: IValidationSchema<TNewInput>): TaskFluentBuilder<TNewInput, TOutput, TDeps, TMeta, TTags, TMiddleware>;
|
|
1119
|
-
resultSchema<TResolved>(schema: IValidationSchema<TResolved>): TaskFluentBuilder<TInput, Promise<TResolved>, TDeps, TMeta, TTags, TMiddleware>;
|
|
1120
|
-
run<TNewInput = TInput, TNewOutput extends Promise<any> = TOutput>(fn: NonNullable<ITaskDefinition<ResolveInput<TInput, TNewInput>, TNewOutput, TDeps, TMeta, TTags, TMiddleware>["run"]>): TaskFluentBuilder<ResolveInput<TInput, TNewInput>, TNewOutput, TDeps, TMeta, TTags, TMiddleware>;
|
|
1121
|
-
throws(list: ThrowsList): TaskFluentBuilder<TInput, TOutput, TDeps, TMeta, TTags, TMiddleware>;
|
|
1122
|
-
meta<TNewMeta extends ITaskMeta>(m: TNewMeta): TaskFluentBuilder<TInput, TOutput, TDeps, TNewMeta, TTags, TMiddleware>;
|
|
1123
|
-
build(): ITask<TInput, TOutput, TDeps, TMeta, TTags, TMiddleware>;
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
/**
|
|
1127
|
-
* Fluent builder interface for constructing phantom tasks.
|
|
1128
|
-
*/
|
|
1129
|
-
interface PhantomTaskFluentBuilder<TInput = undefined, TResolved = any, TDeps extends DependencyMapType = {}, TMeta extends ITaskMeta = ITaskMeta, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> {
|
|
1130
|
-
id: string;
|
|
1131
|
-
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | (() => TNewDeps), options?: {
|
|
1132
|
-
override?: false;
|
|
1133
|
-
}): PhantomTaskFluentBuilder<TInput, TResolved, TDeps & TNewDeps, TMeta, TTags, TMiddleware>;
|
|
1134
|
-
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | (() => TNewDeps), options: {
|
|
1135
|
-
override: true;
|
|
1136
|
-
}): PhantomTaskFluentBuilder<TInput, TResolved, TNewDeps, TMeta, TTags, TMiddleware>;
|
|
1137
|
-
middleware<TNewMw extends TaskMiddlewareAttachmentType[]>(mw: TNewMw, options?: {
|
|
1138
|
-
override?: boolean;
|
|
1139
|
-
}): PhantomTaskFluentBuilder<TInput, TResolved, TDeps, TMeta, TTags, TNewMw>;
|
|
1140
|
-
tags<TNewTags extends TagType[]>(t: TNewTags, options?: {
|
|
1141
|
-
override?: false;
|
|
1142
|
-
}): PhantomTaskFluentBuilder<TInput, TResolved, TDeps, TMeta, [
|
|
1143
|
-
...TTags,
|
|
1144
|
-
...TNewTags
|
|
1145
|
-
], TMiddleware>;
|
|
1146
|
-
tags<TNewTags extends TagType[]>(t: TNewTags, options: {
|
|
1147
|
-
override: true;
|
|
1148
|
-
}): PhantomTaskFluentBuilder<TInput, TResolved, TDeps, TMeta, TNewTags, TMiddleware>;
|
|
1149
|
-
inputSchema<TNewInput>(schema: IValidationSchema<TNewInput>): PhantomTaskFluentBuilder<TNewInput, TResolved, TDeps, TMeta, TTags, TMiddleware>;
|
|
1150
|
-
resultSchema<TNewResolved>(schema: IValidationSchema<TNewResolved>): PhantomTaskFluentBuilder<TInput, TNewResolved, TDeps, TMeta, TTags, TMiddleware>;
|
|
1151
|
-
meta<TNewMeta extends ITaskMeta>(m: TNewMeta): PhantomTaskFluentBuilder<TInput, TResolved, TDeps, TNewMeta, TTags, TMiddleware>;
|
|
1152
|
-
throws(list: ThrowsList): PhantomTaskFluentBuilder<TInput, TResolved, TDeps, TMeta, TTags, TMiddleware>;
|
|
1153
|
-
build(): IPhantomTask<TInput, TResolved, TDeps, TMeta, TTags, TMiddleware>;
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
/**
|
|
1157
|
-
* Entry point for creating a phantom task builder.
|
|
1158
|
-
*/
|
|
1159
|
-
declare function phantomTaskBuilder<TInput = undefined, TResolved = any>(id: string): PhantomTaskFluentBuilder<TInput, TResolved, {}, ITaskMeta, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
1160
|
-
interface TaskBuilderWithPhantom {
|
|
1161
|
-
(id: string): TaskFluentBuilder<undefined, Promise<any>, {}, ITaskMeta, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
1162
|
-
phantom: typeof phantomTaskBuilder;
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
/**
|
|
1166
|
-
* Helper type to determine if config should be replaced.
|
|
1167
|
-
*/
|
|
1168
|
-
type ShouldReplaceConfig<T> = [T] extends [void] ? true : [T] extends [undefined] ? true : false;
|
|
1169
|
-
/**
|
|
1170
|
-
* Resolves the config type - uses proposed if existing is void/undefined.
|
|
1171
|
-
*/
|
|
1172
|
-
type ResolveConfig<TExisting, TProposed> = ShouldReplaceConfig<TExisting> extends true ? TProposed : TExisting;
|
|
1173
|
-
|
|
1174
|
-
/**
|
|
1175
|
-
* Fluent builder interface for constructing resources.
|
|
1176
|
-
* Each method returns a new builder with updated type parameters.
|
|
1177
|
-
*/
|
|
1178
|
-
interface ResourceFluentBuilder<TConfig = void, TValue extends Promise<any> = Promise<any>, TDeps extends DependencyMapType = {}, TContext = any, TMeta extends IResourceMeta = IResourceMeta, TTags extends TagType[] = TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[] = ResourceMiddlewareAttachmentType[]> {
|
|
1179
|
-
id: string;
|
|
1180
|
-
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | ((config: TConfig) => TNewDeps), options?: {
|
|
1181
|
-
override?: false;
|
|
1182
|
-
}): ResourceFluentBuilder<TConfig, TValue, TDeps & TNewDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
1183
|
-
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | ((config: TConfig) => TNewDeps), options: {
|
|
1184
|
-
override: true;
|
|
1185
|
-
}): ResourceFluentBuilder<TConfig, TValue, TNewDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
1186
|
-
register(items: RegisterableItems | Array<RegisterableItems> | ((config: TConfig) => RegisterableItems | Array<RegisterableItems>), options?: {
|
|
1187
|
-
override?: boolean;
|
|
1188
|
-
}): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
1189
|
-
middleware<TNewMw extends ResourceMiddlewareAttachmentType[]>(mw: TNewMw, options?: {
|
|
1190
|
-
override?: boolean;
|
|
1191
|
-
}): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TMeta, TTags, TNewMw>;
|
|
1192
|
-
tags<TNewTags extends TagType[]>(tags: TNewTags, options?: {
|
|
1193
|
-
override?: false;
|
|
1194
|
-
}): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TMeta, [
|
|
1195
|
-
...TTags,
|
|
1196
|
-
...TNewTags
|
|
1197
|
-
], TMiddleware>;
|
|
1198
|
-
tags<TNewTags extends TagType[]>(tags: TNewTags, options: {
|
|
1199
|
-
override: true;
|
|
1200
|
-
}): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TMeta, TNewTags, TMiddleware>;
|
|
1201
|
-
context<TNewCtx>(factory: () => TNewCtx): ResourceFluentBuilder<TConfig, TValue, TDeps, TNewCtx, TMeta, TTags, TMiddleware>;
|
|
1202
|
-
configSchema<TNewConfig>(schema: IValidationSchema<TNewConfig>): ResourceFluentBuilder<TNewConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
1203
|
-
resultSchema<TResolved>(schema: IValidationSchema<TResolved>): ResourceFluentBuilder<TConfig, Promise<TResolved>, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
1204
|
-
init<TNewConfig = TConfig, TNewValue extends Promise<any> = TValue>(fn: ResourceInitFn<ResolveConfig<TConfig, TNewConfig>, TNewValue, TDeps, TContext, TMeta, TTags, TMiddleware>): ResourceFluentBuilder<ResolveConfig<TConfig, TNewConfig>, TNewValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
1205
|
-
dispose(fn: NonNullable<IResourceDefinition<TConfig, TValue, TDeps, TContext, any, any, TMeta, TTags, TMiddleware>["dispose"]>): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
1206
|
-
meta<TNewMeta extends IResourceMeta>(m: TNewMeta): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TNewMeta, TTags, TMiddleware>;
|
|
1207
|
-
throws(list: ThrowsList): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
1208
|
-
overrides(o: Array<OverridableElements>, options?: {
|
|
1209
|
-
override?: boolean;
|
|
1210
|
-
}): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
1211
|
-
build(): IResource<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
/**
|
|
1215
|
-
* Creates a new resource builder with the given id.
|
|
1216
|
-
* Overload allows callers to seed the config type at the entry point for convenience.
|
|
1217
|
-
*/
|
|
1218
|
-
declare function resourceBuilder<TConfig = void>(id: string): ResourceFluentBuilder<TConfig, Promise<any>, {}, any, IResourceMeta, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
1219
|
-
|
|
1220
|
-
type TunnelMiddlewareId = string | ITaskMiddleware<any, any, any, any>;
|
|
1221
|
-
interface TunnelTaskMiddlewareSidePolicy {
|
|
1222
|
-
/**
|
|
1223
|
-
* Middleware ids/definitions allowed to run on this side when the task is tunneled.
|
|
1224
|
-
* If omitted, defaults to allowing none (caller-side middleware is skipped by default).
|
|
1225
|
-
*/
|
|
1226
|
-
middlewareAllowList?: TunnelMiddlewareId[];
|
|
1227
|
-
}
|
|
1228
|
-
type TunnelTaskMiddlewarePolicySideConfig = TunnelTaskMiddlewareSidePolicy | TunnelMiddlewareId[];
|
|
1229
|
-
interface TunnelTaskMiddlewarePolicyConfig {
|
|
1230
|
-
/**
|
|
1231
|
-
* Preferred configuration shape: explicit per-side allowlist.
|
|
1232
|
-
*/
|
|
1233
|
-
client?: TunnelTaskMiddlewarePolicySideConfig;
|
|
1234
|
-
server?: TunnelTaskMiddlewarePolicySideConfig;
|
|
1235
|
-
/**
|
|
1236
|
-
* Backwards-compatible configuration shape (previous): grouped allowlists.
|
|
1237
|
-
*/
|
|
1238
|
-
middlewareAllowList?: {
|
|
1239
|
-
client?: TunnelMiddlewareId[];
|
|
1240
|
-
server?: TunnelMiddlewareId[];
|
|
1241
|
-
};
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
interface TimeoutMiddlewareConfig {
|
|
1245
|
-
/**
|
|
1246
|
-
* Maximum time in milliseconds before the wrapped operation is aborted
|
|
1247
|
-
* and a timeout error is thrown. Defaults to 5000ms.
|
|
1248
|
-
*/
|
|
1249
|
-
ttl: number;
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
/**
|
|
1253
|
-
* Configuration options for the retry middleware
|
|
1254
|
-
*/
|
|
1255
|
-
interface RetryMiddlewareConfig {
|
|
1256
|
-
/**
|
|
1257
|
-
* Maximum number of retry attempts (default: 3)
|
|
1258
|
-
*/
|
|
1259
|
-
retries?: number;
|
|
1260
|
-
/**
|
|
1261
|
-
* Callback to determine if retry should stop based on error
|
|
1262
|
-
* @default () => false (retry all errors)
|
|
1263
|
-
*/
|
|
1264
|
-
stopRetryIf?: (error: Error) => boolean;
|
|
1265
|
-
/**
|
|
1266
|
-
* Custom delay strategy function
|
|
1267
|
-
* @default Exponential backoff starting at 100ms
|
|
1268
|
-
*/
|
|
1269
|
-
delayStrategy?: (attempt: number, error: Error) => number;
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
interface FallbackMiddlewareConfig {
|
|
1273
|
-
/**
|
|
1274
|
-
* The fallback to use if the task fails.
|
|
1275
|
-
* Can be a value, a function that returns a value (or promise), or another task.
|
|
1276
|
-
*/
|
|
1277
|
-
fallback: any;
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
declare const SemaphoreEvents: {
|
|
1281
|
-
readonly queued: IEvent<SemaphoreEvent>;
|
|
1282
|
-
readonly acquired: IEvent<SemaphoreEvent>;
|
|
1283
|
-
readonly released: IEvent<SemaphoreEvent>;
|
|
1284
|
-
readonly timeout: IEvent<SemaphoreEvent>;
|
|
1285
|
-
readonly aborted: IEvent<SemaphoreEvent>;
|
|
1286
|
-
readonly disposed: IEvent<SemaphoreEvent>;
|
|
1287
|
-
};
|
|
1288
|
-
type SemaphoreEventType = keyof typeof SemaphoreEvents;
|
|
1289
|
-
type SemaphoreEvent = {
|
|
1290
|
-
type: SemaphoreEventType;
|
|
1291
|
-
permits: number;
|
|
1292
|
-
waiting: number;
|
|
1293
|
-
maxPermits: number;
|
|
1294
|
-
disposed: boolean;
|
|
1295
|
-
};
|
|
1296
|
-
/**
|
|
1297
|
-
* A semaphore that limits the number of concurrent operations.
|
|
1298
|
-
* Used to prevent connection pool exhaustion by limiting concurrent
|
|
1299
|
-
* database operations to the pool size.
|
|
1300
|
-
*/
|
|
1301
|
-
declare class Semaphore {
|
|
1302
|
-
private permits;
|
|
1303
|
-
private waitingHead;
|
|
1304
|
-
private waitingTail;
|
|
1305
|
-
private waitingCount;
|
|
1306
|
-
private disposed;
|
|
1307
|
-
private readonly maxPermits;
|
|
1308
|
-
private readonly eventManager;
|
|
1309
|
-
private listenerId;
|
|
1310
|
-
private activeListeners;
|
|
1311
|
-
constructor(maxPermits: number);
|
|
1312
|
-
/**
|
|
1313
|
-
* Acquire a permit. If no permits are available, waits until one becomes available.
|
|
1314
|
-
*/
|
|
1315
|
-
acquire(options?: {
|
|
1316
|
-
timeout?: number;
|
|
1317
|
-
signal?: AbortSignal;
|
|
1318
|
-
}): Promise<void>;
|
|
1319
|
-
/**
|
|
1320
|
-
* Release a permit, allowing waiting operations to proceed.
|
|
1321
|
-
*/
|
|
1322
|
-
release(): void;
|
|
1323
|
-
private removeFromQueue;
|
|
1324
|
-
/**
|
|
1325
|
-
* Execute a function with a permit, automatically releasing it afterwards.
|
|
1326
|
-
*/
|
|
1327
|
-
withPermit<T>(fn: () => Promise<T>, options?: {
|
|
1328
|
-
timeout?: number;
|
|
1329
|
-
signal?: AbortSignal;
|
|
1330
|
-
}): Promise<T>;
|
|
1331
|
-
/**
|
|
1332
|
-
* Dispose the semaphore, rejecting all waiting operations and preventing new ones.
|
|
1333
|
-
*/
|
|
1334
|
-
dispose(): void;
|
|
1335
|
-
/**
|
|
1336
|
-
* Get current number of available permits (for debugging)
|
|
1337
|
-
*/
|
|
1338
|
-
getAvailablePermits(): number;
|
|
1339
|
-
/**
|
|
1340
|
-
* Get current number of waiting operations (for debugging)
|
|
1341
|
-
*/
|
|
1342
|
-
getWaitingCount(): number;
|
|
1343
|
-
/**
|
|
1344
|
-
* Get maximum number of permits
|
|
1345
|
-
*/
|
|
1346
|
-
getMaxPermits(): number;
|
|
1347
|
-
/**
|
|
1348
|
-
* Check if the semaphore has been disposed
|
|
1349
|
-
*/
|
|
1350
|
-
isDisposed(): boolean;
|
|
1351
|
-
/**
|
|
1352
|
-
* Get metrics about the current state of the semaphore
|
|
1353
|
-
*/
|
|
1354
|
-
getMetrics(): {
|
|
1355
|
-
availablePermits: number;
|
|
1356
|
-
waitingCount: number;
|
|
1357
|
-
maxPermits: number;
|
|
1358
|
-
utilization: number;
|
|
1359
|
-
disposed: boolean;
|
|
1360
|
-
};
|
|
1361
|
-
on(type: SemaphoreEventType, handler: (event: SemaphoreEvent) => any): () => void;
|
|
1362
|
-
once(type: SemaphoreEventType, handler: (event: SemaphoreEvent) => any): () => void;
|
|
1363
|
-
private enqueue;
|
|
1364
|
-
private dequeue;
|
|
1365
|
-
private emit;
|
|
1366
|
-
private buildEvent;
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
interface ConcurrencyMiddlewareConfig {
|
|
1370
|
-
/**
|
|
1371
|
-
* Maximum number of concurrent executions.
|
|
1372
|
-
* If provided, a Semaphore will be created and shared for this config object.
|
|
1373
|
-
*/
|
|
1374
|
-
limit?: number;
|
|
1375
|
-
/**
|
|
1376
|
-
* Optional key to identify a shared semaphore.
|
|
1377
|
-
* If provided, the semaphore will be shared across all tasks using the same key.
|
|
1378
|
-
*/
|
|
1379
|
-
key?: string;
|
|
1380
|
-
/**
|
|
1381
|
-
* An existing Semaphore instance to use.
|
|
1382
|
-
*/
|
|
1383
|
-
semaphore?: Semaphore;
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1386
|
-
interface TemporalMiddlewareConfig {
|
|
1387
|
-
ms: number;
|
|
1388
|
-
}
|
|
1389
|
-
interface DebounceState {
|
|
1390
|
-
timeoutId?: NodeJS.Timeout;
|
|
1391
|
-
latestInput?: any;
|
|
1392
|
-
resolveList: ((value: any) => void)[];
|
|
1393
|
-
rejectList: ((error: any) => void)[];
|
|
1394
|
-
}
|
|
1395
|
-
interface ThrottleState {
|
|
1396
|
-
lastExecution: number;
|
|
1397
|
-
timeoutId?: NodeJS.Timeout;
|
|
1398
|
-
latestInput?: any;
|
|
1399
|
-
resolveList: ((value: any) => void)[];
|
|
1400
|
-
rejectList: ((error: any) => void)[];
|
|
1401
|
-
currentPromise?: Promise<any>;
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
/**
|
|
1405
|
-
* States of the Circuit Breaker
|
|
1406
|
-
*/
|
|
1407
|
-
declare enum CircuitBreakerState {
|
|
1408
|
-
CLOSED = "CLOSED",
|
|
1409
|
-
OPEN = "OPEN",
|
|
1410
|
-
HALF_OPEN = "HALF_OPEN"
|
|
1411
|
-
}
|
|
1412
|
-
/**
|
|
1413
|
-
* Configuration for the Circuit Breaker middleware
|
|
1414
|
-
*/
|
|
1415
|
-
interface CircuitBreakerMiddlewareConfig {
|
|
1416
|
-
/**
|
|
1417
|
-
* Number of failures before tripping the circuit
|
|
1418
|
-
* @default 5
|
|
1419
|
-
*/
|
|
1420
|
-
failureThreshold?: number;
|
|
1421
|
-
/**
|
|
1422
|
-
* Time in milliseconds before transitioning from OPEN to HALF_OPEN
|
|
1423
|
-
* @default 30000 (30 seconds)
|
|
1424
|
-
*/
|
|
1425
|
-
resetTimeout?: number;
|
|
1426
|
-
}
|
|
1427
|
-
interface CircuitBreakerStatus {
|
|
1428
|
-
state: CircuitBreakerState;
|
|
1429
|
-
failures: number;
|
|
1430
|
-
lastFailureTime: number;
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
interface RateLimitMiddlewareConfig {
|
|
1434
|
-
/**
|
|
1435
|
-
* Time window in milliseconds
|
|
1436
|
-
*/
|
|
1437
|
-
windowMs: number;
|
|
1438
|
-
/**
|
|
1439
|
-
* Maximum number of requests within the window
|
|
1440
|
-
*/
|
|
1441
|
-
max: number;
|
|
1442
|
-
}
|
|
1443
|
-
interface RateLimitState {
|
|
1444
|
-
count: number;
|
|
1445
|
-
resetTime: number;
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
/**
|
|
1449
|
-
* Options for configuring event listeners.
|
|
1450
|
-
*/
|
|
1451
|
-
interface IEventHandlerOptions<T = any> {
|
|
1452
|
-
order?: number;
|
|
1453
|
-
filter?: (event: IEventEmission<T>) => boolean;
|
|
1454
|
-
/**
|
|
1455
|
-
* Represents the listener ID. Use this to avoid a listener calling itself.
|
|
1456
|
-
*/
|
|
1457
|
-
id?: string;
|
|
1458
|
-
}
|
|
1459
|
-
/**
|
|
1460
|
-
* Interceptor for event emissions.
|
|
1461
|
-
*/
|
|
1462
|
-
type EventEmissionInterceptor = (next: (event: IEventEmission<any>) => Promise<void>, event: IEventEmission<any>) => Promise<void>;
|
|
1463
|
-
/**
|
|
1464
|
-
* Interceptor for hook execution.
|
|
1465
|
-
*/
|
|
1466
|
-
type HookExecutionInterceptor = (next: (hook: IHook<any, any>, event: IEventEmission<any>) => Promise<any>, hook: IHook<any, any>, event: IEventEmission<any>) => Promise<any>;
|
|
1467
|
-
|
|
1468
|
-
/**
|
|
1469
|
-
* EventManager handles event emission, listener registration, and event processing.
|
|
1470
|
-
* It supports both specific event listeners and global listeners that handle all events.
|
|
1471
|
-
* Listeners are processed in order based on their priority.
|
|
1472
|
-
*/
|
|
1473
|
-
declare class EventManager {
|
|
1474
|
-
#private;
|
|
1475
|
-
private listeners;
|
|
1476
|
-
private globalListeners;
|
|
1477
|
-
private cachedMergedListeners;
|
|
1478
|
-
private emissionInterceptors;
|
|
1479
|
-
private hookInterceptors;
|
|
1480
|
-
private readonly registry;
|
|
1481
|
-
private readonly cycleContext;
|
|
1482
|
-
private readonly runtimeEventCycleDetection;
|
|
1483
|
-
constructor(options?: {
|
|
1484
|
-
runtimeEventCycleDetection?: boolean;
|
|
1485
|
-
});
|
|
1486
|
-
/**
|
|
1487
|
-
* Gets the current lock status of the EventManager
|
|
1488
|
-
*/
|
|
1489
|
-
get isLocked(): boolean;
|
|
1490
|
-
/**
|
|
1491
|
-
* Locks the EventManager, preventing any further modifications to listeners
|
|
1492
|
-
*/
|
|
1493
|
-
lock(): void;
|
|
1494
|
-
/**
|
|
1495
|
-
* Emits an event to all registered listeners for that event type.
|
|
1496
|
-
* Listeners are processed in order of priority and can stop event propagation.
|
|
1497
|
-
*
|
|
1498
|
-
* @param eventDefinition - The event definition to emit
|
|
1499
|
-
* @param data - The event payload data
|
|
1500
|
-
* @param source - The source identifier of the event emitter
|
|
1501
|
-
*/
|
|
1502
|
-
emit<TInput>(eventDefinition: IEvent<TInput>, data: TInput, source: string): Promise<void>;
|
|
1503
|
-
/**
|
|
1504
|
-
* Emits an event and returns the final payload.
|
|
1505
|
-
* The payload is taken from the deepest emission object that reached either:
|
|
1506
|
-
* - the base listener executor, or
|
|
1507
|
-
* - an interceptor that short-circuited the emission.
|
|
1508
|
-
*
|
|
1509
|
-
* This enables tunnel transports to return the final payload after local and/or remote delivery.
|
|
1510
|
-
*/
|
|
1511
|
-
emitWithResult<TInput>(eventDefinition: IEvent<TInput>, data: TInput, source: string): Promise<TInput>;
|
|
1512
|
-
private emitAndReturnEmission;
|
|
1513
|
-
/**
|
|
1514
|
-
* Registers an event listener for specific event(s).
|
|
1515
|
-
* Listeners are ordered by priority and executed in ascending order.
|
|
1516
|
-
*
|
|
1517
|
-
* @param event - The event definition(s) to listen for
|
|
1518
|
-
* @param handler - The callback function to handle the event
|
|
1519
|
-
* @param options - Configuration options for the listener
|
|
1520
|
-
*/
|
|
1521
|
-
addListener<T>(event: IEvent<T> | Array<IEvent<T>>, handler: EventHandlerType<T>, options?: IEventHandlerOptions<T>): void;
|
|
1522
|
-
/**
|
|
1523
|
-
* Registers a global event listener that handles all events.
|
|
1524
|
-
* Global listeners are mixed with specific listeners and ordered by priority.
|
|
1525
|
-
*
|
|
1526
|
-
* @param handler - The callback function to handle events
|
|
1527
|
-
* @param options - Configuration options for the listener
|
|
1528
|
-
*/
|
|
1529
|
-
addGlobalListener(handler: EventHandlerType, options?: IEventHandlerOptions): void;
|
|
1530
|
-
/**
|
|
1531
|
-
* Checks if there are any listeners registered for the given event
|
|
1532
|
-
*
|
|
1533
|
-
* @param eventDefinition - The event definition to check
|
|
1534
|
-
* @returns true if listeners exist, false otherwise
|
|
1535
|
-
*/
|
|
1536
|
-
hasListeners<T>(eventDefinition: IEvent<T>): boolean;
|
|
1537
|
-
/**
|
|
1538
|
-
* Adds an interceptor for all event emissions
|
|
1539
|
-
* Interceptors are executed in the order they are added, with the ability to
|
|
1540
|
-
* modify, log, or prevent event emissions
|
|
1541
|
-
*
|
|
1542
|
-
* @param interceptor - The interceptor function to add
|
|
1543
|
-
*/
|
|
1544
|
-
intercept(interceptor: EventEmissionInterceptor): void;
|
|
1545
|
-
/**
|
|
1546
|
-
* Adds an interceptor for hook execution
|
|
1547
|
-
* Interceptors are executed in the order they are added, with the ability to
|
|
1548
|
-
* modify, log, or prevent hook execution
|
|
1549
|
-
*
|
|
1550
|
-
* @param interceptor - The interceptor function to add
|
|
1551
|
-
*/
|
|
1552
|
-
interceptHook(interceptor: HookExecutionInterceptor): void;
|
|
1553
|
-
/**
|
|
1554
|
-
* Executes a hook with all registered hook interceptors applied
|
|
1555
|
-
* This method should be used by TaskRunner when executing hooks
|
|
1556
|
-
*
|
|
1557
|
-
* @param hook - The hook to execute
|
|
1558
|
-
* @param event - The event that triggered the hook
|
|
1559
|
-
* @param computedDependencies - The computed dependencies for the hook
|
|
1560
|
-
* @returns Promise resolving to the hook execution result
|
|
1561
|
-
*/
|
|
1562
|
-
executeHookWithInterceptors(hook: IHook<any, any>, event: IEventEmission<any>, computedDependencies: DependencyValuesType<any>): Promise<any>;
|
|
1563
|
-
/**
|
|
1564
|
-
* Throws an error if the EventManager is locked
|
|
1565
|
-
*/
|
|
1566
|
-
private checkLock;
|
|
1567
|
-
/**
|
|
1568
|
-
* Clears all listeners and interceptors.
|
|
1569
|
-
* Call this to release references and free memory.
|
|
1570
|
-
*/
|
|
1571
|
-
clear(): void;
|
|
1572
|
-
/**
|
|
1573
|
-
* Disposes the EventManager, releasing all listeners and interceptors.
|
|
1574
|
-
* Alias for clear() following the IResource disposal pattern.
|
|
1575
|
-
*/
|
|
1576
|
-
dispose(): void;
|
|
1577
|
-
/**
|
|
1578
|
-
* Retrieves cached merged listeners for an event, or creates them if not cached.
|
|
1579
|
-
* Kept for backward compatibility (tests spy on this).
|
|
1580
|
-
*/
|
|
1581
|
-
private getCachedMergedListeners;
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
type PrintStrategy$1 = "pretty" | "plain" | "json" | "json_pretty";
|
|
1585
|
-
type LogLevels$1 = "trace" | "debug" | "info" | "warn" | "error" | "critical";
|
|
1586
|
-
interface PrintableLog {
|
|
1587
|
-
level: LogLevels$1;
|
|
1588
|
-
source?: string;
|
|
1589
|
-
message: any;
|
|
1590
|
-
timestamp: Date;
|
|
1591
|
-
error?: {
|
|
1592
|
-
name: string;
|
|
1593
|
-
message: string;
|
|
1594
|
-
stack?: string;
|
|
1595
|
-
};
|
|
1596
|
-
data?: Record<string, any>;
|
|
1597
|
-
context?: Record<string, any>;
|
|
1598
|
-
}
|
|
1599
|
-
type ColorTheme = {
|
|
1600
|
-
trace: string;
|
|
1601
|
-
debug: string;
|
|
1602
|
-
info: string;
|
|
1603
|
-
warn: string;
|
|
1604
|
-
error: string;
|
|
1605
|
-
critical: string;
|
|
1606
|
-
reset: string;
|
|
1607
|
-
bold: string;
|
|
1608
|
-
dim: string;
|
|
1609
|
-
blue: string;
|
|
1610
|
-
cyan: string;
|
|
1611
|
-
gray: string;
|
|
1612
|
-
};
|
|
1613
|
-
declare class LogPrinter {
|
|
1614
|
-
private strategy;
|
|
1615
|
-
private colors;
|
|
1616
|
-
constructor(options: {
|
|
1617
|
-
strategy: PrintStrategy$1;
|
|
1618
|
-
useColors: boolean;
|
|
1619
|
-
colorTheme?: Partial<ColorTheme>;
|
|
1620
|
-
});
|
|
1621
|
-
print(log: PrintableLog): void;
|
|
1622
|
-
private pickWriter;
|
|
1623
|
-
private formatTime;
|
|
1624
|
-
private formatLevel;
|
|
1625
|
-
private formatSource;
|
|
1626
|
-
private formatMessage;
|
|
1627
|
-
private formatError;
|
|
1628
|
-
private formatData;
|
|
1629
|
-
private formatContext;
|
|
1630
|
-
private normalizeForJson;
|
|
1631
|
-
private static NO_COLORS;
|
|
1632
|
-
private static readonly DEFAULT_WRITERS;
|
|
1633
|
-
private static writers;
|
|
1634
|
-
static setWriters(writers: Partial<{
|
|
1635
|
-
log: (msg: any) => void;
|
|
1636
|
-
error?: (msg: any) => void;
|
|
1637
|
-
}>): void;
|
|
1638
|
-
static resetWriters(): void;
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1641
|
-
type LogLevels = "trace" | "debug" | "info" | "warn" | "error" | "critical";
|
|
1642
|
-
interface ILogInfo {
|
|
1643
|
-
source?: string;
|
|
1644
|
-
error?: unknown | Error;
|
|
1645
|
-
data?: Record<string, any>;
|
|
1646
|
-
context?: Record<string, any>;
|
|
1647
|
-
[key: string]: any;
|
|
1648
|
-
}
|
|
1649
|
-
interface ILog {
|
|
1650
|
-
level: LogLevels;
|
|
1651
|
-
source?: string;
|
|
1652
|
-
message: any;
|
|
1653
|
-
timestamp: Date;
|
|
1654
|
-
error?: {
|
|
1655
|
-
name: string;
|
|
1656
|
-
message: string;
|
|
1657
|
-
stack?: string;
|
|
1658
|
-
};
|
|
1659
|
-
data?: Record<string, any>;
|
|
1660
|
-
context?: Record<string, any>;
|
|
1661
|
-
}
|
|
1662
|
-
type PrintStrategy = PrintStrategy$1;
|
|
1663
|
-
declare class Logger {
|
|
1664
|
-
private printThreshold;
|
|
1665
|
-
private printStrategy;
|
|
1666
|
-
private bufferLogs;
|
|
1667
|
-
private buffer;
|
|
1668
|
-
private boundContext;
|
|
1669
|
-
private isLocked;
|
|
1670
|
-
private useColors;
|
|
1671
|
-
private printer;
|
|
1672
|
-
private source?;
|
|
1673
|
-
private rootLogger?;
|
|
1674
|
-
localListeners: Array<(log: ILog) => void | Promise<void>>;
|
|
1675
|
-
static Severity: {
|
|
1676
|
-
trace: number;
|
|
1677
|
-
debug: number;
|
|
1678
|
-
info: number;
|
|
1679
|
-
warn: number;
|
|
1680
|
-
error: number;
|
|
1681
|
-
critical: number;
|
|
1682
|
-
};
|
|
1683
|
-
constructor(options: {
|
|
1684
|
-
printThreshold: null | LogLevels;
|
|
1685
|
-
printStrategy: PrintStrategy;
|
|
1686
|
-
bufferLogs: boolean;
|
|
1687
|
-
useColors?: boolean;
|
|
1688
|
-
}, boundContext?: Record<string, any>, source?: string, printer?: LogPrinter);
|
|
1689
|
-
private detectColorSupport;
|
|
1690
|
-
/**
|
|
1691
|
-
* Creates a new logger instance with additional bound context
|
|
1692
|
-
*/
|
|
1693
|
-
with({ source, additionalContext: context, }: {
|
|
1694
|
-
source?: string;
|
|
1695
|
-
additionalContext?: Record<string, any>;
|
|
1696
|
-
}): Logger;
|
|
1697
|
-
/**
|
|
1698
|
-
* Core logging method with structured LogInfo
|
|
1699
|
-
*/
|
|
1700
|
-
log(level: LogLevels, message: any, logInfo?: ILogInfo): Promise<void>;
|
|
1701
|
-
private extractErrorInfo;
|
|
1702
|
-
info(message: any, logInfo?: ILogInfo): Promise<void>;
|
|
1703
|
-
error(message: any, logInfo?: ILogInfo): Promise<void>;
|
|
1704
|
-
warn(message: any, logInfo?: ILogInfo): Promise<void>;
|
|
1705
|
-
debug(message: any, logInfo?: ILogInfo): Promise<void>;
|
|
1706
|
-
trace(message: any, logInfo?: ILogInfo): Promise<void>;
|
|
1707
|
-
critical(message: any, logInfo?: ILogInfo): Promise<void>;
|
|
1708
|
-
/**
|
|
1709
|
-
* Direct print for tests and advanced scenarios. Delegates to LogPrinter.
|
|
1710
|
-
*/
|
|
1711
|
-
print(log: ILog): void;
|
|
1712
|
-
/**
|
|
1713
|
-
* @param listener - A listener that will be triggered for every log.
|
|
1714
|
-
*/
|
|
1715
|
-
onLog(listener: (log: ILog) => any): void;
|
|
1716
|
-
/**
|
|
1717
|
-
* Marks the logger as ready.
|
|
1718
|
-
* This is used to trigger the local listeners and print the buffered logs (if they exists)
|
|
1719
|
-
* @returns A promise that resolves when the logger is ready.
|
|
1720
|
-
*/
|
|
1721
|
-
lock(): Promise<void>;
|
|
1722
|
-
private canPrint;
|
|
1723
|
-
private triggerLogListeners;
|
|
1724
|
-
}
|
|
1725
|
-
|
|
1726
|
-
type ResourceStoreElementType<C = any, V extends Promise<any> = any, D extends DependencyMapType = {}, TContext = any> = {
|
|
1727
|
-
resource: IResource<C, V, D>;
|
|
1728
|
-
computedDependencies?: ResourceDependencyValuesType<D>;
|
|
1729
|
-
config: C;
|
|
1730
|
-
value: V;
|
|
1731
|
-
context: TContext;
|
|
1732
|
-
isInitialized?: boolean;
|
|
1733
|
-
};
|
|
1734
|
-
type TaskStoreElementType<Input = any, Output extends Promise<any> = any, D extends DependencyMapType = any> = {
|
|
1735
|
-
task: ITask<Input, Output, D>;
|
|
1736
|
-
computedDependencies: DependencyValuesType<D>;
|
|
1737
|
-
isInitialized: boolean;
|
|
1738
|
-
interceptors?: Array<TaskLocalInterceptor<any, any>>;
|
|
1739
|
-
};
|
|
1740
|
-
type HookStoreElementType<D extends DependencyMapType = any, TOn extends "*" | IEventDefinition = any> = {
|
|
1741
|
-
hook: IHook<D, TOn>;
|
|
1742
|
-
computedDependencies: DependencyValuesType<D>;
|
|
1743
|
-
};
|
|
1744
|
-
type TaskMiddlewareStoreElementType<TDeps extends DependencyMapType = any> = {
|
|
1745
|
-
middleware: ITaskMiddleware<any, TDeps>;
|
|
1746
|
-
computedDependencies: DependencyValuesType<TDeps>;
|
|
1747
|
-
isInitialized: boolean;
|
|
1748
|
-
};
|
|
1749
|
-
type ResourceMiddlewareStoreElementType<TDeps extends DependencyMapType = any> = {
|
|
1750
|
-
middleware: IResourceMiddleware<any, TDeps>;
|
|
1751
|
-
computedDependencies: DependencyValuesType<TDeps>;
|
|
1752
|
-
isInitialized: boolean;
|
|
1753
|
-
};
|
|
1754
|
-
type EventStoreElementType = {
|
|
1755
|
-
event: IEvent<any>;
|
|
1756
|
-
};
|
|
1757
|
-
|
|
1758
|
-
declare class TaskRunner {
|
|
1759
|
-
protected readonly store: Store;
|
|
1760
|
-
protected readonly eventManager: EventManager;
|
|
1761
|
-
protected readonly logger: Logger;
|
|
1762
|
-
protected readonly runnerStore: Map<string | symbol, (input: any, journal?: ExecutionJournal) => Promise<any>>;
|
|
1763
|
-
constructor(store: Store, eventManager: EventManager, logger: Logger);
|
|
1764
|
-
private readonly middlewareManager;
|
|
1765
|
-
/**
|
|
1766
|
-
* Begins the execution of an task. These are registered tasks and all sanity checks have been performed at this stage to ensure consistency of the object.
|
|
1767
|
-
* This function can throw only if any of the event listeners or run function throws
|
|
1768
|
-
* @param task the task to be run
|
|
1769
|
-
* @param input the input to be passed to the task
|
|
1770
|
-
* @param options optional call options including journal for forwarding
|
|
1771
|
-
*/
|
|
1772
|
-
run<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps>, input?: TInput, options?: TaskCallOptions): Promise<TOutput | undefined>;
|
|
1773
|
-
/**
|
|
1774
|
-
* Creates the function with the chain of middleware.
|
|
1775
|
-
* @param task
|
|
1776
|
-
* @param input
|
|
1777
|
-
* @param taskDependencies
|
|
1778
|
-
* @returns
|
|
1779
|
-
*/
|
|
1780
|
-
protected createRunnerWithMiddleware<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps>): (input: TInput, parentJournal?: ExecutionJournal) => Promise<Awaited<TOutput>>;
|
|
1781
|
-
}
|
|
1782
|
-
|
|
1783
|
-
type UnhandledErrorKind = "process" | "task" | "middleware" | "resourceInit" | "hook" | "run";
|
|
1784
|
-
interface OnUnhandledErrorInfo {
|
|
1785
|
-
error: unknown;
|
|
1786
|
-
kind?: UnhandledErrorKind;
|
|
1787
|
-
source?: string;
|
|
1788
|
-
}
|
|
1789
|
-
type OnUnhandledError = (info: OnUnhandledErrorInfo) => void | Promise<void>;
|
|
1790
|
-
declare function createDefaultUnhandledError(logger: Logger): OnUnhandledError;
|
|
1791
|
-
declare function bindProcessErrorHandler(handler: OnUnhandledError): (error: unknown, source: "uncaughtException" | "unhandledRejection") => void | Promise<void>;
|
|
1792
|
-
declare function safeReportUnhandledError(handler: OnUnhandledError, info: OnUnhandledErrorInfo): Promise<void>;
|
|
1793
|
-
|
|
1794
|
-
/**
|
|
1795
|
-
* Interceptor for task middleware execution
|
|
1796
|
-
*/
|
|
1797
|
-
type TaskMiddlewareInterceptor = (next: (input: ITaskMiddlewareExecutionInput<any>) => Promise<any>, input: ITaskMiddlewareExecutionInput<any>) => Promise<any>;
|
|
1798
|
-
/**
|
|
1799
|
-
* Interceptor for resource middleware execution
|
|
1800
|
-
*/
|
|
1801
|
-
type ResourceMiddlewareInterceptor = (next: (input: IResourceMiddlewareExecutionInput<any>) => Promise<any>, input: IResourceMiddlewareExecutionInput<any>) => Promise<any>;
|
|
1802
|
-
|
|
1803
|
-
/**
|
|
1804
|
-
* Centralizes middleware composition and execution for both tasks and resources.
|
|
1805
|
-
* Keeps observability emissions and unhandled error routing consistent.
|
|
1806
|
-
*
|
|
1807
|
-
* This is a facade that delegates to specialized composer classes for maintainability.
|
|
1808
|
-
*/
|
|
1809
|
-
declare class MiddlewareManager {
|
|
1810
|
-
protected readonly store: Store;
|
|
1811
|
-
protected readonly eventManager: EventManager;
|
|
1812
|
-
protected readonly logger: Logger;
|
|
1813
|
-
private readonly interceptorRegistry;
|
|
1814
|
-
private readonly middlewareResolver;
|
|
1815
|
-
private readonly taskComposer;
|
|
1816
|
-
private readonly resourceComposer;
|
|
1817
|
-
constructor(store: Store, eventManager: EventManager, logger: Logger);
|
|
1818
|
-
/**
|
|
1819
|
-
* @internal
|
|
1820
|
-
*/
|
|
1821
|
-
get taskMiddlewareInterceptors(): TaskMiddlewareInterceptor[];
|
|
1822
|
-
/**
|
|
1823
|
-
* @internal
|
|
1824
|
-
*/
|
|
1825
|
-
get resourceMiddlewareInterceptors(): ResourceMiddlewareInterceptor[];
|
|
1826
|
-
/**
|
|
1827
|
-
* Gets the current lock status of the MiddlewareManager
|
|
1828
|
-
*/
|
|
1829
|
-
get isLocked(): boolean;
|
|
1830
|
-
/**
|
|
1831
|
-
* Locks the MiddlewareManager, preventing any further modifications to interceptors
|
|
1832
|
-
*/
|
|
1833
|
-
lock(): void;
|
|
1834
|
-
/**
|
|
1835
|
-
* Adds an interceptor for task or resource middleware execution
|
|
1836
|
-
* Interceptors are executed in the order they are added, with the ability to
|
|
1837
|
-
* modify, log, or prevent middleware execution
|
|
1838
|
-
*
|
|
1839
|
-
* @param kind - The type of middleware to intercept ("task" or "resource")
|
|
1840
|
-
* @param interceptor - The interceptor function to add
|
|
1841
|
-
*/
|
|
1842
|
-
intercept(kind: "task" | "resource", interceptor: TaskMiddlewareInterceptor | ResourceMiddlewareInterceptor): void;
|
|
1843
|
-
/**
|
|
1844
|
-
* Adds an interceptor for a specific middleware instance with better type safety
|
|
1845
|
-
* This method automatically determines the type and provides type-safe access
|
|
1846
|
-
*
|
|
1847
|
-
* @param middleware - The middleware instance to intercept
|
|
1848
|
-
* @param interceptor - The interceptor function with proper typing
|
|
1849
|
-
*/
|
|
1850
|
-
interceptMiddleware(middleware: ITaskMiddleware<any, any, any, any> | IResourceMiddleware<any, any, any, any>, interceptor: TaskMiddlewareInterceptor | ResourceMiddlewareInterceptor): void;
|
|
1851
|
-
/**
|
|
1852
|
-
* Compose a runner for a task with its local interceptors and applicable middlewares.
|
|
1853
|
-
* Returns a function that accepts the task input and resolves to the task output.
|
|
1854
|
-
*/
|
|
1855
|
-
composeTaskRunner<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps>): (input: TInput, parentJournal?: ExecutionJournal) => Promise<Awaited<TOutput>>;
|
|
1856
|
-
/**
|
|
1857
|
-
* Run a resource init wrapped with its applicable middlewares.
|
|
1858
|
-
*/
|
|
1859
|
-
runResourceInit<C, V extends Promise<any>, D extends DependencyMapType, TContext>(resource: IResource<C, V, D, TContext>, config: C, dependencies: any, context: TContext): Promise<V | undefined>;
|
|
1860
|
-
/**
|
|
1861
|
-
* Gets all "everywhere" middlewares that apply to the given task
|
|
1862
|
-
* @deprecated Internal method exposed for testing - may be removed in future versions
|
|
1863
|
-
*/
|
|
1864
|
-
getEverywhereMiddlewareForTasks(task: ITask<any, any, any>): ITaskMiddleware[];
|
|
1865
|
-
/**
|
|
1866
|
-
* Gets all "everywhere" middlewares that apply to the given resource
|
|
1867
|
-
* @deprecated Internal method exposed for testing - may be removed in future versions
|
|
1868
|
-
*/
|
|
1869
|
-
getEverywhereMiddlewareForResources(resource: IResource<any, any, any, any>): IResourceMiddleware[];
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1872
|
-
/**
|
|
1873
|
-
* Store class which is used to store all the resources, tasks, middleware and events.
|
|
1874
|
-
*/
|
|
1875
|
-
declare class Store {
|
|
1876
|
-
#private;
|
|
1877
|
-
protected readonly eventManager: EventManager;
|
|
1878
|
-
protected readonly logger: Logger;
|
|
1879
|
-
readonly onUnhandledError: OnUnhandledError;
|
|
1880
|
-
root: ResourceStoreElementType;
|
|
1881
|
-
private registry;
|
|
1882
|
-
private overrideManager;
|
|
1883
|
-
private validator;
|
|
1884
|
-
private taskRunner?;
|
|
1885
|
-
private middlewareManager;
|
|
1886
|
-
private readonly initializedResourceIds;
|
|
1887
|
-
mode: RunnerMode;
|
|
1888
|
-
constructor(eventManager: EventManager, logger: Logger, onUnhandledError: OnUnhandledError, mode?: RunnerMode);
|
|
1889
|
-
get tasks(): Map<string, TaskStoreElementType>;
|
|
1890
|
-
get hooks(): Map<string, HookStoreElementType>;
|
|
1891
|
-
get resources(): Map<string, ResourceStoreElementType>;
|
|
1892
|
-
get events(): Map<string, EventStoreElementType>;
|
|
1893
|
-
get errors(): Map<string, IErrorHelper<any>>;
|
|
1894
|
-
get asyncContexts(): Map<string, IAsyncContext<any>>;
|
|
1895
|
-
get taskMiddlewares(): Map<string, TaskMiddlewareStoreElementType>;
|
|
1896
|
-
get resourceMiddlewares(): Map<string, ResourceMiddlewareStoreElementType>;
|
|
1897
|
-
get tags(): Map<string, ITag<void, void, void>>;
|
|
1898
|
-
get overrides(): Map<string, IResourceMiddleware<any, void, void, any> | ITask<any, any, {}, any, TagType[], TaskMiddlewareAttachmentType[]> | IHook<{}, any, any> | IResource<void, Promise<any>, any, any, any, TagType[], ResourceMiddlewareAttachmentType[]> | ITaskMiddleware<any, void, void, any> | IResourceWithConfig<any, Promise<any>, any, any, any, TagType[], IResourceMiddleware<any, void, void, any>[]>>;
|
|
1899
|
-
get overrideRequests(): Set<{
|
|
1900
|
-
source: string;
|
|
1901
|
-
override: RegisterableItems;
|
|
1902
|
-
}>;
|
|
1903
|
-
getMiddlewareManager(): MiddlewareManager;
|
|
1904
|
-
get isLocked(): boolean;
|
|
1905
|
-
lock(): void;
|
|
1906
|
-
checkLock(): void;
|
|
1907
|
-
private registerGlobalComponents;
|
|
1908
|
-
setTaskRunner(taskRunner: TaskRunner): void;
|
|
1909
|
-
private setupRootResource;
|
|
1910
|
-
validateDependencyGraph(): void;
|
|
1911
|
-
validateEventEmissionGraph(): void;
|
|
1912
|
-
initializeStore(root: IResource<any, any, any, any, any>, config: any): void;
|
|
1913
|
-
dispose(): Promise<void>;
|
|
1914
|
-
recordResourceInitialized(resourceId: string): void;
|
|
1915
|
-
private getResourcesInDisposeOrder;
|
|
1916
|
-
/**
|
|
1917
|
-
* Internal, avoid using this method directly.
|
|
1918
|
-
*/
|
|
1919
|
-
processOverrides(): void;
|
|
1920
|
-
/**
|
|
1921
|
-
* Internal, avoid using this method directly.
|
|
1922
|
-
* @param item
|
|
1923
|
-
* @returns
|
|
1924
|
-
*/
|
|
1925
|
-
storeGenericItem<C>(item: RegisterableItems): void;
|
|
1926
|
-
/**
|
|
1927
|
-
* Returns all tasks with the given tag.
|
|
1928
|
-
* @param tag - The tag to filter by.
|
|
1929
|
-
* @returns The tasks with the given tag.
|
|
1930
|
-
*/
|
|
1931
|
-
getTasksWithTag(tag: string | ITag<any, any, any>): ITask<any, any, any, any, TagType[], TaskMiddlewareAttachmentType[]>[];
|
|
1932
|
-
/**
|
|
1933
|
-
* Returns all resources with the given tag.
|
|
1934
|
-
* @param tag - The tag to filter by.
|
|
1935
|
-
* @returns The resources with the given tag.
|
|
1936
|
-
*/
|
|
1937
|
-
getResourcesWithTag(tag: string | ITag<any, any, any>): IResource<any, any, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>[];
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
|
-
declare class ResourceInitializer {
|
|
1941
|
-
protected readonly store: Store;
|
|
1942
|
-
protected readonly eventManager: EventManager;
|
|
1943
|
-
protected readonly logger: Logger;
|
|
1944
|
-
constructor(store: Store, eventManager: EventManager, logger: Logger);
|
|
1945
|
-
private readonly middlewareManager;
|
|
1946
|
-
/**
|
|
1947
|
-
* Begins the execution of an task. These are registered tasks and all sanity checks have been performed at this stage to ensure consistency of the object.
|
|
1948
|
-
* This function can throw only if any of the event listeners or run function throws
|
|
1949
|
-
*/
|
|
1950
|
-
initializeResource<TConfig = null, TValue extends Promise<any> = Promise<any>, TDeps extends DependencyMapType = {}, TContext = any>(resource: IResource<TConfig, TValue, TDeps>, config: TConfig, dependencies: ResourceDependencyValuesType<TDeps>): Promise<{
|
|
1951
|
-
value: TValue | undefined;
|
|
1952
|
-
context: TContext;
|
|
1953
|
-
}>;
|
|
1954
|
-
initWithMiddleware<C, V extends Promise<any>, D extends DependencyMapType, TContext>(resource: IResource<C, V, D, TContext>, config: C, dependencies: ResourceDependencyValuesType<D>, context: TContext): Promise<V | undefined>;
|
|
1955
|
-
}
|
|
1956
|
-
|
|
1957
|
-
/**
|
|
1958
|
-
* Resolves and caches computed dependencies for store items (resources, tasks, middleware, hooks).
|
|
1959
|
-
*/
|
|
1960
|
-
declare class DependencyProcessor {
|
|
1961
|
-
protected readonly store: Store;
|
|
1962
|
-
protected readonly eventManager: EventManager;
|
|
1963
|
-
protected readonly taskRunner: TaskRunner;
|
|
1964
|
-
protected readonly resourceInitializer: ResourceInitializer;
|
|
1965
|
-
protected readonly logger: Logger;
|
|
1966
|
-
constructor(store: Store, eventManager: EventManager, taskRunner: TaskRunner, logger: Logger);
|
|
1967
|
-
/**
|
|
1968
|
-
* Computes and caches dependencies for all registered store items.
|
|
1969
|
-
*/
|
|
1970
|
-
computeAllDependencies(): Promise<void>;
|
|
1971
|
-
private computeTaskDependencies;
|
|
1972
|
-
initializeUninitializedResources(): Promise<void>;
|
|
1973
|
-
private rethrowResourceInitError;
|
|
1974
|
-
/**
|
|
1975
|
-
* Computes and caches dependencies for a resource (if not already computed).
|
|
1976
|
-
*/
|
|
1977
|
-
protected processResourceDependencies<TD extends DependencyMapType>(resource: ResourceStoreElementType<any, any, TD>): Promise<void>;
|
|
1978
|
-
private wrapResourceDependencies;
|
|
1979
|
-
private makeTaskWithIntercept;
|
|
1980
|
-
initializeRoot(): Promise<void>;
|
|
1981
|
-
/**
|
|
1982
|
-
* Attaches listeners for all hooks. Must run before emitting events.
|
|
1983
|
-
*/
|
|
1984
|
-
attachListeners(): void;
|
|
1985
|
-
extractDependencies<T extends DependencyMapType>(map: T, source: string): Promise<DependencyValuesType<T>>;
|
|
1986
|
-
extractDependency(object: any, source: string): Promise<any>;
|
|
1987
|
-
/**
|
|
1988
|
-
* Converts the event into a running functions with real inputs
|
|
1989
|
-
* @param object
|
|
1990
|
-
* @returns
|
|
1991
|
-
*/
|
|
1992
|
-
extractEventDependency(object: IEvent<any>, source: string): (input: any) => Promise<void>;
|
|
1993
|
-
extractTaskDependency(object: ITask<any, any, {}>): Promise<(input: unknown, options?: TaskCallOptions) => Promise<any>>;
|
|
1994
|
-
extractResourceDependency(object: IResource<any, any, any>): Promise<any>;
|
|
1995
|
-
}
|
|
1996
|
-
|
|
1997
|
-
declare const QueueEvents: {
|
|
1998
|
-
readonly enqueue: IEvent<QueueEvent>;
|
|
1999
|
-
readonly start: IEvent<QueueEvent>;
|
|
2000
|
-
readonly finish: IEvent<QueueEvent>;
|
|
2001
|
-
readonly error: IEvent<QueueEvent>;
|
|
2002
|
-
readonly cancel: IEvent<QueueEvent>;
|
|
2003
|
-
readonly disposed: IEvent<QueueEvent>;
|
|
2004
|
-
};
|
|
2005
|
-
type QueueEventType = keyof typeof QueueEvents;
|
|
2006
|
-
type QueueEvent = {
|
|
2007
|
-
type: QueueEventType;
|
|
2008
|
-
taskId: number;
|
|
2009
|
-
disposed: boolean;
|
|
2010
|
-
error?: Error;
|
|
2011
|
-
};
|
|
2012
|
-
/**
|
|
2013
|
-
* Cooperative task queue.
|
|
2014
|
-
* • Tasks run one‑after‑another (FIFO ordering).
|
|
2015
|
-
* • Dead‑lock detection prevents nesting.
|
|
2016
|
-
* • dispose() drains or cancels outstanding tasks, then rejects new ones.
|
|
2017
|
-
*/
|
|
2018
|
-
declare class Queue {
|
|
2019
|
-
private tail;
|
|
2020
|
-
private disposed;
|
|
2021
|
-
private abortController;
|
|
2022
|
-
private readonly eventManager;
|
|
2023
|
-
private nextTaskId;
|
|
2024
|
-
private listenerId;
|
|
2025
|
-
private activeListeners;
|
|
2026
|
-
private readonly executionContext;
|
|
2027
|
-
private readonly hasAsyncLocalStorage;
|
|
2028
|
-
/**
|
|
2029
|
-
* Schedule an asynchronous task.
|
|
2030
|
-
* @param task – receives an AbortSignal so it can cancel early if desired.
|
|
2031
|
-
*/
|
|
2032
|
-
run<T>(task: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
2033
|
-
/**
|
|
2034
|
-
* Disposes the queue.
|
|
2035
|
-
* @param options.cancel – if true, broadcasts AbortSignal to running task.
|
|
2036
|
-
* default: false (waits for tasks to finish).
|
|
2037
|
-
*/
|
|
2038
|
-
dispose(options?: {
|
|
2039
|
-
cancel?: boolean;
|
|
2040
|
-
}): Promise<void>;
|
|
2041
|
-
on(type: QueueEventType, handler: (event: QueueEvent) => any): () => void;
|
|
2042
|
-
once(type: QueueEventType, handler: (event: QueueEvent) => any): () => void;
|
|
2043
|
-
private emit;
|
|
2044
|
-
}
|
|
2045
|
-
|
|
2046
|
-
declare class RunResult<V> {
|
|
2047
|
-
readonly value: V;
|
|
2048
|
-
readonly logger: Logger;
|
|
2049
|
-
readonly store: Store;
|
|
2050
|
-
private readonly eventManager;
|
|
2051
|
-
private readonly taskRunner;
|
|
2052
|
-
private readonly disposeFn;
|
|
2053
|
-
constructor(value: V, logger: Logger, store: Store, eventManager: EventManager, taskRunner: TaskRunner, disposeFn: () => Promise<void>);
|
|
2054
|
-
/**
|
|
2055
|
-
* Run a task within the context of the run result.
|
|
2056
|
-
* @param task - The task to run.
|
|
2057
|
-
* @param args - The arguments to pass to the task.
|
|
2058
|
-
* @returns The result of the task.
|
|
2059
|
-
*/
|
|
2060
|
-
runTask: <I = undefined, O extends Promise<any> = any, D extends DependencyMapType = any>(task: ITask<I, O, D> | string, ...args: I extends undefined | void ? [] : [I]) => Promise<O | undefined>;
|
|
2061
|
-
/**
|
|
2062
|
-
* Emit an event within the context of the run result.
|
|
2063
|
-
* @param event - The event to emit.
|
|
2064
|
-
* @param payload - The payload to emit.
|
|
2065
|
-
*/
|
|
2066
|
-
emitEvent: <P>(event: IEvent<P> | string, payload?: P extends undefined | void ? undefined : P) => Promise<void>;
|
|
2067
|
-
/**
|
|
2068
|
-
* Get the value of a resource from the run result.
|
|
2069
|
-
* @param resource - The resource to get the value of.
|
|
2070
|
-
* @returns The value of the resource.
|
|
2071
|
-
*/
|
|
2072
|
-
getResourceValue: <Output extends Promise<any>>(resource: string | IResource<any, Output, any, any, any>) => Output extends Promise<infer U> ? U : Output;
|
|
2073
|
-
dispose: () => Promise<void>;
|
|
2074
|
-
}
|
|
2075
|
-
|
|
2076
|
-
/**
|
|
2077
|
-
* Define a task.
|
|
2078
|
-
* Generates a strongly-typed task object with id, dependencies,
|
|
2079
|
-
* middleware, and metadata.
|
|
2080
|
-
*
|
|
2081
|
-
* @typeParam Input - Input type accepted by the task's `run` function.
|
|
2082
|
-
* @typeParam Output - Promise type returned by the `run` function.
|
|
2083
|
-
* @typeParam Deps - Dependency map type this task requires.
|
|
2084
|
-
* @typeParam TOn - Event type or "*" this task listens to.
|
|
2085
|
-
* @typeParam TMeta - Arbitrary metadata type carried by the task.
|
|
2086
|
-
* @param taskConfig - The task definition config.
|
|
2087
|
-
* @returns A branded task definition usable by the runner.
|
|
2088
|
-
*/
|
|
2089
|
-
declare function defineTask<Input = undefined, Output extends Promise<any> = any, Deps extends DependencyMapType = any, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]>(taskConfig: ITaskDefinition<Input, Output, Deps, TMeta, TTags, TMiddleware>): ITask<Input, Output, Deps, TMeta, TTags, TMiddleware>;
|
|
2090
|
-
declare namespace defineTask {
|
|
2091
|
-
var phantom: <Input = undefined, Output extends Promise<any> = any>(taskConfig: Omit<ITaskDefinition<Input, Output, any, any, any, any>, "run">) => IPhantomTask<Input, Output, any, any, any, any>;
|
|
2092
|
-
}
|
|
2093
|
-
|
|
2094
|
-
/**
|
|
2095
|
-
* Define a hook (event listeners).
|
|
2096
|
-
* Same shape as task with mandatory `on` and without `middleware`.
|
|
2097
|
-
*/
|
|
2098
|
-
declare function defineHook<D extends DependencyMapType = any, TOn extends "*" | IEventDefinition<any> | readonly IEventDefinition<any>[] = any, TMeta extends ITaskMeta = any>(hookDef: IHookDefinition<D, TOn, TMeta>): IHook<D, TOn, TMeta>;
|
|
2099
|
-
|
|
2100
|
-
declare function defineResource<TConfig = void, TValue extends Promise<any> = Promise<any>, TDeps extends DependencyMapType = {}, TPrivate = any, TMeta extends IResourceMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[] = ResourceMiddlewareAttachmentType[]>(constConfig: IResourceDefinition<TConfig, TValue, TDeps, TPrivate, any, any, TMeta, TTags, TMiddleware>): IResource<TConfig, TValue, TDeps, TPrivate, TMeta, TTags, TMiddleware>;
|
|
2101
|
-
|
|
2102
|
-
declare function defineEvent<TPayload = void>(config: IEventDefinition<TPayload>): IEvent<TPayload>;
|
|
2103
|
-
|
|
2104
|
-
declare function defineTaskMiddleware<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any>(middlewareDef: ITaskMiddlewareDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>): ITaskMiddleware<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
2105
|
-
|
|
2106
|
-
declare function defineResourceMiddleware<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any>(middlewareDef: IResourceMiddlewareDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>): IResourceMiddleware<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
2107
|
-
|
|
2108
|
-
/**
|
|
2109
|
-
* Override helper that preserves the original `id` and returns the same type.
|
|
2110
|
-
* You can override any property except `id`. The override is shallow-merged over the base.
|
|
2111
|
-
*
|
|
2112
|
-
* @param base - The base definition to override.
|
|
2113
|
-
* @param patch - Properties to override (except `id`).
|
|
2114
|
-
* @returns A definition of the same kind with overrides applied.
|
|
2115
|
-
*/
|
|
2116
|
-
type AnyTask = ITask<any, any, any, any, any, any>;
|
|
2117
|
-
type AnyResource = IResource<any, any, any, any, any, any, any>;
|
|
2118
|
-
type AnyTaskMiddleware = ITaskMiddleware<any, any, any, any>;
|
|
2119
|
-
type AnyResourceMiddleware = IResourceMiddleware<any, any, any, any>;
|
|
2120
|
-
type AnyHook = IHook<any, any, any>;
|
|
2121
|
-
type AnyOverrideable = AnyTask | AnyResource | AnyTaskMiddleware | AnyResourceMiddleware | AnyHook;
|
|
2122
|
-
type OverridePatch<TBase extends AnyOverrideable> = Readonly<TBase extends AnyHook ? Omit<Partial<TBase>, "id" | "on"> : Omit<Partial<TBase>, "id">>;
|
|
2123
|
-
declare function defineOverride<TBase extends AnyOverrideable>(base: TBase, patch: OverridePatch<TBase>): TBase;
|
|
2124
|
-
|
|
2125
|
-
/**
|
|
2126
|
-
* Create a tag definition.
|
|
2127
|
-
* - `.with(config)` to create configured instances
|
|
2128
|
-
* - `.extract(tags)` to extract this tag from a list of tags or a taggable's meta
|
|
2129
|
-
*
|
|
2130
|
-
* @typeParam TConfig - Configuration type carried by configured tags.
|
|
2131
|
-
* @typeParam TEnforceContract - Optional helper type to enforce a contract when tags are used.
|
|
2132
|
-
* @param definition - The tag definition (id).
|
|
2133
|
-
* @returns A tag object with helpers to configure and extract.
|
|
2134
|
-
*/
|
|
2135
|
-
declare function defineTag<TConfig = void, TEnforceInputContract = void, TEnforceOutputContract = void>(definition: ITagDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract>): ITag<TConfig, TEnforceInputContract, TEnforceOutputContract>;
|
|
2136
|
-
|
|
2137
|
-
/**
|
|
2138
|
-
* Platform abstraction interface for universal compatibility
|
|
2139
|
-
* Inspired by Remix's approach to Web APIs and runtime-agnostic design
|
|
2140
|
-
*/
|
|
2141
|
-
type PlatformId = "node" | "browser" | "edge" | "universal";
|
|
2142
|
-
interface IPlatformAdapter {
|
|
2143
|
-
readonly id: PlatformId;
|
|
2144
|
-
onUncaughtException(handler: (error: Error) => void): () => void;
|
|
2145
|
-
onUnhandledRejection(handler: (reason: unknown) => void): () => void;
|
|
2146
|
-
onShutdownSignal(handler: () => void): () => void;
|
|
2147
|
-
exit(code: number): void;
|
|
2148
|
-
getEnv(key: string): string | undefined;
|
|
2149
|
-
hasAsyncLocalStorage(): boolean;
|
|
2150
|
-
createAsyncLocalStorage<T>(): IAsyncLocalStorage<T>;
|
|
2151
|
-
setTimeout: typeof globalThis.setTimeout;
|
|
2152
|
-
clearTimeout: typeof globalThis.clearTimeout;
|
|
2153
|
-
init: () => Promise<void>;
|
|
2154
|
-
}
|
|
2155
|
-
interface IAsyncLocalStorage<T> {
|
|
2156
|
-
getStore(): T | undefined;
|
|
2157
|
-
run<R>(store: T, callback: () => R): R;
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
declare function setPlatform(adapter: IPlatformAdapter): void;
|
|
2161
|
-
declare class PlatformAdapter implements IPlatformAdapter {
|
|
2162
|
-
private inner;
|
|
2163
|
-
readonly env: PlatformId;
|
|
2164
|
-
readonly id: PlatformId;
|
|
2165
|
-
constructor(env?: PlatformId);
|
|
2166
|
-
init(): Promise<void>;
|
|
2167
|
-
onUncaughtException(handler: (error: any) => void): () => void;
|
|
2168
|
-
onUnhandledRejection(handler: (reason: any) => void): () => void;
|
|
2169
|
-
onShutdownSignal(handler: () => void): () => void;
|
|
2170
|
-
exit(code: number): void;
|
|
2171
|
-
getEnv(key: string): string | undefined;
|
|
2172
|
-
hasAsyncLocalStorage(): boolean;
|
|
2173
|
-
createAsyncLocalStorage<T>(): IAsyncLocalStorage<T>;
|
|
2174
|
-
setTimeout: typeof setTimeout;
|
|
2175
|
-
clearTimeout: typeof clearTimeout;
|
|
2176
|
-
}
|
|
2177
|
-
|
|
2178
|
-
declare const duplicateRegistrationError: IErrorHelper<{
|
|
2179
|
-
type: string;
|
|
2180
|
-
id: string;
|
|
2181
|
-
} & DefaultErrorType>;
|
|
2182
|
-
declare const dependencyNotFoundError: IErrorHelper<{
|
|
2183
|
-
key: string;
|
|
2184
|
-
} & DefaultErrorType>;
|
|
2185
|
-
declare const unknownItemTypeError: IErrorHelper<{
|
|
2186
|
-
item: unknown;
|
|
2187
|
-
} & DefaultErrorType>;
|
|
2188
|
-
declare const contextError: IErrorHelper<{
|
|
2189
|
-
details?: string;
|
|
2190
|
-
} & DefaultErrorType>;
|
|
2191
|
-
declare const circularDependenciesError: IErrorHelper<{
|
|
2192
|
-
cycles: string[];
|
|
2193
|
-
} & DefaultErrorType>;
|
|
2194
|
-
declare const eventNotFoundError: IErrorHelper<{
|
|
2195
|
-
id: string;
|
|
2196
|
-
} & DefaultErrorType>;
|
|
2197
|
-
declare const resourceNotFoundError: IErrorHelper<{
|
|
2198
|
-
id: string;
|
|
2199
|
-
} & DefaultErrorType>;
|
|
2200
|
-
declare const middlewareNotRegisteredError: IErrorHelper<{
|
|
2201
|
-
type: "task" | "resource";
|
|
2202
|
-
source: string;
|
|
2203
|
-
middlewareId: string;
|
|
2204
|
-
} & DefaultErrorType>;
|
|
2205
|
-
declare const tagNotFoundError: IErrorHelper<{
|
|
2206
|
-
id: string;
|
|
2207
|
-
} & DefaultErrorType>;
|
|
2208
|
-
declare const lockedError: IErrorHelper<{
|
|
2209
|
-
what: string;
|
|
2210
|
-
} & DefaultErrorType>;
|
|
2211
|
-
declare const storeAlreadyInitializedError: IErrorHelper<DefaultErrorType>;
|
|
2212
|
-
declare const validationError: IErrorHelper<{
|
|
2213
|
-
subject: string;
|
|
2214
|
-
id: string;
|
|
2215
|
-
originalError: string | Error;
|
|
2216
|
-
} & DefaultErrorType>;
|
|
2217
|
-
declare const eventCycleError: IErrorHelper<{
|
|
2218
|
-
path: Array<{
|
|
2219
|
-
id: string;
|
|
2220
|
-
source: string;
|
|
2221
|
-
}>;
|
|
2222
|
-
} & DefaultErrorType>;
|
|
2223
|
-
declare const eventEmissionCycleError: IErrorHelper<{
|
|
2224
|
-
cycles: string[];
|
|
2225
|
-
} & DefaultErrorType>;
|
|
2226
|
-
declare const platformUnsupportedFunctionError: IErrorHelper<{
|
|
2227
|
-
functionName: string;
|
|
2228
|
-
} & DefaultErrorType>;
|
|
2229
|
-
declare const cancellationError: IErrorHelper<{
|
|
2230
|
-
reason?: string;
|
|
2231
|
-
} & DefaultErrorType>;
|
|
2232
|
-
declare const tunnelOwnershipConflictError: IErrorHelper<{
|
|
2233
|
-
taskId: string;
|
|
2234
|
-
currentOwnerId: string;
|
|
2235
|
-
attemptedOwnerId: string;
|
|
2236
|
-
} & DefaultErrorType>;
|
|
2237
|
-
declare const phantomTaskNotRoutedError: IErrorHelper<{
|
|
2238
|
-
taskId: string;
|
|
2239
|
-
} & DefaultErrorType>;
|
|
2240
|
-
declare const taskNotRegisteredError: IErrorHelper<{
|
|
2241
|
-
taskId: string;
|
|
2242
|
-
} & DefaultErrorType>;
|
|
2243
|
-
/** Builder types that require validation before build() */
|
|
2244
|
-
type BuilderType = "hook" | "task-middleware" | "resource-middleware";
|
|
2245
|
-
declare const builderIncompleteError: IErrorHelper<{
|
|
2246
|
-
type: BuilderType;
|
|
2247
|
-
builderId: string;
|
|
2248
|
-
missingFields: string[];
|
|
2249
|
-
} & DefaultErrorType>;
|
|
2250
|
-
declare function isCancellationError(err: unknown): boolean;
|
|
2251
|
-
|
|
2252
|
-
type errors_BuilderType = BuilderType;
|
|
2253
|
-
type errors_IErrorHelper<TData extends DefaultErrorType = DefaultErrorType> = IErrorHelper<TData>;
|
|
2254
|
-
declare const errors_builderIncompleteError: typeof builderIncompleteError;
|
|
2255
|
-
declare const errors_cancellationError: typeof cancellationError;
|
|
2256
|
-
declare const errors_circularDependenciesError: typeof circularDependenciesError;
|
|
2257
|
-
declare const errors_contextError: typeof contextError;
|
|
2258
|
-
declare const errors_dependencyNotFoundError: typeof dependencyNotFoundError;
|
|
2259
|
-
declare const errors_duplicateRegistrationError: typeof duplicateRegistrationError;
|
|
2260
|
-
declare const errors_eventCycleError: typeof eventCycleError;
|
|
2261
|
-
declare const errors_eventEmissionCycleError: typeof eventEmissionCycleError;
|
|
2262
|
-
declare const errors_eventNotFoundError: typeof eventNotFoundError;
|
|
2263
|
-
declare const errors_isCancellationError: typeof isCancellationError;
|
|
2264
|
-
declare const errors_lockedError: typeof lockedError;
|
|
2265
|
-
declare const errors_middlewareNotRegisteredError: typeof middlewareNotRegisteredError;
|
|
2266
|
-
declare const errors_phantomTaskNotRoutedError: typeof phantomTaskNotRoutedError;
|
|
2267
|
-
declare const errors_platformUnsupportedFunctionError: typeof platformUnsupportedFunctionError;
|
|
2268
|
-
declare const errors_resourceNotFoundError: typeof resourceNotFoundError;
|
|
2269
|
-
declare const errors_storeAlreadyInitializedError: typeof storeAlreadyInitializedError;
|
|
2270
|
-
declare const errors_tagNotFoundError: typeof tagNotFoundError;
|
|
2271
|
-
declare const errors_taskNotRegisteredError: typeof taskNotRegisteredError;
|
|
2272
|
-
declare const errors_tunnelOwnershipConflictError: typeof tunnelOwnershipConflictError;
|
|
2273
|
-
declare const errors_unknownItemTypeError: typeof unknownItemTypeError;
|
|
2274
|
-
declare const errors_validationError: typeof validationError;
|
|
2275
|
-
declare namespace errors {
|
|
2276
|
-
export { type errors_BuilderType as BuilderType, type errors_IErrorHelper as IErrorHelper, errors_builderIncompleteError as builderIncompleteError, errors_cancellationError as cancellationError, errors_circularDependenciesError as circularDependenciesError, errors_contextError as contextError, errors_dependencyNotFoundError as dependencyNotFoundError, errors_duplicateRegistrationError as duplicateRegistrationError, errors_eventCycleError as eventCycleError, errors_eventEmissionCycleError as eventEmissionCycleError, errors_eventNotFoundError as eventNotFoundError, errors_isCancellationError as isCancellationError, errors_lockedError as lockedError, errors_middlewareNotRegisteredError as middlewareNotRegisteredError, errors_phantomTaskNotRoutedError as phantomTaskNotRoutedError, errors_platformUnsupportedFunctionError as platformUnsupportedFunctionError, errors_resourceNotFoundError as resourceNotFoundError, errors_storeAlreadyInitializedError as storeAlreadyInitializedError, errors_tagNotFoundError as tagNotFoundError, errors_taskNotRegisteredError as taskNotRegisteredError, errors_tunnelOwnershipConflictError as tunnelOwnershipConflictError, errors_unknownItemTypeError as unknownItemTypeError, errors_validationError as validationError };
|
|
2277
|
-
}
|
|
2278
|
-
|
|
2279
|
-
/**
|
|
2280
|
-
* Create a new typed Context. The result contains helpers similar to React’s
|
|
2281
|
-
* Context API but adapted for async usage in Runner.
|
|
2282
|
-
*/
|
|
2283
|
-
declare function defineAsyncContext<T>(def: IAsyncContextDefinition<T>): IAsyncContext<T>;
|
|
2284
|
-
|
|
2285
|
-
/** Convenience creator allowing optional name. Used by tests and legacy API. */
|
|
2286
|
-
/** @deprecated Use defineAsyncContext instead */
|
|
2287
|
-
declare function createContext$1<T>(name?: string): IAsyncContext<T>;
|
|
2288
|
-
|
|
2289
|
-
/**
|
|
2290
|
-
* Helper to create a minimal test harness resource that wraps a root app (or any registerable)
|
|
2291
|
-
* and exposes convenient testing utilities while running the full ecosystem
|
|
2292
|
-
* (registration, overrides, middleware, events) without modifying the core API.
|
|
2293
|
-
* @deprecated Use `run` instead with your testResource, as it provides the necessary toolkit.
|
|
2294
|
-
*/
|
|
2295
|
-
declare function createTestResource(root: RegisterableItems, options?: {
|
|
2296
|
-
overrides?: Array<IResource | ITask | ITaskMiddleware | IResourceMiddleware | IResourceWithConfig>;
|
|
2297
|
-
}): IResource<void, Promise<ReturnType<typeof buildTestFacade>>>;
|
|
2298
|
-
declare function buildTestFacade(deps: {
|
|
2299
|
-
taskRunner: TaskRunner;
|
|
2300
|
-
store: Store;
|
|
2301
|
-
logger: Logger;
|
|
2302
|
-
eventManager: EventManager;
|
|
2303
|
-
}): {
|
|
2304
|
-
runTask: <I, O extends Promise<any>, D extends DependencyMapType>(task: ITask<I, O, D>, ...args: I extends undefined ? [] : [I]) => Promise<Awaited<O> | undefined>;
|
|
2305
|
-
getResource: (id: string) => any;
|
|
2306
|
-
taskRunner: TaskRunner;
|
|
2307
|
-
store: Store;
|
|
2308
|
-
logger: Logger;
|
|
2309
|
-
eventManager: EventManager;
|
|
2310
|
-
};
|
|
2311
|
-
|
|
2312
|
-
type HookOn = "*" | IEventDefinition<any> | readonly IEventDefinition<any>[];
|
|
2313
|
-
interface HookOverrideBuilder<TDeps extends DependencyMapType, TOn extends HookOn, TMeta extends ITaskMeta> {
|
|
2314
|
-
id: string;
|
|
2315
|
-
order(order: number): HookOverrideBuilder<TDeps, TOn, TMeta>;
|
|
2316
|
-
dependencies<TNewDeps extends DependencyMapType, TIsOverride extends boolean = false>(deps: TNewDeps | (() => TNewDeps), options?: {
|
|
2317
|
-
override?: TIsOverride;
|
|
2318
|
-
}): HookOverrideBuilder<TIsOverride extends true ? TNewDeps : TDeps & TNewDeps, TOn, TMeta>;
|
|
2319
|
-
tags<TNewTags extends TagType[]>(t: TNewTags, options?: {
|
|
2320
|
-
override?: boolean;
|
|
2321
|
-
}): HookOverrideBuilder<TDeps, TOn, TMeta>;
|
|
2322
|
-
meta<TNewMeta extends ITaskMeta>(m: TNewMeta): HookOverrideBuilder<TDeps, TOn, TNewMeta>;
|
|
2323
|
-
run(fn: IHookDefinition<TDeps, TOn, TMeta>["run"]): HookOverrideBuilder<TDeps, TOn, TMeta>;
|
|
2324
|
-
build(): IHook<TDeps, TOn, TMeta>;
|
|
2325
|
-
}
|
|
2326
|
-
|
|
2327
|
-
declare function override<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType, TMeta extends ITaskMeta, TTags extends TagType[], TMiddleware extends TaskMiddlewareAttachmentType[]>(base: ITask<TInput, TOutput, TDeps, TMeta, TTags, TMiddleware>): TaskFluentBuilder<TInput, TOutput, TDeps, TMeta, TTags, TMiddleware>;
|
|
2328
|
-
declare function override<TConfig, TValue extends Promise<any>, TDeps extends DependencyMapType, TContext, TMeta extends IResourceMeta, TTags extends TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[]>(base: IResource<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
2329
|
-
declare function override<TDeps extends DependencyMapType, TOn extends HookOn, TMeta extends ITaskMeta>(base: IHook<TDeps, TOn, TMeta>): HookOverrideBuilder<TDeps, TOn, TMeta>;
|
|
2330
|
-
declare function override<C, In, Out, D extends DependencyMapType>(base: ITaskMiddleware<C, In, Out, D>): TaskMiddlewareFluentBuilder<C, In, Out, D>;
|
|
2331
|
-
declare function override<C, In, Out, D extends DependencyMapType>(base: IResourceMiddleware<C, In, Out, D>): ResourceMiddlewareFluentBuilder<C, In, Out, D>;
|
|
2332
|
-
|
|
2333
|
-
type DebugConfig = {
|
|
2334
|
-
logResourceConfig: boolean;
|
|
2335
|
-
logResourceValue: boolean;
|
|
2336
|
-
logResourceBeforeRun: boolean;
|
|
2337
|
-
logResourceAfterRun: boolean;
|
|
2338
|
-
logTaskBeforeRun: boolean;
|
|
2339
|
-
logTaskInput: boolean;
|
|
2340
|
-
logTaskOutput: boolean;
|
|
2341
|
-
logTaskAfterRun: boolean;
|
|
2342
|
-
logMiddlewareBeforeRun: boolean;
|
|
2343
|
-
logMiddlewareAfterRun: boolean;
|
|
2344
|
-
logEventEmissionOnRun: boolean;
|
|
2345
|
-
logEventEmissionInput: boolean;
|
|
2346
|
-
logHookTriggered: boolean;
|
|
2347
|
-
logHookCompleted: boolean;
|
|
2348
|
-
};
|
|
2349
|
-
declare const allFalse: DebugConfig;
|
|
2350
|
-
declare const levelNormal: DebugConfig;
|
|
2351
|
-
declare const levelVerbose: DebugConfig;
|
|
2352
|
-
/**
|
|
2353
|
-
* If you choose to specify your own config, all values will be set to false by default and extended by your config.
|
|
2354
|
-
*/
|
|
2355
|
-
type DebugFriendlyConfig = "normal" | "verbose" | Partial<DebugConfig>;
|
|
2356
|
-
declare const getConfig: (config: DebugFriendlyConfig, taggable?: ITaggable) => DebugConfig;
|
|
2357
|
-
|
|
2358
|
-
declare const debugLevels: {
|
|
2359
|
-
normal: DebugConfig;
|
|
2360
|
-
verbose: DebugConfig;
|
|
2361
|
-
};
|
|
2362
|
-
declare const debug: {
|
|
2363
|
-
levels: {
|
|
2364
|
-
normal: DebugConfig;
|
|
2365
|
-
verbose: DebugConfig;
|
|
2366
|
-
};
|
|
2367
|
-
};
|
|
2368
|
-
|
|
2369
|
-
interface HttpClientAuth {
|
|
2370
|
-
header?: string;
|
|
2371
|
-
token: string;
|
|
2372
|
-
}
|
|
2373
|
-
interface HttpClientConfig {
|
|
2374
|
-
baseUrl: string;
|
|
2375
|
-
auth?: HttpClientAuth;
|
|
2376
|
-
timeoutMs?: number;
|
|
2377
|
-
fetchImpl?: typeof fetch;
|
|
2378
|
-
serializer: SerializerLike;
|
|
2379
|
-
onRequest?: (ctx: {
|
|
2380
|
-
url: string;
|
|
2381
|
-
headers: Record<string, string>;
|
|
2382
|
-
}) => void | Promise<void>;
|
|
2383
|
-
contexts?: Array<IAsyncContext<unknown>>;
|
|
2384
|
-
errorRegistry?: Map<string, IErrorHelper<any>>;
|
|
2385
|
-
}
|
|
2386
|
-
interface HttpClient {
|
|
2387
|
-
task<I = unknown, O = unknown>(id: string, input?: I): Promise<O>;
|
|
2388
|
-
event<P = unknown>(id: string, payload?: P): Promise<void>;
|
|
2389
|
-
eventWithResult?<P = unknown>(id: string, payload?: P): Promise<P>;
|
|
2390
|
-
}
|
|
2391
|
-
declare function createHttpClient(cfg: HttpClientConfig): HttpClient;
|
|
2392
|
-
|
|
2393
|
-
/**
|
|
2394
|
-
* Factory for creating HTTP clients with automatic injection of:
|
|
2395
|
-
* - serializer
|
|
2396
|
-
* - error registry (from Store)
|
|
2397
|
-
* - async contexts (from Store)
|
|
2398
|
-
*
|
|
2399
|
-
* Note: Node streaming clients are exposed via the Node entry only
|
|
2400
|
-
* (see createHttpSmartClient/createHttpMixedClient in `@bluelibs/runner/node`).
|
|
2401
|
-
* Keeping this universal factory browser-safe avoids dynamic imports.
|
|
2402
|
-
*/
|
|
2403
|
-
interface HttpClientFactoryConfig {
|
|
2404
|
-
baseUrl: string;
|
|
2405
|
-
auth?: HttpClientConfig["auth"];
|
|
2406
|
-
timeoutMs?: number;
|
|
2407
|
-
fetchImpl?: typeof fetch;
|
|
2408
|
-
onRequest?: HttpClientConfig["onRequest"];
|
|
2409
|
-
}
|
|
2410
|
-
type HttpClientFactory = (config: HttpClientFactoryConfig) => HttpClient;
|
|
2411
|
-
|
|
2412
|
-
/**
|
|
2413
|
-
* Implementation of ExecutionJournal.
|
|
2414
|
-
* Created per task execution and passed through the middleware chain.
|
|
2415
|
-
*/
|
|
2416
|
-
declare class ExecutionJournalImpl implements ExecutionJournal {
|
|
2417
|
-
private readonly store;
|
|
2418
|
-
/**
|
|
2419
|
-
* Store a value in the journal.
|
|
2420
|
-
* Throws an error if the key already exists unless { override: true } is passed.
|
|
2421
|
-
*/
|
|
2422
|
-
set<T>(key: JournalKey<T>, value: T, options?: JournalSetOptions): void;
|
|
2423
|
-
get<T>(key: JournalKey<T>): T | undefined;
|
|
2424
|
-
has<T>(key: JournalKey<T>): boolean;
|
|
2425
|
-
}
|
|
2426
|
-
/**
|
|
2427
|
-
* Creates a typed journal key for use with ExecutionJournal.
|
|
2428
|
-
*
|
|
2429
|
-
* @example
|
|
2430
|
-
* ```typescript
|
|
2431
|
-
* const abortController = journal.createKey<AbortController>("timeout.abortController");
|
|
2432
|
-
* journal.set(abortController, new AbortController());
|
|
2433
|
-
* const ctrl = journal.get(abortController); // AbortController | undefined
|
|
2434
|
-
* ```
|
|
2435
|
-
*/
|
|
2436
|
-
declare function createKey<T>(id: string): JournalKey<T>;
|
|
2437
|
-
declare const journal: {
|
|
2438
|
-
createKey: typeof createKey;
|
|
2439
|
-
/**
|
|
2440
|
-
* Creates a new empty ExecutionJournal.
|
|
2441
|
-
* Useful when you need to pass a specific journal instance to `runTask` or nested calls.
|
|
2442
|
-
*/
|
|
2443
|
-
create: () => ExecutionJournalImpl;
|
|
2444
|
-
};
|
|
2445
|
-
|
|
2446
|
-
declare const createContext: typeof createContext$1;
|
|
2447
|
-
|
|
2448
|
-
declare const r: Readonly<{
|
|
2449
|
-
resource: typeof resourceBuilder;
|
|
2450
|
-
task: TaskBuilderWithPhantom;
|
|
2451
|
-
event: typeof eventBuilder;
|
|
2452
|
-
hook: typeof hookBuilder;
|
|
2453
|
-
tag: typeof tagBuilder;
|
|
2454
|
-
override: typeof override;
|
|
2455
|
-
asyncContext: typeof asyncContextBuilder;
|
|
2456
|
-
error: typeof errorBuilder;
|
|
2457
|
-
middleware: Readonly<{
|
|
2458
|
-
task: typeof taskMiddlewareBuilder;
|
|
2459
|
-
resource: typeof resourceMiddlewareBuilder;
|
|
2460
|
-
}>;
|
|
2461
|
-
}>;
|
|
2462
|
-
|
|
2463
|
-
type RunOptions = {
|
|
2464
|
-
/**
|
|
2465
|
-
* Defaults to undefined. If true, we introduce logging to the console.
|
|
2466
|
-
*/
|
|
2467
|
-
debug?: DebugFriendlyConfig;
|
|
2468
|
-
/**
|
|
2469
|
-
* Configure logging settings.
|
|
2470
|
-
*/
|
|
2471
|
-
logs?: {
|
|
2472
|
-
/**
|
|
2473
|
-
* Defaults to info. Use null to disable logging.
|
|
2474
|
-
*/
|
|
2475
|
-
printThreshold?: null | LogLevels;
|
|
2476
|
-
/**
|
|
2477
|
-
* Defaults to PRETTY. How to print the logs.
|
|
2478
|
-
*/
|
|
2479
|
-
printStrategy?: PrintStrategy;
|
|
2480
|
-
/**
|
|
2481
|
-
* Defaults to false. If true, we buffer logs until the root resource is ready.
|
|
2482
|
-
* This provides you with the chance to see the logs before the root resource is ready.
|
|
2483
|
-
*/
|
|
2484
|
-
bufferLogs?: boolean;
|
|
2485
|
-
};
|
|
2486
|
-
/**
|
|
2487
|
-
* When true (default), installs a central error boundary that catches uncaught errors
|
|
2488
|
-
* from process-level events and routes them to `onUnhandledError`.
|
|
2489
|
-
*/
|
|
2490
|
-
errorBoundary?: boolean;
|
|
2491
|
-
/**
|
|
2492
|
-
* When true (default), installs SIGINT/SIGTERM handlers that call dispose() on the root allowing for graceful shutdown.
|
|
2493
|
-
*/
|
|
2494
|
-
shutdownHooks?: boolean;
|
|
2495
|
-
/**
|
|
2496
|
-
* Custom handler for any unhandled error caught by Runner. Defaults to logging via the created logger.
|
|
2497
|
-
*/
|
|
2498
|
-
onUnhandledError?: OnUnhandledError;
|
|
2499
|
-
/**
|
|
2500
|
-
* Defaults to false.
|
|
2501
|
-
*
|
|
2502
|
-
* Dry run mode. When true, the runner will setup the system, ensure there are no errors, but will not start the system.
|
|
2503
|
-
* Your resources will not be initialized, and no events will be emitted. This is useful for testing and debugging.
|
|
2504
|
-
*
|
|
2505
|
-
* Note: this cannot catch init() errors that happen within resources.
|
|
2506
|
-
*/
|
|
2507
|
-
dryRun?: boolean;
|
|
2508
|
-
/**
|
|
2509
|
-
* Defaults to true.
|
|
2510
|
-
* When set, forces runtime cycle detection for event emissions. Disable if you're sure
|
|
2511
|
-
* you don't have event deadlocks to improve event emission performance.
|
|
2512
|
-
*/
|
|
2513
|
-
runtimeEventCycleDetection?: boolean;
|
|
2514
|
-
/**
|
|
2515
|
-
* Specify in which mode to run "dev", "prod" or "test".
|
|
2516
|
-
* If inside Node this is automatically detected from the NODE_ENV environment variable if not provided.
|
|
2517
|
-
*/
|
|
2518
|
-
mode?: RunnerMode;
|
|
2519
|
-
};
|
|
2520
|
-
/**
|
|
2521
|
-
* The mode in which the runner is operating
|
|
2522
|
-
*/
|
|
2523
|
-
declare enum RunnerMode {
|
|
2524
|
-
TEST = "test",
|
|
2525
|
-
DEV = "dev",
|
|
2526
|
-
PROD = "prod"
|
|
2527
|
-
}
|
|
2528
|
-
|
|
2529
|
-
interface ICacheInstance {
|
|
2530
|
-
set(key: string, value: any): void;
|
|
2531
|
-
get(key: string): any;
|
|
2532
|
-
clear(): void;
|
|
2533
|
-
/** Optional presence check to disambiguate cached undefined values */
|
|
2534
|
-
has?(key: string): boolean;
|
|
2535
|
-
}
|
|
2536
|
-
|
|
2537
|
-
/**
|
|
2538
|
-
* Core public TypeScript types for BlueLibs Runner.
|
|
2539
|
-
*
|
|
2540
|
-
* This file contains the strongly-typed contract for tasks, resources, events
|
|
2541
|
-
* and middleware. It mirrors the mental model described in the README:
|
|
2542
|
-
* - Tasks are functions
|
|
2543
|
-
* - Resources are singletons (with init/dispose hooks)
|
|
2544
|
-
* - Hooks are event listeners without middleware
|
|
2545
|
-
* - Events are simple, strongly-typed emissions
|
|
2546
|
-
* - Middleware can target both tasks and resources (taskMiddleware, resourceMiddleware)
|
|
2547
|
-
*
|
|
2548
|
-
* DX goals:
|
|
2549
|
-
* - Crystal‑clear generics and helper types that infer dependency shapes
|
|
2550
|
-
* - Friendly JSDoc you can hover in editors to understand usage instantly
|
|
2551
|
-
* - Safe overrides and strong typing around config and register mechanics
|
|
2552
|
-
*/
|
|
2553
|
-
|
|
2554
|
-
type defs_CommonPayload<T extends readonly IEventDefinition<any>[] | IEventDefinition<any>> = CommonPayload<T>;
|
|
2555
|
-
type defs_DefaultErrorType = DefaultErrorType;
|
|
2556
|
-
type defs_DependencyMapType = DependencyMapType;
|
|
2557
|
-
type defs_DependencyValueType<T> = DependencyValueType<T>;
|
|
2558
|
-
type defs_DependencyValuesType<T extends DependencyMapType> = DependencyValuesType<T>;
|
|
2559
|
-
type defs_ErrorReference = ErrorReference;
|
|
2560
|
-
type defs_EventHandlerType<T = any> = EventHandlerType<T>;
|
|
2561
|
-
type defs_EventStoreElementType = EventStoreElementType;
|
|
2562
|
-
type defs_ExtractEventPayload<T> = ExtractEventPayload<T>;
|
|
2563
|
-
type defs_ExtractResourceConfig<T> = ExtractResourceConfig<T>;
|
|
2564
|
-
type defs_ExtractResourceValue<T> = ExtractResourceValue<T>;
|
|
2565
|
-
type defs_ExtractTaskInput<T> = ExtractTaskInput<T>;
|
|
2566
|
-
type defs_ExtractTaskOutput<T> = ExtractTaskOutput<T>;
|
|
2567
|
-
type defs_HookStoreElementType<D extends DependencyMapType = any, TOn extends "*" | IEventDefinition = any> = HookStoreElementType<D, TOn>;
|
|
2568
|
-
type defs_IAsyncContext<T> = IAsyncContext<T>;
|
|
2569
|
-
type defs_IAsyncContextDefinition<T> = IAsyncContextDefinition<T>;
|
|
2570
|
-
type defs_IAsyncContextMeta = IAsyncContextMeta;
|
|
2571
|
-
type defs_ICacheInstance = ICacheInstance;
|
|
2572
|
-
type defs_IErrorDefinition<TData extends DefaultErrorType = DefaultErrorType> = IErrorDefinition<TData>;
|
|
2573
|
-
type defs_IErrorDefinitionFinal<TData extends DefaultErrorType> = IErrorDefinitionFinal<TData>;
|
|
2574
|
-
type defs_IErrorHelper<TData extends DefaultErrorType = DefaultErrorType> = IErrorHelper<TData>;
|
|
2575
|
-
type defs_IErrorMeta = IErrorMeta;
|
|
2576
|
-
type defs_IEvent<TPayload = any> = IEvent<TPayload>;
|
|
2577
|
-
type defs_IEventDefinition<TPayload = void> = IEventDefinition<TPayload>;
|
|
2578
|
-
type defs_IEventEmission<TPayload = any> = IEventEmission<TPayload>;
|
|
2579
|
-
type defs_IEventMeta = IEventMeta;
|
|
2580
|
-
type defs_IHook<TDependencies extends DependencyMapType = {}, TOn extends OnType = any, TMeta extends ITaskMeta = any> = IHook<TDependencies, TOn, TMeta>;
|
|
2581
|
-
type defs_IHookDefinition<TDependencies extends DependencyMapType = {}, TOn extends OnType = any, TMeta extends ITaskMeta = any> = IHookDefinition<TDependencies, TOn, TMeta>;
|
|
2582
|
-
type defs_IMeta = IMeta;
|
|
2583
|
-
type defs_IMiddlewareMeta = IMiddlewareMeta;
|
|
2584
|
-
type defs_IOptionalDependency<T> = IOptionalDependency<T>;
|
|
2585
|
-
type defs_IPhantomTask<TInput = any, TResolved = any, TDependencies extends DependencyMapType = {}, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> = IPhantomTask<TInput, TResolved, TDependencies, TMeta, TTags, TMiddleware>;
|
|
2586
|
-
type defs_IResource<TConfig = void, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = any, TContext = any, TMeta extends IResourceMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[] = ResourceMiddlewareAttachmentType[]> = IResource<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
2587
|
-
type defs_IResourceDefinition<TConfig = any, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = {}, TContext = any, _THooks = any, _TRegisterableItems = any, TMeta extends IResourceMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[] = ResourceMiddlewareAttachmentType[]> = IResourceDefinition<TConfig, TValue, TDependencies, TContext, _THooks, _TRegisterableItems, TMeta, TTags, TMiddleware>;
|
|
2588
|
-
type defs_IResourceMeta = IResourceMeta;
|
|
2589
|
-
type defs_IResourceMiddleware<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> = IResourceMiddleware<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
2590
|
-
type defs_IResourceMiddlewareConfigured<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> = IResourceMiddlewareConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
2591
|
-
type defs_IResourceMiddlewareDefinition<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> = IResourceMiddlewareDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
2592
|
-
type defs_IResourceMiddlewareExecutionInput<TResourceConfig = any, TResourceOutput = any> = IResourceMiddlewareExecutionInput<TResourceConfig, TResourceOutput>;
|
|
2593
|
-
type defs_IResourceWithConfig<TConfig = any, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = any, TContext = any, TMeta extends IResourceMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends IResourceMiddleware<any, any, any, any>[] = IResourceMiddleware[]> = IResourceWithConfig<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
2594
|
-
type defs_ITag<TConfig = void, TEnforceInputContract = void, TEnforceOutputContract = void> = ITag<TConfig, TEnforceInputContract, TEnforceOutputContract>;
|
|
2595
|
-
type defs_ITagConfigured<TConfig = void, TEnforceInputContract = void, TEnforceOutputContract = void> = ITagConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract>;
|
|
2596
|
-
type defs_ITagDefinition<TConfig = void, _TEnforceInputContract = void, _TEnforceOutputContract = void> = ITagDefinition<TConfig, _TEnforceInputContract, _TEnforceOutputContract>;
|
|
2597
|
-
type defs_ITagMeta = ITagMeta;
|
|
2598
|
-
type defs_ITaggable = ITaggable;
|
|
2599
|
-
type defs_ITask<TInput = any, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> = ITask<TInput, TOutput, TDependencies, TMeta, TTags, TMiddleware>;
|
|
2600
|
-
type defs_ITaskDefinition<TInput = undefined, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> = ITaskDefinition<TInput, TOutput, TDependencies, TMeta, TTags, TMiddleware>;
|
|
2601
|
-
type defs_ITaskMeta = ITaskMeta;
|
|
2602
|
-
type defs_ITaskMiddleware<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> = ITaskMiddleware<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
2603
|
-
type defs_ITaskMiddlewareConfigured<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> = ITaskMiddlewareConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
2604
|
-
type defs_ITaskMiddlewareDefinition<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> = ITaskMiddlewareDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
2605
|
-
type defs_ITaskMiddlewareExecutionInput<TTaskInput = any, TTaskOutput = any> = ITaskMiddlewareExecutionInput<TTaskInput, TTaskOutput>;
|
|
2606
|
-
type defs_IValidationSchema<T = any> = IValidationSchema<T>;
|
|
2607
|
-
type defs_OverridableElements = OverridableElements;
|
|
2608
|
-
type defs_RegisterableItems = RegisterableItems;
|
|
2609
|
-
type defs_RequiredKeys<T> = RequiredKeys<T>;
|
|
2610
|
-
type defs_ResourceDependencyValueType<T> = ResourceDependencyValueType<T>;
|
|
2611
|
-
type defs_ResourceDependencyValuesType<T extends DependencyMapType> = ResourceDependencyValuesType<T>;
|
|
2612
|
-
type defs_ResourceForkInfo = ResourceForkInfo;
|
|
2613
|
-
type defs_ResourceForkOptions = ResourceForkOptions;
|
|
2614
|
-
type defs_ResourceForkRegisterMode = ResourceForkRegisterMode;
|
|
2615
|
-
type defs_ResourceInitFn<TConfig, TValue extends Promise<any>, TDependencies extends DependencyMapType, TContext, TMeta extends IResourceMeta, TTags extends TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[]> = ResourceInitFn<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
2616
|
-
type defs_ResourceMiddlewareAttachmentType = ResourceMiddlewareAttachmentType;
|
|
2617
|
-
type defs_ResourceMiddlewareStoreElementType<TDeps extends DependencyMapType = any> = ResourceMiddlewareStoreElementType<TDeps>;
|
|
2618
|
-
type defs_ResourceStoreElementType<C = any, V extends Promise<any> = any, D extends DependencyMapType = {}, TContext = any> = ResourceStoreElementType<C, V, D, TContext>;
|
|
2619
|
-
type defs_RunOptions = RunOptions;
|
|
2620
|
-
type defs_RunnerMode = RunnerMode;
|
|
2621
|
-
declare const defs_RunnerMode: typeof RunnerMode;
|
|
2622
|
-
type defs_TagType = TagType;
|
|
2623
|
-
type defs_TaskCallOptions = TaskCallOptions;
|
|
2624
|
-
type defs_TaskDependencyWithIntercept<TInput, TOutput> = TaskDependencyWithIntercept<TInput, TOutput>;
|
|
2625
|
-
type defs_TaskLocalInterceptor<TInput, TOutput> = TaskLocalInterceptor<TInput, TOutput>;
|
|
2626
|
-
type defs_TaskMiddlewareAttachmentType = TaskMiddlewareAttachmentType;
|
|
2627
|
-
type defs_TaskMiddlewareStoreElementType<TDeps extends DependencyMapType = any> = TaskMiddlewareStoreElementType<TDeps>;
|
|
2628
|
-
type defs_TaskStoreElementType<Input = any, Output extends Promise<any> = any, D extends DependencyMapType = any> = TaskStoreElementType<Input, Output, D>;
|
|
2629
|
-
type defs_ThrowsList = ThrowsList;
|
|
2630
|
-
type defs_UnionToIntersection<U> = UnionToIntersection<U>;
|
|
2631
|
-
declare const defs_isOneOf: typeof isOneOf;
|
|
2632
|
-
declare const defs_onAnyOf: typeof onAnyOf;
|
|
2633
|
-
declare const defs_symbolAsyncContext: typeof symbolAsyncContext;
|
|
2634
|
-
declare const defs_symbolError: typeof symbolError;
|
|
2635
|
-
declare const defs_symbolEvent: typeof symbolEvent;
|
|
2636
|
-
declare const defs_symbolFilePath: typeof symbolFilePath;
|
|
2637
|
-
declare const defs_symbolHook: typeof symbolHook;
|
|
2638
|
-
declare const defs_symbolMiddleware: typeof symbolMiddleware;
|
|
2639
|
-
declare const defs_symbolMiddlewareConfigured: typeof symbolMiddlewareConfigured;
|
|
2640
|
-
declare const defs_symbolOptionalDependency: typeof symbolOptionalDependency;
|
|
2641
|
-
declare const defs_symbolPhantomTask: typeof symbolPhantomTask;
|
|
2642
|
-
declare const defs_symbolResource: typeof symbolResource;
|
|
2643
|
-
declare const defs_symbolResourceForkedFrom: typeof symbolResourceForkedFrom;
|
|
2644
|
-
declare const defs_symbolResourceMiddleware: typeof symbolResourceMiddleware;
|
|
2645
|
-
declare const defs_symbolResourceWithConfig: typeof symbolResourceWithConfig;
|
|
2646
|
-
declare const defs_symbolTag: typeof symbolTag;
|
|
2647
|
-
declare const defs_symbolTagConfigured: typeof symbolTagConfigured;
|
|
2648
|
-
declare const defs_symbolTask: typeof symbolTask;
|
|
2649
|
-
declare const defs_symbolTaskMiddleware: typeof symbolTaskMiddleware;
|
|
2650
|
-
declare const defs_symbolTunneledBy: typeof symbolTunneledBy;
|
|
2651
|
-
declare namespace defs {
|
|
2652
|
-
export { type defs_CommonPayload as CommonPayload, type defs_DefaultErrorType as DefaultErrorType, type defs_DependencyMapType as DependencyMapType, type defs_DependencyValueType as DependencyValueType, type defs_DependencyValuesType as DependencyValuesType, type defs_ErrorReference as ErrorReference, type defs_EventHandlerType as EventHandlerType, type defs_EventStoreElementType as EventStoreElementType, type defs_ExtractEventPayload as ExtractEventPayload, type defs_ExtractResourceConfig as ExtractResourceConfig, type defs_ExtractResourceValue as ExtractResourceValue, type defs_ExtractTaskInput as ExtractTaskInput, type defs_ExtractTaskOutput as ExtractTaskOutput, type defs_HookStoreElementType as HookStoreElementType, type defs_IAsyncContext as IAsyncContext, type defs_IAsyncContextDefinition as IAsyncContextDefinition, type defs_IAsyncContextMeta as IAsyncContextMeta, type defs_ICacheInstance as ICacheInstance, type defs_IErrorDefinition as IErrorDefinition, type defs_IErrorDefinitionFinal as IErrorDefinitionFinal, type defs_IErrorHelper as IErrorHelper, type defs_IErrorMeta as IErrorMeta, type defs_IEvent as IEvent, type defs_IEventDefinition as IEventDefinition, type defs_IEventEmission as IEventEmission, type defs_IEventMeta as IEventMeta, type defs_IHook as IHook, type defs_IHookDefinition as IHookDefinition, type defs_IMeta as IMeta, type defs_IMiddlewareMeta as IMiddlewareMeta, type defs_IOptionalDependency as IOptionalDependency, type defs_IPhantomTask as IPhantomTask, type defs_IResource as IResource, type defs_IResourceDefinition as IResourceDefinition, type defs_IResourceMeta as IResourceMeta, type defs_IResourceMiddleware as IResourceMiddleware, type defs_IResourceMiddlewareConfigured as IResourceMiddlewareConfigured, type defs_IResourceMiddlewareDefinition as IResourceMiddlewareDefinition, type defs_IResourceMiddlewareExecutionInput as IResourceMiddlewareExecutionInput, type defs_IResourceWithConfig as IResourceWithConfig, type defs_ITag as ITag, type defs_ITagConfigured as ITagConfigured, type defs_ITagDefinition as ITagDefinition, type defs_ITagMeta as ITagMeta, type defs_ITaggable as ITaggable, type defs_ITask as ITask, type defs_ITaskDefinition as ITaskDefinition, type defs_ITaskMeta as ITaskMeta, type defs_ITaskMiddleware as ITaskMiddleware, type defs_ITaskMiddlewareConfigured as ITaskMiddlewareConfigured, type defs_ITaskMiddlewareDefinition as ITaskMiddlewareDefinition, type defs_ITaskMiddlewareExecutionInput as ITaskMiddlewareExecutionInput, type defs_IValidationSchema as IValidationSchema, type defs_OverridableElements as OverridableElements, type defs_RegisterableItems as RegisterableItems, type defs_RequiredKeys as RequiredKeys, type defs_ResourceDependencyValueType as ResourceDependencyValueType, type defs_ResourceDependencyValuesType as ResourceDependencyValuesType, type defs_ResourceForkInfo as ResourceForkInfo, type defs_ResourceForkOptions as ResourceForkOptions, type defs_ResourceForkRegisterMode as ResourceForkRegisterMode, type defs_ResourceInitFn as ResourceInitFn, type defs_ResourceMiddlewareAttachmentType as ResourceMiddlewareAttachmentType, type defs_ResourceMiddlewareStoreElementType as ResourceMiddlewareStoreElementType, type defs_ResourceStoreElementType as ResourceStoreElementType, type defs_RunOptions as RunOptions, defs_RunnerMode as RunnerMode, type defs_TagType as TagType, type defs_TaskCallOptions as TaskCallOptions, type defs_TaskDependencyWithIntercept as TaskDependencyWithIntercept, type defs_TaskLocalInterceptor as TaskLocalInterceptor, type defs_TaskMiddlewareAttachmentType as TaskMiddlewareAttachmentType, type defs_TaskMiddlewareStoreElementType as TaskMiddlewareStoreElementType, type defs_TaskStoreElementType as TaskStoreElementType, type defs_ThrowsList as ThrowsList, type defs_UnionToIntersection as UnionToIntersection, defs_isOneOf as isOneOf, defs_onAnyOf as onAnyOf, defs_symbolAsyncContext as symbolAsyncContext, defs_symbolError as symbolError, defs_symbolEvent as symbolEvent, defs_symbolFilePath as symbolFilePath, defs_symbolHook as symbolHook, defs_symbolMiddleware as symbolMiddleware, defs_symbolMiddlewareConfigured as symbolMiddlewareConfigured, defs_symbolOptionalDependency as symbolOptionalDependency, defs_symbolPhantomTask as symbolPhantomTask, defs_symbolResource as symbolResource, defs_symbolResourceForkedFrom as symbolResourceForkedFrom, defs_symbolResourceMiddleware as symbolResourceMiddleware, defs_symbolResourceWithConfig as symbolResourceWithConfig, defs_symbolTag as symbolTag, defs_symbolTagConfigured as symbolTagConfigured, defs_symbolTask as symbolTask, defs_symbolTaskMiddleware as symbolTaskMiddleware, defs_symbolTunneledBy as symbolTunneledBy };
|
|
2653
|
-
}
|
|
2654
|
-
|
|
2655
|
-
type TunnelMode = "client" | "server" | "both" | "none";
|
|
2656
|
-
type TunnelTaskSelector = Array<string | ITask<any, any, any, any, any, any>> | ((task: ITask<any, any, any, any, any, any>) => boolean);
|
|
2657
|
-
type TunnelEventSelector = Array<string | IEvent<any>> | ((event: IEvent<any>) => boolean);
|
|
2658
|
-
type EventDeliveryMode = "mirror" | "remote-only" | "local-only" | "remote-first";
|
|
2659
|
-
interface TunnelTagConfig {
|
|
2660
|
-
}
|
|
2661
|
-
type TunnelTaskRunner = (task: ITask<any, any, any, any, any, any>, input?: any) => Promise<any>;
|
|
2662
|
-
interface TunnelRunner {
|
|
2663
|
-
transport?: "http" | string;
|
|
2664
|
-
mode?: TunnelMode;
|
|
2665
|
-
tasks?: TunnelTaskSelector;
|
|
2666
|
-
events?: TunnelEventSelector;
|
|
2667
|
-
eventDeliveryMode?: EventDeliveryMode;
|
|
2668
|
-
run?: TunnelTaskRunner;
|
|
2669
|
-
emit?: (event: IEventEmission<any>) => Promise<any>;
|
|
2670
|
-
}
|
|
2671
|
-
interface ExposureFetchAuthConfig {
|
|
2672
|
-
header?: string;
|
|
2673
|
-
token: string;
|
|
2674
|
-
}
|
|
2675
|
-
interface ExposureFetchConfig {
|
|
2676
|
-
baseUrl: string;
|
|
2677
|
-
auth?: ExposureFetchAuthConfig;
|
|
2678
|
-
timeoutMs?: number;
|
|
2679
|
-
fetchImpl?: typeof fetch;
|
|
2680
|
-
serializer: SerializerLike;
|
|
2681
|
-
onRequest?: (ctx: {
|
|
2682
|
-
url: string;
|
|
2683
|
-
headers: Record<string, string>;
|
|
2684
|
-
}) => void | Promise<void>;
|
|
2685
|
-
contexts?: Array<IAsyncContext<unknown>>;
|
|
2686
|
-
errorRegistry?: Map<string, IErrorHelper<any>>;
|
|
2687
|
-
}
|
|
2688
|
-
interface ExposureFetchClient {
|
|
2689
|
-
task<I = unknown, O = unknown>(id: string, input?: I): Promise<O>;
|
|
2690
|
-
event<P = unknown>(id: string, payload?: P): Promise<void>;
|
|
2691
|
-
/**
|
|
2692
|
-
* Emits an event and returns the final payload as seen by the remote Runner.
|
|
2693
|
-
* Requires server support; older servers will respond with `{ ok: true }`
|
|
2694
|
-
* without `result`, in which case clients should throw.
|
|
2695
|
-
*/
|
|
2696
|
-
eventWithResult?<P = unknown>(id: string, payload?: P): Promise<P>;
|
|
2697
|
-
}
|
|
2698
|
-
|
|
2699
|
-
declare function normalizeError(input: unknown): Error;
|
|
2700
|
-
|
|
2701
|
-
/**
|
|
2702
|
-
* This functions communicates with the exposure server over HTTP.
|
|
2703
|
-
* It uses the @readmes/TUNNEL_HTTP_POLICY.md strategy.
|
|
2704
|
-
*
|
|
2705
|
-
* @param cfg
|
|
2706
|
-
* @returns
|
|
2707
|
-
*/
|
|
2708
|
-
declare function createExposureFetch(cfg: ExposureFetchConfig): ExposureFetchClient;
|
|
2709
|
-
|
|
2710
|
-
interface HttpClientAuthConfig {
|
|
2711
|
-
header?: string;
|
|
2712
|
-
token: string;
|
|
2713
|
-
}
|
|
2714
|
-
interface HttpCreateClientConfig {
|
|
2715
|
-
url: string;
|
|
2716
|
-
auth?: HttpClientAuthConfig;
|
|
2717
|
-
timeoutMs?: number;
|
|
2718
|
-
fetchImpl?: typeof fetch;
|
|
2719
|
-
serializer: SerializerLike;
|
|
2720
|
-
onRequest?: (ctx: {
|
|
2721
|
-
url: string;
|
|
2722
|
-
headers: Record<string, string>;
|
|
2723
|
-
}) => void | Promise<void>;
|
|
2724
|
-
}
|
|
2725
|
-
|
|
2726
|
-
interface HttpSmartClientAuthConfig {
|
|
2727
|
-
header?: string;
|
|
2728
|
-
token: string;
|
|
2729
|
-
}
|
|
2730
|
-
interface HttpSmartClientConfig {
|
|
2731
|
-
baseUrl: string;
|
|
2732
|
-
auth?: HttpSmartClientAuthConfig;
|
|
2733
|
-
timeoutMs?: number;
|
|
2734
|
-
serializer: SerializerLike;
|
|
2735
|
-
onRequest?: (ctx: {
|
|
2736
|
-
url: string;
|
|
2737
|
-
headers: Record<string, string>;
|
|
2738
|
-
}) => void | Promise<void>;
|
|
2739
|
-
contexts?: Array<IAsyncContext<unknown>>;
|
|
2740
|
-
errorRegistry?: Map<string, IErrorHelper<any>>;
|
|
2741
|
-
}
|
|
2742
|
-
interface HttpSmartClient {
|
|
2743
|
-
task<I = unknown, O = unknown>(id: string, input?: I): Promise<O | Readable>;
|
|
2744
|
-
event<P = unknown>(id: string, payload?: P): Promise<void>;
|
|
2745
|
-
eventWithResult?<P = unknown>(id: string, payload?: P): Promise<P>;
|
|
2746
|
-
}
|
|
2747
|
-
declare function createHttpSmartClient(cfg: HttpSmartClientConfig): HttpSmartClient;
|
|
2748
|
-
|
|
2749
|
-
interface MixedHttpClientAuthConfig {
|
|
2750
|
-
header?: string;
|
|
2751
|
-
token: string;
|
|
2752
|
-
}
|
|
2753
|
-
interface MixedHttpClientConfig {
|
|
2754
|
-
baseUrl: string;
|
|
2755
|
-
auth?: MixedHttpClientAuthConfig;
|
|
2756
|
-
timeoutMs?: number;
|
|
2757
|
-
fetchImpl?: typeof fetch;
|
|
2758
|
-
/**
|
|
2759
|
-
* Forces the Smart client path even for plain JSON inputs.
|
|
2760
|
-
*
|
|
2761
|
-
* Use this when a task may return a stream even when its input is not a stream
|
|
2762
|
-
* and does not include Node File sentinels (ex: download endpoints).
|
|
2763
|
-
*
|
|
2764
|
-
* - `true`: always use Smart for tasks
|
|
2765
|
-
* - predicate: use Smart for selected task ids/inputs
|
|
2766
|
-
*/
|
|
2767
|
-
forceSmart?: boolean | ((ctx: {
|
|
2768
|
-
id: string;
|
|
2769
|
-
input: unknown;
|
|
2770
|
-
}) => boolean | Promise<boolean>);
|
|
2771
|
-
serializer: SerializerLike;
|
|
2772
|
-
onRequest?: (ctx: {
|
|
2773
|
-
url: string;
|
|
2774
|
-
headers: Record<string, string>;
|
|
2775
|
-
}) => void | Promise<void>;
|
|
2776
|
-
contexts?: Array<IAsyncContext<unknown>>;
|
|
2777
|
-
errorRegistry?: Map<string, IErrorHelper<any>>;
|
|
2778
|
-
}
|
|
2779
|
-
interface MixedHttpClient {
|
|
2780
|
-
task<I = unknown, O = unknown>(id: string, input?: I): Promise<O | Readable | ReadableStream<Uint8Array>>;
|
|
2781
|
-
event<P = unknown>(id: string, payload?: P): Promise<void>;
|
|
2782
|
-
eventWithResult?<P = unknown>(id: string, payload?: P): Promise<P>;
|
|
2783
|
-
}
|
|
2784
|
-
/**
|
|
2785
|
-
* Unified Node client that mixes JSON fetch for standard calls and
|
|
2786
|
-
* Smart client for streaming/multipart. Keeps transport details out of app code.
|
|
2787
|
-
*/
|
|
2788
|
-
declare function createHttpMixedClient(cfg: MixedHttpClientConfig): MixedHttpClient;
|
|
2789
|
-
|
|
2790
|
-
interface HttpSmartClientFactoryConfig {
|
|
2791
|
-
baseUrl: string;
|
|
2792
|
-
auth?: {
|
|
2793
|
-
header?: string;
|
|
2794
|
-
token: string;
|
|
2795
|
-
};
|
|
2796
|
-
timeoutMs?: number;
|
|
2797
|
-
onRequest?: (ctx: {
|
|
2798
|
-
url: string;
|
|
2799
|
-
headers: Record<string, string>;
|
|
2800
|
-
}) => void | Promise<void>;
|
|
2801
|
-
}
|
|
2802
|
-
type HttpSmartClientFactory = (config: HttpSmartClientFactoryConfig) => HttpSmartClient;
|
|
2803
|
-
|
|
2804
|
-
interface HttpMixedClientFactoryConfig {
|
|
2805
|
-
baseUrl: string;
|
|
2806
|
-
auth?: {
|
|
2807
|
-
header?: string;
|
|
2808
|
-
token: string;
|
|
2809
|
-
};
|
|
2810
|
-
timeoutMs?: number;
|
|
2811
|
-
fetchImpl?: typeof fetch;
|
|
2812
|
-
onRequest?: (ctx: {
|
|
2813
|
-
url: string;
|
|
2814
|
-
headers: Record<string, string>;
|
|
2815
|
-
}) => void | Promise<void>;
|
|
2816
|
-
}
|
|
2817
|
-
type HttpMixedClientFactory = (config: HttpMixedClientFactoryConfig) => MixedHttpClient;
|
|
2818
|
-
|
|
2819
|
-
declare const globalResources: {
|
|
2820
|
-
readonly store: IResource<void, Promise<Store>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2821
|
-
readonly middlewareManager: IResource<void, Promise<MiddlewareManager>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2822
|
-
readonly eventManager: IResource<void, Promise<EventManager>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2823
|
-
readonly taskRunner: IResource<void, Promise<TaskRunner>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2824
|
-
readonly logger: IResource<void, Promise<Logger>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2825
|
-
readonly serializer: IResource<void, Promise<SerializerLike>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2826
|
-
readonly cache: IResource<{
|
|
2827
|
-
defaultOptions?: any;
|
|
2828
|
-
}, Promise<{
|
|
2829
|
-
map: Map<string, ICacheInstance>;
|
|
2830
|
-
cacheFactoryTask: TaskDependencyWithIntercept<lru_cache.LRUCache.Options<any, any, any>, Promise<ICacheInstance>>;
|
|
2831
|
-
defaultOptions: any;
|
|
2832
|
-
}>, {
|
|
2833
|
-
cacheFactoryTask: ITask<lru_cache.LRUCache.Options<any, any, any>, Promise<ICacheInstance>, any, any, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
2834
|
-
}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2835
|
-
readonly queue: IResource<void, Promise<{
|
|
2836
|
-
map: Map<string, Queue>;
|
|
2837
|
-
run: <T>(id: string, task: (signal: AbortSignal) => Promise<T>) => Promise<T>;
|
|
2838
|
-
}>, {}, {
|
|
2839
|
-
map: Map<string, Queue>;
|
|
2840
|
-
}, {
|
|
2841
|
-
title: string;
|
|
2842
|
-
description: string;
|
|
2843
|
-
}, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2844
|
-
readonly httpClientFactory: IResource<void, Promise<HttpClientFactory>, {
|
|
2845
|
-
serializer: IResource<void, Promise<SerializerLike>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2846
|
-
store: IResource<void, Promise<Store>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2847
|
-
}, any, {
|
|
2848
|
-
title: string;
|
|
2849
|
-
description: string;
|
|
2850
|
-
}, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2851
|
-
readonly rateLimit: IResource<void, Promise<{
|
|
2852
|
-
states: WeakMap<RateLimitMiddlewareConfig, RateLimitState>;
|
|
2853
|
-
}>, {}, any, any, ITag<{
|
|
2854
|
-
metadata?: Record<string, any>;
|
|
2855
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
2856
|
-
readonly circuitBreaker: IResource<void, Promise<{
|
|
2857
|
-
statusMap: Map<string, CircuitBreakerStatus>;
|
|
2858
|
-
}>, {}, any, any, ITag<{
|
|
2859
|
-
metadata?: Record<string, any>;
|
|
2860
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
2861
|
-
readonly temporal: IResource<void, Promise<{
|
|
2862
|
-
debounceStates: WeakMap<TemporalMiddlewareConfig, DebounceState>;
|
|
2863
|
-
throttleStates: WeakMap<TemporalMiddlewareConfig, ThrottleState>;
|
|
2864
|
-
}>, {}, any, any, ITag<{
|
|
2865
|
-
metadata?: Record<string, any>;
|
|
2866
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
2867
|
-
readonly concurrency: IResource<void, Promise<{
|
|
2868
|
-
semaphoresByConfig: WeakMap<ConcurrencyMiddlewareConfig, Semaphore>;
|
|
2869
|
-
semaphoresByKey: Map<string, {
|
|
2870
|
-
semaphore: Semaphore;
|
|
2871
|
-
limit: number;
|
|
2872
|
-
}>;
|
|
2873
|
-
}>, {}, any, any, ITag<{
|
|
2874
|
-
metadata?: Record<string, any>;
|
|
2875
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
2876
|
-
};
|
|
2877
|
-
|
|
2878
|
-
interface NodeExposureHttpAuthConfig {
|
|
2879
|
-
header?: string;
|
|
2880
|
-
token?: string | string[];
|
|
2881
|
-
/**
|
|
2882
|
-
* When true, allows unauthenticated access if no token or validators are configured.
|
|
2883
|
-
* Defaults to false (secure by default - requires explicit auth configuration).
|
|
2884
|
-
*
|
|
2885
|
-
* WARNING: Setting this to true without proper network isolation exposes
|
|
2886
|
-
* all tasks and events to unauthenticated access.
|
|
2887
|
-
*/
|
|
2888
|
-
allowAnonymous?: boolean;
|
|
2889
|
-
}
|
|
2890
|
-
|
|
2891
|
-
interface MultipartLimits {
|
|
2892
|
-
fieldNameSize?: number;
|
|
2893
|
-
fieldSize?: number;
|
|
2894
|
-
fields?: number;
|
|
2895
|
-
fileSize?: number;
|
|
2896
|
-
files?: number;
|
|
2897
|
-
parts?: number;
|
|
2898
|
-
headerPairs?: number;
|
|
2899
|
-
}
|
|
2900
|
-
|
|
2901
|
-
interface JsonLimits {
|
|
2902
|
-
maxSize?: number;
|
|
2903
|
-
}
|
|
2904
|
-
type NodeExposureDependencyMap = {
|
|
2905
|
-
store: typeof globalResources.store;
|
|
2906
|
-
taskRunner: typeof globalResources.taskRunner;
|
|
2907
|
-
eventManager: typeof globalResources.eventManager;
|
|
2908
|
-
logger: typeof globalResources.logger;
|
|
2909
|
-
serializer: typeof globalResources.serializer;
|
|
2910
|
-
};
|
|
2911
|
-
type NodeExposureDeps = ResourceDependencyValuesType<NodeExposureDependencyMap>;
|
|
2912
|
-
interface NodeExposureHttpConfig {
|
|
2913
|
-
basePath?: string;
|
|
2914
|
-
server?: http.Server;
|
|
2915
|
-
listen?: {
|
|
2916
|
-
port: number;
|
|
2917
|
-
host?: string;
|
|
2918
|
-
};
|
|
2919
|
-
auth?: NodeExposureHttpAuthConfig;
|
|
2920
|
-
cors?: NodeExposureHttpCorsConfig;
|
|
2921
|
-
limits?: {
|
|
2922
|
-
json?: JsonLimits;
|
|
2923
|
-
multipart?: MultipartLimits;
|
|
2924
|
-
};
|
|
2925
|
-
/**
|
|
2926
|
-
* Opt out of fail-closed exposure (not recommended).
|
|
2927
|
-
* When true and no server-mode tunnel is registered, exposure is open.
|
|
2928
|
-
*/
|
|
2929
|
-
dangerouslyAllowOpenExposure?: boolean;
|
|
2930
|
-
}
|
|
2931
|
-
interface NodeExposureConfig {
|
|
2932
|
-
http?: NodeExposureHttpConfig;
|
|
2933
|
-
}
|
|
2934
|
-
interface NodeExposureHandlers {
|
|
2935
|
-
handleRequest: (req: IncomingMessage, res: ServerResponse) => Promise<boolean>;
|
|
2936
|
-
handleTask: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
2937
|
-
handleEvent: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
2938
|
-
handleDiscovery: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
2939
|
-
createRequestListener: () => http.RequestListener;
|
|
2940
|
-
createServer: () => http.Server;
|
|
2941
|
-
attachTo: (server: http.Server) => () => void;
|
|
2942
|
-
server?: http.Server | null;
|
|
2943
|
-
basePath: string;
|
|
2944
|
-
close: () => Promise<void>;
|
|
2945
|
-
}
|
|
2946
|
-
interface NodeExposureHttpCorsConfig {
|
|
2947
|
-
/**
|
|
2948
|
-
* Allowed origin(s). When omitted, defaults to "*".
|
|
2949
|
-
* - string: exact origin value to send
|
|
2950
|
-
* - string[]: allow-list; request origin must match an item
|
|
2951
|
-
* - RegExp: allow when test(origin) is true
|
|
2952
|
-
* - function: returns the origin to send or null to disallow
|
|
2953
|
-
*/
|
|
2954
|
-
origin?: string | string[] | RegExp | ((origin: string | undefined) => string | null | undefined);
|
|
2955
|
-
/** Which methods are allowed on preflight; defaults to ["POST", "OPTIONS"]. */
|
|
2956
|
-
methods?: string[];
|
|
2957
|
-
/** Access-Control-Allow-Headers value. If omitted, echoes Access-Control-Request-Headers. */
|
|
2958
|
-
allowedHeaders?: string[];
|
|
2959
|
-
/** Expose response headers for actual requests. */
|
|
2960
|
-
exposedHeaders?: string[];
|
|
2961
|
-
/** Whether to include Access-Control-Allow-Credentials: true. */
|
|
2962
|
-
credentials?: boolean;
|
|
2963
|
-
/** Max age in seconds for preflight caching. */
|
|
2964
|
-
maxAge?: number;
|
|
2965
|
-
/** Whether to append Vary: Origin when a specific origin is returned. Default true. */
|
|
2966
|
-
varyOrigin?: boolean;
|
|
2967
|
-
}
|
|
2968
|
-
|
|
2969
|
-
declare const nodeExposure: IResource<NodeExposureConfig, Promise<NodeExposureHandlers>, {
|
|
2970
|
-
store: IResource<void, Promise<Store>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2971
|
-
taskRunner: IResource<void, Promise<TaskRunner>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2972
|
-
eventManager: IResource<void, Promise<EventManager>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2973
|
-
logger: IResource<void, Promise<Logger>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2974
|
-
serializer: IResource<void, Promise<SerializerLike>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2975
|
-
}, any, {
|
|
2976
|
-
title: string;
|
|
2977
|
-
description: string;
|
|
2978
|
-
}, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2979
|
-
|
|
2980
|
-
interface ExposureRequestContextValue {
|
|
2981
|
-
req: IncomingMessage;
|
|
2982
|
-
res: ServerResponse;
|
|
2983
|
-
url: URL;
|
|
2984
|
-
basePath: string;
|
|
2985
|
-
headers: IncomingMessage["headers"];
|
|
2986
|
-
method?: string;
|
|
2987
|
-
signal: AbortSignal;
|
|
2988
|
-
}
|
|
2989
|
-
declare function useExposureContext(): ExposureRequestContextValue;
|
|
2990
|
-
/**
|
|
2991
|
-
* Checks if the exposure request context is currently available without throwing an error.
|
|
2992
|
-
* Useful for conditional logic in tasks that may or may not be exposed.
|
|
2993
|
-
*/
|
|
2994
|
-
declare function hasExposureContext(): boolean;
|
|
2995
|
-
|
|
2996
|
-
interface InputFileMeta {
|
|
2997
|
-
name: string;
|
|
2998
|
-
type?: string;
|
|
2999
|
-
size?: number;
|
|
3000
|
-
lastModified?: number;
|
|
3001
|
-
extra?: Record<string, unknown>;
|
|
3002
|
-
}
|
|
3003
|
-
/** Universal interface exposed to tasks for streamed files. */
|
|
3004
|
-
interface InputFile<TStream = unknown> extends InputFileMeta {
|
|
3005
|
-
/**
|
|
3006
|
-
* Resolve the underlying stream for one-time consumption.
|
|
3007
|
-
* Implementations must enforce single-use semantics.
|
|
3008
|
-
*/
|
|
3009
|
-
resolve(): Promise<{
|
|
3010
|
-
stream: TStream;
|
|
3011
|
-
}>;
|
|
3012
|
-
/**
|
|
3013
|
-
* Return the underlying stream (single-use). Should throw if already consumed.
|
|
3014
|
-
*/
|
|
3015
|
-
stream(): TStream;
|
|
3016
|
-
/**
|
|
3017
|
-
* Persist the stream to a temporary file on disk and return its path and number of bytes written.
|
|
3018
|
-
*/
|
|
3019
|
-
toTempFile(dir?: string): Promise<{
|
|
3020
|
-
path: string;
|
|
3021
|
-
bytesWritten: number;
|
|
3022
|
-
}>;
|
|
3023
|
-
}
|
|
3024
|
-
/** Client-side sentinel to declare file presence in an input structure. */
|
|
3025
|
-
interface RunnerFileSentinel {
|
|
3026
|
-
$runnerFile: "File";
|
|
3027
|
-
id: string;
|
|
3028
|
-
meta: InputFileMeta;
|
|
3029
|
-
}
|
|
3030
|
-
|
|
3031
|
-
interface NodeFileSource {
|
|
3032
|
-
stream?: Readable;
|
|
3033
|
-
buffer?: Buffer;
|
|
3034
|
-
}
|
|
3035
|
-
declare function createNodeFile(meta: InputFileMeta, source: NodeFileSource, id?: string): RunnerFileSentinel & {
|
|
3036
|
-
_node: NodeFileSource;
|
|
3037
|
-
};
|
|
3038
|
-
|
|
3039
|
-
/**
|
|
3040
|
-
* Read an InputFile's contents fully into memory as a Buffer.
|
|
3041
|
-
* Note: InputFile streams are single-use; this will consume it.
|
|
3042
|
-
*/
|
|
3043
|
-
declare function readInputFileToBuffer(file: InputFile<Readable>): Promise<Buffer>;
|
|
3044
|
-
/**
|
|
3045
|
-
* Write an InputFile's contents to a specific path, returning bytesWritten.
|
|
3046
|
-
* Note: InputFile streams are single-use; this will consume it.
|
|
3047
|
-
*/
|
|
3048
|
-
declare function writeInputFileToPath(file: InputFile<Readable>, targetPath: string): Promise<{
|
|
3049
|
-
bytesWritten: number;
|
|
3050
|
-
}>;
|
|
3051
|
-
|
|
3052
|
-
declare const ExecutionStatus: {
|
|
3053
|
-
readonly Pending: "pending";
|
|
3054
|
-
readonly Running: "running";
|
|
3055
|
-
readonly Retrying: "retrying";
|
|
3056
|
-
readonly Sleeping: "sleeping";
|
|
3057
|
-
readonly Completed: "completed";
|
|
3058
|
-
readonly CompensationFailed: "compensation_failed";
|
|
3059
|
-
readonly Failed: "failed";
|
|
3060
|
-
readonly Cancelled: "cancelled";
|
|
3061
|
-
};
|
|
3062
|
-
type ExecutionStatus = (typeof ExecutionStatus)[keyof typeof ExecutionStatus];
|
|
3063
|
-
interface Execution<TInput = unknown, TResult = unknown> {
|
|
3064
|
-
id: string;
|
|
3065
|
-
taskId: string;
|
|
3066
|
-
input: TInput | undefined;
|
|
3067
|
-
status: ExecutionStatus;
|
|
3068
|
-
result?: TResult;
|
|
3069
|
-
error?: {
|
|
3070
|
-
message: string;
|
|
3071
|
-
stack?: string;
|
|
3072
|
-
};
|
|
3073
|
-
/** Optional cancellation metadata (cooperative cancellation). */
|
|
3074
|
-
cancelledAt?: Date;
|
|
3075
|
-
cancelRequestedAt?: Date;
|
|
3076
|
-
attempt: number;
|
|
3077
|
-
maxAttempts: number;
|
|
3078
|
-
timeout?: number;
|
|
3079
|
-
createdAt: Date;
|
|
3080
|
-
updatedAt: Date;
|
|
3081
|
-
completedAt?: Date;
|
|
3082
|
-
}
|
|
3083
|
-
interface StepResult<T = unknown> {
|
|
3084
|
-
executionId: string;
|
|
3085
|
-
stepId: string;
|
|
3086
|
-
result: T;
|
|
3087
|
-
completedAt: Date;
|
|
3088
|
-
}
|
|
3089
|
-
declare const TimerType: {
|
|
3090
|
-
readonly Sleep: "sleep";
|
|
3091
|
-
readonly Timeout: "timeout";
|
|
3092
|
-
readonly Scheduled: "scheduled";
|
|
3093
|
-
readonly Cron: "cron";
|
|
3094
|
-
readonly Retry: "retry";
|
|
3095
|
-
readonly SignalTimeout: "signal_timeout";
|
|
3096
|
-
};
|
|
3097
|
-
type TimerType = (typeof TimerType)[keyof typeof TimerType];
|
|
3098
|
-
declare const TimerStatus: {
|
|
3099
|
-
readonly Pending: "pending";
|
|
3100
|
-
readonly Fired: "fired";
|
|
3101
|
-
};
|
|
3102
|
-
type TimerStatus = (typeof TimerStatus)[keyof typeof TimerStatus];
|
|
3103
|
-
interface Timer {
|
|
3104
|
-
id: string;
|
|
3105
|
-
executionId?: string;
|
|
3106
|
-
stepId?: string;
|
|
3107
|
-
scheduleId?: string;
|
|
3108
|
-
taskId?: string;
|
|
3109
|
-
input?: unknown;
|
|
3110
|
-
type: TimerType;
|
|
3111
|
-
fireAt: Date;
|
|
3112
|
-
status: TimerStatus;
|
|
3113
|
-
}
|
|
3114
|
-
declare const ScheduleType: {
|
|
3115
|
-
readonly Cron: "cron";
|
|
3116
|
-
readonly Interval: "interval";
|
|
3117
|
-
};
|
|
3118
|
-
type ScheduleType = (typeof ScheduleType)[keyof typeof ScheduleType];
|
|
3119
|
-
declare const ScheduleStatus: {
|
|
3120
|
-
readonly Active: "active";
|
|
3121
|
-
readonly Paused: "paused";
|
|
3122
|
-
};
|
|
3123
|
-
type ScheduleStatus = (typeof ScheduleStatus)[keyof typeof ScheduleStatus];
|
|
3124
|
-
interface Schedule<TInput = unknown> {
|
|
3125
|
-
id: string;
|
|
3126
|
-
taskId: string;
|
|
3127
|
-
type: ScheduleType;
|
|
3128
|
-
pattern: string;
|
|
3129
|
-
input: TInput | undefined;
|
|
3130
|
-
status: ScheduleStatus;
|
|
3131
|
-
lastRun?: Date;
|
|
3132
|
-
nextRun?: Date;
|
|
3133
|
-
createdAt: Date;
|
|
3134
|
-
updatedAt: Date;
|
|
3135
|
-
}
|
|
3136
|
-
|
|
3137
|
-
type DurableSignalId<TPayload = unknown> = IEventDefinition<TPayload>;
|
|
3138
|
-
interface DurableStepId<TResult = unknown> {
|
|
3139
|
-
id: string;
|
|
3140
|
-
/**
|
|
3141
|
-
* Phantom field used only for type inference. Not present at runtime.
|
|
3142
|
-
* The result type is carried through the object type.
|
|
3143
|
-
*/
|
|
3144
|
-
readonly __result?: TResult;
|
|
3145
|
-
}
|
|
3146
|
-
declare function createDurableStepId<TResult>(id: string): DurableStepId<TResult>;
|
|
3147
|
-
|
|
3148
|
-
declare const DurableAuditEntryKind: {
|
|
3149
|
-
readonly ExecutionStatusChanged: "execution_status_changed";
|
|
3150
|
-
readonly StepCompleted: "step_completed";
|
|
3151
|
-
readonly SleepScheduled: "sleep_scheduled";
|
|
3152
|
-
readonly SleepCompleted: "sleep_completed";
|
|
3153
|
-
readonly SignalWaiting: "signal_waiting";
|
|
3154
|
-
readonly SignalDelivered: "signal_delivered";
|
|
3155
|
-
readonly SignalTimedOut: "signal_timed_out";
|
|
3156
|
-
readonly EmitPublished: "emit_published";
|
|
3157
|
-
readonly Note: "note";
|
|
3158
|
-
};
|
|
3159
|
-
type DurableAuditEntryKind = (typeof DurableAuditEntryKind)[keyof typeof DurableAuditEntryKind];
|
|
3160
|
-
interface DurableAuditEntryBase {
|
|
3161
|
-
id: string;
|
|
3162
|
-
executionId: string;
|
|
3163
|
-
at: Date;
|
|
3164
|
-
kind: DurableAuditEntryKind;
|
|
3165
|
-
attempt: number;
|
|
3166
|
-
taskId?: string;
|
|
3167
|
-
}
|
|
3168
|
-
type DurableAuditEntry = (DurableAuditEntryBase & {
|
|
3169
|
-
kind: typeof DurableAuditEntryKind.ExecutionStatusChanged;
|
|
3170
|
-
from: ExecutionStatus | null;
|
|
3171
|
-
to: ExecutionStatus;
|
|
3172
|
-
reason?: string;
|
|
3173
|
-
}) | (DurableAuditEntryBase & {
|
|
3174
|
-
kind: typeof DurableAuditEntryKind.StepCompleted;
|
|
3175
|
-
stepId: string;
|
|
3176
|
-
durationMs: number;
|
|
3177
|
-
isInternal: boolean;
|
|
3178
|
-
}) | (DurableAuditEntryBase & {
|
|
3179
|
-
kind: typeof DurableAuditEntryKind.SleepScheduled;
|
|
3180
|
-
stepId: string;
|
|
3181
|
-
timerId: string;
|
|
3182
|
-
durationMs: number;
|
|
3183
|
-
fireAt: Date;
|
|
3184
|
-
}) | (DurableAuditEntryBase & {
|
|
3185
|
-
kind: typeof DurableAuditEntryKind.SleepCompleted;
|
|
3186
|
-
stepId: string;
|
|
3187
|
-
timerId: string;
|
|
3188
|
-
}) | (DurableAuditEntryBase & {
|
|
3189
|
-
kind: typeof DurableAuditEntryKind.SignalWaiting;
|
|
3190
|
-
stepId: string;
|
|
3191
|
-
signalId: string;
|
|
3192
|
-
timeoutMs?: number;
|
|
3193
|
-
timeoutAtMs?: number;
|
|
3194
|
-
timerId?: string;
|
|
3195
|
-
reason?: "initial" | "timeout_armed";
|
|
3196
|
-
}) | (DurableAuditEntryBase & {
|
|
3197
|
-
kind: typeof DurableAuditEntryKind.SignalDelivered;
|
|
3198
|
-
stepId: string;
|
|
3199
|
-
signalId: string;
|
|
3200
|
-
}) | (DurableAuditEntryBase & {
|
|
3201
|
-
kind: typeof DurableAuditEntryKind.SignalTimedOut;
|
|
3202
|
-
stepId: string;
|
|
3203
|
-
signalId: string;
|
|
3204
|
-
timerId: string;
|
|
3205
|
-
}) | (DurableAuditEntryBase & {
|
|
3206
|
-
kind: typeof DurableAuditEntryKind.EmitPublished;
|
|
3207
|
-
stepId: string;
|
|
3208
|
-
eventId: string;
|
|
3209
|
-
}) | (DurableAuditEntryBase & {
|
|
3210
|
-
kind: typeof DurableAuditEntryKind.Note;
|
|
3211
|
-
message: string;
|
|
3212
|
-
meta?: Record<string, unknown>;
|
|
3213
|
-
});
|
|
3214
|
-
/**
|
|
3215
|
-
* Input type for appendAuditEntry - omits auto-generated fields (id, at).
|
|
3216
|
-
* Preserves the discriminated union for proper type checking at call sites.
|
|
3217
|
-
* executionId and attempt are required for service-level entries but filled by context.
|
|
3218
|
-
*/
|
|
3219
|
-
type DurableAuditEntryInput = {
|
|
3220
|
-
kind: typeof DurableAuditEntryKind.ExecutionStatusChanged;
|
|
3221
|
-
executionId: string;
|
|
3222
|
-
attempt: number;
|
|
3223
|
-
from: ExecutionStatus | null;
|
|
3224
|
-
to: ExecutionStatus;
|
|
3225
|
-
reason?: string;
|
|
3226
|
-
taskId?: string;
|
|
3227
|
-
} | {
|
|
3228
|
-
kind: typeof DurableAuditEntryKind.StepCompleted;
|
|
3229
|
-
stepId: string;
|
|
3230
|
-
durationMs: number;
|
|
3231
|
-
isInternal: boolean;
|
|
3232
|
-
taskId?: string;
|
|
3233
|
-
} | {
|
|
3234
|
-
kind: typeof DurableAuditEntryKind.SleepScheduled;
|
|
3235
|
-
stepId: string;
|
|
3236
|
-
timerId: string;
|
|
3237
|
-
durationMs: number;
|
|
3238
|
-
fireAt: Date;
|
|
3239
|
-
taskId?: string;
|
|
3240
|
-
} | {
|
|
3241
|
-
kind: typeof DurableAuditEntryKind.SleepCompleted;
|
|
3242
|
-
executionId: string;
|
|
3243
|
-
attempt: number;
|
|
3244
|
-
stepId: string;
|
|
3245
|
-
timerId: string;
|
|
3246
|
-
taskId?: string;
|
|
3247
|
-
} | {
|
|
3248
|
-
kind: typeof DurableAuditEntryKind.SignalWaiting;
|
|
3249
|
-
stepId: string;
|
|
3250
|
-
signalId: string;
|
|
3251
|
-
timeoutMs?: number;
|
|
3252
|
-
timeoutAtMs?: number;
|
|
3253
|
-
timerId?: string;
|
|
3254
|
-
reason?: "initial" | "timeout_armed";
|
|
3255
|
-
taskId?: string;
|
|
3256
|
-
} | {
|
|
3257
|
-
kind: typeof DurableAuditEntryKind.SignalDelivered;
|
|
3258
|
-
executionId: string;
|
|
3259
|
-
attempt: number;
|
|
3260
|
-
stepId: string;
|
|
3261
|
-
signalId: string;
|
|
3262
|
-
taskId?: string;
|
|
3263
|
-
} | {
|
|
3264
|
-
kind: typeof DurableAuditEntryKind.SignalTimedOut;
|
|
3265
|
-
executionId: string;
|
|
3266
|
-
attempt: number;
|
|
3267
|
-
stepId: string;
|
|
3268
|
-
signalId: string;
|
|
3269
|
-
timerId: string;
|
|
3270
|
-
taskId?: string;
|
|
3271
|
-
} | {
|
|
3272
|
-
kind: typeof DurableAuditEntryKind.EmitPublished;
|
|
3273
|
-
stepId: string;
|
|
3274
|
-
eventId: string;
|
|
3275
|
-
taskId?: string;
|
|
3276
|
-
} | {
|
|
3277
|
-
kind: typeof DurableAuditEntryKind.Note;
|
|
3278
|
-
message: string;
|
|
3279
|
-
meta?: Record<string, unknown>;
|
|
3280
|
-
taskId?: string;
|
|
3281
|
-
};
|
|
3282
|
-
interface DurableAuditEmitter {
|
|
3283
|
-
emit(entry: DurableAuditEntry): Promise<void>;
|
|
3284
|
-
}
|
|
3285
|
-
declare function isDurableInternalStepId(stepId: string): boolean;
|
|
3286
|
-
declare function createDurableAuditEntryId(atMs?: number): string;
|
|
3287
|
-
|
|
3288
|
-
interface ListExecutionsOptions {
|
|
3289
|
-
status?: ExecutionStatus[];
|
|
3290
|
-
taskId?: string;
|
|
3291
|
-
limit?: number;
|
|
3292
|
-
offset?: number;
|
|
3293
|
-
}
|
|
3294
|
-
interface IDurableStore {
|
|
3295
|
-
saveExecution(execution: Execution): Promise<void>;
|
|
3296
|
-
getExecution(id: string): Promise<Execution | null>;
|
|
3297
|
-
updateExecution(id: string, updates: Partial<Execution>): Promise<void>;
|
|
3298
|
-
listIncompleteExecutions(): Promise<Execution[]>;
|
|
3299
|
-
/**
|
|
3300
|
-
* Optional execution-level idempotency mapping.
|
|
3301
|
-
* If supported, allows `startExecution(..., { idempotencyKey })` to dedupe workflow starts.
|
|
3302
|
-
*/
|
|
3303
|
-
getExecutionIdByIdempotencyKey?(params: {
|
|
3304
|
-
taskId: string;
|
|
3305
|
-
idempotencyKey: string;
|
|
3306
|
-
}): Promise<string | null>;
|
|
3307
|
-
setExecutionIdByIdempotencyKey?(params: {
|
|
3308
|
-
taskId: string;
|
|
3309
|
-
idempotencyKey: string;
|
|
3310
|
-
executionId: string;
|
|
3311
|
-
}): Promise<boolean>;
|
|
3312
|
-
listExecutions?(options?: ListExecutionsOptions): Promise<Execution[]>;
|
|
3313
|
-
listStepResults?(executionId: string): Promise<StepResult[]>;
|
|
3314
|
-
appendAuditEntry?(entry: DurableAuditEntry): Promise<void>;
|
|
3315
|
-
listAuditEntries?(executionId: string, options?: {
|
|
3316
|
-
limit?: number;
|
|
3317
|
-
offset?: number;
|
|
3318
|
-
}): Promise<DurableAuditEntry[]>;
|
|
3319
|
-
retryRollback?(executionId: string): Promise<void>;
|
|
3320
|
-
skipStep?(executionId: string, stepId: string): Promise<void>;
|
|
3321
|
-
forceFail?(executionId: string, error: {
|
|
3322
|
-
message: string;
|
|
3323
|
-
stack?: string;
|
|
3324
|
-
}): Promise<void>;
|
|
3325
|
-
editStepResult?(executionId: string, stepId: string, newResult: unknown): Promise<void>;
|
|
3326
|
-
getStepResult(executionId: string, stepId: string): Promise<StepResult | null>;
|
|
3327
|
-
saveStepResult(result: StepResult): Promise<void>;
|
|
3328
|
-
createTimer(timer: Timer): Promise<void>;
|
|
3329
|
-
getReadyTimers(now?: Date): Promise<Timer[]>;
|
|
3330
|
-
markTimerFired(timerId: string): Promise<void>;
|
|
3331
|
-
/**
|
|
3332
|
-
* Atomically claim a timer for processing. Returns true if claimed, false if already claimed.
|
|
3333
|
-
* Used for distributed timer coordination to ensure only one worker processes each timer.
|
|
3334
|
-
* @param timerId The ID of the timer to claim
|
|
3335
|
-
* @param workerId A unique identifier for the worker claiming the timer
|
|
3336
|
-
* @param ttlMs Time-to-live in milliseconds for the claim (in case worker dies)
|
|
3337
|
-
*/
|
|
3338
|
-
claimTimer?(timerId: string, workerId: string, ttlMs: number): Promise<boolean>;
|
|
3339
|
-
deleteTimer(timerId: string): Promise<void>;
|
|
3340
|
-
createSchedule(schedule: Schedule): Promise<void>;
|
|
3341
|
-
getSchedule(id: string): Promise<Schedule | null>;
|
|
3342
|
-
updateSchedule(id: string, updates: Partial<Schedule>): Promise<void>;
|
|
3343
|
-
deleteSchedule(id: string): Promise<void>;
|
|
3344
|
-
listSchedules(): Promise<Schedule[]>;
|
|
3345
|
-
listActiveSchedules(): Promise<Schedule[]>;
|
|
3346
|
-
listStuckExecutions?(): Promise<Execution[]>;
|
|
3347
|
-
init?(): Promise<void>;
|
|
3348
|
-
dispose?(): Promise<void>;
|
|
3349
|
-
acquireLock?(resource: string, ttlMs: number): Promise<string | null>;
|
|
3350
|
-
releaseLock?(resource: string, lockId: string): Promise<void>;
|
|
3351
|
-
}
|
|
3352
|
-
|
|
3353
|
-
interface QueueMessage<T = unknown> {
|
|
3354
|
-
id: string;
|
|
3355
|
-
type: "execute" | "resume" | "schedule";
|
|
3356
|
-
payload: T;
|
|
3357
|
-
attempts: number;
|
|
3358
|
-
maxAttempts: number;
|
|
3359
|
-
createdAt: Date;
|
|
3360
|
-
}
|
|
3361
|
-
type MessageHandler<T = unknown> = (message: QueueMessage<T>) => Promise<void>;
|
|
3362
|
-
interface IDurableQueue {
|
|
3363
|
-
enqueue<T>(message: Omit<QueueMessage<T>, "id" | "createdAt" | "attempts">): Promise<string>;
|
|
3364
|
-
consume<T>(handler: MessageHandler<T>): Promise<void>;
|
|
3365
|
-
ack(messageId: string): Promise<void>;
|
|
3366
|
-
nack(messageId: string, requeue?: boolean): Promise<void>;
|
|
3367
|
-
init?(): Promise<void>;
|
|
3368
|
-
dispose?(): Promise<void>;
|
|
3369
|
-
}
|
|
3370
|
-
|
|
3371
|
-
interface BusEvent {
|
|
3372
|
-
type: string;
|
|
3373
|
-
payload: unknown;
|
|
3374
|
-
timestamp: Date;
|
|
3375
|
-
}
|
|
3376
|
-
type BusEventHandler = (event: BusEvent) => Promise<void>;
|
|
3377
|
-
interface IEventBus {
|
|
3378
|
-
publish(channel: string, event: BusEvent): Promise<void>;
|
|
3379
|
-
subscribe(channel: string, handler: BusEventHandler): Promise<void>;
|
|
3380
|
-
unsubscribe(channel: string): Promise<void>;
|
|
3381
|
-
init?(): Promise<void>;
|
|
3382
|
-
dispose?(): Promise<void>;
|
|
3383
|
-
}
|
|
3384
|
-
|
|
3385
|
-
interface StepOptions {
|
|
3386
|
-
retries?: number;
|
|
3387
|
-
timeout?: number;
|
|
3388
|
-
}
|
|
3389
|
-
/**
|
|
3390
|
-
* Options for sleep operations.
|
|
3391
|
-
* Use `stepId` to provide a stable identifier that survives code refactoring.
|
|
3392
|
-
*/
|
|
3393
|
-
interface SleepOptions {
|
|
3394
|
-
/** Explicit step ID for replay stability. If not provided, an auto-indexed ID is used. */
|
|
3395
|
-
stepId?: string;
|
|
3396
|
-
}
|
|
3397
|
-
/**
|
|
3398
|
-
* Options for waitForSignal operations.
|
|
3399
|
-
*/
|
|
3400
|
-
interface SignalOptions {
|
|
3401
|
-
/** Timeout in milliseconds. If provided, returns a discriminated union with kind. */
|
|
3402
|
-
timeoutMs?: number;
|
|
3403
|
-
/** Explicit step ID for replay stability. If not provided, an auto-indexed ID is used. */
|
|
3404
|
-
stepId?: string;
|
|
3405
|
-
}
|
|
3406
|
-
/**
|
|
3407
|
-
* Options for emit operations.
|
|
3408
|
-
*/
|
|
3409
|
-
interface EmitOptions {
|
|
3410
|
-
/** Explicit step ID for replay stability. If not provided, an auto-indexed ID is used. */
|
|
3411
|
-
stepId?: string;
|
|
3412
|
-
}
|
|
3413
|
-
interface IStepBuilder<T> extends PromiseLike<T> {
|
|
3414
|
-
up(fn: () => Promise<T>): this;
|
|
3415
|
-
down(fn: (result: T) => Promise<void>): this;
|
|
3416
|
-
}
|
|
3417
|
-
interface IDurableContext {
|
|
3418
|
-
readonly executionId: string;
|
|
3419
|
-
readonly attempt: number;
|
|
3420
|
-
step<T>(stepId: string): IStepBuilder<T>;
|
|
3421
|
-
step<T>(stepId: DurableStepId<T>): IStepBuilder<T>;
|
|
3422
|
-
step<T>(stepId: string, fn: () => Promise<T>): Promise<T>;
|
|
3423
|
-
step<T>(stepId: DurableStepId<T>, fn: () => Promise<T>): Promise<T>;
|
|
3424
|
-
step<T>(stepId: string, options: StepOptions, fn: () => Promise<T>): Promise<T>;
|
|
3425
|
-
step<T>(stepId: DurableStepId<T>, options: StepOptions, fn: () => Promise<T>): Promise<T>;
|
|
3426
|
-
sleep(durationMs: number, options?: SleepOptions): Promise<void>;
|
|
3427
|
-
/**
|
|
3428
|
-
* Suspend until an external signal is delivered via DurableService.signal().
|
|
3429
|
-
* The signal is memoized as a durable step under `__signal:<signalId>[:index]`.
|
|
3430
|
-
* Use options.stepId to provide a stable identifier for replay safety.
|
|
3431
|
-
*/
|
|
3432
|
-
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>): Promise<TPayload>;
|
|
3433
|
-
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>, options: SignalOptions & {
|
|
3434
|
-
timeoutMs: number;
|
|
3435
|
-
}): Promise<{
|
|
3436
|
-
kind: "signal";
|
|
3437
|
-
payload: TPayload;
|
|
3438
|
-
} | {
|
|
3439
|
-
kind: "timeout";
|
|
3440
|
-
}>;
|
|
3441
|
-
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>, options: SignalOptions): Promise<TPayload>;
|
|
3442
|
-
emit<TPayload>(event: IEventDefinition<TPayload>, payload: TPayload, options?: EmitOptions): Promise<void>;
|
|
3443
|
-
/**
|
|
3444
|
-
* Append a custom audit entry for observability and debugging.
|
|
3445
|
-
* This is a no-op if audit is disabled or the store does not support it.
|
|
3446
|
-
*/
|
|
3447
|
-
note(message: string, meta?: Record<string, unknown>): Promise<void>;
|
|
3448
|
-
rollback(): Promise<void>;
|
|
3449
|
-
}
|
|
3450
|
-
/**
|
|
3451
|
-
* Internal control-flow signal used to suspend a durable execution without failing it.
|
|
3452
|
-
*
|
|
3453
|
-
* `DurableContext` throws this error to indicate "pause here and resume later":
|
|
3454
|
-
* - `"sleep"`: durable sleep timer was scheduled
|
|
3455
|
-
* - `"yield"`: waiting for a signal (or signal-timeout timer) to complete
|
|
3456
|
-
*
|
|
3457
|
-
* `ExecutionManager` treats this as a normal suspension and will not mark the execution
|
|
3458
|
-
* as failed; instead it schedules a resume via timers/queue depending on configuration.
|
|
3459
|
-
*/
|
|
3460
|
-
declare class SuspensionSignal extends Error {
|
|
3461
|
-
readonly reason: "sleep" | "yield" | "timeout";
|
|
3462
|
-
constructor(reason: "sleep" | "yield" | "timeout");
|
|
3463
|
-
}
|
|
3464
|
-
|
|
3465
|
-
type DurableTask<TInput = unknown, TResult = unknown> = ITask<TInput, Promise<TResult>, any>;
|
|
3466
|
-
interface ITaskExecutor {
|
|
3467
|
-
run<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput): Promise<TResult>;
|
|
3468
|
-
}
|
|
3469
|
-
interface ScheduleConfig<TInput = unknown> {
|
|
3470
|
-
id: string;
|
|
3471
|
-
task: DurableTask<TInput, unknown>;
|
|
3472
|
-
cron?: string;
|
|
3473
|
-
interval?: number;
|
|
3474
|
-
input: TInput;
|
|
3475
|
-
}
|
|
3476
|
-
interface DurableServiceConfig {
|
|
3477
|
-
store: IDurableStore;
|
|
3478
|
-
queue?: IDurableQueue;
|
|
3479
|
-
eventBus?: IEventBus;
|
|
3480
|
-
taskExecutor?: ITaskExecutor;
|
|
3481
|
-
determinism?: {
|
|
3482
|
-
/**
|
|
3483
|
-
* Internal step IDs for `sleep()`/`emit()`/`waitForSignal()` default to call-order based IDs.
|
|
3484
|
-
* In production this can be a replay/versioning footgun when refactors change call order.
|
|
3485
|
-
*
|
|
3486
|
-
* - "allow" (default): do nothing
|
|
3487
|
-
* - "warn": emit a warning on first implicit internal step per kind
|
|
3488
|
-
* - "error": throw when an implicit internal step id would be used
|
|
3489
|
-
*/
|
|
3490
|
-
implicitInternalStepIds?: "allow" | "warn" | "error";
|
|
3491
|
-
};
|
|
3492
|
-
/**
|
|
3493
|
-
* Unique identifier for this worker instance.
|
|
3494
|
-
* Used for distributed timer coordination to ensure only one worker processes each timer.
|
|
3495
|
-
* If not provided, a random UUID is generated.
|
|
3496
|
-
*/
|
|
3497
|
-
workerId?: string;
|
|
3498
|
-
/**
|
|
3499
|
-
* Runs a callback with the given durable context available.
|
|
3500
|
-
* In Runner environments this is typically implemented via AsyncLocalStorage
|
|
3501
|
-
* so tasks can call `durable.use()`.
|
|
3502
|
-
*/
|
|
3503
|
-
contextProvider?: <R>(context: IDurableContext, fn: () => Promise<R> | R) => Promise<R> | R;
|
|
3504
|
-
/**
|
|
3505
|
-
* Resolves tasks by id for resuming/recovering executions.
|
|
3506
|
-
* Useful in Runner environments where tasks are registered in the Store registry.
|
|
3507
|
-
*/
|
|
3508
|
-
taskResolver?: (taskId: string) => DurableTask<any, any> | undefined;
|
|
3509
|
-
audit?: {
|
|
3510
|
-
enabled?: boolean;
|
|
3511
|
-
emitter?: DurableAuditEmitter;
|
|
3512
|
-
};
|
|
3513
|
-
polling?: {
|
|
3514
|
-
enabled?: boolean;
|
|
3515
|
-
interval?: number;
|
|
3516
|
-
/** Time-to-live for timer claims in milliseconds. Default: 30000. */
|
|
3517
|
-
claimTtlMs?: number;
|
|
3518
|
-
};
|
|
3519
|
-
execution?: {
|
|
3520
|
-
maxAttempts?: number;
|
|
3521
|
-
timeout?: number;
|
|
3522
|
-
/**
|
|
3523
|
-
* When a queue is configured, `startExecution()` persists the execution and then enqueues it.
|
|
3524
|
-
* If enqueue fails (eg. broker outage), the execution would otherwise remain "pending" forever.
|
|
3525
|
-
*
|
|
3526
|
-
* This delay arms a small store-backed timer as a failsafe so workers can retry resuming it
|
|
3527
|
-
* via the poller. Default: 10000 (10s). Set to 0 to disable.
|
|
3528
|
-
*/
|
|
3529
|
-
kickoffFailsafeDelayMs?: number;
|
|
3530
|
-
};
|
|
3531
|
-
schedules?: ScheduleConfig[];
|
|
3532
|
-
tasks?: Array<DurableTask<any, any>>;
|
|
3533
|
-
}
|
|
3534
|
-
interface ExecuteOptions {
|
|
3535
|
-
timeout?: number;
|
|
3536
|
-
priority?: number;
|
|
3537
|
-
waitPollIntervalMs?: number;
|
|
3538
|
-
/**
|
|
3539
|
-
* Optional workflow-level idempotency key.
|
|
3540
|
-
* When supported by the store, multiple concurrent callers using the same key will receive the same executionId.
|
|
3541
|
-
*/
|
|
3542
|
-
idempotencyKey?: string;
|
|
3543
|
-
}
|
|
3544
|
-
interface ScheduleOptions {
|
|
3545
|
-
id?: string;
|
|
3546
|
-
at?: Date;
|
|
3547
|
-
delay?: number;
|
|
3548
|
-
cron?: string;
|
|
3549
|
-
interval?: number;
|
|
3550
|
-
}
|
|
3551
|
-
interface IDurableService {
|
|
3552
|
-
startExecution<TInput>(task: DurableTask<TInput, unknown>, input?: TInput, options?: ExecuteOptions): Promise<string>;
|
|
3553
|
-
/**
|
|
3554
|
-
* Request cancellation for an execution.
|
|
3555
|
-
* Cancellation is cooperative: it marks the execution as cancelled and unblocks waiters,
|
|
3556
|
-
* but cannot preempt arbitrary in-process async work.
|
|
3557
|
-
*/
|
|
3558
|
-
cancelExecution(executionId: string, reason?: string): Promise<void>;
|
|
3559
|
-
wait<TResult>(executionId: string, options?: {
|
|
3560
|
-
timeout?: number;
|
|
3561
|
-
waitPollIntervalMs?: number;
|
|
3562
|
-
}): Promise<TResult>;
|
|
3563
|
-
execute<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3564
|
-
/**
|
|
3565
|
-
* A stricter alternative to `execute()` that rejects tasks whose result type
|
|
3566
|
-
* includes `undefined` (including `void`, `unknown`, and `any`).
|
|
3567
|
-
*
|
|
3568
|
-
* This mirrors the runtime contract where `wait()`/`execute()` treat
|
|
3569
|
-
* "completed without result" as an error.
|
|
3570
|
-
*/
|
|
3571
|
-
executeStrict<TInput, TResult>(task: undefined extends TResult ? never : DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3572
|
-
schedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions): Promise<string>;
|
|
3573
|
-
/**
|
|
3574
|
-
* Idempotently create (or update) a recurring schedule (cron/interval) with a stable id.
|
|
3575
|
-
* Safe to call concurrently from multiple processes.
|
|
3576
|
-
*/
|
|
3577
|
-
ensureSchedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions & {
|
|
3578
|
-
id: string;
|
|
3579
|
-
}): Promise<string>;
|
|
3580
|
-
recover(): Promise<void>;
|
|
3581
|
-
start(): void;
|
|
3582
|
-
stop(): Promise<void>;
|
|
3583
|
-
pauseSchedule(scheduleId: string): Promise<void>;
|
|
3584
|
-
resumeSchedule(scheduleId: string): Promise<void>;
|
|
3585
|
-
getSchedule(scheduleId: string): Promise<Schedule | null>;
|
|
3586
|
-
listSchedules(): Promise<Schedule[]>;
|
|
3587
|
-
updateSchedule(scheduleId: string, updates: {
|
|
3588
|
-
cron?: string;
|
|
3589
|
-
interval?: number;
|
|
3590
|
-
input?: unknown;
|
|
3591
|
-
}): Promise<void>;
|
|
3592
|
-
removeSchedule(scheduleId: string): Promise<void>;
|
|
3593
|
-
/**
|
|
3594
|
-
* Deliver a signal payload to a waiting workflow execution and resume it.
|
|
3595
|
-
*/
|
|
3596
|
-
signal<TPayload>(executionId: string, signal: IEventDefinition<TPayload>, payload: TPayload): Promise<void>;
|
|
3597
|
-
}
|
|
3598
|
-
interface IDurableExecutionProcessor {
|
|
3599
|
-
processExecution(executionId: string): Promise<void>;
|
|
3600
|
-
}
|
|
3601
|
-
|
|
3602
|
-
interface DurableResourceConfig {
|
|
3603
|
-
worker?: boolean;
|
|
3604
|
-
}
|
|
3605
|
-
interface IDurableResource extends Pick<IDurableService, "startExecution" | "cancelExecution" | "wait" | "execute" | "executeStrict" | "schedule" | "ensureSchedule" | "pauseSchedule" | "resumeSchedule" | "getSchedule" | "listSchedules" | "updateSchedule" | "removeSchedule" | "recover" | "signal"> {
|
|
3606
|
-
/**
|
|
3607
|
-
* Reads the durable context for the currently running workflow execution.
|
|
3608
|
-
* Throws if called outside of a durable execution.
|
|
3609
|
-
*/
|
|
3610
|
-
use(): IDurableContext;
|
|
3611
|
-
}
|
|
3612
|
-
/**
|
|
3613
|
-
* A Runner-facing wrapper around `DurableService` that exposes a per-instance
|
|
3614
|
-
* context store and the public durable API (`execute`, `signal`, `wait`, etc.).
|
|
3615
|
-
*
|
|
3616
|
-
* This enables tasks to depend on a specific durable instance and call
|
|
3617
|
-
* `durable.use()` to access the per-execution durable context.
|
|
3618
|
-
*/
|
|
3619
|
-
declare class DurableResource$1 implements IDurableResource {
|
|
3620
|
-
readonly service: IDurableService;
|
|
3621
|
-
private readonly contextStorage;
|
|
3622
|
-
constructor(service: IDurableService, contextStorage: AsyncLocalStorage<IDurableContext>);
|
|
3623
|
-
use(): IDurableContext;
|
|
3624
|
-
startExecution<TInput>(task: DurableTask<TInput, unknown>, input?: TInput, options?: ExecuteOptions): Promise<string>;
|
|
3625
|
-
cancelExecution(executionId: string, reason?: string): Promise<void>;
|
|
3626
|
-
wait<TResult>(executionId: string, options?: {
|
|
3627
|
-
timeout?: number;
|
|
3628
|
-
waitPollIntervalMs?: number;
|
|
3629
|
-
}): Promise<TResult>;
|
|
3630
|
-
execute<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3631
|
-
executeStrict<TInput, TResult>(task: undefined extends TResult ? never : DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3632
|
-
schedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions): Promise<string>;
|
|
3633
|
-
ensureSchedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions & {
|
|
3634
|
-
id: string;
|
|
3635
|
-
}): Promise<string>;
|
|
3636
|
-
pauseSchedule(scheduleId: string): Promise<void>;
|
|
3637
|
-
resumeSchedule(scheduleId: string): Promise<void>;
|
|
3638
|
-
getSchedule(scheduleId: string): Promise<Schedule | null>;
|
|
3639
|
-
listSchedules(): Promise<Schedule[]>;
|
|
3640
|
-
updateSchedule(scheduleId: string, updates: {
|
|
3641
|
-
cron?: string;
|
|
3642
|
-
interval?: number;
|
|
3643
|
-
input?: unknown;
|
|
3644
|
-
}): Promise<void>;
|
|
3645
|
-
removeSchedule(scheduleId: string): Promise<void>;
|
|
3646
|
-
recover(): Promise<void>;
|
|
3647
|
-
signal<TPayload>(executionId: string, signal: IEventDefinition<TPayload>, payload: TPayload): Promise<void>;
|
|
3648
|
-
}
|
|
3649
|
-
|
|
3650
|
-
declare const durableEvents: {
|
|
3651
|
-
readonly audit: {
|
|
3652
|
-
readonly appended: IEvent<{
|
|
3653
|
-
entry: DurableAuditEntry;
|
|
3654
|
-
}>;
|
|
3655
|
-
};
|
|
3656
|
-
readonly execution: {
|
|
3657
|
-
readonly statusChanged: IEvent<DurableAuditEntryBase & {
|
|
3658
|
-
kind: typeof DurableAuditEntryKind.ExecutionStatusChanged;
|
|
3659
|
-
from: ExecutionStatus | null;
|
|
3660
|
-
to: ExecutionStatus;
|
|
3661
|
-
reason?: string;
|
|
3662
|
-
}>;
|
|
3663
|
-
};
|
|
3664
|
-
readonly step: {
|
|
3665
|
-
readonly completed: IEvent<DurableAuditEntryBase & {
|
|
3666
|
-
kind: typeof DurableAuditEntryKind.StepCompleted;
|
|
3667
|
-
stepId: string;
|
|
3668
|
-
durationMs: number;
|
|
3669
|
-
isInternal: boolean;
|
|
3670
|
-
}>;
|
|
3671
|
-
};
|
|
3672
|
-
readonly sleep: {
|
|
3673
|
-
readonly scheduled: IEvent<DurableAuditEntryBase & {
|
|
3674
|
-
kind: typeof DurableAuditEntryKind.SleepScheduled;
|
|
3675
|
-
stepId: string;
|
|
3676
|
-
timerId: string;
|
|
3677
|
-
durationMs: number;
|
|
3678
|
-
fireAt: Date;
|
|
3679
|
-
}>;
|
|
3680
|
-
readonly completed: IEvent<DurableAuditEntryBase & {
|
|
3681
|
-
kind: typeof DurableAuditEntryKind.SleepCompleted;
|
|
3682
|
-
stepId: string;
|
|
3683
|
-
timerId: string;
|
|
3684
|
-
}>;
|
|
3685
|
-
};
|
|
3686
|
-
readonly signal: {
|
|
3687
|
-
readonly waiting: IEvent<DurableAuditEntryBase & {
|
|
3688
|
-
kind: typeof DurableAuditEntryKind.SignalWaiting;
|
|
3689
|
-
stepId: string;
|
|
3690
|
-
signalId: string;
|
|
3691
|
-
timeoutMs?: number;
|
|
3692
|
-
timeoutAtMs?: number;
|
|
3693
|
-
timerId?: string;
|
|
3694
|
-
reason?: "initial" | "timeout_armed";
|
|
3695
|
-
}>;
|
|
3696
|
-
readonly delivered: IEvent<DurableAuditEntryBase & {
|
|
3697
|
-
kind: typeof DurableAuditEntryKind.SignalDelivered;
|
|
3698
|
-
stepId: string;
|
|
3699
|
-
signalId: string;
|
|
3700
|
-
}>;
|
|
3701
|
-
readonly timedOut: IEvent<DurableAuditEntryBase & {
|
|
3702
|
-
kind: typeof DurableAuditEntryKind.SignalTimedOut;
|
|
3703
|
-
stepId: string;
|
|
3704
|
-
signalId: string;
|
|
3705
|
-
timerId: string;
|
|
3706
|
-
}>;
|
|
3707
|
-
};
|
|
3708
|
-
readonly emit: {
|
|
3709
|
-
readonly published: IEvent<DurableAuditEntryBase & {
|
|
3710
|
-
kind: typeof DurableAuditEntryKind.EmitPublished;
|
|
3711
|
-
stepId: string;
|
|
3712
|
-
eventId: string;
|
|
3713
|
-
}>;
|
|
3714
|
-
};
|
|
3715
|
-
readonly note: {
|
|
3716
|
-
readonly created: IEvent<DurableAuditEntryBase & {
|
|
3717
|
-
kind: typeof DurableAuditEntryKind.Note;
|
|
3718
|
-
message: string;
|
|
3719
|
-
meta?: Record<string, unknown>;
|
|
3720
|
-
}>;
|
|
3721
|
-
};
|
|
3722
|
-
};
|
|
3723
|
-
declare const durableEventsArray: IEvent<any>[];
|
|
3724
|
-
|
|
3725
|
-
declare function createDurableRunnerAuditEmitter(params: {
|
|
3726
|
-
eventManager: EventManager;
|
|
3727
|
-
source?: string;
|
|
3728
|
-
}): DurableAuditEmitter;
|
|
3729
|
-
|
|
3730
|
-
declare class NoopEventBus implements IEventBus {
|
|
3731
|
-
publish(_channel: string, _event: BusEvent): Promise<void>;
|
|
3732
|
-
subscribe(_channel: string, _handler: BusEventHandler): Promise<void>;
|
|
3733
|
-
unsubscribe(_channel: string): Promise<void>;
|
|
3734
|
-
}
|
|
3735
|
-
|
|
3736
|
-
/**
|
|
3737
|
-
* In-memory durable task registry.
|
|
3738
|
-
*
|
|
3739
|
-
* Durable executions persist only a `taskId` in the store, so the runtime needs a way
|
|
3740
|
-
* to resolve `taskId -> DurableTask` when resuming. This registry holds tasks that
|
|
3741
|
-
* were registered on the current process and optionally delegates to an external
|
|
3742
|
-
* resolver for tasks defined elsewhere (useful for modular apps).
|
|
3743
|
-
*/
|
|
3744
|
-
declare class TaskRegistry {
|
|
3745
|
-
private readonly externalResolver?;
|
|
3746
|
-
private readonly tasks;
|
|
3747
|
-
constructor(externalResolver?: ((taskId: string) => DurableTask<any, any> | undefined) | undefined);
|
|
3748
|
-
register<TInput, TResult>(task: DurableTask<TInput, TResult>): void;
|
|
3749
|
-
find(taskId: string): DurableTask<any, any> | undefined;
|
|
3750
|
-
}
|
|
3751
|
-
|
|
3752
|
-
interface AuditConfig {
|
|
3753
|
-
/**
|
|
3754
|
-
* When enabled, attempts to persist audit entries to the store (if supported).
|
|
3755
|
-
* This is separate from event emission via `emitter`.
|
|
3756
|
-
*/
|
|
3757
|
-
enabled?: boolean;
|
|
3758
|
-
/**
|
|
3759
|
-
* Optional emitter for streaming audit entries (e.g. Runner events, logging, mirroring).
|
|
3760
|
-
* Emissions must be best-effort and never affect workflow correctness.
|
|
3761
|
-
*/
|
|
3762
|
-
emitter?: DurableAuditEmitter;
|
|
3763
|
-
}
|
|
3764
|
-
/**
|
|
3765
|
-
* Durable audit trail sink.
|
|
3766
|
-
*
|
|
3767
|
-
* Used across the durable subsystem (service/managers/context) to record lifecycle
|
|
3768
|
-
* events in a best-effort way. Persistence and emission are explicitly non-critical:
|
|
3769
|
-
* failures must never affect workflow correctness (the store remains the source of truth).
|
|
3770
|
-
*/
|
|
3771
|
-
declare class AuditLogger {
|
|
3772
|
-
private readonly config;
|
|
3773
|
-
private readonly store;
|
|
3774
|
-
constructor(config: AuditConfig, store: IDurableStore);
|
|
3775
|
-
log(params: DurableAuditEntryInput & {
|
|
3776
|
-
at?: Date;
|
|
3777
|
-
}): Promise<void>;
|
|
3778
|
-
}
|
|
3779
|
-
|
|
3780
|
-
interface WaitConfig {
|
|
3781
|
-
defaultTimeout?: number;
|
|
3782
|
-
defaultPollIntervalMs?: number;
|
|
3783
|
-
}
|
|
3784
|
-
/**
|
|
3785
|
-
* Waits for an execution to reach a terminal state and returns/throws accordingly.
|
|
3786
|
-
*
|
|
3787
|
-
* Strategy:
|
|
3788
|
-
* - if an event bus is configured, subscribe to `execution:<executionId>` for low-latency completion
|
|
3789
|
-
* - otherwise (or on bus issues) fall back to polling the store
|
|
3790
|
-
*
|
|
3791
|
-
* The durable store remains the source of truth; this manager is purely a convenience layer
|
|
3792
|
-
* for callers that want `await durable.wait(...)` / `await durable.execute(...)`.
|
|
3793
|
-
*/
|
|
3794
|
-
declare class WaitManager {
|
|
3795
|
-
private readonly store;
|
|
3796
|
-
private readonly eventBus?;
|
|
3797
|
-
private readonly config?;
|
|
3798
|
-
constructor(store: IDurableStore, eventBus?: IEventBus | undefined, config?: WaitConfig | undefined);
|
|
3799
|
-
waitForResult<TResult>(executionId: string, options?: {
|
|
3800
|
-
timeout?: number;
|
|
3801
|
-
waitPollIntervalMs?: number;
|
|
3802
|
-
}): Promise<TResult>;
|
|
3803
|
-
}
|
|
3804
|
-
|
|
3805
|
-
/**
|
|
3806
|
-
* Creates and maintains durable schedules.
|
|
3807
|
-
*
|
|
3808
|
-
* A schedule is persisted in the store and translated into durable timers that
|
|
3809
|
-
* `PollingManager` will later process to kick off executions. This keeps scheduling
|
|
3810
|
-
* crash-safe and horizontally scalable: schedules aren't owned by in-memory timers.
|
|
3811
|
-
*/
|
|
3812
|
-
declare class ScheduleManager {
|
|
3813
|
-
private readonly store;
|
|
3814
|
-
private readonly taskRegistry;
|
|
3815
|
-
constructor(store: IDurableStore, taskRegistry: TaskRegistry);
|
|
3816
|
-
ensureSchedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions & {
|
|
3817
|
-
id: string;
|
|
3818
|
-
}): Promise<string>;
|
|
3819
|
-
schedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions): Promise<string>;
|
|
3820
|
-
reschedule(schedule: Schedule, options?: {
|
|
3821
|
-
lastRunAt?: Date;
|
|
3822
|
-
}): Promise<void>;
|
|
3823
|
-
pause(id: string): Promise<void>;
|
|
3824
|
-
resume(id: string): Promise<void>;
|
|
3825
|
-
get(id: string): Promise<Schedule | null>;
|
|
3826
|
-
list(): Promise<Schedule[]>;
|
|
3827
|
-
update(id: string, updates: {
|
|
3828
|
-
cron?: string;
|
|
3829
|
-
interval?: number;
|
|
3830
|
-
input?: unknown;
|
|
3831
|
-
}): Promise<void>;
|
|
3832
|
-
remove(id: string): Promise<void>;
|
|
3833
|
-
}
|
|
3834
|
-
|
|
3835
|
-
interface ExecutionManagerConfig {
|
|
3836
|
-
store: IDurableStore;
|
|
3837
|
-
queue?: IDurableQueue;
|
|
3838
|
-
eventBus?: IEventBus;
|
|
3839
|
-
taskExecutor?: ITaskExecutor;
|
|
3840
|
-
contextProvider?: DurableServiceConfig["contextProvider"];
|
|
3841
|
-
audit?: DurableServiceConfig["audit"];
|
|
3842
|
-
determinism?: DurableServiceConfig["determinism"];
|
|
3843
|
-
execution?: {
|
|
3844
|
-
maxAttempts?: number;
|
|
3845
|
-
timeout?: number;
|
|
3846
|
-
kickoffFailsafeDelayMs?: number;
|
|
3847
|
-
};
|
|
3848
|
-
}
|
|
3849
|
-
/**
|
|
3850
|
-
* Runs durable executions (the "workflow engine" for attempts).
|
|
3851
|
-
*
|
|
3852
|
-
* Responsibilities:
|
|
3853
|
-
* - persist new executions (including optional idempotency keys)
|
|
3854
|
-
* - enqueue work (queue mode) or run directly (embedded mode)
|
|
3855
|
-
* - execute a workflow attempt via `taskExecutor.run(...)`
|
|
3856
|
-
* - inject a per-attempt `DurableContext` (via `contextProvider` / ALS wrapper)
|
|
3857
|
-
* - interpret `SuspensionSignal` as "pause + reschedule" rather than failure
|
|
3858
|
-
* - update execution status/result/error and notify waiters (`WaitManager`)
|
|
3859
|
-
*/
|
|
3860
|
-
declare class ExecutionManager {
|
|
3861
|
-
private readonly config;
|
|
3862
|
-
private readonly taskRegistry;
|
|
3863
|
-
private readonly auditLogger;
|
|
3864
|
-
private readonly waitManager;
|
|
3865
|
-
constructor(config: ExecutionManagerConfig, taskRegistry: TaskRegistry, auditLogger: AuditLogger, waitManager: WaitManager);
|
|
3866
|
-
startExecution<TInput>(task: DurableTask<TInput, unknown>, input?: TInput, options?: ExecuteOptions): Promise<string>;
|
|
3867
|
-
cancelExecution(executionId: string, reason?: string): Promise<void>;
|
|
3868
|
-
execute<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3869
|
-
executeStrict<TInput, TResult>(task: undefined extends TResult ? never : DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3870
|
-
processExecution(executionId: string): Promise<void>;
|
|
3871
|
-
kickoffExecution(executionId: string): Promise<void>;
|
|
3872
|
-
notifyExecutionFinished(execution: Execution): Promise<void>;
|
|
3873
|
-
private runExecutionAttempt;
|
|
3874
|
-
}
|
|
3875
|
-
|
|
3876
|
-
interface PollingConfig {
|
|
3877
|
-
enabled?: boolean;
|
|
3878
|
-
interval?: number;
|
|
3879
|
-
claimTtlMs?: number;
|
|
3880
|
-
}
|
|
3881
|
-
interface PollingManagerCallbacks {
|
|
3882
|
-
processExecution: (executionId: string) => Promise<void>;
|
|
3883
|
-
kickoffExecution: (executionId: string) => Promise<void>;
|
|
3884
|
-
}
|
|
3885
|
-
/**
|
|
3886
|
-
* Timer/tick driver for durable workflows.
|
|
3887
|
-
*
|
|
3888
|
-
* The durable store is the source of truth, but time needs an active driver:
|
|
3889
|
-
* `PollingManager` periodically scans ready timers and performs the appropriate action:
|
|
3890
|
-
*
|
|
3891
|
-
* - complete `sleep()` steps by marking their step result as completed
|
|
3892
|
-
* - resume executions after signal timeouts / scheduled kickoffs / retries
|
|
3893
|
-
* - coordinate multi-worker polling via optional `store.claimTimer(...)`
|
|
3894
|
-
*
|
|
3895
|
-
* In production topologies you typically enable polling on worker nodes only.
|
|
3896
|
-
*/
|
|
3897
|
-
declare class PollingManager {
|
|
3898
|
-
private readonly workerId;
|
|
3899
|
-
private readonly config;
|
|
3900
|
-
private readonly store;
|
|
3901
|
-
private readonly queue;
|
|
3902
|
-
private readonly maxAttempts;
|
|
3903
|
-
private readonly defaultTimeout;
|
|
3904
|
-
private readonly taskRegistry;
|
|
3905
|
-
private readonly auditLogger;
|
|
3906
|
-
private readonly scheduleManager;
|
|
3907
|
-
private readonly callbacks;
|
|
3908
|
-
private isRunning;
|
|
3909
|
-
private pollingTimer;
|
|
3910
|
-
private pollingWake;
|
|
3911
|
-
constructor(workerId: string, config: PollingConfig, store: IDurableStore, queue: IDurableQueue | undefined, maxAttempts: number, defaultTimeout: number | undefined, taskRegistry: TaskRegistry, auditLogger: AuditLogger, scheduleManager: ScheduleManager, callbacks: PollingManagerCallbacks);
|
|
3912
|
-
start(): void;
|
|
3913
|
-
stop(): Promise<void>;
|
|
3914
|
-
private poll;
|
|
3915
|
-
/** @internal - public for testing */
|
|
3916
|
-
handleTimer(timer: Timer): Promise<void>;
|
|
3917
|
-
}
|
|
3918
|
-
|
|
3919
|
-
/**
|
|
3920
|
-
* Error thrown to consumers waiting on an execution (`DurableService.wait/execute*`).
|
|
3921
|
-
*
|
|
3922
|
-
* Distinguishes durable execution failures/timeouts/cancellations from ordinary
|
|
3923
|
-
* task errors by carrying execution metadata and a (serialized) cause payload.
|
|
3924
|
-
* `WaitManager` is the primary producer of this error.
|
|
3925
|
-
*/
|
|
3926
|
-
declare class DurableExecutionError extends Error {
|
|
3927
|
-
readonly executionId: string;
|
|
3928
|
-
readonly taskId: string;
|
|
3929
|
-
readonly attempt: number;
|
|
3930
|
-
readonly causeInfo?: {
|
|
3931
|
-
message: string;
|
|
3932
|
-
stack?: string;
|
|
3933
|
-
} | undefined;
|
|
3934
|
-
constructor(message: string, executionId: string, taskId: string, attempt: number, causeInfo?: {
|
|
3935
|
-
message: string;
|
|
3936
|
-
stack?: string;
|
|
3937
|
-
} | undefined);
|
|
3938
|
-
}
|
|
3939
|
-
|
|
3940
|
-
/**
|
|
3941
|
-
* High-level facade for the Durable Workflows subsystem.
|
|
3942
|
-
*
|
|
3943
|
-
* `DurableService` glues together the durable backends (store/queue/event bus) and
|
|
3944
|
-
* the specialized managers that implement durable semantics:
|
|
3945
|
-
*
|
|
3946
|
-
* - `ExecutionManager` runs workflow attempts and injects `DurableContext`
|
|
3947
|
-
* - `SignalHandler` delivers external signals to waiting steps
|
|
3948
|
-
* - `WaitManager` waits for results (event-bus first, polling fallback)
|
|
3949
|
-
* - `ScheduleManager` creates/updates schedules and their timers
|
|
3950
|
-
* - `PollingManager` drives timers (sleep, retries, signal timeouts, schedules)
|
|
3951
|
-
* - `AuditLogger` emits/persists an audit trail (best-effort)
|
|
3952
|
-
*
|
|
3953
|
-
* `DurableResource` wraps this service for Runner integration and provides
|
|
3954
|
-
* `durable.use()` to read the per-execution `DurableContext`.
|
|
3955
|
-
*/
|
|
3956
|
-
declare class DurableService implements IDurableService {
|
|
3957
|
-
private readonly config;
|
|
3958
|
-
private readonly taskRegistry;
|
|
3959
|
-
private readonly auditLogger;
|
|
3960
|
-
private readonly waitManager;
|
|
3961
|
-
private readonly scheduleManager;
|
|
3962
|
-
private readonly signalHandler;
|
|
3963
|
-
private readonly executionManager;
|
|
3964
|
-
private readonly pollingManager;
|
|
3965
|
-
/** Unique worker ID for distributed timer coordination */
|
|
3966
|
-
private readonly workerId;
|
|
3967
|
-
constructor(config: DurableServiceConfig);
|
|
3968
|
-
registerTask<TInput, TResult>(task: DurableTask<TInput, TResult>): void;
|
|
3969
|
-
findTask(taskId: string): DurableTask<any, any> | undefined;
|
|
3970
|
-
startExecution<TInput>(task: DurableTask<TInput, unknown>, input?: TInput, options?: ExecuteOptions): Promise<string>;
|
|
3971
|
-
cancelExecution(executionId: string, reason?: string): Promise<void>;
|
|
3972
|
-
execute<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3973
|
-
executeStrict<TInput, TResult>(task: undefined extends TResult ? never : DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3974
|
-
wait<TResult>(executionId: string, options?: {
|
|
3975
|
-
timeout?: number;
|
|
3976
|
-
waitPollIntervalMs?: number;
|
|
3977
|
-
}): Promise<TResult>;
|
|
3978
|
-
schedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions): Promise<string>;
|
|
3979
|
-
ensureSchedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions & {
|
|
3980
|
-
id: string;
|
|
3981
|
-
}): Promise<string>;
|
|
3982
|
-
recover(): Promise<void>;
|
|
3983
|
-
start(): void;
|
|
3984
|
-
stop(): Promise<void>;
|
|
3985
|
-
pauseSchedule(id: string): Promise<void>;
|
|
3986
|
-
resumeSchedule(id: string): Promise<void>;
|
|
3987
|
-
getSchedule(id: string): Promise<Schedule | null>;
|
|
3988
|
-
listSchedules(): Promise<Schedule[]>;
|
|
3989
|
-
updateSchedule(id: string, updates: {
|
|
3990
|
-
cron?: string;
|
|
3991
|
-
interval?: number;
|
|
3992
|
-
input?: unknown;
|
|
3993
|
-
}): Promise<void>;
|
|
3994
|
-
removeSchedule(id: string): Promise<void>;
|
|
3995
|
-
signal<TPayload>(executionId: string, signal: IEventDefinition<TPayload>, payload: TPayload): Promise<void>;
|
|
3996
|
-
processExecution(executionId: string): Promise<void>;
|
|
3997
|
-
getEventBus(): NoopEventBus;
|
|
3998
|
-
/** @internal - exposed for unit testing */
|
|
3999
|
-
get _pollingManager(): PollingManager;
|
|
4000
|
-
/** @internal - exposed for unit testing */
|
|
4001
|
-
get _executionManager(): ExecutionManager;
|
|
4002
|
-
/** @internal - exposed for unit testing (delegates to pollingManager) */
|
|
4003
|
-
handleTimer(timer: Timer): Promise<void>;
|
|
4004
|
-
}
|
|
4005
|
-
declare function initDurableService(config: DurableServiceConfig): Promise<DurableService>;
|
|
4006
|
-
declare function disposeDurableService(service: IDurableService, config: DurableServiceConfig): Promise<void>;
|
|
4007
|
-
|
|
4008
|
-
type DurableResourceRuntimeConfig = Omit<DurableServiceConfig, "taskExecutor" | "tasks" | "taskResolver" | "contextProvider"> & {
|
|
4009
|
-
/**
|
|
4010
|
-
* Starts an embedded worker (queue consumer) in this process.
|
|
4011
|
-
* Has effect only when `queue` is configured.
|
|
4012
|
-
*/
|
|
4013
|
-
worker?: boolean;
|
|
4014
|
-
};
|
|
4015
|
-
/**
|
|
4016
|
-
* A reusable durable resource template.
|
|
4017
|
-
*
|
|
4018
|
-
* Usage:
|
|
4019
|
-
* - `const durable = durableResource.fork("app.durable");`
|
|
4020
|
-
* - Register it via `durable.with({ store, queue, eventBus, ... })`
|
|
4021
|
-
*/
|
|
4022
|
-
declare const durableResource: IResource<DurableResourceRuntimeConfig, Promise<DurableResource$1>, {
|
|
4023
|
-
taskRunner: IResource<void, Promise<TaskRunner>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4024
|
-
eventManager: IResource<void, Promise<EventManager>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4025
|
-
runnerStore: IResource<void, Promise<Store>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4026
|
-
}, any, IResourceMeta, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4027
|
-
|
|
4028
|
-
type ImplicitInternalStepIdsPolicy = "allow" | "warn" | "error";
|
|
4029
|
-
|
|
4030
|
-
/**
|
|
4031
|
-
* Per-execution workflow toolkit used by durable tasks.
|
|
4032
|
-
*
|
|
4033
|
-
* `DurableContext` is created by `ExecutionManager` for each execution attempt and
|
|
4034
|
-
* made available to user code via `DurableResource.use()` (AsyncLocalStorage).
|
|
4035
|
-
*
|
|
4036
|
-
* It provides deterministic "save points" (`step()`), durable suspension primitives
|
|
4037
|
-
* (`sleep()`, `waitForSignal()`), and best-effort side-channel notifications (`emit()`).
|
|
4038
|
-
* The durable store is the source of truth; this class is intentionally thin state
|
|
4039
|
-
* around indexes/guards to keep a single in-memory attempt deterministic.
|
|
4040
|
-
*/
|
|
4041
|
-
declare class DurableContext implements IDurableContext {
|
|
4042
|
-
private readonly store;
|
|
4043
|
-
private readonly bus;
|
|
4044
|
-
readonly executionId: string;
|
|
4045
|
-
readonly attempt: number;
|
|
4046
|
-
private readonly sleepIndexRef;
|
|
4047
|
-
private readonly signalIndexes;
|
|
4048
|
-
private readonly emitIndexes;
|
|
4049
|
-
private noteIndex;
|
|
4050
|
-
private readonly implicitInternalStepIdsWarned;
|
|
4051
|
-
private readonly seenStepIds;
|
|
4052
|
-
private readonly compensations;
|
|
4053
|
-
private readonly audit;
|
|
4054
|
-
private readonly determinism;
|
|
4055
|
-
private readonly auditEnabled;
|
|
4056
|
-
private readonly auditEmitter;
|
|
4057
|
-
private readonly implicitInternalStepIdsPolicy;
|
|
4058
|
-
constructor(store: IDurableStore, bus: IEventBus, executionId: string, attempt: number, options?: {
|
|
4059
|
-
auditEnabled?: boolean;
|
|
4060
|
-
auditEmitter?: DurableAuditEmitter;
|
|
4061
|
-
implicitInternalStepIds?: ImplicitInternalStepIdsPolicy;
|
|
4062
|
-
});
|
|
4063
|
-
private assertNotCancelled;
|
|
4064
|
-
private getStepId;
|
|
4065
|
-
private internalStep;
|
|
4066
|
-
step<T>(stepId: string): IStepBuilder<T>;
|
|
4067
|
-
step<T>(stepId: DurableStepId<T>): IStepBuilder<T>;
|
|
4068
|
-
step<T>(stepId: string | DurableStepId<T>, fn: () => Promise<T>): Promise<T>;
|
|
4069
|
-
step<T>(stepId: string | DurableStepId<T>, options: StepOptions, fn: () => Promise<T>): Promise<T>;
|
|
4070
|
-
_executeStep<T>(stepId: string, options: StepOptions, upFn: () => Promise<T>, downFn?: (result: T) => Promise<void>): Promise<T>;
|
|
4071
|
-
rollback(): Promise<void>;
|
|
4072
|
-
sleep(durationMs: number, options?: SleepOptions): Promise<void>;
|
|
4073
|
-
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>): Promise<TPayload>;
|
|
4074
|
-
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>, options: SignalOptions & {
|
|
4075
|
-
timeoutMs: number;
|
|
4076
|
-
}): Promise<{
|
|
4077
|
-
kind: "signal";
|
|
4078
|
-
payload: TPayload;
|
|
4079
|
-
} | {
|
|
4080
|
-
kind: "timeout";
|
|
4081
|
-
}>;
|
|
4082
|
-
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>, options: SignalOptions): Promise<TPayload>;
|
|
4083
|
-
emit<TPayload>(event: IEventDefinition<TPayload>, payload: TPayload, options?: EmitOptions): Promise<void>;
|
|
4084
|
-
note(message: string, meta?: Record<string, unknown>): Promise<void>;
|
|
4085
|
-
}
|
|
4086
|
-
|
|
4087
|
-
/**
|
|
4088
|
-
* Fluent helper for building a durable step.
|
|
4089
|
-
*
|
|
4090
|
-
* This is the ergonomic layer behind `ctx.step("id")`:
|
|
4091
|
-
* - `up()` defines the memoized computation
|
|
4092
|
-
* - `down()` registers a compensation to be invoked by `ctx.rollback()`
|
|
4093
|
-
*
|
|
4094
|
-
* It is `PromiseLike`, so users can `await ctx.step("x").up(...).down(...)`.
|
|
4095
|
-
*/
|
|
4096
|
-
declare class StepBuilder<T> implements IStepBuilder<T> {
|
|
4097
|
-
private readonly context;
|
|
4098
|
-
private readonly stepId;
|
|
4099
|
-
private readonly options;
|
|
4100
|
-
private upFn?;
|
|
4101
|
-
private downFn?;
|
|
4102
|
-
constructor(context: DurableContext, stepId: string, options?: StepOptions);
|
|
4103
|
-
up(fn: () => Promise<T>): this;
|
|
4104
|
-
down(fn: (result: T) => Promise<void>): this;
|
|
4105
|
-
private execute;
|
|
4106
|
-
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
|
|
4107
|
-
}
|
|
4108
|
-
|
|
4109
|
-
/**
|
|
4110
|
-
* Administrative / operator API for durable workflows.
|
|
4111
|
-
*
|
|
4112
|
-
* This class is intentionally store-backed and side-effect free with respect to
|
|
4113
|
-
* "running" workflows: it reads execution details and, when supported by the store,
|
|
4114
|
-
* can perform operator actions (retry rollback, skip a step, force fail, patch state).
|
|
4115
|
-
*
|
|
4116
|
-
* Used by dashboards / CLIs / tooling to inspect and recover executions.
|
|
4117
|
-
*/
|
|
4118
|
-
declare class DurableOperator {
|
|
4119
|
-
private readonly store;
|
|
4120
|
-
constructor(store: IDurableStore);
|
|
4121
|
-
listExecutions(options?: ListExecutionsOptions): Promise<Execution[]>;
|
|
4122
|
-
getExecutionDetail(executionId: string): Promise<{
|
|
4123
|
-
execution: Execution | null;
|
|
4124
|
-
steps: StepResult[];
|
|
4125
|
-
audit: DurableAuditEntry[];
|
|
4126
|
-
}>;
|
|
4127
|
-
/**
|
|
4128
|
-
* Resets an execution from `compensation_failed` (or other states) to `pending`.
|
|
4129
|
-
* This effectively retries the workflow from the last memoized step.
|
|
4130
|
-
*/
|
|
4131
|
-
retryRollback(executionId: string): Promise<void>;
|
|
4132
|
-
/**
|
|
4133
|
-
* Manually marks a step as completed with a specific result.
|
|
4134
|
-
* Useful for skipping broken steps or providing a manual fix.
|
|
4135
|
-
*/
|
|
4136
|
-
skipStep(executionId: string, stepId: string): Promise<void>;
|
|
4137
|
-
/**
|
|
4138
|
-
* Forces an execution to the `failed` state.
|
|
4139
|
-
*/
|
|
4140
|
-
forceFail(executionId: string, reason: string): Promise<void>;
|
|
4141
|
-
/**
|
|
4142
|
-
* Manually patches the result of a step.
|
|
4143
|
-
* Useful when a step failed to save its result but the side effect occurred.
|
|
4144
|
-
*/
|
|
4145
|
-
editState(executionId: string, stepId: string, newState: unknown): Promise<void>;
|
|
4146
|
-
/**
|
|
4147
|
-
* Lists all executions that require manual intervention.
|
|
4148
|
-
*/
|
|
4149
|
-
listStuckExecutions(): Promise<Execution[]>;
|
|
4150
|
-
}
|
|
4151
|
-
|
|
4152
|
-
/**
|
|
4153
|
-
* Durable queue consumer (worker process role).
|
|
4154
|
-
*
|
|
4155
|
-
* The worker listens to the durable queue and turns queue messages into
|
|
4156
|
-
* `processExecution(executionId)` calls on the service layer (`ExecutionManager`
|
|
4157
|
-
* behind `IDurableExecutionProcessor`). This is how "resume" work is distributed
|
|
4158
|
-
* horizontally: the store is the source of truth, the queue provides delivery.
|
|
4159
|
-
*/
|
|
4160
|
-
declare class DurableWorker {
|
|
4161
|
-
private readonly service;
|
|
4162
|
-
private readonly queue;
|
|
4163
|
-
constructor(service: IDurableExecutionProcessor, queue: IDurableQueue);
|
|
4164
|
-
start(): Promise<void>;
|
|
4165
|
-
private handleMessage;
|
|
4166
|
-
private extractExecutionId;
|
|
4167
|
-
}
|
|
4168
|
-
declare function initDurableWorker(service: IDurableExecutionProcessor, queue: IDurableQueue): Promise<DurableWorker>;
|
|
4169
|
-
|
|
4170
|
-
type DashboardMiddlewareOptions = {
|
|
4171
|
-
/**
|
|
4172
|
-
* Override where the dashboard UI is served from.
|
|
4173
|
-
* Useful for tests or custom deployments.
|
|
4174
|
-
*/
|
|
4175
|
-
uiDistPath?: string;
|
|
4176
|
-
/**
|
|
4177
|
-
* Authorization hook for operator actions (retry/skip/force/edit).
|
|
4178
|
-
* Return true to allow, false to deny.
|
|
4179
|
-
*/
|
|
4180
|
-
operatorAuth?: (req: Request) => boolean | Promise<boolean>;
|
|
4181
|
-
/**
|
|
4182
|
-
* Opt out of operator auth checks (not recommended).
|
|
4183
|
-
*/
|
|
4184
|
-
dangerouslyAllowUnauthenticatedOperator?: boolean;
|
|
4185
|
-
};
|
|
4186
|
-
declare function createDashboardMiddleware(_service: IDurableService, operator: DurableOperator, options?: DashboardMiddlewareOptions): Router;
|
|
4187
|
-
|
|
4188
|
-
declare class MemoryStore implements IDurableStore {
|
|
4189
|
-
private executions;
|
|
4190
|
-
private executionIdByIdempotencyKey;
|
|
4191
|
-
private stepResults;
|
|
4192
|
-
private auditEntries;
|
|
4193
|
-
private timers;
|
|
4194
|
-
private schedules;
|
|
4195
|
-
private locks;
|
|
4196
|
-
private getIdempotencyMapKey;
|
|
4197
|
-
getExecutionIdByIdempotencyKey(params: {
|
|
4198
|
-
taskId: string;
|
|
4199
|
-
idempotencyKey: string;
|
|
4200
|
-
}): Promise<string | null>;
|
|
4201
|
-
setExecutionIdByIdempotencyKey(params: {
|
|
4202
|
-
taskId: string;
|
|
4203
|
-
idempotencyKey: string;
|
|
4204
|
-
executionId: string;
|
|
4205
|
-
}): Promise<boolean>;
|
|
4206
|
-
saveExecution(execution: Execution): Promise<void>;
|
|
4207
|
-
getExecution(id: string): Promise<Execution | null>;
|
|
4208
|
-
updateExecution(id: string, updates: Partial<Execution>): Promise<void>;
|
|
4209
|
-
listIncompleteExecutions(): Promise<Execution[]>;
|
|
4210
|
-
listStuckExecutions(): Promise<Execution[]>;
|
|
4211
|
-
listExecutions(options?: ListExecutionsOptions): Promise<Execution[]>;
|
|
4212
|
-
listStepResults(executionId: string): Promise<StepResult[]>;
|
|
4213
|
-
appendAuditEntry(entry: DurableAuditEntry): Promise<void>;
|
|
4214
|
-
listAuditEntries(executionId: string, options?: {
|
|
4215
|
-
limit?: number;
|
|
4216
|
-
offset?: number;
|
|
4217
|
-
}): Promise<DurableAuditEntry[]>;
|
|
4218
|
-
retryRollback(executionId: string): Promise<void>;
|
|
4219
|
-
skipStep(executionId: string, stepId: string): Promise<void>;
|
|
4220
|
-
forceFail(executionId: string, error: {
|
|
4221
|
-
message: string;
|
|
4222
|
-
stack?: string;
|
|
4223
|
-
}): Promise<void>;
|
|
4224
|
-
editStepResult(executionId: string, stepId: string, newResult: unknown): Promise<void>;
|
|
4225
|
-
getStepResult(executionId: string, stepId: string): Promise<StepResult | null>;
|
|
4226
|
-
saveStepResult(result: StepResult): Promise<void>;
|
|
4227
|
-
createTimer(timer: Timer): Promise<void>;
|
|
4228
|
-
getReadyTimers(now?: Date): Promise<Timer[]>;
|
|
4229
|
-
markTimerFired(timerId: string): Promise<void>;
|
|
4230
|
-
deleteTimer(timerId: string): Promise<void>;
|
|
4231
|
-
claimTimer(timerId: string, workerId: string, ttlMs: number): Promise<boolean>;
|
|
4232
|
-
createSchedule(schedule: Schedule): Promise<void>;
|
|
4233
|
-
getSchedule(id: string): Promise<Schedule | null>;
|
|
4234
|
-
updateSchedule(id: string, updates: Partial<Schedule>): Promise<void>;
|
|
4235
|
-
deleteSchedule(id: string): Promise<void>;
|
|
4236
|
-
listSchedules(): Promise<Schedule[]>;
|
|
4237
|
-
listActiveSchedules(): Promise<Schedule[]>;
|
|
4238
|
-
acquireLock(resource: string, ttlMs: number): Promise<string | null>;
|
|
4239
|
-
releaseLock(resource: string, lockId: string): Promise<void>;
|
|
4240
|
-
}
|
|
4241
|
-
|
|
4242
|
-
interface RedisPipeline {
|
|
4243
|
-
get(key: string): RedisPipeline;
|
|
4244
|
-
hget(hash: string, key: string): RedisPipeline;
|
|
4245
|
-
exec(): Promise<Array<[unknown, unknown]> | null>;
|
|
4246
|
-
}
|
|
4247
|
-
interface RedisClient {
|
|
4248
|
-
set(...args: unknown[]): Promise<unknown>;
|
|
4249
|
-
get(...args: unknown[]): Promise<unknown>;
|
|
4250
|
-
scan(...args: unknown[]): Promise<unknown>;
|
|
4251
|
-
sscan(...args: unknown[]): Promise<unknown>;
|
|
4252
|
-
sadd(...args: unknown[]): Promise<unknown>;
|
|
4253
|
-
srem(...args: unknown[]): Promise<unknown>;
|
|
4254
|
-
keys?(...args: unknown[]): Promise<unknown>;
|
|
4255
|
-
pipeline(): RedisPipeline;
|
|
4256
|
-
hset(...args: unknown[]): Promise<unknown>;
|
|
4257
|
-
hget(...args: unknown[]): Promise<unknown>;
|
|
4258
|
-
hdel(...args: unknown[]): Promise<unknown>;
|
|
4259
|
-
hgetall(...args: unknown[]): Promise<unknown>;
|
|
4260
|
-
zadd(...args: unknown[]): Promise<unknown>;
|
|
4261
|
-
zrangebyscore(...args: unknown[]): Promise<unknown>;
|
|
4262
|
-
zrem(...args: unknown[]): Promise<unknown>;
|
|
4263
|
-
eval(...args: unknown[]): Promise<unknown>;
|
|
4264
|
-
quit(...args: unknown[]): Promise<unknown>;
|
|
4265
|
-
}
|
|
4266
|
-
interface RedisStoreConfig {
|
|
4267
|
-
prefix?: string;
|
|
4268
|
-
redis?: RedisClient | string;
|
|
4269
|
-
}
|
|
4270
|
-
declare class RedisStore implements IDurableStore {
|
|
4271
|
-
private redis;
|
|
4272
|
-
private prefix;
|
|
4273
|
-
constructor(config: RedisStoreConfig);
|
|
4274
|
-
private k;
|
|
4275
|
-
private encodeKeyPart;
|
|
4276
|
-
getExecutionIdByIdempotencyKey(params: {
|
|
4277
|
-
taskId: string;
|
|
4278
|
-
idempotencyKey: string;
|
|
4279
|
-
}): Promise<string | null>;
|
|
4280
|
-
setExecutionIdByIdempotencyKey(params: {
|
|
4281
|
-
taskId: string;
|
|
4282
|
-
idempotencyKey: string;
|
|
4283
|
-
executionId: string;
|
|
4284
|
-
}): Promise<boolean>;
|
|
4285
|
-
private parseRedisString;
|
|
4286
|
-
private parseScanResponse;
|
|
4287
|
-
private scanKeys;
|
|
4288
|
-
private scanSetMembers;
|
|
4289
|
-
private activeExecutionsKey;
|
|
4290
|
-
private isActiveExecutionStatus;
|
|
4291
|
-
private updateActiveExecutionMembership;
|
|
4292
|
-
saveExecution(execution: Execution): Promise<void>;
|
|
4293
|
-
getExecution(id: string): Promise<Execution | null>;
|
|
4294
|
-
updateExecution(id: string, updates: Partial<Execution>): Promise<void>;
|
|
4295
|
-
listIncompleteExecutions(): Promise<Execution[]>;
|
|
4296
|
-
listStuckExecutions(): Promise<Execution[]>;
|
|
4297
|
-
retryRollback(executionId: string): Promise<void>;
|
|
4298
|
-
skipStep(executionId: string, stepId: string): Promise<void>;
|
|
4299
|
-
forceFail(executionId: string, error: {
|
|
4300
|
-
message: string;
|
|
4301
|
-
stack?: string;
|
|
4302
|
-
}): Promise<void>;
|
|
4303
|
-
editStepResult(executionId: string, stepId: string, newResult: unknown): Promise<void>;
|
|
4304
|
-
listExecutions(options?: ListExecutionsOptions): Promise<Execution[]>;
|
|
4305
|
-
listStepResults(executionId: string): Promise<StepResult[]>;
|
|
4306
|
-
appendAuditEntry(entry: DurableAuditEntry): Promise<void>;
|
|
4307
|
-
listAuditEntries(executionId: string, options?: {
|
|
4308
|
-
limit?: number;
|
|
4309
|
-
offset?: number;
|
|
4310
|
-
}): Promise<DurableAuditEntry[]>;
|
|
4311
|
-
getStepResult(executionId: string, stepId: string): Promise<StepResult | null>;
|
|
4312
|
-
saveStepResult(result: StepResult): Promise<void>;
|
|
4313
|
-
createTimer(timer: Timer): Promise<void>;
|
|
4314
|
-
getReadyTimers(now?: Date): Promise<Timer[]>;
|
|
4315
|
-
markTimerFired(timerId: string): Promise<void>;
|
|
4316
|
-
deleteTimer(timerId: string): Promise<void>;
|
|
4317
|
-
claimTimer(timerId: string, workerId: string, ttlMs: number): Promise<boolean>;
|
|
4318
|
-
createSchedule(schedule: Schedule): Promise<void>;
|
|
4319
|
-
getSchedule(id: string): Promise<Schedule | null>;
|
|
4320
|
-
updateSchedule(id: string, updates: Partial<Schedule>): Promise<void>;
|
|
4321
|
-
deleteSchedule(id: string): Promise<void>;
|
|
4322
|
-
listSchedules(): Promise<Schedule[]>;
|
|
4323
|
-
listActiveSchedules(): Promise<Schedule[]>;
|
|
4324
|
-
acquireLock(resource: string, ttlMs: number): Promise<string | null>;
|
|
4325
|
-
releaseLock(resource: string, lockId: string): Promise<void>;
|
|
4326
|
-
dispose(): Promise<void>;
|
|
4327
|
-
}
|
|
4328
|
-
|
|
4329
|
-
declare class MemoryQueue implements IDurableQueue {
|
|
4330
|
-
private queue;
|
|
4331
|
-
private handler;
|
|
4332
|
-
private isProcessing;
|
|
4333
|
-
private readonly inFlight;
|
|
4334
|
-
enqueue<T>(message: Omit<QueueMessage<T>, "id" | "createdAt" | "attempts">): Promise<string>;
|
|
4335
|
-
consume<T>(handler: MessageHandler<T>): Promise<void>;
|
|
4336
|
-
ack(_messageId: string): Promise<void>;
|
|
4337
|
-
nack(_messageId: string, _requeue?: boolean): Promise<void>;
|
|
4338
|
-
private processNext;
|
|
4339
|
-
}
|
|
4340
|
-
|
|
4341
|
-
interface RabbitMQQueueConfig {
|
|
4342
|
-
url?: string;
|
|
4343
|
-
queueName?: string;
|
|
4344
|
-
queue?: {
|
|
4345
|
-
name?: string;
|
|
4346
|
-
quorum?: boolean;
|
|
4347
|
-
deadLetter?: string;
|
|
4348
|
-
messageTtl?: number;
|
|
4349
|
-
};
|
|
4350
|
-
prefetch?: number;
|
|
4351
|
-
}
|
|
4352
|
-
declare class RabbitMQQueue implements IDurableQueue {
|
|
4353
|
-
private connection;
|
|
4354
|
-
private channel;
|
|
4355
|
-
private url;
|
|
4356
|
-
private queueName;
|
|
4357
|
-
private prefetch;
|
|
4358
|
-
private readonly isQuorum;
|
|
4359
|
-
private readonly deadLetterQueue?;
|
|
4360
|
-
private readonly messageTtl?;
|
|
4361
|
-
private messageMap;
|
|
4362
|
-
constructor(config: RabbitMQQueueConfig);
|
|
4363
|
-
init(): Promise<void>;
|
|
4364
|
-
enqueue<T>(message: Omit<QueueMessage<T>, "id" | "createdAt" | "attempts">): Promise<string>;
|
|
4365
|
-
consume<T>(handler: MessageHandler<T>): Promise<void>;
|
|
4366
|
-
ack(messageId: string): Promise<void>;
|
|
4367
|
-
nack(messageId: string, requeue?: boolean): Promise<void>;
|
|
4368
|
-
dispose(): Promise<void>;
|
|
4369
|
-
}
|
|
4370
|
-
|
|
4371
|
-
declare class MemoryEventBus implements IEventBus {
|
|
4372
|
-
private handlers;
|
|
4373
|
-
publish(channel: string, event: BusEvent): Promise<void>;
|
|
4374
|
-
subscribe(channel: string, handler: BusEventHandler): Promise<void>;
|
|
4375
|
-
unsubscribe(channel: string): Promise<void>;
|
|
4376
|
-
}
|
|
4377
|
-
|
|
4378
|
-
interface RedisEventBusConfig {
|
|
4379
|
-
prefix?: string;
|
|
4380
|
-
redis?: RedisEventBusClient | string;
|
|
4381
|
-
}
|
|
4382
|
-
interface RedisEventBusClient {
|
|
4383
|
-
publish(channel: string, payload: string): Promise<unknown>;
|
|
4384
|
-
subscribe(channel: string): Promise<unknown>;
|
|
4385
|
-
unsubscribe(channel: string): Promise<unknown>;
|
|
4386
|
-
on(event: "message", fn: (channel: string, message: string) => void): unknown;
|
|
4387
|
-
quit(): Promise<unknown>;
|
|
4388
|
-
duplicate(): RedisEventBusClient;
|
|
4389
|
-
}
|
|
4390
|
-
declare class RedisEventBus implements IEventBus {
|
|
4391
|
-
private pub;
|
|
4392
|
-
private sub;
|
|
4393
|
-
private prefix;
|
|
4394
|
-
private readonly channels;
|
|
4395
|
-
private readonly serializer;
|
|
4396
|
-
constructor(config: RedisEventBusConfig);
|
|
4397
|
-
private k;
|
|
4398
|
-
private tryParse;
|
|
4399
|
-
private coerceTimestamp;
|
|
4400
|
-
private toBusEvent;
|
|
4401
|
-
private deserializeEvent;
|
|
4402
|
-
publish(channel: string, event: BusEvent): Promise<void>;
|
|
4403
|
-
subscribe(channel: string, handler: BusEventHandler): Promise<void>;
|
|
4404
|
-
unsubscribe(channel: string): Promise<void>;
|
|
4405
|
-
dispose(): Promise<void>;
|
|
4406
|
-
}
|
|
4407
|
-
|
|
4408
|
-
type DurableResource = ReturnType<typeof durableResource.fork>;
|
|
4409
|
-
type DurableResourceRegistration = ReturnType<DurableResource["with"]>;
|
|
4410
|
-
interface DurableTestSetup {
|
|
4411
|
-
durable: DurableResource;
|
|
4412
|
-
durableRegistration: DurableResourceRegistration;
|
|
4413
|
-
store: MemoryStore;
|
|
4414
|
-
eventBus: MemoryEventBus;
|
|
4415
|
-
queue?: MemoryQueue;
|
|
4416
|
-
}
|
|
4417
|
-
interface DurableTestSetupOptions {
|
|
4418
|
-
durableId?: string;
|
|
4419
|
-
store?: MemoryStore;
|
|
4420
|
-
eventBus?: MemoryEventBus;
|
|
4421
|
-
queue?: MemoryQueue;
|
|
4422
|
-
worker?: boolean;
|
|
4423
|
-
pollingIntervalMs?: number;
|
|
4424
|
-
durableConfig?: Partial<DurableResourceRuntimeConfig>;
|
|
4425
|
-
}
|
|
4426
|
-
declare function createDurableTestSetup(options?: DurableTestSetupOptions): DurableTestSetup;
|
|
4427
|
-
declare function waitUntil(predicate: () => boolean | Promise<boolean>, options: {
|
|
4428
|
-
timeoutMs: number;
|
|
4429
|
-
intervalMs: number;
|
|
4430
|
-
}): Promise<void>;
|
|
4431
|
-
|
|
4432
|
-
declare const globals: {
|
|
4433
|
-
resources: {
|
|
4434
|
-
httpSmartClientFactory: IResource<void, Promise<HttpSmartClientFactory>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4435
|
-
httpMixedClientFactory: IResource<void, Promise<HttpMixedClientFactory>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4436
|
-
store: IResource<void, Promise<Store>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4437
|
-
middlewareManager: IResource<void, Promise<MiddlewareManager>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4438
|
-
eventManager: IResource<void, Promise<EventManager>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4439
|
-
taskRunner: IResource<void, Promise<TaskRunner>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4440
|
-
logger: IResource<void, Promise<Logger>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4441
|
-
serializer: IResource<void, Promise<SerializerLike>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4442
|
-
cache: IResource<{
|
|
4443
|
-
defaultOptions?: any;
|
|
4444
|
-
}, Promise<{
|
|
4445
|
-
map: Map<string, ICacheInstance>;
|
|
4446
|
-
cacheFactoryTask: TaskDependencyWithIntercept<lru_cache.LRUCache.Options<any, any, any>, Promise<ICacheInstance>>;
|
|
4447
|
-
defaultOptions: any;
|
|
4448
|
-
}>, {
|
|
4449
|
-
cacheFactoryTask: ITask<lru_cache.LRUCache.Options<any, any, any>, Promise<ICacheInstance>, any, any, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
4450
|
-
}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4451
|
-
queue: IResource<void, Promise<{
|
|
4452
|
-
map: Map<string, Queue>;
|
|
4453
|
-
run: <T>(id: string, task: (signal: AbortSignal) => Promise<T>) => Promise<T>;
|
|
4454
|
-
}>, {}, {
|
|
4455
|
-
map: Map<string, Queue>;
|
|
4456
|
-
}, {
|
|
4457
|
-
title: string;
|
|
4458
|
-
description: string;
|
|
4459
|
-
}, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4460
|
-
httpClientFactory: IResource<void, Promise<HttpClientFactory>, {
|
|
4461
|
-
serializer: IResource<void, Promise<SerializerLike>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4462
|
-
store: IResource<void, Promise<Store>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4463
|
-
}, any, {
|
|
4464
|
-
title: string;
|
|
4465
|
-
description: string;
|
|
4466
|
-
}, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4467
|
-
rateLimit: IResource<void, Promise<{
|
|
4468
|
-
states: WeakMap<RateLimitMiddlewareConfig, RateLimitState>;
|
|
4469
|
-
}>, {}, any, any, ITag<{
|
|
4470
|
-
metadata?: Record<string, any>;
|
|
4471
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4472
|
-
circuitBreaker: IResource<void, Promise<{
|
|
4473
|
-
statusMap: Map<string, CircuitBreakerStatus>;
|
|
4474
|
-
}>, {}, any, any, ITag<{
|
|
4475
|
-
metadata?: Record<string, any>;
|
|
4476
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4477
|
-
temporal: IResource<void, Promise<{
|
|
4478
|
-
debounceStates: WeakMap<TemporalMiddlewareConfig, DebounceState>;
|
|
4479
|
-
throttleStates: WeakMap<TemporalMiddlewareConfig, ThrottleState>;
|
|
4480
|
-
}>, {}, any, any, ITag<{
|
|
4481
|
-
metadata?: Record<string, any>;
|
|
4482
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4483
|
-
concurrency: IResource<void, Promise<{
|
|
4484
|
-
semaphoresByConfig: WeakMap<ConcurrencyMiddlewareConfig, Semaphore>;
|
|
4485
|
-
semaphoresByKey: Map<string, {
|
|
4486
|
-
semaphore: Semaphore;
|
|
4487
|
-
limit: number;
|
|
4488
|
-
}>;
|
|
4489
|
-
}>, {}, any, any, ITag<{
|
|
4490
|
-
metadata?: Record<string, any>;
|
|
4491
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4492
|
-
};
|
|
4493
|
-
events: {
|
|
4494
|
-
readonly ready: IEvent<void>;
|
|
4495
|
-
};
|
|
4496
|
-
middleware: {
|
|
4497
|
-
requireContext: ITaskMiddleware<{
|
|
4498
|
-
context: IAsyncContext<any>;
|
|
4499
|
-
}, void, void, any>;
|
|
4500
|
-
task: {
|
|
4501
|
-
requireContext: ITaskMiddleware<{
|
|
4502
|
-
context: IAsyncContext<any>;
|
|
4503
|
-
}, void, void, any>;
|
|
4504
|
-
cache: ITaskMiddleware<any, void, void, {
|
|
4505
|
-
cache: IResource<{
|
|
4506
|
-
defaultOptions?: any;
|
|
4507
|
-
}, Promise<{
|
|
4508
|
-
map: Map<string, ICacheInstance>;
|
|
4509
|
-
cacheFactoryTask: TaskDependencyWithIntercept<lru_cache.LRUCache.Options<any, any, any>, Promise<ICacheInstance>>;
|
|
4510
|
-
defaultOptions: any;
|
|
4511
|
-
}>, {
|
|
4512
|
-
cacheFactoryTask: ITask<lru_cache.LRUCache.Options<any, any, any>, Promise<ICacheInstance>, any, any, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
4513
|
-
}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4514
|
-
}> & {
|
|
4515
|
-
journalKeys: {
|
|
4516
|
-
readonly hit: JournalKey<boolean>;
|
|
4517
|
-
};
|
|
4518
|
-
};
|
|
4519
|
-
concurrency: ITaskMiddleware<ConcurrencyMiddlewareConfig, void, void, {
|
|
4520
|
-
state: IResource<void, Promise<{
|
|
4521
|
-
semaphoresByConfig: WeakMap<ConcurrencyMiddlewareConfig, Semaphore>;
|
|
4522
|
-
semaphoresByKey: Map<string, {
|
|
4523
|
-
semaphore: Semaphore;
|
|
4524
|
-
limit: number;
|
|
4525
|
-
}>;
|
|
4526
|
-
}>, {}, any, any, ITag<{
|
|
4527
|
-
metadata?: Record<string, any>;
|
|
4528
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4529
|
-
}>;
|
|
4530
|
-
debounce: ITaskMiddleware<TemporalMiddlewareConfig, void, void, {
|
|
4531
|
-
state: IResource<void, Promise<{
|
|
4532
|
-
debounceStates: WeakMap<TemporalMiddlewareConfig, DebounceState>;
|
|
4533
|
-
throttleStates: WeakMap<TemporalMiddlewareConfig, ThrottleState>;
|
|
4534
|
-
}>, {}, any, any, ITag<{
|
|
4535
|
-
metadata?: Record<string, any>;
|
|
4536
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4537
|
-
}>;
|
|
4538
|
-
throttle: ITaskMiddleware<TemporalMiddlewareConfig, void, void, {
|
|
4539
|
-
state: IResource<void, Promise<{
|
|
4540
|
-
debounceStates: WeakMap<TemporalMiddlewareConfig, DebounceState>;
|
|
4541
|
-
throttleStates: WeakMap<TemporalMiddlewareConfig, ThrottleState>;
|
|
4542
|
-
}>, {}, any, any, ITag<{
|
|
4543
|
-
metadata?: Record<string, any>;
|
|
4544
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4545
|
-
}>;
|
|
4546
|
-
fallback: ITaskMiddleware<FallbackMiddlewareConfig, void, void, {
|
|
4547
|
-
taskRunner: IResource<void, Promise<TaskRunner>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4548
|
-
}> & {
|
|
4549
|
-
journalKeys: {
|
|
4550
|
-
readonly active: JournalKey<boolean>;
|
|
4551
|
-
readonly error: JournalKey<Error>;
|
|
4552
|
-
};
|
|
4553
|
-
};
|
|
4554
|
-
rateLimit: ITaskMiddleware<RateLimitMiddlewareConfig, void, void, {
|
|
4555
|
-
state: IResource<void, Promise<{
|
|
4556
|
-
states: WeakMap<RateLimitMiddlewareConfig, RateLimitState>;
|
|
4557
|
-
}>, {}, any, any, ITag<{
|
|
4558
|
-
metadata?: Record<string, any>;
|
|
4559
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4560
|
-
}> & {
|
|
4561
|
-
journalKeys: {
|
|
4562
|
-
readonly remaining: JournalKey<number>;
|
|
4563
|
-
readonly resetTime: JournalKey<number>;
|
|
4564
|
-
readonly limit: JournalKey<number>;
|
|
4565
|
-
};
|
|
4566
|
-
};
|
|
4567
|
-
retry: ITaskMiddleware<RetryMiddlewareConfig, void, void, any> & {
|
|
4568
|
-
journalKeys: {
|
|
4569
|
-
readonly attempt: JournalKey<number>;
|
|
4570
|
-
readonly lastError: JournalKey<Error>;
|
|
4571
|
-
};
|
|
4572
|
-
};
|
|
4573
|
-
timeout: ITaskMiddleware<TimeoutMiddlewareConfig, void, void, any> & {
|
|
4574
|
-
journalKeys: {
|
|
4575
|
-
readonly abortController: JournalKey<AbortController>;
|
|
4576
|
-
};
|
|
4577
|
-
};
|
|
4578
|
-
circuitBreaker: ITaskMiddleware<CircuitBreakerMiddlewareConfig, void, void, {
|
|
4579
|
-
state: IResource<void, Promise<{
|
|
4580
|
-
statusMap: Map<string, CircuitBreakerStatus>;
|
|
4581
|
-
}>, {}, any, any, ITag<{
|
|
4582
|
-
metadata?: Record<string, any>;
|
|
4583
|
-
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4584
|
-
}> & {
|
|
4585
|
-
journalKeys: {
|
|
4586
|
-
readonly state: JournalKey<CircuitBreakerState>;
|
|
4587
|
-
readonly failures: JournalKey<number>;
|
|
4588
|
-
};
|
|
4589
|
-
};
|
|
4590
|
-
};
|
|
4591
|
-
resource: {
|
|
4592
|
-
retry: IResourceMiddleware<RetryMiddlewareConfig, void, void, any>;
|
|
4593
|
-
timeout: IResourceMiddleware<TimeoutMiddlewareConfig, void, void, any>;
|
|
4594
|
-
};
|
|
4595
|
-
};
|
|
4596
|
-
tags: {
|
|
4597
|
-
system: ITag<{
|
|
4598
|
-
metadata?: Record<string, any>;
|
|
4599
|
-
}, void, void>;
|
|
4600
|
-
excludeFromGlobalHooks: ITag<{
|
|
4601
|
-
metadata?: Record<string, any>;
|
|
4602
|
-
}, void, void>;
|
|
4603
|
-
debug: ITag<DebugFriendlyConfig, void, void>;
|
|
4604
|
-
tunnel: ITag<void, void, TunnelRunner>;
|
|
4605
|
-
tunnelPolicy: ITag<TunnelTaskMiddlewarePolicyConfig, void, void>;
|
|
4606
|
-
authValidator: ITag<void, void, void>;
|
|
4607
|
-
};
|
|
4608
|
-
tunnels: Readonly<{
|
|
4609
|
-
http: Readonly<{
|
|
4610
|
-
createClient(cfg: HttpCreateClientConfig): ExposureFetchClient;
|
|
4611
|
-
}>;
|
|
4612
|
-
}>;
|
|
4613
|
-
debug: {
|
|
4614
|
-
levels: {
|
|
4615
|
-
normal: DebugConfig;
|
|
4616
|
-
verbose: DebugConfig;
|
|
4617
|
-
};
|
|
4618
|
-
};
|
|
4619
|
-
};
|
|
4620
|
-
declare function run(root: any, config?: any): Promise<RunResult<any>>;
|
|
4621
|
-
|
|
4622
|
-
export { type BusEvent, type BusEventHandler, type CommonPayload, type DebugConfig, type DebugFriendlyConfig, type DefaultErrorType, type DependencyMapType, DependencyProcessor, type DependencyValueType, type DependencyValuesType, type DurableAuditEmitter, type DurableAuditEntry, type DurableAuditEntryBase, type DurableAuditEntryInput, DurableAuditEntryKind, DurableContext, DurableExecutionError, DurableOperator, DurableResource$1 as DurableResource, type DurableResourceConfig, type DurableResourceRuntimeConfig, DurableService, type DurableServiceConfig, type DurableSignalId, type DurableStepId, type DurableTask, type DurableTestSetup, type DurableTestSetupOptions, DurableWorker, type EmitOptions, type ErrorReference, errors as Errors, type EventDeliveryMode, type EventEmissionInterceptor, type EventHandlerType, EventManager, type EventStoreElementType, type ExecuteOptions, type Execution, type ExecutionJournal, ExecutionStatus, type ExposureFetchAuthConfig, type ExposureFetchClient, type ExposureFetchConfig, type ExtractEventPayload, type ExtractResourceConfig, type ExtractResourceValue, type ExtractTaskInput, type ExtractTaskOutput, type HookExecutionInterceptor, type HookStoreElementType, type HttpClient, type HttpClientAuth, type HttpClientConfig, type HttpClientFactory, type HttpClientFactoryConfig, type HttpSmartClient, type HttpSmartClientAuthConfig, type HttpSmartClientConfig, type IAsyncContext, type IAsyncContextDefinition, type IAsyncContextMeta, type ICacheInstance, type IDurableContext, type IDurableExecutionProcessor, type IDurableResource, type IDurableService, type IDurableStore, type IErrorDefinition, type IErrorDefinitionFinal, type IErrorHelper, type IErrorMeta, type IEvent, type IEventBus, type IEventDefinition, type IEventEmission, type IEventHandlerOptions, type IEventMeta, type IHook, type IHookDefinition, type ILog, type ILogInfo, type IMeta, type IMiddlewareMeta, type IOptionalDependency, type IPhantomTask, type IResource, type IResourceDefinition, type IResourceMeta, type IResourceMiddleware, type IResourceMiddlewareConfigured, type IResourceMiddlewareDefinition, type IResourceMiddlewareExecutionInput, type IResourceWithConfig, type IStepBuilder, type ITag, type ITagConfigured, type ITagDefinition, type ITagMeta, type ITaggable, type ITask, type ITaskDefinition, type ITaskExecutor, type ITaskMeta, type ITaskMiddleware, type ITaskMiddlewareConfigured, type ITaskMiddlewareDefinition, type ITaskMiddlewareExecutionInput, type IValidationSchema, type JournalKey, type JsonLimits, type ListExecutionsOptions, type LogLevels, Logger, MemoryEventBus, MemoryQueue, MemoryStore, MiddlewareManager, type MixedHttpClient, type MixedHttpClientAuthConfig, type MixedHttpClientConfig, type NodeExposureConfig, type NodeExposureDependencyMap, type NodeExposureDeps, type NodeExposureHandlers, type NodeExposureHttpConfig, type NodeExposureHttpCorsConfig, NoopEventBus, type OnUnhandledError, type OnUnhandledErrorInfo, type OverridableElements, PlatformAdapter, type PrintStrategy, Queue, RabbitMQQueue, RedisEventBus, RedisStore, type RegisterableItems, type RequiredKeys, type ResourceDependencyValueType, type ResourceDependencyValuesType, type ResourceForkInfo, type ResourceForkOptions, type ResourceForkRegisterMode, type ResourceInitFn, ResourceInitializer, type ResourceMiddlewareAttachmentType, type ResourceMiddlewareInterceptor, type ResourceMiddlewareStoreElementType, type ResourceStoreElementType, type RunOptions, RunResult, RunnerMode, type Schedule, type ScheduleConfig, type ScheduleOptions, ScheduleStatus, ScheduleType, Semaphore, Serializer, type SerializerOptions, type SignalOptions, type SleepOptions, StepBuilder, type StepOptions, type StepResult, Store, SuspensionSignal, type TagType, type TaskCallOptions, type TaskDependencyWithIntercept, type TaskLocalInterceptor, type TaskMiddlewareAttachmentType, type TaskMiddlewareInterceptor, type TaskMiddlewareStoreElementType, TaskRunner, type TaskStoreElementType, type ThrowsList, type Timer, TimerStatus, TimerType, type TunnelEventSelector, type TunnelMode, type TunnelRunner, type TunnelTagConfig, type TunnelTaskRunner, type TunnelTaskSelector, type TypeDefinition, type UnhandledErrorKind, type UnionToIntersection, allFalse, defineAsyncContext as asyncContext, bindProcessErrorHandler, createContext, createDashboardMiddleware, createDefaultUnhandledError, createDurableAuditEntryId, createDurableRunnerAuditEmitter, createDurableStepId, createDurableTestSetup, createExposureFetch, createHttpClient, createHttpMixedClient, createHttpSmartClient, createNodeFile, createTestResource, debug, debugLevels, defs as definitions, disposeDurableService, durableEvents, durableEventsArray, durableResource, defineEvent as event, getConfig, getDefaultSerializer, globals, hasExposureContext, defineHook as hook, initDurableService, initDurableWorker, isDurableInternalStepId, isOneOf, journal, levelNormal, levelVerbose, nodeExposure, normalizeError, onAnyOf, defineOverride as override, r, readInputFileToBuffer, defineResource as resource, defineResourceMiddleware as resourceMiddleware, run, safeReportUnhandledError, setPlatform, symbolAsyncContext, symbolError, symbolEvent, symbolFilePath, symbolHook, symbolMiddleware, symbolMiddlewareConfigured, symbolOptionalDependency, symbolPhantomTask, symbolResource, symbolResourceForkedFrom, symbolResourceMiddleware, symbolResourceWithConfig, symbolTag, symbolTagConfigured, symbolTask, symbolTaskMiddleware, symbolTunneledBy, defineTag as tag, defineTask as task, defineTaskMiddleware as taskMiddleware, useExposureContext, waitUntil, writeInputFileToPath };
|