@hatchet-dev/typescript-sdk 1.9.4 → 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.
Files changed (33) hide show
  1. package/clients/admin/admin-client.d.ts +3 -3
  2. package/clients/dispatcher/action-listener.d.ts +1 -0
  3. package/clients/dispatcher/action-listener.js +16 -0
  4. package/clients/listeners/durable-listener/pooled-durable-listener-client.js +3 -3
  5. package/clients/rest/generated/Api.d.ts +124 -124
  6. package/clients/worker/worker.d.ts +1 -1
  7. package/package.json +1 -1
  8. package/v1/client/features/runs.d.ts +2 -2
  9. package/v1/client/worker/worker-internal.d.ts +1 -1
  10. package/v1/client/worker/worker-internal.js +6 -2
  11. package/v1/client/worker/worker.d.ts +1 -1
  12. package/v1/declaration.d.ts +1 -1
  13. package/v1/examples/affinity/affinity-workers.d.ts +1 -0
  14. package/v1/examples/affinity/affinity-workers.js +89 -0
  15. package/v1/examples/child_workflows/workflow.d.ts +6 -0
  16. package/v1/examples/child_workflows/workflow.js +31 -1
  17. package/v1/examples/dag/run.js +2 -0
  18. package/v1/examples/dag/workflow.js +18 -1
  19. package/v1/examples/hatchet-client.js +2 -0
  20. package/v1/examples/logging/byo-logger.d.ts +1 -0
  21. package/v1/examples/logging/byo-logger.js +73 -0
  22. package/v1/examples/logging/logger.d.ts +1 -0
  23. package/v1/examples/logging/logger.js +46 -0
  24. package/v1/examples/on_event/event.js +26 -0
  25. package/v1/examples/simple/replay-cancel.d.ts +1 -0
  26. package/v1/examples/simple/replay-cancel.js +34 -0
  27. package/v1/examples/simple/run.js +9 -0
  28. package/v1/examples/simple/typed-run-methods.d.ts +1 -0
  29. package/v1/examples/simple/typed-run-methods.js +37 -0
  30. package/v1/examples/with_timeouts/workflow.js +0 -1
  31. package/v1/task.d.ts +1 -1
  32. package/version.d.ts +1 -1
  33. package/version.js +1 -1
@@ -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.4",
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
  */
@@ -92,14 +92,18 @@ class V1Worker {
92
92
  });
93
93
  }
94
94
  registerDurableActionsV1(workflow) {
95
- const newActions = workflow._durableTasks.reduce((acc, task) => {
95
+ const newActions = workflow._durableTasks
96
+ .filter((task) => !!task.fn)
97
+ .reduce((acc, task) => {
96
98
  acc[`${(0, apply_namespace_1.applyNamespace)(workflow.name, this.client.config.namespace).toLowerCase()}:${task.name.toLowerCase()}`] = (ctx) => task.fn(ctx.input, ctx);
97
99
  return acc;
98
100
  }, {});
99
101
  this.action_registry = Object.assign(Object.assign({}, this.action_registry), newActions);
100
102
  }
101
103
  registerActionsV1(workflow) {
102
- const newActions = workflow._tasks.reduce((acc, task) => {
104
+ const newActions = workflow._tasks
105
+ .filter((task) => !!task.fn)
106
+ .reduce((acc, task) => {
103
107
  acc[`${workflow.name}:${task.name.toLowerCase()}`] = (ctx) => task.fn(ctx.input, ctx);
104
108
  return acc;
105
109
  }, {});
@@ -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[]>;
@@ -295,7 +295,7 @@ export declare class WorkflowDeclaration<I extends InputType = UnknownInputType,
295
295
  */
296
296
  task<Name extends string, Fn extends Name extends keyof O ? (input: I, ctx: Context<I>) => O[Name] extends OutputType ? O[Name] | Promise<O[Name]> : void : (input: I, ctx: Context<I>) => void, FnReturn = ReturnType<Fn> extends Promise<infer P> ? P : ReturnType<Fn>, TO extends OutputType = Name extends keyof O ? O[Name] extends OutputType ? O[Name] : never : FnReturn extends OutputType ? FnReturn : never>(options: (Omit<CreateWorkflowTaskOpts<I, TO>, 'fn'> & {
297
297
  name: Name;
298
- fn: Fn;
298
+ fn?: Fn;
299
299
  }) | TaskWorkflowDeclaration<I, TO>): CreateWorkflowTaskOpts<I, TO>;
300
300
  /**
301
301
  * Adds an onFailure task to the workflow.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,89 @@
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 workflows_1 = require("../../../protoc/workflows");
13
+ const hatchet_client_1 = require("../hatchet-client");
14
+ // > AffinityWorkflow
15
+ const workflow = hatchet_client_1.hatchet.workflow({
16
+ name: 'affinity-workflow',
17
+ description: 'test',
18
+ });
19
+ workflow.task({
20
+ name: 'step1',
21
+ fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
22
+ const results = [];
23
+ // eslint-disable-next-line no-plusplus
24
+ for (let i = 0; i < 50; i++) {
25
+ const result = yield ctx.spawnWorkflow(childWorkflow.id, {});
26
+ results.push(result.output);
27
+ }
28
+ console.log('Spawned 50 child workflows');
29
+ console.log('Results:', yield Promise.all(results));
30
+ return { step1: 'step1 results!' };
31
+ }),
32
+ });
33
+ // !!
34
+ // > Task with labels
35
+ const childWorkflow = hatchet_client_1.hatchet.workflow({
36
+ name: 'child-affinity-workflow',
37
+ description: 'test',
38
+ });
39
+ childWorkflow.task({
40
+ name: 'child-step1',
41
+ desiredWorkerLabels: {
42
+ model: {
43
+ value: 'xyz',
44
+ required: true,
45
+ },
46
+ },
47
+ fn: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
48
+ return { childStep1: 'childStep1 results!' };
49
+ }),
50
+ });
51
+ // !!
52
+ childWorkflow.task({
53
+ name: 'child-step2',
54
+ desiredWorkerLabels: {
55
+ memory: {
56
+ value: 512,
57
+ required: true,
58
+ comparator: workflows_1.WorkerLabelComparator.LESS_THAN,
59
+ },
60
+ },
61
+ fn: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
62
+ return { childStep2: 'childStep2 results!' };
63
+ }),
64
+ });
65
+ function main() {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ // > AffinityWorker
68
+ const worker1 = yield hatchet_client_1.hatchet.worker('affinity-worker-1', {
69
+ labels: {
70
+ model: 'abc',
71
+ memory: 1024,
72
+ },
73
+ });
74
+ // !!
75
+ yield worker1.registerWorkflow(workflow);
76
+ yield worker1.registerWorkflow(childWorkflow);
77
+ worker1.start();
78
+ const worker2 = yield hatchet_client_1.hatchet.worker('affinity-worker-2', {
79
+ labels: {
80
+ model: 'xyz',
81
+ memory: 512,
82
+ },
83
+ });
84
+ yield worker2.registerWorkflow(workflow);
85
+ yield worker2.registerWorkflow(childWorkflow);
86
+ worker2.start();
87
+ });
88
+ }
89
+ main();
@@ -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
+ // !!
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ // eslint-disable-next-line import/no-extraneous-dependencies
16
+ const pino_1 = __importDefault(require("pino"));
17
+ const sdk_1 = __importDefault(require("../../../sdk"));
18
+ // > Create Pino logger
19
+ const logger = (0, pino_1.default)();
20
+ class PinoLogger {
21
+ constructor(context, logLevel = 'DEBUG') {
22
+ this.logLevel = logLevel;
23
+ this.context = context;
24
+ }
25
+ debug(message, extra) {
26
+ logger.debug(extra, message);
27
+ }
28
+ info(message, extra) {
29
+ logger.info(extra, message);
30
+ }
31
+ green(message, extra) {
32
+ logger.info(extra, `%c${message}`);
33
+ }
34
+ warn(message, error, extra) {
35
+ logger.warn(extra, `${message} ${error}`);
36
+ }
37
+ error(message, error, extra) {
38
+ logger.error(extra, `${message} ${error}`);
39
+ }
40
+ // optional util method
41
+ util(key, message, extra) {
42
+ // for example you may want to expose a trace method
43
+ if (key === 'trace') {
44
+ logger.info(extra, 'trace');
45
+ }
46
+ }
47
+ }
48
+ const hatchet = sdk_1.default.init({
49
+ log_level: 'DEBUG',
50
+ logger: (ctx, level) => new PinoLogger(ctx, level),
51
+ });
52
+ // !!
53
+ // > Use the logger
54
+ const workflow = hatchet.task({
55
+ name: 'byo-logger-example',
56
+ fn: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
57
+ // eslint-disable-next-line no-plusplus
58
+ for (let i = 0; i < 5; i++) {
59
+ logger.info(`log message ${i}`);
60
+ }
61
+ return { step1: 'completed step run' };
62
+ }),
63
+ });
64
+ // !!
65
+ function main() {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const worker = yield hatchet.worker('byo-logger-worker', {
68
+ workflows: [workflow],
69
+ });
70
+ worker.start();
71
+ });
72
+ }
73
+ main();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,46 @@
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 sleep = (ms) => new Promise((resolve) => {
14
+ setTimeout(resolve, ms);
15
+ });
16
+ // > Logger
17
+ const workflow = hatchet_client_1.hatchet.workflow({
18
+ name: 'logger-example',
19
+ description: 'test',
20
+ on: {
21
+ event: 'user:create',
22
+ },
23
+ });
24
+ workflow.task({
25
+ name: 'logger-step1',
26
+ fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
27
+ // log in a for loop
28
+ // eslint-disable-next-line no-plusplus
29
+ for (let i = 0; i < 10; i++) {
30
+ ctx.logger.info(`log message ${i}`);
31
+ yield sleep(200);
32
+ }
33
+ return { step1: 'completed step run' };
34
+ }),
35
+ });
36
+ // !!
37
+ function main() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const worker = yield hatchet_client_1.hatchet.worker('logger-worker', {
40
+ slots: 1,
41
+ workflows: [workflow],
42
+ });
43
+ yield worker.start();
44
+ });
45
+ }
46
+ main();
@@ -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
+ }
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.refreshTimeout = exports.withTimeouts = void 0;
16
- // > Declaring a Task
17
16
  const sleep_1 = __importDefault(require("../../../util/sleep"));
18
17
  const hatchet_client_1 = require("../hatchet-client");
19
18
  // > Execution Timeout
package/v1/task.d.ts CHANGED
@@ -55,7 +55,7 @@ export type CreateBaseTaskOpts<I extends InputType = UnknownInputType, O extends
55
55
  * @param ctx The execution context for the task.
56
56
  * @returns The result of the task execution.
57
57
  */
58
- fn: C;
58
+ fn?: C;
59
59
  /**
60
60
  * @deprecated use executionTimeout instead
61
61
  */
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.9.4";
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.4';
4
+ exports.HATCHET_VERSION = '1.9.6';