@hatchet-dev/typescript-sdk 0.20.2 → 1.0.0-alpha0

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 (95) hide show
  1. package/clients/hatchet-client/features/cron-client.d.ts +0 -1
  2. package/clients/hatchet-client/features/cron-client.js +6 -3
  3. package/clients/hatchet-client/hatchet-client.d.ts +8 -7
  4. package/clients/hatchet-client/hatchet-client.js +9 -8
  5. package/clients/hatchet-client/hatchet-logger.js +2 -2
  6. package/clients/listener/listener-client.js +1 -0
  7. package/clients/rest/generated/Api.d.ts +201 -1
  8. package/clients/rest/generated/Api.js +108 -0
  9. package/clients/rest/generated/data-contracts.d.ts +270 -8
  10. package/clients/rest/generated/data-contracts.js +20 -1
  11. package/clients/worker/handler.d.ts +2 -2
  12. package/clients/worker/worker.d.ts +4 -4
  13. package/clients/worker/worker.js +3 -3
  14. package/examples/api.js +1 -1
  15. package/examples/example-event-with-results.js +1 -1
  16. package/examples/stream-by-additional-meta.js +1 -1
  17. package/index.d.ts +3 -1
  18. package/index.js +5 -3
  19. package/package.json +2 -2
  20. package/protoc/dispatcher/dispatcher.d.ts +2 -0
  21. package/protoc/dispatcher/dispatcher.js +17 -1
  22. package/protoc/workflows/v1-admin.d.ts +79 -0
  23. package/protoc/workflows/v1-admin.js +529 -0
  24. package/sdk.d.ts +1 -1
  25. package/sdk.js +2 -2
  26. package/step.d.ts +75 -9
  27. package/step.js +65 -2
  28. package/util/hatchet-promise/hatchet-promise.js +1 -0
  29. package/v1/client/client.d.ts +81 -0
  30. package/v1/client/client.interface.d.ts +4 -0
  31. package/v1/client/client.interface.js +2 -0
  32. package/v1/client/client.js +134 -0
  33. package/v1/client/worker.d.ts +82 -0
  34. package/v1/client/worker.js +125 -0
  35. package/v1/examples/child_workflows/run.d.ts +1 -0
  36. package/v1/examples/child_workflows/run.js +30 -0
  37. package/v1/examples/child_workflows/worker.d.ts +1 -0
  38. package/v1/examples/child_workflows/worker.js +24 -0
  39. package/v1/examples/child_workflows/workflow.d.ts +19 -0
  40. package/v1/examples/child_workflows/workflow.js +43 -0
  41. package/v1/examples/client.d.ts +2 -0
  42. package/v1/examples/client.js +5 -0
  43. package/v1/examples/concurrency-rr/load.d.ts +1 -0
  44. package/v1/examples/concurrency-rr/load.js +54 -0
  45. package/v1/examples/concurrency-rr/run.d.ts +1 -0
  46. package/v1/examples/concurrency-rr/run.js +39 -0
  47. package/v1/examples/concurrency-rr/worker.d.ts +1 -0
  48. package/v1/examples/concurrency-rr/worker.js +24 -0
  49. package/v1/examples/concurrency-rr/workflow.d.ts +11 -0
  50. package/v1/examples/concurrency-rr/workflow.js +35 -0
  51. package/v1/examples/dag/run.d.ts +1 -0
  52. package/v1/examples/dag/run.js +24 -0
  53. package/v1/examples/dag/worker.d.ts +1 -0
  54. package/v1/examples/dag/worker.js +24 -0
  55. package/v1/examples/dag/workflow.d.ts +11 -0
  56. package/v1/examples/dag/workflow.js +35 -0
  57. package/v1/examples/deep/run.d.ts +1 -0
  58. package/v1/examples/deep/run.js +28 -0
  59. package/v1/examples/deep/worker.d.ts +1 -0
  60. package/v1/examples/deep/worker.js +25 -0
  61. package/v1/examples/deep/workflow.d.ts +18 -0
  62. package/v1/examples/deep/workflow.js +110 -0
  63. package/v1/examples/legacy/run.d.ts +1 -0
  64. package/v1/examples/legacy/run.js +25 -0
  65. package/v1/examples/legacy/worker.d.ts +1 -0
  66. package/v1/examples/legacy/worker.js +24 -0
  67. package/v1/examples/legacy/workflow.d.ts +2 -0
  68. package/v1/examples/legacy/workflow.js +36 -0
  69. package/v1/examples/on_event/event.d.ts +1 -0
  70. package/v1/examples/on_event/event.js +25 -0
  71. package/v1/examples/on_event/worker.d.ts +1 -0
  72. package/v1/examples/on_event/worker.js +24 -0
  73. package/v1/examples/on_event/workflow.d.ts +17 -0
  74. package/v1/examples/on_event/workflow.js +33 -0
  75. package/v1/examples/simple/cron.d.ts +1 -0
  76. package/v1/examples/simple/cron.js +26 -0
  77. package/v1/examples/simple/delay.d.ts +1 -0
  78. package/v1/examples/simple/delay.js +27 -0
  79. package/v1/examples/simple/run.d.ts +1 -0
  80. package/v1/examples/simple/run.js +24 -0
  81. package/v1/examples/simple/schedule.d.ts +1 -0
  82. package/v1/examples/simple/schedule.js +27 -0
  83. package/v1/examples/simple/worker.d.ts +1 -0
  84. package/v1/examples/simple/worker.js +24 -0
  85. package/v1/examples/simple/workflow.d.ts +5 -0
  86. package/v1/examples/simple/workflow.js +15 -0
  87. package/v1/index.d.ts +0 -0
  88. package/v1/index.js +1 -0
  89. package/v1/task.d.ts +51 -0
  90. package/v1/task.js +2 -0
  91. package/v1/workflow.d.ts +152 -0
  92. package/v1/workflow.js +145 -0
  93. package/version.d.ts +1 -1
  94. package/version.js +1 -1
  95. package/workflow.d.ts +3 -0
package/step.d.ts CHANGED
@@ -3,11 +3,13 @@ import { Workflow } from './workflow';
3
3
  import { Action } from './clients/dispatcher/action-listener';
4
4
  import { LogLevel } from './clients/event/event-client';
5
5
  import { Logger } from './util/logger';
6
- import { HatchetClient } from './clients/hatchet-client';
6
+ import { InternalHatchetClient } from './clients/hatchet-client';
7
7
  import WorkflowRunRef from './util/workflow-run-ref';
8
- import { Worker } from './clients/worker';
8
+ import { V0Worker } from './clients/worker';
9
9
  import { WorkerLabels } from './clients/dispatcher/dispatcher-client';
10
10
  import { CreateStepRateLimit, RateLimitDuration, WorkerLabelComparator } from './protoc/workflows';
11
+ import { CreateTaskOpts } from './v1/task';
12
+ import { Workflow as WorkflowV1 } from './v1/workflow';
11
13
  export declare const CreateRateLimitSchema: z.ZodObject<{
12
14
  key: z.ZodOptional<z.ZodString>;
13
15
  staticKey: z.ZodOptional<z.ZodString>;
@@ -166,7 +168,7 @@ interface ContextData<T, K> {
166
168
  }
167
169
  export declare class ContextWorker {
168
170
  private worker;
169
- constructor(worker: Worker);
171
+ constructor(worker: V0Worker);
170
172
  id(): string | undefined;
171
173
  hasWorkflow(workflowName: string): boolean;
172
174
  labels(): WorkerLabels;
@@ -177,13 +179,14 @@ export declare class Context<T, K = {}> {
177
179
  input: T;
178
180
  controller: AbortController;
179
181
  action: Action;
180
- client: HatchetClient;
182
+ client: InternalHatchetClient;
181
183
  worker: ContextWorker;
182
184
  overridesData: Record<string, any>;
183
185
  logger: Logger;
184
186
  spawnIndex: number;
185
- constructor(action: Action, client: HatchetClient, worker: Worker);
186
- stepOutput(step: string): NextStep;
187
+ constructor(action: Action, client: InternalHatchetClient, worker: V0Worker);
188
+ parentData<L = NextStep>(task: CreateTaskOpts<any, L> | string): Promise<L>;
189
+ stepOutput<L = NextStep>(step: string): L;
187
190
  stepRunErrors(): Record<string, string>;
188
191
  triggeredByEvent(): boolean;
189
192
  workflowInput(): T;
@@ -203,14 +206,43 @@ export declare class Context<T, K = {}> {
203
206
  refreshTimeout(incrementBy: string): Promise<void>;
204
207
  releaseSlot(): Promise<void>;
205
208
  putStream(data: string | Uint8Array): Promise<void>;
209
+ /**
210
+ * Enqueues multiple children workflows in parallel.
211
+ * @param children an array of objects containing the workflow name, input data, and options for each workflow
212
+ * @returns a list of workflow run references to the enqueued runs
213
+ */
214
+ bulkEnqueueChildren<Q extends Record<string, any> = any, P extends Record<string, any> = any>(children: Array<{
215
+ workflow: string | Workflow | WorkflowV1<Q, P>;
216
+ input: Q;
217
+ options?: {
218
+ key?: string;
219
+ sticky?: boolean;
220
+ additionalMetadata?: Record<string, string>;
221
+ };
222
+ }>): Promise<WorkflowRunRef<P>[]>;
223
+ /**
224
+ * Runs multiple children workflows in parallel.
225
+ * @param children an array of objects containing the workflow name, input data, and options for each workflow
226
+ * @returns a list of results from the children workflows
227
+ */
228
+ bulkRunChildren<Q extends Record<string, any> = any, P extends Record<string, any> = any>(children: Array<{
229
+ workflow: string | Workflow | WorkflowV1<Q, P>;
230
+ input: Q;
231
+ options?: {
232
+ key?: string;
233
+ sticky?: boolean;
234
+ additionalMetadata?: Record<string, string>;
235
+ };
236
+ }>): Promise<P[]>;
206
237
  /**
207
238
  * Spawns multiple workflows.
208
239
  *
209
240
  * @param workflows an array of objects containing the workflow name, input data, and options for each workflow
210
241
  * @returns a list of references to the spawned workflow runs
242
+ * @deprecated use bulkEnqueueChildren or bulkRunChildren instead
211
243
  */
212
- spawnWorkflows<Q = JsonValue, P = JsonValue>(workflows: Array<{
213
- workflow: string | Workflow;
244
+ spawnWorkflows<Q extends Record<string, any> = any, P extends Record<string, any> = any>(workflows: Array<{
245
+ workflow: string | Workflow | WorkflowV1<Q, P>;
214
246
  input: Q;
215
247
  options?: {
216
248
  key?: string;
@@ -218,6 +250,39 @@ export declare class Context<T, K = {}> {
218
250
  additionalMetadata?: Record<string, string>;
219
251
  };
220
252
  }>): Promise<WorkflowRunRef<P>[]>;
253
+ /**
254
+ * Runs a new workflow.
255
+ *
256
+ * @param workflow the workflow to run
257
+ * @param input the input data for the workflow
258
+ * @param options additional options for spawning the workflow. If a string is provided, it is used as the key.
259
+ * @param <Q> the type of the input data
260
+ * @param <P> the type of the output data
261
+ * @return the result of the workflow
262
+ */
263
+ runChild<Q extends Record<string, any>, P extends Record<string, any>>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, options?: string | {
264
+ key?: string;
265
+ sticky?: boolean;
266
+ additionalMetadata?: Record<string, string>;
267
+ }): Promise<P>;
268
+ /**
269
+ * Enqueues a new workflow.
270
+ *
271
+ * @param workflowName the name of the workflow to spawn
272
+ * @param input the input data for the workflow
273
+ * @param options additional options for spawning the workflow. If a string is provided, it is used as the key.
274
+ * If an object is provided, it can include:
275
+ * - key: a unique identifier for the workflow (deprecated, use options.key instead)
276
+ * - sticky: a boolean indicating whether to use sticky execution
277
+ * @param <Q> the type of the input data
278
+ * @param <P> the type of the output data
279
+ * @return a reference to the spawned workflow run
280
+ */
281
+ enqueueChild<Q extends Record<string, any>, P extends Record<string, any>>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, options?: string | {
282
+ key?: string;
283
+ sticky?: boolean;
284
+ additionalMetadata?: Record<string, string>;
285
+ }): WorkflowRunRef<P>;
221
286
  /**
222
287
  * Spawns a new workflow.
223
288
  *
@@ -230,8 +295,9 @@ export declare class Context<T, K = {}> {
230
295
  * @param <Q> the type of the input data
231
296
  * @param <P> the type of the output data
232
297
  * @return a reference to the spawned workflow run
298
+ * @deprecated use runChild or enqueueChild instead
233
299
  */
234
- spawnWorkflow<Q = JsonValue, P = JsonValue>(workflow: string | Workflow, input: Q, options?: string | {
300
+ spawnWorkflow<Q extends Record<string, any>, P extends Record<string, any>>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, options?: string | {
235
301
  key?: string;
236
302
  sticky?: boolean;
237
303
  additionalMetadata?: Record<string, string>;
package/step.js CHANGED
@@ -50,7 +50,6 @@ exports.mapRateLimit = mapRateLimit;
50
50
  /* eslint-disable max-classes-per-file */
51
51
  const hatchet_error_1 = __importDefault(require("./util/errors/hatchet-error"));
52
52
  const z = __importStar(require("zod"));
53
- const workflow_1 = require("./workflow");
54
53
  const parse_1 = require("./util/parse");
55
54
  const workflows_1 = require("./protoc/workflows");
56
55
  exports.CreateRateLimitSchema = z.object({
@@ -79,7 +78,7 @@ exports.DesiredWorkerLabelSchema = z
79
78
  exports.CreateStepSchema = z.object({
80
79
  name: z.string(),
81
80
  parents: z.array(z.string()).optional(),
82
- timeout: workflow_1.HatchetTimeoutSchema.optional(),
81
+ timeout: z.string().optional(),
83
82
  retries: z.number().optional(),
84
83
  rate_limits: z.array(exports.CreateRateLimitSchema).optional(),
85
84
  worker_labels: z.record(z.lazy(() => exports.DesiredWorkerLabelSchema)).optional(),
@@ -133,6 +132,16 @@ class Context {
133
132
  throw new hatchet_error_1.default(`Could not parse payload: ${e.message}`);
134
133
  }
135
134
  }
135
+ // NOTE: parentData is async since we plan on potentially making this a cacheable server call
136
+ parentData(task) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ if (typeof task === 'string') {
139
+ return this.stepOutput(task);
140
+ }
141
+ return this.stepOutput(task.name);
142
+ });
143
+ }
144
+ // TODO deprecated
136
145
  stepOutput(step) {
137
146
  if (!this.data.parents) {
138
147
  throw new hatchet_error_1.default('Step output not found');
@@ -227,11 +236,32 @@ class Context {
227
236
  yield this.client.event.putStream(stepRunId, data);
228
237
  });
229
238
  }
239
+ /**
240
+ * Enqueues multiple children workflows in parallel.
241
+ * @param children an array of objects containing the workflow name, input data, and options for each workflow
242
+ * @returns a list of workflow run references to the enqueued runs
243
+ */
244
+ bulkEnqueueChildren(children) {
245
+ return this.spawnWorkflows(children);
246
+ }
247
+ /**
248
+ * Runs multiple children workflows in parallel.
249
+ * @param children an array of objects containing the workflow name, input data, and options for each workflow
250
+ * @returns a list of results from the children workflows
251
+ */
252
+ bulkRunChildren(children) {
253
+ return __awaiter(this, void 0, void 0, function* () {
254
+ const runs = yield this.bulkEnqueueChildren(children);
255
+ const res = runs.map((run) => run.result());
256
+ return Promise.all(res);
257
+ });
258
+ }
230
259
  /**
231
260
  * Spawns multiple workflows.
232
261
  *
233
262
  * @param workflows an array of objects containing the workflow name, input data, and options for each workflow
234
263
  * @returns a list of references to the spawned workflow runs
264
+ * @deprecated use bulkEnqueueChildren or bulkRunChildren instead
235
265
  */
236
266
  spawnWorkflows(workflows) {
237
267
  const { workflowRunId, stepRunId } = this.action;
@@ -278,6 +308,38 @@ class Context {
278
308
  throw new hatchet_error_1.default(e.message);
279
309
  }
280
310
  }
311
+ /**
312
+ * Runs a new workflow.
313
+ *
314
+ * @param workflow the workflow to run
315
+ * @param input the input data for the workflow
316
+ * @param options additional options for spawning the workflow. If a string is provided, it is used as the key.
317
+ * @param <Q> the type of the input data
318
+ * @param <P> the type of the output data
319
+ * @return the result of the workflow
320
+ */
321
+ runChild(workflow, input, options) {
322
+ return __awaiter(this, void 0, void 0, function* () {
323
+ const run = yield this.spawnWorkflow(workflow, input, options);
324
+ return run.result();
325
+ });
326
+ }
327
+ /**
328
+ * Enqueues a new workflow.
329
+ *
330
+ * @param workflowName the name of the workflow to spawn
331
+ * @param input the input data for the workflow
332
+ * @param options additional options for spawning the workflow. If a string is provided, it is used as the key.
333
+ * If an object is provided, it can include:
334
+ * - key: a unique identifier for the workflow (deprecated, use options.key instead)
335
+ * - sticky: a boolean indicating whether to use sticky execution
336
+ * @param <Q> the type of the input data
337
+ * @param <P> the type of the output data
338
+ * @return a reference to the spawned workflow run
339
+ */
340
+ enqueueChild(workflow, input, options) {
341
+ return this.spawnWorkflow(workflow, input, options);
342
+ }
281
343
  /**
282
344
  * Spawns a new workflow.
283
345
  *
@@ -290,6 +352,7 @@ class Context {
290
352
  * @param <Q> the type of the input data
291
353
  * @param <P> the type of the output data
292
354
  * @return a reference to the spawned workflow run
355
+ * @deprecated use runChild or enqueueChild instead
293
356
  */
294
357
  spawnWorkflow(workflow, input, options) {
295
358
  const { workflowRunId, stepRunId } = this.action;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class HatchetPromise {
4
4
  constructor(promise) {
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
6
  this.cancel = (reason) => { };
6
7
  this.promise = new Promise((resolve, reject) => {
7
8
  this.cancel = reject;
@@ -0,0 +1,81 @@
1
+ import { ClientConfig, InternalHatchetClient, HatchetClientOptions } from '../../clients/hatchet-client';
2
+ import { AxiosRequestConfig } from 'axios';
3
+ import WorkflowRunRef from '../../util/workflow-run-ref';
4
+ import { Workflow as V0Workflow } from '../../workflow';
5
+ import { CreateWorkflowOpts, RunOpts, Workflow } from '../workflow';
6
+ import { IHatchetClient } from './client.interface';
7
+ import { CreateWorkerOpts, Worker } from './worker';
8
+ /**
9
+ * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
10
+ * It provides methods for creating and executing workflows, as well as managing workers.
11
+ */
12
+ export declare class HatchetClient implements IHatchetClient {
13
+ /** The underlying v0 client instance */
14
+ v0: InternalHatchetClient;
15
+ /** The tenant ID for the Hatchet client */
16
+ get tenantId(): string;
17
+ /**
18
+ * Creates a new Hatchet client instance.
19
+ * @param config - Optional configuration for the client
20
+ * @param options - Optional client options
21
+ * @param axiosConfig - Optional Axios configuration for HTTP requests
22
+ */
23
+ constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig);
24
+ /**
25
+ * Static factory method to create a new Hatchet client instance.
26
+ * @param config - Optional configuration for the client
27
+ * @param options - Optional client options
28
+ * @param axiosConfig - Optional Axios configuration for HTTP requests
29
+ * @returns A new Hatchet client instance
30
+ */
31
+ static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): HatchetClient;
32
+ /**
33
+ * Creates a new workflow definition.
34
+ * @template T - The input type for the workflow
35
+ * @template K - The return type of the workflow
36
+ * @param options - Configuration options for creating the workflow
37
+ * @returns A new Workflow instance
38
+ * @note It is possible to create an orphaned workflow if no client is available using @hatchet/client CreateWorkflow
39
+ */
40
+ workflow<T extends Record<string, any> = any, K = any>(options: CreateWorkflowOpts): Workflow<T, K>;
41
+ /**
42
+ * Triggers a workflow run without waiting for completion.
43
+ * @template T - The input type for the workflow
44
+ * @template K - The return type of the workflow
45
+ * @param workflow - The workflow to run, either as a Workflow instance or workflow name
46
+ * @param input - The input data for the workflow
47
+ * @param options - Configuration options for the workflow run
48
+ * @returns A WorkflowRunRef containing the run ID and methods to interact with the run
49
+ */
50
+ enqueue<T extends Record<string, any> = any, K = any>(workflow: Workflow<T, K> | string | V0Workflow, input: T, options: RunOpts): WorkflowRunRef<K>;
51
+ /**
52
+ * Triggers a workflow run and waits for the result.
53
+ * @template T - The input type for the workflow
54
+ * @template K - The return type of the workflow
55
+ * @param workflow - The workflow to run, either as a Workflow instance or workflow name
56
+ * @param input - The input data for the workflow
57
+ * @param options - Configuration options for the workflow run
58
+ * @returns A promise that resolves with the workflow result
59
+ */
60
+ run<T extends Record<string, any> = any, K = any>(workflow: Workflow<T, K> | string | V0Workflow, input: T, options?: RunOpts): Promise<K>;
61
+ get cron(): import("../../clients/hatchet-client/features/cron-client").CronClient;
62
+ get schedule(): import("../../clients/hatchet-client/features/schedule-client").ScheduleClient;
63
+ get event(): import("../../clients/event/event-client").EventClient;
64
+ get api(): import("../..").Api<unknown>;
65
+ /**
66
+ * @deprecated use workflow.run or client.run instead
67
+ */
68
+ get admin(): import("../..").AdminClient;
69
+ /**
70
+ * Creates a new worker instance for processing workflow tasks.
71
+ * @param options - Configuration options for creating the worker
72
+ * @returns A promise that resolves with a new HatchetWorker instance
73
+ */
74
+ worker(name: string, options?: CreateWorkerOpts | number): Promise<Worker>;
75
+ /**
76
+ * Register a webhook with the worker
77
+ * @param workflows - The workflows to register on the webhooks
78
+ * @returns A promise that resolves when the webhook is registered
79
+ */
80
+ webhooks(workflows: Workflow<any, any>[] | V0Workflow[]): import("../../clients/worker/handler").WebhookHandler;
81
+ }
@@ -0,0 +1,4 @@
1
+ import { InternalHatchetClient } from '../../clients/hatchet-client';
2
+ export interface IHatchetClient {
3
+ v0: InternalHatchetClient;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,134 @@
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.HatchetClient = void 0;
13
+ const hatchet_client_1 = require("../../clients/hatchet-client");
14
+ const workflow_1 = require("../workflow");
15
+ const worker_1 = require("./worker");
16
+ /**
17
+ * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
18
+ * It provides methods for creating and executing workflows, as well as managing workers.
19
+ */
20
+ class HatchetClient {
21
+ /** The tenant ID for the Hatchet client */
22
+ get tenantId() {
23
+ return this.v0.tenantId;
24
+ }
25
+ /**
26
+ * Creates a new Hatchet client instance.
27
+ * @param config - Optional configuration for the client
28
+ * @param options - Optional client options
29
+ * @param axiosConfig - Optional Axios configuration for HTTP requests
30
+ */
31
+ constructor(config, options, axiosConfig) {
32
+ this.v0 = new hatchet_client_1.InternalHatchetClient(config, options, axiosConfig);
33
+ }
34
+ /**
35
+ * Static factory method to create a new Hatchet client instance.
36
+ * @param config - Optional configuration for the client
37
+ * @param options - Optional client options
38
+ * @param axiosConfig - Optional Axios configuration for HTTP requests
39
+ * @returns A new Hatchet client instance
40
+ */
41
+ static init(config, options, axiosConfig) {
42
+ return new HatchetClient(config, options, axiosConfig);
43
+ }
44
+ /**
45
+ * Creates a new workflow definition.
46
+ * @template T - The input type for the workflow
47
+ * @template K - The return type of the workflow
48
+ * @param options - Configuration options for creating the workflow
49
+ * @returns A new Workflow instance
50
+ * @note It is possible to create an orphaned workflow if no client is available using @hatchet/client CreateWorkflow
51
+ */
52
+ workflow(options) {
53
+ return (0, workflow_1.CreateWorkflow)(options, this);
54
+ }
55
+ /**
56
+ * Triggers a workflow run without waiting for completion.
57
+ * @template T - The input type for the workflow
58
+ * @template K - The return type of the workflow
59
+ * @param workflow - The workflow to run, either as a Workflow instance or workflow name
60
+ * @param input - The input data for the workflow
61
+ * @param options - Configuration options for the workflow run
62
+ * @returns A WorkflowRunRef containing the run ID and methods to interact with the run
63
+ */
64
+ enqueue(workflow, input, options) {
65
+ let name;
66
+ if (typeof workflow === 'string') {
67
+ name = workflow;
68
+ }
69
+ else if ('id' in workflow) {
70
+ name = workflow.id;
71
+ }
72
+ else {
73
+ throw new Error('unable to identify workflow');
74
+ }
75
+ return this.v0.admin.runWorkflow(name, input, options);
76
+ }
77
+ /**
78
+ * Triggers a workflow run and waits for the result.
79
+ * @template T - The input type for the workflow
80
+ * @template K - The return type of the workflow
81
+ * @param workflow - The workflow to run, either as a Workflow instance or workflow name
82
+ * @param input - The input data for the workflow
83
+ * @param options - Configuration options for the workflow run
84
+ * @returns A promise that resolves with the workflow result
85
+ */
86
+ run(workflow_2, input_1) {
87
+ return __awaiter(this, arguments, void 0, function* (workflow, input, options = {}) {
88
+ const run = this.enqueue(workflow, input, options);
89
+ return run.result();
90
+ });
91
+ }
92
+ get cron() {
93
+ return this.v0.cron;
94
+ }
95
+ get schedule() {
96
+ return this.v0.schedule;
97
+ }
98
+ get event() {
99
+ return this.v0.event;
100
+ }
101
+ get api() {
102
+ return this.v0.api;
103
+ }
104
+ /**
105
+ * @deprecated use workflow.run or client.run instead
106
+ */
107
+ get admin() {
108
+ return this.v0.admin;
109
+ }
110
+ /**
111
+ * Creates a new worker instance for processing workflow tasks.
112
+ * @param options - Configuration options for creating the worker
113
+ * @returns A promise that resolves with a new HatchetWorker instance
114
+ */
115
+ worker(name, options) {
116
+ let opts = {};
117
+ if (typeof options === 'number') {
118
+ opts = { slots: options };
119
+ }
120
+ else {
121
+ opts = options || {};
122
+ }
123
+ return worker_1.Worker.create(this.v0, name, opts);
124
+ }
125
+ /**
126
+ * Register a webhook with the worker
127
+ * @param workflows - The workflows to register on the webhooks
128
+ * @returns A promise that resolves when the webhook is registered
129
+ */
130
+ webhooks(workflows) {
131
+ return this.v0.webhooks(workflows);
132
+ }
133
+ }
134
+ exports.HatchetClient = HatchetClient;
@@ -0,0 +1,82 @@
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 { Workflow } from '../workflow';
7
+ /**
8
+ * Options for creating a new hatchet worker
9
+ * @interface CreateWorkerOpts
10
+ */
11
+ export interface CreateWorkerOpts {
12
+ /** Maximum number of concurrent runs on this worker */
13
+ slots?: number;
14
+ /** Array of workflows to register */
15
+ workflows?: Workflow<any, any>[] | V0Workflow[];
16
+ /** Worker labels for affinity-based assignment */
17
+ labels?: WorkerLabels;
18
+ /** Whether to handle kill signals */
19
+ handleKill?: boolean;
20
+ /** @deprecated Use slots instead */
21
+ maxRuns?: number;
22
+ }
23
+ /**
24
+ * HatchetWorker class for workflow execution runtime
25
+ */
26
+ export declare class Worker {
27
+ /** Internal reference to the underlying V0 worker implementation */
28
+ v0: V0Worker;
29
+ /**
30
+ * Creates a new HatchetWorker instance
31
+ * @param v0 - The V0 worker implementation
32
+ */
33
+ constructor(v0: V0Worker);
34
+ /**
35
+ * Creates and initializes a new HatchetWorker
36
+ * @param v0 - The HatchetClient instance
37
+ * @param options - Worker creation options
38
+ * @returns A new HatchetWorker instance
39
+ */
40
+ static create(v0: InternalHatchetClient, name: string, options: CreateWorkerOpts): Promise<Worker>;
41
+ /**
42
+ * Registers workflows with the worker
43
+ * @param workflows - Array of workflows to register
44
+ * @returns Array of registered workflow promises
45
+ */
46
+ registerWorkflows(workflows?: Array<Workflow<any, any> | V0Workflow>): Promise<void>[] | undefined;
47
+ /**
48
+ * Registers a single workflow with the worker
49
+ * @param workflow - The workflow to register
50
+ * @returns A promise that resolves when the workflow is registered
51
+ * @deprecated use registerWorkflows instead
52
+ */
53
+ registerWorkflow(workflow: Workflow<any, any> | V0Workflow): Promise<void>[] | undefined;
54
+ /**
55
+ * Starts the worker
56
+ * @returns Promise that resolves when the worker is stopped or killed
57
+ */
58
+ start(): Promise<void>;
59
+ /**
60
+ * Stops the worker
61
+ * @returns Promise that resolves when the worker stops
62
+ */
63
+ stop(): Promise<void>;
64
+ /**
65
+ * Updates or inserts worker labels
66
+ * @param labels - Worker labels to update
67
+ * @returns Promise that resolves when labels are updated
68
+ */
69
+ upsertLabels(labels: WorkerLabels): Promise<WorkerLabels>;
70
+ /**
71
+ * Get the labels for the worker
72
+ * @returns The labels for the worker
73
+ */
74
+ getLabels(): WorkerLabels;
75
+ /**
76
+ * Register a webhook with the worker
77
+ * @param webhook - The webhook to register
78
+ * @returns A promise that resolves when the webhook is registered
79
+ */
80
+ registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../../clients/rest/generated/data-contracts").WebhookWorkerCreated, any>>;
81
+ }
82
+ export declare function toV0Workflow(wf: Workflow<any, any> | V0Workflow): V0Workflow;