@hatchet-dev/typescript-sdk 0.12.5 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/step.js CHANGED
@@ -225,7 +225,7 @@ class Context {
225
225
  const name = this.client.config.namespace + workflowName;
226
226
  let key = '';
227
227
  let sticky = false;
228
- let metadata = undefined;
228
+ let metadata;
229
229
  if (typeof options === 'string') {
230
230
  this.logger.warn('Using key param is deprecated and will be removed in a future release. Use options.key instead.');
231
231
  key = options;
@@ -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
  }
package/workflow.d.ts CHANGED
@@ -69,14 +69,17 @@ export declare const WorkflowConcurrency: z.ZodObject<{
69
69
  name: z.ZodString;
70
70
  maxRuns: z.ZodOptional<z.ZodNumber>;
71
71
  limitStrategy: z.ZodOptional<z.ZodNativeEnum<typeof PbConcurrencyLimitStrategy>>;
72
+ expression: z.ZodOptional<z.ZodString>;
72
73
  }, "strip", z.ZodTypeAny, {
73
74
  name: string;
74
75
  maxRuns?: number | undefined;
75
76
  limitStrategy?: PbConcurrencyLimitStrategy | undefined;
77
+ expression?: string | undefined;
76
78
  }, {
77
79
  name: string;
78
80
  maxRuns?: number | undefined;
79
81
  limitStrategy?: PbConcurrencyLimitStrategy | undefined;
82
+ expression?: string | undefined;
80
83
  }>;
81
84
  export declare const HatchetTimeoutSchema: z.ZodString;
82
85
  export declare const StickyStrategy: typeof PbStickyStrategy;
@@ -331,7 +334,7 @@ export declare const CreateWorkflowSchema: z.ZodObject<{
331
334
  }>;
332
335
  export interface Workflow extends z.infer<typeof CreateWorkflowSchema> {
333
336
  concurrency?: z.infer<typeof WorkflowConcurrency> & {
334
- key: (ctx: any) => string;
337
+ key?: (ctx: any) => string;
335
338
  };
336
339
  steps: CreateStep<any, any>[];
337
340
  onFailure?: CreateStep<any, any>;
package/workflow.js CHANGED
@@ -42,6 +42,7 @@ exports.WorkflowConcurrency = z.object({
42
42
  name: z.string(),
43
43
  maxRuns: z.number().optional(),
44
44
  limitStrategy: z.nativeEnum(exports.ConcurrencyLimitStrategy).optional(),
45
+ expression: z.string().optional(),
45
46
  });
46
47
  exports.HatchetTimeoutSchema = z.string();
47
48
  exports.StickyStrategy = workflows_1.StickyStrategy;