@hatchet-dev/typescript-sdk 1.0.6 → 1.1.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 (38) hide show
  1. package/README.md +109 -0
  2. package/clients/rest/generated/Api.js +1 -0
  3. package/clients/rest/generated/data-contracts.d.ts +2 -0
  4. package/clients/rest/generated/data-contracts.js +3 -0
  5. package/clients/rest/generated/http-client.js +1 -0
  6. package/clients/worker/worker.d.ts +1 -1
  7. package/clients/worker/worker.js +8 -5
  8. package/package.json +42 -38
  9. package/protoc/dispatcher/dispatcher.d.ts +2 -2
  10. package/protoc/dispatcher/dispatcher.js +20 -2
  11. package/protoc/events/events.js +1 -1
  12. package/protoc/google/protobuf/timestamp.js +1 -1
  13. package/protoc/v1/dispatcher.js +1 -1
  14. package/protoc/v1/shared/condition.js +1 -1
  15. package/protoc/v1/workflows.js +1 -1
  16. package/protoc/workflows/workflows.js +1 -1
  17. package/step.js +59 -57
  18. package/util/workflow-run-ref.d.ts +1 -0
  19. package/util/workflow-run-ref.js +10 -2
  20. package/v1/client/client.d.ts +2 -2
  21. package/v1/declaration.d.ts +13 -5
  22. package/v1/declaration.js +28 -12
  23. package/v1/examples/dag/interface-workflow.d.ts +12 -0
  24. package/v1/examples/dag/interface-workflow.js +40 -0
  25. package/v1/examples/non_retryable/run.d.ts +1 -0
  26. package/v1/examples/non_retryable/run.js +22 -0
  27. package/v1/examples/non_retryable/worker.d.ts +1 -0
  28. package/v1/examples/non_retryable/worker.js +24 -0
  29. package/v1/examples/non_retryable/workflow.d.ts +1 -0
  30. package/v1/examples/non_retryable/workflow.js +29 -0
  31. package/v1/examples/simple/worker.js +2 -1
  32. package/v1/examples/simple/workflow-with-child.d.ts +12 -0
  33. package/v1/examples/simple/workflow-with-child.js +35 -0
  34. package/v1/task.d.ts +3 -0
  35. package/v1/task.js +9 -0
  36. package/v1/types.d.ts +6 -1
  37. package/version.d.ts +1 -1
  38. package/version.js +1 -1
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # Hatchet TypeScript SDK
2
+
3
+ <div align="center">
4
+
5
+ [![npm version](https://badge.fury.io/js/@hatchet-dev%2Ftypescript-sdk.svg)](https://badge.fury.io/js/@hatchet-dev%2Ftypescript-sdk)
6
+ [![Documentation](https://img.shields.io/badge/docs-hatchet.run-blue)](https://docs.hatchet.run)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-purple.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ </div>
10
+
11
+ This is the official TypeScript SDK for [Hatchet](https://hatchet.run), a distributed, fault-tolerant task queue. The SDK provides a type-safe way to integrate Hatchet's task scheduling and workflow orchestration capabilities into your TypeScript/JavaScript applications.
12
+
13
+ ## Installation
14
+
15
+ Install the SDK using npm:
16
+
17
+ ```bash
18
+ npm install @hatchet-dev/typescript-sdk
19
+ ```
20
+
21
+ Using yarn:
22
+
23
+ ```bash
24
+ yarn add @hatchet-dev/typescript-sdk
25
+ ```
26
+
27
+ Using pnpm:
28
+
29
+ ```bash
30
+ pnpm add @hatchet-dev/typescript-sdk
31
+ ```
32
+
33
+ ## Quick Start
34
+
35
+ Here's a simple example of how to use the Hatchet TypeScript SDK:
36
+
37
+ ```typescript
38
+ import { HatchetClient } from '@hatchet-dev/typescript-sdk';
39
+
40
+ export const hatchet = HatchetClient.init();
41
+
42
+ export type SimpleInput = {
43
+ Message: string;
44
+ };
45
+
46
+ export const simple = hatchet.task({
47
+ name: 'simple',
48
+ fn: (input: SimpleInput) => {
49
+ return {
50
+ TransformedMessage: input.Message.toLowerCase(),
51
+ };
52
+ },
53
+ });
54
+
55
+ async function main() {
56
+ const worker = await hatchet.worker('simple-worker', {
57
+ workflows: [simple],
58
+ slots: 100,
59
+ });
60
+
61
+ await worker.start();
62
+ }
63
+
64
+ if (require.main === module) {
65
+ main();
66
+ }
67
+ ```
68
+
69
+ ## Features
70
+
71
+ - 📝 **Type Safety**: Full TypeScript support with type inference for workflow inputs and outputs
72
+ - 🔄 **Workflow Orchestration**: Define complex workflows with dependencies and parallel execution
73
+ - 🔁 **Automatic Retries**: Configure retry policies for handling transient failures
74
+ - 📊 **Observability**: Track workflow progress and monitor execution metrics
75
+ - ⏰ **Scheduling**: Schedule workflows to run at specific times or on a recurring basis
76
+ - 🔄 **Event-Driven**: Trigger workflows based on events in your system
77
+
78
+ ## Documentation
79
+
80
+ For detailed documentation, examples, and best practices, visit:
81
+ - [Hatchet Documentation](https://docs.hatchet.run)
82
+ - [Examples](https://github.com/hatchet-dev/hatchet/tree/main/sdks/typescript/src/v1/examples)
83
+
84
+ ## Development
85
+
86
+ We use `pnpm` as our package manager. To get started with development:
87
+
88
+ 1. Install dependencies:
89
+ ```bash
90
+ pnpm install
91
+ ```
92
+
93
+ 2. Build the SDK:
94
+ ```bash
95
+ pnpm build
96
+ ```
97
+
98
+ 3. Run tests:
99
+ ```bash
100
+ pnpm test
101
+ ```
102
+
103
+ ## Contributing
104
+
105
+ We welcome contributions! Please check out our [contributing guidelines](https://docs.hatchet.run/contributing) and join our [Discord community](https://discord.gg/ZMeUafwH89) for discussions and support.
106
+
107
+ ## License
108
+
109
+ This SDK is released under the MIT License. See [LICENSE](https://github.com/hatchet-dev/hatchet/blob/main/LICENSE) for details.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
3
  /* tslint:disable */
4
+ // @ts-nocheck
4
5
  /*
5
6
  * ---------------------------------------------------------------
6
7
  * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
@@ -212,8 +212,10 @@ export declare enum TenantMemberRole {
212
212
  }
213
213
  export declare enum TenantResource {
214
214
  WORKER = "WORKER",
215
+ WORKER_SLOT = "WORKER_SLOT",
215
216
  EVENT = "EVENT",
216
217
  WORKFLOW_RUN = "WORKFLOW_RUN",
218
+ TASK_RUN = "TASK_RUN",
217
219
  CRON = "CRON",
218
220
  SCHEDULE = "SCHEDULE"
219
221
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
3
  /* tslint:disable */
4
+ // @ts-nocheck
4
5
  /*
5
6
  * ---------------------------------------------------------------
6
7
  * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
@@ -20,8 +21,10 @@ var TenantMemberRole;
20
21
  var TenantResource;
21
22
  (function (TenantResource) {
22
23
  TenantResource["WORKER"] = "WORKER";
24
+ TenantResource["WORKER_SLOT"] = "WORKER_SLOT";
23
25
  TenantResource["EVENT"] = "EVENT";
24
26
  TenantResource["WORKFLOW_RUN"] = "WORKFLOW_RUN";
27
+ TenantResource["TASK_RUN"] = "TASK_RUN";
25
28
  TenantResource["CRON"] = "CRON";
26
29
  TenantResource["SCHEDULE"] = "SCHEDULE";
27
30
  })(TenantResource || (exports.TenantResource = TenantResource = {}));
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  /* eslint-disable */
3
3
  /* tslint:disable */
4
+ // @ts-nocheck
4
5
  /*
5
6
  * ---------------------------------------------------------------
6
7
  * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
@@ -51,7 +51,7 @@ export declare class V0Worker {
51
51
  registerAction<T, K>(actionId: string, action: StepRunFunction<T, K>): void;
52
52
  handleStartStepRun(action: Action): Promise<void>;
53
53
  handleStartGroupKeyRun(action: Action): Promise<void>;
54
- getStepActionEvent(action: Action, eventType: StepActionEventType, payload?: any): StepActionEvent;
54
+ getStepActionEvent(action: Action, eventType: StepActionEventType, shouldNotRetry: boolean, payload?: any): StepActionEvent;
55
55
  getGroupKeyActionEvent(action: Action, eventType: GroupKeyActionEventType, payload?: any): GroupKeyActionEvent;
56
56
  handleCancelStepRun(action: Action): Promise<void>;
57
57
  stop(): Promise<void>;
@@ -25,6 +25,7 @@ const dispatcher_1 = require("../../protoc/dispatcher");
25
25
  const hatchet_promise_1 = __importDefault(require("../../util/hatchet-promise/hatchet-promise"));
26
26
  const workflows_1 = require("../../protoc/workflows");
27
27
  const handler_1 = require("./handler");
28
+ const task_1 = require("../../v1/task");
28
29
  const transformer_1 = require("../../v1/conditions/transformer");
29
30
  const step_1 = require("../../step");
30
31
  class V0Worker {
@@ -345,13 +346,13 @@ class V0Worker {
345
346
  this.logger.info(`Step run ${action.stepRunId} succeeded`);
346
347
  try {
347
348
  // Send the action event to the dispatcher
348
- const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, result || null);
349
+ const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, false, result || null);
349
350
  yield this.client.dispatcher.sendStepActionEvent(event);
350
351
  }
351
352
  catch (actionEventError) {
352
353
  this.logger.error(`Could not send completed action event: ${actionEventError.message || actionEventError}`);
353
354
  // send a failure event
354
- const failureEvent = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, actionEventError.message);
355
+ const failureEvent = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, false, actionEventError.message);
355
356
  try {
356
357
  yield this.client.dispatcher.sendStepActionEvent(failureEvent);
357
358
  }
@@ -371,9 +372,10 @@ class V0Worker {
371
372
  if (error.stack) {
372
373
  this.logger.error(error.stack);
373
374
  }
375
+ const shouldNotRetry = error instanceof task_1.NonRetryableError;
374
376
  try {
375
377
  // Send the action event to the dispatcher
376
- const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, {
378
+ const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, shouldNotRetry, {
377
379
  message: error === null || error === void 0 ? void 0 : error.message,
378
380
  stack: error === null || error === void 0 ? void 0 : error.stack,
379
381
  });
@@ -401,7 +403,7 @@ class V0Worker {
401
403
  }))());
402
404
  this.futures[action.stepRunId] = future;
403
405
  // Send the action event to the dispatcher
404
- const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_STARTED);
406
+ const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_STARTED, false);
405
407
  this.client.dispatcher.sendStepActionEvent(event).catch((e) => {
406
408
  this.logger.error(`Could not send action event: ${e.message}`);
407
409
  });
@@ -487,7 +489,7 @@ class V0Worker {
487
489
  }
488
490
  });
489
491
  }
490
- getStepActionEvent(action, eventType, payload = '') {
492
+ getStepActionEvent(action, eventType, shouldNotRetry, payload = '') {
491
493
  return {
492
494
  workerId: this.name,
493
495
  jobId: action.jobId,
@@ -498,6 +500,7 @@ class V0Worker {
498
500
  eventTimestamp: new Date(),
499
501
  eventType,
500
502
  eventPayload: JSON.stringify(payload),
503
+ shouldNotRetry,
501
504
  };
502
505
  }
503
506
  getGroupKeyActionEvent(action, eventType, payload = '') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -8,11 +8,12 @@
8
8
  "!**/*.test.js",
9
9
  "!**/*.test.d.ts",
10
10
  "!**/*.e2e.js",
11
- "!**/*.e2e.d.ts"
11
+ "!**/*.e2e.d.ts",
12
+ "README.md"
12
13
  ],
13
14
  "repository": {
14
15
  "type": "git",
15
- "url": "https://github.com/hatchet-dev/hatchet-typescript.git"
16
+ "url": "https://github.com/hatchet-dev/hatchet.git"
16
17
  },
17
18
  "scripts": {
18
19
  "build": "echo 'build hatchet sdk with `npm run tsc:build` to ensure it is not build during the publish step' && exit 0",
@@ -23,7 +24,7 @@
23
24
  "test:e2e": "jest --testMatch='**/*.e2e.ts'",
24
25
  "test:unit:watch": "jest --testMatch='**/*.test.ts' --watch",
25
26
  "generate": "pnpm run '/generate-.*/'",
26
- "generate-api": "npx --yes swagger-cli bundle ../../api-contracts/openapi/openapi.yaml --outfile openapi.yaml --type yaml && npx swagger-typescript-api -p openapi.yaml -o src/clients/rest/generated -n hatchet.ts --modular --axios",
27
+ "generate-api": "npx --yes swagger-cli bundle ../../api-contracts/openapi/openapi.yaml --outfile openapi.yaml --type yaml && npx swagger-typescript-api generate -p openapi.yaml -o src/clients/rest/generated -n hatchet.ts --modular --axios",
27
28
  "generate-protoc": "./generate-protoc.sh",
28
29
  "lint:check": "npm run eslint:check && npm run prettier:check",
29
30
  "lint:fix": "npm run eslint:fix && npm run prettier:fix",
@@ -60,8 +61,10 @@
60
61
  "worker:multi-workflow": "npm run exec -- ./src/examples/multi-workflow.ts",
61
62
  "worker:logger": "npm run exec -- ./src/examples/logger.ts",
62
63
  "worker:byo-logger": "npm run exec -- ./src/examples/byo-logger.ts",
64
+ "worker:no-retry": "npm run exec -- ./src/v1/examples/non_retryable/worker.ts",
65
+ "worker:no-retry:trigger": "npm run exec -- ./src/v1/examples/non_retryable/run.ts",
63
66
  "api": "npm run exec -- ./src/examples/api.ts",
64
- "prepublish": "cp package.json dist/package.json;",
67
+ "prepublish": "cp package.json dist/package.json; cp README.md dist/",
65
68
  "publish:ci": "rm -rf ./dist && npm run dump-version && npm run tsc:build && npm run prepublish && cd dist && npm publish --access public --no-git-checks",
66
69
  "publish:ci:alpha": "rm -rf ./dist && npm run dump-version && npm run tsc:build && npm run prepublish && cd dist && npm publish --access public --no-git-checks --tag alpha",
67
70
  "generate-docs": "typedoc"
@@ -71,49 +74,50 @@
71
74
  "license": "MIT",
72
75
  "devDependencies": {
73
76
  "@tsd/typescript": "^5.8.2",
77
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
78
+ "@typescript-eslint/parser": "^6.21.0",
74
79
  "@types/jest": "^29.5.14",
75
- "@types/node": "^22.0.0",
76
- "@typescript-eslint/eslint-plugin": "^6.4.0",
77
- "autoprefixer": "^10.4.16",
78
- "dotenv-cli": "^7.3.0",
80
+ "@types/node": "^22.13.14",
81
+ "autoprefixer": "^10.4.21",
82
+ "dotenv-cli": "^7.4.4",
79
83
  "eslint": "^8.56.0",
80
- "eslint-config-airbnb-typescript": "^18.0.0",
84
+ "eslint-config-airbnb-typescript": "^17.1.0",
81
85
  "eslint-config-prettier": "^9.1.0",
82
- "eslint-config-standard-with-typescript": "^43.0.0",
83
- "eslint-import-resolver-typescript": "^3.6.1",
84
- "eslint-plugin-import": "^2.29.1",
85
- "eslint-plugin-jest": "^28.5.0",
86
- "eslint-plugin-n": "^15.0.0 || ^16.0.0 ",
87
- "eslint-plugin-prettier": "^5.0.1",
88
- "eslint-plugin-promise": "^6.0.0",
89
- "eslint-plugin-react": "^7.34.1",
90
- "eslint-plugin-react-hooks": "^4.6.0",
91
- "eslint-plugin-react-refresh": "^0.4.6",
92
- "eslint-plugin-unused-imports": "^4.1.3",
93
- "grpc-tools": "^1.12.4",
86
+ "eslint-config-standard": "^17.1.0",
87
+ "eslint-import-resolver-typescript": "^3.10.0",
88
+ "eslint-plugin-import": "^2.31.0",
89
+ "eslint-plugin-jest": "^28.11.0",
90
+ "eslint-plugin-n": "^16.6.2",
91
+ "eslint-plugin-prettier": "^5.2.5",
92
+ "eslint-plugin-promise": "^6.6.0",
93
+ "eslint-plugin-react": "^7.37.4",
94
+ "eslint-plugin-react-hooks": "^4.6.2",
95
+ "eslint-plugin-react-refresh": "^0.4.19",
96
+ "eslint-plugin-unused-imports": "^4.1.4",
97
+ "grpc-tools": "^1.13.0",
94
98
  "jest": "^29.7.0",
95
99
  "jest-tsd": "^0.2.2",
96
100
  "pino": "^9.6.0",
97
- "prettier": "^3.1.1",
98
- "resolve-tspaths": "^0.8.17",
99
- "ts-jest": "^29.1.1",
101
+ "prettier": "^3.5.3",
102
+ "resolve-tspaths": "^0.8.23",
103
+ "ts-jest": "^29.3.1",
100
104
  "ts-node": "^10.9.2",
101
- "ts-proto": "^2.0.2",
102
- "typedoc": "^0.27.1",
103
- "typedoc-plugin-markdown": "^4.0.2",
104
- "typescript": "^5.3.3"
105
+ "ts-proto": "^2.7.0",
106
+ "typedoc": "^0.28.0",
107
+ "typedoc-plugin-markdown": "^4.6.0",
108
+ "typescript": "^5.8.2"
105
109
  },
106
110
  "dependencies": {
107
- "@bufbuild/protobuf": "^2.1.0",
108
- "@types/qs": "^6.9.11",
111
+ "@bufbuild/protobuf": "^2.2.5",
112
+ "@types/qs": "^6.9.18",
109
113
  "abort-controller-x": "^0.4.3",
110
- "axios": "^1.6.7",
111
- "long": "^5.2.3",
112
- "nice-grpc": "^2.1.7",
114
+ "axios": "^1.8.4",
115
+ "long": "^5.3.1",
116
+ "nice-grpc": "^2.1.12",
113
117
  "nice-grpc-common": "^2.0.2",
114
- "protobufjs": "^7.2.6",
115
- "qs": "^6.11.2",
116
- "yaml": "^2.3.4",
117
- "zod": "^3.22.4"
118
+ "protobufjs": "^7.4.0",
119
+ "qs": "^6.14.0",
120
+ "yaml": "^2.7.1",
121
+ "zod": "^3.24.2"
118
122
  }
119
123
  }
@@ -130,8 +130,6 @@ export interface AssignedAction {
130
130
  workflowRunId: string;
131
131
  /** the get group key run id (optional) */
132
132
  getGroupKeyRunId: string;
133
- /** task id */
134
- taskId?: number;
135
133
  /** the job id */
136
134
  jobId: string;
137
135
  /** the job name */
@@ -209,6 +207,8 @@ export interface StepActionEvent {
209
207
  eventPayload: string;
210
208
  /** the retry count */
211
209
  retryCount?: number | undefined;
210
+ /** a flag indicating if the task should _not_ be retried */
211
+ shouldNotRetry?: boolean | undefined;
212
212
  }
213
213
  export interface ActionEventResponse {
214
214
  /** the tenant id */
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.6.1
4
+ // protoc-gen-ts_proto v2.7.0
5
5
  // protoc v3.19.1
6
6
  // source: dispatcher/dispatcher.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1737,6 +1737,7 @@ function createBaseStepActionEvent() {
1737
1737
  eventType: 0,
1738
1738
  eventPayload: '',
1739
1739
  retryCount: undefined,
1740
+ shouldNotRetry: undefined,
1740
1741
  };
1741
1742
  }
1742
1743
  exports.StepActionEvent = {
@@ -1771,6 +1772,9 @@ exports.StepActionEvent = {
1771
1772
  if (message.retryCount !== undefined) {
1772
1773
  writer.uint32(80).int32(message.retryCount);
1773
1774
  }
1775
+ if (message.shouldNotRetry !== undefined) {
1776
+ writer.uint32(88).bool(message.shouldNotRetry);
1777
+ }
1774
1778
  return writer;
1775
1779
  },
1776
1780
  decode(input, length) {
@@ -1850,6 +1854,13 @@ exports.StepActionEvent = {
1850
1854
  message.retryCount = reader.int32();
1851
1855
  continue;
1852
1856
  }
1857
+ case 11: {
1858
+ if (tag !== 88) {
1859
+ break;
1860
+ }
1861
+ message.shouldNotRetry = reader.bool();
1862
+ continue;
1863
+ }
1853
1864
  }
1854
1865
  if ((tag & 7) === 4 || tag === 0) {
1855
1866
  break;
@@ -1872,6 +1883,9 @@ exports.StepActionEvent = {
1872
1883
  eventType: isSet(object.eventType) ? stepActionEventTypeFromJSON(object.eventType) : 0,
1873
1884
  eventPayload: isSet(object.eventPayload) ? globalThis.String(object.eventPayload) : '',
1874
1885
  retryCount: isSet(object.retryCount) ? globalThis.Number(object.retryCount) : undefined,
1886
+ shouldNotRetry: isSet(object.shouldNotRetry)
1887
+ ? globalThis.Boolean(object.shouldNotRetry)
1888
+ : undefined,
1875
1889
  };
1876
1890
  },
1877
1891
  toJSON(message) {
@@ -1906,13 +1920,16 @@ exports.StepActionEvent = {
1906
1920
  if (message.retryCount !== undefined) {
1907
1921
  obj.retryCount = Math.round(message.retryCount);
1908
1922
  }
1923
+ if (message.shouldNotRetry !== undefined) {
1924
+ obj.shouldNotRetry = message.shouldNotRetry;
1925
+ }
1909
1926
  return obj;
1910
1927
  },
1911
1928
  create(base) {
1912
1929
  return exports.StepActionEvent.fromPartial(base !== null && base !== void 0 ? base : {});
1913
1930
  },
1914
1931
  fromPartial(object) {
1915
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1932
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1916
1933
  const message = createBaseStepActionEvent();
1917
1934
  message.workerId = (_a = object.workerId) !== null && _a !== void 0 ? _a : '';
1918
1935
  message.jobId = (_b = object.jobId) !== null && _b !== void 0 ? _b : '';
@@ -1924,6 +1941,7 @@ exports.StepActionEvent = {
1924
1941
  message.eventType = (_h = object.eventType) !== null && _h !== void 0 ? _h : 0;
1925
1942
  message.eventPayload = (_j = object.eventPayload) !== null && _j !== void 0 ? _j : '';
1926
1943
  message.retryCount = (_k = object.retryCount) !== null && _k !== void 0 ? _k : undefined;
1944
+ message.shouldNotRetry = (_l = object.shouldNotRetry) !== null && _l !== void 0 ? _l : undefined;
1927
1945
  return message;
1928
1946
  },
1929
1947
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.6.1
4
+ // protoc-gen-ts_proto v2.7.0
5
5
  // protoc v3.19.1
6
6
  // source: events/events.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.6.1
4
+ // protoc-gen-ts_proto v2.7.0
5
5
  // protoc v3.19.1
6
6
  // source: google/protobuf/timestamp.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.6.1
4
+ // protoc-gen-ts_proto v2.7.0
5
5
  // protoc v3.19.1
6
6
  // source: v1/dispatcher.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.6.1
4
+ // protoc-gen-ts_proto v2.7.0
5
5
  // protoc v3.19.1
6
6
  // source: v1/shared/condition.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.6.1
4
+ // protoc-gen-ts_proto v2.7.0
5
5
  // protoc v3.19.1
6
6
  // source: v1/workflows.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.6.1
4
+ // protoc-gen-ts_proto v2.7.0
5
5
  // protoc v3.19.1
6
6
  // source: workflows/workflows.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
package/step.js CHANGED
@@ -47,6 +47,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
48
  exports.DurableContext = exports.Context = exports.ContextWorker = exports.CreateStepSchema = exports.DesiredWorkerLabelSchema = exports.CreateRateLimitSchema = void 0;
49
49
  exports.mapRateLimit = mapRateLimit;
50
+ /* eslint-disable no-underscore-dangle */
50
51
  /* eslint-disable max-classes-per-file */
51
52
  const hatchet_error_1 = __importDefault(require("./util/errors/hatchet-error"));
52
53
  const z = __importStar(require("zod"));
@@ -351,7 +352,9 @@ class Context {
351
352
  * @returns A list of workflow run references to the enqueued runs.
352
353
  */
353
354
  bulkRunNoWaitChildren(children) {
354
- return this.spawnWorkflows(children);
355
+ return __awaiter(this, void 0, void 0, function* () {
356
+ return this.spawnWorkflows(children);
357
+ });
355
358
  }
356
359
  /**
357
360
  * Runs multiple children workflows in parallel and waits for all results.
@@ -361,15 +364,7 @@ class Context {
361
364
  bulkRunChildren(children) {
362
365
  return __awaiter(this, void 0, void 0, function* () {
363
366
  const runs = yield this.bulkRunNoWaitChildren(children);
364
- const res = runs.map((run, index) => __awaiter(this, void 0, void 0, function* () {
365
- const wf = children[index].workflow;
366
- if (wf instanceof declaration_1.TaskWorkflowDeclaration) {
367
- // eslint-disable-next-line no-underscore-dangle
368
- return (yield run.output)[wf._standalone_task_name];
369
- }
370
- return run.output;
371
- }));
372
- return Promise.all(res);
367
+ return Promise.all(runs.map((run) => run.output));
373
368
  });
374
369
  }
375
370
  /**
@@ -380,49 +375,60 @@ class Context {
380
375
  * @deprecated Use bulkRunNoWaitChildren or bulkRunChildren instead.
381
376
  */
382
377
  spawnWorkflows(workflows) {
383
- const { workflowRunId, stepRunId } = this.action;
384
- const workflowRuns = workflows.map(({ workflow, input, options }) => {
385
- let workflowName;
386
- if (typeof workflow === 'string') {
387
- workflowName = workflow;
388
- }
389
- else {
390
- workflowName = workflow.id;
391
- }
392
- const name = this.client.config.namespace + workflowName;
393
- let key;
394
- let sticky = false;
395
- let metadata;
396
- if (options) {
397
- key = options.key;
398
- sticky = options.sticky;
399
- metadata = options.additionalMetadata;
378
+ return __awaiter(this, void 0, void 0, function* () {
379
+ const { workflowRunId, stepRunId } = this.action;
380
+ const workflowRuns = workflows.map(({ workflow, input, options }) => {
381
+ let workflowName;
382
+ if (typeof workflow === 'string') {
383
+ workflowName = workflow;
384
+ }
385
+ else {
386
+ workflowName = workflow.id;
387
+ }
388
+ const name = this.client.config.namespace + workflowName;
389
+ let key;
390
+ let sticky = false;
391
+ let metadata;
392
+ if (options) {
393
+ key = options.key;
394
+ sticky = options.sticky;
395
+ metadata = options.additionalMetadata;
396
+ }
397
+ if (sticky && !this.worker.hasWorkflow(name)) {
398
+ throw new hatchet_error_1.default(`Cannot run with sticky: workflow ${name} is not registered on the worker`);
399
+ }
400
+ const resp = {
401
+ workflowName: name,
402
+ input,
403
+ options: {
404
+ parentId: workflowRunId,
405
+ parentStepRunId: stepRunId,
406
+ childKey: key,
407
+ childIndex: this.spawnIndex,
408
+ desiredWorkerId: sticky ? this.worker.id() : undefined,
409
+ additionalMetadata: metadata,
410
+ },
411
+ };
412
+ this.spawnIndex += 1;
413
+ return resp;
414
+ });
415
+ try {
416
+ const resp = yield this.client.admin.runWorkflows(workflowRuns);
417
+ const res = [];
418
+ resp.forEach((ref, index) => {
419
+ const wf = workflows[index].workflow;
420
+ if (wf instanceof declaration_1.TaskWorkflowDeclaration) {
421
+ // eslint-disable-next-line no-param-reassign
422
+ ref._standalone_task_name = wf._standalone_task_name;
423
+ }
424
+ res.push(ref);
425
+ });
426
+ return resp;
400
427
  }
401
- if (sticky && !this.worker.hasWorkflow(name)) {
402
- throw new hatchet_error_1.default(`Cannot run with sticky: workflow ${name} is not registered on the worker`);
428
+ catch (e) {
429
+ throw new hatchet_error_1.default(e.message);
403
430
  }
404
- const resp = {
405
- workflowName: name,
406
- input,
407
- options: {
408
- parentId: workflowRunId,
409
- parentStepRunId: stepRunId,
410
- childKey: key,
411
- childIndex: this.spawnIndex,
412
- desiredWorkerId: sticky ? this.worker.id() : undefined,
413
- additionalMetadata: metadata,
414
- },
415
- };
416
- this.spawnIndex += 1;
417
- return resp;
418
431
  });
419
- try {
420
- const resp = this.client.admin.runWorkflows(workflowRuns);
421
- return resp;
422
- }
423
- catch (e) {
424
- throw new hatchet_error_1.default(e.message);
425
- }
426
432
  }
427
433
  /**
428
434
  * Runs a new workflow and waits for its result.
@@ -435,13 +441,6 @@ class Context {
435
441
  runChild(workflow, input, optionsOrKey) {
436
442
  return __awaiter(this, void 0, void 0, function* () {
437
443
  const run = yield this.spawnWorkflow(workflow, input, optionsOrKey);
438
- if (workflow instanceof declaration_1.TaskWorkflowDeclaration) {
439
- // eslint-disable-next-line no-underscore-dangle
440
- if (workflow._standalone_task_name) {
441
- // eslint-disable-next-line no-underscore-dangle
442
- return (yield run.output)[workflow._standalone_task_name];
443
- }
444
- }
445
444
  return run.output;
446
445
  });
447
446
  }
@@ -500,6 +499,9 @@ class Context {
500
499
  additionalMetadata: metadata,
501
500
  });
502
501
  this.spawnIndex += 1;
502
+ if (workflow instanceof declaration_1.TaskWorkflowDeclaration) {
503
+ resp._standalone_task_name = workflow._standalone_task_name;
504
+ }
503
505
  return resp;
504
506
  }
505
507
  catch (e) {
@@ -11,6 +11,7 @@ export default class WorkflowRunRef<T> {
11
11
  parentWorkflowRunId?: string;
12
12
  private client;
13
13
  private runs;
14
+ _standalone_task_name?: string;
14
15
  constructor(workflowRunId: string | Promise<string> | Promise<{
15
16
  workflowRunId: string;
16
17
  }>, client: RunListenerClient, runsClient?: RunsClient, parentWorkflowRunId?: string);
@@ -118,11 +118,19 @@ class WorkflowRunRef {
118
118
  outputs[readableStepName] = stepRun.output;
119
119
  }
120
120
  });
121
- resolve(outputs);
121
+ if (!this._standalone_task_name) {
122
+ resolve(outputs);
123
+ return;
124
+ }
125
+ resolve(outputs[this._standalone_task_name]);
122
126
  return;
123
127
  }
124
128
  const result = event.results.reduce((acc, r) => (Object.assign(Object.assign({}, acc), { [r.stepReadableId]: JSON.parse(r.output || '{}') })), {});
125
- resolve(result);
129
+ if (!this._standalone_task_name) {
130
+ resolve(result);
131
+ return;
132
+ }
133
+ resolve(result[this._standalone_task_name]);
126
134
  return;
127
135
  }
128
136
  }
@@ -12,7 +12,7 @@ import { WorkersClient } from './features/workers';
12
12
  import { WorkflowsClient } from './features/workflows';
13
13
  import { RunsClient } from './features/runs';
14
14
  import { CreateStandaloneDurableTaskOpts } from '../task';
15
- import { InputType, OutputType, UnknownInputType, WorkflowOutputType } from '../types';
15
+ import { InputType, OutputType, UnknownInputType, StrictWorkflowOutputType } from '../types';
16
16
  /**
17
17
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
18
18
  * It provides methods for creating and executing workflows, as well as managing workers.
@@ -52,7 +52,7 @@ export declare class HatchetClient implements IHatchetClient {
52
52
  * @returns A new Workflow instance
53
53
  * @note It is possible to create an orphaned workflow if no client is available using @hatchet/client CreateWorkflow
54
54
  */
55
- workflow<I extends InputType = UnknownInputType, O extends WorkflowOutputType = {}>(options: CreateWorkflowOpts): WorkflowDeclaration<I, O>;
55
+ workflow<I extends InputType = UnknownInputType, O extends StrictWorkflowOutputType = {}>(options: CreateWorkflowOpts): WorkflowDeclaration<I, O>;
56
56
  /**
57
57
  * Creates a new task workflow.
58
58
  * Types can be explicitly specified as generics or inferred from the function signature.
@@ -171,7 +171,7 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
171
171
  * @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
172
172
  * @throws Error if the workflow is not bound to a Hatchet client.
173
173
  */
174
- runNoWait(input: I, options?: RunOpts): WorkflowRunRef<O>;
174
+ runNoWait(input: I, options?: RunOpts, _standaloneTaskName?: string): WorkflowRunRef<O>;
175
175
  /**
176
176
  * @alias run
177
177
  * Triggers a workflow run and waits for the result.
@@ -181,8 +181,8 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
181
181
  * @param options - Configuration options for the workflow run
182
182
  * @returns A promise that resolves with the workflow result
183
183
  */
184
- runAndWait(input: I, options?: RunOpts): Promise<O>;
185
- runAndWait(input: I[], options?: RunOpts): Promise<O[]>;
184
+ runAndWait(input: I, options?: RunOpts, _standaloneTaskName?: string): Promise<O>;
185
+ runAndWait(input: I[], options?: RunOpts, _standaloneTaskName?: string): Promise<O[]>;
186
186
  /**
187
187
  * Executes the workflow with the given input and awaits the results.
188
188
  * @param input The input data for the workflow.
@@ -190,8 +190,8 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
190
190
  * @returns A promise that resolves with the workflow result.
191
191
  * @throws Error if the workflow is not bound to a Hatchet client.
192
192
  */
193
- run(input: I, options?: RunOpts): Promise<O>;
194
- run(input: I[], options?: RunOpts): Promise<O[]>;
193
+ run(input: I, options?: RunOpts, _standaloneTaskName?: string): Promise<O>;
194
+ run(input: I[], options?: RunOpts, _standaloneTaskName?: string): Promise<O[]>;
195
195
  /**
196
196
  * Schedules a workflow to run at a specific date and time in the future.
197
197
  * @param enqueueAt The date when the workflow should be triggered.
@@ -302,6 +302,14 @@ export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputT
302
302
  constructor(options: CreateTaskWorkflowOpts<I, O>, client?: IHatchetClient);
303
303
  run(input: I, options?: RunOpts): Promise<O>;
304
304
  run(input: I[], options?: RunOpts): Promise<O[]>;
305
+ /**
306
+ * Triggers a workflow run without waiting for completion.
307
+ * @param input The input data for the workflow.
308
+ * @param options Optional configuration for this workflow run.
309
+ * @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
310
+ * @throws Error if the workflow is not bound to a Hatchet client.
311
+ */
312
+ runNoWait(input: I, options?: RunOpts): WorkflowRunRef<O>;
305
313
  get taskDef(): CreateWorkflowTaskOpts<any, any>;
306
314
  }
307
315
  /**
package/v1/declaration.js CHANGED
@@ -36,33 +36,40 @@ class BaseWorkflowDeclaration {
36
36
  * @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
37
37
  * @throws Error if the workflow is not bound to a Hatchet client.
38
38
  */
39
- runNoWait(input, options) {
39
+ runNoWait(input, options, _standaloneTaskName) {
40
40
  if (!this.client) {
41
41
  throw UNBOUND_ERR;
42
42
  }
43
- return this.client._v0.admin.runWorkflow(this.name, input, options);
43
+ const res = this.client._v0.admin.runWorkflow(this.name, input, options);
44
+ if (_standaloneTaskName) {
45
+ res._standalone_task_name = _standaloneTaskName;
46
+ }
47
+ return res;
44
48
  }
45
- runAndWait(input, options) {
49
+ runAndWait(input, options, _standaloneTaskName) {
46
50
  return __awaiter(this, void 0, void 0, function* () {
47
51
  if (!this.client) {
48
52
  throw UNBOUND_ERR;
49
53
  }
50
54
  if (Array.isArray(input)) {
51
- return Promise.all(input.map((i) => this.runAndWait(i, options)));
55
+ return Promise.all(input.map((i) => this.runAndWait(i, options, _standaloneTaskName)));
52
56
  }
53
- return this.run(input, options);
57
+ return this.run(input, options, _standaloneTaskName);
54
58
  });
55
59
  }
56
- run(input, options) {
60
+ run(input, options, _standaloneTaskName) {
57
61
  return __awaiter(this, void 0, void 0, function* () {
58
62
  if (!this.client) {
59
63
  throw UNBOUND_ERR;
60
64
  }
61
65
  if (Array.isArray(input)) {
62
66
  // FIXME use bulk endpoint?
63
- return Promise.all(input.map((i) => this.run(i, options)));
67
+ return Promise.all(input.map((i) => this.run(i, options, _standaloneTaskName)));
64
68
  }
65
69
  const res = this.client._v0.admin.runWorkflow(this.definition.name, input, options);
70
+ if (_standaloneTaskName) {
71
+ res._standalone_task_name = _standaloneTaskName;
72
+ }
66
73
  return res.result();
67
74
  });
68
75
  }
@@ -288,13 +295,22 @@ class TaskWorkflowDeclaration extends BaseWorkflowDeclaration {
288
295
  run: { get: () => super.run }
289
296
  });
290
297
  return __awaiter(this, void 0, void 0, function* () {
291
- const res = (yield _super.run.call(this, input, options));
292
- if (Array.isArray(res)) {
293
- return res.map((r) => r[this._standalone_task_name]);
294
- }
295
- return res[this._standalone_task_name];
298
+ return (yield _super.run.call(this, input, options, this._standalone_task_name));
296
299
  });
297
300
  }
301
+ /**
302
+ * Triggers a workflow run without waiting for completion.
303
+ * @param input The input data for the workflow.
304
+ * @param options Optional configuration for this workflow run.
305
+ * @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
306
+ * @throws Error if the workflow is not bound to a Hatchet client.
307
+ */
308
+ runNoWait(input, options) {
309
+ if (!this.client) {
310
+ throw UNBOUND_ERR;
311
+ }
312
+ return super.runNoWait(input, options, this._standalone_task_name);
313
+ }
298
314
  get taskDef() {
299
315
  return this.definition._tasks[0];
300
316
  }
@@ -0,0 +1,12 @@
1
+ import { WorkflowInputType, WorkflowOutputType } from '../..';
2
+ interface DagInput extends WorkflowInputType {
3
+ Message: string;
4
+ }
5
+ interface DagOutput extends WorkflowOutputType {
6
+ reverse: {
7
+ Original: string;
8
+ Transformed: string;
9
+ };
10
+ }
11
+ export declare const dag: import("../..").WorkflowDeclaration<DagInput, DagOutput>;
12
+ export {};
@@ -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
+ exports.dag = void 0;
13
+ const hatchet_client_1 = require("../hatchet-client");
14
+ // ❓ Declaring a DAG Workflow
15
+ // First, we declare the workflow
16
+ exports.dag = hatchet_client_1.hatchet.workflow({
17
+ name: 'simple',
18
+ });
19
+ const reverse = exports.dag.task({
20
+ name: 'reverse',
21
+ fn: (input) => {
22
+ return {
23
+ Original: input.Message,
24
+ Transformed: input.Message.split('').reverse().join(''),
25
+ };
26
+ },
27
+ });
28
+ exports.dag.task({
29
+ name: 'to-lower',
30
+ parents: [reverse],
31
+ fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
32
+ const r = yield ctx.parentOutput(reverse);
33
+ return {
34
+ reverse: {
35
+ Original: r.Transformed,
36
+ Transformed: r.Transformed.toLowerCase(),
37
+ },
38
+ };
39
+ }),
40
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
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 workflow_1 = require("./workflow");
13
+ function main() {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const res = yield workflow_1.nonRetryableWorkflow.runNoWait({});
16
+ // eslint-disable-next-line no-console
17
+ console.log(res);
18
+ });
19
+ }
20
+ if (require.main === module) {
21
+ main();
22
+ }
@@ -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('no-retry-worker', {
17
+ workflows: [workflow_1.nonRetryableWorkflow],
18
+ });
19
+ yield worker.start();
20
+ });
21
+ }
22
+ if (require.main === module) {
23
+ main();
24
+ }
@@ -0,0 +1 @@
1
+ export declare const nonRetryableWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nonRetryableWorkflow = void 0;
4
+ const task_1 = require("../../task");
5
+ const hatchet_client_1 = require("../hatchet-client");
6
+ exports.nonRetryableWorkflow = hatchet_client_1.hatchet.workflow({
7
+ name: 'no-retry-workflow',
8
+ });
9
+ // ❓ Non-retrying task
10
+ const shouldNotRetry = exports.nonRetryableWorkflow.task({
11
+ name: 'should-not-retry',
12
+ fn: () => {
13
+ throw new task_1.NonRetryableError('This task should not retry');
14
+ },
15
+ retries: 1,
16
+ });
17
+ // !!
18
+ // Create a task that should retry
19
+ const shouldRetryWrongErrorType = exports.nonRetryableWorkflow.task({
20
+ name: 'should-retry-wrong-error-type',
21
+ fn: () => {
22
+ throw new Error('This task should not retry');
23
+ },
24
+ retries: 1,
25
+ });
26
+ const shouldNotRetrySuccessfulTask = exports.nonRetryableWorkflow.task({
27
+ name: 'should-not-retry-successful-task',
28
+ fn: () => { },
29
+ });
@@ -12,11 +12,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  // ❓ Declaring a Worker
13
13
  const hatchet_client_1 = require("../hatchet-client");
14
14
  const workflow_1 = require("./workflow");
15
+ const workflow_with_child_1 = require("./workflow-with-child");
15
16
  function main() {
16
17
  return __awaiter(this, void 0, void 0, function* () {
17
18
  const worker = yield hatchet_client_1.hatchet.worker('simple-worker', {
18
19
  // 👀 Declare the workflows that the worker can execute
19
- workflows: [workflow_1.simple],
20
+ workflows: [workflow_1.simple, workflow_with_child_1.parent, workflow_with_child_1.child],
20
21
  // 👀 Declare the number of concurrent task runs the worker can accept
21
22
  slots: 100,
22
23
  });
@@ -0,0 +1,12 @@
1
+ export type ChildInput = {
2
+ Message: string;
3
+ };
4
+ export type ParentInput = {
5
+ Message: string;
6
+ };
7
+ export declare const child: import("../..").TaskWorkflowDeclaration<ChildInput, {
8
+ TransformedMessage: string;
9
+ }>;
10
+ export declare const parent: import("../..").TaskWorkflowDeclaration<ParentInput, {
11
+ TransformedMessage: string;
12
+ }>;
@@ -0,0 +1,35 @@
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.parent = exports.child = void 0;
13
+ // ❓ Declaring a Task
14
+ const hatchet_client_1 = require("../hatchet-client");
15
+ exports.child = hatchet_client_1.hatchet.task({
16
+ name: 'child',
17
+ fn: (input) => {
18
+ return {
19
+ TransformedMessage: input.Message.toLowerCase(),
20
+ };
21
+ },
22
+ });
23
+ exports.parent = hatchet_client_1.hatchet.task({
24
+ name: 'parent',
25
+ fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const c = yield ctx.runChild(exports.child, {
27
+ Message: input.Message,
28
+ });
29
+ return {
30
+ TransformedMessage: c.TransformedMessage,
31
+ };
32
+ }),
33
+ });
34
+ // !!
35
+ // see ./worker.ts and ./run.ts for how to run the workflow
package/v1/task.d.ts CHANGED
@@ -29,6 +29,9 @@ export type TaskConcurrency = {
29
29
  */
30
30
  limitStrategy?: ConcurrencyLimitStrategy;
31
31
  };
32
+ export declare class NonRetryableError extends Error {
33
+ constructor(message?: string);
34
+ }
32
35
  export type TaskFn<I extends InputType = UnknownInputType, O extends OutputType = void, C = Context<I>> = (input: I, ctx: C) => O | Promise<O>;
33
36
  export type DurableTaskFn<I extends InputType = UnknownInputType, O extends OutputType = void> = TaskFn<I, O, DurableContext<I>>;
34
37
  /**
package/v1/task.js CHANGED
@@ -1,2 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NonRetryableError = void 0;
4
+ class NonRetryableError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'NonRetryableError';
8
+ Object.setPrototypeOf(this, new.target.prototype);
9
+ }
10
+ }
11
+ exports.NonRetryableError = NonRetryableError;
package/v1/types.d.ts CHANGED
@@ -7,10 +7,15 @@ export type JsonObject = {
7
7
  [Key in string]?: JsonValue | undefined;
8
8
  };
9
9
  export type InputType = JsonObject;
10
+ export interface WorkflowInputType extends InputType {
11
+ }
10
12
  export type UnknownInputType = {};
11
13
  export type OutputType = JsonObject | void;
14
+ export interface WorkflowOutputType {
15
+ [key: string]: JsonObject;
16
+ }
12
17
  type IsValidWorkflowOutput<T> = T extends Record<string, JsonObject> ? true : false;
13
- export type WorkflowOutputType<T = any> = IsValidWorkflowOutput<T> extends true ? T : (Record<string, JsonObject> | void) & {
18
+ export type StrictWorkflowOutputType<T = any> = IsValidWorkflowOutput<T> extends true ? T : (Record<string, JsonObject> | void) & {
14
19
  [ERROR_WORKFLOW_OUTPUT]?: 'Workflow output must be shaped as Record<"task-name", JsonObject>. Each property must be an object, not a primitive value.';
15
20
  };
16
21
  declare const ERROR_WORKFLOW_OUTPUT: unique symbol;
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.0.6";
1
+ export declare const HATCHET_VERSION = "1.1.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.0.6';
4
+ exports.HATCHET_VERSION = '1.1.0';