@hatchet-dev/typescript-sdk 1.15.2 → 1.17.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 (202) hide show
  1. package/README.md +14 -2
  2. package/clients/admin/admin-client.d.ts +2 -2
  3. package/clients/admin/admin-client.js +8 -9
  4. package/clients/dispatcher/action-listener.d.ts +3 -6
  5. package/clients/dispatcher/action-listener.js +54 -23
  6. package/clients/dispatcher/dispatcher-client.js +5 -8
  7. package/clients/dispatcher/heartbeat/heartbeat-worker.js +7 -4
  8. package/clients/event/event-client.d.ts +2 -2
  9. package/clients/event/event-client.js +5 -11
  10. package/clients/hatchet-client/hatchet-logger.js +8 -17
  11. package/clients/listeners/durable-listener/durable-listener-client.d.ts +115 -15
  12. package/clients/listeners/durable-listener/durable-listener-client.js +769 -19
  13. package/clients/listeners/durable-listener/pooled-durable-listener-client.js +11 -22
  14. package/clients/listeners/run-listener/child-listener-client.d.ts +1 -1
  15. package/clients/listeners/run-listener/child-listener-client.js +34 -30
  16. package/clients/listeners/run-listener/pooled-child-listener-client.js +9 -19
  17. package/clients/rest/generated/Api.d.ts +25 -1
  18. package/clients/rest/generated/Api.js +20 -0
  19. package/clients/rest/generated/data-contracts.d.ts +60 -1
  20. package/clients/rest/generated/data-contracts.js +9 -1
  21. package/legacy/examples/affinity-workers.js +2 -3
  22. package/legacy/examples/byo-logger.js +0 -2
  23. package/legacy/examples/concurrency/cancel-in-progress/concurrency-worker.js +4 -2
  24. package/legacy/examples/concurrency/group-round-robin/concurrency-event.js +0 -1
  25. package/legacy/examples/concurrency/group-round-robin/concurrency-worker-expression.js +4 -2
  26. package/legacy/examples/concurrency/group-round-robin/concurrency-worker-key-fn.js +4 -2
  27. package/legacy/examples/example-event.js +0 -3
  28. package/legacy/examples/logger.js +0 -1
  29. package/legacy/examples/sticky-worker-with-check.js +0 -1
  30. package/legacy/examples/sticky-worker.js +0 -1
  31. package/legacy/legacy-client.js +2 -2
  32. package/legacy/legacy-transformer.js +2 -4
  33. package/legacy/step.d.ts +16 -16
  34. package/legacy/step.js +8 -17
  35. package/legacy/workflow.d.ts +81 -81
  36. package/package.json +20 -29
  37. package/protoc/dispatcher/dispatcher.d.ts +20 -0
  38. package/protoc/dispatcher/dispatcher.js +136 -2
  39. package/protoc/v1/dispatcher.d.ts +168 -0
  40. package/protoc/v1/dispatcher.js +1920 -1
  41. package/protoc/v1/shared/trigger.d.ts +89 -0
  42. package/protoc/v1/shared/trigger.js +493 -0
  43. package/protoc/v1/workflows.d.ts +34 -34
  44. package/protoc/v1/workflows.js +252 -200
  45. package/protoc/workflows/workflows.d.ts +2 -75
  46. package/protoc/workflows/workflows.js +16 -491
  47. package/util/abort-error.d.ts +15 -1
  48. package/util/abort-error.js +30 -5
  49. package/util/config-loader/config-loader.js +4 -3
  50. package/util/config-loader/token.js +9 -2
  51. package/util/errors/eviction-not-supported-error.d.ts +5 -0
  52. package/util/errors/eviction-not-supported-error.js +18 -0
  53. package/util/errors/hatchet-error.d.ts +9 -1
  54. package/util/errors/hatchet-error.js +23 -2
  55. package/util/errors/non-determinism-error.d.ts +7 -0
  56. package/util/errors/non-determinism-error.js +21 -0
  57. package/util/errors/task-run-terminated-error.d.ts +6 -0
  58. package/util/errors/task-run-terminated-error.js +15 -0
  59. package/util/grpc-error.d.ts +9 -0
  60. package/util/grpc-error.js +25 -0
  61. package/util/hatchet-promise/hatchet-promise.d.ts +6 -1
  62. package/util/hatchet-promise/hatchet-promise.js +16 -2
  63. package/util/logger/logger.js +0 -1
  64. package/util/parse.d.ts +1 -1
  65. package/util/parse.js +4 -2
  66. package/util/retrier.js +2 -3
  67. package/util/sleep.d.ts +3 -2
  68. package/util/sleep.js +6 -4
  69. package/util/workflow-run-ref.js +5 -3
  70. package/v1/client/admin.d.ts +2 -2
  71. package/v1/client/admin.js +2 -6
  72. package/v1/client/client.d.ts +7 -11
  73. package/v1/client/client.interface.d.ts +5 -8
  74. package/v1/client/client.js +34 -40
  75. package/v1/client/duration.d.ts +11 -1
  76. package/v1/client/duration.js +44 -0
  77. package/v1/client/features/cel.js +1 -1
  78. package/v1/client/features/crons.js +2 -2
  79. package/v1/client/features/index.d.ts +5 -0
  80. package/v1/client/features/index.js +5 -0
  81. package/v1/client/features/logs.d.ts +37 -0
  82. package/v1/client/features/logs.js +46 -0
  83. package/v1/client/features/runs.d.ts +16 -3
  84. package/v1/client/features/runs.js +38 -4
  85. package/v1/client/features/schedules.js +4 -4
  86. package/v1/client/features/webhooks.js +4 -2
  87. package/v1/client/features/workflows.js +1 -1
  88. package/v1/client/worker/context.d.ts +101 -6
  89. package/v1/client/worker/context.js +257 -44
  90. package/v1/client/worker/deprecated/deprecation.js +8 -4
  91. package/v1/client/worker/deprecated/index.d.ts +1 -1
  92. package/v1/client/worker/deprecated/index.js +2 -1
  93. package/v1/client/worker/deprecated/legacy-worker.d.ts +5 -0
  94. package/v1/client/worker/deprecated/legacy-worker.js +33 -24
  95. package/v1/client/worker/deprecated/pre-eviction.d.ts +12 -0
  96. package/v1/client/worker/deprecated/pre-eviction.js +37 -0
  97. package/v1/client/worker/engine-version.d.ts +5 -0
  98. package/v1/client/worker/engine-version.js +14 -0
  99. package/v1/client/worker/eviction/eviction-cache.d.ts +33 -0
  100. package/v1/client/worker/eviction/eviction-cache.js +139 -0
  101. package/v1/client/worker/eviction/eviction-manager.d.ts +42 -0
  102. package/v1/client/worker/eviction/eviction-manager.js +132 -0
  103. package/v1/client/worker/eviction/eviction-policy.d.ts +19 -0
  104. package/v1/client/worker/eviction/eviction-policy.js +8 -0
  105. package/v1/client/worker/eviction/index.d.ts +3 -0
  106. package/v1/client/worker/eviction/index.js +11 -0
  107. package/v1/client/worker/health-server.js +3 -3
  108. package/v1/client/worker/slot-utils.js +0 -3
  109. package/v1/client/worker/worker-internal.d.ts +23 -4
  110. package/v1/client/worker/worker-internal.js +216 -148
  111. package/v1/client/worker/worker.d.ts +1 -0
  112. package/v1/client/worker/worker.js +34 -0
  113. package/v1/conditions/base.js +0 -1
  114. package/v1/conditions/index.js +2 -4
  115. package/v1/conditions/sleep-condition.js +2 -1
  116. package/v1/conditions/transformer.js +2 -1
  117. package/v1/declaration.d.ts +6 -4
  118. package/v1/declaration.js +20 -7
  119. package/v1/examples/__e2e__/harness.d.ts +5 -0
  120. package/v1/examples/__e2e__/harness.js +17 -3
  121. package/v1/examples/affinity/affinity-workers.js +0 -1
  122. package/v1/examples/bulk_operations/workflow.js +0 -1
  123. package/v1/examples/cancellation/run.js +0 -1
  124. package/v1/examples/cancellations/run.js +0 -1
  125. package/v1/examples/child_workflows/run.js +0 -2
  126. package/v1/examples/child_workflows/workflow.js +0 -1
  127. package/v1/examples/concurrency-rr/load.js +0 -1
  128. package/v1/examples/concurrency-rr/run.js +0 -3
  129. package/v1/examples/concurrency_limit_rr/load.js +0 -1
  130. package/v1/examples/concurrency_limit_rr/run.js +0 -3
  131. package/v1/examples/concurrency_workflow_level/workflow.d.ts +1 -1
  132. package/v1/examples/concurrency_workflow_level/workflow.js +1 -1
  133. package/v1/examples/conditions/event.js +0 -1
  134. package/v1/examples/conditions/run.js +0 -1
  135. package/v1/examples/dag/run.js +0 -1
  136. package/v1/examples/dag_match_condition/event.js +0 -1
  137. package/v1/examples/dag_match_condition/run.js +0 -1
  138. package/v1/examples/deep/run.js +0 -2
  139. package/v1/examples/durable/workflow.d.ts +57 -0
  140. package/v1/examples/durable/workflow.js +164 -10
  141. package/v1/examples/durable-event/event.js +0 -1
  142. package/v1/examples/durable-event/run.js +0 -2
  143. package/v1/examples/durable-event/workflow.js +2 -7
  144. package/v1/examples/durable-sleep/event.js +0 -1
  145. package/v1/examples/durable-sleep/run.js +0 -2
  146. package/v1/examples/durable_event/event.js +0 -1
  147. package/v1/examples/durable_event/run.js +0 -2
  148. package/v1/examples/durable_event/workflow.d.ts +1 -0
  149. package/v1/examples/durable_event/workflow.js +4 -9
  150. package/v1/examples/durable_eviction/capacity-worker.d.ts +1 -0
  151. package/v1/examples/durable_eviction/capacity-worker.js +31 -0
  152. package/v1/examples/durable_eviction/worker.d.ts +1 -0
  153. package/v1/examples/durable_eviction/worker.js +34 -0
  154. package/v1/examples/durable_eviction/workflow.d.ts +44 -0
  155. package/v1/examples/durable_eviction/workflow.js +129 -0
  156. package/v1/examples/durable_sleep/event.js +0 -1
  157. package/v1/examples/durable_sleep/run.js +0 -2
  158. package/v1/examples/e2e-worker.js +42 -19
  159. package/v1/examples/events/event.js +0 -1
  160. package/v1/examples/high-memory/run.js +0 -1
  161. package/v1/examples/inferred-typing/run.js +0 -1
  162. package/v1/examples/landing_page/durable-excution.js +0 -1
  163. package/v1/examples/landing_page/queues.js +0 -1
  164. package/v1/examples/legacy/run.js +0 -1
  165. package/v1/examples/logger/byo-logger.js +0 -2
  166. package/v1/examples/logger/logger.js +0 -1
  167. package/v1/examples/logging/byo-logger.js +0 -2
  168. package/v1/examples/logging/logger.js +0 -1
  169. package/v1/examples/middleware/recipes.js +3 -1
  170. package/v1/examples/migration-guides/mergent.js +2 -1
  171. package/v1/examples/multiple_wf_concurrency/run.js +0 -3
  172. package/v1/examples/non_retryable/run.js +0 -1
  173. package/v1/examples/on_event/event.js +0 -1
  174. package/v1/examples/on_failure/run.js +0 -1
  175. package/v1/examples/on_failure/workflow.js +0 -1
  176. package/v1/examples/on_success/run.js +0 -1
  177. package/v1/examples/on_success/workflow.js +0 -1
  178. package/v1/examples/priority/run.js +0 -1
  179. package/v1/examples/priority/workflow.js +0 -1
  180. package/v1/examples/retries/run.js +0 -1
  181. package/v1/examples/retries/workflow.js +0 -1
  182. package/v1/examples/simple/bulk.js +0 -1
  183. package/v1/examples/simple/cron.js +0 -2
  184. package/v1/examples/simple/delay.js +0 -1
  185. package/v1/examples/simple/enqueue.js +0 -2
  186. package/v1/examples/simple/run.js +0 -1
  187. package/v1/examples/simple/schedule.js +0 -1
  188. package/v1/examples/simple/workflow-with-child.js +10 -4
  189. package/v1/examples/sticky/run.js +0 -1
  190. package/v1/examples/sticky/workflow.js +0 -1
  191. package/v1/examples/streaming/nextjs-proxy.js +0 -1
  192. package/v1/examples/streaming/run.js +0 -1
  193. package/v1/examples/timeout/run.js +0 -1
  194. package/v1/examples/timeouts/run.js +0 -1
  195. package/v1/index.d.ts +5 -0
  196. package/v1/index.js +10 -0
  197. package/v1/parent-run-context-vars.d.ts +6 -0
  198. package/v1/slot-types.js +0 -1
  199. package/v1/task.d.ts +10 -2
  200. package/v1/task.js +2 -1
  201. package/version.d.ts +1 -1
  202. package/version.js +1 -1
@@ -14,10 +14,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.__testing = exports.Worker = void 0;
16
16
  const sleep_1 = __importDefault(require("../../../util/sleep"));
17
+ const declaration_1 = require("../../declaration");
17
18
  const legacy_transformer_1 = require("../../../legacy/legacy-transformer");
18
19
  const worker_internal_1 = require("./worker-internal");
19
20
  const slot_utils_1 = require("./slot-utils");
20
21
  const deprecated_1 = require("./deprecated");
22
+ const engine_version_1 = require("./engine-version");
21
23
  /**
22
24
  * HatchetWorker class for workflow execution runtime
23
25
  */
@@ -97,9 +99,35 @@ class Worker {
97
99
  this._legacyWorker = yield deprecated_1.LegacyDualWorker.create(this._v1, this.name, legacyConfig);
98
100
  return this._legacyWorker.start();
99
101
  }
102
+ const engineVersion = yield (0, deprecated_1.fetchEngineVersion)(this._v1).catch(() => undefined);
103
+ this._checkEvictionSupport(engineVersion);
104
+ this._internal.engineVersion = engineVersion;
100
105
  return this._internal.start();
101
106
  });
102
107
  }
108
+ _checkEvictionSupport(engineVersion) {
109
+ if ((0, engine_version_1.supportsEviction)(engineVersion))
110
+ return;
111
+ const workflows = (this.config.workflows || []);
112
+ const tasksWithEviction = [];
113
+ for (const wf of workflows) {
114
+ if (!(wf instanceof declaration_1.BaseWorkflowDeclaration))
115
+ continue;
116
+ for (const task of wf.definition._durableTasks) {
117
+ if (task.evictionPolicy) {
118
+ tasksWithEviction.push(`${wf.definition.name}:${task.name}`);
119
+ }
120
+ }
121
+ }
122
+ if (tasksWithEviction.length === 0)
123
+ return;
124
+ const names = tasksWithEviction.join(', ');
125
+ const logger = this._v1.config.logger('Worker', this._v1.config.log_level);
126
+ (0, deprecated_1.emitDeprecationNotice)('pre-eviction-engine', `Engine ${engineVersion || 'unknown'} does not support durable eviction ` +
127
+ `(requires >= ${engine_version_1.MinEngineVersion.DURABLE_EVICTION}). ` +
128
+ `Eviction policies will be ignored for tasks: ${names}. ` +
129
+ `Please upgrade your Hatchet engine.`, new Date('2026-03-01T00:00:00Z'), logger);
130
+ }
103
131
  /**
104
132
  * Stops the worker
105
133
  * @returns Promise that resolves when the worker stops
@@ -163,6 +191,12 @@ class Worker {
163
191
  const pollInterval = 200;
164
192
  const start = Date.now();
165
193
  while (Date.now() - start < timeoutMs) {
194
+ // start() may asynchronously detect a legacy engine and set _legacyWorker
195
+ // after waitUntilReady has already entered this loop
196
+ if (this._legacyWorker) {
197
+ yield (0, sleep_1.default)(2000);
198
+ return;
199
+ }
166
200
  if ((_a = this._internal) === null || _a === void 0 ? void 0 : _a.workerId)
167
201
  return;
168
202
  yield (0, sleep_1.default)(pollInterval);
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Condition = exports.Action = void 0;
4
- /* eslint-disable no-shadow */
5
4
  var Action;
6
5
  (function (Action) {
7
6
  Action[Action["CREATE"] = 0] = "CREATE";
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable no-param-reassign */
3
- /* eslint-disable no-shadow */
4
- /* eslint-disable max-classes-per-file */
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.OrCondition = exports.UserEventCondition = exports.SleepCondition = void 0;
7
4
  exports.Render = Render;
@@ -33,8 +30,9 @@ exports.OrCondition = OrCondition;
33
30
  * );
34
31
  */
35
32
  function Render(action, conditions) {
36
- if (!conditions)
33
+ if (!conditions) {
37
34
  return [];
35
+ }
38
36
  if (!Array.isArray(conditions)) {
39
37
  return Render(action, [conditions]);
40
38
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SleepCondition = void 0;
4
+ const duration_1 = require("../client/duration");
4
5
  const base_1 = require("./base");
5
6
  /**
6
7
  * Represents a condition that waits for a specified duration before proceeding.
@@ -27,7 +28,7 @@ class SleepCondition extends base_1.Condition {
27
28
  */
28
29
  constructor(sleepFor, readableDataKey, action) {
29
30
  super({
30
- readableDataKey: readableDataKey || `sleep-${sleepFor}`,
31
+ readableDataKey: readableDataKey || `sleep-${(0, duration_1.durationToString)(sleepFor)}`,
31
32
  action,
32
33
  orGroupId: '',
33
34
  expression: '',
@@ -6,6 +6,7 @@ const apply_namespace_1 = require("../../util/apply-namespace");
6
6
  const _1 = require(".");
7
7
  const base_1 = require("./base");
8
8
  const parent_condition_1 = require("./parent-condition");
9
+ const duration_1 = require("../client/duration");
9
10
  function taskConditionsToPb(task, namespace) {
10
11
  const waitForConditions = (0, _1.Render)(base_1.Action.QUEUE, task.waitFor);
11
12
  const cancelIfConditions = (0, _1.Render)(base_1.Action.CANCEL, task.cancelIf);
@@ -21,7 +22,7 @@ function conditionsToPb(conditions, namespace) {
21
22
  if (condition instanceof _1.SleepCondition) {
22
23
  sleepConditions.push({
23
24
  base: baseToPb(condition.base),
24
- sleepFor: condition.sleepFor,
25
+ sleepFor: (0, duration_1.durationToString)(condition.sleepFor),
25
26
  });
26
27
  }
27
28
  else if (condition instanceof _1.UserEventCondition) {
@@ -8,13 +8,13 @@
8
8
  import WorkflowRunRef from '../util/workflow-run-ref';
9
9
  import { CronWorkflows, ScheduledWorkflows, V1CreateFilterRequest } from '../clients/rest/generated/data-contracts';
10
10
  import { z } from 'zod';
11
- import { WorkerLabelComparator } from '../protoc/v1/workflows';
12
11
  import { IHatchetClient } from './client/client.interface';
13
- import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskFn, CreateWorkflowDurableTaskOpts, CreateBaseTaskOpts, CreateOnSuccessTaskOpts, Concurrency, DurableTaskFn } from './task';
12
+ import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskFn, CreateWorkflowDurableTaskOpts, CreateBaseTaskOpts, CreateOnSuccessTaskOpts, Concurrency, DurableTaskFn, WorkerLabelComparator } from './task';
14
13
  import { Duration } from './client/duration';
15
14
  import { MetricsClient } from './client/features/metrics';
16
15
  import { InputType, OutputType, UnknownInputType, JsonObject, Resolved } from './types';
17
16
  import { Context, DurableContext } from './client/worker/context';
17
+ import { EvictionPolicy } from './client/worker/eviction/eviction-policy';
18
18
  export declare enum Priority {
19
19
  LOW = 1,
20
20
  MEDIUM = 2,
@@ -141,7 +141,9 @@ export type CreateBaseWorkflowOpts = {
141
141
  inputValidator?: z.ZodType<any>;
142
142
  };
143
143
  export type CreateTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, TaskFn<I, O>>;
144
- export type CreateDurableTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, DurableTaskFn<I, O>>;
144
+ export type CreateDurableTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, DurableTaskFn<I, O>> & {
145
+ evictionPolicy?: EvictionPolicy;
146
+ };
145
147
  /**
146
148
  * Options for creating a new workflow.
147
149
  * @hidden
@@ -453,7 +455,7 @@ export declare class WorkflowDeclaration<I extends InputType = UnknownInputType,
453
455
  * @template MiddlewareBefore - Extra fields added to the task fn input by pre-middleware hooks.
454
456
  * @template MiddlewareAfter - Extra fields merged into the task output by post-middleware hooks.
455
457
  */
456
- export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputType, O extends OutputType = void, GlobalInput extends Record<string, any> = {}, GlobalOutput extends Record<string, any> = {}, MiddlewareBefore extends Record<string, any> = {}, MiddlewareAfter extends Record<string, any> = {}> extends BaseWorkflowDeclaration<I, O> {
458
+ export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputType, O extends OutputType = void, GlobalInput extends Record<string, any> = {}, GlobalOutput extends Record<string, any> = {}, _MiddlewareBefore extends Record<string, any> = {}, MiddlewareAfter extends Record<string, any> = {}> extends BaseWorkflowDeclaration<I, O> {
457
459
  _standalone_task_name: string;
458
460
  constructor(options: CreateTaskWorkflowOpts<any, any>, client?: IHatchetClient);
459
461
  /**
package/v1/declaration.js CHANGED
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ /**
3
+ * `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:
4
+ *
5
+ * - `WorkflowDeclaration`, returned by `hatchet.workflow(...)`, which lets you define tasks and call `run()`, `schedule()`, `cron()`, etc.
6
+ * - `TaskWorkflowDeclaration`, returned by `hatchet.task(...)`, which is a single standalone task that exposes the same execution helpers as a workflow.
7
+ * @module Runnables
8
+ */
2
9
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
10
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
11
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -16,7 +23,6 @@ exports.CreateDurableTaskWorkflow = CreateDurableTaskWorkflow;
16
23
  const abort_error_1 = require("../util/abort-error");
17
24
  const parent_run_context_vars_1 = require("./parent-run-context-vars");
18
25
  const UNBOUND_ERR = new Error('workflow unbound to hatchet client, hint: use client.run instead');
19
- // eslint-disable-next-line no-shadow
20
26
  var Priority;
21
27
  (function (Priority) {
22
28
  Priority[Priority["LOW"] = 1] = "LOW";
@@ -93,15 +99,12 @@ class BaseWorkflowDeclaration {
93
99
  resp.forEach((ref, index) => {
94
100
  const wf = input[index].workflow;
95
101
  if (wf instanceof TaskWorkflowDeclaration) {
96
- // eslint-disable-next-line no-param-reassign
97
102
  ref._standaloneTaskName = wf._standalone_task_name;
98
103
  }
99
104
  if (_standaloneTaskName) {
100
- // eslint-disable-next-line no-param-reassign
101
105
  ref._standaloneTaskName = _standaloneTaskName;
102
106
  }
103
107
  // Ensure result subscriptions inherit cancellation if no signal is provided explicitly.
104
- // eslint-disable-next-line no-param-reassign
105
108
  ref.defaultSignal = inheritedSignal;
106
109
  res.push(ref);
107
110
  });
@@ -128,19 +131,29 @@ class BaseWorkflowDeclaration {
128
131
  }
129
132
  run(input, options, _standaloneTaskName) {
130
133
  return __awaiter(this, void 0, void 0, function* () {
134
+ var _a;
131
135
  if (!this.client) {
132
136
  throw UNBOUND_ERR;
133
137
  }
138
+ const durableCtx = (_a = parent_run_context_vars_1.parentRunContextManager.getContext()) === null || _a === void 0 ? void 0 : _a.durableContext;
139
+ if (durableCtx) {
140
+ if (Array.isArray(input)) {
141
+ return durableCtx.spawnChildren(input.map((inp) => ({ workflow: this, input: inp, options })));
142
+ }
143
+ return durableCtx.spawnChild(this, input, options);
144
+ }
134
145
  if (Array.isArray(input)) {
135
146
  const refs = yield this.runNoWait(input, options, _standaloneTaskName);
136
147
  if (options === null || options === void 0 ? void 0 : options.returnExceptions) {
137
148
  const settled = yield Promise.allSettled(refs.map((ref) => ref.result()));
138
149
  return settled.map((s) => {
139
- if (s.status === 'fulfilled')
150
+ if (s.status === 'fulfilled') {
140
151
  return s.value;
152
+ }
141
153
  const { reason } = s;
142
- if (reason instanceof Error)
154
+ if (reason instanceof Error) {
143
155
  return reason;
156
+ }
144
157
  return new Error(Array.isArray(reason) ? reason.join('; ') : String(reason));
145
158
  });
146
159
  }
@@ -567,7 +580,7 @@ function CreateDurableTaskWorkflow(options, client) {
567
580
  const taskWorkflow = new TaskWorkflowDeclaration(options, client);
568
581
  // Move the task from tasks to durableTasks
569
582
  if (taskWorkflow.definition._tasks.length > 0) {
570
- const task = taskWorkflow.definition._tasks[0];
583
+ const [task] = taskWorkflow.definition._tasks;
571
584
  taskWorkflow.definition._tasks = [];
572
585
  taskWorkflow.definition._durableTasks.push(task);
573
586
  }
@@ -11,6 +11,11 @@ export declare function startWorker({ client, name, workflows, slots, }: {
11
11
  slots?: number;
12
12
  }): Promise<Worker>;
13
13
  export declare function stopWorker(worker: Worker | undefined): Promise<void>;
14
+ /**
15
+ * Checks whether the connected engine supports durable eviction.
16
+ * Call from beforeAll / beforeEach and skip tests when false.
17
+ */
18
+ export declare function checkDurableEvictionSupport(client: HatchetClient): Promise<boolean>;
14
19
  export declare function poll<T>(fn: () => Promise<T>, { timeoutMs, intervalMs, shouldStop, label, }: {
15
20
  timeoutMs?: number;
16
21
  intervalMs?: number;
@@ -17,10 +17,13 @@ exports.makeE2EClient = makeE2EClient;
17
17
  exports.makeTestScope = makeTestScope;
18
18
  exports.startWorker = startWorker;
19
19
  exports.stopWorker = stopWorker;
20
+ exports.checkDurableEvictionSupport = checkDurableEvictionSupport;
20
21
  exports.poll = poll;
21
22
  const sleep_1 = __importDefault(require("../../../util/sleep"));
22
23
  const crypto_1 = require("crypto");
23
24
  const v1_1 = require("../..");
25
+ const engine_version_1 = require("../../client/worker/engine-version");
26
+ const legacy_worker_1 = require("../../client/worker/deprecated/legacy-worker");
24
27
  function requireEnv(name) {
25
28
  const value = process.env[name];
26
29
  if (!value) {
@@ -47,20 +50,31 @@ function startWorker(_a) {
47
50
  }
48
51
  function stopWorker(worker) {
49
52
  return __awaiter(this, void 0, void 0, function* () {
50
- if (!worker)
53
+ if (!worker) {
51
54
  return;
55
+ }
52
56
  yield worker.stop();
53
57
  yield (0, sleep_1.default)(300);
54
58
  });
55
59
  }
60
+ /**
61
+ * Checks whether the connected engine supports durable eviction.
62
+ * Call from beforeAll / beforeEach and skip tests when false.
63
+ */
64
+ function checkDurableEvictionSupport(client) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const version = yield (0, legacy_worker_1.fetchEngineVersion)(client).catch(() => undefined);
67
+ return (0, engine_version_1.supportsEviction)(version);
68
+ });
69
+ }
56
70
  function poll(fn_1, _a) {
57
71
  return __awaiter(this, arguments, void 0, function* (fn, { timeoutMs = 30000, intervalMs = 100, shouldStop, label = 'poll', }) {
58
72
  const start = Date.now();
59
- // eslint-disable-next-line no-constant-condition
60
73
  while (true) {
61
74
  const value = yield fn();
62
- if (shouldStop(value))
75
+ if (shouldStop(value)) {
63
76
  return value;
77
+ }
64
78
  if (Date.now() - start > timeoutMs) {
65
79
  throw new Error(`Timed out waiting for ${label} after ${timeoutMs}ms`);
66
80
  }
@@ -20,7 +20,6 @@ workflow.task({
20
20
  name: 'step1',
21
21
  fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
22
22
  const results = [];
23
- // eslint-disable-next-line no-plusplus
24
23
  for (let i = 0; i < 50; i++) {
25
24
  const result = yield childWorkflow.run({});
26
25
  results.push(result);
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.bulkReplayTest3 = exports.bulkReplayTest2 = exports.bulkReplayTest1 = void 0;
13
- /* eslint-disable no-console */
14
13
  const hatchet_client_1 = require("../hatchet-client");
15
14
  exports.bulkReplayTest1 = hatchet_client_1.hatchet.task({
16
15
  name: 'bulk-replay-test-1',
@@ -12,7 +12,6 @@ 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
- /* eslint-disable no-console */
16
15
  // > Running a Task with Results
17
16
  const sleep_1 = __importDefault(require("../../../util/sleep"));
18
17
  const cancellation_workflow_1 = require("./cancellation-workflow");
@@ -12,7 +12,6 @@ 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
- /* eslint-disable no-console */
16
15
  // > Running a Task with Results
17
16
  const sleep_1 = __importDefault(require("../../../util/sleep"));
18
17
  const workflow_1 = require("./workflow");
@@ -15,7 +15,6 @@ function main() {
15
15
  const res = yield workflow_1.parent.run({
16
16
  N: 10,
17
17
  });
18
- // eslint-disable-next-line no-console
19
18
  console.log(res.Result);
20
19
  });
21
20
  }
@@ -23,7 +22,6 @@ if (require.main === module) {
23
22
  main()
24
23
  .then(() => process.exit(0))
25
24
  .catch((error) => {
26
- // eslint-disable-next-line no-console
27
25
  console.error('Error:', error);
28
26
  process.exit(1);
29
27
  });
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.withErrorHandling = exports.parentSingleChild = exports.parent = exports.child = void 0;
13
- /* eslint-disable no-plusplus */
14
13
  // > Declaring a Child
15
14
  const hatchet_client_1 = require("../hatchet-client");
16
15
  exports.child = hatchet_client_1.hatchet.task({
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- /* eslint-disable no-plusplus */
13
12
  const hatchet_client_1 = require("../hatchet-client");
14
13
  const workflow_1 = require("./workflow");
15
14
  function generateRandomString(length) {
@@ -26,11 +26,8 @@ function main() {
26
26
  GroupKey: 'B',
27
27
  },
28
28
  ]);
29
- // eslint-disable-next-line no-console
30
29
  console.log(res[0]['to-lower'].TransformedMessage);
31
- // eslint-disable-next-line no-console
32
30
  console.log(res[1]['to-lower'].TransformedMessage);
33
- // eslint-disable-next-line no-console
34
31
  console.log(res[2]['to-lower'].TransformedMessage);
35
32
  });
36
33
  }
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- /* eslint-disable no-plusplus */
13
12
  const hatchet_client_1 = require("../hatchet-client");
14
13
  const workflow_1 = require("./workflow");
15
14
  function generateRandomString(length) {
@@ -26,11 +26,8 @@ function main() {
26
26
  GroupKey: 'B',
27
27
  },
28
28
  ]);
29
- // eslint-disable-next-line no-console
30
29
  console.log(res[0]['to-lower'].TransformedMessage);
31
- // eslint-disable-next-line no-console
32
30
  console.log(res[1]['to-lower'].TransformedMessage);
33
- // eslint-disable-next-line no-console
34
31
  console.log(res[2]['to-lower'].TransformedMessage);
35
32
  });
36
33
  }
@@ -1,5 +1,5 @@
1
1
  import type { EmptyTaskOutput } from '../concurrency-types';
2
- export declare const SLEEP_TIME_MS = 500;
2
+ export declare const SLEEP_TIME_MS = 2000;
3
3
  export declare const DIGIT_MAX_RUNS = 8;
4
4
  export declare const NAME_MAX_RUNS = 3;
5
5
  export type WorkflowInput = {
@@ -15,7 +15,7 @@ const hatchet_client_1 = require("../hatchet-client");
15
15
  const sleep = (ms) => new Promise((resolve) => {
16
16
  setTimeout(resolve, ms);
17
17
  });
18
- exports.SLEEP_TIME_MS = 500;
18
+ exports.SLEEP_TIME_MS = 2000;
19
19
  exports.DIGIT_MAX_RUNS = 8;
20
20
  exports.NAME_MAX_RUNS = 3;
21
21
  exports.concurrencyWorkflowLevelWorkflow = hatchet_client_1.hatchet.workflow({
@@ -21,7 +21,6 @@ if (require.main === module) {
21
21
  main()
22
22
  .then(() => process.exit(0))
23
23
  .catch((error) => {
24
- // eslint-disable-next-line no-console
25
24
  console.error('Error:', error);
26
25
  process.exit(1);
27
26
  });
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- /* eslint-disable no-console */
13
12
  const workflow_1 = require("./workflow");
14
13
  function main() {
15
14
  return __awaiter(this, void 0, void 0, function* () {
@@ -17,7 +17,6 @@ function main() {
17
17
  Message: 'hello world',
18
18
  });
19
19
  // !!
20
- // eslint-disable-next-line no-console
21
20
  console.log(res.reverse.Transformed);
22
21
  });
23
22
  }
@@ -21,7 +21,6 @@ if (require.main === module) {
21
21
  main()
22
22
  .then(() => process.exit(0))
23
23
  .catch((error) => {
24
- // eslint-disable-next-line no-console
25
24
  console.error('Error:', error);
26
25
  process.exit(1);
27
26
  });
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- /* eslint-disable no-console */
13
12
  const workflow_1 = require("./workflow");
14
13
  function main() {
15
14
  return __awaiter(this, void 0, void 0, function* () {
@@ -16,13 +16,11 @@ function main() {
16
16
  Message: 'hello',
17
17
  N: 5,
18
18
  });
19
- // eslint-disable-next-line no-console
20
19
  console.log(res.parent.Sum);
21
20
  });
22
21
  }
23
22
  if (require.main === module) {
24
23
  main()
25
- // eslint-disable-next-line no-console
26
24
  .catch(console.error)
27
25
  .finally(() => process.exit(0));
28
26
  }
@@ -5,3 +5,60 @@ export declare const durableWorkflow: import("../..").WorkflowDeclaration<import
5
5
  export declare const waitForSleepTwice: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
6
6
  runtime: number;
7
7
  }, {}, {}, {}, {}>;
8
+ export declare const spawnChildTask: import("../..").TaskWorkflowDeclaration<{
9
+ n?: number;
10
+ }, {
11
+ message: string;
12
+ }, {}, {}, {}, {}>;
13
+ export declare const durableWithSpawn: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
14
+ child_output: {
15
+ message: string;
16
+ };
17
+ }, {}, {}, {}, {}>;
18
+ export declare const durableWithBulkSpawn: import("../..").TaskWorkflowDeclaration<{
19
+ n?: number;
20
+ }, {
21
+ child_outputs: {
22
+ message: string;
23
+ }[];
24
+ }, {}, {}, {}, {}>;
25
+ export declare const durableSleepEventSpawn: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
26
+ runtime: number;
27
+ child_output: {
28
+ message: string;
29
+ };
30
+ }, {}, {}, {}, {}>;
31
+ export declare const durableWithExplicitSpawn: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
32
+ child_output: {
33
+ message: string;
34
+ };
35
+ }, {}, {}, {}, {}>;
36
+ export declare const durableNonDeterminism: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
37
+ attempt_number: number;
38
+ sleep_time: number;
39
+ non_determinism_detected: true;
40
+ node_id: number;
41
+ } | {
42
+ attempt_number: number;
43
+ sleep_time: number;
44
+ non_determinism_detected: false;
45
+ node_id?: undefined;
46
+ }, {}, {}, {}, {}>;
47
+ export declare const REPLAY_RESET_SLEEP_SECONDS = 3;
48
+ /** Max duration (seconds) for a replayed/memoized step; above this we treat it as a real sleep. */
49
+ export declare const REPLAY_RESET_MEMOIZED_MAX_SECONDS = 5;
50
+ export declare const durableReplayReset: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
51
+ sleep_1_duration: number;
52
+ sleep_2_duration: number;
53
+ sleep_3_duration: number;
54
+ }, {}, {}, {}, {}>;
55
+ export declare const memoNowCaching: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
56
+ start_time: string;
57
+ }, {}, {}, {}, {}>;
58
+ export declare const dagChildWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
59
+ export declare const durableSpawnDag: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
60
+ sleep_duration: number;
61
+ sleep_duration_ms: number;
62
+ spawn_duration: number;
63
+ spawn_result: {};
64
+ }, {}, {}, {}, {}>;