@usehelical/workflows 0.0.1-alpha.14 → 0.0.1-alpha.16
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 +661 -0
- package/README.md +0 -111
- package/dist/api.d.ts +45 -0
- package/dist/{workflows.js → api.js} +32 -167
- package/dist/api.js.map +1 -0
- package/dist/chunk-HRDI7EOY.js +441 -0
- package/dist/chunk-HRDI7EOY.js.map +1 -0
- package/dist/index.d.ts +165 -17
- package/dist/index.js +710 -195
- package/dist/index.js.map +1 -1
- package/dist/state-DygxhGtl.d.ts +49 -0
- package/package.json +5 -4
- package/dist/chunk-2CPBPIZ7.js +0 -725
- package/dist/chunk-2CPBPIZ7.js.map +0 -1
- package/dist/run-BCTOgHFp.d.ts +0 -70
- package/dist/workflows.d.ts +0 -66
- package/dist/workflows.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,173 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { R as RunStatus, W as WorkflowDefinition, Q as QueueDefinition, a as WorkflowSignature, M as MessageDefinition, S as StateDefinition } from './state-DygxhGtl.js';
|
|
2
|
+
|
|
3
|
+
declare enum ErrorType {
|
|
4
|
+
INVALID_WORKFLOW_TRANSITION = "INVALID_WORKFLOW_TRANSITION",
|
|
5
|
+
RUN_CANCELLED = "RUN_CANCELLED",
|
|
6
|
+
RUN_NOT_FOUND = "RUN_NOT_FOUND",
|
|
7
|
+
RUN_OUTSIDE_OF_WORKFLOW = "RUN_OUTSIDE_OF_WORKFLOW",
|
|
8
|
+
FATAL_ERROR = "FATAL_ERROR",
|
|
9
|
+
NO_MESSAGE_AVAILABLE = "NO_MESSAGE_AVAILABLE",
|
|
10
|
+
MAX_RETRIES_EXCEEDED = "MAX_RETRIES_EXCEEDED",
|
|
11
|
+
ERROR_THAT_SHOULD_NEVER_HAPPEN = "ERROR_THAT_SHOULD_NEVER_HAPPEN",
|
|
12
|
+
SERIALIZATION_ERROR = "SERIALIZATION_ERROR",
|
|
13
|
+
MAX_RECOVERY_ATTEMPTS_EXCEEDED = "MAX_RECOVERY_ATTEMPTS_EXCEEDED",
|
|
14
|
+
WORKFLOW_NOT_FOUND = "WORKFLOW_NOT_FOUND",
|
|
15
|
+
TIMEOUT = "TIMEOUT",
|
|
16
|
+
CANCEL = "CANCEL",
|
|
17
|
+
DEADLINE = "DEADLINE",
|
|
18
|
+
RUN_NOT_CANCELLABLE = "RUN_NOT_CANCELLABLE",
|
|
19
|
+
QUEUE_NOT_FOUND = "QUEUE_NOT_FOUND"
|
|
20
|
+
}
|
|
21
|
+
type ErrorReason = 'timeout' | 'deadline' | 'cancel' | 'unhandled' | 'max_recovery_attempts_exceeded' | 'workflow_not_found' | 'unknown' | 'run_not_found' | 'outside_workflow_context' | 'fatal_error' | 'max_retries_exceeded' | 'serialization_error';
|
|
22
|
+
declare class BaseError extends Error {
|
|
23
|
+
readonly reason: ErrorReason;
|
|
24
|
+
constructor(message: string, reason: ErrorReason);
|
|
25
|
+
}
|
|
26
|
+
declare class RunTimedOutError extends BaseError {
|
|
27
|
+
constructor();
|
|
28
|
+
}
|
|
29
|
+
declare class UnknownError extends BaseError {
|
|
30
|
+
constructor(message?: string);
|
|
31
|
+
}
|
|
32
|
+
declare class RunDeadlineExceededError extends BaseError {
|
|
33
|
+
constructor();
|
|
34
|
+
}
|
|
35
|
+
declare class RunCancelledError extends BaseError {
|
|
36
|
+
constructor();
|
|
37
|
+
}
|
|
38
|
+
declare class MaxRecoveryAttemptsExceededError extends BaseError {
|
|
39
|
+
constructor(runId: string, attempts: number);
|
|
40
|
+
}
|
|
41
|
+
declare class OperationTimedOutError extends BaseError {
|
|
42
|
+
constructor(operationName: string);
|
|
43
|
+
}
|
|
44
|
+
declare class RunNotFoundError extends BaseError {
|
|
45
|
+
constructor(runId: string);
|
|
46
|
+
}
|
|
47
|
+
declare class RunOutsideOfWorkflowError extends BaseError {
|
|
48
|
+
constructor();
|
|
49
|
+
}
|
|
50
|
+
declare class FatalError extends BaseError {
|
|
51
|
+
constructor(message: string);
|
|
52
|
+
}
|
|
53
|
+
declare class MaxRetriesExceededError extends BaseError {
|
|
54
|
+
readonly attemptErrors: Error[];
|
|
55
|
+
readonly stepName: string;
|
|
56
|
+
readonly maxAttempts: number;
|
|
57
|
+
constructor(stepName: string, maxAttempts: number, errors: Error[]);
|
|
58
|
+
}
|
|
59
|
+
declare class SerializationError extends BaseError {
|
|
60
|
+
constructor(message: string);
|
|
61
|
+
}
|
|
62
|
+
declare class WorkflowNotFoundError extends BaseError {
|
|
63
|
+
constructor(workflowName: string);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type RunResult<TReturn> = {
|
|
67
|
+
error: BaseError | Error;
|
|
68
|
+
success: false;
|
|
69
|
+
} | {
|
|
70
|
+
data: TReturn;
|
|
71
|
+
success: true;
|
|
72
|
+
};
|
|
73
|
+
interface Run<TReturn = unknown> {
|
|
74
|
+
id: string;
|
|
75
|
+
getStatus: () => Promise<RunStatus>;
|
|
76
|
+
waitForResult: () => Promise<RunResult<TReturn>>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type RunWorkflowOptions = {
|
|
80
|
+
timeout?: number;
|
|
81
|
+
deadline?: number;
|
|
82
|
+
id?: string;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
type QueueWorkflowOptions = {
|
|
86
|
+
timeout?: number;
|
|
87
|
+
deadline?: number;
|
|
88
|
+
priority?: number;
|
|
89
|
+
partitionKey?: string;
|
|
90
|
+
id?: string;
|
|
91
|
+
deduplicationId?: string;
|
|
92
|
+
};
|
|
2
93
|
|
|
3
94
|
type CreateInstanceOptions = {
|
|
4
95
|
instanceId?: string;
|
|
5
96
|
connectionString: string;
|
|
6
97
|
};
|
|
7
|
-
type
|
|
8
|
-
workflows:
|
|
9
|
-
queues?:
|
|
98
|
+
type createExecutorParams<TWorkflows extends Array<WorkflowDefinition<unknown[], unknown>>, TQueues extends Array<QueueDefinition>> = {
|
|
99
|
+
workflows: TWorkflows;
|
|
100
|
+
queues?: TQueues;
|
|
10
101
|
options: CreateInstanceOptions;
|
|
11
102
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
103
|
+
type ExtractNames<T extends readonly {
|
|
104
|
+
name: string;
|
|
105
|
+
}[]> = T[number]['name'];
|
|
106
|
+
interface WorkflowOperations<TWorkflows extends readonly WorkflowSignature<unknown[], unknown>[], TQueues extends readonly QueueDefinition[]> {
|
|
107
|
+
queueWorkflow<TQueue extends Extract<TQueues[number], {
|
|
108
|
+
name: ExtractNames<TQueues>;
|
|
109
|
+
}> = Extract<TQueues[number], {
|
|
110
|
+
name: ExtractNames<TQueues>;
|
|
111
|
+
}>, TWorkflow extends Extract<TWorkflows[number], {
|
|
112
|
+
name: ExtractNames<TWorkflows>;
|
|
113
|
+
}> = Extract<TWorkflows[number], {
|
|
114
|
+
name: ExtractNames<TWorkflows>;
|
|
115
|
+
}>, TArgs extends unknown[] = TWorkflow extends WorkflowSignature<infer A extends unknown[], unknown> ? A : never, TReturn = TWorkflow extends WorkflowSignature<unknown[], infer R> ? R : never>(queue: TQueue, wf: TWorkflow, args: TArgs, options?: QueueWorkflowOptions): Promise<Run<TReturn>>;
|
|
116
|
+
queueWorkflow<QK extends ExtractNames<TQueues>, WK extends ExtractNames<TWorkflows>, TWorkflow extends Extract<TWorkflows[number], {
|
|
117
|
+
name: WK;
|
|
118
|
+
}> = Extract<TWorkflows[number], {
|
|
119
|
+
name: WK;
|
|
120
|
+
}>, TReturn = TWorkflow extends WorkflowSignature<unknown[], infer R> ? R : never>(queue: QK, wf: WK, options: QueueWorkflowOptions): Promise<Run<TReturn>>;
|
|
121
|
+
queueWorkflow<QK extends ExtractNames<TQueues>, WK extends ExtractNames<TWorkflows>, TWorkflow extends Extract<TWorkflows[number], {
|
|
122
|
+
name: WK;
|
|
123
|
+
}> = Extract<TWorkflows[number], {
|
|
124
|
+
name: WK;
|
|
125
|
+
}>, TReturn = TWorkflow extends WorkflowSignature<unknown[], infer R> ? R : never>(queue: QK, wf: WK): Promise<Run<TReturn>>;
|
|
126
|
+
cancelRun(runId: string): Promise<void>;
|
|
127
|
+
resumeRun(runId: string): Promise<void>;
|
|
128
|
+
getRun<TWorkflow extends WorkflowSignature<unknown[], unknown>>(runId: string): Promise<Run<TWorkflow extends WorkflowSignature<unknown[], infer R> ? R : never>>;
|
|
129
|
+
getRun<TReturn>(runId: string): Promise<Run<TReturn>>;
|
|
130
|
+
getRunStatus(runId: string): Promise<string>;
|
|
131
|
+
waitForRunResult<TWorkflow extends WorkflowSignature<unknown[], unknown>>(runId: string): Promise<RunResult<TWorkflow extends WorkflowSignature<unknown[], infer R> ? R : never>>;
|
|
132
|
+
waitForRunResult<TReturn>(runId: string): Promise<RunResult<TReturn>>;
|
|
133
|
+
sendMessage<T>(target: Run | string, name: MessageDefinition<T>, data: T): Promise<void>;
|
|
134
|
+
getState<T>(target: Run | string, key: StateDefinition<T> | string): Promise<T | undefined>;
|
|
135
|
+
}
|
|
136
|
+
interface Executor<TWorkflows extends Array<WorkflowDefinition<unknown[], unknown>>, TQueues extends Array<QueueDefinition>> extends WorkflowOperations<TWorkflows, TQueues> {
|
|
137
|
+
runWorkflow<TWorkflow extends WorkflowDefinition<any[], any> & {
|
|
138
|
+
name: ExtractNames<TWorkflows>;
|
|
139
|
+
}, TReturn = TWorkflow extends WorkflowDefinition<any[], infer R> ? R : never>(wf: TWorkflow): Promise<Run<TReturn>>;
|
|
140
|
+
runWorkflow<TWorkflow extends WorkflowDefinition<any[], any> & {
|
|
141
|
+
name: ExtractNames<TWorkflows>;
|
|
142
|
+
}, TReturn = TWorkflow extends WorkflowDefinition<any[], infer R> ? R : never>(wf: TWorkflow, options: RunWorkflowOptions): Promise<Run<TReturn>>;
|
|
143
|
+
runWorkflow<TWorkflow extends WorkflowDefinition<any[], any> & {
|
|
144
|
+
name: ExtractNames<TWorkflows>;
|
|
145
|
+
}, TArgs extends any[] = TWorkflow extends WorkflowDefinition<infer A extends unknown[], unknown> ? A : never, TReturn = TWorkflow extends WorkflowDefinition<any[], infer R> ? R : never>(wf: TWorkflow, args: TArgs, options?: RunWorkflowOptions): Promise<Run<TReturn>>;
|
|
146
|
+
}
|
|
147
|
+
declare function createExecutor<TWorkflows extends Array<WorkflowDefinition<any[], any>>, TQueues extends Array<QueueDefinition>>(props: createExecutorParams<TWorkflows, TQueues>): Executor<TWorkflows, TQueues>;
|
|
148
|
+
type Instance = ReturnType<typeof createExecutor>;
|
|
149
|
+
|
|
150
|
+
type ExtractWorkflows<T> = T extends Executor<infer W, any> ? W : never;
|
|
151
|
+
type ExtractQueues<T> = T extends Executor<any, infer Q> ? Q : never;
|
|
152
|
+
type QueuesProxy<TQueues extends Record<string, QueueDefinition>> = {
|
|
153
|
+
[K in keyof TQueues]: {
|
|
154
|
+
name: K;
|
|
155
|
+
definition: TQueues[K];
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
type WorkflowsProxy<TWorkflows extends Record<string, WorkflowDefinition<unknown[], unknown>>> = {
|
|
159
|
+
[K in keyof TWorkflows]: {
|
|
160
|
+
name: K;
|
|
161
|
+
definition: TWorkflows[K];
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
interface Client<TWorkflows extends Record<string, WorkflowDefinition<unknown[], unknown>>, TQueues extends Record<string, QueueDefinition>> extends WorkflowOperations<ExtractWorkflows<TWorkflows>, ExtractQueues<TQueues>> {
|
|
165
|
+
workflows: WorkflowsProxy<TWorkflows>;
|
|
166
|
+
queues: QueuesProxy<TQueues>;
|
|
167
|
+
}
|
|
168
|
+
type ClientOptions = {
|
|
169
|
+
connectionString: string;
|
|
170
|
+
};
|
|
171
|
+
declare function createClient<TExecutor extends Executor<any, any>>(options: ClientOptions): Client<ExtractWorkflows<TExecutor>, ExtractQueues<TExecutor>>;
|
|
24
172
|
|
|
25
|
-
export { type
|
|
173
|
+
export { BaseError, type ErrorReason, ErrorType, type Executor, FatalError, type Instance, MaxRecoveryAttemptsExceededError, MaxRetriesExceededError, OperationTimedOutError, RunCancelledError, RunDeadlineExceededError, RunNotFoundError, RunOutsideOfWorkflowError, RunTimedOutError, SerializationError, UnknownError, WorkflowNotFoundError, type WorkflowOperations, createClient, createExecutor, type createExecutorParams };
|