@hatchet-dev/typescript-sdk 1.24.0 → 1.24.2
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/README.md +1 -1
- package/clients/listeners/durable-listener/durable-listener-client.d.ts +2 -0
- package/clients/listeners/durable-listener/durable-listener-client.js +11 -4
- package/package.json +17 -3
- 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 +2 -0
- package/protoc/v1/dispatcher.js +41 -3
- package/protoc/v1/shared/condition.js +1 -1
- package/protoc/v1/shared/trigger.js +1 -1
- package/protoc/v1/workflows.js +1 -1
- package/protoc/workflows/workflows.js +1 -1
- package/v1/client/worker/context.js +3 -0
- package/v1/examples/durable/workflow.d.ts +11 -0
- package/v1/examples/durable/workflow.js +30 -1
- package/v1/examples/e2e-worker.js +2 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ pnpm add @hatchet-dev/typescript-sdk
|
|
|
32
32
|
|
|
33
33
|
## Quick Start
|
|
34
34
|
|
|
35
|
-
For examples of how to use the Hatchet TypeScript SDK, including worker setup and task execution, please see our [official documentation](https://docs.hatchet.run/
|
|
35
|
+
For examples of how to use the Hatchet TypeScript SDK, including worker setup and task execution, please see our [official documentation](https://docs.hatchet.run/v1).
|
|
36
36
|
|
|
37
37
|
## Features
|
|
38
38
|
|
|
@@ -37,6 +37,8 @@ export interface DurableTaskEventLogEntryResult {
|
|
|
37
37
|
durableTaskExternalId: string;
|
|
38
38
|
nodeId: number;
|
|
39
39
|
payload: Record<string, unknown> | undefined;
|
|
40
|
+
isFailure: boolean;
|
|
41
|
+
errorMessage: string | undefined;
|
|
40
42
|
}
|
|
41
43
|
export interface WaitForEvent {
|
|
42
44
|
kind: 'waitFor';
|
|
@@ -95,13 +95,15 @@ const WORKER_STATUS_POLL_INTERVAL_MS = 1000;
|
|
|
95
95
|
function eventLogEntryResultFromProto(proto) {
|
|
96
96
|
var _a, _b, _c, _d;
|
|
97
97
|
let payload;
|
|
98
|
-
if (proto.payload && proto.payload.length > 0) {
|
|
98
|
+
if (!proto.isFailure && proto.payload && proto.payload.length > 0) {
|
|
99
99
|
payload = JSON.parse(new TextDecoder().decode(proto.payload));
|
|
100
100
|
}
|
|
101
101
|
return {
|
|
102
102
|
durableTaskExternalId: (_b = (_a = proto.ref) === null || _a === void 0 ? void 0 : _a.durableTaskExternalId) !== null && _b !== void 0 ? _b : '',
|
|
103
103
|
nodeId: (_d = (_c = proto.ref) === null || _c === void 0 ? void 0 : _c.nodeId) !== null && _d !== void 0 ? _d : 0,
|
|
104
104
|
payload,
|
|
105
|
+
isFailure: proto.isFailure,
|
|
106
|
+
errorMessage: proto.errorMessage,
|
|
105
107
|
};
|
|
106
108
|
}
|
|
107
109
|
function ackKey(taskExtId, invocationCount) {
|
|
@@ -185,7 +187,9 @@ class DurableListenerClient {
|
|
|
185
187
|
}
|
|
186
188
|
_connect() {
|
|
187
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
var _a;
|
|
188
191
|
this.logger.info('durable event listener connecting...');
|
|
192
|
+
(_a = this._receiveAbort) === null || _a === void 0 ? void 0 : _a.abort();
|
|
189
193
|
this._requestQueue = [];
|
|
190
194
|
this._receiveAbort = new AbortController();
|
|
191
195
|
this._enqueueRequest({
|
|
@@ -246,12 +250,15 @@ class DurableListenerClient {
|
|
|
246
250
|
}
|
|
247
251
|
_requestIterator() {
|
|
248
252
|
return __asyncGenerator(this, arguments, function* _requestIterator_1() {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
253
|
+
const queue = this._requestQueue;
|
|
254
|
+
const { signal } = this._receiveAbort;
|
|
255
|
+
while (this._running && !signal.aborted) {
|
|
256
|
+
while (queue.length > 0) {
|
|
257
|
+
yield yield __await(queue.shift());
|
|
252
258
|
}
|
|
253
259
|
yield __await(new Promise((resolve) => {
|
|
254
260
|
this._requestNotify = resolve;
|
|
261
|
+
signal.addEventListener('abort', () => resolve(), { once: true });
|
|
255
262
|
}));
|
|
256
263
|
this._requestNotify = undefined;
|
|
257
264
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.2",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -15,8 +15,22 @@
|
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "https://github.com/hatchet-dev/hatchet.git"
|
|
17
17
|
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
|
|
18
|
+
"keywords": [
|
|
19
|
+
"typescript",
|
|
20
|
+
"hatchet",
|
|
21
|
+
"workflow",
|
|
22
|
+
"orchestration",
|
|
23
|
+
"background-tasks",
|
|
24
|
+
"job-queue",
|
|
25
|
+
"task-scheduling"
|
|
26
|
+
],
|
|
27
|
+
"author": "Hatchet <contact@hatchet.run>",
|
|
28
|
+
"contributors": [
|
|
29
|
+
"Alexander Belanger <alexander@hatchet.run>",
|
|
30
|
+
"Matt Kaye <matt@hatchet.run>",
|
|
31
|
+
"Gabe Ruttner <gabe@hatchet.run>",
|
|
32
|
+
"Mohammed Nafees <nafees@hatchet.run>"
|
|
33
|
+
],
|
|
20
34
|
"license": "MIT",
|
|
21
35
|
"devDependencies": {
|
|
22
36
|
"@aws-sdk/client-s3": "^3.1042.0",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.11.
|
|
4
|
+
// protoc-gen-ts_proto v2.11.8
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: dispatcher/dispatcher.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
package/protoc/events/events.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.11.
|
|
4
|
+
// protoc-gen-ts_proto v2.11.8
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: events/events.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.11.
|
|
4
|
+
// protoc-gen-ts_proto v2.11.8
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: google/protobuf/timestamp.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -43,6 +43,8 @@ export interface DurableTaskEventWaitForAckResponse {
|
|
|
43
43
|
export interface DurableTaskEventLogEntryCompletedResponse {
|
|
44
44
|
ref: DurableEventLogEntryRef | undefined;
|
|
45
45
|
payload: Uint8Array;
|
|
46
|
+
isFailure: boolean;
|
|
47
|
+
errorMessage?: string | undefined;
|
|
46
48
|
}
|
|
47
49
|
export interface DurableTaskEvictInvocationRequest {
|
|
48
50
|
invocationCount: number;
|
package/protoc/v1/dispatcher.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.11.
|
|
4
|
+
// protoc-gen-ts_proto v2.11.8
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: v1/dispatcher.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -619,7 +619,7 @@ exports.DurableTaskEventWaitForAckResponse = {
|
|
|
619
619
|
},
|
|
620
620
|
};
|
|
621
621
|
function createBaseDurableTaskEventLogEntryCompletedResponse() {
|
|
622
|
-
return { ref: undefined, payload: new Uint8Array(0) };
|
|
622
|
+
return { ref: undefined, payload: new Uint8Array(0), isFailure: false, errorMessage: undefined };
|
|
623
623
|
}
|
|
624
624
|
exports.DurableTaskEventLogEntryCompletedResponse = {
|
|
625
625
|
encode(message, writer = new wire_1.BinaryWriter()) {
|
|
@@ -629,6 +629,12 @@ exports.DurableTaskEventLogEntryCompletedResponse = {
|
|
|
629
629
|
if (message.payload.length !== 0) {
|
|
630
630
|
writer.uint32(18).bytes(message.payload);
|
|
631
631
|
}
|
|
632
|
+
if (message.isFailure !== false) {
|
|
633
|
+
writer.uint32(24).bool(message.isFailure);
|
|
634
|
+
}
|
|
635
|
+
if (message.errorMessage !== undefined) {
|
|
636
|
+
writer.uint32(34).string(message.errorMessage);
|
|
637
|
+
}
|
|
632
638
|
return writer;
|
|
633
639
|
},
|
|
634
640
|
decode(input, length) {
|
|
@@ -652,6 +658,20 @@ exports.DurableTaskEventLogEntryCompletedResponse = {
|
|
|
652
658
|
message.payload = reader.bytes();
|
|
653
659
|
continue;
|
|
654
660
|
}
|
|
661
|
+
case 3: {
|
|
662
|
+
if (tag !== 24) {
|
|
663
|
+
break;
|
|
664
|
+
}
|
|
665
|
+
message.isFailure = reader.bool();
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
case 4: {
|
|
669
|
+
if (tag !== 34) {
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
message.errorMessage = reader.string();
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
655
675
|
}
|
|
656
676
|
if ((tag & 7) === 4 || tag === 0) {
|
|
657
677
|
break;
|
|
@@ -664,6 +684,16 @@ exports.DurableTaskEventLogEntryCompletedResponse = {
|
|
|
664
684
|
return {
|
|
665
685
|
ref: isSet(object.ref) ? exports.DurableEventLogEntryRef.fromJSON(object.ref) : undefined,
|
|
666
686
|
payload: isSet(object.payload) ? bytesFromBase64(object.payload) : new Uint8Array(0),
|
|
687
|
+
isFailure: isSet(object.isFailure)
|
|
688
|
+
? globalThis.Boolean(object.isFailure)
|
|
689
|
+
: isSet(object.is_failure)
|
|
690
|
+
? globalThis.Boolean(object.is_failure)
|
|
691
|
+
: false,
|
|
692
|
+
errorMessage: isSet(object.errorMessage)
|
|
693
|
+
? globalThis.String(object.errorMessage)
|
|
694
|
+
: isSet(object.error_message)
|
|
695
|
+
? globalThis.String(object.error_message)
|
|
696
|
+
: undefined,
|
|
667
697
|
};
|
|
668
698
|
},
|
|
669
699
|
toJSON(message) {
|
|
@@ -674,19 +704,27 @@ exports.DurableTaskEventLogEntryCompletedResponse = {
|
|
|
674
704
|
if (message.payload.length !== 0) {
|
|
675
705
|
obj.payload = base64FromBytes(message.payload);
|
|
676
706
|
}
|
|
707
|
+
if (message.isFailure !== false) {
|
|
708
|
+
obj.isFailure = message.isFailure;
|
|
709
|
+
}
|
|
710
|
+
if (message.errorMessage !== undefined) {
|
|
711
|
+
obj.errorMessage = message.errorMessage;
|
|
712
|
+
}
|
|
677
713
|
return obj;
|
|
678
714
|
},
|
|
679
715
|
create(base) {
|
|
680
716
|
return exports.DurableTaskEventLogEntryCompletedResponse.fromPartial(base !== null && base !== void 0 ? base : {});
|
|
681
717
|
},
|
|
682
718
|
fromPartial(object) {
|
|
683
|
-
var _a;
|
|
719
|
+
var _a, _b, _c;
|
|
684
720
|
const message = createBaseDurableTaskEventLogEntryCompletedResponse();
|
|
685
721
|
message.ref =
|
|
686
722
|
object.ref !== undefined && object.ref !== null
|
|
687
723
|
? exports.DurableEventLogEntryRef.fromPartial(object.ref)
|
|
688
724
|
: undefined;
|
|
689
725
|
message.payload = (_a = object.payload) !== null && _a !== void 0 ? _a : new Uint8Array(0);
|
|
726
|
+
message.isFailure = (_b = object.isFailure) !== null && _b !== void 0 ? _b : false;
|
|
727
|
+
message.errorMessage = (_c = object.errorMessage) !== null && _c !== void 0 ? _c : undefined;
|
|
690
728
|
return message;
|
|
691
729
|
},
|
|
692
730
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.11.
|
|
4
|
+
// protoc-gen-ts_proto v2.11.8
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: v1/shared/condition.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.11.
|
|
4
|
+
// protoc-gen-ts_proto v2.11.8
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: v1/shared/trigger.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
package/protoc/v1/workflows.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.11.
|
|
4
|
+
// protoc-gen-ts_proto v2.11.8
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: v1/workflows.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
3
|
// versions:
|
|
4
|
-
// protoc-gen-ts_proto v2.11.
|
|
4
|
+
// protoc-gen-ts_proto v2.11.8
|
|
5
5
|
// protoc v3.19.1
|
|
6
6
|
// source: workflows/workflows.proto
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -894,6 +894,9 @@ class DurableContext extends Context {
|
|
|
894
894
|
});
|
|
895
895
|
const results = yield Promise.all(ack.runEntries.map((entry) => this.withEvictionWait('runChild', `workflow:bulk-child`, () => __awaiter(this, void 0, void 0, function* () {
|
|
896
896
|
const result = yield this._durableListener.waitForCallback(this.action.taskRunExternalId, this.invocationCount, entry.branchId, entry.nodeId, { signal: this.abortController.signal });
|
|
897
|
+
if (result.isFailure) {
|
|
898
|
+
throw new hatchet_error_1.default(result.errorMessage || 'child task failed');
|
|
899
|
+
}
|
|
897
900
|
return (result.payload || {});
|
|
898
901
|
}))));
|
|
899
902
|
return results;
|
|
@@ -82,6 +82,17 @@ export declare const memoNowCaching: import("../..").TaskWorkflowDeclaration<imp
|
|
|
82
82
|
start_time: string;
|
|
83
83
|
}, {}, {}, {}, {}>;
|
|
84
84
|
export declare const dagChildWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
|
|
85
|
+
export declare const errorRaisingTask: import("../..").TaskWorkflowDeclaration<{
|
|
86
|
+
error_message: string;
|
|
87
|
+
}, never, {}, {}, {}, {}>;
|
|
88
|
+
export declare const errorRaisingDurableParent: import("../..").TaskWorkflowDeclaration<{
|
|
89
|
+
error_message: string;
|
|
90
|
+
}, {
|
|
91
|
+
child_raised: boolean;
|
|
92
|
+
child_error_str: string | null;
|
|
93
|
+
child_run_external_id: string;
|
|
94
|
+
parent_run_external_id: string;
|
|
95
|
+
}, {}, {}, {}, {}>;
|
|
85
96
|
export declare const durableSpawnDag: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
|
|
86
97
|
sleep_duration: number;
|
|
87
98
|
sleep_duration_ms: number;
|
|
@@ -12,7 +12,7 @@ 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.durableSpawnDag = exports.dagChildWorkflow = exports.memoNowCaching = exports.waitForTwoEventsSecondPushedFirst = exports.waitForOrEventLookback = exports.waitForEventLookback = exports.LOOKBACK_WINDOW = exports.durableReplayReset = exports.REPLAY_RESET_MEMOIZED_MAX_SECONDS = exports.REPLAY_RESET_SLEEP_SECONDS = exports.durableNonDeterminism = exports.durableWithExplicitSpawn = exports.durableSleepEventSpawn = exports.durableWithBulkSpawn = exports.durableWithSpawn = exports.spawnChildTask = exports.waitForSleepTwice = exports.durableWorkflow = exports.SLEEP_TIME = exports.SLEEP_TIME_SECONDS = exports.EVENT_KEY = void 0;
|
|
15
|
+
exports.durableSpawnDag = exports.errorRaisingDurableParent = exports.errorRaisingTask = exports.dagChildWorkflow = exports.memoNowCaching = exports.waitForTwoEventsSecondPushedFirst = exports.waitForOrEventLookback = exports.waitForEventLookback = exports.LOOKBACK_WINDOW = exports.durableReplayReset = exports.REPLAY_RESET_MEMOIZED_MAX_SECONDS = exports.REPLAY_RESET_SLEEP_SECONDS = exports.durableNonDeterminism = exports.durableWithExplicitSpawn = exports.durableSleepEventSpawn = exports.durableWithBulkSpawn = exports.durableWithSpawn = exports.spawnChildTask = exports.waitForSleepTwice = exports.durableWorkflow = exports.SLEEP_TIME = exports.SLEEP_TIME_SECONDS = exports.EVENT_KEY = void 0;
|
|
16
16
|
const v4_1 = require("zod/v4");
|
|
17
17
|
const conditions_1 = require("../../conditions");
|
|
18
18
|
const non_determinism_error_1 = require("../../../util/errors/non-determinism-error");
|
|
@@ -301,6 +301,35 @@ exports.dagChildWorkflow.task({
|
|
|
301
301
|
return { result: 'child2' };
|
|
302
302
|
}),
|
|
303
303
|
});
|
|
304
|
+
// --- Error propagation test ---
|
|
305
|
+
exports.errorRaisingTask = hatchet_client_1.hatchet.task({
|
|
306
|
+
name: 'error-raising-task',
|
|
307
|
+
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
308
|
+
throw new Error(input.error_message);
|
|
309
|
+
}),
|
|
310
|
+
});
|
|
311
|
+
exports.errorRaisingDurableParent = hatchet_client_1.hatchet.durableTask({
|
|
312
|
+
name: 'error-raising-durable-parent',
|
|
313
|
+
executionTimeout: '30s',
|
|
314
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
315
|
+
let childRaised = false;
|
|
316
|
+
let childErrorStr = null;
|
|
317
|
+
const ref = yield exports.errorRaisingTask.runNoWait(input);
|
|
318
|
+
try {
|
|
319
|
+
yield ref.output;
|
|
320
|
+
}
|
|
321
|
+
catch (e) {
|
|
322
|
+
childRaised = true;
|
|
323
|
+
childErrorStr = e instanceof Error ? e.message : String(e);
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
child_raised: childRaised,
|
|
327
|
+
child_error_str: childErrorStr,
|
|
328
|
+
child_run_external_id: yield ref.runId,
|
|
329
|
+
parent_run_external_id: ctx.workflowRunId(),
|
|
330
|
+
};
|
|
331
|
+
}),
|
|
332
|
+
});
|
|
304
333
|
exports.durableSpawnDag = hatchet_client_1.hatchet.durableTask({
|
|
305
334
|
name: 'durable-spawn-dag',
|
|
306
335
|
executionTimeout: '10s',
|
|
@@ -70,6 +70,8 @@ const workflows = [
|
|
|
70
70
|
workflow_8.waitForEventLookback,
|
|
71
71
|
workflow_8.waitForOrEventLookback,
|
|
72
72
|
workflow_8.waitForTwoEventsSecondPushedFirst,
|
|
73
|
+
workflow_8.errorRaisingTask,
|
|
74
|
+
workflow_8.errorRaisingDurableParent,
|
|
73
75
|
workflow_9.durableEvent,
|
|
74
76
|
workflow_9.durableEventWithFilter,
|
|
75
77
|
workflow_11.durableSleep,
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.24.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.24.2";
|
package/version.js
CHANGED