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

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 (91) hide show
  1. package/clients/hatchet-client/features/cron-client.js +0 -1
  2. package/clients/hatchet-client/hatchet-client.d.ts +8 -7
  3. package/clients/hatchet-client/hatchet-client.js +9 -8
  4. package/clients/hatchet-client/hatchet-logger.js +0 -1
  5. package/clients/worker/handler.d.ts +2 -2
  6. package/clients/worker/worker.d.ts +4 -4
  7. package/clients/worker/worker.js +3 -3
  8. package/examples/api.js +1 -1
  9. package/examples/example-event-with-results.js +1 -1
  10. package/examples/stream-by-additional-meta.js +1 -1
  11. package/index.d.ts +4 -1
  12. package/index.js +6 -3
  13. package/package.json +1 -1
  14. package/sdk.d.ts +1 -1
  15. package/sdk.js +2 -2
  16. package/step.d.ts +75 -9
  17. package/step.js +65 -2
  18. package/util/hatchet-promise/hatchet-promise.js +1 -0
  19. package/v1/client/client.d.ts +82 -0
  20. package/v1/client/client.interface.d.ts +4 -0
  21. package/v1/client/client.interface.js +2 -0
  22. package/v1/client/client.js +134 -0
  23. package/v1/client/worker.d.ts +82 -0
  24. package/v1/client/worker.js +131 -0
  25. package/v1/examples/child_workflows/run.d.ts +1 -0
  26. package/v1/examples/child_workflows/run.js +30 -0
  27. package/v1/examples/child_workflows/worker.d.ts +1 -0
  28. package/v1/examples/child_workflows/worker.js +24 -0
  29. package/v1/examples/child_workflows/workflow.d.ts +19 -0
  30. package/v1/examples/child_workflows/workflow.js +43 -0
  31. package/v1/examples/client.d.ts +2 -0
  32. package/v1/examples/client.js +5 -0
  33. package/v1/examples/concurrency-rr/load.d.ts +1 -0
  34. package/v1/examples/concurrency-rr/load.js +54 -0
  35. package/v1/examples/concurrency-rr/run.d.ts +1 -0
  36. package/v1/examples/concurrency-rr/run.js +39 -0
  37. package/v1/examples/concurrency-rr/worker.d.ts +1 -0
  38. package/v1/examples/concurrency-rr/worker.js +24 -0
  39. package/v1/examples/concurrency-rr/workflow.d.ts +11 -0
  40. package/v1/examples/concurrency-rr/workflow.js +35 -0
  41. package/v1/examples/dag/run.d.ts +1 -0
  42. package/v1/examples/dag/run.js +24 -0
  43. package/v1/examples/dag/worker.d.ts +1 -0
  44. package/v1/examples/dag/worker.js +24 -0
  45. package/v1/examples/dag/workflow.d.ts +11 -0
  46. package/v1/examples/dag/workflow.js +35 -0
  47. package/v1/examples/deep/run.d.ts +1 -0
  48. package/v1/examples/deep/run.js +28 -0
  49. package/v1/examples/deep/worker.d.ts +1 -0
  50. package/v1/examples/deep/worker.js +25 -0
  51. package/v1/examples/deep/workflow.d.ts +18 -0
  52. package/v1/examples/deep/workflow.js +110 -0
  53. package/v1/examples/legacy/run.d.ts +1 -0
  54. package/v1/examples/legacy/run.js +25 -0
  55. package/v1/examples/legacy/worker.d.ts +1 -0
  56. package/v1/examples/legacy/worker.js +24 -0
  57. package/v1/examples/legacy/workflow.d.ts +2 -0
  58. package/v1/examples/legacy/workflow.js +36 -0
  59. package/v1/examples/on_event/event.d.ts +1 -0
  60. package/v1/examples/on_event/event.js +25 -0
  61. package/v1/examples/on_event/worker.d.ts +1 -0
  62. package/v1/examples/on_event/worker.js +24 -0
  63. package/v1/examples/on_event/workflow.d.ts +17 -0
  64. package/v1/examples/on_event/workflow.js +33 -0
  65. package/v1/examples/on_failure/run.d.ts +1 -0
  66. package/v1/examples/on_failure/run.js +29 -0
  67. package/v1/examples/on_failure/worker.d.ts +1 -0
  68. package/v1/examples/on_failure/worker.js +24 -0
  69. package/v1/examples/on_failure/workflow.d.ts +1 -0
  70. package/v1/examples/on_failure/workflow.js +20 -0
  71. package/v1/examples/simple/cron.d.ts +1 -0
  72. package/v1/examples/simple/cron.js +26 -0
  73. package/v1/examples/simple/delay.d.ts +1 -0
  74. package/v1/examples/simple/delay.js +27 -0
  75. package/v1/examples/simple/run.d.ts +1 -0
  76. package/v1/examples/simple/run.js +24 -0
  77. package/v1/examples/simple/schedule.d.ts +1 -0
  78. package/v1/examples/simple/schedule.js +27 -0
  79. package/v1/examples/simple/worker.d.ts +1 -0
  80. package/v1/examples/simple/worker.js +24 -0
  81. package/v1/examples/simple/workflow.d.ts +5 -0
  82. package/v1/examples/simple/workflow.js +15 -0
  83. package/v1/index.d.ts +0 -0
  84. package/v1/index.js +1 -0
  85. package/v1/task.d.ts +51 -0
  86. package/v1/task.js +2 -0
  87. package/v1/workflow.d.ts +158 -0
  88. package/v1/workflow.js +145 -0
  89. package/version.d.ts +1 -1
  90. package/version.js +1 -1
  91. package/workflow.d.ts +3 -0
@@ -62,7 +62,6 @@ class CronClient {
62
62
  return __awaiter(this, void 0, void 0, function* () {
63
63
  var _a, _b, _c;
64
64
  const workflowId = typeof workflow === 'string' ? workflow : workflow.id;
65
- console.log('workflowId', workflowId);
66
65
  // Validate cron input with zod schema
67
66
  try {
68
67
  const parsedCron = exports.CreateCronTriggerSchema.parse(cron);
@@ -2,10 +2,11 @@ import { EventClient } from '../event/event-client';
2
2
  import { DispatcherClient } from '../dispatcher/dispatcher-client';
3
3
  import { AdminClient } from '../admin/admin-client';
4
4
  import { CallOptions, ChannelCredentials, ClientMiddlewareCall } from 'nice-grpc';
5
- import { Workflow } from '../../workflow';
6
- import { Worker, WorkerOpts } from '../worker';
5
+ import { Workflow as V0Workflow } from '../../workflow';
6
+ import { V0Worker, WorkerOpts } from '../worker';
7
7
  import { AxiosRequestConfig } from 'axios';
8
8
  import { Logger } from '../../util/logger';
9
+ import { WorkflowDeclaration as V1Workflow } from '../../v1/workflow';
9
10
  import { ClientConfig } from './client-config';
10
11
  import { ListenerClient } from '../listener/listener-client';
11
12
  import { Api } from '../rest/generated/Api';
@@ -17,7 +18,7 @@ export interface HatchetClientOptions {
17
18
  }
18
19
  export declare const channelFactory: (config: ClientConfig, credentials: ChannelCredentials) => import("nice-grpc").Channel;
19
20
  export declare const addTokenMiddleware: (token: string) => <Request, Response>(call: ClientMiddlewareCall<Request, Response>, options: CallOptions) => AsyncGenerator<Awaited<Response>, Awaited<Response> | undefined, undefined>;
20
- export declare class HatchetClient {
21
+ export declare class InternalHatchetClient {
21
22
  config: ClientConfig;
22
23
  credentials: ChannelCredentials;
23
24
  event: EventClient;
@@ -30,8 +31,8 @@ export declare class HatchetClient {
30
31
  cron: CronClient;
31
32
  schedule: ScheduleClient;
32
33
  constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosOpts?: AxiosRequestConfig);
33
- static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): HatchetClient;
34
- run(workflow: string | Workflow): Promise<Worker>;
35
- worker(workflow: string | Workflow, opts?: Omit<WorkerOpts, 'name'> | number): Promise<Worker>;
36
- webhooks(workflows: Workflow[]): import("../worker/handler").WebhookHandler;
34
+ static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): InternalHatchetClient;
35
+ run(workflow: string | V0Workflow): Promise<V0Worker>;
36
+ worker(workflow: string | V0Workflow, opts?: Omit<WorkerOpts, 'name'> | number): Promise<V0Worker>;
37
+ webhooks(workflows: Array<V1Workflow<any, any> | V0Workflow>): import("../worker/handler").WebhookHandler;
37
38
  }
@@ -37,7 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.HatchetClient = exports.addTokenMiddleware = exports.channelFactory = void 0;
40
+ exports.InternalHatchetClient = exports.addTokenMiddleware = exports.channelFactory = void 0;
41
41
  const zod_1 = require("zod");
42
42
  const config_loader_1 = require("../../util/config-loader");
43
43
  const event_client_1 = require("../event/event-client");
@@ -46,6 +46,7 @@ const admin_client_1 = require("../admin/admin-client");
46
46
  const nice_grpc_1 = require("nice-grpc");
47
47
  const worker_1 = require("../worker");
48
48
  const hatchet_logger_1 = require("./hatchet-logger");
49
+ const worker_2 = require("../../v1/client/worker");
49
50
  const client_config_1 = require("./client-config");
50
51
  const listener_client_1 = require("../listener/listener-client");
51
52
  const rest_1 = __importDefault(require("../rest"));
@@ -88,7 +89,7 @@ const addTokenMiddleware = (token) => function _(call, options) {
88
89
  });
89
90
  };
90
91
  exports.addTokenMiddleware = addTokenMiddleware;
91
- class HatchetClient {
92
+ class InternalHatchetClient {
92
93
  constructor(config, options, axiosOpts) {
93
94
  // Initializes a new Client instance.
94
95
  // Loads config in the following order: config param > yaml file > env vars
@@ -120,13 +121,13 @@ class HatchetClient {
120
121
  this.listener = new listener_client_1.ListenerClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory, this.api);
121
122
  this.admin = new admin_client_1.AdminClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory, this.api, this.tenantId, this.listener);
122
123
  this.logger = this.config.logger('HatchetClient', this.config.log_level);
123
- this.logger.info(`Initialized HatchetClient`);
124
+ this.logger.debug(`Initialized HatchetClient`);
124
125
  // Feature Clients
125
126
  this.cron = new cron_client_1.CronClient(this.tenantId, this.config, this.api, this.admin);
126
127
  this.schedule = new schedule_client_1.ScheduleClient(this.tenantId, this.config, this.api, this.admin);
127
128
  }
128
129
  static init(config, options, axiosConfig) {
129
- return new HatchetClient(config, options, axiosConfig);
130
+ return new InternalHatchetClient(config, options, axiosConfig);
130
131
  }
131
132
  // @deprecated
132
133
  run(workflow) {
@@ -150,7 +151,7 @@ class HatchetClient {
150
151
  else {
151
152
  options = Object.assign(Object.assign({}, options), opts);
152
153
  }
153
- const worker = new worker_1.Worker(this, options);
154
+ const worker = new worker_1.V0Worker(this, options);
154
155
  if (typeof workflow !== 'string') {
155
156
  yield worker.registerWorkflow(workflow);
156
157
  return worker;
@@ -159,10 +160,10 @@ class HatchetClient {
159
160
  });
160
161
  }
161
162
  webhooks(workflows) {
162
- const worker = new worker_1.Worker(this, {
163
+ const worker = new worker_1.V0Worker(this, {
163
164
  name: 'webhook-worker',
164
165
  });
165
- return worker.getHandler(workflows);
166
+ return worker.getHandler(workflows.map(worker_2.toV0Workflow));
166
167
  }
167
168
  }
168
- exports.HatchetClient = HatchetClient;
169
+ exports.InternalHatchetClient = InternalHatchetClient;
@@ -20,7 +20,6 @@ class HatchetLogger {
20
20
  minute: '2-digit',
21
21
  second: '2-digit',
22
22
  });
23
- // eslint-disable-next-line no-console
24
23
  // eslint-disable-next-line prefer-destructuring
25
24
  let print = console.log;
26
25
  if (level === 'ERROR') {
@@ -1,13 +1,13 @@
1
1
  import { IncomingMessage, ServerResponse } from 'http';
2
2
  import { Workflow } from '../../workflow';
3
- import { Worker } from './worker';
3
+ import { V0Worker } from './worker';
4
4
  export interface HandlerOpts {
5
5
  secret: string;
6
6
  }
7
7
  export declare class WebhookHandler {
8
8
  private worker;
9
9
  private workflows;
10
- constructor(worker: Worker, workflows: Workflow[]);
10
+ constructor(worker: V0Worker, workflows: Workflow[]);
11
11
  /**
12
12
  * Handles a request with a provided body, secret, and signature.
13
13
  *
@@ -1,4 +1,4 @@
1
- import { HatchetClient } from '../hatchet-client';
1
+ import { InternalHatchetClient } from '../hatchet-client';
2
2
  import { Action, ActionListener } from '../dispatcher/action-listener';
3
3
  import { StepActionEvent, StepActionEventType, GroupKeyActionEvent, GroupKeyActionEventType } from '../../protoc/dispatcher';
4
4
  import HatchetPromise from '../../util/hatchet-promise/hatchet-promise';
@@ -15,8 +15,8 @@ export interface WorkerOpts {
15
15
  maxRuns?: number;
16
16
  labels?: WorkerLabels;
17
17
  }
18
- export declare class Worker {
19
- client: HatchetClient;
18
+ export declare class V0Worker {
19
+ client: InternalHatchetClient;
20
20
  name: string;
21
21
  workerId: string | undefined;
22
22
  killing: boolean;
@@ -30,7 +30,7 @@ export declare class Worker {
30
30
  logger: Logger;
31
31
  registeredWorkflowPromises: Array<Promise<any>>;
32
32
  labels: WorkerLabels;
33
- constructor(client: HatchetClient, options: {
33
+ constructor(client: InternalHatchetClient, options: {
34
34
  name: string;
35
35
  handleKill?: boolean;
36
36
  maxRuns?: number;
@@ -19,14 +19,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19
19
  return (mod && mod.__esModule) ? mod : { "default": mod };
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.Worker = void 0;
22
+ exports.V0Worker = void 0;
23
23
  const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
24
24
  const dispatcher_1 = require("../../protoc/dispatcher");
25
25
  const hatchet_promise_1 = __importDefault(require("../../util/hatchet-promise/hatchet-promise"));
26
26
  const workflows_1 = require("../../protoc/workflows");
27
27
  const handler_1 = require("./handler");
28
28
  const step_1 = require("../../step");
29
- class Worker {
29
+ class V0Worker {
30
30
  constructor(client, options) {
31
31
  this.workflow_registry = [];
32
32
  this.futures = {};
@@ -482,7 +482,7 @@ class Worker {
482
482
  });
483
483
  }
484
484
  }
485
- exports.Worker = Worker;
485
+ exports.V0Worker = V0Worker;
486
486
  function toPbWorkerLabel(in_) {
487
487
  if (!in_) {
488
488
  return {};
package/examples/api.js CHANGED
@@ -49,7 +49,7 @@ function main() {
49
49
  const { admin } = hatchet;
50
50
  yield admin.putWorkflow(opts);
51
51
  const worker = yield hatchet.worker('example-worker');
52
- worker.registerAction('slack:example', (ctx) => __awaiter(this, void 0, void 0, function* () {
52
+ worker.v0.registerAction('slack:example', (ctx) => __awaiter(this, void 0, void 0, function* () {
53
53
  const setData = ctx.userData();
54
54
  console.log('executed step1!', setData);
55
55
  return { step1: 'step1' };
@@ -27,7 +27,7 @@ function main() {
27
27
  const ref = yield hatchet.admin.runWorkflow('simple-workflow', {
28
28
  test: 'test',
29
29
  });
30
- const listener = yield hatchet.listener.stream(yield ref.getWorkflowRunId());
30
+ const listener = yield hatchet.v0.listener.stream(yield ref.getWorkflowRunId());
31
31
  console.log('listening for events');
32
32
  try {
33
33
  for (var _d = true, listener_1 = __asyncValues(listener), listener_1_1; listener_1_1 = yield listener_1.next(), _a = listener_1_1.done, !_a; _d = true) {
@@ -34,7 +34,7 @@ function main() {
34
34
  // and can have an arbitrary property name.
35
35
  yield hatchet.admin.runWorkflow('parent-workflow', {}, { additionalMetadata: { [streamKey]: streamVal } });
36
36
  // Stream all events for the additional meta key value
37
- const stream = yield hatchet.listener.streamByAdditionalMeta(streamKey, streamVal);
37
+ const stream = yield hatchet.v0.listener.streamByAdditionalMeta(streamKey, streamVal);
38
38
  try {
39
39
  for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _a = stream_1_1.done, !_a; _d = true) {
40
40
  _c = stream_1_1.value;
package/index.d.ts CHANGED
@@ -1,9 +1,12 @@
1
- import { HatchetClient as Hatchet } from './clients/hatchet-client';
1
+ import { HatchetClient as Hatchet } from './v1/client/client';
2
2
  export * from './workflow';
3
3
  export * from './step';
4
4
  export * from './clients/worker';
5
5
  export * from './clients/rest';
6
6
  export * from './clients/admin';
7
7
  export * from './util/workflow-run-ref';
8
+ export * from './v1/client/client';
9
+ export * from './v1/client/worker';
10
+ export * from './v1/workflow';
8
11
  export default Hatchet;
9
12
  export { Hatchet };
package/index.js CHANGED
@@ -15,12 +15,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.Hatchet = void 0;
18
- const hatchet_client_1 = require("./clients/hatchet-client");
19
- Object.defineProperty(exports, "Hatchet", { enumerable: true, get: function () { return hatchet_client_1.HatchetClient; } });
18
+ const client_1 = require("./v1/client/client");
19
+ Object.defineProperty(exports, "Hatchet", { enumerable: true, get: function () { return client_1.HatchetClient; } });
20
20
  __exportStar(require("./workflow"), exports);
21
21
  __exportStar(require("./step"), exports);
22
22
  __exportStar(require("./clients/worker"), exports);
23
23
  __exportStar(require("./clients/rest"), exports);
24
24
  __exportStar(require("./clients/admin"), exports);
25
25
  __exportStar(require("./util/workflow-run-ref"), exports);
26
- exports.default = hatchet_client_1.HatchetClient;
26
+ __exportStar(require("./v1/client/client"), exports);
27
+ __exportStar(require("./v1/client/worker"), exports);
28
+ __exportStar(require("./v1/workflow"), exports);
29
+ exports.default = client_1.HatchetClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "0.20.3",
3
+ "version": "1.0.0-alpha1",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
package/sdk.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { HatchetClient as Hatchet } from './clients/hatchet-client';
1
+ import { HatchetClient as Hatchet } from './v1/client/client';
2
2
  export default Hatchet;
package/sdk.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const hatchet_client_1 = require("./clients/hatchet-client");
4
- exports.default = hatchet_client_1.HatchetClient;
3
+ const client_1 = require("./v1/client/client");
4
+ exports.default = client_1.HatchetClient;
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 { WorkflowDeclaration 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 JsonObject = any, P extends JsonObject = 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 JsonObject = any, P extends JsonObject = 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 JsonObject = any, P extends JsonObject = 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 JsonObject, P extends JsonObject>(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 JsonObject, P extends JsonObject>(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 JsonObject, P extends JsonObject>(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,82 @@
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 { JsonObject } from '../../step';
6
+ import { CreateWorkflowOpts, RunOpts, WorkflowDeclaration } from '../workflow';
7
+ import { IHatchetClient } from './client.interface';
8
+ import { CreateWorkerOpts, Worker } from './worker';
9
+ /**
10
+ * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
11
+ * It provides methods for creating and executing workflows, as well as managing workers.
12
+ */
13
+ export declare class HatchetClient implements IHatchetClient {
14
+ /** The underlying v0 client instance */
15
+ v0: InternalHatchetClient;
16
+ /** The tenant ID for the Hatchet client */
17
+ get tenantId(): string;
18
+ /**
19
+ * Creates a new Hatchet client instance.
20
+ * @param config - Optional configuration for the client
21
+ * @param options - Optional client options
22
+ * @param axiosConfig - Optional Axios configuration for HTTP requests
23
+ */
24
+ constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig);
25
+ /**
26
+ * Static factory method to create 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
+ * @returns A new Hatchet client instance
31
+ */
32
+ static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): HatchetClient;
33
+ /**
34
+ * Creates a new workflow definition.
35
+ * @template T - The input type for the workflow
36
+ * @template K - The return type of the workflow
37
+ * @param options - Configuration options for creating the workflow
38
+ * @returns A new Workflow instance
39
+ * @note It is possible to create an orphaned workflow if no client is available using @hatchet/client CreateWorkflow
40
+ */
41
+ workflow<T extends JsonObject = any, K extends JsonObject = any>(options: CreateWorkflowOpts): WorkflowDeclaration<T, K>;
42
+ /**
43
+ * Triggers a workflow run without waiting for completion.
44
+ * @template T - The input type for the workflow
45
+ * @template K - The return type of the workflow
46
+ * @param workflow - The workflow to run, either as a Workflow instance or workflow name
47
+ * @param input - The input data for the workflow
48
+ * @param options - Configuration options for the workflow run
49
+ * @returns A WorkflowRunRef containing the run ID and methods to interact with the run
50
+ */
51
+ enqueue<T extends JsonObject = any, K extends JsonObject = any>(workflow: WorkflowDeclaration<T, K> | string | V0Workflow, input: T, options: RunOpts): WorkflowRunRef<K>;
52
+ /**
53
+ * Triggers a workflow run and waits for the result.
54
+ * @template T - The input type for the workflow
55
+ * @template K - The return type of the workflow
56
+ * @param workflow - The workflow to run, either as a Workflow instance or workflow name
57
+ * @param input - The input data for the workflow
58
+ * @param options - Configuration options for the workflow run
59
+ * @returns A promise that resolves with the workflow result
60
+ */
61
+ run<T extends JsonObject = any, K extends JsonObject = any>(workflow: WorkflowDeclaration<T, K> | string | V0Workflow, input: T, options?: RunOpts): Promise<K>;
62
+ get cron(): import("../../clients/hatchet-client/features/cron-client").CronClient;
63
+ get schedule(): import("../../clients/hatchet-client/features/schedule-client").ScheduleClient;
64
+ get event(): import("../../clients/event/event-client").EventClient;
65
+ get api(): import("../..").Api<unknown>;
66
+ /**
67
+ * @deprecated use workflow.run or client.run instead
68
+ */
69
+ get admin(): import("../..").AdminClient;
70
+ /**
71
+ * Creates a new worker instance for processing workflow tasks.
72
+ * @param options - Configuration options for creating the worker
73
+ * @returns A promise that resolves with a new HatchetWorker instance
74
+ */
75
+ worker(name: string, options?: CreateWorkerOpts | number): Promise<Worker>;
76
+ /**
77
+ * Register a webhook with the worker
78
+ * @param workflows - The workflows to register on the webhooks
79
+ * @returns A promise that resolves when the webhook is registered
80
+ */
81
+ webhooks(workflows: WorkflowDeclaration<any, any>[] | V0Workflow[]): import("../../clients/worker/handler").WebhookHandler;
82
+ }
@@ -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 });