@hatchet-dev/typescript-sdk 1.0.0-alpha1 → 1.0.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 (194) hide show
  1. package/clients/admin/admin-client.d.ts +15 -20
  2. package/clients/admin/admin-client.js +21 -17
  3. package/clients/hatchet-client/hatchet-client.d.ts +5 -4
  4. package/clients/hatchet-client/hatchet-client.js +6 -4
  5. package/clients/listeners/durable-listener/durable-listener-client.d.ts +25 -0
  6. package/clients/listeners/durable-listener/durable-listener-client.js +30 -0
  7. package/clients/listeners/durable-listener/pooled-durable-listener-client.d.ts +43 -0
  8. package/clients/listeners/durable-listener/pooled-durable-listener-client.js +241 -0
  9. package/clients/{listener/listener-client.d.ts → listeners/run-listener/child-listener-client.d.ts} +8 -8
  10. package/clients/{listener/listener-client.js → listeners/run-listener/child-listener-client.js} +8 -19
  11. package/clients/{listener/child-listener-client.d.ts → listeners/run-listener/pooled-child-listener-client.d.ts} +5 -5
  12. package/clients/{listener/child-listener-client.js → listeners/run-listener/pooled-child-listener-client.js} +5 -5
  13. package/clients/rest/generated/Api.d.ts +49 -2
  14. package/clients/rest/generated/Api.js +30 -0
  15. package/clients/rest/generated/data-contracts.d.ts +88 -82
  16. package/clients/rest/generated/data-contracts.js +8 -1
  17. package/clients/worker/worker.d.ts +5 -1
  18. package/clients/worker/worker.js +173 -2
  19. package/examples/affinity-workers.js +5 -1
  20. package/examples/api.js +1 -1
  21. package/examples/bulk-fanout-worker.js +1 -1
  22. package/examples/byo-logger.js +4 -0
  23. package/examples/concurrency/cancel-in-progress/concurrency-event.js +2 -2
  24. package/examples/concurrency/group-round-robin/concurrency-event.js +1 -1
  25. package/examples/crons/programatic-crons.js +4 -4
  26. package/examples/dag-worker.js +0 -1
  27. package/examples/example-event.js +2 -2
  28. package/examples/logger.js +2 -0
  29. package/examples/on-failure.js +1 -1
  30. package/examples/rate-limit/events.js +3 -3
  31. package/examples/scheduled-runs/programatic-schedules.js +4 -4
  32. package/examples/sticky-worker-with-check.js +2 -2
  33. package/examples/sticky-worker.js +5 -0
  34. package/index.d.ts +1 -3
  35. package/index.js +1 -3
  36. package/package.json +2 -2
  37. package/protoc/dispatcher/dispatcher.d.ts +2 -0
  38. package/protoc/dispatcher/dispatcher.js +1 -1
  39. package/protoc/events/events.js +1 -1
  40. package/protoc/google/protobuf/timestamp.js +1 -1
  41. package/protoc/v1/dispatcher.d.ts +77 -0
  42. package/protoc/v1/dispatcher.js +341 -0
  43. package/protoc/v1/shared/condition.d.ts +59 -0
  44. package/protoc/v1/shared/condition.js +549 -0
  45. package/protoc/v1/workflows.d.ts +263 -0
  46. package/protoc/v1/workflows.js +1823 -0
  47. package/protoc/workflows/workflows.js +1 -1
  48. package/step.d.ts +173 -47
  49. package/step.js +208 -64
  50. package/util/sleep.d.ts +7 -0
  51. package/util/sleep.js +7 -0
  52. package/util/workflow-run-ref.d.ts +8 -2
  53. package/util/workflow-run-ref.js +13 -0
  54. package/v1/client/client.d.ts +125 -7
  55. package/v1/client/client.interface.d.ts +9 -1
  56. package/v1/client/client.js +148 -17
  57. package/v1/client/duration.d.ts +7 -0
  58. package/v1/client/duration.js +2 -0
  59. package/v1/client/features/index.d.ts +5 -0
  60. package/v1/client/features/index.js +21 -0
  61. package/v1/client/features/metrics.d.ts +14 -0
  62. package/v1/client/features/metrics.js +45 -0
  63. package/v1/client/features/ratelimits.d.ts +20 -0
  64. package/v1/client/features/ratelimits.js +40 -0
  65. package/v1/client/features/runs.d.ts +15 -0
  66. package/v1/client/features/runs.js +60 -0
  67. package/v1/client/features/workers.d.ts +14 -0
  68. package/v1/client/features/workers.js +56 -0
  69. package/v1/client/features/workflows.d.ts +17 -0
  70. package/v1/client/features/workflows.js +93 -0
  71. package/v1/client/worker.d.ts +25 -15
  72. package/v1/client/worker.js +76 -47
  73. package/v1/conditions/base.d.ts +18 -0
  74. package/v1/conditions/base.js +18 -0
  75. package/v1/conditions/index.d.ts +31 -0
  76. package/v1/conditions/index.js +91 -0
  77. package/v1/conditions/parent-condition.d.ts +40 -0
  78. package/v1/conditions/parent-condition.js +36 -0
  79. package/v1/conditions/sleep-condition.d.ts +47 -0
  80. package/v1/conditions/sleep-condition.js +38 -0
  81. package/v1/conditions/transformer.d.ts +5 -0
  82. package/v1/conditions/transformer.js +52 -0
  83. package/v1/conditions/user-event-condition.d.ts +50 -0
  84. package/v1/conditions/user-event-condition.js +39 -0
  85. package/v1/declaration.d.ts +309 -0
  86. package/v1/declaration.js +296 -0
  87. package/v1/examples/child_workflows/worker.js +2 -2
  88. package/v1/examples/child_workflows/workflow.d.ts +2 -2
  89. package/v1/examples/child_workflows/workflow.js +5 -3
  90. package/v1/examples/concurrency-rr/load.js +2 -2
  91. package/v1/examples/concurrency-rr/worker.js +2 -2
  92. package/v1/examples/concurrency-rr/workflow.d.ts +1 -1
  93. package/v1/examples/concurrency-rr/workflow.js +2 -3
  94. package/v1/examples/dag/worker.js +2 -2
  95. package/v1/examples/dag/workflow.d.ts +1 -1
  96. package/v1/examples/dag/workflow.js +3 -3
  97. package/v1/examples/dag_match_condition/event.js +28 -0
  98. package/v1/examples/dag_match_condition/run.d.ts +1 -0
  99. package/v1/examples/dag_match_condition/run.js +25 -0
  100. package/v1/examples/dag_match_condition/worker.d.ts +1 -0
  101. package/{examples/playground.js → v1/examples/dag_match_condition/worker.js} +7 -22
  102. package/v1/examples/dag_match_condition/workflow.d.ts +11 -0
  103. package/v1/examples/dag_match_condition/workflow.js +41 -0
  104. package/v1/examples/deep/worker.js +2 -2
  105. package/v1/examples/deep/workflow.d.ts +6 -6
  106. package/v1/examples/deep/workflow.js +7 -7
  107. package/v1/examples/durable-sleep/event.d.ts +1 -0
  108. package/v1/examples/durable-sleep/event.js +28 -0
  109. package/v1/examples/durable-sleep/run.d.ts +1 -0
  110. package/v1/examples/durable-sleep/run.js +30 -0
  111. package/v1/examples/durable-sleep/worker.d.ts +1 -0
  112. package/v1/examples/durable-sleep/worker.js +24 -0
  113. package/v1/examples/durable-sleep/workflow.d.ts +1 -0
  114. package/v1/examples/durable-sleep/workflow.js +37 -0
  115. package/v1/examples/inferred-typing/run.d.ts +1 -0
  116. package/v1/examples/inferred-typing/run.js +41 -0
  117. package/v1/examples/inferred-typing/worker.d.ts +1 -0
  118. package/v1/examples/inferred-typing/worker.js +24 -0
  119. package/v1/examples/inferred-typing/workflow.d.ts +15 -0
  120. package/v1/examples/inferred-typing/workflow.js +44 -0
  121. package/v1/examples/landing_page/durable-excution.d.ts +3 -0
  122. package/v1/examples/landing_page/durable-excution.js +40 -0
  123. package/v1/examples/landing_page/event-signaling.d.ts +6 -0
  124. package/v1/examples/landing_page/event-signaling.js +16 -0
  125. package/v1/examples/landing_page/flow-control.d.ts +6 -0
  126. package/v1/examples/landing_page/flow-control.js +26 -0
  127. package/v1/examples/landing_page/queues.d.ts +3 -0
  128. package/v1/examples/landing_page/queues.js +33 -0
  129. package/v1/examples/landing_page/scheduling.d.ts +1 -0
  130. package/v1/examples/landing_page/scheduling.js +12 -0
  131. package/v1/examples/landing_page/task-routing.d.ts +6 -0
  132. package/v1/examples/landing_page/task-routing.js +25 -0
  133. package/v1/examples/legacy/run.js +2 -2
  134. package/v1/examples/legacy/worker.js +2 -2
  135. package/v1/examples/on_cron/worker.d.ts +1 -0
  136. package/v1/examples/on_cron/worker.js +24 -0
  137. package/v1/examples/on_cron/workflow.d.ts +10 -0
  138. package/v1/examples/on_cron/workflow.js +21 -0
  139. package/v1/examples/on_event/event.js +3 -2
  140. package/v1/examples/on_event/worker.js +2 -2
  141. package/v1/examples/on_event/workflow.d.ts +4 -4
  142. package/v1/examples/on_event/workflow.js +6 -3
  143. package/v1/examples/on_event copy/event.d.ts +1 -0
  144. package/v1/examples/on_event copy/event.js +26 -0
  145. package/v1/examples/on_event copy/worker.d.ts +1 -0
  146. package/v1/examples/on_event copy/worker.js +24 -0
  147. package/v1/examples/on_event copy/workflow.d.ts +16 -0
  148. package/v1/examples/on_event copy/workflow.js +35 -0
  149. package/v1/examples/on_failure/worker.js +2 -2
  150. package/v1/examples/on_failure/workflow.d.ts +1 -1
  151. package/v1/examples/on_failure/workflow.js +18 -8
  152. package/v1/examples/on_success/run.d.ts +1 -0
  153. package/v1/examples/on_success/run.js +31 -0
  154. package/v1/examples/on_success/worker.d.ts +1 -0
  155. package/v1/examples/on_success/worker.js +24 -0
  156. package/v1/examples/on_success/workflow.d.ts +4 -0
  157. package/v1/examples/on_success/workflow.js +59 -0
  158. package/v1/examples/retries/run.d.ts +1 -0
  159. package/v1/examples/retries/run.js +29 -0
  160. package/v1/examples/retries/worker.d.ts +1 -0
  161. package/v1/examples/retries/worker.js +24 -0
  162. package/v1/examples/retries/workflow.d.ts +5 -0
  163. package/v1/examples/retries/workflow.js +53 -0
  164. package/v1/examples/simple/client-run.d.ts +1 -0
  165. package/v1/examples/simple/client-run.js +16 -0
  166. package/v1/examples/simple/cron.js +6 -2
  167. package/v1/examples/simple/delay.js +2 -2
  168. package/v1/examples/simple/enqueue.d.ts +1 -0
  169. package/v1/examples/simple/enqueue.js +43 -0
  170. package/v1/examples/simple/run.js +8 -3
  171. package/v1/examples/simple/schedule.js +11 -5
  172. package/v1/examples/simple/stub-workflow.d.ts +9 -0
  173. package/v1/examples/simple/stub-workflow.js +17 -0
  174. package/v1/examples/simple/worker.js +7 -2
  175. package/v1/examples/simple/workflow.d.ts +4 -3
  176. package/v1/examples/simple/workflow.js +5 -5
  177. package/v1/examples/sticky/run.d.ts +1 -0
  178. package/v1/examples/sticky/run.js +29 -0
  179. package/v1/examples/sticky/worker.d.ts +1 -0
  180. package/v1/examples/sticky/worker.js +24 -0
  181. package/v1/examples/sticky/workflow.d.ts +7 -0
  182. package/v1/examples/sticky/workflow.js +32 -0
  183. package/v1/examples/with_timeouts/workflow.d.ts +9 -0
  184. package/v1/examples/with_timeouts/workflow.js +62 -0
  185. package/v1/index.d.ts +5 -0
  186. package/v1/index.js +20 -0
  187. package/v1/task.d.ts +144 -14
  188. package/version.d.ts +1 -1
  189. package/version.js +1 -1
  190. package/v1/workflow.d.ts +0 -158
  191. package/v1/workflow.js +0 -145
  192. /package/{examples/playground.d.ts → v1/examples/dag_match_condition/event.d.ts} +0 -0
  193. /package/v1/examples/{client.d.ts → hatchet-client.d.ts} +0 -0
  194. /package/v1/examples/{client.js → hatchet-client.js} +0 -0
@@ -0,0 +1,40 @@
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 @typescript-eslint/no-unused-vars */
13
+ const conditions_1 = require("../../conditions");
14
+ const hatchet_client_1 = require("../hatchet-client");
15
+ function main() {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ // ❓ Declaring a Durable Task
18
+ const simple = hatchet_client_1.hatchet.durableTask({
19
+ name: 'simple',
20
+ fn: (input, ctx) => __awaiter(this, void 0, void 0, function* () {
21
+ yield ctx.waitFor((0, conditions_1.Or)({
22
+ eventKey: 'user:pay',
23
+ expression: 'input.Status == "PAID"',
24
+ }, {
25
+ sleepFor: '24h',
26
+ }));
27
+ return {
28
+ TransformedMessage: input.Message.toLowerCase(),
29
+ };
30
+ }),
31
+ });
32
+ // !!
33
+ // ❓ Running a Task
34
+ const result = yield simple.run({ Message: 'Hello, World!' });
35
+ // !!
36
+ });
37
+ }
38
+ if (require.main === module) {
39
+ main();
40
+ }
@@ -0,0 +1,6 @@
1
+ export type SimpleInput = {
2
+ Message: string;
3
+ };
4
+ export declare const simple: import("../..").TaskWorkflowDeclaration<SimpleInput, {
5
+ TransformedMessage: string;
6
+ }>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simple = void 0;
4
+ const hatchet_client_1 = require("../hatchet-client");
5
+ // ❓ Trigger on an event
6
+ exports.simple = hatchet_client_1.hatchet.task({
7
+ name: 'simple',
8
+ onEvents: ['user:created'],
9
+ fn: (input) => {
10
+ // ...
11
+ return {
12
+ TransformedMessage: input.Message.toLowerCase(),
13
+ };
14
+ },
15
+ });
16
+ // !!
@@ -0,0 +1,6 @@
1
+ export type SimpleInput = {
2
+ Message: string;
3
+ };
4
+ export declare const simple: import("../..").TaskWorkflowDeclaration<SimpleInput, {
5
+ TransformedMessage: string;
6
+ }>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simple = void 0;
4
+ const workflows_1 = require("../../../protoc/v1/workflows");
5
+ const hatchet_client_1 = require("../hatchet-client");
6
+ // ❓ Process what you can handle
7
+ exports.simple = hatchet_client_1.hatchet.task({
8
+ name: 'simple',
9
+ concurrency: {
10
+ expression: 'input.user_id',
11
+ limitStrategy: workflows_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
12
+ maxRuns: 1,
13
+ },
14
+ rateLimits: [
15
+ {
16
+ key: 'api_throttle',
17
+ units: 1,
18
+ },
19
+ ],
20
+ fn: (input) => {
21
+ return {
22
+ TransformedMessage: input.Message.toLowerCase(),
23
+ };
24
+ },
25
+ });
26
+ // !!
@@ -0,0 +1,3 @@
1
+ export type SimpleInput = {
2
+ Message: string;
3
+ };
@@ -0,0 +1,33 @@
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 @typescript-eslint/no-unused-vars */
13
+ const hatchet_client_1 = require("../hatchet-client");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ // ❓ Declaring a Task
17
+ const simple = hatchet_client_1.hatchet.task({
18
+ name: 'simple',
19
+ fn: (input) => {
20
+ return {
21
+ TransformedMessage: input.Message.toLowerCase(),
22
+ };
23
+ },
24
+ });
25
+ // !!
26
+ // ❓ Running a Task
27
+ const result = yield simple.run({ Message: 'Hello, World!' });
28
+ // !!
29
+ });
30
+ }
31
+ if (require.main === module) {
32
+ main();
33
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const flow_control_1 = require("./flow-control");
4
+ // ❓ Schedules and Crons
5
+ const tomorrow = new Date(Date.now() + 1000 * 60 * 60 * 24);
6
+ const scheduled = flow_control_1.simple.schedule(tomorrow, {
7
+ Message: 'Hello, World!',
8
+ });
9
+ const cron = flow_control_1.simple.cron('every-day', '0 0 * * *', {
10
+ Message: 'Hello, World!',
11
+ });
12
+ // !!
@@ -0,0 +1,6 @@
1
+ export type SimpleInput = {
2
+ Message: string;
3
+ };
4
+ export declare const simple: import("../..").TaskWorkflowDeclaration<SimpleInput, {
5
+ TransformedMessage: string;
6
+ }>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simple = void 0;
4
+ const hatchet_client_1 = require("../hatchet-client");
5
+ // ❓ Route tasks to workers with matching labels
6
+ exports.simple = hatchet_client_1.hatchet.task({
7
+ name: 'simple',
8
+ desiredWorkerLabels: {
9
+ cpu: {
10
+ value: '2x',
11
+ },
12
+ },
13
+ fn: (input) => {
14
+ return {
15
+ TransformedMessage: input.Message.toLowerCase(),
16
+ };
17
+ },
18
+ });
19
+ hatchet_client_1.hatchet.worker('task-routing-worker', {
20
+ workflows: [exports.simple],
21
+ labels: {
22
+ cpu: process.env.CPU_LABEL,
23
+ },
24
+ });
25
+ // !!
@@ -9,11 +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
- const client_1 = require("../client");
12
+ const hatchet_client_1 = require("../hatchet-client");
13
13
  const workflow_1 = require("./workflow");
14
14
  function main() {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
- const res = yield client_1.hatchet.run(workflow_1.simple, {
16
+ const res = yield hatchet_client_1.hatchet.run(workflow_1.simple, {
17
17
  Message: 'hello',
18
18
  });
19
19
  // eslint-disable-next-line no-console
@@ -9,11 +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
- const client_1 = require("../client");
12
+ const hatchet_client_1 = require("../hatchet-client");
13
13
  const workflow_1 = require("./workflow");
14
14
  function main() {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
- const worker = yield client_1.hatchet.worker('legacy-worker', {
16
+ const worker = yield hatchet_client_1.hatchet.worker('legacy-worker', {
17
17
  workflows: [workflow_1.simple],
18
18
  });
19
19
  yield worker.start();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
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('on-cron-worker', {
17
+ workflows: [workflow_1.onCron],
18
+ });
19
+ yield worker.start();
20
+ });
21
+ }
22
+ if (require.main === module) {
23
+ main();
24
+ }
@@ -0,0 +1,10 @@
1
+ export type Input = {
2
+ Message: string;
3
+ };
4
+ type OnCronOutput = {
5
+ job: {
6
+ TransformedMessage: string;
7
+ };
8
+ };
9
+ export declare const onCron: import("../..").WorkflowDeclaration<Input, OnCronOutput>;
10
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onCron = void 0;
4
+ const hatchet_client_1 = require("../hatchet-client");
5
+ // ❓ Run Workflow on Cron
6
+ exports.onCron = hatchet_client_1.hatchet.workflow({
7
+ name: 'on-cron-workflow',
8
+ on: {
9
+ // 👀 add a cron expression to run the workflow every 15 minutes
10
+ cron: '*/15 * * * *',
11
+ },
12
+ });
13
+ // !!
14
+ exports.onCron.task({
15
+ name: 'job',
16
+ fn: (input) => {
17
+ return {
18
+ TransformedMessage: input.Message.toLowerCase(),
19
+ };
20
+ },
21
+ });
@@ -9,13 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const client_1 = require("../client");
12
+ const hatchet_client_1 = require("../hatchet-client");
13
13
  const workflow_1 = require("./workflow");
14
14
  function main() {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
- const res = yield client_1.hatchet.event.push(workflow_1.SIMPLE_EVENT, {
16
+ const res = yield hatchet_client_1.hatchet.events.push(workflow_1.SIMPLE_EVENT, {
17
17
  Message: 'hello',
18
18
  });
19
+ // !!
19
20
  // eslint-disable-next-line no-console
20
21
  console.log(res.eventId);
21
22
  });
@@ -9,11 +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
- const client_1 = require("../client");
12
+ const hatchet_client_1 = require("../hatchet-client");
13
13
  const workflow_1 = require("./workflow");
14
14
  function main() {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
- const worker = yield client_1.hatchet.worker('on-event-worker', {
16
+ const worker = yield hatchet_client_1.hatchet.worker('on-event-worker', {
17
17
  workflows: [workflow_1.lower, workflow_1.upper],
18
18
  });
19
19
  yield worker.start();
@@ -1,17 +1,17 @@
1
- export declare const SIMPLE_EVENT = "simple-event:create";
2
- type Input = {
1
+ export type Input = {
3
2
  Message: string;
4
3
  };
4
+ export declare const SIMPLE_EVENT = "simple-event:create";
5
5
  type LowerOutput = {
6
6
  lower: {
7
7
  TransformedMessage: string;
8
8
  };
9
9
  };
10
- export declare const lower: import("../../workflow").WorkflowDeclaration<Input, LowerOutput>;
10
+ export declare const lower: import("../..").WorkflowDeclaration<Input, LowerOutput>;
11
11
  type UpperOutput = {
12
12
  upper: {
13
13
  TransformedMessage: string;
14
14
  };
15
15
  };
16
- export declare const upper: import("../../workflow").WorkflowDeclaration<Input, UpperOutput>;
16
+ export declare const upper: import("../..").WorkflowDeclaration<Input, UpperOutput>;
17
17
  export {};
@@ -1,14 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.upper = exports.lower = exports.SIMPLE_EVENT = void 0;
4
- const client_1 = require("../client");
4
+ const hatchet_client_1 = require("../hatchet-client");
5
5
  exports.SIMPLE_EVENT = 'simple-event:create';
6
- exports.lower = client_1.hatchet.workflow({
6
+ // Run workflow on event
7
+ exports.lower = hatchet_client_1.hatchet.workflow({
7
8
  name: 'lower',
8
9
  on: {
10
+ // 👀 Declare the event that will trigger the workflow
9
11
  event: exports.SIMPLE_EVENT,
10
12
  },
11
13
  });
14
+ // !!
12
15
  exports.lower.task({
13
16
  name: 'lower',
14
17
  fn: (input) => {
@@ -17,7 +20,7 @@ exports.lower.task({
17
20
  };
18
21
  },
19
22
  });
20
- exports.upper = client_1.hatchet.workflow({
23
+ exports.upper = hatchet_client_1.hatchet.workflow({
21
24
  name: 'upper',
22
25
  on: {
23
26
  event: exports.SIMPLE_EVENT,
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
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
+ function main() {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ // ❓ Pushing an Event
16
+ const res = yield hatchet_client_1.hatchet.event.push('simple-event:create', {
17
+ Message: 'hello',
18
+ });
19
+ // !!
20
+ // eslint-disable-next-line no-console
21
+ console.log(res.eventId);
22
+ });
23
+ }
24
+ if (require.main === module) {
25
+ main();
26
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
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('on-event-worker', {
17
+ workflows: [workflow_1.lower, workflow_1.upper],
18
+ });
19
+ yield worker.start();
20
+ });
21
+ }
22
+ if (require.main === module) {
23
+ main();
24
+ }
@@ -0,0 +1,16 @@
1
+ export type Input = {
2
+ Message: string;
3
+ };
4
+ type LowerOutput = {
5
+ lower: {
6
+ TransformedMessage: string;
7
+ };
8
+ };
9
+ export declare const lower: import("../..").WorkflowDeclaration<Input, LowerOutput>;
10
+ type UpperOutput = {
11
+ upper: {
12
+ TransformedMessage: string;
13
+ };
14
+ };
15
+ export declare const upper: import("../..").WorkflowDeclaration<Input, UpperOutput>;
16
+ export {};
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.upper = exports.lower = void 0;
4
+ const hatchet_client_1 = require("../hatchet-client");
5
+ // ❓ Run workflow on event
6
+ exports.lower = hatchet_client_1.hatchet.workflow({
7
+ name: 'lower',
8
+ on: {
9
+ // 👀 Declare the event that will trigger the workflow
10
+ event: 'simple-event:create',
11
+ },
12
+ });
13
+ // !!
14
+ exports.lower.task({
15
+ name: 'lower',
16
+ fn: (input) => {
17
+ return {
18
+ TransformedMessage: input.Message.toLowerCase(),
19
+ };
20
+ },
21
+ });
22
+ exports.upper = hatchet_client_1.hatchet.workflow({
23
+ name: 'upper',
24
+ on: {
25
+ event: 'simple-event:create',
26
+ },
27
+ });
28
+ exports.upper.task({
29
+ name: 'upper',
30
+ fn: (input) => {
31
+ return {
32
+ TransformedMessage: input.Message.toUpperCase(),
33
+ };
34
+ },
35
+ });
@@ -9,11 +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
- const client_1 = require("../client");
12
+ const hatchet_client_1 = require("../hatchet-client");
13
13
  const workflow_1 = require("./workflow");
14
14
  function main() {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
- const worker = yield client_1.hatchet.worker('always-fail-worker', {
16
+ const worker = yield hatchet_client_1.hatchet.worker('always-fail-worker', {
17
17
  workflows: [workflow_1.alwaysFail],
18
18
  });
19
19
  yield worker.start();
@@ -1 +1 @@
1
- export declare const alwaysFail: import("../../workflow").WorkflowDeclaration<any, any>;
1
+ export declare const alwaysFail: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, never>;
@@ -1,20 +1,30 @@
1
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.alwaysFail = void 0;
4
13
  /* eslint-disable no-console */
5
- const client_1 = require("../client");
6
- exports.alwaysFail = client_1.hatchet.workflow({
14
+ const hatchet_client_1 = require("../hatchet-client");
15
+ // On Failure Task
16
+ exports.alwaysFail = hatchet_client_1.hatchet.task({
7
17
  name: 'always-fail',
8
- onFailure: (ctx) => {
18
+ // the onFailure function is called when the task fails
19
+ // note: not guaranteed to be called on the same worker
20
+ onFailure: (input, ctx) => {
9
21
  console.log('onFailure for run:', ctx.workflowRunId());
10
22
  return {
11
23
  'on-failure': 'success',
12
24
  };
13
25
  },
14
- });
15
- exports.alwaysFail.task({
16
- name: 'always-fail',
17
- fn: () => {
26
+ fn: () => __awaiter(void 0, void 0, void 0, function* () {
18
27
  throw new Error('intentional failure');
19
- },
28
+ }),
20
29
  });
30
+ // !!
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
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
+ const res = yield workflow_1.onSuccess.run({});
18
+ console.log(res);
19
+ const res2 = yield workflow_1.onSuccessDag.run({});
20
+ console.log(res2);
21
+ }
22
+ catch (e) {
23
+ console.log('error', e);
24
+ }
25
+ });
26
+ }
27
+ if (require.main === module) {
28
+ main()
29
+ .catch(console.error)
30
+ .finally(() => process.exit(0));
31
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
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('always-succeed-worker', {
17
+ workflows: [workflow_1.onSuccessDag, workflow_1.onSuccess],
18
+ });
19
+ yield worker.start();
20
+ });
21
+ }
22
+ if (require.main === module) {
23
+ main();
24
+ }
@@ -0,0 +1,4 @@
1
+ export declare const onSuccess: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, {
2
+ 'always-succeed': string;
3
+ }>;
4
+ export declare const onSuccessDag: import("../..").WorkflowDeclaration<any, any>;