@hatchet-dev/typescript-sdk 0.3.0 → 0.4.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,5 +1,5 @@
1
1
  import { Channel, ClientFactory } from 'nice-grpc';
2
- import { CreateWorkflowVersionOpts, WorkflowServiceClient } from '../../protoc/workflows';
2
+ import { CreateWorkflowVersionOpts, RateLimitDuration, WorkflowServiceClient } from '../../protoc/workflows';
3
3
  import { ClientConfig } from '../hatchet-client/client-config';
4
4
  import { Logger } from '../../util/logger';
5
5
  import { Api } from '../rest';
@@ -32,6 +32,7 @@ export declare class AdminClient {
32
32
  * @param workflow a workflow definition to create
33
33
  */
34
34
  put_workflow(workflow: CreateWorkflowVersionOpts): Promise<void>;
35
+ put_rate_limit(key: string, limit: number, duration?: RateLimitDuration): Promise<void>;
35
36
  /**
36
37
  * Run a new instance of a workflow with the given input. This will create a new workflow run and return the ID of the
37
38
  * new run.
@@ -56,6 +56,22 @@ class AdminClient {
56
56
  }
57
57
  });
58
58
  }
59
+ put_rate_limit(key, limit, duration = workflows_1.RateLimitDuration.SECOND) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ try {
62
+ yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () {
63
+ return this.client.putRateLimit({
64
+ key,
65
+ limit,
66
+ duration,
67
+ });
68
+ }), this.logger);
69
+ }
70
+ catch (e) {
71
+ throw new hatchet_error_1.default(e.message);
72
+ }
73
+ });
74
+ }
59
75
  /**
60
76
  * Run a new instance of a workflow with the given input. This will create a new workflow run and return the ID of the
61
77
  * new run.
@@ -24,6 +24,7 @@ export declare class Worker {
24
24
  maxRuns?: number;
25
25
  });
26
26
  registerWorkflow(initWorkflow: Workflow): Promise<void>;
27
+ register_workflow(initWorkflow: Workflow): Promise<void>;
27
28
  registerAction<T, K>(actionId: string, action: StepRunFunction<T, K>): void;
28
29
  handleStartStepRun(action: Action): void;
29
30
  handleStartGroupKeyRun(action: Action): void;
@@ -42,7 +42,13 @@ class Worker {
42
42
  this.handle_kill = options.handleKill === undefined ? true : options.handleKill;
43
43
  this.logger = new logger_1.Logger(`Worker/${this.name}`, this.client.config.log_level);
44
44
  }
45
+ // @deprecated
45
46
  registerWorkflow(initWorkflow) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return this.register_workflow(initWorkflow);
49
+ });
50
+ }
51
+ register_workflow(initWorkflow) {
46
52
  var _a, _b;
47
53
  return __awaiter(this, void 0, void 0, function* () {
48
54
  const workflow = Object.assign(Object.assign({}, initWorkflow), { id: this.client.config.namespace + initWorkflow.id });
@@ -69,7 +75,7 @@ class Worker {
69
75
  timeout: workflow.timeout || '60s',
70
76
  description: workflow.description,
71
77
  steps: workflow.steps.map((step) => {
72
- var _a;
78
+ var _a, _b;
73
79
  return ({
74
80
  readableId: step.name,
75
81
  action: `${workflow.id}:${step.name}`,
@@ -78,6 +84,7 @@ class Worker {
78
84
  parents: (_a = step.parents) !== null && _a !== void 0 ? _a : [],
79
85
  userData: '{}',
80
86
  retries: step.retries || 0,
87
+ rateLimits: (_b = step.rate_limits) !== null && _b !== void 0 ? _b : [], // Add the missing rateLimits property
81
88
  });
82
89
  }),
83
90
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -34,6 +34,10 @@
34
34
  "example:event": "npm run exec -- ./examples/example-event.ts",
35
35
  "example:event-listen": "npm run exec -- ./examples/example-event-with-results.ts",
36
36
  "worker:namespaced": "npm run exec -- ./examples/namespaced-worker.ts",
37
+
38
+ "worker:rate": "npm run exec -- ./examples/rate-limit/worker.ts",
39
+ "example:rate": "npm run exec -- ./examples/rate-limit/events.ts",
40
+
37
41
  "worker:fanout": "npm run exec -- ./examples/fanout-worker.ts",
38
42
  "worker:simple": "npm run exec -- ./examples/simple-worker.ts",
39
43
  "manual:trigger": "npm run exec -- ./examples/manual-trigger.ts",
@@ -10,6 +10,14 @@ export declare enum ConcurrencyLimitStrategy {
10
10
  }
11
11
  export declare function concurrencyLimitStrategyFromJSON(object: any): ConcurrencyLimitStrategy;
12
12
  export declare function concurrencyLimitStrategyToJSON(object: ConcurrencyLimitStrategy): string;
13
+ export declare enum RateLimitDuration {
14
+ SECOND = 0,
15
+ MINUTE = 1,
16
+ HOUR = 2,
17
+ UNRECOGNIZED = -1
18
+ }
19
+ export declare function rateLimitDurationFromJSON(object: any): RateLimitDuration;
20
+ export declare function rateLimitDurationToJSON(object: RateLimitDuration): string;
13
21
  export interface PutWorkflowRequest {
14
22
  opts: CreateWorkflowVersionOpts | undefined;
15
23
  }
@@ -69,6 +77,14 @@ export interface CreateWorkflowStepOpts {
69
77
  userData: string;
70
78
  /** (optional) the number of retries for the step, default 0 */
71
79
  retries: number;
80
+ /** (optional) the rate limits for the step */
81
+ rateLimits: CreateStepRateLimit[];
82
+ }
83
+ export interface CreateStepRateLimit {
84
+ /** (required) the key for the rate limit */
85
+ key: string;
86
+ /** (required) the number of units this step consumes */
87
+ units: number;
72
88
  }
73
89
  /** ListWorkflowsRequest is the request for ListWorkflows. */
74
90
  export interface ListWorkflowsRequest {
@@ -136,6 +152,16 @@ export interface TriggerWorkflowRequest {
136
152
  export interface TriggerWorkflowResponse {
137
153
  workflowRunId: string;
138
154
  }
155
+ export interface PutRateLimitRequest {
156
+ /** (required) the global key for the rate limit */
157
+ key: string;
158
+ /** (required) the max limit for the rate limit (per unit of time) */
159
+ limit: number;
160
+ /** (required) the duration of time for the rate limit (second|minute|hour) */
161
+ duration: RateLimitDuration;
162
+ }
163
+ export interface PutRateLimitResponse {
164
+ }
139
165
  export declare const PutWorkflowRequest: {
140
166
  encode(message: PutWorkflowRequest, writer?: _m0.Writer): _m0.Writer;
141
167
  decode(input: _m0.Reader | Uint8Array, length?: number): PutWorkflowRequest;
@@ -176,6 +202,14 @@ export declare const CreateWorkflowStepOpts: {
176
202
  create(base?: DeepPartial<CreateWorkflowStepOpts>): CreateWorkflowStepOpts;
177
203
  fromPartial(object: DeepPartial<CreateWorkflowStepOpts>): CreateWorkflowStepOpts;
178
204
  };
205
+ export declare const CreateStepRateLimit: {
206
+ encode(message: CreateStepRateLimit, writer?: _m0.Writer): _m0.Writer;
207
+ decode(input: _m0.Reader | Uint8Array, length?: number): CreateStepRateLimit;
208
+ fromJSON(object: any): CreateStepRateLimit;
209
+ toJSON(message: CreateStepRateLimit): unknown;
210
+ create(base?: DeepPartial<CreateStepRateLimit>): CreateStepRateLimit;
211
+ fromPartial(object: DeepPartial<CreateStepRateLimit>): CreateStepRateLimit;
212
+ };
179
213
  export declare const ListWorkflowsRequest: {
180
214
  encode(_: ListWorkflowsRequest, writer?: _m0.Writer): _m0.Writer;
181
215
  decode(input: _m0.Reader | Uint8Array, length?: number): ListWorkflowsRequest;
@@ -232,6 +266,22 @@ export declare const TriggerWorkflowResponse: {
232
266
  create(base?: DeepPartial<TriggerWorkflowResponse>): TriggerWorkflowResponse;
233
267
  fromPartial(object: DeepPartial<TriggerWorkflowResponse>): TriggerWorkflowResponse;
234
268
  };
269
+ export declare const PutRateLimitRequest: {
270
+ encode(message: PutRateLimitRequest, writer?: _m0.Writer): _m0.Writer;
271
+ decode(input: _m0.Reader | Uint8Array, length?: number): PutRateLimitRequest;
272
+ fromJSON(object: any): PutRateLimitRequest;
273
+ toJSON(message: PutRateLimitRequest): unknown;
274
+ create(base?: DeepPartial<PutRateLimitRequest>): PutRateLimitRequest;
275
+ fromPartial(object: DeepPartial<PutRateLimitRequest>): PutRateLimitRequest;
276
+ };
277
+ export declare const PutRateLimitResponse: {
278
+ encode(_: PutRateLimitResponse, writer?: _m0.Writer): _m0.Writer;
279
+ decode(input: _m0.Reader | Uint8Array, length?: number): PutRateLimitResponse;
280
+ fromJSON(_: any): PutRateLimitResponse;
281
+ toJSON(_: PutRateLimitResponse): unknown;
282
+ create(base?: DeepPartial<PutRateLimitResponse>): PutRateLimitResponse;
283
+ fromPartial(_: DeepPartial<PutRateLimitResponse>): PutRateLimitResponse;
284
+ };
235
285
  /** WorkflowService represents a set of RPCs for managing workflows. */
236
286
  export type WorkflowServiceDefinition = typeof WorkflowServiceDefinition;
237
287
  export declare const WorkflowServiceDefinition: {
@@ -304,17 +354,41 @@ export declare const WorkflowServiceDefinition: {
304
354
  readonly responseStream: false;
305
355
  readonly options: {};
306
356
  };
357
+ readonly putRateLimit: {
358
+ readonly name: "PutRateLimit";
359
+ readonly requestType: {
360
+ encode(message: PutRateLimitRequest, writer?: _m0.Writer): _m0.Writer;
361
+ decode(input: _m0.Reader | Uint8Array, length?: number): PutRateLimitRequest;
362
+ fromJSON(object: any): PutRateLimitRequest;
363
+ toJSON(message: PutRateLimitRequest): unknown;
364
+ create(base?: DeepPartial<PutRateLimitRequest>): PutRateLimitRequest;
365
+ fromPartial(object: DeepPartial<PutRateLimitRequest>): PutRateLimitRequest;
366
+ };
367
+ readonly requestStream: false;
368
+ readonly responseType: {
369
+ encode(_: PutRateLimitResponse, writer?: _m0.Writer): _m0.Writer;
370
+ decode(input: _m0.Reader | Uint8Array, length?: number): PutRateLimitResponse;
371
+ fromJSON(_: any): PutRateLimitResponse;
372
+ toJSON(_: PutRateLimitResponse): unknown;
373
+ create(base?: DeepPartial<PutRateLimitResponse>): PutRateLimitResponse;
374
+ fromPartial(_: DeepPartial<PutRateLimitResponse>): PutRateLimitResponse;
375
+ };
376
+ readonly responseStream: false;
377
+ readonly options: {};
378
+ };
307
379
  };
308
380
  };
309
381
  export interface WorkflowServiceImplementation<CallContextExt = {}> {
310
382
  putWorkflow(request: PutWorkflowRequest, context: CallContext & CallContextExt): Promise<DeepPartial<WorkflowVersion>>;
311
383
  scheduleWorkflow(request: ScheduleWorkflowRequest, context: CallContext & CallContextExt): Promise<DeepPartial<WorkflowVersion>>;
312
384
  triggerWorkflow(request: TriggerWorkflowRequest, context: CallContext & CallContextExt): Promise<DeepPartial<TriggerWorkflowResponse>>;
385
+ putRateLimit(request: PutRateLimitRequest, context: CallContext & CallContextExt): Promise<DeepPartial<PutRateLimitResponse>>;
313
386
  }
314
387
  export interface WorkflowServiceClient<CallOptionsExt = {}> {
315
388
  putWorkflow(request: DeepPartial<PutWorkflowRequest>, options?: CallOptions & CallOptionsExt): Promise<WorkflowVersion>;
316
389
  scheduleWorkflow(request: DeepPartial<ScheduleWorkflowRequest>, options?: CallOptions & CallOptionsExt): Promise<WorkflowVersion>;
317
390
  triggerWorkflow(request: DeepPartial<TriggerWorkflowRequest>, options?: CallOptions & CallOptionsExt): Promise<TriggerWorkflowResponse>;
391
+ putRateLimit(request: DeepPartial<PutRateLimitRequest>, options?: CallOptions & CallOptionsExt): Promise<PutRateLimitResponse>;
318
392
  }
319
393
  type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
320
394
  export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.WorkflowServiceDefinition = exports.TriggerWorkflowResponse = exports.TriggerWorkflowRequest = exports.WorkflowTriggerCronRef = exports.WorkflowTriggerEventRef = exports.WorkflowVersion = exports.ScheduleWorkflowRequest = exports.ListWorkflowsRequest = exports.CreateWorkflowStepOpts = exports.CreateWorkflowJobOpts = exports.WorkflowConcurrencyOpts = exports.CreateWorkflowVersionOpts = exports.PutWorkflowRequest = exports.concurrencyLimitStrategyToJSON = exports.concurrencyLimitStrategyFromJSON = exports.ConcurrencyLimitStrategy = exports.protobufPackage = void 0;
26
+ exports.WorkflowServiceDefinition = exports.PutRateLimitResponse = exports.PutRateLimitRequest = exports.TriggerWorkflowResponse = exports.TriggerWorkflowRequest = exports.WorkflowTriggerCronRef = exports.WorkflowTriggerEventRef = exports.WorkflowVersion = exports.ScheduleWorkflowRequest = exports.ListWorkflowsRequest = exports.CreateStepRateLimit = exports.CreateWorkflowStepOpts = exports.CreateWorkflowJobOpts = exports.WorkflowConcurrencyOpts = exports.CreateWorkflowVersionOpts = exports.PutWorkflowRequest = exports.rateLimitDurationToJSON = exports.rateLimitDurationFromJSON = exports.RateLimitDuration = exports.concurrencyLimitStrategyToJSON = exports.concurrencyLimitStrategyFromJSON = exports.ConcurrencyLimitStrategy = exports.protobufPackage = void 0;
27
27
  const _m0 = __importStar(require("protobufjs/minimal"));
28
28
  const timestamp_1 = require("../google/protobuf/timestamp");
29
29
  exports.protobufPackage = '';
@@ -72,6 +72,45 @@ function concurrencyLimitStrategyToJSON(object) {
72
72
  }
73
73
  }
74
74
  exports.concurrencyLimitStrategyToJSON = concurrencyLimitStrategyToJSON;
75
+ var RateLimitDuration;
76
+ (function (RateLimitDuration) {
77
+ RateLimitDuration[RateLimitDuration["SECOND"] = 0] = "SECOND";
78
+ RateLimitDuration[RateLimitDuration["MINUTE"] = 1] = "MINUTE";
79
+ RateLimitDuration[RateLimitDuration["HOUR"] = 2] = "HOUR";
80
+ RateLimitDuration[RateLimitDuration["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
81
+ })(RateLimitDuration || (exports.RateLimitDuration = RateLimitDuration = {}));
82
+ function rateLimitDurationFromJSON(object) {
83
+ switch (object) {
84
+ case 0:
85
+ case 'SECOND':
86
+ return RateLimitDuration.SECOND;
87
+ case 1:
88
+ case 'MINUTE':
89
+ return RateLimitDuration.MINUTE;
90
+ case 2:
91
+ case 'HOUR':
92
+ return RateLimitDuration.HOUR;
93
+ case -1:
94
+ case 'UNRECOGNIZED':
95
+ default:
96
+ return RateLimitDuration.UNRECOGNIZED;
97
+ }
98
+ }
99
+ exports.rateLimitDurationFromJSON = rateLimitDurationFromJSON;
100
+ function rateLimitDurationToJSON(object) {
101
+ switch (object) {
102
+ case RateLimitDuration.SECOND:
103
+ return 'SECOND';
104
+ case RateLimitDuration.MINUTE:
105
+ return 'MINUTE';
106
+ case RateLimitDuration.HOUR:
107
+ return 'HOUR';
108
+ case RateLimitDuration.UNRECOGNIZED:
109
+ default:
110
+ return 'UNRECOGNIZED';
111
+ }
112
+ }
113
+ exports.rateLimitDurationToJSON = rateLimitDurationToJSON;
75
114
  function createBasePutWorkflowRequest() {
76
115
  return { opts: undefined };
77
116
  }
@@ -508,6 +547,7 @@ function createBaseCreateWorkflowStepOpts() {
508
547
  parents: [],
509
548
  userData: '',
510
549
  retries: 0,
550
+ rateLimits: [],
511
551
  };
512
552
  }
513
553
  exports.CreateWorkflowStepOpts = {
@@ -533,6 +573,9 @@ exports.CreateWorkflowStepOpts = {
533
573
  if (message.retries !== 0) {
534
574
  writer.uint32(56).int32(message.retries);
535
575
  }
576
+ for (const v of message.rateLimits) {
577
+ exports.CreateStepRateLimit.encode(v, writer.uint32(66).fork()).ldelim();
578
+ }
536
579
  return writer;
537
580
  },
538
581
  decode(input, length) {
@@ -584,6 +627,12 @@ exports.CreateWorkflowStepOpts = {
584
627
  }
585
628
  message.retries = reader.int32();
586
629
  continue;
630
+ case 8:
631
+ if (tag !== 66) {
632
+ break;
633
+ }
634
+ message.rateLimits.push(exports.CreateStepRateLimit.decode(reader, reader.uint32()));
635
+ continue;
587
636
  }
588
637
  if ((tag & 7) === 4 || tag === 0) {
589
638
  break;
@@ -603,10 +652,13 @@ exports.CreateWorkflowStepOpts = {
603
652
  : [],
604
653
  userData: isSet(object.userData) ? globalThis.String(object.userData) : '',
605
654
  retries: isSet(object.retries) ? globalThis.Number(object.retries) : 0,
655
+ rateLimits: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.rateLimits)
656
+ ? object.rateLimits.map((e) => exports.CreateStepRateLimit.fromJSON(e))
657
+ : [],
606
658
  };
607
659
  },
608
660
  toJSON(message) {
609
- var _a;
661
+ var _a, _b;
610
662
  const obj = {};
611
663
  if (message.readableId !== '') {
612
664
  obj.readableId = message.readableId;
@@ -629,13 +681,16 @@ exports.CreateWorkflowStepOpts = {
629
681
  if (message.retries !== 0) {
630
682
  obj.retries = Math.round(message.retries);
631
683
  }
684
+ if ((_b = message.rateLimits) === null || _b === void 0 ? void 0 : _b.length) {
685
+ obj.rateLimits = message.rateLimits.map((e) => exports.CreateStepRateLimit.toJSON(e));
686
+ }
632
687
  return obj;
633
688
  },
634
689
  create(base) {
635
690
  return exports.CreateWorkflowStepOpts.fromPartial(base !== null && base !== void 0 ? base : {});
636
691
  },
637
692
  fromPartial(object) {
638
- var _a, _b, _c, _d, _e, _f, _g;
693
+ var _a, _b, _c, _d, _e, _f, _g, _h;
639
694
  const message = createBaseCreateWorkflowStepOpts();
640
695
  message.readableId = (_a = object.readableId) !== null && _a !== void 0 ? _a : '';
641
696
  message.action = (_b = object.action) !== null && _b !== void 0 ? _b : '';
@@ -644,6 +699,74 @@ exports.CreateWorkflowStepOpts = {
644
699
  message.parents = ((_e = object.parents) === null || _e === void 0 ? void 0 : _e.map((e) => e)) || [];
645
700
  message.userData = (_f = object.userData) !== null && _f !== void 0 ? _f : '';
646
701
  message.retries = (_g = object.retries) !== null && _g !== void 0 ? _g : 0;
702
+ message.rateLimits = ((_h = object.rateLimits) === null || _h === void 0 ? void 0 : _h.map((e) => exports.CreateStepRateLimit.fromPartial(e))) || [];
703
+ return message;
704
+ },
705
+ };
706
+ function createBaseCreateStepRateLimit() {
707
+ return { key: '', units: 0 };
708
+ }
709
+ exports.CreateStepRateLimit = {
710
+ encode(message, writer = _m0.Writer.create()) {
711
+ if (message.key !== '') {
712
+ writer.uint32(10).string(message.key);
713
+ }
714
+ if (message.units !== 0) {
715
+ writer.uint32(16).int32(message.units);
716
+ }
717
+ return writer;
718
+ },
719
+ decode(input, length) {
720
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
721
+ let end = length === undefined ? reader.len : reader.pos + length;
722
+ const message = createBaseCreateStepRateLimit();
723
+ while (reader.pos < end) {
724
+ const tag = reader.uint32();
725
+ switch (tag >>> 3) {
726
+ case 1:
727
+ if (tag !== 10) {
728
+ break;
729
+ }
730
+ message.key = reader.string();
731
+ continue;
732
+ case 2:
733
+ if (tag !== 16) {
734
+ break;
735
+ }
736
+ message.units = reader.int32();
737
+ continue;
738
+ }
739
+ if ((tag & 7) === 4 || tag === 0) {
740
+ break;
741
+ }
742
+ reader.skipType(tag & 7);
743
+ }
744
+ return message;
745
+ },
746
+ fromJSON(object) {
747
+ return {
748
+ key: isSet(object.key) ? globalThis.String(object.key) : '',
749
+ units: isSet(object.units) ? globalThis.Number(object.units) : 0,
750
+ };
751
+ },
752
+ toJSON(message) {
753
+ const obj = {};
754
+ if (message.key !== '') {
755
+ obj.key = message.key;
756
+ }
757
+ if (message.units !== 0) {
758
+ obj.units = Math.round(message.units);
759
+ }
760
+ return obj;
761
+ },
762
+ create(base) {
763
+ return exports.CreateStepRateLimit.fromPartial(base !== null && base !== void 0 ? base : {});
764
+ },
765
+ fromPartial(object) {
766
+ var _a, _b;
767
+ const message = createBaseCreateStepRateLimit();
768
+ message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
769
+ message.units = (_b = object.units) !== null && _b !== void 0 ? _b : 0;
647
770
  return message;
648
771
  },
649
772
  };
@@ -1283,6 +1406,124 @@ exports.TriggerWorkflowResponse = {
1283
1406
  return message;
1284
1407
  },
1285
1408
  };
1409
+ function createBasePutRateLimitRequest() {
1410
+ return { key: '', limit: 0, duration: 0 };
1411
+ }
1412
+ exports.PutRateLimitRequest = {
1413
+ encode(message, writer = _m0.Writer.create()) {
1414
+ if (message.key !== '') {
1415
+ writer.uint32(10).string(message.key);
1416
+ }
1417
+ if (message.limit !== 0) {
1418
+ writer.uint32(16).int32(message.limit);
1419
+ }
1420
+ if (message.duration !== 0) {
1421
+ writer.uint32(24).int32(message.duration);
1422
+ }
1423
+ return writer;
1424
+ },
1425
+ decode(input, length) {
1426
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
1427
+ let end = length === undefined ? reader.len : reader.pos + length;
1428
+ const message = createBasePutRateLimitRequest();
1429
+ while (reader.pos < end) {
1430
+ const tag = reader.uint32();
1431
+ switch (tag >>> 3) {
1432
+ case 1:
1433
+ if (tag !== 10) {
1434
+ break;
1435
+ }
1436
+ message.key = reader.string();
1437
+ continue;
1438
+ case 2:
1439
+ if (tag !== 16) {
1440
+ break;
1441
+ }
1442
+ message.limit = reader.int32();
1443
+ continue;
1444
+ case 3:
1445
+ if (tag !== 24) {
1446
+ break;
1447
+ }
1448
+ message.duration = reader.int32();
1449
+ continue;
1450
+ }
1451
+ if ((tag & 7) === 4 || tag === 0) {
1452
+ break;
1453
+ }
1454
+ reader.skipType(tag & 7);
1455
+ }
1456
+ return message;
1457
+ },
1458
+ fromJSON(object) {
1459
+ return {
1460
+ key: isSet(object.key) ? globalThis.String(object.key) : '',
1461
+ limit: isSet(object.limit) ? globalThis.Number(object.limit) : 0,
1462
+ duration: isSet(object.duration) ? rateLimitDurationFromJSON(object.duration) : 0,
1463
+ };
1464
+ },
1465
+ toJSON(message) {
1466
+ const obj = {};
1467
+ if (message.key !== '') {
1468
+ obj.key = message.key;
1469
+ }
1470
+ if (message.limit !== 0) {
1471
+ obj.limit = Math.round(message.limit);
1472
+ }
1473
+ if (message.duration !== 0) {
1474
+ obj.duration = rateLimitDurationToJSON(message.duration);
1475
+ }
1476
+ return obj;
1477
+ },
1478
+ create(base) {
1479
+ return exports.PutRateLimitRequest.fromPartial(base !== null && base !== void 0 ? base : {});
1480
+ },
1481
+ fromPartial(object) {
1482
+ var _a, _b, _c;
1483
+ const message = createBasePutRateLimitRequest();
1484
+ message.key = (_a = object.key) !== null && _a !== void 0 ? _a : '';
1485
+ message.limit = (_b = object.limit) !== null && _b !== void 0 ? _b : 0;
1486
+ message.duration = (_c = object.duration) !== null && _c !== void 0 ? _c : 0;
1487
+ return message;
1488
+ },
1489
+ };
1490
+ function createBasePutRateLimitResponse() {
1491
+ return {};
1492
+ }
1493
+ exports.PutRateLimitResponse = {
1494
+ encode(_, writer = _m0.Writer.create()) {
1495
+ return writer;
1496
+ },
1497
+ decode(input, length) {
1498
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
1499
+ let end = length === undefined ? reader.len : reader.pos + length;
1500
+ const message = createBasePutRateLimitResponse();
1501
+ while (reader.pos < end) {
1502
+ const tag = reader.uint32();
1503
+ switch (tag >>> 3) {
1504
+ }
1505
+ if ((tag & 7) === 4 || tag === 0) {
1506
+ break;
1507
+ }
1508
+ reader.skipType(tag & 7);
1509
+ }
1510
+ return message;
1511
+ },
1512
+ fromJSON(_) {
1513
+ return {};
1514
+ },
1515
+ toJSON(_) {
1516
+ const obj = {};
1517
+ return obj;
1518
+ },
1519
+ create(base) {
1520
+ return exports.PutRateLimitResponse.fromPartial(base !== null && base !== void 0 ? base : {});
1521
+ },
1522
+ fromPartial(_) {
1523
+ const message = createBasePutRateLimitResponse();
1524
+ return message;
1525
+ },
1526
+ };
1286
1527
  exports.WorkflowServiceDefinition = {
1287
1528
  name: 'WorkflowService',
1288
1529
  fullName: 'WorkflowService',
@@ -1311,6 +1552,14 @@ exports.WorkflowServiceDefinition = {
1311
1552
  responseStream: false,
1312
1553
  options: {},
1313
1554
  },
1555
+ putRateLimit: {
1556
+ name: 'PutRateLimit',
1557
+ requestType: exports.PutRateLimitRequest,
1558
+ requestStream: false,
1559
+ responseType: exports.PutRateLimitResponse,
1560
+ responseStream: false,
1561
+ options: {},
1562
+ },
1314
1563
  },
1315
1564
  };
1316
1565
  function toTimestamp(date) {
package/step.d.ts CHANGED
@@ -4,21 +4,49 @@ import { LogLevel } from './clients/event/event-client';
4
4
  import { Logger } from './util/logger';
5
5
  import { HatchetClient } from './clients/hatchet-client';
6
6
  import { RunEventType } from './clients/listener/listener-client';
7
+ export declare const CreateRateLimitSchema: z.ZodObject<{
8
+ key: z.ZodString;
9
+ units: z.ZodNumber;
10
+ }, "strip", z.ZodTypeAny, {
11
+ key: string;
12
+ units: number;
13
+ }, {
14
+ key: string;
15
+ units: number;
16
+ }>;
7
17
  export declare const CreateStepSchema: z.ZodObject<{
8
18
  name: z.ZodString;
9
19
  parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
10
20
  timeout: z.ZodOptional<z.ZodString>;
11
21
  retries: z.ZodOptional<z.ZodNumber>;
22
+ rate_limits: z.ZodOptional<z.ZodArray<z.ZodObject<{
23
+ key: z.ZodString;
24
+ units: z.ZodNumber;
25
+ }, "strip", z.ZodTypeAny, {
26
+ key: string;
27
+ units: number;
28
+ }, {
29
+ key: string;
30
+ units: number;
31
+ }>, "many">>;
12
32
  }, "strip", z.ZodTypeAny, {
13
33
  name: string;
14
34
  parents?: string[] | undefined;
15
35
  timeout?: string | undefined;
16
36
  retries?: number | undefined;
37
+ rate_limits?: {
38
+ key: string;
39
+ units: number;
40
+ }[] | undefined;
17
41
  }, {
18
42
  name: string;
19
43
  parents?: string[] | undefined;
20
44
  timeout?: string | undefined;
21
45
  retries?: number | undefined;
46
+ rate_limits?: {
47
+ key: string;
48
+ units: number;
49
+ }[] | undefined;
22
50
  }>;
23
51
  type JSONPrimitive = string | number | boolean | null | Array<JSONPrimitive>;
24
52
  export type NextStep = {
package/step.js CHANGED
@@ -42,7 +42,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
42
42
  return (mod && mod.__esModule) ? mod : { "default": mod };
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.Context = exports.CreateStepSchema = void 0;
45
+ exports.Context = exports.CreateStepSchema = exports.CreateRateLimitSchema = void 0;
46
46
  /* eslint-disable max-classes-per-file */
47
47
  const hatchet_error_1 = __importDefault(require("./util/errors/hatchet-error"));
48
48
  const z = __importStar(require("zod"));
@@ -50,11 +50,16 @@ const workflow_1 = require("./workflow");
50
50
  const logger_1 = require("./util/logger");
51
51
  const parse_1 = require("./util/parse");
52
52
  const listener_client_1 = require("./clients/listener/listener-client");
53
+ exports.CreateRateLimitSchema = z.object({
54
+ key: z.string(),
55
+ units: z.number().min(1),
56
+ });
53
57
  exports.CreateStepSchema = z.object({
54
58
  name: z.string(),
55
59
  parents: z.array(z.string()).optional(),
56
60
  timeout: workflow_1.HatchetTimeoutSchema.optional(),
57
61
  retries: z.number().optional(),
62
+ rate_limits: z.array(exports.CreateRateLimitSchema).optional(),
58
63
  });
59
64
  class ChildWorkflowRef {
60
65
  constructor(workflowRunId, client) {
package/workflow.d.ts CHANGED
@@ -6,16 +6,34 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
6
6
  parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
7
7
  timeout: z.ZodOptional<z.ZodString>;
8
8
  retries: z.ZodOptional<z.ZodNumber>;
9
+ rate_limits: z.ZodOptional<z.ZodArray<z.ZodObject<{
10
+ key: z.ZodString;
11
+ units: z.ZodNumber;
12
+ }, "strip", z.ZodTypeAny, {
13
+ key: string;
14
+ units: number;
15
+ }, {
16
+ key: string;
17
+ units: number;
18
+ }>, "many">>;
9
19
  }, "strip", z.ZodTypeAny, {
10
20
  name: string;
11
21
  parents?: string[] | undefined;
12
22
  timeout?: string | undefined;
13
23
  retries?: number | undefined;
24
+ rate_limits?: {
25
+ key: string;
26
+ units: number;
27
+ }[] | undefined;
14
28
  }, {
15
29
  name: string;
16
30
  parents?: string[] | undefined;
17
31
  timeout?: string | undefined;
18
32
  retries?: number | undefined;
33
+ rate_limits?: {
34
+ key: string;
35
+ units: number;
36
+ }[] | undefined;
19
37
  }>, "many">;
20
38
  export type Steps = z.infer<typeof StepsSchema>;
21
39
  export declare const ConcurrencyLimitStrategy: typeof PbConcurrencyLimitStrategy;
@@ -63,16 +81,34 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
63
81
  parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
64
82
  timeout: z.ZodOptional<z.ZodString>;
65
83
  retries: z.ZodOptional<z.ZodNumber>;
84
+ rate_limits: z.ZodOptional<z.ZodArray<z.ZodObject<{
85
+ key: z.ZodString;
86
+ units: z.ZodNumber;
87
+ }, "strip", z.ZodTypeAny, {
88
+ key: string;
89
+ units: number;
90
+ }, {
91
+ key: string;
92
+ units: number;
93
+ }>, "many">>;
66
94
  }, "strip", z.ZodTypeAny, {
67
95
  name: string;
68
96
  parents?: string[] | undefined;
69
97
  timeout?: string | undefined;
70
98
  retries?: number | undefined;
99
+ rate_limits?: {
100
+ key: string;
101
+ units: number;
102
+ }[] | undefined;
71
103
  }, {
72
104
  name: string;
73
105
  parents?: string[] | undefined;
74
106
  timeout?: string | undefined;
75
107
  retries?: number | undefined;
108
+ rate_limits?: {
109
+ key: string;
110
+ units: number;
111
+ }[] | undefined;
76
112
  }>, "many">;
77
113
  }, "strip", z.ZodTypeAny, {
78
114
  description: string;
@@ -81,6 +117,10 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
81
117
  parents?: string[] | undefined;
82
118
  timeout?: string | undefined;
83
119
  retries?: number | undefined;
120
+ rate_limits?: {
121
+ key: string;
122
+ units: number;
123
+ }[] | undefined;
84
124
  }[];
85
125
  id: string;
86
126
  on: {
@@ -100,6 +140,10 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
100
140
  parents?: string[] | undefined;
101
141
  timeout?: string | undefined;
102
142
  retries?: number | undefined;
143
+ rate_limits?: {
144
+ key: string;
145
+ units: number;
146
+ }[] | undefined;
103
147
  }[];
104
148
  id: string;
105
149
  on: {