@bluelibs/runner 3.4.2 → 4.0.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/AI.md +621 -0
- package/README.md +1024 -577
- package/dist/context.d.ts +4 -8
- package/dist/context.js +5 -12
- package/dist/context.js.map +1 -1
- package/dist/define.d.ts +9 -113
- package/dist/define.js +29 -358
- package/dist/define.js.map +1 -1
- package/dist/definers/defineEvent.d.ts +2 -0
- package/dist/definers/defineEvent.js +23 -0
- package/dist/definers/defineEvent.js.map +1 -0
- package/dist/definers/defineHook.d.ts +6 -0
- package/dist/definers/defineHook.js +24 -0
- package/dist/definers/defineHook.js.map +1 -0
- package/dist/definers/defineOverride.d.ts +14 -0
- package/dist/definers/defineOverride.js +13 -0
- package/dist/definers/defineOverride.js.map +1 -0
- package/dist/definers/defineResource.d.ts +2 -0
- package/dist/definers/defineResource.js +69 -0
- package/dist/definers/defineResource.js.map +1 -0
- package/dist/definers/defineResourceMiddleware.d.ts +2 -0
- package/dist/definers/defineResourceMiddleware.js +42 -0
- package/dist/definers/defineResourceMiddleware.js.map +1 -0
- package/dist/definers/defineTag.d.ts +12 -0
- package/dist/definers/defineTag.js +106 -0
- package/dist/definers/defineTag.js.map +1 -0
- package/dist/definers/defineTask.d.ts +15 -0
- package/dist/definers/defineTask.js +42 -0
- package/dist/definers/defineTask.js.map +1 -0
- package/dist/definers/defineTaskMiddleware.d.ts +2 -0
- package/dist/definers/defineTaskMiddleware.js +42 -0
- package/dist/definers/defineTaskMiddleware.js.map +1 -0
- package/dist/definers/tools.d.ts +45 -0
- package/dist/definers/tools.js +75 -0
- package/dist/definers/tools.js.map +1 -0
- package/dist/defs.d.ts +16 -424
- package/dist/defs.js +26 -38
- package/dist/defs.js.map +1 -1
- package/dist/errors.d.ts +23 -8
- package/dist/errors.js +50 -10
- package/dist/errors.js.map +1 -1
- package/dist/globals/globalEvents.d.ts +15 -39
- package/dist/globals/globalEvents.js +20 -81
- package/dist/globals/globalEvents.js.map +1 -1
- package/dist/globals/globalMiddleware.d.ts +24 -17
- package/dist/globals/globalMiddleware.js +12 -4
- package/dist/globals/globalMiddleware.js.map +1 -1
- package/dist/globals/globalResources.d.ts +13 -28
- package/dist/globals/globalResources.js +15 -7
- package/dist/globals/globalResources.js.map +1 -1
- package/dist/globals/globalTags.d.ts +9 -0
- package/dist/globals/globalTags.js +23 -0
- package/dist/globals/globalTags.js.map +1 -0
- package/dist/globals/middleware/cache.middleware.d.ts +10 -17
- package/dist/globals/middleware/cache.middleware.js +4 -16
- package/dist/globals/middleware/cache.middleware.js.map +1 -1
- package/dist/globals/middleware/requireContext.middleware.d.ts +1 -1
- package/dist/globals/middleware/requireContext.middleware.js +5 -14
- package/dist/globals/middleware/requireContext.middleware.js.map +1 -1
- package/dist/globals/middleware/retry.middleware.d.ts +2 -1
- package/dist/globals/middleware/retry.middleware.js +32 -5
- package/dist/globals/middleware/retry.middleware.js.map +1 -1
- package/dist/globals/middleware/timeout.middleware.d.ts +2 -1
- package/dist/globals/middleware/timeout.middleware.js +31 -5
- package/dist/globals/middleware/timeout.middleware.js.map +1 -1
- package/dist/globals/resources/debug/debug.resource.d.ts +7 -0
- package/dist/globals/resources/debug/debug.resource.js +29 -0
- package/dist/globals/resources/debug/debug.resource.js.map +1 -0
- package/dist/globals/resources/debug/debug.tag.d.ts +2 -0
- package/dist/globals/resources/debug/debug.tag.js +12 -0
- package/dist/globals/resources/debug/debug.tag.js.map +1 -0
- package/dist/globals/resources/debug/debugConfig.resource.d.ts +22 -0
- package/dist/globals/resources/debug/debugConfig.resource.js +20 -0
- package/dist/globals/resources/debug/debugConfig.resource.js.map +1 -0
- package/dist/globals/resources/debug/executionTracker.middleware.d.ts +50 -0
- package/dist/globals/resources/debug/executionTracker.middleware.js +87 -0
- package/dist/globals/resources/debug/executionTracker.middleware.js.map +1 -0
- package/dist/globals/resources/debug/globalEvent.hook.d.ts +27 -0
- package/dist/globals/resources/debug/globalEvent.hook.js +38 -0
- package/dist/globals/resources/debug/globalEvent.hook.js.map +1 -0
- package/dist/globals/resources/debug/hook.hook.d.ts +25 -0
- package/dist/globals/resources/debug/hook.hook.js +42 -0
- package/dist/globals/resources/debug/hook.hook.js.map +1 -0
- package/dist/globals/resources/debug/index.d.ts +6 -0
- package/dist/{types → globals/resources/debug}/index.js +6 -11
- package/dist/globals/resources/debug/index.js.map +1 -0
- package/dist/globals/resources/debug/middleware.hook.d.ts +25 -0
- package/dist/globals/resources/debug/middleware.hook.js +71 -0
- package/dist/globals/resources/debug/middleware.hook.js.map +1 -0
- package/dist/globals/resources/debug/types.d.ts +25 -0
- package/dist/globals/resources/debug/types.js +65 -0
- package/dist/globals/resources/debug/types.js.map +1 -0
- package/dist/globals/resources/debug/utils.d.ts +2 -0
- package/dist/globals/resources/debug/utils.js +9 -0
- package/dist/globals/resources/debug/utils.js.map +1 -0
- package/dist/globals/resources/queue.resource.d.ts +3 -3
- package/dist/globals/resources/queue.resource.js.map +1 -1
- package/dist/globals/types.d.ts +1 -0
- package/dist/{task.types.js → globals/types.js} +2 -7
- package/dist/globals/types.js.map +1 -0
- package/dist/index.d.ts +58 -85
- package/dist/index.js +23 -10
- package/dist/index.js.map +1 -1
- package/dist/models/DependencyProcessor.d.ts +8 -6
- package/dist/models/DependencyProcessor.js +116 -33
- package/dist/models/DependencyProcessor.js.map +1 -1
- package/dist/models/EventManager.d.ts +127 -7
- package/dist/models/EventManager.js +251 -78
- package/dist/models/EventManager.js.map +1 -1
- package/dist/models/LogPrinter.d.ts +55 -0
- package/dist/models/LogPrinter.js +196 -0
- package/dist/models/LogPrinter.js.map +1 -0
- package/dist/models/Logger.d.ts +47 -27
- package/dist/models/Logger.js +133 -155
- package/dist/models/Logger.js.map +1 -1
- package/dist/models/MiddlewareManager.d.ts +86 -0
- package/dist/models/MiddlewareManager.js +409 -0
- package/dist/models/MiddlewareManager.js.map +1 -0
- package/dist/models/OverrideManager.d.ts +3 -3
- package/dist/models/OverrideManager.js +22 -7
- package/dist/models/OverrideManager.js.map +1 -1
- package/dist/models/ResourceInitializer.d.ts +4 -3
- package/dist/models/ResourceInitializer.js +12 -68
- package/dist/models/ResourceInitializer.js.map +1 -1
- package/dist/models/RunResult.d.ts +35 -0
- package/dist/models/RunResult.js +68 -0
- package/dist/models/RunResult.js.map +1 -0
- package/dist/models/Store.d.ts +30 -17
- package/dist/models/Store.js +87 -25
- package/dist/models/Store.js.map +1 -1
- package/dist/models/StoreRegistry.d.ts +34 -19
- package/dist/models/StoreRegistry.js +248 -100
- package/dist/models/StoreRegistry.js.map +1 -1
- package/dist/models/StoreValidator.d.ts +5 -7
- package/dist/models/StoreValidator.js +50 -17
- package/dist/models/StoreValidator.js.map +1 -1
- package/dist/models/TaskRunner.d.ts +3 -2
- package/dist/models/TaskRunner.js +6 -103
- package/dist/models/TaskRunner.js.map +1 -1
- package/dist/models/UnhandledError.d.ts +11 -0
- package/dist/models/UnhandledError.js +30 -0
- package/dist/models/UnhandledError.js.map +1 -0
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.js +3 -0
- package/dist/models/index.js.map +1 -1
- package/dist/{tools → models/utils}/findCircularDependencies.js +8 -16
- package/dist/models/utils/findCircularDependencies.js.map +1 -0
- package/dist/models/utils/safeStringify.d.ts +3 -0
- package/dist/models/utils/safeStringify.js +45 -0
- package/dist/models/utils/safeStringify.js.map +1 -0
- package/dist/processHooks.d.ts +2 -0
- package/dist/processHooks.js +70 -0
- package/dist/processHooks.js.map +1 -0
- package/dist/run.d.ts +14 -27
- package/dist/run.js +100 -36
- package/dist/run.js.map +1 -1
- package/dist/testing.d.ts +5 -4
- package/dist/testing.js +3 -2
- package/dist/testing.js.map +1 -1
- package/dist/tools/getCallerFile.d.ts +0 -8
- package/dist/tools/getCallerFile.js +0 -51
- package/dist/tools/getCallerFile.js.map +1 -1
- package/dist/types/contracts.d.ts +55 -0
- package/dist/types/contracts.js +4 -0
- package/dist/types/contracts.js.map +1 -0
- package/dist/types/event.d.ts +26 -7
- package/dist/types/event.js +1 -1
- package/dist/types/event.js.map +1 -1
- package/dist/types/hook.d.ts +21 -0
- package/dist/{models/StoreTypes.js → types/hook.js} +2 -1
- package/dist/types/hook.js.map +1 -0
- package/dist/types/meta.d.ts +6 -1
- package/dist/types/meta.js +4 -2
- package/dist/types/meta.js.map +1 -1
- package/dist/types/resource.d.ts +40 -52
- package/dist/types/resource.js +1 -0
- package/dist/types/resource.js.map +1 -1
- package/dist/types/resourceMiddleware.d.ts +47 -0
- package/dist/{middleware.types.js → types/resourceMiddleware.js} +1 -1
- package/dist/types/resourceMiddleware.js.map +1 -0
- package/dist/types/runner.d.ts +37 -0
- package/dist/types/{base.js → runner.js} +1 -1
- package/dist/types/runner.js.map +1 -0
- package/dist/types/storeTypes.d.ts +40 -0
- package/dist/types/{metadata.js → storeTypes.js} +1 -1
- package/dist/types/storeTypes.js.map +1 -0
- package/dist/types/symbols.d.ts +10 -21
- package/dist/types/symbols.js +17 -22
- package/dist/types/symbols.js.map +1 -1
- package/dist/types/tag.d.ts +46 -0
- package/dist/{resource.types.js → types/tag.js} +2 -1
- package/dist/types/tag.js.map +1 -0
- package/dist/types/task.d.ts +28 -52
- package/dist/types/task.js +1 -0
- package/dist/types/task.js.map +1 -1
- package/dist/types/taskMiddleware.d.ts +48 -0
- package/dist/{event.types.js → types/taskMiddleware.js} +1 -1
- package/dist/types/taskMiddleware.js.map +1 -0
- package/dist/types/utilities.d.ts +105 -6
- package/dist/types/utilities.js +16 -2
- package/dist/types/utilities.js.map +1 -1
- package/package.json +14 -5
- package/dist/cli/extract-docs.d.ts +0 -2
- package/dist/cli/extract-docs.js +0 -88
- package/dist/cli/extract-docs.js.map +0 -1
- package/dist/common.types.d.ts +0 -20
- package/dist/common.types.js +0 -4
- package/dist/common.types.js.map +0 -1
- package/dist/defs/core.d.ts +0 -144
- package/dist/defs/core.js +0 -6
- package/dist/defs/core.js.map +0 -1
- package/dist/defs/symbols.d.ts +0 -42
- package/dist/defs/symbols.js +0 -45
- package/dist/defs/symbols.js.map +0 -1
- package/dist/defs/tags.d.ts +0 -70
- package/dist/defs/tags.js +0 -6
- package/dist/defs/tags.js.map +0 -1
- package/dist/defs.returnTag.d.ts +0 -36
- package/dist/defs.returnTag.js +0 -4
- package/dist/defs.returnTag.js.map +0 -1
- package/dist/docs/introspect.d.ts +0 -7
- package/dist/docs/introspect.js +0 -199
- package/dist/docs/introspect.js.map +0 -1
- package/dist/docs/markdown.d.ts +0 -2
- package/dist/docs/markdown.js +0 -148
- package/dist/docs/markdown.js.map +0 -1
- package/dist/docs/model.d.ts +0 -62
- package/dist/docs/model.js +0 -33
- package/dist/docs/model.js.map +0 -1
- package/dist/event.types.d.ts +0 -18
- package/dist/event.types.js.map +0 -1
- package/dist/examples/express-mongo/index.d.ts +0 -0
- package/dist/examples/express-mongo/index.js +0 -3
- package/dist/examples/express-mongo/index.js.map +0 -1
- package/dist/examples/registrator-example.d.ts +0 -122
- package/dist/examples/registrator-example.js +0 -147
- package/dist/examples/registrator-example.js.map +0 -1
- package/dist/express/docsRouter.d.ts +0 -12
- package/dist/express/docsRouter.js +0 -54
- package/dist/express/docsRouter.js.map +0 -1
- package/dist/globalEvents.d.ts +0 -40
- package/dist/globalEvents.js +0 -94
- package/dist/globalEvents.js.map +0 -1
- package/dist/globalResources.d.ts +0 -10
- package/dist/globalResources.js +0 -43
- package/dist/globalResources.js.map +0 -1
- package/dist/middleware.types.d.ts +0 -40
- package/dist/middleware.types.js.map +0 -1
- package/dist/models/StoreConstants.d.ts +0 -14
- package/dist/models/StoreConstants.js +0 -19
- package/dist/models/StoreConstants.js.map +0 -1
- package/dist/models/StoreTypes.d.ts +0 -21
- package/dist/models/StoreTypes.js.map +0 -1
- package/dist/models/VarStore.d.ts +0 -17
- package/dist/models/VarStore.js +0 -60
- package/dist/models/VarStore.js.map +0 -1
- package/dist/resource.types.d.ts +0 -31
- package/dist/resource.types.js.map +0 -1
- package/dist/symbols.d.ts +0 -24
- package/dist/symbols.js +0 -29
- package/dist/symbols.js.map +0 -1
- package/dist/t1.d.ts +0 -1
- package/dist/t1.js +0 -13
- package/dist/t1.js.map +0 -1
- package/dist/task.types.d.ts +0 -55
- package/dist/task.types.js.map +0 -1
- package/dist/tools/findCircularDependencies.js.map +0 -1
- package/dist/tools/registratorId.d.ts +0 -4
- package/dist/tools/registratorId.js +0 -40
- package/dist/tools/registratorId.js.map +0 -1
- package/dist/tools/simpleHash.d.ts +0 -9
- package/dist/tools/simpleHash.js +0 -34
- package/dist/tools/simpleHash.js.map +0 -1
- package/dist/types/base-interfaces.d.ts +0 -18
- package/dist/types/base-interfaces.js +0 -6
- package/dist/types/base-interfaces.js.map +0 -1
- package/dist/types/base.d.ts +0 -13
- package/dist/types/base.js.map +0 -1
- package/dist/types/dependencies.d.ts +0 -51
- package/dist/types/dependencies.js +0 -3
- package/dist/types/dependencies.js.map +0 -1
- package/dist/types/dependency-core.d.ts +0 -14
- package/dist/types/dependency-core.js +0 -5
- package/dist/types/dependency-core.js.map +0 -1
- package/dist/types/events.d.ts +0 -52
- package/dist/types/events.js +0 -6
- package/dist/types/events.js.map +0 -1
- package/dist/types/hooks.d.ts +0 -16
- package/dist/types/hooks.js +0 -5
- package/dist/types/hooks.js.map +0 -1
- package/dist/types/index.d.ts +0 -8
- package/dist/types/index.js.map +0 -1
- package/dist/types/metadata.d.ts +0 -75
- package/dist/types/metadata.js.map +0 -1
- package/dist/types/middleware.d.ts +0 -63
- package/dist/types/middleware.js +0 -3
- package/dist/types/middleware.js.map +0 -1
- package/dist/types/registerable.d.ts +0 -10
- package/dist/types/registerable.js +0 -5
- package/dist/types/registerable.js.map +0 -1
- package/dist/types/resources.d.ts +0 -44
- package/dist/types/resources.js +0 -5
- package/dist/types/resources.js.map +0 -1
- package/dist/types/tasks.d.ts +0 -41
- package/dist/types/tasks.js +0 -5
- package/dist/types/tasks.js.map +0 -1
- package/src/__tests__/benchmark/benchmark.test.ts +0 -148
- package/src/__tests__/benchmark/task-benchmark.test.ts +0 -132
- package/src/__tests__/context.test.ts +0 -91
- package/src/__tests__/createTestResource.test.ts +0 -139
- package/src/__tests__/errors.test.ts +0 -341
- package/src/__tests__/globalEvents.test.ts +0 -542
- package/src/__tests__/globals/cache.middleware.test.ts +0 -772
- package/src/__tests__/globals/queue.resource.test.ts +0 -141
- package/src/__tests__/globals/requireContext.middleware.test.ts +0 -98
- package/src/__tests__/globals/retry.middleware.test.ts +0 -157
- package/src/__tests__/globals/timeout.middleware.test.ts +0 -88
- package/src/__tests__/index.helper.test.ts +0 -55
- package/src/__tests__/models/EventManager.test.ts +0 -585
- package/src/__tests__/models/Logger.test.ts +0 -519
- package/src/__tests__/models/Queue.test.ts +0 -189
- package/src/__tests__/models/ResourceInitializer.test.ts +0 -148
- package/src/__tests__/models/Semaphore.test.ts +0 -713
- package/src/__tests__/models/Store.test.ts +0 -227
- package/src/__tests__/models/TaskRunner.test.ts +0 -221
- package/src/__tests__/override.test.ts +0 -104
- package/src/__tests__/recursion/README.md +0 -3
- package/src/__tests__/recursion/a.resource.ts +0 -25
- package/src/__tests__/recursion/b.resource.ts +0 -33
- package/src/__tests__/recursion/c.resource.ts +0 -18
- package/src/__tests__/run.anonymous.test.ts +0 -706
- package/src/__tests__/run.dynamic-register-and-dependencies.test.ts +0 -1185
- package/src/__tests__/run.middleware.test.ts +0 -549
- package/src/__tests__/run.overrides.test.ts +0 -424
- package/src/__tests__/run.test.ts +0 -1040
- package/src/__tests__/setOutput.test.ts +0 -244
- package/src/__tests__/tags.test.ts +0 -396
- package/src/__tests__/tools/findCircularDependencies.test.ts +0 -217
- package/src/__tests__/tools/getCallerFile.test.ts +0 -179
- package/src/__tests__/typesafety.test.ts +0 -423
- package/src/__tests__/validation-edge-cases.test.ts +0 -111
- package/src/__tests__/validation-interface.test.ts +0 -428
- package/src/context.ts +0 -86
- package/src/define.ts +0 -480
- package/src/defs.returnTag.ts +0 -91
- package/src/defs.ts +0 -596
- package/src/errors.ts +0 -105
- package/src/globals/globalEvents.ts +0 -125
- package/src/globals/globalMiddleware.ts +0 -16
- package/src/globals/globalResources.ts +0 -53
- package/src/globals/middleware/cache.middleware.ts +0 -115
- package/src/globals/middleware/requireContext.middleware.ts +0 -36
- package/src/globals/middleware/retry.middleware.ts +0 -56
- package/src/globals/middleware/timeout.middleware.ts +0 -46
- package/src/globals/resources/queue.resource.ts +0 -34
- package/src/index.ts +0 -39
- package/src/models/DependencyProcessor.ts +0 -257
- package/src/models/EventManager.ts +0 -210
- package/src/models/Logger.ts +0 -282
- package/src/models/OverrideManager.ts +0 -79
- package/src/models/Queue.ts +0 -66
- package/src/models/ResourceInitializer.ts +0 -165
- package/src/models/Semaphore.ts +0 -208
- package/src/models/Store.ts +0 -193
- package/src/models/StoreConstants.ts +0 -18
- package/src/models/StoreRegistry.ts +0 -253
- package/src/models/StoreTypes.ts +0 -47
- package/src/models/StoreValidator.ts +0 -43
- package/src/models/TaskRunner.ts +0 -203
- package/src/models/index.ts +0 -8
- package/src/run.ts +0 -116
- package/src/testing.ts +0 -66
- package/src/tools/findCircularDependencies.ts +0 -69
- package/src/tools/getCallerFile.ts +0 -96
- /package/dist/{tools → models/utils}/findCircularDependencies.d.ts +0 -0
package/src/defs.ts
DELETED
|
@@ -1,596 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core public TypeScript types for BlueLibs Runner.
|
|
3
|
-
*
|
|
4
|
-
* This file contains the strongly-typed contract for tasks, resources, events
|
|
5
|
-
* and middleware. It mirrors the mental model described in the README:
|
|
6
|
-
* - Tasks are functions (with lifecycle events)
|
|
7
|
-
* - Resources are singletons (with init/dispose hooks and lifecycle events)
|
|
8
|
-
* - Events are simple, strongly-typed emissions
|
|
9
|
-
* - Middleware can target both tasks and resources
|
|
10
|
-
*
|
|
11
|
-
* DX goals:
|
|
12
|
-
* - Crystal‑clear generics and helper types that infer dependency shapes
|
|
13
|
-
* - Friendly JSDoc you can hover in editors to understand usage instantly
|
|
14
|
-
* - Safe overrides and strong typing around config and register mechanics
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { MiddlewareEverywhereOptions } from "./define";
|
|
18
|
-
import {
|
|
19
|
-
EnsureResponseSatisfiesContracts,
|
|
20
|
-
HasContracts,
|
|
21
|
-
} from "./defs.returnTag";
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Generic validation schema interface that can be implemented by any validation library.
|
|
25
|
-
* Compatible with Zod, Yup, Joi, and other validation libraries.
|
|
26
|
-
*/
|
|
27
|
-
export interface IValidationSchema<T = any> {
|
|
28
|
-
/**
|
|
29
|
-
* Parse and validate the input data.
|
|
30
|
-
* Should throw an error if validation fails.
|
|
31
|
-
* Can transform the data if the schema supports transformations.
|
|
32
|
-
*/
|
|
33
|
-
parse(input: unknown): T;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Re-export public cache type so consumers don’t import from internals.
|
|
37
|
-
export { ICacheInstance } from "./globals/middleware/cache.middleware";
|
|
38
|
-
export * from "./models/StoreTypes";
|
|
39
|
-
/**
|
|
40
|
-
* Internal brand symbols used to tag created objects at runtime and help with
|
|
41
|
-
* type‑narrowing. Prefer the `isTask`/`isResource`/`isEvent`/`isMiddleware`
|
|
42
|
-
* helpers instead of touching these directly.
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
export const symbolTask: unique symbol = Symbol("runner.task");
|
|
46
|
-
export const symbolResource: unique symbol = Symbol("runner.resource");
|
|
47
|
-
export const symbolResourceWithConfig: unique symbol = Symbol(
|
|
48
|
-
"runner.resourceWithConfig"
|
|
49
|
-
);
|
|
50
|
-
export const symbolEvent: unique symbol = Symbol("runner.event");
|
|
51
|
-
export const symbolMiddleware: unique symbol = Symbol("runner.middleware");
|
|
52
|
-
export const symbolMiddlewareConfigured: unique symbol = Symbol(
|
|
53
|
-
"runner.middlewareConfigured"
|
|
54
|
-
);
|
|
55
|
-
export const symbolMiddlewareGlobal: unique symbol = Symbol(
|
|
56
|
-
"runner.middlewareGlobal"
|
|
57
|
-
);
|
|
58
|
-
export const symbolMiddlewareEverywhereTasks: unique symbol = Symbol(
|
|
59
|
-
"runner.middlewareGlobalTasks"
|
|
60
|
-
);
|
|
61
|
-
export const symbolMiddlewareEverywhereResources: unique symbol = Symbol(
|
|
62
|
-
"runner.middlewareGlobalResources"
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
/** @internal Path to aid anonymous id generation and error messages */
|
|
66
|
-
export const symbolFilePath: unique symbol = Symbol("runner.filePath");
|
|
67
|
-
/** @internal Marks disposable instances */
|
|
68
|
-
export const symbolDispose: unique symbol = Symbol("runner.dispose");
|
|
69
|
-
/** @internal Link to internal Store */
|
|
70
|
-
export const symbolStore: unique symbol = Symbol("runner.store");
|
|
71
|
-
|
|
72
|
-
/** @internal Brand used by index() resources */
|
|
73
|
-
export const symbolIndexResource: unique symbol = Symbol(
|
|
74
|
-
"runner.indexResource"
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
export interface ITagDefinition<TConfig = void, TEnforceContract = void> {
|
|
78
|
-
id: string | symbol;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* A configured instance of a tag as produced by `ITag.with()`.
|
|
83
|
-
*/
|
|
84
|
-
export interface ITagWithConfig<TConfig = void, TEnforceContract = void> {
|
|
85
|
-
id: string | symbol;
|
|
86
|
-
/** The tag definition used to produce this configured instance. */
|
|
87
|
-
tag: ITag<TConfig, TEnforceContract>;
|
|
88
|
-
/** The configuration captured for this tag instance. */
|
|
89
|
-
config: TConfig;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* A tag definition (builder). Use `.with(config)` to obtain configured instances,
|
|
94
|
-
* and `.extract(tags)` to find either a configured instance or the bare tag in a list.
|
|
95
|
-
*/
|
|
96
|
-
export interface ITag<TConfig = void, TEnforceContract = void>
|
|
97
|
-
extends ITagDefinition<TConfig, TEnforceContract> {
|
|
98
|
-
/**
|
|
99
|
-
* Creates a configured instance of the tag.
|
|
100
|
-
*/
|
|
101
|
-
with(config: TConfig): ITagWithConfig<TConfig, TEnforceContract>;
|
|
102
|
-
/**
|
|
103
|
-
* Extracts either a configured instance or the bare tag from a list of tags
|
|
104
|
-
* or from a taggable object (`{ meta: { tags?: [] } }`).
|
|
105
|
-
*/
|
|
106
|
-
extract(
|
|
107
|
-
target: TagType[] | ITaggable
|
|
108
|
-
): ExtractedTagResult<TConfig, TEnforceContract> | null;
|
|
109
|
-
[symbolFilePath]: string;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Restrict bare tags to those whose config can be omitted (void or optional object),
|
|
114
|
-
* mirroring the same principle used for resources in `RegisterableItems`.
|
|
115
|
-
* Required-config tags must appear as configured instances.
|
|
116
|
-
*/
|
|
117
|
-
export type TagType =
|
|
118
|
-
| string
|
|
119
|
-
| ITag<void, any>
|
|
120
|
-
| ITag<{ [K in any]?: any }, any>
|
|
121
|
-
| ITagWithConfig<any, any>;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Conditional result type for `ITag.extract`:
|
|
125
|
-
* - For void config → just the identifier
|
|
126
|
-
* - For optional object config → identifier with optional config
|
|
127
|
-
* - For required config → identifier with required config
|
|
128
|
-
*/
|
|
129
|
-
export type ExtractedTagResult<TConfig, TEnforceContract> = {} extends TConfig
|
|
130
|
-
? { id: string | symbol; config?: TConfig }
|
|
131
|
-
: { id: string | symbol; config: TConfig };
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Any object that can carry tags via metadata. This mirrors how tasks,
|
|
135
|
-
* resources, events, and middleware expose `meta.tags`.
|
|
136
|
-
*/
|
|
137
|
-
export interface ITaggable {
|
|
138
|
-
meta?: {
|
|
139
|
-
tags?: TagType[];
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Common metadata you can attach to tasks/resources/events/middleware.
|
|
144
|
-
* Useful for docs, filtering and middleware decisions.
|
|
145
|
-
*/
|
|
146
|
-
export interface IMeta {
|
|
147
|
-
title?: string;
|
|
148
|
-
description?: string;
|
|
149
|
-
tags?: TagType[];
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export interface ITaskMeta extends IMeta {}
|
|
153
|
-
export interface IResourceMeta extends IMeta {}
|
|
154
|
-
export interface IEventMeta extends IMeta {}
|
|
155
|
-
export interface IMiddlewareMeta extends IMeta {}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* A mapping of dependency keys to Runner definitions. Used in `dependencies`
|
|
159
|
-
* for tasks and resources. Values are later transformed into the actual
|
|
160
|
-
* callable/value shape by `DependencyValuesType`.
|
|
161
|
-
*/
|
|
162
|
-
export type DependencyMapType = Record<
|
|
163
|
-
string,
|
|
164
|
-
ITask<any, any, any, any> | IResource<any, any, any> | IEventDefinition<any>
|
|
165
|
-
>;
|
|
166
|
-
|
|
167
|
-
// Helper Types for Extracting Generics
|
|
168
|
-
type ExtractTaskInput<T> = T extends ITask<infer I, any, infer D> ? I : never;
|
|
169
|
-
type ExtractTaskOutput<T> = T extends ITask<any, infer O, infer D> ? O : never;
|
|
170
|
-
type ExtractResourceValue<T> = T extends IResource<any, infer V, infer D>
|
|
171
|
-
? V extends Promise<infer U>
|
|
172
|
-
? U
|
|
173
|
-
: V
|
|
174
|
-
: never;
|
|
175
|
-
|
|
176
|
-
type ExtractEventParams<T> = T extends IEvent<infer P> ? P : never;
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Task dependencies transform into callable functions: call with the task input
|
|
180
|
-
* and you receive the task output.
|
|
181
|
-
*/
|
|
182
|
-
type TaskDependency<I, O> = (...args: I extends null | void ? [] : [I]) => O;
|
|
183
|
-
/**
|
|
184
|
-
* Resource dependencies resolve to the resource's value directly.
|
|
185
|
-
*/
|
|
186
|
-
type ResourceDependency<V> = V;
|
|
187
|
-
/**
|
|
188
|
-
* Event dependencies resolve to an emitter function. If the payload type is
|
|
189
|
-
* `void`, the function can be called with zero args (or an empty object).
|
|
190
|
-
*/
|
|
191
|
-
type EventDependency<P> = P extends void
|
|
192
|
-
? (() => Promise<void>) & ((input?: Record<string, never>) => Promise<void>)
|
|
193
|
-
: (input: P) => Promise<void>;
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Transforms a dependency definition into the usable shape inside `run`/`init`:
|
|
197
|
-
* - Task -> callable function
|
|
198
|
-
* - Resource -> resolved value
|
|
199
|
-
* - Event -> emit function
|
|
200
|
-
*/
|
|
201
|
-
export type DependencyValueType<T> = T extends ITask<any, any, any>
|
|
202
|
-
? TaskDependency<ExtractTaskInput<T>, ExtractTaskOutput<T>>
|
|
203
|
-
: T extends IResource<any, any>
|
|
204
|
-
? ResourceDependency<ExtractResourceValue<T>>
|
|
205
|
-
: T extends IEventDefinition<any>
|
|
206
|
-
? EventDependency<ExtractEventParams<T>>
|
|
207
|
-
: never;
|
|
208
|
-
|
|
209
|
-
export type DependencyValuesType<T extends DependencyMapType> = {
|
|
210
|
-
[K in keyof T]: DependencyValueType<T[K]>;
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Anything you can put inside a resource's `register: []`.
|
|
215
|
-
* - Resources (with or without `.with()`)
|
|
216
|
-
* - Tasks
|
|
217
|
-
* - Middleware
|
|
218
|
-
* - Events
|
|
219
|
-
*/
|
|
220
|
-
export type RegisterableItems<T = any> =
|
|
221
|
-
| IResourceWithConfig<any>
|
|
222
|
-
| IResource<void, any, any, any> // For void configs
|
|
223
|
-
| IResource<{ [K in any]?: any }, any, any, any> // For optional config
|
|
224
|
-
| ITask<any, any, any, any>
|
|
225
|
-
| IMiddleware<any>
|
|
226
|
-
| IEvent<any>;
|
|
227
|
-
|
|
228
|
-
export type MiddlewareAttachments =
|
|
229
|
-
| IMiddleware<void>
|
|
230
|
-
| IMiddleware<{ [K in any]?: any }>
|
|
231
|
-
| IMiddlewareConfigured<any>;
|
|
232
|
-
|
|
233
|
-
export interface ITaskDefinition<
|
|
234
|
-
TInput = any,
|
|
235
|
-
TOutput extends Promise<any> = any,
|
|
236
|
-
TDependencies extends DependencyMapType = {},
|
|
237
|
-
TOn extends "*" | IEventDefinition<any> | undefined = undefined, // Adding a generic to track 'on' type,
|
|
238
|
-
TMeta extends ITaskMeta = any
|
|
239
|
-
> {
|
|
240
|
-
/**
|
|
241
|
-
* Stable identifier. If omitted, an anonymous id is generated from file path
|
|
242
|
-
* (see README: Anonymous IDs).
|
|
243
|
-
*/
|
|
244
|
-
id?: string | symbol;
|
|
245
|
-
/**
|
|
246
|
-
* Access other tasks/resources/events. Can be an object or a function when
|
|
247
|
-
* you need late or config‑dependent resolution.
|
|
248
|
-
*/
|
|
249
|
-
dependencies?: TDependencies | (() => TDependencies);
|
|
250
|
-
/** Middleware applied around task execution. */
|
|
251
|
-
middleware?: MiddlewareAttachments[];
|
|
252
|
-
/**
|
|
253
|
-
* Listen to events in a simple way
|
|
254
|
-
*/
|
|
255
|
-
on?: TOn;
|
|
256
|
-
/**
|
|
257
|
-
* This makes sense only when `on` is specified to provide the order of the execution.
|
|
258
|
-
* The event with the lowest order will be executed first.
|
|
259
|
-
*/
|
|
260
|
-
listenerOrder?: number;
|
|
261
|
-
/** Optional metadata used for docs, filtering and tooling. */
|
|
262
|
-
meta?: TMeta;
|
|
263
|
-
/**
|
|
264
|
-
* Optional validation schema for runtime input validation.
|
|
265
|
-
* When provided, task input will be validated before execution.
|
|
266
|
-
*/
|
|
267
|
-
inputSchema?: IValidationSchema<TInput>;
|
|
268
|
-
/**
|
|
269
|
-
* The task body. If `on` is set, the input is an `IEventEmission`. Otherwise,
|
|
270
|
-
* it's the declared input type.
|
|
271
|
-
*/
|
|
272
|
-
run: (
|
|
273
|
-
input: TOn extends undefined
|
|
274
|
-
? TInput
|
|
275
|
-
: IEventEmission<TOn extends "*" ? any : ExtractEventParams<TOn>>,
|
|
276
|
-
dependencies: DependencyValuesType<TDependencies>
|
|
277
|
-
) => HasContracts<TMeta> extends true
|
|
278
|
-
? EnsureResponseSatisfiesContracts<TMeta, TOutput>
|
|
279
|
-
: TOutput;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export type BeforeRunEventPayload<TInput> = {
|
|
283
|
-
input: TInput;
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
export type AfterRunEventPayload<TInput, TOutput> = {
|
|
287
|
-
input: TInput;
|
|
288
|
-
output: TOutput extends Promise<infer U> ? U : TOutput;
|
|
289
|
-
setOutput(newOutput: TOutput extends Promise<infer U> ? U : TOutput): void;
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
export type OnErrorEventPayload = {
|
|
293
|
-
error: any;
|
|
294
|
-
/**
|
|
295
|
-
* This function can be called to suppress the error from being thrown.
|
|
296
|
-
*/
|
|
297
|
-
suppress(): void;
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
export type BeforeInitEventPayload<TConfig> = {
|
|
301
|
-
config: TConfig;
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
export type AfterInitEventPayload<TConfig, TValue> = {
|
|
305
|
-
config: TConfig;
|
|
306
|
-
value: TValue;
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* This is the response after the definition has been prepared. TODO: better naming?
|
|
311
|
-
*/
|
|
312
|
-
export interface ITask<
|
|
313
|
-
TInput = any,
|
|
314
|
-
TOutput extends Promise<any> = any,
|
|
315
|
-
TDependencies extends DependencyMapType = {},
|
|
316
|
-
TOn extends "*" | IEventDefinition<any> | undefined = undefined,
|
|
317
|
-
TMeta extends ITaskMeta = any
|
|
318
|
-
> extends ITaskDefinition<TInput, TOutput, TDependencies, TOn, TMeta> {
|
|
319
|
-
id: string | symbol;
|
|
320
|
-
dependencies: TDependencies | (() => TDependencies);
|
|
321
|
-
computedDependencies?: DependencyValuesType<TDependencies>;
|
|
322
|
-
middleware: MiddlewareAttachments[];
|
|
323
|
-
/**
|
|
324
|
-
* These events are automatically populated after the task has been defined.
|
|
325
|
-
*/
|
|
326
|
-
events: {
|
|
327
|
-
beforeRun: IEvent<BeforeRunEventPayload<TInput>>;
|
|
328
|
-
afterRun: IEvent<AfterRunEventPayload<TInput, TOutput>>;
|
|
329
|
-
onError: IEvent<OnErrorEventPayload>;
|
|
330
|
-
};
|
|
331
|
-
[symbolFilePath]: string;
|
|
332
|
-
[symbolTask]: true;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export interface IResourceDefinition<
|
|
336
|
-
TConfig = any,
|
|
337
|
-
TValue extends Promise<any> = Promise<any>,
|
|
338
|
-
TDependencies extends DependencyMapType = {},
|
|
339
|
-
TContext = any,
|
|
340
|
-
THooks = any,
|
|
341
|
-
TRegisterableItems = any,
|
|
342
|
-
TMeta extends IResourceMeta = any
|
|
343
|
-
> {
|
|
344
|
-
/** Stable identifier. Omit to get an anonymous id. */
|
|
345
|
-
id?: string | symbol;
|
|
346
|
-
/** Static or lazy dependency map. Receives `config` when provided. */
|
|
347
|
-
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
348
|
-
/**
|
|
349
|
-
* Register other registerables (resources/tasks/middleware/events). Accepts a
|
|
350
|
-
* static array or a function of `config` to support dynamic wiring.
|
|
351
|
-
*/
|
|
352
|
-
register?:
|
|
353
|
-
| Array<RegisterableItems>
|
|
354
|
-
| ((config: TConfig) => Array<RegisterableItems>);
|
|
355
|
-
/**
|
|
356
|
-
* Initialize and return the resource value. Called once during boot.
|
|
357
|
-
*/
|
|
358
|
-
init?: (
|
|
359
|
-
this: any,
|
|
360
|
-
config: TConfig,
|
|
361
|
-
dependencies: DependencyValuesType<TDependencies>,
|
|
362
|
-
context: TContext
|
|
363
|
-
) => HasContracts<TMeta> extends true
|
|
364
|
-
? EnsureResponseSatisfiesContracts<TMeta, TValue>
|
|
365
|
-
: TValue;
|
|
366
|
-
/**
|
|
367
|
-
* Clean-up function for the resource. This is called when the resource is no longer needed.
|
|
368
|
-
*
|
|
369
|
-
* @param value The value of the resource (undefined if no init method)
|
|
370
|
-
* @param config The configuration it received
|
|
371
|
-
* @param dependencies The dependencies it needed
|
|
372
|
-
* @returns Promise<void>
|
|
373
|
-
*/
|
|
374
|
-
dispose?: (
|
|
375
|
-
this: any,
|
|
376
|
-
value: TValue extends Promise<infer U> ? U : TValue,
|
|
377
|
-
config: TConfig,
|
|
378
|
-
dependencies: DependencyValuesType<TDependencies>,
|
|
379
|
-
context: TContext
|
|
380
|
-
) => Promise<void>;
|
|
381
|
-
meta?: TMeta;
|
|
382
|
-
/**
|
|
383
|
-
* Optional validation schema for runtime config validation.
|
|
384
|
-
* When provided, resource config will be validated when .with() is called.
|
|
385
|
-
*/
|
|
386
|
-
configSchema?: IValidationSchema<TConfig>;
|
|
387
|
-
/**
|
|
388
|
-
* Safe overrides to swap behavior while preserving identities. See
|
|
389
|
-
* README: Overrides.
|
|
390
|
-
*/
|
|
391
|
-
overrides?: Array<IResource | ITask | IMiddleware | IResourceWithConfig>;
|
|
392
|
-
/** Middleware applied around init/dispose. */
|
|
393
|
-
middleware?: MiddlewareAttachments[];
|
|
394
|
-
/**
|
|
395
|
-
* Create a private, mutable context shared between `init` and `dispose`.
|
|
396
|
-
*/
|
|
397
|
-
context?: () => TContext;
|
|
398
|
-
/**
|
|
399
|
-
* This is optional and used from an index resource to get the correct caller.
|
|
400
|
-
* This is the reason we allow it here as well.
|
|
401
|
-
*/
|
|
402
|
-
[symbolFilePath]?: string;
|
|
403
|
-
/**
|
|
404
|
-
* This is used internally when creating index resources.
|
|
405
|
-
*/
|
|
406
|
-
[symbolIndexResource]?: boolean;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
export interface IResource<
|
|
410
|
-
TConfig = void,
|
|
411
|
-
TValue extends Promise<any> = Promise<any>,
|
|
412
|
-
TDependencies extends DependencyMapType = any,
|
|
413
|
-
TContext = any,
|
|
414
|
-
TMeta extends IResourceMeta = any
|
|
415
|
-
> extends IResourceDefinition<
|
|
416
|
-
TConfig,
|
|
417
|
-
TValue,
|
|
418
|
-
TDependencies,
|
|
419
|
-
TContext,
|
|
420
|
-
any,
|
|
421
|
-
any,
|
|
422
|
-
TMeta
|
|
423
|
-
> {
|
|
424
|
-
id: string | symbol;
|
|
425
|
-
with(config: TConfig): IResourceWithConfig<TConfig, TValue, TDependencies>;
|
|
426
|
-
register:
|
|
427
|
-
| Array<RegisterableItems>
|
|
428
|
-
| ((config: TConfig) => Array<RegisterableItems>);
|
|
429
|
-
/**
|
|
430
|
-
* These events are automatically populated after the task has been defined.
|
|
431
|
-
*/
|
|
432
|
-
events: {
|
|
433
|
-
beforeInit: IEvent<BeforeInitEventPayload<TConfig>>;
|
|
434
|
-
afterInit: IEvent<AfterInitEventPayload<TConfig, TValue>>;
|
|
435
|
-
onError: IEvent<OnErrorEventPayload>;
|
|
436
|
-
};
|
|
437
|
-
overrides: Array<IResource | ITask | IMiddleware | IResourceWithConfig>;
|
|
438
|
-
middleware: MiddlewareAttachments[];
|
|
439
|
-
[symbolFilePath]: string;
|
|
440
|
-
[symbolIndexResource]: boolean;
|
|
441
|
-
[symbolResource]: true;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
export interface IResourceWithConfig<
|
|
445
|
-
TConfig = any,
|
|
446
|
-
TValue extends Promise<any> = Promise<any>,
|
|
447
|
-
TDependencies extends DependencyMapType = any
|
|
448
|
-
> {
|
|
449
|
-
/** The id of the underlying resource. */
|
|
450
|
-
id: string;
|
|
451
|
-
/** The underlying resource definition. */
|
|
452
|
-
resource: IResource<TConfig, TValue, TDependencies>;
|
|
453
|
-
/** The configuration captured by `.with(config)`. */
|
|
454
|
-
config: TConfig;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
export type EventHandlerType<T = any> = (
|
|
458
|
-
event: IEventEmission<T>
|
|
459
|
-
) => any | Promise<any>;
|
|
460
|
-
|
|
461
|
-
export interface IEventDefinition<TPayload = void> {
|
|
462
|
-
/** Stable identifier. Omit to get an anonymous id. */
|
|
463
|
-
id?: string | symbol;
|
|
464
|
-
meta?: IEventMeta;
|
|
465
|
-
/**
|
|
466
|
-
* Optional validation schema for runtime payload validation.
|
|
467
|
-
* When provided, event payload will be validated when emitted.
|
|
468
|
-
*/
|
|
469
|
-
payloadSchema?: IValidationSchema<TPayload>;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
export interface IEvent<TPayload = any> extends IEventDefinition<TPayload> {
|
|
473
|
-
id: string | symbol;
|
|
474
|
-
/**
|
|
475
|
-
* 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.
|
|
476
|
-
*/
|
|
477
|
-
[symbolEvent]: true;
|
|
478
|
-
[symbolFilePath]: string;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* This represents the object that is passed to event handlers
|
|
483
|
-
*/
|
|
484
|
-
export interface IEventEmission<TPayload = any> {
|
|
485
|
-
/**
|
|
486
|
-
* The ID of the event. This is the same as the event's ID.
|
|
487
|
-
* This is useful for global event listeners.
|
|
488
|
-
*/
|
|
489
|
-
id: string | symbol;
|
|
490
|
-
/**
|
|
491
|
-
* The data that the event carries. It can be anything.
|
|
492
|
-
*/
|
|
493
|
-
data: TPayload;
|
|
494
|
-
/**
|
|
495
|
-
* The timestamp when the event was created.
|
|
496
|
-
*/
|
|
497
|
-
timestamp: Date;
|
|
498
|
-
/**
|
|
499
|
-
* The source of the event. This can be useful for debugging.
|
|
500
|
-
*/
|
|
501
|
-
source: string | symbol;
|
|
502
|
-
/**
|
|
503
|
-
* Metadata associated with the event definition.
|
|
504
|
-
*/
|
|
505
|
-
meta: IEventMeta;
|
|
506
|
-
/**
|
|
507
|
-
* Stops propagation to remaining event listeners.
|
|
508
|
-
*/
|
|
509
|
-
stopPropagation(): void;
|
|
510
|
-
/**
|
|
511
|
-
* Returns true if propagation has been stopped.
|
|
512
|
-
*/
|
|
513
|
-
isPropagationStopped(): boolean;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
export interface IMiddlewareDefinition<
|
|
517
|
-
TConfig = any,
|
|
518
|
-
TDependencies extends DependencyMapType = any
|
|
519
|
-
> {
|
|
520
|
-
/** Stable identifier. Omit to get an anonymous id. */
|
|
521
|
-
id?: string | symbol;
|
|
522
|
-
/** Static or lazy dependency map. */
|
|
523
|
-
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
524
|
-
/**
|
|
525
|
-
* Optional validation schema for runtime config validation.
|
|
526
|
-
* When provided, middleware config will be validated when .with() is called.
|
|
527
|
-
*/
|
|
528
|
-
configSchema?: IValidationSchema<TConfig>;
|
|
529
|
-
/**
|
|
530
|
-
* The middleware body, called with task/resource execution input.
|
|
531
|
-
*/
|
|
532
|
-
run: (
|
|
533
|
-
input: IMiddlewareExecutionInput,
|
|
534
|
-
dependencies: DependencyValuesType<TDependencies>,
|
|
535
|
-
config: TConfig
|
|
536
|
-
) => Promise<any>;
|
|
537
|
-
meta?: IMiddlewareMeta;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
export interface IMiddleware<
|
|
541
|
-
TConfig = any,
|
|
542
|
-
TDependencies extends DependencyMapType = any
|
|
543
|
-
> extends IMiddlewareDefinition<TConfig, TDependencies> {
|
|
544
|
-
[symbolMiddleware]: true;
|
|
545
|
-
[symbolMiddlewareConfigured]?: boolean;
|
|
546
|
-
[symbolMiddlewareEverywhereTasks]?: boolean;
|
|
547
|
-
[symbolMiddlewareEverywhereResources]?: boolean;
|
|
548
|
-
|
|
549
|
-
id: string | symbol;
|
|
550
|
-
dependencies: TDependencies | (() => TDependencies);
|
|
551
|
-
/**
|
|
552
|
-
* Attach this middleware globally. Use options to scope to tasks/resources.
|
|
553
|
-
*/
|
|
554
|
-
everywhere(
|
|
555
|
-
config?: MiddlewareEverywhereOptions
|
|
556
|
-
): IMiddleware<TConfig, TDependencies>;
|
|
557
|
-
/** Current configuration object (empty by default). */
|
|
558
|
-
config: TConfig;
|
|
559
|
-
/** Configure the middleware and return a marked, configured instance. */
|
|
560
|
-
with: (config: TConfig) => IMiddlewareConfigured<TConfig, TDependencies>;
|
|
561
|
-
[symbolFilePath]: string;
|
|
562
|
-
[symbolMiddleware]: true;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
export interface IMiddlewareConfigured<
|
|
566
|
-
TConfig = any,
|
|
567
|
-
TDependencies extends DependencyMapType = any
|
|
568
|
-
> extends IMiddleware<TConfig, TDependencies> {
|
|
569
|
-
[symbolMiddlewareConfigured]: true;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
export interface IMiddlewareDefinitionConfigured<
|
|
573
|
-
C extends Record<string, any> = {}
|
|
574
|
-
> {
|
|
575
|
-
middleware: IMiddleware<C>;
|
|
576
|
-
config?: C;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
export interface IMiddlewareExecutionInput<
|
|
580
|
-
TTaskInput = any,
|
|
581
|
-
TResourceConfig = any
|
|
582
|
-
> {
|
|
583
|
-
/** Task hook: present when wrapping a task run. */
|
|
584
|
-
task?: {
|
|
585
|
-
definition: ITask<TTaskInput>;
|
|
586
|
-
input: TTaskInput;
|
|
587
|
-
};
|
|
588
|
-
/** Resource hook: present when wrapping init/dispose. */
|
|
589
|
-
resource?: {
|
|
590
|
-
definition: IResource<TResourceConfig, any, any, any, any>;
|
|
591
|
-
config: TResourceConfig;
|
|
592
|
-
};
|
|
593
|
-
next: (
|
|
594
|
-
taskInputOrResourceConfig?: TTaskInput | TResourceConfig
|
|
595
|
-
) => Promise<any>;
|
|
596
|
-
}
|
package/src/errors.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base error class for all BlueLibs Runner errors
|
|
3
|
-
*/
|
|
4
|
-
export class RuntimeError extends Error {
|
|
5
|
-
constructor(message: string) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.name = "RuntimeError";
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Error thrown when attempting to register a component with a duplicate ID
|
|
13
|
-
*/
|
|
14
|
-
export class DuplicateRegistrationError extends RuntimeError {
|
|
15
|
-
constructor(type: string, id: string | symbol) {
|
|
16
|
-
super(`${type} "${id.toString()}" already registered`);
|
|
17
|
-
this.name = "DuplicateRegistrationError";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Error thrown when a dependency is not found in the registry
|
|
23
|
-
*/
|
|
24
|
-
export class DependencyNotFoundError extends RuntimeError {
|
|
25
|
-
constructor(key: string | symbol) {
|
|
26
|
-
super(
|
|
27
|
-
`Dependency ${key.toString()} not found. Did you forget to register it through a resource?`
|
|
28
|
-
);
|
|
29
|
-
this.name = "DependencyNotFoundError";
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Error thrown when an unknown item type is encountered
|
|
35
|
-
*/
|
|
36
|
-
export class UnknownItemTypeError extends RuntimeError {
|
|
37
|
-
constructor(item: any) {
|
|
38
|
-
super(`Unknown item type: ${item}`);
|
|
39
|
-
this.name = "UnknownItemTypeError";
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Error thrown when circular dependencies are detected
|
|
45
|
-
*/
|
|
46
|
-
export class CircularDependenciesError extends RuntimeError {
|
|
47
|
-
constructor(cycles: string[]) {
|
|
48
|
-
super(`Circular dependencies detected: ${cycles.join(", ")}`);
|
|
49
|
-
this.name = "CircularDependenciesError";
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Error thrown when an event is not found in the registry
|
|
55
|
-
*/
|
|
56
|
-
export class EventNotFoundError extends RuntimeError {
|
|
57
|
-
constructor(id: string | symbol) {
|
|
58
|
-
super(`Event "${id.toString()}" not found. Did you forget to register it?`);
|
|
59
|
-
this.name = "EventNotFoundError";
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Error thrown when attempting to make a middleware global when it's already global
|
|
65
|
-
*/
|
|
66
|
-
export class MiddlewareAlreadyGlobalError extends RuntimeError {
|
|
67
|
-
constructor(id: string | symbol) {
|
|
68
|
-
super(
|
|
69
|
-
"Cannot call .everywhere() on an already global middleware: " +
|
|
70
|
-
id.toString()
|
|
71
|
-
);
|
|
72
|
-
this.name = "MiddlewareAlreadyGlobalError";
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Error thrown when attempting to modify a locked component
|
|
78
|
-
*/
|
|
79
|
-
export class LockedError extends RuntimeError {
|
|
80
|
-
constructor(what: string | symbol) {
|
|
81
|
-
super(`Cannot modify the ${what.toString()} when it is locked.`);
|
|
82
|
-
this.name = "LockedError";
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Error thrown when attempting to initialize a store that's already initialized
|
|
88
|
-
*/
|
|
89
|
-
export class StoreAlreadyInitializedError extends RuntimeError {
|
|
90
|
-
constructor() {
|
|
91
|
-
super("Store already initialized. Cannot reinitialize.");
|
|
92
|
-
this.name = "StoreAlreadyInitializedError";
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Error thrown when validation fails for task input, resource config, middleware config, or event payload
|
|
98
|
-
*/
|
|
99
|
-
export class ValidationError extends RuntimeError {
|
|
100
|
-
constructor(type: string, id: string | symbol, originalError: Error | string) {
|
|
101
|
-
const errorMessage = originalError instanceof Error ? originalError.message : String(originalError);
|
|
102
|
-
super(`${type} validation failed for ${id.toString()}: ${errorMessage}`);
|
|
103
|
-
this.name = "ValidationError";
|
|
104
|
-
}
|
|
105
|
-
}
|