@hatchet-dev/typescript-sdk 0.13.1 → 0.14.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.
@@ -1,4 +1,4 @@
1
- import { AcceptInviteRequest, APIErrors, APIMeta, BulkCreateEventRequest, BulkCreateEventResponse, CancelEventRequest, CreateAPITokenRequest, CreateAPITokenResponse, CreateEventRequest, CreateSNSIntegrationRequest, CreateTenantAlertEmailGroupRequest, CreateTenantInviteRequest, CreateTenantRequest, Event, EventData, EventKey, EventKeyList, EventList, EventOrderByDirection, EventOrderByField, EventSearch, ListAPIMetaIntegration, ListAPITokensResponse, ListSlackWebhooks, ListSNSIntegrations, LogLineLevelField, LogLineList, LogLineOrderByDirection, LogLineOrderByField, LogLineSearch, RejectInviteRequest, ReplayEventRequest, ReplayWorkflowRunsRequest, ReplayWorkflowRunsResponse, RerunStepRunRequest, SNSIntegration, StepRun, StepRunArchiveList, StepRunEventList, Tenant, TenantAlertEmailGroup, TenantAlertEmailGroupList, TenantAlertingSettings, TenantInvite, TenantInviteList, TenantMember, TenantMemberList, TenantQueueMetrics, TenantResourcePolicy, TriggerWorkflowRunRequest, UpdateTenantAlertEmailGroupRequest, UpdateTenantInviteRequest, UpdateTenantRequest, UpdateWorkerRequest, User, UserChangePasswordRequest, UserLoginRequest, UserRegisterRequest, UserTenantMembershipsList, WebhookWorkerCreated, WebhookWorkerCreateRequest, WebhookWorkerListResponse, WebhookWorkerRequestListResponse, Worker, WorkerList, Workflow, WorkflowID, WorkflowKindList, WorkflowList, WorkflowMetrics, WorkflowRun, WorkflowRunList, WorkflowRunOrderByDirection, WorkflowRunOrderByField, WorkflowRunsCancelRequest, WorkflowRunShape, WorkflowRunsMetrics, WorkflowRunStatus, WorkflowRunStatusList, WorkflowVersion, WorkflowWorkersCount } from './data-contracts';
1
+ import { AcceptInviteRequest, APIErrors, APIMeta, BulkCreateEventRequest, BulkCreateEventResponse, CancelEventRequest, CreateAPITokenRequest, CreateAPITokenResponse, CreateEventRequest, CreateSNSIntegrationRequest, CreateTenantAlertEmailGroupRequest, CreateTenantInviteRequest, CreateTenantRequest, Event, EventData, EventKey, EventKeyList, EventList, EventOrderByDirection, EventOrderByField, EventSearch, ListAPIMetaIntegration, ListAPITokensResponse, ListSlackWebhooks, ListSNSIntegrations, LogLineLevelField, LogLineList, LogLineOrderByDirection, LogLineOrderByField, LogLineSearch, RateLimitList, RateLimitOrderByDirection, RateLimitOrderByField, RejectInviteRequest, ReplayEventRequest, ReplayWorkflowRunsRequest, ReplayWorkflowRunsResponse, RerunStepRunRequest, SNSIntegration, StepRun, StepRunArchiveList, StepRunEventList, Tenant, TenantAlertEmailGroup, TenantAlertEmailGroupList, TenantAlertingSettings, TenantInvite, TenantInviteList, TenantMember, TenantMemberList, TenantQueueMetrics, TenantResourcePolicy, TriggerWorkflowRunRequest, UpdateTenantAlertEmailGroupRequest, UpdateTenantInviteRequest, UpdateTenantRequest, UpdateWorkerRequest, User, UserChangePasswordRequest, UserLoginRequest, UserRegisterRequest, UserTenantMembershipsList, WebhookWorkerCreated, WebhookWorkerCreateRequest, WebhookWorkerListResponse, WebhookWorkerRequestListResponse, Worker, WorkerList, Workflow, WorkflowID, WorkflowKindList, WorkflowList, WorkflowMetrics, WorkflowRun, WorkflowRunList, WorkflowRunOrderByDirection, WorkflowRunOrderByField, WorkflowRunsCancelRequest, WorkflowRunShape, WorkflowRunsMetrics, WorkflowRunStatus, WorkflowRunStatusList, WorkflowUpdateRequest, WorkflowVersion, WorkflowWorkersCount } from './data-contracts';
2
2
  import { HttpClient, RequestParams } from './http-client';
3
3
  export declare class Api<SecurityDataType = unknown> extends HttpClient<SecurityDataType> {
4
4
  /**
@@ -498,6 +498,33 @@ export declare class Api<SecurityDataType = unknown> extends HttpClient<Security
498
498
  eventUpdateCancel: (tenant: string, data: CancelEventRequest, params?: RequestParams) => Promise<import("axios").AxiosResponse<{
499
499
  workflowRunIds?: string[];
500
500
  }, any>>;
501
+ /**
502
+ * @description Lists all rate limits for a tenant.
503
+ *
504
+ * @tags Rate Limits
505
+ * @name RateLimitList
506
+ * @summary List rate limits
507
+ * @request GET:/api/v1/tenants/{tenant}/rate-limits
508
+ * @secure
509
+ */
510
+ rateLimitList: (tenant: string, query?: {
511
+ /**
512
+ * The number to skip
513
+ * @format int64
514
+ */
515
+ offset?: number;
516
+ /**
517
+ * The number to limit by
518
+ * @format int64
519
+ */
520
+ limit?: number;
521
+ /** The search query to filter for */
522
+ search?: string;
523
+ /** What to order by */
524
+ orderByField?: RateLimitOrderByField;
525
+ /** The order direction */
526
+ orderByDirection?: RateLimitOrderByDirection;
527
+ }, params?: RequestParams) => Promise<import("axios").AxiosResponse<RateLimitList, any>>;
501
528
  /**
502
529
  * @description Gets a list of tenant members
503
530
  *
@@ -590,6 +617,16 @@ export declare class Api<SecurityDataType = unknown> extends HttpClient<Security
590
617
  * @secure
591
618
  */
592
619
  workflowDelete: (workflow: string, params?: RequestParams) => Promise<import("axios").AxiosResponse<void, any>>;
620
+ /**
621
+ * @description Update a workflow for a tenant
622
+ *
623
+ * @tags Workflow
624
+ * @name WorkflowUpdate
625
+ * @summary Update workflow
626
+ * @request PATCH:/api/v1/workflows/{workflow}
627
+ * @secure
628
+ */
629
+ workflowUpdate: (workflow: string, data: WorkflowUpdateRequest, params?: RequestParams) => Promise<import("axios").AxiosResponse<Workflow, any>>;
593
630
  /**
594
631
  * @description Get a workflow version for a tenant
595
632
  *
@@ -807,6 +844,18 @@ export declare class Api<SecurityDataType = unknown> extends HttpClient<Security
807
844
  * @example "2021-01-01T00:00:00Z"
808
845
  */
809
846
  createdBefore?: string;
847
+ /**
848
+ * The time after the workflow run was finished
849
+ * @format date-time
850
+ * @example "2021-01-01T00:00:00Z"
851
+ */
852
+ finishedAfter?: string;
853
+ /**
854
+ * The time before the workflow run was finished
855
+ * @format date-time
856
+ * @example "2021-01-01T00:00:00Z"
857
+ */
858
+ finishedBefore?: string;
810
859
  /** The order by field */
811
860
  orderByField?: WorkflowRunOrderByField;
812
861
  /** The order by direction */
@@ -472,6 +472,16 @@ class Api extends http_client_1.HttpClient {
472
472
  * @secure
473
473
  */
474
474
  this.eventUpdateCancel = (tenant, data, params = {}) => this.request(Object.assign({ path: `/api/v1/tenants/${tenant}/events/cancel`, method: 'POST', body: data, secure: true, type: http_client_1.ContentType.Json, format: 'json' }, params));
475
+ /**
476
+ * @description Lists all rate limits for a tenant.
477
+ *
478
+ * @tags Rate Limits
479
+ * @name RateLimitList
480
+ * @summary List rate limits
481
+ * @request GET:/api/v1/tenants/{tenant}/rate-limits
482
+ * @secure
483
+ */
484
+ this.rateLimitList = (tenant, query, params = {}) => this.request(Object.assign({ path: `/api/v1/tenants/${tenant}/rate-limits`, method: 'GET', query: query, secure: true, format: 'json' }, params));
475
485
  /**
476
486
  * @description Gets a list of tenant members
477
487
  *
@@ -562,6 +572,16 @@ class Api extends http_client_1.HttpClient {
562
572
  * @secure
563
573
  */
564
574
  this.workflowDelete = (workflow, params = {}) => this.request(Object.assign({ path: `/api/v1/workflows/${workflow}`, method: 'DELETE', secure: true }, params));
575
+ /**
576
+ * @description Update a workflow for a tenant
577
+ *
578
+ * @tags Workflow
579
+ * @name WorkflowUpdate
580
+ * @summary Update workflow
581
+ * @request PATCH:/api/v1/workflows/{workflow}
582
+ * @secure
583
+ */
584
+ this.workflowUpdate = (workflow, data, params = {}) => this.request(Object.assign({ path: `/api/v1/workflows/${workflow}`, method: 'PATCH', body: data, secure: true, type: http_client_1.ContentType.Json, format: 'json' }, params));
565
585
  /**
566
586
  * @description Get a workflow version for a tenant
567
587
  *
@@ -314,6 +314,7 @@ export interface TenantQueueMetrics {
314
314
  /** The total queue metrics. */
315
315
  total?: QueueMetrics;
316
316
  workflow?: Record<string, QueueMetrics>;
317
+ queues?: Record<string, number>;
317
318
  }
318
319
  export interface AcceptInviteRequest {
319
320
  /**
@@ -437,6 +438,37 @@ export interface EventList {
437
438
  pagination?: PaginationResponse;
438
439
  rows?: Event[];
439
440
  }
441
+ export interface RateLimit {
442
+ /** The key for the rate limit. */
443
+ key: string;
444
+ /** The ID of the tenant associated with this rate limit. */
445
+ tenantId: string;
446
+ /** The maximum number of requests allowed within the window. */
447
+ limitValue: number;
448
+ /** The current number of requests made within the window. */
449
+ value: number;
450
+ /** The window of time in which the limitValue is enforced. */
451
+ window: string;
452
+ /**
453
+ * The last time the rate limit was refilled.
454
+ * @format date-time
455
+ * @example "2022-12-13T20:06:48.888Z"
456
+ */
457
+ lastRefill: string;
458
+ }
459
+ export interface RateLimitList {
460
+ pagination?: PaginationResponse;
461
+ rows?: RateLimit[];
462
+ }
463
+ export declare enum RateLimitOrderByField {
464
+ Key = "key",
465
+ Value = "value",
466
+ LimitValue = "limitValue"
467
+ }
468
+ export declare enum RateLimitOrderByDirection {
469
+ Asc = "asc",
470
+ Desc = "desc"
471
+ }
440
472
  export interface ReplayEventRequest {
441
473
  eventIds: string[];
442
474
  }
@@ -449,12 +481,18 @@ export interface Workflow {
449
481
  name: string;
450
482
  /** The description of the workflow. */
451
483
  description?: string;
484
+ /** Whether the workflow is paused. */
485
+ isPaused?: boolean;
452
486
  versions?: WorkflowVersionMeta[];
453
487
  /** The tags of the workflow. */
454
488
  tags?: WorkflowTag[];
455
489
  /** The jobs of the workflow. */
456
490
  jobs?: Job[];
457
491
  }
492
+ export interface WorkflowUpdateRequest {
493
+ /** Whether the workflow is paused. */
494
+ isPaused?: boolean;
495
+ }
458
496
  export interface WorkflowConcurrency {
459
497
  /**
460
498
  * The maximum number of concurrent workflow runs.
@@ -10,7 +10,7 @@
10
10
  * ---------------------------------------------------------------
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.WebhookWorkerRequestMethod = exports.LogLineOrderByDirection = exports.LogLineOrderByField = exports.LogLineLevel = exports.PullRequestState = exports.StepRunEventSeverity = exports.StepRunEventReason = exports.StepRunStatus = exports.JobRunStatus = exports.WorkflowKind = exports.WorkflowRunStatus = exports.WorkflowRunOrderByDirection = exports.WorkflowRunOrderByField = exports.EventOrderByDirection = exports.EventOrderByField = exports.TenantResource = exports.TenantMemberRole = void 0;
13
+ exports.WebhookWorkerRequestMethod = exports.LogLineOrderByDirection = exports.LogLineOrderByField = exports.LogLineLevel = exports.PullRequestState = exports.StepRunEventSeverity = exports.StepRunEventReason = exports.StepRunStatus = exports.JobRunStatus = exports.WorkflowKind = exports.WorkflowRunStatus = exports.WorkflowRunOrderByDirection = exports.WorkflowRunOrderByField = exports.RateLimitOrderByDirection = exports.RateLimitOrderByField = exports.EventOrderByDirection = exports.EventOrderByField = exports.TenantResource = exports.TenantMemberRole = void 0;
14
14
  var TenantMemberRole;
15
15
  (function (TenantMemberRole) {
16
16
  TenantMemberRole["OWNER"] = "OWNER";
@@ -34,6 +34,17 @@ var EventOrderByDirection;
34
34
  EventOrderByDirection["Asc"] = "asc";
35
35
  EventOrderByDirection["Desc"] = "desc";
36
36
  })(EventOrderByDirection || (exports.EventOrderByDirection = EventOrderByDirection = {}));
37
+ var RateLimitOrderByField;
38
+ (function (RateLimitOrderByField) {
39
+ RateLimitOrderByField["Key"] = "key";
40
+ RateLimitOrderByField["Value"] = "value";
41
+ RateLimitOrderByField["LimitValue"] = "limitValue";
42
+ })(RateLimitOrderByField || (exports.RateLimitOrderByField = RateLimitOrderByField = {}));
43
+ var RateLimitOrderByDirection;
44
+ (function (RateLimitOrderByDirection) {
45
+ RateLimitOrderByDirection["Asc"] = "asc";
46
+ RateLimitOrderByDirection["Desc"] = "desc";
47
+ })(RateLimitOrderByDirection || (exports.RateLimitOrderByDirection = RateLimitOrderByDirection = {}));
37
48
  var WorkflowRunOrderByField;
38
49
  (function (WorkflowRunOrderByField) {
39
50
  WorkflowRunOrderByField["CreatedAt"] = "createdAt";
@@ -83,7 +83,7 @@ class Worker {
83
83
  }
84
84
  registerWorkflow(initWorkflow) {
85
85
  return __awaiter(this, void 0, void 0, function* () {
86
- var _a, _b, _c, _d;
86
+ var _a, _b, _c;
87
87
  const workflow = Object.assign(Object.assign({}, initWorkflow), { id: this.client.config.namespace + initWorkflow.id });
88
88
  try {
89
89
  if (((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.key) && workflow.concurrency.expression) {
@@ -112,7 +112,7 @@ class Worker {
112
112
  parents: [],
113
113
  userData: '{}',
114
114
  retries: workflow.onFailure.retries || 0,
115
- rateLimits: (_d = workflow.onFailure.rate_limits) !== null && _d !== void 0 ? _d : [],
115
+ rateLimits: (0, step_1.mapRateLimit)(workflow.onFailure.rate_limits),
116
116
  workerLabels: {}, // no worker labels for on failure steps
117
117
  },
118
118
  ],
@@ -136,7 +136,7 @@ class Worker {
136
136
  name: workflow.id,
137
137
  description: workflow.description,
138
138
  steps: workflow.steps.map((step) => {
139
- var _a, _b;
139
+ var _a;
140
140
  return ({
141
141
  readableId: step.name,
142
142
  action: `${workflow.id}:${step.name}`,
@@ -145,7 +145,7 @@ class Worker {
145
145
  parents: (_a = step.parents) !== null && _a !== void 0 ? _a : [],
146
146
  userData: '{}',
147
147
  retries: step.retries || 0,
148
- rateLimits: (_b = step.rate_limits) !== null && _b !== void 0 ? _b : [], // Add the missing rateLimits property
148
+ rateLimits: (0, step_1.mapRateLimit)(step.rate_limits),
149
149
  workerLabels: toPbWorkerLabel(step.worker_labels),
150
150
  });
151
151
  }),
@@ -23,10 +23,25 @@ const workflow = {
23
23
  },
24
24
  steps: [
25
25
  {
26
- name: 'step1',
26
+ name: 'dynamic',
27
+ rate_limits: [
28
+ {
29
+ dynamicKey: 'input.group',
30
+ units: 1,
31
+ limit: 10,
32
+ duration: workflows_1.RateLimitDuration.DAY,
33
+ },
34
+ ],
35
+ run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
36
+ console.log('starting step1 with the following input and a dynamic rate limit', ctx.workflowInput());
37
+ return { step1: 'step1 results!' };
38
+ }),
39
+ },
40
+ {
41
+ name: 'static',
27
42
  rate_limits: [{ key: 'test-limit', units: 1 }],
28
43
  run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
29
- console.log('starting step1 with the following input', ctx.workflowInput());
44
+ console.log('starting step1 with the following input and a static rate limit', ctx.workflowInput());
30
45
  return { step1: 'step1 results!' };
31
46
  }),
32
47
  },
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.14.0",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -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 {
@@ -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
  };
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;
@@ -178,4 +210,5 @@ export type StepRunFunction<T, K> = (ctx: Context<T, K>) => Promise<NextStep | v
178
210
  export interface CreateStep<T, K> extends z.infer<typeof CreateStepSchema> {
179
211
  run: StepRunFunction<T, K>;
180
212
  }
213
+ export declare function mapRateLimit(limits: CreateStep<any, any>['rate_limits']): CreateStepRateLimit[];
181
214
  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(1), 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([
@@ -273,3 +278,68 @@ class Context {
273
278
  }
274
279
  }
275
280
  exports.Context = Context;
281
+ function mapRateLimit(limits) {
282
+ if (!limits)
283
+ return [];
284
+ return limits.map((l) => {
285
+ let key = l.staticKey;
286
+ const keyExpression = l.dynamicKey;
287
+ if (l.key !== undefined) {
288
+ // eslint-disable-next-line no-console
289
+ console.warn('key is deprecated and will be removed in a future release, please use staticKey instead');
290
+ key = l.key;
291
+ }
292
+ if (keyExpression !== undefined) {
293
+ if (key !== undefined) {
294
+ throw new Error('Cannot have both static key and dynamic key set');
295
+ }
296
+ key = keyExpression;
297
+ if (!validateCelExpression(keyExpression)) {
298
+ throw new Error(`Invalid CEL expression: ${keyExpression}`);
299
+ }
300
+ }
301
+ if (key === undefined) {
302
+ throw new Error(`Invalid key`);
303
+ }
304
+ let units;
305
+ let unitsExpression;
306
+ if (typeof l.units === 'number') {
307
+ units = l.units;
308
+ }
309
+ else {
310
+ if (!validateCelExpression(l.units)) {
311
+ throw new Error(`Invalid CEL expression: ${l.units}`);
312
+ }
313
+ unitsExpression = l.units;
314
+ }
315
+ let limitExpression;
316
+ if (l.limit !== undefined) {
317
+ if (typeof l.limit === 'number') {
318
+ limitExpression = `${l.limit}`;
319
+ }
320
+ else {
321
+ if (!validateCelExpression(l.limit)) {
322
+ throw new Error(`Invalid CEL expression: ${l.limit}`);
323
+ }
324
+ limitExpression = l.limit;
325
+ }
326
+ }
327
+ if (keyExpression !== undefined && limitExpression === undefined) {
328
+ throw new Error('CEL based keys requires limit to be set');
329
+ }
330
+ return {
331
+ key,
332
+ keyExpr: keyExpression,
333
+ units,
334
+ unitsExpr: unitsExpression,
335
+ limitValuesExpr: limitExpression,
336
+ duration: l.duration,
337
+ };
338
+ });
339
+ }
340
+ // Helper function to validate CEL expressions
341
+ function validateCelExpression(expr) {
342
+ // This is a placeholder. In a real implementation, you'd need to use a CEL parser or validator.
343
+ // For now, we'll just return true to mimic the behavior.
344
+ return true;
345
+ }
package/workflow.d.ts CHANGED
@@ -7,14 +7,26 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
7
7
  timeout: z.ZodOptional<z.ZodString>;
8
8
  retries: z.ZodOptional<z.ZodNumber>;
9
9
  rate_limits: z.ZodOptional<z.ZodArray<z.ZodObject<{
10
- key: z.ZodString;
11
- units: z.ZodNumber;
10
+ key: z.ZodOptional<z.ZodString>;
11
+ staticKey: z.ZodOptional<z.ZodString>;
12
+ dynamicKey: z.ZodOptional<z.ZodString>;
13
+ units: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
14
+ limit: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
15
+ duration: z.ZodOptional<z.ZodNativeEnum<typeof import("./protoc/workflows").RateLimitDuration>>;
12
16
  }, "strip", z.ZodTypeAny, {
13
- key: string;
14
- units: number;
17
+ units: string | number;
18
+ key?: string | undefined;
19
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
20
+ limit?: string | number | undefined;
21
+ staticKey?: string | undefined;
22
+ dynamicKey?: string | undefined;
15
23
  }, {
16
- key: string;
17
- units: number;
24
+ units: string | number;
25
+ key?: string | undefined;
26
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
27
+ limit?: string | number | undefined;
28
+ staticKey?: string | undefined;
29
+ dynamicKey?: string | undefined;
18
30
  }>, "many">>;
19
31
  worker_labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodLazy<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodObject<{
20
32
  value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
@@ -38,8 +50,12 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
38
50
  parents?: string[] | undefined;
39
51
  retries?: number | undefined;
40
52
  rate_limits?: {
41
- key: string;
42
- units: number;
53
+ units: string | number;
54
+ key?: string | undefined;
55
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
56
+ limit?: string | number | undefined;
57
+ staticKey?: string | undefined;
58
+ dynamicKey?: string | undefined;
43
59
  }[] | undefined;
44
60
  worker_labels?: Record<string, string | number | {
45
61
  value: string | number;
@@ -53,8 +69,12 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
53
69
  parents?: string[] | undefined;
54
70
  retries?: number | undefined;
55
71
  rate_limits?: {
56
- key: string;
57
- units: number;
72
+ units: string | number;
73
+ key?: string | undefined;
74
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
75
+ limit?: string | number | undefined;
76
+ staticKey?: string | undefined;
77
+ dynamicKey?: string | undefined;
58
78
  }[] | undefined;
59
79
  worker_labels?: Record<string, string | number | {
60
80
  value: string | number;
@@ -121,14 +141,26 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
121
141
  timeout: z.ZodOptional<z.ZodString>;
122
142
  retries: z.ZodOptional<z.ZodNumber>;
123
143
  rate_limits: z.ZodOptional<z.ZodArray<z.ZodObject<{
124
- key: z.ZodString;
125
- units: z.ZodNumber;
144
+ key: z.ZodOptional<z.ZodString>;
145
+ staticKey: z.ZodOptional<z.ZodString>;
146
+ dynamicKey: z.ZodOptional<z.ZodString>;
147
+ units: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
148
+ limit: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
149
+ duration: z.ZodOptional<z.ZodNativeEnum<typeof import("./protoc/workflows").RateLimitDuration>>;
126
150
  }, "strip", z.ZodTypeAny, {
127
- key: string;
128
- units: number;
151
+ units: string | number;
152
+ key?: string | undefined;
153
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
154
+ limit?: string | number | undefined;
155
+ staticKey?: string | undefined;
156
+ dynamicKey?: string | undefined;
129
157
  }, {
130
- key: string;
131
- units: number;
158
+ units: string | number;
159
+ key?: string | undefined;
160
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
161
+ limit?: string | number | undefined;
162
+ staticKey?: string | undefined;
163
+ dynamicKey?: string | undefined;
132
164
  }>, "many">>;
133
165
  worker_labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodLazy<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodObject<{
134
166
  value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
@@ -152,8 +184,12 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
152
184
  parents?: string[] | undefined;
153
185
  retries?: number | undefined;
154
186
  rate_limits?: {
155
- key: string;
156
- units: number;
187
+ units: string | number;
188
+ key?: string | undefined;
189
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
190
+ limit?: string | number | undefined;
191
+ staticKey?: string | undefined;
192
+ dynamicKey?: string | undefined;
157
193
  }[] | undefined;
158
194
  worker_labels?: Record<string, string | number | {
159
195
  value: string | number;
@@ -167,8 +203,12 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
167
203
  parents?: string[] | undefined;
168
204
  retries?: number | undefined;
169
205
  rate_limits?: {
170
- key: string;
171
- units: number;
206
+ units: string | number;
207
+ key?: string | undefined;
208
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
209
+ limit?: string | number | undefined;
210
+ staticKey?: string | undefined;
211
+ dynamicKey?: string | undefined;
172
212
  }[] | undefined;
173
213
  worker_labels?: Record<string, string | number | {
174
214
  value: string | number;
@@ -183,14 +223,26 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
183
223
  timeout: z.ZodOptional<z.ZodString>;
184
224
  retries: z.ZodOptional<z.ZodNumber>;
185
225
  rate_limits: z.ZodOptional<z.ZodArray<z.ZodObject<{
186
- key: z.ZodString;
187
- units: z.ZodNumber;
226
+ key: z.ZodOptional<z.ZodString>;
227
+ staticKey: z.ZodOptional<z.ZodString>;
228
+ dynamicKey: z.ZodOptional<z.ZodString>;
229
+ units: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
230
+ limit: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
231
+ duration: z.ZodOptional<z.ZodNativeEnum<typeof import("./protoc/workflows").RateLimitDuration>>;
188
232
  }, "strip", z.ZodTypeAny, {
189
- key: string;
190
- units: number;
233
+ units: string | number;
234
+ key?: string | undefined;
235
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
236
+ limit?: string | number | undefined;
237
+ staticKey?: string | undefined;
238
+ dynamicKey?: string | undefined;
191
239
  }, {
192
- key: string;
193
- units: number;
240
+ units: string | number;
241
+ key?: string | undefined;
242
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
243
+ limit?: string | number | undefined;
244
+ staticKey?: string | undefined;
245
+ dynamicKey?: string | undefined;
194
246
  }>, "many">>;
195
247
  worker_labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodLazy<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodObject<{
196
248
  value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
@@ -214,8 +266,12 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
214
266
  parents?: string[] | undefined;
215
267
  retries?: number | undefined;
216
268
  rate_limits?: {
217
- key: string;
218
- units: number;
269
+ units: string | number;
270
+ key?: string | undefined;
271
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
272
+ limit?: string | number | undefined;
273
+ staticKey?: string | undefined;
274
+ dynamicKey?: string | undefined;
219
275
  }[] | undefined;
220
276
  worker_labels?: Record<string, string | number | {
221
277
  value: string | number;
@@ -229,8 +285,12 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
229
285
  parents?: string[] | undefined;
230
286
  retries?: number | undefined;
231
287
  rate_limits?: {
232
- key: string;
233
- units: number;
288
+ units: string | number;
289
+ key?: string | undefined;
290
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
291
+ limit?: string | number | undefined;
292
+ staticKey?: string | undefined;
293
+ dynamicKey?: string | undefined;
234
294
  }[] | undefined;
235
295
  worker_labels?: Record<string, string | number | {
236
296
  value: string | number;
@@ -247,8 +307,12 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
247
307
  parents?: string[] | undefined;
248
308
  retries?: number | undefined;
249
309
  rate_limits?: {
250
- key: string;
251
- units: number;
310
+ units: string | number;
311
+ key?: string | undefined;
312
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
313
+ limit?: string | number | undefined;
314
+ staticKey?: string | undefined;
315
+ dynamicKey?: string | undefined;
252
316
  }[] | undefined;
253
317
  worker_labels?: Record<string, string | number | {
254
318
  value: string | number;
@@ -275,8 +339,12 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
275
339
  parents?: string[] | undefined;
276
340
  retries?: number | undefined;
277
341
  rate_limits?: {
278
- key: string;
279
- units: number;
342
+ units: string | number;
343
+ key?: string | undefined;
344
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
345
+ limit?: string | number | undefined;
346
+ staticKey?: string | undefined;
347
+ dynamicKey?: string | undefined;
280
348
  }[] | undefined;
281
349
  worker_labels?: Record<string, string | number | {
282
350
  value: string | number;
@@ -293,8 +361,12 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
293
361
  parents?: string[] | undefined;
294
362
  retries?: number | undefined;
295
363
  rate_limits?: {
296
- key: string;
297
- units: number;
364
+ units: string | number;
365
+ key?: string | undefined;
366
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
367
+ limit?: string | number | undefined;
368
+ staticKey?: string | undefined;
369
+ dynamicKey?: string | undefined;
298
370
  }[] | undefined;
299
371
  worker_labels?: Record<string, string | number | {
300
372
  value: string | number;
@@ -321,8 +393,12 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
321
393
  parents?: string[] | undefined;
322
394
  retries?: number | undefined;
323
395
  rate_limits?: {
324
- key: string;
325
- units: number;
396
+ units: string | number;
397
+ key?: string | undefined;
398
+ duration?: import("./protoc/workflows").RateLimitDuration | undefined;
399
+ limit?: string | number | undefined;
400
+ staticKey?: string | undefined;
401
+ dynamicKey?: string | undefined;
326
402
  }[] | undefined;
327
403
  worker_labels?: Record<string, string | number | {
328
404
  value: string | number;