@hatchet-dev/typescript-sdk 1.13.1 → 1.14.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 (245) hide show
  1. package/clients/dispatcher/dispatcher-client.d.ts +1 -1
  2. package/clients/dispatcher/heartbeat/heartbeat-controller.js +13 -1
  3. package/clients/dispatcher/heartbeat/heartbeat-worker.js +4 -3
  4. package/clients/event/event-client.d.ts +1 -2
  5. package/clients/event/event-client.js +2 -2
  6. package/clients/hatchet-client/client-config.d.ts +15 -5
  7. package/clients/hatchet-client/client-config.js +3 -0
  8. package/clients/hatchet-client/hatchet-logger.js +1 -0
  9. package/clients/hatchet-client/index.d.ts +1 -1
  10. package/clients/hatchet-client/index.js +1 -1
  11. package/clients/listeners/durable-listener/durable-listener-client.d.ts +6 -0
  12. package/clients/listeners/durable-listener/durable-listener-client.js +8 -0
  13. package/clients/listeners/durable-listener/pooled-durable-listener-client.d.ts +9 -2
  14. package/clients/listeners/durable-listener/pooled-durable-listener-client.js +67 -15
  15. package/clients/listeners/run-listener/child-listener-client.js +1 -0
  16. package/clients/listeners/run-listener/pooled-child-listener-client.d.ts +10 -2
  17. package/clients/listeners/run-listener/pooled-child-listener-client.js +63 -7
  18. package/clients/rest/api.js +10 -2
  19. package/clients/rest/generated/Api.d.ts +2 -2
  20. package/clients/rest/generated/data-contracts.d.ts +6 -0
  21. package/index.d.ts +2 -3
  22. package/index.js +2 -3
  23. package/{examples → legacy/examples}/affinity-workers.js +2 -2
  24. package/{examples → legacy/examples}/bulk-fanout-trigger.js +1 -1
  25. package/{examples → legacy/examples}/bulk-fanout-worker.js +1 -1
  26. package/{examples → legacy/examples}/bulk-trigger.js +1 -1
  27. package/{examples → legacy/examples}/byo-logger.js +1 -1
  28. package/{examples → legacy/examples}/concurrency/cancel-in-progress/concurrency-event.js +1 -1
  29. package/{examples → legacy/examples}/concurrency/cancel-in-progress/concurrency-worker.js +1 -1
  30. package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-event.js +1 -1
  31. package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-worker-expression.js +2 -2
  32. package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-worker-key-fn.js +2 -2
  33. package/{examples → legacy/examples}/crons/cron-worker.d.ts +1 -1
  34. package/{examples → legacy/examples}/crons/cron-worker.js +1 -1
  35. package/{examples → legacy/examples}/crons/programatic-crons.js +1 -1
  36. package/{examples → legacy/examples}/dag-worker.js +1 -1
  37. package/{examples → legacy/examples}/example-event-with-results.js +2 -2
  38. package/{examples → legacy/examples}/example-event.js +1 -1
  39. package/{examples → legacy/examples}/fanout-worker.js +1 -1
  40. package/{examples → legacy/examples}/logger.js +1 -1
  41. package/{examples → legacy/examples}/manual-trigger.js +1 -1
  42. package/{examples → legacy/examples}/multi-workflow.js +1 -1
  43. package/{examples → legacy/examples}/namespaced-worker.js +1 -1
  44. package/{examples → legacy/examples}/on-failure.js +1 -1
  45. package/{examples → legacy/examples}/rate-limit/events.js +1 -1
  46. package/{examples → legacy/examples}/rate-limit/worker.js +2 -2
  47. package/{examples → legacy/examples}/retries-with-backoff.js +1 -1
  48. package/{examples → legacy/examples}/retries-worker.js +1 -1
  49. package/{examples → legacy/examples}/scheduled-runs/programatic-schedules.js +1 -1
  50. package/{examples → legacy/examples}/simple-worker.d.ts +1 -1
  51. package/{examples → legacy/examples}/simple-worker.js +1 -1
  52. package/{examples → legacy/examples}/sticky-trigger.js +1 -1
  53. package/{examples → legacy/examples}/sticky-worker-with-check.js +2 -2
  54. package/{examples → legacy/examples}/sticky-worker.js +2 -2
  55. package/{examples → legacy/examples}/stream-by-additional-meta.js +2 -2
  56. package/legacy/legacy-client.d.ts +30 -0
  57. package/legacy/legacy-client.js +67 -0
  58. package/legacy/legacy-transformer.d.ts +38 -0
  59. package/legacy/legacy-transformer.js +181 -0
  60. package/legacy/step.d.ts +429 -0
  61. package/legacy/step.js +662 -0
  62. package/legacy/workflow.d.ts +488 -0
  63. package/legacy/workflow.js +72 -0
  64. package/package.json +2 -2
  65. package/step.d.ts +1 -430
  66. package/step.js +6 -647
  67. package/util/abort-error.d.ts +38 -0
  68. package/util/abort-error.js +58 -0
  69. package/util/hatchet-promise/hatchet-promise.d.ts +8 -1
  70. package/util/hatchet-promise/hatchet-promise.js +3 -2
  71. package/util/logger/index.d.ts +1 -0
  72. package/util/logger/index.js +1 -0
  73. package/util/logger/task-run-log.d.ts +3 -0
  74. package/util/logger/task-run-log.js +20 -0
  75. package/util/sleep.d.ts +5 -2
  76. package/util/sleep.js +27 -4
  77. package/util/workflow-run-ref.d.ts +7 -1
  78. package/util/workflow-run-ref.js +5 -3
  79. package/v1/client/admin.d.ts +8 -1
  80. package/v1/client/admin.js +22 -6
  81. package/v1/client/client.d.ts +36 -18
  82. package/v1/client/client.interface.d.ts +9 -2
  83. package/v1/client/client.js +47 -27
  84. package/v1/client/features/crons.d.ts +3 -3
  85. package/v1/client/features/crons.js +2 -2
  86. package/v1/client/features/schedules.js +2 -2
  87. package/v1/client/features/workflows.d.ts +5 -5
  88. package/v1/client/features/workflows.js +7 -8
  89. package/v1/client/worker/context.d.ts +49 -10
  90. package/v1/client/worker/context.js +92 -20
  91. package/v1/client/worker/deprecated/legacy-v1-worker.d.ts +3 -3
  92. package/v1/client/worker/deprecated/legacy-v1-worker.js +2 -2
  93. package/v1/client/worker/deprecated/legacy-worker.js +9 -7
  94. package/v1/client/worker/slot-utils.d.ts +3 -3
  95. package/v1/client/worker/worker-internal.d.ts +7 -16
  96. package/v1/client/worker/worker-internal.js +225 -209
  97. package/v1/client/worker/worker.d.ts +18 -18
  98. package/v1/client/worker/worker.js +45 -30
  99. package/v1/declaration.d.ts +28 -7
  100. package/v1/declaration.js +56 -6
  101. package/v1/examples/__e2e__/harness.d.ts +19 -0
  102. package/v1/examples/__e2e__/harness.js +70 -0
  103. package/v1/examples/affinity/affinity-workers.js +4 -4
  104. package/v1/examples/bulk_fanout/workflow.d.ts +9 -0
  105. package/v1/examples/bulk_fanout/workflow.js +34 -0
  106. package/v1/examples/bulk_operations/workflow.d.ts +3 -0
  107. package/v1/examples/bulk_operations/workflow.js +44 -0
  108. package/v1/examples/cancellation/cancellation-workflow.d.ts +2 -0
  109. package/v1/examples/cancellation/cancellation-workflow.js +69 -0
  110. package/v1/examples/cancellation/run.js +53 -0
  111. package/v1/examples/cancellation/worker.d.ts +1 -0
  112. package/v1/examples/cancellation/worker.js +29 -0
  113. package/v1/examples/concurrency-types.d.ts +5 -0
  114. package/v1/examples/concurrency-types.js +2 -0
  115. package/v1/examples/concurrency_cancel_in_progress/workflow.d.ts +9 -0
  116. package/v1/examples/concurrency_cancel_in_progress/workflow.js +45 -0
  117. package/v1/examples/concurrency_cancel_newest/workflow.d.ts +9 -0
  118. package/v1/examples/concurrency_cancel_newest/workflow.js +45 -0
  119. package/v1/examples/concurrency_limit_rr/load.d.ts +1 -0
  120. package/v1/examples/concurrency_limit_rr/load.js +54 -0
  121. package/v1/examples/concurrency_limit_rr/run.d.ts +1 -0
  122. package/v1/examples/concurrency_limit_rr/run.js +39 -0
  123. package/v1/examples/concurrency_limit_rr/worker.d.ts +1 -0
  124. package/v1/examples/concurrency_limit_rr/worker.js +24 -0
  125. package/v1/examples/concurrency_limit_rr/workflow.d.ts +12 -0
  126. package/v1/examples/concurrency_limit_rr/workflow.js +62 -0
  127. package/v1/examples/concurrency_multiple_keys/workflow.d.ts +12 -0
  128. package/v1/examples/concurrency_multiple_keys/workflow.js +42 -0
  129. package/v1/examples/concurrency_workflow_level/workflow.d.ts +13 -0
  130. package/v1/examples/concurrency_workflow_level/workflow.js +49 -0
  131. package/v1/examples/conditions/complex-workflow.d.ts +1 -0
  132. package/v1/examples/conditions/complex-workflow.js +107 -0
  133. package/v1/examples/conditions/event.d.ts +1 -0
  134. package/v1/examples/conditions/event.js +28 -0
  135. package/v1/examples/conditions/run.d.ts +1 -0
  136. package/v1/examples/conditions/run.js +25 -0
  137. package/v1/examples/conditions/worker.d.ts +1 -0
  138. package/v1/examples/conditions/worker.js +24 -0
  139. package/v1/examples/conditions/workflow.d.ts +11 -0
  140. package/v1/examples/conditions/workflow.js +41 -0
  141. package/v1/examples/durable/workflow.d.ts +7 -0
  142. package/v1/examples/durable/workflow.js +116 -0
  143. package/v1/examples/durable_event/event.d.ts +1 -0
  144. package/v1/examples/durable_event/event.js +28 -0
  145. package/v1/examples/durable_event/run.d.ts +1 -0
  146. package/v1/examples/durable_event/run.js +30 -0
  147. package/v1/examples/durable_event/worker.d.ts +1 -0
  148. package/v1/examples/durable_event/worker.js +24 -0
  149. package/v1/examples/durable_event/workflow.d.ts +6 -0
  150. package/v1/examples/durable_event/workflow.js +46 -0
  151. package/v1/examples/durable_sleep/event.d.ts +1 -0
  152. package/v1/examples/durable_sleep/event.js +28 -0
  153. package/v1/examples/durable_sleep/run.d.ts +1 -0
  154. package/v1/examples/durable_sleep/run.js +30 -0
  155. package/v1/examples/durable_sleep/worker.d.ts +1 -0
  156. package/v1/examples/durable_sleep/worker.js +24 -0
  157. package/v1/examples/durable_sleep/workflow.d.ts +1 -0
  158. package/v1/examples/durable_sleep/workflow.js +31 -0
  159. package/v1/examples/e2e-worker.d.ts +1 -0
  160. package/v1/examples/e2e-worker.js +82 -0
  161. package/v1/examples/events/event.d.ts +1 -0
  162. package/v1/examples/events/event.js +53 -0
  163. package/v1/examples/events/filter.d.ts +1 -0
  164. package/v1/examples/events/filter.js +32 -0
  165. package/v1/examples/events/worker.d.ts +1 -0
  166. package/v1/examples/events/worker.js +24 -0
  167. package/v1/examples/events/workflow.d.ts +19 -0
  168. package/v1/examples/events/workflow.js +60 -0
  169. package/v1/examples/high-memory/workflow-with-child.js +1 -1
  170. package/v1/examples/logger/byo-logger.d.ts +1 -0
  171. package/v1/examples/logger/byo-logger.js +73 -0
  172. package/v1/examples/logger/logger.d.ts +1 -0
  173. package/v1/examples/logger/logger.js +46 -0
  174. package/v1/examples/logger/workflow.d.ts +2 -0
  175. package/v1/examples/logger/workflow.js +38 -0
  176. package/v1/examples/multiple_wf_concurrency/workflow.js +3 -3
  177. package/v1/examples/on_failure/workflow.d.ts +1 -0
  178. package/v1/examples/on_failure/workflow.js +12 -7
  179. package/v1/examples/priority/workflow.js +1 -1
  180. package/v1/examples/retries/workflow.js +2 -2
  181. package/v1/examples/return_exceptions/workflow.d.ts +6 -0
  182. package/v1/examples/return_exceptions/workflow.js +22 -0
  183. package/v1/examples/run_details/workflow.d.ts +4 -0
  184. package/v1/examples/run_details/workflow.js +65 -0
  185. package/v1/examples/simple/e2e-workflows.d.ts +14 -0
  186. package/v1/examples/simple/e2e-workflows.js +27 -0
  187. package/v1/examples/simple/enqueue.js +2 -2
  188. package/v1/examples/sticky/workflow.js +2 -2
  189. package/v1/examples/timeout/run.d.ts +1 -0
  190. package/v1/examples/timeout/run.js +30 -0
  191. package/v1/examples/timeout/worker.d.ts +1 -0
  192. package/v1/examples/timeout/worker.js +25 -0
  193. package/v1/examples/timeout/workflow.d.ts +10 -0
  194. package/v1/examples/timeout/workflow.js +56 -0
  195. package/v1/examples/webhooks/workflow.d.ts +5 -0
  196. package/v1/examples/webhooks/workflow.js +23 -0
  197. package/v1/index.d.ts +1 -0
  198. package/v1/index.js +1 -0
  199. package/v1/parent-run-context-vars.d.ts +6 -0
  200. package/v1/parent-run-context-vars.js +3 -0
  201. package/v1/task.d.ts +22 -7
  202. package/v1/task.js +4 -1
  203. package/version.d.ts +1 -1
  204. package/version.js +1 -1
  205. package/workflow.d.ts +3 -491
  206. package/workflow.js +12 -62
  207. package/clients/hatchet-client/hatchet-client.d.ts +0 -35
  208. package/clients/hatchet-client/hatchet-client.js +0 -108
  209. package/clients/worker/handler.d.ts +0 -50
  210. package/clients/worker/handler.js +0 -214
  211. package/clients/worker/index.d.ts +0 -1
  212. package/clients/worker/index.js +0 -17
  213. package/clients/worker/worker.d.ts +0 -59
  214. package/clients/worker/worker.js +0 -568
  215. package/examples/webhooks.js +0 -45
  216. /package/{examples → legacy/examples}/affinity-workers.d.ts +0 -0
  217. /package/{examples → legacy/examples}/bulk-fanout-trigger.d.ts +0 -0
  218. /package/{examples → legacy/examples}/bulk-fanout-worker.d.ts +0 -0
  219. /package/{examples → legacy/examples}/bulk-trigger.d.ts +0 -0
  220. /package/{examples → legacy/examples}/byo-logger.d.ts +0 -0
  221. /package/{examples → legacy/examples}/concurrency/cancel-in-progress/concurrency-event.d.ts +0 -0
  222. /package/{examples → legacy/examples}/concurrency/cancel-in-progress/concurrency-worker.d.ts +0 -0
  223. /package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-event.d.ts +0 -0
  224. /package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-worker-expression.d.ts +0 -0
  225. /package/{examples → legacy/examples}/concurrency/group-round-robin/concurrency-worker-key-fn.d.ts +0 -0
  226. /package/{examples → legacy/examples}/crons/programatic-crons.d.ts +0 -0
  227. /package/{examples → legacy/examples}/dag-worker.d.ts +0 -0
  228. /package/{examples → legacy/examples}/example-event-with-results.d.ts +0 -0
  229. /package/{examples → legacy/examples}/example-event.d.ts +0 -0
  230. /package/{examples → legacy/examples}/fanout-worker.d.ts +0 -0
  231. /package/{examples → legacy/examples}/logger.d.ts +0 -0
  232. /package/{examples → legacy/examples}/manual-trigger.d.ts +0 -0
  233. /package/{examples → legacy/examples}/multi-workflow.d.ts +0 -0
  234. /package/{examples → legacy/examples}/namespaced-worker.d.ts +0 -0
  235. /package/{examples → legacy/examples}/on-failure.d.ts +0 -0
  236. /package/{examples → legacy/examples}/rate-limit/events.d.ts +0 -0
  237. /package/{examples → legacy/examples}/rate-limit/worker.d.ts +0 -0
  238. /package/{examples → legacy/examples}/retries-with-backoff.d.ts +0 -0
  239. /package/{examples → legacy/examples}/retries-worker.d.ts +0 -0
  240. /package/{examples → legacy/examples}/scheduled-runs/programatic-schedules.d.ts +0 -0
  241. /package/{examples → legacy/examples}/sticky-trigger.d.ts +0 -0
  242. /package/{examples → legacy/examples}/sticky-worker-with-check.d.ts +0 -0
  243. /package/{examples → legacy/examples}/sticky-worker.d.ts +0 -0
  244. /package/{examples → legacy/examples}/stream-by-additional-meta.d.ts +0 -0
  245. /package/{examples/webhooks.d.ts → v1/examples/cancellation/run.d.ts} +0 -0
@@ -1,10 +1,8 @@
1
1
  import { WorkerLabels } from '../../../clients/dispatcher/dispatcher-client';
2
- import { LegacyHatchetClient } from '../../../clients/hatchet-client';
3
- import { Workflow as V0Workflow } from '../../../workflow';
4
- import { WebhookWorkerCreateRequest } from '../../../clients/rest/generated/data-contracts';
5
2
  import { BaseWorkflowDeclaration } from '../../declaration';
3
+ import type { LegacyWorkflow } from '../../../legacy/legacy-transformer';
6
4
  import { HatchetClient } from '../..';
7
- import { V1Worker } from './worker-internal';
5
+ import { InternalWorker } from './worker-internal';
8
6
  import { type WorkerSlotOptions } from './slot-utils';
9
7
  /**
10
8
  * Options for creating a new hatchet worker
@@ -23,9 +21,8 @@ export declare class Worker {
23
21
  config: CreateWorkerOpts;
24
22
  name: string;
25
23
  _v1: HatchetClient;
26
- _v0: LegacyHatchetClient;
27
24
  /** Internal reference to the underlying V0 worker implementation */
28
- _internal: V1Worker;
25
+ _internal: InternalWorker;
29
26
  /** Set when connected to a legacy engine that needs dual-worker architecture */
30
27
  private _legacyWorker;
31
28
  /** Tracks all workflows registered after construction (via registerWorkflow/registerWorkflows) */
@@ -34,27 +31,31 @@ export declare class Worker {
34
31
  * Creates a new HatchetWorker instance
35
32
  * @param nonDurable - The V0 worker implementation
36
33
  */
37
- constructor(v1: HatchetClient, v0: LegacyHatchetClient, nonDurable: V1Worker, config: CreateWorkerOpts, name: string);
34
+ constructor(v1: HatchetClient, nonDurable: InternalWorker, config: CreateWorkerOpts, name: string);
38
35
  /**
39
36
  * Creates and initializes a new HatchetWorker
40
37
  * @param v0 - The HatchetClient instance
41
38
  * @param options - Worker creation options
42
39
  * @returns A new HatchetWorker instance
43
40
  */
44
- static create(v1: HatchetClient, v0: LegacyHatchetClient, name: string, options: CreateWorkerOpts): Promise<Worker>;
41
+ static create(v1: HatchetClient, name: string, options: CreateWorkerOpts): Promise<Worker>;
45
42
  /**
46
- * Registers workflows with the worker
43
+ * Registers workflows with the worker.
44
+ * Accepts both v1 BaseWorkflowDeclaration and legacy Workflow objects.
45
+ * Legacy workflows are automatically transformed and a deprecation warning is emitted.
47
46
  * @param workflows - Array of workflows to register
48
47
  * @returns Array of registered workflow promises
49
48
  */
50
- registerWorkflows(workflows?: Array<BaseWorkflowDeclaration<any, any> | V0Workflow>): Promise<void>;
49
+ registerWorkflows(workflows?: Array<BaseWorkflowDeclaration<any, any> | LegacyWorkflow>): Promise<void>;
51
50
  /**
52
- * Registers a single workflow with the worker
51
+ * Registers a single workflow with the worker.
52
+ * Accepts both v1 BaseWorkflowDeclaration and legacy Workflow objects.
53
+ * Legacy workflows are automatically transformed and a deprecation warning is emitted.
53
54
  * @param workflow - The workflow to register
54
55
  * @returns A promise that resolves when the workflow is registered
55
56
  * @deprecated use registerWorkflows instead
56
57
  */
57
- registerWorkflow(workflow: BaseWorkflowDeclaration<any, any> | V0Workflow): Promise<void>;
58
+ registerWorkflow(workflow: BaseWorkflowDeclaration<any, any> | LegacyWorkflow): Promise<void>;
58
59
  /**
59
60
  * Starts the worker
60
61
  * @returns Promise that resolves when the worker is stopped or killed
@@ -76,14 +77,13 @@ export declare class Worker {
76
77
  * @returns The labels for the worker
77
78
  */
78
79
  getLabels(): WorkerLabels;
79
- /**
80
- * Register a webhook with the worker
81
- * @param webhook - The webhook to register
82
- * @returns A promise that resolves when the webhook is registered
83
- */
84
- registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").WebhookWorkerCreated, any, {}>>;
85
80
  isPaused(): Promise<boolean>;
86
81
  pause(): Promise<void> | Promise<import("../../../clients/rest/generated/data-contracts").Worker>;
87
82
  unpause(): Promise<void> | Promise<import("../../../clients/rest/generated/data-contracts").Worker>;
83
+ /**
84
+ * Waits until the worker has connected and registered with the server.
85
+ * Polls every 200ms. Use after start() to avoid fixed sleeps before running workflows.
86
+ */
87
+ waitUntilReady(timeoutMs?: number): Promise<void>;
88
88
  }
89
89
  export { testingExports as __testing } from './slot-utils';
@@ -8,9 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.__testing = exports.Worker = void 0;
13
- const declaration_1 = require("../../declaration");
16
+ const sleep_1 = __importDefault(require("../../../util/sleep"));
17
+ const legacy_transformer_1 = require("../../../legacy/legacy-transformer");
14
18
  const worker_internal_1 = require("./worker-internal");
15
19
  const slot_utils_1 = require("./slot-utils");
16
20
  const deprecated_1 = require("./deprecated");
@@ -22,11 +26,10 @@ class Worker {
22
26
  * Creates a new HatchetWorker instance
23
27
  * @param nonDurable - The V0 worker implementation
24
28
  */
25
- constructor(v1, v0, nonDurable, config, name) {
29
+ constructor(v1, nonDurable, config, name) {
26
30
  /** Tracks all workflows registered after construction (via registerWorkflow/registerWorkflows) */
27
31
  this._registeredWorkflows = [];
28
32
  this._v1 = v1;
29
- this._v0 = v0;
30
33
  this._internal = nonDurable;
31
34
  this.config = config;
32
35
  this.name = name;
@@ -37,41 +40,40 @@ class Worker {
37
40
  * @param options - Worker creation options
38
41
  * @returns A new HatchetWorker instance
39
42
  */
40
- static create(v1, v0, name, options) {
43
+ static create(v1, name, options) {
41
44
  return __awaiter(this, void 0, void 0, function* () {
42
- const resolvedOptions = (0, slot_utils_1.resolveWorkerOptions)(options);
45
+ // Normalize any legacy workflows before resolving worker options
46
+ const normalizedOptions = Object.assign(Object.assign({}, options), { workflows: options.workflows ? (0, legacy_transformer_1.normalizeWorkflows)(options.workflows) : undefined });
47
+ const resolvedOptions = (0, slot_utils_1.resolveWorkerOptions)(normalizedOptions);
43
48
  const opts = Object.assign({ name }, resolvedOptions);
44
- const internalWorker = new worker_internal_1.V1Worker(v1, opts);
45
- const worker = new Worker(v1, v0, internalWorker, options, name);
46
- yield worker.registerWorkflows(options.workflows);
49
+ const internalWorker = new worker_internal_1.InternalWorker(v1, opts);
50
+ const worker = new Worker(v1, internalWorker, normalizedOptions, name);
51
+ yield worker.registerWorkflows(normalizedOptions.workflows);
47
52
  return worker;
48
53
  });
49
54
  }
50
55
  /**
51
- * Registers workflows with the worker
56
+ * Registers workflows with the worker.
57
+ * Accepts both v1 BaseWorkflowDeclaration and legacy Workflow objects.
58
+ * Legacy workflows are automatically transformed and a deprecation warning is emitted.
52
59
  * @param workflows - Array of workflows to register
53
60
  * @returns Array of registered workflow promises
54
61
  */
55
62
  registerWorkflows(workflows) {
56
63
  return __awaiter(this, void 0, void 0, function* () {
57
- for (const wf of workflows || []) {
58
- this._registeredWorkflows.push(wf);
59
- if (wf instanceof declaration_1.BaseWorkflowDeclaration) {
60
- // TODO check if tenant is V1
61
- yield this._internal.registerWorkflowV1(wf);
62
- if (wf.definition._durableTasks.length > 0) {
63
- this._internal.registerDurableActionsV1(wf.definition);
64
- }
65
- }
66
- else {
67
- // fallback to v0 client for backwards compatibility
68
- yield this._internal.registerWorkflow(wf);
64
+ const normalized = workflows ? (0, legacy_transformer_1.normalizeWorkflows)(workflows) : [];
65
+ for (const wf of normalized) {
66
+ yield this._internal.registerWorkflow(wf);
67
+ if (wf.definition._durableTasks.length > 0) {
68
+ this._internal.registerDurableActions(wf.definition);
69
69
  }
70
70
  }
71
71
  });
72
72
  }
73
73
  /**
74
- * Registers a single workflow with the worker
74
+ * Registers a single workflow with the worker.
75
+ * Accepts both v1 BaseWorkflowDeclaration and legacy Workflow objects.
76
+ * Legacy workflows are automatically transformed and a deprecation warning is emitted.
75
77
  * @param workflow - The workflow to register
76
78
  * @returns A promise that resolves when the workflow is registered
77
79
  * @deprecated use registerWorkflows instead
@@ -123,14 +125,6 @@ class Worker {
123
125
  getLabels() {
124
126
  return this._internal.labels;
125
127
  }
126
- /**
127
- * Register a webhook with the worker
128
- * @param webhook - The webhook to register
129
- * @returns A promise that resolves when the webhook is registered
130
- */
131
- registerWebhook(webhook) {
132
- return this._internal.registerWebhook(webhook);
133
- }
134
128
  isPaused() {
135
129
  return __awaiter(this, void 0, void 0, function* () {
136
130
  var _a;
@@ -155,6 +149,27 @@ class Worker {
155
149
  }
156
150
  return this._v1.workers.unpause(this._internal.workerId);
157
151
  }
152
+ /**
153
+ * Waits until the worker has connected and registered with the server.
154
+ * Polls every 200ms. Use after start() to avoid fixed sleeps before running workflows.
155
+ */
156
+ waitUntilReady() {
157
+ return __awaiter(this, arguments, void 0, function* (timeoutMs = 10000) {
158
+ var _a;
159
+ if (this._legacyWorker) {
160
+ yield (0, sleep_1.default)(2000);
161
+ return;
162
+ }
163
+ const pollInterval = 200;
164
+ const start = Date.now();
165
+ while (Date.now() - start < timeoutMs) {
166
+ if ((_a = this._internal) === null || _a === void 0 ? void 0 : _a.workerId)
167
+ return;
168
+ yield (0, sleep_1.default)(pollInterval);
169
+ }
170
+ throw new Error(`Worker ${this.name} did not become ready within ${timeoutMs}ms`);
171
+ });
172
+ }
158
173
  }
159
174
  exports.Worker = Worker;
160
175
  var slot_utils_2 = require("./slot-utils");
@@ -1,6 +1,5 @@
1
1
  import WorkflowRunRef from '../util/workflow-run-ref';
2
2
  import { CronWorkflows, ScheduledWorkflows, V1CreateFilterRequest } from '../clients/rest/generated/data-contracts';
3
- import { Workflow as WorkflowV0 } from '../workflow';
4
3
  import { z } from 'zod';
5
4
  import { IHatchetClient } from './client/client.interface';
6
5
  import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskFn, CreateWorkflowDurableTaskOpts, CreateBaseTaskOpts, CreateOnSuccessTaskOpts, Concurrency, DurableTaskFn } from './task';
@@ -41,6 +40,12 @@ export type RunOpts = {
41
40
  * only used if spawned from within a parent task.
42
41
  */
43
42
  childKey?: string;
43
+ /**
44
+ * (optional) when running multiple workflows (array input), if true, return
45
+ * exceptions in the result array instead of throwing. Successes are outputs,
46
+ * failures are Error instances.
47
+ */
48
+ returnExceptions?: boolean;
44
49
  };
45
50
  /**
46
51
  * Helper type to safely extract output types from task results
@@ -51,28 +56,44 @@ export type TaskOutput<O, Key extends string, Fallback> = O extends Record<Key,
51
56
  */
52
57
  export type TaskOutputType<O, TaskName extends string, InferredType extends OutputType> = TaskName extends keyof O ? O[TaskName] extends OutputType ? O[TaskName] : InferredType : InferredType;
53
58
  type DefaultFilter = Omit<V1CreateFilterRequest, 'workflowId'>;
59
+ /**
60
+ * Sticky strategy for workflow scheduling.
61
+ *
62
+ * Prefer using `StickyStrategy.SOFT` / `StickyStrategy.HARD` (v1, non-protobuf).
63
+ * For backwards compatibility, the workflow/task `sticky` field also accepts legacy
64
+ * protobuf enum values (`0`/`1`) and strings (`'SOFT'`/`'HARD'`).
65
+ */
66
+ export declare const StickyStrategy: {
67
+ readonly SOFT: "soft";
68
+ readonly HARD: "hard";
69
+ };
70
+ export type StickyStrategy = (typeof StickyStrategy)[keyof typeof StickyStrategy];
71
+ export type StickyStrategyInput = StickyStrategy | 'SOFT' | 'HARD' | 0 | 1;
54
72
  export type CreateBaseWorkflowOpts = {
55
73
  /**
56
74
  * The name of the workflow.
57
75
  */
58
- name: WorkflowV0['id'];
76
+ name: string;
59
77
  /**
60
78
  * (optional) description of the workflow.
61
79
  */
62
- description?: WorkflowV0['description'];
80
+ description?: string;
63
81
  /**
64
82
  * (optional) version of the workflow.
65
83
  */
66
- version?: WorkflowV0['version'];
84
+ version?: string;
67
85
  /**
68
86
  * (optional) sticky strategy for the workflow.
69
87
  */
70
- sticky?: WorkflowV0['sticky'];
88
+ sticky?: StickyStrategyInput;
71
89
  /**
72
90
  * (optional) on config for the workflow.
73
- * @deprecated use onCrons and onEvents instead
91
+ * @alias for onCrons and onEvents
74
92
  */
75
- on?: WorkflowV0['on'];
93
+ on?: {
94
+ cron?: string | string[];
95
+ event?: string | string[];
96
+ };
76
97
  /**
77
98
  * (optional) cron config for the workflow.
78
99
  */
package/v1/declaration.js CHANGED
@@ -9,10 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.TaskWorkflowDeclaration = exports.WorkflowDeclaration = exports.BaseWorkflowDeclaration = exports.Priority = void 0;
12
+ exports.TaskWorkflowDeclaration = exports.WorkflowDeclaration = exports.BaseWorkflowDeclaration = exports.StickyStrategy = exports.Priority = void 0;
13
13
  exports.CreateTaskWorkflow = CreateTaskWorkflow;
14
14
  exports.CreateWorkflow = CreateWorkflow;
15
15
  exports.CreateDurableTaskWorkflow = CreateDurableTaskWorkflow;
16
+ const abort_error_1 = require("../util/abort-error");
16
17
  const parent_run_context_vars_1 = require("./parent-run-context-vars");
17
18
  const UNBOUND_ERR = new Error('workflow unbound to hatchet client, hint: use client.run instead');
18
19
  // eslint-disable-next-line no-shadow
@@ -22,6 +23,17 @@ var Priority;
22
23
  Priority[Priority["MEDIUM"] = 2] = "MEDIUM";
23
24
  Priority[Priority["HIGH"] = 3] = "HIGH";
24
25
  })(Priority || (exports.Priority = Priority = {}));
26
+ /**
27
+ * Sticky strategy for workflow scheduling.
28
+ *
29
+ * Prefer using `StickyStrategy.SOFT` / `StickyStrategy.HARD` (v1, non-protobuf).
30
+ * For backwards compatibility, the workflow/task `sticky` field also accepts legacy
31
+ * protobuf enum values (`0`/`1`) and strings (`'SOFT'`/`'HARD'`).
32
+ */
33
+ exports.StickyStrategy = {
34
+ SOFT: 'soft',
35
+ HARD: 'hard',
36
+ };
25
37
  /**
26
38
  * Represents a workflow that can be executed by Hatchet.
27
39
  * @template I The input type for the workflow.
@@ -48,7 +60,18 @@ class BaseWorkflowDeclaration {
48
60
  if (!parentRunContext && ((options === null || options === void 0 ? void 0 : options.childKey) || (options === null || options === void 0 ? void 0 : options.sticky))) {
49
61
  this.client.admin.logger.warn('ignoring childKey or sticky because run is not being spawned from a parent task');
50
62
  }
51
- const runOpts = Object.assign(Object.assign({}, options), { parentId: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentId, parentTaskRunExternalId: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentTaskRunExternalId, childIndex: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.childIndex, sticky: (options === null || options === void 0 ? void 0 : options.sticky) ? parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.desiredWorkerId : undefined, childKey: options === null || options === void 0 ? void 0 : options.childKey });
63
+ const inheritedSignal = parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.signal;
64
+ // Precheck: if we're being called from a cancelled parent task, do not enqueue more work.
65
+ // The signal is inherited from the parent task's `ctx.abortController.signal`.
66
+ (0, abort_error_1.throwIfAborted)(inheritedSignal, {
67
+ isTrigger: true,
68
+ context: (parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentTaskRunExternalId)
69
+ ? `task run ${parentRunContext.parentTaskRunExternalId}`
70
+ : undefined,
71
+ warn: (message) => this.client.admin.logger.warn(message),
72
+ });
73
+ parent_run_context_vars_1.parentRunContextManager.incrementChildIndex(Array.isArray(input) ? input.length : 1);
74
+ const runOpts = Object.assign(Object.assign({}, (options !== null && options !== void 0 ? options : {})), { parentId: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentId, parentTaskRunExternalId: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.parentTaskRunExternalId, childIndex: parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.childIndex, sticky: (options === null || options === void 0 ? void 0 : options.sticky) ? parentRunContext === null || parentRunContext === void 0 ? void 0 : parentRunContext.desiredWorkerId : undefined, childKey: options === null || options === void 0 ? void 0 : options.childKey });
52
75
  if (Array.isArray(input)) {
53
76
  let resp = [];
54
77
  for (let i = 0; i < input.length; i += 500) {
@@ -74,6 +97,9 @@ class BaseWorkflowDeclaration {
74
97
  // eslint-disable-next-line no-param-reassign
75
98
  ref._standaloneTaskName = _standaloneTaskName;
76
99
  }
100
+ // Ensure result subscriptions inherit cancellation if no signal is provided explicitly.
101
+ // eslint-disable-next-line no-param-reassign
102
+ ref.defaultSignal = inheritedSignal;
77
103
  res.push(ref);
78
104
  });
79
105
  return res;
@@ -82,6 +108,7 @@ class BaseWorkflowDeclaration {
82
108
  if (_standaloneTaskName) {
83
109
  res._standaloneTaskName = _standaloneTaskName;
84
110
  }
111
+ res.defaultSignal = inheritedSignal;
85
112
  return res;
86
113
  });
87
114
  }
@@ -103,6 +130,17 @@ class BaseWorkflowDeclaration {
103
130
  }
104
131
  if (Array.isArray(input)) {
105
132
  const refs = yield this.runNoWait(input, options, _standaloneTaskName);
133
+ if (options === null || options === void 0 ? void 0 : options.returnExceptions) {
134
+ const settled = yield Promise.allSettled(refs.map((ref) => ref.result()));
135
+ return settled.map((s) => {
136
+ if (s.status === 'fulfilled')
137
+ return s.value;
138
+ const { reason } = s;
139
+ if (reason instanceof Error)
140
+ return reason;
141
+ return new Error(Array.isArray(reason) ? reason.join('; ') : String(reason));
142
+ });
143
+ }
106
144
  return Promise.all(refs.map((ref) => ref.result()));
107
145
  }
108
146
  const res = yield this.runNoWait(input, options, _standaloneTaskName);
@@ -119,10 +157,16 @@ class BaseWorkflowDeclaration {
119
157
  */
120
158
  schedule(enqueueAt, input, options) {
121
159
  return __awaiter(this, void 0, void 0, function* () {
160
+ var _a;
122
161
  if (!this.client) {
123
162
  throw UNBOUND_ERR;
124
163
  }
125
- const scheduled = this.client.scheduled.create(this.definition.name, Object.assign({ triggerAt: enqueueAt, input: input }, options));
164
+ // If called from within a cancelled parent task, do not enqueue scheduled work.
165
+ (0, abort_error_1.throwIfAborted)((_a = parent_run_context_vars_1.parentRunContextManager.getContext()) === null || _a === void 0 ? void 0 : _a.signal, {
166
+ isTrigger: true,
167
+ warn: (message) => this.client.admin.logger.warn(message),
168
+ });
169
+ const scheduled = this.client.scheduled.create(this.definition.name, Object.assign({ triggerAt: enqueueAt, input: input }, (options !== null && options !== void 0 ? options : {})));
126
170
  return scheduled;
127
171
  });
128
172
  }
@@ -152,10 +196,16 @@ class BaseWorkflowDeclaration {
152
196
  */
153
197
  cron(name, expression, input, options) {
154
198
  return __awaiter(this, void 0, void 0, function* () {
199
+ var _a;
155
200
  if (!this.client) {
156
201
  throw UNBOUND_ERR;
157
202
  }
158
- const cronDef = this.client.crons.create(this.definition.name, Object.assign(Object.assign({ expression, input: input }, options), { additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata, name }));
203
+ // If called from within a cancelled parent task, do not enqueue cron work.
204
+ (0, abort_error_1.throwIfAborted)((_a = parent_run_context_vars_1.parentRunContextManager.getContext()) === null || _a === void 0 ? void 0 : _a.signal, {
205
+ isTrigger: true,
206
+ warn: (message) => this.client.admin.logger.warn(message),
207
+ });
208
+ const cronDef = this.client.crons.create(this.definition.name, Object.assign(Object.assign({ expression, input: input }, (options !== null && options !== void 0 ? options : {})), { additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata, name }));
159
209
  return cronDef;
160
210
  });
161
211
  }
@@ -283,7 +333,7 @@ class WorkflowDeclaration extends BaseWorkflowDeclaration {
283
333
  typedOptions = options;
284
334
  }
285
335
  if (this.definition.onFailure) {
286
- (_a = this.client) === null || _a === void 0 ? void 0 : _a._v0.logger.warn(`onFailure task will override existing onFailure task`);
336
+ (_a = this.client) === null || _a === void 0 ? void 0 : _a.logger.warn(`onFailure task will override existing onFailure task`);
287
337
  }
288
338
  this.definition.onFailure = typedOptions;
289
339
  return typedOptions;
@@ -306,7 +356,7 @@ class WorkflowDeclaration extends BaseWorkflowDeclaration {
306
356
  typedOptions = options;
307
357
  }
308
358
  if (this.definition.onSuccess) {
309
- (_a = this.client) === null || _a === void 0 ? void 0 : _a._v0.logger.warn(`onSuccess task will override existing onSuccess task`);
359
+ (_a = this.client) === null || _a === void 0 ? void 0 : _a.logger.warn(`onSuccess task will override existing onSuccess task`);
310
360
  }
311
361
  this.definition.onSuccess = typedOptions;
312
362
  return typedOptions;
@@ -0,0 +1,19 @@
1
+ import { HatchetClient } from '../..';
2
+ import type { BaseWorkflowDeclaration } from '../..';
3
+ import { Worker } from '../../client/worker/worker';
4
+ export declare function requireEnv(name: string): string;
5
+ export declare function makeE2EClient(): HatchetClient;
6
+ export declare function makeTestScope(prefix?: string): string;
7
+ export declare function startWorker({ client, name, workflows, slots, }: {
8
+ client: HatchetClient;
9
+ name: string;
10
+ workflows: Array<BaseWorkflowDeclaration<any, any>>;
11
+ slots?: number;
12
+ }): Promise<Worker>;
13
+ export declare function stopWorker(worker: Worker | undefined): Promise<void>;
14
+ export declare function poll<T>(fn: () => Promise<T>, { timeoutMs, intervalMs, shouldStop, label, }: {
15
+ timeoutMs?: number;
16
+ intervalMs?: number;
17
+ shouldStop: (value: T) => boolean;
18
+ label?: string;
19
+ }): Promise<T>;
@@ -0,0 +1,70 @@
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.requireEnv = requireEnv;
16
+ exports.makeE2EClient = makeE2EClient;
17
+ exports.makeTestScope = makeTestScope;
18
+ exports.startWorker = startWorker;
19
+ exports.stopWorker = stopWorker;
20
+ exports.poll = poll;
21
+ const sleep_1 = __importDefault(require("../../../util/sleep"));
22
+ const crypto_1 = require("crypto");
23
+ const v1_1 = require("../..");
24
+ function requireEnv(name) {
25
+ const value = process.env[name];
26
+ if (!value) {
27
+ throw new Error(`Missing required environment variable ${name}. ` +
28
+ `E2E tests require a configured Hatchet instance and credentials.`);
29
+ }
30
+ return value;
31
+ }
32
+ function makeE2EClient() {
33
+ // ConfigLoader requires a token; this makes the failure message obvious.
34
+ requireEnv('HATCHET_CLIENT_TOKEN');
35
+ return v1_1.HatchetClient.init();
36
+ }
37
+ function makeTestScope(prefix = 'ts_e2e') {
38
+ return `${prefix}_${(0, crypto_1.randomUUID)()}`;
39
+ }
40
+ function startWorker(_a) {
41
+ return __awaiter(this, arguments, void 0, function* ({ client, name, workflows, slots = 50, }) {
42
+ const worker = yield client.worker(name, { workflows, slots });
43
+ void worker.start();
44
+ yield worker.waitUntilReady(10000);
45
+ return worker;
46
+ });
47
+ }
48
+ function stopWorker(worker) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ if (!worker)
51
+ return;
52
+ yield worker.stop();
53
+ yield (0, sleep_1.default)(300);
54
+ });
55
+ }
56
+ function poll(fn_1, _a) {
57
+ return __awaiter(this, arguments, void 0, function* (fn, { timeoutMs = 30000, intervalMs = 100, shouldStop, label = 'poll', }) {
58
+ const start = Date.now();
59
+ // eslint-disable-next-line no-constant-condition
60
+ while (true) {
61
+ const value = yield fn();
62
+ if (shouldStop(value))
63
+ return value;
64
+ if (Date.now() - start > timeoutMs) {
65
+ throw new Error(`Timed out waiting for ${label} after ${timeoutMs}ms`);
66
+ }
67
+ yield (0, sleep_1.default)(intervalMs);
68
+ }
69
+ });
70
+ }
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const workflows_1 = require("../../../protoc/workflows");
12
+ const v1_1 = require("../..");
13
13
  const hatchet_client_1 = require("../hatchet-client");
14
14
  // > AffinityWorkflow
15
15
  const workflow = hatchet_client_1.hatchet.workflow({
@@ -22,8 +22,8 @@ workflow.task({
22
22
  const results = [];
23
23
  // eslint-disable-next-line no-plusplus
24
24
  for (let i = 0; i < 50; i++) {
25
- const result = yield ctx.spawnWorkflow(childWorkflow.id, {});
26
- results.push(result.output);
25
+ const result = yield childWorkflow.run({});
26
+ results.push(result);
27
27
  }
28
28
  console.log('Spawned 50 child workflows');
29
29
  console.log('Results:', yield Promise.all(results));
@@ -55,7 +55,7 @@ childWorkflow.task({
55
55
  memory: {
56
56
  value: 512,
57
57
  required: true,
58
- comparator: workflows_1.WorkerLabelComparator.LESS_THAN,
58
+ comparator: v1_1.WorkerLabelComparator.LESS_THAN,
59
59
  },
60
60
  },
61
61
  fn: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
@@ -0,0 +1,9 @@
1
+ export type ParentInput = {
2
+ n: number;
3
+ };
4
+ export declare const bulkChild: import("../..").TaskWorkflowDeclaration<{
5
+ i: number;
6
+ }, {
7
+ i: number;
8
+ }, {}, {}, {}, {}>;
9
+ export declare const bulkParentWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
@@ -0,0 +1,34 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.bulkParentWorkflow = exports.bulkChild = void 0;
13
+ const hatchet_client_1 = require("../hatchet-client");
14
+ exports.bulkChild = hatchet_client_1.hatchet.task({
15
+ name: 'bulk-child',
16
+ fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
17
+ return { i: input.i };
18
+ }),
19
+ });
20
+ exports.bulkParentWorkflow = hatchet_client_1.hatchet.workflow({
21
+ name: 'bulk-parent',
22
+ });
23
+ exports.bulkParentWorkflow.task({
24
+ name: 'spawn',
25
+ fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const typed = input;
27
+ const children = Array.from({ length: typed.n }, (_, i) => ({
28
+ workflow: exports.bulkChild,
29
+ input: { i },
30
+ }));
31
+ const results = yield ctx.bulkRunChildren(children);
32
+ return { results };
33
+ }),
34
+ });
@@ -0,0 +1,3 @@
1
+ export declare const bulkReplayTest1: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, void, {}, {}, {}, {}>;
2
+ export declare const bulkReplayTest2: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, void, {}, {}, {}, {}>;
3
+ export declare const bulkReplayTest3: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, void, {}, {}, {}, {}>;
@@ -0,0 +1,44 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.bulkReplayTest3 = exports.bulkReplayTest2 = exports.bulkReplayTest1 = void 0;
13
+ /* eslint-disable no-console */
14
+ const hatchet_client_1 = require("../hatchet-client");
15
+ exports.bulkReplayTest1 = hatchet_client_1.hatchet.task({
16
+ name: 'bulk-replay-test-1',
17
+ retries: 1,
18
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
19
+ console.log('retrying bulk replay test task', ctx.retryCount());
20
+ if (ctx.retryCount() === 0) {
21
+ throw new Error('This is a test error to trigger a retry.');
22
+ }
23
+ }),
24
+ });
25
+ exports.bulkReplayTest2 = hatchet_client_1.hatchet.task({
26
+ name: 'bulk-replay-test-2',
27
+ retries: 1,
28
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
29
+ console.log('retrying bulk replay test task', ctx.retryCount());
30
+ if (ctx.retryCount() === 0) {
31
+ throw new Error('This is a test error to trigger a retry.');
32
+ }
33
+ }),
34
+ });
35
+ exports.bulkReplayTest3 = hatchet_client_1.hatchet.task({
36
+ name: 'bulk-replay-test-3',
37
+ retries: 1,
38
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
39
+ console.log('retrying bulk replay test task', ctx.retryCount());
40
+ if (ctx.retryCount() === 0) {
41
+ throw new Error('This is a test error to trigger a retry.');
42
+ }
43
+ }),
44
+ });
@@ -0,0 +1,2 @@
1
+ export declare const cancellationWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}, {}>;
2
+ export declare const abortSignal: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, void, {}, {}, {}, {}>;