@hatchet-dev/typescript-sdk 1.9.5 → 1.9.6

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
  */
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.6",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -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.6";
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.6';