@bluelibs/runner 4.8.6 → 4.9.0

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.
Files changed (173) hide show
  1. package/AI.md +8 -0
  2. package/README.md +39 -4
  3. package/dist/browser/index.cjs +543 -418
  4. package/dist/browser/index.cjs.map +1 -1
  5. package/dist/browser/index.d.mts +2221 -0
  6. package/dist/browser/index.d.ts +2221 -0
  7. package/dist/browser/index.mjs +543 -418
  8. package/dist/browser/index.mjs.map +1 -1
  9. package/dist/edge/index.cjs +543 -418
  10. package/dist/edge/index.cjs.map +1 -1
  11. package/dist/edge/index.d.mts +2221 -0
  12. package/dist/edge/index.d.ts +2221 -0
  13. package/dist/edge/index.mjs +543 -418
  14. package/dist/edge/index.mjs.map +1 -1
  15. package/dist/node/node.cjs +584 -436
  16. package/dist/node/node.cjs.map +1 -1
  17. package/dist/node/node.d.mts +2472 -0
  18. package/dist/node/node.d.ts +2425 -55
  19. package/dist/node/node.mjs +584 -436
  20. package/dist/node/node.mjs.map +1 -1
  21. package/dist/universal/index.cjs +541 -418
  22. package/dist/universal/index.cjs.map +1 -1
  23. package/dist/universal/index.d.mts +2221 -0
  24. package/dist/universal/index.d.ts +2221 -0
  25. package/dist/universal/index.mjs +541 -418
  26. package/dist/universal/index.mjs.map +1 -1
  27. package/package.json +5 -5
  28. package/dist/define.d.ts +0 -9
  29. package/dist/definers/builders/asyncContext.d.ts +0 -13
  30. package/dist/definers/builders/core.d.ts +0 -30
  31. package/dist/definers/builders/error.d.ts +0 -15
  32. package/dist/definers/builders/event.d.ts +0 -12
  33. package/dist/definers/builders/hook.d.ts +0 -20
  34. package/dist/definers/builders/middleware.d.ts +0 -39
  35. package/dist/definers/builders/resource.d.ts +0 -40
  36. package/dist/definers/builders/tag.d.ts +0 -10
  37. package/dist/definers/builders/task.d.ts +0 -37
  38. package/dist/definers/builders/task.phantom.d.ts +0 -27
  39. package/dist/definers/builders/utils.d.ts +0 -4
  40. package/dist/definers/defineAsyncContext.d.ts +0 -15
  41. package/dist/definers/defineError.d.ts +0 -26
  42. package/dist/definers/defineEvent.d.ts +0 -2
  43. package/dist/definers/defineHook.d.ts +0 -6
  44. package/dist/definers/defineOverride.d.ts +0 -17
  45. package/dist/definers/defineResource.d.ts +0 -2
  46. package/dist/definers/defineResourceMiddleware.d.ts +0 -2
  47. package/dist/definers/defineTag.d.ts +0 -12
  48. package/dist/definers/defineTask.d.ts +0 -18
  49. package/dist/definers/defineTaskMiddleware.d.ts +0 -2
  50. package/dist/definers/tools.d.ts +0 -53
  51. package/dist/defs.d.ts +0 -31
  52. package/dist/errors.d.ts +0 -62
  53. package/dist/globals/debug.d.ts +0 -10
  54. package/dist/globals/globalEvents.d.ts +0 -8
  55. package/dist/globals/globalMiddleware.d.ts +0 -31
  56. package/dist/globals/globalResources.d.ts +0 -41
  57. package/dist/globals/globalTags.d.ts +0 -11
  58. package/dist/globals/middleware/cache.middleware.d.ts +0 -27
  59. package/dist/globals/middleware/requireContext.middleware.d.ts +0 -6
  60. package/dist/globals/middleware/retry.middleware.d.ts +0 -21
  61. package/dist/globals/middleware/timeout.middleware.d.ts +0 -9
  62. package/dist/globals/middleware/tunnel.middleware.d.ts +0 -2
  63. package/dist/globals/resources/debug/debug.resource.d.ts +0 -7
  64. package/dist/globals/resources/debug/debug.tag.d.ts +0 -2
  65. package/dist/globals/resources/debug/debugConfig.resource.d.ts +0 -22
  66. package/dist/globals/resources/debug/executionTracker.middleware.d.ts +0 -50
  67. package/dist/globals/resources/debug/globalEvent.hook.d.ts +0 -27
  68. package/dist/globals/resources/debug/hook.hook.d.ts +0 -30
  69. package/dist/globals/resources/debug/index.d.ts +0 -6
  70. package/dist/globals/resources/debug/middleware.hook.d.ts +0 -30
  71. package/dist/globals/resources/debug/types.d.ts +0 -25
  72. package/dist/globals/resources/debug/utils.d.ts +0 -2
  73. package/dist/globals/resources/httpClientFactory.resource.d.ts +0 -28
  74. package/dist/globals/resources/queue.resource.d.ts +0 -10
  75. package/dist/globals/resources/tunnel/ejson-extensions.d.ts +0 -1
  76. package/dist/globals/resources/tunnel/error-utils.d.ts +0 -1
  77. package/dist/globals/resources/tunnel/plan.d.ts +0 -19
  78. package/dist/globals/resources/tunnel/protocol.d.ts +0 -47
  79. package/dist/globals/resources/tunnel/serializer.d.ts +0 -9
  80. package/dist/globals/resources/tunnel/tunnel.policy.tag.d.ts +0 -18
  81. package/dist/globals/resources/tunnel/tunnel.tag.d.ts +0 -2
  82. package/dist/globals/resources/tunnel/types.d.ts +0 -42
  83. package/dist/globals/tunnels/index.d.ts +0 -23
  84. package/dist/globals/types.d.ts +0 -4
  85. package/dist/http-client.d.ts +0 -25
  86. package/dist/http-fetch-tunnel.resource.d.ts +0 -11
  87. package/dist/index.d.ts +0 -117
  88. package/dist/models/DependencyProcessor.d.ts +0 -48
  89. package/dist/models/EventManager.d.ts +0 -153
  90. package/dist/models/LogPrinter.d.ts +0 -55
  91. package/dist/models/Logger.d.ts +0 -85
  92. package/dist/models/MiddlewareManager.d.ts +0 -75
  93. package/dist/models/OverrideManager.d.ts +0 -13
  94. package/dist/models/Queue.d.ts +0 -26
  95. package/dist/models/ResourceInitializer.d.ts +0 -20
  96. package/dist/models/RunResult.d.ts +0 -35
  97. package/dist/models/Semaphore.d.ts +0 -61
  98. package/dist/models/Store.d.ts +0 -73
  99. package/dist/models/StoreRegistry.d.ts +0 -49
  100. package/dist/models/StoreValidator.d.ts +0 -8
  101. package/dist/models/TaskRunner.d.ts +0 -27
  102. package/dist/models/UnhandledError.d.ts +0 -11
  103. package/dist/models/index.d.ts +0 -11
  104. package/dist/models/middleware/InterceptorRegistry.d.ts +0 -56
  105. package/dist/models/middleware/MiddlewareResolver.d.ts +0 -31
  106. package/dist/models/middleware/ResourceMiddlewareComposer.d.ts +0 -34
  107. package/dist/models/middleware/TaskMiddlewareComposer.d.ts +0 -43
  108. package/dist/models/middleware/ValidationHelper.d.ts +0 -20
  109. package/dist/models/middleware/index.d.ts +0 -6
  110. package/dist/models/middleware/types.d.ts +0 -10
  111. package/dist/models/utils/findCircularDependencies.d.ts +0 -16
  112. package/dist/models/utils/safeStringify.d.ts +0 -3
  113. package/dist/node/exposure/allowList.d.ts +0 -3
  114. package/dist/node/exposure/authenticator.d.ts +0 -6
  115. package/dist/node/exposure/cors.d.ts +0 -4
  116. package/dist/node/exposure/createNodeExposure.d.ts +0 -2
  117. package/dist/node/exposure/exposureServer.d.ts +0 -18
  118. package/dist/node/exposure/httpResponse.d.ts +0 -10
  119. package/dist/node/exposure/logging.d.ts +0 -4
  120. package/dist/node/exposure/multipart.d.ts +0 -27
  121. package/dist/node/exposure/requestBody.d.ts +0 -11
  122. package/dist/node/exposure/requestContext.d.ts +0 -17
  123. package/dist/node/exposure/requestHandlers.d.ts +0 -24
  124. package/dist/node/exposure/resourceTypes.d.ts +0 -60
  125. package/dist/node/exposure/router.d.ts +0 -17
  126. package/dist/node/exposure/serverLifecycle.d.ts +0 -13
  127. package/dist/node/exposure/types.d.ts +0 -31
  128. package/dist/node/exposure/utils.d.ts +0 -17
  129. package/dist/node/exposure.resource.d.ts +0 -12
  130. package/dist/node/files.d.ts +0 -9
  131. package/dist/node/http-mixed-client.d.ts +0 -30
  132. package/dist/node/http-smart-client.model.d.ts +0 -24
  133. package/dist/node/index.d.ts +0 -1
  134. package/dist/node/inputFile.model.d.ts +0 -22
  135. package/dist/node/inputFile.utils.d.ts +0 -14
  136. package/dist/node/platform/createFile.d.ts +0 -9
  137. package/dist/node/resources/http-mixed-client.factory.resource.d.ts +0 -17
  138. package/dist/node/resources/http-smart-client.factory.resource.d.ts +0 -16
  139. package/dist/node/tunnel.allowlist.d.ts +0 -7
  140. package/dist/node/upload/manifest.d.ts +0 -22
  141. package/dist/platform/adapters/browser.d.ts +0 -14
  142. package/dist/platform/adapters/edge.d.ts +0 -5
  143. package/dist/platform/adapters/node-als.d.ts +0 -1
  144. package/dist/platform/adapters/node.d.ts +0 -15
  145. package/dist/platform/adapters/universal-generic.d.ts +0 -14
  146. package/dist/platform/adapters/universal.d.ts +0 -17
  147. package/dist/platform/createFile.d.ts +0 -10
  148. package/dist/platform/createWebFile.d.ts +0 -11
  149. package/dist/platform/factory.d.ts +0 -2
  150. package/dist/platform/index.d.ts +0 -27
  151. package/dist/platform/types.d.ts +0 -29
  152. package/dist/processHooks.d.ts +0 -2
  153. package/dist/run.d.ts +0 -14
  154. package/dist/testing.d.ts +0 -25
  155. package/dist/tools/getCallerFile.d.ts +0 -1
  156. package/dist/tunnels/buildUniversalManifest.d.ts +0 -24
  157. package/dist/types/asyncContext.d.ts +0 -41
  158. package/dist/types/contracts.d.ts +0 -63
  159. package/dist/types/error.d.ts +0 -36
  160. package/dist/types/event.d.ts +0 -74
  161. package/dist/types/hook.d.ts +0 -23
  162. package/dist/types/inputFile.d.ts +0 -34
  163. package/dist/types/meta.d.ts +0 -22
  164. package/dist/types/resource.d.ts +0 -87
  165. package/dist/types/resourceMiddleware.d.ts +0 -47
  166. package/dist/types/runner.d.ts +0 -68
  167. package/dist/types/storeTypes.d.ts +0 -40
  168. package/dist/types/symbols.d.ts +0 -32
  169. package/dist/types/tag.d.ts +0 -46
  170. package/dist/types/task.d.ts +0 -54
  171. package/dist/types/taskMiddleware.d.ts +0 -48
  172. package/dist/types/utilities.d.ts +0 -113
  173. package/dist/utils/detectRunnerMode.d.ts +0 -9
@@ -1,63 +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
- 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 {};
@@ -1,36 +0,0 @@
1
- import { symbolError } from "./symbols";
2
- import type { IOptionalDependency } from "./utilities";
3
- import type { IValidationSchema } from "./utilities";
4
- import type { IErrorMeta } from "./meta";
5
- export declare const ERROR_TYPES_LOADED: true;
6
- export interface IErrorDefinition<TData extends DefaultErrorType = DefaultErrorType> {
7
- id: string;
8
- serialize?: (data: TData) => string;
9
- parse?: (data: string) => TData;
10
- format?: (data: TData) => string;
11
- /**
12
- * Validate error data on throw(). If provided, data is parsed first.
13
- */
14
- dataSchema?: IValidationSchema<TData>;
15
- meta?: IErrorMeta;
16
- }
17
- export interface IErrorDefinitionFinal<TData extends DefaultErrorType> extends IErrorDefinition<TData> {
18
- format: (data: TData) => string;
19
- }
20
- export type DefaultErrorType = Record<string, unknown>;
21
- /**
22
- * Runtime helper returned by defineError()/r.error().
23
- * Contains helpers to throw typed errors and perform type-safe checks.
24
- */
25
- export interface IErrorHelper<TData extends DefaultErrorType = DefaultErrorType> {
26
- /** Unique id for registration and DI */
27
- id: string;
28
- /** Throw a typed error with the given data */
29
- throw(data: TData): never;
30
- /** Type guard for checking if an unknown error is this error */
31
- is(error: unknown): boolean;
32
- /** Brand symbol for runtime detection */
33
- [symbolError]: true;
34
- /** Return an optional dependency wrapper for this error */
35
- optional(): IOptionalDependency<IErrorHelper<TData>>;
36
- }
@@ -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
- }
@@ -1,23 +0,0 @@
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 {};
@@ -1,34 +0,0 @@
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
- }
@@ -1,22 +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
- }
19
- export interface IErrorMeta extends IMeta {
20
- }
21
- export interface IAsyncContextMeta extends IMeta {
22
- }
@@ -1,87 +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, 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 {};
@@ -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,68 +0,0 @@
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
- /**
10
- * Configure logging settings.
11
- */
12
- logs?: {
13
- /**
14
- * Defaults to info. Use null to disable logging.
15
- */
16
- printThreshold?: null | LogLevels;
17
- /**
18
- * Defaults to PRETTY. How to print the logs.
19
- */
20
- printStrategy?: PrintStrategy;
21
- /**
22
- * Defaults to false. If true, we buffer logs until the root resource is ready.
23
- * This provides you with the chance to see the logs before the root resource is ready.
24
- */
25
- bufferLogs?: boolean;
26
- };
27
- /**
28
- * When true (default), installs a central error boundary that catches uncaught errors
29
- * from process-level events and routes them to `onUnhandledError`.
30
- */
31
- errorBoundary?: boolean;
32
- /**
33
- * When true (default), installs SIGINT/SIGTERM handlers that call dispose() on the root allowing for graceful shutdown.
34
- */
35
- shutdownHooks?: boolean;
36
- /**
37
- * Custom handler for any unhandled error caught by Runner. Defaults to logging via the created logger.
38
- */
39
- onUnhandledError?: OnUnhandledError;
40
- /**
41
- * Defaults to false.
42
- *
43
- * Dry run mode. When true, the runner will setup the system, ensure there are no errors, but will not start the system.
44
- * Your resources will not be initialized, and no events will be emitted. This is useful for testing and debugging.
45
- *
46
- * Note: this cannot catch init() errors that happen within resources.
47
- */
48
- dryRun?: boolean;
49
- /**
50
- * Defaults to true.
51
- * When set, forces runtime cycle detection for event emissions. Disable if you're sure
52
- * you don't have event deadlocks to improve event emission performance.
53
- */
54
- runtimeCycleDetection?: boolean;
55
- /**
56
- * Specify in which mode to run "dev", "prod" or "test".
57
- * If inside Node this is automatically detected from the NODE_ENV environment variable if not provided.
58
- */
59
- mode?: RunnerMode;
60
- };
61
- /**
62
- * The mode in which the runner is operating
63
- */
64
- export declare enum RunnerMode {
65
- TEST = "test",
66
- DEV = "dev",
67
- PROD = "prod"
68
- }
@@ -1,40 +0,0 @@
1
- import { DependencyMapType, DependencyValuesType, ResourceDependencyValuesType } from "./utilities";
2
- import { IResource } from "./resource";
3
- import { ITask } from "./task";
4
- import { IHook } from "./hook";
5
- import { ITaskMiddleware } from "./taskMiddleware";
6
- import { IResourceMiddleware } from "./resourceMiddleware";
7
- import { IEvent } from "./event";
8
- import { IEventDefinition } from "./event";
9
- import { TaskLocalInterceptor } from "./utilities";
10
- export type ResourceStoreElementType<C = any, V extends Promise<any> = any, D extends DependencyMapType = {}, TContext = any> = {
11
- resource: IResource<C, V, D>;
12
- computedDependencies?: ResourceDependencyValuesType<D>;
13
- config: C;
14
- value: V;
15
- context: TContext;
16
- isInitialized?: boolean;
17
- };
18
- export type TaskStoreElementType<Input = any, Output extends Promise<any> = any, D extends DependencyMapType = any> = {
19
- task: ITask<Input, Output, D>;
20
- computedDependencies: DependencyValuesType<D>;
21
- isInitialized: boolean;
22
- interceptors?: Array<TaskLocalInterceptor<any, any>>;
23
- };
24
- export type HookStoreElementType<D extends DependencyMapType = any, TOn extends "*" | IEventDefinition = any> = {
25
- hook: IHook<D, TOn>;
26
- computedDependencies: DependencyValuesType<D>;
27
- };
28
- export type TaskMiddlewareStoreElementType<TDeps extends DependencyMapType = any> = {
29
- middleware: ITaskMiddleware<any, TDeps>;
30
- computedDependencies: DependencyValuesType<TDeps>;
31
- isInitialized: boolean;
32
- };
33
- export type ResourceMiddlewareStoreElementType<TDeps extends DependencyMapType = any> = {
34
- middleware: IResourceMiddleware<any, TDeps>;
35
- computedDependencies: DependencyValuesType<TDeps>;
36
- isInitialized: boolean;
37
- };
38
- export type EventStoreElementType = {
39
- event: IEvent<any>;
40
- };
@@ -1,32 +0,0 @@
1
- /**
2
- * Internal brand symbols used to tag created objects at runtime and help with
3
- * type‑narrowing. Prefer the `isTask`/`isResource`/`isEvent`/`isMiddleware`
4
- * helpers instead of touching these directly.
5
- * @internal
6
- */
7
- export declare const symbolTask: unique symbol;
8
- /** Marks a task as a phantom task (no-op run; meant to be tunneled/routed). */
9
- export declare const symbolPhantomTask: unique symbol;
10
- export declare const symbolResource: unique symbol;
11
- export declare const symbolResourceWithConfig: unique symbol;
12
- export declare const symbolEvent: unique symbol;
13
- /** @internal Marks an error helper definition */
14
- export declare const symbolError: unique symbol;
15
- export declare const symbolMiddleware: unique symbol;
16
- /** New brands for separated middleware kinds */
17
- export declare const symbolTaskMiddleware: unique symbol;
18
- export declare const symbolResourceMiddleware: unique symbol;
19
- export declare const symbolMiddlewareConfigured: unique symbol;
20
- /** Records which tunnel resource owns the task patching (exclusivity). */
21
- export declare const symbolTunneledBy: unique symbol;
22
- /** @internal Marks hook definitions (event listeners without middleware) */
23
- export declare const symbolHook: unique symbol;
24
- /** @internal Marks a tag definition */
25
- export declare const symbolTag: unique symbol;
26
- export declare const symbolTagConfigured: unique symbol;
27
- /** @internal Marks an optional dependency wrapper */
28
- export declare const symbolOptionalDependency: unique symbol;
29
- /** @internal Path to aid anonymous id generation and error messages */
30
- export declare const symbolFilePath: unique symbol;
31
- /** @internal Marks an async context definition */
32
- export declare const symbolAsyncContext: unique symbol;
@@ -1,46 +0,0 @@
1
- import { IContractable } from "./contracts";
2
- import { ITagMeta } from "./meta";
3
- import { IValidationSchema, RequiredKeys, symbolFilePath, symbolTag, symbolTagConfigured } from "./utilities";
4
- export interface ITaggable {
5
- tags: TagType[];
6
- }
7
- export interface ITagDefinition<TConfig = void, TEnforceInputContract = void, TEnforceOutputContract = void> {
8
- id: string;
9
- meta?: ITagMeta;
10
- configSchema?: IValidationSchema<TConfig>;
11
- /**
12
- * Utilizing config at definition level stores its defaults
13
- */
14
- config?: TConfig;
15
- }
16
- export interface ITag<TConfig = void, TEnforceInputContract = void, TEnforceOutputContract = void> extends ITagDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract>, IContractable<TConfig, TEnforceInputContract, TEnforceOutputContract> {
17
- /**
18
- * A special validation property.
19
- * It resolves to `true` if TConfig only has optional keys, otherwise `false`.
20
- */
21
- readonly __configHasOnlyOptionalKeys: RequiredKeys<TConfig> extends never ? true : false;
22
- config?: TConfig;
23
- /**
24
- * Checks if the tag exists in a taggable or a list of tags.
25
- */
26
- exists(target: ITaggable | TagType[]): boolean;
27
- /**
28
- * Creates a configured instance of the tag.
29
- */
30
- with(config: TConfig): ITagConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract>;
31
- /**
32
- * Extracts the configuration of the tag from a taggable or a list of tags.
33
- */
34
- extract(target: ITaggable | TagType[]): TConfig | undefined;
35
- [symbolFilePath]: string;
36
- [symbolTag]: true;
37
- }
38
- type ITagWithOptionalConfig<TValue, TEnforceInputContract, TEnforceOutputContract> = ITag<any, TEnforceInputContract, TEnforceOutputContract> & {
39
- readonly __configHasOnlyOptionalKeys: true;
40
- };
41
- export interface ITagConfigured<TConfig = void, TEnforceInputContract = void, TEnforceOutputContract = void> extends ITag<TConfig, TEnforceInputContract, TEnforceOutputContract> {
42
- [symbolTagConfigured]: true;
43
- config: TConfig;
44
- }
45
- export type TagType = ITag<void, any, any> | ITagWithOptionalConfig<any, any, any> | ITagConfigured<any, any, any>;
46
- export {};
@@ -1,54 +0,0 @@
1
- import { DependencyMapType, DependencyValuesType, IOptionalDependency, IValidationSchema, TaskMiddlewareAttachmentType } from "../defs";
2
- import { TagType } from "./tag";
3
- import { ITaskMeta } from "./meta";
4
- import { symbolFilePath, symbolTask, symbolPhantomTask, symbolTunneledBy } from "./symbols";
5
- import { EnsureInputSatisfiesContracts, EnsureOutputSatisfiesContracts, HasInputContracts, HasOutputContracts, InferInputOrViolationFromContracts } from "./contracts";
6
- export interface ITaskDefinition<TInput = undefined, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> {
7
- id: string;
8
- /**
9
- * Access other tasks/resources/events. Can be an object or a function when
10
- * you need late or config‑dependent resolution.
11
- */
12
- dependencies?: TDependencies | (() => TDependencies);
13
- /** Middleware applied around task execution. */
14
- middleware?: TMiddleware;
15
- /** Optional metadata used for docs, filtering and tooling. */
16
- meta?: TMeta;
17
- /**
18
- * Optional validation schema for runtime input validation.
19
- * When provided, task input will be validated before execution.
20
- */
21
- inputSchema?: IValidationSchema<TInput>;
22
- /**
23
- * Optional validation schema for the task result.
24
- * When provided, the result will be validated immediately after the task's
25
- * `run` resolves, without considering middleware.
26
- */
27
- resultSchema?: IValidationSchema<TOutput extends Promise<infer U> ? U : never>;
28
- run: (input: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? [TInput] extends [undefined] ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : EnsureInputSatisfiesContracts<[...TTags, ...TMiddleware], TInput> : TInput, dependencies: DependencyValuesType<TDependencies>) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TOutput> : TOutput;
29
- /**
30
- * Tags applied to the task that might define its behvaiour or impact the systems.
31
- */
32
- tags?: TTags;
33
- }
34
- export interface ITask<TInput = any, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> extends ITaskDefinition<TInput, TOutput, TDependencies, TMeta, TTags, TMiddleware> {
35
- [symbolFilePath]: string;
36
- [symbolTask]: true;
37
- /** Present only for phantom tasks. */
38
- [symbolPhantomTask]?: true;
39
- /** Indicates if the task is tunneled through a tunnel client. */
40
- isTunneled?: boolean;
41
- /** Records which tunnel resource owns the task (exclusivity). */
42
- [symbolTunneledBy]?: string;
43
- id: string;
44
- dependencies: TDependencies | (() => TDependencies);
45
- computedDependencies?: DependencyValuesType<TDependencies>;
46
- middleware: TMiddleware;
47
- /** Return an optional dependency wrapper for this task. */
48
- optional: () => IOptionalDependency<ITask<TInput, TOutput, TDependencies, TMeta, TTags, TMiddleware>>;
49
- tags: TTags;
50
- }
51
- /** Narrowed type for phantom tasks (no-op run by default). */
52
- export type IPhantomTask<TInput = any, TResolved = any, TDependencies extends DependencyMapType = {}, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> = ITask<TInput, Promise<TResolved>, TDependencies, TMeta, TTags, TMiddleware> & {
53
- [symbolPhantomTask]: true;
54
- };