@hatchet-dev/typescript-sdk 1.0.2 → 1.0.4

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 (35) hide show
  1. package/clients/dispatcher/heartbeat/heartbeat-controller.d.ts +5 -0
  2. package/clients/dispatcher/heartbeat/heartbeat-controller.js +6 -2
  3. package/clients/dispatcher/heartbeat/heartbeat-worker.js +37 -5
  4. package/package.json +4 -2
  5. package/step.d.ts +14 -16
  6. package/step.js +22 -15
  7. package/v1/client/client.d.ts +22 -21
  8. package/v1/client/client.js +8 -8
  9. package/v1/declaration.d.ts +46 -41
  10. package/v1/declaration.js +11 -11
  11. package/v1/examples/cancellations/workflow.d.ts +1 -1
  12. package/v1/examples/concurrency-rr/workflow.js +2 -2
  13. package/v1/examples/durable-sleep/workflow.d.ts +1 -1
  14. package/v1/examples/durable-sleep/workflow.js +1 -1
  15. package/v1/examples/on_failure/workflow.d.ts +1 -1
  16. package/v1/examples/on_success/workflow.d.ts +1 -1
  17. package/v1/examples/rate_limit/run.d.ts +1 -0
  18. package/v1/examples/rate_limit/run.js +29 -0
  19. package/v1/examples/rate_limit/worker.d.ts +1 -0
  20. package/v1/examples/rate_limit/worker.js +24 -0
  21. package/v1/examples/rate_limit/workflow.d.ts +5 -0
  22. package/v1/examples/rate_limit/workflow.js +40 -0
  23. package/v1/examples/retries/workflow.d.ts +3 -3
  24. package/v1/examples/retries/workflow.js +7 -4
  25. package/v1/examples/simple/run.js +2 -4
  26. package/v1/examples/sticky/workflow.d.ts +1 -1
  27. package/v1/examples/timeouts/workflow.d.ts +1 -1
  28. package/v1/index.d.ts +2 -0
  29. package/v1/index.js +2 -0
  30. package/v1/task.d.ts +26 -25
  31. package/v1/types.d.ts +17 -0
  32. package/v1/types.js +2 -0
  33. package/version.d.ts +1 -1
  34. package/version.js +1 -1
  35. package/workflow.d.ts +8 -8
@@ -1,11 +1,12 @@
1
1
  import WorkflowRunRef from '../util/workflow-run-ref';
2
- import { Context, DurableContext, JsonObject } from '../step';
2
+ import { Context, DurableContext } from '../step';
3
3
  import { CronWorkflows, ScheduledWorkflows } from '../clients/rest/generated/data-contracts';
4
4
  import { Workflow as WorkflowV0 } from '../workflow';
5
5
  import { IHatchetClient } from './client/client.interface';
6
6
  import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskConcurrency, TaskFn, CreateWorkflowDurableTaskOpts, CreateBaseTaskOpts, CreateOnSuccessTaskOpts } from './task';
7
7
  import { Duration } from './client/duration';
8
8
  import { MetricsClient } from './client/features/metrics';
9
+ import { InputType, OutputType, UnknownInputType, JsonObject } from './types';
9
10
  /**
10
11
  * Additional metadata that can be attached to a workflow run.
11
12
  */
@@ -19,10 +20,14 @@ export type RunOpts = {
19
20
  */
20
21
  additionalMetadata?: AdditionalMetadata;
21
22
  };
23
+ /**
24
+ * Helper type to safely extract output types from task results
25
+ */
26
+ export type TaskOutput<O, Key extends string, Fallback> = O extends Record<Key, infer Value> ? (Value extends OutputType ? Value : Fallback) : Fallback;
22
27
  /**
23
28
  * Extracts a property from an object type based on task name, or falls back to inferred type
24
29
  */
25
- export type TaskOutputType<K, TaskName extends string, InferredType> = TaskName extends keyof K ? K[TaskName] : InferredType;
30
+ export type TaskOutputType<O, TaskName extends string, InferredType extends OutputType> = TaskName extends keyof O ? O[TaskName] extends OutputType ? O[TaskName] : InferredType : InferredType;
26
31
  export type CreateBaseWorkflowOpts = {
27
32
  /**
28
33
  * The name of the workflow.
@@ -55,7 +60,7 @@ export type CreateBaseWorkflowOpts = {
55
60
  onEvents?: string[];
56
61
  concurrency?: TaskConcurrency;
57
62
  };
58
- export type CreateTaskWorkflowOpts<T extends JsonObject = any, K extends JsonObject = any> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<T, K, TaskFn<T, K>>;
63
+ export type CreateTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, TaskFn<I, O>>;
59
64
  /**
60
65
  * Options for creating a new workflow.
61
66
  */
@@ -141,10 +146,10 @@ export type WorkflowDefinition = CreateWorkflowOpts & {
141
146
  };
142
147
  /**
143
148
  * Represents a workflow that can be executed by Hatchet.
144
- * @template T The input type for the workflow.
145
- * @template K The return type of the workflow.
149
+ * @template I The input type for the workflow.
150
+ * @template O The return type of the workflow.
146
151
  */
147
- export declare class BaseWorkflowDeclaration<T extends JsonObject, K extends JsonObject> {
152
+ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputType, O extends OutputType = void> {
148
153
  /**
149
154
  * The Hatchet client instance used to execute the workflow.
150
155
  */
@@ -166,18 +171,18 @@ export declare class BaseWorkflowDeclaration<T extends JsonObject, K extends Jso
166
171
  * @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
167
172
  * @throws Error if the workflow is not bound to a Hatchet client.
168
173
  */
169
- runNoWait(input: T, options?: RunOpts): WorkflowRunRef<K>;
174
+ runNoWait(input: I, options?: RunOpts): WorkflowRunRef<O>;
170
175
  /**
171
176
  * @alias run
172
177
  * Triggers a workflow run and waits for the result.
173
- * @template T - The input type for the workflow
174
- * @template K - The return type of the workflow
178
+ * @template I - The input type for the workflow
179
+ * @template O - The return type of the workflow
175
180
  * @param input - The input data for the workflow
176
181
  * @param options - Configuration options for the workflow run
177
182
  * @returns A promise that resolves with the workflow result
178
183
  */
179
- runAndWait(input: T, options?: RunOpts): Promise<K>;
180
- runAndWait(input: T[], options?: RunOpts): Promise<K[]>;
184
+ runAndWait(input: I, options?: RunOpts): Promise<O>;
185
+ runAndWait(input: I[], options?: RunOpts): Promise<O[]>;
181
186
  /**
182
187
  * Executes the workflow with the given input and awaits the results.
183
188
  * @param input The input data for the workflow.
@@ -185,8 +190,8 @@ export declare class BaseWorkflowDeclaration<T extends JsonObject, K extends Jso
185
190
  * @returns A promise that resolves with the workflow result.
186
191
  * @throws Error if the workflow is not bound to a Hatchet client.
187
192
  */
188
- run(input: T, options?: RunOpts): Promise<K>;
189
- run(input: T[], options?: RunOpts): Promise<K[]>;
193
+ run(input: I, options?: RunOpts): Promise<O>;
194
+ run(input: I[], options?: RunOpts): Promise<O[]>;
190
195
  /**
191
196
  * Schedules a workflow to run at a specific date and time in the future.
192
197
  * @param enqueueAt The date when the workflow should be triggered.
@@ -195,7 +200,7 @@ export declare class BaseWorkflowDeclaration<T extends JsonObject, K extends Jso
195
200
  * @returns A promise that resolves with the scheduled workflow details.
196
201
  * @throws Error if the workflow is not bound to a Hatchet client.
197
202
  */
198
- schedule(enqueueAt: Date, input: T, options?: RunOpts): Promise<ScheduledWorkflows>;
203
+ schedule(enqueueAt: Date, input: I, options?: RunOpts): Promise<ScheduledWorkflows>;
199
204
  /**
200
205
  * Schedules a workflow to run after a specified delay.
201
206
  * @param duration The delay in seconds before the workflow should run.
@@ -204,7 +209,7 @@ export declare class BaseWorkflowDeclaration<T extends JsonObject, K extends Jso
204
209
  * @returns A promise that resolves with the scheduled workflow details.
205
210
  * @throws Error if the workflow is not bound to a Hatchet client.
206
211
  */
207
- delay(duration: number, input: T, options?: RunOpts): Promise<ScheduledWorkflows>;
212
+ delay(duration: number, input: I, options?: RunOpts): Promise<ScheduledWorkflows>;
208
213
  /**
209
214
  * Creates a cron schedule for the workflow.
210
215
  * @param name The name of the cron schedule.
@@ -214,7 +219,7 @@ export declare class BaseWorkflowDeclaration<T extends JsonObject, K extends Jso
214
219
  * @returns A promise that resolves with the cron workflow details.
215
220
  * @throws Error if the workflow is not bound to a Hatchet client.
216
221
  */
217
- cron(name: string, expression: string, input: T, options?: RunOpts): Promise<CronWorkflows>;
222
+ cron(name: string, expression: string, input: I, options?: RunOpts): Promise<CronWorkflows>;
218
223
  /**
219
224
  * Get metrics for the workflow.
220
225
  * @param opts Optional configuration for the metrics request.
@@ -242,20 +247,20 @@ export declare class BaseWorkflowDeclaration<T extends JsonObject, K extends Jso
242
247
  */
243
248
  get name(): string;
244
249
  }
245
- export declare class WorkflowDeclaration<T extends JsonObject, K extends JsonObject> extends BaseWorkflowDeclaration<T, K> {
250
+ export declare class WorkflowDeclaration<I extends InputType = UnknownInputType, O extends OutputType = void> extends BaseWorkflowDeclaration<I, O> {
246
251
  /**
247
252
  * Adds a task to the workflow.
248
- * The return type will be either the property on K that corresponds to the task name,
253
+ * The return type will be either the property on O that corresponds to the task name,
249
254
  * or if there is no matching property, the inferred return type of the function.
250
255
  * @template Name The literal string name of the task.
251
- * @template L The inferred return type of the task function.
256
+ * @template Fn The type of the task function.
252
257
  * @param options The task configuration options.
253
258
  * @returns The task options that were added.
254
259
  */
255
- task<Name extends string, L>(options: (Omit<CreateWorkflowTaskOpts<T, TaskOutputType<K, Name, L>>, 'fn'> & {
260
+ task<Name extends string, Fn extends Name extends keyof O ? (input: I, ctx: Context<I>) => O[Name] extends OutputType ? O[Name] | Promise<O[Name]> : void : (input: I, ctx: Context<I>) => void, FnReturn = ReturnType<Fn> extends Promise<infer P> ? P : ReturnType<Fn>, TO extends OutputType = Name extends keyof O ? O[Name] extends OutputType ? O[Name] : never : FnReturn extends OutputType ? FnReturn : never>(options: (Omit<CreateWorkflowTaskOpts<I, TO>, 'fn'> & {
256
261
  name: Name;
257
- fn: (input: T, ctx: Context<T>) => TaskOutputType<K, Name, L> | Promise<TaskOutputType<K, Name, L>>;
258
- }) | TaskWorkflowDeclaration<any, any>): CreateWorkflowTaskOpts<T, TaskOutputType<K, Name, L>>;
262
+ fn: Fn;
263
+ }) | TaskWorkflowDeclaration<I, TO>): CreateWorkflowTaskOpts<I, TO>;
259
264
  /**
260
265
  * Adds an onFailure task to the workflow.
261
266
  * This will only run if any task in the workflow fails.
@@ -264,9 +269,9 @@ export declare class WorkflowDeclaration<T extends JsonObject, K extends JsonObj
264
269
  * @param options The task configuration options.
265
270
  * @returns The task options that were added.
266
271
  */
267
- onFailure<Name extends string, L>(options: (Omit<CreateOnFailureTaskOpts<T, TaskOutputType<K, Name, L>>, 'fn'> & {
268
- fn: (input: T, ctx: Context<T>) => TaskOutputType<K, Name, L> | Promise<TaskOutputType<K, Name, L>>;
269
- }) | TaskWorkflowDeclaration<any, any>): CreateWorkflowTaskOpts<T, TaskOutputType<K, Name, L>>;
272
+ onFailure<Name extends string, L extends OutputType>(options: (Omit<CreateOnFailureTaskOpts<I, TaskOutputType<O, Name, L>>, 'fn'> & {
273
+ fn: (input: I, ctx: Context<I>) => TaskOutputType<O, Name, L> | Promise<TaskOutputType<O, Name, L>>;
274
+ }) | TaskWorkflowDeclaration<any, any>): CreateWorkflowTaskOpts<I, TaskOutputType<O, Name, L>>;
270
275
  /**
271
276
  * Adds an onSuccess task to the workflow.
272
277
  * This will only run if all tasks in the workflow complete successfully.
@@ -275,28 +280,28 @@ export declare class WorkflowDeclaration<T extends JsonObject, K extends JsonObj
275
280
  * @param options The task configuration options.
276
281
  * @returns The task options that were added.
277
282
  */
278
- onSuccess<Name extends string, L>(options: (Omit<CreateOnSuccessTaskOpts<T, TaskOutputType<K, Name, L>>, 'fn'> & {
279
- fn: (input: T, ctx: Context<T>) => TaskOutputType<K, Name, L> | Promise<TaskOutputType<K, Name, L>>;
280
- }) | TaskWorkflowDeclaration<any, any>): CreateWorkflowTaskOpts<T, TaskOutputType<K, Name, L>>;
283
+ onSuccess<Name extends string, L extends OutputType>(options: (Omit<CreateOnSuccessTaskOpts<I, TaskOutputType<O, Name, L>>, 'fn'> & {
284
+ fn: (input: I, ctx: Context<I>) => TaskOutputType<O, Name, L> | Promise<TaskOutputType<O, Name, L>>;
285
+ }) | TaskWorkflowDeclaration<any, any>): CreateWorkflowTaskOpts<I, TaskOutputType<O, Name, L>>;
281
286
  /**
282
287
  * Adds a durable task to the workflow.
283
- * The return type will be either the property on K that corresponds to the task name,
288
+ * The return type will be either the property on O that corresponds to the task name,
284
289
  * or if there is no matching property, the inferred return type of the function.
285
290
  * @template Name The literal string name of the task.
286
- * @template L The inferred return type of the task function.
291
+ * @template Fn The type of the task function.
287
292
  * @param options The task configuration options.
288
293
  * @returns The task options that were added.
289
294
  */
290
- durableTask<Name extends string, L>(options: Omit<CreateWorkflowTaskOpts<T, TaskOutputType<K, Name, L>>, 'fn'> & {
295
+ durableTask<Name extends string, Fn extends Name extends keyof O ? (input: I, ctx: DurableContext<I>) => O[Name] extends OutputType ? O[Name] | Promise<O[Name]> : void : (input: I, ctx: DurableContext<I>) => void, FnReturn = ReturnType<Fn> extends Promise<infer P> ? P : ReturnType<Fn>, TO extends OutputType = Name extends keyof O ? O[Name] extends OutputType ? O[Name] : never : FnReturn extends OutputType ? FnReturn : never>(options: Omit<CreateWorkflowTaskOpts<I, TO>, 'fn'> & {
291
296
  name: Name;
292
- fn: (input: T, ctx: DurableContext<T>) => TaskOutputType<K, Name, L> | Promise<TaskOutputType<K, Name, L>>;
293
- }): CreateWorkflowDurableTaskOpts<T, TaskOutputType<K, Name, L>>;
297
+ fn: Fn;
298
+ }): CreateWorkflowDurableTaskOpts<I, TO>;
294
299
  }
295
- export declare class TaskWorkflowDeclaration<T extends JsonObject, K extends JsonObject> extends BaseWorkflowDeclaration<T, K> {
300
+ export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputType, O extends OutputType = void> extends BaseWorkflowDeclaration<I, O> {
296
301
  private _standalone_task_name;
297
- constructor(options: CreateTaskWorkflowOpts<T, K>, client?: IHatchetClient);
298
- run(input: T, options?: RunOpts): Promise<K>;
299
- run(input: T[], options?: RunOpts): Promise<K[]>;
302
+ constructor(options: CreateTaskWorkflowOpts<I, O>, client?: IHatchetClient);
303
+ run(input: I, options?: RunOpts): Promise<O>;
304
+ run(input: I[], options?: RunOpts): Promise<O[]>;
300
305
  get taskDef(): CreateWorkflowTaskOpts<any, any>;
301
306
  }
302
307
  /**
@@ -306,18 +311,18 @@ export declare class TaskWorkflowDeclaration<T extends JsonObject, K extends Jso
306
311
  * @param client Optional Hatchet client instance.
307
312
  * @returns A new TaskWorkflowDeclaration with inferred types.
308
313
  */
309
- export declare function CreateTaskWorkflow<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: {
314
+ export declare function CreateTaskWorkflow<Fn extends (input: I, ctx?: any) => O | Promise<O>, I extends InputType = Parameters<Fn>[0], O extends OutputType = ReturnType<Fn> extends Promise<infer P> ? P extends OutputType ? P : void : ReturnType<Fn> extends OutputType ? ReturnType<Fn> : void>(options: {
310
315
  fn: Fn;
311
316
  } & Omit<CreateTaskWorkflowOpts<I, O>, 'fn'>, client?: IHatchetClient): TaskWorkflowDeclaration<I, O>;
312
317
  /**
313
318
  * Creates a new workflow instance.
314
- * @template T The input type for the workflow.
315
- * @template K The return type of the workflow.
319
+ * @template I The input type for the workflow.
320
+ * @template O The return type of the workflow.
316
321
  * @param options The options for creating the workflow.
317
322
  * @param client Optional Hatchet client instance.
318
323
  * @returns A new Workflow instance.
319
324
  */
320
- export declare function CreateWorkflow<T extends JsonObject = any, K extends JsonObject = any>(options: CreateWorkflowOpts, client?: IHatchetClient): WorkflowDeclaration<T, K>;
325
+ export declare function CreateWorkflow<I extends InputType = UnknownInputType, O extends OutputType = void>(options: CreateWorkflowOpts, client?: IHatchetClient): WorkflowDeclaration<I, O>;
321
326
  /**
322
327
  * Creates a new durable task workflow declaration with types inferred from the function parameter.
323
328
  * @template Fn The type of the durable task function
package/v1/declaration.js CHANGED
@@ -16,8 +16,8 @@ exports.CreateDurableTaskWorkflow = CreateDurableTaskWorkflow;
16
16
  const UNBOUND_ERR = new Error('workflow unbound to hatchet client, hint: use client.run instead');
17
17
  /**
18
18
  * Represents a workflow that can be executed by Hatchet.
19
- * @template T The input type for the workflow.
20
- * @template K The return type of the workflow.
19
+ * @template I The input type for the workflow.
20
+ * @template O The return type of the workflow.
21
21
  */
22
22
  class BaseWorkflowDeclaration {
23
23
  /**
@@ -81,7 +81,7 @@ class BaseWorkflowDeclaration {
81
81
  }
82
82
  const scheduled = this.client._v0.schedule.create(this.definition.name, {
83
83
  triggerAt: enqueueAt,
84
- input,
84
+ input: input,
85
85
  additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata,
86
86
  });
87
87
  return scheduled;
@@ -118,7 +118,7 @@ class BaseWorkflowDeclaration {
118
118
  }
119
119
  const cronDef = this.client._v0.cron.create(this.definition.name, {
120
120
  expression,
121
- input,
121
+ input: input,
122
122
  additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata,
123
123
  name,
124
124
  });
@@ -197,10 +197,10 @@ exports.BaseWorkflowDeclaration = BaseWorkflowDeclaration;
197
197
  class WorkflowDeclaration extends BaseWorkflowDeclaration {
198
198
  /**
199
199
  * Adds a task to the workflow.
200
- * The return type will be either the property on K that corresponds to the task name,
200
+ * The return type will be either the property on O that corresponds to the task name,
201
201
  * or if there is no matching property, the inferred return type of the function.
202
202
  * @template Name The literal string name of the task.
203
- * @template L The inferred return type of the task function.
203
+ * @template Fn The type of the task function.
204
204
  * @param options The task configuration options.
205
205
  * @returns The task options that were added.
206
206
  */
@@ -263,10 +263,10 @@ class WorkflowDeclaration extends BaseWorkflowDeclaration {
263
263
  }
264
264
  /**
265
265
  * Adds a durable task to the workflow.
266
- * The return type will be either the property on K that corresponds to the task name,
266
+ * The return type will be either the property on O that corresponds to the task name,
267
267
  * or if there is no matching property, the inferred return type of the function.
268
268
  * @template Name The literal string name of the task.
269
- * @template L The inferred return type of the task function.
269
+ * @template Fn The type of the task function.
270
270
  * @param options The task configuration options.
271
271
  * @returns The task options that were added.
272
272
  */
@@ -288,7 +288,7 @@ class TaskWorkflowDeclaration extends BaseWorkflowDeclaration {
288
288
  run: { get: () => super.run }
289
289
  });
290
290
  return __awaiter(this, void 0, void 0, function* () {
291
- const res = yield _super.run.call(this, input, options);
291
+ const res = (yield _super.run.call(this, input, options));
292
292
  if (Array.isArray(res)) {
293
293
  return res.map((r) => r[this._standalone_task_name]);
294
294
  }
@@ -312,8 +312,8 @@ function CreateTaskWorkflow(options, client) {
312
312
  }
313
313
  /**
314
314
  * Creates a new workflow instance.
315
- * @template T The input type for the workflow.
316
- * @template K The return type of the workflow.
315
+ * @template I The input type for the workflow.
316
+ * @template O The return type of the workflow.
317
317
  * @param options The options for creating the workflow.
318
318
  * @param client Optional Hatchet client instance.
319
319
  * @returns A new Workflow instance.
@@ -1,3 +1,3 @@
1
- export declare const cancellation: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, {
1
+ export declare const cancellation: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
2
2
  Completed: true;
3
3
  }>;
@@ -15,11 +15,11 @@ const hatchet_client_1 = require("../hatchet-client");
15
15
  const sleep = (ms) => new Promise((resolve) => {
16
16
  setTimeout(resolve, ms);
17
17
  });
18
- // ❓ Workflow
18
+ // ❓ Concurrency Strategy With Key
19
19
  exports.simpleConcurrency = hatchet_client_1.hatchet.workflow({
20
20
  name: 'simple-concurrency',
21
21
  concurrency: {
22
- maxRuns: 100,
22
+ maxRuns: 1,
23
23
  limitStrategy: workflow_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
24
24
  expression: 'input.GroupKey',
25
25
  },
@@ -1 +1 @@
1
- export declare const durableSleep: import("../..").WorkflowDeclaration<any, any>;
1
+ export declare const durableSleep: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
@@ -23,7 +23,7 @@ exports.durableSleep.durableTask({
23
23
  console.log('sleeping for 5s');
24
24
  const sleepRes = yield ctx.sleepFor('5s');
25
25
  console.log('done sleeping for 5s', sleepRes);
26
- // wait for an event or a sleep
26
+ // wait for either an event or a sleep
27
27
  const res = yield ctx.waitFor((0, conditions_1.Or)({
28
28
  eventKey: 'user:event',
29
29
  }, {
@@ -1 +1 @@
1
- export declare const failureWorkflow: import("../..").WorkflowDeclaration<any, any>;
1
+ export declare const failureWorkflow: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
@@ -1 +1 @@
1
- export declare const onSuccessDag: import("../..").WorkflowDeclaration<any, any>;
1
+ export declare const onSuccessDag: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
@@ -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
+ /* eslint-disable no-console */
13
+ const workflow_1 = require("./workflow");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ try {
17
+ const res = yield workflow_1.rateLimitWorkflow.run({ userId: 'abc' });
18
+ console.log(res);
19
+ }
20
+ catch (e) {
21
+ console.log('error', e);
22
+ }
23
+ });
24
+ }
25
+ if (require.main === module) {
26
+ main()
27
+ .catch(console.error)
28
+ .finally(() => process.exit(0));
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const hatchet_client_1 = require("../hatchet-client");
13
+ const workflow_1 = require("./workflow");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const worker = yield hatchet_client_1.hatchet.worker('rate-limit-worker', {
17
+ workflows: [workflow_1.rateLimitWorkflow],
18
+ });
19
+ yield worker.start();
20
+ });
21
+ }
22
+ if (require.main === module) {
23
+ main();
24
+ }
@@ -0,0 +1,5 @@
1
+ type RateLimitInput = {
2
+ userId: string;
3
+ };
4
+ export declare const rateLimitWorkflow: import("../..").WorkflowDeclaration<RateLimitInput, {}>;
5
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rateLimitWorkflow = void 0;
4
+ const workflows_1 = require("../../../protoc/v1/workflows");
5
+ const hatchet_client_1 = require("../hatchet-client");
6
+ exports.rateLimitWorkflow = hatchet_client_1.hatchet.workflow({
7
+ name: 'RateLimitWorkflow',
8
+ });
9
+ // !!
10
+ // ❓ Static
11
+ const RATE_LIMIT_KEY = 'test-limit';
12
+ const task1 = exports.rateLimitWorkflow.task({
13
+ name: 'task1',
14
+ fn: (input) => {
15
+ console.log('executed task1');
16
+ },
17
+ rateLimits: [
18
+ {
19
+ staticKey: RATE_LIMIT_KEY,
20
+ units: 1,
21
+ },
22
+ ],
23
+ });
24
+ // !!
25
+ // ❓ Dynamic
26
+ const task2 = exports.rateLimitWorkflow.task({
27
+ name: 'task2',
28
+ fn: (input) => {
29
+ console.log('executed task2 for user: ', input.userId);
30
+ },
31
+ rateLimits: [
32
+ {
33
+ dynamicKey: 'input.userId',
34
+ units: 1,
35
+ limit: 10,
36
+ duration: workflows_1.RateLimitDuration.MINUTE,
37
+ },
38
+ ],
39
+ });
40
+ // !!
@@ -1,5 +1,5 @@
1
- export declare const retries: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, never>;
2
- export declare const retriesWithCount: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, {
1
+ export declare const retries: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, never>;
2
+ export declare const retriesWithCount: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
3
3
  message: string;
4
4
  }>;
5
- export declare const withBackoff: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, never>;
5
+ export declare const withBackoff: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, never>;
@@ -21,7 +21,7 @@ exports.retries = hatchet_client_1.hatchet.task({
21
21
  }),
22
22
  });
23
23
  // !!
24
- // ❓ Step Retries with Count
24
+ // ❓ Retries with Count
25
25
  exports.retriesWithCount = hatchet_client_1.hatchet.task({
26
26
  name: 'retriesWithCount',
27
27
  retries: 3,
@@ -38,13 +38,16 @@ exports.retriesWithCount = hatchet_client_1.hatchet.task({
38
38
  }),
39
39
  });
40
40
  // !!
41
- // ❓ Step Retries with Backoff
41
+ // ❓ Retries with Backoff
42
42
  exports.withBackoff = hatchet_client_1.hatchet.task({
43
43
  name: 'withBackoff',
44
- retries: 3,
44
+ retries: 10,
45
45
  backoff: {
46
- factor: 2,
46
+ // 👀 Maximum number of seconds to wait between retries
47
47
  maxSeconds: 10,
48
+ // 👀 Factor to increase the wait time between retries.
49
+ // This sequence will be 2s, 4s, 8s, 10s, 10s, 10s... due to the maxSeconds limit
50
+ factor: 2,
48
51
  },
49
52
  fn: () => __awaiter(void 0, void 0, void 0, function* () {
50
53
  throw new Error('intentional failure');
@@ -10,16 +10,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  /* eslint-disable no-console */
13
- // ❓ Running a Task with Results
14
13
  const workflow_1 = require("./workflow");
15
- // ...
16
14
  function main() {
17
15
  return __awaiter(this, void 0, void 0, function* () {
18
- // 👀 Run the workflow with results
16
+ // Running a Task
19
17
  const res = yield workflow_1.simple.run({
20
18
  Message: 'HeLlO WoRlD',
21
19
  });
22
- // 👀 Access the results of the workflow
20
+ // 👀 Access the results of the Task
23
21
  console.log(res.TransformedMessage);
24
22
  // !!
25
23
  });
@@ -1,4 +1,4 @@
1
- export declare const sticky: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, {
1
+ export declare const sticky: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
2
2
  result: {
3
3
  Value: number;
4
4
  };
@@ -1,3 +1,3 @@
1
- export declare const cancellation: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, {
1
+ export declare const cancellation: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
2
2
  Completed: true;
3
3
  }>;
package/v1/index.d.ts CHANGED
@@ -3,3 +3,5 @@ export * from './client/features';
3
3
  export * from './client/worker';
4
4
  export * from './declaration';
5
5
  export * from './conditions';
6
+ export * from './client/duration';
7
+ export * from './types';
package/v1/index.js CHANGED
@@ -19,3 +19,5 @@ __exportStar(require("./client/features"), exports);
19
19
  __exportStar(require("./client/worker"), exports);
20
20
  __exportStar(require("./declaration"), exports);
21
21
  __exportStar(require("./conditions"), exports);
22
+ __exportStar(require("./client/duration"), exports);
23
+ __exportStar(require("./types"), exports);