@hatchet-dev/typescript-sdk 0.13.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "0.13.1",
3
+ "version": "0.15.0",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -43,6 +43,9 @@
43
43
  "worker:on-failure": "npm run exec -- ./src/examples/on-failure.ts",
44
44
  "manual:trigger": "npm run exec -- ./src/examples/manual-trigger.ts",
45
45
  "manual:meta": "npm run exec -- ./src/examples/stream-by-additional-meta.ts",
46
+ "bulk:trigger": "npm run exec -- ./src/examples/bulk-trigger.ts",
47
+ "bulk:fanout:worker": "npm run exec -- ./src/examples/bulk-fanout-worker.ts",
48
+ "bulk:fanout:trigger": "npm run exec -- ./src/examples/bulk-fanout-trigger.ts",
46
49
  "worker:dag": "npm run exec -- ./src/examples/dag-worker.ts",
47
50
  "worker:concurrency": "npm run exec -- ./src/examples/concurrency/cancel-in-progress/concurrency-worker.ts",
48
51
  "event:concurrency": "npm run exec -- ./src/examples/concurrency/cancel-in-progress/concurrency-event.ts",
@@ -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';
@@ -153,8 +153,16 @@ export interface CreateWorkflowStepOpts_WorkerLabelsEntry {
153
153
  export interface CreateStepRateLimit {
154
154
  /** (required) the key for the rate limit */
155
155
  key: string;
156
- /** (required) the number of units this step consumes */
157
- units: number;
156
+ /** (optional) the number of units this step consumes */
157
+ units?: number | undefined;
158
+ /** (optional) a CEL expression for determining the rate limit key */
159
+ keyExpr?: string | undefined;
160
+ /** (optional) a CEL expression for determining the number of units consumed */
161
+ unitsExpr?: string | undefined;
162
+ /** (optional) a CEL expression for determining the total amount of rate limit units */
163
+ limitValuesExpr?: string | undefined;
164
+ /** (optional) the default rate limit window to use for dynamic rate limits */
165
+ duration?: RateLimitDuration | undefined;
158
166
  }
159
167
  /** ListWorkflowsRequest is the request for ListWorkflows. */
160
168
  export interface ListWorkflowsRequest {
@@ -198,6 +206,12 @@ export interface WorkflowTriggerCronRef {
198
206
  parentId: string;
199
207
  cron: string;
200
208
  }
209
+ export interface BulkTriggerWorkflowRequest {
210
+ workflows: TriggerWorkflowRequest[];
211
+ }
212
+ export interface BulkTriggerWorkflowResponse {
213
+ workflowRunIds: string[];
214
+ }
201
215
  export interface TriggerWorkflowRequest {
202
216
  name: string;
203
217
  /** (optional) the input data for the workflow */
@@ -254,6 +268,8 @@ export declare const ScheduleWorkflowRequest: MessageFns<ScheduleWorkflowRequest
254
268
  export declare const WorkflowVersion: MessageFns<WorkflowVersion>;
255
269
  export declare const WorkflowTriggerEventRef: MessageFns<WorkflowTriggerEventRef>;
256
270
  export declare const WorkflowTriggerCronRef: MessageFns<WorkflowTriggerCronRef>;
271
+ export declare const BulkTriggerWorkflowRequest: MessageFns<BulkTriggerWorkflowRequest>;
272
+ export declare const BulkTriggerWorkflowResponse: MessageFns<BulkTriggerWorkflowResponse>;
257
273
  export declare const TriggerWorkflowRequest: MessageFns<TriggerWorkflowRequest>;
258
274
  export declare const TriggerWorkflowResponse: MessageFns<TriggerWorkflowResponse>;
259
275
  export declare const PutRateLimitRequest: MessageFns<PutRateLimitRequest>;
@@ -288,6 +304,14 @@ export declare const WorkflowServiceDefinition: {
288
304
  readonly responseStream: false;
289
305
  readonly options: {};
290
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
+ };
291
315
  readonly putRateLimit: {
292
316
  readonly name: "PutRateLimit";
293
317
  readonly requestType: MessageFns<PutRateLimitRequest>;
@@ -302,12 +326,14 @@ export interface WorkflowServiceImplementation<CallContextExt = {}> {
302
326
  putWorkflow(request: PutWorkflowRequest, context: CallContext & CallContextExt): Promise<DeepPartial<WorkflowVersion>>;
303
327
  scheduleWorkflow(request: ScheduleWorkflowRequest, context: CallContext & CallContextExt): Promise<DeepPartial<WorkflowVersion>>;
304
328
  triggerWorkflow(request: TriggerWorkflowRequest, context: CallContext & CallContextExt): Promise<DeepPartial<TriggerWorkflowResponse>>;
329
+ bulkTriggerWorkflow(request: BulkTriggerWorkflowRequest, context: CallContext & CallContextExt): Promise<DeepPartial<BulkTriggerWorkflowResponse>>;
305
330
  putRateLimit(request: PutRateLimitRequest, context: CallContext & CallContextExt): Promise<DeepPartial<PutRateLimitResponse>>;
306
331
  }
307
332
  export interface WorkflowServiceClient<CallOptionsExt = {}> {
308
333
  putWorkflow(request: DeepPartial<PutWorkflowRequest>, options?: CallOptions & CallOptionsExt): Promise<WorkflowVersion>;
309
334
  scheduleWorkflow(request: DeepPartial<ScheduleWorkflowRequest>, options?: CallOptions & CallOptionsExt): Promise<WorkflowVersion>;
310
335
  triggerWorkflow(request: DeepPartial<TriggerWorkflowRequest>, options?: CallOptions & CallOptionsExt): Promise<TriggerWorkflowResponse>;
336
+ bulkTriggerWorkflow(request: DeepPartial<BulkTriggerWorkflowRequest>, options?: CallOptions & CallOptionsExt): Promise<BulkTriggerWorkflowResponse>;
311
337
  putRateLimit(request: DeepPartial<PutRateLimitRequest>, options?: CallOptions & CallOptionsExt): Promise<PutRateLimitResponse>;
312
338
  }
313
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;
@@ -1143,16 +1143,35 @@ exports.CreateWorkflowStepOpts_WorkerLabelsEntry = {
1143
1143
  },
1144
1144
  };
1145
1145
  function createBaseCreateStepRateLimit() {
1146
- return { key: '', units: 0 };
1146
+ return {
1147
+ key: '',
1148
+ units: undefined,
1149
+ keyExpr: undefined,
1150
+ unitsExpr: undefined,
1151
+ limitValuesExpr: undefined,
1152
+ duration: undefined,
1153
+ };
1147
1154
  }
1148
1155
  exports.CreateStepRateLimit = {
1149
1156
  encode(message, writer = new wire_1.BinaryWriter()) {
1150
1157
  if (message.key !== '') {
1151
1158
  writer.uint32(10).string(message.key);
1152
1159
  }
1153
- if (message.units !== 0) {
1160
+ if (message.units !== undefined) {
1154
1161
  writer.uint32(16).int32(message.units);
1155
1162
  }
1163
+ if (message.keyExpr !== undefined) {
1164
+ writer.uint32(26).string(message.keyExpr);
1165
+ }
1166
+ if (message.unitsExpr !== undefined) {
1167
+ writer.uint32(34).string(message.unitsExpr);
1168
+ }
1169
+ if (message.limitValuesExpr !== undefined) {
1170
+ writer.uint32(42).string(message.limitValuesExpr);
1171
+ }
1172
+ if (message.duration !== undefined) {
1173
+ writer.uint32(48).int32(message.duration);
1174
+ }
1156
1175
  return writer;
1157
1176
  },
1158
1177
  decode(input, length) {
@@ -1174,6 +1193,30 @@ exports.CreateStepRateLimit = {
1174
1193
  }
1175
1194
  message.units = reader.int32();
1176
1195
  continue;
1196
+ case 3:
1197
+ if (tag !== 26) {
1198
+ break;
1199
+ }
1200
+ message.keyExpr = reader.string();
1201
+ continue;
1202
+ case 4:
1203
+ if (tag !== 34) {
1204
+ break;
1205
+ }
1206
+ message.unitsExpr = reader.string();
1207
+ continue;
1208
+ case 5:
1209
+ if (tag !== 42) {
1210
+ break;
1211
+ }
1212
+ message.limitValuesExpr = reader.string();
1213
+ continue;
1214
+ case 6:
1215
+ if (tag !== 48) {
1216
+ break;
1217
+ }
1218
+ message.duration = reader.int32();
1219
+ continue;
1177
1220
  }
1178
1221
  if ((tag & 7) === 4 || tag === 0) {
1179
1222
  break;
@@ -1185,7 +1228,13 @@ exports.CreateStepRateLimit = {
1185
1228
  fromJSON(object) {
1186
1229
  return {
1187
1230
  key: isSet(object.key) ? globalThis.String(object.key) : '',
1188
- units: isSet(object.units) ? globalThis.Number(object.units) : 0,
1231
+ units: isSet(object.units) ? globalThis.Number(object.units) : undefined,
1232
+ keyExpr: isSet(object.keyExpr) ? globalThis.String(object.keyExpr) : undefined,
1233
+ unitsExpr: isSet(object.unitsExpr) ? globalThis.String(object.unitsExpr) : undefined,
1234
+ limitValuesExpr: isSet(object.limitValuesExpr)
1235
+ ? globalThis.String(object.limitValuesExpr)
1236
+ : undefined,
1237
+ duration: isSet(object.duration) ? rateLimitDurationFromJSON(object.duration) : undefined,
1189
1238
  };
1190
1239
  },
1191
1240
  toJSON(message) {
@@ -1193,19 +1242,35 @@ exports.CreateStepRateLimit = {
1193
1242
  if (message.key !== '') {
1194
1243
  obj.key = message.key;
1195
1244
  }
1196
- if (message.units !== 0) {
1245
+ if (message.units !== undefined) {
1197
1246
  obj.units = Math.round(message.units);
1198
1247
  }
1248
+ if (message.keyExpr !== undefined) {
1249
+ obj.keyExpr = message.keyExpr;
1250
+ }
1251
+ if (message.unitsExpr !== undefined) {
1252
+ obj.unitsExpr = message.unitsExpr;
1253
+ }
1254
+ if (message.limitValuesExpr !== undefined) {
1255
+ obj.limitValuesExpr = message.limitValuesExpr;
1256
+ }
1257
+ if (message.duration !== undefined) {
1258
+ obj.duration = rateLimitDurationToJSON(message.duration);
1259
+ }
1199
1260
  return obj;
1200
1261
  },
1201
1262
  create(base) {
1202
1263
  return exports.CreateStepRateLimit.fromPartial(base !== null && base !== void 0 ? base : {});
1203
1264
  },
1204
1265
  fromPartial(object) {
1205
- var _a, _b;
1266
+ var _a, _b, _c, _d, _e, _f;
1206
1267
  const message = createBaseCreateStepRateLimit();
1207
1268
  message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
1208
- message.units = (_b = object.units) !== null && _b !== void 0 ? _b : 0;
1269
+ message.units = (_b = object.units) !== null && _b !== void 0 ? _b : undefined;
1270
+ message.keyExpr = (_c = object.keyExpr) !== null && _c !== void 0 ? _c : undefined;
1271
+ message.unitsExpr = (_d = object.unitsExpr) !== null && _d !== void 0 ? _d : undefined;
1272
+ message.limitValuesExpr = (_e = object.limitValuesExpr) !== null && _e !== void 0 ? _e : undefined;
1273
+ message.duration = (_f = object.duration) !== null && _f !== void 0 ? _f : undefined;
1209
1274
  return message;
1210
1275
  },
1211
1276
  };
@@ -1660,6 +1725,118 @@ exports.WorkflowTriggerCronRef = {
1660
1725
  return message;
1661
1726
  },
1662
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
+ };
1663
1840
  function createBaseTriggerWorkflowRequest() {
1664
1841
  return {
1665
1842
  name: '',
@@ -2040,6 +2217,14 @@ exports.WorkflowServiceDefinition = {
2040
2217
  responseStream: false,
2041
2218
  options: {},
2042
2219
  },
2220
+ bulkTriggerWorkflow: {
2221
+ name: 'BulkTriggerWorkflow',
2222
+ requestType: exports.BulkTriggerWorkflowRequest,
2223
+ requestStream: false,
2224
+ responseType: exports.BulkTriggerWorkflowResponse,
2225
+ responseStream: false,
2226
+ options: {},
2227
+ },
2043
2228
  putRateLimit: {
2044
2229
  name: 'PutRateLimit',
2045
2230
  requestType: exports.PutRateLimitRequest,
package/step.d.ts CHANGED
@@ -7,16 +7,28 @@ import { HatchetClient } from './clients/hatchet-client';
7
7
  import WorkflowRunRef from './util/workflow-run-ref';
8
8
  import { Worker } from './clients/worker';
9
9
  import { WorkerLabels } from './clients/dispatcher/dispatcher-client';
10
- import { WorkerLabelComparator } from './protoc/workflows';
10
+ import { CreateStepRateLimit, RateLimitDuration, WorkerLabelComparator } from './protoc/workflows';
11
11
  export declare const CreateRateLimitSchema: z.ZodObject<{
12
- key: z.ZodString;
13
- units: z.ZodNumber;
12
+ key: z.ZodOptional<z.ZodString>;
13
+ staticKey: z.ZodOptional<z.ZodString>;
14
+ dynamicKey: z.ZodOptional<z.ZodString>;
15
+ units: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
16
+ limit: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
17
+ duration: z.ZodOptional<z.ZodNativeEnum<typeof RateLimitDuration>>;
14
18
  }, "strip", z.ZodTypeAny, {
15
- key: string;
16
- units: number;
19
+ units: string | number;
20
+ key?: string | undefined;
21
+ duration?: RateLimitDuration | undefined;
22
+ limit?: string | number | undefined;
23
+ staticKey?: string | undefined;
24
+ dynamicKey?: string | undefined;
17
25
  }, {
18
- key: string;
19
- units: number;
26
+ units: string | number;
27
+ key?: string | undefined;
28
+ duration?: RateLimitDuration | undefined;
29
+ limit?: string | number | undefined;
30
+ staticKey?: string | undefined;
31
+ dynamicKey?: string | undefined;
20
32
  }>;
21
33
  export declare const DesiredWorkerLabelSchema: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodObject<{
22
34
  value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
@@ -40,14 +52,26 @@ export declare const CreateStepSchema: z.ZodObject<{
40
52
  timeout: z.ZodOptional<z.ZodString>;
41
53
  retries: z.ZodOptional<z.ZodNumber>;
42
54
  rate_limits: z.ZodOptional<z.ZodArray<z.ZodObject<{
43
- key: z.ZodString;
44
- units: z.ZodNumber;
55
+ key: z.ZodOptional<z.ZodString>;
56
+ staticKey: z.ZodOptional<z.ZodString>;
57
+ dynamicKey: z.ZodOptional<z.ZodString>;
58
+ units: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
59
+ limit: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
60
+ duration: z.ZodOptional<z.ZodNativeEnum<typeof RateLimitDuration>>;
45
61
  }, "strip", z.ZodTypeAny, {
46
- key: string;
47
- units: number;
62
+ units: string | number;
63
+ key?: string | undefined;
64
+ duration?: RateLimitDuration | undefined;
65
+ limit?: string | number | undefined;
66
+ staticKey?: string | undefined;
67
+ dynamicKey?: string | undefined;
48
68
  }, {
49
- key: string;
50
- units: number;
69
+ units: string | number;
70
+ key?: string | undefined;
71
+ duration?: RateLimitDuration | undefined;
72
+ limit?: string | number | undefined;
73
+ staticKey?: string | undefined;
74
+ dynamicKey?: string | undefined;
51
75
  }>, "many">>;
52
76
  worker_labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodLazy<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodObject<{
53
77
  value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
@@ -71,8 +95,12 @@ export declare const CreateStepSchema: z.ZodObject<{
71
95
  parents?: string[] | undefined;
72
96
  retries?: number | undefined;
73
97
  rate_limits?: {
74
- key: string;
75
- units: number;
98
+ units: string | number;
99
+ key?: string | undefined;
100
+ duration?: RateLimitDuration | undefined;
101
+ limit?: string | number | undefined;
102
+ staticKey?: string | undefined;
103
+ dynamicKey?: string | undefined;
76
104
  }[] | undefined;
77
105
  worker_labels?: Record<string, string | number | {
78
106
  value: string | number;
@@ -86,8 +114,12 @@ export declare const CreateStepSchema: z.ZodObject<{
86
114
  parents?: string[] | undefined;
87
115
  retries?: number | undefined;
88
116
  rate_limits?: {
89
- key: string;
90
- units: number;
117
+ units: string | number;
118
+ key?: string | undefined;
119
+ duration?: RateLimitDuration | undefined;
120
+ limit?: string | number | undefined;
121
+ staticKey?: string | undefined;
122
+ dynamicKey?: string | undefined;
91
123
  }[] | undefined;
92
124
  worker_labels?: Record<string, string | number | {
93
125
  value: string | number;
@@ -151,6 +183,21 @@ export declare class Context<T, K = {}> {
151
183
  refreshTimeout(incrementBy: string): Promise<void>;
152
184
  releaseSlot(): Promise<void>;
153
185
  putStream(data: string | Uint8Array): Promise<void>;
186
+ /**
187
+ * Spawns multiple workflows.
188
+ *
189
+ * @param workflows an array of objects containing the workflow name, input data, and options for each workflow
190
+ * @returns a list of references to the spawned workflow runs
191
+ */
192
+ spawnWorkflows<Q = JsonValue, P = JsonValue>(workflows: Array<{
193
+ workflow: string | Workflow;
194
+ input: Q;
195
+ options?: {
196
+ key?: string;
197
+ sticky?: boolean;
198
+ additionalMetadata?: Record<string, string>;
199
+ };
200
+ }>): Promise<WorkflowRunRef<P>[]>;
154
201
  /**
155
202
  * Spawns a new workflow.
156
203
  *
@@ -178,4 +225,5 @@ export type StepRunFunction<T, K> = (ctx: Context<T, K>) => Promise<NextStep | v
178
225
  export interface CreateStep<T, K> extends z.infer<typeof CreateStepSchema> {
179
226
  run: StepRunFunction<T, K>;
180
227
  }
228
+ export declare function mapRateLimit(limits: CreateStep<any, any>['rate_limits']): CreateStepRateLimit[];
181
229
  export {};
package/step.js CHANGED
@@ -36,6 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.Context = exports.ContextWorker = exports.CreateStepSchema = exports.DesiredWorkerLabelSchema = exports.CreateRateLimitSchema = void 0;
39
+ exports.mapRateLimit = mapRateLimit;
39
40
  /* eslint-disable max-classes-per-file */
40
41
  const hatchet_error_1 = __importDefault(require("./util/errors/hatchet-error"));
41
42
  const z = __importStar(require("zod"));
@@ -44,8 +45,12 @@ const logger_1 = require("./util/logger");
44
45
  const parse_1 = require("./util/parse");
45
46
  const workflows_1 = require("./protoc/workflows");
46
47
  exports.CreateRateLimitSchema = z.object({
47
- key: z.string(),
48
- units: z.number().min(1),
48
+ key: z.string().optional(),
49
+ staticKey: z.string().optional(),
50
+ dynamicKey: z.string().optional(),
51
+ units: z.union([z.number().min(0), z.string()]),
52
+ limit: z.union([z.number().min(1), z.string()]).optional(),
53
+ duration: z.nativeEnum(workflows_1.RateLimitDuration).optional(),
49
54
  });
50
55
  exports.DesiredWorkerLabelSchema = z
51
56
  .union([
@@ -200,6 +205,57 @@ class Context {
200
205
  yield this.client.event.putStream(stepRunId, data);
201
206
  });
202
207
  }
208
+ /**
209
+ * Spawns multiple workflows.
210
+ *
211
+ * @param workflows an array of objects containing the workflow name, input data, and options for each workflow
212
+ * @returns a list of references to the spawned workflow runs
213
+ */
214
+ spawnWorkflows(workflows) {
215
+ const { workflowRunId, stepRunId } = this.action;
216
+ const workflowRuns = workflows.map(({ workflow, input, options }) => {
217
+ let workflowName;
218
+ if (typeof workflow === 'string') {
219
+ workflowName = workflow;
220
+ }
221
+ else {
222
+ workflowName = workflow.id;
223
+ }
224
+ const name = this.client.config.namespace + workflowName;
225
+ let key;
226
+ let sticky = false;
227
+ let metadata;
228
+ if (options) {
229
+ key = options.key;
230
+ sticky = options.sticky;
231
+ metadata = options.additionalMetadata;
232
+ }
233
+ if (sticky && !this.worker.hasWorkflow(name)) {
234
+ throw new hatchet_error_1.default(`Cannot run with sticky: workflow ${name} is not registered on the worker`);
235
+ }
236
+ const resp = {
237
+ workflowName: name,
238
+ input,
239
+ options: {
240
+ parentId: workflowRunId,
241
+ parentStepRunId: stepRunId,
242
+ childKey: key,
243
+ childIndex: this.spawnIndex,
244
+ desiredWorkerId: sticky ? this.worker.id() : undefined,
245
+ additionalMetadata: metadata,
246
+ },
247
+ };
248
+ this.spawnIndex += 1;
249
+ return resp;
250
+ });
251
+ try {
252
+ const resp = this.client.admin.runWorkflows(workflowRuns);
253
+ return resp;
254
+ }
255
+ catch (e) {
256
+ throw new hatchet_error_1.default(e.message);
257
+ }
258
+ }
203
259
  /**
204
260
  * Spawns a new workflow.
205
261
  *
@@ -273,3 +329,68 @@ class Context {
273
329
  }
274
330
  }
275
331
  exports.Context = Context;
332
+ function mapRateLimit(limits) {
333
+ if (!limits)
334
+ return [];
335
+ return limits.map((l) => {
336
+ let key = l.staticKey;
337
+ const keyExpression = l.dynamicKey;
338
+ if (l.key !== undefined) {
339
+ // eslint-disable-next-line no-console
340
+ console.warn('key is deprecated and will be removed in a future release, please use staticKey instead');
341
+ key = l.key;
342
+ }
343
+ if (keyExpression !== undefined) {
344
+ if (key !== undefined) {
345
+ throw new Error('Cannot have both static key and dynamic key set');
346
+ }
347
+ key = keyExpression;
348
+ if (!validateCelExpression(keyExpression)) {
349
+ throw new Error(`Invalid CEL expression: ${keyExpression}`);
350
+ }
351
+ }
352
+ if (key === undefined) {
353
+ throw new Error(`Invalid key`);
354
+ }
355
+ let units;
356
+ let unitsExpression;
357
+ if (typeof l.units === 'number') {
358
+ units = l.units;
359
+ }
360
+ else {
361
+ if (!validateCelExpression(l.units)) {
362
+ throw new Error(`Invalid CEL expression: ${l.units}`);
363
+ }
364
+ unitsExpression = l.units;
365
+ }
366
+ let limitExpression;
367
+ if (l.limit !== undefined) {
368
+ if (typeof l.limit === 'number') {
369
+ limitExpression = `${l.limit}`;
370
+ }
371
+ else {
372
+ if (!validateCelExpression(l.limit)) {
373
+ throw new Error(`Invalid CEL expression: ${l.limit}`);
374
+ }
375
+ limitExpression = l.limit;
376
+ }
377
+ }
378
+ if (keyExpression !== undefined && limitExpression === undefined) {
379
+ throw new Error('CEL based keys requires limit to be set');
380
+ }
381
+ return {
382
+ key,
383
+ keyExpr: keyExpression,
384
+ units,
385
+ unitsExpr: unitsExpression,
386
+ limitValuesExpr: limitExpression,
387
+ duration: l.duration,
388
+ };
389
+ });
390
+ }
391
+ // Helper function to validate CEL expressions
392
+ function validateCelExpression(expr) {
393
+ // This is a placeholder. In a real implementation, you'd need to use a CEL parser or validator.
394
+ // For now, we'll just return true to mimic the behavior.
395
+ return true;
396
+ }