@hatchet-dev/typescript-sdk 1.0.0-alpha1 → 1.0.0

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 (194) hide show
  1. package/clients/admin/admin-client.d.ts +15 -20
  2. package/clients/admin/admin-client.js +21 -17
  3. package/clients/hatchet-client/hatchet-client.d.ts +5 -4
  4. package/clients/hatchet-client/hatchet-client.js +6 -4
  5. package/clients/listeners/durable-listener/durable-listener-client.d.ts +25 -0
  6. package/clients/listeners/durable-listener/durable-listener-client.js +30 -0
  7. package/clients/listeners/durable-listener/pooled-durable-listener-client.d.ts +43 -0
  8. package/clients/listeners/durable-listener/pooled-durable-listener-client.js +241 -0
  9. package/clients/{listener/listener-client.d.ts → listeners/run-listener/child-listener-client.d.ts} +8 -8
  10. package/clients/{listener/listener-client.js → listeners/run-listener/child-listener-client.js} +8 -19
  11. package/clients/{listener/child-listener-client.d.ts → listeners/run-listener/pooled-child-listener-client.d.ts} +5 -5
  12. package/clients/{listener/child-listener-client.js → listeners/run-listener/pooled-child-listener-client.js} +5 -5
  13. package/clients/rest/generated/Api.d.ts +49 -2
  14. package/clients/rest/generated/Api.js +30 -0
  15. package/clients/rest/generated/data-contracts.d.ts +88 -82
  16. package/clients/rest/generated/data-contracts.js +8 -1
  17. package/clients/worker/worker.d.ts +5 -1
  18. package/clients/worker/worker.js +173 -2
  19. package/examples/affinity-workers.js +5 -1
  20. package/examples/api.js +1 -1
  21. package/examples/bulk-fanout-worker.js +1 -1
  22. package/examples/byo-logger.js +4 -0
  23. package/examples/concurrency/cancel-in-progress/concurrency-event.js +2 -2
  24. package/examples/concurrency/group-round-robin/concurrency-event.js +1 -1
  25. package/examples/crons/programatic-crons.js +4 -4
  26. package/examples/dag-worker.js +0 -1
  27. package/examples/example-event.js +2 -2
  28. package/examples/logger.js +2 -0
  29. package/examples/on-failure.js +1 -1
  30. package/examples/rate-limit/events.js +3 -3
  31. package/examples/scheduled-runs/programatic-schedules.js +4 -4
  32. package/examples/sticky-worker-with-check.js +2 -2
  33. package/examples/sticky-worker.js +5 -0
  34. package/index.d.ts +1 -3
  35. package/index.js +1 -3
  36. package/package.json +2 -2
  37. package/protoc/dispatcher/dispatcher.d.ts +2 -0
  38. package/protoc/dispatcher/dispatcher.js +1 -1
  39. package/protoc/events/events.js +1 -1
  40. package/protoc/google/protobuf/timestamp.js +1 -1
  41. package/protoc/v1/dispatcher.d.ts +77 -0
  42. package/protoc/v1/dispatcher.js +341 -0
  43. package/protoc/v1/shared/condition.d.ts +59 -0
  44. package/protoc/v1/shared/condition.js +549 -0
  45. package/protoc/v1/workflows.d.ts +263 -0
  46. package/protoc/v1/workflows.js +1823 -0
  47. package/protoc/workflows/workflows.js +1 -1
  48. package/step.d.ts +173 -47
  49. package/step.js +208 -64
  50. package/util/sleep.d.ts +7 -0
  51. package/util/sleep.js +7 -0
  52. package/util/workflow-run-ref.d.ts +8 -2
  53. package/util/workflow-run-ref.js +13 -0
  54. package/v1/client/client.d.ts +125 -7
  55. package/v1/client/client.interface.d.ts +9 -1
  56. package/v1/client/client.js +148 -17
  57. package/v1/client/duration.d.ts +7 -0
  58. package/v1/client/duration.js +2 -0
  59. package/v1/client/features/index.d.ts +5 -0
  60. package/v1/client/features/index.js +21 -0
  61. package/v1/client/features/metrics.d.ts +14 -0
  62. package/v1/client/features/metrics.js +45 -0
  63. package/v1/client/features/ratelimits.d.ts +20 -0
  64. package/v1/client/features/ratelimits.js +40 -0
  65. package/v1/client/features/runs.d.ts +15 -0
  66. package/v1/client/features/runs.js +60 -0
  67. package/v1/client/features/workers.d.ts +14 -0
  68. package/v1/client/features/workers.js +56 -0
  69. package/v1/client/features/workflows.d.ts +17 -0
  70. package/v1/client/features/workflows.js +93 -0
  71. package/v1/client/worker.d.ts +25 -15
  72. package/v1/client/worker.js +76 -47
  73. package/v1/conditions/base.d.ts +18 -0
  74. package/v1/conditions/base.js +18 -0
  75. package/v1/conditions/index.d.ts +31 -0
  76. package/v1/conditions/index.js +91 -0
  77. package/v1/conditions/parent-condition.d.ts +40 -0
  78. package/v1/conditions/parent-condition.js +36 -0
  79. package/v1/conditions/sleep-condition.d.ts +47 -0
  80. package/v1/conditions/sleep-condition.js +38 -0
  81. package/v1/conditions/transformer.d.ts +5 -0
  82. package/v1/conditions/transformer.js +52 -0
  83. package/v1/conditions/user-event-condition.d.ts +50 -0
  84. package/v1/conditions/user-event-condition.js +39 -0
  85. package/v1/declaration.d.ts +309 -0
  86. package/v1/declaration.js +296 -0
  87. package/v1/examples/child_workflows/worker.js +2 -2
  88. package/v1/examples/child_workflows/workflow.d.ts +2 -2
  89. package/v1/examples/child_workflows/workflow.js +5 -3
  90. package/v1/examples/concurrency-rr/load.js +2 -2
  91. package/v1/examples/concurrency-rr/worker.js +2 -2
  92. package/v1/examples/concurrency-rr/workflow.d.ts +1 -1
  93. package/v1/examples/concurrency-rr/workflow.js +2 -3
  94. package/v1/examples/dag/worker.js +2 -2
  95. package/v1/examples/dag/workflow.d.ts +1 -1
  96. package/v1/examples/dag/workflow.js +3 -3
  97. package/v1/examples/dag_match_condition/event.js +28 -0
  98. package/v1/examples/dag_match_condition/run.d.ts +1 -0
  99. package/v1/examples/dag_match_condition/run.js +25 -0
  100. package/v1/examples/dag_match_condition/worker.d.ts +1 -0
  101. package/{examples/playground.js → v1/examples/dag_match_condition/worker.js} +7 -22
  102. package/v1/examples/dag_match_condition/workflow.d.ts +11 -0
  103. package/v1/examples/dag_match_condition/workflow.js +41 -0
  104. package/v1/examples/deep/worker.js +2 -2
  105. package/v1/examples/deep/workflow.d.ts +6 -6
  106. package/v1/examples/deep/workflow.js +7 -7
  107. package/v1/examples/durable-sleep/event.d.ts +1 -0
  108. package/v1/examples/durable-sleep/event.js +28 -0
  109. package/v1/examples/durable-sleep/run.d.ts +1 -0
  110. package/v1/examples/durable-sleep/run.js +30 -0
  111. package/v1/examples/durable-sleep/worker.d.ts +1 -0
  112. package/v1/examples/durable-sleep/worker.js +24 -0
  113. package/v1/examples/durable-sleep/workflow.d.ts +1 -0
  114. package/v1/examples/durable-sleep/workflow.js +37 -0
  115. package/v1/examples/inferred-typing/run.d.ts +1 -0
  116. package/v1/examples/inferred-typing/run.js +41 -0
  117. package/v1/examples/inferred-typing/worker.d.ts +1 -0
  118. package/v1/examples/inferred-typing/worker.js +24 -0
  119. package/v1/examples/inferred-typing/workflow.d.ts +15 -0
  120. package/v1/examples/inferred-typing/workflow.js +44 -0
  121. package/v1/examples/landing_page/durable-excution.d.ts +3 -0
  122. package/v1/examples/landing_page/durable-excution.js +40 -0
  123. package/v1/examples/landing_page/event-signaling.d.ts +6 -0
  124. package/v1/examples/landing_page/event-signaling.js +16 -0
  125. package/v1/examples/landing_page/flow-control.d.ts +6 -0
  126. package/v1/examples/landing_page/flow-control.js +26 -0
  127. package/v1/examples/landing_page/queues.d.ts +3 -0
  128. package/v1/examples/landing_page/queues.js +33 -0
  129. package/v1/examples/landing_page/scheduling.d.ts +1 -0
  130. package/v1/examples/landing_page/scheduling.js +12 -0
  131. package/v1/examples/landing_page/task-routing.d.ts +6 -0
  132. package/v1/examples/landing_page/task-routing.js +25 -0
  133. package/v1/examples/legacy/run.js +2 -2
  134. package/v1/examples/legacy/worker.js +2 -2
  135. package/v1/examples/on_cron/worker.d.ts +1 -0
  136. package/v1/examples/on_cron/worker.js +24 -0
  137. package/v1/examples/on_cron/workflow.d.ts +10 -0
  138. package/v1/examples/on_cron/workflow.js +21 -0
  139. package/v1/examples/on_event/event.js +3 -2
  140. package/v1/examples/on_event/worker.js +2 -2
  141. package/v1/examples/on_event/workflow.d.ts +4 -4
  142. package/v1/examples/on_event/workflow.js +6 -3
  143. package/v1/examples/on_event copy/event.d.ts +1 -0
  144. package/v1/examples/on_event copy/event.js +26 -0
  145. package/v1/examples/on_event copy/worker.d.ts +1 -0
  146. package/v1/examples/on_event copy/worker.js +24 -0
  147. package/v1/examples/on_event copy/workflow.d.ts +16 -0
  148. package/v1/examples/on_event copy/workflow.js +35 -0
  149. package/v1/examples/on_failure/worker.js +2 -2
  150. package/v1/examples/on_failure/workflow.d.ts +1 -1
  151. package/v1/examples/on_failure/workflow.js +18 -8
  152. package/v1/examples/on_success/run.d.ts +1 -0
  153. package/v1/examples/on_success/run.js +31 -0
  154. package/v1/examples/on_success/worker.d.ts +1 -0
  155. package/v1/examples/on_success/worker.js +24 -0
  156. package/v1/examples/on_success/workflow.d.ts +4 -0
  157. package/v1/examples/on_success/workflow.js +59 -0
  158. package/v1/examples/retries/run.d.ts +1 -0
  159. package/v1/examples/retries/run.js +29 -0
  160. package/v1/examples/retries/worker.d.ts +1 -0
  161. package/v1/examples/retries/worker.js +24 -0
  162. package/v1/examples/retries/workflow.d.ts +5 -0
  163. package/v1/examples/retries/workflow.js +53 -0
  164. package/v1/examples/simple/client-run.d.ts +1 -0
  165. package/v1/examples/simple/client-run.js +16 -0
  166. package/v1/examples/simple/cron.js +6 -2
  167. package/v1/examples/simple/delay.js +2 -2
  168. package/v1/examples/simple/enqueue.d.ts +1 -0
  169. package/v1/examples/simple/enqueue.js +43 -0
  170. package/v1/examples/simple/run.js +8 -3
  171. package/v1/examples/simple/schedule.js +11 -5
  172. package/v1/examples/simple/stub-workflow.d.ts +9 -0
  173. package/v1/examples/simple/stub-workflow.js +17 -0
  174. package/v1/examples/simple/worker.js +7 -2
  175. package/v1/examples/simple/workflow.d.ts +4 -3
  176. package/v1/examples/simple/workflow.js +5 -5
  177. package/v1/examples/sticky/run.d.ts +1 -0
  178. package/v1/examples/sticky/run.js +29 -0
  179. package/v1/examples/sticky/worker.d.ts +1 -0
  180. package/v1/examples/sticky/worker.js +24 -0
  181. package/v1/examples/sticky/workflow.d.ts +7 -0
  182. package/v1/examples/sticky/workflow.js +32 -0
  183. package/v1/examples/with_timeouts/workflow.d.ts +9 -0
  184. package/v1/examples/with_timeouts/workflow.js +62 -0
  185. package/v1/index.d.ts +5 -0
  186. package/v1/index.js +20 -0
  187. package/v1/task.d.ts +144 -14
  188. package/version.d.ts +1 -1
  189. package/version.js +1 -1
  190. package/v1/workflow.d.ts +0 -158
  191. package/v1/workflow.js +0 -145
  192. /package/{examples/playground.d.ts → v1/examples/dag_match_condition/event.d.ts} +0 -0
  193. /package/v1/examples/{client.d.ts → hatchet-client.d.ts} +0 -0
  194. /package/v1/examples/{client.js → hatchet-client.js} +0 -0
@@ -2,19 +2,30 @@ import { ClientConfig, InternalHatchetClient, HatchetClientOptions } from '../..
2
2
  import { AxiosRequestConfig } from 'axios';
3
3
  import WorkflowRunRef from '../../util/workflow-run-ref';
4
4
  import { Workflow as V0Workflow } from '../../workflow';
5
- import { JsonObject } from '../../step';
6
- import { CreateWorkflowOpts, RunOpts, WorkflowDeclaration } from '../workflow';
5
+ import { JsonObject, DurableContext } from '../../step';
6
+ import { CreateTaskWorkflowOpts, CreateWorkflowOpts, RunOpts, BaseWorkflowDeclaration, WorkflowDeclaration, TaskWorkflowDeclaration } from '../declaration';
7
7
  import { IHatchetClient } from './client.interface';
8
8
  import { CreateWorkerOpts, Worker } from './worker';
9
+ import { MetricsClient } from './features/metrics';
10
+ import { WorkersClient } from './features/workers';
11
+ import { WorkflowsClient } from './features/workflows';
12
+ import { RunsClient } from './features/runs';
13
+ import { CreateStandaloneDurableTaskOpts } from '../task';
9
14
  /**
10
15
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
11
16
  * It provides methods for creating and executing workflows, as well as managing workers.
12
17
  */
13
18
  export declare class HatchetClient implements IHatchetClient {
14
19
  /** The underlying v0 client instance */
15
- v0: InternalHatchetClient;
20
+ _v0: InternalHatchetClient;
21
+ /**
22
+ * @deprecated v0 client will be removed in a future release, please upgrade to v1
23
+ */
24
+ get v0(): InternalHatchetClient;
16
25
  /** The tenant ID for the Hatchet client */
17
26
  get tenantId(): string;
27
+ _isV1: boolean | undefined;
28
+ get isV1(): boolean;
18
29
  /**
19
30
  * Creates a new Hatchet client instance.
20
31
  * @param config - Optional configuration for the client
@@ -39,6 +50,42 @@ export declare class HatchetClient implements IHatchetClient {
39
50
  * @note It is possible to create an orphaned workflow if no client is available using @hatchet/client CreateWorkflow
40
51
  */
41
52
  workflow<T extends JsonObject = any, K extends JsonObject = any>(options: CreateWorkflowOpts): WorkflowDeclaration<T, K>;
53
+ /**
54
+ * Creates a new task workflow.
55
+ * Types can be explicitly specified as generics or inferred from the function signature.
56
+ * @template T The input type for the task
57
+ * @template K The output type of the task
58
+ * @param options Task configuration options
59
+ * @returns A TaskWorkflowDeclaration instance
60
+ */
61
+ task<T extends JsonObject, K extends JsonObject>(options: CreateTaskWorkflowOpts<T, K>): TaskWorkflowDeclaration<T, K>;
62
+ /**
63
+ * Creates a new task workflow with types inferred from the function parameter.
64
+ * @template Fn The type of the task function with input and output extending JsonObject
65
+ * @param options Task configuration options with function that defines types
66
+ * @returns A TaskWorkflowDeclaration instance with inferred types
67
+ */
68
+ task<Fn extends (input: I, ctx?: any) => O | Promise<O>, I extends JsonObject = Parameters<Fn>[0], O extends JsonObject = ReturnType<Fn> extends Promise<infer P> ? P extends JsonObject ? P : never : ReturnType<Fn> extends JsonObject ? ReturnType<Fn> : never>(options: {
69
+ fn: Fn;
70
+ } & Omit<CreateTaskWorkflowOpts<I, O>, 'fn'>): TaskWorkflowDeclaration<I, O>;
71
+ /**
72
+ * Creates a new durable task workflow.
73
+ * Types can be explicitly specified as generics or inferred from the function signature.
74
+ * @template T The input type for the durable task
75
+ * @template K The output type of the durable task
76
+ * @param options Durable task configuration options
77
+ * @returns A TaskWorkflowDeclaration instance for a durable task
78
+ */
79
+ durableTask<T extends JsonObject, K extends JsonObject>(options: CreateStandaloneDurableTaskOpts<T, K>): TaskWorkflowDeclaration<T, K>;
80
+ /**
81
+ * Creates a new durable task workflow with types inferred from the function parameter.
82
+ * @template Fn The type of the durable task function with input and output extending JsonObject
83
+ * @param options Durable task configuration options with function that defines types
84
+ * @returns A TaskWorkflowDeclaration instance with inferred types
85
+ */
86
+ durableTask<Fn extends (input: I, ctx: DurableContext<I>) => O | Promise<O>, I extends JsonObject = Parameters<Fn>[0], O extends JsonObject = ReturnType<Fn> extends Promise<infer P> ? P extends JsonObject ? P : never : ReturnType<Fn> extends JsonObject ? ReturnType<Fn> : never>(options: {
87
+ fn: Fn;
88
+ } & Omit<CreateStandaloneDurableTaskOpts<I, O>, 'fn'>): TaskWorkflowDeclaration<I, O>;
42
89
  /**
43
90
  * Triggers a workflow run without waiting for completion.
44
91
  * @template T - The input type for the workflow
@@ -48,8 +95,9 @@ export declare class HatchetClient implements IHatchetClient {
48
95
  * @param options - Configuration options for the workflow run
49
96
  * @returns A WorkflowRunRef containing the run ID and methods to interact with the run
50
97
  */
51
- enqueue<T extends JsonObject = any, K extends JsonObject = any>(workflow: WorkflowDeclaration<T, K> | string | V0Workflow, input: T, options: RunOpts): WorkflowRunRef<K>;
98
+ runNoWait<T extends JsonObject = any, K extends JsonObject = any>(workflow: BaseWorkflowDeclaration<T, K> | string | V0Workflow, input: T, options: RunOpts): WorkflowRunRef<K>;
52
99
  /**
100
+ * @alias run
53
101
  * Triggers a workflow run and waits for the result.
54
102
  * @template T - The input type for the workflow
55
103
  * @template K - The return type of the workflow
@@ -58,13 +106,82 @@ export declare class HatchetClient implements IHatchetClient {
58
106
  * @param options - Configuration options for the workflow run
59
107
  * @returns A promise that resolves with the workflow result
60
108
  */
61
- run<T extends JsonObject = any, K extends JsonObject = any>(workflow: WorkflowDeclaration<T, K> | string | V0Workflow, input: T, options?: RunOpts): Promise<K>;
109
+ runAndWait<T extends JsonObject = any, K extends JsonObject = any>(workflow: BaseWorkflowDeclaration<T, K> | string | V0Workflow, input: T, options?: RunOpts): Promise<K>;
110
+ /**
111
+ * Triggers a workflow run and waits for the result.
112
+ * @template T - The input type for the workflow
113
+ * @template K - The return type of the workflow
114
+ * @param workflow - The workflow to run, either as a Workflow instance or workflow name
115
+ * @param input - The input data for the workflow
116
+ * @param options - Configuration options for the workflow run
117
+ * @returns A promise that resolves with the workflow result
118
+ */
119
+ run<T extends JsonObject = any, K extends JsonObject = any>(workflow: BaseWorkflowDeclaration<T, K> | string | V0Workflow, input: T, options?: RunOpts): Promise<K>;
120
+ /**
121
+ * Get the cron client for creating and managing cron workflow runs
122
+ * @returns A cron client instance
123
+ */
124
+ get crons(): import("../../clients/hatchet-client/features/cron-client").CronClient;
125
+ /**
126
+ * Get the cron client for creating and managing cron workflow runs
127
+ * @returns A cron client instance
128
+ * @deprecated use client.crons instead
129
+ */
62
130
  get cron(): import("../../clients/hatchet-client/features/cron-client").CronClient;
131
+ /**
132
+ * Get the schedules client for creating and managing scheduled workflow runs
133
+ * @returns A schedules client instance
134
+ */
135
+ get schedules(): import("../../clients/hatchet-client/features/schedule-client").ScheduleClient;
136
+ /**
137
+ * Get the schedule client for creating and managing scheduled workflow runs
138
+ * @returns A schedule client instance
139
+ * @deprecated use client.schedules instead
140
+ */
63
141
  get schedule(): import("../../clients/hatchet-client/features/schedule-client").ScheduleClient;
142
+ /**
143
+ * Get the event client for creating and managing event workflow runs
144
+ * @returns A event client instance
145
+ */
146
+ get events(): import("../../clients/event/event-client").EventClient;
147
+ /**
148
+ * Get the event client for creating and managing event workflow runs
149
+ * @returns A event client instance
150
+ * @deprecated use client.events instead
151
+ */
64
152
  get event(): import("../../clients/event/event-client").EventClient;
153
+ private _metrics;
154
+ /**
155
+ * Get the metrics client for creating and managing metrics
156
+ * @returns A metrics client instance
157
+ */
158
+ get metrics(): MetricsClient;
159
+ private _runs;
160
+ /**
161
+ * Get the runs client for creating and managing runs
162
+ * @returns A runs client instance
163
+ */
164
+ get runs(): RunsClient;
165
+ private _workflows;
166
+ /**
167
+ * Get the workflows client for creating and managing workflows
168
+ * @returns A workflows client instance
169
+ */
170
+ get workflows(): WorkflowsClient;
171
+ private _workers;
172
+ /**
173
+ * Get the workers client for creating and managing workers
174
+ * @returns A workers client instance
175
+ */
176
+ get workers(): WorkersClient;
177
+ /**
178
+ * Get the API client for making HTTP requests to the Hatchet API
179
+ * Note: This is not recommended for general use, but is available for advanced scenarios
180
+ * @returns A API client instance
181
+ */
65
182
  get api(): import("../..").Api<unknown>;
66
183
  /**
67
- * @deprecated use workflow.run or client.run instead
184
+ * @deprecated use workflow.run, client.run, or client.* feature methods instead
68
185
  */
69
186
  get admin(): import("../..").AdminClient;
70
187
  /**
@@ -78,5 +195,6 @@ export declare class HatchetClient implements IHatchetClient {
78
195
  * @param workflows - The workflows to register on the webhooks
79
196
  * @returns A promise that resolves when the webhook is registered
80
197
  */
81
- webhooks(workflows: WorkflowDeclaration<any, any>[] | V0Workflow[]): import("../../clients/worker/handler").WebhookHandler;
198
+ webhooks(workflows: V0Workflow[]): import("../../clients/worker/handler").WebhookHandler;
199
+ runRef<T extends Record<string, any> = any>(id: string): WorkflowRunRef<T>;
82
200
  }
@@ -1,4 +1,12 @@
1
1
  import { InternalHatchetClient } from '../../clients/hatchet-client';
2
+ import { MetricsClient } from './features/metrics';
3
+ import { RunsClient } from './features/runs';
4
+ import { WorkersClient } from './features/workers';
5
+ import { WorkflowsClient } from './features/workflows';
2
6
  export interface IHatchetClient {
3
- v0: InternalHatchetClient;
7
+ _v0: InternalHatchetClient;
8
+ metrics: MetricsClient;
9
+ runs: RunsClient;
10
+ workflows: WorkflowsClient;
11
+ workers: WorkersClient;
4
12
  }
@@ -8,19 +8,38 @@ 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
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.HatchetClient = void 0;
16
+ /* eslint-disable no-dupe-class-members */
17
+ /* eslint-disable no-underscore-dangle */
13
18
  const hatchet_client_1 = require("../../clients/hatchet-client");
14
- const workflow_1 = require("../workflow");
19
+ const workflow_run_ref_1 = __importDefault(require("../../util/workflow-run-ref"));
20
+ const declaration_1 = require("../declaration");
15
21
  const worker_1 = require("./worker");
22
+ const metrics_1 = require("./features/metrics");
23
+ const workers_1 = require("./features/workers");
24
+ const workflows_1 = require("./features/workflows");
25
+ const runs_1 = require("./features/runs");
16
26
  /**
17
27
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
18
28
  * It provides methods for creating and executing workflows, as well as managing workers.
19
29
  */
20
30
  class HatchetClient {
31
+ /**
32
+ * @deprecated v0 client will be removed in a future release, please upgrade to v1
33
+ */
34
+ get v0() {
35
+ return this._v0;
36
+ }
21
37
  /** The tenant ID for the Hatchet client */
22
38
  get tenantId() {
23
- return this.v0.tenantId;
39
+ return this._v0.tenantId;
40
+ }
41
+ get isV1() {
42
+ return true;
24
43
  }
25
44
  /**
26
45
  * Creates a new Hatchet client instance.
@@ -29,7 +48,8 @@ class HatchetClient {
29
48
  * @param axiosConfig - Optional Axios configuration for HTTP requests
30
49
  */
31
50
  constructor(config, options, axiosConfig) {
32
- this.v0 = new hatchet_client_1.InternalHatchetClient(config, options, axiosConfig);
51
+ this._isV1 = true;
52
+ this._v0 = new hatchet_client_1.InternalHatchetClient(config, options, axiosConfig);
33
53
  }
34
54
  /**
35
55
  * Static factory method to create a new Hatchet client instance.
@@ -50,7 +70,19 @@ class HatchetClient {
50
70
  * @note It is possible to create an orphaned workflow if no client is available using @hatchet/client CreateWorkflow
51
71
  */
52
72
  workflow(options) {
53
- return (0, workflow_1.CreateWorkflow)(options, this);
73
+ return (0, declaration_1.CreateWorkflow)(options, this);
74
+ }
75
+ /**
76
+ * Implementation of the task method.
77
+ */
78
+ task(options) {
79
+ return (0, declaration_1.CreateTaskWorkflow)(options, this);
80
+ }
81
+ /**
82
+ * Implementation of the durableTask method.
83
+ */
84
+ durableTask(options) {
85
+ return (0, declaration_1.CreateDurableTaskWorkflow)(options, this);
54
86
  }
55
87
  /**
56
88
  * Triggers a workflow run without waiting for completion.
@@ -61,7 +93,7 @@ class HatchetClient {
61
93
  * @param options - Configuration options for the workflow run
62
94
  * @returns A WorkflowRunRef containing the run ID and methods to interact with the run
63
95
  */
64
- enqueue(workflow, input, options) {
96
+ runNoWait(workflow, input, options) {
65
97
  let name;
66
98
  if (typeof workflow === 'string') {
67
99
  name = workflow;
@@ -72,9 +104,10 @@ class HatchetClient {
72
104
  else {
73
105
  throw new Error('unable to identify workflow');
74
106
  }
75
- return this.v0.admin.runWorkflow(name, input, options);
107
+ return this._v0.admin.runWorkflow(name, input, options);
76
108
  }
77
109
  /**
110
+ * @alias run
78
111
  * Triggers a workflow run and waits for the result.
79
112
  * @template T - The input type for the workflow
80
113
  * @template K - The return type of the workflow
@@ -83,29 +116,124 @@ class HatchetClient {
83
116
  * @param options - Configuration options for the workflow run
84
117
  * @returns A promise that resolves with the workflow result
85
118
  */
86
- run(workflow_2, input_1) {
119
+ runAndWait(workflow_1, input_1) {
87
120
  return __awaiter(this, arguments, void 0, function* (workflow, input, options = {}) {
88
- const run = this.enqueue(workflow, input, options);
89
- return run.result();
121
+ return this.run(workflow, input, options);
90
122
  });
91
123
  }
124
+ /**
125
+ * Triggers a workflow run and waits for the result.
126
+ * @template T - The input type for the workflow
127
+ * @template K - The return type of the workflow
128
+ * @param workflow - The workflow to run, either as a Workflow instance or workflow name
129
+ * @param input - The input data for the workflow
130
+ * @param options - Configuration options for the workflow run
131
+ * @returns A promise that resolves with the workflow result
132
+ */
133
+ run(workflow_1, input_1) {
134
+ return __awaiter(this, arguments, void 0, function* (workflow, input, options = {}) {
135
+ const run = this.runNoWait(workflow, input, options);
136
+ return run.output;
137
+ });
138
+ }
139
+ /**
140
+ * Get the cron client for creating and managing cron workflow runs
141
+ * @returns A cron client instance
142
+ */
143
+ get crons() {
144
+ return this._v0.cron;
145
+ }
146
+ /**
147
+ * Get the cron client for creating and managing cron workflow runs
148
+ * @returns A cron client instance
149
+ * @deprecated use client.crons instead
150
+ */
92
151
  get cron() {
93
- return this.v0.cron;
152
+ return this.crons;
94
153
  }
154
+ /**
155
+ * Get the schedules client for creating and managing scheduled workflow runs
156
+ * @returns A schedules client instance
157
+ */
158
+ get schedules() {
159
+ return this._v0.schedule;
160
+ }
161
+ /**
162
+ * Get the schedule client for creating and managing scheduled workflow runs
163
+ * @returns A schedule client instance
164
+ * @deprecated use client.schedules instead
165
+ */
95
166
  get schedule() {
96
- return this.v0.schedule;
167
+ return this.schedules;
168
+ }
169
+ /**
170
+ * Get the event client for creating and managing event workflow runs
171
+ * @returns A event client instance
172
+ */
173
+ get events() {
174
+ return this._v0.event;
97
175
  }
176
+ /**
177
+ * Get the event client for creating and managing event workflow runs
178
+ * @returns A event client instance
179
+ * @deprecated use client.events instead
180
+ */
98
181
  get event() {
99
- return this.v0.event;
182
+ return this.events;
183
+ }
184
+ /**
185
+ * Get the metrics client for creating and managing metrics
186
+ * @returns A metrics client instance
187
+ */
188
+ get metrics() {
189
+ if (!this._metrics) {
190
+ this._metrics = new metrics_1.MetricsClient(this);
191
+ }
192
+ return this._metrics;
193
+ }
194
+ /**
195
+ * Get the runs client for creating and managing runs
196
+ * @returns A runs client instance
197
+ */
198
+ get runs() {
199
+ if (!this._runs) {
200
+ this._runs = new runs_1.RunsClient(this);
201
+ }
202
+ return this._runs;
203
+ }
204
+ /**
205
+ * Get the workflows client for creating and managing workflows
206
+ * @returns A workflows client instance
207
+ */
208
+ get workflows() {
209
+ if (!this._workflows) {
210
+ this._workflows = new workflows_1.WorkflowsClient(this);
211
+ }
212
+ return this._workflows;
100
213
  }
214
+ /**
215
+ * Get the workers client for creating and managing workers
216
+ * @returns A workers client instance
217
+ */
218
+ get workers() {
219
+ if (!this._workers) {
220
+ this._workers = new workers_1.WorkersClient(this);
221
+ }
222
+ return this._workers;
223
+ }
224
+ /**
225
+ * Get the API client for making HTTP requests to the Hatchet API
226
+ * Note: This is not recommended for general use, but is available for advanced scenarios
227
+ * @returns A API client instance
228
+ */
101
229
  get api() {
102
- return this.v0.api;
230
+ return this._v0.api;
103
231
  }
104
232
  /**
105
- * @deprecated use workflow.run or client.run instead
233
+ * @deprecated use workflow.run, client.run, or client.* feature methods instead
106
234
  */
107
235
  get admin() {
108
- return this.v0.admin;
236
+ return this._v0.admin;
109
237
  }
110
238
  /**
111
239
  * Creates a new worker instance for processing workflow tasks.
@@ -120,7 +248,7 @@ class HatchetClient {
120
248
  else {
121
249
  opts = options || {};
122
250
  }
123
- return worker_1.Worker.create(this.v0, name, opts);
251
+ return worker_1.Worker.create(this, this._v0, name, opts);
124
252
  }
125
253
  /**
126
254
  * Register a webhook with the worker
@@ -128,7 +256,10 @@ class HatchetClient {
128
256
  * @returns A promise that resolves when the webhook is registered
129
257
  */
130
258
  webhooks(workflows) {
131
- return this.v0.webhooks(workflows);
259
+ return this._v0.webhooks(workflows);
260
+ }
261
+ runRef(id) {
262
+ return new workflow_run_ref_1.default(id, this.v0.listener);
132
263
  }
133
264
  }
134
265
  exports.HatchetClient = HatchetClient;
@@ -0,0 +1,7 @@
1
+ type SecondsDuration = `${number}s`;
2
+ type MinutesDuration = `${number}m`;
3
+ type HoursDuration = `${number}h`;
4
+ type TwoUnitDurations = `${number}h${number}m` | `${number}h${number}s` | `${number}m${number}s`;
5
+ type ThreeUnitDurations = `${number}h${number}m${number}s`;
6
+ export type Duration = SecondsDuration | MinutesDuration | HoursDuration | TwoUnitDurations | ThreeUnitDurations;
7
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export * from './metrics';
2
+ export * from './ratelimits';
3
+ export * from './runs';
4
+ export * from './workers';
5
+ export * from './workflows';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./metrics"), exports);
18
+ __exportStar(require("./ratelimits"), exports);
19
+ __exportStar(require("./runs"), exports);
20
+ __exportStar(require("./workers"), exports);
21
+ __exportStar(require("./workflows"), exports);
@@ -0,0 +1,14 @@
1
+ import { BaseWorkflowDeclaration } from '../..';
2
+ import { Workflow } from '../../../workflow';
3
+ import { HatchetClient } from '../client';
4
+ /**
5
+ * MetricsClient is used to get metrics for workflows
6
+ */
7
+ export declare class MetricsClient {
8
+ tenantId: string;
9
+ api: HatchetClient['api'];
10
+ constructor(client: HatchetClient);
11
+ getWorkflowMetrics(workflow: string | Workflow | BaseWorkflowDeclaration<any, any>, opts?: Parameters<typeof this.api.workflowGetMetrics>[1]): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowMetrics>;
12
+ getQueueMetrics(opts?: Parameters<typeof this.api.tenantGetQueueMetrics>[1] & {}): Promise<import("../../../clients/rest/generated/data-contracts").TenantQueueMetrics>;
13
+ getTaskMetrics(opts?: Parameters<typeof this.api.tenantGetStepRunQueueMetrics>[1]): Promise<import("../../../clients/rest/generated/data-contracts").TenantStepRunQueueMetrics>;
14
+ }
@@ -0,0 +1,45 @@
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.MetricsClient = void 0;
13
+ const v1_1 = require("../..");
14
+ /**
15
+ * MetricsClient is used to get metrics for workflows
16
+ */
17
+ class MetricsClient {
18
+ constructor(client) {
19
+ this.tenantId = client.tenantId;
20
+ this.api = client.api;
21
+ }
22
+ getWorkflowMetrics(workflow, opts) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const name = (0, v1_1.workflowNameString)(workflow);
25
+ const { data } = yield this.api.workflowGetMetrics(name, opts);
26
+ return data;
27
+ });
28
+ }
29
+ getQueueMetrics(opts) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ // TODO IMPORTANT workflow id is the uuid for the workflow... not its name
32
+ // const stringWorkflows = opts?.workflows?
33
+ const { data } = yield this.api.tenantGetQueueMetrics(this.tenantId, Object.assign({}, opts));
34
+ return data;
35
+ });
36
+ }
37
+ getTaskMetrics(opts) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ // TODO what is this...
40
+ const { data } = yield this.api.tenantGetStepRunQueueMetrics(this.tenantId, opts);
41
+ return data;
42
+ });
43
+ }
44
+ }
45
+ exports.MetricsClient = MetricsClient;
@@ -0,0 +1,20 @@
1
+ import { RateLimitDuration } from '../../../protoc/workflows';
2
+ import { RateLimitOrderByField, RateLimitOrderByDirection } from '../../../clients/rest/generated/data-contracts';
3
+ import { HatchetClient } from '../client';
4
+ export { RateLimitDuration, RateLimitOrderByField, RateLimitOrderByDirection };
5
+ export type CreateRateLimitOpts = {
6
+ key: string;
7
+ limit: number;
8
+ duration?: RateLimitDuration;
9
+ };
10
+ /**
11
+ * RatelimitsClient is used to manage rate limits for the Hatchet
12
+ */
13
+ export declare class RatelimitsClient {
14
+ api: HatchetClient['api'];
15
+ admin: HatchetClient['admin'];
16
+ tenantId: string;
17
+ constructor(client: HatchetClient);
18
+ upsert(opts: CreateRateLimitOpts): Promise<string>;
19
+ list(opts: Parameters<typeof this.api.rateLimitList>[1]): Promise<import("../../../clients/rest/generated/data-contracts").RateLimitList>;
20
+ }
@@ -0,0 +1,40 @@
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.RatelimitsClient = exports.RateLimitOrderByDirection = exports.RateLimitOrderByField = exports.RateLimitDuration = void 0;
13
+ const workflows_1 = require("../../../protoc/workflows");
14
+ Object.defineProperty(exports, "RateLimitDuration", { enumerable: true, get: function () { return workflows_1.RateLimitDuration; } });
15
+ const data_contracts_1 = require("../../../clients/rest/generated/data-contracts");
16
+ Object.defineProperty(exports, "RateLimitOrderByField", { enumerable: true, get: function () { return data_contracts_1.RateLimitOrderByField; } });
17
+ Object.defineProperty(exports, "RateLimitOrderByDirection", { enumerable: true, get: function () { return data_contracts_1.RateLimitOrderByDirection; } });
18
+ /**
19
+ * RatelimitsClient is used to manage rate limits for the Hatchet
20
+ */
21
+ class RatelimitsClient {
22
+ constructor(client) {
23
+ this.api = client.api;
24
+ this.admin = client.admin;
25
+ this.tenantId = client.tenantId;
26
+ }
27
+ upsert(opts) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ yield this.admin.putRateLimit(opts.key, opts.limit, opts.duration);
30
+ return opts.key;
31
+ });
32
+ }
33
+ list(opts) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const { data } = yield this.api.rateLimitList(this.tenantId, opts);
36
+ return data;
37
+ });
38
+ }
39
+ }
40
+ exports.RatelimitsClient = RatelimitsClient;
@@ -0,0 +1,15 @@
1
+ import WorkflowRunRef from '../../../util/workflow-run-ref';
2
+ import { HatchetClient } from '../client';
3
+ /**
4
+ * RunsClient is used to list and manage runs
5
+ */
6
+ export declare class RunsClient {
7
+ api: HatchetClient['api'];
8
+ tenantId: string;
9
+ constructor(client: HatchetClient);
10
+ get<T = any>(run: string | WorkflowRunRef<T>): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowRun>;
11
+ getDetails<T = any>(run: string | WorkflowRunRef<T>): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowRunShape>;
12
+ list(opts?: Parameters<typeof this.api.workflowRunList>[1]): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowRunList>;
13
+ replay(opts: Parameters<typeof this.api.v1TaskReplay>[1]): Promise<void>;
14
+ cancel(opts: Parameters<typeof this.api.v1TaskCancel>[1]): Promise<void>;
15
+ }