@bluelibs/runner 4.6.0 → 4.7.0-alpha
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 +319 -579
- package/README.md +886 -731
- package/dist/browser/index.cjs +1438 -251
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.mjs +1433 -252
- package/dist/browser/index.mjs.map +1 -1
- package/dist/context.d.ts +31 -0
- package/dist/define.d.ts +9 -0
- package/dist/definers/builders/core.d.ts +30 -0
- package/dist/definers/builders/event.d.ts +12 -0
- package/dist/definers/builders/hook.d.ts +20 -0
- package/dist/definers/builders/middleware.d.ts +39 -0
- package/dist/definers/builders/resource.d.ts +40 -0
- package/dist/definers/builders/tag.d.ts +10 -0
- package/dist/definers/builders/task.d.ts +37 -0
- package/dist/definers/builders/task.phantom.d.ts +27 -0
- package/dist/definers/builders/utils.d.ts +4 -0
- package/dist/definers/defineEvent.d.ts +2 -0
- package/dist/definers/defineHook.d.ts +6 -0
- package/dist/definers/defineOverride.d.ts +17 -0
- package/dist/definers/defineResource.d.ts +2 -0
- package/dist/definers/defineResourceMiddleware.d.ts +2 -0
- package/dist/definers/defineTag.d.ts +12 -0
- package/dist/definers/defineTask.d.ts +18 -0
- package/dist/definers/defineTaskMiddleware.d.ts +2 -0
- package/dist/definers/tools.d.ts +47 -0
- package/dist/defs.d.ts +29 -0
- package/dist/edge/index.cjs +1438 -251
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.mjs +1433 -252
- package/dist/edge/index.mjs.map +1 -1
- package/dist/errors.d.ts +104 -0
- package/dist/globals/globalEvents.d.ts +8 -0
- package/dist/globals/globalMiddleware.d.ts +31 -0
- package/dist/globals/globalResources.d.ts +32 -0
- package/dist/globals/globalTags.d.ts +11 -0
- package/dist/globals/middleware/cache.middleware.d.ts +27 -0
- package/dist/globals/middleware/requireContext.middleware.d.ts +6 -0
- package/dist/globals/middleware/retry.middleware.d.ts +21 -0
- package/dist/globals/middleware/timeout.middleware.d.ts +9 -0
- package/dist/globals/middleware/tunnel.middleware.d.ts +2 -0
- package/dist/globals/resources/debug/debug.resource.d.ts +7 -0
- package/dist/globals/resources/debug/debug.tag.d.ts +2 -0
- package/dist/globals/resources/debug/debugConfig.resource.d.ts +22 -0
- package/dist/globals/resources/debug/executionTracker.middleware.d.ts +50 -0
- package/dist/globals/resources/debug/globalEvent.hook.d.ts +27 -0
- package/dist/globals/resources/debug/hook.hook.d.ts +30 -0
- package/dist/globals/resources/debug/index.d.ts +6 -0
- package/dist/globals/resources/debug/middleware.hook.d.ts +30 -0
- package/dist/globals/resources/debug/types.d.ts +25 -0
- package/dist/globals/resources/debug/utils.d.ts +2 -0
- package/dist/globals/resources/queue.resource.d.ts +10 -0
- package/dist/globals/resources/tunnel/ejson-extensions.d.ts +1 -0
- package/dist/globals/resources/tunnel/error-utils.d.ts +1 -0
- package/dist/globals/resources/tunnel/plan.d.ts +19 -0
- package/dist/globals/resources/tunnel/protocol.d.ts +40 -0
- package/dist/globals/resources/tunnel/serializer.d.ts +9 -0
- package/dist/globals/resources/tunnel/tunnel.policy.tag.d.ts +18 -0
- package/dist/globals/resources/tunnel/tunnel.tag.d.ts +2 -0
- package/dist/globals/resources/tunnel/types.d.ts +17 -0
- package/dist/globals/tunnels/index.d.ts +23 -0
- package/dist/globals/types.d.ts +1 -0
- package/dist/http-client.d.ts +23 -0
- package/dist/http-fetch-tunnel.resource.d.ts +22 -0
- package/dist/index.d.ts +99 -0
- package/dist/models/DependencyProcessor.d.ts +48 -0
- package/dist/models/EventManager.d.ts +153 -0
- package/dist/models/LogPrinter.d.ts +55 -0
- package/dist/models/Logger.d.ts +85 -0
- package/dist/models/MiddlewareManager.d.ts +86 -0
- package/dist/models/OverrideManager.d.ts +13 -0
- package/dist/models/Queue.d.ts +26 -0
- package/dist/models/ResourceInitializer.d.ts +20 -0
- package/dist/models/RunResult.d.ts +35 -0
- package/dist/models/Semaphore.d.ts +61 -0
- package/dist/models/Store.d.ts +69 -0
- package/dist/models/StoreRegistry.d.ts +43 -0
- package/dist/models/StoreValidator.d.ts +8 -0
- package/dist/models/TaskRunner.d.ts +27 -0
- package/dist/models/UnhandledError.d.ts +11 -0
- package/dist/models/index.d.ts +11 -0
- package/dist/models/utils/findCircularDependencies.d.ts +16 -0
- package/dist/models/utils/safeStringify.d.ts +3 -0
- package/dist/node/exposure/allowList.d.ts +3 -0
- package/dist/node/exposure/authenticator.d.ts +6 -0
- package/dist/node/exposure/cors.d.ts +4 -0
- package/dist/node/exposure/createNodeExposure.d.ts +2 -0
- package/dist/node/exposure/exposureServer.d.ts +18 -0
- package/dist/node/exposure/httpResponse.d.ts +10 -0
- package/dist/node/exposure/logging.d.ts +4 -0
- package/dist/node/exposure/multipart.d.ts +27 -0
- package/dist/node/exposure/requestBody.d.ts +11 -0
- package/dist/node/exposure/requestContext.d.ts +17 -0
- package/dist/node/exposure/requestHandlers.d.ts +24 -0
- package/dist/node/exposure/resourceTypes.d.ts +60 -0
- package/dist/node/exposure/router.d.ts +17 -0
- package/dist/node/exposure/serverLifecycle.d.ts +13 -0
- package/dist/node/exposure/types.d.ts +31 -0
- package/dist/node/exposure/utils.d.ts +17 -0
- package/dist/node/exposure.resource.d.ts +12 -0
- package/dist/node/files.d.ts +9 -0
- package/dist/node/http-smart-client.model.d.ts +22 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/inputFile.model.d.ts +22 -0
- package/dist/node/inputFile.utils.d.ts +14 -0
- package/dist/node/mixed-http-client.node.d.ts +27 -0
- package/dist/node/node.cjs +11168 -0
- package/dist/node/node.cjs.map +1 -0
- package/dist/node/node.d.ts +6 -0
- package/dist/node/node.mjs +11099 -0
- package/dist/node/node.mjs.map +1 -0
- package/dist/node/platform/createFile.d.ts +9 -0
- package/dist/node/tunnel.allowlist.d.ts +7 -0
- package/dist/node/upload/manifest.d.ts +22 -0
- package/dist/platform/adapters/browser.d.ts +14 -0
- package/dist/platform/adapters/edge.d.ts +5 -0
- package/dist/platform/adapters/node-als.d.ts +1 -0
- package/dist/platform/adapters/node.d.ts +15 -0
- package/dist/platform/adapters/universal-generic.d.ts +14 -0
- package/dist/platform/adapters/universal.d.ts +17 -0
- package/dist/platform/createFile.d.ts +10 -0
- package/dist/platform/createWebFile.d.ts +11 -0
- package/dist/platform/factory.d.ts +2 -0
- package/dist/platform/index.d.ts +27 -0
- package/dist/platform/types.d.ts +29 -0
- package/dist/processHooks.d.ts +2 -0
- package/dist/run.d.ts +14 -0
- package/dist/testing.d.ts +25 -0
- package/dist/tools/getCallerFile.d.ts +1 -0
- package/dist/tunnels/buildUniversalManifest.d.ts +24 -0
- package/dist/types/contracts.d.ts +63 -0
- package/dist/types/event.d.ts +74 -0
- package/dist/types/hook.d.ts +23 -0
- package/dist/types/inputFile.d.ts +34 -0
- package/dist/types/meta.d.ts +18 -0
- package/dist/types/resource.d.ts +87 -0
- package/dist/types/resourceMiddleware.d.ts +47 -0
- package/dist/types/runner.d.ts +55 -0
- package/dist/types/storeTypes.d.ts +40 -0
- package/dist/types/symbols.d.ts +28 -0
- package/dist/types/tag.d.ts +46 -0
- package/dist/types/task.d.ts +50 -0
- package/dist/types/taskMiddleware.d.ts +48 -0
- package/dist/types/utilities.d.ts +111 -0
- package/dist/universal/index.cjs +1438 -251
- package/dist/universal/index.cjs.map +1 -1
- package/dist/universal/index.mjs +1433 -252
- package/dist/universal/index.mjs.map +1 -1
- package/package.json +34 -8
- package/dist/index.d.mts +0 -1747
- package/dist/index.unused.js +0 -4466
- package/dist/index.unused.js.map +0 -1
- package/dist/node/index.cjs +0 -4498
- package/dist/node/index.cjs.map +0 -1
- package/dist/node/index.mjs +0 -4466
- package/dist/node/index.mjs.map +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Readable } from "stream";
|
|
2
|
+
import type { InputFileMeta, EjsonFileSentinel } from "../../types/inputFile";
|
|
3
|
+
export interface NodeFileSource {
|
|
4
|
+
stream?: Readable;
|
|
5
|
+
buffer?: Buffer;
|
|
6
|
+
}
|
|
7
|
+
export declare function createFile(meta: InputFileMeta, source: NodeFileSource, id?: string): EjsonFileSentinel & {
|
|
8
|
+
_node: NodeFileSource;
|
|
9
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Readable } from "stream";
|
|
2
|
+
import type { InputFileMeta } from "../../types/inputFile";
|
|
3
|
+
export interface NodeFileSource {
|
|
4
|
+
id: string;
|
|
5
|
+
meta: InputFileMeta;
|
|
6
|
+
source: {
|
|
7
|
+
type: "buffer";
|
|
8
|
+
buffer: Buffer;
|
|
9
|
+
} | {
|
|
10
|
+
type: "stream";
|
|
11
|
+
stream: Readable;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface BuiltManifest<T = any> {
|
|
15
|
+
input: T;
|
|
16
|
+
files: NodeFileSource[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Walk an input object and collect File sentinels having local Node sources.
|
|
20
|
+
* It returns a shallow-cloned structure where any internal _node fields are removed.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildNodeManifest<T = any>(input: T): BuiltManifest<T>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IAsyncLocalStorage, IPlatformAdapter, PlatformId } from "../types";
|
|
2
|
+
export declare class BrowserPlatformAdapter implements IPlatformAdapter {
|
|
3
|
+
readonly id: PlatformId;
|
|
4
|
+
init(): Promise<void>;
|
|
5
|
+
onUncaughtException(handler: (error: any) => void): () => any;
|
|
6
|
+
onUnhandledRejection(handler: (reason: any) => void): () => any;
|
|
7
|
+
onShutdownSignal(handler: () => void): () => void;
|
|
8
|
+
exit(): void;
|
|
9
|
+
getEnv(key: string): any;
|
|
10
|
+
hasAsyncLocalStorage(): boolean;
|
|
11
|
+
createAsyncLocalStorage<T>(): IAsyncLocalStorage<T>;
|
|
12
|
+
setTimeout: typeof setTimeout;
|
|
13
|
+
clearTimeout: typeof clearTimeout;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadAsyncLocalStorageClass(): Promise<any>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IAsyncLocalStorage, IPlatformAdapter } from "../types";
|
|
2
|
+
export declare class NodePlatformAdapter implements IPlatformAdapter {
|
|
3
|
+
readonly id: "node";
|
|
4
|
+
private alsClass;
|
|
5
|
+
init(): Promise<void>;
|
|
6
|
+
onUncaughtException(handler: (error: any) => void): () => NodeJS.Process;
|
|
7
|
+
onUnhandledRejection(handler: (reason: any) => void): () => NodeJS.Process;
|
|
8
|
+
onShutdownSignal(handler: () => void): () => void;
|
|
9
|
+
exit(code: number): void;
|
|
10
|
+
getEnv(key: string): string | undefined;
|
|
11
|
+
hasAsyncLocalStorage(): boolean;
|
|
12
|
+
createAsyncLocalStorage<T>(): IAsyncLocalStorage<T>;
|
|
13
|
+
setTimeout: typeof setTimeout;
|
|
14
|
+
clearTimeout: typeof clearTimeout;
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IAsyncLocalStorage, IPlatformAdapter } from "../types";
|
|
2
|
+
export declare class GenericUniversalPlatformAdapter implements IPlatformAdapter {
|
|
3
|
+
readonly id: "universal";
|
|
4
|
+
init(): Promise<void>;
|
|
5
|
+
onUncaughtException(handler: (error: any) => void): () => any;
|
|
6
|
+
onUnhandledRejection(handler: (reason: any) => void): () => any;
|
|
7
|
+
onShutdownSignal(handler: () => void): () => void;
|
|
8
|
+
exit(): void;
|
|
9
|
+
getEnv(key: string): string | undefined;
|
|
10
|
+
hasAsyncLocalStorage(): boolean;
|
|
11
|
+
createAsyncLocalStorage<T>(): IAsyncLocalStorage<T>;
|
|
12
|
+
setTimeout: typeof setTimeout;
|
|
13
|
+
clearTimeout: typeof clearTimeout;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IPlatformAdapter, PlatformId } from "../types";
|
|
2
|
+
export declare function detectEnvironment(): PlatformId;
|
|
3
|
+
export declare class UniversalPlatformAdapter implements IPlatformAdapter {
|
|
4
|
+
readonly id: PlatformId;
|
|
5
|
+
private inner;
|
|
6
|
+
init(): Promise<void>;
|
|
7
|
+
private get;
|
|
8
|
+
onUncaughtException(handler: (error: Error) => void): () => void;
|
|
9
|
+
onUnhandledRejection(handler: (reason: unknown) => void): () => void;
|
|
10
|
+
onShutdownSignal(handler: () => void): () => void;
|
|
11
|
+
exit(code: number): void;
|
|
12
|
+
getEnv(key: string): string | undefined;
|
|
13
|
+
hasAsyncLocalStorage(): boolean;
|
|
14
|
+
createAsyncLocalStorage<T>(): import("..").IAsyncLocalStorage<T>;
|
|
15
|
+
setTimeout: typeof setTimeout;
|
|
16
|
+
clearTimeout: typeof clearTimeout;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { InputFileMeta, EjsonFileSentinel } from "../types/inputFile";
|
|
2
|
+
/**
|
|
3
|
+
* Universal/browser `createFile` helper. For Node, import from `@bluelibs/runner/node`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createFile(meta: InputFileMeta, blob: Blob, id?: string): EjsonFileSentinel & {
|
|
6
|
+
_web: {
|
|
7
|
+
blob: Blob;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export type { EjsonFileSentinel };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { InputFileMeta, EjsonFileSentinel } from "../types/inputFile";
|
|
2
|
+
/**
|
|
3
|
+
* Browser/edge-friendly File sentinel creator.
|
|
4
|
+
* Produces the same public EJSON File shape with a browser sidecar `_web`.
|
|
5
|
+
* The sidecar will be stripped out by the universal manifest walker before upload.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createWebFile(meta: InputFileMeta, blob: Blob, id?: string): EjsonFileSentinel & {
|
|
8
|
+
_web: {
|
|
9
|
+
blob: Blob;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IPlatformAdapter, IAsyncLocalStorage, PlatformId } from "./types";
|
|
2
|
+
import { detectEnvironment } from "./adapters/universal";
|
|
3
|
+
export { detectEnvironment };
|
|
4
|
+
export declare function getPlatform(): IPlatformAdapter;
|
|
5
|
+
export declare function setPlatform(adapter: IPlatformAdapter): void;
|
|
6
|
+
export declare function resetPlatform(): void;
|
|
7
|
+
export declare function getDetectedEnvironment(): PlatformId;
|
|
8
|
+
export declare function isNode(): boolean;
|
|
9
|
+
export declare function isBrowser(): boolean;
|
|
10
|
+
export declare function isUniversal(): boolean;
|
|
11
|
+
export type { IPlatformAdapter, IAsyncLocalStorage } from "./types";
|
|
12
|
+
export declare class PlatformAdapter implements IPlatformAdapter {
|
|
13
|
+
private inner;
|
|
14
|
+
readonly env: PlatformId;
|
|
15
|
+
readonly id: PlatformId;
|
|
16
|
+
constructor(env?: PlatformId);
|
|
17
|
+
init(): Promise<void>;
|
|
18
|
+
onUncaughtException(handler: (error: any) => void): () => void;
|
|
19
|
+
onUnhandledRejection(handler: (reason: any) => void): () => void;
|
|
20
|
+
onShutdownSignal(handler: () => void): () => void;
|
|
21
|
+
exit(code: number): void;
|
|
22
|
+
getEnv(key: string): string | undefined;
|
|
23
|
+
hasAsyncLocalStorage(): boolean;
|
|
24
|
+
createAsyncLocalStorage<T>(): IAsyncLocalStorage<T>;
|
|
25
|
+
setTimeout: typeof setTimeout;
|
|
26
|
+
clearTimeout: typeof clearTimeout;
|
|
27
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform abstraction interface for universal compatibility
|
|
3
|
+
* Inspired by Remix's approach to Web APIs and runtime-agnostic design
|
|
4
|
+
*/
|
|
5
|
+
export type PlatformId = "node" | "browser" | "edge" | "universal";
|
|
6
|
+
export interface IPlatformAdapter {
|
|
7
|
+
readonly id: PlatformId;
|
|
8
|
+
onUncaughtException(handler: (error: Error) => void): () => void;
|
|
9
|
+
onUnhandledRejection(handler: (reason: unknown) => void): () => void;
|
|
10
|
+
onShutdownSignal(handler: () => void): () => void;
|
|
11
|
+
exit(code: number): void;
|
|
12
|
+
getEnv(key: string): string | undefined;
|
|
13
|
+
hasAsyncLocalStorage(): boolean;
|
|
14
|
+
createAsyncLocalStorage<T>(): IAsyncLocalStorage<T>;
|
|
15
|
+
setTimeout: typeof globalThis.setTimeout;
|
|
16
|
+
clearTimeout: typeof globalThis.clearTimeout;
|
|
17
|
+
init: () => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export interface IAsyncLocalStorage<T> {
|
|
20
|
+
getStore(): T | undefined;
|
|
21
|
+
run<R>(store: T, callback: () => R): R;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Utility functions for environment detection
|
|
25
|
+
*/
|
|
26
|
+
export declare function isNode(): boolean;
|
|
27
|
+
export declare function isBrowser(): boolean;
|
|
28
|
+
export declare function isWebWorker(): boolean;
|
|
29
|
+
export declare function isUniversal(): boolean;
|
package/dist/run.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IResource, IResourceWithConfig } from "./defs";
|
|
2
|
+
import { RunResult } from "./models/RunResult";
|
|
3
|
+
import { RunOptions } from "./types/runner";
|
|
4
|
+
/**
|
|
5
|
+
* 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.
|
|
6
|
+
*
|
|
7
|
+
* @param resourceOrResourceWithConfig - The resource or resource with config to run.
|
|
8
|
+
* @param options - The options for the run.
|
|
9
|
+
* @returns A promise that resolves to the result of the run.
|
|
10
|
+
*/
|
|
11
|
+
export declare function run<C, V extends Promise<any>>(resourceOrResourceWithConfig: IResourceWithConfig<C, V> | IResource<void, V, any, any> | IResource<{
|
|
12
|
+
[K in any]?: any;
|
|
13
|
+
}, V, any, any>, // For optional config
|
|
14
|
+
options?: RunOptions): Promise<RunResult<V extends Promise<infer U> ? U : V>>;
|
|
@@ -0,0 +1,25 @@
|
|
|
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 {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getCallerFile(): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Readable } from "stream";
|
|
2
|
+
import type { InputFileMeta } from "../types/inputFile";
|
|
3
|
+
export interface NodeCollectedFile {
|
|
4
|
+
id: string;
|
|
5
|
+
meta: InputFileMeta;
|
|
6
|
+
source: {
|
|
7
|
+
type: "buffer";
|
|
8
|
+
buffer: Buffer;
|
|
9
|
+
} | {
|
|
10
|
+
type: "stream";
|
|
11
|
+
stream: Readable;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface WebCollectedFile {
|
|
15
|
+
id: string;
|
|
16
|
+
meta: InputFileMeta;
|
|
17
|
+
blob: Blob;
|
|
18
|
+
}
|
|
19
|
+
export interface BuiltUniversalManifest<T = any> {
|
|
20
|
+
input: T;
|
|
21
|
+
nodeFiles: NodeCollectedFile[];
|
|
22
|
+
webFiles: WebCollectedFile[];
|
|
23
|
+
}
|
|
24
|
+
export declare function buildUniversalManifest<T = any>(input: T): BuiltUniversalManifest<T>;
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
type NonVoid<T> = [T] extends [void] ? never : T;
|
|
13
|
+
type IsTuple<T extends readonly unknown[]> = number extends T["length"] ? false : true;
|
|
14
|
+
type UnionToIntersection<U> = (U extends any ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
|
|
15
|
+
type Simplify<T> = {
|
|
16
|
+
[K in keyof T]: T[K];
|
|
17
|
+
} & {};
|
|
18
|
+
type IsUnknown<T> = unknown extends T ? [T] extends [unknown] ? true : false : false;
|
|
19
|
+
type UnknownToNever<T> = IsUnknown<T> extends true ? never : T;
|
|
20
|
+
type ExtractContractOf<T, Kind extends "input" | "output"> = T extends IContractable<any, infer I, infer O> ? UnknownToNever<Kind extends "input" ? NonVoid<I> : NonVoid<O>> : never;
|
|
21
|
+
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;
|
|
22
|
+
type ExtractContractsFromCollection<TItems extends readonly unknown[], Kind extends "input" | "output"> = IsTuple<TItems> extends true ? FilterContractsKind<TItems, Kind> : Array<ExtractContractOf<TItems[number], Kind>>;
|
|
23
|
+
export type ExtractInputTypeFromContracts<TItems extends readonly unknown[]> = ExtractContractsFromCollection<TItems, "input">;
|
|
24
|
+
export type ExtractOutputTypeFromContracts<TItems extends readonly unknown[]> = ExtractContractsFromCollection<TItems, "output">;
|
|
25
|
+
type ContractsUnionInputs<TItems extends readonly unknown[]> = ExtractInputTypeFromContracts<TItems> extends readonly (infer U)[] ? U : never;
|
|
26
|
+
type ContractsUnionOutputs<TItems extends readonly unknown[]> = ExtractOutputTypeFromContracts<TItems> extends readonly (infer U)[] ? U : never;
|
|
27
|
+
type ContractsIntersectionInputs<TItems extends readonly unknown[]> = UnionToIntersection<ContractsUnionInputs<TItems>>;
|
|
28
|
+
type ContractsIntersectionOutputs<TItems extends readonly unknown[]> = UnionToIntersection<ContractsUnionOutputs<TItems>>;
|
|
29
|
+
export type HasInputContracts<TItems extends readonly unknown[]> = [
|
|
30
|
+
ContractsUnionInputs<TItems>
|
|
31
|
+
] extends [never] ? false : true;
|
|
32
|
+
export type HasOutputContracts<TItems extends readonly unknown[]> = [
|
|
33
|
+
ContractsUnionOutputs<TItems>
|
|
34
|
+
] extends [never] ? false : true;
|
|
35
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
36
|
+
type KeysWithNever<T> = T extends object ? {
|
|
37
|
+
[K in keyof T]-?: [T[K]] extends [never] ? K : never;
|
|
38
|
+
}[keyof T] : never;
|
|
39
|
+
type HasNeverProperty<T> = KeysWithNever<T> extends never ? false : true;
|
|
40
|
+
type IsImpossibleIntersection<T> = IsNever<T> extends true ? true : HasNeverProperty<T> extends true ? true : false;
|
|
41
|
+
export type InputContractViolationError<TItems extends readonly unknown[], TActual> = {
|
|
42
|
+
message: "Value does not satisfy all input contracts";
|
|
43
|
+
expected: Simplify<ContractsIntersectionInputs<TItems>>;
|
|
44
|
+
received: TActual;
|
|
45
|
+
};
|
|
46
|
+
export type OutputContractViolationError<TItems extends readonly unknown[], TActual> = {
|
|
47
|
+
message: "Value does not satisfy all output contracts";
|
|
48
|
+
expected: Simplify<ContractsIntersectionOutputs<TItems>>;
|
|
49
|
+
received: TActual;
|
|
50
|
+
};
|
|
51
|
+
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>;
|
|
52
|
+
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>;
|
|
53
|
+
export type InferInputOrViolationFromContracts<TItems extends readonly unknown[]> = HasInputContracts<TItems> extends false ? void : ContractsIntersectionInputs<TItems> extends infer I ? IsImpossibleIntersection<I> extends true ? InputContractViolationError<TItems, Simplify<I extends never ? never : I>> : Simplify<I> : never;
|
|
54
|
+
export type InputArg<TItems extends readonly unknown[]> = [
|
|
55
|
+
InferInputOrViolationFromContracts<TItems>
|
|
56
|
+
] extends [void] ? [] : [InferInputOrViolationFromContracts<TItems>];
|
|
57
|
+
export type InputCollisionGuard<TItems extends readonly unknown[]> = IsImpossibleIntersection<ContractsIntersectionInputs<TItems>> extends true ? InputContractViolationError<TItems, Simplify<ContractsIntersectionInputs<TItems>>> : unknown;
|
|
58
|
+
export type InferOutputOrViolationFromContracts<TItems extends readonly unknown[]> = HasOutputContracts<TItems> extends false ? unknown : ContractsIntersectionOutputs<TItems> extends infer O ? IsImpossibleIntersection<O> extends true ? OutputContractViolationError<TItems, Simplify<O extends never ? never : O>> : Simplify<O> : never;
|
|
59
|
+
/** @deprecated Use ExtractOutputTypeFromContracts instead */
|
|
60
|
+
export type ExtractTagsWithNonVoidReturnTypeFromTags<TTags extends TagType[]> = ExtractOutputTypeFromContracts<TTags>;
|
|
61
|
+
/** @deprecated Use EnsureOutputSatisfiesContracts instead */
|
|
62
|
+
export type EnsureResponseSatisfiesContracts<TTags extends TagType[], TResponse> = EnsureOutputSatisfiesContracts<TTags, TResponse>;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DependencyMapType, DependencyValuesType, IEventDefinition, IEventEmission, ExtractEventPayload } 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> : ExtractEventPayload<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 {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface InputFileMeta {
|
|
2
|
+
name: string;
|
|
3
|
+
type?: string;
|
|
4
|
+
size?: number;
|
|
5
|
+
lastModified?: number;
|
|
6
|
+
extra?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
/** Universal interface exposed to tasks for streamed files. */
|
|
9
|
+
export interface InputFile<TStream = unknown> extends InputFileMeta {
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the underlying stream for one-time consumption.
|
|
12
|
+
* Implementations must enforce single-use semantics.
|
|
13
|
+
*/
|
|
14
|
+
resolve(): Promise<{
|
|
15
|
+
stream: TStream;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Return the underlying stream (single-use). Should throw if already consumed.
|
|
19
|
+
*/
|
|
20
|
+
stream(): TStream;
|
|
21
|
+
/**
|
|
22
|
+
* Persist the stream to a temporary file on disk and return its path and number of bytes written.
|
|
23
|
+
*/
|
|
24
|
+
toTempFile(dir?: string): Promise<{
|
|
25
|
+
path: string;
|
|
26
|
+
bytesWritten: number;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
/** Client-side sentinel to declare file presence in an input structure. */
|
|
30
|
+
export interface EjsonFileSentinel {
|
|
31
|
+
$ejson: "File";
|
|
32
|
+
id: string;
|
|
33
|
+
meta: InputFileMeta;
|
|
34
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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, symbolResource, symbolResourceWithConfig } from "./symbols";
|
|
5
|
+
import { EnsureInputSatisfiesContracts, EnsureOutputSatisfiesContracts, HasInputContracts, HasOutputContracts, InferInputOrViolationFromContracts } from "./contracts";
|
|
6
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
7
|
+
type IsUnspecified<T> = [T] extends [undefined] ? true : [T] extends [void] ? true : IsAny<T> extends true ? true : false;
|
|
8
|
+
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[]> {
|
|
9
|
+
/** Stable identifier. */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Static or lazy dependency map. Receives `config` when provided. */
|
|
12
|
+
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
13
|
+
/**
|
|
14
|
+
* Register other registerables (resources/tasks/middleware/events). Accepts a
|
|
15
|
+
* static array or a function of `config` to support dynamic wiring.
|
|
16
|
+
*/
|
|
17
|
+
register?: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
18
|
+
/**
|
|
19
|
+
* Initialize and return the resource value. Called once during boot.
|
|
20
|
+
*/
|
|
21
|
+
init?: (config: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? IsUnspecified<TConfig> extends true ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : EnsureInputSatisfiesContracts<[...TTags, ...TMiddleware], TConfig> : TConfig, dependencies: ResourceDependencyValuesType<TDependencies>, context: TContext) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TValue> : TValue;
|
|
22
|
+
/**
|
|
23
|
+
* Optional validation schema for the resource's resolved value.
|
|
24
|
+
* When provided, the value will be validated immediately after `init` resolves,
|
|
25
|
+
* without considering middleware.
|
|
26
|
+
*/
|
|
27
|
+
resultSchema?: IValidationSchema<TValue extends Promise<infer U> ? U : TValue>;
|
|
28
|
+
/**
|
|
29
|
+
* Clean-up function for the resource. This is called when the resource is no longer needed.
|
|
30
|
+
*
|
|
31
|
+
* @param value The value of the resource (undefined if no init method)
|
|
32
|
+
* @param config The configuration it received
|
|
33
|
+
* @param dependencies The dependencies it needed
|
|
34
|
+
* @returns Promise<void>
|
|
35
|
+
*/
|
|
36
|
+
dispose?: (this: any, value: TValue extends Promise<infer U> ? U : TValue, config: TConfig, dependencies: ResourceDependencyValuesType<TDependencies>, context: TContext) => Promise<void>;
|
|
37
|
+
meta?: TMeta;
|
|
38
|
+
/**
|
|
39
|
+
* Optional validation schema for runtime config validation.
|
|
40
|
+
* When provided, resource config will be validated when .with() is called.
|
|
41
|
+
*/
|
|
42
|
+
configSchema?: IValidationSchema<TConfig>;
|
|
43
|
+
/**
|
|
44
|
+
* Safe overrides to swap behavior while preserving identities. See
|
|
45
|
+
* README: Overrides.
|
|
46
|
+
*/
|
|
47
|
+
overrides?: Array<OverridableElements>;
|
|
48
|
+
/** Middleware applied around init/dispose. */
|
|
49
|
+
middleware?: TMiddleware;
|
|
50
|
+
/**
|
|
51
|
+
* Create a private, mutable context shared between `init` and `dispose`.
|
|
52
|
+
*/
|
|
53
|
+
context?: () => TContext;
|
|
54
|
+
/**
|
|
55
|
+
* This is optional and used from an index resource to get the correct caller.
|
|
56
|
+
* This is the reason we allow it here as well.
|
|
57
|
+
*/
|
|
58
|
+
[symbolFilePath]?: string;
|
|
59
|
+
tags?: TTags;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Helper alias describing the canonical resource init call signature.
|
|
63
|
+
* Shared with fluent builders to keep init typing consistent.
|
|
64
|
+
*/
|
|
65
|
+
export type ResourceInitFn<TConfig, TValue extends Promise<any>, TDependencies extends DependencyMapType, TContext, TMeta extends IResourceMeta, TTags extends TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[]> = NonNullable<IResourceDefinition<TConfig, TValue, TDependencies, TContext, any, any, TMeta, TTags, TMiddleware>["init"]>;
|
|
66
|
+
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> {
|
|
67
|
+
id: string;
|
|
68
|
+
with(config: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? IsUnspecified<TConfig> extends true ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : TConfig : TConfig): IResourceWithConfig<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
69
|
+
register: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
|
|
70
|
+
overrides: Array<OverridableElements>;
|
|
71
|
+
middleware: TMiddleware;
|
|
72
|
+
[symbolFilePath]: string;
|
|
73
|
+
[symbolResource]: true;
|
|
74
|
+
/** Return an optional dependency wrapper for this resource. */
|
|
75
|
+
optional: () => IOptionalDependency<IResource<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>>;
|
|
76
|
+
tags: TTags;
|
|
77
|
+
}
|
|
78
|
+
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[]> {
|
|
79
|
+
[symbolResourceWithConfig]: true;
|
|
80
|
+
/** The id of the underlying resource. */
|
|
81
|
+
id: string;
|
|
82
|
+
/** The underlying resource definition. */
|
|
83
|
+
resource: IResource<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
84
|
+
/** The configuration captured by `.with(config)`. */
|
|
85
|
+
config: TConfig;
|
|
86
|
+
}
|
|
87
|
+
export {};
|
|
@@ -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>;
|