@hatchet-dev/typescript-sdk 0.14.0 → 0.16.0-alpha.1

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 (43) hide show
  1. package/clients/admin/admin-client.d.ts +29 -0
  2. package/clients/admin/admin-client.js +34 -0
  3. package/clients/hatchet-client/client-config.d.ts +6 -0
  4. package/clients/hatchet-client/client-config.js +2 -0
  5. package/clients/hatchet-client/hatchet-client.d.ts +2 -0
  6. package/clients/hatchet-client/hatchet-client.js +25 -1
  7. package/clients/rest/api.d.ts +3 -0
  8. package/clients/rest/api.js +10 -0
  9. package/clients/rest/generated/Api.d.ts +11 -1
  10. package/clients/rest/generated/Api.js +10 -0
  11. package/clients/rest/generated/cloud/Api.d.ts +364 -0
  12. package/clients/rest/generated/cloud/Api.js +316 -0
  13. package/clients/rest/generated/cloud/data-contracts.d.ts +460 -0
  14. package/clients/rest/generated/cloud/data-contracts.js +68 -0
  15. package/clients/rest/generated/cloud/http-client.d.ts +41 -0
  16. package/clients/rest/generated/cloud/http-client.js +102 -0
  17. package/clients/rest/generated/data-contracts.d.ts +4 -0
  18. package/clients/rest/generated/data-contracts.js +1 -0
  19. package/clients/rest/index.d.ts +2 -2
  20. package/clients/rest/index.js +4 -5
  21. package/clients/worker/compute/compute-config.d.ts +96 -0
  22. package/clients/worker/compute/compute-config.js +52 -0
  23. package/clients/worker/compute/managed-compute.d.ts +15 -0
  24. package/clients/worker/compute/managed-compute.js +100 -0
  25. package/clients/worker/worker.d.ts +10 -2
  26. package/clients/worker/worker.js +31 -10
  27. package/examples/bulk-fanout-trigger.d.ts +1 -0
  28. package/examples/bulk-fanout-trigger.js +74 -0
  29. package/examples/bulk-fanout-worker.d.ts +1 -0
  30. package/examples/bulk-fanout-worker.js +93 -0
  31. package/examples/bulk-trigger.d.ts +1 -0
  32. package/examples/bulk-trigger.js +63 -0
  33. package/examples/managed-worker.d.ts +1 -0
  34. package/examples/managed-worker.js +65 -0
  35. package/package.json +7 -1
  36. package/protoc/dispatcher/dispatcher.d.ts +1 -0
  37. package/protoc/dispatcher/dispatcher.js +6 -0
  38. package/protoc/workflows/workflows.d.ts +18 -0
  39. package/protoc/workflows/workflows.js +121 -1
  40. package/step.d.ts +90 -0
  41. package/step.js +54 -1
  42. package/util/config-loader/config-loader.js +19 -1
  43. package/workflow.d.ts +285 -0
@@ -0,0 +1,65 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const data_contracts_1 = require("../clients/rest/generated/cloud/data-contracts");
16
+ const sdk_1 = __importDefault(require("../sdk"));
17
+ const hatchet = sdk_1.default.init();
18
+ const oneCpuWorkerConfig = {
19
+ cpuKind: 'shared',
20
+ memoryMb: 1024,
21
+ numReplicas: 1,
22
+ cpus: 1,
23
+ regions: [data_contracts_1.ManagedWorkerRegion.Ewr],
24
+ };
25
+ const twoCpuWorkerConfig = {
26
+ cpuKind: 'shared',
27
+ memoryMb: 1024,
28
+ numReplicas: 1,
29
+ cpus: 2,
30
+ regions: [data_contracts_1.ManagedWorkerRegion.Ewr],
31
+ };
32
+ const workflow = {
33
+ id: 'simple-workflow',
34
+ description: 'test',
35
+ on: {
36
+ event: 'user:create',
37
+ },
38
+ steps: [
39
+ {
40
+ name: 'step1',
41
+ compute: oneCpuWorkerConfig,
42
+ run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
43
+ console.log('executed step1!');
44
+ return { step1: 'step1 results!' };
45
+ }),
46
+ },
47
+ {
48
+ name: 'step2',
49
+ parents: ['step1'],
50
+ compute: twoCpuWorkerConfig,
51
+ run: (ctx) => {
52
+ console.log('executed step2 after step1 returned ', ctx.stepOutput('step1'));
53
+ return { step2: 'step2 results!' };
54
+ },
55
+ },
56
+ ],
57
+ };
58
+ function main() {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const worker = yield hatchet.worker('managed-worker');
61
+ yield worker.registerWorkflow(workflow);
62
+ worker.start();
63
+ });
64
+ }
65
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "0.14.0",
3
+ "version": "0.16.0-alpha.1",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -23,6 +23,7 @@
23
23
  "test:unit:watch": "jest --testMatch='**/*.test.ts' --watch",
24
24
  "generate": "pnpm run '/generate-.*/'",
25
25
  "generate-api": "npx --yes swagger-cli bundle ./hatchet/api-contracts/openapi/openapi.yaml --outfile openapi.yaml --type yaml && npx swagger-typescript-api -p openapi.yaml -o src/clients/rest/generated -n hatchet.ts --modular --axios",
26
+ "generate-cloud-api": "npx --yes swagger-cli bundle ./hatchet-cloud/api-contracts/openapi/openapi.yaml --outfile openapi.yaml --type yaml && npx swagger-typescript-api -p openapi.yaml -o src/clients/rest/generated/cloud -n hatchet.ts --modular --axios",
26
27
  "generate-protoc": "./generate-protoc.sh",
27
28
  "lint:check": "npm run eslint:check && npm run prettier:check",
28
29
  "lint:fix": "npm run eslint:fix && npm run prettier:fix",
@@ -38,11 +39,15 @@
38
39
  "example:rate": "npm run exec -- ./src/examples/rate-limit/events.ts",
39
40
  "worker:fanout": "npm run exec -- ./src/examples/fanout-worker.ts",
40
41
  "worker:simple": "npm run exec -- ./src/examples/simple-worker.ts",
42
+ "worker:managed": "npm run exec -- ./src/examples/managed-worker.ts",
41
43
  "worker:affinity": "npm run exec -- ./src/examples/affinity-workers.ts",
42
44
  "worker:sticky": "npm run exec -- ./src/examples/sticky-worker.ts",
43
45
  "worker:on-failure": "npm run exec -- ./src/examples/on-failure.ts",
44
46
  "manual:trigger": "npm run exec -- ./src/examples/manual-trigger.ts",
45
47
  "manual:meta": "npm run exec -- ./src/examples/stream-by-additional-meta.ts",
48
+ "bulk:trigger": "npm run exec -- ./src/examples/bulk-trigger.ts",
49
+ "bulk:fanout:worker": "npm run exec -- ./src/examples/bulk-fanout-worker.ts",
50
+ "bulk:fanout:trigger": "npm run exec -- ./src/examples/bulk-fanout-trigger.ts",
46
51
  "worker:dag": "npm run exec -- ./src/examples/dag-worker.ts",
47
52
  "worker:concurrency": "npm run exec -- ./src/examples/concurrency/cancel-in-progress/concurrency-worker.ts",
48
53
  "event:concurrency": "npm run exec -- ./src/examples/concurrency/cancel-in-progress/concurrency-event.ts",
@@ -55,6 +60,7 @@
55
60
  "api": "npm run exec -- ./src/examples/api.ts",
56
61
  "prepublish": "cp package.json dist/package.json;",
57
62
  "publish:ci": "rm -rf ./dist && npm run tsc:build && npm run prepublish && cd dist && npm publish --access public --no-git-checks",
63
+ "publish:ci:alpha": "rm -rf ./dist && npm run tsc:build && npm run prepublish && cd dist && npm publish --access public --no-git-checks --tag alpha",
58
64
  "generate-docs": "typedoc"
59
65
  },
60
66
  "keywords": [],
@@ -23,6 +23,7 @@ export declare enum StepActionEventType {
23
23
  STEP_EVENT_TYPE_STARTED = 1,
24
24
  STEP_EVENT_TYPE_COMPLETED = 2,
25
25
  STEP_EVENT_TYPE_FAILED = 3,
26
+ STEP_EVENT_TYPE_ACKNOWLEDGED = 4,
26
27
  UNRECOGNIZED = -1
27
28
  }
28
29
  export declare function stepActionEventTypeFromJSON(object: any): StepActionEventType;
@@ -108,6 +108,7 @@ var StepActionEventType;
108
108
  StepActionEventType[StepActionEventType["STEP_EVENT_TYPE_STARTED"] = 1] = "STEP_EVENT_TYPE_STARTED";
109
109
  StepActionEventType[StepActionEventType["STEP_EVENT_TYPE_COMPLETED"] = 2] = "STEP_EVENT_TYPE_COMPLETED";
110
110
  StepActionEventType[StepActionEventType["STEP_EVENT_TYPE_FAILED"] = 3] = "STEP_EVENT_TYPE_FAILED";
111
+ StepActionEventType[StepActionEventType["STEP_EVENT_TYPE_ACKNOWLEDGED"] = 4] = "STEP_EVENT_TYPE_ACKNOWLEDGED";
111
112
  StepActionEventType[StepActionEventType["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
112
113
  })(StepActionEventType || (exports.StepActionEventType = StepActionEventType = {}));
113
114
  function stepActionEventTypeFromJSON(object) {
@@ -124,6 +125,9 @@ function stepActionEventTypeFromJSON(object) {
124
125
  case 3:
125
126
  case 'STEP_EVENT_TYPE_FAILED':
126
127
  return StepActionEventType.STEP_EVENT_TYPE_FAILED;
128
+ case 4:
129
+ case 'STEP_EVENT_TYPE_ACKNOWLEDGED':
130
+ return StepActionEventType.STEP_EVENT_TYPE_ACKNOWLEDGED;
127
131
  case -1:
128
132
  case 'UNRECOGNIZED':
129
133
  default:
@@ -140,6 +144,8 @@ function stepActionEventTypeToJSON(object) {
140
144
  return 'STEP_EVENT_TYPE_COMPLETED';
141
145
  case StepActionEventType.STEP_EVENT_TYPE_FAILED:
142
146
  return 'STEP_EVENT_TYPE_FAILED';
147
+ case StepActionEventType.STEP_EVENT_TYPE_ACKNOWLEDGED:
148
+ return 'STEP_EVENT_TYPE_ACKNOWLEDGED';
143
149
  case StepActionEventType.UNRECOGNIZED:
144
150
  default:
145
151
  return 'UNRECOGNIZED';
@@ -206,6 +206,12 @@ export interface WorkflowTriggerCronRef {
206
206
  parentId: string;
207
207
  cron: string;
208
208
  }
209
+ export interface BulkTriggerWorkflowRequest {
210
+ workflows: TriggerWorkflowRequest[];
211
+ }
212
+ export interface BulkTriggerWorkflowResponse {
213
+ workflowRunIds: string[];
214
+ }
209
215
  export interface TriggerWorkflowRequest {
210
216
  name: string;
211
217
  /** (optional) the input data for the workflow */
@@ -262,6 +268,8 @@ export declare const ScheduleWorkflowRequest: MessageFns<ScheduleWorkflowRequest
262
268
  export declare const WorkflowVersion: MessageFns<WorkflowVersion>;
263
269
  export declare const WorkflowTriggerEventRef: MessageFns<WorkflowTriggerEventRef>;
264
270
  export declare const WorkflowTriggerCronRef: MessageFns<WorkflowTriggerCronRef>;
271
+ export declare const BulkTriggerWorkflowRequest: MessageFns<BulkTriggerWorkflowRequest>;
272
+ export declare const BulkTriggerWorkflowResponse: MessageFns<BulkTriggerWorkflowResponse>;
265
273
  export declare const TriggerWorkflowRequest: MessageFns<TriggerWorkflowRequest>;
266
274
  export declare const TriggerWorkflowResponse: MessageFns<TriggerWorkflowResponse>;
267
275
  export declare const PutRateLimitRequest: MessageFns<PutRateLimitRequest>;
@@ -296,6 +304,14 @@ export declare const WorkflowServiceDefinition: {
296
304
  readonly responseStream: false;
297
305
  readonly options: {};
298
306
  };
307
+ readonly bulkTriggerWorkflow: {
308
+ readonly name: "BulkTriggerWorkflow";
309
+ readonly requestType: MessageFns<BulkTriggerWorkflowRequest>;
310
+ readonly requestStream: false;
311
+ readonly responseType: MessageFns<BulkTriggerWorkflowResponse>;
312
+ readonly responseStream: false;
313
+ readonly options: {};
314
+ };
299
315
  readonly putRateLimit: {
300
316
  readonly name: "PutRateLimit";
301
317
  readonly requestType: MessageFns<PutRateLimitRequest>;
@@ -310,12 +326,14 @@ export interface WorkflowServiceImplementation<CallContextExt = {}> {
310
326
  putWorkflow(request: PutWorkflowRequest, context: CallContext & CallContextExt): Promise<DeepPartial<WorkflowVersion>>;
311
327
  scheduleWorkflow(request: ScheduleWorkflowRequest, context: CallContext & CallContextExt): Promise<DeepPartial<WorkflowVersion>>;
312
328
  triggerWorkflow(request: TriggerWorkflowRequest, context: CallContext & CallContextExt): Promise<DeepPartial<TriggerWorkflowResponse>>;
329
+ bulkTriggerWorkflow(request: BulkTriggerWorkflowRequest, context: CallContext & CallContextExt): Promise<DeepPartial<BulkTriggerWorkflowResponse>>;
313
330
  putRateLimit(request: PutRateLimitRequest, context: CallContext & CallContextExt): Promise<DeepPartial<PutRateLimitResponse>>;
314
331
  }
315
332
  export interface WorkflowServiceClient<CallOptionsExt = {}> {
316
333
  putWorkflow(request: DeepPartial<PutWorkflowRequest>, options?: CallOptions & CallOptionsExt): Promise<WorkflowVersion>;
317
334
  scheduleWorkflow(request: DeepPartial<ScheduleWorkflowRequest>, options?: CallOptions & CallOptionsExt): Promise<WorkflowVersion>;
318
335
  triggerWorkflow(request: DeepPartial<TriggerWorkflowRequest>, options?: CallOptions & CallOptionsExt): Promise<TriggerWorkflowResponse>;
336
+ bulkTriggerWorkflow(request: DeepPartial<BulkTriggerWorkflowRequest>, options?: CallOptions & CallOptionsExt): Promise<BulkTriggerWorkflowResponse>;
319
337
  putRateLimit(request: DeepPartial<PutRateLimitRequest>, options?: CallOptions & CallOptionsExt): Promise<PutRateLimitResponse>;
320
338
  }
321
339
  type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
@@ -5,7 +5,7 @@
5
5
  // protoc v3.19.1
6
6
  // source: workflows/workflows.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.WorkflowServiceDefinition = exports.PutRateLimitResponse = exports.PutRateLimitRequest = exports.TriggerWorkflowResponse = exports.TriggerWorkflowRequest = exports.WorkflowTriggerCronRef = exports.WorkflowTriggerEventRef = exports.WorkflowVersion = exports.ScheduleWorkflowRequest = exports.ListWorkflowsRequest = exports.CreateStepRateLimit = exports.CreateWorkflowStepOpts_WorkerLabelsEntry = exports.CreateWorkflowStepOpts = exports.DesiredWorkerLabels = exports.CreateWorkflowJobOpts = exports.WorkflowConcurrencyOpts = exports.CreateWorkflowVersionOpts = exports.PutWorkflowRequest = exports.RateLimitDuration = exports.WorkerLabelComparator = exports.ConcurrencyLimitStrategy = exports.WorkflowKind = exports.StickyStrategy = exports.protobufPackage = void 0;
8
+ exports.WorkflowServiceDefinition = exports.PutRateLimitResponse = exports.PutRateLimitRequest = exports.TriggerWorkflowResponse = exports.TriggerWorkflowRequest = exports.BulkTriggerWorkflowResponse = exports.BulkTriggerWorkflowRequest = exports.WorkflowTriggerCronRef = exports.WorkflowTriggerEventRef = exports.WorkflowVersion = exports.ScheduleWorkflowRequest = exports.ListWorkflowsRequest = exports.CreateStepRateLimit = exports.CreateWorkflowStepOpts_WorkerLabelsEntry = exports.CreateWorkflowStepOpts = exports.DesiredWorkerLabels = exports.CreateWorkflowJobOpts = exports.WorkflowConcurrencyOpts = exports.CreateWorkflowVersionOpts = exports.PutWorkflowRequest = exports.RateLimitDuration = exports.WorkerLabelComparator = exports.ConcurrencyLimitStrategy = exports.WorkflowKind = exports.StickyStrategy = exports.protobufPackage = void 0;
9
9
  exports.stickyStrategyFromJSON = stickyStrategyFromJSON;
10
10
  exports.stickyStrategyToJSON = stickyStrategyToJSON;
11
11
  exports.workflowKindFromJSON = workflowKindFromJSON;
@@ -1725,6 +1725,118 @@ exports.WorkflowTriggerCronRef = {
1725
1725
  return message;
1726
1726
  },
1727
1727
  };
1728
+ function createBaseBulkTriggerWorkflowRequest() {
1729
+ return { workflows: [] };
1730
+ }
1731
+ exports.BulkTriggerWorkflowRequest = {
1732
+ encode(message, writer = new wire_1.BinaryWriter()) {
1733
+ for (const v of message.workflows) {
1734
+ exports.TriggerWorkflowRequest.encode(v, writer.uint32(10).fork()).join();
1735
+ }
1736
+ return writer;
1737
+ },
1738
+ decode(input, length) {
1739
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
1740
+ let end = length === undefined ? reader.len : reader.pos + length;
1741
+ const message = createBaseBulkTriggerWorkflowRequest();
1742
+ while (reader.pos < end) {
1743
+ const tag = reader.uint32();
1744
+ switch (tag >>> 3) {
1745
+ case 1:
1746
+ if (tag !== 10) {
1747
+ break;
1748
+ }
1749
+ message.workflows.push(exports.TriggerWorkflowRequest.decode(reader, reader.uint32()));
1750
+ continue;
1751
+ }
1752
+ if ((tag & 7) === 4 || tag === 0) {
1753
+ break;
1754
+ }
1755
+ reader.skip(tag & 7);
1756
+ }
1757
+ return message;
1758
+ },
1759
+ fromJSON(object) {
1760
+ return {
1761
+ workflows: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.workflows)
1762
+ ? object.workflows.map((e) => exports.TriggerWorkflowRequest.fromJSON(e))
1763
+ : [],
1764
+ };
1765
+ },
1766
+ toJSON(message) {
1767
+ var _a;
1768
+ const obj = {};
1769
+ if ((_a = message.workflows) === null || _a === void 0 ? void 0 : _a.length) {
1770
+ obj.workflows = message.workflows.map((e) => exports.TriggerWorkflowRequest.toJSON(e));
1771
+ }
1772
+ return obj;
1773
+ },
1774
+ create(base) {
1775
+ return exports.BulkTriggerWorkflowRequest.fromPartial(base !== null && base !== void 0 ? base : {});
1776
+ },
1777
+ fromPartial(object) {
1778
+ var _a;
1779
+ const message = createBaseBulkTriggerWorkflowRequest();
1780
+ message.workflows = ((_a = object.workflows) === null || _a === void 0 ? void 0 : _a.map((e) => exports.TriggerWorkflowRequest.fromPartial(e))) || [];
1781
+ return message;
1782
+ },
1783
+ };
1784
+ function createBaseBulkTriggerWorkflowResponse() {
1785
+ return { workflowRunIds: [] };
1786
+ }
1787
+ exports.BulkTriggerWorkflowResponse = {
1788
+ encode(message, writer = new wire_1.BinaryWriter()) {
1789
+ for (const v of message.workflowRunIds) {
1790
+ writer.uint32(10).string(v);
1791
+ }
1792
+ return writer;
1793
+ },
1794
+ decode(input, length) {
1795
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
1796
+ let end = length === undefined ? reader.len : reader.pos + length;
1797
+ const message = createBaseBulkTriggerWorkflowResponse();
1798
+ while (reader.pos < end) {
1799
+ const tag = reader.uint32();
1800
+ switch (tag >>> 3) {
1801
+ case 1:
1802
+ if (tag !== 10) {
1803
+ break;
1804
+ }
1805
+ message.workflowRunIds.push(reader.string());
1806
+ continue;
1807
+ }
1808
+ if ((tag & 7) === 4 || tag === 0) {
1809
+ break;
1810
+ }
1811
+ reader.skip(tag & 7);
1812
+ }
1813
+ return message;
1814
+ },
1815
+ fromJSON(object) {
1816
+ return {
1817
+ workflowRunIds: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.workflowRunIds)
1818
+ ? object.workflowRunIds.map((e) => globalThis.String(e))
1819
+ : [],
1820
+ };
1821
+ },
1822
+ toJSON(message) {
1823
+ var _a;
1824
+ const obj = {};
1825
+ if ((_a = message.workflowRunIds) === null || _a === void 0 ? void 0 : _a.length) {
1826
+ obj.workflowRunIds = message.workflowRunIds;
1827
+ }
1828
+ return obj;
1829
+ },
1830
+ create(base) {
1831
+ return exports.BulkTriggerWorkflowResponse.fromPartial(base !== null && base !== void 0 ? base : {});
1832
+ },
1833
+ fromPartial(object) {
1834
+ var _a;
1835
+ const message = createBaseBulkTriggerWorkflowResponse();
1836
+ message.workflowRunIds = ((_a = object.workflowRunIds) === null || _a === void 0 ? void 0 : _a.map((e) => e)) || [];
1837
+ return message;
1838
+ },
1839
+ };
1728
1840
  function createBaseTriggerWorkflowRequest() {
1729
1841
  return {
1730
1842
  name: '',
@@ -2105,6 +2217,14 @@ exports.WorkflowServiceDefinition = {
2105
2217
  responseStream: false,
2106
2218
  options: {},
2107
2219
  },
2220
+ bulkTriggerWorkflow: {
2221
+ name: 'BulkTriggerWorkflow',
2222
+ requestType: exports.BulkTriggerWorkflowRequest,
2223
+ requestStream: false,
2224
+ responseType: exports.BulkTriggerWorkflowResponse,
2225
+ responseStream: false,
2226
+ options: {},
2227
+ },
2108
2228
  putRateLimit: {
2109
2229
  name: 'PutRateLimit',
2110
2230
  requestType: exports.PutRateLimitRequest,
package/step.d.ts CHANGED
@@ -89,11 +89,71 @@ export declare const CreateStepSchema: z.ZodObject<{
89
89
  comparator?: WorkerLabelComparator | undefined;
90
90
  weight?: number | undefined;
91
91
  }>]>>>>>;
92
+ compute: z.ZodOptional<z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
93
+ pool: z.ZodOptional<z.ZodDefault<z.ZodString>>;
94
+ numReplicas: z.ZodDefault<z.ZodNumber>;
95
+ regions: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion>, "many">>;
96
+ cpus: z.ZodNumber;
97
+ }, {
98
+ cpuKind: z.ZodLiteral<"shared">;
99
+ memoryMb: z.ZodEffects<z.ZodNumber, number, number>;
100
+ }>, "strip", z.ZodTypeAny, {
101
+ numReplicas: number;
102
+ cpus: number;
103
+ cpuKind: "shared";
104
+ memoryMb: number;
105
+ pool?: string | undefined;
106
+ regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
107
+ }, {
108
+ cpus: number;
109
+ cpuKind: "shared";
110
+ memoryMb: number;
111
+ pool?: string | undefined;
112
+ numReplicas?: number | undefined;
113
+ regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
114
+ }>, z.ZodObject<z.objectUtil.extendShape<{
115
+ pool: z.ZodOptional<z.ZodDefault<z.ZodString>>;
116
+ numReplicas: z.ZodDefault<z.ZodNumber>;
117
+ regions: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion>, "many">>;
118
+ cpus: z.ZodNumber;
119
+ }, {
120
+ cpuKind: z.ZodLiteral<"dedicated">;
121
+ memoryMb: z.ZodEffects<z.ZodNumber, number, number>;
122
+ }>, "strip", z.ZodTypeAny, {
123
+ numReplicas: number;
124
+ cpus: number;
125
+ cpuKind: "dedicated";
126
+ memoryMb: number;
127
+ pool?: string | undefined;
128
+ regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
129
+ }, {
130
+ cpus: number;
131
+ cpuKind: "dedicated";
132
+ memoryMb: number;
133
+ pool?: string | undefined;
134
+ numReplicas?: number | undefined;
135
+ regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
136
+ }>]>>;
92
137
  }, "strip", z.ZodTypeAny, {
93
138
  name: string;
94
139
  timeout?: string | undefined;
95
140
  parents?: string[] | undefined;
96
141
  retries?: number | undefined;
142
+ compute?: {
143
+ numReplicas: number;
144
+ cpus: number;
145
+ cpuKind: "shared";
146
+ memoryMb: number;
147
+ pool?: string | undefined;
148
+ regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
149
+ } | {
150
+ numReplicas: number;
151
+ cpus: number;
152
+ cpuKind: "dedicated";
153
+ memoryMb: number;
154
+ pool?: string | undefined;
155
+ regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
156
+ } | undefined;
97
157
  rate_limits?: {
98
158
  units: string | number;
99
159
  key?: string | undefined;
@@ -113,6 +173,21 @@ export declare const CreateStepSchema: z.ZodObject<{
113
173
  timeout?: string | undefined;
114
174
  parents?: string[] | undefined;
115
175
  retries?: number | undefined;
176
+ compute?: {
177
+ cpus: number;
178
+ cpuKind: "shared";
179
+ memoryMb: number;
180
+ pool?: string | undefined;
181
+ numReplicas?: number | undefined;
182
+ regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
183
+ } | {
184
+ cpus: number;
185
+ cpuKind: "dedicated";
186
+ memoryMb: number;
187
+ pool?: string | undefined;
188
+ numReplicas?: number | undefined;
189
+ regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
190
+ } | undefined;
116
191
  rate_limits?: {
117
192
  units: string | number;
118
193
  key?: string | undefined;
@@ -183,6 +258,21 @@ export declare class Context<T, K = {}> {
183
258
  refreshTimeout(incrementBy: string): Promise<void>;
184
259
  releaseSlot(): Promise<void>;
185
260
  putStream(data: string | Uint8Array): Promise<void>;
261
+ /**
262
+ * Spawns multiple workflows.
263
+ *
264
+ * @param workflows an array of objects containing the workflow name, input data, and options for each workflow
265
+ * @returns a list of references to the spawned workflow runs
266
+ */
267
+ spawnWorkflows<Q = JsonValue, P = JsonValue>(workflows: Array<{
268
+ workflow: string | Workflow;
269
+ input: Q;
270
+ options?: {
271
+ key?: string;
272
+ sticky?: boolean;
273
+ additionalMetadata?: Record<string, string>;
274
+ };
275
+ }>): Promise<WorkflowRunRef<P>[]>;
186
276
  /**
187
277
  * Spawns a new workflow.
188
278
  *
package/step.js CHANGED
@@ -44,11 +44,12 @@ const workflow_1 = require("./workflow");
44
44
  const logger_1 = require("./util/logger");
45
45
  const parse_1 = require("./util/parse");
46
46
  const workflows_1 = require("./protoc/workflows");
47
+ const compute_config_1 = require("./clients/worker/compute/compute-config");
47
48
  exports.CreateRateLimitSchema = z.object({
48
49
  key: z.string().optional(),
49
50
  staticKey: z.string().optional(),
50
51
  dynamicKey: z.string().optional(),
51
- units: z.union([z.number().min(1), z.string()]),
52
+ units: z.union([z.number().min(0), z.string()]),
52
53
  limit: z.union([z.number().min(1), z.string()]).optional(),
53
54
  duration: z.nativeEnum(workflows_1.RateLimitDuration).optional(),
54
55
  });
@@ -74,6 +75,7 @@ exports.CreateStepSchema = z.object({
74
75
  retries: z.number().optional(),
75
76
  rate_limits: z.array(exports.CreateRateLimitSchema).optional(),
76
77
  worker_labels: z.record(z.lazy(() => exports.DesiredWorkerLabelSchema)).optional(),
78
+ compute: compute_config_1.ComputeSchema.optional(),
77
79
  });
78
80
  class ContextWorker {
79
81
  constructor(worker) {
@@ -205,6 +207,57 @@ class Context {
205
207
  yield this.client.event.putStream(stepRunId, data);
206
208
  });
207
209
  }
210
+ /**
211
+ * Spawns multiple workflows.
212
+ *
213
+ * @param workflows an array of objects containing the workflow name, input data, and options for each workflow
214
+ * @returns a list of references to the spawned workflow runs
215
+ */
216
+ spawnWorkflows(workflows) {
217
+ const { workflowRunId, stepRunId } = this.action;
218
+ const workflowRuns = workflows.map(({ workflow, input, options }) => {
219
+ let workflowName;
220
+ if (typeof workflow === 'string') {
221
+ workflowName = workflow;
222
+ }
223
+ else {
224
+ workflowName = workflow.id;
225
+ }
226
+ const name = this.client.config.namespace + workflowName;
227
+ let key;
228
+ let sticky = false;
229
+ let metadata;
230
+ if (options) {
231
+ key = options.key;
232
+ sticky = options.sticky;
233
+ metadata = options.additionalMetadata;
234
+ }
235
+ if (sticky && !this.worker.hasWorkflow(name)) {
236
+ throw new hatchet_error_1.default(`Cannot run with sticky: workflow ${name} is not registered on the worker`);
237
+ }
238
+ const resp = {
239
+ workflowName: name,
240
+ input,
241
+ options: {
242
+ parentId: workflowRunId,
243
+ parentStepRunId: stepRunId,
244
+ childKey: key,
245
+ childIndex: this.spawnIndex,
246
+ desiredWorkerId: sticky ? this.worker.id() : undefined,
247
+ additionalMetadata: metadata,
248
+ },
249
+ };
250
+ this.spawnIndex += 1;
251
+ return resp;
252
+ });
253
+ try {
254
+ const resp = this.client.admin.runWorkflows(workflowRuns);
255
+ return resp;
256
+ }
257
+ catch (e) {
258
+ throw new hatchet_error_1.default(e.message);
259
+ }
260
+ }
208
261
  /**
209
262
  * Spawns a new workflow.
210
263
  *
@@ -66,6 +66,22 @@ class ConfigLoader {
66
66
  apiUrl = (_z = (_y = override === null || override === void 0 ? void 0 : override.api_url) !== null && _y !== void 0 ? _y : yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _z !== void 0 ? _z : this.env('HATCHET_CLIENT_API_URL');
67
67
  }
68
68
  const namespace = (_1 = (_0 = override === null || override === void 0 ? void 0 : override.namespace) !== null && _0 !== void 0 ? _0 : yaml === null || yaml === void 0 ? void 0 : yaml.namespace) !== null && _1 !== void 0 ? _1 : this.env('HATCHET_CLIENT_NAMESPACE');
69
+ let rawRunnableActions;
70
+ if (override === null || override === void 0 ? void 0 : override.runnable_actions) {
71
+ rawRunnableActions = override.runnable_actions;
72
+ }
73
+ else if (yaml === null || yaml === void 0 ? void 0 : yaml.runnable_actions) {
74
+ rawRunnableActions = yaml.runnable_actions;
75
+ }
76
+ else {
77
+ const envActions = this.env('HATCHET_CLOUD_ACTIONS');
78
+ if (envActions) {
79
+ rawRunnableActions = envActions.split(',');
80
+ }
81
+ }
82
+ const registerId = this.env('HATCHET_CLOUD_REGISTER_ID');
83
+ const namespacePrefix = namespace ? `${namespace}_`.toLowerCase() : '';
84
+ const runnableActions = rawRunnableActions === null || rawRunnableActions === void 0 ? void 0 : rawRunnableActions.map((action) => namespacePrefix + action.trim());
69
85
  return {
70
86
  token: (_3 = (_2 = override === null || override === void 0 ? void 0 : override.token) !== null && _2 !== void 0 ? _2 : yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _3 !== void 0 ? _3 : this.env('HATCHET_CLIENT_TOKEN'),
71
87
  host_port: grpcBroadcastAddress,
@@ -73,7 +89,9 @@ class ConfigLoader {
73
89
  tls_config: tlsConfig,
74
90
  log_level: (_6 = (_5 = (_4 = override === null || override === void 0 ? void 0 : override.log_level) !== null && _4 !== void 0 ? _4 : yaml === null || yaml === void 0 ? void 0 : yaml.log_level) !== null && _5 !== void 0 ? _5 : this.env('HATCHET_CLIENT_LOG_LEVEL')) !== null && _6 !== void 0 ? _6 : 'INFO',
75
91
  tenant_id: tenantId,
76
- namespace: namespace ? `${namespace}_`.toLowerCase() : '',
92
+ namespace: namespacePrefix,
93
+ runnable_actions: runnableActions,
94
+ cloud_register_id: registerId,
77
95
  };
78
96
  }
79
97
  static get default_yaml_config_path() {