Skip to content

Commit

Permalink
Add subtasks to the schema/types when getting an individual run (#343)
Browse files Browse the repository at this point in the history
* Add subtasks to the schema/types when getting an individual run

* Added a changeset
  • Loading branch information
matt-aitken authored Aug 16, 2023
1 parent 5611768 commit 33184a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fair-spiders-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/core": patch
---

Add subtasks to the schema/types when getting an individual run
11 changes: 10 additions & 1 deletion packages/core/src/schemas/runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export const RunTaskSchema = z.object({
completedAt: z.coerce.date().nullable(),
});

export type RunTaskWithSubtasks = z.infer<typeof RunTaskSchema> & {
/** The subtasks of the task */
subtasks?: RunTaskWithSubtasks[];
};

const RunTaskWithSubtasksSchema: z.ZodType<RunTaskWithSubtasks> = RunTaskSchema.extend({
subtasks: z.lazy(() => RunTaskWithSubtasksSchema.array()).optional(),
});

const GetRunOptionsSchema = z.object({
/** Return subtasks, which appear in a `subtasks` array on a task. @default false */
subtasks: z.boolean().optional(),
Expand Down Expand Up @@ -68,7 +77,7 @@ export const GetRunSchema = RunSchema.extend({
/** The output of the run */
output: z.any().optional(),
/** The tasks from the run */
tasks: z.array(RunTaskSchema),
tasks: z.array(RunTaskWithSubtasksSchema),
/** If there are more tasks, you can use this to get them */
nextCursor: z.string().optional(),
});
Expand Down

0 comments on commit 33184a8

Please sign in to comment.