@hatchet-dev/typescript-sdk 1.5.1 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -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._standaloneTaskName = _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;
@@ -89,14 +59,42 @@ class BaseWorkflowDeclaration {
89
59
  // eslint-disable-next-line no-param-reassign
90
60
  ref._standaloneTaskName = wf._standalone_task_name;
91
61
  }
92
- res.push(ref.result());
62
+ if (_standaloneTaskName) {
63
+ // eslint-disable-next-line no-param-reassign
64
+ ref._standaloneTaskName = _standaloneTaskName;
65
+ }
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
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() {
@@ -8,25 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.simple = void 0;
16
13
  // > Declaring a Task
17
- const sleep_1 = __importDefault(require("../../../util/sleep"));
18
14
  const hatchet_client_1 = require("../hatchet-client");
19
15
  exports.simple = hatchet_client_1.hatchet.task({
20
16
  name: 'simple',
21
17
  retries: 3,
22
- fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
23
- ctx.log('hello from the workflow');
24
- yield (0, sleep_1.default)(100);
25
- ctx.log('goodbye from the workflow');
26
- yield (0, sleep_1.default)(100);
27
- if (ctx.retryCount() < 2) {
28
- throw new Error('test error');
29
- }
18
+ fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
30
19
  return {
31
20
  TransformedMessage: input.Message.toLowerCase(),
32
21
  };
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.5.1";
1
+ export declare const HATCHET_VERSION = "1.5.2";
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.5.1';
4
+ exports.HATCHET_VERSION = '1.5.2';
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
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
- function main() {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- // ❓ Pushing an Event
16
- const res = yield hatchet_client_1.hatchet.event.push('simple-event:create', {
17
- Message: 'hello',
18
- });
19
- // !!
20
- // eslint-disable-next-line no-console
21
- console.log(res.eventId);
22
- });
23
- }
24
- if (require.main === module) {
25
- main();
26
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,24 +0,0 @@
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('on-event-worker', {
17
- workflows: [workflow_1.lower, workflow_1.upper],
18
- });
19
- yield worker.start();
20
- });
21
- }
22
- if (require.main === module) {
23
- main();
24
- }
@@ -1,16 +0,0 @@
1
- export type Input = {
2
- Message: string;
3
- };
4
- type LowerOutput = {
5
- lower: {
6
- TransformedMessage: string;
7
- };
8
- };
9
- export declare const lower: import("../..").WorkflowDeclaration<Input, LowerOutput>;
10
- type UpperOutput = {
11
- upper: {
12
- TransformedMessage: string;
13
- };
14
- };
15
- export declare const upper: import("../..").WorkflowDeclaration<Input, UpperOutput>;
16
- export {};
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.upper = exports.lower = void 0;
4
- const hatchet_client_1 = require("../hatchet-client");
5
- // ❓ Run workflow on event
6
- exports.lower = hatchet_client_1.hatchet.workflow({
7
- name: 'lower',
8
- on: {
9
- // 👀 Declare the event that will trigger the workflow
10
- event: 'simple-event:create',
11
- },
12
- });
13
- // !!
14
- exports.lower.task({
15
- name: 'lower',
16
- fn: (input) => {
17
- return {
18
- TransformedMessage: input.Message.toLowerCase(),
19
- };
20
- },
21
- });
22
- exports.upper = hatchet_client_1.hatchet.workflow({
23
- name: 'upper',
24
- on: {
25
- event: 'simple-event:create',
26
- },
27
- });
28
- exports.upper.task({
29
- name: 'upper',
30
- fn: (input) => {
31
- return {
32
- TransformedMessage: input.Message.toUpperCase(),
33
- };
34
- },
35
- });