@hatchet-dev/typescript-sdk 1.3.2 → 1.4.0-alpha.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 (42) hide show
  1. package/clients/dispatcher/heartbeat/heartbeat-worker.js +3 -2
  2. package/clients/hatchet-client/hatchet-client.d.ts +3 -5
  3. package/clients/hatchet-client/hatchet-client.js +11 -72
  4. package/clients/worker/worker.d.ts +6 -9
  5. package/clients/worker/worker.js +2 -164
  6. package/examples/fanout-worker.js +1 -2
  7. package/examples/manual-trigger.js +1 -1
  8. package/package.json +3 -2
  9. package/step.d.ts +13 -11
  10. package/step.js +44 -40
  11. package/util/grpc-helpers.d.ts +10 -0
  12. package/util/grpc-helpers.js +79 -0
  13. package/v1/client/admin.d.ts +64 -0
  14. package/v1/client/admin.js +155 -0
  15. package/v1/client/client.d.ts +14 -9
  16. package/v1/client/client.interface.d.ts +4 -2
  17. package/v1/client/client.js +28 -16
  18. package/v1/client/worker/context.d.ts +246 -0
  19. package/v1/client/worker/context.js +512 -0
  20. package/v1/client/worker/worker-internal.d.ts +62 -0
  21. package/v1/client/worker/worker-internal.js +703 -0
  22. package/v1/client/{worker.d.ts → worker/worker.d.ts} +15 -15
  23. package/v1/client/{worker.js → worker/worker.js} +14 -11
  24. package/v1/declaration.d.ts +3 -3
  25. package/v1/declaration.js +21 -14
  26. package/v1/examples/cancellations/run.js +4 -4
  27. package/v1/examples/cancellations/workflow.js +2 -2
  28. package/v1/examples/high-memory/child-worker.js +29 -0
  29. package/v1/examples/high-memory/parent-worker.d.ts +1 -0
  30. package/v1/examples/high-memory/parent-worker.js +29 -0
  31. package/v1/examples/high-memory/run.d.ts +1 -0
  32. package/v1/examples/high-memory/run.js +27 -0
  33. package/v1/examples/high-memory/workflow-with-child.d.ts +12 -0
  34. package/v1/examples/high-memory/workflow-with-child.js +48 -0
  35. package/v1/examples/with_timeouts/workflow.js +4 -4
  36. package/v1/index.d.ts +1 -1
  37. package/v1/index.js +1 -1
  38. package/v1/task.d.ts +2 -1
  39. package/version.d.ts +1 -1
  40. package/version.js +1 -1
  41. package/examples/api.js +0 -61
  42. /package/{examples/api.d.ts → v1/examples/high-memory/child-worker.d.ts} +0 -0
@@ -1,10 +1,10 @@
1
- import { WorkerLabels } from '../../clients/dispatcher/dispatcher-client';
2
- import { InternalHatchetClient } from '../../clients/hatchet-client';
3
- import { V0Worker } from '../../clients/worker';
4
- import { Workflow as V0Workflow } from '../../workflow';
5
- import { WebhookWorkerCreateRequest } from '../../clients/rest/generated/data-contracts';
6
- import { BaseWorkflowDeclaration } from '../declaration';
7
- import { HatchetClient } from '..';
1
+ import { WorkerLabels } from '../../../clients/dispatcher/dispatcher-client';
2
+ import { LegacyHatchetClient } from '../../../clients/hatchet-client';
3
+ import { Workflow as V0Workflow } from '../../../workflow';
4
+ import { WebhookWorkerCreateRequest } from '../../../clients/rest/generated/data-contracts';
5
+ import { BaseWorkflowDeclaration } from '../../declaration';
6
+ import { HatchetClient } from '../..';
7
+ import { V1Worker } from './worker-internal';
8
8
  /**
9
9
  * Options for creating a new hatchet worker
10
10
  * @interface CreateWorkerOpts
@@ -30,35 +30,35 @@ export declare class Worker {
30
30
  config: CreateWorkerOpts;
31
31
  name: string;
32
32
  _v1: HatchetClient;
33
- _v0: InternalHatchetClient;
33
+ _v0: LegacyHatchetClient;
34
34
  /** Internal reference to the underlying V0 worker implementation */
35
- nonDurable: V0Worker;
36
- durable?: V0Worker;
35
+ nonDurable: V1Worker;
36
+ durable?: V1Worker;
37
37
  /**
38
38
  * Creates a new HatchetWorker instance
39
39
  * @param nonDurable - The V0 worker implementation
40
40
  */
41
- constructor(v1: HatchetClient, v0: InternalHatchetClient, nonDurable: V0Worker, config: CreateWorkerOpts, name: string);
41
+ constructor(v1: HatchetClient, v0: LegacyHatchetClient, nonDurable: V1Worker, config: CreateWorkerOpts, name: string);
42
42
  /**
43
43
  * Creates and initializes a new HatchetWorker
44
44
  * @param v0 - The HatchetClient instance
45
45
  * @param options - Worker creation options
46
46
  * @returns A new HatchetWorker instance
47
47
  */
48
- static create(v1: HatchetClient, v0: InternalHatchetClient, name: string, options: CreateWorkerOpts): Promise<Worker>;
48
+ static create(v1: HatchetClient, v0: LegacyHatchetClient, name: string, options: CreateWorkerOpts): Promise<Worker>;
49
49
  /**
50
50
  * Registers workflows with the worker
51
51
  * @param workflows - Array of workflows to register
52
52
  * @returns Array of registered workflow promises
53
53
  */
54
- registerWorkflows(workflows?: Array<BaseWorkflowDeclaration<any, any> | V0Workflow>): Promise<void>;
54
+ registerWorkflows(workflows?: Array<BaseWorkflowDeclaration<any, any> | V0Workflow>): Promise<void[]>;
55
55
  /**
56
56
  * Registers a single workflow with the worker
57
57
  * @param workflow - The workflow to register
58
58
  * @returns A promise that resolves when the workflow is registered
59
59
  * @deprecated use registerWorkflows instead
60
60
  */
61
- registerWorkflow(workflow: BaseWorkflowDeclaration<any, any> | V0Workflow): Promise<void>;
61
+ registerWorkflow(workflow: BaseWorkflowDeclaration<any, any> | V0Workflow): Promise<void[]>;
62
62
  /**
63
63
  * Starts the worker
64
64
  * @returns Promise that resolves when the worker is stopped or killed
@@ -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[]>;
@@ -10,7 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Worker = void 0;
13
- const declaration_1 = require("../declaration");
13
+ const declaration_1 = require("../../declaration");
14
+ const worker_internal_1 = require("./worker-internal");
14
15
  const DEFAULT_DURABLE_SLOTS = 1000;
15
16
  /**
16
17
  * HatchetWorker class for workflow execution runtime
@@ -35,8 +36,9 @@ class Worker {
35
36
  */
36
37
  static create(v1, v0, name, options) {
37
38
  return __awaiter(this, void 0, void 0, function* () {
38
- const v0worker = yield v0.worker(name, Object.assign(Object.assign({}, options), { maxRuns: options.slots || options.maxRuns }));
39
- const worker = new Worker(v1, v0, v0worker, options, name);
39
+ const opts = Object.assign(Object.assign({ name }, options), { maxRuns: options.slots || options.maxRuns });
40
+ const internalWorker = new worker_internal_1.V1Worker(v1, opts);
41
+ const worker = new Worker(v1, v0, internalWorker, options, name);
40
42
  yield worker.registerWorkflows(options.workflows);
41
43
  return worker;
42
44
  });
@@ -48,22 +50,23 @@ class Worker {
48
50
  */
49
51
  registerWorkflows(workflows) {
50
52
  return __awaiter(this, void 0, void 0, function* () {
51
- for (const wf of workflows || []) {
53
+ return Promise.all((workflows === null || workflows === void 0 ? void 0 : workflows.map((wf) => __awaiter(this, void 0, void 0, function* () {
52
54
  if (wf instanceof declaration_1.BaseWorkflowDeclaration) {
53
55
  // TODO check if tenant is V1
54
- yield this.nonDurable.registerWorkflowV1(wf);
56
+ const register = this.nonDurable.registerWorkflowV1(wf);
55
57
  if (wf.definition._durableTasks.length > 0) {
56
58
  if (!this.durable) {
57
- this.durable = yield this._v0.worker(`${this.name}-durable`, Object.assign(Object.assign({}, this.config), { maxRuns: this.config.durableSlots || DEFAULT_DURABLE_SLOTS }));
59
+ const opts = Object.assign(Object.assign({ name: `${this.name}-durable` }, this.config), { maxRuns: this.config.durableSlots || DEFAULT_DURABLE_SLOTS });
60
+ this.durable = new worker_internal_1.V1Worker(this._v1, opts);
61
+ yield this.durable.registerWorkflowV1(wf);
58
62
  }
59
63
  this.durable.registerDurableActionsV1(wf.definition);
60
64
  }
65
+ return register;
61
66
  }
62
- else {
63
- // fallback to v0 client for backwards compatibility
64
- yield this.nonDurable.registerWorkflow(wf);
65
- }
66
- }
67
+ // fallback to v0 client for backwards compatibility
68
+ return this.nonDurable.registerWorkflow(wf);
69
+ }))) || []);
67
70
  });
68
71
  }
69
72
  /**
@@ -1,5 +1,4 @@
1
1
  import WorkflowRunRef from '../util/workflow-run-ref';
2
- import { Context, DurableContext } from '../step';
3
2
  import { CronWorkflows, ScheduledWorkflows } from '../clients/rest/generated/data-contracts';
4
3
  import { Workflow as WorkflowV0 } from '../workflow';
5
4
  import { IHatchetClient } from './client/client.interface';
@@ -7,6 +6,7 @@ import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskFn, CreateWorkflow
7
6
  import { Duration } from './client/duration';
8
7
  import { MetricsClient } from './client/features/metrics';
9
8
  import { InputType, OutputType, UnknownInputType, JsonObject } from './types';
9
+ import { Context, DurableContext } from './client/worker/context';
10
10
  export declare enum Priority {
11
11
  LOW = 1,
12
12
  MEDIUM = 2,
@@ -191,7 +191,7 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
191
191
  * @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
192
192
  * @throws Error if the workflow is not bound to a Hatchet client.
193
193
  */
194
- runNoWait(input: I, options?: RunOpts, _standaloneTaskName?: string): WorkflowRunRef<O>;
194
+ runNoWait(input: I, options?: RunOpts, _standaloneTaskName?: string): Promise<WorkflowRunRef<O>>;
195
195
  /**
196
196
  * @alias run
197
197
  * Triggers a workflow run and waits for the result.
@@ -329,7 +329,7 @@ export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputT
329
329
  * @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
330
330
  * @throws Error if the workflow is not bound to a Hatchet client.
331
331
  */
332
- runNoWait(input: I, options?: RunOpts): WorkflowRunRef<O>;
332
+ runNoWait(input: I, options?: RunOpts): Promise<WorkflowRunRef<O>>;
333
333
  get taskDef(): CreateWorkflowTaskOpts<any, any>;
334
334
  }
335
335
  /**
package/v1/declaration.js CHANGED
@@ -44,14 +44,16 @@ class BaseWorkflowDeclaration {
44
44
  * @throws Error if the workflow is not bound to a Hatchet client.
45
45
  */
46
46
  runNoWait(input, options, _standaloneTaskName) {
47
- if (!this.client) {
48
- throw UNBOUND_ERR;
49
- }
50
- const res = this.client._v0.admin.runWorkflow(this.name, input, options);
51
- if (_standaloneTaskName) {
52
- res._standalone_task_name = _standaloneTaskName;
53
- }
54
- return res;
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
+ });
55
57
  }
56
58
  runAndWait(input, options, _standaloneTaskName) {
57
59
  return __awaiter(this, void 0, void 0, function* () {
@@ -73,7 +75,7 @@ class BaseWorkflowDeclaration {
73
75
  let resp = [];
74
76
  for (let i = 0; i < input.length; i += 500) {
75
77
  const batch = input.slice(i, i + 500);
76
- const batchResp = yield this.client._v0.admin.runWorkflows(batch.map((inp) => ({
78
+ const batchResp = yield this.client.admin.runWorkflows(batch.map((inp) => ({
77
79
  workflowName: this.definition.name,
78
80
  input: inp,
79
81
  options,
@@ -91,7 +93,7 @@ class BaseWorkflowDeclaration {
91
93
  });
92
94
  return Promise.all(res);
93
95
  }
94
- const res = this.client._v0.admin.runWorkflow(this.definition.name, input, options);
96
+ const res = yield this.client.admin.runWorkflow(this.definition.name, input, options);
95
97
  if (_standaloneTaskName) {
96
98
  res._standalone_task_name = _standaloneTaskName;
97
99
  }
@@ -322,10 +324,15 @@ class TaskWorkflowDeclaration extends BaseWorkflowDeclaration {
322
324
  * @throws Error if the workflow is not bound to a Hatchet client.
323
325
  */
324
326
  runNoWait(input, options) {
325
- if (!this.client) {
326
- throw UNBOUND_ERR;
327
- }
328
- return super.runNoWait(input, options, this._standalone_task_name);
327
+ const _super = Object.create(null, {
328
+ runNoWait: { get: () => super.runNoWait }
329
+ });
330
+ 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);
335
+ });
329
336
  }
330
337
  get taskDef() {
331
338
  return this.definition._tasks[0];
@@ -20,8 +20,8 @@ const hatchet_client_1 = require("../hatchet-client");
20
20
  // ...
21
21
  function main() {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
- const run = workflow_1.cancellation.runNoWait({});
24
- const run1 = workflow_1.cancellation.runNoWait({});
23
+ const run = yield workflow_1.cancellation.runNoWait({});
24
+ const run1 = yield workflow_1.cancellation.runNoWait({});
25
25
  yield (0, sleep_1.default)(1000);
26
26
  yield run.cancel();
27
27
  const res = yield run.output;
@@ -32,8 +32,8 @@ function main() {
32
32
  yield run.replay();
33
33
  const resReplay = yield run.output;
34
34
  console.log(resReplay);
35
- const run2 = workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'abc' } });
36
- const run4 = workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'test' } });
35
+ const run2 = yield workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'abc' } });
36
+ const run4 = yield workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'test' } });
37
37
  yield (0, sleep_1.default)(1000);
38
38
  yield hatchet_client_1.hatchet.runs.cancel({
39
39
  filters: {
@@ -33,10 +33,10 @@ exports.cancellation = hatchet_client_1.hatchet.task({
33
33
  // ❓ Abort Signal
34
34
  exports.abortSignal = hatchet_client_1.hatchet.task({
35
35
  name: 'abort-signal',
36
- fn: (_1, _a) => __awaiter(void 0, [_1, _a], void 0, function* (_, { controller }) {
36
+ fn: (_1, _a) => __awaiter(void 0, [_1, _a], void 0, function* (_, { abortController }) {
37
37
  try {
38
38
  const response = yield axios_1.default.get('https://api.example.com/data', {
39
- signal: controller.signal,
39
+ signal: abortController.signal,
40
40
  });
41
41
  // Handle the response
42
42
  }
@@ -0,0 +1,29 @@
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
+ // ❓ Declaring a Worker
13
+ const hatchet_client_1 = require("../hatchet-client");
14
+ const workflow_with_child_1 = require("./workflow-with-child");
15
+ function main() {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const worker = yield hatchet_client_1.hatchet.worker('child-worker', {
18
+ // 👀 Declare the workflows that the worker can execute
19
+ workflows: [workflow_with_child_1.child],
20
+ // 👀 Declare the number of concurrent task runs the worker can accept
21
+ slots: 1000,
22
+ });
23
+ yield worker.start();
24
+ });
25
+ }
26
+ if (require.main === module) {
27
+ main();
28
+ }
29
+ // !!
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
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
+ // ❓ Declaring a Worker
13
+ const hatchet_client_1 = require("../hatchet-client");
14
+ const workflow_with_child_1 = require("./workflow-with-child");
15
+ function main() {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const worker = yield hatchet_client_1.hatchet.worker('parent-worker', {
18
+ // 👀 Declare the workflows that the worker can execute
19
+ workflows: [workflow_with_child_1.parent],
20
+ // 👀 Declare the number of concurrent task runs the worker can accept
21
+ slots: 20,
22
+ });
23
+ yield worker.start();
24
+ });
25
+ }
26
+ if (require.main === module) {
27
+ main();
28
+ }
29
+ // !!
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
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
+ /* eslint-disable no-console */
13
+ const workflow_with_child_1 = require("./workflow-with-child");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ // ❓ Running a Task
17
+ const res = yield workflow_with_child_1.parent.run({
18
+ Message: 'HeLlO WoRlD',
19
+ });
20
+ // 👀 Access the results of the Task
21
+ console.log(res.TransformedMessage);
22
+ // !!
23
+ });
24
+ }
25
+ if (require.main === module) {
26
+ main();
27
+ }
@@ -0,0 +1,12 @@
1
+ export type ChildInput = {
2
+ Message: string;
3
+ };
4
+ export type ParentInput = {
5
+ Message: string;
6
+ };
7
+ export declare const child: import("../..").TaskWorkflowDeclaration<ChildInput, {
8
+ TransformedMessage: string;
9
+ }>;
10
+ export declare const parent: import("../..").TaskWorkflowDeclaration<ParentInput, {
11
+ TransformedMessage: string;
12
+ }>;
@@ -0,0 +1,48 @@
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.parent = exports.child = void 0;
13
+ // ❓ Declaring a Task
14
+ const hatchet_client_1 = require("../hatchet-client");
15
+ exports.child = hatchet_client_1.hatchet.task({
16
+ name: 'child',
17
+ fn: (input) => {
18
+ const largePayload = new Array(1024 * 1024).fill('a').join('');
19
+ return {
20
+ TransformedMessage: largePayload,
21
+ };
22
+ },
23
+ });
24
+ exports.parent = hatchet_client_1.hatchet.task({
25
+ name: 'parent',
26
+ timeout: '10m',
27
+ fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
28
+ // lets generate large payload 1 mb
29
+ const largePayload = new Array(1024 * 1024).fill('a').join('');
30
+ // Send the large payload 100 times
31
+ const num = 1000;
32
+ const children = [];
33
+ for (let i = 0; i < num; i += 1) {
34
+ children.push({
35
+ workflow: exports.child,
36
+ input: {
37
+ Message: `Iteration ${i + 1}: ${largePayload}`,
38
+ },
39
+ });
40
+ }
41
+ yield ctx.bulkRunNoWaitChildren(children);
42
+ return {
43
+ TransformedMessage: 'done',
44
+ };
45
+ }),
46
+ });
47
+ // !!
48
+ // see ./worker.ts and ./run.ts for how to run the workflow
@@ -27,9 +27,9 @@ exports.withTimeouts = hatchet_client_1.hatchet.task({
27
27
  // wait 15 seconds
28
28
  yield (0, sleep_1.default)(15000);
29
29
  // get the abort controller
30
- const { controller } = ctx;
30
+ const { abortController } = ctx;
31
31
  // if the abort controller is aborted, throw an error
32
- if (controller.signal.aborted) {
32
+ if (abortController.signal.aborted) {
33
33
  throw new Error('cancelled');
34
34
  }
35
35
  return {
@@ -48,10 +48,10 @@ exports.refreshTimeout = hatchet_client_1.hatchet.task({
48
48
  ctx.refreshTimeout('15s');
49
49
  yield (0, sleep_1.default)(15000);
50
50
  // get the abort controller
51
- const { controller } = ctx;
51
+ const { abortController } = ctx;
52
52
  // now this condition will not be met
53
53
  // if the abort controller is aborted, throw an error
54
- if (controller.signal.aborted) {
54
+ if (abortController.signal.aborted) {
55
55
  throw new Error('cancelled');
56
56
  }
57
57
  return {
package/v1/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './client/client';
2
2
  export * from './client/features';
3
- export * from './client/worker';
3
+ export * from './client/worker/worker';
4
4
  export * from './declaration';
5
5
  export * from './conditions';
6
6
  export * from './client/duration';
package/v1/index.js CHANGED
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./client/client"), exports);
18
18
  __exportStar(require("./client/features"), exports);
19
- __exportStar(require("./client/worker"), exports);
19
+ __exportStar(require("./client/worker/worker"), exports);
20
20
  __exportStar(require("./declaration"), exports);
21
21
  __exportStar(require("./conditions"), exports);
22
22
  __exportStar(require("./client/duration"), exports);
package/v1/task.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { ConcurrencyLimitStrategy } from '../protoc/v1/workflows';
2
- import { Context, CreateStep, DurableContext } from '../step';
2
+ import { CreateStep } from '../step';
3
3
  import { Conditions } from './conditions';
4
4
  import { Duration } from './client/duration';
5
5
  import { InputType, OutputType, UnknownInputType } from './types';
6
+ import { Context, DurableContext } from './client/worker/context';
6
7
  /**
7
8
  * Options for configuring the concurrency for a task.
8
9
  */
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.3.2";
1
+ export declare const HATCHET_VERSION = "1.4.0-alpha.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.3.2';
4
+ exports.HATCHET_VERSION = '1.4.0-alpha.2';
package/examples/api.js DELETED
@@ -1,61 +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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const __1 = __importDefault(require(".."));
16
- const opts = {
17
- name: 'api-workflow',
18
- description: 'My workflow',
19
- version: '',
20
- eventTriggers: [],
21
- cronTriggers: [],
22
- scheduledTriggers: [],
23
- concurrency: undefined,
24
- jobs: [
25
- {
26
- name: 'my-job',
27
- description: 'Job description',
28
- steps: [
29
- {
30
- retries: 0,
31
- readableId: 'custom-step',
32
- action: `slack:example`,
33
- timeout: '60s',
34
- inputs: '{}',
35
- parents: [],
36
- workerLabels: {},
37
- userData: `{
38
- "example": "value"
39
- }`,
40
- rateLimits: [],
41
- },
42
- ],
43
- },
44
- ],
45
- };
46
- function main() {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- const hatchet = __1.default.init();
49
- const { admin } = hatchet;
50
- yield admin.putWorkflow(opts);
51
- const worker = yield hatchet.worker('example-worker');
52
- worker.nonDurable.registerAction('slack:example', (ctx) => __awaiter(this, void 0, void 0, function* () {
53
- const setData = ctx.userData();
54
- console.log('executed step1!', setData);
55
- return { step1: 'step1' };
56
- }));
57
- yield hatchet.admin.runWorkflow('api-workflow', {});
58
- worker.start();
59
- });
60
- }
61
- main();