@hatchet-dev/typescript-sdk 1.29.3 → 1.30.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.
Files changed (32) hide show
  1. package/clients/dispatcher/action-listener.d.ts +1 -1
  2. package/clients/dispatcher/action-listener.js +6 -0
  3. package/clients/listeners/durable-listener/durable-listener-client.d.ts +6 -1
  4. package/clients/listeners/durable-listener/durable-listener-client.js +124 -37
  5. package/clients/rest/generated/Api.d.ts +6 -1
  6. package/clients/rest/generated/Api.js +1 -1
  7. package/clients/rest/generated/data-contracts.d.ts +9 -1
  8. package/clients/rest/generated/data-contracts.js +1 -0
  9. package/legacy/workflow.d.ts +4 -4
  10. package/legacy/workflow.js +1 -1
  11. package/package.json +1 -1
  12. package/protoc/v1/workflows.d.ts +17 -0
  13. package/protoc/v1/workflows.js +74 -2
  14. package/v1/client/worker/context.d.ts +2 -0
  15. package/v1/client/worker/context.js +26 -8
  16. package/v1/client/worker/eviction/eviction-manager.d.ts +1 -1
  17. package/v1/client/worker/eviction/eviction-manager.js +12 -5
  18. package/v1/client/worker/worker-internal.d.ts +2 -1
  19. package/v1/client/worker/worker-internal.js +52 -25
  20. package/v1/embedded.d.ts +36 -2
  21. package/v1/embedded.js +35 -8
  22. package/v1/examples/concurrency_cancel_queued_except_newest/workflow.d.ts +9 -0
  23. package/v1/examples/concurrency_cancel_queued_except_newest/workflow.js +47 -0
  24. package/v1/examples/concurrency_cancel_queued_except_oldest/workflow.d.ts +9 -0
  25. package/v1/examples/concurrency_cancel_queued_except_oldest/workflow.js +47 -0
  26. package/v1/examples/durable_callback_ordering/workflow.d.ts +42 -0
  27. package/v1/examples/durable_callback_ordering/workflow.js +95 -0
  28. package/v1/examples/durable_eviction/workflow.d.ts +5 -0
  29. package/v1/examples/durable_eviction/workflow.js +15 -1
  30. package/v1/examples/e2e-worker.js +99 -90
  31. package/version.d.ts +1 -1
  32. package/version.js +1 -1
@@ -0,0 +1,95 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.callbackOrderingRoot = exports.callbackOrderingMid = exports.callbackOrderingLeaf = exports.ROOT_DEFAULTS = void 0;
16
+ const sleep_1 = __importDefault(require("../../../util/sleep"));
17
+ const hatchet_client_1 = require("../hatchet-client");
18
+ const WORKFLOW_PREFIX = 'durable-callback-ordering';
19
+ const EVICTION_POLICY = {
20
+ ttl: 250,
21
+ allowCapacityEviction: true,
22
+ priority: 0,
23
+ };
24
+ exports.ROOT_DEFAULTS = {
25
+ durables: 4,
26
+ branches: 8,
27
+ childDelayMs: 1500,
28
+ delayStepMs: 3,
29
+ };
30
+ exports.callbackOrderingLeaf = hatchet_client_1.hatchet.task({
31
+ name: `${WORKFLOW_PREFIX}-leaf`,
32
+ executionTimeout: '1m',
33
+ fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
34
+ yield (0, sleep_1.default)(input.delayMs);
35
+ return { mid: input.mid, branch: input.branch, generation: input.generation };
36
+ }),
37
+ });
38
+ exports.callbackOrderingMid = hatchet_client_1.hatchet.durableTask({
39
+ name: `${WORKFLOW_PREFIX}-mid`,
40
+ executionTimeout: '5m',
41
+ retries: 0,
42
+ evictionPolicy: EVICTION_POLICY,
43
+ fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
44
+ // Staggered first-generation children complete out of spawn order, so each
45
+ // branch's second-generation spawn is emitted in completion order. Replays
46
+ // after eviction must re-deliver those completions in the recorded order or
47
+ // the re-emitted spawn sequence diverges from the event log.
48
+ const branch = (branchIndex) => __awaiter(void 0, void 0, void 0, function* () {
49
+ const firstDelayMs = input.childDelayMs + (input.branches - branchIndex - 1) * input.delayStepMs;
50
+ const first = yield exports.callbackOrderingLeaf.run({
51
+ mid: input.mid,
52
+ branch: branchIndex,
53
+ delayMs: firstDelayMs,
54
+ generation: 1,
55
+ });
56
+ const second = yield exports.callbackOrderingLeaf.run({
57
+ mid: input.mid,
58
+ branch: first.branch,
59
+ delayMs: input.childDelayMs,
60
+ generation: 2,
61
+ });
62
+ return second.branch;
63
+ });
64
+ const completed = yield Promise.all(Array.from({ length: input.branches }, (_, branchIndex) => branch(branchIndex)));
65
+ return {
66
+ mid: input.mid,
67
+ completedBranches: completed,
68
+ invocationCount: ctx.invocationCount,
69
+ };
70
+ }),
71
+ });
72
+ exports.callbackOrderingRoot = hatchet_client_1.hatchet.durableTask({
73
+ name: `${WORKFLOW_PREFIX}-root`,
74
+ executionTimeout: '10m',
75
+ retries: 0,
76
+ evictionPolicy: EVICTION_POLICY,
77
+ fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
78
+ var _a;
79
+ const durables = (_a = input.durables) !== null && _a !== void 0 ? _a : exports.ROOT_DEFAULTS.durables;
80
+ const results = yield Promise.all(Array.from({ length: durables }, (_, midIndex) => {
81
+ var _a, _b, _c;
82
+ return exports.callbackOrderingMid.run({
83
+ mid: midIndex,
84
+ branches: (_a = input.branches) !== null && _a !== void 0 ? _a : exports.ROOT_DEFAULTS.branches,
85
+ childDelayMs: (_b = input.childDelayMs) !== null && _b !== void 0 ? _b : exports.ROOT_DEFAULTS.childDelayMs,
86
+ delayStepMs: (_c = input.delayStepMs) !== null && _c !== void 0 ? _c : exports.ROOT_DEFAULTS.delayStepMs,
87
+ });
88
+ }));
89
+ return {
90
+ rootInvocationCount: ctx.invocationCount,
91
+ midInvocationCounts: results.map((item) => item.invocationCount),
92
+ completedMids: results.map((item) => item.mid),
93
+ };
94
+ }),
95
+ });
@@ -13,6 +13,11 @@ export declare const evictableSleepForGracefulTermination: import("../..").TaskW
13
13
  export declare const evictableWaitForEvent: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
14
14
  status: string;
15
15
  }, {}, {}, {}, {}>;
16
+ export declare const MEMO_EVENT_KEY = "durable-eviction:memo-event";
17
+ export declare const evictableMemoThenWaitForEvent: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
18
+ status: string;
19
+ memoizedNow: string;
20
+ }, {}, {}, {}, {}>;
16
21
  export declare const evictableChildSpawn: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
17
22
  child: {
18
23
  child_status: string;
@@ -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.nonEvictableSleep = exports.capacityEvictableSleep = exports.CAPACITY_SLEEP_SECONDS = exports.evictableChildBulkSpawn = exports.bulkChildTask = exports.multipleEviction = exports.evictableChildSpawn = exports.evictableWaitForEvent = exports.evictableSleepForGracefulTermination = exports.evictableSleep = exports.childTask = exports.EVENT_KEY = exports.LONG_SLEEP_SECONDS = exports.EVICTION_TTL_SECONDS = void 0;
15
+ exports.nonEvictableSleep = exports.capacityEvictableSleep = exports.CAPACITY_SLEEP_SECONDS = exports.evictableChildBulkSpawn = exports.bulkChildTask = exports.multipleEviction = exports.evictableChildSpawn = exports.evictableMemoThenWaitForEvent = exports.MEMO_EVENT_KEY = exports.evictableWaitForEvent = exports.evictableSleepForGracefulTermination = exports.evictableSleep = exports.childTask = exports.EVENT_KEY = exports.LONG_SLEEP_SECONDS = exports.EVICTION_TTL_SECONDS = void 0;
16
16
  const sleep_1 = __importDefault(require("../../../util/sleep"));
17
17
  const hatchet_client_1 = require("../hatchet-client");
18
18
  exports.EVICTION_TTL_SECONDS = 5;
@@ -66,6 +66,20 @@ exports.evictableWaitForEvent = hatchet_client_1.hatchet.durableTask({
66
66
  return { status: 'completed' };
67
67
  }),
68
68
  });
69
+ exports.MEMO_EVENT_KEY = 'durable-eviction:memo-event';
70
+ exports.evictableMemoThenWaitForEvent = hatchet_client_1.hatchet.durableTask({
71
+ name: 'evictable-memo-then-wait-for-event',
72
+ executionTimeout: '5m',
73
+ evictionPolicy: EVICTION_POLICY,
74
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
75
+ // now() records a memo node. On replay after eviction, the server
76
+ // re-delivers that node's completion, which never has a callback waiter
77
+ // and must not block the event completion queued behind it.
78
+ const memoizedNow = yield ctx.now();
79
+ yield ctx.waitForEvent(exports.MEMO_EVENT_KEY, 'true');
80
+ return { status: 'completed', memoizedNow: memoizedNow.toISOString() };
81
+ }),
82
+ });
69
83
  exports.evictableChildSpawn = hatchet_client_1.hatchet.durableTask({
70
84
  name: 'evictable-child-spawn',
71
85
  executionTimeout: '5m',
@@ -22,30 +22,33 @@ const cancellation_workflow_1 = require("./cancellation/cancellation-workflow");
22
22
  const complex_workflow_1 = require("./conditions/complex-workflow");
23
23
  const workflow_3 = require("./concurrency_cancel_in_progress/workflow");
24
24
  const workflow_4 = require("./concurrency_cancel_newest/workflow");
25
- const workflow_5 = require("./concurrency_multiple_keys/workflow");
26
- const workflow_6 = require("./concurrency_workflow_level/workflow");
27
- const workflow_7 = require("./dag/workflow");
28
- const workflow_8 = require("./durable/workflow");
29
- const workflow_9 = require("./durable_event/workflow");
30
- const workflow_10 = require("./durable_eviction/workflow");
31
- const workflow_11 = require("./durable_sleep/workflow");
32
- const workflow_12 = require("./logger/workflow");
33
- const workflow_13 = require("./non_retryable/workflow");
34
- const workflow_14 = require("./on_failure/workflow");
35
- const workflow_15 = require("./idempotency/workflow");
36
- const workflow_16 = require("./on_event/workflow");
37
- const workflow_17 = require("./return_exceptions/workflow");
38
- const workflow_18 = require("./run_details/workflow");
25
+ const workflow_5 = require("./concurrency_cancel_queued_except_newest/workflow");
26
+ const workflow_6 = require("./concurrency_cancel_queued_except_oldest/workflow");
27
+ const workflow_7 = require("./concurrency_multiple_keys/workflow");
28
+ const workflow_8 = require("./concurrency_workflow_level/workflow");
29
+ const workflow_9 = require("./dag/workflow");
30
+ const workflow_10 = require("./durable/workflow");
31
+ const workflow_11 = require("./durable_event/workflow");
32
+ const workflow_12 = require("./durable_eviction/workflow");
33
+ const workflow_13 = require("./durable_callback_ordering/workflow");
34
+ const workflow_14 = require("./durable_sleep/workflow");
35
+ const workflow_15 = require("./logger/workflow");
36
+ const workflow_16 = require("./non_retryable/workflow");
37
+ const workflow_17 = require("./on_failure/workflow");
38
+ const workflow_18 = require("./idempotency/workflow");
39
+ const workflow_19 = require("./on_event/workflow");
40
+ const workflow_20 = require("./return_exceptions/workflow");
41
+ const workflow_21 = require("./run_details/workflow");
39
42
  const e2e_workflows_1 = require("./simple/e2e-workflows");
40
- const workflow_19 = require("./batch_assign/workflow");
41
- const workflow_20 = require("./streaming/workflow");
42
- const workflow_21 = require("./subscribe_to_stream/workflow");
43
- const workflow_22 = require("./timeout/workflow");
44
- const workflow_23 = require("./webhooks/workflow");
45
- const workflow_24 = require("./child_index/workflow");
46
- const workflow_25 = require("./support_agent/workflow");
47
- const workflow_26 = require("./welcome_email/workflow");
48
- const workflow_27 = require("./pdf_pipeline/workflow");
43
+ const workflow_22 = require("./batch_assign/workflow");
44
+ const workflow_23 = require("./streaming/workflow");
45
+ const workflow_24 = require("./subscribe_to_stream/workflow");
46
+ const workflow_25 = require("./timeout/workflow");
47
+ const workflow_26 = require("./webhooks/workflow");
48
+ const workflow_27 = require("./child_index/workflow");
49
+ const workflow_28 = require("./support_agent/workflow");
50
+ const workflow_29 = require("./welcome_email/workflow");
51
+ const workflow_30 = require("./pdf_pipeline/workflow");
49
52
  const workflows = [
50
53
  workflow_1.bulkChild,
51
54
  workflow_1.bulkParentWorkflow,
@@ -56,75 +59,81 @@ const workflows = [
56
59
  complex_workflow_1.taskConditionWorkflow,
57
60
  workflow_3.concurrencyCancelInProgressWorkflow,
58
61
  workflow_4.concurrencyCancelNewestWorkflow,
59
- workflow_5.concurrencyMultipleKeysWorkflow,
60
- workflow_6.concurrencyWorkflowLevelWorkflow,
61
- workflow_7.dag,
62
- workflow_8.durableWorkflow,
63
- workflow_8.waitForSleepTwice,
64
- workflow_8.spawnChildTask,
65
- workflow_8.durableWithSpawn,
66
- workflow_8.durableWithBulkSpawn,
67
- workflow_8.durableSleepEventSpawn,
68
- workflow_8.durableWithExplicitSpawn,
69
- workflow_8.durableNonDeterminism,
70
- workflow_8.durableReplayReset,
71
- workflow_8.dagChildWorkflow,
72
- workflow_8.durableSpawnDag,
73
- workflow_8.waitForEventLookback,
74
- workflow_8.waitForOrEventLookback,
75
- workflow_8.waitForTwoEventsSecondPushedFirst,
76
- workflow_8.errorRaisingTask,
77
- workflow_8.errorRaisingDurableParent,
78
- workflow_9.durableEvent,
79
- workflow_9.durableEventWithFilter,
80
- workflow_11.durableSleep,
81
- workflow_10.evictableSleep,
82
- workflow_10.evictableWaitForEvent,
83
- workflow_10.evictableChildSpawn,
84
- workflow_10.multipleEviction,
85
- workflow_10.nonEvictableSleep,
86
- workflow_10.childTask,
87
- workflow_10.bulkChildTask,
88
- workflow_10.evictableChildBulkSpawn,
89
- (0, workflow_12.createLoggingWorkflow)(hatchet_client_1.hatchet),
90
- workflow_13.nonRetryableWorkflow,
91
- workflow_14.failureWorkflow,
92
- workflow_15.idempotentTask,
93
- workflow_15.idempotentTaskShortWindow,
94
- workflow_16.lower,
95
- workflow_17.returnExceptionsTask,
96
- workflow_18.runDetailTestWorkflow,
62
+ workflow_5.concurrencyCancelQueuedExceptNewestWorkflow,
63
+ workflow_6.concurrencyCancelQueuedExceptOldestWorkflow,
64
+ workflow_7.concurrencyMultipleKeysWorkflow,
65
+ workflow_8.concurrencyWorkflowLevelWorkflow,
66
+ workflow_9.dag,
67
+ workflow_10.durableWorkflow,
68
+ workflow_10.waitForSleepTwice,
69
+ workflow_10.spawnChildTask,
70
+ workflow_10.durableWithSpawn,
71
+ workflow_10.durableWithBulkSpawn,
72
+ workflow_10.durableSleepEventSpawn,
73
+ workflow_10.durableWithExplicitSpawn,
74
+ workflow_10.durableNonDeterminism,
75
+ workflow_10.durableReplayReset,
76
+ workflow_10.dagChildWorkflow,
77
+ workflow_10.durableSpawnDag,
78
+ workflow_10.waitForEventLookback,
79
+ workflow_10.waitForOrEventLookback,
80
+ workflow_10.waitForTwoEventsSecondPushedFirst,
81
+ workflow_10.errorRaisingTask,
82
+ workflow_10.errorRaisingDurableParent,
83
+ workflow_11.durableEvent,
84
+ workflow_11.durableEventWithFilter,
85
+ workflow_13.callbackOrderingLeaf,
86
+ workflow_13.callbackOrderingMid,
87
+ workflow_13.callbackOrderingRoot,
88
+ workflow_14.durableSleep,
89
+ workflow_12.evictableSleep,
90
+ workflow_12.evictableWaitForEvent,
91
+ workflow_12.evictableMemoThenWaitForEvent,
92
+ workflow_12.evictableChildSpawn,
93
+ workflow_12.multipleEviction,
94
+ workflow_12.nonEvictableSleep,
95
+ workflow_12.childTask,
96
+ workflow_12.bulkChildTask,
97
+ workflow_12.evictableChildBulkSpawn,
98
+ (0, workflow_15.createLoggingWorkflow)(hatchet_client_1.hatchet),
99
+ workflow_16.nonRetryableWorkflow,
100
+ workflow_17.failureWorkflow,
101
+ workflow_18.idempotentTask,
102
+ workflow_18.idempotentTaskShortWindow,
103
+ workflow_19.lower,
104
+ workflow_20.returnExceptionsTask,
105
+ workflow_21.runDetailTestWorkflow,
97
106
  e2e_workflows_1.helloWorld,
98
107
  e2e_workflows_1.helloWorldDurable,
99
- workflow_20.streamingTask,
100
- workflow_21.dagStream,
101
- workflow_21.longStream,
102
- workflow_22.timeoutTask,
103
- workflow_22.refreshTimeoutTask,
104
- workflow_23.webhookWorkflow,
105
- workflow_24.childIndexChild,
106
- workflow_24.childIndexParent,
107
- workflow_24.scenarioTask,
108
- workflow_24.orchestratorTask,
109
- workflow_25.supportAgent,
110
- workflow_25.triageTicket,
111
- workflow_25.generateReply,
112
- workflow_25.escalateTicket,
113
- workflow_26.welcomeEmail,
114
- workflow_27.pdfPipeline,
115
- workflow_19.batchSimple,
116
- workflow_19.batchKeyed,
117
- workflow_19.batchKeyedFailable,
118
- workflow_19.batchKeyedInterval,
119
- workflow_19.batchLarge,
120
- workflow_19.batchSingle,
121
- workflow_19.batchOrdered,
122
- workflow_19.batchBroadcast,
123
- workflow_19.batchCancel,
124
- workflow_19.child,
125
- workflow_19.childBatch,
126
- workflow_19.batchChildSpawn,
127
- workflow_19.batchChildBatchSpawn,
108
+ workflow_23.streamingTask,
109
+ workflow_24.dagStream,
110
+ workflow_24.longStream,
111
+ workflow_25.timeoutTask,
112
+ workflow_25.refreshTimeoutTask,
113
+ workflow_26.webhookWorkflow,
114
+ workflow_27.childIndexChild,
115
+ workflow_27.childIndexParent,
116
+ workflow_27.scenarioTask,
117
+ workflow_27.orchestratorTask,
118
+ workflow_28.supportAgent,
119
+ workflow_28.triageTicket,
120
+ workflow_28.generateReply,
121
+ workflow_28.escalateTicket,
122
+ workflow_29.welcomeEmail,
123
+ workflow_30.pdfPipeline,
124
+ workflow_22.batchSimple,
125
+ workflow_22.batchKeyed,
126
+ workflow_22.batchKeyedFailable,
127
+ workflow_22.batchKeyedInterval,
128
+ workflow_22.batchLarge,
129
+ workflow_22.batchSingle,
130
+ workflow_22.batchOrdered,
131
+ workflow_22.batchBroadcast,
132
+ workflow_22.batchCancel,
133
+ workflow_22.child,
134
+ workflow_22.childBatch,
135
+ workflow_22.batchChildSpawn,
136
+ workflow_22.batchChildBatchSpawn,
128
137
  ];
129
138
  function main() {
130
139
  return __awaiter(this, void 0, void 0, function* () {
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.29.3";
1
+ export declare const HATCHET_VERSION = "1.30.1";
package/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HATCHET_VERSION = void 0;
4
- exports.HATCHET_VERSION = '1.29.3';
4
+ exports.HATCHET_VERSION = '1.30.1';