@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
@@ -0,0 +1,65 @@
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.runDetailTestWorkflow = void 0;
16
+ const sleep_1 = __importDefault(require("../../../util/sleep"));
17
+ const hatchet_client_1 = require("../hatchet-client");
18
+ exports.runDetailTestWorkflow = hatchet_client_1.hatchet.workflow({
19
+ name: 'run-detail-test',
20
+ });
21
+ const step1 = exports.runDetailTestWorkflow.task({
22
+ name: 'step1',
23
+ fn: () => __awaiter(void 0, void 0, void 0, function* () {
24
+ return ({
25
+ random_number: Math.floor(Math.random() * 100) + 1,
26
+ });
27
+ }),
28
+ });
29
+ const step2 = exports.runDetailTestWorkflow.task({
30
+ name: 'step2',
31
+ fn: () => __awaiter(void 0, void 0, void 0, function* () {
32
+ yield (0, sleep_1.default)(5000);
33
+ return {
34
+ random_number: Math.floor(Math.random() * 100) + 1,
35
+ };
36
+ }),
37
+ });
38
+ exports.runDetailTestWorkflow.task({
39
+ name: 'cancel_step',
40
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
41
+ yield ctx.cancel();
42
+ yield (0, sleep_1.default)(10000);
43
+ return {};
44
+ }),
45
+ });
46
+ exports.runDetailTestWorkflow.task({
47
+ name: 'fail_step',
48
+ fn: () => __awaiter(void 0, void 0, void 0, function* () {
49
+ throw new Error('Intentional Failure');
50
+ }),
51
+ });
52
+ const step3 = exports.runDetailTestWorkflow.task({
53
+ name: 'step3',
54
+ parents: [step1, step2],
55
+ fn: (_input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
56
+ const one = (yield ctx.parentOutput(step1)).random_number;
57
+ const two = (yield ctx.parentOutput(step2)).random_number;
58
+ return { sum: one + two };
59
+ }),
60
+ });
61
+ exports.runDetailTestWorkflow.task({
62
+ name: 'step4',
63
+ parents: [step1, step3],
64
+ fn: () => __awaiter(void 0, void 0, void 0, function* () { return ({ step4: 'step4' }); }),
65
+ });
@@ -0,0 +1,14 @@
1
+ export declare const helloWorld: import("../..").TaskWorkflowDeclaration<{
2
+ [x: string]: import("../..").JsonValue;
3
+ } & {
4
+ [x: string]: import("../..").JsonValue;
5
+ }, {
6
+ result: string;
7
+ }, {}, {}, {}, {}>;
8
+ export declare const helloWorldDurable: import("../..").TaskWorkflowDeclaration<{
9
+ [x: string]: import("../..").JsonValue;
10
+ } & {
11
+ [x: string]: import("../..").JsonValue;
12
+ }, {
13
+ result: string;
14
+ }, {}, {}, {}, {}>;
@@ -0,0 +1,27 @@
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.helloWorldDurable = exports.helloWorld = void 0;
13
+ const hatchet_client_1 = require("../hatchet-client");
14
+ // Mirrors `sdks/python/examples/simple/worker.py` outputs for e2e.
15
+ exports.helloWorld = hatchet_client_1.hatchet.task({
16
+ name: 'hello-world',
17
+ fn: (_input) => __awaiter(void 0, void 0, void 0, function* () {
18
+ return { result: 'Hello, world!' };
19
+ }),
20
+ });
21
+ exports.helloWorldDurable = hatchet_client_1.hatchet.durableTask({
22
+ name: 'hello-world-durable',
23
+ executionTimeout: '10m',
24
+ fn: (_input) => __awaiter(void 0, void 0, void 0, function* () {
25
+ return { result: 'Hello, world!' };
26
+ }),
27
+ });
@@ -29,11 +29,11 @@ function main() {
29
29
  // !!
30
30
  // > Subscribing to results
31
31
  // the return object of the enqueue method is a WorkflowRunRef which includes a listener for the result of the workflow
32
- const result = yield run.result();
32
+ const result = yield run.output;
33
33
  console.log(result);
34
34
  // if you need to subscribe to the result of the workflow at a later time, you can use the runRef method and the stored runId
35
35
  const ref = hatchet_client_1.hatchet.runRef(runId);
36
- const result2 = yield ref.result();
36
+ const result2 = yield ref.output;
37
37
  console.log(result2);
38
38
  // !!
39
39
  });
@@ -11,14 +11,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.sticky = void 0;
13
13
  /* eslint-disable no-console */
14
- const workflows_1 = require("../../../protoc/workflows");
14
+ const v1_1 = require("../..");
15
15
  const hatchet_client_1 = require("../hatchet-client");
16
16
  const workflow_1 = require("../child_workflows/workflow");
17
17
  // > Sticky Task
18
18
  exports.sticky = hatchet_client_1.hatchet.task({
19
19
  name: 'sticky',
20
20
  retries: 3,
21
- sticky: workflows_1.StickyStrategy.SOFT,
21
+ sticky: v1_1.StickyStrategy.SOFT,
22
22
  fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
23
23
  // specify a child workflow to run on the same worker
24
24
  const result = yield workflow_1.child.run({
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
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
+ /* eslint-disable no-console */
13
+ const workflow_1 = require("./workflow");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ try {
17
+ yield workflow_1.timeoutTask.run({ Message: 'hello' });
18
+ }
19
+ catch (e) {
20
+ console.log('timeoutTask failed as expected', e);
21
+ }
22
+ const res = yield workflow_1.refreshTimeoutTask.run({ Message: 'hello' });
23
+ console.log(res);
24
+ });
25
+ }
26
+ if (require.main === module) {
27
+ main()
28
+ .catch(console.error)
29
+ .finally(() => process.exit(0));
30
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
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
+ const hatchet_client_1 = require("../hatchet-client");
13
+ const workflow_1 = require("./workflow");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const worker = yield hatchet_client_1.hatchet.worker('timeout-worker', {
17
+ workflows: [workflow_1.timeoutTask, workflow_1.refreshTimeoutTask],
18
+ slots: 50,
19
+ });
20
+ yield worker.start();
21
+ });
22
+ }
23
+ if (require.main === module) {
24
+ main();
25
+ }
@@ -0,0 +1,10 @@
1
+ export type SimpleInput = {
2
+ Message: string;
3
+ };
4
+ export declare const timeoutTask: import("../..").TaskWorkflowDeclaration<SimpleInput, {
5
+ status: string;
6
+ }, {}, {}, {}, {}>;
7
+ export declare const refreshTimeoutTask: import("../..").TaskWorkflowDeclaration<SimpleInput, {
8
+ status: string;
9
+ message: string;
10
+ }, {}, {}, {}, {}>;
@@ -0,0 +1,56 @@
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.refreshTimeoutTask = exports.timeoutTask = void 0;
16
+ const sleep_1 = __importDefault(require("../../../util/sleep"));
17
+ const hatchet_client_1 = require("../hatchet-client");
18
+ // > Execution Timeout
19
+ // Mirrors Python `examples/timeout/test_timeout.py::test_execution_timeout`
20
+ exports.timeoutTask = hatchet_client_1.hatchet.task({
21
+ name: 'timeout',
22
+ executionTimeout: '3s',
23
+ fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
24
+ try {
25
+ yield (0, sleep_1.default)(10 * 1000, ctx.abortController.signal);
26
+ }
27
+ catch (_a) {
28
+ throw new Error('Task was cancelled');
29
+ }
30
+ return {
31
+ status: 'success',
32
+ };
33
+ }),
34
+ });
35
+ // !!
36
+ // > Refresh Timeout
37
+ // Mirrors Python `examples/timeout/test_timeout.py::test_run_refresh_timeout`
38
+ exports.refreshTimeoutTask = hatchet_client_1.hatchet.task({
39
+ name: 'refresh-timeout',
40
+ executionTimeout: '3s',
41
+ scheduleTimeout: '5s',
42
+ fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
43
+ ctx.refreshTimeout('5s');
44
+ try {
45
+ yield (0, sleep_1.default)(4000, ctx.abortController.signal);
46
+ }
47
+ catch (_a) {
48
+ throw new Error('cancelled');
49
+ }
50
+ return {
51
+ status: 'success',
52
+ message: input.Message.toLowerCase(),
53
+ };
54
+ }),
55
+ });
56
+ // !!
@@ -0,0 +1,5 @@
1
+ export type WebhookInput = {
2
+ type: string;
3
+ message: string;
4
+ };
5
+ export declare const webhookWorkflow: import("../..").WorkflowDeclaration<WebhookInput, {}, {}>;
@@ -0,0 +1,23 @@
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.webhookWorkflow = void 0;
13
+ const hatchet_client_1 = require("../hatchet-client");
14
+ exports.webhookWorkflow = hatchet_client_1.hatchet.workflow({
15
+ name: 'webhook-workflow',
16
+ onEvents: ['webhook:test'],
17
+ });
18
+ exports.webhookWorkflow.task({
19
+ name: 'webhook-task',
20
+ fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
21
+ return input;
22
+ }),
23
+ });
package/v1/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from './types';
8
8
  export * from './task';
9
9
  export * from './client/worker/context';
10
10
  export * from './slot-types';
11
+ export * from '../legacy/legacy-transformer';
package/v1/index.js CHANGED
@@ -24,3 +24,4 @@ __exportStar(require("./types"), exports);
24
24
  __exportStar(require("./task"), exports);
25
25
  __exportStar(require("./client/worker/context"), exports);
26
26
  __exportStar(require("./slot-types"), exports);
27
+ __exportStar(require("../legacy/legacy-transformer"), exports);
@@ -6,10 +6,16 @@ export interface ParentRunContext {
6
6
  parentTaskRunExternalId: string;
7
7
  desiredWorkerId: string;
8
8
  childIndex?: number;
9
+ /**
10
+ * (optional) AbortSignal inherited by nested `run()` calls.
11
+ * Used to cancel local "wait for result" subscriptions when the parent task is cancelled.
12
+ */
13
+ signal?: AbortSignal;
9
14
  }
10
15
  export declare class ParentRunContextManager {
11
16
  private storage;
12
17
  constructor();
18
+ runWithContext<T>(opts: ParentRunContext, fn: () => T): T;
13
19
  setContext(opts: ParentRunContext): void;
14
20
  setParentRunIdAndIncrementChildIndex(opts: ParentRunContext): void;
15
21
  incrementChildIndex(n: number): void;
@@ -6,6 +6,9 @@ class ParentRunContextManager {
6
6
  constructor() {
7
7
  this.storage = new async_hooks_1.AsyncLocalStorage();
8
8
  }
9
+ runWithContext(opts, fn) {
10
+ return this.storage.run(Object.assign({}, opts), fn);
11
+ }
9
12
  setContext(opts) {
10
13
  this.storage.enterWith(Object.assign({}, opts));
11
14
  }
package/v1/task.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { ConcurrencyLimitStrategy } from '../protoc/v1/workflows';
2
- import { CreateStep } from '../step';
1
+ import { ConcurrencyLimitStrategy, RateLimitDuration, WorkerLabelComparator } from '../protoc/v1/workflows';
3
2
  import { Conditions } from './conditions';
4
3
  import { Duration } from './client/duration';
5
4
  import { InputType, OutputType, UnknownInputType } from './types';
6
5
  import { Context, DurableContext } from './client/worker/context';
6
+ export { ConcurrencyLimitStrategy, WorkerLabelComparator };
7
7
  /**
8
8
  * Options for configuring the concurrency for a task.
9
9
  */
@@ -59,7 +59,7 @@ export type CreateBaseTaskOpts<I extends InputType = UnknownInputType, O extends
59
59
  /**
60
60
  * @deprecated use executionTimeout instead
61
61
  */
62
- timeout?: CreateStep<I, O>['timeout'];
62
+ timeout?: Duration;
63
63
  /**
64
64
  * (optional) execution timeout duration for the task after it starts running
65
65
  * go duration format (e.g., "1s", "5m", "1h").
@@ -79,17 +79,27 @@ export type CreateBaseTaskOpts<I extends InputType = UnknownInputType, O extends
79
79
  *
80
80
  * default: 0
81
81
  */
82
- retries?: CreateStep<I, O>['retries'];
82
+ retries?: number;
83
83
  /**
84
84
  * (optional) backoff strategy configuration for retries.
85
85
  * - factor: Base of the exponential backoff (base ^ retry count)
86
86
  * - maxSeconds: Maximum backoff duration in seconds
87
87
  */
88
- backoff?: CreateStep<I, O>['backoff'];
88
+ backoff?: {
89
+ factor?: number | undefined;
90
+ maxSeconds?: number | undefined;
91
+ };
89
92
  /**
90
93
  * (optional) rate limits for the task.
91
94
  */
92
- rateLimits?: CreateStep<I, O>['rate_limits'];
95
+ rateLimits?: {
96
+ units: string | number;
97
+ key?: string;
98
+ staticKey?: string;
99
+ dynamicKey?: string;
100
+ limit?: string | number;
101
+ duration?: RateLimitDuration;
102
+ }[];
93
103
  /**
94
104
  * (optional) worker labels for task routing and scheduling.
95
105
  * Each label can be a simple string/number value or an object with additional configuration:
@@ -98,7 +108,12 @@ export type CreateBaseTaskOpts<I extends InputType = UnknownInputType, O extends
98
108
  * - weight: Priority weight for worker selection
99
109
  * - comparator: Custom comparison logic for label matching
100
110
  */
101
- desiredWorkerLabels?: CreateStep<I, O>['worker_labels'];
111
+ desiredWorkerLabels?: Record<string, {
112
+ value: string | number;
113
+ required?: boolean;
114
+ weight?: number;
115
+ comparator?: WorkerLabelComparator;
116
+ }>;
102
117
  /**
103
118
  * (optional) the concurrency options for the task
104
119
  */
package/v1/task.js CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NonRetryableError = void 0;
3
+ exports.NonRetryableError = exports.WorkerLabelComparator = exports.ConcurrencyLimitStrategy = void 0;
4
+ const workflows_1 = require("../protoc/v1/workflows");
5
+ Object.defineProperty(exports, "ConcurrencyLimitStrategy", { enumerable: true, get: function () { return workflows_1.ConcurrencyLimitStrategy; } });
6
+ Object.defineProperty(exports, "WorkerLabelComparator", { enumerable: true, get: function () { return workflows_1.WorkerLabelComparator; } });
4
7
  class NonRetryableError extends Error {
5
8
  constructor(message) {
6
9
  super(message);
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.13.1";
1
+ export declare const HATCHET_VERSION = "1.14.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.13.1';
4
+ exports.HATCHET_VERSION = '1.14.0';