@bluelibs/runner 4.9.0 → 5.0.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.
- package/README.md +110 -3475
- package/dist/browser/index.cjs +6828 -3845
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.mts +986 -317
- package/dist/browser/index.d.ts +986 -317
- package/dist/browser/index.mjs +6821 -3838
- package/dist/browser/index.mjs.map +1 -1
- package/dist/edge/index.cjs +6828 -3845
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.d.mts +986 -317
- package/dist/edge/index.d.ts +986 -317
- package/dist/edge/index.mjs +6821 -3838
- package/dist/edge/index.mjs.map +1 -1
- package/dist/node/node.cjs +42195 -7093
- package/dist/node/node.cjs.map +1 -1
- package/dist/node/node.d.mts +2518 -397
- package/dist/node/node.d.ts +2518 -397
- package/dist/node/node.mjs +42263 -7195
- package/dist/node/node.mjs.map +1 -1
- package/dist/ui/assets/index-2cb8f39f.js +141 -0
- package/dist/ui/assets/index-b1f988bf.css +1 -0
- package/dist/ui/index.html +14 -0
- package/dist/universal/index.cjs +6828 -3845
- package/dist/universal/index.cjs.map +1 -1
- package/dist/universal/index.d.mts +986 -317
- package/dist/universal/index.d.ts +986 -317
- package/dist/universal/index.mjs +6821 -3838
- package/dist/universal/index.mjs.map +1 -1
- package/package.json +54 -22
- package/readmes/AI.md +534 -0
- package/AI.md +0 -462
package/dist/node/node.d.ts
CHANGED
|
@@ -1,15 +1,212 @@
|
|
|
1
|
+
import * as lru_cache from 'lru-cache';
|
|
1
2
|
import { Readable } from 'stream';
|
|
2
3
|
export { Readable } from 'stream';
|
|
3
4
|
import * as http from 'http';
|
|
4
5
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
5
|
-
|
|
6
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
7
|
+
import { Request, Router } from 'express';
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Type definitions for the Serializer class
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Definition for a custom type that can be serialized/deserialized
|
|
14
|
+
*/
|
|
15
|
+
interface TypeDefinition<TInstance = unknown, TSerialized = unknown> {
|
|
16
|
+
/** Unique identifier for the type */
|
|
17
|
+
id: string;
|
|
18
|
+
/** Predicate function to check if an object matches this type */
|
|
19
|
+
is: (obj: unknown) => obj is TInstance;
|
|
20
|
+
/** Function to serialize the object */
|
|
21
|
+
serialize: (obj: TInstance) => TSerialized;
|
|
22
|
+
/** Function to deserialize the data back to the original object */
|
|
23
|
+
deserialize: (data: TSerialized) => TInstance;
|
|
24
|
+
/** Optional factory used to create a placeholder during deserialization */
|
|
25
|
+
create?: () => TInstance;
|
|
26
|
+
/** Serialization strategy: 'value' (inline, no identity) or 'ref' (graph node, identity preserved). Default: 'ref' */
|
|
27
|
+
strategy?: "value" | "ref";
|
|
28
|
+
}
|
|
29
|
+
/** Reference to another object in the serialization */
|
|
30
|
+
interface ObjectReference {
|
|
31
|
+
/** Reference to object ID */
|
|
32
|
+
__ref: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Discriminated union describing the serialized graph payload.
|
|
36
|
+
* Each node captures either an array, plain object, or typed payload.
|
|
37
|
+
*/
|
|
38
|
+
type SerializedNode = {
|
|
39
|
+
kind: "array";
|
|
40
|
+
value: SerializedValue[];
|
|
41
|
+
} | {
|
|
42
|
+
kind: "object";
|
|
43
|
+
value: Record<string, SerializedValue>;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "type";
|
|
46
|
+
type: string;
|
|
47
|
+
value: SerializedValue;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Serialization context for tracking object references
|
|
51
|
+
*/
|
|
52
|
+
interface SerializationContext {
|
|
53
|
+
/** Map of objects to their IDs */
|
|
54
|
+
objectIds: WeakMap<object, string>;
|
|
55
|
+
/** Counter for generating unique IDs */
|
|
56
|
+
idCounter: number;
|
|
57
|
+
/** Number of graph nodes recorded */
|
|
58
|
+
nodeCount: number;
|
|
59
|
+
/** Nodes collected during serialization (id -> serialized node) */
|
|
60
|
+
nodes: Record<string, SerializedNode>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Deserialization context used when materialising a graph payload.
|
|
64
|
+
*/
|
|
65
|
+
interface DeserializationContext {
|
|
66
|
+
nodes: Record<string, SerializedNode>;
|
|
67
|
+
resolved: Map<string, unknown>;
|
|
68
|
+
resolving: Set<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Tracks reference ids that were requested while still being resolved.
|
|
71
|
+
* Used to detect circular references that rely on placeholders.
|
|
72
|
+
*/
|
|
73
|
+
resolvingRefs: Set<string>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Union type for serialized values
|
|
77
|
+
*/
|
|
78
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
79
|
+
interface SerializedTypeRecord {
|
|
80
|
+
__type: string;
|
|
81
|
+
value: SerializedValue;
|
|
82
|
+
}
|
|
83
|
+
type SerializedValue = JsonPrimitive | ObjectReference | SerializedTypeRecord | SerializedValue[] | {
|
|
84
|
+
[key: string]: SerializedValue;
|
|
85
|
+
};
|
|
86
|
+
declare enum SymbolPolicy {
|
|
87
|
+
AllowAll = "AllowAll",
|
|
88
|
+
WellKnownOnly = "WellKnownOnly",
|
|
89
|
+
Disabled = "Disabled"
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Main serializer options
|
|
93
|
+
*/
|
|
94
|
+
interface SerializerOptions {
|
|
95
|
+
/** Whether to pretty-print JSON (for debugging) */
|
|
96
|
+
pretty?: boolean;
|
|
97
|
+
/** Maximum recursion depth allowed during serialize/deserialize */
|
|
98
|
+
maxDepth?: number;
|
|
99
|
+
/** Restrict deserialization to this list of type IDs */
|
|
100
|
+
allowedTypes?: readonly string[];
|
|
101
|
+
/** Controls which Symbol payloads may be deserialized */
|
|
102
|
+
symbolPolicy?: SymbolPolicy;
|
|
103
|
+
/** Maximum accepted RegExp pattern length during deserialization */
|
|
104
|
+
maxRegExpPatternLength?: number;
|
|
105
|
+
/** Allow RegExp patterns that fail the safety heuristic */
|
|
106
|
+
allowUnsafeRegExp?: boolean;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Minimal serializer contract used across transports and persistence.
|
|
110
|
+
* Implementations must be able to round-trip JSON-compatible payloads and
|
|
111
|
+
* should support custom value types via `addType`.
|
|
112
|
+
*/
|
|
113
|
+
interface SerializerLike {
|
|
8
114
|
stringify(value: unknown): string;
|
|
9
115
|
parse<T = unknown>(text: string): T;
|
|
10
|
-
addType?<TJson = unknown,
|
|
116
|
+
addType?<TJson = unknown, TInstance = unknown>(name: string, factory: (json: TJson) => TInstance): void;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Graph-aware serializer/deserializer with circular reference
|
|
121
|
+
* handling and pluggable type support.
|
|
122
|
+
*
|
|
123
|
+
* Internal protocol reference: `readmes/SERIALIZER_PROTOCOL.md`.
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
declare class Serializer {
|
|
127
|
+
/** Type registry for managing custom types */
|
|
128
|
+
private readonly typeRegistry;
|
|
129
|
+
private readonly runtimeOptions;
|
|
130
|
+
/** JSON indentation width when pretty printing is enabled */
|
|
131
|
+
private readonly indent;
|
|
132
|
+
/** Maximum recursion depth allowed */
|
|
133
|
+
private readonly maxDepth;
|
|
134
|
+
/** Maximum allowed RegExp pattern length during deserialization */
|
|
135
|
+
private readonly maxRegExpPatternLength;
|
|
136
|
+
/** Allow RegExp patterns that fail the safety heuristic */
|
|
137
|
+
private readonly allowUnsafeRegExp;
|
|
138
|
+
/** Disallowed keys that can lead to prototype pollution */
|
|
139
|
+
private readonly unsafeKeys;
|
|
140
|
+
constructor(options?: SerializerOptions);
|
|
141
|
+
/**
|
|
142
|
+
* Alias of `serialize()` to match the historical tunnel serializer surface.
|
|
143
|
+
*/
|
|
144
|
+
stringify<T>(value: T): string;
|
|
145
|
+
/**
|
|
146
|
+
* Alias of `deserialize()` to match the historical tunnel serializer surface.
|
|
147
|
+
*/
|
|
148
|
+
parse<T = unknown>(payload: string): T;
|
|
149
|
+
/**
|
|
150
|
+
* Serialize an arbitrary value into a JSON string.
|
|
151
|
+
*/
|
|
152
|
+
serialize<T>(value: T, context?: SerializationContext): string;
|
|
153
|
+
/**
|
|
154
|
+
* Deserialize a JSON string back to its original value.
|
|
155
|
+
*/
|
|
156
|
+
deserialize<T = unknown>(payload: string): T;
|
|
157
|
+
/**
|
|
158
|
+
* Register a custom type for serialization/deserialization.
|
|
159
|
+
*/
|
|
160
|
+
addType<TInstance, TSerialized>(typeDef: TypeDefinition<TInstance, TSerialized>): void;
|
|
161
|
+
addType<TJson = unknown, TInstance = unknown>(name: string, factory: (json: TJson) => TInstance): void;
|
|
162
|
+
/**
|
|
163
|
+
* @internal - Exposed for testing RegExp safety validation
|
|
164
|
+
*/
|
|
165
|
+
readonly isRegExpPatternSafe: (pattern: string) => boolean;
|
|
166
|
+
/**
|
|
167
|
+
* @internal - Exposed for testing quantifier detection
|
|
168
|
+
*/
|
|
169
|
+
readonly isQuantifierAt: (pattern: string, index: number) => boolean;
|
|
170
|
+
/**
|
|
171
|
+
* @internal - Exposed for testing quantifier character detection
|
|
172
|
+
*/
|
|
173
|
+
readonly isQuantifierChar: (char: string, pattern: string, index: number) => boolean;
|
|
174
|
+
/**
|
|
175
|
+
* @internal - Exposed for testing bounded quantifier detection
|
|
176
|
+
*/
|
|
177
|
+
readonly isBoundedQuantifier: (pattern: string, index: number) => boolean;
|
|
178
|
+
/**
|
|
179
|
+
* @internal - Exposed for test compatibility
|
|
180
|
+
*/
|
|
181
|
+
toNodeRecord(nodes: Record<string, SerializedNode>): Record<string, SerializedNode>;
|
|
182
|
+
/**
|
|
183
|
+
* @internal - Exposed for test compatibility
|
|
184
|
+
*/
|
|
185
|
+
deserializeValue(value: SerializedValue, context: DeserializationContext, depth?: number): unknown;
|
|
186
|
+
/**
|
|
187
|
+
* @internal - Exposed for test compatibility
|
|
188
|
+
*/
|
|
189
|
+
resolveReference(id: string, context: DeserializationContext, depth?: number): unknown;
|
|
190
|
+
/**
|
|
191
|
+
* @internal - Exposed for test compatibility
|
|
192
|
+
*/
|
|
193
|
+
mergePlaceholder(placeholder: unknown, result: unknown): unknown;
|
|
194
|
+
/**
|
|
195
|
+
* @internal - Exposed for test compatibility
|
|
196
|
+
*/
|
|
197
|
+
isSerializedTypeRecord(value: unknown): value is {
|
|
198
|
+
__type: string;
|
|
199
|
+
value: unknown;
|
|
200
|
+
};
|
|
201
|
+
private jsonStringify;
|
|
11
202
|
}
|
|
12
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Main export module for the Serializer
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
declare function getDefaultSerializer(): Serializer;
|
|
209
|
+
|
|
13
210
|
declare const CONTRACT: unique symbol;
|
|
14
211
|
type CONTRACT = typeof CONTRACT;
|
|
15
212
|
interface IContractable<TConfig = any, TInput = void, TOutput = void> {
|
|
@@ -89,7 +286,7 @@ interface IAsyncContextMeta extends IMeta {
|
|
|
89
286
|
interface ITaggable {
|
|
90
287
|
tags: TagType[];
|
|
91
288
|
}
|
|
92
|
-
interface ITagDefinition<TConfig = void,
|
|
289
|
+
interface ITagDefinition<TConfig = void, _TEnforceInputContract = void, _TEnforceOutputContract = void> {
|
|
93
290
|
id: string;
|
|
94
291
|
meta?: ITagMeta;
|
|
95
292
|
configSchema?: IValidationSchema<TConfig>;
|
|
@@ -120,7 +317,7 @@ interface ITag<TConfig = void, TEnforceInputContract = void, TEnforceOutputContr
|
|
|
120
317
|
[symbolFilePath]: string;
|
|
121
318
|
[symbolTag]: true;
|
|
122
319
|
}
|
|
123
|
-
type ITagWithOptionalConfig<
|
|
320
|
+
type ITagWithOptionalConfig<_TValue, TEnforceInputContract, TEnforceOutputContract> = ITag<any, TEnforceInputContract, TEnforceOutputContract> & {
|
|
124
321
|
readonly __configHasOnlyOptionalKeys: true;
|
|
125
322
|
};
|
|
126
323
|
interface ITagConfigured<TConfig = void, TEnforceInputContract = void, TEnforceOutputContract = void> extends ITag<TConfig, TEnforceInputContract, TEnforceOutputContract> {
|
|
@@ -162,9 +359,86 @@ declare const symbolFilePath: unique symbol;
|
|
|
162
359
|
/** @internal Marks an async context definition */
|
|
163
360
|
declare const symbolAsyncContext: unique symbol;
|
|
164
361
|
|
|
362
|
+
interface IResourceMiddlewareDefinition<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> {
|
|
363
|
+
id: string;
|
|
364
|
+
/** Static or lazy dependency map. */
|
|
365
|
+
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
366
|
+
/**
|
|
367
|
+
* Optional validation schema for runtime config validation.
|
|
368
|
+
* When provided, middleware config will be validated when .with() is called.
|
|
369
|
+
*/
|
|
370
|
+
configSchema?: IValidationSchema<TConfig>;
|
|
371
|
+
/**
|
|
372
|
+
* The middleware body, called with resource execution input.
|
|
373
|
+
*/
|
|
374
|
+
run: (input: IResourceMiddlewareExecutionInput<TEnforceInputContract extends void ? any : TEnforceInputContract, TEnforceOutputContract extends void ? any : TEnforceOutputContract>, dependencies: DependencyValuesType<TDependencies>, config: TConfig) => Promise<any>;
|
|
375
|
+
meta?: IMiddlewareMeta;
|
|
376
|
+
tags?: TagType[];
|
|
377
|
+
everywhere?: boolean | ((resource: IResource<any, any, any, any, any>) => boolean);
|
|
378
|
+
}
|
|
379
|
+
interface IResourceMiddleware<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends IResourceMiddlewareDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>, IContractable<TConfig, TEnforceInputContract, TEnforceOutputContract> {
|
|
380
|
+
[symbolResourceMiddleware]: true;
|
|
381
|
+
id: string;
|
|
382
|
+
dependencies: TDependencies | ((config: TConfig) => TDependencies);
|
|
383
|
+
/** Current configuration object (empty by default). */
|
|
384
|
+
config: TConfig;
|
|
385
|
+
/** Configure the middleware and return a marked, configured instance. */
|
|
386
|
+
with: (config: TConfig) => IResourceMiddlewareConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
387
|
+
[symbolFilePath]: string;
|
|
388
|
+
tags: TagType[];
|
|
389
|
+
}
|
|
390
|
+
interface IResourceMiddlewareConfigured<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends IResourceMiddleware<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies> {
|
|
391
|
+
[symbolMiddlewareConfigured]: true;
|
|
392
|
+
}
|
|
393
|
+
interface IResourceMiddlewareExecutionInput<TResourceConfig = any, TResourceOutput = any> {
|
|
394
|
+
/** Resource hook */
|
|
395
|
+
resource: {
|
|
396
|
+
definition: IResource<TResourceConfig, any, any, any, any>;
|
|
397
|
+
config: TResourceConfig;
|
|
398
|
+
};
|
|
399
|
+
next: (resourceConfig?: TResourceConfig) => Promise<TResourceOutput>;
|
|
400
|
+
}
|
|
401
|
+
type ResourceMiddlewareAttachmentType = IResourceMiddleware<void, any, any, any> | IResourceMiddleware<{
|
|
402
|
+
[K in any]?: any;
|
|
403
|
+
}, any, any, any> | IResourceMiddlewareConfigured<any, any, any, any>;
|
|
404
|
+
|
|
405
|
+
type ErrorReference = string | IErrorHelper<any>;
|
|
406
|
+
type ThrowsList = ReadonlyArray<ErrorReference>;
|
|
407
|
+
interface IErrorDefinition<TData extends DefaultErrorType = DefaultErrorType> {
|
|
408
|
+
id: string;
|
|
409
|
+
serialize?: (data: TData) => string;
|
|
410
|
+
parse?: (data: string) => TData;
|
|
411
|
+
format?: (data: TData) => string;
|
|
412
|
+
/**
|
|
413
|
+
* Validate error data on throw(). If provided, data is parsed first.
|
|
414
|
+
*/
|
|
415
|
+
dataSchema?: IValidationSchema<TData>;
|
|
416
|
+
meta?: IErrorMeta;
|
|
417
|
+
}
|
|
418
|
+
interface IErrorDefinitionFinal<TData extends DefaultErrorType> extends IErrorDefinition<TData> {
|
|
419
|
+
format: (data: TData) => string;
|
|
420
|
+
}
|
|
421
|
+
type DefaultErrorType = Record<string, unknown>;
|
|
422
|
+
/**
|
|
423
|
+
* Runtime helper returned by defineError()/r.error().
|
|
424
|
+
* Contains helpers to throw typed errors and perform type-safe checks.
|
|
425
|
+
*/
|
|
426
|
+
interface IErrorHelper<TData extends DefaultErrorType = DefaultErrorType> {
|
|
427
|
+
/** Unique id for registration and DI */
|
|
428
|
+
id: string;
|
|
429
|
+
/** Throw a typed error with the given data */
|
|
430
|
+
throw(data: TData): never;
|
|
431
|
+
/** Type guard for checking if an unknown error is this error */
|
|
432
|
+
is(error: unknown): boolean;
|
|
433
|
+
/** Brand symbol for runtime detection */
|
|
434
|
+
[symbolError]: true;
|
|
435
|
+
/** Return an optional dependency wrapper for this error */
|
|
436
|
+
optional(): IOptionalDependency<IErrorHelper<TData>>;
|
|
437
|
+
}
|
|
438
|
+
|
|
165
439
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
166
440
|
type IsUnspecified<T> = [T] extends [undefined] ? true : [T] extends [void] ? true : IsAny<T> extends true ? true : false;
|
|
167
|
-
interface IResourceDefinition<TConfig = any, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = {}, TContext = any,
|
|
441
|
+
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[]> {
|
|
168
442
|
/** Stable identifier. */
|
|
169
443
|
id: string;
|
|
170
444
|
/** Static or lazy dependency map. Receives `config` when provided. */
|
|
@@ -194,6 +468,16 @@ interface IResourceDefinition<TConfig = any, TValue extends Promise<any> = Promi
|
|
|
194
468
|
*/
|
|
195
469
|
dispose?: (this: any, value: TValue extends Promise<infer U> ? U : TValue, config: TConfig, dependencies: ResourceDependencyValuesType<TDependencies>, context: TContext) => Promise<void>;
|
|
196
470
|
meta?: TMeta;
|
|
471
|
+
/**
|
|
472
|
+
* Declares which typed errors are part of this resource's contract.
|
|
473
|
+
*
|
|
474
|
+
* This is a declarative contract only:
|
|
475
|
+
* - It does not imply dependency injection
|
|
476
|
+
* - It does not enforce that only these errors can be thrown
|
|
477
|
+
*
|
|
478
|
+
* Use string ids or Error helpers.
|
|
479
|
+
*/
|
|
480
|
+
throws?: ThrowsList;
|
|
197
481
|
/**
|
|
198
482
|
* Optional validation schema for runtime config validation.
|
|
199
483
|
* When provided, resource config will be validated when .with() is called.
|
|
@@ -230,9 +514,17 @@ interface IResource<TConfig = void, TValue extends Promise<any> = Promise<any>,
|
|
|
230
514
|
middleware: TMiddleware;
|
|
231
515
|
[symbolFilePath]: string;
|
|
232
516
|
[symbolResource]: true;
|
|
517
|
+
/** Normalized list of error ids declared via `throws`. */
|
|
518
|
+
throws?: readonly string[];
|
|
233
519
|
/** Return an optional dependency wrapper for this resource. */
|
|
234
520
|
optional: () => IOptionalDependency<IResource<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>>;
|
|
235
521
|
tags: TTags;
|
|
522
|
+
/**
|
|
523
|
+
* Create a new resource with a different id but the same definition.
|
|
524
|
+
* Useful for creating multiple instances of a "template" resource.
|
|
525
|
+
* The forked resource should be exported and used as a dependency.
|
|
526
|
+
*/
|
|
527
|
+
fork(newId: string): IResource<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
236
528
|
}
|
|
237
529
|
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[]> {
|
|
238
530
|
[symbolResourceWithConfig]: true;
|
|
@@ -244,6 +536,81 @@ interface IResourceWithConfig<TConfig = any, TValue extends Promise<any> = Promi
|
|
|
244
536
|
config: TConfig;
|
|
245
537
|
}
|
|
246
538
|
|
|
539
|
+
/**
|
|
540
|
+
* Typed key used to store/retrieve values from an ExecutionJournal.
|
|
541
|
+
* The `id` is used as the storage slot.
|
|
542
|
+
*/
|
|
543
|
+
declare const journalKeyBrand: unique symbol;
|
|
544
|
+
type JournalKey<T> = {
|
|
545
|
+
readonly id: string;
|
|
546
|
+
readonly [journalKeyBrand]?: (value: T) => T;
|
|
547
|
+
};
|
|
548
|
+
/**
|
|
549
|
+
* Options for setting values in the journal.
|
|
550
|
+
*/
|
|
551
|
+
interface JournalSetOptions {
|
|
552
|
+
/**
|
|
553
|
+
* If true, allows overwriting an existing value.
|
|
554
|
+
* By default, attempting to set a key that already exists will throw an error.
|
|
555
|
+
*/
|
|
556
|
+
override?: boolean;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Per-execution registry that allows middleware and tasks to share state.
|
|
560
|
+
* A new journal is created for each top-level task execution unless explicitly forwarded.
|
|
561
|
+
*/
|
|
562
|
+
interface ExecutionJournal {
|
|
563
|
+
set<T>(key: JournalKey<T>, value: T, options?: JournalSetOptions): void;
|
|
564
|
+
get<T>(key: JournalKey<T>): T | undefined;
|
|
565
|
+
has<T>(key: JournalKey<T>): boolean;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
interface ITaskMiddlewareDefinition<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> {
|
|
569
|
+
id: string;
|
|
570
|
+
/** Static or lazy dependency map. */
|
|
571
|
+
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
572
|
+
/**
|
|
573
|
+
* Optional validation schema for runtime config validation.
|
|
574
|
+
* When provided, middleware config will be validated when .with() is called.
|
|
575
|
+
*/
|
|
576
|
+
configSchema?: IValidationSchema<TConfig>;
|
|
577
|
+
/**
|
|
578
|
+
* The middleware body, called with task execution input.
|
|
579
|
+
*/
|
|
580
|
+
run: (input: ITaskMiddlewareExecutionInput<TEnforceInputContract extends void ? any : TEnforceInputContract, TEnforceOutputContract extends void ? any : TEnforceOutputContract>, dependencies: DependencyValuesType<TDependencies>, config: TConfig) => Promise<any>;
|
|
581
|
+
meta?: IMiddlewareMeta;
|
|
582
|
+
tags?: TagType[];
|
|
583
|
+
everywhere?: boolean | ((task: ITask<any, any, any, any>) => boolean);
|
|
584
|
+
}
|
|
585
|
+
interface ITaskMiddleware<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends ITaskMiddlewareDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>, IContractable<TConfig, TEnforceInputContract, TEnforceOutputContract> {
|
|
586
|
+
[symbolTaskMiddleware]: true;
|
|
587
|
+
[symbolFilePath]: string;
|
|
588
|
+
id: string;
|
|
589
|
+
dependencies: TDependencies | ((config: TConfig) => TDependencies);
|
|
590
|
+
/** Current configuration object (empty by default). */
|
|
591
|
+
config: TConfig;
|
|
592
|
+
/** Configure the middleware and return a marked, configured instance. */
|
|
593
|
+
with: (config: TConfig) => ITaskMiddlewareConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
594
|
+
tags: TagType[];
|
|
595
|
+
}
|
|
596
|
+
interface ITaskMiddlewareConfigured<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends ITaskMiddleware<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies> {
|
|
597
|
+
[symbolMiddlewareConfigured]: true;
|
|
598
|
+
config: TConfig;
|
|
599
|
+
}
|
|
600
|
+
interface ITaskMiddlewareExecutionInput<TTaskInput = any, TTaskOutput = any> {
|
|
601
|
+
/** Task hook */
|
|
602
|
+
task: {
|
|
603
|
+
definition: ITask<TTaskInput, any, any, any>;
|
|
604
|
+
input: TTaskInput;
|
|
605
|
+
};
|
|
606
|
+
next: (taskInput?: TTaskInput) => Promise<TTaskOutput>;
|
|
607
|
+
/** Per-execution registry for sharing state between middleware and task */
|
|
608
|
+
journal: ExecutionJournal;
|
|
609
|
+
}
|
|
610
|
+
type TaskMiddlewareAttachmentType = ITaskMiddleware<void, any, any, any> | ITaskMiddleware<{
|
|
611
|
+
[K in any]?: any;
|
|
612
|
+
}, any, any, any> | ITaskMiddlewareConfigured<any, any, any, any>;
|
|
613
|
+
|
|
247
614
|
interface ITaskDefinition<TInput = undefined, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> {
|
|
248
615
|
id: string;
|
|
249
616
|
/**
|
|
@@ -266,7 +633,19 @@ interface ITaskDefinition<TInput = undefined, TOutput extends Promise<any> = any
|
|
|
266
633
|
* `run` resolves, without considering middleware.
|
|
267
634
|
*/
|
|
268
635
|
resultSchema?: IValidationSchema<TOutput extends Promise<infer U> ? U : never>;
|
|
269
|
-
|
|
636
|
+
/**
|
|
637
|
+
* Declares which typed errors are part of this task's contract.
|
|
638
|
+
*
|
|
639
|
+
* This is a declarative contract only:
|
|
640
|
+
* - It does not imply dependency injection
|
|
641
|
+
* - It does not enforce that only these errors can be thrown
|
|
642
|
+
*
|
|
643
|
+
* Use string ids or Error helpers.
|
|
644
|
+
*/
|
|
645
|
+
throws?: ThrowsList;
|
|
646
|
+
run: (input: HasInputContracts<[...TTags, ...TMiddleware]> extends true ? [TInput] extends [undefined] ? InferInputOrViolationFromContracts<[...TTags, ...TMiddleware]> : EnsureInputSatisfiesContracts<[...TTags, ...TMiddleware], TInput> : TInput, dependencies: DependencyValuesType<TDependencies>, context?: {
|
|
647
|
+
journal: ExecutionJournal;
|
|
648
|
+
}) => HasOutputContracts<[...TTags, ...TMiddleware]> extends true ? EnsureOutputSatisfiesContracts<[...TTags, ...TMiddleware], TOutput> : TOutput;
|
|
270
649
|
/**
|
|
271
650
|
* Tags applied to the task that might define its behvaiour or impact the systems.
|
|
272
651
|
*/
|
|
@@ -285,6 +664,8 @@ interface ITask<TInput = any, TOutput extends Promise<any> = any, TDependencies
|
|
|
285
664
|
dependencies: TDependencies | (() => TDependencies);
|
|
286
665
|
computedDependencies?: DependencyValuesType<TDependencies>;
|
|
287
666
|
middleware: TMiddleware;
|
|
667
|
+
/** Normalized list of error ids declared via `throws`. */
|
|
668
|
+
throws?: readonly string[];
|
|
288
669
|
/** Return an optional dependency wrapper for this task. */
|
|
289
670
|
optional: () => IOptionalDependency<ITask<TInput, TOutput, TDependencies, TMeta, TTags, TMiddleware>>;
|
|
290
671
|
tags: TTags;
|
|
@@ -294,147 +675,41 @@ type IPhantomTask<TInput = any, TResolved = any, TDependencies extends Dependenc
|
|
|
294
675
|
[symbolPhantomTask]: true;
|
|
295
676
|
};
|
|
296
677
|
|
|
297
|
-
|
|
678
|
+
type EventHandlerType<T = any> = (event: IEventEmission<T>) => any | Promise<any>;
|
|
679
|
+
declare function onAnyOf<T extends readonly IEventDefinition<any>[]>(...defs: T): T;
|
|
680
|
+
/**
|
|
681
|
+
* Runtime guard that checks if an emission belongs to one of the given event defs.
|
|
682
|
+
* Narrows payload type to the intersection of the provided events' payloads.
|
|
683
|
+
*/
|
|
684
|
+
declare function isOneOf<TDefs extends readonly IEventDefinition<any>[]>(emission: IEventEmission<any>, defs: TDefs): emission is IEventEmission<CommonPayload<TDefs>>;
|
|
685
|
+
interface IEventDefinition<TPayload = void> {
|
|
298
686
|
id: string;
|
|
299
|
-
|
|
300
|
-
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
687
|
+
meta?: IEventMeta;
|
|
301
688
|
/**
|
|
302
|
-
* Optional validation schema for runtime
|
|
303
|
-
* When provided,
|
|
689
|
+
* Optional validation schema for runtime payload validation.
|
|
690
|
+
* When provided, event payload will be validated when emitted.
|
|
304
691
|
*/
|
|
305
|
-
|
|
692
|
+
payloadSchema?: IValidationSchema<TPayload>;
|
|
693
|
+
tags?: TagType[];
|
|
306
694
|
/**
|
|
307
|
-
*
|
|
695
|
+
* If true, listeners with the same priority run concurrently within a batch.
|
|
696
|
+
* Batches (grouped by order) still execute sequentially in priority order.
|
|
308
697
|
*/
|
|
309
|
-
|
|
310
|
-
meta?: IMiddlewareMeta;
|
|
311
|
-
tags?: TagType[];
|
|
312
|
-
everywhere?: boolean | ((task: ITask<any, any, any, any>) => boolean);
|
|
698
|
+
parallel?: boolean;
|
|
313
699
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
700
|
+
/**
|
|
701
|
+
* The definioten of the event.
|
|
702
|
+
* This is different from the event emission.
|
|
703
|
+
*/
|
|
704
|
+
interface IEvent<TPayload = any> extends IEventDefinition<TPayload> {
|
|
317
705
|
id: string;
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
interface ITaskMiddlewareConfigured<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends ITaskMiddleware<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies> {
|
|
326
|
-
[symbolMiddlewareConfigured]: true;
|
|
327
|
-
config: TConfig;
|
|
328
|
-
}
|
|
329
|
-
interface ITaskMiddlewareExecutionInput<TTaskInput = any, TTaskOutput = any> {
|
|
330
|
-
/** Task hook */
|
|
331
|
-
task: {
|
|
332
|
-
definition: ITask<TTaskInput, any, any, any>;
|
|
333
|
-
input: TTaskInput;
|
|
334
|
-
};
|
|
335
|
-
next: (taskInput?: TTaskInput) => Promise<TTaskOutput>;
|
|
336
|
-
}
|
|
337
|
-
type TaskMiddlewareAttachmentType = ITaskMiddleware<void, any, any, any> | ITaskMiddleware<{
|
|
338
|
-
[K in any]?: any;
|
|
339
|
-
}, any, any, any> | ITaskMiddlewareConfigured<any, any, any, any>;
|
|
340
|
-
|
|
341
|
-
interface IResourceMiddlewareDefinition<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> {
|
|
342
|
-
id: string;
|
|
343
|
-
/** Static or lazy dependency map. */
|
|
344
|
-
dependencies?: TDependencies | ((config: TConfig) => TDependencies);
|
|
345
|
-
/**
|
|
346
|
-
* Optional validation schema for runtime config validation.
|
|
347
|
-
* When provided, middleware config will be validated when .with() is called.
|
|
348
|
-
*/
|
|
349
|
-
configSchema?: IValidationSchema<TConfig>;
|
|
350
|
-
/**
|
|
351
|
-
* The middleware body, called with resource execution input.
|
|
352
|
-
*/
|
|
353
|
-
run: (input: IResourceMiddlewareExecutionInput<TEnforceInputContract extends void ? any : TEnforceInputContract, TEnforceOutputContract extends void ? any : TEnforceOutputContract>, dependencies: DependencyValuesType<TDependencies>, config: TConfig) => Promise<any>;
|
|
354
|
-
meta?: IMiddlewareMeta;
|
|
355
|
-
tags?: TagType[];
|
|
356
|
-
everywhere?: boolean | ((resource: IResource<any, any, any, any, any>) => boolean);
|
|
357
|
-
}
|
|
358
|
-
interface IResourceMiddleware<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends IResourceMiddlewareDefinition<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>, IContractable<TConfig, TEnforceInputContract, TEnforceOutputContract> {
|
|
359
|
-
[symbolResourceMiddleware]: true;
|
|
360
|
-
id: string;
|
|
361
|
-
dependencies: TDependencies | (() => TDependencies);
|
|
362
|
-
/** Current configuration object (empty by default). */
|
|
363
|
-
config: TConfig;
|
|
364
|
-
/** Configure the middleware and return a marked, configured instance. */
|
|
365
|
-
with: (config: TConfig) => IResourceMiddlewareConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
366
|
-
[symbolFilePath]: string;
|
|
367
|
-
tags: TagType[];
|
|
368
|
-
}
|
|
369
|
-
interface IResourceMiddlewareConfigured<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> extends IResourceMiddleware<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies> {
|
|
370
|
-
[symbolMiddlewareConfigured]: true;
|
|
371
|
-
}
|
|
372
|
-
interface IResourceMiddlewareExecutionInput<TResourceConfig = any, TResourceOutput = any> {
|
|
373
|
-
/** Resource hook */
|
|
374
|
-
resource: {
|
|
375
|
-
definition: IResource<TResourceConfig, any, any, any, any>;
|
|
376
|
-
config: TResourceConfig;
|
|
377
|
-
};
|
|
378
|
-
next: (resourceConfig?: TResourceConfig) => Promise<TResourceOutput>;
|
|
379
|
-
}
|
|
380
|
-
type ResourceMiddlewareAttachmentType = IResourceMiddleware<void, any, any, any> | IResourceMiddleware<{
|
|
381
|
-
[K in any]?: any;
|
|
382
|
-
}, any, any, any> | IResourceMiddlewareConfigured<any, any, any, any>;
|
|
383
|
-
|
|
384
|
-
type OnType = "*" | IEventDefinition<any> | readonly IEventDefinition<any>[];
|
|
385
|
-
interface IHookDefinition<TDependencies extends DependencyMapType = {}, TOn extends OnType = any, TMeta extends ITaskMeta = any> {
|
|
386
|
-
id: string;
|
|
387
|
-
dependencies?: TDependencies | (() => TDependencies);
|
|
388
|
-
on: TOn;
|
|
389
|
-
/** Listener execution order. Lower numbers run first. */
|
|
390
|
-
order?: number;
|
|
391
|
-
meta?: TMeta;
|
|
392
|
-
run: (event: IEventEmission<TOn extends "*" ? any : TOn extends readonly IEventDefinition<any>[] ? CommonPayload<TOn> : ExtractEventPayload<TOn>>, dependencies: DependencyValuesType<TDependencies>) => Promise<any>;
|
|
393
|
-
tags?: TagType[];
|
|
394
|
-
}
|
|
395
|
-
interface IHook<TDependencies extends DependencyMapType = {}, TOn extends OnType = any, TMeta extends ITaskMeta = any> extends IHookDefinition<TDependencies, TOn, TMeta> {
|
|
396
|
-
id: string;
|
|
397
|
-
dependencies: TDependencies | (() => TDependencies);
|
|
398
|
-
[symbolFilePath]: string;
|
|
399
|
-
[symbolHook]: true;
|
|
400
|
-
tags: TagType[];
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
type EventHandlerType<T = any> = (event: IEventEmission<T>) => any | Promise<any>;
|
|
404
|
-
declare function onAnyOf<T extends readonly IEventDefinition<any>[]>(...defs: T): T;
|
|
405
|
-
/**
|
|
406
|
-
* Runtime guard that checks if an emission belongs to one of the given event defs.
|
|
407
|
-
* Narrows payload type to the intersection of the provided events' payloads.
|
|
408
|
-
*/
|
|
409
|
-
declare function isOneOf<TDefs extends readonly IEventDefinition<any>[]>(emission: IEventEmission<any>, defs: TDefs): emission is IEventEmission<CommonPayload<TDefs>>;
|
|
410
|
-
interface IEventDefinition<TPayload = void> {
|
|
411
|
-
id: string;
|
|
412
|
-
meta?: IEventMeta;
|
|
413
|
-
/**
|
|
414
|
-
* Optional validation schema for runtime payload validation.
|
|
415
|
-
* When provided, event payload will be validated when emitted.
|
|
416
|
-
*/
|
|
417
|
-
payloadSchema?: IValidationSchema<TPayload>;
|
|
418
|
-
tags?: TagType[];
|
|
419
|
-
/**
|
|
420
|
-
* If true, listeners with the same priority run concurrently within a batch.
|
|
421
|
-
* Batches (grouped by order) still execute sequentially in priority order.
|
|
422
|
-
*/
|
|
423
|
-
parallel?: boolean;
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* The definioten of the event.
|
|
427
|
-
* This is different from the event emission.
|
|
428
|
-
*/
|
|
429
|
-
interface IEvent<TPayload = any> extends IEventDefinition<TPayload> {
|
|
430
|
-
id: string;
|
|
431
|
-
/**
|
|
432
|
-
* 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.
|
|
433
|
-
*/
|
|
434
|
-
[symbolEvent]: true;
|
|
435
|
-
[symbolFilePath]: string;
|
|
436
|
-
/** Return an optional dependency wrapper for this event. */
|
|
437
|
-
optional: () => IOptionalDependency<IEvent<TPayload>>;
|
|
706
|
+
/**
|
|
707
|
+
* 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.
|
|
708
|
+
*/
|
|
709
|
+
[symbolEvent]: true;
|
|
710
|
+
[symbolFilePath]: string;
|
|
711
|
+
/** Return an optional dependency wrapper for this event. */
|
|
712
|
+
optional: () => IOptionalDependency<IEvent<TPayload>>;
|
|
438
713
|
tags: TagType[];
|
|
439
714
|
}
|
|
440
715
|
/**
|
|
@@ -476,41 +751,25 @@ interface IEventEmission<TPayload = any> {
|
|
|
476
751
|
tags: TagType[];
|
|
477
752
|
}
|
|
478
753
|
|
|
479
|
-
|
|
480
|
-
interface
|
|
754
|
+
type OnType = "*" | IEventDefinition<any> | readonly IEventDefinition<any>[];
|
|
755
|
+
interface IHookDefinition<TDependencies extends DependencyMapType = {}, TOn extends OnType = any, TMeta extends ITaskMeta = any> {
|
|
481
756
|
id: string;
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
meta?: IErrorMeta;
|
|
490
|
-
}
|
|
491
|
-
interface IErrorDefinitionFinal<TData extends DefaultErrorType> extends IErrorDefinition<TData> {
|
|
492
|
-
format: (data: TData) => string;
|
|
757
|
+
dependencies?: TDependencies | (() => TDependencies);
|
|
758
|
+
on: TOn;
|
|
759
|
+
/** Listener execution order. Lower numbers run first. */
|
|
760
|
+
order?: number;
|
|
761
|
+
meta?: TMeta;
|
|
762
|
+
run: (event: IEventEmission<TOn extends "*" ? any : TOn extends readonly IEventDefinition<any>[] ? CommonPayload<TOn> : ExtractEventPayload<TOn>>, dependencies: DependencyValuesType<TDependencies>) => Promise<any>;
|
|
763
|
+
tags?: TagType[];
|
|
493
764
|
}
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* Runtime helper returned by defineError()/r.error().
|
|
497
|
-
* Contains helpers to throw typed errors and perform type-safe checks.
|
|
498
|
-
*/
|
|
499
|
-
interface IErrorHelper<TData extends DefaultErrorType = DefaultErrorType> {
|
|
500
|
-
/** Unique id for registration and DI */
|
|
765
|
+
interface IHook<TDependencies extends DependencyMapType = {}, TOn extends OnType = any, TMeta extends ITaskMeta = any> extends IHookDefinition<TDependencies, TOn, TMeta> {
|
|
501
766
|
id: string;
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
/** Brand symbol for runtime detection */
|
|
507
|
-
[symbolError]: true;
|
|
508
|
-
/** Return an optional dependency wrapper for this error */
|
|
509
|
-
optional(): IOptionalDependency<IErrorHelper<TData>>;
|
|
767
|
+
dependencies: TDependencies | (() => TDependencies);
|
|
768
|
+
[symbolFilePath]: string;
|
|
769
|
+
[symbolHook]: true;
|
|
770
|
+
tags: TagType[];
|
|
510
771
|
}
|
|
511
772
|
|
|
512
|
-
declare const ASYNC_CONTEXT_TYPES_LOADED: true;
|
|
513
|
-
|
|
514
773
|
interface IAsyncContextDefinition<T> {
|
|
515
774
|
id: string;
|
|
516
775
|
serialize?(data: T): string;
|
|
@@ -598,20 +857,31 @@ interface IOptionalDependency<T> {
|
|
|
598
857
|
/** Brand symbol for optional dependency */
|
|
599
858
|
[symbolOptionalDependency]: true;
|
|
600
859
|
}
|
|
601
|
-
type ExtractTaskInput<T> = T extends ITask<infer I, any, infer
|
|
602
|
-
type ExtractTaskOutput<T> = T extends ITask<any, infer O, infer
|
|
860
|
+
type ExtractTaskInput<T> = T extends ITask<infer I, any, infer _D> ? I : never;
|
|
861
|
+
type ExtractTaskOutput<T> = T extends ITask<any, infer O, infer _D> ? O : never;
|
|
603
862
|
type ExtractResourceConfig<T> = T extends IResource<infer C, any, any> ? C : never;
|
|
604
|
-
type ExtractResourceValue<T> = T extends IResource<any, infer V, infer
|
|
863
|
+
type ExtractResourceValue<T> = T extends IResource<any, infer V, infer _D> ? V extends Promise<infer U> ? U : V : never;
|
|
605
864
|
type ExtractEventPayload<T> = T extends IEventDefinition<infer P> ? P : T extends IEvent<infer P> ? P : never;
|
|
606
865
|
type UnionToIntersection<U> = (U extends any ? (x: U) => any : never) extends (x: infer I) => any ? I : never;
|
|
607
866
|
type CommonPayload<T extends readonly IEventDefinition<any>[] | IEventDefinition<any>> = T extends readonly IEventDefinition<any>[] ? {
|
|
608
867
|
[K in keyof ExtractEventPayload<T[number]>]: UnionToIntersection<ExtractEventPayload<T[number]> extends any ? ExtractEventPayload<T[number]>[K] : never>;
|
|
609
868
|
} : ExtractEventPayload<T>;
|
|
869
|
+
/**
|
|
870
|
+
* Options that can be passed when calling a task dependency.
|
|
871
|
+
* Allows forwarding the execution journal to nested task calls.
|
|
872
|
+
*/
|
|
873
|
+
interface TaskCallOptions {
|
|
874
|
+
/** Optional journal to forward to the nested task */
|
|
875
|
+
journal?: ExecutionJournal;
|
|
876
|
+
}
|
|
610
877
|
/**
|
|
611
878
|
* Task dependencies transform into callable functions: call with the task input
|
|
612
|
-
* and you receive the task output.
|
|
879
|
+
* and you receive the task output. Optionally accepts TaskCallOptions for journal forwarding.
|
|
613
880
|
*/
|
|
614
|
-
type TaskDependency<I, O> =
|
|
881
|
+
type TaskDependency<I, O> = I extends null | void ? {
|
|
882
|
+
(options?: TaskCallOptions): O;
|
|
883
|
+
(input?: I, options?: TaskCallOptions): O;
|
|
884
|
+
} : (input: I, options?: TaskCallOptions) => O;
|
|
615
885
|
/**
|
|
616
886
|
* Resource dependencies resolve to the resource's value directly.
|
|
617
887
|
*/
|
|
@@ -668,7 +938,7 @@ interface TaskMiddlewareFluentBuilder<C = any, In = void, Out = void, D extends
|
|
|
668
938
|
everywhere(flag: boolean | ((task: ITask<any, any, any, any>) => boolean)): TaskMiddlewareFluentBuilder<C, In, Out, D>;
|
|
669
939
|
build(): ITaskMiddleware<C, In, Out, D>;
|
|
670
940
|
}
|
|
671
|
-
|
|
941
|
+
|
|
672
942
|
interface ResourceMiddlewareFluentBuilder<C = any, In = void, Out = void, D extends DependencyMapType = {}> {
|
|
673
943
|
id: string;
|
|
674
944
|
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | ((config: C) => TNewDeps), options?: {
|
|
@@ -686,35 +956,29 @@ interface ResourceMiddlewareFluentBuilder<C = any, In = void, Out = void, D exte
|
|
|
686
956
|
everywhere(flag: boolean | ((resource: IResource<any, any, any, any, any>) => boolean)): ResourceMiddlewareFluentBuilder<C, In, Out, D>;
|
|
687
957
|
build(): IResourceMiddleware<C, In, Out, D>;
|
|
688
958
|
}
|
|
689
|
-
declare function resourceMiddlewareBuilder<C = void, In = void, Out = void, D extends DependencyMapType = {}>(id: string): ResourceMiddlewareFluentBuilder<C, In, Out, D>;
|
|
690
959
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
constructor(definition: IErrorDefinitionFinal<TData>);
|
|
700
|
-
get id(): string;
|
|
701
|
-
throw(data: TData): never;
|
|
702
|
-
is(error: unknown): error is RunnerError<TData>;
|
|
703
|
-
optional(): {
|
|
704
|
-
readonly inner: IErrorHelper<TData>;
|
|
705
|
-
readonly [symbolOptionalDependency]: true;
|
|
706
|
-
};
|
|
707
|
-
}
|
|
960
|
+
/**
|
|
961
|
+
* Entry point for creating a task middleware builder.
|
|
962
|
+
*/
|
|
963
|
+
declare function taskMiddlewareBuilder<C = void, In = void, Out = void, D extends DependencyMapType = {}>(id: string): TaskMiddlewareFluentBuilder<C, In, Out, D>;
|
|
964
|
+
/**
|
|
965
|
+
* Entry point for creating a resource middleware builder.
|
|
966
|
+
*/
|
|
967
|
+
declare function resourceMiddlewareBuilder<C = void, In = void, Out = void, D extends DependencyMapType = {}>(id: string): ResourceMiddlewareFluentBuilder<C, In, Out, D>;
|
|
708
968
|
|
|
709
969
|
interface ErrorFluentBuilder<TData extends DefaultErrorType = DefaultErrorType> {
|
|
710
970
|
id: string;
|
|
711
971
|
serialize(fn: (data: TData) => string): ErrorFluentBuilder<TData>;
|
|
712
972
|
parse(fn: (raw: string) => TData): ErrorFluentBuilder<TData>;
|
|
713
973
|
dataSchema(schema: IValidationSchema<TData>): ErrorFluentBuilder<TData>;
|
|
714
|
-
build():
|
|
974
|
+
build(): IErrorHelper<TData>;
|
|
715
975
|
format(fn: (data: TData) => string): ErrorFluentBuilder<TData>;
|
|
716
976
|
meta<TNewMeta extends IErrorMeta>(m: TNewMeta): ErrorFluentBuilder<TData>;
|
|
717
977
|
}
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* Entry point for creating an error builder.
|
|
981
|
+
*/
|
|
718
982
|
declare function errorBuilder<TData extends DefaultErrorType = DefaultErrorType>(id: string): ErrorFluentBuilder<TData>;
|
|
719
983
|
|
|
720
984
|
interface AsyncContextFluentBuilder<T = unknown> {
|
|
@@ -725,6 +989,10 @@ interface AsyncContextFluentBuilder<T = unknown> {
|
|
|
725
989
|
meta<TNewMeta extends IAsyncContextMeta>(m: TNewMeta): AsyncContextFluentBuilder<T>;
|
|
726
990
|
build(): IAsyncContext<T>;
|
|
727
991
|
}
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* Entry point for creating an async context builder.
|
|
995
|
+
*/
|
|
728
996
|
declare function asyncContextBuilder<T = unknown>(id: string): AsyncContextFluentBuilder<T>;
|
|
729
997
|
|
|
730
998
|
interface TagFluentBuilder<TConfig = void, TEnforceIn = void, TEnforceOut = void> {
|
|
@@ -734,11 +1002,19 @@ interface TagFluentBuilder<TConfig = void, TEnforceIn = void, TEnforceOut = void
|
|
|
734
1002
|
config<TNewConfig>(config: TNewConfig): TagFluentBuilder<TNewConfig, TEnforceIn, TEnforceOut>;
|
|
735
1003
|
build(): ITag<TConfig, TEnforceIn, TEnforceOut>;
|
|
736
1004
|
}
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* Entry point for creating a tag builder.
|
|
1008
|
+
*/
|
|
737
1009
|
declare function tagBuilder<TConfig = void, TEnforceIn = void, TEnforceOut = void>(id: string): TagFluentBuilder<TConfig, TEnforceIn, TEnforceOut>;
|
|
738
1010
|
|
|
739
|
-
|
|
1011
|
+
/** Valid event targets for hook's .on() method */
|
|
1012
|
+
type ValidOnTarget = "*" | IEventDefinition<any> | readonly IEventDefinition<any>[];
|
|
1013
|
+
/** Resolved TOn when valid, or `any` when undefined (build will throw at runtime) */
|
|
1014
|
+
type ResolvedOn<TOn> = TOn extends ValidOnTarget ? TOn : any;
|
|
1015
|
+
interface HookFluentBuilder<TDeps extends DependencyMapType = {}, TOn extends ValidOnTarget | undefined = undefined, TMeta extends ITaskMeta = ITaskMeta> {
|
|
740
1016
|
id: string;
|
|
741
|
-
on<TNewOn extends
|
|
1017
|
+
on<TNewOn extends ValidOnTarget>(on: TNewOn): HookFluentBuilder<TDeps, TNewOn, TMeta>;
|
|
742
1018
|
order(order: number): HookFluentBuilder<TDeps, TOn, TMeta>;
|
|
743
1019
|
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | (() => TNewDeps), options?: {
|
|
744
1020
|
override?: false;
|
|
@@ -750,10 +1026,20 @@ interface HookFluentBuilder<TDeps extends DependencyMapType = {}, TOn extends "*
|
|
|
750
1026
|
override?: boolean;
|
|
751
1027
|
}): HookFluentBuilder<TDeps, TOn, TMeta>;
|
|
752
1028
|
meta<TNewMeta extends ITaskMeta>(m: TNewMeta): HookFluentBuilder<TDeps, TOn, TNewMeta>;
|
|
753
|
-
|
|
754
|
-
|
|
1029
|
+
/** Set the hook's run handler. Required before build(). */
|
|
1030
|
+
run(fn: IHookDefinition<TDeps, ResolvedOn<TOn>, TMeta>["run"]): HookFluentBuilder<TDeps, TOn, TMeta>;
|
|
1031
|
+
/**
|
|
1032
|
+
* Build the hook definition. Requires .on() and .run() to be called first.
|
|
1033
|
+
* @throws {Error} if on or run are not set
|
|
1034
|
+
*/
|
|
1035
|
+
build(): IHook<TDeps, ResolvedOn<TOn>, TMeta>;
|
|
755
1036
|
}
|
|
756
|
-
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* Entry point for creating a hook builder.
|
|
1040
|
+
* Requires calling .on() and .run() before .build().
|
|
1041
|
+
*/
|
|
1042
|
+
declare function hookBuilder(id: string): HookFluentBuilder<{}, undefined, ITaskMeta>;
|
|
757
1043
|
|
|
758
1044
|
interface EventFluentBuilder<TPayload = void> {
|
|
759
1045
|
id: string;
|
|
@@ -772,69 +1058,98 @@ interface EventFluentBuilder<TPayload = void> {
|
|
|
772
1058
|
parallel(enabled?: boolean): EventFluentBuilder<TPayload>;
|
|
773
1059
|
build(): IEvent<TPayload>;
|
|
774
1060
|
}
|
|
775
|
-
declare function eventBuilder(id: string): EventFluentBuilder<void>;
|
|
776
1061
|
|
|
777
|
-
|
|
1062
|
+
/**
|
|
1063
|
+
* Entry point for creating an event builder.
|
|
1064
|
+
*/
|
|
1065
|
+
declare function eventBuilder<TPayload = void>(id: string): EventFluentBuilder<TPayload>;
|
|
1066
|
+
|
|
1067
|
+
type ShouldReplaceInput<T> = [T] extends [undefined] ? true : [T] extends [void] ? true : 0 extends 1 & T ? true : false;
|
|
1068
|
+
type ResolveInput<TExisting, TProposed> = ShouldReplaceInput<TExisting> extends true ? TProposed : TExisting;
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* Fluent builder interface for constructing tasks.
|
|
1072
|
+
*/
|
|
1073
|
+
interface TaskFluentBuilder<TInput = undefined, TOutput extends Promise<any> = Promise<any>, TDeps extends DependencyMapType = {}, TMeta extends ITaskMeta = ITaskMeta, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> {
|
|
778
1074
|
id: string;
|
|
779
1075
|
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | (() => TNewDeps), options?: {
|
|
780
1076
|
override?: false;
|
|
781
|
-
}):
|
|
1077
|
+
}): TaskFluentBuilder<TInput, TOutput, TDeps & TNewDeps, TMeta, TTags, TMiddleware>;
|
|
782
1078
|
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | (() => TNewDeps), options: {
|
|
783
1079
|
override: true;
|
|
784
|
-
}):
|
|
1080
|
+
}): TaskFluentBuilder<TInput, TOutput, TNewDeps, TMeta, TTags, TMiddleware>;
|
|
785
1081
|
middleware<TNewMw extends TaskMiddlewareAttachmentType[]>(mw: TNewMw, options?: {
|
|
786
1082
|
override?: boolean;
|
|
787
|
-
}):
|
|
1083
|
+
}): TaskFluentBuilder<TInput, TOutput, TDeps, TMeta, TTags, TNewMw>;
|
|
788
1084
|
tags<TNewTags extends TagType[]>(t: TNewTags, options?: {
|
|
789
1085
|
override?: false;
|
|
790
|
-
}):
|
|
1086
|
+
}): TaskFluentBuilder<TInput, TOutput, TDeps, TMeta, [
|
|
791
1087
|
...TTags,
|
|
792
1088
|
...TNewTags
|
|
793
1089
|
], TMiddleware>;
|
|
794
1090
|
tags<TNewTags extends TagType[]>(t: TNewTags, options: {
|
|
795
1091
|
override: true;
|
|
796
|
-
}):
|
|
797
|
-
inputSchema<TNewInput>(schema: IValidationSchema<TNewInput>):
|
|
798
|
-
resultSchema<
|
|
799
|
-
|
|
800
|
-
|
|
1092
|
+
}): TaskFluentBuilder<TInput, TOutput, TDeps, TMeta, TNewTags, TMiddleware>;
|
|
1093
|
+
inputSchema<TNewInput>(schema: IValidationSchema<TNewInput>): TaskFluentBuilder<TNewInput, TOutput, TDeps, TMeta, TTags, TMiddleware>;
|
|
1094
|
+
resultSchema<TResolved>(schema: IValidationSchema<TResolved>): TaskFluentBuilder<TInput, Promise<TResolved>, TDeps, TMeta, TTags, TMiddleware>;
|
|
1095
|
+
run<TNewInput = TInput, TNewOutput extends Promise<any> = TOutput>(fn: NonNullable<ITaskDefinition<ResolveInput<TInput, TNewInput>, TNewOutput, TDeps, TMeta, TTags, TMiddleware>["run"]>): TaskFluentBuilder<ResolveInput<TInput, TNewInput>, TNewOutput, TDeps, TMeta, TTags, TMiddleware>;
|
|
1096
|
+
throws(list: ThrowsList): TaskFluentBuilder<TInput, TOutput, TDeps, TMeta, TTags, TMiddleware>;
|
|
1097
|
+
meta<TNewMeta extends ITaskMeta>(m: TNewMeta): TaskFluentBuilder<TInput, TOutput, TDeps, TNewMeta, TTags, TMiddleware>;
|
|
1098
|
+
build(): ITask<TInput, TOutput, TDeps, TMeta, TTags, TMiddleware>;
|
|
801
1099
|
}
|
|
802
1100
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
1101
|
+
/**
|
|
1102
|
+
* Fluent builder interface for constructing phantom tasks.
|
|
1103
|
+
*/
|
|
1104
|
+
interface PhantomTaskFluentBuilder<TInput = undefined, TResolved = any, TDeps extends DependencyMapType = {}, TMeta extends ITaskMeta = ITaskMeta, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> {
|
|
806
1105
|
id: string;
|
|
807
1106
|
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | (() => TNewDeps), options?: {
|
|
808
1107
|
override?: false;
|
|
809
|
-
}):
|
|
1108
|
+
}): PhantomTaskFluentBuilder<TInput, TResolved, TDeps & TNewDeps, TMeta, TTags, TMiddleware>;
|
|
810
1109
|
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | (() => TNewDeps), options: {
|
|
811
1110
|
override: true;
|
|
812
|
-
}):
|
|
1111
|
+
}): PhantomTaskFluentBuilder<TInput, TResolved, TNewDeps, TMeta, TTags, TMiddleware>;
|
|
813
1112
|
middleware<TNewMw extends TaskMiddlewareAttachmentType[]>(mw: TNewMw, options?: {
|
|
814
1113
|
override?: boolean;
|
|
815
|
-
}):
|
|
1114
|
+
}): PhantomTaskFluentBuilder<TInput, TResolved, TDeps, TMeta, TTags, TNewMw>;
|
|
816
1115
|
tags<TNewTags extends TagType[]>(t: TNewTags, options?: {
|
|
817
1116
|
override?: false;
|
|
818
|
-
}):
|
|
1117
|
+
}): PhantomTaskFluentBuilder<TInput, TResolved, TDeps, TMeta, [
|
|
819
1118
|
...TTags,
|
|
820
1119
|
...TNewTags
|
|
821
1120
|
], TMiddleware>;
|
|
822
1121
|
tags<TNewTags extends TagType[]>(t: TNewTags, options: {
|
|
823
1122
|
override: true;
|
|
824
|
-
}):
|
|
825
|
-
inputSchema<TNewInput>(schema: IValidationSchema<TNewInput>):
|
|
826
|
-
resultSchema<
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
build():
|
|
1123
|
+
}): PhantomTaskFluentBuilder<TInput, TResolved, TDeps, TMeta, TNewTags, TMiddleware>;
|
|
1124
|
+
inputSchema<TNewInput>(schema: IValidationSchema<TNewInput>): PhantomTaskFluentBuilder<TNewInput, TResolved, TDeps, TMeta, TTags, TMiddleware>;
|
|
1125
|
+
resultSchema<TNewResolved>(schema: IValidationSchema<TNewResolved>): PhantomTaskFluentBuilder<TInput, TNewResolved, TDeps, TMeta, TTags, TMiddleware>;
|
|
1126
|
+
meta<TNewMeta extends ITaskMeta>(m: TNewMeta): PhantomTaskFluentBuilder<TInput, TResolved, TDeps, TNewMeta, TTags, TMiddleware>;
|
|
1127
|
+
throws(list: ThrowsList): PhantomTaskFluentBuilder<TInput, TResolved, TDeps, TMeta, TTags, TMiddleware>;
|
|
1128
|
+
build(): IPhantomTask<TInput, TResolved, TDeps, TMeta, TTags, TMiddleware>;
|
|
830
1129
|
}
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* Entry point for creating a phantom task builder.
|
|
1133
|
+
*/
|
|
1134
|
+
declare function phantomTaskBuilder<TInput = undefined, TResolved = any>(id: string): PhantomTaskFluentBuilder<TInput, TResolved, {}, ITaskMeta, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
831
1135
|
interface TaskBuilderWithPhantom {
|
|
832
1136
|
(id: string): TaskFluentBuilder<undefined, Promise<any>, {}, ITaskMeta, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
833
|
-
phantom:
|
|
1137
|
+
phantom: typeof phantomTaskBuilder;
|
|
834
1138
|
}
|
|
835
1139
|
|
|
1140
|
+
/**
|
|
1141
|
+
* Helper type to determine if config should be replaced.
|
|
1142
|
+
*/
|
|
836
1143
|
type ShouldReplaceConfig<T> = [T] extends [void] ? true : [T] extends [undefined] ? true : false;
|
|
1144
|
+
/**
|
|
1145
|
+
* Resolves the config type - uses proposed if existing is void/undefined.
|
|
1146
|
+
*/
|
|
837
1147
|
type ResolveConfig<TExisting, TProposed> = ShouldReplaceConfig<TExisting> extends true ? TProposed : TExisting;
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* Fluent builder interface for constructing resources.
|
|
1151
|
+
* Each method returns a new builder with updated type parameters.
|
|
1152
|
+
*/
|
|
838
1153
|
interface ResourceFluentBuilder<TConfig = void, TValue extends Promise<any> = Promise<any>, TDeps extends DependencyMapType = {}, TContext = any, TMeta extends IResourceMeta = IResourceMeta, TTags extends TagType[] = TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[] = ResourceMiddlewareAttachmentType[]> {
|
|
839
1154
|
id: string;
|
|
840
1155
|
dependencies<TNewDeps extends DependencyMapType>(deps: TNewDeps | ((config: TConfig) => TNewDeps), options?: {
|
|
@@ -864,27 +1179,41 @@ interface ResourceFluentBuilder<TConfig = void, TValue extends Promise<any> = Pr
|
|
|
864
1179
|
init<TNewConfig = TConfig, TNewValue extends Promise<any> = TValue>(fn: ResourceInitFn<ResolveConfig<TConfig, TNewConfig>, TNewValue, TDeps, TContext, TMeta, TTags, TMiddleware>): ResourceFluentBuilder<ResolveConfig<TConfig, TNewConfig>, TNewValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
865
1180
|
dispose(fn: NonNullable<IResourceDefinition<TConfig, TValue, TDeps, TContext, any, any, TMeta, TTags, TMiddleware>["dispose"]>): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
866
1181
|
meta<TNewMeta extends IResourceMeta>(m: TNewMeta): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TNewMeta, TTags, TMiddleware>;
|
|
1182
|
+
throws(list: ThrowsList): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
867
1183
|
overrides(o: Array<OverridableElements>, options?: {
|
|
868
1184
|
override?: boolean;
|
|
869
1185
|
}): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
870
1186
|
build(): IResource<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
871
1187
|
}
|
|
1188
|
+
|
|
1189
|
+
/**
|
|
1190
|
+
* Creates a new resource builder with the given id.
|
|
1191
|
+
* Overload allows callers to seed the config type at the entry point for convenience.
|
|
1192
|
+
*/
|
|
872
1193
|
declare function resourceBuilder<TConfig = void>(id: string): ResourceFluentBuilder<TConfig, Promise<any>, {}, any, IResourceMeta, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
873
1194
|
|
|
874
1195
|
type TunnelMiddlewareId = string | ITaskMiddleware<any, any, any, any>;
|
|
875
|
-
interface
|
|
1196
|
+
interface TunnelTaskMiddlewareSidePolicy {
|
|
876
1197
|
/**
|
|
877
|
-
*
|
|
878
|
-
*
|
|
879
|
-
* allowing all (the framework default remains "both").
|
|
1198
|
+
* Middleware ids/definitions allowed to run on this side when the task is tunneled.
|
|
1199
|
+
* If omitted, defaults to allowing none (caller-side middleware is skipped by default).
|
|
880
1200
|
*/
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
1201
|
+
middlewareAllowList?: TunnelMiddlewareId[];
|
|
1202
|
+
}
|
|
1203
|
+
type TunnelTaskMiddlewarePolicySideConfig = TunnelTaskMiddlewareSidePolicy | TunnelMiddlewareId[];
|
|
1204
|
+
interface TunnelTaskMiddlewarePolicyConfig {
|
|
1205
|
+
/**
|
|
1206
|
+
* Preferred configuration shape: explicit per-side allowlist.
|
|
1207
|
+
*/
|
|
1208
|
+
client?: TunnelTaskMiddlewarePolicySideConfig;
|
|
1209
|
+
server?: TunnelTaskMiddlewarePolicySideConfig;
|
|
1210
|
+
/**
|
|
1211
|
+
* Backwards-compatible configuration shape (previous): grouped allowlists.
|
|
886
1212
|
*/
|
|
887
|
-
|
|
1213
|
+
middlewareAllowList?: {
|
|
1214
|
+
client?: TunnelMiddlewareId[];
|
|
1215
|
+
server?: TunnelMiddlewareId[];
|
|
1216
|
+
};
|
|
888
1217
|
}
|
|
889
1218
|
|
|
890
1219
|
interface TimeoutMiddlewareConfig {
|
|
@@ -915,6 +1244,182 @@ interface RetryMiddlewareConfig {
|
|
|
915
1244
|
delayStrategy?: (attempt: number, error: Error) => number;
|
|
916
1245
|
}
|
|
917
1246
|
|
|
1247
|
+
interface FallbackMiddlewareConfig {
|
|
1248
|
+
/**
|
|
1249
|
+
* The fallback to use if the task fails.
|
|
1250
|
+
* Can be a value, a function that returns a value (or promise), or another task.
|
|
1251
|
+
*/
|
|
1252
|
+
fallback: any;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
declare const SemaphoreEvents: {
|
|
1256
|
+
readonly queued: IEvent<SemaphoreEvent>;
|
|
1257
|
+
readonly acquired: IEvent<SemaphoreEvent>;
|
|
1258
|
+
readonly released: IEvent<SemaphoreEvent>;
|
|
1259
|
+
readonly timeout: IEvent<SemaphoreEvent>;
|
|
1260
|
+
readonly aborted: IEvent<SemaphoreEvent>;
|
|
1261
|
+
readonly disposed: IEvent<SemaphoreEvent>;
|
|
1262
|
+
};
|
|
1263
|
+
type SemaphoreEventType = keyof typeof SemaphoreEvents;
|
|
1264
|
+
type SemaphoreEvent = {
|
|
1265
|
+
type: SemaphoreEventType;
|
|
1266
|
+
permits: number;
|
|
1267
|
+
waiting: number;
|
|
1268
|
+
maxPermits: number;
|
|
1269
|
+
disposed: boolean;
|
|
1270
|
+
};
|
|
1271
|
+
/**
|
|
1272
|
+
* A semaphore that limits the number of concurrent operations.
|
|
1273
|
+
* Used to prevent connection pool exhaustion by limiting concurrent
|
|
1274
|
+
* database operations to the pool size.
|
|
1275
|
+
*/
|
|
1276
|
+
declare class Semaphore {
|
|
1277
|
+
private permits;
|
|
1278
|
+
private waitingHead;
|
|
1279
|
+
private waitingTail;
|
|
1280
|
+
private waitingCount;
|
|
1281
|
+
private disposed;
|
|
1282
|
+
private readonly maxPermits;
|
|
1283
|
+
private readonly eventManager;
|
|
1284
|
+
private listenerId;
|
|
1285
|
+
private activeListeners;
|
|
1286
|
+
constructor(maxPermits: number);
|
|
1287
|
+
/**
|
|
1288
|
+
* Acquire a permit. If no permits are available, waits until one becomes available.
|
|
1289
|
+
*/
|
|
1290
|
+
acquire(options?: {
|
|
1291
|
+
timeout?: number;
|
|
1292
|
+
signal?: AbortSignal;
|
|
1293
|
+
}): Promise<void>;
|
|
1294
|
+
/**
|
|
1295
|
+
* Release a permit, allowing waiting operations to proceed.
|
|
1296
|
+
*/
|
|
1297
|
+
release(): void;
|
|
1298
|
+
private removeFromQueue;
|
|
1299
|
+
/**
|
|
1300
|
+
* Execute a function with a permit, automatically releasing it afterwards.
|
|
1301
|
+
*/
|
|
1302
|
+
withPermit<T>(fn: () => Promise<T>, options?: {
|
|
1303
|
+
timeout?: number;
|
|
1304
|
+
signal?: AbortSignal;
|
|
1305
|
+
}): Promise<T>;
|
|
1306
|
+
/**
|
|
1307
|
+
* Dispose the semaphore, rejecting all waiting operations and preventing new ones.
|
|
1308
|
+
*/
|
|
1309
|
+
dispose(): void;
|
|
1310
|
+
/**
|
|
1311
|
+
* Get current number of available permits (for debugging)
|
|
1312
|
+
*/
|
|
1313
|
+
getAvailablePermits(): number;
|
|
1314
|
+
/**
|
|
1315
|
+
* Get current number of waiting operations (for debugging)
|
|
1316
|
+
*/
|
|
1317
|
+
getWaitingCount(): number;
|
|
1318
|
+
/**
|
|
1319
|
+
* Get maximum number of permits
|
|
1320
|
+
*/
|
|
1321
|
+
getMaxPermits(): number;
|
|
1322
|
+
/**
|
|
1323
|
+
* Check if the semaphore has been disposed
|
|
1324
|
+
*/
|
|
1325
|
+
isDisposed(): boolean;
|
|
1326
|
+
/**
|
|
1327
|
+
* Get metrics about the current state of the semaphore
|
|
1328
|
+
*/
|
|
1329
|
+
getMetrics(): {
|
|
1330
|
+
availablePermits: number;
|
|
1331
|
+
waitingCount: number;
|
|
1332
|
+
maxPermits: number;
|
|
1333
|
+
utilization: number;
|
|
1334
|
+
disposed: boolean;
|
|
1335
|
+
};
|
|
1336
|
+
on(type: SemaphoreEventType, handler: (event: SemaphoreEvent) => any): () => void;
|
|
1337
|
+
once(type: SemaphoreEventType, handler: (event: SemaphoreEvent) => any): () => void;
|
|
1338
|
+
private enqueue;
|
|
1339
|
+
private dequeue;
|
|
1340
|
+
private emit;
|
|
1341
|
+
private buildEvent;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
interface ConcurrencyMiddlewareConfig {
|
|
1345
|
+
/**
|
|
1346
|
+
* Maximum number of concurrent executions.
|
|
1347
|
+
* If provided, a Semaphore will be created and shared for this config object.
|
|
1348
|
+
*/
|
|
1349
|
+
limit?: number;
|
|
1350
|
+
/**
|
|
1351
|
+
* Optional key to identify a shared semaphore.
|
|
1352
|
+
* If provided, the semaphore will be shared across all tasks using the same key.
|
|
1353
|
+
*/
|
|
1354
|
+
key?: string;
|
|
1355
|
+
/**
|
|
1356
|
+
* An existing Semaphore instance to use.
|
|
1357
|
+
*/
|
|
1358
|
+
semaphore?: Semaphore;
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
interface TemporalMiddlewareConfig {
|
|
1362
|
+
ms: number;
|
|
1363
|
+
}
|
|
1364
|
+
interface DebounceState {
|
|
1365
|
+
timeoutId?: NodeJS.Timeout;
|
|
1366
|
+
latestInput?: any;
|
|
1367
|
+
resolveList: ((value: any) => void)[];
|
|
1368
|
+
rejectList: ((error: any) => void)[];
|
|
1369
|
+
}
|
|
1370
|
+
interface ThrottleState {
|
|
1371
|
+
lastExecution: number;
|
|
1372
|
+
timeoutId?: NodeJS.Timeout;
|
|
1373
|
+
latestInput?: any;
|
|
1374
|
+
resolveList: ((value: any) => void)[];
|
|
1375
|
+
rejectList: ((error: any) => void)[];
|
|
1376
|
+
currentPromise?: Promise<any>;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* States of the Circuit Breaker
|
|
1381
|
+
*/
|
|
1382
|
+
declare enum CircuitBreakerState {
|
|
1383
|
+
CLOSED = "CLOSED",
|
|
1384
|
+
OPEN = "OPEN",
|
|
1385
|
+
HALF_OPEN = "HALF_OPEN"
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Configuration for the Circuit Breaker middleware
|
|
1389
|
+
*/
|
|
1390
|
+
interface CircuitBreakerMiddlewareConfig {
|
|
1391
|
+
/**
|
|
1392
|
+
* Number of failures before tripping the circuit
|
|
1393
|
+
* @default 5
|
|
1394
|
+
*/
|
|
1395
|
+
failureThreshold?: number;
|
|
1396
|
+
/**
|
|
1397
|
+
* Time in milliseconds before transitioning from OPEN to HALF_OPEN
|
|
1398
|
+
* @default 30000 (30 seconds)
|
|
1399
|
+
*/
|
|
1400
|
+
resetTimeout?: number;
|
|
1401
|
+
}
|
|
1402
|
+
interface CircuitBreakerStatus {
|
|
1403
|
+
state: CircuitBreakerState;
|
|
1404
|
+
failures: number;
|
|
1405
|
+
lastFailureTime: number;
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
interface RateLimitMiddlewareConfig {
|
|
1409
|
+
/**
|
|
1410
|
+
* Time window in milliseconds
|
|
1411
|
+
*/
|
|
1412
|
+
windowMs: number;
|
|
1413
|
+
/**
|
|
1414
|
+
* Maximum number of requests within the window
|
|
1415
|
+
*/
|
|
1416
|
+
max: number;
|
|
1417
|
+
}
|
|
1418
|
+
interface RateLimitState {
|
|
1419
|
+
count: number;
|
|
1420
|
+
resetTime: number;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
918
1423
|
/**
|
|
919
1424
|
* Options for configuring event listeners.
|
|
920
1425
|
*/
|
|
@@ -949,9 +1454,9 @@ declare class EventManager {
|
|
|
949
1454
|
private hookInterceptors;
|
|
950
1455
|
private readonly registry;
|
|
951
1456
|
private readonly cycleContext;
|
|
952
|
-
private readonly
|
|
1457
|
+
private readonly runtimeEventCycleDetection;
|
|
953
1458
|
constructor(options?: {
|
|
954
|
-
|
|
1459
|
+
runtimeEventCycleDetection?: boolean;
|
|
955
1460
|
});
|
|
956
1461
|
/**
|
|
957
1462
|
* Gets the current lock status of the EventManager
|
|
@@ -970,6 +1475,16 @@ declare class EventManager {
|
|
|
970
1475
|
* @param source - The source identifier of the event emitter
|
|
971
1476
|
*/
|
|
972
1477
|
emit<TInput>(eventDefinition: IEvent<TInput>, data: TInput, source: string): Promise<void>;
|
|
1478
|
+
/**
|
|
1479
|
+
* Emits an event and returns the final payload.
|
|
1480
|
+
* The payload is taken from the deepest emission object that reached either:
|
|
1481
|
+
* - the base listener executor, or
|
|
1482
|
+
* - an interceptor that short-circuited the emission.
|
|
1483
|
+
*
|
|
1484
|
+
* This enables tunnel transports to return the final payload after local and/or remote delivery.
|
|
1485
|
+
*/
|
|
1486
|
+
emitWithResult<TInput>(eventDefinition: IEvent<TInput>, data: TInput, source: string): Promise<TInput>;
|
|
1487
|
+
private emitAndReturnEmission;
|
|
973
1488
|
/**
|
|
974
1489
|
* Registers an event listener for specific event(s).
|
|
975
1490
|
* Listeners are ordered by priority and executed in ascending order.
|
|
@@ -1024,6 +1539,16 @@ declare class EventManager {
|
|
|
1024
1539
|
* Throws an error if the EventManager is locked
|
|
1025
1540
|
*/
|
|
1026
1541
|
private checkLock;
|
|
1542
|
+
/**
|
|
1543
|
+
* Clears all listeners and interceptors.
|
|
1544
|
+
* Call this to release references and free memory.
|
|
1545
|
+
*/
|
|
1546
|
+
clear(): void;
|
|
1547
|
+
/**
|
|
1548
|
+
* Disposes the EventManager, releasing all listeners and interceptors.
|
|
1549
|
+
* Alias for clear() following the IResource disposal pattern.
|
|
1550
|
+
*/
|
|
1551
|
+
dispose(): void;
|
|
1027
1552
|
/**
|
|
1028
1553
|
* Retrieves cached merged listeners for an event, or creates them if not cached.
|
|
1029
1554
|
* Kept for backward compatibility (tests spy on this).
|
|
@@ -1079,6 +1604,7 @@ declare class LogPrinter {
|
|
|
1079
1604
|
private formatContext;
|
|
1080
1605
|
private normalizeForJson;
|
|
1081
1606
|
private static NO_COLORS;
|
|
1607
|
+
private static readonly DEFAULT_WRITERS;
|
|
1082
1608
|
private static writers;
|
|
1083
1609
|
static setWriters(writers: Partial<{
|
|
1084
1610
|
log: (msg: any) => void;
|
|
@@ -1208,7 +1734,7 @@ declare class TaskRunner {
|
|
|
1208
1734
|
protected readonly store: Store;
|
|
1209
1735
|
protected readonly eventManager: EventManager;
|
|
1210
1736
|
protected readonly logger: Logger;
|
|
1211
|
-
protected readonly runnerStore: Map<string | symbol, (input: any) => Promise<any>>;
|
|
1737
|
+
protected readonly runnerStore: Map<string | symbol, (input: any, journal?: ExecutionJournal) => Promise<any>>;
|
|
1212
1738
|
constructor(store: Store, eventManager: EventManager, logger: Logger);
|
|
1213
1739
|
private readonly middlewareManager;
|
|
1214
1740
|
/**
|
|
@@ -1216,8 +1742,9 @@ declare class TaskRunner {
|
|
|
1216
1742
|
* This function can throw only if any of the event listeners or run function throws
|
|
1217
1743
|
* @param task the task to be run
|
|
1218
1744
|
* @param input the input to be passed to the task
|
|
1745
|
+
* @param options optional call options including journal for forwarding
|
|
1219
1746
|
*/
|
|
1220
|
-
run<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps>, input?: TInput): Promise<TOutput | undefined>;
|
|
1747
|
+
run<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps>, input?: TInput, options?: TaskCallOptions): Promise<TOutput | undefined>;
|
|
1221
1748
|
/**
|
|
1222
1749
|
* Creates the function with the chain of middleware.
|
|
1223
1750
|
* @param task
|
|
@@ -1225,7 +1752,7 @@ declare class TaskRunner {
|
|
|
1225
1752
|
* @param taskDependencies
|
|
1226
1753
|
* @returns
|
|
1227
1754
|
*/
|
|
1228
|
-
protected createRunnerWithMiddleware<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps>): (input: TInput) => Promise<Awaited<TOutput>>;
|
|
1755
|
+
protected createRunnerWithMiddleware<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps>): (input: TInput, parentJournal?: ExecutionJournal) => Promise<Awaited<TOutput>>;
|
|
1229
1756
|
}
|
|
1230
1757
|
|
|
1231
1758
|
type UnhandledErrorKind = "process" | "task" | "middleware" | "resourceInit" | "hook" | "run";
|
|
@@ -1300,7 +1827,7 @@ declare class MiddlewareManager {
|
|
|
1300
1827
|
* Compose a runner for a task with its local interceptors and applicable middlewares.
|
|
1301
1828
|
* Returns a function that accepts the task input and resolves to the task output.
|
|
1302
1829
|
*/
|
|
1303
|
-
composeTaskRunner<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps>): (input: TInput) => Promise<Awaited<TOutput>>;
|
|
1830
|
+
composeTaskRunner<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps>): (input: TInput, parentJournal?: ExecutionJournal) => Promise<Awaited<TOutput>>;
|
|
1304
1831
|
/**
|
|
1305
1832
|
* Run a resource init wrapped with its applicable middlewares.
|
|
1306
1833
|
*/
|
|
@@ -1331,6 +1858,7 @@ declare class Store {
|
|
|
1331
1858
|
private validator;
|
|
1332
1859
|
private taskRunner?;
|
|
1333
1860
|
private middlewareManager;
|
|
1861
|
+
private readonly initializedResourceIds;
|
|
1334
1862
|
mode: RunnerMode;
|
|
1335
1863
|
constructor(eventManager: EventManager, logger: Logger, onUnhandledError: OnUnhandledError, mode?: RunnerMode);
|
|
1336
1864
|
get tasks(): Map<string, TaskStoreElementType>;
|
|
@@ -1358,6 +1886,8 @@ declare class Store {
|
|
|
1358
1886
|
validateEventEmissionGraph(): void;
|
|
1359
1887
|
initializeStore(root: IResource<any, any, any, any, any>, config: any): void;
|
|
1360
1888
|
dispose(): Promise<void>;
|
|
1889
|
+
recordResourceInitialized(resourceId: string): void;
|
|
1890
|
+
private getResourcesInDisposeOrder;
|
|
1361
1891
|
/**
|
|
1362
1892
|
* Internal, avoid using this method directly.
|
|
1363
1893
|
*/
|
|
@@ -1393,16 +1923,14 @@ declare class ResourceInitializer {
|
|
|
1393
1923
|
* This function can throw only if any of the event listeners or run function throws
|
|
1394
1924
|
*/
|
|
1395
1925
|
initializeResource<TConfig = null, TValue extends Promise<any> = Promise<any>, TDeps extends DependencyMapType = {}, TContext = any>(resource: IResource<TConfig, TValue, TDeps>, config: TConfig, dependencies: ResourceDependencyValuesType<TDeps>): Promise<{
|
|
1396
|
-
value: TValue;
|
|
1926
|
+
value: TValue | undefined;
|
|
1397
1927
|
context: TContext;
|
|
1398
1928
|
}>;
|
|
1399
1929
|
initWithMiddleware<C, V extends Promise<any>, D extends DependencyMapType, TContext>(resource: IResource<C, V, D, TContext>, config: C, dependencies: ResourceDependencyValuesType<D>, context: TContext): Promise<V | undefined>;
|
|
1400
1930
|
}
|
|
1401
1931
|
|
|
1402
1932
|
/**
|
|
1403
|
-
*
|
|
1404
|
-
* Note that all elements must have been previously registered otherwise errors will be thrown
|
|
1405
|
-
* when trying to depend on something not in the store.
|
|
1933
|
+
* Resolves and caches computed dependencies for store items (resources, tasks, middleware, hooks).
|
|
1406
1934
|
*/
|
|
1407
1935
|
declare class DependencyProcessor {
|
|
1408
1936
|
protected readonly store: Store;
|
|
@@ -1412,21 +1940,21 @@ declare class DependencyProcessor {
|
|
|
1412
1940
|
protected readonly logger: Logger;
|
|
1413
1941
|
constructor(store: Store, eventManager: EventManager, taskRunner: TaskRunner, logger: Logger);
|
|
1414
1942
|
/**
|
|
1415
|
-
*
|
|
1943
|
+
* Computes and caches dependencies for all registered store items.
|
|
1416
1944
|
*/
|
|
1417
1945
|
computeAllDependencies(): Promise<void>;
|
|
1418
1946
|
private computeTaskDependencies;
|
|
1419
1947
|
initializeUninitializedResources(): Promise<void>;
|
|
1948
|
+
private rethrowResourceInitError;
|
|
1420
1949
|
/**
|
|
1421
|
-
*
|
|
1422
|
-
* @param resource
|
|
1950
|
+
* Computes and caches dependencies for a resource (if not already computed).
|
|
1423
1951
|
*/
|
|
1424
1952
|
protected processResourceDependencies<TD extends DependencyMapType>(resource: ResourceStoreElementType<any, any, TD>): Promise<void>;
|
|
1425
1953
|
private wrapResourceDependencies;
|
|
1426
1954
|
private makeTaskWithIntercept;
|
|
1427
1955
|
initializeRoot(): Promise<void>;
|
|
1428
1956
|
/**
|
|
1429
|
-
*
|
|
1957
|
+
* Attaches listeners for all hooks. Must run before emitting events.
|
|
1430
1958
|
*/
|
|
1431
1959
|
attachListeners(): void;
|
|
1432
1960
|
extractDependencies<T extends DependencyMapType>(map: T, source: string): Promise<DependencyValuesType<T>>;
|
|
@@ -1437,72 +1965,25 @@ declare class DependencyProcessor {
|
|
|
1437
1965
|
* @returns
|
|
1438
1966
|
*/
|
|
1439
1967
|
extractEventDependency(object: IEvent<any>, source: string): (input: any) => Promise<void>;
|
|
1440
|
-
extractTaskDependency(object: ITask<any, any, {}>): Promise<(input: unknown) => Promise<any>>;
|
|
1968
|
+
extractTaskDependency(object: ITask<any, any, {}>): Promise<(input: unknown, options?: TaskCallOptions) => Promise<any>>;
|
|
1441
1969
|
extractResourceDependency(object: IResource<any, any, any>): Promise<any>;
|
|
1442
1970
|
}
|
|
1443
1971
|
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
timeout?: number;
|
|
1460
|
-
signal?: AbortSignal;
|
|
1461
|
-
}): Promise<void>;
|
|
1462
|
-
/**
|
|
1463
|
-
* Release a permit, allowing waiting operations to proceed.
|
|
1464
|
-
*/
|
|
1465
|
-
release(): void;
|
|
1466
|
-
private removeFromQueue;
|
|
1467
|
-
/**
|
|
1468
|
-
* Execute a function with a permit, automatically releasing it afterwards.
|
|
1469
|
-
*/
|
|
1470
|
-
withPermit<T>(fn: () => Promise<T>, options?: {
|
|
1471
|
-
timeout?: number;
|
|
1472
|
-
signal?: AbortSignal;
|
|
1473
|
-
}): Promise<T>;
|
|
1474
|
-
/**
|
|
1475
|
-
* Dispose the semaphore, rejecting all waiting operations and preventing new ones.
|
|
1476
|
-
*/
|
|
1477
|
-
dispose(): void;
|
|
1478
|
-
/**
|
|
1479
|
-
* Get current number of available permits (for debugging)
|
|
1480
|
-
*/
|
|
1481
|
-
getAvailablePermits(): number;
|
|
1482
|
-
/**
|
|
1483
|
-
* Get current number of waiting operations (for debugging)
|
|
1484
|
-
*/
|
|
1485
|
-
getWaitingCount(): number;
|
|
1486
|
-
/**
|
|
1487
|
-
* Get maximum number of permits
|
|
1488
|
-
*/
|
|
1489
|
-
getMaxPermits(): number;
|
|
1490
|
-
/**
|
|
1491
|
-
* Check if the semaphore has been disposed
|
|
1492
|
-
*/
|
|
1493
|
-
isDisposed(): boolean;
|
|
1494
|
-
/**
|
|
1495
|
-
* Get metrics about the current state of the semaphore
|
|
1496
|
-
*/
|
|
1497
|
-
getMetrics(): {
|
|
1498
|
-
availablePermits: number;
|
|
1499
|
-
waitingCount: number;
|
|
1500
|
-
maxPermits: number;
|
|
1501
|
-
utilization: number;
|
|
1502
|
-
disposed: boolean;
|
|
1503
|
-
};
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1972
|
+
declare const QueueEvents: {
|
|
1973
|
+
readonly enqueue: IEvent<QueueEvent>;
|
|
1974
|
+
readonly start: IEvent<QueueEvent>;
|
|
1975
|
+
readonly finish: IEvent<QueueEvent>;
|
|
1976
|
+
readonly error: IEvent<QueueEvent>;
|
|
1977
|
+
readonly cancel: IEvent<QueueEvent>;
|
|
1978
|
+
readonly disposed: IEvent<QueueEvent>;
|
|
1979
|
+
};
|
|
1980
|
+
type QueueEventType = keyof typeof QueueEvents;
|
|
1981
|
+
type QueueEvent = {
|
|
1982
|
+
type: QueueEventType;
|
|
1983
|
+
taskId: number;
|
|
1984
|
+
disposed: boolean;
|
|
1985
|
+
error?: Error;
|
|
1986
|
+
};
|
|
1506
1987
|
/**
|
|
1507
1988
|
* Cooperative task queue.
|
|
1508
1989
|
* • Tasks run one‑after‑another (FIFO ordering).
|
|
@@ -1513,6 +1994,10 @@ declare class Queue {
|
|
|
1513
1994
|
private tail;
|
|
1514
1995
|
private disposed;
|
|
1515
1996
|
private abortController;
|
|
1997
|
+
private readonly eventManager;
|
|
1998
|
+
private nextTaskId;
|
|
1999
|
+
private listenerId;
|
|
2000
|
+
private activeListeners;
|
|
1516
2001
|
private readonly executionContext;
|
|
1517
2002
|
private readonly hasAsyncLocalStorage;
|
|
1518
2003
|
/**
|
|
@@ -1528,6 +2013,9 @@ declare class Queue {
|
|
|
1528
2013
|
dispose(options?: {
|
|
1529
2014
|
cancel?: boolean;
|
|
1530
2015
|
}): Promise<void>;
|
|
2016
|
+
on(type: QueueEventType, handler: (event: QueueEvent) => any): () => void;
|
|
2017
|
+
once(type: QueueEventType, handler: (event: QueueEvent) => any): () => void;
|
|
2018
|
+
private emit;
|
|
1531
2019
|
}
|
|
1532
2020
|
|
|
1533
2021
|
declare class RunResult<V> {
|
|
@@ -1605,8 +2093,9 @@ type AnyResource = IResource<any, any, any, any, any, any, any>;
|
|
|
1605
2093
|
type AnyTaskMiddleware = ITaskMiddleware<any, any, any, any>;
|
|
1606
2094
|
type AnyResourceMiddleware = IResourceMiddleware<any, any, any, any>;
|
|
1607
2095
|
type AnyHook = IHook<any, any, any>;
|
|
1608
|
-
type
|
|
1609
|
-
|
|
2096
|
+
type AnyOverrideable = AnyTask | AnyResource | AnyTaskMiddleware | AnyResourceMiddleware | AnyHook;
|
|
2097
|
+
type OverridePatch<TBase extends AnyOverrideable> = Readonly<TBase extends AnyHook ? Omit<Partial<TBase>, "id" | "on"> : Omit<Partial<TBase>, "id">>;
|
|
2098
|
+
declare function defineOverride<TBase extends AnyOverrideable>(base: TBase, patch: OverridePatch<TBase>): TBase;
|
|
1610
2099
|
|
|
1611
2100
|
/**
|
|
1612
2101
|
* Create a tag definition.
|
|
@@ -1661,68 +2150,83 @@ declare class PlatformAdapter implements IPlatformAdapter {
|
|
|
1661
2150
|
clearTimeout: typeof clearTimeout;
|
|
1662
2151
|
}
|
|
1663
2152
|
|
|
1664
|
-
declare const duplicateRegistrationError:
|
|
2153
|
+
declare const duplicateRegistrationError: IErrorHelper<{
|
|
1665
2154
|
type: string;
|
|
1666
2155
|
id: string;
|
|
1667
2156
|
} & DefaultErrorType>;
|
|
1668
|
-
declare const dependencyNotFoundError:
|
|
2157
|
+
declare const dependencyNotFoundError: IErrorHelper<{
|
|
1669
2158
|
key: string;
|
|
1670
2159
|
} & DefaultErrorType>;
|
|
1671
|
-
declare const unknownItemTypeError:
|
|
2160
|
+
declare const unknownItemTypeError: IErrorHelper<{
|
|
1672
2161
|
item: unknown;
|
|
1673
2162
|
} & DefaultErrorType>;
|
|
1674
|
-
declare const contextError:
|
|
2163
|
+
declare const contextError: IErrorHelper<{
|
|
1675
2164
|
details?: string;
|
|
1676
2165
|
} & DefaultErrorType>;
|
|
1677
|
-
declare const circularDependenciesError:
|
|
2166
|
+
declare const circularDependenciesError: IErrorHelper<{
|
|
1678
2167
|
cycles: string[];
|
|
1679
2168
|
} & DefaultErrorType>;
|
|
1680
|
-
declare const eventNotFoundError:
|
|
2169
|
+
declare const eventNotFoundError: IErrorHelper<{
|
|
1681
2170
|
id: string;
|
|
1682
2171
|
} & DefaultErrorType>;
|
|
1683
|
-
declare const resourceNotFoundError:
|
|
2172
|
+
declare const resourceNotFoundError: IErrorHelper<{
|
|
1684
2173
|
id: string;
|
|
1685
2174
|
} & DefaultErrorType>;
|
|
1686
|
-
declare const middlewareNotRegisteredError:
|
|
2175
|
+
declare const middlewareNotRegisteredError: IErrorHelper<{
|
|
1687
2176
|
type: "task" | "resource";
|
|
1688
2177
|
source: string;
|
|
1689
2178
|
middlewareId: string;
|
|
1690
2179
|
} & DefaultErrorType>;
|
|
1691
|
-
declare const tagNotFoundError:
|
|
2180
|
+
declare const tagNotFoundError: IErrorHelper<{
|
|
1692
2181
|
id: string;
|
|
1693
2182
|
} & DefaultErrorType>;
|
|
1694
|
-
declare const lockedError:
|
|
2183
|
+
declare const lockedError: IErrorHelper<{
|
|
1695
2184
|
what: string;
|
|
1696
2185
|
} & DefaultErrorType>;
|
|
1697
|
-
declare const storeAlreadyInitializedError:
|
|
1698
|
-
declare const validationError:
|
|
2186
|
+
declare const storeAlreadyInitializedError: IErrorHelper<DefaultErrorType>;
|
|
2187
|
+
declare const validationError: IErrorHelper<{
|
|
1699
2188
|
subject: string;
|
|
1700
2189
|
id: string;
|
|
1701
2190
|
originalError: string | Error;
|
|
1702
2191
|
} & DefaultErrorType>;
|
|
1703
|
-
declare const eventCycleError:
|
|
2192
|
+
declare const eventCycleError: IErrorHelper<{
|
|
1704
2193
|
path: Array<{
|
|
1705
2194
|
id: string;
|
|
1706
2195
|
source: string;
|
|
1707
2196
|
}>;
|
|
1708
2197
|
} & DefaultErrorType>;
|
|
1709
|
-
declare const eventEmissionCycleError:
|
|
2198
|
+
declare const eventEmissionCycleError: IErrorHelper<{
|
|
1710
2199
|
cycles: string[];
|
|
1711
2200
|
} & DefaultErrorType>;
|
|
1712
|
-
declare const platformUnsupportedFunctionError:
|
|
2201
|
+
declare const platformUnsupportedFunctionError: IErrorHelper<{
|
|
1713
2202
|
functionName: string;
|
|
1714
2203
|
} & DefaultErrorType>;
|
|
1715
|
-
declare const cancellationError:
|
|
2204
|
+
declare const cancellationError: IErrorHelper<{
|
|
1716
2205
|
reason?: string;
|
|
1717
2206
|
} & DefaultErrorType>;
|
|
1718
|
-
declare const tunnelOwnershipConflictError:
|
|
2207
|
+
declare const tunnelOwnershipConflictError: IErrorHelper<{
|
|
1719
2208
|
taskId: string;
|
|
1720
2209
|
currentOwnerId: string;
|
|
1721
2210
|
attemptedOwnerId: string;
|
|
1722
2211
|
} & DefaultErrorType>;
|
|
2212
|
+
declare const phantomTaskNotRoutedError: IErrorHelper<{
|
|
2213
|
+
taskId: string;
|
|
2214
|
+
} & DefaultErrorType>;
|
|
2215
|
+
declare const taskNotRegisteredError: IErrorHelper<{
|
|
2216
|
+
taskId: string;
|
|
2217
|
+
} & DefaultErrorType>;
|
|
2218
|
+
/** Builder types that require validation before build() */
|
|
2219
|
+
type BuilderType = "hook" | "task-middleware" | "resource-middleware";
|
|
2220
|
+
declare const builderIncompleteError: IErrorHelper<{
|
|
2221
|
+
type: BuilderType;
|
|
2222
|
+
builderId: string;
|
|
2223
|
+
missingFields: string[];
|
|
2224
|
+
} & DefaultErrorType>;
|
|
1723
2225
|
declare function isCancellationError(err: unknown): boolean;
|
|
1724
2226
|
|
|
2227
|
+
type errors_BuilderType = BuilderType;
|
|
1725
2228
|
type errors_IErrorHelper<TData extends DefaultErrorType = DefaultErrorType> = IErrorHelper<TData>;
|
|
2229
|
+
declare const errors_builderIncompleteError: typeof builderIncompleteError;
|
|
1726
2230
|
declare const errors_cancellationError: typeof cancellationError;
|
|
1727
2231
|
declare const errors_circularDependenciesError: typeof circularDependenciesError;
|
|
1728
2232
|
declare const errors_contextError: typeof contextError;
|
|
@@ -1734,15 +2238,17 @@ declare const errors_eventNotFoundError: typeof eventNotFoundError;
|
|
|
1734
2238
|
declare const errors_isCancellationError: typeof isCancellationError;
|
|
1735
2239
|
declare const errors_lockedError: typeof lockedError;
|
|
1736
2240
|
declare const errors_middlewareNotRegisteredError: typeof middlewareNotRegisteredError;
|
|
2241
|
+
declare const errors_phantomTaskNotRoutedError: typeof phantomTaskNotRoutedError;
|
|
1737
2242
|
declare const errors_platformUnsupportedFunctionError: typeof platformUnsupportedFunctionError;
|
|
1738
2243
|
declare const errors_resourceNotFoundError: typeof resourceNotFoundError;
|
|
1739
2244
|
declare const errors_storeAlreadyInitializedError: typeof storeAlreadyInitializedError;
|
|
1740
2245
|
declare const errors_tagNotFoundError: typeof tagNotFoundError;
|
|
2246
|
+
declare const errors_taskNotRegisteredError: typeof taskNotRegisteredError;
|
|
1741
2247
|
declare const errors_tunnelOwnershipConflictError: typeof tunnelOwnershipConflictError;
|
|
1742
2248
|
declare const errors_unknownItemTypeError: typeof unknownItemTypeError;
|
|
1743
2249
|
declare const errors_validationError: typeof validationError;
|
|
1744
2250
|
declare namespace errors {
|
|
1745
|
-
export { type errors_IErrorHelper as IErrorHelper, errors_cancellationError as cancellationError, errors_circularDependenciesError as circularDependenciesError, errors_contextError as contextError, errors_dependencyNotFoundError as dependencyNotFoundError, errors_duplicateRegistrationError as duplicateRegistrationError, errors_eventCycleError as eventCycleError, errors_eventEmissionCycleError as eventEmissionCycleError, errors_eventNotFoundError as eventNotFoundError, errors_isCancellationError as isCancellationError, errors_lockedError as lockedError, errors_middlewareNotRegisteredError as middlewareNotRegisteredError, errors_platformUnsupportedFunctionError as platformUnsupportedFunctionError, errors_resourceNotFoundError as resourceNotFoundError, errors_storeAlreadyInitializedError as storeAlreadyInitializedError, errors_tagNotFoundError as tagNotFoundError, errors_tunnelOwnershipConflictError as tunnelOwnershipConflictError, errors_unknownItemTypeError as unknownItemTypeError, errors_validationError as validationError };
|
|
2251
|
+
export { type errors_BuilderType as BuilderType, type errors_IErrorHelper as IErrorHelper, errors_builderIncompleteError as builderIncompleteError, errors_cancellationError as cancellationError, errors_circularDependenciesError as circularDependenciesError, errors_contextError as contextError, errors_dependencyNotFoundError as dependencyNotFoundError, errors_duplicateRegistrationError as duplicateRegistrationError, errors_eventCycleError as eventCycleError, errors_eventEmissionCycleError as eventEmissionCycleError, errors_eventNotFoundError as eventNotFoundError, errors_isCancellationError as isCancellationError, errors_lockedError as lockedError, errors_middlewareNotRegisteredError as middlewareNotRegisteredError, errors_phantomTaskNotRoutedError as phantomTaskNotRoutedError, errors_platformUnsupportedFunctionError as platformUnsupportedFunctionError, errors_resourceNotFoundError as resourceNotFoundError, errors_storeAlreadyInitializedError as storeAlreadyInitializedError, errors_tagNotFoundError as tagNotFoundError, errors_taskNotRegisteredError as taskNotRegisteredError, errors_tunnelOwnershipConflictError as tunnelOwnershipConflictError, errors_unknownItemTypeError as unknownItemTypeError, errors_validationError as validationError };
|
|
1746
2252
|
}
|
|
1747
2253
|
|
|
1748
2254
|
/**
|
|
@@ -1778,6 +2284,27 @@ declare function buildTestFacade(deps: {
|
|
|
1778
2284
|
eventManager: EventManager;
|
|
1779
2285
|
};
|
|
1780
2286
|
|
|
2287
|
+
type HookOn = "*" | IEventDefinition<any> | readonly IEventDefinition<any>[];
|
|
2288
|
+
interface HookOverrideBuilder<TDeps extends DependencyMapType, TOn extends HookOn, TMeta extends ITaskMeta> {
|
|
2289
|
+
id: string;
|
|
2290
|
+
order(order: number): HookOverrideBuilder<TDeps, TOn, TMeta>;
|
|
2291
|
+
dependencies<TNewDeps extends DependencyMapType, TIsOverride extends boolean = false>(deps: TNewDeps | (() => TNewDeps), options?: {
|
|
2292
|
+
override?: TIsOverride;
|
|
2293
|
+
}): HookOverrideBuilder<TIsOverride extends true ? TNewDeps : TDeps & TNewDeps, TOn, TMeta>;
|
|
2294
|
+
tags<TNewTags extends TagType[]>(t: TNewTags, options?: {
|
|
2295
|
+
override?: boolean;
|
|
2296
|
+
}): HookOverrideBuilder<TDeps, TOn, TMeta>;
|
|
2297
|
+
meta<TNewMeta extends ITaskMeta>(m: TNewMeta): HookOverrideBuilder<TDeps, TOn, TNewMeta>;
|
|
2298
|
+
run(fn: IHookDefinition<TDeps, TOn, TMeta>["run"]): HookOverrideBuilder<TDeps, TOn, TMeta>;
|
|
2299
|
+
build(): IHook<TDeps, TOn, TMeta>;
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2302
|
+
declare function override<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType, TMeta extends ITaskMeta, TTags extends TagType[], TMiddleware extends TaskMiddlewareAttachmentType[]>(base: ITask<TInput, TOutput, TDeps, TMeta, TTags, TMiddleware>): TaskFluentBuilder<TInput, TOutput, TDeps, TMeta, TTags, TMiddleware>;
|
|
2303
|
+
declare function override<TConfig, TValue extends Promise<any>, TDeps extends DependencyMapType, TContext, TMeta extends IResourceMeta, TTags extends TagType[], TMiddleware extends ResourceMiddlewareAttachmentType[]>(base: IResource<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>): ResourceFluentBuilder<TConfig, TValue, TDeps, TContext, TMeta, TTags, TMiddleware>;
|
|
2304
|
+
declare function override<TDeps extends DependencyMapType, TOn extends HookOn, TMeta extends ITaskMeta>(base: IHook<TDeps, TOn, TMeta>): HookOverrideBuilder<TDeps, TOn, TMeta>;
|
|
2305
|
+
declare function override<C, In, Out, D extends DependencyMapType>(base: ITaskMiddleware<C, In, Out, D>): TaskMiddlewareFluentBuilder<C, In, Out, D>;
|
|
2306
|
+
declare function override<C, In, Out, D extends DependencyMapType>(base: IResourceMiddleware<C, In, Out, D>): ResourceMiddlewareFluentBuilder<C, In, Out, D>;
|
|
2307
|
+
|
|
1781
2308
|
type DebugConfig = {
|
|
1782
2309
|
logResourceConfig: boolean;
|
|
1783
2310
|
logResourceValue: boolean;
|
|
@@ -1823,23 +2350,24 @@ interface HttpClientConfig {
|
|
|
1823
2350
|
auth?: HttpClientAuth;
|
|
1824
2351
|
timeoutMs?: number;
|
|
1825
2352
|
fetchImpl?: typeof fetch;
|
|
1826
|
-
serializer:
|
|
2353
|
+
serializer: SerializerLike;
|
|
1827
2354
|
onRequest?: (ctx: {
|
|
1828
2355
|
url: string;
|
|
1829
2356
|
headers: Record<string, string>;
|
|
1830
2357
|
}) => void | Promise<void>;
|
|
1831
|
-
contexts?: Array<IAsyncContext<
|
|
2358
|
+
contexts?: Array<IAsyncContext<unknown>>;
|
|
1832
2359
|
errorRegistry?: Map<string, IErrorHelper<any>>;
|
|
1833
2360
|
}
|
|
1834
2361
|
interface HttpClient {
|
|
1835
2362
|
task<I = unknown, O = unknown>(id: string, input?: I): Promise<O>;
|
|
1836
2363
|
event<P = unknown>(id: string, payload?: P): Promise<void>;
|
|
2364
|
+
eventWithResult?<P = unknown>(id: string, payload?: P): Promise<P>;
|
|
1837
2365
|
}
|
|
1838
2366
|
declare function createHttpClient(cfg: HttpClientConfig): HttpClient;
|
|
1839
2367
|
|
|
1840
2368
|
/**
|
|
1841
2369
|
* Factory for creating HTTP clients with automatic injection of:
|
|
1842
|
-
* - serializer
|
|
2370
|
+
* - serializer
|
|
1843
2371
|
* - error registry (from Store)
|
|
1844
2372
|
* - async contexts (from Store)
|
|
1845
2373
|
*
|
|
@@ -1856,6 +2384,40 @@ interface HttpClientFactoryConfig {
|
|
|
1856
2384
|
}
|
|
1857
2385
|
type HttpClientFactory = (config: HttpClientFactoryConfig) => HttpClient;
|
|
1858
2386
|
|
|
2387
|
+
/**
|
|
2388
|
+
* Implementation of ExecutionJournal.
|
|
2389
|
+
* Created per task execution and passed through the middleware chain.
|
|
2390
|
+
*/
|
|
2391
|
+
declare class ExecutionJournalImpl implements ExecutionJournal {
|
|
2392
|
+
private readonly store;
|
|
2393
|
+
/**
|
|
2394
|
+
* Store a value in the journal.
|
|
2395
|
+
* Throws an error if the key already exists unless { override: true } is passed.
|
|
2396
|
+
*/
|
|
2397
|
+
set<T>(key: JournalKey<T>, value: T, options?: JournalSetOptions): void;
|
|
2398
|
+
get<T>(key: JournalKey<T>): T | undefined;
|
|
2399
|
+
has<T>(key: JournalKey<T>): boolean;
|
|
2400
|
+
}
|
|
2401
|
+
/**
|
|
2402
|
+
* Creates a typed journal key for use with ExecutionJournal.
|
|
2403
|
+
*
|
|
2404
|
+
* @example
|
|
2405
|
+
* ```typescript
|
|
2406
|
+
* const abortController = journal.createKey<AbortController>("timeout.abortController");
|
|
2407
|
+
* journal.set(abortController, new AbortController());
|
|
2408
|
+
* const ctrl = journal.get(abortController); // AbortController | undefined
|
|
2409
|
+
* ```
|
|
2410
|
+
*/
|
|
2411
|
+
declare function createKey<T>(id: string): JournalKey<T>;
|
|
2412
|
+
declare const journal: {
|
|
2413
|
+
createKey: typeof createKey;
|
|
2414
|
+
/**
|
|
2415
|
+
* Creates a new empty ExecutionJournal.
|
|
2416
|
+
* Useful when you need to pass a specific journal instance to `runTask` or nested calls.
|
|
2417
|
+
*/
|
|
2418
|
+
create: () => ExecutionJournalImpl;
|
|
2419
|
+
};
|
|
2420
|
+
|
|
1859
2421
|
declare const createContext: typeof createContext$1;
|
|
1860
2422
|
|
|
1861
2423
|
declare const r: Readonly<{
|
|
@@ -1864,6 +2426,7 @@ declare const r: Readonly<{
|
|
|
1864
2426
|
event: typeof eventBuilder;
|
|
1865
2427
|
hook: typeof hookBuilder;
|
|
1866
2428
|
tag: typeof tagBuilder;
|
|
2429
|
+
override: typeof override;
|
|
1867
2430
|
asyncContext: typeof asyncContextBuilder;
|
|
1868
2431
|
error: typeof errorBuilder;
|
|
1869
2432
|
middleware: Readonly<{
|
|
@@ -1922,7 +2485,7 @@ type RunOptions = {
|
|
|
1922
2485
|
* When set, forces runtime cycle detection for event emissions. Disable if you're sure
|
|
1923
2486
|
* you don't have event deadlocks to improve event emission performance.
|
|
1924
2487
|
*/
|
|
1925
|
-
|
|
2488
|
+
runtimeEventCycleDetection?: boolean;
|
|
1926
2489
|
/**
|
|
1927
2490
|
* Specify in which mode to run "dev", "prod" or "test".
|
|
1928
2491
|
* If inside Node this is automatically detected from the NODE_ENV environment variable if not provided.
|
|
@@ -1942,6 +2505,8 @@ interface ICacheInstance {
|
|
|
1942
2505
|
set(key: string, value: any): void;
|
|
1943
2506
|
get(key: string): any;
|
|
1944
2507
|
clear(): void;
|
|
2508
|
+
/** Optional presence check to disambiguate cached undefined values */
|
|
2509
|
+
has?(key: string): boolean;
|
|
1945
2510
|
}
|
|
1946
2511
|
|
|
1947
2512
|
/**
|
|
@@ -1961,13 +2526,12 @@ interface ICacheInstance {
|
|
|
1961
2526
|
* - Safe overrides and strong typing around config and register mechanics
|
|
1962
2527
|
*/
|
|
1963
2528
|
|
|
1964
|
-
declare const defs_ASYNC_CONTEXT_TYPES_LOADED: typeof ASYNC_CONTEXT_TYPES_LOADED;
|
|
1965
2529
|
type defs_CommonPayload<T extends readonly IEventDefinition<any>[] | IEventDefinition<any>> = CommonPayload<T>;
|
|
1966
2530
|
type defs_DefaultErrorType = DefaultErrorType;
|
|
1967
2531
|
type defs_DependencyMapType = DependencyMapType;
|
|
1968
2532
|
type defs_DependencyValueType<T> = DependencyValueType<T>;
|
|
1969
2533
|
type defs_DependencyValuesType<T extends DependencyMapType> = DependencyValuesType<T>;
|
|
1970
|
-
|
|
2534
|
+
type defs_ErrorReference = ErrorReference;
|
|
1971
2535
|
type defs_EventHandlerType<T = any> = EventHandlerType<T>;
|
|
1972
2536
|
type defs_EventStoreElementType = EventStoreElementType;
|
|
1973
2537
|
type defs_ExtractEventPayload<T> = ExtractEventPayload<T>;
|
|
@@ -1995,7 +2559,7 @@ type defs_IMiddlewareMeta = IMiddlewareMeta;
|
|
|
1995
2559
|
type defs_IOptionalDependency<T> = IOptionalDependency<T>;
|
|
1996
2560
|
type defs_IPhantomTask<TInput = any, TResolved = any, TDependencies extends DependencyMapType = {}, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> = IPhantomTask<TInput, TResolved, TDependencies, TMeta, TTags, TMiddleware>;
|
|
1997
2561
|
type defs_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[]> = IResource<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
1998
|
-
type defs_IResourceDefinition<TConfig = any, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = {}, TContext = any,
|
|
2562
|
+
type defs_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[]> = IResourceDefinition<TConfig, TValue, TDependencies, TContext, _THooks, _TRegisterableItems, TMeta, TTags, TMiddleware>;
|
|
1999
2563
|
type defs_IResourceMeta = IResourceMeta;
|
|
2000
2564
|
type defs_IResourceMiddleware<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> = IResourceMiddleware<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
2001
2565
|
type defs_IResourceMiddlewareConfigured<TConfig = any, TEnforceInputContract = void, TEnforceOutputContract = void, TDependencies extends DependencyMapType = any> = IResourceMiddlewareConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract, TDependencies>;
|
|
@@ -2004,7 +2568,7 @@ type defs_IResourceMiddlewareExecutionInput<TResourceConfig = any, TResourceOutp
|
|
|
2004
2568
|
type defs_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[]> = IResourceWithConfig<TConfig, TValue, TDependencies, TContext, TMeta, TTags, TMiddleware>;
|
|
2005
2569
|
type defs_ITag<TConfig = void, TEnforceInputContract = void, TEnforceOutputContract = void> = ITag<TConfig, TEnforceInputContract, TEnforceOutputContract>;
|
|
2006
2570
|
type defs_ITagConfigured<TConfig = void, TEnforceInputContract = void, TEnforceOutputContract = void> = ITagConfigured<TConfig, TEnforceInputContract, TEnforceOutputContract>;
|
|
2007
|
-
type defs_ITagDefinition<TConfig = void,
|
|
2571
|
+
type defs_ITagDefinition<TConfig = void, _TEnforceInputContract = void, _TEnforceOutputContract = void> = ITagDefinition<TConfig, _TEnforceInputContract, _TEnforceOutputContract>;
|
|
2008
2572
|
type defs_ITagMeta = ITagMeta;
|
|
2009
2573
|
type defs_ITaggable = ITaggable;
|
|
2010
2574
|
type defs_ITask<TInput = any, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TMeta extends ITaskMeta = any, TTags extends TagType[] = TagType[], TMiddleware extends TaskMiddlewareAttachmentType[] = TaskMiddlewareAttachmentType[]> = ITask<TInput, TOutput, TDependencies, TMeta, TTags, TMiddleware>;
|
|
@@ -2028,11 +2592,13 @@ type defs_RunOptions = RunOptions;
|
|
|
2028
2592
|
type defs_RunnerMode = RunnerMode;
|
|
2029
2593
|
declare const defs_RunnerMode: typeof RunnerMode;
|
|
2030
2594
|
type defs_TagType = TagType;
|
|
2595
|
+
type defs_TaskCallOptions = TaskCallOptions;
|
|
2031
2596
|
type defs_TaskDependencyWithIntercept<TInput, TOutput> = TaskDependencyWithIntercept<TInput, TOutput>;
|
|
2032
2597
|
type defs_TaskLocalInterceptor<TInput, TOutput> = TaskLocalInterceptor<TInput, TOutput>;
|
|
2033
2598
|
type defs_TaskMiddlewareAttachmentType = TaskMiddlewareAttachmentType;
|
|
2034
2599
|
type defs_TaskMiddlewareStoreElementType<TDeps extends DependencyMapType = any> = TaskMiddlewareStoreElementType<TDeps>;
|
|
2035
2600
|
type defs_TaskStoreElementType<Input = any, Output extends Promise<any> = any, D extends DependencyMapType = any> = TaskStoreElementType<Input, Output, D>;
|
|
2601
|
+
type defs_ThrowsList = ThrowsList;
|
|
2036
2602
|
type defs_UnionToIntersection<U> = UnionToIntersection<U>;
|
|
2037
2603
|
declare const defs_isOneOf: typeof isOneOf;
|
|
2038
2604
|
declare const defs_onAnyOf: typeof onAnyOf;
|
|
@@ -2054,7 +2620,7 @@ declare const defs_symbolTask: typeof symbolTask;
|
|
|
2054
2620
|
declare const defs_symbolTaskMiddleware: typeof symbolTaskMiddleware;
|
|
2055
2621
|
declare const defs_symbolTunneledBy: typeof symbolTunneledBy;
|
|
2056
2622
|
declare namespace defs {
|
|
2057
|
-
export {
|
|
2623
|
+
export { type defs_CommonPayload as CommonPayload, type defs_DefaultErrorType as DefaultErrorType, type defs_DependencyMapType as DependencyMapType, type defs_DependencyValueType as DependencyValueType, type defs_DependencyValuesType as DependencyValuesType, type defs_ErrorReference as ErrorReference, type defs_EventHandlerType as EventHandlerType, type defs_EventStoreElementType as EventStoreElementType, type defs_ExtractEventPayload as ExtractEventPayload, type defs_ExtractResourceConfig as ExtractResourceConfig, type defs_ExtractResourceValue as ExtractResourceValue, type defs_ExtractTaskInput as ExtractTaskInput, type defs_ExtractTaskOutput as ExtractTaskOutput, type defs_HookStoreElementType as HookStoreElementType, type defs_IAsyncContext as IAsyncContext, type defs_IAsyncContextDefinition as IAsyncContextDefinition, type defs_IAsyncContextMeta as IAsyncContextMeta, type defs_ICacheInstance as ICacheInstance, type defs_IErrorDefinition as IErrorDefinition, type defs_IErrorDefinitionFinal as IErrorDefinitionFinal, type defs_IErrorHelper as IErrorHelper, type defs_IErrorMeta as IErrorMeta, type defs_IEvent as IEvent, type defs_IEventDefinition as IEventDefinition, type defs_IEventEmission as IEventEmission, type defs_IEventMeta as IEventMeta, type defs_IHook as IHook, type defs_IHookDefinition as IHookDefinition, type defs_IMeta as IMeta, type defs_IMiddlewareMeta as IMiddlewareMeta, type defs_IOptionalDependency as IOptionalDependency, type defs_IPhantomTask as IPhantomTask, type defs_IResource as IResource, type defs_IResourceDefinition as IResourceDefinition, type defs_IResourceMeta as IResourceMeta, type defs_IResourceMiddleware as IResourceMiddleware, type defs_IResourceMiddlewareConfigured as IResourceMiddlewareConfigured, type defs_IResourceMiddlewareDefinition as IResourceMiddlewareDefinition, type defs_IResourceMiddlewareExecutionInput as IResourceMiddlewareExecutionInput, type defs_IResourceWithConfig as IResourceWithConfig, type defs_ITag as ITag, type defs_ITagConfigured as ITagConfigured, type defs_ITagDefinition as ITagDefinition, type defs_ITagMeta as ITagMeta, type defs_ITaggable as ITaggable, type defs_ITask as ITask, type defs_ITaskDefinition as ITaskDefinition, type defs_ITaskMeta as ITaskMeta, type defs_ITaskMiddleware as ITaskMiddleware, type defs_ITaskMiddlewareConfigured as ITaskMiddlewareConfigured, type defs_ITaskMiddlewareDefinition as ITaskMiddlewareDefinition, type defs_ITaskMiddlewareExecutionInput as ITaskMiddlewareExecutionInput, type defs_IValidationSchema as IValidationSchema, type defs_OverridableElements as OverridableElements, type defs_RegisterableItems as RegisterableItems, type defs_RequiredKeys as RequiredKeys, type defs_ResourceDependencyValueType as ResourceDependencyValueType, type defs_ResourceDependencyValuesType as ResourceDependencyValuesType, type defs_ResourceInitFn as ResourceInitFn, type defs_ResourceMiddlewareAttachmentType as ResourceMiddlewareAttachmentType, type defs_ResourceMiddlewareStoreElementType as ResourceMiddlewareStoreElementType, type defs_ResourceStoreElementType as ResourceStoreElementType, type defs_RunOptions as RunOptions, defs_RunnerMode as RunnerMode, type defs_TagType as TagType, type defs_TaskCallOptions as TaskCallOptions, type defs_TaskDependencyWithIntercept as TaskDependencyWithIntercept, type defs_TaskLocalInterceptor as TaskLocalInterceptor, type defs_TaskMiddlewareAttachmentType as TaskMiddlewareAttachmentType, type defs_TaskMiddlewareStoreElementType as TaskMiddlewareStoreElementType, type defs_TaskStoreElementType as TaskStoreElementType, type defs_ThrowsList as ThrowsList, type defs_UnionToIntersection as UnionToIntersection, defs_isOneOf as isOneOf, defs_onAnyOf as onAnyOf, defs_symbolAsyncContext as symbolAsyncContext, defs_symbolError as symbolError, defs_symbolEvent as symbolEvent, defs_symbolFilePath as symbolFilePath, defs_symbolHook as symbolHook, defs_symbolMiddleware as symbolMiddleware, defs_symbolMiddlewareConfigured as symbolMiddlewareConfigured, defs_symbolOptionalDependency as symbolOptionalDependency, defs_symbolPhantomTask as symbolPhantomTask, defs_symbolResource as symbolResource, defs_symbolResourceMiddleware as symbolResourceMiddleware, defs_symbolResourceWithConfig as symbolResourceWithConfig, defs_symbolTag as symbolTag, defs_symbolTagConfigured as symbolTagConfigured, defs_symbolTask as symbolTask, defs_symbolTaskMiddleware as symbolTaskMiddleware, defs_symbolTunneledBy as symbolTunneledBy };
|
|
2058
2624
|
}
|
|
2059
2625
|
|
|
2060
2626
|
type TunnelMode = "client" | "server" | "both" | "none";
|
|
@@ -2082,17 +2648,23 @@ interface ExposureFetchConfig {
|
|
|
2082
2648
|
auth?: ExposureFetchAuthConfig;
|
|
2083
2649
|
timeoutMs?: number;
|
|
2084
2650
|
fetchImpl?: typeof fetch;
|
|
2085
|
-
serializer:
|
|
2651
|
+
serializer: SerializerLike;
|
|
2086
2652
|
onRequest?: (ctx: {
|
|
2087
2653
|
url: string;
|
|
2088
2654
|
headers: Record<string, string>;
|
|
2089
2655
|
}) => void | Promise<void>;
|
|
2090
|
-
contexts?: Array<IAsyncContext<
|
|
2656
|
+
contexts?: Array<IAsyncContext<unknown>>;
|
|
2091
2657
|
errorRegistry?: Map<string, IErrorHelper<any>>;
|
|
2092
2658
|
}
|
|
2093
2659
|
interface ExposureFetchClient {
|
|
2094
2660
|
task<I = unknown, O = unknown>(id: string, input?: I): Promise<O>;
|
|
2095
2661
|
event<P = unknown>(id: string, payload?: P): Promise<void>;
|
|
2662
|
+
/**
|
|
2663
|
+
* Emits an event and returns the final payload as seen by the remote Runner.
|
|
2664
|
+
* Requires server support; older servers will respond with `{ ok: true }`
|
|
2665
|
+
* without `result`, in which case clients should throw.
|
|
2666
|
+
*/
|
|
2667
|
+
eventWithResult?<P = unknown>(id: string, payload?: P): Promise<P>;
|
|
2096
2668
|
}
|
|
2097
2669
|
|
|
2098
2670
|
declare function normalizeError(input: unknown): Error;
|
|
@@ -2115,12 +2687,35 @@ interface HttpCreateClientConfig {
|
|
|
2115
2687
|
auth?: HttpClientAuthConfig;
|
|
2116
2688
|
timeoutMs?: number;
|
|
2117
2689
|
fetchImpl?: typeof fetch;
|
|
2118
|
-
serializer:
|
|
2690
|
+
serializer: SerializerLike;
|
|
2691
|
+
onRequest?: (ctx: {
|
|
2692
|
+
url: string;
|
|
2693
|
+
headers: Record<string, string>;
|
|
2694
|
+
}) => void | Promise<void>;
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2697
|
+
interface HttpSmartClientAuthConfig {
|
|
2698
|
+
header?: string;
|
|
2699
|
+
token: string;
|
|
2700
|
+
}
|
|
2701
|
+
interface HttpSmartClientConfig {
|
|
2702
|
+
baseUrl: string;
|
|
2703
|
+
auth?: HttpSmartClientAuthConfig;
|
|
2704
|
+
timeoutMs?: number;
|
|
2705
|
+
serializer: SerializerLike;
|
|
2119
2706
|
onRequest?: (ctx: {
|
|
2120
2707
|
url: string;
|
|
2121
2708
|
headers: Record<string, string>;
|
|
2122
2709
|
}) => void | Promise<void>;
|
|
2710
|
+
contexts?: Array<IAsyncContext<unknown>>;
|
|
2711
|
+
errorRegistry?: Map<string, IErrorHelper<any>>;
|
|
2712
|
+
}
|
|
2713
|
+
interface HttpSmartClient {
|
|
2714
|
+
task<I = unknown, O = unknown>(id: string, input?: I): Promise<O | Readable>;
|
|
2715
|
+
event<P = unknown>(id: string, payload?: P): Promise<void>;
|
|
2716
|
+
eventWithResult?<P = unknown>(id: string, payload?: P): Promise<P>;
|
|
2123
2717
|
}
|
|
2718
|
+
declare function createHttpSmartClient(cfg: HttpSmartClientConfig): HttpSmartClient;
|
|
2124
2719
|
|
|
2125
2720
|
interface MixedHttpClientAuthConfig {
|
|
2126
2721
|
header?: string;
|
|
@@ -2131,74 +2726,66 @@ interface MixedHttpClientConfig {
|
|
|
2131
2726
|
auth?: MixedHttpClientAuthConfig;
|
|
2132
2727
|
timeoutMs?: number;
|
|
2133
2728
|
fetchImpl?: typeof fetch;
|
|
2134
|
-
|
|
2729
|
+
/**
|
|
2730
|
+
* Forces the Smart client path even for plain JSON inputs.
|
|
2731
|
+
*
|
|
2732
|
+
* Use this when a task may return a stream even when its input is not a stream
|
|
2733
|
+
* and does not include Node File sentinels (ex: download endpoints).
|
|
2734
|
+
*
|
|
2735
|
+
* - `true`: always use Smart for tasks
|
|
2736
|
+
* - predicate: use Smart for selected task ids/inputs
|
|
2737
|
+
*/
|
|
2738
|
+
forceSmart?: boolean | ((ctx: {
|
|
2739
|
+
id: string;
|
|
2740
|
+
input: unknown;
|
|
2741
|
+
}) => boolean | Promise<boolean>);
|
|
2742
|
+
serializer: SerializerLike;
|
|
2135
2743
|
onRequest?: (ctx: {
|
|
2136
2744
|
url: string;
|
|
2137
2745
|
headers: Record<string, string>;
|
|
2138
2746
|
}) => void | Promise<void>;
|
|
2139
|
-
contexts?: Array<IAsyncContext<
|
|
2747
|
+
contexts?: Array<IAsyncContext<unknown>>;
|
|
2140
2748
|
errorRegistry?: Map<string, IErrorHelper<any>>;
|
|
2141
2749
|
}
|
|
2142
2750
|
interface MixedHttpClient {
|
|
2143
2751
|
task<I = unknown, O = unknown>(id: string, input?: I): Promise<O | Readable | ReadableStream<Uint8Array>>;
|
|
2144
2752
|
event<P = unknown>(id: string, payload?: P): Promise<void>;
|
|
2753
|
+
eventWithResult?<P = unknown>(id: string, payload?: P): Promise<P>;
|
|
2145
2754
|
}
|
|
2146
2755
|
/**
|
|
2147
|
-
* Unified Node client that mixes JSON
|
|
2756
|
+
* Unified Node client that mixes JSON fetch for standard calls and
|
|
2148
2757
|
* Smart client for streaming/multipart. Keeps transport details out of app code.
|
|
2149
2758
|
*/
|
|
2150
2759
|
declare function createHttpMixedClient(cfg: MixedHttpClientConfig): MixedHttpClient;
|
|
2151
2760
|
|
|
2152
|
-
interface
|
|
2761
|
+
interface HttpSmartClientFactoryConfig {
|
|
2153
2762
|
baseUrl: string;
|
|
2154
2763
|
auth?: {
|
|
2155
2764
|
header?: string;
|
|
2156
2765
|
token: string;
|
|
2157
2766
|
};
|
|
2158
2767
|
timeoutMs?: number;
|
|
2159
|
-
fetchImpl?: typeof fetch;
|
|
2160
2768
|
onRequest?: (ctx: {
|
|
2161
2769
|
url: string;
|
|
2162
2770
|
headers: Record<string, string>;
|
|
2163
2771
|
}) => void | Promise<void>;
|
|
2164
2772
|
}
|
|
2165
|
-
type
|
|
2773
|
+
type HttpSmartClientFactory = (config: HttpSmartClientFactoryConfig) => HttpSmartClient;
|
|
2166
2774
|
|
|
2167
|
-
interface
|
|
2168
|
-
header?: string;
|
|
2169
|
-
token: string;
|
|
2170
|
-
}
|
|
2171
|
-
interface HttpSmartClientConfig {
|
|
2775
|
+
interface HttpMixedClientFactoryConfig {
|
|
2172
2776
|
baseUrl: string;
|
|
2173
|
-
auth?:
|
|
2777
|
+
auth?: {
|
|
2778
|
+
header?: string;
|
|
2779
|
+
token: string;
|
|
2780
|
+
};
|
|
2174
2781
|
timeoutMs?: number;
|
|
2175
|
-
|
|
2782
|
+
fetchImpl?: typeof fetch;
|
|
2176
2783
|
onRequest?: (ctx: {
|
|
2177
2784
|
url: string;
|
|
2178
2785
|
headers: Record<string, string>;
|
|
2179
2786
|
}) => void | Promise<void>;
|
|
2180
|
-
contexts?: Array<IAsyncContext<any>>;
|
|
2181
|
-
errorRegistry?: Map<string, IErrorHelper<any>>;
|
|
2182
|
-
}
|
|
2183
|
-
interface HttpSmartClient {
|
|
2184
|
-
task<I = unknown, O = unknown>(id: string, input?: I): Promise<O | Readable>;
|
|
2185
|
-
event<P = unknown>(id: string, payload?: P): Promise<void>;
|
|
2186
2787
|
}
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
interface HttpSmartClientFactoryConfig {
|
|
2190
|
-
baseUrl: string;
|
|
2191
|
-
auth?: {
|
|
2192
|
-
header?: string;
|
|
2193
|
-
token: string;
|
|
2194
|
-
};
|
|
2195
|
-
timeoutMs?: number;
|
|
2196
|
-
onRequest?: (ctx: {
|
|
2197
|
-
url: string;
|
|
2198
|
-
headers: Record<string, string>;
|
|
2199
|
-
}) => void | Promise<void>;
|
|
2200
|
-
}
|
|
2201
|
-
type HttpSmartClientFactory = (config: HttpSmartClientFactoryConfig) => HttpSmartClient;
|
|
2788
|
+
type HttpMixedClientFactory = (config: HttpMixedClientFactoryConfig) => MixedHttpClient;
|
|
2202
2789
|
|
|
2203
2790
|
declare const globalResources: {
|
|
2204
2791
|
readonly store: IResource<void, Promise<Store>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
@@ -2206,15 +2793,15 @@ declare const globalResources: {
|
|
|
2206
2793
|
readonly eventManager: IResource<void, Promise<EventManager>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2207
2794
|
readonly taskRunner: IResource<void, Promise<TaskRunner>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2208
2795
|
readonly logger: IResource<void, Promise<Logger>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2209
|
-
readonly serializer: IResource<void, Promise<
|
|
2796
|
+
readonly serializer: IResource<void, Promise<SerializerLike>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2210
2797
|
readonly cache: IResource<{
|
|
2211
2798
|
defaultOptions?: any;
|
|
2212
2799
|
}, Promise<{
|
|
2213
2800
|
map: Map<string, ICacheInstance>;
|
|
2214
|
-
cacheFactoryTask: TaskDependencyWithIntercept<any, Promise<ICacheInstance>>;
|
|
2801
|
+
cacheFactoryTask: TaskDependencyWithIntercept<lru_cache.LRUCache.Options<any, any, any>, Promise<ICacheInstance>>;
|
|
2215
2802
|
defaultOptions: any;
|
|
2216
2803
|
}>, {
|
|
2217
|
-
cacheFactoryTask: ITask<any, Promise<ICacheInstance>, any, any, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
2804
|
+
cacheFactoryTask: ITask<lru_cache.LRUCache.Options<any, any, any>, Promise<ICacheInstance>, any, any, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
2218
2805
|
}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2219
2806
|
readonly queue: IResource<void, Promise<{
|
|
2220
2807
|
map: Map<string, Queue>;
|
|
@@ -2226,19 +2813,65 @@ declare const globalResources: {
|
|
|
2226
2813
|
description: string;
|
|
2227
2814
|
}, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2228
2815
|
readonly httpClientFactory: IResource<void, Promise<HttpClientFactory>, {
|
|
2229
|
-
serializer: IResource<void, Promise<
|
|
2816
|
+
serializer: IResource<void, Promise<SerializerLike>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2230
2817
|
store: IResource<void, Promise<Store>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2231
2818
|
}, any, {
|
|
2232
2819
|
title: string;
|
|
2233
2820
|
description: string;
|
|
2234
2821
|
}, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2822
|
+
readonly rateLimit: IResource<void, Promise<{
|
|
2823
|
+
states: WeakMap<RateLimitMiddlewareConfig, RateLimitState>;
|
|
2824
|
+
}>, {}, any, any, ITag<{
|
|
2825
|
+
metadata?: Record<string, any>;
|
|
2826
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
2827
|
+
readonly circuitBreaker: IResource<void, Promise<{
|
|
2828
|
+
statusMap: Map<string, CircuitBreakerStatus>;
|
|
2829
|
+
}>, {}, any, any, ITag<{
|
|
2830
|
+
metadata?: Record<string, any>;
|
|
2831
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
2832
|
+
readonly temporal: IResource<void, Promise<{
|
|
2833
|
+
debounceStates: WeakMap<TemporalMiddlewareConfig, DebounceState>;
|
|
2834
|
+
throttleStates: WeakMap<TemporalMiddlewareConfig, ThrottleState>;
|
|
2835
|
+
}>, {}, any, any, ITag<{
|
|
2836
|
+
metadata?: Record<string, any>;
|
|
2837
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
2838
|
+
readonly concurrency: IResource<void, Promise<{
|
|
2839
|
+
semaphoresByConfig: WeakMap<ConcurrencyMiddlewareConfig, Semaphore>;
|
|
2840
|
+
semaphoresByKey: Map<string, {
|
|
2841
|
+
semaphore: Semaphore;
|
|
2842
|
+
limit: number;
|
|
2843
|
+
}>;
|
|
2844
|
+
}>, {}, any, any, ITag<{
|
|
2845
|
+
metadata?: Record<string, any>;
|
|
2846
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
2235
2847
|
};
|
|
2236
2848
|
|
|
2237
2849
|
interface NodeExposureHttpAuthConfig {
|
|
2238
2850
|
header?: string;
|
|
2239
|
-
token
|
|
2851
|
+
token?: string | string[];
|
|
2852
|
+
/**
|
|
2853
|
+
* When true, allows unauthenticated access if no token or validators are configured.
|
|
2854
|
+
* Defaults to false (secure by default - requires explicit auth configuration).
|
|
2855
|
+
*
|
|
2856
|
+
* WARNING: Setting this to true without proper network isolation exposes
|
|
2857
|
+
* all tasks and events to unauthenticated access.
|
|
2858
|
+
*/
|
|
2859
|
+
allowAnonymous?: boolean;
|
|
2240
2860
|
}
|
|
2241
2861
|
|
|
2862
|
+
interface MultipartLimits {
|
|
2863
|
+
fieldNameSize?: number;
|
|
2864
|
+
fieldSize?: number;
|
|
2865
|
+
fields?: number;
|
|
2866
|
+
fileSize?: number;
|
|
2867
|
+
files?: number;
|
|
2868
|
+
parts?: number;
|
|
2869
|
+
headerPairs?: number;
|
|
2870
|
+
}
|
|
2871
|
+
|
|
2872
|
+
interface JsonLimits {
|
|
2873
|
+
maxSize?: number;
|
|
2874
|
+
}
|
|
2242
2875
|
type NodeExposureDependencyMap = {
|
|
2243
2876
|
store: typeof globalResources.store;
|
|
2244
2877
|
taskRunner: typeof globalResources.taskRunner;
|
|
@@ -2256,6 +2889,15 @@ interface NodeExposureHttpConfig {
|
|
|
2256
2889
|
};
|
|
2257
2890
|
auth?: NodeExposureHttpAuthConfig;
|
|
2258
2891
|
cors?: NodeExposureHttpCorsConfig;
|
|
2892
|
+
limits?: {
|
|
2893
|
+
json?: JsonLimits;
|
|
2894
|
+
multipart?: MultipartLimits;
|
|
2895
|
+
};
|
|
2896
|
+
/**
|
|
2897
|
+
* Opt out of fail-closed exposure (not recommended).
|
|
2898
|
+
* When true and no server-mode tunnel is registered, exposure is open.
|
|
2899
|
+
*/
|
|
2900
|
+
dangerouslyAllowOpenExposure?: boolean;
|
|
2259
2901
|
}
|
|
2260
2902
|
interface NodeExposureConfig {
|
|
2261
2903
|
http?: NodeExposureHttpConfig;
|
|
@@ -2300,7 +2942,7 @@ declare const nodeExposure: IResource<NodeExposureConfig, Promise<NodeExposureHa
|
|
|
2300
2942
|
taskRunner: IResource<void, Promise<TaskRunner>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2301
2943
|
eventManager: IResource<void, Promise<EventManager>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2302
2944
|
logger: IResource<void, Promise<Logger>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2303
|
-
serializer: IResource<void, Promise<
|
|
2945
|
+
serializer: IResource<void, Promise<SerializerLike>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2304
2946
|
}, any, {
|
|
2305
2947
|
title: string;
|
|
2306
2948
|
description: string;
|
|
@@ -2351,8 +2993,8 @@ interface InputFile<TStream = unknown> extends InputFileMeta {
|
|
|
2351
2993
|
}>;
|
|
2352
2994
|
}
|
|
2353
2995
|
/** Client-side sentinel to declare file presence in an input structure. */
|
|
2354
|
-
interface
|
|
2355
|
-
$
|
|
2996
|
+
interface RunnerFileSentinel {
|
|
2997
|
+
$runnerFile: "File";
|
|
2356
2998
|
id: string;
|
|
2357
2999
|
meta: InputFileMeta;
|
|
2358
3000
|
}
|
|
@@ -2361,7 +3003,7 @@ interface NodeFileSource {
|
|
|
2361
3003
|
stream?: Readable;
|
|
2362
3004
|
buffer?: Buffer;
|
|
2363
3005
|
}
|
|
2364
|
-
declare function createNodeFile(meta: InputFileMeta, source: NodeFileSource, id?: string):
|
|
3006
|
+
declare function createNodeFile(meta: InputFileMeta, source: NodeFileSource, id?: string): RunnerFileSentinel & {
|
|
2365
3007
|
_node: NodeFileSource;
|
|
2366
3008
|
};
|
|
2367
3009
|
|
|
@@ -2378,6 +3020,1386 @@ declare function writeInputFileToPath(file: InputFile<Readable>, targetPath: str
|
|
|
2378
3020
|
bytesWritten: number;
|
|
2379
3021
|
}>;
|
|
2380
3022
|
|
|
3023
|
+
declare const ExecutionStatus: {
|
|
3024
|
+
readonly Pending: "pending";
|
|
3025
|
+
readonly Running: "running";
|
|
3026
|
+
readonly Retrying: "retrying";
|
|
3027
|
+
readonly Sleeping: "sleeping";
|
|
3028
|
+
readonly Completed: "completed";
|
|
3029
|
+
readonly CompensationFailed: "compensation_failed";
|
|
3030
|
+
readonly Failed: "failed";
|
|
3031
|
+
readonly Cancelled: "cancelled";
|
|
3032
|
+
};
|
|
3033
|
+
type ExecutionStatus = (typeof ExecutionStatus)[keyof typeof ExecutionStatus];
|
|
3034
|
+
interface Execution<TInput = unknown, TResult = unknown> {
|
|
3035
|
+
id: string;
|
|
3036
|
+
taskId: string;
|
|
3037
|
+
input: TInput | undefined;
|
|
3038
|
+
status: ExecutionStatus;
|
|
3039
|
+
result?: TResult;
|
|
3040
|
+
error?: {
|
|
3041
|
+
message: string;
|
|
3042
|
+
stack?: string;
|
|
3043
|
+
};
|
|
3044
|
+
/** Optional cancellation metadata (cooperative cancellation). */
|
|
3045
|
+
cancelledAt?: Date;
|
|
3046
|
+
cancelRequestedAt?: Date;
|
|
3047
|
+
attempt: number;
|
|
3048
|
+
maxAttempts: number;
|
|
3049
|
+
timeout?: number;
|
|
3050
|
+
createdAt: Date;
|
|
3051
|
+
updatedAt: Date;
|
|
3052
|
+
completedAt?: Date;
|
|
3053
|
+
}
|
|
3054
|
+
interface StepResult<T = unknown> {
|
|
3055
|
+
executionId: string;
|
|
3056
|
+
stepId: string;
|
|
3057
|
+
result: T;
|
|
3058
|
+
completedAt: Date;
|
|
3059
|
+
}
|
|
3060
|
+
declare const TimerType: {
|
|
3061
|
+
readonly Sleep: "sleep";
|
|
3062
|
+
readonly Timeout: "timeout";
|
|
3063
|
+
readonly Scheduled: "scheduled";
|
|
3064
|
+
readonly Cron: "cron";
|
|
3065
|
+
readonly Retry: "retry";
|
|
3066
|
+
readonly SignalTimeout: "signal_timeout";
|
|
3067
|
+
};
|
|
3068
|
+
type TimerType = (typeof TimerType)[keyof typeof TimerType];
|
|
3069
|
+
declare const TimerStatus: {
|
|
3070
|
+
readonly Pending: "pending";
|
|
3071
|
+
readonly Fired: "fired";
|
|
3072
|
+
};
|
|
3073
|
+
type TimerStatus = (typeof TimerStatus)[keyof typeof TimerStatus];
|
|
3074
|
+
interface Timer {
|
|
3075
|
+
id: string;
|
|
3076
|
+
executionId?: string;
|
|
3077
|
+
stepId?: string;
|
|
3078
|
+
scheduleId?: string;
|
|
3079
|
+
taskId?: string;
|
|
3080
|
+
input?: unknown;
|
|
3081
|
+
type: TimerType;
|
|
3082
|
+
fireAt: Date;
|
|
3083
|
+
status: TimerStatus;
|
|
3084
|
+
}
|
|
3085
|
+
declare const ScheduleType: {
|
|
3086
|
+
readonly Cron: "cron";
|
|
3087
|
+
readonly Interval: "interval";
|
|
3088
|
+
};
|
|
3089
|
+
type ScheduleType = (typeof ScheduleType)[keyof typeof ScheduleType];
|
|
3090
|
+
declare const ScheduleStatus: {
|
|
3091
|
+
readonly Active: "active";
|
|
3092
|
+
readonly Paused: "paused";
|
|
3093
|
+
};
|
|
3094
|
+
type ScheduleStatus = (typeof ScheduleStatus)[keyof typeof ScheduleStatus];
|
|
3095
|
+
interface Schedule<TInput = unknown> {
|
|
3096
|
+
id: string;
|
|
3097
|
+
taskId: string;
|
|
3098
|
+
type: ScheduleType;
|
|
3099
|
+
pattern: string;
|
|
3100
|
+
input: TInput | undefined;
|
|
3101
|
+
status: ScheduleStatus;
|
|
3102
|
+
lastRun?: Date;
|
|
3103
|
+
nextRun?: Date;
|
|
3104
|
+
createdAt: Date;
|
|
3105
|
+
updatedAt: Date;
|
|
3106
|
+
}
|
|
3107
|
+
|
|
3108
|
+
type DurableSignalId<TPayload = unknown> = IEventDefinition<TPayload>;
|
|
3109
|
+
interface DurableStepId<TResult = unknown> {
|
|
3110
|
+
id: string;
|
|
3111
|
+
/**
|
|
3112
|
+
* Phantom field used only for type inference. Not present at runtime.
|
|
3113
|
+
* The result type is carried through the object type.
|
|
3114
|
+
*/
|
|
3115
|
+
readonly __result?: TResult;
|
|
3116
|
+
}
|
|
3117
|
+
declare function createDurableStepId<TResult>(id: string): DurableStepId<TResult>;
|
|
3118
|
+
|
|
3119
|
+
declare const DurableAuditEntryKind: {
|
|
3120
|
+
readonly ExecutionStatusChanged: "execution_status_changed";
|
|
3121
|
+
readonly StepCompleted: "step_completed";
|
|
3122
|
+
readonly SleepScheduled: "sleep_scheduled";
|
|
3123
|
+
readonly SleepCompleted: "sleep_completed";
|
|
3124
|
+
readonly SignalWaiting: "signal_waiting";
|
|
3125
|
+
readonly SignalDelivered: "signal_delivered";
|
|
3126
|
+
readonly SignalTimedOut: "signal_timed_out";
|
|
3127
|
+
readonly EmitPublished: "emit_published";
|
|
3128
|
+
readonly Note: "note";
|
|
3129
|
+
};
|
|
3130
|
+
type DurableAuditEntryKind = (typeof DurableAuditEntryKind)[keyof typeof DurableAuditEntryKind];
|
|
3131
|
+
interface DurableAuditEntryBase {
|
|
3132
|
+
id: string;
|
|
3133
|
+
executionId: string;
|
|
3134
|
+
at: Date;
|
|
3135
|
+
kind: DurableAuditEntryKind;
|
|
3136
|
+
attempt: number;
|
|
3137
|
+
taskId?: string;
|
|
3138
|
+
}
|
|
3139
|
+
type DurableAuditEntry = (DurableAuditEntryBase & {
|
|
3140
|
+
kind: typeof DurableAuditEntryKind.ExecutionStatusChanged;
|
|
3141
|
+
from: ExecutionStatus | null;
|
|
3142
|
+
to: ExecutionStatus;
|
|
3143
|
+
reason?: string;
|
|
3144
|
+
}) | (DurableAuditEntryBase & {
|
|
3145
|
+
kind: typeof DurableAuditEntryKind.StepCompleted;
|
|
3146
|
+
stepId: string;
|
|
3147
|
+
durationMs: number;
|
|
3148
|
+
isInternal: boolean;
|
|
3149
|
+
}) | (DurableAuditEntryBase & {
|
|
3150
|
+
kind: typeof DurableAuditEntryKind.SleepScheduled;
|
|
3151
|
+
stepId: string;
|
|
3152
|
+
timerId: string;
|
|
3153
|
+
durationMs: number;
|
|
3154
|
+
fireAt: Date;
|
|
3155
|
+
}) | (DurableAuditEntryBase & {
|
|
3156
|
+
kind: typeof DurableAuditEntryKind.SleepCompleted;
|
|
3157
|
+
stepId: string;
|
|
3158
|
+
timerId: string;
|
|
3159
|
+
}) | (DurableAuditEntryBase & {
|
|
3160
|
+
kind: typeof DurableAuditEntryKind.SignalWaiting;
|
|
3161
|
+
stepId: string;
|
|
3162
|
+
signalId: string;
|
|
3163
|
+
timeoutMs?: number;
|
|
3164
|
+
timeoutAtMs?: number;
|
|
3165
|
+
timerId?: string;
|
|
3166
|
+
reason?: "initial" | "timeout_armed";
|
|
3167
|
+
}) | (DurableAuditEntryBase & {
|
|
3168
|
+
kind: typeof DurableAuditEntryKind.SignalDelivered;
|
|
3169
|
+
stepId: string;
|
|
3170
|
+
signalId: string;
|
|
3171
|
+
}) | (DurableAuditEntryBase & {
|
|
3172
|
+
kind: typeof DurableAuditEntryKind.SignalTimedOut;
|
|
3173
|
+
stepId: string;
|
|
3174
|
+
signalId: string;
|
|
3175
|
+
timerId: string;
|
|
3176
|
+
}) | (DurableAuditEntryBase & {
|
|
3177
|
+
kind: typeof DurableAuditEntryKind.EmitPublished;
|
|
3178
|
+
stepId: string;
|
|
3179
|
+
eventId: string;
|
|
3180
|
+
}) | (DurableAuditEntryBase & {
|
|
3181
|
+
kind: typeof DurableAuditEntryKind.Note;
|
|
3182
|
+
message: string;
|
|
3183
|
+
meta?: Record<string, unknown>;
|
|
3184
|
+
});
|
|
3185
|
+
/**
|
|
3186
|
+
* Input type for appendAuditEntry - omits auto-generated fields (id, at).
|
|
3187
|
+
* Preserves the discriminated union for proper type checking at call sites.
|
|
3188
|
+
* executionId and attempt are required for service-level entries but filled by context.
|
|
3189
|
+
*/
|
|
3190
|
+
type DurableAuditEntryInput = {
|
|
3191
|
+
kind: typeof DurableAuditEntryKind.ExecutionStatusChanged;
|
|
3192
|
+
executionId: string;
|
|
3193
|
+
attempt: number;
|
|
3194
|
+
from: ExecutionStatus | null;
|
|
3195
|
+
to: ExecutionStatus;
|
|
3196
|
+
reason?: string;
|
|
3197
|
+
taskId?: string;
|
|
3198
|
+
} | {
|
|
3199
|
+
kind: typeof DurableAuditEntryKind.StepCompleted;
|
|
3200
|
+
stepId: string;
|
|
3201
|
+
durationMs: number;
|
|
3202
|
+
isInternal: boolean;
|
|
3203
|
+
taskId?: string;
|
|
3204
|
+
} | {
|
|
3205
|
+
kind: typeof DurableAuditEntryKind.SleepScheduled;
|
|
3206
|
+
stepId: string;
|
|
3207
|
+
timerId: string;
|
|
3208
|
+
durationMs: number;
|
|
3209
|
+
fireAt: Date;
|
|
3210
|
+
taskId?: string;
|
|
3211
|
+
} | {
|
|
3212
|
+
kind: typeof DurableAuditEntryKind.SleepCompleted;
|
|
3213
|
+
executionId: string;
|
|
3214
|
+
attempt: number;
|
|
3215
|
+
stepId: string;
|
|
3216
|
+
timerId: string;
|
|
3217
|
+
taskId?: string;
|
|
3218
|
+
} | {
|
|
3219
|
+
kind: typeof DurableAuditEntryKind.SignalWaiting;
|
|
3220
|
+
stepId: string;
|
|
3221
|
+
signalId: string;
|
|
3222
|
+
timeoutMs?: number;
|
|
3223
|
+
timeoutAtMs?: number;
|
|
3224
|
+
timerId?: string;
|
|
3225
|
+
reason?: "initial" | "timeout_armed";
|
|
3226
|
+
taskId?: string;
|
|
3227
|
+
} | {
|
|
3228
|
+
kind: typeof DurableAuditEntryKind.SignalDelivered;
|
|
3229
|
+
executionId: string;
|
|
3230
|
+
attempt: number;
|
|
3231
|
+
stepId: string;
|
|
3232
|
+
signalId: string;
|
|
3233
|
+
taskId?: string;
|
|
3234
|
+
} | {
|
|
3235
|
+
kind: typeof DurableAuditEntryKind.SignalTimedOut;
|
|
3236
|
+
executionId: string;
|
|
3237
|
+
attempt: number;
|
|
3238
|
+
stepId: string;
|
|
3239
|
+
signalId: string;
|
|
3240
|
+
timerId: string;
|
|
3241
|
+
taskId?: string;
|
|
3242
|
+
} | {
|
|
3243
|
+
kind: typeof DurableAuditEntryKind.EmitPublished;
|
|
3244
|
+
stepId: string;
|
|
3245
|
+
eventId: string;
|
|
3246
|
+
taskId?: string;
|
|
3247
|
+
} | {
|
|
3248
|
+
kind: typeof DurableAuditEntryKind.Note;
|
|
3249
|
+
message: string;
|
|
3250
|
+
meta?: Record<string, unknown>;
|
|
3251
|
+
taskId?: string;
|
|
3252
|
+
};
|
|
3253
|
+
interface DurableAuditEmitter {
|
|
3254
|
+
emit(entry: DurableAuditEntry): Promise<void>;
|
|
3255
|
+
}
|
|
3256
|
+
declare function isDurableInternalStepId(stepId: string): boolean;
|
|
3257
|
+
declare function createDurableAuditEntryId(atMs?: number): string;
|
|
3258
|
+
|
|
3259
|
+
interface ListExecutionsOptions {
|
|
3260
|
+
status?: ExecutionStatus[];
|
|
3261
|
+
taskId?: string;
|
|
3262
|
+
limit?: number;
|
|
3263
|
+
offset?: number;
|
|
3264
|
+
}
|
|
3265
|
+
interface IDurableStore {
|
|
3266
|
+
saveExecution(execution: Execution): Promise<void>;
|
|
3267
|
+
getExecution(id: string): Promise<Execution | null>;
|
|
3268
|
+
updateExecution(id: string, updates: Partial<Execution>): Promise<void>;
|
|
3269
|
+
listIncompleteExecutions(): Promise<Execution[]>;
|
|
3270
|
+
/**
|
|
3271
|
+
* Optional execution-level idempotency mapping.
|
|
3272
|
+
* If supported, allows `startExecution(..., { idempotencyKey })` to dedupe workflow starts.
|
|
3273
|
+
*/
|
|
3274
|
+
getExecutionIdByIdempotencyKey?(params: {
|
|
3275
|
+
taskId: string;
|
|
3276
|
+
idempotencyKey: string;
|
|
3277
|
+
}): Promise<string | null>;
|
|
3278
|
+
setExecutionIdByIdempotencyKey?(params: {
|
|
3279
|
+
taskId: string;
|
|
3280
|
+
idempotencyKey: string;
|
|
3281
|
+
executionId: string;
|
|
3282
|
+
}): Promise<boolean>;
|
|
3283
|
+
listExecutions?(options?: ListExecutionsOptions): Promise<Execution[]>;
|
|
3284
|
+
listStepResults?(executionId: string): Promise<StepResult[]>;
|
|
3285
|
+
appendAuditEntry?(entry: DurableAuditEntry): Promise<void>;
|
|
3286
|
+
listAuditEntries?(executionId: string, options?: {
|
|
3287
|
+
limit?: number;
|
|
3288
|
+
offset?: number;
|
|
3289
|
+
}): Promise<DurableAuditEntry[]>;
|
|
3290
|
+
retryRollback?(executionId: string): Promise<void>;
|
|
3291
|
+
skipStep?(executionId: string, stepId: string): Promise<void>;
|
|
3292
|
+
forceFail?(executionId: string, error: {
|
|
3293
|
+
message: string;
|
|
3294
|
+
stack?: string;
|
|
3295
|
+
}): Promise<void>;
|
|
3296
|
+
editStepResult?(executionId: string, stepId: string, newResult: unknown): Promise<void>;
|
|
3297
|
+
getStepResult(executionId: string, stepId: string): Promise<StepResult | null>;
|
|
3298
|
+
saveStepResult(result: StepResult): Promise<void>;
|
|
3299
|
+
createTimer(timer: Timer): Promise<void>;
|
|
3300
|
+
getReadyTimers(now?: Date): Promise<Timer[]>;
|
|
3301
|
+
markTimerFired(timerId: string): Promise<void>;
|
|
3302
|
+
/**
|
|
3303
|
+
* Atomically claim a timer for processing. Returns true if claimed, false if already claimed.
|
|
3304
|
+
* Used for distributed timer coordination to ensure only one worker processes each timer.
|
|
3305
|
+
* @param timerId The ID of the timer to claim
|
|
3306
|
+
* @param workerId A unique identifier for the worker claiming the timer
|
|
3307
|
+
* @param ttlMs Time-to-live in milliseconds for the claim (in case worker dies)
|
|
3308
|
+
*/
|
|
3309
|
+
claimTimer?(timerId: string, workerId: string, ttlMs: number): Promise<boolean>;
|
|
3310
|
+
deleteTimer(timerId: string): Promise<void>;
|
|
3311
|
+
createSchedule(schedule: Schedule): Promise<void>;
|
|
3312
|
+
getSchedule(id: string): Promise<Schedule | null>;
|
|
3313
|
+
updateSchedule(id: string, updates: Partial<Schedule>): Promise<void>;
|
|
3314
|
+
deleteSchedule(id: string): Promise<void>;
|
|
3315
|
+
listSchedules(): Promise<Schedule[]>;
|
|
3316
|
+
listActiveSchedules(): Promise<Schedule[]>;
|
|
3317
|
+
listStuckExecutions?(): Promise<Execution[]>;
|
|
3318
|
+
init?(): Promise<void>;
|
|
3319
|
+
dispose?(): Promise<void>;
|
|
3320
|
+
acquireLock?(resource: string, ttlMs: number): Promise<string | null>;
|
|
3321
|
+
releaseLock?(resource: string, lockId: string): Promise<void>;
|
|
3322
|
+
}
|
|
3323
|
+
|
|
3324
|
+
interface QueueMessage<T = unknown> {
|
|
3325
|
+
id: string;
|
|
3326
|
+
type: "execute" | "resume" | "schedule";
|
|
3327
|
+
payload: T;
|
|
3328
|
+
attempts: number;
|
|
3329
|
+
maxAttempts: number;
|
|
3330
|
+
createdAt: Date;
|
|
3331
|
+
}
|
|
3332
|
+
type MessageHandler<T = unknown> = (message: QueueMessage<T>) => Promise<void>;
|
|
3333
|
+
interface IDurableQueue {
|
|
3334
|
+
enqueue<T>(message: Omit<QueueMessage<T>, "id" | "createdAt" | "attempts">): Promise<string>;
|
|
3335
|
+
consume<T>(handler: MessageHandler<T>): Promise<void>;
|
|
3336
|
+
ack(messageId: string): Promise<void>;
|
|
3337
|
+
nack(messageId: string, requeue?: boolean): Promise<void>;
|
|
3338
|
+
init?(): Promise<void>;
|
|
3339
|
+
dispose?(): Promise<void>;
|
|
3340
|
+
}
|
|
3341
|
+
|
|
3342
|
+
interface BusEvent {
|
|
3343
|
+
type: string;
|
|
3344
|
+
payload: unknown;
|
|
3345
|
+
timestamp: Date;
|
|
3346
|
+
}
|
|
3347
|
+
type BusEventHandler = (event: BusEvent) => Promise<void>;
|
|
3348
|
+
interface IEventBus {
|
|
3349
|
+
publish(channel: string, event: BusEvent): Promise<void>;
|
|
3350
|
+
subscribe(channel: string, handler: BusEventHandler): Promise<void>;
|
|
3351
|
+
unsubscribe(channel: string): Promise<void>;
|
|
3352
|
+
init?(): Promise<void>;
|
|
3353
|
+
dispose?(): Promise<void>;
|
|
3354
|
+
}
|
|
3355
|
+
|
|
3356
|
+
interface StepOptions {
|
|
3357
|
+
retries?: number;
|
|
3358
|
+
timeout?: number;
|
|
3359
|
+
}
|
|
3360
|
+
/**
|
|
3361
|
+
* Options for sleep operations.
|
|
3362
|
+
* Use `stepId` to provide a stable identifier that survives code refactoring.
|
|
3363
|
+
*/
|
|
3364
|
+
interface SleepOptions {
|
|
3365
|
+
/** Explicit step ID for replay stability. If not provided, an auto-indexed ID is used. */
|
|
3366
|
+
stepId?: string;
|
|
3367
|
+
}
|
|
3368
|
+
/**
|
|
3369
|
+
* Options for waitForSignal operations.
|
|
3370
|
+
*/
|
|
3371
|
+
interface SignalOptions {
|
|
3372
|
+
/** Timeout in milliseconds. If provided, returns a discriminated union with kind. */
|
|
3373
|
+
timeoutMs?: number;
|
|
3374
|
+
/** Explicit step ID for replay stability. If not provided, an auto-indexed ID is used. */
|
|
3375
|
+
stepId?: string;
|
|
3376
|
+
}
|
|
3377
|
+
/**
|
|
3378
|
+
* Options for emit operations.
|
|
3379
|
+
*/
|
|
3380
|
+
interface EmitOptions {
|
|
3381
|
+
/** Explicit step ID for replay stability. If not provided, an auto-indexed ID is used. */
|
|
3382
|
+
stepId?: string;
|
|
3383
|
+
}
|
|
3384
|
+
interface IStepBuilder<T> extends PromiseLike<T> {
|
|
3385
|
+
up(fn: () => Promise<T>): this;
|
|
3386
|
+
down(fn: (result: T) => Promise<void>): this;
|
|
3387
|
+
}
|
|
3388
|
+
interface IDurableContext {
|
|
3389
|
+
readonly executionId: string;
|
|
3390
|
+
readonly attempt: number;
|
|
3391
|
+
step<T>(stepId: string): IStepBuilder<T>;
|
|
3392
|
+
step<T>(stepId: DurableStepId<T>): IStepBuilder<T>;
|
|
3393
|
+
step<T>(stepId: string, fn: () => Promise<T>): Promise<T>;
|
|
3394
|
+
step<T>(stepId: DurableStepId<T>, fn: () => Promise<T>): Promise<T>;
|
|
3395
|
+
step<T>(stepId: string, options: StepOptions, fn: () => Promise<T>): Promise<T>;
|
|
3396
|
+
step<T>(stepId: DurableStepId<T>, options: StepOptions, fn: () => Promise<T>): Promise<T>;
|
|
3397
|
+
sleep(durationMs: number, options?: SleepOptions): Promise<void>;
|
|
3398
|
+
/**
|
|
3399
|
+
* Suspend until an external signal is delivered via DurableService.signal().
|
|
3400
|
+
* The signal is memoized as a durable step under `__signal:<signalId>[:index]`.
|
|
3401
|
+
* Use options.stepId to provide a stable identifier for replay safety.
|
|
3402
|
+
*/
|
|
3403
|
+
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>): Promise<TPayload>;
|
|
3404
|
+
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>, options: SignalOptions & {
|
|
3405
|
+
timeoutMs: number;
|
|
3406
|
+
}): Promise<{
|
|
3407
|
+
kind: "signal";
|
|
3408
|
+
payload: TPayload;
|
|
3409
|
+
} | {
|
|
3410
|
+
kind: "timeout";
|
|
3411
|
+
}>;
|
|
3412
|
+
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>, options: SignalOptions): Promise<TPayload>;
|
|
3413
|
+
emit<TPayload>(event: IEventDefinition<TPayload>, payload: TPayload, options?: EmitOptions): Promise<void>;
|
|
3414
|
+
/**
|
|
3415
|
+
* Append a custom audit entry for observability and debugging.
|
|
3416
|
+
* This is a no-op if audit is disabled or the store does not support it.
|
|
3417
|
+
*/
|
|
3418
|
+
note(message: string, meta?: Record<string, unknown>): Promise<void>;
|
|
3419
|
+
rollback(): Promise<void>;
|
|
3420
|
+
}
|
|
3421
|
+
/**
|
|
3422
|
+
* Internal control-flow signal used to suspend a durable execution without failing it.
|
|
3423
|
+
*
|
|
3424
|
+
* `DurableContext` throws this error to indicate "pause here and resume later":
|
|
3425
|
+
* - `"sleep"`: durable sleep timer was scheduled
|
|
3426
|
+
* - `"yield"`: waiting for a signal (or signal-timeout timer) to complete
|
|
3427
|
+
*
|
|
3428
|
+
* `ExecutionManager` treats this as a normal suspension and will not mark the execution
|
|
3429
|
+
* as failed; instead it schedules a resume via timers/queue depending on configuration.
|
|
3430
|
+
*/
|
|
3431
|
+
declare class SuspensionSignal extends Error {
|
|
3432
|
+
readonly reason: "sleep" | "yield" | "timeout";
|
|
3433
|
+
constructor(reason: "sleep" | "yield" | "timeout");
|
|
3434
|
+
}
|
|
3435
|
+
|
|
3436
|
+
type DurableTask<TInput = unknown, TResult = unknown> = ITask<TInput, Promise<TResult>, any>;
|
|
3437
|
+
interface ITaskExecutor {
|
|
3438
|
+
run<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput): Promise<TResult>;
|
|
3439
|
+
}
|
|
3440
|
+
interface ScheduleConfig<TInput = unknown> {
|
|
3441
|
+
id: string;
|
|
3442
|
+
task: DurableTask<TInput, unknown>;
|
|
3443
|
+
cron?: string;
|
|
3444
|
+
interval?: number;
|
|
3445
|
+
input: TInput;
|
|
3446
|
+
}
|
|
3447
|
+
interface DurableServiceConfig {
|
|
3448
|
+
store: IDurableStore;
|
|
3449
|
+
queue?: IDurableQueue;
|
|
3450
|
+
eventBus?: IEventBus;
|
|
3451
|
+
taskExecutor?: ITaskExecutor;
|
|
3452
|
+
determinism?: {
|
|
3453
|
+
/**
|
|
3454
|
+
* Internal step IDs for `sleep()`/`emit()`/`waitForSignal()` default to call-order based IDs.
|
|
3455
|
+
* In production this can be a replay/versioning footgun when refactors change call order.
|
|
3456
|
+
*
|
|
3457
|
+
* - "allow" (default): do nothing
|
|
3458
|
+
* - "warn": emit a warning on first implicit internal step per kind
|
|
3459
|
+
* - "error": throw when an implicit internal step id would be used
|
|
3460
|
+
*/
|
|
3461
|
+
implicitInternalStepIds?: "allow" | "warn" | "error";
|
|
3462
|
+
};
|
|
3463
|
+
/**
|
|
3464
|
+
* Unique identifier for this worker instance.
|
|
3465
|
+
* Used for distributed timer coordination to ensure only one worker processes each timer.
|
|
3466
|
+
* If not provided, a random UUID is generated.
|
|
3467
|
+
*/
|
|
3468
|
+
workerId?: string;
|
|
3469
|
+
/**
|
|
3470
|
+
* Runs a callback with the given durable context available.
|
|
3471
|
+
* In Runner environments this is typically implemented via AsyncLocalStorage
|
|
3472
|
+
* so tasks can call `durable.use()`.
|
|
3473
|
+
*/
|
|
3474
|
+
contextProvider?: <R>(context: IDurableContext, fn: () => Promise<R> | R) => Promise<R> | R;
|
|
3475
|
+
/**
|
|
3476
|
+
* Resolves tasks by id for resuming/recovering executions.
|
|
3477
|
+
* Useful in Runner environments where tasks are registered in the Store registry.
|
|
3478
|
+
*/
|
|
3479
|
+
taskResolver?: (taskId: string) => DurableTask<any, any> | undefined;
|
|
3480
|
+
audit?: {
|
|
3481
|
+
enabled?: boolean;
|
|
3482
|
+
emitter?: DurableAuditEmitter;
|
|
3483
|
+
};
|
|
3484
|
+
polling?: {
|
|
3485
|
+
enabled?: boolean;
|
|
3486
|
+
interval?: number;
|
|
3487
|
+
/** Time-to-live for timer claims in milliseconds. Default: 30000. */
|
|
3488
|
+
claimTtlMs?: number;
|
|
3489
|
+
};
|
|
3490
|
+
execution?: {
|
|
3491
|
+
maxAttempts?: number;
|
|
3492
|
+
timeout?: number;
|
|
3493
|
+
/**
|
|
3494
|
+
* When a queue is configured, `startExecution()` persists the execution and then enqueues it.
|
|
3495
|
+
* If enqueue fails (eg. broker outage), the execution would otherwise remain "pending" forever.
|
|
3496
|
+
*
|
|
3497
|
+
* This delay arms a small store-backed timer as a failsafe so workers can retry resuming it
|
|
3498
|
+
* via the poller. Default: 10000 (10s). Set to 0 to disable.
|
|
3499
|
+
*/
|
|
3500
|
+
kickoffFailsafeDelayMs?: number;
|
|
3501
|
+
};
|
|
3502
|
+
schedules?: ScheduleConfig[];
|
|
3503
|
+
tasks?: Array<DurableTask<any, any>>;
|
|
3504
|
+
}
|
|
3505
|
+
interface ExecuteOptions {
|
|
3506
|
+
timeout?: number;
|
|
3507
|
+
priority?: number;
|
|
3508
|
+
waitPollIntervalMs?: number;
|
|
3509
|
+
/**
|
|
3510
|
+
* Optional workflow-level idempotency key.
|
|
3511
|
+
* When supported by the store, multiple concurrent callers using the same key will receive the same executionId.
|
|
3512
|
+
*/
|
|
3513
|
+
idempotencyKey?: string;
|
|
3514
|
+
}
|
|
3515
|
+
interface ScheduleOptions {
|
|
3516
|
+
id?: string;
|
|
3517
|
+
at?: Date;
|
|
3518
|
+
delay?: number;
|
|
3519
|
+
cron?: string;
|
|
3520
|
+
interval?: number;
|
|
3521
|
+
}
|
|
3522
|
+
interface IDurableService {
|
|
3523
|
+
startExecution<TInput>(task: DurableTask<TInput, unknown>, input?: TInput, options?: ExecuteOptions): Promise<string>;
|
|
3524
|
+
/**
|
|
3525
|
+
* Request cancellation for an execution.
|
|
3526
|
+
* Cancellation is cooperative: it marks the execution as cancelled and unblocks waiters,
|
|
3527
|
+
* but cannot preempt arbitrary in-process async work.
|
|
3528
|
+
*/
|
|
3529
|
+
cancelExecution(executionId: string, reason?: string): Promise<void>;
|
|
3530
|
+
wait<TResult>(executionId: string, options?: {
|
|
3531
|
+
timeout?: number;
|
|
3532
|
+
waitPollIntervalMs?: number;
|
|
3533
|
+
}): Promise<TResult>;
|
|
3534
|
+
execute<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3535
|
+
/**
|
|
3536
|
+
* A stricter alternative to `execute()` that rejects tasks whose result type
|
|
3537
|
+
* includes `undefined` (including `void`, `unknown`, and `any`).
|
|
3538
|
+
*
|
|
3539
|
+
* This mirrors the runtime contract where `wait()`/`execute()` treat
|
|
3540
|
+
* "completed without result" as an error.
|
|
3541
|
+
*/
|
|
3542
|
+
executeStrict<TInput, TResult>(task: undefined extends TResult ? never : DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3543
|
+
schedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions): Promise<string>;
|
|
3544
|
+
/**
|
|
3545
|
+
* Idempotently create (or update) a recurring schedule (cron/interval) with a stable id.
|
|
3546
|
+
* Safe to call concurrently from multiple processes.
|
|
3547
|
+
*/
|
|
3548
|
+
ensureSchedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions & {
|
|
3549
|
+
id: string;
|
|
3550
|
+
}): Promise<string>;
|
|
3551
|
+
recover(): Promise<void>;
|
|
3552
|
+
start(): void;
|
|
3553
|
+
stop(): Promise<void>;
|
|
3554
|
+
pauseSchedule(scheduleId: string): Promise<void>;
|
|
3555
|
+
resumeSchedule(scheduleId: string): Promise<void>;
|
|
3556
|
+
getSchedule(scheduleId: string): Promise<Schedule | null>;
|
|
3557
|
+
listSchedules(): Promise<Schedule[]>;
|
|
3558
|
+
updateSchedule(scheduleId: string, updates: {
|
|
3559
|
+
cron?: string;
|
|
3560
|
+
interval?: number;
|
|
3561
|
+
input?: unknown;
|
|
3562
|
+
}): Promise<void>;
|
|
3563
|
+
removeSchedule(scheduleId: string): Promise<void>;
|
|
3564
|
+
/**
|
|
3565
|
+
* Deliver a signal payload to a waiting workflow execution and resume it.
|
|
3566
|
+
*/
|
|
3567
|
+
signal<TPayload>(executionId: string, signal: IEventDefinition<TPayload>, payload: TPayload): Promise<void>;
|
|
3568
|
+
}
|
|
3569
|
+
interface IDurableExecutionProcessor {
|
|
3570
|
+
processExecution(executionId: string): Promise<void>;
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3573
|
+
interface DurableResourceConfig {
|
|
3574
|
+
worker?: boolean;
|
|
3575
|
+
}
|
|
3576
|
+
interface IDurableResource extends Pick<IDurableService, "startExecution" | "cancelExecution" | "wait" | "execute" | "executeStrict" | "schedule" | "ensureSchedule" | "pauseSchedule" | "resumeSchedule" | "getSchedule" | "listSchedules" | "updateSchedule" | "removeSchedule" | "recover" | "signal"> {
|
|
3577
|
+
/**
|
|
3578
|
+
* Reads the durable context for the currently running workflow execution.
|
|
3579
|
+
* Throws if called outside of a durable execution.
|
|
3580
|
+
*/
|
|
3581
|
+
use(): IDurableContext;
|
|
3582
|
+
}
|
|
3583
|
+
/**
|
|
3584
|
+
* A Runner-facing wrapper around `DurableService` that exposes a per-instance
|
|
3585
|
+
* context store and the public durable API (`execute`, `signal`, `wait`, etc.).
|
|
3586
|
+
*
|
|
3587
|
+
* This enables tasks to depend on a specific durable instance and call
|
|
3588
|
+
* `durable.use()` to access the per-execution durable context.
|
|
3589
|
+
*/
|
|
3590
|
+
declare class DurableResource$1 implements IDurableResource {
|
|
3591
|
+
readonly service: IDurableService;
|
|
3592
|
+
private readonly contextStorage;
|
|
3593
|
+
constructor(service: IDurableService, contextStorage: AsyncLocalStorage<IDurableContext>);
|
|
3594
|
+
use(): IDurableContext;
|
|
3595
|
+
startExecution<TInput>(task: DurableTask<TInput, unknown>, input?: TInput, options?: ExecuteOptions): Promise<string>;
|
|
3596
|
+
cancelExecution(executionId: string, reason?: string): Promise<void>;
|
|
3597
|
+
wait<TResult>(executionId: string, options?: {
|
|
3598
|
+
timeout?: number;
|
|
3599
|
+
waitPollIntervalMs?: number;
|
|
3600
|
+
}): Promise<TResult>;
|
|
3601
|
+
execute<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3602
|
+
executeStrict<TInput, TResult>(task: undefined extends TResult ? never : DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3603
|
+
schedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions): Promise<string>;
|
|
3604
|
+
ensureSchedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions & {
|
|
3605
|
+
id: string;
|
|
3606
|
+
}): Promise<string>;
|
|
3607
|
+
pauseSchedule(scheduleId: string): Promise<void>;
|
|
3608
|
+
resumeSchedule(scheduleId: string): Promise<void>;
|
|
3609
|
+
getSchedule(scheduleId: string): Promise<Schedule | null>;
|
|
3610
|
+
listSchedules(): Promise<Schedule[]>;
|
|
3611
|
+
updateSchedule(scheduleId: string, updates: {
|
|
3612
|
+
cron?: string;
|
|
3613
|
+
interval?: number;
|
|
3614
|
+
input?: unknown;
|
|
3615
|
+
}): Promise<void>;
|
|
3616
|
+
removeSchedule(scheduleId: string): Promise<void>;
|
|
3617
|
+
recover(): Promise<void>;
|
|
3618
|
+
signal<TPayload>(executionId: string, signal: IEventDefinition<TPayload>, payload: TPayload): Promise<void>;
|
|
3619
|
+
}
|
|
3620
|
+
|
|
3621
|
+
declare const durableEvents: {
|
|
3622
|
+
readonly audit: {
|
|
3623
|
+
readonly appended: IEvent<{
|
|
3624
|
+
entry: DurableAuditEntry;
|
|
3625
|
+
}>;
|
|
3626
|
+
};
|
|
3627
|
+
readonly execution: {
|
|
3628
|
+
readonly statusChanged: IEvent<DurableAuditEntryBase & {
|
|
3629
|
+
kind: typeof DurableAuditEntryKind.ExecutionStatusChanged;
|
|
3630
|
+
from: ExecutionStatus | null;
|
|
3631
|
+
to: ExecutionStatus;
|
|
3632
|
+
reason?: string;
|
|
3633
|
+
}>;
|
|
3634
|
+
};
|
|
3635
|
+
readonly step: {
|
|
3636
|
+
readonly completed: IEvent<DurableAuditEntryBase & {
|
|
3637
|
+
kind: typeof DurableAuditEntryKind.StepCompleted;
|
|
3638
|
+
stepId: string;
|
|
3639
|
+
durationMs: number;
|
|
3640
|
+
isInternal: boolean;
|
|
3641
|
+
}>;
|
|
3642
|
+
};
|
|
3643
|
+
readonly sleep: {
|
|
3644
|
+
readonly scheduled: IEvent<DurableAuditEntryBase & {
|
|
3645
|
+
kind: typeof DurableAuditEntryKind.SleepScheduled;
|
|
3646
|
+
stepId: string;
|
|
3647
|
+
timerId: string;
|
|
3648
|
+
durationMs: number;
|
|
3649
|
+
fireAt: Date;
|
|
3650
|
+
}>;
|
|
3651
|
+
readonly completed: IEvent<DurableAuditEntryBase & {
|
|
3652
|
+
kind: typeof DurableAuditEntryKind.SleepCompleted;
|
|
3653
|
+
stepId: string;
|
|
3654
|
+
timerId: string;
|
|
3655
|
+
}>;
|
|
3656
|
+
};
|
|
3657
|
+
readonly signal: {
|
|
3658
|
+
readonly waiting: IEvent<DurableAuditEntryBase & {
|
|
3659
|
+
kind: typeof DurableAuditEntryKind.SignalWaiting;
|
|
3660
|
+
stepId: string;
|
|
3661
|
+
signalId: string;
|
|
3662
|
+
timeoutMs?: number;
|
|
3663
|
+
timeoutAtMs?: number;
|
|
3664
|
+
timerId?: string;
|
|
3665
|
+
reason?: "initial" | "timeout_armed";
|
|
3666
|
+
}>;
|
|
3667
|
+
readonly delivered: IEvent<DurableAuditEntryBase & {
|
|
3668
|
+
kind: typeof DurableAuditEntryKind.SignalDelivered;
|
|
3669
|
+
stepId: string;
|
|
3670
|
+
signalId: string;
|
|
3671
|
+
}>;
|
|
3672
|
+
readonly timedOut: IEvent<DurableAuditEntryBase & {
|
|
3673
|
+
kind: typeof DurableAuditEntryKind.SignalTimedOut;
|
|
3674
|
+
stepId: string;
|
|
3675
|
+
signalId: string;
|
|
3676
|
+
timerId: string;
|
|
3677
|
+
}>;
|
|
3678
|
+
};
|
|
3679
|
+
readonly emit: {
|
|
3680
|
+
readonly published: IEvent<DurableAuditEntryBase & {
|
|
3681
|
+
kind: typeof DurableAuditEntryKind.EmitPublished;
|
|
3682
|
+
stepId: string;
|
|
3683
|
+
eventId: string;
|
|
3684
|
+
}>;
|
|
3685
|
+
};
|
|
3686
|
+
readonly note: {
|
|
3687
|
+
readonly created: IEvent<DurableAuditEntryBase & {
|
|
3688
|
+
kind: typeof DurableAuditEntryKind.Note;
|
|
3689
|
+
message: string;
|
|
3690
|
+
meta?: Record<string, unknown>;
|
|
3691
|
+
}>;
|
|
3692
|
+
};
|
|
3693
|
+
};
|
|
3694
|
+
declare const durableEventsArray: IEvent<any>[];
|
|
3695
|
+
|
|
3696
|
+
declare function createDurableRunnerAuditEmitter(params: {
|
|
3697
|
+
eventManager: EventManager;
|
|
3698
|
+
source?: string;
|
|
3699
|
+
}): DurableAuditEmitter;
|
|
3700
|
+
|
|
3701
|
+
declare class NoopEventBus implements IEventBus {
|
|
3702
|
+
publish(_channel: string, _event: BusEvent): Promise<void>;
|
|
3703
|
+
subscribe(_channel: string, _handler: BusEventHandler): Promise<void>;
|
|
3704
|
+
unsubscribe(_channel: string): Promise<void>;
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3707
|
+
/**
|
|
3708
|
+
* In-memory durable task registry.
|
|
3709
|
+
*
|
|
3710
|
+
* Durable executions persist only a `taskId` in the store, so the runtime needs a way
|
|
3711
|
+
* to resolve `taskId -> DurableTask` when resuming. This registry holds tasks that
|
|
3712
|
+
* were registered on the current process and optionally delegates to an external
|
|
3713
|
+
* resolver for tasks defined elsewhere (useful for modular apps).
|
|
3714
|
+
*/
|
|
3715
|
+
declare class TaskRegistry {
|
|
3716
|
+
private readonly externalResolver?;
|
|
3717
|
+
private readonly tasks;
|
|
3718
|
+
constructor(externalResolver?: ((taskId: string) => DurableTask<any, any> | undefined) | undefined);
|
|
3719
|
+
register<TInput, TResult>(task: DurableTask<TInput, TResult>): void;
|
|
3720
|
+
find(taskId: string): DurableTask<any, any> | undefined;
|
|
3721
|
+
}
|
|
3722
|
+
|
|
3723
|
+
interface AuditConfig {
|
|
3724
|
+
/**
|
|
3725
|
+
* When enabled, attempts to persist audit entries to the store (if supported).
|
|
3726
|
+
* This is separate from event emission via `emitter`.
|
|
3727
|
+
*/
|
|
3728
|
+
enabled?: boolean;
|
|
3729
|
+
/**
|
|
3730
|
+
* Optional emitter for streaming audit entries (e.g. Runner events, logging, mirroring).
|
|
3731
|
+
* Emissions must be best-effort and never affect workflow correctness.
|
|
3732
|
+
*/
|
|
3733
|
+
emitter?: DurableAuditEmitter;
|
|
3734
|
+
}
|
|
3735
|
+
/**
|
|
3736
|
+
* Durable audit trail sink.
|
|
3737
|
+
*
|
|
3738
|
+
* Used across the durable subsystem (service/managers/context) to record lifecycle
|
|
3739
|
+
* events in a best-effort way. Persistence and emission are explicitly non-critical:
|
|
3740
|
+
* failures must never affect workflow correctness (the store remains the source of truth).
|
|
3741
|
+
*/
|
|
3742
|
+
declare class AuditLogger {
|
|
3743
|
+
private readonly config;
|
|
3744
|
+
private readonly store;
|
|
3745
|
+
constructor(config: AuditConfig, store: IDurableStore);
|
|
3746
|
+
log(params: DurableAuditEntryInput & {
|
|
3747
|
+
at?: Date;
|
|
3748
|
+
}): Promise<void>;
|
|
3749
|
+
}
|
|
3750
|
+
|
|
3751
|
+
interface WaitConfig {
|
|
3752
|
+
defaultTimeout?: number;
|
|
3753
|
+
defaultPollIntervalMs?: number;
|
|
3754
|
+
}
|
|
3755
|
+
/**
|
|
3756
|
+
* Waits for an execution to reach a terminal state and returns/throws accordingly.
|
|
3757
|
+
*
|
|
3758
|
+
* Strategy:
|
|
3759
|
+
* - if an event bus is configured, subscribe to `execution:<executionId>` for low-latency completion
|
|
3760
|
+
* - otherwise (or on bus issues) fall back to polling the store
|
|
3761
|
+
*
|
|
3762
|
+
* The durable store remains the source of truth; this manager is purely a convenience layer
|
|
3763
|
+
* for callers that want `await durable.wait(...)` / `await durable.execute(...)`.
|
|
3764
|
+
*/
|
|
3765
|
+
declare class WaitManager {
|
|
3766
|
+
private readonly store;
|
|
3767
|
+
private readonly eventBus?;
|
|
3768
|
+
private readonly config?;
|
|
3769
|
+
constructor(store: IDurableStore, eventBus?: IEventBus | undefined, config?: WaitConfig | undefined);
|
|
3770
|
+
waitForResult<TResult>(executionId: string, options?: {
|
|
3771
|
+
timeout?: number;
|
|
3772
|
+
waitPollIntervalMs?: number;
|
|
3773
|
+
}): Promise<TResult>;
|
|
3774
|
+
}
|
|
3775
|
+
|
|
3776
|
+
/**
|
|
3777
|
+
* Creates and maintains durable schedules.
|
|
3778
|
+
*
|
|
3779
|
+
* A schedule is persisted in the store and translated into durable timers that
|
|
3780
|
+
* `PollingManager` will later process to kick off executions. This keeps scheduling
|
|
3781
|
+
* crash-safe and horizontally scalable: schedules aren't owned by in-memory timers.
|
|
3782
|
+
*/
|
|
3783
|
+
declare class ScheduleManager {
|
|
3784
|
+
private readonly store;
|
|
3785
|
+
private readonly taskRegistry;
|
|
3786
|
+
constructor(store: IDurableStore, taskRegistry: TaskRegistry);
|
|
3787
|
+
ensureSchedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions & {
|
|
3788
|
+
id: string;
|
|
3789
|
+
}): Promise<string>;
|
|
3790
|
+
schedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions): Promise<string>;
|
|
3791
|
+
reschedule(schedule: Schedule, options?: {
|
|
3792
|
+
lastRunAt?: Date;
|
|
3793
|
+
}): Promise<void>;
|
|
3794
|
+
pause(id: string): Promise<void>;
|
|
3795
|
+
resume(id: string): Promise<void>;
|
|
3796
|
+
get(id: string): Promise<Schedule | null>;
|
|
3797
|
+
list(): Promise<Schedule[]>;
|
|
3798
|
+
update(id: string, updates: {
|
|
3799
|
+
cron?: string;
|
|
3800
|
+
interval?: number;
|
|
3801
|
+
input?: unknown;
|
|
3802
|
+
}): Promise<void>;
|
|
3803
|
+
remove(id: string): Promise<void>;
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
interface ExecutionManagerConfig {
|
|
3807
|
+
store: IDurableStore;
|
|
3808
|
+
queue?: IDurableQueue;
|
|
3809
|
+
eventBus?: IEventBus;
|
|
3810
|
+
taskExecutor?: ITaskExecutor;
|
|
3811
|
+
contextProvider?: DurableServiceConfig["contextProvider"];
|
|
3812
|
+
audit?: DurableServiceConfig["audit"];
|
|
3813
|
+
determinism?: DurableServiceConfig["determinism"];
|
|
3814
|
+
execution?: {
|
|
3815
|
+
maxAttempts?: number;
|
|
3816
|
+
timeout?: number;
|
|
3817
|
+
kickoffFailsafeDelayMs?: number;
|
|
3818
|
+
};
|
|
3819
|
+
}
|
|
3820
|
+
/**
|
|
3821
|
+
* Runs durable executions (the "workflow engine" for attempts).
|
|
3822
|
+
*
|
|
3823
|
+
* Responsibilities:
|
|
3824
|
+
* - persist new executions (including optional idempotency keys)
|
|
3825
|
+
* - enqueue work (queue mode) or run directly (embedded mode)
|
|
3826
|
+
* - execute a workflow attempt via `taskExecutor.run(...)`
|
|
3827
|
+
* - inject a per-attempt `DurableContext` (via `contextProvider` / ALS wrapper)
|
|
3828
|
+
* - interpret `SuspensionSignal` as "pause + reschedule" rather than failure
|
|
3829
|
+
* - update execution status/result/error and notify waiters (`WaitManager`)
|
|
3830
|
+
*/
|
|
3831
|
+
declare class ExecutionManager {
|
|
3832
|
+
private readonly config;
|
|
3833
|
+
private readonly taskRegistry;
|
|
3834
|
+
private readonly auditLogger;
|
|
3835
|
+
private readonly waitManager;
|
|
3836
|
+
constructor(config: ExecutionManagerConfig, taskRegistry: TaskRegistry, auditLogger: AuditLogger, waitManager: WaitManager);
|
|
3837
|
+
startExecution<TInput>(task: DurableTask<TInput, unknown>, input?: TInput, options?: ExecuteOptions): Promise<string>;
|
|
3838
|
+
cancelExecution(executionId: string, reason?: string): Promise<void>;
|
|
3839
|
+
execute<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3840
|
+
executeStrict<TInput, TResult>(task: undefined extends TResult ? never : DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3841
|
+
processExecution(executionId: string): Promise<void>;
|
|
3842
|
+
kickoffExecution(executionId: string): Promise<void>;
|
|
3843
|
+
notifyExecutionFinished(execution: Execution): Promise<void>;
|
|
3844
|
+
private runExecutionAttempt;
|
|
3845
|
+
}
|
|
3846
|
+
|
|
3847
|
+
interface PollingConfig {
|
|
3848
|
+
enabled?: boolean;
|
|
3849
|
+
interval?: number;
|
|
3850
|
+
claimTtlMs?: number;
|
|
3851
|
+
}
|
|
3852
|
+
interface PollingManagerCallbacks {
|
|
3853
|
+
processExecution: (executionId: string) => Promise<void>;
|
|
3854
|
+
kickoffExecution: (executionId: string) => Promise<void>;
|
|
3855
|
+
}
|
|
3856
|
+
/**
|
|
3857
|
+
* Timer/tick driver for durable workflows.
|
|
3858
|
+
*
|
|
3859
|
+
* The durable store is the source of truth, but time needs an active driver:
|
|
3860
|
+
* `PollingManager` periodically scans ready timers and performs the appropriate action:
|
|
3861
|
+
*
|
|
3862
|
+
* - complete `sleep()` steps by marking their step result as completed
|
|
3863
|
+
* - resume executions after signal timeouts / scheduled kickoffs / retries
|
|
3864
|
+
* - coordinate multi-worker polling via optional `store.claimTimer(...)`
|
|
3865
|
+
*
|
|
3866
|
+
* In production topologies you typically enable polling on worker nodes only.
|
|
3867
|
+
*/
|
|
3868
|
+
declare class PollingManager {
|
|
3869
|
+
private readonly workerId;
|
|
3870
|
+
private readonly config;
|
|
3871
|
+
private readonly store;
|
|
3872
|
+
private readonly queue;
|
|
3873
|
+
private readonly maxAttempts;
|
|
3874
|
+
private readonly defaultTimeout;
|
|
3875
|
+
private readonly taskRegistry;
|
|
3876
|
+
private readonly auditLogger;
|
|
3877
|
+
private readonly scheduleManager;
|
|
3878
|
+
private readonly callbacks;
|
|
3879
|
+
private isRunning;
|
|
3880
|
+
private pollingTimer;
|
|
3881
|
+
private pollingWake;
|
|
3882
|
+
constructor(workerId: string, config: PollingConfig, store: IDurableStore, queue: IDurableQueue | undefined, maxAttempts: number, defaultTimeout: number | undefined, taskRegistry: TaskRegistry, auditLogger: AuditLogger, scheduleManager: ScheduleManager, callbacks: PollingManagerCallbacks);
|
|
3883
|
+
start(): void;
|
|
3884
|
+
stop(): Promise<void>;
|
|
3885
|
+
private poll;
|
|
3886
|
+
/** @internal - public for testing */
|
|
3887
|
+
handleTimer(timer: Timer): Promise<void>;
|
|
3888
|
+
}
|
|
3889
|
+
|
|
3890
|
+
/**
|
|
3891
|
+
* Error thrown to consumers waiting on an execution (`DurableService.wait/execute*`).
|
|
3892
|
+
*
|
|
3893
|
+
* Distinguishes durable execution failures/timeouts/cancellations from ordinary
|
|
3894
|
+
* task errors by carrying execution metadata and a (serialized) cause payload.
|
|
3895
|
+
* `WaitManager` is the primary producer of this error.
|
|
3896
|
+
*/
|
|
3897
|
+
declare class DurableExecutionError extends Error {
|
|
3898
|
+
readonly executionId: string;
|
|
3899
|
+
readonly taskId: string;
|
|
3900
|
+
readonly attempt: number;
|
|
3901
|
+
readonly causeInfo?: {
|
|
3902
|
+
message: string;
|
|
3903
|
+
stack?: string;
|
|
3904
|
+
} | undefined;
|
|
3905
|
+
constructor(message: string, executionId: string, taskId: string, attempt: number, causeInfo?: {
|
|
3906
|
+
message: string;
|
|
3907
|
+
stack?: string;
|
|
3908
|
+
} | undefined);
|
|
3909
|
+
}
|
|
3910
|
+
|
|
3911
|
+
/**
|
|
3912
|
+
* High-level facade for the Durable Workflows subsystem.
|
|
3913
|
+
*
|
|
3914
|
+
* `DurableService` glues together the durable backends (store/queue/event bus) and
|
|
3915
|
+
* the specialized managers that implement durable semantics:
|
|
3916
|
+
*
|
|
3917
|
+
* - `ExecutionManager` runs workflow attempts and injects `DurableContext`
|
|
3918
|
+
* - `SignalHandler` delivers external signals to waiting steps
|
|
3919
|
+
* - `WaitManager` waits for results (event-bus first, polling fallback)
|
|
3920
|
+
* - `ScheduleManager` creates/updates schedules and their timers
|
|
3921
|
+
* - `PollingManager` drives timers (sleep, retries, signal timeouts, schedules)
|
|
3922
|
+
* - `AuditLogger` emits/persists an audit trail (best-effort)
|
|
3923
|
+
*
|
|
3924
|
+
* `DurableResource` wraps this service for Runner integration and provides
|
|
3925
|
+
* `durable.use()` to read the per-execution `DurableContext`.
|
|
3926
|
+
*/
|
|
3927
|
+
declare class DurableService implements IDurableService {
|
|
3928
|
+
private readonly config;
|
|
3929
|
+
private readonly taskRegistry;
|
|
3930
|
+
private readonly auditLogger;
|
|
3931
|
+
private readonly waitManager;
|
|
3932
|
+
private readonly scheduleManager;
|
|
3933
|
+
private readonly signalHandler;
|
|
3934
|
+
private readonly executionManager;
|
|
3935
|
+
private readonly pollingManager;
|
|
3936
|
+
/** Unique worker ID for distributed timer coordination */
|
|
3937
|
+
private readonly workerId;
|
|
3938
|
+
constructor(config: DurableServiceConfig);
|
|
3939
|
+
registerTask<TInput, TResult>(task: DurableTask<TInput, TResult>): void;
|
|
3940
|
+
findTask(taskId: string): DurableTask<any, any> | undefined;
|
|
3941
|
+
startExecution<TInput>(task: DurableTask<TInput, unknown>, input?: TInput, options?: ExecuteOptions): Promise<string>;
|
|
3942
|
+
cancelExecution(executionId: string, reason?: string): Promise<void>;
|
|
3943
|
+
execute<TInput, TResult>(task: DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3944
|
+
executeStrict<TInput, TResult>(task: undefined extends TResult ? never : DurableTask<TInput, TResult>, input?: TInput, options?: ExecuteOptions): Promise<TResult>;
|
|
3945
|
+
wait<TResult>(executionId: string, options?: {
|
|
3946
|
+
timeout?: number;
|
|
3947
|
+
waitPollIntervalMs?: number;
|
|
3948
|
+
}): Promise<TResult>;
|
|
3949
|
+
schedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions): Promise<string>;
|
|
3950
|
+
ensureSchedule<TInput>(task: DurableTask<TInput, unknown>, input: TInput | undefined, options: ScheduleOptions & {
|
|
3951
|
+
id: string;
|
|
3952
|
+
}): Promise<string>;
|
|
3953
|
+
recover(): Promise<void>;
|
|
3954
|
+
start(): void;
|
|
3955
|
+
stop(): Promise<void>;
|
|
3956
|
+
pauseSchedule(id: string): Promise<void>;
|
|
3957
|
+
resumeSchedule(id: string): Promise<void>;
|
|
3958
|
+
getSchedule(id: string): Promise<Schedule | null>;
|
|
3959
|
+
listSchedules(): Promise<Schedule[]>;
|
|
3960
|
+
updateSchedule(id: string, updates: {
|
|
3961
|
+
cron?: string;
|
|
3962
|
+
interval?: number;
|
|
3963
|
+
input?: unknown;
|
|
3964
|
+
}): Promise<void>;
|
|
3965
|
+
removeSchedule(id: string): Promise<void>;
|
|
3966
|
+
signal<TPayload>(executionId: string, signal: IEventDefinition<TPayload>, payload: TPayload): Promise<void>;
|
|
3967
|
+
processExecution(executionId: string): Promise<void>;
|
|
3968
|
+
getEventBus(): NoopEventBus;
|
|
3969
|
+
/** @internal - exposed for unit testing */
|
|
3970
|
+
get _pollingManager(): PollingManager;
|
|
3971
|
+
/** @internal - exposed for unit testing */
|
|
3972
|
+
get _executionManager(): ExecutionManager;
|
|
3973
|
+
/** @internal - exposed for unit testing (delegates to pollingManager) */
|
|
3974
|
+
handleTimer(timer: Timer): Promise<void>;
|
|
3975
|
+
}
|
|
3976
|
+
declare function initDurableService(config: DurableServiceConfig): Promise<DurableService>;
|
|
3977
|
+
declare function disposeDurableService(service: IDurableService, config: DurableServiceConfig): Promise<void>;
|
|
3978
|
+
|
|
3979
|
+
type DurableResourceRuntimeConfig = Omit<DurableServiceConfig, "taskExecutor" | "tasks" | "taskResolver" | "contextProvider"> & {
|
|
3980
|
+
/**
|
|
3981
|
+
* Starts an embedded worker (queue consumer) in this process.
|
|
3982
|
+
* Has effect only when `queue` is configured.
|
|
3983
|
+
*/
|
|
3984
|
+
worker?: boolean;
|
|
3985
|
+
};
|
|
3986
|
+
/**
|
|
3987
|
+
* A reusable durable resource template.
|
|
3988
|
+
*
|
|
3989
|
+
* Usage:
|
|
3990
|
+
* - `const durable = durableResource.fork("app.durable");`
|
|
3991
|
+
* - Register it via `durable.with({ store, queue, eventBus, ... })`
|
|
3992
|
+
*/
|
|
3993
|
+
declare const durableResource: IResource<DurableResourceRuntimeConfig, Promise<DurableResource$1>, {
|
|
3994
|
+
taskRunner: IResource<void, Promise<TaskRunner>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
3995
|
+
eventManager: IResource<void, Promise<EventManager>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
3996
|
+
runnerStore: IResource<void, Promise<Store>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
3997
|
+
}, any, IResourceMeta, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
3998
|
+
|
|
3999
|
+
type ImplicitInternalStepIdsPolicy = "allow" | "warn" | "error";
|
|
4000
|
+
|
|
4001
|
+
/**
|
|
4002
|
+
* Per-execution workflow toolkit used by durable tasks.
|
|
4003
|
+
*
|
|
4004
|
+
* `DurableContext` is created by `ExecutionManager` for each execution attempt and
|
|
4005
|
+
* made available to user code via `DurableResource.use()` (AsyncLocalStorage).
|
|
4006
|
+
*
|
|
4007
|
+
* It provides deterministic "save points" (`step()`), durable suspension primitives
|
|
4008
|
+
* (`sleep()`, `waitForSignal()`), and best-effort side-channel notifications (`emit()`).
|
|
4009
|
+
* The durable store is the source of truth; this class is intentionally thin state
|
|
4010
|
+
* around indexes/guards to keep a single in-memory attempt deterministic.
|
|
4011
|
+
*/
|
|
4012
|
+
declare class DurableContext implements IDurableContext {
|
|
4013
|
+
private readonly store;
|
|
4014
|
+
private readonly bus;
|
|
4015
|
+
readonly executionId: string;
|
|
4016
|
+
readonly attempt: number;
|
|
4017
|
+
private readonly sleepIndexRef;
|
|
4018
|
+
private readonly signalIndexes;
|
|
4019
|
+
private readonly emitIndexes;
|
|
4020
|
+
private noteIndex;
|
|
4021
|
+
private readonly implicitInternalStepIdsWarned;
|
|
4022
|
+
private readonly seenStepIds;
|
|
4023
|
+
private readonly compensations;
|
|
4024
|
+
private readonly audit;
|
|
4025
|
+
private readonly determinism;
|
|
4026
|
+
private readonly auditEnabled;
|
|
4027
|
+
private readonly auditEmitter;
|
|
4028
|
+
private readonly implicitInternalStepIdsPolicy;
|
|
4029
|
+
constructor(store: IDurableStore, bus: IEventBus, executionId: string, attempt: number, options?: {
|
|
4030
|
+
auditEnabled?: boolean;
|
|
4031
|
+
auditEmitter?: DurableAuditEmitter;
|
|
4032
|
+
implicitInternalStepIds?: ImplicitInternalStepIdsPolicy;
|
|
4033
|
+
});
|
|
4034
|
+
private assertNotCancelled;
|
|
4035
|
+
private getStepId;
|
|
4036
|
+
private internalStep;
|
|
4037
|
+
step<T>(stepId: string): IStepBuilder<T>;
|
|
4038
|
+
step<T>(stepId: DurableStepId<T>): IStepBuilder<T>;
|
|
4039
|
+
step<T>(stepId: string | DurableStepId<T>, fn: () => Promise<T>): Promise<T>;
|
|
4040
|
+
step<T>(stepId: string | DurableStepId<T>, options: StepOptions, fn: () => Promise<T>): Promise<T>;
|
|
4041
|
+
_executeStep<T>(stepId: string, options: StepOptions, upFn: () => Promise<T>, downFn?: (result: T) => Promise<void>): Promise<T>;
|
|
4042
|
+
rollback(): Promise<void>;
|
|
4043
|
+
sleep(durationMs: number, options?: SleepOptions): Promise<void>;
|
|
4044
|
+
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>): Promise<TPayload>;
|
|
4045
|
+
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>, options: SignalOptions & {
|
|
4046
|
+
timeoutMs: number;
|
|
4047
|
+
}): Promise<{
|
|
4048
|
+
kind: "signal";
|
|
4049
|
+
payload: TPayload;
|
|
4050
|
+
} | {
|
|
4051
|
+
kind: "timeout";
|
|
4052
|
+
}>;
|
|
4053
|
+
waitForSignal<TPayload>(signal: IEventDefinition<TPayload>, options: SignalOptions): Promise<TPayload>;
|
|
4054
|
+
emit<TPayload>(event: IEventDefinition<TPayload>, payload: TPayload, options?: EmitOptions): Promise<void>;
|
|
4055
|
+
note(message: string, meta?: Record<string, unknown>): Promise<void>;
|
|
4056
|
+
}
|
|
4057
|
+
|
|
4058
|
+
/**
|
|
4059
|
+
* Fluent helper for building a durable step.
|
|
4060
|
+
*
|
|
4061
|
+
* This is the ergonomic layer behind `ctx.step("id")`:
|
|
4062
|
+
* - `up()` defines the memoized computation
|
|
4063
|
+
* - `down()` registers a compensation to be invoked by `ctx.rollback()`
|
|
4064
|
+
*
|
|
4065
|
+
* It is `PromiseLike`, so users can `await ctx.step("x").up(...).down(...)`.
|
|
4066
|
+
*/
|
|
4067
|
+
declare class StepBuilder<T> implements IStepBuilder<T> {
|
|
4068
|
+
private readonly context;
|
|
4069
|
+
private readonly stepId;
|
|
4070
|
+
private readonly options;
|
|
4071
|
+
private upFn?;
|
|
4072
|
+
private downFn?;
|
|
4073
|
+
constructor(context: DurableContext, stepId: string, options?: StepOptions);
|
|
4074
|
+
up(fn: () => Promise<T>): this;
|
|
4075
|
+
down(fn: (result: T) => Promise<void>): this;
|
|
4076
|
+
private execute;
|
|
4077
|
+
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
|
|
4078
|
+
}
|
|
4079
|
+
|
|
4080
|
+
/**
|
|
4081
|
+
* Administrative / operator API for durable workflows.
|
|
4082
|
+
*
|
|
4083
|
+
* This class is intentionally store-backed and side-effect free with respect to
|
|
4084
|
+
* "running" workflows: it reads execution details and, when supported by the store,
|
|
4085
|
+
* can perform operator actions (retry rollback, skip a step, force fail, patch state).
|
|
4086
|
+
*
|
|
4087
|
+
* Used by dashboards / CLIs / tooling to inspect and recover executions.
|
|
4088
|
+
*/
|
|
4089
|
+
declare class DurableOperator {
|
|
4090
|
+
private readonly store;
|
|
4091
|
+
constructor(store: IDurableStore);
|
|
4092
|
+
listExecutions(options?: ListExecutionsOptions): Promise<Execution[]>;
|
|
4093
|
+
getExecutionDetail(executionId: string): Promise<{
|
|
4094
|
+
execution: Execution | null;
|
|
4095
|
+
steps: StepResult[];
|
|
4096
|
+
audit: DurableAuditEntry[];
|
|
4097
|
+
}>;
|
|
4098
|
+
/**
|
|
4099
|
+
* Resets an execution from `compensation_failed` (or other states) to `pending`.
|
|
4100
|
+
* This effectively retries the workflow from the last memoized step.
|
|
4101
|
+
*/
|
|
4102
|
+
retryRollback(executionId: string): Promise<void>;
|
|
4103
|
+
/**
|
|
4104
|
+
* Manually marks a step as completed with a specific result.
|
|
4105
|
+
* Useful for skipping broken steps or providing a manual fix.
|
|
4106
|
+
*/
|
|
4107
|
+
skipStep(executionId: string, stepId: string): Promise<void>;
|
|
4108
|
+
/**
|
|
4109
|
+
* Forces an execution to the `failed` state.
|
|
4110
|
+
*/
|
|
4111
|
+
forceFail(executionId: string, reason: string): Promise<void>;
|
|
4112
|
+
/**
|
|
4113
|
+
* Manually patches the result of a step.
|
|
4114
|
+
* Useful when a step failed to save its result but the side effect occurred.
|
|
4115
|
+
*/
|
|
4116
|
+
editState(executionId: string, stepId: string, newState: unknown): Promise<void>;
|
|
4117
|
+
/**
|
|
4118
|
+
* Lists all executions that require manual intervention.
|
|
4119
|
+
*/
|
|
4120
|
+
listStuckExecutions(): Promise<Execution[]>;
|
|
4121
|
+
}
|
|
4122
|
+
|
|
4123
|
+
/**
|
|
4124
|
+
* Durable queue consumer (worker process role).
|
|
4125
|
+
*
|
|
4126
|
+
* The worker listens to the durable queue and turns queue messages into
|
|
4127
|
+
* `processExecution(executionId)` calls on the service layer (`ExecutionManager`
|
|
4128
|
+
* behind `IDurableExecutionProcessor`). This is how "resume" work is distributed
|
|
4129
|
+
* horizontally: the store is the source of truth, the queue provides delivery.
|
|
4130
|
+
*/
|
|
4131
|
+
declare class DurableWorker {
|
|
4132
|
+
private readonly service;
|
|
4133
|
+
private readonly queue;
|
|
4134
|
+
constructor(service: IDurableExecutionProcessor, queue: IDurableQueue);
|
|
4135
|
+
start(): Promise<void>;
|
|
4136
|
+
private handleMessage;
|
|
4137
|
+
private extractExecutionId;
|
|
4138
|
+
}
|
|
4139
|
+
declare function initDurableWorker(service: IDurableExecutionProcessor, queue: IDurableQueue): Promise<DurableWorker>;
|
|
4140
|
+
|
|
4141
|
+
type DashboardMiddlewareOptions = {
|
|
4142
|
+
/**
|
|
4143
|
+
* Override where the dashboard UI is served from.
|
|
4144
|
+
* Useful for tests or custom deployments.
|
|
4145
|
+
*/
|
|
4146
|
+
uiDistPath?: string;
|
|
4147
|
+
/**
|
|
4148
|
+
* Authorization hook for operator actions (retry/skip/force/edit).
|
|
4149
|
+
* Return true to allow, false to deny.
|
|
4150
|
+
*/
|
|
4151
|
+
operatorAuth?: (req: Request) => boolean | Promise<boolean>;
|
|
4152
|
+
/**
|
|
4153
|
+
* Opt out of operator auth checks (not recommended).
|
|
4154
|
+
*/
|
|
4155
|
+
dangerouslyAllowUnauthenticatedOperator?: boolean;
|
|
4156
|
+
};
|
|
4157
|
+
declare function createDashboardMiddleware(_service: IDurableService, operator: DurableOperator, options?: DashboardMiddlewareOptions): Router;
|
|
4158
|
+
|
|
4159
|
+
declare class MemoryStore implements IDurableStore {
|
|
4160
|
+
private executions;
|
|
4161
|
+
private executionIdByIdempotencyKey;
|
|
4162
|
+
private stepResults;
|
|
4163
|
+
private auditEntries;
|
|
4164
|
+
private timers;
|
|
4165
|
+
private schedules;
|
|
4166
|
+
private locks;
|
|
4167
|
+
private getIdempotencyMapKey;
|
|
4168
|
+
getExecutionIdByIdempotencyKey(params: {
|
|
4169
|
+
taskId: string;
|
|
4170
|
+
idempotencyKey: string;
|
|
4171
|
+
}): Promise<string | null>;
|
|
4172
|
+
setExecutionIdByIdempotencyKey(params: {
|
|
4173
|
+
taskId: string;
|
|
4174
|
+
idempotencyKey: string;
|
|
4175
|
+
executionId: string;
|
|
4176
|
+
}): Promise<boolean>;
|
|
4177
|
+
saveExecution(execution: Execution): Promise<void>;
|
|
4178
|
+
getExecution(id: string): Promise<Execution | null>;
|
|
4179
|
+
updateExecution(id: string, updates: Partial<Execution>): Promise<void>;
|
|
4180
|
+
listIncompleteExecutions(): Promise<Execution[]>;
|
|
4181
|
+
listStuckExecutions(): Promise<Execution[]>;
|
|
4182
|
+
listExecutions(options?: ListExecutionsOptions): Promise<Execution[]>;
|
|
4183
|
+
listStepResults(executionId: string): Promise<StepResult[]>;
|
|
4184
|
+
appendAuditEntry(entry: DurableAuditEntry): Promise<void>;
|
|
4185
|
+
listAuditEntries(executionId: string, options?: {
|
|
4186
|
+
limit?: number;
|
|
4187
|
+
offset?: number;
|
|
4188
|
+
}): Promise<DurableAuditEntry[]>;
|
|
4189
|
+
retryRollback(executionId: string): Promise<void>;
|
|
4190
|
+
skipStep(executionId: string, stepId: string): Promise<void>;
|
|
4191
|
+
forceFail(executionId: string, error: {
|
|
4192
|
+
message: string;
|
|
4193
|
+
stack?: string;
|
|
4194
|
+
}): Promise<void>;
|
|
4195
|
+
editStepResult(executionId: string, stepId: string, newResult: unknown): Promise<void>;
|
|
4196
|
+
getStepResult(executionId: string, stepId: string): Promise<StepResult | null>;
|
|
4197
|
+
saveStepResult(result: StepResult): Promise<void>;
|
|
4198
|
+
createTimer(timer: Timer): Promise<void>;
|
|
4199
|
+
getReadyTimers(now?: Date): Promise<Timer[]>;
|
|
4200
|
+
markTimerFired(timerId: string): Promise<void>;
|
|
4201
|
+
deleteTimer(timerId: string): Promise<void>;
|
|
4202
|
+
claimTimer(timerId: string, workerId: string, ttlMs: number): Promise<boolean>;
|
|
4203
|
+
createSchedule(schedule: Schedule): Promise<void>;
|
|
4204
|
+
getSchedule(id: string): Promise<Schedule | null>;
|
|
4205
|
+
updateSchedule(id: string, updates: Partial<Schedule>): Promise<void>;
|
|
4206
|
+
deleteSchedule(id: string): Promise<void>;
|
|
4207
|
+
listSchedules(): Promise<Schedule[]>;
|
|
4208
|
+
listActiveSchedules(): Promise<Schedule[]>;
|
|
4209
|
+
acquireLock(resource: string, ttlMs: number): Promise<string | null>;
|
|
4210
|
+
releaseLock(resource: string, lockId: string): Promise<void>;
|
|
4211
|
+
}
|
|
4212
|
+
|
|
4213
|
+
interface RedisPipeline {
|
|
4214
|
+
get(key: string): RedisPipeline;
|
|
4215
|
+
hget(hash: string, key: string): RedisPipeline;
|
|
4216
|
+
exec(): Promise<Array<[unknown, unknown]> | null>;
|
|
4217
|
+
}
|
|
4218
|
+
interface RedisClient {
|
|
4219
|
+
set(...args: unknown[]): Promise<unknown>;
|
|
4220
|
+
get(...args: unknown[]): Promise<unknown>;
|
|
4221
|
+
scan(...args: unknown[]): Promise<unknown>;
|
|
4222
|
+
sscan(...args: unknown[]): Promise<unknown>;
|
|
4223
|
+
sadd(...args: unknown[]): Promise<unknown>;
|
|
4224
|
+
srem(...args: unknown[]): Promise<unknown>;
|
|
4225
|
+
keys?(...args: unknown[]): Promise<unknown>;
|
|
4226
|
+
pipeline(): RedisPipeline;
|
|
4227
|
+
hset(...args: unknown[]): Promise<unknown>;
|
|
4228
|
+
hget(...args: unknown[]): Promise<unknown>;
|
|
4229
|
+
hdel(...args: unknown[]): Promise<unknown>;
|
|
4230
|
+
hgetall(...args: unknown[]): Promise<unknown>;
|
|
4231
|
+
zadd(...args: unknown[]): Promise<unknown>;
|
|
4232
|
+
zrangebyscore(...args: unknown[]): Promise<unknown>;
|
|
4233
|
+
zrem(...args: unknown[]): Promise<unknown>;
|
|
4234
|
+
eval(...args: unknown[]): Promise<unknown>;
|
|
4235
|
+
quit(...args: unknown[]): Promise<unknown>;
|
|
4236
|
+
}
|
|
4237
|
+
interface RedisStoreConfig {
|
|
4238
|
+
prefix?: string;
|
|
4239
|
+
redis?: RedisClient | string;
|
|
4240
|
+
}
|
|
4241
|
+
declare class RedisStore implements IDurableStore {
|
|
4242
|
+
private redis;
|
|
4243
|
+
private prefix;
|
|
4244
|
+
constructor(config: RedisStoreConfig);
|
|
4245
|
+
private k;
|
|
4246
|
+
private encodeKeyPart;
|
|
4247
|
+
getExecutionIdByIdempotencyKey(params: {
|
|
4248
|
+
taskId: string;
|
|
4249
|
+
idempotencyKey: string;
|
|
4250
|
+
}): Promise<string | null>;
|
|
4251
|
+
setExecutionIdByIdempotencyKey(params: {
|
|
4252
|
+
taskId: string;
|
|
4253
|
+
idempotencyKey: string;
|
|
4254
|
+
executionId: string;
|
|
4255
|
+
}): Promise<boolean>;
|
|
4256
|
+
private parseRedisString;
|
|
4257
|
+
private parseScanResponse;
|
|
4258
|
+
private scanKeys;
|
|
4259
|
+
private scanSetMembers;
|
|
4260
|
+
private activeExecutionsKey;
|
|
4261
|
+
private isActiveExecutionStatus;
|
|
4262
|
+
private updateActiveExecutionMembership;
|
|
4263
|
+
saveExecution(execution: Execution): Promise<void>;
|
|
4264
|
+
getExecution(id: string): Promise<Execution | null>;
|
|
4265
|
+
updateExecution(id: string, updates: Partial<Execution>): Promise<void>;
|
|
4266
|
+
listIncompleteExecutions(): Promise<Execution[]>;
|
|
4267
|
+
listStuckExecutions(): Promise<Execution[]>;
|
|
4268
|
+
retryRollback(executionId: string): Promise<void>;
|
|
4269
|
+
skipStep(executionId: string, stepId: string): Promise<void>;
|
|
4270
|
+
forceFail(executionId: string, error: {
|
|
4271
|
+
message: string;
|
|
4272
|
+
stack?: string;
|
|
4273
|
+
}): Promise<void>;
|
|
4274
|
+
editStepResult(executionId: string, stepId: string, newResult: unknown): Promise<void>;
|
|
4275
|
+
listExecutions(options?: ListExecutionsOptions): Promise<Execution[]>;
|
|
4276
|
+
listStepResults(executionId: string): Promise<StepResult[]>;
|
|
4277
|
+
appendAuditEntry(entry: DurableAuditEntry): Promise<void>;
|
|
4278
|
+
listAuditEntries(executionId: string, options?: {
|
|
4279
|
+
limit?: number;
|
|
4280
|
+
offset?: number;
|
|
4281
|
+
}): Promise<DurableAuditEntry[]>;
|
|
4282
|
+
getStepResult(executionId: string, stepId: string): Promise<StepResult | null>;
|
|
4283
|
+
saveStepResult(result: StepResult): Promise<void>;
|
|
4284
|
+
createTimer(timer: Timer): Promise<void>;
|
|
4285
|
+
getReadyTimers(now?: Date): Promise<Timer[]>;
|
|
4286
|
+
markTimerFired(timerId: string): Promise<void>;
|
|
4287
|
+
deleteTimer(timerId: string): Promise<void>;
|
|
4288
|
+
claimTimer(timerId: string, workerId: string, ttlMs: number): Promise<boolean>;
|
|
4289
|
+
createSchedule(schedule: Schedule): Promise<void>;
|
|
4290
|
+
getSchedule(id: string): Promise<Schedule | null>;
|
|
4291
|
+
updateSchedule(id: string, updates: Partial<Schedule>): Promise<void>;
|
|
4292
|
+
deleteSchedule(id: string): Promise<void>;
|
|
4293
|
+
listSchedules(): Promise<Schedule[]>;
|
|
4294
|
+
listActiveSchedules(): Promise<Schedule[]>;
|
|
4295
|
+
acquireLock(resource: string, ttlMs: number): Promise<string | null>;
|
|
4296
|
+
releaseLock(resource: string, lockId: string): Promise<void>;
|
|
4297
|
+
dispose(): Promise<void>;
|
|
4298
|
+
}
|
|
4299
|
+
|
|
4300
|
+
declare class MemoryQueue implements IDurableQueue {
|
|
4301
|
+
private queue;
|
|
4302
|
+
private handler;
|
|
4303
|
+
private isProcessing;
|
|
4304
|
+
private readonly inFlight;
|
|
4305
|
+
enqueue<T>(message: Omit<QueueMessage<T>, "id" | "createdAt" | "attempts">): Promise<string>;
|
|
4306
|
+
consume<T>(handler: MessageHandler<T>): Promise<void>;
|
|
4307
|
+
ack(_messageId: string): Promise<void>;
|
|
4308
|
+
nack(_messageId: string, _requeue?: boolean): Promise<void>;
|
|
4309
|
+
private processNext;
|
|
4310
|
+
}
|
|
4311
|
+
|
|
4312
|
+
interface RabbitMQQueueConfig {
|
|
4313
|
+
url?: string;
|
|
4314
|
+
queueName?: string;
|
|
4315
|
+
queue?: {
|
|
4316
|
+
name?: string;
|
|
4317
|
+
quorum?: boolean;
|
|
4318
|
+
deadLetter?: string;
|
|
4319
|
+
messageTtl?: number;
|
|
4320
|
+
};
|
|
4321
|
+
prefetch?: number;
|
|
4322
|
+
}
|
|
4323
|
+
declare class RabbitMQQueue implements IDurableQueue {
|
|
4324
|
+
private connection;
|
|
4325
|
+
private channel;
|
|
4326
|
+
private url;
|
|
4327
|
+
private queueName;
|
|
4328
|
+
private prefetch;
|
|
4329
|
+
private readonly isQuorum;
|
|
4330
|
+
private readonly deadLetterQueue?;
|
|
4331
|
+
private readonly messageTtl?;
|
|
4332
|
+
private messageMap;
|
|
4333
|
+
constructor(config: RabbitMQQueueConfig);
|
|
4334
|
+
init(): Promise<void>;
|
|
4335
|
+
enqueue<T>(message: Omit<QueueMessage<T>, "id" | "createdAt" | "attempts">): Promise<string>;
|
|
4336
|
+
consume<T>(handler: MessageHandler<T>): Promise<void>;
|
|
4337
|
+
ack(messageId: string): Promise<void>;
|
|
4338
|
+
nack(messageId: string, requeue?: boolean): Promise<void>;
|
|
4339
|
+
dispose(): Promise<void>;
|
|
4340
|
+
}
|
|
4341
|
+
|
|
4342
|
+
declare class MemoryEventBus implements IEventBus {
|
|
4343
|
+
private handlers;
|
|
4344
|
+
publish(channel: string, event: BusEvent): Promise<void>;
|
|
4345
|
+
subscribe(channel: string, handler: BusEventHandler): Promise<void>;
|
|
4346
|
+
unsubscribe(channel: string): Promise<void>;
|
|
4347
|
+
}
|
|
4348
|
+
|
|
4349
|
+
interface RedisEventBusConfig {
|
|
4350
|
+
prefix?: string;
|
|
4351
|
+
redis?: RedisEventBusClient | string;
|
|
4352
|
+
}
|
|
4353
|
+
interface RedisEventBusClient {
|
|
4354
|
+
publish(channel: string, payload: string): Promise<unknown>;
|
|
4355
|
+
subscribe(channel: string): Promise<unknown>;
|
|
4356
|
+
unsubscribe(channel: string): Promise<unknown>;
|
|
4357
|
+
on(event: "message", fn: (channel: string, message: string) => void): unknown;
|
|
4358
|
+
quit(): Promise<unknown>;
|
|
4359
|
+
duplicate(): RedisEventBusClient;
|
|
4360
|
+
}
|
|
4361
|
+
declare class RedisEventBus implements IEventBus {
|
|
4362
|
+
private pub;
|
|
4363
|
+
private sub;
|
|
4364
|
+
private prefix;
|
|
4365
|
+
private readonly channels;
|
|
4366
|
+
private readonly serializer;
|
|
4367
|
+
constructor(config: RedisEventBusConfig);
|
|
4368
|
+
private k;
|
|
4369
|
+
private tryParse;
|
|
4370
|
+
private coerceTimestamp;
|
|
4371
|
+
private toBusEvent;
|
|
4372
|
+
private deserializeEvent;
|
|
4373
|
+
publish(channel: string, event: BusEvent): Promise<void>;
|
|
4374
|
+
subscribe(channel: string, handler: BusEventHandler): Promise<void>;
|
|
4375
|
+
unsubscribe(channel: string): Promise<void>;
|
|
4376
|
+
dispose(): Promise<void>;
|
|
4377
|
+
}
|
|
4378
|
+
|
|
4379
|
+
type DurableResource = ReturnType<typeof durableResource.fork>;
|
|
4380
|
+
type DurableResourceRegistration = ReturnType<DurableResource["with"]>;
|
|
4381
|
+
interface DurableTestSetup {
|
|
4382
|
+
durable: DurableResource;
|
|
4383
|
+
durableRegistration: DurableResourceRegistration;
|
|
4384
|
+
store: MemoryStore;
|
|
4385
|
+
eventBus: MemoryEventBus;
|
|
4386
|
+
queue?: MemoryQueue;
|
|
4387
|
+
}
|
|
4388
|
+
interface DurableTestSetupOptions {
|
|
4389
|
+
durableId?: string;
|
|
4390
|
+
store?: MemoryStore;
|
|
4391
|
+
eventBus?: MemoryEventBus;
|
|
4392
|
+
queue?: MemoryQueue;
|
|
4393
|
+
worker?: boolean;
|
|
4394
|
+
pollingIntervalMs?: number;
|
|
4395
|
+
durableConfig?: Partial<DurableResourceRuntimeConfig>;
|
|
4396
|
+
}
|
|
4397
|
+
declare function createDurableTestSetup(options?: DurableTestSetupOptions): DurableTestSetup;
|
|
4398
|
+
declare function waitUntil(predicate: () => boolean | Promise<boolean>, options: {
|
|
4399
|
+
timeoutMs: number;
|
|
4400
|
+
intervalMs: number;
|
|
4401
|
+
}): Promise<void>;
|
|
4402
|
+
|
|
2381
4403
|
declare const globals: {
|
|
2382
4404
|
resources: {
|
|
2383
4405
|
httpSmartClientFactory: IResource<void, Promise<HttpSmartClientFactory>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
@@ -2387,15 +4409,15 @@ declare const globals: {
|
|
|
2387
4409
|
eventManager: IResource<void, Promise<EventManager>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2388
4410
|
taskRunner: IResource<void, Promise<TaskRunner>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2389
4411
|
logger: IResource<void, Promise<Logger>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2390
|
-
serializer: IResource<void, Promise<
|
|
4412
|
+
serializer: IResource<void, Promise<SerializerLike>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2391
4413
|
cache: IResource<{
|
|
2392
4414
|
defaultOptions?: any;
|
|
2393
4415
|
}, Promise<{
|
|
2394
4416
|
map: Map<string, ICacheInstance>;
|
|
2395
|
-
cacheFactoryTask: TaskDependencyWithIntercept<any, Promise<ICacheInstance>>;
|
|
4417
|
+
cacheFactoryTask: TaskDependencyWithIntercept<lru_cache.LRUCache.Options<any, any, any>, Promise<ICacheInstance>>;
|
|
2396
4418
|
defaultOptions: any;
|
|
2397
4419
|
}>, {
|
|
2398
|
-
cacheFactoryTask: ITask<any, Promise<ICacheInstance>, any, any, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
4420
|
+
cacheFactoryTask: ITask<lru_cache.LRUCache.Options<any, any, any>, Promise<ICacheInstance>, any, any, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
2399
4421
|
}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2400
4422
|
queue: IResource<void, Promise<{
|
|
2401
4423
|
map: Map<string, Queue>;
|
|
@@ -2407,12 +4429,37 @@ declare const globals: {
|
|
|
2407
4429
|
description: string;
|
|
2408
4430
|
}, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2409
4431
|
httpClientFactory: IResource<void, Promise<HttpClientFactory>, {
|
|
2410
|
-
serializer: IResource<void, Promise<
|
|
4432
|
+
serializer: IResource<void, Promise<SerializerLike>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2411
4433
|
store: IResource<void, Promise<Store>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
2412
4434
|
}, any, {
|
|
2413
4435
|
title: string;
|
|
2414
4436
|
description: string;
|
|
2415
4437
|
}, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4438
|
+
rateLimit: IResource<void, Promise<{
|
|
4439
|
+
states: WeakMap<RateLimitMiddlewareConfig, RateLimitState>;
|
|
4440
|
+
}>, {}, any, any, ITag<{
|
|
4441
|
+
metadata?: Record<string, any>;
|
|
4442
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4443
|
+
circuitBreaker: IResource<void, Promise<{
|
|
4444
|
+
statusMap: Map<string, CircuitBreakerStatus>;
|
|
4445
|
+
}>, {}, any, any, ITag<{
|
|
4446
|
+
metadata?: Record<string, any>;
|
|
4447
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4448
|
+
temporal: IResource<void, Promise<{
|
|
4449
|
+
debounceStates: WeakMap<TemporalMiddlewareConfig, DebounceState>;
|
|
4450
|
+
throttleStates: WeakMap<TemporalMiddlewareConfig, ThrottleState>;
|
|
4451
|
+
}>, {}, any, any, ITag<{
|
|
4452
|
+
metadata?: Record<string, any>;
|
|
4453
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4454
|
+
concurrency: IResource<void, Promise<{
|
|
4455
|
+
semaphoresByConfig: WeakMap<ConcurrencyMiddlewareConfig, Semaphore>;
|
|
4456
|
+
semaphoresByKey: Map<string, {
|
|
4457
|
+
semaphore: Semaphore;
|
|
4458
|
+
limit: number;
|
|
4459
|
+
}>;
|
|
4460
|
+
}>, {}, any, any, ITag<{
|
|
4461
|
+
metadata?: Record<string, any>;
|
|
4462
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
2416
4463
|
};
|
|
2417
4464
|
events: {
|
|
2418
4465
|
readonly ready: IEvent<void>;
|
|
@@ -2430,14 +4477,87 @@ declare const globals: {
|
|
|
2430
4477
|
defaultOptions?: any;
|
|
2431
4478
|
}, Promise<{
|
|
2432
4479
|
map: Map<string, ICacheInstance>;
|
|
2433
|
-
cacheFactoryTask: TaskDependencyWithIntercept<any, Promise<ICacheInstance>>;
|
|
4480
|
+
cacheFactoryTask: TaskDependencyWithIntercept<lru_cache.LRUCache.Options<any, any, any>, Promise<ICacheInstance>>;
|
|
2434
4481
|
defaultOptions: any;
|
|
2435
4482
|
}>, {
|
|
2436
|
-
cacheFactoryTask: ITask<any, Promise<ICacheInstance>, any, any, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
4483
|
+
cacheFactoryTask: ITask<lru_cache.LRUCache.Options<any, any, any>, Promise<ICacheInstance>, any, any, TagType[], TaskMiddlewareAttachmentType[]>;
|
|
2437
4484
|
}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4485
|
+
}> & {
|
|
4486
|
+
journalKeys: {
|
|
4487
|
+
readonly hit: JournalKey<boolean>;
|
|
4488
|
+
};
|
|
4489
|
+
};
|
|
4490
|
+
concurrency: ITaskMiddleware<ConcurrencyMiddlewareConfig, void, void, {
|
|
4491
|
+
state: IResource<void, Promise<{
|
|
4492
|
+
semaphoresByConfig: WeakMap<ConcurrencyMiddlewareConfig, Semaphore>;
|
|
4493
|
+
semaphoresByKey: Map<string, {
|
|
4494
|
+
semaphore: Semaphore;
|
|
4495
|
+
limit: number;
|
|
4496
|
+
}>;
|
|
4497
|
+
}>, {}, any, any, ITag<{
|
|
4498
|
+
metadata?: Record<string, any>;
|
|
4499
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4500
|
+
}>;
|
|
4501
|
+
debounce: ITaskMiddleware<TemporalMiddlewareConfig, void, void, {
|
|
4502
|
+
state: IResource<void, Promise<{
|
|
4503
|
+
debounceStates: WeakMap<TemporalMiddlewareConfig, DebounceState>;
|
|
4504
|
+
throttleStates: WeakMap<TemporalMiddlewareConfig, ThrottleState>;
|
|
4505
|
+
}>, {}, any, any, ITag<{
|
|
4506
|
+
metadata?: Record<string, any>;
|
|
4507
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4508
|
+
}>;
|
|
4509
|
+
throttle: ITaskMiddleware<TemporalMiddlewareConfig, void, void, {
|
|
4510
|
+
state: IResource<void, Promise<{
|
|
4511
|
+
debounceStates: WeakMap<TemporalMiddlewareConfig, DebounceState>;
|
|
4512
|
+
throttleStates: WeakMap<TemporalMiddlewareConfig, ThrottleState>;
|
|
4513
|
+
}>, {}, any, any, ITag<{
|
|
4514
|
+
metadata?: Record<string, any>;
|
|
4515
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
2438
4516
|
}>;
|
|
2439
|
-
|
|
2440
|
-
|
|
4517
|
+
fallback: ITaskMiddleware<FallbackMiddlewareConfig, void, void, {
|
|
4518
|
+
taskRunner: IResource<void, Promise<TaskRunner>, {}, any, any, TagType[], ResourceMiddlewareAttachmentType[]>;
|
|
4519
|
+
}> & {
|
|
4520
|
+
journalKeys: {
|
|
4521
|
+
readonly active: JournalKey<boolean>;
|
|
4522
|
+
readonly error: JournalKey<Error>;
|
|
4523
|
+
};
|
|
4524
|
+
};
|
|
4525
|
+
rateLimit: ITaskMiddleware<RateLimitMiddlewareConfig, void, void, {
|
|
4526
|
+
state: IResource<void, Promise<{
|
|
4527
|
+
states: WeakMap<RateLimitMiddlewareConfig, RateLimitState>;
|
|
4528
|
+
}>, {}, any, any, ITag<{
|
|
4529
|
+
metadata?: Record<string, any>;
|
|
4530
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4531
|
+
}> & {
|
|
4532
|
+
journalKeys: {
|
|
4533
|
+
readonly remaining: JournalKey<number>;
|
|
4534
|
+
readonly resetTime: JournalKey<number>;
|
|
4535
|
+
readonly limit: JournalKey<number>;
|
|
4536
|
+
};
|
|
4537
|
+
};
|
|
4538
|
+
retry: ITaskMiddleware<RetryMiddlewareConfig, void, void, any> & {
|
|
4539
|
+
journalKeys: {
|
|
4540
|
+
readonly attempt: JournalKey<number>;
|
|
4541
|
+
readonly lastError: JournalKey<Error>;
|
|
4542
|
+
};
|
|
4543
|
+
};
|
|
4544
|
+
timeout: ITaskMiddleware<TimeoutMiddlewareConfig, void, void, any> & {
|
|
4545
|
+
journalKeys: {
|
|
4546
|
+
readonly abortController: JournalKey<AbortController>;
|
|
4547
|
+
};
|
|
4548
|
+
};
|
|
4549
|
+
circuitBreaker: ITaskMiddleware<CircuitBreakerMiddlewareConfig, void, void, {
|
|
4550
|
+
state: IResource<void, Promise<{
|
|
4551
|
+
statusMap: Map<string, CircuitBreakerStatus>;
|
|
4552
|
+
}>, {}, any, any, ITag<{
|
|
4553
|
+
metadata?: Record<string, any>;
|
|
4554
|
+
}, void, void>[], ResourceMiddlewareAttachmentType[]>;
|
|
4555
|
+
}> & {
|
|
4556
|
+
journalKeys: {
|
|
4557
|
+
readonly state: JournalKey<CircuitBreakerState>;
|
|
4558
|
+
readonly failures: JournalKey<number>;
|
|
4559
|
+
};
|
|
4560
|
+
};
|
|
2441
4561
|
};
|
|
2442
4562
|
resource: {
|
|
2443
4563
|
retry: IResourceMiddleware<RetryMiddlewareConfig, void, void, any>;
|
|
@@ -2454,6 +4574,7 @@ declare const globals: {
|
|
|
2454
4574
|
debug: ITag<DebugFriendlyConfig, void, void>;
|
|
2455
4575
|
tunnel: ITag<void, void, TunnelRunner>;
|
|
2456
4576
|
tunnelPolicy: ITag<TunnelTaskMiddlewarePolicyConfig, void, void>;
|
|
4577
|
+
authValidator: ITag<void, void, void>;
|
|
2457
4578
|
};
|
|
2458
4579
|
tunnels: Readonly<{
|
|
2459
4580
|
http: Readonly<{
|
|
@@ -2469,4 +4590,4 @@ declare const globals: {
|
|
|
2469
4590
|
};
|
|
2470
4591
|
declare function run(root: any, config?: any): Promise<RunResult<any>>;
|
|
2471
4592
|
|
|
2472
|
-
export {
|
|
4593
|
+
export { type BusEvent, type BusEventHandler, type CommonPayload, type DebugConfig, type DebugFriendlyConfig, type DefaultErrorType, type DependencyMapType, DependencyProcessor, type DependencyValueType, type DependencyValuesType, type DurableAuditEmitter, type DurableAuditEntry, type DurableAuditEntryBase, type DurableAuditEntryInput, DurableAuditEntryKind, DurableContext, DurableExecutionError, DurableOperator, DurableResource$1 as DurableResource, type DurableResourceConfig, type DurableResourceRuntimeConfig, DurableService, type DurableServiceConfig, type DurableSignalId, type DurableStepId, type DurableTask, type DurableTestSetup, type DurableTestSetupOptions, DurableWorker, type EmitOptions, type ErrorReference, errors as Errors, type EventDeliveryMode, type EventEmissionInterceptor, type EventHandlerType, EventManager, type EventStoreElementType, type ExecuteOptions, type Execution, type ExecutionJournal, ExecutionStatus, type ExposureFetchAuthConfig, type ExposureFetchClient, type ExposureFetchConfig, type ExtractEventPayload, type ExtractResourceConfig, type ExtractResourceValue, type ExtractTaskInput, type ExtractTaskOutput, type HookExecutionInterceptor, type HookStoreElementType, type HttpClient, type HttpClientAuth, type HttpClientConfig, type HttpClientFactory, type HttpClientFactoryConfig, type HttpSmartClient, type HttpSmartClientAuthConfig, type HttpSmartClientConfig, type IAsyncContext, type IAsyncContextDefinition, type IAsyncContextMeta, type ICacheInstance, type IDurableContext, type IDurableExecutionProcessor, type IDurableResource, type IDurableService, type IDurableStore, type IErrorDefinition, type IErrorDefinitionFinal, type IErrorHelper, type IErrorMeta, type IEvent, type IEventBus, type IEventDefinition, type IEventEmission, type IEventHandlerOptions, type IEventMeta, type IHook, type IHookDefinition, type ILog, type ILogInfo, type IMeta, type IMiddlewareMeta, type IOptionalDependency, type IPhantomTask, type IResource, type IResourceDefinition, type IResourceMeta, type IResourceMiddleware, type IResourceMiddlewareConfigured, type IResourceMiddlewareDefinition, type IResourceMiddlewareExecutionInput, type IResourceWithConfig, type IStepBuilder, type ITag, type ITagConfigured, type ITagDefinition, type ITagMeta, type ITaggable, type ITask, type ITaskDefinition, type ITaskExecutor, type ITaskMeta, type ITaskMiddleware, type ITaskMiddlewareConfigured, type ITaskMiddlewareDefinition, type ITaskMiddlewareExecutionInput, type IValidationSchema, type JournalKey, type JsonLimits, type ListExecutionsOptions, type LogLevels, Logger, MemoryEventBus, MemoryQueue, MemoryStore, MiddlewareManager, type MixedHttpClient, type MixedHttpClientAuthConfig, type MixedHttpClientConfig, type NodeExposureConfig, type NodeExposureDependencyMap, type NodeExposureDeps, type NodeExposureHandlers, type NodeExposureHttpConfig, type NodeExposureHttpCorsConfig, NoopEventBus, type OnUnhandledError, type OnUnhandledErrorInfo, type OverridableElements, PlatformAdapter, type PrintStrategy, Queue, RabbitMQQueue, RedisEventBus, RedisStore, type RegisterableItems, type RequiredKeys, type ResourceDependencyValueType, type ResourceDependencyValuesType, type ResourceInitFn, ResourceInitializer, type ResourceMiddlewareAttachmentType, type ResourceMiddlewareInterceptor, type ResourceMiddlewareStoreElementType, type ResourceStoreElementType, type RunOptions, RunResult, RunnerMode, type Schedule, type ScheduleConfig, type ScheduleOptions, ScheduleStatus, ScheduleType, Semaphore, Serializer, type SerializerOptions, type SignalOptions, type SleepOptions, StepBuilder, type StepOptions, type StepResult, Store, SuspensionSignal, type TagType, type TaskCallOptions, type TaskDependencyWithIntercept, type TaskLocalInterceptor, type TaskMiddlewareAttachmentType, type TaskMiddlewareInterceptor, type TaskMiddlewareStoreElementType, TaskRunner, type TaskStoreElementType, type ThrowsList, type Timer, TimerStatus, TimerType, type TunnelEventSelector, type TunnelMode, type TunnelRunner, type TunnelTagConfig, type TunnelTaskRunner, type TunnelTaskSelector, type TypeDefinition, type UnhandledErrorKind, type UnionToIntersection, allFalse, defineAsyncContext as asyncContext, bindProcessErrorHandler, createContext, createDashboardMiddleware, createDefaultUnhandledError, createDurableAuditEntryId, createDurableRunnerAuditEmitter, createDurableStepId, createDurableTestSetup, createExposureFetch, createHttpClient, createHttpMixedClient, createHttpSmartClient, createNodeFile, createTestResource, debug, debugLevels, defs as definitions, disposeDurableService, durableEvents, durableEventsArray, durableResource, defineEvent as event, getConfig, getDefaultSerializer, globals, hasExposureContext, defineHook as hook, initDurableService, initDurableWorker, isDurableInternalStepId, isOneOf, journal, levelNormal, levelVerbose, nodeExposure, normalizeError, onAnyOf, defineOverride as override, r, readInputFileToBuffer, defineResource as resource, defineResourceMiddleware as resourceMiddleware, run, safeReportUnhandledError, setPlatform, symbolAsyncContext, symbolError, symbolEvent, symbolFilePath, symbolHook, symbolMiddleware, symbolMiddlewareConfigured, symbolOptionalDependency, symbolPhantomTask, symbolResource, symbolResourceMiddleware, symbolResourceWithConfig, symbolTag, symbolTagConfigured, symbolTask, symbolTaskMiddleware, symbolTunneledBy, defineTag as tag, defineTask as task, defineTaskMiddleware as taskMiddleware, useExposureContext, waitUntil, writeInputFileToPath };
|