@trigger.dev/sdk 3.0.0-beta.2 → 3.0.0-beta.20

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
- import { TaskRunContext, InitOutput, RetryOptions, QueueOptions, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, SuccessFnParams, FetchRetryOptions } from '@trigger.dev/core/v3';
2
- export { HandleErrorArgs, HandleErrorFunction, RetryOptions, ProjectConfig as TriggerConfig, logger } from '@trigger.dev/core/v3';
1
+ import { TaskRunContext, QueueOptions, InitOutput, RetryOptions, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, SuccessFnParams, FetchRetryOptions, ReplayRunResponse, CanceledRunResponse, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, ListSchedulesResult } from '@trigger.dev/core/v3';
2
+ export { APIError, AuthenticationError, BadRequestError, ConflictError, HandleErrorArgs, HandleErrorFunction, InternalServerError, LogLevel, NotFoundError, PermissionDeniedError, RateLimitError, RetryOptions, ProjectConfig as TriggerConfig, UnprocessableEntityError, logger } from '@trigger.dev/core/v3';
3
3
  import { HttpHandler } from 'msw';
4
4
 
5
5
  type Context = TaskRunContext;
@@ -9,7 +9,10 @@ type RequireOne<T, K extends keyof T> = {
9
9
  [P in K]-?: T[P];
10
10
  };
11
11
  type Queue = RequireOne<QueueOptions, "name">;
12
- type TaskOptions<TPayload, TOutput = any, TInitOutput extends InitOutput = any> = {
12
+ declare function queue(options: {
13
+ name: string;
14
+ } & QueueOptions): Queue;
15
+ type TaskOptions<TPayload = void, TOutput = unknown, TInitOutput extends InitOutput = any> = {
13
16
  /** An id for your task. This must be unique inside your project and not change between versions. */
14
17
  id: string;
15
18
  /** The retry settings when an uncaught error is thrown.
@@ -119,36 +122,79 @@ type TaskRunResult<TOutput = any> = {
119
122
  } | {
120
123
  ok: false;
121
124
  id: string;
122
- error: any;
125
+ error: unknown;
123
126
  };
124
127
  type BatchResult<TOutput = any> = {
125
128
  id: string;
126
129
  runs: TaskRunResult<TOutput>[];
127
130
  };
128
- type Task<TInput, TOutput = any> = {
129
- trigger: (params: {
130
- payload: TInput;
131
- options?: TaskRunOptions;
132
- }) => Promise<InvokeHandle>;
133
- batchTrigger: (params: {
134
- items: {
135
- payload: TInput;
136
- options?: TaskRunOptions;
137
- }[];
138
- batchOptions?: BatchRunOptions;
139
- }) => Promise<InvokeBatchHandle>;
140
- triggerAndWait: (params: {
141
- payload: TInput;
142
- options?: TaskRunOptions;
143
- }) => Promise<TOutput>;
144
- batchTriggerAndWait: (params: {
145
- items: {
146
- payload: TInput;
147
- options?: TaskRunOptions;
148
- }[];
149
- batchOptions?: BatchRunOptions;
150
- }) => Promise<BatchResult<TOutput>>;
131
+ type BatchItem<TInput> = TInput extends void ? {
132
+ payload?: TInput;
133
+ options?: TaskRunOptions;
134
+ } : {
135
+ payload: TInput;
136
+ options?: TaskRunOptions;
151
137
  };
138
+ interface Task<TInput = void, TOutput = any> {
139
+ /**
140
+ * The id of the task.
141
+ */
142
+ id: string;
143
+ /**
144
+ * Trigger a task with the given payload, and continue without waiting for the result. If you want to wait for the result, use `triggerAndWait`. Returns the id of the triggered task run.
145
+ * @param payload
146
+ * @param options
147
+ * @returns InvokeHandle
148
+ * - `id` - The id of the triggered task run.
149
+ */
150
+ trigger: (payload: TInput, options?: TaskRunOptions) => Promise<InvokeHandle>;
151
+ /**
152
+ * Batch trigger multiple task runs with the given payloads, and continue without waiting for the results. If you want to wait for the results, use `batchTriggerAndWait`. Returns the id of the triggered batch.
153
+ * @param items
154
+ * @returns InvokeBatchHandle
155
+ * - `batchId` - The id of the triggered batch.
156
+ * - `runs` - The ids of the triggered task runs.
157
+ */
158
+ batchTrigger: (items: Array<BatchItem<TInput>>) => Promise<InvokeBatchHandle>;
159
+ /**
160
+ * Trigger a task with the given payload, and wait for the result. Returns the result of the task run
161
+ * @param payload
162
+ * @param options - Options for the task run
163
+ * @returns TaskRunResult
164
+ * @example
165
+ * ```
166
+ * const result = await task.triggerAndWait({ foo: "bar" });
167
+ *
168
+ * if (result.ok) {
169
+ * console.log(result.output);
170
+ * } else {
171
+ * console.error(result.error);
172
+ * }
173
+ * ```
174
+ */
175
+ triggerAndWait: (payload: TInput, options?: TaskRunOptions) => Promise<TaskRunResult<TOutput>>;
176
+ /**
177
+ * Batch trigger multiple task runs with the given payloads, and wait for the results. Returns the results of the task runs.
178
+ * @param items
179
+ * @returns BatchResult
180
+ * @example
181
+ * ```
182
+ * const result = await task.batchTriggerAndWait([
183
+ * { payload: { foo: "bar" } },
184
+ * { payload: { foo: "baz" } },
185
+ * ]);
186
+ *
187
+ * for (const run of result.runs) {
188
+ * if (run.ok) {
189
+ * console.log(run.output);
190
+ * } else {
191
+ * console.error(run.error);
192
+ * }
193
+ * }
194
+ * ```
195
+ */
196
+ batchTriggerAndWait: (items: Array<BatchItem<TInput>>) => Promise<BatchResult<TOutput>>;
197
+ }
152
198
  type TaskRunOptions = {
153
199
  idempotencyKey?: string;
154
200
  maxAttempts?: number;
@@ -158,9 +204,6 @@ type TaskRunOptions = {
158
204
  concurrencyKey?: string;
159
205
  };
160
206
  type TaskRunConcurrencyOptions = Queue;
161
- type BatchRunOptions = TaskRunOptions & {
162
- maxConcurrency?: number;
163
- };
164
207
 
165
208
  /** Creates a task that can be triggered
166
209
  * @param options - Task options
@@ -180,7 +223,7 @@ type BatchRunOptions = TaskRunOptions & {
180
223
  *
181
224
  * @returns A task that can be triggered
182
225
  */
183
- declare function task<TInput, TOutput = any, TInitOutput extends InitOutput = any>(options: TaskOptions<TInput, TOutput, TInitOutput>): Task<TInput, TOutput>;
226
+ declare function task$1<TInput = void, TOutput = unknown, TInitOutput extends InitOutput = any>(options: TaskOptions<TInput, TOutput, TInitOutput>): Task<TInput, TOutput>;
184
227
 
185
228
  type WaitOptions = {
186
229
  seconds: number;
@@ -251,4 +294,74 @@ declare const retry: {
251
294
  };
252
295
  };
253
296
 
254
- export { type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type Context, type Eventually, InMemoryCache, type WaitOptions, createCache, retry, task, wait };
297
+ declare const runs: {
298
+ replay: typeof replayRun;
299
+ cancel: typeof cancelRun;
300
+ };
301
+ declare function replayRun(runId: string): Promise<ReplayRunResponse>;
302
+ declare function cancelRun(runId: string): Promise<CanceledRunResponse>;
303
+
304
+ declare function task<TOutput, TInitOutput extends InitOutput>(params: TaskOptions<ScheduledTaskPayload, TOutput, TInitOutput>): Task<ScheduledTaskPayload, TOutput>;
305
+ /**
306
+ * Creates a new schedule
307
+ * @param options
308
+ * @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
309
+ * @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
310
+ * @param options.externalId - An optional external identifier for the schedule
311
+ * @param options.deduplicationKey - An optional deduplication key for the schedule
312
+ * @returns The created schedule
313
+ */
314
+ declare function create(options: CreateScheduleOptions): Promise<ScheduleObject>;
315
+ /**
316
+ * Retrieves a schedule
317
+ * @param scheduleId - The ID of the schedule to retrieve
318
+ * @returns The retrieved schedule
319
+ */
320
+ declare function retrieve(scheduleId: string): Promise<ScheduleObject>;
321
+ /**
322
+ * Updates a schedule
323
+ * @param scheduleId - The ID of the schedule to update
324
+ * @param options - The updated schedule options
325
+ * @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
326
+ * @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
327
+ * @param options.externalId - An optional external identifier for the schedule
328
+ * @returns The updated schedule
329
+ */
330
+ declare function update(scheduleId: string, options: UpdateScheduleOptions): Promise<ScheduleObject>;
331
+ /**
332
+ * Deletes a schedule
333
+ * @param scheduleId - The ID of the schedule to delete
334
+ */
335
+ declare function del(scheduleId: string): Promise<DeletedScheduleObject>;
336
+ /**
337
+ * Deactivates a schedule
338
+ * @param scheduleId - The ID of the schedule to deactivate
339
+ */
340
+ declare function deactivate(scheduleId: string): Promise<ScheduleObject>;
341
+ /**
342
+ * Activates a schedule
343
+ * @param scheduleId - The ID of the schedule to activate
344
+ */
345
+ declare function activate(scheduleId: string): Promise<ScheduleObject>;
346
+ /**
347
+ * Lists schedules
348
+ * @param options - The list options
349
+ * @param options.page - The page number
350
+ * @param options.perPage - The number of schedules per page
351
+ * @returns The list of schedules
352
+ */
353
+ declare function list(options?: ListScheduleOptions): Promise<ListSchedulesResult>;
354
+
355
+ declare const index_activate: typeof activate;
356
+ declare const index_create: typeof create;
357
+ declare const index_deactivate: typeof deactivate;
358
+ declare const index_del: typeof del;
359
+ declare const index_list: typeof list;
360
+ declare const index_retrieve: typeof retrieve;
361
+ declare const index_task: typeof task;
362
+ declare const index_update: typeof update;
363
+ declare namespace index {
364
+ export { index_activate as activate, index_create as create, index_deactivate as deactivate, index_del as del, index_list as list, index_retrieve as retrieve, index_task as task, index_update as update };
365
+ }
366
+
367
+ export { type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type Context, type Eventually, InMemoryCache, type Task, type TaskOptions, type WaitOptions, createCache, queue, retry, runs, index as schedules, task$1 as task, wait };
@@ -1,5 +1,5 @@
1
- import { TaskRunContext, InitOutput, RetryOptions, QueueOptions, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, SuccessFnParams, FetchRetryOptions } from '@trigger.dev/core/v3';
2
- export { HandleErrorArgs, HandleErrorFunction, RetryOptions, ProjectConfig as TriggerConfig, logger } from '@trigger.dev/core/v3';
1
+ import { TaskRunContext, QueueOptions, InitOutput, RetryOptions, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, SuccessFnParams, FetchRetryOptions, ReplayRunResponse, CanceledRunResponse, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, ListSchedulesResult } from '@trigger.dev/core/v3';
2
+ export { APIError, AuthenticationError, BadRequestError, ConflictError, HandleErrorArgs, HandleErrorFunction, InternalServerError, LogLevel, NotFoundError, PermissionDeniedError, RateLimitError, RetryOptions, ProjectConfig as TriggerConfig, UnprocessableEntityError, logger } from '@trigger.dev/core/v3';
3
3
  import { HttpHandler } from 'msw';
4
4
 
5
5
  type Context = TaskRunContext;
@@ -9,7 +9,10 @@ type RequireOne<T, K extends keyof T> = {
9
9
  [P in K]-?: T[P];
10
10
  };
11
11
  type Queue = RequireOne<QueueOptions, "name">;
12
- type TaskOptions<TPayload, TOutput = any, TInitOutput extends InitOutput = any> = {
12
+ declare function queue(options: {
13
+ name: string;
14
+ } & QueueOptions): Queue;
15
+ type TaskOptions<TPayload = void, TOutput = unknown, TInitOutput extends InitOutput = any> = {
13
16
  /** An id for your task. This must be unique inside your project and not change between versions. */
14
17
  id: string;
15
18
  /** The retry settings when an uncaught error is thrown.
@@ -119,36 +122,79 @@ type TaskRunResult<TOutput = any> = {
119
122
  } | {
120
123
  ok: false;
121
124
  id: string;
122
- error: any;
125
+ error: unknown;
123
126
  };
124
127
  type BatchResult<TOutput = any> = {
125
128
  id: string;
126
129
  runs: TaskRunResult<TOutput>[];
127
130
  };
128
- type Task<TInput, TOutput = any> = {
129
- trigger: (params: {
130
- payload: TInput;
131
- options?: TaskRunOptions;
132
- }) => Promise<InvokeHandle>;
133
- batchTrigger: (params: {
134
- items: {
135
- payload: TInput;
136
- options?: TaskRunOptions;
137
- }[];
138
- batchOptions?: BatchRunOptions;
139
- }) => Promise<InvokeBatchHandle>;
140
- triggerAndWait: (params: {
141
- payload: TInput;
142
- options?: TaskRunOptions;
143
- }) => Promise<TOutput>;
144
- batchTriggerAndWait: (params: {
145
- items: {
146
- payload: TInput;
147
- options?: TaskRunOptions;
148
- }[];
149
- batchOptions?: BatchRunOptions;
150
- }) => Promise<BatchResult<TOutput>>;
131
+ type BatchItem<TInput> = TInput extends void ? {
132
+ payload?: TInput;
133
+ options?: TaskRunOptions;
134
+ } : {
135
+ payload: TInput;
136
+ options?: TaskRunOptions;
151
137
  };
138
+ interface Task<TInput = void, TOutput = any> {
139
+ /**
140
+ * The id of the task.
141
+ */
142
+ id: string;
143
+ /**
144
+ * Trigger a task with the given payload, and continue without waiting for the result. If you want to wait for the result, use `triggerAndWait`. Returns the id of the triggered task run.
145
+ * @param payload
146
+ * @param options
147
+ * @returns InvokeHandle
148
+ * - `id` - The id of the triggered task run.
149
+ */
150
+ trigger: (payload: TInput, options?: TaskRunOptions) => Promise<InvokeHandle>;
151
+ /**
152
+ * Batch trigger multiple task runs with the given payloads, and continue without waiting for the results. If you want to wait for the results, use `batchTriggerAndWait`. Returns the id of the triggered batch.
153
+ * @param items
154
+ * @returns InvokeBatchHandle
155
+ * - `batchId` - The id of the triggered batch.
156
+ * - `runs` - The ids of the triggered task runs.
157
+ */
158
+ batchTrigger: (items: Array<BatchItem<TInput>>) => Promise<InvokeBatchHandle>;
159
+ /**
160
+ * Trigger a task with the given payload, and wait for the result. Returns the result of the task run
161
+ * @param payload
162
+ * @param options - Options for the task run
163
+ * @returns TaskRunResult
164
+ * @example
165
+ * ```
166
+ * const result = await task.triggerAndWait({ foo: "bar" });
167
+ *
168
+ * if (result.ok) {
169
+ * console.log(result.output);
170
+ * } else {
171
+ * console.error(result.error);
172
+ * }
173
+ * ```
174
+ */
175
+ triggerAndWait: (payload: TInput, options?: TaskRunOptions) => Promise<TaskRunResult<TOutput>>;
176
+ /**
177
+ * Batch trigger multiple task runs with the given payloads, and wait for the results. Returns the results of the task runs.
178
+ * @param items
179
+ * @returns BatchResult
180
+ * @example
181
+ * ```
182
+ * const result = await task.batchTriggerAndWait([
183
+ * { payload: { foo: "bar" } },
184
+ * { payload: { foo: "baz" } },
185
+ * ]);
186
+ *
187
+ * for (const run of result.runs) {
188
+ * if (run.ok) {
189
+ * console.log(run.output);
190
+ * } else {
191
+ * console.error(run.error);
192
+ * }
193
+ * }
194
+ * ```
195
+ */
196
+ batchTriggerAndWait: (items: Array<BatchItem<TInput>>) => Promise<BatchResult<TOutput>>;
197
+ }
152
198
  type TaskRunOptions = {
153
199
  idempotencyKey?: string;
154
200
  maxAttempts?: number;
@@ -158,9 +204,6 @@ type TaskRunOptions = {
158
204
  concurrencyKey?: string;
159
205
  };
160
206
  type TaskRunConcurrencyOptions = Queue;
161
- type BatchRunOptions = TaskRunOptions & {
162
- maxConcurrency?: number;
163
- };
164
207
 
165
208
  /** Creates a task that can be triggered
166
209
  * @param options - Task options
@@ -180,7 +223,7 @@ type BatchRunOptions = TaskRunOptions & {
180
223
  *
181
224
  * @returns A task that can be triggered
182
225
  */
183
- declare function task<TInput, TOutput = any, TInitOutput extends InitOutput = any>(options: TaskOptions<TInput, TOutput, TInitOutput>): Task<TInput, TOutput>;
226
+ declare function task$1<TInput = void, TOutput = unknown, TInitOutput extends InitOutput = any>(options: TaskOptions<TInput, TOutput, TInitOutput>): Task<TInput, TOutput>;
184
227
 
185
228
  type WaitOptions = {
186
229
  seconds: number;
@@ -251,4 +294,74 @@ declare const retry: {
251
294
  };
252
295
  };
253
296
 
254
- export { type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type Context, type Eventually, InMemoryCache, type WaitOptions, createCache, retry, task, wait };
297
+ declare const runs: {
298
+ replay: typeof replayRun;
299
+ cancel: typeof cancelRun;
300
+ };
301
+ declare function replayRun(runId: string): Promise<ReplayRunResponse>;
302
+ declare function cancelRun(runId: string): Promise<CanceledRunResponse>;
303
+
304
+ declare function task<TOutput, TInitOutput extends InitOutput>(params: TaskOptions<ScheduledTaskPayload, TOutput, TInitOutput>): Task<ScheduledTaskPayload, TOutput>;
305
+ /**
306
+ * Creates a new schedule
307
+ * @param options
308
+ * @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
309
+ * @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
310
+ * @param options.externalId - An optional external identifier for the schedule
311
+ * @param options.deduplicationKey - An optional deduplication key for the schedule
312
+ * @returns The created schedule
313
+ */
314
+ declare function create(options: CreateScheduleOptions): Promise<ScheduleObject>;
315
+ /**
316
+ * Retrieves a schedule
317
+ * @param scheduleId - The ID of the schedule to retrieve
318
+ * @returns The retrieved schedule
319
+ */
320
+ declare function retrieve(scheduleId: string): Promise<ScheduleObject>;
321
+ /**
322
+ * Updates a schedule
323
+ * @param scheduleId - The ID of the schedule to update
324
+ * @param options - The updated schedule options
325
+ * @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
326
+ * @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
327
+ * @param options.externalId - An optional external identifier for the schedule
328
+ * @returns The updated schedule
329
+ */
330
+ declare function update(scheduleId: string, options: UpdateScheduleOptions): Promise<ScheduleObject>;
331
+ /**
332
+ * Deletes a schedule
333
+ * @param scheduleId - The ID of the schedule to delete
334
+ */
335
+ declare function del(scheduleId: string): Promise<DeletedScheduleObject>;
336
+ /**
337
+ * Deactivates a schedule
338
+ * @param scheduleId - The ID of the schedule to deactivate
339
+ */
340
+ declare function deactivate(scheduleId: string): Promise<ScheduleObject>;
341
+ /**
342
+ * Activates a schedule
343
+ * @param scheduleId - The ID of the schedule to activate
344
+ */
345
+ declare function activate(scheduleId: string): Promise<ScheduleObject>;
346
+ /**
347
+ * Lists schedules
348
+ * @param options - The list options
349
+ * @param options.page - The page number
350
+ * @param options.perPage - The number of schedules per page
351
+ * @returns The list of schedules
352
+ */
353
+ declare function list(options?: ListScheduleOptions): Promise<ListSchedulesResult>;
354
+
355
+ declare const index_activate: typeof activate;
356
+ declare const index_create: typeof create;
357
+ declare const index_deactivate: typeof deactivate;
358
+ declare const index_del: typeof del;
359
+ declare const index_list: typeof list;
360
+ declare const index_retrieve: typeof retrieve;
361
+ declare const index_task: typeof task;
362
+ declare const index_update: typeof update;
363
+ declare namespace index {
364
+ export { index_activate as activate, index_create as create, index_deactivate as deactivate, index_del as del, index_list as list, index_retrieve as retrieve, index_task as task, index_update as update };
365
+ }
366
+
367
+ export { type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type Context, type Eventually, InMemoryCache, type Task, type TaskOptions, type WaitOptions, createCache, queue, retry, runs, index as schedules, task$1 as task, wait };