@hatchet-dev/typescript-sdk 1.1.2 → 1.1.5

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/README.md CHANGED
@@ -32,39 +32,7 @@ pnpm add @hatchet-dev/typescript-sdk
32
32
 
33
33
  ## Quick Start
34
34
 
35
- Here's a simple example of how to use the Hatchet TypeScript SDK:
36
-
37
- ```typescript
38
- import { HatchetClient } from '@hatchet-dev/typescript-sdk';
39
-
40
- export const hatchet = HatchetClient.init();
41
-
42
- export type SimpleInput = {
43
- Message: string;
44
- };
45
-
46
- export const simple = hatchet.task({
47
- name: 'simple',
48
- fn: (input: SimpleInput) => {
49
- return {
50
- TransformedMessage: input.Message.toLowerCase(),
51
- };
52
- },
53
- });
54
-
55
- async function main() {
56
- const worker = await hatchet.worker('simple-worker', {
57
- workflows: [simple],
58
- slots: 100,
59
- });
60
-
61
- await worker.start();
62
- }
63
-
64
- if (require.main === module) {
65
- main();
66
- }
67
- ```
35
+ For examples of how to use the Hatchet TypeScript SDK, including worker setup and task execution, please see our [official documentation](https://docs.hatchet.run/home/setup).
68
36
 
69
37
  ## Features
70
38
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.1.2",
3
+ "version": "1.1.5",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -32,42 +32,11 @@
32
32
  "eslint:fix": "eslint \"{src,tests}/**/*.{ts,tsx,js}\" --fix",
33
33
  "prettier:check": "prettier \"src/**/*.{ts,tsx}\" --list-different",
34
34
  "prettier:fix": "prettier \"src/**/*.{ts,tsx}\" --write",
35
- "exec": "npx dotenv -- ts-node -r tsconfig-paths/register --project tsconfig.json",
36
- "example:event": "npm run exec -- ./src/examples/example-event.ts",
37
- "example:event-listen": "npm run exec -- ./src/examples/example-event-with-results.ts",
38
- "worker:namespaced": "npm run exec -- ./src/examples/namespaced-worker.ts",
39
- "worker:rate": "npm run exec -- ./src/examples/rate-limit/worker.ts",
40
- "example:rate": "npm run exec -- ./src/examples/rate-limit/events.ts",
41
- "worker:fanout": "npm run exec -- ./src/examples/fanout-worker.ts",
42
- "worker:simple": "npm run exec -- ./src/examples/simple-worker.ts",
43
- "worker:affinity": "npm run exec -- ./src/examples/affinity-workers.ts",
44
- "worker:sticky": "npm run exec -- ./src/examples/sticky-worker.ts",
45
- "worker:sticky-with-check": "npm run exec -- ./src/examples/sticky-worker-with-check.ts",
46
- "trigger:sticky": "npm run exec -- ./src/examples/sticky-trigger.ts",
47
- "worker:on-failure": "npm run exec -- ./src/examples/on-failure.ts",
48
- "manual:trigger": "npm run exec -- ./src/examples/manual-trigger.ts",
49
- "manual:meta": "npm run exec -- ./src/examples/stream-by-additional-meta.ts",
50
- "bulk:trigger": "npm run exec -- ./src/examples/bulk-trigger.ts",
51
- "bulk:fanout:worker": "npm run exec -- ./src/examples/bulk-fanout-worker.ts",
52
- "bulk:fanout:trigger": "npm run exec -- ./src/examples/bulk-fanout-trigger.ts",
53
- "worker:dag": "npm run exec -- ./src/examples/dag-worker.ts",
54
- "worker:concurrency": "npm run exec -- ./src/examples/concurrency/cancel-in-progress/concurrency-worker.ts",
55
- "event:concurrency": "npm run exec -- ./src/examples/concurrency/cancel-in-progress/concurrency-event.ts",
56
- "worker:concurrency:rr": "npm run exec -- ./src/examples/concurrency/group-round-robin/concurrency-worker-expression.ts",
57
- "event:concurrency:rr": "npm run exec -- ./src/examples/concurrency/group-round-robin/concurrency-event.ts",
58
- "worker:playground": "npm run exec -- ./src/examples/playground.ts",
59
- "worker:retries": "npm run exec -- ./src/examples/retries-worker.ts",
60
- "worker:retries-with-backoff": "npm run exec -- ./src/examples/retries-with-backoff.ts",
61
- "worker:multi-workflow": "npm run exec -- ./src/examples/multi-workflow.ts",
62
- "worker:logger": "npm run exec -- ./src/examples/logger.ts",
63
- "worker:byo-logger": "npm run exec -- ./src/examples/byo-logger.ts",
64
- "worker:no-retry": "npm run exec -- ./src/v1/examples/non_retryable/worker.ts",
65
- "worker:no-retry:trigger": "npm run exec -- ./src/v1/examples/non_retryable/run.ts",
66
- "api": "npm run exec -- ./src/examples/api.ts",
67
35
  "prepublish": "cp package.json dist/package.json; cp README.md dist/",
68
36
  "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",
69
37
  "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",
70
- "generate-docs": "typedoc"
38
+ "generate-docs": "typedoc",
39
+ "exec": "npx dotenv -- ts-node -r tsconfig-paths/register --project tsconfig.json"
71
40
  },
72
41
  "keywords": [],
73
42
  "author": "",
package/step.js CHANGED
@@ -413,10 +413,10 @@ class Context {
413
413
  return resp;
414
414
  });
415
415
  try {
416
- // Batch workflowRuns in groups of 500
416
+ const batchSize = 1000;
417
417
  let resp = [];
418
- for (let i = 0; i < workflowRuns.length; i += 500) {
419
- const batch = workflowRuns.slice(i, i + 500);
418
+ for (let i = 0; i < workflowRuns.length; i += batchSize) {
419
+ const batch = workflowRuns.slice(i, i + batchSize);
420
420
  const batchResp = yield this.client.admin.runWorkflows(batch);
421
421
  resp = resp.concat(batchResp);
422
422
  }
@@ -178,6 +178,11 @@ export declare class HatchetClient implements IHatchetClient {
178
178
  * @returns A workflows client instance
179
179
  */
180
180
  get workflows(): WorkflowsClient;
181
+ /**
182
+ * Get the tasks client for creating and managing tasks
183
+ * @returns A tasks client instance
184
+ */
185
+ get tasks(): WorkflowsClient;
181
186
  private _workers;
182
187
  /**
183
188
  * Get the workers client for creating and managing workers
@@ -241,6 +241,13 @@ class HatchetClient {
241
241
  }
242
242
  return this._workflows;
243
243
  }
244
+ /**
245
+ * Get the tasks client for creating and managing tasks
246
+ * @returns A tasks client instance
247
+ */
248
+ get tasks() {
249
+ return this.workflows;
250
+ }
244
251
  /**
245
252
  * Get the workers client for creating and managing workers
246
253
  * @returns A workers client instance
@@ -3,7 +3,7 @@ import { V1TaskStatus } from '../../../clients/rest/generated/data-contracts';
3
3
  import { WorkflowsClient } from './workflows';
4
4
  import { HatchetClient } from '../client';
5
5
  export type RunFilter = {
6
- since: Date;
6
+ since?: Date;
7
7
  until?: Date;
8
8
  statuses?: V1TaskStatus[];
9
9
  workflowNames?: string[];
@@ -17,6 +17,35 @@ export type ReplayRunOpts = {
17
17
  ids?: string[];
18
18
  filters?: RunFilter;
19
19
  };
20
+ export interface ListRunsOpts extends RunFilter {
21
+ /**
22
+ * The number to skip
23
+ * @format int64
24
+ */
25
+ offset?: number;
26
+ /**
27
+ * The number to limit by
28
+ * @format int64
29
+ */
30
+ limit?: number;
31
+ /** A list of statuses to filter by */
32
+ /**
33
+ * The worker id to filter by
34
+ * @format uuid
35
+ * @minLength 36
36
+ * @maxLength 36
37
+ */
38
+ workerId?: string;
39
+ /** Whether to include DAGs or only to include tasks */
40
+ onlyTasks: boolean;
41
+ /**
42
+ * The parent task external id to filter by
43
+ * @format uuid
44
+ * @minLength 36
45
+ * @maxLength 36
46
+ */
47
+ parentTaskExternalId?: string;
48
+ }
20
49
  /**
21
50
  * RunsClient is used to list and manage runs
22
51
  */
@@ -27,8 +56,9 @@ export declare class RunsClient {
27
56
  constructor(client: HatchetClient);
28
57
  get<T = any>(run: string | WorkflowRunRef<T>): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowRun>;
29
58
  getDetails<T = any>(run: string | WorkflowRunRef<T>): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowRunShape>;
30
- list(opts?: Parameters<typeof this.api.workflowRunList>[1]): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowRunList>;
59
+ list(opts?: Partial<ListRunsOpts>): Promise<import("../../../clients/rest/generated/data-contracts").V1TaskSummaryList>;
31
60
  cancel(opts: CancelRunOpts): Promise<import("axios").AxiosResponse<void, any>>;
32
61
  replay(opts: ReplayRunOpts): Promise<import("axios").AxiosResponse<void, any>>;
33
62
  private prepareFilter;
63
+ private prepareListFilter;
34
64
  }
@@ -35,37 +35,56 @@ class RunsClient {
35
35
  }
36
36
  list(opts) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
- // TODO workflow id on opts is a uuid
39
- const { data } = yield this.api.workflowRunList(this.tenantId, opts);
38
+ const { data } = yield this.api.v1WorkflowRunList(this.tenantId, Object.assign({}, (yield this.prepareListFilter(opts || {}))));
40
39
  return data;
41
40
  });
42
41
  }
43
42
  cancel(opts) {
44
43
  return __awaiter(this, void 0, void 0, function* () {
45
- const filter = opts.filters && (yield this.prepareFilter(opts.filters));
44
+ const filter = yield this.prepareFilter(opts.filters || {});
46
45
  return this.api.v1TaskCancel(this.tenantId, {
47
46
  externalIds: opts.ids,
48
- filter,
47
+ filter: !opts.ids ? filter : undefined,
49
48
  });
50
49
  });
51
50
  }
52
51
  replay(opts) {
53
52
  return __awaiter(this, void 0, void 0, function* () {
54
- const filter = opts.filters && (yield this.prepareFilter(opts.filters));
53
+ const filter = yield this.prepareFilter(opts.filters || {});
55
54
  return this.api.v1TaskReplay(this.tenantId, {
56
55
  externalIds: opts.ids,
57
- filter,
56
+ filter: !opts.ids ? filter : undefined,
58
57
  });
59
58
  });
60
59
  }
61
60
  prepareFilter(_a) {
62
61
  return __awaiter(this, arguments, void 0, function* ({ since, until, statuses, workflowNames, additionalMetadata, }) {
62
+ const am = Object.entries(additionalMetadata || {}).map(([key, value]) => `${key}:${value}`);
63
63
  return {
64
- since: since.toISOString(),
64
+ // default to 1 hour ago
65
+ since: since ? since.toISOString() : new Date(Date.now() - 1000 * 60 * 60).toISOString(),
65
66
  until: until === null || until === void 0 ? void 0 : until.toISOString(),
66
67
  statuses,
67
68
  workflowIds: yield Promise.all((workflowNames === null || workflowNames === void 0 ? void 0 : workflowNames.map((name) => __awaiter(this, void 0, void 0, function* () { return (yield this.workflows.get(name)).metadata.id; }))) || []),
68
- additionalMetadata: Object.entries(additionalMetadata || {}).map(([key, value]) => `${key}:${value}`),
69
+ additionalMetadata: am,
70
+ };
71
+ });
72
+ }
73
+ prepareListFilter(opts) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ var _a, _b;
76
+ const am = Object.entries(opts.additionalMetadata || {}).map(([key, value]) => `${key}:${value}`);
77
+ return {
78
+ // default to 1 hour ago
79
+ since: opts.since
80
+ ? opts.since.toISOString()
81
+ : new Date(Date.now() - 1000 * 60 * 60).toISOString(),
82
+ until: (_a = opts.until) === null || _a === void 0 ? void 0 : _a.toISOString(),
83
+ statuses: opts.statuses,
84
+ worker_id: opts.workerId,
85
+ workflow_ids: yield Promise.all(((_b = opts.workflowNames) === null || _b === void 0 ? void 0 : _b.map((name) => __awaiter(this, void 0, void 0, function* () { return (yield this.workflows.get(name)).metadata.id; }))) || []),
86
+ additional_metadata: am,
87
+ only_tasks: opts.onlyTasks || false,
69
88
  };
70
89
  });
71
90
  }
@@ -21,15 +21,18 @@ const hatchet_client_1 = require("../hatchet-client");
21
21
  function main() {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
23
  const run = workflow_1.cancellation.runNoWait({});
24
+ const run1 = workflow_1.cancellation.runNoWait({});
24
25
  yield (0, sleep_1.default)(1000);
25
26
  yield run.cancel();
26
27
  const res = yield run.output;
27
- console.log(res);
28
+ const res1 = yield run1.output;
29
+ console.log('canceled', res);
30
+ console.log('completed', res1);
28
31
  yield (0, sleep_1.default)(1000);
29
32
  yield run.replay();
30
33
  const resReplay = yield run.output;
31
34
  console.log(resReplay);
32
- const run2 = workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'test' } });
35
+ const run2 = workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'abc' } });
33
36
  const run4 = workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'test' } });
34
37
  yield (0, sleep_1.default)(1000);
35
38
  yield hatchet_client_1.hatchet.runs.cancel({
@@ -1,3 +1,4 @@
1
1
  export declare const cancellation: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
2
2
  Completed: true;
3
3
  }>;
4
+ export declare const abortSignal: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, void>;
@@ -12,11 +12,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.cancellation = void 0;
16
- // ❓ Declaring a Task
15
+ exports.abortSignal = exports.cancellation = void 0;
17
16
  const sleep_1 = __importDefault(require("../../../util/sleep"));
17
+ const axios_1 = __importDefault(require("axios"));
18
18
  const hatchet_client_1 = require("../hatchet-client");
19
- // (optional) Define the input type for the workflow
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,4 +30,26 @@ exports.cancellation = hatchet_client_1.hatchet.task({
30
30
  }),
31
31
  });
32
32
  // !!
33
+ // ❓ Abort Signal
34
+ exports.abortSignal = hatchet_client_1.hatchet.task({
35
+ name: 'abort-signal',
36
+ fn: (_1, _a) => __awaiter(void 0, [_1, _a], void 0, function* (_, { controller }) {
37
+ try {
38
+ const response = yield axios_1.default.get('https://api.example.com/data', {
39
+ signal: controller.signal,
40
+ });
41
+ // Handle the response
42
+ }
43
+ catch (error) {
44
+ if (axios_1.default.isCancel(error)) {
45
+ // Request was canceled
46
+ console.log('Request canceled');
47
+ }
48
+ else {
49
+ // Handle other errors
50
+ }
51
+ }
52
+ }),
53
+ });
54
+ // !!
33
55
  // see ./worker.ts and ./run.ts for how to run the workflow
@@ -15,6 +15,7 @@ function main() {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
16
  const worker = yield hatchet_client_1.hatchet.worker('child-workflow-worker', {
17
17
  workflows: [workflow_1.parent, workflow_1.child],
18
+ slots: 100,
18
19
  });
19
20
  yield worker.start();
20
21
  });
@@ -0,0 +1 @@
1
+ export declare const taskConditionWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
@@ -0,0 +1,107 @@
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
+ exports.taskConditionWorkflow = void 0;
13
+ // ❓ Create a workflow
14
+ const conditions_1 = require("../../conditions");
15
+ const parent_condition_1 = require("../../conditions/parent-condition");
16
+ const hatchet_client_1 = require("../hatchet-client");
17
+ exports.taskConditionWorkflow = hatchet_client_1.hatchet.workflow({
18
+ name: 'TaskConditionWorkflow',
19
+ });
20
+ // !!
21
+ // ❓ Add base task
22
+ const start = exports.taskConditionWorkflow.task({
23
+ name: 'start',
24
+ fn: () => {
25
+ return {
26
+ randomNumber: Math.floor(Math.random() * 100) + 1,
27
+ };
28
+ },
29
+ });
30
+ // !!
31
+ // ❓ Add wait for sleep
32
+ const waitForSleep = exports.taskConditionWorkflow.task({
33
+ name: 'waitForSleep',
34
+ parents: [start],
35
+ waitFor: [new conditions_1.SleepCondition('10s')],
36
+ fn: () => {
37
+ return {
38
+ randomNumber: Math.floor(Math.random() * 100) + 1,
39
+ };
40
+ },
41
+ });
42
+ // !!
43
+ // ❓ Add skip on event
44
+ const skipOnEvent = exports.taskConditionWorkflow.task({
45
+ name: 'skipOnEvent',
46
+ parents: [start],
47
+ waitFor: [new conditions_1.SleepCondition('10s')],
48
+ skipIf: [new conditions_1.UserEventCondition('skip_on_event:skip', 'true')],
49
+ fn: () => {
50
+ return {
51
+ randomNumber: Math.floor(Math.random() * 100) + 1,
52
+ };
53
+ },
54
+ });
55
+ // !!
56
+ // ❓ Add branching
57
+ const leftBranch = exports.taskConditionWorkflow.task({
58
+ name: 'leftBranch',
59
+ parents: [waitForSleep],
60
+ skipIf: [new parent_condition_1.ParentCondition(waitForSleep, 'output.randomNumber > 50')],
61
+ fn: () => {
62
+ return {
63
+ randomNumber: Math.floor(Math.random() * 100) + 1,
64
+ };
65
+ },
66
+ });
67
+ const rightBranch = exports.taskConditionWorkflow.task({
68
+ name: 'rightBranch',
69
+ parents: [waitForSleep],
70
+ skipIf: [new parent_condition_1.ParentCondition(waitForSleep, 'output.randomNumber <= 50')],
71
+ fn: () => {
72
+ return {
73
+ randomNumber: Math.floor(Math.random() * 100) + 1,
74
+ };
75
+ },
76
+ });
77
+ // !!
78
+ // ❓ Add wait for event
79
+ const waitForEvent = exports.taskConditionWorkflow.task({
80
+ name: 'waitForEvent',
81
+ parents: [start],
82
+ waitFor: [(0, conditions_1.Or)(new conditions_1.SleepCondition('1m'), new conditions_1.UserEventCondition('wait_for_event:start', 'true'))],
83
+ fn: () => {
84
+ return {
85
+ randomNumber: Math.floor(Math.random() * 100) + 1,
86
+ };
87
+ },
88
+ });
89
+ // !!
90
+ // ❓ Add sum
91
+ exports.taskConditionWorkflow.task({
92
+ name: 'sum',
93
+ parents: [start, waitForSleep, waitForEvent, skipOnEvent, leftBranch, rightBranch],
94
+ fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
95
+ var _a, _b, _c;
96
+ const one = (yield ctx.parentOutput(start)).randomNumber;
97
+ const two = (yield ctx.parentOutput(waitForEvent)).randomNumber;
98
+ const three = (yield ctx.parentOutput(waitForSleep)).randomNumber;
99
+ const four = ((_a = (yield ctx.parentOutput(skipOnEvent))) === null || _a === void 0 ? void 0 : _a.randomNumber) || 0;
100
+ const five = ((_b = (yield ctx.parentOutput(leftBranch))) === null || _b === void 0 ? void 0 : _b.randomNumber) || 0;
101
+ const six = ((_c = (yield ctx.parentOutput(rightBranch))) === null || _c === void 0 ? void 0 : _c.randomNumber) || 0;
102
+ return {
103
+ sum: one + two + three + four + five + six,
104
+ };
105
+ }),
106
+ });
107
+ // !!
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
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
+ const event = yield hatchet_client_1.hatchet.events.push('user:update', {
16
+ userId: '1234',
17
+ });
18
+ });
19
+ }
20
+ if (require.main === module) {
21
+ main()
22
+ .then(() => process.exit(0))
23
+ .catch((error) => {
24
+ // eslint-disable-next-line no-console
25
+ console.error('Error:', error);
26
+ process.exit(1);
27
+ });
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
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
+ const timeStart = Date.now();
16
+ const res = yield workflow_1.durableEvent.run({});
17
+ const timeEnd = Date.now();
18
+ // eslint-disable-next-line no-console
19
+ console.log(`Time taken: ${timeEnd - timeStart}ms`);
20
+ });
21
+ }
22
+ if (require.main === module) {
23
+ main()
24
+ .then(() => process.exit(0))
25
+ .catch((error) => {
26
+ // eslint-disable-next-line no-console
27
+ console.error('Error:', error);
28
+ process.exit(1);
29
+ });
30
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
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('durable-event-worker', {
17
+ workflows: [workflow_1.durableEvent],
18
+ });
19
+ yield worker.start();
20
+ });
21
+ }
22
+ if (require.main === module) {
23
+ main();
24
+ }
@@ -0,0 +1,6 @@
1
+ export declare const durableEvent: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
2
+ Value: string;
3
+ }>;
4
+ export declare const durableEventWithFilter: import("../..").TaskWorkflowDeclaration<import("../..").JsonObject, {
5
+ Value: string;
6
+ }>;
@@ -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
+ exports.durableEventWithFilter = exports.durableEvent = void 0;
13
+ // import sleep from '../../../util/sleep.js';
14
+ const hatchet_client_1 = require("../hatchet-client");
15
+ // ❓ Durable Event
16
+ exports.durableEvent = hatchet_client_1.hatchet.durableTask({
17
+ name: 'durable-event',
18
+ executionTimeout: '10m',
19
+ fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
20
+ const res = ctx.waitFor({
21
+ eventKey: 'user:update',
22
+ });
23
+ console.log('res', res);
24
+ return {
25
+ Value: 'done',
26
+ };
27
+ }),
28
+ });
29
+ // !!
30
+ exports.durableEventWithFilter = hatchet_client_1.hatchet.durableTask({
31
+ name: 'durable-event-with-filter',
32
+ executionTimeout: '10m',
33
+ fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
34
+ // ❓ Durable Event With Filter
35
+ const res = ctx.waitFor({
36
+ eventKey: 'user:update',
37
+ expression: "input.userId == '1234'",
38
+ });
39
+ // !!
40
+ console.log('res', res);
41
+ return {
42
+ Value: 'done',
43
+ };
44
+ }),
45
+ });
46
+ // !!
@@ -11,11 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.durableSleep = void 0;
13
13
  // import sleep from '../../../util/sleep.js';
14
- const conditions_1 = require("../../conditions");
15
14
  const hatchet_client_1 = require("../hatchet-client");
16
15
  exports.durableSleep = hatchet_client_1.hatchet.workflow({
17
16
  name: 'durable-sleep',
18
17
  });
18
+ // ❓ Durable Sleep
19
19
  exports.durableSleep.durableTask({
20
20
  name: 'durable-sleep',
21
21
  executionTimeout: '10m',
@@ -23,15 +23,9 @@ exports.durableSleep.durableTask({
23
23
  console.log('sleeping for 5s');
24
24
  const sleepRes = yield ctx.sleepFor('5s');
25
25
  console.log('done sleeping for 5s', sleepRes);
26
- // wait for either an event or a sleep
27
- const res = yield ctx.waitFor((0, conditions_1.Or)({
28
- eventKey: 'user:event',
29
- }, {
30
- sleepFor: '1m',
31
- }));
32
- console.log('res', res);
33
26
  return {
34
27
  Value: 'done',
35
28
  };
36
29
  }),
37
30
  });
31
+ // !!
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.1.2";
1
+ export declare const HATCHET_VERSION = "1.1.5";
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.1.2';
4
+ exports.HATCHET_VERSION = '1.1.5';