@hatchet-dev/typescript-sdk 1.5.0 → 1.5.2

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 (74) hide show
  1. package/examples/affinity-workers.js +4 -4
  2. package/examples/byo-logger.js +2 -2
  3. package/examples/crons/cron-worker.js +2 -2
  4. package/examples/logger.js +2 -2
  5. package/examples/on-failure.js +4 -4
  6. package/examples/retries-with-backoff.js +2 -2
  7. package/examples/sticky-worker.js +4 -4
  8. package/package.json +1 -1
  9. package/step.js +2 -2
  10. package/util/workflow-run-ref.d.ts +2 -2
  11. package/util/workflow-run-ref.js +6 -7
  12. package/v1/client/admin.d.ts +2 -0
  13. package/v1/client/admin.js +6 -2
  14. package/v1/client/worker/context.js +5 -4
  15. package/v1/declaration.d.ts +2 -0
  16. package/v1/declaration.js +40 -46
  17. package/v1/examples/cancellations/run.js +1 -1
  18. package/v1/examples/cancellations/worker.js +1 -1
  19. package/v1/examples/cancellations/workflow.js +2 -2
  20. package/v1/examples/child_workflows/workflow.js +1 -1
  21. package/v1/examples/concurrency-rr/workflow.js +2 -2
  22. package/v1/examples/dag/interface-workflow.js +1 -1
  23. package/v1/examples/dag/workflow.js +1 -1
  24. package/v1/examples/dag_match_condition/complex-workflow.js +7 -7
  25. package/v1/examples/durable-event/workflow.js +2 -2
  26. package/v1/examples/durable-sleep/workflow.js +1 -1
  27. package/v1/examples/hatchet-client.d.ts +1 -1
  28. package/v1/examples/hatchet-client.js +2 -2
  29. package/v1/examples/landing_page/durable-excution.js +2 -2
  30. package/v1/examples/landing_page/event-signaling.js +1 -1
  31. package/v1/examples/landing_page/flow-control.js +1 -1
  32. package/v1/examples/landing_page/queues.js +2 -2
  33. package/v1/examples/landing_page/scheduling.js +1 -1
  34. package/v1/examples/landing_page/task-routing.js +1 -1
  35. package/v1/examples/migration-guides/mergent.js +5 -5
  36. package/v1/examples/multiple_wf_concurrency/workflow.js +1 -1
  37. package/v1/examples/non_retryable/workflow.js +1 -1
  38. package/v1/examples/on_cron/workflow.js +1 -1
  39. package/v1/examples/on_event/event.js +1 -1
  40. package/v1/examples/on_event/workflow.js +1 -1
  41. package/v1/examples/on_failure/workflow.js +1 -1
  42. package/v1/examples/on_success/workflow.js +1 -1
  43. package/v1/examples/priority/run.js +2 -2
  44. package/v1/examples/priority/workflow.js +2 -2
  45. package/v1/examples/quickstart/hatchet-client.d.ts +2 -0
  46. package/v1/examples/quickstart/hatchet-client.js +9 -0
  47. package/v1/examples/{on_event copy/event.js → quickstart/run.js} +7 -8
  48. package/v1/examples/{on_event copy/worker.js → quickstart/worker.js} +4 -3
  49. package/v1/examples/quickstart/workflows/first-task.d.ts +8 -0
  50. package/v1/examples/quickstart/workflows/first-task.js +12 -0
  51. package/v1/examples/rate_limit/workflow.js +3 -3
  52. package/v1/examples/retries/workflow.js +4 -4
  53. package/v1/examples/simple/bulk.js +2 -2
  54. package/v1/examples/simple/client-run.js +1 -1
  55. package/v1/examples/simple/cron.js +3 -3
  56. package/v1/examples/simple/enqueue.js +2 -2
  57. package/v1/examples/simple/run.js +7 -3
  58. package/v1/examples/simple/schedule.js +9 -1
  59. package/v1/examples/simple/stub-workflow.js +1 -1
  60. package/v1/examples/simple/worker.js +1 -1
  61. package/v1/examples/simple/workflow-with-child.d.ts +5 -1
  62. package/v1/examples/simple/workflow-with-child.js +18 -5
  63. package/v1/examples/simple/workflow.js +13 -3
  64. package/v1/examples/sticky/workflow.js +1 -1
  65. package/v1/examples/timeouts/run.js +1 -1
  66. package/v1/examples/timeouts/worker.js +1 -1
  67. package/v1/examples/timeouts/workflow.js +1 -1
  68. package/v1/examples/with_timeouts/workflow.js +3 -3
  69. package/version.d.ts +1 -1
  70. package/version.js +1 -1
  71. package/v1/examples/on_event copy/workflow.d.ts +0 -16
  72. package/v1/examples/on_event copy/workflow.js +0 -35
  73. /package/v1/examples/{on_event copy/event.d.ts → quickstart/run.d.ts} +0 -0
  74. /package/v1/examples/{on_event copy → quickstart}/worker.d.ts +0 -0
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const workflows_1 = require("../protoc/workflows");
16
16
  const sdk_1 = __importDefault(require("../sdk"));
17
17
  const hatchet = sdk_1.default.init();
18
- // AffinityWorkflow
18
+ // > AffinityWorkflow
19
19
  const workflow = {
20
20
  id: 'affinity-workflow',
21
21
  description: 'test',
@@ -36,7 +36,7 @@ const workflow = {
36
36
  },
37
37
  ],
38
38
  };
39
- // ‼️
39
+ // !!
40
40
  const childWorkflow = {
41
41
  id: 'child-affinity-workflow',
42
42
  description: 'test',
@@ -72,14 +72,14 @@ const childWorkflow = {
72
72
  };
73
73
  function main() {
74
74
  return __awaiter(this, void 0, void 0, function* () {
75
- // AffinityWorker
75
+ // > AffinityWorker
76
76
  const worker1 = yield hatchet.worker('affinity-worker-1', {
77
77
  labels: {
78
78
  model: 'abc',
79
79
  memory: 1024,
80
80
  },
81
81
  });
82
- // ‼️
82
+ // !!
83
83
  yield worker1.registerWorkflow(workflow);
84
84
  yield worker1.registerWorkflow(childWorkflow);
85
85
  worker1.start();
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  // eslint-disable-next-line import/no-extraneous-dependencies
16
16
  const pino_1 = __importDefault(require("pino"));
17
17
  const sdk_1 = __importDefault(require("../sdk"));
18
- // Create Pino logger
18
+ // > Create Pino logger
19
19
  const logger = (0, pino_1.default)();
20
20
  class PinoLogger {
21
21
  constructor(context, logLevel = 'DEBUG') {
@@ -43,7 +43,7 @@ const hatchet = sdk_1.default.init({
43
43
  logger: (ctx, level) => new PinoLogger(ctx, level),
44
44
  });
45
45
  // !!
46
- // Use the logger
46
+ // > Use the logger
47
47
  const sleep = (ms) => new Promise((resolve) => {
48
48
  setTimeout(resolve, ms);
49
49
  });
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.simpleCronWorkflow = void 0;
16
16
  const sdk_1 = __importDefault(require("../../sdk"));
17
17
  const hatchet = sdk_1.default.init();
18
- // Workflow Definition Cron Trigger
18
+ // > Workflow Definition Cron Trigger
19
19
  // Adding a cron trigger to a workflow is as simple as adding a `cron expression` to the `on` prop of the workflow definition
20
20
  exports.simpleCronWorkflow = {
21
21
  id: 'simple-cron-workflow',
@@ -35,7 +35,7 @@ exports.simpleCronWorkflow = {
35
35
  ],
36
36
  // ,
37
37
  };
38
- // ‼️
38
+ // !!
39
39
  function main() {
40
40
  return __awaiter(this, void 0, void 0, function* () {
41
41
  const worker = yield hatchet.worker('example-worker');
@@ -19,7 +19,7 @@ const hatchet = sdk_1.default.init({
19
19
  const sleep = (ms) => new Promise((resolve) => {
20
20
  setTimeout(resolve, ms);
21
21
  });
22
- // Logger
22
+ // > Logger
23
23
  const workflow = {
24
24
  id: 'logger-example',
25
25
  description: 'test',
@@ -41,7 +41,7 @@ const workflow = {
41
41
  },
42
42
  ],
43
43
  };
44
- // ‼️
44
+ // !!
45
45
  function main() {
46
46
  return __awaiter(this, void 0, void 0, function* () {
47
47
  const worker = yield hatchet.worker('logger-worker', 1);
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const sdk_1 = __importDefault(require("../sdk"));
16
16
  const hatchet = sdk_1.default.init();
17
- // OnFailure Step
17
+ // > OnFailure Step
18
18
  // This workflow will fail because the step will throw an error
19
19
  // we define an onFailure step to handle this case
20
20
  const workflow = {
@@ -46,10 +46,10 @@ const workflow = {
46
46
  }),
47
47
  },
48
48
  };
49
- // ‼️
50
- // OnFailure With Details
49
+ // !!
50
+ // > OnFailure With Details
51
51
  // Coming soon to TypeScript! https://github.com/hatchet-dev/hatchet-typescript/issues/447
52
- // ‼️
52
+ // !!
53
53
  function main() {
54
54
  return __awaiter(this, void 0, void 0, function* () {
55
55
  const worker = yield hatchet.worker('example-worker', 1);
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const sdk_1 = __importDefault(require("../sdk"));
16
16
  const hatchet = sdk_1.default.init();
17
17
  let numRetries = 0;
18
- // Backoff
18
+ // > Backoff
19
19
  const workflow = {
20
20
  // ... normal workflow definition
21
21
  id: 'retries-with-backoff',
@@ -45,7 +45,7 @@ const workflow = {
45
45
  },
46
46
  ],
47
47
  };
48
- // ‼️
48
+ // !!
49
49
  function main() {
50
50
  return __awaiter(this, void 0, void 0, function* () {
51
51
  const worker = yield hatchet.worker('backoff-worker');
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const sdk_1 = __importDefault(require("../sdk"));
16
16
  const workflow_1 = require("../workflow");
17
17
  const hatchet = sdk_1.default.init();
18
- // StickyWorker
18
+ // > StickyWorker
19
19
  const workflow = {
20
20
  id: 'sticky-workflow',
21
21
  description: 'test',
@@ -36,8 +36,8 @@ const workflow = {
36
36
  },
37
37
  ],
38
38
  };
39
- // ‼️
40
- // StickyChild
39
+ // !!
40
+ // > StickyChild
41
41
  const childWorkflow = {
42
42
  id: 'child-sticky-workflow',
43
43
  description: 'test',
@@ -62,7 +62,7 @@ const childWorkflow = {
62
62
  },
63
63
  ],
64
64
  };
65
- // ‼️
65
+ // !!
66
66
  function main() {
67
67
  return __awaiter(this, void 0, void 0, function* () {
68
68
  const worker1 = yield hatchet.worker('sticky-worker-1');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
package/step.js CHANGED
@@ -413,7 +413,7 @@ class V0Context {
413
413
  const wf = workflows[index].workflow;
414
414
  if (wf instanceof declaration_1.TaskWorkflowDeclaration) {
415
415
  // eslint-disable-next-line no-param-reassign
416
- ref._standalone_task_name = wf._standalone_task_name;
416
+ ref._standaloneTaskName = wf._standalone_task_name;
417
417
  }
418
418
  res.push(ref);
419
419
  });
@@ -480,7 +480,7 @@ class V0Context {
480
480
  const resp = yield this.v0.admin.runWorkflow(name, input, Object.assign({ parentId: workflowRunId, parentStepRunId: stepRunId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined }, opts));
481
481
  this.spawnIndex += 1;
482
482
  if (workflow instanceof declaration_1.TaskWorkflowDeclaration) {
483
- resp._standalone_task_name = workflow._standalone_task_name;
483
+ resp._standaloneTaskName = workflow._standalone_task_name;
484
484
  }
485
485
  return resp;
486
486
  }
@@ -11,10 +11,10 @@ export default class WorkflowRunRef<T> {
11
11
  parentWorkflowRunId?: string;
12
12
  private client;
13
13
  private runs;
14
- _standalone_task_name?: string;
14
+ _standaloneTaskName?: string;
15
15
  constructor(workflowRunId: string | Promise<string> | Promise<{
16
16
  workflowRunId: string;
17
- }>, client: RunListenerClient, runsClient?: RunsClient, parentWorkflowRunId?: string);
17
+ }>, client: RunListenerClient, runsClient?: RunsClient, parentWorkflowRunId?: string, standaloneTaskName?: string);
18
18
  get runId(): Promise<string>;
19
19
  getWorkflowRunId(): Promise<string>;
20
20
  stream(): Promise<AsyncGenerator<StepRunEvent, void, unknown>>;
@@ -50,11 +50,12 @@ function getWorkflowRunId(workflowRunId) {
50
50
  });
51
51
  }
52
52
  class WorkflowRunRef {
53
- constructor(workflowRunId, client, runsClient, parentWorkflowRunId) {
53
+ constructor(workflowRunId, client, runsClient, parentWorkflowRunId, standaloneTaskName) {
54
54
  this.workflowRunId = workflowRunId;
55
55
  this.parentWorkflowRunId = parentWorkflowRunId;
56
56
  this.client = client;
57
57
  this.runs = runsClient;
58
+ this._standaloneTaskName = standaloneTaskName;
58
59
  }
59
60
  // TODO docstrings
60
61
  get runId() {
@@ -72,9 +73,7 @@ class WorkflowRunRef {
72
73
  return this.client.stream(workflowRunId);
73
74
  });
74
75
  }
75
- // TODO not sure if i want this to be a get since it might be blocking for a long time..
76
76
  get output() {
77
- // TODO output for single task workflows
78
77
  return this.result();
79
78
  }
80
79
  /**
@@ -118,19 +117,19 @@ class WorkflowRunRef {
118
117
  outputs[readableStepName] = stepRun.output;
119
118
  }
120
119
  });
121
- if (!this._standalone_task_name) {
120
+ if (!this._standaloneTaskName) {
122
121
  resolve(outputs);
123
122
  return;
124
123
  }
125
- resolve(outputs[this._standalone_task_name]);
124
+ resolve(outputs[this._standaloneTaskName]);
126
125
  return;
127
126
  }
128
127
  const result = event.results.reduce((acc, r) => (Object.assign(Object.assign({}, acc), { [r.stepReadableId]: JSON.parse(r.output || '{}') })), {});
129
- if (!this._standalone_task_name) {
128
+ if (!this._standaloneTaskName) {
130
129
  resolve(result);
131
130
  return;
132
131
  }
133
- resolve(result[this._standalone_task_name]);
132
+ resolve(result[this._standaloneTaskName]);
134
133
  return;
135
134
  }
136
135
  }
@@ -39,6 +39,7 @@ export declare class AdminClient {
39
39
  additionalMetadata?: Record<string, string> | undefined;
40
40
  desiredWorkerId?: string | undefined;
41
41
  priority?: Priority;
42
+ _standaloneTaskName?: string | undefined;
42
43
  }): Promise<WorkflowRunRef<P>>;
43
44
  /**
44
45
  * Run multiple workflows runs with the given input and options. This will create new workflow runs and return their IDs.
@@ -57,6 +58,7 @@ export declare class AdminClient {
57
58
  additionalMetadata?: Record<string, string> | undefined;
58
59
  desiredWorkerId?: string | undefined;
59
60
  priority?: Priority;
61
+ _standaloneTaskName?: string | undefined;
60
62
  };
61
63
  }>, batchSize?: number): Promise<WorkflowRunRef<P>[]>;
62
64
  putRateLimit(key: string, limit: number, duration?: RateLimitDuration): Promise<void>;
@@ -48,7 +48,9 @@ class AdminClient {
48
48
  ? JSON.stringify(options === null || options === void 0 ? void 0 : options.additionalMetadata)
49
49
  : undefined, priority: options === null || options === void 0 ? void 0 : options.priority }));
50
50
  const id = resp.workflowRunId;
51
- const ref = new workflow_run_ref_1.default(id, this.listenerClient, this.runs, options === null || options === void 0 ? void 0 : options.parentId);
51
+ const ref = new workflow_run_ref_1.default(id, this.listenerClient, this.runs, options === null || options === void 0 ? void 0 : options.parentId,
52
+ // eslint-disable-next-line no-underscore-dangle
53
+ options === null || options === void 0 ? void 0 : options._standaloneTaskName);
52
54
  yield ref.getWorkflowRunId();
53
55
  return ref;
54
56
  }
@@ -92,7 +94,9 @@ class AdminClient {
92
94
  const batchResults = bulkTriggerWorkflowResponse.workflowRunIds.map((resp, index) => {
93
95
  const originalIndex = originalIndices[index];
94
96
  const { options } = workflowRuns[originalIndex];
95
- return new workflow_run_ref_1.default(resp, this.listenerClient, this.runs, options === null || options === void 0 ? void 0 : options.parentId);
97
+ return new workflow_run_ref_1.default(resp, this.listenerClient, this.runs, options === null || options === void 0 ? void 0 : options.parentId,
98
+ // eslint-disable-next-line no-underscore-dangle
99
+ options === null || options === void 0 ? void 0 : options._standaloneTaskName);
96
100
  });
97
101
  results.push(...batchResults);
98
102
  }
@@ -240,7 +240,7 @@ class Context {
240
240
  throw new hatchet_error_1.default(`Cannot run with sticky: workflow ${workflowName} is not registered on the worker`);
241
241
  }
242
242
  const { workflowRunId, stepRunId } = this.action;
243
- const finalOpts = Object.assign(Object.assign({}, options), { parentId: workflowRunId, parentStepRunId: stepRunId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined });
243
+ const finalOpts = Object.assign(Object.assign({}, options), { parentId: workflowRunId, parentStepRunId: stepRunId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined, _standaloneTaskName: workflow instanceof declaration_1.TaskWorkflowDeclaration ? workflow._standalone_task_name : undefined });
244
244
  this.spawnIndex += 1;
245
245
  return { workflowName, opts: finalOpts };
246
246
  }
@@ -300,7 +300,8 @@ class Context {
300
300
  */
301
301
  runNoWaitChild(workflow, input, options) {
302
302
  return __awaiter(this, void 0, void 0, function* () {
303
- return this.spawn(workflow, input, options);
303
+ const ref = yield this.spawn(workflow, input, options);
304
+ return ref;
304
305
  });
305
306
  }
306
307
  /**
@@ -426,7 +427,7 @@ class Context {
426
427
  const wf = workflows[index].workflow;
427
428
  if (wf instanceof declaration_1.TaskWorkflowDeclaration) {
428
429
  // eslint-disable-next-line no-param-reassign
429
- ref._standalone_task_name = wf._standalone_task_name;
430
+ ref._standaloneTaskName = wf._standalone_task_name;
430
431
  }
431
432
  res.push(ref);
432
433
  });
@@ -466,7 +467,7 @@ class Context {
466
467
  const resp = yield this.v1._v0.admin.runWorkflow(name, input, Object.assign({ parentId: workflowRunId, parentStepRunId: stepRunId, childIndex: this.spawnIndex, desiredWorkerId: sticky ? this.worker.id() : undefined }, opts));
467
468
  this.spawnIndex += 1;
468
469
  if (workflow instanceof declaration_1.TaskWorkflowDeclaration) {
469
- resp._standalone_task_name = workflow._standalone_task_name;
470
+ resp._standaloneTaskName = workflow._standalone_task_name;
470
471
  }
471
472
  return resp;
472
473
  }
@@ -192,6 +192,7 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
192
192
  * @throws Error if the workflow is not bound to a Hatchet client.
193
193
  */
194
194
  runNoWait(input: I, options?: RunOpts, _standaloneTaskName?: string): Promise<WorkflowRunRef<O>>;
195
+ runNoWait(input: I[], options?: RunOpts, _standaloneTaskName?: string): Promise<WorkflowRunRef<O>[]>;
195
196
  /**
196
197
  * @alias run
197
198
  * Triggers a workflow run and waits for the result.
@@ -330,6 +331,7 @@ export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputT
330
331
  * @throws Error if the workflow is not bound to a Hatchet client.
331
332
  */
332
333
  runNoWait(input: I, options?: RunOpts): Promise<WorkflowRunRef<O>>;
334
+ runNoWait(input: I[], options?: RunOpts): Promise<WorkflowRunRef<O>[]>;
333
335
  get taskDef(): CreateWorkflowTaskOpts<any, any>;
334
336
  }
335
337
  /**
package/v1/declaration.js CHANGED
@@ -36,37 +36,7 @@ class BaseWorkflowDeclaration {
36
36
  this.definition = Object.assign(Object.assign({}, options), { _tasks: [], _durableTasks: [] });
37
37
  this.client = client;
38
38
  }
39
- /**
40
- * Triggers a workflow run without waiting for completion.
41
- * @param input The input data for the workflow.
42
- * @param options Optional configuration for this workflow run.
43
- * @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
44
- * @throws Error if the workflow is not bound to a Hatchet client.
45
- */
46
39
  runNoWait(input, options, _standaloneTaskName) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- if (!this.client) {
49
- throw UNBOUND_ERR;
50
- }
51
- const res = yield this.client.admin.runWorkflow(this.name, input, options);
52
- if (_standaloneTaskName) {
53
- res._standalone_task_name = _standaloneTaskName;
54
- }
55
- return res;
56
- });
57
- }
58
- runAndWait(input, options, _standaloneTaskName) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- if (!this.client) {
61
- throw UNBOUND_ERR;
62
- }
63
- if (Array.isArray(input)) {
64
- return Promise.all(input.map((i) => this.runAndWait(i, options, _standaloneTaskName)));
65
- }
66
- return this.run(input, options, _standaloneTaskName);
67
- });
68
- }
69
- run(input, options, _standaloneTaskName) {
70
40
  return __awaiter(this, void 0, void 0, function* () {
71
41
  if (!this.client) {
72
42
  throw UNBOUND_ERR;
@@ -87,16 +57,44 @@ class BaseWorkflowDeclaration {
87
57
  const wf = input[index].workflow;
88
58
  if (wf instanceof TaskWorkflowDeclaration) {
89
59
  // eslint-disable-next-line no-param-reassign
90
- ref._standalone_task_name = wf._standalone_task_name;
60
+ ref._standaloneTaskName = wf._standalone_task_name;
61
+ }
62
+ if (_standaloneTaskName) {
63
+ // eslint-disable-next-line no-param-reassign
64
+ ref._standaloneTaskName = _standaloneTaskName;
91
65
  }
92
- res.push(ref.result());
66
+ res.push(ref);
93
67
  });
94
- return Promise.all(res);
68
+ return res;
95
69
  }
96
70
  const res = yield this.client.admin.runWorkflow(this.definition.name, input, options);
97
71
  if (_standaloneTaskName) {
98
- res._standalone_task_name = _standaloneTaskName;
72
+ res._standaloneTaskName = _standaloneTaskName;
99
73
  }
74
+ return res;
75
+ });
76
+ }
77
+ runAndWait(input, options, _standaloneTaskName) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ if (!this.client) {
80
+ throw UNBOUND_ERR;
81
+ }
82
+ // note: typescript is not smart enough to infer that input is an array
83
+ return Array.isArray(input)
84
+ ? this.run(input, options, _standaloneTaskName)
85
+ : this.run(input, options, _standaloneTaskName);
86
+ });
87
+ }
88
+ run(input, options, _standaloneTaskName) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ if (!this.client) {
91
+ throw UNBOUND_ERR;
92
+ }
93
+ if (Array.isArray(input)) {
94
+ const refs = yield this.runNoWait(input, options, _standaloneTaskName);
95
+ return Promise.all(refs.map((ref) => ref.result()));
96
+ }
97
+ const res = yield this.runNoWait(input, options, _standaloneTaskName);
100
98
  return res.result();
101
99
  });
102
100
  }
@@ -313,25 +311,21 @@ class TaskWorkflowDeclaration extends BaseWorkflowDeclaration {
313
311
  run: { get: () => super.run }
314
312
  });
315
313
  return __awaiter(this, void 0, void 0, function* () {
316
- return (yield _super.run.call(this, input, options, this._standalone_task_name));
314
+ // note: typescript is not smart enough to infer that input is an array
315
+ return Array.isArray(input)
316
+ ? _super.run.call(this, input, options, this._standalone_task_name)
317
+ : _super.run.call(this, input, options, this._standalone_task_name);
317
318
  });
318
319
  }
319
- /**
320
- * Triggers a workflow run without waiting for completion.
321
- * @param input The input data for the workflow.
322
- * @param options Optional configuration for this workflow run.
323
- * @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
324
- * @throws Error if the workflow is not bound to a Hatchet client.
325
- */
326
320
  runNoWait(input, options) {
327
321
  const _super = Object.create(null, {
328
322
  runNoWait: { get: () => super.runNoWait }
329
323
  });
330
324
  return __awaiter(this, void 0, void 0, function* () {
331
- if (!this.client) {
332
- throw UNBOUND_ERR;
333
- }
334
- return _super.runNoWait.call(this, input, options, this._standalone_task_name);
325
+ // note: typescript is not smart enough to infer that input is an array
326
+ return Array.isArray(input)
327
+ ? _super.runNoWait.call(this, input, options, this._standalone_task_name)
328
+ : _super.runNoWait.call(this, input, options, this._standalone_task_name);
335
329
  });
336
330
  }
337
331
  get taskDef() {
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  /* eslint-disable no-console */
16
- // Running a Task with Results
16
+ // > Running a Task with Results
17
17
  const sleep_1 = __importDefault(require("../../../util/sleep"));
18
18
  const workflow_1 = require("./workflow");
19
19
  const hatchet_client_1 = require("../hatchet-client");
@@ -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
- // Declaring a Worker
12
+ // > Declaring a Worker
13
13
  const hatchet_client_1 = require("../hatchet-client");
14
14
  const workflow_1 = require("./workflow");
15
15
  function main() {
@@ -16,7 +16,7 @@ exports.abortSignal = exports.cancellation = void 0;
16
16
  const sleep_1 = __importDefault(require("../../../util/sleep"));
17
17
  const axios_1 = __importDefault(require("axios"));
18
18
  const hatchet_client_1 = require("../hatchet-client");
19
- // Declaring a Task
19
+ // > Declaring a Task
20
20
  exports.cancellation = hatchet_client_1.hatchet.task({
21
21
  name: 'cancellation',
22
22
  fn: (_1, _a) => __awaiter(void 0, [_1, _a], void 0, function* (_, { cancelled }) {
@@ -30,7 +30,7 @@ exports.cancellation = hatchet_client_1.hatchet.task({
30
30
  }),
31
31
  });
32
32
  // !!
33
- // Abort Signal
33
+ // > Abort Signal
34
34
  exports.abortSignal = hatchet_client_1.hatchet.task({
35
35
  name: 'abort-signal',
36
36
  fn: (_1, _a) => __awaiter(void 0, [_1, _a], void 0, function* (_, { abortController }) {
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.parent = exports.child = void 0;
13
13
  /* eslint-disable no-plusplus */
14
- // Declaring a Child
14
+ // > Declaring a Child
15
15
  const hatchet_client_1 = require("../hatchet-client");
16
16
  exports.child = hatchet_client_1.hatchet.task({
17
17
  name: 'child',
@@ -15,7 +15,7 @@ const hatchet_client_1 = require("../hatchet-client");
15
15
  const sleep = (ms) => new Promise((resolve) => {
16
16
  setTimeout(resolve, ms);
17
17
  });
18
- // Concurrency Strategy With Key
18
+ // > Concurrency Strategy With Key
19
19
  exports.simpleConcurrency = hatchet_client_1.hatchet.workflow({
20
20
  name: 'simple-concurrency',
21
21
  concurrency: {
@@ -34,7 +34,7 @@ exports.simpleConcurrency.task({
34
34
  };
35
35
  }),
36
36
  });
37
- // Multiple Concurrency Keys
37
+ // > Multiple Concurrency Keys
38
38
  exports.multipleConcurrencyKeys = hatchet_client_1.hatchet.workflow({
39
39
  name: 'simple-concurrency',
40
40
  concurrency: [
@@ -11,7 +11,7 @@ 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
- // Declaring a DAG Workflow
14
+ // > Declaring a DAG Workflow
15
15
  // First, we declare the workflow
16
16
  exports.dag = hatchet_client_1.hatchet.workflow({
17
17
  name: 'simple',
@@ -11,7 +11,7 @@ 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
- // Declaring a DAG Workflow
14
+ // > Declaring a DAG Workflow
15
15
  // First, we declare the workflow
16
16
  exports.dag = hatchet_client_1.hatchet.workflow({
17
17
  name: 'simple',
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.taskConditionWorkflow = void 0;
13
- // Create a workflow
13
+ // > Create a workflow
14
14
  const conditions_1 = require("../../conditions");
15
15
  const parent_condition_1 = require("../../conditions/parent-condition");
16
16
  const hatchet_client_1 = require("../hatchet-client");
@@ -18,7 +18,7 @@ exports.taskConditionWorkflow = hatchet_client_1.hatchet.workflow({
18
18
  name: 'TaskConditionWorkflow',
19
19
  });
20
20
  // !!
21
- // Add base task
21
+ // > Add base task
22
22
  const start = exports.taskConditionWorkflow.task({
23
23
  name: 'start',
24
24
  fn: () => {
@@ -28,7 +28,7 @@ const start = exports.taskConditionWorkflow.task({
28
28
  },
29
29
  });
30
30
  // !!
31
- // Add wait for sleep
31
+ // > Add wait for sleep
32
32
  const waitForSleep = exports.taskConditionWorkflow.task({
33
33
  name: 'waitForSleep',
34
34
  parents: [start],
@@ -40,7 +40,7 @@ const waitForSleep = exports.taskConditionWorkflow.task({
40
40
  },
41
41
  });
42
42
  // !!
43
- // Add skip on event
43
+ // > Add skip on event
44
44
  const skipOnEvent = exports.taskConditionWorkflow.task({
45
45
  name: 'skipOnEvent',
46
46
  parents: [start],
@@ -53,7 +53,7 @@ const skipOnEvent = exports.taskConditionWorkflow.task({
53
53
  },
54
54
  });
55
55
  // !!
56
- // Add branching
56
+ // > Add branching
57
57
  const leftBranch = exports.taskConditionWorkflow.task({
58
58
  name: 'leftBranch',
59
59
  parents: [waitForSleep],
@@ -75,7 +75,7 @@ const rightBranch = exports.taskConditionWorkflow.task({
75
75
  },
76
76
  });
77
77
  // !!
78
- // Add wait for event
78
+ // > Add wait for event
79
79
  const waitForEvent = exports.taskConditionWorkflow.task({
80
80
  name: 'waitForEvent',
81
81
  parents: [start],
@@ -87,7 +87,7 @@ const waitForEvent = exports.taskConditionWorkflow.task({
87
87
  },
88
88
  });
89
89
  // !!
90
- // Add sum
90
+ // > Add sum
91
91
  exports.taskConditionWorkflow.task({
92
92
  name: 'sum',
93
93
  parents: [start, waitForSleep, waitForEvent, skipOnEvent, leftBranch, rightBranch],
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.durableEventWithFilter = exports.durableEvent = void 0;
13
13
  // import sleep from '../../../util/sleep.js';
14
14
  const hatchet_client_1 = require("../hatchet-client");
15
- // Durable Event
15
+ // > Durable Event
16
16
  exports.durableEvent = hatchet_client_1.hatchet.durableTask({
17
17
  name: 'durable-event',
18
18
  executionTimeout: '10m',
@@ -31,7 +31,7 @@ exports.durableEventWithFilter = hatchet_client_1.hatchet.durableTask({
31
31
  name: 'durable-event-with-filter',
32
32
  executionTimeout: '10m',
33
33
  fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
34
- // Durable Event With Filter
34
+ // > Durable Event With Filter
35
35
  const res = ctx.waitFor({
36
36
  eventKey: 'user:update',
37
37
  expression: "input.userId == '1234'",
@@ -15,7 +15,7 @@ const hatchet_client_1 = require("../hatchet-client");
15
15
  exports.durableSleep = hatchet_client_1.hatchet.workflow({
16
16
  name: 'durable-sleep',
17
17
  });
18
- // Durable Sleep
18
+ // > Durable Sleep
19
19
  exports.durableSleep.durableTask({
20
20
  name: 'durable-sleep',
21
21
  executionTimeout: '10m',
@@ -1,2 +1,2 @@
1
- import { HatchetClient } from '../client/client';
1
+ import { HatchetClient } from './..';
2
2
  export declare const hatchet: HatchetClient;