observed-js 0.1.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/LICENSE +21 -0
- package/README.md +589 -0
- package/dist/actions/index.d.ts +168 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +478 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/scheduler/index.d.ts +60 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js +146 -0
- package/dist/scheduler/index.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
export type ActionEvent<I> = {
|
|
2
|
+
requestId: string;
|
|
3
|
+
payload: I;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Retry configuration options
|
|
7
|
+
*/
|
|
8
|
+
export interface RetryOptions {
|
|
9
|
+
/** Number of retry attempts (0 = no retries) */
|
|
10
|
+
maxRetries: number;
|
|
11
|
+
/** Backoff strategy */
|
|
12
|
+
backoff: 'linear' | 'exponential';
|
|
13
|
+
/** Base delay in milliseconds (default: 100) */
|
|
14
|
+
baseDelay?: number;
|
|
15
|
+
/** Maximum delay cap in milliseconds (default: 30000) */
|
|
16
|
+
maxDelay?: number;
|
|
17
|
+
/** Add randomness to delay to prevent thundering herd (default: false) */
|
|
18
|
+
jitter?: boolean;
|
|
19
|
+
/** Predicate to determine if an error is retryable (default: all errors are retryable) */
|
|
20
|
+
shouldRetry?: (error: unknown) => boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Context object passed to handlers for attaching data
|
|
24
|
+
*/
|
|
25
|
+
export interface InvocationContext {
|
|
26
|
+
/** Unique identifier for this invocation */
|
|
27
|
+
readonly actionId: string;
|
|
28
|
+
/**
|
|
29
|
+
* Attach data to this invocation's wide event
|
|
30
|
+
* Supports both primitives and objects (objects are deep-merged)
|
|
31
|
+
*/
|
|
32
|
+
attach(key: string, value: unknown): void;
|
|
33
|
+
attach(data: Record<string, unknown>): void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Complete wide event record after invocation completes
|
|
37
|
+
*/
|
|
38
|
+
export interface WideEvent<I extends any[], O> {
|
|
39
|
+
/** Unique invocation identifier */
|
|
40
|
+
actionId: string;
|
|
41
|
+
/** Invocation start timestamp (epoch ms) */
|
|
42
|
+
startedAt: number;
|
|
43
|
+
/** Invocation end timestamp (epoch ms) */
|
|
44
|
+
completedAt: number;
|
|
45
|
+
/** Duration in milliseconds */
|
|
46
|
+
duration: number;
|
|
47
|
+
/** Input arguments */
|
|
48
|
+
input: I;
|
|
49
|
+
/** Output value (if successful) */
|
|
50
|
+
output?: O;
|
|
51
|
+
/** Error (if failed) */
|
|
52
|
+
error?: Error;
|
|
53
|
+
/** User-attached data */
|
|
54
|
+
attachments: Record<string, unknown>;
|
|
55
|
+
/** Current retry attempt number (0 = original, 1+ = retry) */
|
|
56
|
+
retryAttempt?: number;
|
|
57
|
+
/** Total attempts made (only present on final event) */
|
|
58
|
+
totalAttempts?: number;
|
|
59
|
+
/** Actual delays used for retries in milliseconds */
|
|
60
|
+
retryDelays?: number[];
|
|
61
|
+
/** True if this is a retry attempt */
|
|
62
|
+
isRetry?: boolean;
|
|
63
|
+
/** True if another retry will be attempted after this failure */
|
|
64
|
+
willRetry?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Callback for receiving wide events
|
|
68
|
+
*/
|
|
69
|
+
export type EventCallback<I extends any[], O> = (event: WideEvent<I, O>) => void | Promise<void>;
|
|
70
|
+
type ActionResult<O> = {
|
|
71
|
+
actionId: string;
|
|
72
|
+
data: Promise<O>;
|
|
73
|
+
eventLogged: Promise<void>;
|
|
74
|
+
};
|
|
75
|
+
type BatchResult<O> = {
|
|
76
|
+
actionId: string;
|
|
77
|
+
index: number;
|
|
78
|
+
data: O;
|
|
79
|
+
error: undefined;
|
|
80
|
+
} | {
|
|
81
|
+
actionId: string;
|
|
82
|
+
index: number;
|
|
83
|
+
data: undefined;
|
|
84
|
+
error: Error;
|
|
85
|
+
};
|
|
86
|
+
type InferInput<T> = T extends (...args: infer P) => any ? P : never;
|
|
87
|
+
type InferOutput<T> = T extends (...args: any[]) => Promise<infer R> ? R : T extends (...args: any[]) => infer R ? R : never;
|
|
88
|
+
export declare class ActionBuilder<I extends any[], O> {
|
|
89
|
+
/** The execution scheduler for concurrency and rate limiting */
|
|
90
|
+
private scheduler;
|
|
91
|
+
/** The user-provided handler function */
|
|
92
|
+
private callbackHandler;
|
|
93
|
+
/** Event callback for wide events */
|
|
94
|
+
private eventCallback?;
|
|
95
|
+
/** Whether this action uses context (set by withContext wrapper) */
|
|
96
|
+
private usesContext;
|
|
97
|
+
/** Retry configuration */
|
|
98
|
+
private retryOptions?;
|
|
99
|
+
constructor(handler: (...args: I) => O | Promise<O>);
|
|
100
|
+
/**
|
|
101
|
+
* Set the maximum number of concurrent executions
|
|
102
|
+
* @param concurrency Max concurrent executions (default: 1 = sequential)
|
|
103
|
+
*/
|
|
104
|
+
setConcurrency(concurrency: number): ActionBuilder<I, O>;
|
|
105
|
+
/**
|
|
106
|
+
* Set the rate limit (max executions per second)
|
|
107
|
+
* @param rateLimit Max executions per second (default: Infinity = no limit)
|
|
108
|
+
*/
|
|
109
|
+
setRateLimit(rateLimit: number): ActionBuilder<I, O>;
|
|
110
|
+
/**
|
|
111
|
+
* Configure retry behavior for failed executions
|
|
112
|
+
* @param options Retry configuration
|
|
113
|
+
*/
|
|
114
|
+
setRetry(options: RetryOptions): ActionBuilder<I, O>;
|
|
115
|
+
/**
|
|
116
|
+
* Register a callback to receive wide events after each invocation
|
|
117
|
+
* @param callback Function to receive wide events
|
|
118
|
+
*/
|
|
119
|
+
onEvent(callback: EventCallback<I, O>): ActionBuilder<I, O>;
|
|
120
|
+
/**
|
|
121
|
+
* Mark this action as using context (internal - called by withContext)
|
|
122
|
+
*/
|
|
123
|
+
private setUsesContext;
|
|
124
|
+
/**
|
|
125
|
+
* Calculate retry delay based on backoff strategy
|
|
126
|
+
*/
|
|
127
|
+
private calculateRetryDelay;
|
|
128
|
+
/**
|
|
129
|
+
* Execute handler with retry logic
|
|
130
|
+
*/
|
|
131
|
+
private executeWithRetry;
|
|
132
|
+
/**
|
|
133
|
+
* Invoke the action with the given payload
|
|
134
|
+
* Returns immediately with actionId and a promise for the result
|
|
135
|
+
*/
|
|
136
|
+
invoke(...payload: I): ActionResult<O>;
|
|
137
|
+
/**
|
|
138
|
+
* Batch invoke - Promise.all style
|
|
139
|
+
* Waits for all invocations to complete and returns results in input order
|
|
140
|
+
* Individual failures don't fail the whole batch
|
|
141
|
+
*/
|
|
142
|
+
invokeAll(payloads: I[]): Promise<BatchResult<O>[]>;
|
|
143
|
+
/**
|
|
144
|
+
* Batch invoke - Async iterator style
|
|
145
|
+
* Yields results as they complete (not in input order)
|
|
146
|
+
* Ideal for processing results as soon as they're available
|
|
147
|
+
*/
|
|
148
|
+
invokeStream(payloads: I[]): AsyncGenerator<BatchResult<O>, void, unknown>;
|
|
149
|
+
/**
|
|
150
|
+
* Get current queue length (useful for monitoring/backpressure)
|
|
151
|
+
*/
|
|
152
|
+
getQueueLength(): number;
|
|
153
|
+
/**
|
|
154
|
+
* Get current active execution count (useful for monitoring)
|
|
155
|
+
*/
|
|
156
|
+
getActiveCount(): number;
|
|
157
|
+
}
|
|
158
|
+
export declare function createAction<T extends (...args: any[]) => any>(handler: T): ActionBuilder<InferInput<T>, InferOutput<T>>;
|
|
159
|
+
/**
|
|
160
|
+
* Wrapper function to enable context for a handler
|
|
161
|
+
* Returns a modified handler that can be used with createAction
|
|
162
|
+
*/
|
|
163
|
+
export declare function withContext<Args extends any[], Output>(handler: (ctx: InvocationContext, ...args: Args) => Output | Promise<Output>): ((...args: Args) => Output | Promise<Output>) & {
|
|
164
|
+
__usesContext: true;
|
|
165
|
+
__originalHandler: typeof handler;
|
|
166
|
+
};
|
|
167
|
+
export {};
|
|
168
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,CAAC,CAAC;CACd,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAC;IACnB,uBAAuB;IACvB,OAAO,EAAE,QAAQ,GAAG,aAAa,CAAC;IAClC,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,0FAA0F;IAC1F,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,4CAA4C;IAC5C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1C,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC/C;AAED;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC;IACzC,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IAEjB,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAElB,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAC;IAEpB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IAEjB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EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;IA8DtC;;;;OAIG;IACG,SAAS,CAAC,QAAQ,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IAsFzD;;;;OAIG;IACI,YAAY,CAAC,QAAQ,EAAE,CAAC,EAAE,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC;IA4EjF;;OAEG;IACH,cAAc,IAAI,MAAM;IAIxB;;OAEG;IACH,cAAc,IAAI,MAAM;CAG3B;AAGD,wBAAgB,YAAY,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAC1D,OAAO,EAAE,CAAC,GACX,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAE9C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,SAAS,GAAG,EAAE,EAAE,MAAM,EAClD,OAAO,EAAE,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAC7E,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG;IAAE,aAAa,EAAE,IAAI,CAAC;IAAC,iBAAiB,EAAE,OAAO,OAAO,CAAA;CAAE,CAW5G"}
|
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import { ExecutionScheduler } from "../scheduler/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Internal implementation of InvocationContext
|
|
4
|
+
*/
|
|
5
|
+
class InvocationContextImpl {
|
|
6
|
+
actionId;
|
|
7
|
+
attachmentsMap = {};
|
|
8
|
+
constructor(actionId) {
|
|
9
|
+
this.actionId = actionId;
|
|
10
|
+
}
|
|
11
|
+
attach(keyOrData, value) {
|
|
12
|
+
if (typeof keyOrData === 'string') {
|
|
13
|
+
// Single key-value pair
|
|
14
|
+
const existingValue = this.attachmentsMap[keyOrData];
|
|
15
|
+
// If both existing and new values are objects, deep merge them
|
|
16
|
+
if (existingValue &&
|
|
17
|
+
typeof existingValue === 'object' &&
|
|
18
|
+
!Array.isArray(existingValue) &&
|
|
19
|
+
value &&
|
|
20
|
+
typeof value === 'object' &&
|
|
21
|
+
!Array.isArray(value)) {
|
|
22
|
+
this.deepMerge(existingValue, value);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// Otherwise just set/overwrite
|
|
26
|
+
this.attachmentsMap[keyOrData] = value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Object - deep merge into root
|
|
31
|
+
this.deepMerge(this.attachmentsMap, keyOrData);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
deepMerge(target, source) {
|
|
35
|
+
for (const key in source) {
|
|
36
|
+
const sourceValue = source[key];
|
|
37
|
+
const targetValue = target[key];
|
|
38
|
+
if (sourceValue &&
|
|
39
|
+
typeof sourceValue === 'object' &&
|
|
40
|
+
!Array.isArray(sourceValue) &&
|
|
41
|
+
targetValue &&
|
|
42
|
+
typeof targetValue === 'object' &&
|
|
43
|
+
!Array.isArray(targetValue)) {
|
|
44
|
+
// Both are objects, recurse
|
|
45
|
+
this.deepMerge(targetValue, sourceValue);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// Overwrite
|
|
49
|
+
target[key] = sourceValue;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
getAttachments() {
|
|
54
|
+
return { ...this.attachmentsMap };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export class ActionBuilder {
|
|
58
|
+
/** The execution scheduler for concurrency and rate limiting */
|
|
59
|
+
scheduler;
|
|
60
|
+
/** The user-provided handler function */
|
|
61
|
+
callbackHandler;
|
|
62
|
+
/** Event callback for wide events */
|
|
63
|
+
eventCallback;
|
|
64
|
+
/** Whether this action uses context (set by withContext wrapper) */
|
|
65
|
+
usesContext = false;
|
|
66
|
+
/** Retry configuration */
|
|
67
|
+
retryOptions;
|
|
68
|
+
constructor(handler) {
|
|
69
|
+
// Check if handler was wrapped with withContext
|
|
70
|
+
if (handler.__usesContext && handler.__originalHandler) {
|
|
71
|
+
this.usesContext = true;
|
|
72
|
+
this.callbackHandler = handler.__originalHandler;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.callbackHandler = handler;
|
|
76
|
+
}
|
|
77
|
+
this.scheduler = new ExecutionScheduler();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Set the maximum number of concurrent executions
|
|
81
|
+
* @param concurrency Max concurrent executions (default: 1 = sequential)
|
|
82
|
+
*/
|
|
83
|
+
setConcurrency(concurrency) {
|
|
84
|
+
this.scheduler.setConcurrency(concurrency);
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Set the rate limit (max executions per second)
|
|
89
|
+
* @param rateLimit Max executions per second (default: Infinity = no limit)
|
|
90
|
+
*/
|
|
91
|
+
setRateLimit(rateLimit) {
|
|
92
|
+
this.scheduler.setRateLimit(rateLimit);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Configure retry behavior for failed executions
|
|
97
|
+
* @param options Retry configuration
|
|
98
|
+
*/
|
|
99
|
+
setRetry(options) {
|
|
100
|
+
// Validate configuration
|
|
101
|
+
if (options.maxRetries < 0) {
|
|
102
|
+
throw new Error('maxRetries must be >= 0');
|
|
103
|
+
}
|
|
104
|
+
if (options.baseDelay !== undefined && options.baseDelay < 0) {
|
|
105
|
+
throw new Error('baseDelay must be >= 0');
|
|
106
|
+
}
|
|
107
|
+
if (options.maxDelay !== undefined && options.maxDelay < 0) {
|
|
108
|
+
throw new Error('maxDelay must be >= 0');
|
|
109
|
+
}
|
|
110
|
+
this.retryOptions = options;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Register a callback to receive wide events after each invocation
|
|
115
|
+
* @param callback Function to receive wide events
|
|
116
|
+
*/
|
|
117
|
+
onEvent(callback) {
|
|
118
|
+
this.eventCallback = callback;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Mark this action as using context (internal - called by withContext)
|
|
123
|
+
*/
|
|
124
|
+
setUsesContext(value) {
|
|
125
|
+
this.usesContext = value;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Calculate retry delay based on backoff strategy
|
|
129
|
+
*/
|
|
130
|
+
calculateRetryDelay(attemptNumber, options) {
|
|
131
|
+
const baseDelay = options.baseDelay ?? 100;
|
|
132
|
+
const maxDelay = options.maxDelay ?? 30000;
|
|
133
|
+
let delay;
|
|
134
|
+
if (options.backoff === 'linear') {
|
|
135
|
+
delay = baseDelay * attemptNumber;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// Exponential backoff
|
|
139
|
+
delay = baseDelay * Math.pow(2, attemptNumber - 1);
|
|
140
|
+
}
|
|
141
|
+
// Apply max delay cap
|
|
142
|
+
delay = Math.min(delay, maxDelay);
|
|
143
|
+
// Apply jitter if enabled
|
|
144
|
+
if (options.jitter) {
|
|
145
|
+
delay = delay * (0.5 + Math.random() * 0.5);
|
|
146
|
+
}
|
|
147
|
+
return Math.floor(delay);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Execute handler with retry logic
|
|
151
|
+
*/
|
|
152
|
+
async executeWithRetry(context, payload, actionId, startedAt, emitIntermediateEvents = false) {
|
|
153
|
+
let result;
|
|
154
|
+
let error;
|
|
155
|
+
const retryDelays = [];
|
|
156
|
+
let attemptNumber = 0;
|
|
157
|
+
const maxAttempts = (this.retryOptions?.maxRetries ?? 0) + 1;
|
|
158
|
+
while (attemptNumber < maxAttempts) {
|
|
159
|
+
const isRetry = attemptNumber > 0;
|
|
160
|
+
try {
|
|
161
|
+
if (this.usesContext) {
|
|
162
|
+
result = await this.callbackHandler(context, ...payload);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
result = await this.callbackHandler(...payload);
|
|
166
|
+
}
|
|
167
|
+
// Success!
|
|
168
|
+
error = undefined;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
error = e;
|
|
173
|
+
const isLastAttempt = attemptNumber === maxAttempts - 1;
|
|
174
|
+
// Determine if we should retry
|
|
175
|
+
let shouldRetry = false;
|
|
176
|
+
if (!isLastAttempt && this.retryOptions) {
|
|
177
|
+
if (this.retryOptions.shouldRetry) {
|
|
178
|
+
try {
|
|
179
|
+
shouldRetry = this.retryOptions.shouldRetry(error);
|
|
180
|
+
}
|
|
181
|
+
catch (predicateError) {
|
|
182
|
+
console.error('Error in shouldRetry predicate:', predicateError);
|
|
183
|
+
shouldRetry = false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
shouldRetry = true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// Fire intermediate event for failed attempt if requested
|
|
191
|
+
if (emitIntermediateEvents && this.eventCallback) {
|
|
192
|
+
const completedAt = Date.now();
|
|
193
|
+
const intermediateEvent = {
|
|
194
|
+
actionId,
|
|
195
|
+
startedAt,
|
|
196
|
+
completedAt,
|
|
197
|
+
duration: completedAt - startedAt,
|
|
198
|
+
input: payload,
|
|
199
|
+
error,
|
|
200
|
+
attachments: context.getAttachments(),
|
|
201
|
+
retryAttempt: attemptNumber,
|
|
202
|
+
isRetry,
|
|
203
|
+
willRetry: shouldRetry,
|
|
204
|
+
retryDelays: [...retryDelays]
|
|
205
|
+
};
|
|
206
|
+
try {
|
|
207
|
+
await this.eventCallback(intermediateEvent);
|
|
208
|
+
}
|
|
209
|
+
catch (callbackError) {
|
|
210
|
+
console.error('Error in event callback:', callbackError);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (!shouldRetry) {
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
// Calculate and apply retry delay
|
|
217
|
+
attemptNumber++;
|
|
218
|
+
if (attemptNumber < maxAttempts) {
|
|
219
|
+
const delay = this.calculateRetryDelay(attemptNumber, this.retryOptions);
|
|
220
|
+
retryDelays.push(delay);
|
|
221
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (!error) {
|
|
226
|
+
return { result: result, retryAttempt: attemptNumber, retryDelays };
|
|
227
|
+
}
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Invoke the action with the given payload
|
|
232
|
+
* Returns immediately with actionId and a promise for the result
|
|
233
|
+
*/
|
|
234
|
+
invoke(...payload) {
|
|
235
|
+
const actionId = crypto.randomUUID();
|
|
236
|
+
const startedAt = Date.now();
|
|
237
|
+
const context = new InvocationContextImpl(actionId);
|
|
238
|
+
let eventLoggedResolve;
|
|
239
|
+
let eventLoggedReject;
|
|
240
|
+
const eventLogged = new Promise((resolve, reject) => {
|
|
241
|
+
eventLoggedResolve = resolve;
|
|
242
|
+
eventLoggedReject = reject;
|
|
243
|
+
});
|
|
244
|
+
const data = this.scheduler.schedule(async () => {
|
|
245
|
+
return await this.executeWithRetry(context, payload, actionId, startedAt, true);
|
|
246
|
+
});
|
|
247
|
+
// Attach handlers to emit the final wide event
|
|
248
|
+
data.then(async (execResult) => {
|
|
249
|
+
// Success path
|
|
250
|
+
const completedAt = Date.now();
|
|
251
|
+
const wideEvent = {
|
|
252
|
+
actionId,
|
|
253
|
+
startedAt,
|
|
254
|
+
completedAt,
|
|
255
|
+
duration: completedAt - startedAt,
|
|
256
|
+
input: payload,
|
|
257
|
+
output: execResult.result,
|
|
258
|
+
attachments: context.getAttachments(),
|
|
259
|
+
retryAttempt: execResult.retryAttempt,
|
|
260
|
+
isRetry: execResult.retryAttempt > 0,
|
|
261
|
+
totalAttempts: execResult.retryAttempt + 1,
|
|
262
|
+
retryDelays: execResult.retryDelays
|
|
263
|
+
};
|
|
264
|
+
// Fire event callback (if registered)
|
|
265
|
+
if (this.eventCallback) {
|
|
266
|
+
try {
|
|
267
|
+
await this.eventCallback(wideEvent);
|
|
268
|
+
eventLoggedResolve();
|
|
269
|
+
}
|
|
270
|
+
catch (callbackError) {
|
|
271
|
+
console.error('Error in event callback:', callbackError);
|
|
272
|
+
eventLoggedReject(callbackError);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
eventLoggedResolve();
|
|
277
|
+
}
|
|
278
|
+
}, async (error) => {
|
|
279
|
+
// Error path - don't emit another event since the last intermediate event
|
|
280
|
+
// already covered the final failure
|
|
281
|
+
eventLoggedResolve();
|
|
282
|
+
});
|
|
283
|
+
return {
|
|
284
|
+
actionId,
|
|
285
|
+
data: data.then(r => r.result),
|
|
286
|
+
eventLogged
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Batch invoke - Promise.all style
|
|
291
|
+
* Waits for all invocations to complete and returns results in input order
|
|
292
|
+
* Individual failures don't fail the whole batch
|
|
293
|
+
*/
|
|
294
|
+
async invokeAll(payloads) {
|
|
295
|
+
if (payloads.length === 0) {
|
|
296
|
+
return [];
|
|
297
|
+
}
|
|
298
|
+
const tasks = payloads.map((payload, index) => {
|
|
299
|
+
const actionId = crypto.randomUUID();
|
|
300
|
+
const startedAt = Date.now();
|
|
301
|
+
const context = new InvocationContextImpl(actionId);
|
|
302
|
+
return {
|
|
303
|
+
actionId,
|
|
304
|
+
index,
|
|
305
|
+
startedAt,
|
|
306
|
+
context,
|
|
307
|
+
promise: this.scheduler.schedule(async () => {
|
|
308
|
+
let result;
|
|
309
|
+
let error;
|
|
310
|
+
let retryAttempt = 0;
|
|
311
|
+
let retryDelays = [];
|
|
312
|
+
try {
|
|
313
|
+
const execResult = await this.executeWithRetry(context, payload, actionId, startedAt, true);
|
|
314
|
+
result = execResult.result;
|
|
315
|
+
retryAttempt = execResult.retryAttempt;
|
|
316
|
+
retryDelays = execResult.retryDelays;
|
|
317
|
+
return result;
|
|
318
|
+
}
|
|
319
|
+
catch (e) {
|
|
320
|
+
error = e;
|
|
321
|
+
throw e;
|
|
322
|
+
}
|
|
323
|
+
finally {
|
|
324
|
+
// Emit final wide event
|
|
325
|
+
const completedAt = Date.now();
|
|
326
|
+
const wideEvent = {
|
|
327
|
+
actionId,
|
|
328
|
+
startedAt,
|
|
329
|
+
completedAt,
|
|
330
|
+
duration: completedAt - startedAt,
|
|
331
|
+
input: payload,
|
|
332
|
+
output: result,
|
|
333
|
+
error,
|
|
334
|
+
attachments: context.getAttachments(),
|
|
335
|
+
...(retryDelays.length > 0 ? {
|
|
336
|
+
retryAttempt,
|
|
337
|
+
isRetry: retryAttempt > 0,
|
|
338
|
+
totalAttempts: retryAttempt + 1,
|
|
339
|
+
retryDelays
|
|
340
|
+
} : {})
|
|
341
|
+
};
|
|
342
|
+
if (this.eventCallback) {
|
|
343
|
+
try {
|
|
344
|
+
await this.eventCallback(wideEvent);
|
|
345
|
+
}
|
|
346
|
+
catch (callbackError) {
|
|
347
|
+
console.error('Error in event callback:', callbackError);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
})
|
|
352
|
+
};
|
|
353
|
+
});
|
|
354
|
+
const settledResults = await Promise.allSettled(tasks.map(t => t.promise));
|
|
355
|
+
return settledResults.map((result, idx) => {
|
|
356
|
+
const task = tasks[idx];
|
|
357
|
+
if (result.status === 'fulfilled') {
|
|
358
|
+
return {
|
|
359
|
+
actionId: task.actionId,
|
|
360
|
+
index: task.index,
|
|
361
|
+
data: result.value,
|
|
362
|
+
error: undefined
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
return {
|
|
367
|
+
actionId: task.actionId,
|
|
368
|
+
index: task.index,
|
|
369
|
+
data: undefined,
|
|
370
|
+
error: result.reason
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Batch invoke - Async iterator style
|
|
377
|
+
* Yields results as they complete (not in input order)
|
|
378
|
+
* Ideal for processing results as soon as they're available
|
|
379
|
+
*/
|
|
380
|
+
async *invokeStream(payloads) {
|
|
381
|
+
if (payloads.length === 0) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
// Create all tasks with tracking info
|
|
385
|
+
const pendingTasks = new Map();
|
|
386
|
+
for (let index = 0; index < payloads.length; index++) {
|
|
387
|
+
const payload = payloads[index];
|
|
388
|
+
const actionId = crypto.randomUUID();
|
|
389
|
+
const startedAt = Date.now();
|
|
390
|
+
const context = new InvocationContextImpl(actionId);
|
|
391
|
+
const taskPromise = this.scheduler.schedule(async () => {
|
|
392
|
+
let result;
|
|
393
|
+
let error;
|
|
394
|
+
let retryAttempt = 0;
|
|
395
|
+
let retryDelays = [];
|
|
396
|
+
try {
|
|
397
|
+
const execResult = await this.executeWithRetry(context, payload, actionId, startedAt, true);
|
|
398
|
+
result = execResult.result;
|
|
399
|
+
retryAttempt = execResult.retryAttempt;
|
|
400
|
+
retryDelays = execResult.retryDelays;
|
|
401
|
+
return result;
|
|
402
|
+
}
|
|
403
|
+
catch (e) {
|
|
404
|
+
error = e;
|
|
405
|
+
throw e;
|
|
406
|
+
}
|
|
407
|
+
finally {
|
|
408
|
+
// Emit final wide event
|
|
409
|
+
const completedAt = Date.now();
|
|
410
|
+
const wideEvent = {
|
|
411
|
+
actionId,
|
|
412
|
+
startedAt,
|
|
413
|
+
completedAt,
|
|
414
|
+
duration: completedAt - startedAt,
|
|
415
|
+
input: payload,
|
|
416
|
+
output: result,
|
|
417
|
+
error,
|
|
418
|
+
attachments: context.getAttachments(),
|
|
419
|
+
...(retryDelays.length > 0 ? {
|
|
420
|
+
retryAttempt,
|
|
421
|
+
isRetry: retryAttempt > 0,
|
|
422
|
+
totalAttempts: retryAttempt + 1,
|
|
423
|
+
retryDelays
|
|
424
|
+
} : {})
|
|
425
|
+
};
|
|
426
|
+
if (this.eventCallback) {
|
|
427
|
+
try {
|
|
428
|
+
await this.eventCallback(wideEvent);
|
|
429
|
+
}
|
|
430
|
+
catch (callbackError) {
|
|
431
|
+
console.error('Error in event callback:', callbackError);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}).then((data) => ({ actionId, index, data, error: undefined }), (error) => ({ actionId, index, data: undefined, error }));
|
|
436
|
+
pendingTasks.set(actionId, taskPromise);
|
|
437
|
+
}
|
|
438
|
+
// Yield results as they complete
|
|
439
|
+
while (pendingTasks.size > 0) {
|
|
440
|
+
// Race all pending tasks
|
|
441
|
+
const result = await Promise.race(pendingTasks.values());
|
|
442
|
+
// Remove completed task and yield result
|
|
443
|
+
pendingTasks.delete(result.actionId);
|
|
444
|
+
yield result;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Get current queue length (useful for monitoring/backpressure)
|
|
449
|
+
*/
|
|
450
|
+
getQueueLength() {
|
|
451
|
+
return this.scheduler.getQueueLength();
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Get current active execution count (useful for monitoring)
|
|
455
|
+
*/
|
|
456
|
+
getActiveCount() {
|
|
457
|
+
return this.scheduler.getActiveCount();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
// Factory function that infers types from the handler
|
|
461
|
+
export function createAction(handler) {
|
|
462
|
+
return new ActionBuilder(handler);
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Wrapper function to enable context for a handler
|
|
466
|
+
* Returns a modified handler that can be used with createAction
|
|
467
|
+
*/
|
|
468
|
+
export function withContext(handler) {
|
|
469
|
+
// Return a wrapper that will be detected by ActionBuilder
|
|
470
|
+
const wrapper = ((...args) => {
|
|
471
|
+
// This will never be called directly - ActionBuilder intercepts it
|
|
472
|
+
throw new Error('withContext handler should not be called directly');
|
|
473
|
+
});
|
|
474
|
+
wrapper.__usesContext = true;
|
|
475
|
+
wrapper.__originalHandler = handler;
|
|
476
|
+
return wrapper;
|
|
477
|
+
}
|
|
478
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAyF3D;;GAEG;AACH,MAAM,qBAAqB;IACd,QAAQ,CAAS;IAClB,cAAc,GAA4B,EAAE,CAAC;IAErD,YAAY,QAAgB;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,SAA2C,EAAE,KAAe;QAC/D,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;YAChC,wBAAwB;YACxB,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;YAErD,+DAA+D;YAC/D,IACI,aAAa;gBACb,OAAO,aAAa,KAAK,QAAQ;gBACjC,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC;gBAC7B,KAAK;gBACL,OAAO,KAAK,KAAK,QAAQ;gBACzB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EACvB,CAAC;gBACC,IAAI,CAAC,SAAS,CAAC,aAAwC,EAAE,KAAgC,CAAC,CAAC;YAC/F,CAAC;iBAAM,CAAC;gBACJ,+BAA+B;gBAC/B,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;YAC3C,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,gCAAgC;YAChC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;QACnD,CAAC;IACL,CAAC;IAEO,SAAS,CAAC,MAA+B,EAAE,MAA+B;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