@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/dist/testing.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { IResource, IResourceWithConfig,
|
|
1
|
+
import { IResource, IResourceWithConfig, ITaskMiddleware, IResourceMiddleware, ITask, RegisterableItems, DependencyMapType } from "./defs";
|
|
2
2
|
import { EventManager, Logger, Store, TaskRunner } from "./models";
|
|
3
3
|
/**
|
|
4
4
|
* Helper to create a minimal test harness resource that wraps a root app (or any registerable)
|
|
5
5
|
* and exposes convenient testing utilities while running the full ecosystem
|
|
6
6
|
* (registration, overrides, middleware, events) without modifying the core API.
|
|
7
|
+
* @deprecated Use `run` instead with your testResource, as it provides the necessary toolkit.
|
|
7
8
|
*/
|
|
8
9
|
export declare function createTestResource(root: RegisterableItems, options?: {
|
|
9
|
-
overrides?: Array<IResource | ITask |
|
|
10
|
+
overrides?: Array<IResource | ITask | ITaskMiddleware | IResourceMiddleware | IResourceWithConfig>;
|
|
10
11
|
}): IResource<void, Promise<ReturnType<typeof buildTestFacade>>>;
|
|
11
12
|
declare function buildTestFacade(deps: {
|
|
12
13
|
taskRunner: TaskRunner;
|
|
@@ -14,8 +15,8 @@ declare function buildTestFacade(deps: {
|
|
|
14
15
|
logger: Logger;
|
|
15
16
|
eventManager: EventManager;
|
|
16
17
|
}): {
|
|
17
|
-
runTask: <I, O extends Promise<any>, D extends DependencyMapType>(task: ITask<I, O, D>,
|
|
18
|
-
getResource: (id: string
|
|
18
|
+
runTask: <I, O extends Promise<any>, D extends DependencyMapType>(task: ITask<I, O, D>, ...args: I extends undefined ? [] : [I]) => Promise<Awaited<O> | undefined>;
|
|
19
|
+
getResource: (id: string) => any;
|
|
19
20
|
taskRunner: TaskRunner;
|
|
20
21
|
store: Store;
|
|
21
22
|
logger: Logger;
|
package/dist/testing.js
CHANGED
|
@@ -8,10 +8,11 @@ let testResourceCounter = 0;
|
|
|
8
8
|
* Helper to create a minimal test harness resource that wraps a root app (or any registerable)
|
|
9
9
|
* and exposes convenient testing utilities while running the full ecosystem
|
|
10
10
|
* (registration, overrides, middleware, events) without modifying the core API.
|
|
11
|
+
* @deprecated Use `run` instead with your testResource, as it provides the necessary toolkit.
|
|
11
12
|
*/
|
|
12
13
|
function createTestResource(root, options) {
|
|
13
14
|
return (0, define_1.defineResource)({
|
|
14
|
-
id: `
|
|
15
|
+
id: `testing.${root.id}.${++testResourceCounter}`,
|
|
15
16
|
register: [root],
|
|
16
17
|
overrides: options?.overrides || [],
|
|
17
18
|
dependencies: {
|
|
@@ -28,7 +29,7 @@ function createTestResource(root, options) {
|
|
|
28
29
|
function buildTestFacade(deps) {
|
|
29
30
|
return {
|
|
30
31
|
// Run a task within the fully initialized ecosystem
|
|
31
|
-
runTask: (task,
|
|
32
|
+
runTask: (task, ...args) => deps.taskRunner.run(task, ...args),
|
|
32
33
|
// Access a resource value by id (string or symbol)
|
|
33
34
|
getResource: (id) => deps.store.resources.get(id)?.value,
|
|
34
35
|
// Expose internals when needed in tests (not recommended for app usage)
|
package/dist/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":";;AAyBA,gDA0BC;AAnDD,qCAA0C;AAC1C,+DAA4D;AAgB5D,IAAI,mBAAmB,GAAG,CAAC,CAAC;AAE5B;;;;;GAKG;AACH,SAAgB,kBAAkB,CAChC,IAAuB,EACvB,OAQC;IAED,OAAO,IAAA,uBAAc,EAAC;QACpB,EAAE,EAAE,WAAW,IAAI,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE;QACjD,QAAQ,EAAE,CAAC,IAAI,CAAC;QAChB,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,EAAE;QACnC,YAAY,EAAE;YACZ,UAAU,EAAE,iCAAe,CAAC,UAAU;YACtC,KAAK,EAAE,iCAAe,CAAC,KAAK;YAC5B,MAAM,EAAE,iCAAe,CAAC,MAAM;YAC9B,YAAY,EAAE,iCAAe,CAAC,YAAY;SAC3C;QACD,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI;YAChB,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AACD,SAAS,eAAe,CAAC,IAKxB;IACC,OAAO;QACL,oDAAoD;QACpD,OAAO,EAAE,CACP,IAAoB,EACpB,GAAG,IAAoC,EACN,EAAE,CACnC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,CAAQ;QAC3C,mDAAmD;QACnD,WAAW,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK;QAChE,wEAAwE;QACxE,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,YAAY,EAAE,IAAI,CAAC,YAAY;KAChC,CAAC;AACJ,CAAC"}
|
|
@@ -1,9 +1 @@
|
|
|
1
1
|
export declare function getCallerFile(): string;
|
|
2
|
-
/**
|
|
3
|
-
* Gets a file path, looks at all the parts between current path and 'src' and generates a unique symbol based on that.
|
|
4
|
-
* If there is no 'src' to be found, it will rely on using the last 4 parts of the path.
|
|
5
|
-
* This is useful for generating unique IDs for tasks, resources, etc.
|
|
6
|
-
* @param filePath
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
export declare function generateCallerIdFromFile(filePath: string, suffix?: string, fallbackParts?: number): symbol;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCallerFile = getCallerFile;
|
|
4
|
-
exports.generateCallerIdFromFile = generateCallerIdFromFile;
|
|
5
4
|
function getCallerFile() {
|
|
6
5
|
const originalFunc = Error.prepareStackTrace;
|
|
7
6
|
try {
|
|
@@ -28,54 +27,4 @@ function getCallerFile() {
|
|
|
28
27
|
Error.prepareStackTrace = originalFunc;
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Gets a file path, looks at all the parts between current path and 'src' and generates a unique symbol based on that.
|
|
33
|
-
* If there is no 'src' to be found, it will rely on using the last 4 parts of the path.
|
|
34
|
-
* This is useful for generating unique IDs for tasks, resources, etc.
|
|
35
|
-
* @param filePath
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
|
-
function generateCallerIdFromFile(filePath, suffix = "", fallbackParts = 4) {
|
|
39
|
-
// Normalize paths for consistency across platforms
|
|
40
|
-
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
41
|
-
const cwdNormalized = process.cwd().replace(/\\/g, "/");
|
|
42
|
-
const parts = normalizedPath.split("/");
|
|
43
|
-
const nodeModulesIndex = parts.lastIndexOf("node_modules");
|
|
44
|
-
let relevantParts;
|
|
45
|
-
if (nodeModulesIndex !== -1) {
|
|
46
|
-
// If inside node_modules, generate id relative to the package path
|
|
47
|
-
relevantParts = parts.slice(nodeModulesIndex + 1);
|
|
48
|
-
}
|
|
49
|
-
else if (normalizedPath === cwdNormalized ||
|
|
50
|
-
normalizedPath.startsWith(cwdNormalized + "/")) {
|
|
51
|
-
// Prefer generating id relative to the workspace root (process.cwd())
|
|
52
|
-
const relativeToCwd = normalizedPath
|
|
53
|
-
.slice(cwdNormalized.length)
|
|
54
|
-
.replace(/^\//, "");
|
|
55
|
-
relevantParts = relativeToCwd.length > 0 ? relativeToCwd.split("/") : [""];
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
// Fallback: use the last N parts if path is outside cwd and not in node_modules
|
|
59
|
-
relevantParts = parts.slice(-fallbackParts);
|
|
60
|
-
}
|
|
61
|
-
if (relevantParts.length > 0) {
|
|
62
|
-
const lastPartIndex = relevantParts.length - 1;
|
|
63
|
-
const lastPart = relevantParts[lastPartIndex];
|
|
64
|
-
const dotIndex = lastPart.lastIndexOf(".");
|
|
65
|
-
if (dotIndex !== -1 && dotIndex > 0) {
|
|
66
|
-
const extension = lastPart.substring(dotIndex + 1);
|
|
67
|
-
const knownExtensions = ["ts", "js", "tsx", "jsx", "json", "node"];
|
|
68
|
-
if (knownExtensions.includes(extension)) {
|
|
69
|
-
relevantParts[lastPartIndex] = lastPart.substring(0, dotIndex);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const id = relevantParts.join(".");
|
|
74
|
-
const lastPart = relevantParts.length > 0 ? relevantParts[relevantParts.length - 1] : "";
|
|
75
|
-
let finalId = id;
|
|
76
|
-
if (suffix && !lastPart.includes(suffix)) {
|
|
77
|
-
finalId += "." + suffix;
|
|
78
|
-
}
|
|
79
|
-
return Symbol(finalId);
|
|
80
|
-
}
|
|
81
30
|
//# sourceMappingURL=getCallerFile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCallerFile.js","sourceRoot":"","sources":["../../src/tools/getCallerFile.ts"],"names":[],"mappings":";;AAAA,sCAgCC;
|
|
1
|
+
{"version":3,"file":"getCallerFile.js","sourceRoot":"","sources":["../../src/tools/getCallerFile.ts"],"names":[],"mappings":";;AAAA,sCAgCC;AAhCD,SAAgB,aAAa;IAC3B,MAAM,YAAY,GAAG,KAAK,CAAC,iBAAiB,CAAC;IAE7C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,UAAU,CAAC;QACf,IAAI,WAAW,CAAC;QAEhB,8BAA8B;QAC9B,KAAK,CAAC,iBAAiB,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC;QAEhD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAqC,CAAC;QAExD,+BAA+B;QAC/B,0BAA0B;QAC1B,8EAA8E;QAC9E,sBAAsB;QACtB,IAAI;QAEJ,gDAAgD;QAChD,KAAK,CAAC,KAAK,EAAE,CAAC;QAEd,+DAA+D;QAC/D,WAAW,GAAG,KAAK,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,CAAC;QAE3C,uDAAuD;QACvD,UAAU,GAAG,KAAK,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,CAAC;QAE1C,OAAO,UAAoB,CAAC,CAAC,2CAA2C;IAC1E,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,iBAAiB,GAAG,YAAY,CAAC;IACzC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { TagType } from "./tag";
|
|
2
|
+
export declare const CONTRACT: unique symbol;
|
|
3
|
+
export type CONTRACT = typeof CONTRACT;
|
|
4
|
+
export interface IContractable<TConfig = any, TInput = void, TOutput = void> {
|
|
5
|
+
readonly __containsContract: true;
|
|
6
|
+
readonly [CONTRACT]: {
|
|
7
|
+
config: TConfig;
|
|
8
|
+
input: TInput;
|
|
9
|
+
output: TOutput;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface ITag<TConfig = any, TOutput = void> extends IContractable<TConfig, void, TOutput> {
|
|
13
|
+
}
|
|
14
|
+
export interface IMiddleware<TConfig = any, TInput = void, TOutput = void> extends IContractable<TConfig, TInput, TOutput> {
|
|
15
|
+
}
|
|
16
|
+
type NonVoid<T> = [T] extends [void] ? never : T;
|
|
17
|
+
type IsTuple<T extends readonly unknown[]> = number extends T["length"] ? false : true;
|
|
18
|
+
type UnionToIntersection<U> = (U extends any ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
|
|
19
|
+
type Simplify<T> = {
|
|
20
|
+
[K in keyof T]: T[K];
|
|
21
|
+
} & {};
|
|
22
|
+
type IsUnknown<T> = unknown extends T ? [T] extends [unknown] ? true : false : false;
|
|
23
|
+
type UnknownToNever<T> = IsUnknown<T> extends true ? never : T;
|
|
24
|
+
type ExtractContractOf<T, Kind extends "input" | "output"> = T extends IContractable<any, infer I, infer O> ? UnknownToNever<Kind extends "input" ? NonVoid<I> : NonVoid<O>> : never;
|
|
25
|
+
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;
|
|
26
|
+
type ExtractContractsFromCollection<TItems extends readonly unknown[], Kind extends "input" | "output"> = IsTuple<TItems> extends true ? FilterContractsKind<TItems, Kind> : Array<ExtractContractOf<TItems[number], Kind>>;
|
|
27
|
+
export type ExtractInputTypeFromContracts<TItems extends readonly unknown[]> = ExtractContractsFromCollection<TItems, "input">;
|
|
28
|
+
export type ExtractOutputTypeFromContracts<TItems extends readonly unknown[]> = ExtractContractsFromCollection<TItems, "output">;
|
|
29
|
+
type ContractsUnionInputs<TItems extends readonly unknown[]> = ExtractInputTypeFromContracts<TItems> extends readonly (infer U)[] ? U : never;
|
|
30
|
+
type ContractsUnionOutputs<TItems extends readonly unknown[]> = ExtractOutputTypeFromContracts<TItems> extends readonly (infer U)[] ? U : never;
|
|
31
|
+
type ContractsIntersectionInputs<TItems extends readonly unknown[]> = UnionToIntersection<ContractsUnionInputs<TItems>>;
|
|
32
|
+
type ContractsIntersectionOutputs<TItems extends readonly unknown[]> = UnionToIntersection<ContractsUnionOutputs<TItems>>;
|
|
33
|
+
export type HasInputContracts<TItems extends readonly unknown[]> = [
|
|
34
|
+
ContractsUnionInputs<TItems>
|
|
35
|
+
] extends [never] ? false : true;
|
|
36
|
+
export type HasOutputContracts<TItems extends readonly unknown[]> = [
|
|
37
|
+
ContractsUnionOutputs<TItems>
|
|
38
|
+
] extends [never] ? false : true;
|
|
39
|
+
export type InputContractViolationError<TItems extends readonly unknown[], TActual> = {
|
|
40
|
+
message: "Value does not satisfy all input contracts";
|
|
41
|
+
expected: Simplify<ContractsIntersectionInputs<TItems>>;
|
|
42
|
+
received: TActual;
|
|
43
|
+
};
|
|
44
|
+
export type OutputContractViolationError<TItems extends readonly unknown[], TActual> = {
|
|
45
|
+
message: "Value does not satisfy all output contracts";
|
|
46
|
+
expected: Simplify<ContractsIntersectionOutputs<TItems>>;
|
|
47
|
+
received: TActual;
|
|
48
|
+
};
|
|
49
|
+
export 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>;
|
|
50
|
+
export 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>;
|
|
51
|
+
/** @deprecated Use ExtractOutputTypeFromContracts instead */
|
|
52
|
+
export type ExtractTagsWithNonVoidReturnTypeFromTags<TTags extends TagType[]> = ExtractOutputTypeFromContracts<TTags>;
|
|
53
|
+
/** @deprecated Use EnsureOutputSatisfiesContracts instead */
|
|
54
|
+
export type EnsureResponseSatisfiesContracts<TTags extends TagType[], TResponse> = EnsureOutputSatisfiesContracts<TTags, TResponse>;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/types/contracts.ts"],"names":[],"mappings":";AAAA,0EAA0E"}
|
package/dist/types/event.d.ts
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { IOptionalDependency, IValidationSchema } from "../defs";
|
|
2
|
+
import { TagType } from "./tag";
|
|
3
|
+
import { IEventMeta } from "./meta";
|
|
4
|
+
import { symbolEvent, symbolFilePath } from "./utilities";
|
|
3
5
|
export type EventHandlerType<T = any> = (event: IEventEmission<T>) => any | Promise<any>;
|
|
4
6
|
export interface IEventDefinition<TPayload = void> {
|
|
5
|
-
|
|
6
|
-
id?: string | symbol;
|
|
7
|
+
id: string;
|
|
7
8
|
meta?: IEventMeta;
|
|
9
|
+
/**
|
|
10
|
+
* Optional validation schema for runtime payload validation.
|
|
11
|
+
* When provided, event payload will be validated when emitted.
|
|
12
|
+
*/
|
|
13
|
+
payloadSchema?: IValidationSchema<TPayload>;
|
|
14
|
+
tags?: TagType[];
|
|
8
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* The definioten of the event.
|
|
18
|
+
* This is different from the event emission.
|
|
19
|
+
*/
|
|
9
20
|
export interface IEvent<TPayload = any> extends IEventDefinition<TPayload> {
|
|
10
|
-
id: string
|
|
21
|
+
id: string;
|
|
11
22
|
/**
|
|
12
23
|
* 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.
|
|
13
24
|
*/
|
|
14
25
|
[symbolEvent]: true;
|
|
26
|
+
[symbolFilePath]: string;
|
|
27
|
+
/** Return an optional dependency wrapper for this event. */
|
|
28
|
+
optional: () => IOptionalDependency<IEvent<TPayload>>;
|
|
29
|
+
tags: TagType[];
|
|
15
30
|
}
|
|
16
31
|
/**
|
|
17
32
|
* This represents the object that is passed to event handlers
|
|
@@ -21,7 +36,7 @@ export interface IEventEmission<TPayload = any> {
|
|
|
21
36
|
* The ID of the event. This is the same as the event's ID.
|
|
22
37
|
* This is useful for global event listeners.
|
|
23
38
|
*/
|
|
24
|
-
id: string
|
|
39
|
+
id: string;
|
|
25
40
|
/**
|
|
26
41
|
* The data that the event carries. It can be anything.
|
|
27
42
|
*/
|
|
@@ -33,7 +48,7 @@ export interface IEventEmission<TPayload = any> {
|
|
|
33
48
|
/**
|
|
34
49
|
* The source of the event. This can be useful for debugging.
|
|
35
50
|
*/
|
|
36
|
-
source: string
|
|
51
|
+
source: string;
|
|
37
52
|
/**
|
|
38
53
|
* Metadata associated with the event definition.
|
|
39
54
|
*/
|
|
@@ -46,4 +61,8 @@ export interface IEventEmission<TPayload = any> {
|
|
|
46
61
|
* Returns true if propagation has been stopped.
|
|
47
62
|
*/
|
|
48
63
|
isPropagationStopped(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The tags that the event carries.
|
|
66
|
+
*/
|
|
67
|
+
tags: TagType[];
|
|
49
68
|
}
|
package/dist/types/event.js
CHANGED
package/dist/types/event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/types/event.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/types/event.ts"],"names":[],"mappings":";;AAGA,2CAA0D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DependencyMapType, DependencyValuesType, IEventDefinition, IEventEmission, ExtractEventParams } from "../defs";
|
|
2
|
+
import { TagType } from "./tag";
|
|
3
|
+
import { ITaskMeta } from "./meta";
|
|
4
|
+
import { symbolFilePath, symbolHook } from "./utilities";
|
|
5
|
+
export interface IHookDefinition<TDependencies extends DependencyMapType = {}, TOn extends "*" | IEventDefinition<any> = any, TMeta extends ITaskMeta = any> {
|
|
6
|
+
id: string;
|
|
7
|
+
dependencies?: TDependencies | (() => TDependencies);
|
|
8
|
+
on: TOn;
|
|
9
|
+
/** Listener execution order. Lower numbers run first. */
|
|
10
|
+
order?: number;
|
|
11
|
+
meta?: TMeta;
|
|
12
|
+
run: (event: IEventEmission<TOn extends "*" ? any : ExtractEventParams<TOn>>, dependencies: DependencyValuesType<TDependencies>) => Promise<any>;
|
|
13
|
+
tags?: TagType[];
|
|
14
|
+
}
|
|
15
|
+
export interface IHook<TDependencies extends DependencyMapType = {}, TOn extends "*" | IEventDefinition<any> = any, TMeta extends ITaskMeta = any> extends IHookDefinition<TDependencies, TOn, TMeta> {
|
|
16
|
+
id: string;
|
|
17
|
+
dependencies: TDependencies | (() => TDependencies);
|
|
18
|
+
[symbolFilePath]: string;
|
|
19
|
+
[symbolHook]: true;
|
|
20
|
+
tags: TagType[];
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../src/types/hook.ts"],"names":[],"mappings":";;AASA,2CAAyD"}
|
package/dist/types/meta.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common metadata you can attach to tasks/resources/events/middleware.
|
|
3
|
+
* Useful for docs, filtering and middleware decisions.
|
|
4
|
+
*/
|
|
1
5
|
export interface IMeta {
|
|
2
6
|
title?: string;
|
|
3
7
|
description?: string;
|
|
4
|
-
tags?: string[];
|
|
5
8
|
}
|
|
6
9
|
export interface ITaskMeta extends IMeta {
|
|
7
10
|
}
|
|
@@ -11,3 +14,5 @@ export interface IEventMeta extends IMeta {
|
|
|
11
14
|
}
|
|
12
15
|
export interface IMiddlewareMeta extends IMeta {
|
|
13
16
|
}
|
|
17
|
+
export interface ITagMeta extends IMeta {
|
|
18
|
+
}
|
package/dist/types/meta.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Common metadata you can attach to tasks/resources/events/middleware.
|
|
4
|
+
* Useful for docs, filtering and middleware decisions.
|
|
5
|
+
*/
|
|
4
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
7
|
//# sourceMappingURL=meta.js.map
|
package/dist/types/meta.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta.js","sourceRoot":"","sources":["../../src/types/meta.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"meta.js","sourceRoot":"","sources":["../../src/types/meta.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
package/dist/types/resource.d.ts
CHANGED
|
@@ -1,35 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export type AfterInitEventPayload<TConfig, TValue> = {
|
|
10
|
-
config: TConfig;
|
|
11
|
-
value: TValue;
|
|
12
|
-
};
|
|
13
|
-
export type OnErrorEventPayloadResource = {
|
|
14
|
-
error: any;
|
|
15
|
-
/**
|
|
16
|
-
* This function can be called to suppress the error from being thrown.
|
|
17
|
-
*/
|
|
18
|
-
suppress(): void;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Anything you can put inside a resource's `register: []`.
|
|
22
|
-
* - Resources (with or without `.with()`)
|
|
23
|
-
* - Tasks
|
|
24
|
-
* - Middleware
|
|
25
|
-
* - Events
|
|
26
|
-
*/
|
|
27
|
-
export type RegisterableItems<T = any> = IResourceWithConfig<any> | IResource<void, any, any, any> | IResource<{
|
|
28
|
-
[K in any]?: any;
|
|
29
|
-
}, any, any, any> | any | any | any;
|
|
30
|
-
export interface IResourceDefinition<TConfig = any, TValue = unknown, TDependencies extends DependencyMapType = {}, TContext = any, THooks = any, TRegisterableItems = any> {
|
|
31
|
-
/** Stable identifier. Omit to get an anonymous id. */
|
|
32
|
-
id?: string | symbol;
|
|
1
|
+
import { DependencyMapType, IOptionalDependency, IResourceMiddleware, IValidationSchema, OverridableElements, RegisterableItems, ResourceDependencyValuesType, ResourceMiddlewareAttachmentType } from "../defs";
|
|
2
|
+
import { TagType } from "./tag";
|
|
3
|
+
import { IResourceMeta } from "./meta";
|
|
4
|
+
import { symbolFilePath, symbolIndexResource, symbolResource, symbolResourceWithConfig } from "./symbols";
|
|
5
|
+
import { EnsureInputSatisfiesContracts, EnsureOutputSatisfiesContracts, HasInputContracts, HasOutputContracts } from "./contracts";
|
|
6
|
+
export 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[]> {
|
|
7
|
+
/** Stable identifier. */
|
|
8
|
+
id: string;
|
|
33
9
|
/** Static or lazy dependency map. Receives `config` when provided. */
|
|
34
10
|
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
35
11
|
/**
|
|
@@ -40,7 +16,13 @@ export interface IResourceDefinition<TConfig = any, TValue = unknown, TDependenc
|
|
|
40
16
|
/**
|
|
41
17
|
* Initialize and return the resource value. Called once during boot.
|
|
42
18
|
*/
|
|
43
|
-
init?: (
|
|
19
|
+
init?: (config: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureInputSatisfiesContracts<[...TTags, ...TMiddleware], TConfig> : TConfig, dependencies: ResourceDependencyValuesType<TDependencies>, context: TContext) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TValue> : TValue;
|
|
20
|
+
/**
|
|
21
|
+
* Optional validation schema for the resource's resolved value.
|
|
22
|
+
* When provided, the value will be validated immediately after `init` resolves,
|
|
23
|
+
* without considering middleware.
|
|
24
|
+
*/
|
|
25
|
+
resultSchema?: IValidationSchema<TValue extends Promise<infer U> ? U : TValue>;
|
|
44
26
|
/**
|
|
45
27
|
* Clean-up function for the resource. This is called when the resource is no longer needed.
|
|
46
28
|
*
|
|
@@ -49,48 +31,54 @@ export interface IResourceDefinition<TConfig = any, TValue = unknown, TDependenc
|
|
|
49
31
|
* @param dependencies The dependencies it needed
|
|
50
32
|
* @returns Promise<void>
|
|
51
33
|
*/
|
|
52
|
-
dispose?: (this: any, value: TValue, config: TConfig, dependencies:
|
|
53
|
-
meta?:
|
|
34
|
+
dispose?: (this: any, value: TValue extends Promise<infer U> ? U : TValue, config: TConfig, dependencies: ResourceDependencyValuesType<TDependencies>, context: TContext) => Promise<void>;
|
|
35
|
+
meta?: TMeta;
|
|
36
|
+
/**
|
|
37
|
+
* Optional validation schema for runtime config validation.
|
|
38
|
+
* When provided, resource config will be validated when .with() is called.
|
|
39
|
+
*/
|
|
40
|
+
configSchema?: IValidationSchema<TConfig>;
|
|
54
41
|
/**
|
|
55
42
|
* Safe overrides to swap behavior while preserving identities. See
|
|
56
43
|
* README: Overrides.
|
|
57
44
|
*/
|
|
58
|
-
overrides?: Array<
|
|
45
|
+
overrides?: Array<OverridableElements>;
|
|
59
46
|
/** Middleware applied around init/dispose. */
|
|
60
|
-
middleware?:
|
|
47
|
+
middleware?: TMiddleware;
|
|
61
48
|
/**
|
|
62
49
|
* Create a private, mutable context shared between `init` and `dispose`.
|
|
63
50
|
*/
|
|
64
51
|
context?: () => TContext;
|
|
65
52
|
/**
|
|
66
53
|
* This is optional and used from an index resource to get the correct caller.
|
|
54
|
+
* This is the reason we allow it here as well.
|
|
67
55
|
*/
|
|
68
56
|
[symbolFilePath]?: string;
|
|
69
57
|
/**
|
|
70
58
|
* This is used internally when creating index resources.
|
|
71
59
|
*/
|
|
72
60
|
[symbolIndexResource]?: boolean;
|
|
61
|
+
tags?: TTags;
|
|
73
62
|
}
|
|
74
|
-
export interface IResource<TConfig = void, TValue = any
|
|
75
|
-
id: string
|
|
76
|
-
with(config: TConfig): IResourceWithConfig<TConfig, TValue, TDependencies>;
|
|
63
|
+
export 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> {
|
|
64
|
+
id: string;
|
|
65
|
+
with(config: TConfig): IResourceWithConfig<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
77
66
|
register: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
overrides: Array<IResource | any | any | IResourceWithConfig>;
|
|
87
|
-
middleware: MiddlewareAttachments[];
|
|
67
|
+
overrides: Array<OverridableElements>;
|
|
68
|
+
middleware: TMiddleware;
|
|
69
|
+
[symbolFilePath]: string;
|
|
70
|
+
[symbolIndexResource]: boolean;
|
|
71
|
+
[symbolResource]: true;
|
|
72
|
+
/** Return an optional dependency wrapper for this resource. */
|
|
73
|
+
optional: () => IOptionalDependency<IResource<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>>;
|
|
74
|
+
tags: TTags;
|
|
88
75
|
}
|
|
89
|
-
export interface IResourceWithConfig<TConfig = any, TValue = any
|
|
76
|
+
export 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[]> {
|
|
77
|
+
[symbolResourceWithConfig]: true;
|
|
90
78
|
/** The id of the underlying resource. */
|
|
91
79
|
id: string;
|
|
92
80
|
/** The underlying resource definition. */
|
|
93
|
-
resource: IResource<TConfig, TValue, TDependencies>;
|
|
81
|
+
resource: IResource<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
94
82
|
/** The configuration captured by `.with(config)`. */
|
|
95
83
|
config: TConfig;
|
|
96
84
|
}
|
package/dist/types/resource.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/types/resource.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/types/resource.ts"],"names":[],"mappings":";;AAYA,uCAKmB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DependencyMapType, DependencyValuesType, IValidationSchema, IResource } from "../defs";
|
|
2
|
+
import { TagType } from "./tag";
|
|
3
|
+
import { IMiddlewareMeta } from "./meta";
|
|
4
|
+
import { symbolFilePath, symbolMiddlewareConfigured, symbolResourceMiddleware } from "./symbols";
|
|
5
|
+
import { IContractable } from "./contracts";
|
|
6
|
+
export interface IResourceMiddlewareDefinition<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> {
|
|
7
|
+
id: string;
|
|
8
|
+
/** Static or lazy dependency map. */
|
|
9
|
+
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
10
|
+
/**
|
|
11
|
+
* Optional validation schema for runtime config validation.
|
|
12
|
+
* When provided, middleware config will be validated when .with() is called.
|
|
13
|
+
*/
|
|
14
|
+
configSchema?: IValidationSchema<TConfig>;
|
|
15
|
+
/**
|
|
16
|
+
* The middleware body, called with resource execution input.
|
|
17
|
+
*/
|
|
18
|
+
run: (input: IResourceMiddlewareExecutionInput<TEnforceInputContract extends void ? any : TEnforceInputContract, TEnforceOutputContract extends void ? any : TEnforceOutputContract>, dependencies: DependencyValuesType<TDependencies>, config: TConfig) => Promise<any>;
|
|
19
|
+
meta?: IMiddlewareMeta;
|
|
20
|
+
tags?: TagType[];
|
|
21
|
+
everywhere?: boolean | ((resource: IResource<any, any, any, any, any>) => boolean);
|
|
22
|
+
}
|
|
23
|
+
export interface IResourceMiddleware<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends IResourceMiddlewareDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>, IContractable<TConfig, TEnforceInputContract, TEnforceOutputContract> {
|
|
24
|
+
[symbolResourceMiddleware]: true;
|
|
25
|
+
id: string;
|
|
26
|
+
dependencies: TDependencies | (() => TDependencies);
|
|
27
|
+
/** Current configuration object (empty by default). */
|
|
28
|
+
config: TConfig;
|
|
29
|
+
/** Configure the middleware and return a marked, configured instance. */
|
|
30
|
+
with: (config: TConfig) => IResourceMiddlewareConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
31
|
+
[symbolFilePath]: string;
|
|
32
|
+
tags: TagType[];
|
|
33
|
+
}
|
|
34
|
+
export interface IResourceMiddlewareConfigured<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends IResourceMiddleware<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies> {
|
|
35
|
+
[symbolMiddlewareConfigured]: true;
|
|
36
|
+
}
|
|
37
|
+
export interface IResourceMiddlewareExecutionInput<TResourceConfig = any, TResourceOutput = any> {
|
|
38
|
+
/** Resource hook */
|
|
39
|
+
resource: {
|
|
40
|
+
definition: IResource<TResourceConfig, any, any, any, any>;
|
|
41
|
+
config: TResourceConfig;
|
|
42
|
+
};
|
|
43
|
+
next: (resourceConfig?: TResourceConfig) => Promise<TResourceOutput>;
|
|
44
|
+
}
|
|
45
|
+
export type ResourceMiddlewareAttachmentType = IResourceMiddleware<void, any, any, any> | IResourceMiddleware<{
|
|
46
|
+
[K in any]?: any;
|
|
47
|
+
}, any, any, any> | IResourceMiddlewareConfigured<any, any, any, any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceMiddleware.js","sourceRoot":"","sources":["../../src/types/resourceMiddleware.ts"],"names":[],"mappings":";;AAQA,uCAImB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { DebugFriendlyConfig } from "../globals/resources/debug";
|
|
2
|
+
import { LogLevels, PrintStrategy } from "../models/Logger";
|
|
3
|
+
import { OnUnhandledError } from "../models/UnhandledError";
|
|
4
|
+
export type RunOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Defaults to undefined. If true, we introduce logging to the console.
|
|
7
|
+
*/
|
|
8
|
+
debug?: DebugFriendlyConfig;
|
|
9
|
+
logs?: {
|
|
10
|
+
/**
|
|
11
|
+
* Defaults to info. Use null to disable logging.
|
|
12
|
+
*/
|
|
13
|
+
printThreshold?: null | LogLevels;
|
|
14
|
+
/**
|
|
15
|
+
* Defaults to PRETTY. How to print the logs.
|
|
16
|
+
*/
|
|
17
|
+
printStrategy?: PrintStrategy;
|
|
18
|
+
/**
|
|
19
|
+
* Defaults to false. If true, we buffer logs until the root resource is ready.
|
|
20
|
+
* This provides you with the chance to see the logs before the root resource is ready.
|
|
21
|
+
*/
|
|
22
|
+
bufferLogs?: boolean;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* When true (default), installs a central error boundary that catches uncaught errors
|
|
26
|
+
* from process-level events and routes them to `onUnhandledError`.
|
|
27
|
+
*/
|
|
28
|
+
errorBoundary?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* When true (default), installs SIGINT/SIGTERM handlers that call dispose() on the root.
|
|
31
|
+
*/
|
|
32
|
+
shutdownHooks?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Custom handler for any unhandled error caught by Runner. Defaults to logging via the created logger.
|
|
35
|
+
*/
|
|
36
|
+
onUnhandledError?: OnUnhandledError;
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/types/runner.ts"],"names":[],"mappings":""}
|