@hatchet-dev/typescript-sdk 1.14.0 → 1.15.1
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 +9 -1
- package/clients/admin/admin-client.js +20 -4
- package/legacy/step.d.ts +12 -12
- package/legacy/workflow.d.ts +36 -36
- package/package.json +4 -3
- package/protoc/v1/workflows.d.ts +8 -0
- package/protoc/v1/workflows.js +109 -2
- package/protoc/workflows/workflows.d.ts +9 -0
- package/protoc/workflows/workflows.js +109 -2
- package/v1/client/admin.d.ts +10 -1
- package/v1/client/admin.js +20 -4
- package/v1/client/client.d.ts +19 -1
- package/v1/client/client.js +19 -1
- package/v1/client/features/crons.d.ts +3 -1
- package/v1/client/features/crons.js +2 -1
- package/v1/client/features/filters.d.ts +30 -0
- package/v1/client/features/filters.js +30 -0
- package/v1/client/features/metrics.d.ts +10 -6
- package/v1/client/features/metrics.js +10 -6
- package/v1/client/features/ratelimits.d.ts +11 -1
- package/v1/client/features/ratelimits.js +11 -1
- package/v1/client/features/runs.d.ts +36 -1
- package/v1/client/features/runs.js +36 -1
- package/v1/client/features/schedules.d.ts +4 -1
- package/v1/client/features/schedules.js +3 -1
- package/v1/client/features/tenant.d.ts +3 -0
- package/v1/client/features/webhooks.d.ts +30 -4
- package/v1/client/features/webhooks.js +30 -4
- package/v1/client/features/workers.d.ts +25 -1
- package/v1/client/features/workers.js +25 -1
- package/v1/client/features/workflows.d.ts +19 -1
- package/v1/client/features/workflows.js +19 -1
- package/v1/client/worker/context.d.ts +21 -0
- package/v1/client/worker/context.js +21 -0
- package/v1/declaration.d.ts +89 -5
- package/v1/declaration.js +62 -4
- package/v1/examples/runtime_affinity/workflow.d.ts +3 -0
- package/v1/examples/runtime_affinity/workflow.js +19 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -11,31 +11,50 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.WorkersClient = void 0;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* The workers client is a client for managing workers programmatically within Hatchet.
|
|
15
15
|
*/
|
|
16
16
|
class WorkersClient {
|
|
17
17
|
constructor(client) {
|
|
18
18
|
this.api = client.api;
|
|
19
19
|
this.tenantId = client.tenantId;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Get a worker by its ID.
|
|
23
|
+
* @param workerId - The ID of the worker to get.
|
|
24
|
+
* @returns A promise that resolves to the worker.
|
|
25
|
+
*/
|
|
21
26
|
get(workerId) {
|
|
22
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
28
|
const { data } = yield this.api.workerGet(workerId);
|
|
24
29
|
return data;
|
|
25
30
|
});
|
|
26
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* List all workers in the tenant.
|
|
34
|
+
* @returns A promise that resolves to the list of workers.
|
|
35
|
+
*/
|
|
27
36
|
list() {
|
|
28
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
38
|
const { data } = yield this.api.workerList(this.tenantId);
|
|
30
39
|
return data;
|
|
31
40
|
});
|
|
32
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Check if a worker is paused.
|
|
44
|
+
* @param workerId - The ID of the worker to check.
|
|
45
|
+
* @returns A promise that resolves to true if the worker is paused, false otherwise.
|
|
46
|
+
*/
|
|
33
47
|
isPaused(workerId) {
|
|
34
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
49
|
const wf = yield this.get(workerId);
|
|
36
50
|
return wf.status === 'PAUSED';
|
|
37
51
|
});
|
|
38
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Pause a worker.
|
|
55
|
+
* @param workerId - The ID of the worker to pause.
|
|
56
|
+
* @returns A promise that resolves to the paused worker.
|
|
57
|
+
*/
|
|
39
58
|
pause(workerId) {
|
|
40
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
60
|
const { data } = yield this.api.workerUpdate(workerId, {
|
|
@@ -44,6 +63,11 @@ class WorkersClient {
|
|
|
44
63
|
return data;
|
|
45
64
|
});
|
|
46
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Unpause a worker.
|
|
68
|
+
* @param workerId - The ID of the worker to unpause.
|
|
69
|
+
* @returns A promise that resolves to the unpaused worker.
|
|
70
|
+
*/
|
|
47
71
|
unpause(workerId) {
|
|
48
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
73
|
const { data } = yield this.api.workerUpdate(workerId, {
|
|
@@ -3,7 +3,10 @@ import type { LegacyWorkflow } from '../../../legacy/legacy-transformer';
|
|
|
3
3
|
import { HatchetClient } from '../client';
|
|
4
4
|
export declare const workflowNameString: (workflow: string | WorkflowDefinition | BaseWorkflowDeclaration<any, any> | LegacyWorkflow) => string;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* The workflows client is a client for managing workflows programmatically within Hatchet.
|
|
7
|
+
*
|
|
8
|
+
* NOTE: that workflows are the declaration, not the individual runs. If you're looking for runs, use the RunsClient instead.
|
|
9
|
+
*
|
|
7
10
|
*/
|
|
8
11
|
export declare class WorkflowsClient {
|
|
9
12
|
api: HatchetClient['api'];
|
|
@@ -18,7 +21,22 @@ export declare class WorkflowsClient {
|
|
|
18
21
|
* @returns The workflow ID as a string.
|
|
19
22
|
*/
|
|
20
23
|
getWorkflowIdFromName(workflow: string | WorkflowDefinition | BaseWorkflowDeclaration<any, any> | LegacyWorkflow): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Get a workflow by its name, ID, or object.
|
|
26
|
+
* @param workflow - The workflow name, ID, or object.
|
|
27
|
+
* @returns A promise that resolves to the workflow.
|
|
28
|
+
*/
|
|
21
29
|
get(workflow: string | BaseWorkflowDeclaration<any, any> | LegacyWorkflow): Promise<import("../../../clients/rest/generated/data-contracts").Workflow>;
|
|
30
|
+
/**
|
|
31
|
+
* List all workflows in the tenant.
|
|
32
|
+
* @param opts - The options for the list operation.
|
|
33
|
+
* @returns A promise that resolves to the list of workflows.
|
|
34
|
+
*/
|
|
22
35
|
list(opts?: Parameters<typeof this.api.workflowList>[1]): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowList>;
|
|
36
|
+
/**
|
|
37
|
+
* Delete a workflow by its name, ID, or object.
|
|
38
|
+
* @param workflow - The workflow name, ID, or object.
|
|
39
|
+
* @returns A promise that resolves to the deleted workflow.
|
|
40
|
+
*/
|
|
23
41
|
delete(workflow: string | BaseWorkflowDeclaration<any, any> | LegacyWorkflow): Promise<void>;
|
|
24
42
|
}
|
|
@@ -27,7 +27,10 @@ const workflowNameString = (workflow) => {
|
|
|
27
27
|
};
|
|
28
28
|
exports.workflowNameString = workflowNameString;
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* The workflows client is a client for managing workflows programmatically within Hatchet.
|
|
31
|
+
*
|
|
32
|
+
* NOTE: that workflows are the declaration, not the individual runs. If you're looking for runs, use the RunsClient instead.
|
|
33
|
+
*
|
|
31
34
|
*/
|
|
32
35
|
class WorkflowsClient {
|
|
33
36
|
constructor(client, cacheTTL) {
|
|
@@ -69,6 +72,11 @@ class WorkflowsClient {
|
|
|
69
72
|
return str;
|
|
70
73
|
});
|
|
71
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Get a workflow by its name, ID, or object.
|
|
77
|
+
* @param workflow - The workflow name, ID, or object.
|
|
78
|
+
* @returns A promise that resolves to the workflow.
|
|
79
|
+
*/
|
|
72
80
|
get(workflow) {
|
|
73
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
82
|
// Get workflow name string
|
|
@@ -103,12 +111,22 @@ class WorkflowsClient {
|
|
|
103
111
|
}
|
|
104
112
|
});
|
|
105
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* List all workflows in the tenant.
|
|
116
|
+
* @param opts - The options for the list operation.
|
|
117
|
+
* @returns A promise that resolves to the list of workflows.
|
|
118
|
+
*/
|
|
106
119
|
list(opts) {
|
|
107
120
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
121
|
const { data } = yield this.api.workflowList(this.tenantId, opts);
|
|
109
122
|
return data;
|
|
110
123
|
});
|
|
111
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Delete a workflow by its name, ID, or object.
|
|
127
|
+
* @param workflow - The workflow name, ID, or object.
|
|
128
|
+
* @returns A promise that resolves to the deleted workflow.
|
|
129
|
+
*/
|
|
112
130
|
delete(workflow) {
|
|
113
131
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
132
|
const name = (0, exports.workflowNameString)(workflow);
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Hatchet Context class provides helper methods and useful data to tasks at runtime. It is passed as the second argument to all tasks and durable tasks.
|
|
3
|
+
*
|
|
4
|
+
* There are two types of context classes you'll encounter:
|
|
5
|
+
*
|
|
6
|
+
* - Context - The standard context for regular tasks with methods for logging, task output retrieval, cancellation, and more.
|
|
7
|
+
* - DurableContext - An extended context for durable tasks that includes additional methods for durable execution.
|
|
8
|
+
* @module Context
|
|
9
|
+
*/
|
|
1
10
|
import { Priority, RunOpts, TaskWorkflowDeclaration, BaseWorkflowDeclaration as WorkflowV1 } from '../../declaration';
|
|
2
11
|
import { JsonObject } from '@bufbuild/protobuf';
|
|
3
12
|
import { Action } from '../../../clients/dispatcher/action-listener';
|
|
@@ -94,6 +103,7 @@ export declare class Context<T, K = {}> {
|
|
|
94
103
|
* @returns A record mapping task names to error messages.
|
|
95
104
|
* @throws A warning if no errors are found (this method should be used in on-failure tasks).
|
|
96
105
|
* @deprecated use ctx.errors() instead
|
|
106
|
+
* @hidden
|
|
97
107
|
*/
|
|
98
108
|
stepRunErrors(): Record<string, string>;
|
|
99
109
|
/**
|
|
@@ -156,6 +166,7 @@ export declare class Context<T, K = {}> {
|
|
|
156
166
|
* Gets the ID of the current task run.
|
|
157
167
|
* @returns The task run ID.
|
|
158
168
|
* @deprecated use taskRunExternalId() instead
|
|
169
|
+
* @hidden
|
|
159
170
|
*/
|
|
160
171
|
taskRunId(): string;
|
|
161
172
|
/**
|
|
@@ -168,6 +179,7 @@ export declare class Context<T, K = {}> {
|
|
|
168
179
|
* @param message - The message to log.
|
|
169
180
|
* @param level - The log level (optional).
|
|
170
181
|
* @deprecated use ctx.logger.infoger.info, ctx.logger.infoger.debug, ctx.logger.infoger.warn, ctx.logger.infoger.error, ctx.logger.infoger.trace instead
|
|
182
|
+
* @hidden
|
|
171
183
|
*/
|
|
172
184
|
log(message: string, level?: LogLevel, extra?: LogExtra): Promise<void> | Promise<void[]>;
|
|
173
185
|
get logger(): {
|
|
@@ -263,18 +275,21 @@ export declare class Context<T, K = {}> {
|
|
|
263
275
|
* @returns The output of the task.
|
|
264
276
|
* @throws An error if the task output is not found.
|
|
265
277
|
* @deprecated use ctx.parentOutput instead
|
|
278
|
+
* @hidden
|
|
266
279
|
*/
|
|
267
280
|
stepOutput<L = NextStep>(step: string): L;
|
|
268
281
|
/**
|
|
269
282
|
* Gets the input data for the current workflow.
|
|
270
283
|
* @returns The input data for the workflow.
|
|
271
284
|
* @deprecated use task input parameter instead
|
|
285
|
+
* @hidden
|
|
272
286
|
*/
|
|
273
287
|
workflowInput(): T;
|
|
274
288
|
/**
|
|
275
289
|
* Gets the name of the current task.
|
|
276
290
|
* @returns The name of the task.
|
|
277
291
|
* @deprecated use ctx.taskName instead
|
|
292
|
+
* @hidden
|
|
278
293
|
*/
|
|
279
294
|
stepName(): string;
|
|
280
295
|
/**
|
|
@@ -283,6 +298,7 @@ export declare class Context<T, K = {}> {
|
|
|
283
298
|
* @param workflows - An array of objects containing the workflow name, input data, and options for each workflow.
|
|
284
299
|
* @returns A list of references to the spawned workflow runs.
|
|
285
300
|
* @deprecated Use bulkRunNoWaitChildren or bulkRunChildren instead.
|
|
301
|
+
* @hidden
|
|
286
302
|
*/
|
|
287
303
|
spawnWorkflows<Q extends JsonObject = any, P extends JsonObject = any>(workflows: Array<{
|
|
288
304
|
workflow: string | WorkflowV1<Q, P>;
|
|
@@ -297,10 +313,15 @@ export declare class Context<T, K = {}> {
|
|
|
297
313
|
* @param options - Additional options for spawning the workflow.
|
|
298
314
|
* @returns A reference to the spawned workflow run.
|
|
299
315
|
* @deprecated Use runChild or runNoWaitChild instead.
|
|
316
|
+
* @hidden
|
|
300
317
|
*/
|
|
301
318
|
spawnWorkflow<Q extends JsonObject, P extends JsonObject>(workflow: string | WorkflowV1<Q, P> | TaskWorkflowDeclaration<Q, P>, input: Q, options?: ChildRunOpts): Promise<WorkflowRunRef<P>>;
|
|
302
319
|
_incrementStreamIndex(): number;
|
|
303
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* DurableContext provides helper methods and useful data to durable tasks at runtime.
|
|
323
|
+
* It extends the Context class and includes additional methods for durable execution like sleepFor and waitFor.
|
|
324
|
+
*/
|
|
304
325
|
export declare class DurableContext<T, K = {}> extends Context<T, K> {
|
|
305
326
|
waitKey: number;
|
|
306
327
|
/**
|
|
@@ -13,6 +13,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.DurableContext = exports.Context = exports.ContextWorker = void 0;
|
|
16
|
+
/**
|
|
17
|
+
* The Hatchet Context class provides helper methods and useful data to tasks at runtime. It is passed as the second argument to all tasks and durable tasks.
|
|
18
|
+
*
|
|
19
|
+
* There are two types of context classes you'll encounter:
|
|
20
|
+
*
|
|
21
|
+
* - Context - The standard context for regular tasks with methods for logging, task output retrieval, cancellation, and more.
|
|
22
|
+
* - DurableContext - An extended context for durable tasks that includes additional methods for durable execution.
|
|
23
|
+
* @module Context
|
|
24
|
+
*/
|
|
16
25
|
/* eslint-disable no-underscore-dangle */
|
|
17
26
|
/* eslint-disable max-classes-per-file */
|
|
18
27
|
const declaration_1 = require("../../declaration");
|
|
@@ -146,6 +155,7 @@ class Context {
|
|
|
146
155
|
* @returns A record mapping task names to error messages.
|
|
147
156
|
* @throws A warning if no errors are found (this method should be used in on-failure tasks).
|
|
148
157
|
* @deprecated use ctx.errors() instead
|
|
158
|
+
* @hidden
|
|
149
159
|
*/
|
|
150
160
|
stepRunErrors() {
|
|
151
161
|
return this.errors();
|
|
@@ -239,6 +249,7 @@ class Context {
|
|
|
239
249
|
* Gets the ID of the current task run.
|
|
240
250
|
* @returns The task run ID.
|
|
241
251
|
* @deprecated use taskRunExternalId() instead
|
|
252
|
+
* @hidden
|
|
242
253
|
*/
|
|
243
254
|
taskRunId() {
|
|
244
255
|
return this.taskRunExternalId();
|
|
@@ -255,6 +266,7 @@ class Context {
|
|
|
255
266
|
* @param message - The message to log.
|
|
256
267
|
* @param level - The log level (optional).
|
|
257
268
|
* @deprecated use ctx.logger.infoger.info, ctx.logger.infoger.debug, ctx.logger.infoger.warn, ctx.logger.infoger.error, ctx.logger.infoger.trace instead
|
|
269
|
+
* @hidden
|
|
258
270
|
*/
|
|
259
271
|
log(message, level, extra) {
|
|
260
272
|
const { taskRunExternalId } = this.action;
|
|
@@ -491,6 +503,7 @@ class Context {
|
|
|
491
503
|
* @returns The output of the task.
|
|
492
504
|
* @throws An error if the task output is not found.
|
|
493
505
|
* @deprecated use ctx.parentOutput instead
|
|
506
|
+
* @hidden
|
|
494
507
|
*/
|
|
495
508
|
stepOutput(step) {
|
|
496
509
|
if (!this.data.parents) {
|
|
@@ -505,6 +518,7 @@ class Context {
|
|
|
505
518
|
* Gets the input data for the current workflow.
|
|
506
519
|
* @returns The input data for the workflow.
|
|
507
520
|
* @deprecated use task input parameter instead
|
|
521
|
+
* @hidden
|
|
508
522
|
*/
|
|
509
523
|
workflowInput() {
|
|
510
524
|
return this.input;
|
|
@@ -513,6 +527,7 @@ class Context {
|
|
|
513
527
|
* Gets the name of the current task.
|
|
514
528
|
* @returns The name of the task.
|
|
515
529
|
* @deprecated use ctx.taskName instead
|
|
530
|
+
* @hidden
|
|
516
531
|
*/
|
|
517
532
|
stepName() {
|
|
518
533
|
return this.taskName();
|
|
@@ -523,6 +538,7 @@ class Context {
|
|
|
523
538
|
* @param workflows - An array of objects containing the workflow name, input data, and options for each workflow.
|
|
524
539
|
* @returns A list of references to the spawned workflow runs.
|
|
525
540
|
* @deprecated Use bulkRunNoWaitChildren or bulkRunChildren instead.
|
|
541
|
+
* @hidden
|
|
526
542
|
*/
|
|
527
543
|
spawnWorkflows(workflows) {
|
|
528
544
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -586,6 +602,7 @@ class Context {
|
|
|
586
602
|
* @param options - Additional options for spawning the workflow.
|
|
587
603
|
* @returns A reference to the spawned workflow run.
|
|
588
604
|
* @deprecated Use runChild or runNoWaitChild instead.
|
|
605
|
+
* @hidden
|
|
589
606
|
*/
|
|
590
607
|
spawnWorkflow(workflow, input, options) {
|
|
591
608
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -624,6 +641,10 @@ class Context {
|
|
|
624
641
|
}
|
|
625
642
|
}
|
|
626
643
|
exports.Context = Context;
|
|
644
|
+
/**
|
|
645
|
+
* DurableContext provides helper methods and useful data to durable tasks at runtime.
|
|
646
|
+
* It extends the Context class and includes additional methods for durable execution like sleepFor and waitFor.
|
|
647
|
+
*/
|
|
627
648
|
class DurableContext extends Context {
|
|
628
649
|
constructor() {
|
|
629
650
|
super(...arguments);
|
package/v1/declaration.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Runnables` in the Hatchet TypeScript SDK are things that can be run, namely tasks and workflows. The two main types of runnables you'll encounter are:
|
|
3
|
+
*
|
|
4
|
+
* - `WorkflowDeclaration`, returned by `hatchet.workflow(...)`, which lets you define tasks and call `run()`, `schedule()`, `cron()`, etc.
|
|
5
|
+
* - `TaskWorkflowDeclaration`, returned by `hatchet.task(...)`, which is a single standalone task that exposes the same execution helpers as a workflow.
|
|
6
|
+
* @module Runnables
|
|
7
|
+
*/
|
|
1
8
|
import WorkflowRunRef from '../util/workflow-run-ref';
|
|
2
9
|
import { CronWorkflows, ScheduledWorkflows, V1CreateFilterRequest } from '../clients/rest/generated/data-contracts';
|
|
3
10
|
import { z } from 'zod';
|
|
11
|
+
import { WorkerLabelComparator } from '../protoc/v1/workflows';
|
|
4
12
|
import { IHatchetClient } from './client/client.interface';
|
|
5
13
|
import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskFn, CreateWorkflowDurableTaskOpts, CreateBaseTaskOpts, CreateOnSuccessTaskOpts, Concurrency, DurableTaskFn } from './task';
|
|
6
14
|
import { Duration } from './client/duration';
|
|
@@ -18,6 +26,7 @@ export declare enum Priority {
|
|
|
18
26
|
type AdditionalMetadata = Record<string, string>;
|
|
19
27
|
/**
|
|
20
28
|
* Options for running a workflow.
|
|
29
|
+
* @hidden
|
|
21
30
|
*/
|
|
22
31
|
export type RunOpts = {
|
|
23
32
|
/**
|
|
@@ -46,13 +55,24 @@ export type RunOpts = {
|
|
|
46
55
|
* failures are Error instances.
|
|
47
56
|
*/
|
|
48
57
|
returnExceptions?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* (optional) desired worker labels for routing the workflow run to specific workers.
|
|
60
|
+
*/
|
|
61
|
+
desiredWorkerLabels?: Record<string, {
|
|
62
|
+
value: string | number;
|
|
63
|
+
required?: boolean;
|
|
64
|
+
weight?: number;
|
|
65
|
+
comparator?: WorkerLabelComparator;
|
|
66
|
+
}>;
|
|
49
67
|
};
|
|
50
68
|
/**
|
|
51
69
|
* Helper type to safely extract output types from task results
|
|
70
|
+
* @hidden
|
|
52
71
|
*/
|
|
53
72
|
export type TaskOutput<O, Key extends string, Fallback> = O extends Record<Key, infer Value> ? (Value extends OutputType ? Value : Fallback) : Fallback;
|
|
54
73
|
/**
|
|
55
74
|
* Extracts a property from an object type based on task name, or falls back to inferred type
|
|
75
|
+
* @hidden
|
|
56
76
|
*/
|
|
57
77
|
export type TaskOutputType<O, TaskName extends string, InferredType extends OutputType> = TaskName extends keyof O ? O[TaskName] extends OutputType ? O[TaskName] : InferredType : InferredType;
|
|
58
78
|
type DefaultFilter = Omit<V1CreateFilterRequest, 'workflowId'>;
|
|
@@ -62,6 +82,7 @@ type DefaultFilter = Omit<V1CreateFilterRequest, 'workflowId'>;
|
|
|
62
82
|
* Prefer using `StickyStrategy.SOFT` / `StickyStrategy.HARD` (v1, non-protobuf).
|
|
63
83
|
* For backwards compatibility, the workflow/task `sticky` field also accepts legacy
|
|
64
84
|
* protobuf enum values (`0`/`1`) and strings (`'SOFT'`/`'HARD'`).
|
|
85
|
+
* @internal
|
|
65
86
|
*/
|
|
66
87
|
export declare const StickyStrategy: {
|
|
67
88
|
readonly SOFT: "soft";
|
|
@@ -123,6 +144,7 @@ export type CreateTaskWorkflowOpts<I extends InputType = UnknownInputType, O ext
|
|
|
123
144
|
export type CreateDurableTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, DurableTaskFn<I, O>>;
|
|
124
145
|
/**
|
|
125
146
|
* Options for creating a new workflow.
|
|
147
|
+
* @hidden
|
|
126
148
|
*/
|
|
127
149
|
export type CreateWorkflowOpts = CreateBaseWorkflowOpts & {
|
|
128
150
|
/**
|
|
@@ -133,6 +155,7 @@ export type CreateWorkflowOpts = CreateBaseWorkflowOpts & {
|
|
|
133
155
|
/**
|
|
134
156
|
* Default configuration for all tasks in the workflow.
|
|
135
157
|
* Can be overridden by task-specific options.
|
|
158
|
+
* @hidden
|
|
136
159
|
*/
|
|
137
160
|
export type TaskDefaults = {
|
|
138
161
|
/**
|
|
@@ -181,6 +204,7 @@ export type TaskDefaults = {
|
|
|
181
204
|
};
|
|
182
205
|
/**
|
|
183
206
|
* Internal definition of a workflow and its tasks.
|
|
207
|
+
* @hidden
|
|
184
208
|
*/
|
|
185
209
|
export type WorkflowDefinition = CreateWorkflowOpts & {
|
|
186
210
|
/**
|
|
@@ -208,24 +232,28 @@ export type WorkflowDefinition = CreateWorkflowOpts & {
|
|
|
208
232
|
* Represents a workflow that can be executed by Hatchet.
|
|
209
233
|
* @template I The input type for the workflow.
|
|
210
234
|
* @template O The return type of the workflow.
|
|
235
|
+
* @internal
|
|
211
236
|
*/
|
|
212
237
|
export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputType, O extends OutputType = void> {
|
|
213
238
|
/**
|
|
214
239
|
* The Hatchet client instance used to execute the workflow.
|
|
240
|
+
* @internal
|
|
215
241
|
*/
|
|
216
242
|
client: IHatchetClient | undefined;
|
|
217
243
|
/**
|
|
218
244
|
* The internal workflow definition.
|
|
245
|
+
* @internal
|
|
219
246
|
*/
|
|
220
247
|
definition: WorkflowDefinition;
|
|
221
248
|
/**
|
|
222
249
|
* Creates a new workflow instance.
|
|
223
250
|
* @param options The options for creating the workflow.
|
|
224
251
|
* @param client Optional Hatchet client instance.
|
|
252
|
+
* @internal
|
|
225
253
|
*/
|
|
226
254
|
constructor(options: CreateWorkflowOpts, client?: IHatchetClient);
|
|
227
255
|
/**
|
|
228
|
-
*
|
|
256
|
+
* Synchronously trigger a workflow run without waiting for it to complete. This method is useful for starting a workflow run and immediately returning a reference to the run without blocking while the workflow runs.
|
|
229
257
|
* @param input The input data for the workflow.
|
|
230
258
|
* @param options Optional configuration for this workflow run.
|
|
231
259
|
* @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
|
|
@@ -303,6 +331,7 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
|
|
|
303
331
|
get(): Promise<import("../clients/rest/generated/data-contracts").Workflow>;
|
|
304
332
|
/**
|
|
305
333
|
* @deprecated use definition.name instead
|
|
334
|
+
* @hidden
|
|
306
335
|
*/
|
|
307
336
|
get id(): string;
|
|
308
337
|
/**
|
|
@@ -311,6 +340,44 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
|
|
|
311
340
|
*/
|
|
312
341
|
get name(): string;
|
|
313
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* A Hatchet workflow, which lets you define tasks and perform actions on the workflow.
|
|
345
|
+
*
|
|
346
|
+
* Workflows in Hatchet represent coordinated units of work that can be triggered,
|
|
347
|
+
* scheduled, or run on a cron schedule. Each workflow can contain multiple tasks
|
|
348
|
+
* that can be arranged in dependencies (DAGs), with customized retry behavior,
|
|
349
|
+
* timeouts, concurrency controls, and more.
|
|
350
|
+
*
|
|
351
|
+
* Example:
|
|
352
|
+
* ```typescript
|
|
353
|
+
* import { hatchet } from './hatchet-client';
|
|
354
|
+
*
|
|
355
|
+
* type MyInput = { name: string };
|
|
356
|
+
*
|
|
357
|
+
* const workflow = hatchet.workflow<MyInput>({
|
|
358
|
+
* name: 'my-workflow',
|
|
359
|
+
* });
|
|
360
|
+
*
|
|
361
|
+
* workflow.task({
|
|
362
|
+
* name: 'greet',
|
|
363
|
+
* fn: async (input) => {
|
|
364
|
+
* return { message: `Hello, ${input.name}!` };
|
|
365
|
+
* },
|
|
366
|
+
* });
|
|
367
|
+
*
|
|
368
|
+
* // Run the workflow
|
|
369
|
+
* await workflow.run({ name: 'World' });
|
|
370
|
+
* ```
|
|
371
|
+
*
|
|
372
|
+
* Workflows support various execution patterns, including:
|
|
373
|
+
* - One-time execution with `run()` and `runNoWait()`
|
|
374
|
+
* - Scheduled execution with `schedule()`
|
|
375
|
+
* - Cron-based recurring execution with `cron()`
|
|
376
|
+
* - Bulk execution by passing an array input to `run()` and `runNoWait()`
|
|
377
|
+
*
|
|
378
|
+
* Tasks within workflows can be defined with `workflow.task()` or
|
|
379
|
+
* `workflow.durableTask()` and arranged into complex dependency patterns.
|
|
380
|
+
*/
|
|
314
381
|
export declare class WorkflowDeclaration<I extends InputType = UnknownInputType, O extends OutputType = void, MiddlewareBefore extends Record<string, any> = {}> extends BaseWorkflowDeclaration<I, O> {
|
|
315
382
|
/**
|
|
316
383
|
* Adds a task to the workflow.
|
|
@@ -362,10 +429,26 @@ export declare class WorkflowDeclaration<I extends InputType = UnknownInputType,
|
|
|
362
429
|
}): CreateWorkflowDurableTaskOpts<I, TO>;
|
|
363
430
|
}
|
|
364
431
|
/**
|
|
365
|
-
* A standalone task
|
|
432
|
+
* A standalone task declaration that can be run like a workflow.
|
|
433
|
+
*
|
|
434
|
+
* `TaskWorkflowDeclaration` is returned by `hatchet.task(...)` and wraps a single
|
|
435
|
+
* task definition while exposing the same execution helpers as workflows, such as
|
|
436
|
+
* `run()`, `runNoWait()`, `schedule()`, and `cron()` (inherited from
|
|
437
|
+
* `BaseWorkflowDeclaration`).
|
|
438
|
+
*
|
|
439
|
+
* Example:
|
|
440
|
+
* ```typescript
|
|
441
|
+
* const greet = hatchet.task<{ name: string }, { message: string }>({
|
|
442
|
+
* name: 'greet',
|
|
443
|
+
* fn: async (input) => ({ message: `Hello, ${input.name}!` }),
|
|
444
|
+
* });
|
|
445
|
+
*
|
|
446
|
+
* await greet.run({ name: 'World' });
|
|
447
|
+
* const ref = await greet.runNoWait({ name: 'World' });
|
|
448
|
+
* ```
|
|
366
449
|
*
|
|
367
|
-
* @template I
|
|
368
|
-
* @template O
|
|
450
|
+
* @template I The input type for the standalone task.
|
|
451
|
+
* @template O The output type returned by the standalone task.
|
|
369
452
|
* @template GlobalInput - Global input type from the client, merged into all run/schedule/cron input signatures.
|
|
370
453
|
* @template MiddlewareBefore - Extra fields added to the task fn input by pre-middleware hooks.
|
|
371
454
|
* @template MiddlewareAfter - Extra fields merged into the task output by post-middleware hooks.
|
|
@@ -380,6 +463,7 @@ export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputT
|
|
|
380
463
|
* @returns A promise that resolves with the task output merged with post-middleware fields.
|
|
381
464
|
*/
|
|
382
465
|
runAndWait(input: I & GlobalInput, options?: RunOpts): Promise<O & Resolved<GlobalOutput, MiddlewareAfter>>;
|
|
466
|
+
/** @hidden */
|
|
383
467
|
runAndWait(input: (I & GlobalInput)[], options?: RunOpts): Promise<(O & Resolved<GlobalOutput, MiddlewareAfter>)[]>;
|
|
384
468
|
/**
|
|
385
469
|
* Triggers a task run and waits for the result.
|
|
@@ -388,6 +472,7 @@ export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputT
|
|
|
388
472
|
* @returns A promise that resolves with the task output merged with post-middleware fields.
|
|
389
473
|
*/
|
|
390
474
|
run(input: I & GlobalInput, options?: RunOpts): Promise<O & Resolved<GlobalOutput, MiddlewareAfter>>;
|
|
475
|
+
/** @hidden */
|
|
391
476
|
run(input: (I & GlobalInput)[], options?: RunOpts): Promise<(O & Resolved<GlobalOutput, MiddlewareAfter>)[]>;
|
|
392
477
|
/**
|
|
393
478
|
* Triggers a task run without waiting for completion.
|
|
@@ -422,7 +507,6 @@ export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputT
|
|
|
422
507
|
* @returns A promise that resolves with the cron workflow details.
|
|
423
508
|
*/
|
|
424
509
|
cron(name: string, expression: string, input: I & GlobalInput, options?: RunOpts): Promise<CronWorkflows>;
|
|
425
|
-
/** Returns the underlying task definition for this declaration. */
|
|
426
510
|
get taskDef(): CreateWorkflowTaskOpts<any, any>;
|
|
427
511
|
}
|
|
428
512
|
/**
|
package/v1/declaration.js
CHANGED
|
@@ -29,6 +29,7 @@ var Priority;
|
|
|
29
29
|
* Prefer using `StickyStrategy.SOFT` / `StickyStrategy.HARD` (v1, non-protobuf).
|
|
30
30
|
* For backwards compatibility, the workflow/task `sticky` field also accepts legacy
|
|
31
31
|
* protobuf enum values (`0`/`1`) and strings (`'SOFT'`/`'HARD'`).
|
|
32
|
+
* @internal
|
|
32
33
|
*/
|
|
33
34
|
exports.StickyStrategy = {
|
|
34
35
|
SOFT: 'soft',
|
|
@@ -38,12 +39,14 @@ exports.StickyStrategy = {
|
|
|
38
39
|
* Represents a workflow that can be executed by Hatchet.
|
|
39
40
|
* @template I The input type for the workflow.
|
|
40
41
|
* @template O The return type of the workflow.
|
|
42
|
+
* @internal
|
|
41
43
|
*/
|
|
42
44
|
class BaseWorkflowDeclaration {
|
|
43
45
|
/**
|
|
44
46
|
* Creates a new workflow instance.
|
|
45
47
|
* @param options The options for creating the workflow.
|
|
46
48
|
* @param client Optional Hatchet client instance.
|
|
49
|
+
* @internal
|
|
47
50
|
*/
|
|
48
51
|
constructor(options, client) {
|
|
49
52
|
this.definition = Object.assign(Object.assign({}, options), { _tasks: [], _durableTasks: [] });
|
|
@@ -281,6 +284,7 @@ class BaseWorkflowDeclaration {
|
|
|
281
284
|
// }
|
|
282
285
|
/**
|
|
283
286
|
* @deprecated use definition.name instead
|
|
287
|
+
* @hidden
|
|
284
288
|
*/
|
|
285
289
|
get id() {
|
|
286
290
|
return this.definition.name;
|
|
@@ -294,6 +298,44 @@ class BaseWorkflowDeclaration {
|
|
|
294
298
|
}
|
|
295
299
|
}
|
|
296
300
|
exports.BaseWorkflowDeclaration = BaseWorkflowDeclaration;
|
|
301
|
+
/**
|
|
302
|
+
* A Hatchet workflow, which lets you define tasks and perform actions on the workflow.
|
|
303
|
+
*
|
|
304
|
+
* Workflows in Hatchet represent coordinated units of work that can be triggered,
|
|
305
|
+
* scheduled, or run on a cron schedule. Each workflow can contain multiple tasks
|
|
306
|
+
* that can be arranged in dependencies (DAGs), with customized retry behavior,
|
|
307
|
+
* timeouts, concurrency controls, and more.
|
|
308
|
+
*
|
|
309
|
+
* Example:
|
|
310
|
+
* ```typescript
|
|
311
|
+
* import { hatchet } from './hatchet-client';
|
|
312
|
+
*
|
|
313
|
+
* type MyInput = { name: string };
|
|
314
|
+
*
|
|
315
|
+
* const workflow = hatchet.workflow<MyInput>({
|
|
316
|
+
* name: 'my-workflow',
|
|
317
|
+
* });
|
|
318
|
+
*
|
|
319
|
+
* workflow.task({
|
|
320
|
+
* name: 'greet',
|
|
321
|
+
* fn: async (input) => {
|
|
322
|
+
* return { message: `Hello, ${input.name}!` };
|
|
323
|
+
* },
|
|
324
|
+
* });
|
|
325
|
+
*
|
|
326
|
+
* // Run the workflow
|
|
327
|
+
* await workflow.run({ name: 'World' });
|
|
328
|
+
* ```
|
|
329
|
+
*
|
|
330
|
+
* Workflows support various execution patterns, including:
|
|
331
|
+
* - One-time execution with `run()` and `runNoWait()`
|
|
332
|
+
* - Scheduled execution with `schedule()`
|
|
333
|
+
* - Cron-based recurring execution with `cron()`
|
|
334
|
+
* - Bulk execution by passing an array input to `run()` and `runNoWait()`
|
|
335
|
+
*
|
|
336
|
+
* Tasks within workflows can be defined with `workflow.task()` or
|
|
337
|
+
* `workflow.durableTask()` and arranged into complex dependency patterns.
|
|
338
|
+
*/
|
|
297
339
|
class WorkflowDeclaration extends BaseWorkflowDeclaration {
|
|
298
340
|
/**
|
|
299
341
|
* Adds a task to the workflow.
|
|
@@ -378,10 +420,26 @@ class WorkflowDeclaration extends BaseWorkflowDeclaration {
|
|
|
378
420
|
}
|
|
379
421
|
exports.WorkflowDeclaration = WorkflowDeclaration;
|
|
380
422
|
/**
|
|
381
|
-
* A standalone task
|
|
423
|
+
* A standalone task declaration that can be run like a workflow.
|
|
424
|
+
*
|
|
425
|
+
* `TaskWorkflowDeclaration` is returned by `hatchet.task(...)` and wraps a single
|
|
426
|
+
* task definition while exposing the same execution helpers as workflows, such as
|
|
427
|
+
* `run()`, `runNoWait()`, `schedule()`, and `cron()` (inherited from
|
|
428
|
+
* `BaseWorkflowDeclaration`).
|
|
429
|
+
*
|
|
430
|
+
* Example:
|
|
431
|
+
* ```typescript
|
|
432
|
+
* const greet = hatchet.task<{ name: string }, { message: string }>({
|
|
433
|
+
* name: 'greet',
|
|
434
|
+
* fn: async (input) => ({ message: `Hello, ${input.name}!` }),
|
|
435
|
+
* });
|
|
436
|
+
*
|
|
437
|
+
* await greet.run({ name: 'World' });
|
|
438
|
+
* const ref = await greet.runNoWait({ name: 'World' });
|
|
439
|
+
* ```
|
|
382
440
|
*
|
|
383
|
-
* @template I
|
|
384
|
-
* @template O
|
|
441
|
+
* @template I The input type for the standalone task.
|
|
442
|
+
* @template O The output type returned by the standalone task.
|
|
385
443
|
* @template GlobalInput - Global input type from the client, merged into all run/schedule/cron input signatures.
|
|
386
444
|
* @template MiddlewareBefore - Extra fields added to the task fn input by pre-middleware hooks.
|
|
387
445
|
* @template MiddlewareAfter - Extra fields merged into the task output by post-middleware hooks.
|
|
@@ -468,7 +526,7 @@ class TaskWorkflowDeclaration extends BaseWorkflowDeclaration {
|
|
|
468
526
|
return _super.cron.call(this, name, expression, input, options);
|
|
469
527
|
});
|
|
470
528
|
}
|
|
471
|
-
|
|
529
|
+
// Returns the underlying task definition for this declaration.
|
|
472
530
|
get taskDef() {
|
|
473
531
|
return this.definition._tasks[0];
|
|
474
532
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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.affinityExampleTask = void 0;
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
exports.affinityExampleTask = hatchet_client_1.hatchet.task({
|
|
15
|
+
name: 'affinity-example-task',
|
|
16
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
return { worker_id: ctx.worker.id() };
|
|
18
|
+
}),
|
|
19
|
+
});
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.15.1";
|
package/version.js
CHANGED