@hatchet-dev/typescript-sdk 1.9.5 → 1.9.7

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.
@@ -39,7 +39,7 @@ export declare class V0Worker {
39
39
  });
40
40
  private registerActions;
41
41
  getHandler(workflows: Workflow[]): WebhookHandler;
42
- registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../rest/generated/data-contracts").WebhookWorkerCreated, any>>;
42
+ registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../rest/generated/data-contracts").WebhookWorkerCreated, any, {}>>;
43
43
  /**
44
44
  * @deprecated use registerWorkflow instead
45
45
  */
@@ -0,0 +1,65 @@
1
+ /* eslint-disable no-console */
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const semver = require('semver');
5
+
6
+ const WARNINGS = {
7
+ '1.4.0':
8
+ 'Breaking Changes in v1.4.0: This release fixes a critical bug which makes the runNoWait methods async. You will need to await this method to access the runRef.',
9
+ };
10
+
11
+ try {
12
+ // Get the current package version
13
+ // eslint-disable-next-line global-require
14
+ const currentVersion = require('../package.json').version;
15
+
16
+ // Look for the package.json in various possible locations
17
+ const possiblePaths = [
18
+ // npm
19
+ path.join(process.cwd(), 'package.json'),
20
+ // pnpm
21
+ path.join(process.cwd(), '..', 'package.json'),
22
+ // yarn
23
+ path.join(process.cwd(), '..', '..', 'package.json'),
24
+ // monorepo setup
25
+ path.join(process.cwd(), '..', '..', '..', 'package.json'),
26
+ ];
27
+
28
+ let parentPackagePath = null;
29
+ for (const possiblePath of possiblePaths) {
30
+ if (fs.existsSync(possiblePath)) {
31
+ parentPackagePath = possiblePath;
32
+ break;
33
+ }
34
+ }
35
+
36
+ if (parentPackagePath) {
37
+ const parentPackage = JSON.parse(fs.readFileSync(parentPackagePath, 'utf8'));
38
+ const dependencies = {
39
+ ...parentPackage.dependencies,
40
+ ...parentPackage.devDependencies,
41
+ };
42
+
43
+ const installedVersion = dependencies['@hatchet-dev/typescript-sdk'];
44
+
45
+ // If there's no installed version, this is a first-time install
46
+ if (!installedVersion) {
47
+ // Show all warnings for the current version
48
+ for (const [version, warning] of Object.entries(WARNINGS)) {
49
+ if (semver.gte(currentVersion, version)) {
50
+ console.warn('\x1b[33m%s\x1b[0m', warning);
51
+ }
52
+ }
53
+ } else {
54
+ // Check for specific version warnings
55
+ for (const [version, warning] of Object.entries(WARNINGS)) {
56
+ if (semver.gte(currentVersion, version) && semver.lt(installedVersion, version)) {
57
+ console.warn('\x1b[33m%s\x1b[0m', warning);
58
+ }
59
+ }
60
+ }
61
+ }
62
+ } catch (error) {
63
+ // Silently fail - this is just a warning system
64
+ // console.error(error);
65
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.9.5",
3
+ "version": "1.9.7",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -15,30 +15,6 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/hatchet-dev/hatchet.git"
17
17
  },
18
- "scripts": {
19
- "build": "echo 'build hatchet sdk with `npm run tsc:build` to ensure it is not build during the publish step' && exit 0",
20
- "prepare": "npm run build",
21
- "postinstall": "node scripts/version-check.js",
22
- "dump-version": "node -e \"console.log('export const HATCHET_VERSION = \\'' + require('./package.json').version + '\\';');\" > src/version.ts",
23
- "tsc:build": "npm run dump-version && tsc && resolve-tspaths",
24
- "test:unit": "jest --testMatch='**/*.test.ts'",
25
- "test:e2e": "jest --testMatch='**/*.e2e.ts'",
26
- "test:unit:watch": "jest --testMatch='**/*.test.ts' --watch",
27
- "generate": "pnpm run '/generate-.*/'",
28
- "generate-api": "npx --yes swagger-cli bundle ../../api-contracts/openapi/openapi.yaml --outfile openapi.yaml --type yaml && npx swagger-typescript-api@13.1.0 generate -p openapi.yaml -o src/clients/rest/generated -n hatchet.ts --modular --axios",
29
- "generate-protoc": "./generate-protoc.sh",
30
- "lint:check": "npm run eslint:check && npm run prettier:check",
31
- "lint:fix": "npm run eslint:fix && npm run prettier:fix",
32
- "eslint:check": "eslint \"{src,tests}/**/*.{ts,tsx,js}\"",
33
- "eslint:fix": "eslint \"{src,tests}/**/*.{ts,tsx,js}\" --fix",
34
- "prettier:check": "prettier \"src/**/*.{ts,tsx}\" --list-different",
35
- "prettier:fix": "prettier \"src/**/*.{ts,tsx}\" --write",
36
- "prepublish": "cp package.json dist/package.json; cp README.md dist/; cp -r scripts dist/",
37
- "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",
38
- "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",
39
- "generate-docs": "typedoc",
40
- "exec": "npx dotenv -- ts-node -r tsconfig-paths/register --project tsconfig.json"
41
- },
42
18
  "keywords": [],
43
19
  "author": "",
44
20
  "license": "MIT",
@@ -91,5 +67,28 @@
91
67
  "yaml": "^2.7.1",
92
68
  "zod": "^3.24.2"
93
69
  },
94
- "packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0"
95
- }
70
+ "packageManager": "pnpm@10.16.1",
71
+ "scripts": {
72
+ "build": "echo 'build hatchet sdk with `npm run tsc:build` to ensure it is not build during the publish step' && exit 0",
73
+ "postinstall": "node scripts/version-check.js",
74
+ "dump-version": "node -e \"console.log('export const HATCHET_VERSION = \\'' + require('./package.json').version + '\\';');\" > src/version.ts",
75
+ "tsc:build": "pnpm run dump-version && tsc && resolve-tspaths",
76
+ "test:unit": "jest --testMatch='**/*.test.ts'",
77
+ "test:e2e": "jest --testMatch='**/*.e2e.ts'",
78
+ "test:unit:watch": "jest --testMatch='**/*.test.ts' --watch",
79
+ "generate": "pnpm run '/generate-.*/'",
80
+ "generate-api": "npx --yes swagger-cli bundle ../../api-contracts/openapi/openapi.yaml --outfile openapi.yaml --type yaml && npx swagger-typescript-api@13.1.0 generate -p openapi.yaml -o src/clients/rest/generated -n hatchet.ts --modular --axios",
81
+ "generate-protoc": "./generate-protoc.sh",
82
+ "lint:check": "pnpm run eslint:check && pnpm run prettier:check",
83
+ "lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix",
84
+ "eslint:check": "eslint \"{src,tests}/**/*.{ts,tsx,js}\"",
85
+ "eslint:fix": "eslint \"{src,tests}/**/*.{ts,tsx,js}\" --fix",
86
+ "prettier:check": "prettier \"src/**/*.{ts,tsx}\" --list-different",
87
+ "prettier:fix": "prettier \"src/**/*.{ts,tsx}\" --write",
88
+ "prepublish": "cp package.json dist/package.json; cp README.md dist/; cp -r scripts dist/",
89
+ "publish:ci": "rm -rf ./dist && pnpm run dump-version && pnpm run tsc:build && pnpm run prepublish && cd dist && pnpm publish --access public --no-git-checks",
90
+ "publish:ci:alpha": "rm -rf ./dist && pnpm run dump-version && pnpm run tsc:build && pnpm run prepublish && cd dist && pnpm publish --access public --no-git-checks --tag alpha",
91
+ "generate-docs": "typedoc",
92
+ "exec": "npx dotenv -- ts-node -r tsconfig-paths/register --project tsconfig.json"
93
+ }
94
+ }
@@ -68,8 +68,8 @@ export declare class RunsClient {
68
68
  get<T = any>(run: string | WorkflowRunRef<T>): Promise<import("../../../clients/rest/generated/data-contracts").V1WorkflowRunDetails>;
69
69
  get_status<T = any>(run: string | WorkflowRunRef<T>): Promise<V1TaskStatus>;
70
70
  list(opts?: Partial<ListRunsOpts>): Promise<import("../../../clients/rest/generated/data-contracts").V1TaskSummaryList>;
71
- cancel(opts: CancelRunOpts): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").V1CancelledTasks, any>>;
72
- replay(opts: ReplayRunOpts): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").V1ReplayedTasks, any>>;
71
+ cancel(opts: CancelRunOpts): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").V1CancelledTasks, any, {}>>;
72
+ replay(opts: ReplayRunOpts): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").V1ReplayedTasks, any, {}>>;
73
73
  private prepareFilter;
74
74
  private prepareListFilter;
75
75
  runRef<T extends Record<string, any> = any>(id: string): WorkflowRunRef<T>;
@@ -38,7 +38,7 @@ export declare class V1Worker {
38
38
  });
39
39
  private registerActions;
40
40
  getHandler(workflows: Workflow[]): void;
41
- registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").WebhookWorkerCreated, any>>;
41
+ registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").WebhookWorkerCreated, any, {}>>;
42
42
  /**
43
43
  * @deprecated use registerWorkflow instead
44
44
  */
@@ -85,7 +85,7 @@ export declare class Worker {
85
85
  * @param webhook - The webhook to register
86
86
  * @returns A promise that resolves when the webhook is registered
87
87
  */
88
- registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").WebhookWorkerCreated, any>>;
88
+ registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../../../clients/rest/generated/data-contracts").WebhookWorkerCreated, any, {}>>;
89
89
  isPaused(): Promise<boolean>;
90
90
  pause(): Promise<any[]>;
91
91
  unpause(): Promise<any[]>;
@@ -31,6 +31,7 @@ workflow.task({
31
31
  }),
32
32
  });
33
33
  // !!
34
+ // > Task with labels
34
35
  const childWorkflow = hatchet_client_1.hatchet.workflow({
35
36
  name: 'child-affinity-workflow',
36
37
  description: 'test',
@@ -47,6 +48,7 @@ childWorkflow.task({
47
48
  return { childStep1: 'childStep1 results!' };
48
49
  }),
49
50
  });
51
+ // !!
50
52
  childWorkflow.task({
51
53
  name: 'child-step2',
52
54
  desiredWorkerLabels: {
@@ -10,4 +10,10 @@ type ParentInput = {
10
10
  export declare const parent: import("../..").TaskWorkflowDeclaration<ParentInput, {
11
11
  Result: number;
12
12
  }>;
13
+ export declare const parentSingleChild: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
14
+ Result: number;
15
+ }>;
16
+ export declare const withErrorHandling: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
17
+ Result: number;
18
+ }>;
13
19
  export {};
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.parent = exports.child = void 0;
12
+ exports.withErrorHandling = exports.parentSingleChild = exports.parent = exports.child = void 0;
13
13
  /* eslint-disable no-plusplus */
14
14
  // > Declaring a Child
15
15
  const hatchet_client_1 = require("../hatchet-client");
@@ -37,3 +37,33 @@ exports.parent = hatchet_client_1.hatchet.task({
37
37
  }),
38
38
  });
39
39
  // !!
40
+ // > Parent with Single Child
41
+ exports.parentSingleChild = hatchet_client_1.hatchet.task({
42
+ name: 'parent-single-child',
43
+ fn: () => __awaiter(void 0, void 0, void 0, function* () {
44
+ const childRes = yield exports.child.run({ N: 1 });
45
+ return {
46
+ Result: childRes.Value,
47
+ };
48
+ }),
49
+ });
50
+ // !!
51
+ // > Parent with Error Handling
52
+ exports.withErrorHandling = hatchet_client_1.hatchet.task({
53
+ name: 'parent-error-handling',
54
+ fn: () => __awaiter(void 0, void 0, void 0, function* () {
55
+ try {
56
+ const childRes = yield exports.child.run({ N: 1 });
57
+ return {
58
+ Result: childRes.Value,
59
+ };
60
+ }
61
+ catch (error) {
62
+ // decide how to proceed here
63
+ return {
64
+ Result: -1,
65
+ };
66
+ }
67
+ }),
68
+ });
69
+ // !!
@@ -12,9 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const workflow_1 = require("./workflow");
13
13
  function main() {
14
14
  return __awaiter(this, void 0, void 0, function* () {
15
+ // > Run the workflow
15
16
  const res = yield workflow_1.dag.run({
16
17
  Message: 'hello world',
17
18
  });
19
+ // !!
18
20
  // eslint-disable-next-line no-console
19
21
  console.log(res.reverse.Transformed);
20
22
  });
@@ -11,11 +11,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.dag = void 0;
13
13
  const hatchet_client_1 = require("../hatchet-client");
14
+ // !!
14
15
  // > Declaring a DAG Workflow
15
16
  // First, we declare the workflow
16
17
  exports.dag = hatchet_client_1.hatchet.workflow({
17
18
  name: 'simple',
18
19
  });
20
+ // !!
21
+ // > First task
19
22
  // Next, we declare the tasks bound to the workflow
20
23
  const toLower = exports.dag.task({
21
24
  name: 'to-lower',
@@ -25,7 +28,8 @@ const toLower = exports.dag.task({
25
28
  };
26
29
  },
27
30
  });
28
- // Next, we declare the tasks bound to the workflow
31
+ // !!
32
+ // > Second task with parent
29
33
  exports.dag.task({
30
34
  name: 'reverse',
31
35
  parents: [toLower],
@@ -38,3 +42,16 @@ exports.dag.task({
38
42
  }),
39
43
  });
40
44
  // !!
45
+ // > Accessing Parent Outputs
46
+ exports.dag.task({
47
+ name: 'task-with-parent-output',
48
+ parents: [toLower],
49
+ fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
50
+ const lower = yield ctx.parentOutput(toLower);
51
+ return {
52
+ Original: input.Message,
53
+ Transformed: lower.TransformedMessage.split('').reverse().join(''),
54
+ };
55
+ }),
56
+ });
57
+ // !!
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hatchet = void 0;
4
+ // > Create client
4
5
  const v1_1 = require("./..");
5
6
  exports.hatchet = v1_1.HatchetClient.init();
7
+ // !!
@@ -18,6 +18,32 @@ function main() {
18
18
  ShouldSkip: false,
19
19
  });
20
20
  // !!
21
+ // > Push an Event with Metadata
22
+ const withMetadata = yield hatchet_client_1.hatchet.events.push('user:create', {
23
+ test: 'test',
24
+ }, {
25
+ additionalMetadata: {
26
+ source: 'api', // Arbitrary key-value pair
27
+ },
28
+ });
29
+ // !!
30
+ // > Bulk push events
31
+ const events = [
32
+ {
33
+ payload: { test: 'test1' },
34
+ additionalMetadata: { user_id: 'user1', source: 'test' },
35
+ },
36
+ {
37
+ payload: { test: 'test2' },
38
+ additionalMetadata: { user_id: 'user2', source: 'test' },
39
+ },
40
+ {
41
+ payload: { test: 'test3' },
42
+ additionalMetadata: { user_id: 'user3', source: 'test' },
43
+ },
44
+ ];
45
+ yield hatchet_client_1.hatchet.events.bulkPush('user:create', events);
46
+ // !!
21
47
  // eslint-disable-next-line no-console
22
48
  console.log(res.eventId);
23
49
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const data_contracts_1 = require("../../../clients/rest/generated/data-contracts");
13
+ const hatchet_client_1 = require("../hatchet-client");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ var _a;
17
+ const { runs } = hatchet_client_1.hatchet;
18
+ // > API operations
19
+ // list all failed runs
20
+ const allFailedRuns = yield runs.list({
21
+ statuses: [data_contracts_1.V1TaskStatus.FAILED],
22
+ });
23
+ // replay by ids
24
+ yield runs.replay({ ids: (_a = allFailedRuns.rows) === null || _a === void 0 ? void 0 : _a.map((r) => r.metadata.id) });
25
+ // or you can run bulk operations with filters directly
26
+ yield runs.cancel({
27
+ filters: {
28
+ since: new Date('2025-03-27'),
29
+ additionalMetadata: { user: '123' },
30
+ },
31
+ });
32
+ // !!
33
+ });
34
+ }
@@ -56,6 +56,15 @@ function extra() {
56
56
  }),
57
57
  });
58
58
  // !!
59
+ // > Run with metadata
60
+ const withMetadata = workflow_1.simple.run({
61
+ Message: 'HeLlO WoRlD',
62
+ }, {
63
+ additionalMetadata: {
64
+ source: 'api', // Arbitrary key-value pair
65
+ },
66
+ });
67
+ // !!
59
68
  });
60
69
  }
61
70
  if (require.main === module) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
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
+ // > Run methods
16
+ const input = { Message: 'Hello, World!' };
17
+ // run now
18
+ const result = yield workflow_1.simple.run(input);
19
+ const runReference = yield workflow_1.simple.runNoWait(input);
20
+ // or in the future
21
+ const runAt = new Date(new Date().setHours(12, 0, 0, 0) + 24 * 60 * 60 * 1000);
22
+ const scheduled = yield workflow_1.simple.schedule(runAt, input);
23
+ const cron = yield workflow_1.simple.cron('simple-daily', '0 0 * * *', input);
24
+ // !!
25
+ });
26
+ }
27
+ function runFlavors() {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ // > Run method flavors
30
+ const input = { Message: 'Hello, World!' };
31
+ // Run workflow and wait for the result
32
+ const result = yield workflow_1.simple.run(input);
33
+ // Enqueue workflow to be executed asynchronously
34
+ const runReference = yield workflow_1.simple.runNoWait(input);
35
+ // !!
36
+ });
37
+ }
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.9.5";
1
+ export declare const HATCHET_VERSION = "1.9.7";
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.9.5';
4
+ exports.HATCHET_VERSION = '1.9.7';