@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
package/v1/task.d.ts CHANGED
@@ -2,6 +2,7 @@ import { ConcurrencyLimitStrategy } from '../protoc/v1/workflows';
2
2
  import { Context, CreateStep, DurableContext } from '../step';
3
3
  import { Conditions } from './conditions';
4
4
  import { Duration } from './client/duration';
5
+ import { InputType, OutputType, UnknownInputType } from './types';
5
6
  /**
6
7
  * Options for configuring the concurrency for a task.
7
8
  */
@@ -28,14 +29,14 @@ export type TaskConcurrency = {
28
29
  */
29
30
  limitStrategy?: ConcurrencyLimitStrategy;
30
31
  };
31
- export type TaskFn<T, K> = (input: T, ctx: Context<T>) => K | Promise<K>;
32
- export type DurableTaskFn<T, K> = (input: T, ctx: DurableContext<T>) => K | Promise<K>;
32
+ export type TaskFn<I extends InputType = UnknownInputType, O extends OutputType = void, C = Context<I>> = (input: I, ctx: C) => O | Promise<O>;
33
+ export type DurableTaskFn<I extends InputType = UnknownInputType, O extends OutputType = void> = TaskFn<I, O, DurableContext<I>>;
33
34
  /**
34
35
  * Options for creating a hatchet task which is an atomic unit of work in a workflow.
35
- * @template T The input type for the task function.
36
- * @template K The return type of the task function (can be inferred from the return value of fn).
36
+ * @template I The input type for the task function.
37
+ * @template O The return type of the task function (can be inferred from the return value of fn).
37
38
  */
38
- export type CreateBaseTaskOpts<T, K, C> = {
39
+ export type CreateBaseTaskOpts<I extends InputType = UnknownInputType, O extends OutputType = void, C = TaskFn<I, O>> = {
39
40
  /**
40
41
  * The name of the task.
41
42
  */
@@ -50,7 +51,7 @@ export type CreateBaseTaskOpts<T, K, C> = {
50
51
  /**
51
52
  * @deprecated use executionTimeout instead
52
53
  */
53
- timeout?: CreateStep<T, K>['timeout'];
54
+ timeout?: CreateStep<I, O>['timeout'];
54
55
  /**
55
56
  * (optional) execution timeout duration for the task after it starts running
56
57
  * go duration format (e.g., "1s", "5m", "1h").
@@ -70,17 +71,17 @@ export type CreateBaseTaskOpts<T, K, C> = {
70
71
  *
71
72
  * default: 0
72
73
  */
73
- retries?: CreateStep<T, K>['retries'];
74
+ retries?: CreateStep<I, O>['retries'];
74
75
  /**
75
76
  * (optional) backoff strategy configuration for retries.
76
77
  * - factor: Base of the exponential backoff (base ^ retry count)
77
78
  * - maxSeconds: Maximum backoff duration in seconds
78
79
  */
79
- backoff?: CreateStep<T, K>['backoff'];
80
+ backoff?: CreateStep<I, O>['backoff'];
80
81
  /**
81
82
  * (optional) rate limits for the task.
82
83
  */
83
- rateLimits?: CreateStep<T, K>['rate_limits'];
84
+ rateLimits?: CreateStep<I, O>['rate_limits'];
84
85
  /**
85
86
  * (optional) worker labels for task routing and scheduling.
86
87
  * Each label can be a simple string/number value or an object with additional configuration:
@@ -89,18 +90,18 @@ export type CreateBaseTaskOpts<T, K, C> = {
89
90
  * - weight: Priority weight for worker selection
90
91
  * - comparator: Custom comparison logic for label matching
91
92
  */
92
- desiredWorkerLabels?: CreateStep<T, K>['worker_labels'];
93
+ desiredWorkerLabels?: CreateStep<I, O>['worker_labels'];
93
94
  /**
94
95
  * (optional) the concurrency options for the task
95
96
  */
96
97
  concurrency?: TaskConcurrency | TaskConcurrency[];
97
98
  };
98
- export type CreateWorkflowTaskOpts<T, K, C = TaskFn<T, K>> = CreateBaseTaskOpts<T, K, C> & {
99
+ export type CreateWorkflowTaskOpts<I extends InputType = UnknownInputType, O extends OutputType = void, C extends TaskFn<I, O> | DurableTaskFn<I, O> = TaskFn<I, O>> = CreateBaseTaskOpts<I, O, C> & {
99
100
  /**
100
101
  * Parent tasks that must complete before this task runs.
101
102
  * Used to define the directed acyclic graph (DAG) of the workflow.
102
103
  */
103
- parents?: CreateWorkflowTaskOpts<T, any, any>[];
104
+ parents?: CreateWorkflowTaskOpts<I, any, any>[];
104
105
  /**
105
106
  * (optional) the conditions to match before the task is queued
106
107
  * all provided conditions must be met (AND logic)
@@ -154,28 +155,28 @@ export type CreateWorkflowTaskOpts<T, K, C = TaskFn<T, K>> = CreateBaseTaskOpts<
154
155
  */
155
156
  skipIf?: Conditions | Conditions[];
156
157
  };
157
- export type CreateStandaloneTaskOpts<T, K> = CreateBaseTaskOpts<T, K, TaskFn<T, K>>;
158
+ export type CreateStandaloneTaskOpts<I extends InputType = UnknownInputType, O extends OutputType = void, C extends TaskFn<I, O> = TaskFn<I, O>> = CreateBaseTaskOpts<I, O, C>;
158
159
  /**
159
160
  * Options for creating a hatchet durable task which is an atomic unit of work in a workflow.
160
- * @template T The input type for the task function.
161
- * @template K The return type of the task function (can be inferred from the return value of fn).
161
+ * @template I The input type for the task function.
162
+ * @template O The return type of the task function (can be inferred from the return value of fn).
162
163
  */
163
- export type CreateWorkflowDurableTaskOpts<T, K> = CreateWorkflowTaskOpts<T, K, DurableTaskFn<T, K>>;
164
+ export type CreateWorkflowDurableTaskOpts<I extends InputType = UnknownInputType, O extends OutputType = void, C extends DurableTaskFn<I, O> = DurableTaskFn<I, O>> = CreateWorkflowTaskOpts<I, O, C>;
164
165
  /**
165
166
  * Options for creating a hatchet task which is an atomic unit of work in a workflow.
166
- * @template T The input type for the task function.
167
- * @template K The return type of the task function (can be inferred from the return value of fn).
167
+ * @template I The input type for the task function.
168
+ * @template O The return type of the task function (can be inferred from the return value of fn).
168
169
  */
169
- export type CreateStandaloneDurableTaskOpts<T, K> = CreateBaseTaskOpts<T, K, DurableTaskFn<T, K>>;
170
+ export type CreateStandaloneDurableTaskOpts<I extends InputType = UnknownInputType, O extends OutputType = void, C extends DurableTaskFn<I, O> = DurableTaskFn<I, O>> = CreateBaseTaskOpts<I, O, C>;
170
171
  /**
171
172
  * Options for configuring the onSuccess task that is invoked when a task succeeds.
172
- * @template T The input type for the task function.
173
- * @template K The return type of the task function (can be inferred from the return value of fn).
173
+ * @template I The input type for the task function.
174
+ * @template O The return type of the task function (can be inferred from the return value of fn).
174
175
  */
175
- export type CreateOnSuccessTaskOpts<T, K> = Omit<CreateBaseTaskOpts<T, K, TaskFn<T, K>>, 'name'>;
176
+ export type CreateOnSuccessTaskOpts<I extends InputType = UnknownInputType, O extends OutputType = void, C extends TaskFn<I, O> = TaskFn<I, O>> = Omit<CreateBaseTaskOpts<I, O, C>, 'name'>;
176
177
  /**
177
178
  * Options for configuring the onFailure task that is invoked when a task fails.
178
- * @template T The input type for the task function.
179
- * @template K The return type of the task function (can be inferred from the return value of fn).
179
+ * @template I The input type for the task function.
180
+ * @template O The return type of the task function (can be inferred from the return value of fn).
180
181
  */
181
- export type CreateOnFailureTaskOpts<T, K> = Omit<CreateBaseTaskOpts<T, K, TaskFn<T, K>>, 'name'>;
182
+ export type CreateOnFailureTaskOpts<I extends InputType = UnknownInputType, O extends OutputType = void, C extends TaskFn<I, O> = TaskFn<I, O>> = Omit<CreateBaseTaskOpts<I, O, C>, 'name'>;
package/v1/types.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ export type JsonPrimitive = string | number | boolean | null | undefined;
2
+ export type JsonArray = JsonValue[];
3
+ export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
4
+ export type JsonObject = {
5
+ [Key in string]: JsonValue;
6
+ } & {
7
+ [Key in string]?: JsonValue | undefined;
8
+ };
9
+ export type InputType = JsonObject;
10
+ export type UnknownInputType = {};
11
+ export type OutputType = JsonObject | void;
12
+ type IsValidWorkflowOutput<T> = T extends Record<string, JsonObject> ? true : false;
13
+ export type WorkflowOutputType<T = any> = IsValidWorkflowOutput<T> extends true ? T : (Record<string, JsonObject> | void) & {
14
+ [ERROR_WORKFLOW_OUTPUT]?: 'Workflow output must be shaped as Record<"task-name", JsonObject>. Each property must be an object, not a primitive value.';
15
+ };
16
+ declare const ERROR_WORKFLOW_OUTPUT: unique symbol;
17
+ export {};
package/v1/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.0.2";
1
+ export declare const HATCHET_VERSION = "1.0.4";
package/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HATCHET_VERSION = void 0;
4
- exports.HATCHET_VERSION = '1.0.2';
4
+ exports.HATCHET_VERSION = '1.0.4';
package/workflow.d.ts CHANGED
@@ -380,10 +380,6 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
380
380
  } | undefined;
381
381
  }[];
382
382
  id: string;
383
- version?: string | undefined;
384
- scheduleTimeout?: string | undefined;
385
- sticky?: PbStickyStrategy | undefined;
386
- timeout?: string | undefined;
387
383
  on?: {
388
384
  cron: string;
389
385
  event?: undefined;
@@ -391,6 +387,10 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
391
387
  event: string;
392
388
  cron?: undefined;
393
389
  } | undefined;
390
+ version?: string | undefined;
391
+ scheduleTimeout?: string | undefined;
392
+ sticky?: PbStickyStrategy | undefined;
393
+ timeout?: string | undefined;
394
394
  onFailure?: {
395
395
  name: string;
396
396
  timeout?: string | undefined;
@@ -442,10 +442,6 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
442
442
  } | undefined;
443
443
  }[];
444
444
  id: string;
445
- version?: string | undefined;
446
- scheduleTimeout?: string | undefined;
447
- sticky?: PbStickyStrategy | undefined;
448
- timeout?: string | undefined;
449
445
  on?: {
450
446
  cron: string;
451
447
  event?: undefined;
@@ -453,6 +449,10 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
453
449
  event: string;
454
450
  cron?: undefined;
455
451
  } | undefined;
452
+ version?: string | undefined;
453
+ scheduleTimeout?: string | undefined;
454
+ sticky?: PbStickyStrategy | undefined;
455
+ timeout?: string | undefined;
456
456
  onFailure?: {
457
457
  name: string;
458
458
  timeout?: string | undefined;