@hatchet-dev/typescript-sdk 1.0.2 → 1.0.4
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/dispatcher/heartbeat/heartbeat-controller.d.ts +5 -0
- package/clients/dispatcher/heartbeat/heartbeat-controller.js +6 -2
- package/clients/dispatcher/heartbeat/heartbeat-worker.js +37 -5
- package/package.json +4 -2
- package/step.d.ts +14 -16
- package/step.js +22 -15
- package/v1/client/client.d.ts +22 -21
- package/v1/client/client.js +8 -8
- package/v1/declaration.d.ts +46 -41
- package/v1/declaration.js +11 -11
- package/v1/examples/cancellations/workflow.d.ts +1 -1
- package/v1/examples/concurrency-rr/workflow.js +2 -2
- package/v1/examples/durable-sleep/workflow.d.ts +1 -1
- package/v1/examples/durable-sleep/workflow.js +1 -1
- package/v1/examples/on_failure/workflow.d.ts +1 -1
- package/v1/examples/on_success/workflow.d.ts +1 -1
- package/v1/examples/rate_limit/run.d.ts +1 -0
- package/v1/examples/rate_limit/run.js +29 -0
- package/v1/examples/rate_limit/worker.d.ts +1 -0
- package/v1/examples/rate_limit/worker.js +24 -0
- package/v1/examples/rate_limit/workflow.d.ts +5 -0
- package/v1/examples/rate_limit/workflow.js +40 -0
- package/v1/examples/retries/workflow.d.ts +3 -3
- package/v1/examples/retries/workflow.js +7 -4
- package/v1/examples/simple/run.js +2 -4
- package/v1/examples/sticky/workflow.d.ts +1 -1
- package/v1/examples/timeouts/workflow.d.ts +1 -1
- package/v1/index.d.ts +2 -0
- package/v1/index.js +2 -0
- package/v1/task.d.ts +26 -25
- package/v1/types.d.ts +17 -0
- package/v1/types.js +2 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/workflow.d.ts +8 -8
|
@@ -3,6 +3,11 @@ import { DispatcherClient as PbDispatcherClient } from '../../../protoc/dispatch
|
|
|
3
3
|
import { Worker } from 'worker_threads';
|
|
4
4
|
import { ClientConfig } from '../../hatchet-client';
|
|
5
5
|
import { DispatcherClient } from '../dispatcher-client';
|
|
6
|
+
export interface HeartbeatMessage {
|
|
7
|
+
type: 'info' | 'warn' | 'error' | 'debug';
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const STOP_HEARTBEAT = "stop";
|
|
6
11
|
export declare class Heartbeat {
|
|
7
12
|
config: ClientConfig;
|
|
8
13
|
client: PbDispatcherClient;
|
|
@@ -12,9 +12,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Heartbeat = void 0;
|
|
15
|
+
exports.Heartbeat = exports.STOP_HEARTBEAT = void 0;
|
|
16
16
|
const path_1 = __importDefault(require("path"));
|
|
17
17
|
const thread_helper_1 = require("../../../util/thread-helper");
|
|
18
|
+
exports.STOP_HEARTBEAT = 'stop';
|
|
18
19
|
class Heartbeat {
|
|
19
20
|
constructor(client, workerId) {
|
|
20
21
|
this.config = client.config;
|
|
@@ -31,13 +32,16 @@ class Heartbeat {
|
|
|
31
32
|
workerId: this.workerId,
|
|
32
33
|
},
|
|
33
34
|
});
|
|
35
|
+
this.heartbeatWorker.on('message', (message) => {
|
|
36
|
+
this.logger[message.type](message.message);
|
|
37
|
+
});
|
|
34
38
|
}
|
|
35
39
|
});
|
|
36
40
|
}
|
|
37
41
|
stop() {
|
|
38
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
43
|
var _a, _b;
|
|
40
|
-
(_a = this.heartbeatWorker) === null || _a === void 0 ? void 0 : _a.postMessage(
|
|
44
|
+
(_a = this.heartbeatWorker) === null || _a === void 0 ? void 0 : _a.postMessage(exports.STOP_HEARTBEAT);
|
|
41
45
|
(_b = this.heartbeatWorker) === null || _b === void 0 ? void 0 : _b.terminate();
|
|
42
46
|
this.heartbeatWorker = undefined;
|
|
43
47
|
});
|
|
@@ -14,16 +14,25 @@ const hatchet_client_1 = require("../../hatchet-client");
|
|
|
14
14
|
const config_loader_1 = require("../../../util/config-loader");
|
|
15
15
|
const nice_grpc_1 = require("nice-grpc");
|
|
16
16
|
const dispatcher_client_1 = require("../dispatcher-client");
|
|
17
|
+
const heartbeat_controller_1 = require("./heartbeat-controller");
|
|
17
18
|
const HEARTBEAT_INTERVAL = 4000;
|
|
19
|
+
const postMessage = (message) => {
|
|
20
|
+
worker_threads_1.parentPort === null || worker_threads_1.parentPort === void 0 ? void 0 : worker_threads_1.parentPort.postMessage(message);
|
|
21
|
+
};
|
|
18
22
|
class HeartbeatWorker {
|
|
19
23
|
constructor(config, workerId) {
|
|
20
24
|
this.timeLastHeartbeat = new Date().getTime();
|
|
21
25
|
this.workerId = workerId;
|
|
22
|
-
this.logger = new hatchet_client_1.HatchetLogger(`
|
|
26
|
+
this.logger = new hatchet_client_1.HatchetLogger(`HeartbeatThread`, config.log_level);
|
|
27
|
+
this.logger.debug('Heartbeat thread starting...');
|
|
23
28
|
const credentials = config_loader_1.ConfigLoader.createCredentials(config.tls_config);
|
|
24
29
|
const clientFactory = (0, nice_grpc_1.createClientFactory)().use((0, hatchet_client_1.addTokenMiddleware)(config.token));
|
|
25
30
|
const dispatcher = new dispatcher_client_1.DispatcherClient(Object.assign(Object.assign({}, config), { logger: (ctx, level) => new hatchet_client_1.HatchetLogger(ctx, level) }), (0, hatchet_client_1.channelFactory)(config, credentials), clientFactory);
|
|
26
31
|
this.client = dispatcher.client;
|
|
32
|
+
postMessage({
|
|
33
|
+
type: 'debug',
|
|
34
|
+
message: 'Heartbeat thread started.',
|
|
35
|
+
});
|
|
27
36
|
}
|
|
28
37
|
start() {
|
|
29
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -33,6 +42,10 @@ class HeartbeatWorker {
|
|
|
33
42
|
const beat = () => __awaiter(this, void 0, void 0, function* () {
|
|
34
43
|
try {
|
|
35
44
|
this.logger.debug('Heartbeat sending...');
|
|
45
|
+
postMessage({
|
|
46
|
+
type: 'debug',
|
|
47
|
+
message: 'Heartbeat sending...',
|
|
48
|
+
});
|
|
36
49
|
yield this.client.heartbeat({
|
|
37
50
|
workerId: this.workerId,
|
|
38
51
|
heartbeatAt: new Date(),
|
|
@@ -40,19 +53,38 @@ class HeartbeatWorker {
|
|
|
40
53
|
const now = new Date().getTime();
|
|
41
54
|
const actualInterval = now - this.timeLastHeartbeat;
|
|
42
55
|
if (actualInterval > HEARTBEAT_INTERVAL * 1.2) {
|
|
43
|
-
|
|
56
|
+
const message = `Heartbeat interval delay (${actualInterval}ms >> ${HEARTBEAT_INTERVAL}ms)`;
|
|
57
|
+
this.logger.warn(message);
|
|
58
|
+
postMessage({
|
|
59
|
+
type: 'warn',
|
|
60
|
+
message,
|
|
61
|
+
});
|
|
44
62
|
}
|
|
45
63
|
this.logger.debug(`Heartbeat sent ${actualInterval}ms ago`);
|
|
64
|
+
postMessage({
|
|
65
|
+
type: 'debug',
|
|
66
|
+
message: `Heartbeat sent ${actualInterval}ms ago`,
|
|
67
|
+
});
|
|
46
68
|
this.timeLastHeartbeat = now;
|
|
47
69
|
}
|
|
48
70
|
catch (e) {
|
|
49
71
|
if (e.code === nice_grpc_1.Status.UNIMPLEMENTED) {
|
|
50
72
|
// break out of interval
|
|
51
|
-
|
|
73
|
+
const message = 'Heartbeat not implemented, closing heartbeat';
|
|
74
|
+
this.logger.debug(message);
|
|
75
|
+
postMessage({
|
|
76
|
+
type: 'error',
|
|
77
|
+
message,
|
|
78
|
+
});
|
|
52
79
|
this.stop();
|
|
53
80
|
return;
|
|
54
81
|
}
|
|
55
|
-
|
|
82
|
+
const message = `Failed to send heartbeat: ${e.message}`;
|
|
83
|
+
this.logger.debug(message);
|
|
84
|
+
postMessage({
|
|
85
|
+
type: 'error',
|
|
86
|
+
message,
|
|
87
|
+
});
|
|
56
88
|
}
|
|
57
89
|
});
|
|
58
90
|
// start with a heartbeat
|
|
@@ -69,6 +101,6 @@ class HeartbeatWorker {
|
|
|
69
101
|
}
|
|
70
102
|
const heartbeat = new HeartbeatWorker(worker_threads_1.workerData.config, worker_threads_1.workerData.workerId);
|
|
71
103
|
heartbeat.start();
|
|
72
|
-
worker_threads_1.parentPort === null || worker_threads_1.parentPort === void 0 ? void 0 : worker_threads_1.parentPort.on(
|
|
104
|
+
worker_threads_1.parentPort === null || worker_threads_1.parentPort === void 0 ? void 0 : worker_threads_1.parentPort.on(heartbeat_controller_1.STOP_HEARTBEAT, () => {
|
|
73
105
|
heartbeat.stop();
|
|
74
106
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -70,7 +70,8 @@
|
|
|
70
70
|
"author": "",
|
|
71
71
|
"license": "MIT",
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@
|
|
73
|
+
"@tsd/typescript": "^5.8.2",
|
|
74
|
+
"@types/jest": "^29.5.14",
|
|
74
75
|
"@types/node": "^22.0.0",
|
|
75
76
|
"@typescript-eslint/eslint-plugin": "^6.4.0",
|
|
76
77
|
"autoprefixer": "^10.4.16",
|
|
@@ -91,6 +92,7 @@
|
|
|
91
92
|
"eslint-plugin-unused-imports": "^4.1.3",
|
|
92
93
|
"grpc-tools": "^1.12.4",
|
|
93
94
|
"jest": "^29.7.0",
|
|
95
|
+
"jest-tsd": "^0.2.2",
|
|
94
96
|
"pino": "^9.6.0",
|
|
95
97
|
"prettier": "^3.1.1",
|
|
96
98
|
"resolve-tspaths": "^0.8.17",
|
package/step.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { CreateWorkflowTaskOpts } from './v1/task';
|
|
|
12
12
|
import { BaseWorkflowDeclaration as WorkflowV1 } from './v1/declaration';
|
|
13
13
|
import { Conditions } from './v1/conditions';
|
|
14
14
|
import { Duration } from './v1/client/duration';
|
|
15
|
+
import { JsonObject, JsonValue, OutputType } from './v1/types';
|
|
15
16
|
export declare const CreateRateLimitSchema: z.ZodObject<{
|
|
16
17
|
key: z.ZodOptional<z.ZodString>;
|
|
17
18
|
staticKey: z.ZodOptional<z.ZodString>;
|
|
@@ -150,14 +151,6 @@ export declare const CreateStepSchema: z.ZodObject<{
|
|
|
150
151
|
maxSeconds?: number | undefined;
|
|
151
152
|
} | undefined;
|
|
152
153
|
}>;
|
|
153
|
-
export type JsonObject = {
|
|
154
|
-
[Key in string]: JsonValue;
|
|
155
|
-
} & {
|
|
156
|
-
[Key in string]?: JsonValue | undefined;
|
|
157
|
-
};
|
|
158
|
-
export type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
159
|
-
export type JsonPrimitive = string | number | boolean | null;
|
|
160
|
-
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
161
154
|
export type NextStep = {
|
|
162
155
|
[key: string]: JsonValue;
|
|
163
156
|
};
|
|
@@ -211,12 +204,11 @@ export declare class Context<T, K = {}> {
|
|
|
211
204
|
get cancelled(): boolean;
|
|
212
205
|
/**
|
|
213
206
|
* Retrieves the output of a parent task.
|
|
214
|
-
* @param
|
|
207
|
+
* @param parentTask - The a CreateTaskOpts or string of the parent task name.
|
|
215
208
|
* @returns The output of the specified parent task.
|
|
216
209
|
* @throws An error if the task output is not found.
|
|
217
|
-
*
|
|
218
210
|
*/
|
|
219
|
-
parentOutput<L
|
|
211
|
+
parentOutput<L extends OutputType>(parentTask: CreateWorkflowTaskOpts<any, L> | string): Promise<L>;
|
|
220
212
|
/**
|
|
221
213
|
* Get the output of a task.
|
|
222
214
|
* @param task - The name of the task to get the output for.
|
|
@@ -229,7 +221,7 @@ export declare class Context<T, K = {}> {
|
|
|
229
221
|
* Returns errors from any task runs in the workflow.
|
|
230
222
|
* @returns A record mapping task names to error messages.
|
|
231
223
|
* @throws A warning if no errors are found (this method should be used in on-failure tasks).
|
|
232
|
-
* @deprecated use ctx.errors instead
|
|
224
|
+
* @deprecated use ctx.errors() instead
|
|
233
225
|
*/
|
|
234
226
|
stepRunErrors(): Record<string, string>;
|
|
235
227
|
/**
|
|
@@ -251,6 +243,7 @@ export declare class Context<T, K = {}> {
|
|
|
251
243
|
/**
|
|
252
244
|
* Gets the input data for the current workflow.
|
|
253
245
|
* @returns The input data for the workflow.
|
|
246
|
+
* @deprecated use task input parameter instead
|
|
254
247
|
*/
|
|
255
248
|
workflowInput(): T;
|
|
256
249
|
/**
|
|
@@ -279,6 +272,11 @@ export declare class Context<T, K = {}> {
|
|
|
279
272
|
* @returns The workflow run ID.
|
|
280
273
|
*/
|
|
281
274
|
workflowRunId(): string;
|
|
275
|
+
/**
|
|
276
|
+
* Gets the ID of the current task run.
|
|
277
|
+
* @returns The task run ID.
|
|
278
|
+
*/
|
|
279
|
+
taskRunId(): string;
|
|
282
280
|
/**
|
|
283
281
|
* Gets the number of times the current task has been retried.
|
|
284
282
|
* @returns The retry count.
|
|
@@ -357,10 +355,10 @@ export declare class Context<T, K = {}> {
|
|
|
357
355
|
*
|
|
358
356
|
* @param workflow - The workflow to run (name, Workflow instance, or WorkflowV1 instance).
|
|
359
357
|
* @param input - The input data for the workflow.
|
|
360
|
-
* @param
|
|
358
|
+
* @param optionsOrKey - Either a string key or an options object containing key, sticky, and additionalMetadata.
|
|
361
359
|
* @returns The result of the workflow.
|
|
362
360
|
*/
|
|
363
|
-
runChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q,
|
|
361
|
+
runChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, optionsOrKey?: string | {
|
|
364
362
|
key?: string;
|
|
365
363
|
sticky?: boolean;
|
|
366
364
|
additionalMetadata?: Record<string, string>;
|
|
@@ -370,10 +368,10 @@ export declare class Context<T, K = {}> {
|
|
|
370
368
|
*
|
|
371
369
|
* @param workflow - The workflow to enqueue (name, Workflow instance, or WorkflowV1 instance).
|
|
372
370
|
* @param input - The input data for the workflow.
|
|
373
|
-
* @param
|
|
371
|
+
* @param optionsOrKey - Either a string key or an options object containing key, sticky, and additionalMetadata.
|
|
374
372
|
* @returns A reference to the spawned workflow run.
|
|
375
373
|
*/
|
|
376
|
-
runNoWaitChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q,
|
|
374
|
+
runNoWaitChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, optionsOrKey?: string | {
|
|
377
375
|
key?: string;
|
|
378
376
|
sticky?: boolean;
|
|
379
377
|
additionalMetadata?: Record<string, string>;
|
package/step.js
CHANGED
|
@@ -162,18 +162,17 @@ class Context {
|
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
164
|
* Retrieves the output of a parent task.
|
|
165
|
-
* @param
|
|
165
|
+
* @param parentTask - The a CreateTaskOpts or string of the parent task name.
|
|
166
166
|
* @returns The output of the specified parent task.
|
|
167
167
|
* @throws An error if the task output is not found.
|
|
168
|
-
*
|
|
169
168
|
*/
|
|
170
|
-
parentOutput(
|
|
169
|
+
parentOutput(parentTask) {
|
|
171
170
|
return __awaiter(this, void 0, void 0, function* () {
|
|
172
171
|
// NOTE: parentOutput is async since we plan on potentially making this a cacheable server call
|
|
173
|
-
if (typeof
|
|
174
|
-
return this.stepOutput(
|
|
172
|
+
if (typeof parentTask === 'string') {
|
|
173
|
+
return this.stepOutput(parentTask);
|
|
175
174
|
}
|
|
176
|
-
return this.stepOutput(
|
|
175
|
+
return this.stepOutput(parentTask.name);
|
|
177
176
|
});
|
|
178
177
|
}
|
|
179
178
|
/**
|
|
@@ -185,10 +184,10 @@ class Context {
|
|
|
185
184
|
*/
|
|
186
185
|
stepOutput(step) {
|
|
187
186
|
if (!this.data.parents) {
|
|
188
|
-
throw new hatchet_error_1.default('
|
|
187
|
+
throw new hatchet_error_1.default('Parent task outputs not found');
|
|
189
188
|
}
|
|
190
189
|
if (!this.data.parents[step]) {
|
|
191
|
-
throw new hatchet_error_1.default(`
|
|
190
|
+
throw new hatchet_error_1.default(`Output for parent task '${step}' not found`);
|
|
192
191
|
}
|
|
193
192
|
return this.data.parents[step];
|
|
194
193
|
}
|
|
@@ -196,7 +195,7 @@ class Context {
|
|
|
196
195
|
* Returns errors from any task runs in the workflow.
|
|
197
196
|
* @returns A record mapping task names to error messages.
|
|
198
197
|
* @throws A warning if no errors are found (this method should be used in on-failure tasks).
|
|
199
|
-
* @deprecated use ctx.errors instead
|
|
198
|
+
* @deprecated use ctx.errors() instead
|
|
200
199
|
*/
|
|
201
200
|
stepRunErrors() {
|
|
202
201
|
return this.errors();
|
|
@@ -231,6 +230,7 @@ class Context {
|
|
|
231
230
|
/**
|
|
232
231
|
* Gets the input data for the current workflow.
|
|
233
232
|
* @returns The input data for the workflow.
|
|
233
|
+
* @deprecated use task input parameter instead
|
|
234
234
|
*/
|
|
235
235
|
workflowInput() {
|
|
236
236
|
return this.input;
|
|
@@ -272,6 +272,13 @@ class Context {
|
|
|
272
272
|
workflowRunId() {
|
|
273
273
|
return this.action.workflowRunId;
|
|
274
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* Gets the ID of the current task run.
|
|
277
|
+
* @returns The task run ID.
|
|
278
|
+
*/
|
|
279
|
+
taskRunId() {
|
|
280
|
+
return this.action.stepRunId;
|
|
281
|
+
}
|
|
275
282
|
/**
|
|
276
283
|
* Gets the number of times the current task has been retried.
|
|
277
284
|
* @returns The retry count.
|
|
@@ -414,12 +421,12 @@ class Context {
|
|
|
414
421
|
*
|
|
415
422
|
* @param workflow - The workflow to run (name, Workflow instance, or WorkflowV1 instance).
|
|
416
423
|
* @param input - The input data for the workflow.
|
|
417
|
-
* @param
|
|
424
|
+
* @param optionsOrKey - Either a string key or an options object containing key, sticky, and additionalMetadata.
|
|
418
425
|
* @returns The result of the workflow.
|
|
419
426
|
*/
|
|
420
|
-
runChild(workflow, input,
|
|
427
|
+
runChild(workflow, input, optionsOrKey) {
|
|
421
428
|
return __awaiter(this, void 0, void 0, function* () {
|
|
422
|
-
const run = yield this.spawnWorkflow(workflow, input,
|
|
429
|
+
const run = yield this.spawnWorkflow(workflow, input, optionsOrKey);
|
|
423
430
|
return run.output;
|
|
424
431
|
});
|
|
425
432
|
}
|
|
@@ -428,11 +435,11 @@ class Context {
|
|
|
428
435
|
*
|
|
429
436
|
* @param workflow - The workflow to enqueue (name, Workflow instance, or WorkflowV1 instance).
|
|
430
437
|
* @param input - The input data for the workflow.
|
|
431
|
-
* @param
|
|
438
|
+
* @param optionsOrKey - Either a string key or an options object containing key, sticky, and additionalMetadata.
|
|
432
439
|
* @returns A reference to the spawned workflow run.
|
|
433
440
|
*/
|
|
434
|
-
runNoWaitChild(workflow, input,
|
|
435
|
-
return this.spawnWorkflow(workflow, input,
|
|
441
|
+
runNoWaitChild(workflow, input, optionsOrKey) {
|
|
442
|
+
return this.spawnWorkflow(workflow, input, optionsOrKey);
|
|
436
443
|
}
|
|
437
444
|
/**
|
|
438
445
|
* Spawns a new workflow.
|
package/v1/client/client.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ClientConfig, InternalHatchetClient, HatchetClientOptions } from '../..
|
|
|
2
2
|
import { AxiosRequestConfig } from 'axios';
|
|
3
3
|
import WorkflowRunRef from '../../util/workflow-run-ref';
|
|
4
4
|
import { Workflow as V0Workflow } from '../../workflow';
|
|
5
|
-
import {
|
|
5
|
+
import { DurableContext } from '../../step';
|
|
6
6
|
import { Api } from '../../clients/rest';
|
|
7
7
|
import { CreateTaskWorkflowOpts, CreateWorkflowOpts, RunOpts, BaseWorkflowDeclaration, WorkflowDeclaration, TaskWorkflowDeclaration } from '../declaration';
|
|
8
8
|
import { IHatchetClient } from './client.interface';
|
|
@@ -12,6 +12,7 @@ import { WorkersClient } from './features/workers';
|
|
|
12
12
|
import { WorkflowsClient } from './features/workflows';
|
|
13
13
|
import { RunsClient } from './features/runs';
|
|
14
14
|
import { CreateStandaloneDurableTaskOpts } from '../task';
|
|
15
|
+
import { InputType, OutputType, UnknownInputType, WorkflowOutputType } from '../types';
|
|
15
16
|
/**
|
|
16
17
|
* HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
|
|
17
18
|
* It provides methods for creating and executing workflows, as well as managing workers.
|
|
@@ -45,80 +46,80 @@ export declare class HatchetClient implements IHatchetClient {
|
|
|
45
46
|
static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): HatchetClient;
|
|
46
47
|
/**
|
|
47
48
|
* Creates a new workflow definition.
|
|
48
|
-
* @template
|
|
49
|
-
* @template
|
|
49
|
+
* @template I - The input type for the workflow
|
|
50
|
+
* @template O - The return type of the workflow
|
|
50
51
|
* @param options - Configuration options for creating the workflow
|
|
51
52
|
* @returns A new Workflow instance
|
|
52
53
|
* @note It is possible to create an orphaned workflow if no client is available using @hatchet/client CreateWorkflow
|
|
53
54
|
*/
|
|
54
|
-
workflow<
|
|
55
|
+
workflow<I extends InputType = UnknownInputType, O extends WorkflowOutputType = {}>(options: CreateWorkflowOpts): WorkflowDeclaration<I, O>;
|
|
55
56
|
/**
|
|
56
57
|
* Creates a new task workflow.
|
|
57
58
|
* Types can be explicitly specified as generics or inferred from the function signature.
|
|
58
|
-
* @template
|
|
59
|
-
* @template
|
|
59
|
+
* @template I The input type for the task
|
|
60
|
+
* @template O The output type of the task
|
|
60
61
|
* @param options Task configuration options
|
|
61
62
|
* @returns A TaskWorkflowDeclaration instance
|
|
62
63
|
*/
|
|
63
|
-
task<
|
|
64
|
+
task<I extends InputType = UnknownInputType, O extends OutputType = void>(options: CreateTaskWorkflowOpts<I, O>): TaskWorkflowDeclaration<I, O>;
|
|
64
65
|
/**
|
|
65
66
|
* Creates a new task workflow with types inferred from the function parameter.
|
|
66
67
|
* @template Fn The type of the task function with input and output extending JsonObject
|
|
67
68
|
* @param options Task configuration options with function that defines types
|
|
68
69
|
* @returns A TaskWorkflowDeclaration instance with inferred types
|
|
69
70
|
*/
|
|
70
|
-
task<Fn extends (input: I, ctx?: any) => O | Promise<O>, I extends
|
|
71
|
+
task<Fn extends (input: I, ctx?: any) => O | Promise<O>, I extends InputType = Parameters<Fn>[0] | UnknownInputType, O extends OutputType = ReturnType<Fn> extends Promise<infer P> ? P extends OutputType ? P : void : ReturnType<Fn> extends OutputType ? ReturnType<Fn> : void>(options: {
|
|
71
72
|
fn: Fn;
|
|
72
73
|
} & Omit<CreateTaskWorkflowOpts<I, O>, 'fn'>): TaskWorkflowDeclaration<I, O>;
|
|
73
74
|
/**
|
|
74
75
|
* Creates a new durable task workflow.
|
|
75
76
|
* Types can be explicitly specified as generics or inferred from the function signature.
|
|
76
|
-
* @template
|
|
77
|
-
* @template
|
|
77
|
+
* @template I The input type for the durable task
|
|
78
|
+
* @template O The output type of the durable task
|
|
78
79
|
* @param options Durable task configuration options
|
|
79
80
|
* @returns A TaskWorkflowDeclaration instance for a durable task
|
|
80
81
|
*/
|
|
81
|
-
durableTask<
|
|
82
|
+
durableTask<I extends InputType, O extends OutputType>(options: CreateStandaloneDurableTaskOpts<I, O>): TaskWorkflowDeclaration<I, O>;
|
|
82
83
|
/**
|
|
83
84
|
* Creates a new durable task workflow with types inferred from the function parameter.
|
|
84
85
|
* @template Fn The type of the durable task function with input and output extending JsonObject
|
|
85
86
|
* @param options Durable task configuration options with function that defines types
|
|
86
87
|
* @returns A TaskWorkflowDeclaration instance with inferred types
|
|
87
88
|
*/
|
|
88
|
-
durableTask<Fn extends (input: I, ctx: DurableContext<I>) => O | Promise<O>, I extends
|
|
89
|
+
durableTask<Fn extends (input: I, ctx: DurableContext<I>) => O | Promise<O>, I extends InputType = Parameters<Fn>[0], O extends OutputType = ReturnType<Fn> extends Promise<infer P> ? P extends OutputType ? P : void : ReturnType<Fn> extends OutputType ? ReturnType<Fn> : void>(options: {
|
|
89
90
|
fn: Fn;
|
|
90
91
|
} & Omit<CreateStandaloneDurableTaskOpts<I, O>, 'fn'>): TaskWorkflowDeclaration<I, O>;
|
|
91
92
|
/**
|
|
92
93
|
* Triggers a workflow run without waiting for completion.
|
|
93
|
-
* @template
|
|
94
|
-
* @template
|
|
94
|
+
* @template I - The input type for the workflow
|
|
95
|
+
* @template O - The return type of the workflow
|
|
95
96
|
* @param workflow - The workflow to run, either as a Workflow instance or workflow name
|
|
96
97
|
* @param input - The input data for the workflow
|
|
97
98
|
* @param options - Configuration options for the workflow run
|
|
98
99
|
* @returns A WorkflowRunRef containing the run ID and methods to interact with the run
|
|
99
100
|
*/
|
|
100
|
-
runNoWait<
|
|
101
|
+
runNoWait<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | string | V0Workflow, input: I, options: RunOpts): WorkflowRunRef<O>;
|
|
101
102
|
/**
|
|
102
103
|
* @alias run
|
|
103
104
|
* Triggers a workflow run and waits for the result.
|
|
104
|
-
* @template
|
|
105
|
-
* @template
|
|
105
|
+
* @template I - The input type for the workflow
|
|
106
|
+
* @template O - The return type of the workflow
|
|
106
107
|
* @param workflow - The workflow to run, either as a Workflow instance or workflow name
|
|
107
108
|
* @param input - The input data for the workflow
|
|
108
109
|
* @param options - Configuration options for the workflow run
|
|
109
110
|
* @returns A promise that resolves with the workflow result
|
|
110
111
|
*/
|
|
111
|
-
runAndWait<
|
|
112
|
+
runAndWait<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | string | V0Workflow, input: I, options?: RunOpts): Promise<O>;
|
|
112
113
|
/**
|
|
113
114
|
* Triggers a workflow run and waits for the result.
|
|
114
|
-
* @template
|
|
115
|
-
* @template
|
|
115
|
+
* @template I - The input type for the workflow
|
|
116
|
+
* @template O - The return type of the workflow
|
|
116
117
|
* @param workflow - The workflow to run, either as a Workflow instance or workflow name
|
|
117
118
|
* @param input - The input data for the workflow
|
|
118
119
|
* @param options - Configuration options for the workflow run
|
|
119
120
|
* @returns A promise that resolves with the workflow result
|
|
120
121
|
*/
|
|
121
|
-
run<
|
|
122
|
+
run<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | string | V0Workflow, input: I, options?: RunOpts): Promise<O>;
|
|
122
123
|
/**
|
|
123
124
|
* Get the cron client for creating and managing cron workflow runs
|
|
124
125
|
* @returns A cron client instance
|
package/v1/client/client.js
CHANGED
|
@@ -82,8 +82,8 @@ class HatchetClient {
|
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Creates a new workflow definition.
|
|
85
|
-
* @template
|
|
86
|
-
* @template
|
|
85
|
+
* @template I - The input type for the workflow
|
|
86
|
+
* @template O - The return type of the workflow
|
|
87
87
|
* @param options - Configuration options for creating the workflow
|
|
88
88
|
* @returns A new Workflow instance
|
|
89
89
|
* @note It is possible to create an orphaned workflow if no client is available using @hatchet/client CreateWorkflow
|
|
@@ -105,8 +105,8 @@ class HatchetClient {
|
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
* Triggers a workflow run without waiting for completion.
|
|
108
|
-
* @template
|
|
109
|
-
* @template
|
|
108
|
+
* @template I - The input type for the workflow
|
|
109
|
+
* @template O - The return type of the workflow
|
|
110
110
|
* @param workflow - The workflow to run, either as a Workflow instance or workflow name
|
|
111
111
|
* @param input - The input data for the workflow
|
|
112
112
|
* @param options - Configuration options for the workflow run
|
|
@@ -128,8 +128,8 @@ class HatchetClient {
|
|
|
128
128
|
/**
|
|
129
129
|
* @alias run
|
|
130
130
|
* Triggers a workflow run and waits for the result.
|
|
131
|
-
* @template
|
|
132
|
-
* @template
|
|
131
|
+
* @template I - The input type for the workflow
|
|
132
|
+
* @template O - The return type of the workflow
|
|
133
133
|
* @param workflow - The workflow to run, either as a Workflow instance or workflow name
|
|
134
134
|
* @param input - The input data for the workflow
|
|
135
135
|
* @param options - Configuration options for the workflow run
|
|
@@ -142,8 +142,8 @@ class HatchetClient {
|
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
144
|
* Triggers a workflow run and waits for the result.
|
|
145
|
-
* @template
|
|
146
|
-
* @template
|
|
145
|
+
* @template I - The input type for the workflow
|
|
146
|
+
* @template O - The return type of the workflow
|
|
147
147
|
* @param workflow - The workflow to run, either as a Workflow instance or workflow name
|
|
148
148
|
* @param input - The input data for the workflow
|
|
149
149
|
* @param options - Configuration options for the workflow run
|