Added JSDocs to the schedule options in the SDK

This commit is contained in:
Matt Aitken
2024-04-17 14:25:40 +01:00
parent fde939a30e
commit 03b104a3d5
2 changed files with 39 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/core": patch
---
Added JSDocs to the schedule SDK types
+34
View File
@@ -214,19 +214,53 @@ export const CanceledRunResponse = z.object({
export type CanceledRunResponse = z.infer<typeof CanceledRunResponse>;
export const ScheduledTaskPayload = z.object({
/** The schedule id associated with this run (you can have many schedules for the same task).
You can use this to remove the schedule, update it, etc */
scheduleId: z.string(),
/** When the task was scheduled to run.
* Note this will be slightly different from `new Date()` because it takes a few ms to run the task. */
timestamp: z.date(),
/** When the task was last run (it has been).
This can be undefined if it's never been run */
lastTimestamp: z.date().optional(),
/** You can optionally provide an external id when creating the schedule.
Usually you would use a userId or some other unique identifier.
This defaults to undefined if you didn't provide one. */
externalId: z.string().optional(),
/** The next 5 dates this task is scheduled to run */
upcoming: z.array(z.date()),
});
export type ScheduledTaskPayload = z.infer<typeof ScheduledTaskPayload>;
export const CreateScheduleOptions = z.object({
/** The id of the task you want to attach to. */
task: z.string(),
/** The schedule in CRON format.
*
* ```txt
* * * * * *
┬ ┬ ┬ ┬ ┬
│ │ │ │ |
│ │ │ │ └ day of week (0 - 7, 1L - 7L) (0 or 7 is Sun)
│ │ │ └───── month (1 - 12)
│ │ └────────── day of month (1 - 31, L)
│ └─────────────── hour (0 - 23)
└──────────────────── minute (0 - 59)
* ```
"L" means the last. In the "day of week" field, 1L means the last Monday of the month. In the day of month field, L means the last day of the month.
*/
cron: z.string(),
/** (Optional) You can only create one schedule with this key. If you use it twice, the second call will update the schedule.
*
* This is useful if you don't want to create duplicate schedules for a user. */
deduplicationKey: z.string().optional(),
/** Optionally, you can specify your own IDs (like a user ID) and then use it inside the run function of your task.
*
* This allows you to have per-user CRON tasks.
*/
externalId: z.string().optional(),
});