@hatchet-dev/typescript-sdk 0.13.0 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -15,6 +15,9 @@ export interface Event {
15
15
  /** the payload for the event */
16
16
  additionalMetadata?: string | undefined;
17
17
  }
18
+ export interface Events {
19
+ events: Event[];
20
+ }
18
21
  export interface PutLogRequest {
19
22
  /** the step run id for the request */
20
23
  stepRunId: string;
@@ -41,6 +44,9 @@ export interface PutStreamEventRequest {
41
44
  }
42
45
  export interface PutStreamEventResponse {
43
46
  }
47
+ export interface BulkPushEventRequest {
48
+ events: PushEventRequest[];
49
+ }
44
50
  export interface PushEventRequest {
45
51
  /** the key for the event */
46
52
  key: string;
@@ -56,10 +62,12 @@ export interface ReplayEventRequest {
56
62
  eventId: string;
57
63
  }
58
64
  export declare const Event: MessageFns<Event>;
65
+ export declare const Events: MessageFns<Events>;
59
66
  export declare const PutLogRequest: MessageFns<PutLogRequest>;
60
67
  export declare const PutLogResponse: MessageFns<PutLogResponse>;
61
68
  export declare const PutStreamEventRequest: MessageFns<PutStreamEventRequest>;
62
69
  export declare const PutStreamEventResponse: MessageFns<PutStreamEventResponse>;
70
+ export declare const BulkPushEventRequest: MessageFns<BulkPushEventRequest>;
63
71
  export declare const PushEventRequest: MessageFns<PushEventRequest>;
64
72
  export declare const ReplayEventRequest: MessageFns<ReplayEventRequest>;
65
73
  export type EventsServiceDefinition = typeof EventsServiceDefinition;
@@ -75,6 +83,14 @@ export declare const EventsServiceDefinition: {
75
83
  readonly responseStream: false;
76
84
  readonly options: {};
77
85
  };
86
+ readonly bulkPush: {
87
+ readonly name: "BulkPush";
88
+ readonly requestType: MessageFns<BulkPushEventRequest>;
89
+ readonly requestStream: false;
90
+ readonly responseType: MessageFns<Events>;
91
+ readonly responseStream: false;
92
+ readonly options: {};
93
+ };
78
94
  readonly replaySingleEvent: {
79
95
  readonly name: "ReplaySingleEvent";
80
96
  readonly requestType: MessageFns<ReplayEventRequest>;
@@ -103,12 +119,14 @@ export declare const EventsServiceDefinition: {
103
119
  };
104
120
  export interface EventsServiceImplementation<CallContextExt = {}> {
105
121
  push(request: PushEventRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Event>>;
122
+ bulkPush(request: BulkPushEventRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Events>>;
106
123
  replaySingleEvent(request: ReplayEventRequest, context: CallContext & CallContextExt): Promise<DeepPartial<Event>>;
107
124
  putLog(request: PutLogRequest, context: CallContext & CallContextExt): Promise<DeepPartial<PutLogResponse>>;
108
125
  putStreamEvent(request: PutStreamEventRequest, context: CallContext & CallContextExt): Promise<DeepPartial<PutStreamEventResponse>>;
109
126
  }
110
127
  export interface EventsServiceClient<CallOptionsExt = {}> {
111
128
  push(request: DeepPartial<PushEventRequest>, options?: CallOptions & CallOptionsExt): Promise<Event>;
129
+ bulkPush(request: DeepPartial<BulkPushEventRequest>, options?: CallOptions & CallOptionsExt): Promise<Events>;
112
130
  replaySingleEvent(request: DeepPartial<ReplayEventRequest>, options?: CallOptions & CallOptionsExt): Promise<Event>;
113
131
  putLog(request: DeepPartial<PutLogRequest>, options?: CallOptions & CallOptionsExt): Promise<PutLogResponse>;
114
132
  putStreamEvent(request: DeepPartial<PutStreamEventRequest>, options?: CallOptions & CallOptionsExt): Promise<PutStreamEventResponse>;
@@ -5,7 +5,7 @@
5
5
  // protoc v3.19.1
6
6
  // source: events/events.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.EventsServiceDefinition = exports.ReplayEventRequest = exports.PushEventRequest = exports.PutStreamEventResponse = exports.PutStreamEventRequest = exports.PutLogResponse = exports.PutLogRequest = exports.Event = exports.protobufPackage = void 0;
8
+ exports.EventsServiceDefinition = exports.ReplayEventRequest = exports.PushEventRequest = exports.BulkPushEventRequest = exports.PutStreamEventResponse = exports.PutStreamEventRequest = exports.PutLogResponse = exports.PutLogRequest = exports.Events = exports.Event = exports.protobufPackage = void 0;
9
9
  /* eslint-disable */
10
10
  const wire_1 = require("@bufbuild/protobuf/wire");
11
11
  const timestamp_1 = require("../google/protobuf/timestamp");
@@ -144,6 +144,62 @@ exports.Event = {
144
144
  return message;
145
145
  },
146
146
  };
147
+ function createBaseEvents() {
148
+ return { events: [] };
149
+ }
150
+ exports.Events = {
151
+ encode(message, writer = new wire_1.BinaryWriter()) {
152
+ for (const v of message.events) {
153
+ exports.Event.encode(v, writer.uint32(10).fork()).join();
154
+ }
155
+ return writer;
156
+ },
157
+ decode(input, length) {
158
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
159
+ let end = length === undefined ? reader.len : reader.pos + length;
160
+ const message = createBaseEvents();
161
+ while (reader.pos < end) {
162
+ const tag = reader.uint32();
163
+ switch (tag >>> 3) {
164
+ case 1:
165
+ if (tag !== 10) {
166
+ break;
167
+ }
168
+ message.events.push(exports.Event.decode(reader, reader.uint32()));
169
+ continue;
170
+ }
171
+ if ((tag & 7) === 4 || tag === 0) {
172
+ break;
173
+ }
174
+ reader.skip(tag & 7);
175
+ }
176
+ return message;
177
+ },
178
+ fromJSON(object) {
179
+ return {
180
+ events: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.events)
181
+ ? object.events.map((e) => exports.Event.fromJSON(e))
182
+ : [],
183
+ };
184
+ },
185
+ toJSON(message) {
186
+ var _a;
187
+ const obj = {};
188
+ if ((_a = message.events) === null || _a === void 0 ? void 0 : _a.length) {
189
+ obj.events = message.events.map((e) => exports.Event.toJSON(e));
190
+ }
191
+ return obj;
192
+ },
193
+ create(base) {
194
+ return exports.Events.fromPartial(base !== null && base !== void 0 ? base : {});
195
+ },
196
+ fromPartial(object) {
197
+ var _a;
198
+ const message = createBaseEvents();
199
+ message.events = ((_a = object.events) === null || _a === void 0 ? void 0 : _a.map((e) => exports.Event.fromPartial(e))) || [];
200
+ return message;
201
+ },
202
+ };
147
203
  function createBasePutLogRequest() {
148
204
  return { stepRunId: '', createdAt: undefined, message: '', level: undefined, metadata: '' };
149
205
  }
@@ -422,6 +478,62 @@ exports.PutStreamEventResponse = {
422
478
  return message;
423
479
  },
424
480
  };
481
+ function createBaseBulkPushEventRequest() {
482
+ return { events: [] };
483
+ }
484
+ exports.BulkPushEventRequest = {
485
+ encode(message, writer = new wire_1.BinaryWriter()) {
486
+ for (const v of message.events) {
487
+ exports.PushEventRequest.encode(v, writer.uint32(10).fork()).join();
488
+ }
489
+ return writer;
490
+ },
491
+ decode(input, length) {
492
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
493
+ let end = length === undefined ? reader.len : reader.pos + length;
494
+ const message = createBaseBulkPushEventRequest();
495
+ while (reader.pos < end) {
496
+ const tag = reader.uint32();
497
+ switch (tag >>> 3) {
498
+ case 1:
499
+ if (tag !== 10) {
500
+ break;
501
+ }
502
+ message.events.push(exports.PushEventRequest.decode(reader, reader.uint32()));
503
+ continue;
504
+ }
505
+ if ((tag & 7) === 4 || tag === 0) {
506
+ break;
507
+ }
508
+ reader.skip(tag & 7);
509
+ }
510
+ return message;
511
+ },
512
+ fromJSON(object) {
513
+ return {
514
+ events: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.events)
515
+ ? object.events.map((e) => exports.PushEventRequest.fromJSON(e))
516
+ : [],
517
+ };
518
+ },
519
+ toJSON(message) {
520
+ var _a;
521
+ const obj = {};
522
+ if ((_a = message.events) === null || _a === void 0 ? void 0 : _a.length) {
523
+ obj.events = message.events.map((e) => exports.PushEventRequest.toJSON(e));
524
+ }
525
+ return obj;
526
+ },
527
+ create(base) {
528
+ return exports.BulkPushEventRequest.fromPartial(base !== null && base !== void 0 ? base : {});
529
+ },
530
+ fromPartial(object) {
531
+ var _a;
532
+ const message = createBaseBulkPushEventRequest();
533
+ message.events = ((_a = object.events) === null || _a === void 0 ? void 0 : _a.map((e) => exports.PushEventRequest.fromPartial(e))) || [];
534
+ return message;
535
+ },
536
+ };
425
537
  function createBasePushEventRequest() {
426
538
  return { key: '', payload: '', eventTimestamp: undefined, additionalMetadata: undefined };
427
539
  }
@@ -584,6 +696,14 @@ exports.EventsServiceDefinition = {
584
696
  responseStream: false,
585
697
  options: {},
586
698
  },
699
+ bulkPush: {
700
+ name: 'BulkPush',
701
+ requestType: exports.BulkPushEventRequest,
702
+ requestStream: false,
703
+ responseType: exports.Events,
704
+ responseStream: false,
705
+ options: {},
706
+ },
587
707
  replaySingleEvent: {
588
708
  name: 'ReplaySingleEvent',
589
709
  requestType: exports.ReplayEventRequest,
@@ -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
+ }
@@ -73,16 +73,39 @@ class WorkflowRunRef {
73
73
  return new Promise((resolve, reject) => {
74
74
  (() => __awaiter(this, void 0, void 0, function* () {
75
75
  var _a, e_1, _b, _c;
76
+ var _d, _e;
76
77
  try {
77
- for (var _d = true, _e = __asyncValues(streamable.stream()), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
78
- _c = _f.value;
79
- _d = false;
78
+ for (var _f = true, _g = __asyncValues(streamable.stream()), _h; _h = yield _g.next(), _a = _h.done, !_a; _f = true) {
79
+ _c = _h.value;
80
+ _f = false;
80
81
  const event = _c;
81
82
  if (event.eventType === dispatcher_1.WorkflowRunEventType.WORKFLOW_RUN_EVENT_TYPE_FINISHED) {
82
83
  if (event.results.some((r) => !!r.error)) {
83
84
  reject(event.results);
84
85
  return;
85
86
  }
87
+ if (event.results.length === 0) {
88
+ const data = yield this.client.api.workflowRunGetShape(this.client.config.tenant_id, event.workflowRunId);
89
+ const mostRecentJobRun = (_d = data.data.jobRuns) === null || _d === void 0 ? void 0 : _d[0];
90
+ if (!mostRecentJobRun) {
91
+ reject(new Error('No job runs found'));
92
+ return;
93
+ }
94
+ const outputs = {};
95
+ (_e = mostRecentJobRun.stepRuns) === null || _e === void 0 ? void 0 : _e.forEach((stepRun) => {
96
+ var _a, _b;
97
+ const readable = (_b = (_a = mostRecentJobRun.job) === null || _a === void 0 ? void 0 : _a.steps) === null || _b === void 0 ? void 0 : _b.find((step) => step.metadata.id === stepRun.stepId);
98
+ const readableStepName = `${readable === null || readable === void 0 ? void 0 : readable.readableId}`;
99
+ try {
100
+ outputs[readableStepName] = JSON.parse(stepRun.output || '{}');
101
+ }
102
+ catch (error) {
103
+ outputs[readableStepName] = stepRun.output;
104
+ }
105
+ });
106
+ resolve(outputs);
107
+ return;
108
+ }
86
109
  const result = event.results.reduce((acc, r) => (Object.assign(Object.assign({}, acc), { [r.stepReadableId]: JSON.parse(r.output || '{}') })), {});
87
110
  resolve(result);
88
111
  return;
@@ -92,7 +115,7 @@ class WorkflowRunRef {
92
115
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
93
116
  finally {
94
117
  try {
95
- if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
118
+ if (!_f && !_a && (_b = _g.return)) yield _b.call(_g);
96
119
  }
97
120
  finally { if (e_1) throw e_1.error; }
98
121
  }