@hatchet-dev/typescript-sdk 1.30.0 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/package.json +1 -1
  10. package/protoc/v1/workflows.d.ts +15 -0
  11. package/protoc/v1/workflows.js +62 -2
  12. package/v1/client/worker/context.d.ts +2 -0
  13. package/v1/client/worker/context.js +26 -8
  14. package/v1/client/worker/eviction/eviction-manager.d.ts +1 -1
  15. package/v1/client/worker/eviction/eviction-manager.js +12 -5
  16. package/v1/client/worker/worker-internal.d.ts +15 -0
  17. package/v1/client/worker/worker-internal.js +66 -29
  18. package/v1/declaration.d.ts +3 -1
  19. package/v1/embedded.d.ts +36 -2
  20. package/v1/embedded.js +35 -8
  21. package/v1/examples/concurrency_dynamic/workflow.d.ts +10 -0
  22. package/v1/examples/concurrency_dynamic/workflow.js +32 -0
  23. package/v1/examples/concurrency_shared/workflow.d.ts +17 -0
  24. package/v1/examples/concurrency_shared/workflow.js +70 -0
  25. package/v1/examples/durable_callback_ordering/workflow.d.ts +42 -0
  26. package/v1/examples/durable_callback_ordering/workflow.js +95 -0
  27. package/v1/examples/durable_eviction/workflow.d.ts +5 -0
  28. package/v1/examples/durable_eviction/workflow.js +15 -1
  29. package/v1/examples/e2e-worker.js +97 -88
  30. package/v1/task.d.ts +24 -3
  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',
@@ -25,29 +25,31 @@ const workflow_4 = require("./concurrency_cancel_newest/workflow");
25
25
  const workflow_5 = require("./concurrency_cancel_queued_except_newest/workflow");
26
26
  const workflow_6 = require("./concurrency_cancel_queued_except_oldest/workflow");
27
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_sleep/workflow");
34
- const workflow_14 = require("./logger/workflow");
35
- const workflow_15 = require("./non_retryable/workflow");
36
- const workflow_16 = require("./on_failure/workflow");
37
- const workflow_17 = require("./idempotency/workflow");
38
- const workflow_18 = require("./on_event/workflow");
39
- const workflow_19 = require("./return_exceptions/workflow");
40
- const workflow_20 = require("./run_details/workflow");
28
+ const workflow_8 = require("./concurrency_shared/workflow");
29
+ const workflow_9 = require("./concurrency_workflow_level/workflow");
30
+ const workflow_10 = require("./dag/workflow");
31
+ const workflow_11 = require("./durable/workflow");
32
+ const workflow_12 = require("./durable_event/workflow");
33
+ const workflow_13 = require("./durable_eviction/workflow");
34
+ const workflow_14 = require("./durable_callback_ordering/workflow");
35
+ const workflow_15 = require("./durable_sleep/workflow");
36
+ const workflow_16 = require("./logger/workflow");
37
+ const workflow_17 = require("./non_retryable/workflow");
38
+ const workflow_18 = require("./on_failure/workflow");
39
+ const workflow_19 = require("./idempotency/workflow");
40
+ const workflow_20 = require("./on_event/workflow");
41
+ const workflow_21 = require("./return_exceptions/workflow");
42
+ const workflow_22 = require("./run_details/workflow");
41
43
  const e2e_workflows_1 = require("./simple/e2e-workflows");
42
- const workflow_21 = require("./batch_assign/workflow");
43
- const workflow_22 = require("./streaming/workflow");
44
- const workflow_23 = require("./subscribe_to_stream/workflow");
45
- const workflow_24 = require("./timeout/workflow");
46
- const workflow_25 = require("./webhooks/workflow");
47
- const workflow_26 = require("./child_index/workflow");
48
- const workflow_27 = require("./support_agent/workflow");
49
- const workflow_28 = require("./welcome_email/workflow");
50
- const workflow_29 = require("./pdf_pipeline/workflow");
44
+ const workflow_23 = require("./batch_assign/workflow");
45
+ const workflow_24 = require("./streaming/workflow");
46
+ const workflow_25 = require("./subscribe_to_stream/workflow");
47
+ const workflow_26 = require("./timeout/workflow");
48
+ const workflow_27 = require("./webhooks/workflow");
49
+ const workflow_28 = require("./child_index/workflow");
50
+ const workflow_29 = require("./support_agent/workflow");
51
+ const workflow_30 = require("./welcome_email/workflow");
52
+ const workflow_31 = require("./pdf_pipeline/workflow");
51
53
  const workflows = [
52
54
  workflow_1.bulkChild,
53
55
  workflow_1.bulkParentWorkflow,
@@ -61,74 +63,81 @@ const workflows = [
61
63
  workflow_5.concurrencyCancelQueuedExceptNewestWorkflow,
62
64
  workflow_6.concurrencyCancelQueuedExceptOldestWorkflow,
63
65
  workflow_7.concurrencyMultipleKeysWorkflow,
64
- workflow_8.concurrencyWorkflowLevelWorkflow,
65
- workflow_9.dag,
66
- workflow_10.durableWorkflow,
67
- workflow_10.waitForSleepTwice,
68
- workflow_10.spawnChildTask,
69
- workflow_10.durableWithSpawn,
70
- workflow_10.durableWithBulkSpawn,
71
- workflow_10.durableSleepEventSpawn,
72
- workflow_10.durableWithExplicitSpawn,
73
- workflow_10.durableNonDeterminism,
74
- workflow_10.durableReplayReset,
75
- workflow_10.dagChildWorkflow,
76
- workflow_10.durableSpawnDag,
77
- workflow_10.waitForEventLookback,
78
- workflow_10.waitForOrEventLookback,
79
- workflow_10.waitForTwoEventsSecondPushedFirst,
80
- workflow_10.errorRaisingTask,
81
- workflow_10.errorRaisingDurableParent,
82
- workflow_11.durableEvent,
83
- workflow_11.durableEventWithFilter,
84
- workflow_13.durableSleep,
85
- workflow_12.evictableSleep,
86
- workflow_12.evictableWaitForEvent,
87
- workflow_12.evictableChildSpawn,
88
- workflow_12.multipleEviction,
89
- workflow_12.nonEvictableSleep,
90
- workflow_12.childTask,
91
- workflow_12.bulkChildTask,
92
- workflow_12.evictableChildBulkSpawn,
93
- (0, workflow_14.createLoggingWorkflow)(hatchet_client_1.hatchet),
94
- workflow_15.nonRetryableWorkflow,
95
- workflow_16.failureWorkflow,
96
- workflow_17.idempotentTask,
97
- workflow_17.idempotentTaskShortWindow,
98
- workflow_18.lower,
99
- workflow_19.returnExceptionsTask,
100
- workflow_20.runDetailTestWorkflow,
66
+ workflow_8.concurrencySharedWorkflowA,
67
+ workflow_8.concurrencySharedWorkflowB,
68
+ workflow_8.concurrencySharedMixedWorkflow,
69
+ workflow_9.concurrencyWorkflowLevelWorkflow,
70
+ workflow_10.dag,
71
+ workflow_11.durableWorkflow,
72
+ workflow_11.waitForSleepTwice,
73
+ workflow_11.spawnChildTask,
74
+ workflow_11.durableWithSpawn,
75
+ workflow_11.durableWithBulkSpawn,
76
+ workflow_11.durableSleepEventSpawn,
77
+ workflow_11.durableWithExplicitSpawn,
78
+ workflow_11.durableNonDeterminism,
79
+ workflow_11.durableReplayReset,
80
+ workflow_11.dagChildWorkflow,
81
+ workflow_11.durableSpawnDag,
82
+ workflow_11.waitForEventLookback,
83
+ workflow_11.waitForOrEventLookback,
84
+ workflow_11.waitForTwoEventsSecondPushedFirst,
85
+ workflow_11.errorRaisingTask,
86
+ workflow_11.errorRaisingDurableParent,
87
+ workflow_12.durableEvent,
88
+ workflow_12.durableEventWithFilter,
89
+ workflow_14.callbackOrderingLeaf,
90
+ workflow_14.callbackOrderingMid,
91
+ workflow_14.callbackOrderingRoot,
92
+ workflow_15.durableSleep,
93
+ workflow_13.evictableSleep,
94
+ workflow_13.evictableWaitForEvent,
95
+ workflow_13.evictableMemoThenWaitForEvent,
96
+ workflow_13.evictableChildSpawn,
97
+ workflow_13.multipleEviction,
98
+ workflow_13.nonEvictableSleep,
99
+ workflow_13.childTask,
100
+ workflow_13.bulkChildTask,
101
+ workflow_13.evictableChildBulkSpawn,
102
+ (0, workflow_16.createLoggingWorkflow)(hatchet_client_1.hatchet),
103
+ workflow_17.nonRetryableWorkflow,
104
+ workflow_18.failureWorkflow,
105
+ workflow_19.idempotentTask,
106
+ workflow_19.idempotentTaskShortWindow,
107
+ workflow_20.lower,
108
+ workflow_21.returnExceptionsTask,
109
+ workflow_22.runDetailTestWorkflow,
101
110
  e2e_workflows_1.helloWorld,
102
111
  e2e_workflows_1.helloWorldDurable,
103
- workflow_22.streamingTask,
104
- workflow_23.dagStream,
105
- workflow_23.longStream,
106
- workflow_24.timeoutTask,
107
- workflow_24.refreshTimeoutTask,
108
- workflow_25.webhookWorkflow,
109
- workflow_26.childIndexChild,
110
- workflow_26.childIndexParent,
111
- workflow_26.scenarioTask,
112
- workflow_26.orchestratorTask,
113
- workflow_27.supportAgent,
114
- workflow_27.triageTicket,
115
- workflow_27.generateReply,
116
- workflow_27.escalateTicket,
117
- workflow_28.welcomeEmail,
118
- workflow_29.pdfPipeline,
119
- workflow_21.batchSimple,
120
- workflow_21.batchKeyed,
121
- workflow_21.batchKeyedFailable,
122
- workflow_21.batchKeyedInterval,
123
- workflow_21.batchLarge,
124
- workflow_21.batchSingle,
125
- workflow_21.batchOrdered,
126
- workflow_21.batchBroadcast,
127
- workflow_21.batchCancel,
128
- workflow_21.child,
129
- workflow_21.childBatch,
130
- workflow_21.batchChildSpawn,
131
- workflow_21.batchChildBatchSpawn,
112
+ workflow_24.streamingTask,
113
+ workflow_25.dagStream,
114
+ workflow_25.longStream,
115
+ workflow_26.timeoutTask,
116
+ workflow_26.refreshTimeoutTask,
117
+ workflow_27.webhookWorkflow,
118
+ workflow_28.childIndexChild,
119
+ workflow_28.childIndexParent,
120
+ workflow_28.scenarioTask,
121
+ workflow_28.orchestratorTask,
122
+ workflow_29.supportAgent,
123
+ workflow_29.triageTicket,
124
+ workflow_29.generateReply,
125
+ workflow_29.escalateTicket,
126
+ workflow_30.welcomeEmail,
127
+ workflow_31.pdfPipeline,
128
+ workflow_23.batchSimple,
129
+ workflow_23.batchKeyed,
130
+ workflow_23.batchKeyedFailable,
131
+ workflow_23.batchKeyedInterval,
132
+ workflow_23.batchLarge,
133
+ workflow_23.batchSingle,
134
+ workflow_23.batchOrdered,
135
+ workflow_23.batchBroadcast,
136
+ workflow_23.batchCancel,
137
+ workflow_23.child,
138
+ workflow_23.childBatch,
139
+ workflow_23.batchChildSpawn,
140
+ workflow_23.batchChildBatchSpawn,
132
141
  ];
133
142
  function main() {
134
143
  return __awaiter(this, void 0, void 0, function* () {
package/v1/task.d.ts CHANGED
@@ -11,7 +11,7 @@ export { ConcurrencyLimitStrategy, WorkerLabelComparator };
11
11
  */
12
12
  export type Concurrency = {
13
13
  /**
14
- * required the CEL expression to use for concurrency
14
+ * required: the CEL expression to use for concurrency
15
15
  *
16
16
  * @example
17
17
  * ```
@@ -20,17 +20,38 @@ export type Concurrency = {
20
20
  */
21
21
  expression: string;
22
22
  /**
23
- * (optional) the maximum number of concurrent workflow runs
23
+ * (optional) the maximum number of concurrent runs: a fixed number, or a CEL
24
+ * expression over task input computing the max runs for that task's concurrency
25
+ * group. With an expression, a group's effective limit is the value from its most
26
+ * recently created task.
24
27
  *
25
28
  * default: 1
29
+ *
30
+ * @example
31
+ * ```
32
+ * maxRuns: 5
33
+ * maxRuns: "input.tier == 'premium' ? 10 : 1"
34
+ * ```
26
35
  */
27
- maxRuns?: number;
36
+ maxRuns?: number | string;
28
37
  /**
29
38
  * (optional) the strategy to use when the concurrency limit is reached
30
39
  *
31
40
  * default: CANCEL_IN_PROGRESS
32
41
  */
33
42
  limitStrategy?: ConcurrencyLimitStrategy;
43
+ /**
44
+ * (required when isTenantScoped) the strategy name; unique per tenant for tenant-scoped
45
+ * strategies
46
+ */
47
+ name?: string;
48
+ /**
49
+ * (optional) when true, the entry defines (or updates in place) a tenant-scoped strategy
50
+ * shared across workflows, keyed by name: every task declaring the same name consumes
51
+ * the same concurrency limit. The position in the concurrency list is the chain order,
52
+ * and chains sharing tenant-scoped strategies must order them consistently.
53
+ */
54
+ isTenantScoped?: boolean;
34
55
  };
35
56
  /**
36
57
  * @deprecated use Concurrency instead
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.30.0";
1
+ export declare const HATCHET_VERSION = "1.31.0";
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.30.0';
4
+ exports.HATCHET_VERSION = '1.31.0';