@bluelibs/runner 4.5.0-alpha → 4.5.0-alpha.2
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/dist/index.cjs +4265 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +1734 -0
- package/dist/index.d.ts +1696 -45
- package/dist/index.mjs +4233 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +11 -14
- package/dist/context.d.ts +0 -29
- package/dist/context.js +0 -52
- package/dist/context.js.map +0 -1
- package/dist/define.d.ts +0 -9
- package/dist/define.js +0 -32
- package/dist/define.js.map +0 -1
- package/dist/definers/defineEvent.d.ts +0 -2
- package/dist/definers/defineEvent.js +0 -23
- package/dist/definers/defineEvent.js.map +0 -1
- package/dist/definers/defineHook.d.ts +0 -6
- package/dist/definers/defineHook.js +0 -24
- package/dist/definers/defineHook.js.map +0 -1
- package/dist/definers/defineOverride.d.ts +0 -14
- package/dist/definers/defineOverride.js +0 -13
- package/dist/definers/defineOverride.js.map +0 -1
- package/dist/definers/defineResource.d.ts +0 -2
- package/dist/definers/defineResource.js +0 -69
- package/dist/definers/defineResource.js.map +0 -1
- package/dist/definers/defineResourceMiddleware.d.ts +0 -2
- package/dist/definers/defineResourceMiddleware.js +0 -42
- package/dist/definers/defineResourceMiddleware.js.map +0 -1
- package/dist/definers/defineTag.d.ts +0 -12
- package/dist/definers/defineTag.js +0 -107
- package/dist/definers/defineTag.js.map +0 -1
- package/dist/definers/defineTask.d.ts +0 -15
- package/dist/definers/defineTask.js +0 -42
- package/dist/definers/defineTask.js.map +0 -1
- package/dist/definers/defineTaskMiddleware.d.ts +0 -2
- package/dist/definers/defineTaskMiddleware.js +0 -42
- package/dist/definers/defineTaskMiddleware.js.map +0 -1
- package/dist/definers/tools.d.ts +0 -45
- package/dist/definers/tools.js +0 -75
- package/dist/definers/tools.js.map +0 -1
- package/dist/defs.d.ts +0 -29
- package/dist/defs.js +0 -45
- package/dist/defs.js.map +0 -1
- package/dist/errors.d.ts +0 -96
- package/dist/errors.js +0 -178
- package/dist/errors.js.map +0 -1
- package/dist/globals/globalEvents.d.ts +0 -17
- package/dist/globals/globalEvents.js +0 -33
- package/dist/globals/globalEvents.js.map +0 -1
- package/dist/globals/globalMiddleware.d.ts +0 -31
- package/dist/globals/globalMiddleware.js +0 -25
- package/dist/globals/globalMiddleware.js.map +0 -1
- package/dist/globals/globalResources.d.ts +0 -30
- package/dist/globals/globalResources.js +0 -55
- package/dist/globals/globalResources.js.map +0 -1
- package/dist/globals/globalTags.d.ts +0 -9
- package/dist/globals/globalTags.js +0 -23
- package/dist/globals/globalTags.js.map +0 -1
- package/dist/globals/middleware/cache.middleware.d.ts +0 -27
- package/dist/globals/middleware/cache.middleware.js +0 -73
- package/dist/globals/middleware/cache.middleware.js.map +0 -1
- package/dist/globals/middleware/requireContext.middleware.d.ts +0 -6
- package/dist/globals/middleware/requireContext.middleware.js +0 -16
- package/dist/globals/middleware/requireContext.middleware.js.map +0 -1
- package/dist/globals/middleware/retry.middleware.d.ts +0 -21
- package/dist/globals/middleware/retry.middleware.js +0 -61
- package/dist/globals/middleware/retry.middleware.js.map +0 -1
- package/dist/globals/middleware/timeout.middleware.d.ts +0 -9
- package/dist/globals/middleware/timeout.middleware.js +0 -61
- package/dist/globals/middleware/timeout.middleware.js.map +0 -1
- package/dist/globals/resources/debug/debug.resource.d.ts +0 -7
- package/dist/globals/resources/debug/debug.resource.js +0 -29
- package/dist/globals/resources/debug/debug.resource.js.map +0 -1
- package/dist/globals/resources/debug/debug.tag.d.ts +0 -2
- package/dist/globals/resources/debug/debug.tag.js +0 -12
- package/dist/globals/resources/debug/debug.tag.js.map +0 -1
- package/dist/globals/resources/debug/debugConfig.resource.d.ts +0 -22
- package/dist/globals/resources/debug/debugConfig.resource.js +0 -20
- package/dist/globals/resources/debug/debugConfig.resource.js.map +0 -1
- package/dist/globals/resources/debug/executionTracker.middleware.d.ts +0 -50
- package/dist/globals/resources/debug/executionTracker.middleware.js +0 -78
- package/dist/globals/resources/debug/executionTracker.middleware.js.map +0 -1
- package/dist/globals/resources/debug/globalEvent.hook.d.ts +0 -27
- package/dist/globals/resources/debug/globalEvent.hook.js +0 -38
- package/dist/globals/resources/debug/globalEvent.hook.js.map +0 -1
- package/dist/globals/resources/debug/hook.hook.d.ts +0 -30
- package/dist/globals/resources/debug/hook.hook.js +0 -48
- package/dist/globals/resources/debug/hook.hook.js.map +0 -1
- package/dist/globals/resources/debug/index.d.ts +0 -6
- package/dist/globals/resources/debug/index.js +0 -23
- package/dist/globals/resources/debug/index.js.map +0 -1
- package/dist/globals/resources/debug/middleware.hook.d.ts +0 -30
- package/dist/globals/resources/debug/middleware.hook.js +0 -75
- package/dist/globals/resources/debug/middleware.hook.js.map +0 -1
- package/dist/globals/resources/debug/types.d.ts +0 -25
- package/dist/globals/resources/debug/types.js +0 -65
- package/dist/globals/resources/debug/types.js.map +0 -1
- package/dist/globals/resources/debug/utils.d.ts +0 -2
- package/dist/globals/resources/debug/utils.js +0 -13
- package/dist/globals/resources/debug/utils.js.map +0 -1
- package/dist/globals/resources/queue.resource.d.ts +0 -10
- package/dist/globals/resources/queue.resource.js +0 -31
- package/dist/globals/resources/queue.resource.js.map +0 -1
- package/dist/globals/types.d.ts +0 -1
- package/dist/globals/types.js +0 -18
- package/dist/globals/types.js.map +0 -1
- package/dist/index.js +0 -48
- package/dist/index.js.map +0 -1
- package/dist/models/DependencyProcessor.d.ts +0 -48
- package/dist/models/DependencyProcessor.js +0 -276
- package/dist/models/DependencyProcessor.js.map +0 -1
- package/dist/models/EventManager.d.ts +0 -153
- package/dist/models/EventManager.js +0 -421
- package/dist/models/EventManager.js.map +0 -1
- package/dist/models/LogPrinter.d.ts +0 -55
- package/dist/models/LogPrinter.js +0 -202
- package/dist/models/LogPrinter.js.map +0 -1
- package/dist/models/Logger.d.ts +0 -85
- package/dist/models/Logger.js +0 -194
- package/dist/models/Logger.js.map +0 -1
- package/dist/models/MiddlewareManager.d.ts +0 -86
- package/dist/models/MiddlewareManager.js +0 -391
- package/dist/models/MiddlewareManager.js.map +0 -1
- package/dist/models/OverrideManager.d.ts +0 -13
- package/dist/models/OverrideManager.js +0 -84
- package/dist/models/OverrideManager.js.map +0 -1
- package/dist/models/Queue.d.ts +0 -25
- package/dist/models/Queue.js +0 -56
- package/dist/models/Queue.js.map +0 -1
- package/dist/models/ResourceInitializer.d.ts +0 -20
- package/dist/models/ResourceInitializer.js +0 -34
- package/dist/models/ResourceInitializer.js.map +0 -1
- package/dist/models/RunResult.d.ts +0 -35
- package/dist/models/RunResult.js +0 -62
- package/dist/models/RunResult.js.map +0 -1
- package/dist/models/Semaphore.d.ts +0 -61
- package/dist/models/Semaphore.js +0 -164
- package/dist/models/Semaphore.js.map +0 -1
- package/dist/models/Store.d.ts +0 -56
- package/dist/models/Store.js +0 -209
- package/dist/models/Store.js.map +0 -1
- package/dist/models/StoreRegistry.d.ts +0 -43
- package/dist/models/StoreRegistry.js +0 -375
- package/dist/models/StoreRegistry.js.map +0 -1
- package/dist/models/StoreValidator.d.ts +0 -8
- package/dist/models/StoreValidator.js +0 -73
- package/dist/models/StoreValidator.js.map +0 -1
- package/dist/models/TaskRunner.d.ts +0 -27
- package/dist/models/TaskRunner.js +0 -53
- package/dist/models/TaskRunner.js.map +0 -1
- package/dist/models/UnhandledError.d.ts +0 -11
- package/dist/models/UnhandledError.js +0 -32
- package/dist/models/UnhandledError.js.map +0 -1
- package/dist/models/index.d.ts +0 -11
- package/dist/models/index.js +0 -28
- package/dist/models/index.js.map +0 -1
- package/dist/models/utils/findCircularDependencies.d.ts +0 -16
- package/dist/models/utils/findCircularDependencies.js +0 -45
- package/dist/models/utils/findCircularDependencies.js.map +0 -1
- package/dist/models/utils/safeStringify.d.ts +0 -3
- package/dist/models/utils/safeStringify.js +0 -45
- package/dist/models/utils/safeStringify.js.map +0 -1
- package/dist/platform/browser.d.ts +0 -15
- package/dist/platform/browser.js +0 -98
- package/dist/platform/browser.js.map +0 -1
- package/dist/platform/index.d.ts +0 -8
- package/dist/platform/index.js +0 -47
- package/dist/platform/index.js.map +0 -1
- package/dist/platform/node.d.ts +0 -11
- package/dist/platform/node.js +0 -45
- package/dist/platform/node.js.map +0 -1
- package/dist/platform/types.d.ts +0 -28
- package/dist/platform/types.js +0 -19
- package/dist/platform/types.js.map +0 -1
- package/dist/platform/universal.d.ts +0 -16
- package/dist/platform/universal.js +0 -57
- package/dist/platform/universal.js.map +0 -1
- package/dist/processHooks.d.ts +0 -2
- package/dist/processHooks.js +0 -79
- package/dist/processHooks.js.map +0 -1
- package/dist/run.d.ts +0 -14
- package/dist/run.js +0 -126
- package/dist/run.js.map +0 -1
- package/dist/testing.d.ts +0 -25
- package/dist/testing.js +0 -42
- package/dist/testing.js.map +0 -1
- package/dist/tools/getCallerFile.d.ts +0 -1
- package/dist/tools/getCallerFile.js +0 -30
- package/dist/tools/getCallerFile.js.map +0 -1
- package/dist/types/contracts.d.ts +0 -55
- package/dist/types/contracts.js +0 -4
- package/dist/types/contracts.js.map +0 -1
- package/dist/types/event.d.ts +0 -74
- package/dist/types/event.js +0 -17
- package/dist/types/event.js.map +0 -1
- package/dist/types/hook.d.ts +0 -23
- package/dist/types/hook.js +0 -4
- package/dist/types/hook.js.map +0 -1
- package/dist/types/meta.d.ts +0 -18
- package/dist/types/meta.js +0 -7
- package/dist/types/meta.js.map +0 -1
- package/dist/types/resource.d.ts +0 -84
- package/dist/types/resource.js +0 -4
- package/dist/types/resource.js.map +0 -1
- package/dist/types/resourceMiddleware.d.ts +0 -47
- package/dist/types/resourceMiddleware.js +0 -4
- package/dist/types/resourceMiddleware.js.map +0 -1
- package/dist/types/runner.d.ts +0 -55
- package/dist/types/runner.js +0 -3
- package/dist/types/runner.js.map +0 -1
- package/dist/types/storeTypes.d.ts +0 -40
- package/dist/types/storeTypes.js +0 -3
- package/dist/types/storeTypes.js.map +0 -1
- package/dist/types/symbols.d.ts +0 -30
- package/dist/types/symbols.js +0 -40
- package/dist/types/symbols.js.map +0 -1
- package/dist/types/tag.d.ts +0 -46
- package/dist/types/tag.js +0 -4
- package/dist/types/tag.js.map +0 -1
- package/dist/types/task.d.ts +0 -44
- package/dist/types/task.js +0 -4
- package/dist/types/task.js.map +0 -1
- package/dist/types/taskMiddleware.d.ts +0 -48
- package/dist/types/taskMiddleware.js +0 -4
- package/dist/types/taskMiddleware.js.map +0 -1
- package/dist/types/utilities.d.ts +0 -110
- package/dist/types/utilities.js +0 -19
- package/dist/types/utilities.js.map +0 -1
package/dist/run.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.run = run;
|
|
4
|
-
const TaskRunner_1 = require("./models/TaskRunner");
|
|
5
|
-
const DependencyProcessor_1 = require("./models/DependencyProcessor");
|
|
6
|
-
const EventManager_1 = require("./models/EventManager");
|
|
7
|
-
const globalEvents_1 = require("./globals/globalEvents");
|
|
8
|
-
const Store_1 = require("./models/Store");
|
|
9
|
-
const Logger_1 = require("./models/Logger");
|
|
10
|
-
const define_1 = require("./define");
|
|
11
|
-
const debug_1 = require("./globals/resources/debug");
|
|
12
|
-
const processHooks_1 = require("./processHooks");
|
|
13
|
-
const UnhandledError_1 = require("./models/UnhandledError");
|
|
14
|
-
const RunResult_1 = require("./models/RunResult");
|
|
15
|
-
const platform_1 = require("./platform");
|
|
16
|
-
const platform = (0, platform_1.getPlatform)();
|
|
17
|
-
/**
|
|
18
|
-
* This is the central function that kicks off you runner. You can run as many resources as you want in a single process, they will run in complete isolation.
|
|
19
|
-
*
|
|
20
|
-
* @param resourceOrResourceWithConfig - The resource or resource with config to run.
|
|
21
|
-
* @param options - The options for the run.
|
|
22
|
-
* @returns A promise that resolves to the result of the run.
|
|
23
|
-
*/
|
|
24
|
-
async function run(resourceOrResourceWithConfig, // For optional config
|
|
25
|
-
options) {
|
|
26
|
-
const { debug = undefined, logs = {}, errorBoundary = true, shutdownHooks = true, dryRun = false, onUnhandledError: onUnhandledErrorOpt, runtimeCycleDetection = true, } = options || {};
|
|
27
|
-
const { printThreshold = platform.getEnv("NODE_ENV") === "test" ? null : "info", printStrategy = "pretty", bufferLogs = false, } = logs;
|
|
28
|
-
const eventManager = new EventManager_1.EventManager({
|
|
29
|
-
runtimeCycleDetection,
|
|
30
|
-
});
|
|
31
|
-
let { resource, config } = extractResourceAndConfig(resourceOrResourceWithConfig);
|
|
32
|
-
// ensure for logger, that it can be used only after: computeAllDependencies() has executed
|
|
33
|
-
const logger = new Logger_1.Logger({
|
|
34
|
-
printThreshold,
|
|
35
|
-
printStrategy,
|
|
36
|
-
bufferLogs,
|
|
37
|
-
});
|
|
38
|
-
const onUnhandledError = onUnhandledErrorOpt || (0, UnhandledError_1.createDefaultUnhandledError)(logger);
|
|
39
|
-
const store = new Store_1.Store(eventManager, logger, onUnhandledError);
|
|
40
|
-
const taskRunner = new TaskRunner_1.TaskRunner(store, eventManager, logger);
|
|
41
|
-
store.setTaskRunner(taskRunner);
|
|
42
|
-
// Register this run's event manager for global process error safety nets
|
|
43
|
-
let unhookProcessSafetyNets;
|
|
44
|
-
if (errorBoundary) {
|
|
45
|
-
unhookProcessSafetyNets = (0, processHooks_1.registerProcessLevelSafetyNets)((0, UnhandledError_1.bindProcessErrorHandler)(onUnhandledError));
|
|
46
|
-
}
|
|
47
|
-
const processor = new DependencyProcessor_1.DependencyProcessor(store, eventManager, taskRunner, logger);
|
|
48
|
-
// We may install shutdown hooks; capture unhook function to remove them on dispose
|
|
49
|
-
let unhookShutdown;
|
|
50
|
-
// Helper dispose that always unhooks process listeners first
|
|
51
|
-
const disposeAll = async () => {
|
|
52
|
-
try {
|
|
53
|
-
if (unhookProcessSafetyNets) {
|
|
54
|
-
unhookProcessSafetyNets();
|
|
55
|
-
unhookProcessSafetyNets = undefined;
|
|
56
|
-
}
|
|
57
|
-
if (unhookShutdown) {
|
|
58
|
-
unhookShutdown();
|
|
59
|
-
unhookShutdown = undefined;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
finally {
|
|
63
|
-
await store.dispose();
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
try {
|
|
67
|
-
if (debug) {
|
|
68
|
-
store.storeGenericItem(debug_1.debugResource.with(debug));
|
|
69
|
-
}
|
|
70
|
-
// In the registration phase we register deeply all the resources, tasks, middleware and events
|
|
71
|
-
store.initializeStore(resource, config);
|
|
72
|
-
// the overrides that were registered now will override the other registered resources
|
|
73
|
-
await store.processOverrides();
|
|
74
|
-
store.validateDependencyGraph();
|
|
75
|
-
// Compile-time event emission cycle detection (cheap, graph-based)
|
|
76
|
-
store.validateEventEmissionGraph();
|
|
77
|
-
const boundedLogger = logger.with({ source: "run" });
|
|
78
|
-
if (dryRun) {
|
|
79
|
-
await boundedLogger.debug("Dry run mode. Skipping initialization...");
|
|
80
|
-
return new RunResult_1.RunResult(store.root.value, logger, store, eventManager, taskRunner, disposeAll);
|
|
81
|
-
}
|
|
82
|
-
// Beginning initialization
|
|
83
|
-
await boundedLogger.debug("Events stored. Attaching listeners...");
|
|
84
|
-
await processor.attachListeners();
|
|
85
|
-
await boundedLogger.debug("Listeners attached. Computing dependencies...");
|
|
86
|
-
await processor.computeAllDependencies();
|
|
87
|
-
// After this stage, logger print policy could have been set.
|
|
88
|
-
await boundedLogger.debug("Dependencies computed. Proceeding with initialization...");
|
|
89
|
-
// Now we can safely compute dependencies without being afraid of an infinite loop.
|
|
90
|
-
// The hooking part is done here.
|
|
91
|
-
// Now we can initialise the root resource
|
|
92
|
-
await processor.initializeRoot();
|
|
93
|
-
// disallow manipulation or attaching more
|
|
94
|
-
store.lock();
|
|
95
|
-
eventManager.lock();
|
|
96
|
-
await logger.lock();
|
|
97
|
-
await eventManager.emit(globalEvents_1.globalEvents.ready, {
|
|
98
|
-
root: store.root.resource,
|
|
99
|
-
}, "system");
|
|
100
|
-
await boundedLogger.info("Runner online. Awaiting tasks and events.");
|
|
101
|
-
if (shutdownHooks) {
|
|
102
|
-
unhookShutdown = (0, processHooks_1.registerShutdownHook)(() => store.dispose());
|
|
103
|
-
}
|
|
104
|
-
return new RunResult_1.RunResult(store.root.value, logger, store, eventManager, taskRunner, disposeAll);
|
|
105
|
-
}
|
|
106
|
-
catch (err) {
|
|
107
|
-
// Rollback initialized resources
|
|
108
|
-
await disposeAll();
|
|
109
|
-
throw err;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
// process hooks moved to processHooks.ts for clarity
|
|
113
|
-
function extractResourceAndConfig(resourceOrResourceWithConfig) {
|
|
114
|
-
let resource;
|
|
115
|
-
let config;
|
|
116
|
-
if ((0, define_1.isResourceWithConfig)(resourceOrResourceWithConfig)) {
|
|
117
|
-
resource = resourceOrResourceWithConfig.resource;
|
|
118
|
-
config = resourceOrResourceWithConfig.config;
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
resource = resourceOrResourceWithConfig;
|
|
122
|
-
config = undefined;
|
|
123
|
-
}
|
|
124
|
-
return { resource, config };
|
|
125
|
-
}
|
|
126
|
-
//# sourceMappingURL=run.js.map
|
package/dist/run.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":";;AAiCA,kBA2JC;AA5LD,oDAAiD;AAEjD,sEAAmE;AACnE,wDAAqD;AACrD,yDAAsD;AACtD,0CAAuC;AAGvC,4CAAyC;AACzC,qCAAgD;AAChD,qDAA0D;AAC1D,iDAGwB;AACxB,4DAIiC;AACjC,kDAA+C;AAE/C,yCAAyC;AAEzC,MAAM,QAAQ,GAAG,IAAA,sBAAW,GAAE,CAAC;AAE/B;;;;;;GAMG;AACI,KAAK,UAAU,GAAG,CACvB,4BAGgD,EAAE,sBAAsB;AACxE,OAAoB;IAEpB,MAAM,EACJ,KAAK,GAAG,SAAS,EACjB,IAAI,GAAG,EAAE,EACT,aAAa,GAAG,IAAI,EACpB,aAAa,GAAG,IAAI,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IACrB,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC"}
|
package/dist/testing.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { IResource, IResourceWithConfig, ITaskMiddleware, IResourceMiddleware, ITask, RegisterableItems, DependencyMapType } from "./defs";
|
|
2
|
-
import { EventManager, Logger, Store, TaskRunner } from "./models";
|
|
3
|
-
/**
|
|
4
|
-
* Helper to create a minimal test harness resource that wraps a root app (or any registerable)
|
|
5
|
-
* and exposes convenient testing utilities while running the full ecosystem
|
|
6
|
-
* (registration, overrides, middleware, events) without modifying the core API.
|
|
7
|
-
* @deprecated Use `run` instead with your testResource, as it provides the necessary toolkit.
|
|
8
|
-
*/
|
|
9
|
-
export declare function createTestResource(root: RegisterableItems, options?: {
|
|
10
|
-
overrides?: Array<IResource | ITask | ITaskMiddleware | IResourceMiddleware | IResourceWithConfig>;
|
|
11
|
-
}): IResource<void, Promise<ReturnType<typeof buildTestFacade>>>;
|
|
12
|
-
declare function buildTestFacade(deps: {
|
|
13
|
-
taskRunner: TaskRunner;
|
|
14
|
-
store: Store;
|
|
15
|
-
logger: Logger;
|
|
16
|
-
eventManager: EventManager;
|
|
17
|
-
}): {
|
|
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;
|
|
20
|
-
taskRunner: TaskRunner;
|
|
21
|
-
store: Store;
|
|
22
|
-
logger: Logger;
|
|
23
|
-
eventManager: EventManager;
|
|
24
|
-
};
|
|
25
|
-
export {};
|
package/dist/testing.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTestResource = createTestResource;
|
|
4
|
-
const define_1 = require("./define");
|
|
5
|
-
const globalResources_1 = require("./globals/globalResources");
|
|
6
|
-
let testResourceCounter = 0;
|
|
7
|
-
/**
|
|
8
|
-
* Helper to create a minimal test harness resource that wraps a root app (or any registerable)
|
|
9
|
-
* and exposes convenient testing utilities while running the full ecosystem
|
|
10
|
-
* (registration, overrides, middleware, events) without modifying the core API.
|
|
11
|
-
* @deprecated Use `run` instead with your testResource, as it provides the necessary toolkit.
|
|
12
|
-
*/
|
|
13
|
-
function createTestResource(root, options) {
|
|
14
|
-
return (0, define_1.defineResource)({
|
|
15
|
-
id: `testing.${root.id}.${++testResourceCounter}`,
|
|
16
|
-
register: [root],
|
|
17
|
-
overrides: options?.overrides || [],
|
|
18
|
-
dependencies: {
|
|
19
|
-
taskRunner: globalResources_1.globalResources.taskRunner,
|
|
20
|
-
store: globalResources_1.globalResources.store,
|
|
21
|
-
logger: globalResources_1.globalResources.logger,
|
|
22
|
-
eventManager: globalResources_1.globalResources.eventManager,
|
|
23
|
-
},
|
|
24
|
-
async init(_, deps) {
|
|
25
|
-
return buildTestFacade(deps);
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
function buildTestFacade(deps) {
|
|
30
|
-
return {
|
|
31
|
-
// Run a task within the fully initialized ecosystem
|
|
32
|
-
runTask: (task, ...args) => deps.taskRunner.run(task, ...args),
|
|
33
|
-
// Access a resource value by id (string or symbol)
|
|
34
|
-
getResource: (id) => deps.store.resources.get(id)?.value,
|
|
35
|
-
// Expose internals when needed in tests (not recommended for app usage)
|
|
36
|
-
taskRunner: deps.taskRunner,
|
|
37
|
-
store: deps.store,
|
|
38
|
-
logger: deps.logger,
|
|
39
|
-
eventManager: deps.eventManager,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=testing.js.map
|
package/dist/testing.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":";;AAyBA,gDA0BC;AAnDD,qCAA0C;AAC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.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCallerFile = getCallerFile;
|
|
4
|
-
function getCallerFile() {
|
|
5
|
-
const originalFunc = Error.prepareStackTrace;
|
|
6
|
-
try {
|
|
7
|
-
const err = new Error();
|
|
8
|
-
let callerfile;
|
|
9
|
-
let currentfile;
|
|
10
|
-
// Safeguard prepareStackTrace
|
|
11
|
-
Error.prepareStackTrace = (err, stack) => stack;
|
|
12
|
-
const stack = err.stack;
|
|
13
|
-
// Don't know how to test this.
|
|
14
|
-
// if (stack.length < 3) {
|
|
15
|
-
// // We need at least 3 frames: current function, its caller, and one above
|
|
16
|
-
// return undefined;
|
|
17
|
-
// }
|
|
18
|
-
// Remove the first frame (getCallerFile itself)
|
|
19
|
-
stack.shift();
|
|
20
|
-
// Remove the second frame (the direct caller of getCallerFile)
|
|
21
|
-
currentfile = stack.shift()?.getFileName?.();
|
|
22
|
-
// The third frame (the caller above the immediate one)
|
|
23
|
-
callerfile = stack.shift()?.getFileName?.();
|
|
24
|
-
return callerfile; // Return the file name of the caller above
|
|
25
|
-
}
|
|
26
|
-
finally {
|
|
27
|
-
Error.prepareStackTrace = originalFunc;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=getCallerFile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAE,CAAC;QAE7C,uDAAuD;QACvD,UAAU,GAAG,KAAK,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC;QAE5C,OAAO,UAAoB,CAAC,CAAC,2CAA2C;IAC1E,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,iBAAiB,GAAG,YAAY,CAAC;IACzC,CAAC;AACH,CAAC"}
|
|
@@ -1,55 +0,0 @@
|
|
|
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 {};
|
package/dist/types/contracts.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/types/contracts.ts"],"names":[],"mappings":";AAAA,0EAA0E"}
|
package/dist/types/event.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { IOptionalDependency, IValidationSchema } from "../defs";
|
|
2
|
-
import { TagType } from "./tag";
|
|
3
|
-
import { IEventMeta } from "./meta";
|
|
4
|
-
import { CommonPayload, symbolEvent, symbolFilePath } from "./utilities";
|
|
5
|
-
export type EventHandlerType<T = any> = (event: IEventEmission<T>) => any | Promise<any>;
|
|
6
|
-
export declare function onAnyOf<T extends readonly IEventDefinition<any>[]>(...defs: T): T;
|
|
7
|
-
/**
|
|
8
|
-
* Runtime guard that checks if an emission belongs to one of the given event defs.
|
|
9
|
-
* Narrows payload type to the intersection of the provided events' payloads.
|
|
10
|
-
*/
|
|
11
|
-
export declare function isOneOf<TDefs extends readonly IEventDefinition<any>[]>(emission: IEventEmission<any>, defs: TDefs): emission is IEventEmission<CommonPayload<TDefs>>;
|
|
12
|
-
export interface IEventDefinition<TPayload = void> {
|
|
13
|
-
id: string;
|
|
14
|
-
meta?: IEventMeta;
|
|
15
|
-
/**
|
|
16
|
-
* Optional validation schema for runtime payload validation.
|
|
17
|
-
* When provided, event payload will be validated when emitted.
|
|
18
|
-
*/
|
|
19
|
-
payloadSchema?: IValidationSchema<TPayload>;
|
|
20
|
-
tags?: TagType[];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The definioten of the event.
|
|
24
|
-
* This is different from the event emission.
|
|
25
|
-
*/
|
|
26
|
-
export interface IEvent<TPayload = any> extends IEventDefinition<TPayload> {
|
|
27
|
-
id: string;
|
|
28
|
-
/**
|
|
29
|
-
* 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.
|
|
30
|
-
*/
|
|
31
|
-
[symbolEvent]: true;
|
|
32
|
-
[symbolFilePath]: string;
|
|
33
|
-
/** Return an optional dependency wrapper for this event. */
|
|
34
|
-
optional: () => IOptionalDependency<IEvent<TPayload>>;
|
|
35
|
-
tags: TagType[];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* This represents the object that is passed to event handlers
|
|
39
|
-
*/
|
|
40
|
-
export interface IEventEmission<TPayload = any> {
|
|
41
|
-
/**
|
|
42
|
-
* The ID of the event. This is the same as the event's ID.
|
|
43
|
-
* This is useful for global event listeners.
|
|
44
|
-
*/
|
|
45
|
-
id: string;
|
|
46
|
-
/**
|
|
47
|
-
* The data that the event carries. It can be anything.
|
|
48
|
-
*/
|
|
49
|
-
data: TPayload;
|
|
50
|
-
/**
|
|
51
|
-
* The timestamp when the event was created.
|
|
52
|
-
*/
|
|
53
|
-
timestamp: Date;
|
|
54
|
-
/**
|
|
55
|
-
* The source of the event. This can be useful for debugging.
|
|
56
|
-
*/
|
|
57
|
-
source: string;
|
|
58
|
-
/**
|
|
59
|
-
* Metadata associated with the event definition.
|
|
60
|
-
*/
|
|
61
|
-
meta: IEventMeta;
|
|
62
|
-
/**
|
|
63
|
-
* Stops propagation to remaining event listeners.
|
|
64
|
-
*/
|
|
65
|
-
stopPropagation(): void;
|
|
66
|
-
/**
|
|
67
|
-
* Returns true if propagation has been stopped.
|
|
68
|
-
*/
|
|
69
|
-
isPropagationStopped(): boolean;
|
|
70
|
-
/**
|
|
71
|
-
* The tags that the event carries.
|
|
72
|
-
*/
|
|
73
|
-
tags: TagType[];
|
|
74
|
-
}
|
package/dist/types/event.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onAnyOf = onAnyOf;
|
|
4
|
-
exports.isOneOf = isOneOf;
|
|
5
|
-
const utilities_1 = require("./utilities");
|
|
6
|
-
// Helper to keep tuple inference intact for multi-event hooks
|
|
7
|
-
function onAnyOf(...defs) {
|
|
8
|
-
return defs;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Runtime guard that checks if an emission belongs to one of the given event defs.
|
|
12
|
-
* Narrows payload type to the intersection of the provided events' payloads.
|
|
13
|
-
*/
|
|
14
|
-
function isOneOf(emission, defs) {
|
|
15
|
-
return defs.some((d) => d.id === emission.id);
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=event.js.map
|
package/dist/types/event.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/types/event.ts"],"names":[],"mappings":";;AAUA,0BAIC;AAMD,0BAKC;AAtBD,2CAAyE;AAMzE,8DAA8D;AAC9D,SAAgB,OAAO,CACrB,GAAG,IAAO;IAEV,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAgB,OAAO,CACrB,QAA6B,EAC7B,IAAW;IAEX,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,EAAE,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/types/hook.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { DependencyMapType, DependencyValuesType, IEventDefinition, IEventEmission, ExtractEventParams } from "../defs";
|
|
2
|
-
import { TagType } from "./tag";
|
|
3
|
-
import { ITaskMeta } from "./meta";
|
|
4
|
-
import { CommonPayload, symbolFilePath, symbolHook } from "./utilities";
|
|
5
|
-
type OnType = "*" | IEventDefinition<any> | readonly IEventDefinition<any>[];
|
|
6
|
-
export interface IHookDefinition<TDependencies extends DependencyMapType = {}, TOn extends OnType = any, TMeta extends ITaskMeta = any> {
|
|
7
|
-
id: string;
|
|
8
|
-
dependencies?: TDependencies | (() => TDependencies);
|
|
9
|
-
on: TOn;
|
|
10
|
-
/** Listener execution order. Lower numbers run first. */
|
|
11
|
-
order?: number;
|
|
12
|
-
meta?: TMeta;
|
|
13
|
-
run: (event: IEventEmission<TOn extends "*" ? any : TOn extends readonly IEventDefinition<any>[] ? CommonPayload<TOn> : ExtractEventParams<TOn>>, dependencies: DependencyValuesType<TDependencies>) => Promise<any>;
|
|
14
|
-
tags?: TagType[];
|
|
15
|
-
}
|
|
16
|
-
export interface IHook<TDependencies extends DependencyMapType = {}, TOn extends OnType = any, TMeta extends ITaskMeta = any> extends IHookDefinition<TDependencies, TOn, TMeta> {
|
|
17
|
-
id: string;
|
|
18
|
-
dependencies: TDependencies | (() => TDependencies);
|
|
19
|
-
[symbolFilePath]: string;
|
|
20
|
-
[symbolHook]: true;
|
|
21
|
-
tags: TagType[];
|
|
22
|
-
}
|
|
23
|
-
export {};
|
package/dist/types/hook.js
DELETED
package/dist/types/hook.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../src/types/hook.ts"],"names":[],"mappings":";;AASA,2CAAwE"}
|
package/dist/types/meta.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Common metadata you can attach to tasks/resources/events/middleware.
|
|
3
|
-
* Useful for docs, filtering and middleware decisions.
|
|
4
|
-
*/
|
|
5
|
-
export interface IMeta {
|
|
6
|
-
title?: string;
|
|
7
|
-
description?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface ITaskMeta extends IMeta {
|
|
10
|
-
}
|
|
11
|
-
export interface IResourceMeta extends IMeta {
|
|
12
|
-
}
|
|
13
|
-
export interface IEventMeta extends IMeta {
|
|
14
|
-
}
|
|
15
|
-
export interface IMiddlewareMeta extends IMeta {
|
|
16
|
-
}
|
|
17
|
-
export interface ITagMeta extends IMeta {
|
|
18
|
-
}
|
package/dist/types/meta.js
DELETED
package/dist/types/meta.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"meta.js","sourceRoot":"","sources":["../../src/types/meta.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
package/dist/types/resource.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
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;
|
|
9
|
-
/** Static or lazy dependency map. Receives `config` when provided. */
|
|
10
|
-
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
11
|
-
/**
|
|
12
|
-
* Register other registerables (resources/tasks/middleware/events). Accepts a
|
|
13
|
-
* static array or a function of `config` to support dynamic wiring.
|
|
14
|
-
*/
|
|
15
|
-
register?: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
16
|
-
/**
|
|
17
|
-
* Initialize and return the resource value. Called once during boot.
|
|
18
|
-
*/
|
|
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>;
|
|
26
|
-
/**
|
|
27
|
-
* Clean-up function for the resource. This is called when the resource is no longer needed.
|
|
28
|
-
*
|
|
29
|
-
* @param value The value of the resource (undefined if no init method)
|
|
30
|
-
* @param config The configuration it received
|
|
31
|
-
* @param dependencies The dependencies it needed
|
|
32
|
-
* @returns Promise<void>
|
|
33
|
-
*/
|
|
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>;
|
|
41
|
-
/**
|
|
42
|
-
* Safe overrides to swap behavior while preserving identities. See
|
|
43
|
-
* README: Overrides.
|
|
44
|
-
*/
|
|
45
|
-
overrides?: Array<OverridableElements>;
|
|
46
|
-
/** Middleware applied around init/dispose. */
|
|
47
|
-
middleware?: TMiddleware;
|
|
48
|
-
/**
|
|
49
|
-
* Create a private, mutable context shared between `init` and `dispose`.
|
|
50
|
-
*/
|
|
51
|
-
context?: () => TContext;
|
|
52
|
-
/**
|
|
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.
|
|
55
|
-
*/
|
|
56
|
-
[symbolFilePath]?: string;
|
|
57
|
-
/**
|
|
58
|
-
* This is used internally when creating index resources.
|
|
59
|
-
*/
|
|
60
|
-
[symbolIndexResource]?: boolean;
|
|
61
|
-
tags?: TTags;
|
|
62
|
-
}
|
|
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>;
|
|
66
|
-
register: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
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;
|
|
75
|
-
}
|
|
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;
|
|
78
|
-
/** The id of the underlying resource. */
|
|
79
|
-
id: string;
|
|
80
|
-
/** The underlying resource definition. */
|
|
81
|
-
resource: IResource<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
82
|
-
/** The configuration captured by `.with(config)`. */
|
|
83
|
-
config: TConfig;
|
|
84
|
-
}
|
package/dist/types/resource.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/types/resource.ts"],"names":[],"mappings":";;AAYA,uCAKmB"}
|
|
@@ -1,47 +0,0 @@
|
|
|
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>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resourceMiddleware.js","sourceRoot":"","sources":["../../src/types/resourceMiddleware.ts"],"names":[],"mappings":";;AAQA,uCAImB"}
|