@hatchet-dev/typescript-sdk 1.0.0-alpha1 → 1.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/clients/admin/admin-client.d.ts +15 -20
- package/clients/admin/admin-client.js +21 -17
- package/clients/hatchet-client/hatchet-client.d.ts +5 -4
- package/clients/hatchet-client/hatchet-client.js +6 -4
- package/clients/listeners/durable-listener/durable-listener-client.d.ts +25 -0
- package/clients/listeners/durable-listener/durable-listener-client.js +30 -0
- package/clients/listeners/durable-listener/pooled-durable-listener-client.d.ts +43 -0
- package/clients/listeners/durable-listener/pooled-durable-listener-client.js +241 -0
- package/clients/{listener/listener-client.d.ts → listeners/run-listener/child-listener-client.d.ts} +8 -8
- package/clients/{listener/listener-client.js → listeners/run-listener/child-listener-client.js} +8 -19
- package/clients/{listener/child-listener-client.d.ts → listeners/run-listener/pooled-child-listener-client.d.ts} +5 -5
- package/clients/{listener/child-listener-client.js → listeners/run-listener/pooled-child-listener-client.js} +5 -5
- package/clients/rest/generated/Api.d.ts +49 -2
- package/clients/rest/generated/Api.js +30 -0
- package/clients/rest/generated/data-contracts.d.ts +88 -82
- package/clients/rest/generated/data-contracts.js +8 -1
- package/clients/worker/worker.d.ts +5 -1
- package/clients/worker/worker.js +173 -2
- package/examples/affinity-workers.js +5 -1
- package/examples/api.js +1 -1
- package/examples/bulk-fanout-worker.js +1 -1
- package/examples/byo-logger.js +4 -0
- package/examples/concurrency/cancel-in-progress/concurrency-event.js +2 -2
- package/examples/concurrency/group-round-robin/concurrency-event.js +1 -1
- package/examples/crons/programatic-crons.js +4 -4
- package/examples/dag-worker.js +0 -1
- package/examples/example-event.js +2 -2
- package/examples/logger.js +2 -0
- package/examples/on-failure.js +1 -1
- package/examples/rate-limit/events.js +3 -3
- package/examples/scheduled-runs/programatic-schedules.js +4 -4
- package/examples/sticky-worker-with-check.js +2 -2
- package/examples/sticky-worker.js +5 -0
- package/index.d.ts +1 -3
- package/index.js +1 -3
- package/package.json +2 -2
- package/protoc/dispatcher/dispatcher.d.ts +2 -0
- package/protoc/dispatcher/dispatcher.js +1 -1
- package/protoc/events/events.js +1 -1
- package/protoc/google/protobuf/timestamp.js +1 -1
- package/protoc/v1/dispatcher.d.ts +77 -0
- package/protoc/v1/dispatcher.js +341 -0
- package/protoc/v1/shared/condition.d.ts +59 -0
- package/protoc/v1/shared/condition.js +549 -0
- package/protoc/v1/workflows.d.ts +263 -0
- package/protoc/v1/workflows.js +1823 -0
- package/protoc/workflows/workflows.js +1 -1
- package/step.d.ts +173 -47
- package/step.js +208 -64
- package/util/sleep.d.ts +7 -0
- package/util/sleep.js +7 -0
- package/util/workflow-run-ref.d.ts +8 -2
- package/util/workflow-run-ref.js +13 -0
- package/v1/client/client.d.ts +125 -7
- package/v1/client/client.interface.d.ts +9 -1
- package/v1/client/client.js +148 -17
- package/v1/client/duration.d.ts +7 -0
- package/v1/client/duration.js +2 -0
- package/v1/client/features/index.d.ts +5 -0
- package/v1/client/features/index.js +21 -0
- package/v1/client/features/metrics.d.ts +14 -0
- package/v1/client/features/metrics.js +45 -0
- package/v1/client/features/ratelimits.d.ts +20 -0
- package/v1/client/features/ratelimits.js +40 -0
- package/v1/client/features/runs.d.ts +15 -0
- package/v1/client/features/runs.js +60 -0
- package/v1/client/features/workers.d.ts +14 -0
- package/v1/client/features/workers.js +56 -0
- package/v1/client/features/workflows.d.ts +17 -0
- package/v1/client/features/workflows.js +93 -0
- package/v1/client/worker.d.ts +25 -15
- package/v1/client/worker.js +76 -47
- package/v1/conditions/base.d.ts +18 -0
- package/v1/conditions/base.js +18 -0
- package/v1/conditions/index.d.ts +31 -0
- package/v1/conditions/index.js +91 -0
- package/v1/conditions/parent-condition.d.ts +40 -0
- package/v1/conditions/parent-condition.js +36 -0
- package/v1/conditions/sleep-condition.d.ts +47 -0
- package/v1/conditions/sleep-condition.js +38 -0
- package/v1/conditions/transformer.d.ts +5 -0
- package/v1/conditions/transformer.js +52 -0
- package/v1/conditions/user-event-condition.d.ts +50 -0
- package/v1/conditions/user-event-condition.js +39 -0
- package/v1/declaration.d.ts +309 -0
- package/v1/declaration.js +296 -0
- package/v1/examples/child_workflows/worker.js +2 -2
- package/v1/examples/child_workflows/workflow.d.ts +2 -2
- package/v1/examples/child_workflows/workflow.js +5 -3
- package/v1/examples/concurrency-rr/load.js +2 -2
- package/v1/examples/concurrency-rr/worker.js +2 -2
- package/v1/examples/concurrency-rr/workflow.d.ts +1 -1
- package/v1/examples/concurrency-rr/workflow.js +2 -3
- package/v1/examples/dag/worker.js +2 -2
- package/v1/examples/dag/workflow.d.ts +1 -1
- package/v1/examples/dag/workflow.js +3 -3
- package/v1/examples/dag_match_condition/event.js +28 -0
- package/v1/examples/dag_match_condition/run.d.ts +1 -0
- package/v1/examples/dag_match_condition/run.js +25 -0
- package/v1/examples/dag_match_condition/worker.d.ts +1 -0
- package/{examples/playground.js → v1/examples/dag_match_condition/worker.js} +7 -22
- package/v1/examples/dag_match_condition/workflow.d.ts +11 -0
- package/v1/examples/dag_match_condition/workflow.js +41 -0
- package/v1/examples/deep/worker.js +2 -2
- package/v1/examples/deep/workflow.d.ts +6 -6
- package/v1/examples/deep/workflow.js +7 -7
- package/v1/examples/durable-sleep/event.d.ts +1 -0
- package/v1/examples/durable-sleep/event.js +28 -0
- package/v1/examples/durable-sleep/run.d.ts +1 -0
- package/v1/examples/durable-sleep/run.js +30 -0
- package/v1/examples/durable-sleep/worker.d.ts +1 -0
- package/v1/examples/durable-sleep/worker.js +24 -0
- package/v1/examples/durable-sleep/workflow.d.ts +1 -0
- package/v1/examples/durable-sleep/workflow.js +37 -0
- package/v1/examples/inferred-typing/run.d.ts +1 -0
- package/v1/examples/inferred-typing/run.js +41 -0
- package/v1/examples/inferred-typing/worker.d.ts +1 -0
- package/v1/examples/inferred-typing/worker.js +24 -0
- package/v1/examples/inferred-typing/workflow.d.ts +15 -0
- package/v1/examples/inferred-typing/workflow.js +44 -0
- package/v1/examples/landing_page/durable-excution.d.ts +3 -0
- package/v1/examples/landing_page/durable-excution.js +40 -0
- package/v1/examples/landing_page/event-signaling.d.ts +6 -0
- package/v1/examples/landing_page/event-signaling.js +16 -0
- package/v1/examples/landing_page/flow-control.d.ts +6 -0
- package/v1/examples/landing_page/flow-control.js +26 -0
- package/v1/examples/landing_page/queues.d.ts +3 -0
- package/v1/examples/landing_page/queues.js +33 -0
- package/v1/examples/landing_page/scheduling.d.ts +1 -0
- package/v1/examples/landing_page/scheduling.js +12 -0
- package/v1/examples/landing_page/task-routing.d.ts +6 -0
- package/v1/examples/landing_page/task-routing.js +25 -0
- package/v1/examples/legacy/run.js +2 -2
- package/v1/examples/legacy/worker.js +2 -2
- package/v1/examples/on_cron/worker.d.ts +1 -0
- package/v1/examples/on_cron/worker.js +24 -0
- package/v1/examples/on_cron/workflow.d.ts +10 -0
- package/v1/examples/on_cron/workflow.js +21 -0
- package/v1/examples/on_event/event.js +3 -2
- package/v1/examples/on_event/worker.js +2 -2
- package/v1/examples/on_event/workflow.d.ts +4 -4
- package/v1/examples/on_event/workflow.js +6 -3
- package/v1/examples/on_event copy/event.d.ts +1 -0
- package/v1/examples/on_event copy/event.js +26 -0
- package/v1/examples/on_event copy/worker.d.ts +1 -0
- package/v1/examples/on_event copy/worker.js +24 -0
- package/v1/examples/on_event copy/workflow.d.ts +16 -0
- package/v1/examples/on_event copy/workflow.js +35 -0
- package/v1/examples/on_failure/worker.js +2 -2
- package/v1/examples/on_failure/workflow.d.ts +1 -1
- package/v1/examples/on_failure/workflow.js +18 -8
- package/v1/examples/on_success/run.d.ts +1 -0
- package/v1/examples/on_success/run.js +31 -0
- package/v1/examples/on_success/worker.d.ts +1 -0
- package/v1/examples/on_success/worker.js +24 -0
- package/v1/examples/on_success/workflow.d.ts +4 -0
- package/v1/examples/on_success/workflow.js +59 -0
- package/v1/examples/retries/run.d.ts +1 -0
- package/v1/examples/retries/run.js +29 -0
- package/v1/examples/retries/worker.d.ts +1 -0
- package/v1/examples/retries/worker.js +24 -0
- package/v1/examples/retries/workflow.d.ts +5 -0
- package/v1/examples/retries/workflow.js +53 -0
- package/v1/examples/simple/client-run.d.ts +1 -0
- package/v1/examples/simple/client-run.js +16 -0
- package/v1/examples/simple/cron.js +6 -2
- package/v1/examples/simple/delay.js +2 -2
- package/v1/examples/simple/enqueue.d.ts +1 -0
- package/v1/examples/simple/enqueue.js +43 -0
- package/v1/examples/simple/run.js +8 -3
- package/v1/examples/simple/schedule.js +11 -5
- package/v1/examples/simple/stub-workflow.d.ts +9 -0
- package/v1/examples/simple/stub-workflow.js +17 -0
- package/v1/examples/simple/worker.js +7 -2
- package/v1/examples/simple/workflow.d.ts +4 -3
- package/v1/examples/simple/workflow.js +5 -5
- package/v1/examples/sticky/run.d.ts +1 -0
- package/v1/examples/sticky/run.js +29 -0
- package/v1/examples/sticky/worker.d.ts +1 -0
- package/v1/examples/sticky/worker.js +24 -0
- package/v1/examples/sticky/workflow.d.ts +7 -0
- package/v1/examples/sticky/workflow.js +32 -0
- package/v1/examples/with_timeouts/workflow.d.ts +9 -0
- package/v1/examples/with_timeouts/workflow.js +62 -0
- package/v1/index.d.ts +5 -0
- package/v1/index.js +20 -0
- package/v1/task.d.ts +144 -14
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/v1/workflow.d.ts +0 -158
- package/v1/workflow.js +0 -145
- /package/{examples/playground.d.ts → v1/examples/dag_match_condition/event.d.ts} +0 -0
- /package/v1/examples/{client.d.ts → hatchet-client.d.ts} +0 -0
- /package/v1/examples/{client.js → hatchet-client.js} +0 -0
package/v1/task.d.ts
CHANGED
|
@@ -1,10 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConcurrencyLimitStrategy } from '../protoc/v1/workflows';
|
|
2
|
+
import { Context, CreateStep, DurableContext } from '../step';
|
|
3
|
+
import { Conditions } from './conditions';
|
|
4
|
+
import { Duration } from './client/duration';
|
|
5
|
+
/**
|
|
6
|
+
* Options for configuring the concurrency for a task.
|
|
7
|
+
*/
|
|
8
|
+
export type TaskConcurrency = {
|
|
9
|
+
/**
|
|
10
|
+
* required the CEL expression to use for concurrency
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```
|
|
14
|
+
* "input.key" // use the value of the key in the input
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
expression: string;
|
|
18
|
+
/**
|
|
19
|
+
* (optional) the maximum number of concurrent workflow runs
|
|
20
|
+
*
|
|
21
|
+
* default: 1
|
|
22
|
+
*/
|
|
23
|
+
maxRuns?: number;
|
|
24
|
+
/**
|
|
25
|
+
* (optional) the strategy to use when the concurrency limit is reached
|
|
26
|
+
*
|
|
27
|
+
* default: CANCEL_IN_PROGRESS
|
|
28
|
+
*/
|
|
29
|
+
limitStrategy?: ConcurrencyLimitStrategy;
|
|
30
|
+
};
|
|
31
|
+
export type TaskFn<T, K> = (input: T, ctx: Context<T>) => K | Promise<K>;
|
|
32
|
+
export type DurableTaskFn<T, K> = (input: T, ctx: DurableContext<T>) => K | Promise<K>;
|
|
2
33
|
/**
|
|
3
34
|
* Options for creating a hatchet task which is an atomic unit of work in a workflow.
|
|
4
35
|
* @template T The input type for the task function.
|
|
5
36
|
* @template K The return type of the task function (can be inferred from the return value of fn).
|
|
6
37
|
*/
|
|
7
|
-
export type
|
|
38
|
+
export type CreateBaseTaskOpts<T, K, C> = {
|
|
8
39
|
/**
|
|
9
40
|
* The name of the task.
|
|
10
41
|
*/
|
|
@@ -15,37 +46,136 @@ export type CreateTaskOpts<T, K> = {
|
|
|
15
46
|
* @param ctx The execution context for the task.
|
|
16
47
|
* @returns The result of the task execution.
|
|
17
48
|
*/
|
|
18
|
-
fn:
|
|
49
|
+
fn: C;
|
|
19
50
|
/**
|
|
20
|
-
*
|
|
21
|
-
* Used to define the directed acyclic graph (DAG) of the workflow.
|
|
51
|
+
* @deprecated use executionTimeout instead
|
|
22
52
|
*/
|
|
23
|
-
|
|
53
|
+
timeout?: CreateStep<T, K>['timeout'];
|
|
24
54
|
/**
|
|
25
|
-
*
|
|
55
|
+
* (optional) execution timeout duration for the task after it starts running
|
|
56
|
+
* go duration format (e.g., "1s", "5m", "1h").
|
|
57
|
+
*
|
|
58
|
+
* default: 60s
|
|
26
59
|
*/
|
|
27
|
-
|
|
60
|
+
executionTimeout?: Duration;
|
|
61
|
+
/**
|
|
62
|
+
* (optional) schedule timeout for the task (max duration to allow the task to wait in the queue)
|
|
63
|
+
* go duration format (e.g., "1s", "5m", "1h").
|
|
64
|
+
*
|
|
65
|
+
* default: 5m
|
|
66
|
+
*/
|
|
67
|
+
scheduleTimeout?: Duration;
|
|
28
68
|
/**
|
|
29
|
-
*
|
|
69
|
+
* (optional) number of retries for the task.
|
|
70
|
+
*
|
|
71
|
+
* default: 0
|
|
30
72
|
*/
|
|
31
73
|
retries?: CreateStep<T, K>['retries'];
|
|
32
74
|
/**
|
|
33
|
-
*
|
|
34
|
-
* - factor:
|
|
75
|
+
* (optional) backoff strategy configuration for retries.
|
|
76
|
+
* - factor: Base of the exponential backoff (base ^ retry count)
|
|
35
77
|
* - maxSeconds: Maximum backoff duration in seconds
|
|
36
78
|
*/
|
|
37
79
|
backoff?: CreateStep<T, K>['backoff'];
|
|
38
80
|
/**
|
|
39
|
-
*
|
|
81
|
+
* (optional) rate limits for the task.
|
|
40
82
|
*/
|
|
41
83
|
rateLimits?: CreateStep<T, K>['rate_limits'];
|
|
42
84
|
/**
|
|
43
|
-
*
|
|
85
|
+
* (optional) worker labels for task routing and scheduling.
|
|
44
86
|
* Each label can be a simple string/number value or an object with additional configuration:
|
|
45
87
|
* - value: The label value (string or number)
|
|
46
88
|
* - required: Whether the label is required for worker matching
|
|
47
89
|
* - weight: Priority weight for worker selection
|
|
48
90
|
* - comparator: Custom comparison logic for label matching
|
|
49
91
|
*/
|
|
50
|
-
|
|
92
|
+
desiredWorkerLabels?: CreateStep<T, K>['worker_labels'];
|
|
93
|
+
/**
|
|
94
|
+
* (optional) the concurrency options for the task
|
|
95
|
+
*/
|
|
96
|
+
concurrency?: TaskConcurrency | TaskConcurrency[];
|
|
51
97
|
};
|
|
98
|
+
export type CreateWorkflowTaskOpts<T, K, C = TaskFn<T, K>> = CreateBaseTaskOpts<T, K, C> & {
|
|
99
|
+
/**
|
|
100
|
+
* Parent tasks that must complete before this task runs.
|
|
101
|
+
* Used to define the directed acyclic graph (DAG) of the workflow.
|
|
102
|
+
*/
|
|
103
|
+
parents?: CreateWorkflowTaskOpts<T, any, any>[];
|
|
104
|
+
/**
|
|
105
|
+
* (optional) the conditions to match before the task is queued
|
|
106
|
+
* all provided conditions must be met (AND logic)
|
|
107
|
+
* use Or() to create a condition that waits for any of the provided conditions to be met (OR logic)
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```
|
|
111
|
+
* waitFor: [{ sleepFor: 5 }, { eventKey: 'user:update' }] // all conditions must be met
|
|
112
|
+
* ```
|
|
113
|
+
* @example
|
|
114
|
+
* ```
|
|
115
|
+
* waitFor: Or({ eventKey: 'user:update' }, { parent: firstTask }) // any of the conditions must be met
|
|
116
|
+
* ```
|
|
117
|
+
* @example
|
|
118
|
+
* ```
|
|
119
|
+
* waitFor: [{ sleepFor: 5 }, Or({ eventKey: 'user:update' }, { eventKey: 'user:delete' })] // sleep or both user:update or user:delete must be met
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
waitFor?: Conditions | Conditions[];
|
|
123
|
+
/**
|
|
124
|
+
* (optional) cancel the task if the conditions are met
|
|
125
|
+
* all provided conditions must be met (AND logic)
|
|
126
|
+
* use Or() to create a condition that waits for any of the provided conditions to be met (OR logic)
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```
|
|
130
|
+
* cancelIf: { eventKey: 'user:update' } // cancel the task if the user:update event is received
|
|
131
|
+
* ```
|
|
132
|
+
* @example
|
|
133
|
+
* ```
|
|
134
|
+
* cancelIf: [{ sleepFor: 5 }, Or({ eventKey: 'user:update' }, { eventKey: 'user:delete' })] // cancel the task if the sleep or both user:update or user:delete are met
|
|
135
|
+
*/
|
|
136
|
+
cancelIf?: Conditions | Conditions[];
|
|
137
|
+
/**
|
|
138
|
+
* (optional) skip the task if the conditions are met
|
|
139
|
+
* all provided conditions must be met (AND logic)
|
|
140
|
+
* use Or() to create a condition that waits for any of the provided conditions to be met (OR logic)
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```
|
|
144
|
+
* skipIf: [{ eventKey: 'user:update' }] // skip the task if the user:update event is received
|
|
145
|
+
* ```
|
|
146
|
+
* @example
|
|
147
|
+
* ```
|
|
148
|
+
* skipIf: [{ sleepFor: 5 }, Or({ eventKey: 'user:update' }, { eventKey: 'user:delete' })] // skip the task if the sleep or both user:update or user:delete are met
|
|
149
|
+
* ```
|
|
150
|
+
* @example
|
|
151
|
+
* ```
|
|
152
|
+
* skipIf: [{ parent: firstTask }] // skip the task if the parent task completes
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
skipIf?: Conditions | Conditions[];
|
|
156
|
+
};
|
|
157
|
+
export type CreateStandaloneTaskOpts<T, K> = CreateBaseTaskOpts<T, K, TaskFn<T, K>>;
|
|
158
|
+
/**
|
|
159
|
+
* Options for creating a hatchet durable task which is an atomic unit of work in a workflow.
|
|
160
|
+
* @template T The input type for the task function.
|
|
161
|
+
* @template K The return type of the task function (can be inferred from the return value of fn).
|
|
162
|
+
*/
|
|
163
|
+
export type CreateWorkflowDurableTaskOpts<T, K> = CreateWorkflowTaskOpts<T, K, DurableTaskFn<T, K>>;
|
|
164
|
+
/**
|
|
165
|
+
* Options for creating a hatchet task which is an atomic unit of work in a workflow.
|
|
166
|
+
* @template T The input type for the task function.
|
|
167
|
+
* @template K The return type of the task function (can be inferred from the return value of fn).
|
|
168
|
+
*/
|
|
169
|
+
export type CreateStandaloneDurableTaskOpts<T, K> = CreateBaseTaskOpts<T, K, DurableTaskFn<T, K>>;
|
|
170
|
+
/**
|
|
171
|
+
* Options for configuring the onSuccess task that is invoked when a task succeeds.
|
|
172
|
+
* @template T The input type for the task function.
|
|
173
|
+
* @template K The return type of the task function (can be inferred from the return value of fn).
|
|
174
|
+
*/
|
|
175
|
+
export type CreateOnSuccessTaskOpts<T, K> = CreateBaseTaskOpts<T, K, TaskFn<T, K>>;
|
|
176
|
+
/**
|
|
177
|
+
* Options for configuring the onFailure task that is invoked when a task fails.
|
|
178
|
+
* @template T The input type for the task function.
|
|
179
|
+
* @template K The return type of the task function (can be inferred from the return value of fn).
|
|
180
|
+
*/
|
|
181
|
+
export type CreateOnFailureTaskOpts<T, K> = CreateBaseTaskOpts<T, K, TaskFn<T, K>>;
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.0.0
|
|
1
|
+
export declare const HATCHET_VERSION = "1.0.0";
|
package/version.js
CHANGED
package/v1/workflow.d.ts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import WorkflowRunRef from '../util/workflow-run-ref';
|
|
2
|
-
import { Context, JsonObject } from '../step';
|
|
3
|
-
import { CronWorkflows, ScheduledWorkflows } from '../clients/rest/generated/data-contracts';
|
|
4
|
-
import { Workflow as WorkflowV0 } from '../workflow';
|
|
5
|
-
import { IHatchetClient } from './client/client.interface';
|
|
6
|
-
import { CreateTaskOpts } from './task';
|
|
7
|
-
/**
|
|
8
|
-
* Additional metadata that can be attached to a workflow run.
|
|
9
|
-
*/
|
|
10
|
-
type AdditionalMetadata = Record<string, string>;
|
|
11
|
-
/**
|
|
12
|
-
* Options for running a workflow.
|
|
13
|
-
*/
|
|
14
|
-
export type RunOpts = {
|
|
15
|
-
/**
|
|
16
|
-
* Additional metadata to attach to the workflow run.
|
|
17
|
-
*/
|
|
18
|
-
additionalMetadata?: AdditionalMetadata;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Extracts a property from an object type based on task name, or falls back to inferred type
|
|
22
|
-
*/
|
|
23
|
-
type TaskOutputType<K, TaskName extends string, InferredType> = TaskName extends keyof K ? K[TaskName] : InferredType;
|
|
24
|
-
/**
|
|
25
|
-
* Options for creating a new workflow.
|
|
26
|
-
*/
|
|
27
|
-
export type CreateWorkflowOpts = {
|
|
28
|
-
/**
|
|
29
|
-
* The name of the workflow.
|
|
30
|
-
*/
|
|
31
|
-
name: WorkflowV0['id'];
|
|
32
|
-
/**
|
|
33
|
-
* (optional) description of the workflow.
|
|
34
|
-
*/
|
|
35
|
-
description?: WorkflowV0['description'];
|
|
36
|
-
/**
|
|
37
|
-
* (optional) version of the workflow.
|
|
38
|
-
*/
|
|
39
|
-
version?: WorkflowV0['version'];
|
|
40
|
-
/**
|
|
41
|
-
* (optional) sticky strategy for the workflow.
|
|
42
|
-
*/
|
|
43
|
-
sticky?: WorkflowV0['sticky'];
|
|
44
|
-
/**
|
|
45
|
-
* (optional) schedule timeout for the workflow.
|
|
46
|
-
*/
|
|
47
|
-
scheduleTimeout?: WorkflowV0['scheduleTimeout'];
|
|
48
|
-
/**
|
|
49
|
-
* (optional) on config for the workflow.
|
|
50
|
-
*/
|
|
51
|
-
on?: WorkflowV0['on'];
|
|
52
|
-
concurrency?: WorkflowV0['concurrency'];
|
|
53
|
-
/**
|
|
54
|
-
* (optional) onFailure handler for the workflow.
|
|
55
|
-
* Invoked when any task in the workflow fails.
|
|
56
|
-
* @param ctx The context of the workflow.
|
|
57
|
-
*/
|
|
58
|
-
onFailure?: (ctx: Context<any>) => void;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Internal definition of a workflow and its tasks.
|
|
62
|
-
*/
|
|
63
|
-
type WorkflowDefinition = CreateWorkflowOpts & {
|
|
64
|
-
/**
|
|
65
|
-
* The tasks that make up this workflow.
|
|
66
|
-
*/
|
|
67
|
-
tasks: CreateTaskOpts<any, any>[];
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Represents a workflow that can be executed by Hatchet.
|
|
71
|
-
* @template T The input type for the workflow.
|
|
72
|
-
* @template K The return type of the workflow.
|
|
73
|
-
*/
|
|
74
|
-
export declare class WorkflowDeclaration<T extends JsonObject, K extends JsonObject> {
|
|
75
|
-
/**
|
|
76
|
-
* The Hatchet client instance used to execute the workflow.
|
|
77
|
-
*/
|
|
78
|
-
client: IHatchetClient | undefined;
|
|
79
|
-
/**
|
|
80
|
-
* The internal workflow definition.
|
|
81
|
-
*/
|
|
82
|
-
definition: WorkflowDefinition;
|
|
83
|
-
/**
|
|
84
|
-
* Creates a new workflow instance.
|
|
85
|
-
* @param options The options for creating the workflow.
|
|
86
|
-
* @param client Optional Hatchet client instance.
|
|
87
|
-
*/
|
|
88
|
-
constructor(options: CreateWorkflowOpts, client?: IHatchetClient);
|
|
89
|
-
/**
|
|
90
|
-
* Triggers a workflow run without waiting for completion.
|
|
91
|
-
* @param input The input data for the workflow.
|
|
92
|
-
* @param options Optional configuration for this workflow run.
|
|
93
|
-
* @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
|
|
94
|
-
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
95
|
-
*/
|
|
96
|
-
enqueue(input: T, options?: RunOpts): WorkflowRunRef<K>;
|
|
97
|
-
/**
|
|
98
|
-
* Executes the workflow with the given input and awaits the results.
|
|
99
|
-
* @param input The input data for the workflow.
|
|
100
|
-
* @param options Optional configuration for this workflow run.
|
|
101
|
-
* @returns A promise that resolves with the workflow result.
|
|
102
|
-
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
103
|
-
*/
|
|
104
|
-
run(input: T, options?: RunOpts): Promise<K>;
|
|
105
|
-
run(input: T[], options?: RunOpts): Promise<K[]>;
|
|
106
|
-
/**
|
|
107
|
-
* Schedules a workflow to run at a specific date and time in the future.
|
|
108
|
-
* @param enqueueAt The date when the workflow should be triggered.
|
|
109
|
-
* @param input The input data for the workflow.
|
|
110
|
-
* @param options Optional configuration for this workflow run.
|
|
111
|
-
* @returns A promise that resolves with the scheduled workflow details.
|
|
112
|
-
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
113
|
-
*/
|
|
114
|
-
schedule(enqueueAt: Date, input: T, options?: RunOpts): Promise<ScheduledWorkflows>;
|
|
115
|
-
/**
|
|
116
|
-
* Schedules a workflow to run after a specified delay.
|
|
117
|
-
* @param duration The delay in seconds before the workflow should run.
|
|
118
|
-
* @param input The input data for the workflow.
|
|
119
|
-
* @param options Optional configuration for this workflow run.
|
|
120
|
-
* @returns A promise that resolves with the scheduled workflow details.
|
|
121
|
-
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
122
|
-
*/
|
|
123
|
-
delay(duration: number, input: T, options?: RunOpts): Promise<ScheduledWorkflows>;
|
|
124
|
-
/**
|
|
125
|
-
* Creates a cron schedule for the workflow.
|
|
126
|
-
* @param name The name of the cron schedule.
|
|
127
|
-
* @param expression The cron expression defining the schedule.
|
|
128
|
-
* @param input The input data for the workflow.
|
|
129
|
-
* @param options Optional configuration for this workflow run.
|
|
130
|
-
* @returns A promise that resolves with the cron workflow details.
|
|
131
|
-
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
132
|
-
*/
|
|
133
|
-
cron(name: string, expression: string, input: T, options?: RunOpts): Promise<CronWorkflows>;
|
|
134
|
-
/**
|
|
135
|
-
* Adds a task to the workflow.
|
|
136
|
-
* The return type will be either the property on K that corresponds to the task name,
|
|
137
|
-
* or if there is no matching property, the inferred return type of the function.
|
|
138
|
-
* @template Name The literal string name of the task.
|
|
139
|
-
* @template L The inferred return type of the task function.
|
|
140
|
-
* @param options The task configuration options.
|
|
141
|
-
* @returns The task options that were added.
|
|
142
|
-
*/
|
|
143
|
-
task<Name extends string, L>(options: Omit<CreateTaskOpts<T, TaskOutputType<K, Name, L>>, 'fn'> & {
|
|
144
|
-
name: Name;
|
|
145
|
-
fn: (input: T, ctx: Context<T>) => TaskOutputType<K, Name, L> | Promise<TaskOutputType<K, Name, L>>;
|
|
146
|
-
}): CreateTaskOpts<T, TaskOutputType<K, Name, L>>;
|
|
147
|
-
get id(): string;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Creates a new workflow instance.
|
|
151
|
-
* @template T The input type for the workflow.
|
|
152
|
-
* @template K The return type of the workflow.
|
|
153
|
-
* @param options The options for creating the workflow.
|
|
154
|
-
* @param client Optional Hatchet client instance.
|
|
155
|
-
* @returns A new Workflow instance.
|
|
156
|
-
*/
|
|
157
|
-
export declare function CreateWorkflow<T extends JsonObject = any, K extends JsonObject = any>(options: CreateWorkflowOpts, client?: IHatchetClient): WorkflowDeclaration<T, K>;
|
|
158
|
-
export {};
|
package/v1/workflow.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.WorkflowDeclaration = void 0;
|
|
13
|
-
exports.CreateWorkflow = CreateWorkflow;
|
|
14
|
-
const UNBOUND_ERR = new Error('workflow unbound to hatchet client, hint: use client.run instead');
|
|
15
|
-
/**
|
|
16
|
-
* Represents a workflow that can be executed by Hatchet.
|
|
17
|
-
* @template T The input type for the workflow.
|
|
18
|
-
* @template K The return type of the workflow.
|
|
19
|
-
*/
|
|
20
|
-
class WorkflowDeclaration {
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new workflow instance.
|
|
23
|
-
* @param options The options for creating the workflow.
|
|
24
|
-
* @param client Optional Hatchet client instance.
|
|
25
|
-
*/
|
|
26
|
-
constructor(options, client) {
|
|
27
|
-
this.definition = Object.assign(Object.assign({}, options), { tasks: [] });
|
|
28
|
-
this.client = client;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Triggers a workflow run without waiting for completion.
|
|
32
|
-
* @param input The input data for the workflow.
|
|
33
|
-
* @param options Optional configuration for this workflow run.
|
|
34
|
-
* @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
|
|
35
|
-
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
36
|
-
*/
|
|
37
|
-
enqueue(input, options) {
|
|
38
|
-
if (!this.client) {
|
|
39
|
-
throw UNBOUND_ERR;
|
|
40
|
-
}
|
|
41
|
-
return this.client.v0.admin.runWorkflow(this.definition.name, input, options);
|
|
42
|
-
}
|
|
43
|
-
run(input, options) {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
if (!this.client) {
|
|
46
|
-
throw UNBOUND_ERR;
|
|
47
|
-
}
|
|
48
|
-
if (Array.isArray(input)) {
|
|
49
|
-
// FIXME use bulk endpoint?
|
|
50
|
-
return Promise.all(input.map((i) => this.run(i, options)));
|
|
51
|
-
}
|
|
52
|
-
const res = this.client.v0.admin.runWorkflow(this.definition.name, input, options);
|
|
53
|
-
return res.result();
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Schedules a workflow to run at a specific date and time in the future.
|
|
58
|
-
* @param enqueueAt The date when the workflow should be triggered.
|
|
59
|
-
* @param input The input data for the workflow.
|
|
60
|
-
* @param options Optional configuration for this workflow run.
|
|
61
|
-
* @returns A promise that resolves with the scheduled workflow details.
|
|
62
|
-
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
63
|
-
*/
|
|
64
|
-
schedule(enqueueAt, input, options) {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
if (!this.client) {
|
|
67
|
-
throw UNBOUND_ERR;
|
|
68
|
-
}
|
|
69
|
-
const scheduled = this.client.v0.schedule.create(this.definition.name, {
|
|
70
|
-
triggerAt: enqueueAt,
|
|
71
|
-
input,
|
|
72
|
-
additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata,
|
|
73
|
-
});
|
|
74
|
-
return scheduled;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Schedules a workflow to run after a specified delay.
|
|
79
|
-
* @param duration The delay in seconds before the workflow should run.
|
|
80
|
-
* @param input The input data for the workflow.
|
|
81
|
-
* @param options Optional configuration for this workflow run.
|
|
82
|
-
* @returns A promise that resolves with the scheduled workflow details.
|
|
83
|
-
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
84
|
-
*/
|
|
85
|
-
delay(duration, input, options) {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
const now = Date.now();
|
|
88
|
-
const triggerAt = new Date(now + duration * 1000);
|
|
89
|
-
return this.schedule(triggerAt, input, options);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Creates a cron schedule for the workflow.
|
|
94
|
-
* @param name The name of the cron schedule.
|
|
95
|
-
* @param expression The cron expression defining the schedule.
|
|
96
|
-
* @param input The input data for the workflow.
|
|
97
|
-
* @param options Optional configuration for this workflow run.
|
|
98
|
-
* @returns A promise that resolves with the cron workflow details.
|
|
99
|
-
* @throws Error if the workflow is not bound to a Hatchet client.
|
|
100
|
-
*/
|
|
101
|
-
cron(name, expression, input, options) {
|
|
102
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
if (!this.client) {
|
|
104
|
-
throw UNBOUND_ERR;
|
|
105
|
-
}
|
|
106
|
-
const cronDef = this.client.v0.cron.create(this.definition.name, {
|
|
107
|
-
expression,
|
|
108
|
-
input,
|
|
109
|
-
additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata,
|
|
110
|
-
name,
|
|
111
|
-
});
|
|
112
|
-
return cronDef;
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Adds a task to the workflow.
|
|
117
|
-
* The return type will be either the property on K that corresponds to the task name,
|
|
118
|
-
* or if there is no matching property, the inferred return type of the function.
|
|
119
|
-
* @template Name The literal string name of the task.
|
|
120
|
-
* @template L The inferred return type of the task function.
|
|
121
|
-
* @param options The task configuration options.
|
|
122
|
-
* @returns The task options that were added.
|
|
123
|
-
*/
|
|
124
|
-
task(options) {
|
|
125
|
-
const typedOptions = options;
|
|
126
|
-
this.definition.tasks.push(typedOptions);
|
|
127
|
-
return typedOptions;
|
|
128
|
-
}
|
|
129
|
-
// @deprecated use definition.name instead
|
|
130
|
-
get id() {
|
|
131
|
-
return this.definition.name;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
exports.WorkflowDeclaration = WorkflowDeclaration;
|
|
135
|
-
/**
|
|
136
|
-
* Creates a new workflow instance.
|
|
137
|
-
* @template T The input type for the workflow.
|
|
138
|
-
* @template K The return type of the workflow.
|
|
139
|
-
* @param options The options for creating the workflow.
|
|
140
|
-
* @param client Optional Hatchet client instance.
|
|
141
|
-
* @returns A new Workflow instance.
|
|
142
|
-
*/
|
|
143
|
-
function CreateWorkflow(options, client) {
|
|
144
|
-
return new WorkflowDeclaration(options, client);
|
|
145
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|