@trigger.dev/sdk 3.0.0-beta.4 → 3.0.0-beta.41
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/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +221 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +221 -69
- package/dist/index.mjs.map +1 -1
- package/dist/v3/index.d.mts +610 -78
- package/dist/v3/index.d.ts +610 -78
- package/dist/v3/index.js +1101 -477
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +1060 -479
- package/dist/v3/index.mjs.map +1 -1
- package/package.json +5 -12
package/dist/v3/index.d.mts
CHANGED
|
@@ -1,7 +1,253 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { HandleErrorArgs, HandleErrorFunction, LogLevel, RetryOptions, ProjectConfig as TriggerConfig, logger } from '@trigger.dev/core/v3';
|
|
1
|
+
import { RetryOptions, FetchRetryOptions, ListProjectRunsQueryParams, CursorPagePromise, ListRunResponseItem, ListRunsQueryParams, ApiPromise, ReplayRunResponse, CanceledRunResponse, RetrieveRunResponse, TaskRunContext, QueueOptions, InitOutput, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, StartFnParams, SuccessFnParams, FailureFnParams, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, OffsetLimitPagePromise, ImportEnvironmentVariablesParams, EnvironmentVariableResponseBody, EnvironmentVariables, CreateEnvironmentVariableParams, EnvironmentVariableValue, UpdateEnvironmentVariableParams, ApiClientConfiguration } from '@trigger.dev/core/v3';
|
|
2
|
+
export { ApiClientConfiguration, ApiError, AuthenticationError, BadRequestError, ConflictError, HandleErrorArgs, HandleErrorFunction, ImportEnvironmentVariablesParams, InternalServerError, LogLevel, NotFoundError, PermissionDeniedError, RateLimitError, ResolveEnvironmentVariablesFunction, ResolveEnvironmentVariablesParams, ResolveEnvironmentVariablesResult, RetryOptions, ProjectConfig as TriggerConfig, UnprocessableEntityError, logger } from '@trigger.dev/core/v3';
|
|
3
3
|
import { HttpHandler } from 'msw';
|
|
4
4
|
|
|
5
|
+
type CacheMetadata = {
|
|
6
|
+
createdTime: number;
|
|
7
|
+
ttl?: number | null;
|
|
8
|
+
};
|
|
9
|
+
type CacheEntry<Value = unknown> = {
|
|
10
|
+
metadata: CacheMetadata;
|
|
11
|
+
value: Value;
|
|
12
|
+
};
|
|
13
|
+
type Eventually<Value> = Value | null | undefined | Promise<Value | null | undefined>;
|
|
14
|
+
type CacheStore<Value = any> = {
|
|
15
|
+
name?: string;
|
|
16
|
+
get: (key: string) => Eventually<CacheEntry<Value>>;
|
|
17
|
+
set: (key: string, value: CacheEntry<Value>) => unknown | Promise<unknown>;
|
|
18
|
+
delete: (key: string) => unknown | Promise<unknown>;
|
|
19
|
+
};
|
|
20
|
+
type CacheFunction = <Value>(cacheKey: string, fn: () => Promise<Value> | Value) => Promise<Value> | Value;
|
|
21
|
+
declare class InMemoryCache<Value = any> {
|
|
22
|
+
private _cache;
|
|
23
|
+
get(key: string): Eventually<CacheEntry<Value>>;
|
|
24
|
+
set(key: string, value: CacheEntry<Value>): unknown;
|
|
25
|
+
delete(key: string): unknown;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a cache function that uses the provided store to cache values. Using InMemoryCache is safe because each task run is isolated.
|
|
29
|
+
* @param store
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
declare function createCache(store: CacheStore): CacheFunction;
|
|
33
|
+
|
|
34
|
+
declare function onThrow<T>(fn: (options: {
|
|
35
|
+
attempt: number;
|
|
36
|
+
maxAttempts: number;
|
|
37
|
+
}) => Promise<T>, options: RetryOptions): Promise<T>;
|
|
38
|
+
interface RetryFetchRequestInit extends RequestInit {
|
|
39
|
+
retry?: FetchRetryOptions;
|
|
40
|
+
timeoutInMs?: number;
|
|
41
|
+
}
|
|
42
|
+
declare function retryFetch(input: RequestInfo | URL, init?: RetryFetchRequestInit | undefined): Promise<Response>;
|
|
43
|
+
declare const retry: {
|
|
44
|
+
onThrow: typeof onThrow;
|
|
45
|
+
fetch: typeof retryFetch;
|
|
46
|
+
interceptFetch: (...handlers: Array<HttpHandler>) => {
|
|
47
|
+
run: <T>(fn: (...args: any[]) => Promise<T>) => Promise<T>;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type RetrieveRunResult<TOutput> = Prettify<TOutput extends RunHandle<infer THandleOutput> ? Omit<RetrieveRunResponse, "output"> & {
|
|
52
|
+
output?: THandleOutput;
|
|
53
|
+
} : Omit<RetrieveRunResponse, "output"> & {
|
|
54
|
+
output?: TOutput;
|
|
55
|
+
}>;
|
|
56
|
+
declare const runs: {
|
|
57
|
+
replay: typeof replayRun;
|
|
58
|
+
cancel: typeof cancelRun;
|
|
59
|
+
retrieve: typeof retrieveRun;
|
|
60
|
+
list: typeof listRuns;
|
|
61
|
+
poll: typeof poll;
|
|
62
|
+
};
|
|
63
|
+
declare function listRuns(projectRef: string, params?: ListProjectRunsQueryParams): CursorPagePromise<typeof ListRunResponseItem>;
|
|
64
|
+
declare function listRuns(params?: ListRunsQueryParams): CursorPagePromise<typeof ListRunResponseItem>;
|
|
65
|
+
declare function retrieveRun<TRunId extends RunHandle<any> | string>(runId: TRunId): ApiPromise<RetrieveRunResult<TRunId>>;
|
|
66
|
+
declare function replayRun(runId: string): ApiPromise<ReplayRunResponse>;
|
|
67
|
+
declare function cancelRun(runId: string): ApiPromise<CanceledRunResponse>;
|
|
68
|
+
type PollOptions = {
|
|
69
|
+
pollIntervalMs?: number;
|
|
70
|
+
};
|
|
71
|
+
declare function poll<TRunHandle extends RunHandle<any> | string>(handle: TRunHandle, options?: {
|
|
72
|
+
pollIntervalMs?: number;
|
|
73
|
+
}): Promise<(TRunHandle extends RunHandle<infer THandleOutput> ? Omit<{
|
|
74
|
+
status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE";
|
|
75
|
+
id: string;
|
|
76
|
+
isTest: boolean;
|
|
77
|
+
createdAt: Date;
|
|
78
|
+
attempts: ({
|
|
79
|
+
status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
|
|
80
|
+
id: string;
|
|
81
|
+
createdAt: Date;
|
|
82
|
+
updatedAt: Date;
|
|
83
|
+
startedAt?: Date | undefined;
|
|
84
|
+
completedAt?: Date | undefined;
|
|
85
|
+
error?: {
|
|
86
|
+
message: string;
|
|
87
|
+
name?: string | undefined;
|
|
88
|
+
stackTrace?: string | undefined;
|
|
89
|
+
} | undefined;
|
|
90
|
+
} | undefined)[];
|
|
91
|
+
updatedAt: Date;
|
|
92
|
+
taskIdentifier: string;
|
|
93
|
+
isQueued: boolean;
|
|
94
|
+
isExecuting: boolean;
|
|
95
|
+
isCompleted: boolean;
|
|
96
|
+
isSuccess: boolean;
|
|
97
|
+
isFailed: boolean;
|
|
98
|
+
isCancelled: boolean;
|
|
99
|
+
payload?: any;
|
|
100
|
+
output?: any;
|
|
101
|
+
schedule?: {
|
|
102
|
+
id: string;
|
|
103
|
+
generator: {
|
|
104
|
+
type: "CRON";
|
|
105
|
+
expression: string;
|
|
106
|
+
description: string;
|
|
107
|
+
};
|
|
108
|
+
externalId?: string | undefined;
|
|
109
|
+
deduplicationKey?: string | undefined;
|
|
110
|
+
} | undefined;
|
|
111
|
+
idempotencyKey?: string | undefined;
|
|
112
|
+
version?: string | undefined;
|
|
113
|
+
startedAt?: Date | undefined;
|
|
114
|
+
finishedAt?: Date | undefined;
|
|
115
|
+
}, "output"> & {
|
|
116
|
+
output?: THandleOutput | undefined;
|
|
117
|
+
} : Omit<{
|
|
118
|
+
status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE";
|
|
119
|
+
id: string;
|
|
120
|
+
isTest: boolean;
|
|
121
|
+
createdAt: Date;
|
|
122
|
+
attempts: ({
|
|
123
|
+
status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
|
|
124
|
+
id: string;
|
|
125
|
+
createdAt: Date;
|
|
126
|
+
updatedAt: Date;
|
|
127
|
+
startedAt?: Date | undefined;
|
|
128
|
+
completedAt?: Date | undefined;
|
|
129
|
+
error?: {
|
|
130
|
+
message: string;
|
|
131
|
+
name?: string | undefined;
|
|
132
|
+
stackTrace?: string | undefined;
|
|
133
|
+
} | undefined;
|
|
134
|
+
} | undefined)[];
|
|
135
|
+
updatedAt: Date;
|
|
136
|
+
taskIdentifier: string;
|
|
137
|
+
isQueued: boolean;
|
|
138
|
+
isExecuting: boolean;
|
|
139
|
+
isCompleted: boolean;
|
|
140
|
+
isSuccess: boolean;
|
|
141
|
+
isFailed: boolean;
|
|
142
|
+
isCancelled: boolean;
|
|
143
|
+
payload?: any;
|
|
144
|
+
output?: any;
|
|
145
|
+
schedule?: {
|
|
146
|
+
id: string;
|
|
147
|
+
generator: {
|
|
148
|
+
type: "CRON";
|
|
149
|
+
expression: string;
|
|
150
|
+
description: string;
|
|
151
|
+
};
|
|
152
|
+
externalId?: string | undefined;
|
|
153
|
+
deduplicationKey?: string | undefined;
|
|
154
|
+
} | undefined;
|
|
155
|
+
idempotencyKey?: string | undefined;
|
|
156
|
+
version?: string | undefined;
|
|
157
|
+
startedAt?: Date | undefined;
|
|
158
|
+
finishedAt?: Date | undefined;
|
|
159
|
+
}, "output"> & {
|
|
160
|
+
output?: TRunHandle | undefined;
|
|
161
|
+
}) extends infer T ? { [K in keyof T]: (TRunHandle extends RunHandle<infer THandleOutput> ? Omit<{
|
|
162
|
+
status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE";
|
|
163
|
+
id: string;
|
|
164
|
+
isTest: boolean;
|
|
165
|
+
createdAt: Date;
|
|
166
|
+
attempts: ({
|
|
167
|
+
status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
|
|
168
|
+
id: string;
|
|
169
|
+
createdAt: Date;
|
|
170
|
+
updatedAt: Date;
|
|
171
|
+
startedAt?: Date | undefined;
|
|
172
|
+
completedAt?: Date | undefined;
|
|
173
|
+
error?: {
|
|
174
|
+
message: string;
|
|
175
|
+
name?: string | undefined;
|
|
176
|
+
stackTrace?: string | undefined;
|
|
177
|
+
} | undefined;
|
|
178
|
+
} | undefined)[];
|
|
179
|
+
updatedAt: Date;
|
|
180
|
+
taskIdentifier: string;
|
|
181
|
+
isQueued: boolean;
|
|
182
|
+
isExecuting: boolean;
|
|
183
|
+
isCompleted: boolean;
|
|
184
|
+
isSuccess: boolean;
|
|
185
|
+
isFailed: boolean;
|
|
186
|
+
isCancelled: boolean;
|
|
187
|
+
payload?: any;
|
|
188
|
+
output?: any;
|
|
189
|
+
schedule?: {
|
|
190
|
+
id: string;
|
|
191
|
+
generator: {
|
|
192
|
+
type: "CRON";
|
|
193
|
+
expression: string;
|
|
194
|
+
description: string;
|
|
195
|
+
};
|
|
196
|
+
externalId?: string | undefined;
|
|
197
|
+
deduplicationKey?: string | undefined;
|
|
198
|
+
} | undefined;
|
|
199
|
+
idempotencyKey?: string | undefined;
|
|
200
|
+
version?: string | undefined;
|
|
201
|
+
startedAt?: Date | undefined;
|
|
202
|
+
finishedAt?: Date | undefined;
|
|
203
|
+
}, "output"> & {
|
|
204
|
+
output?: THandleOutput | undefined;
|
|
205
|
+
} : Omit<{
|
|
206
|
+
status: "CANCELED" | "COMPLETED" | "FAILED" | "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE";
|
|
207
|
+
id: string;
|
|
208
|
+
isTest: boolean;
|
|
209
|
+
createdAt: Date;
|
|
210
|
+
attempts: ({
|
|
211
|
+
status: "PENDING" | "CANCELED" | "COMPLETED" | "FAILED" | "EXECUTING" | "PAUSED";
|
|
212
|
+
id: string;
|
|
213
|
+
createdAt: Date;
|
|
214
|
+
updatedAt: Date;
|
|
215
|
+
startedAt?: Date | undefined;
|
|
216
|
+
completedAt?: Date | undefined;
|
|
217
|
+
error?: {
|
|
218
|
+
message: string;
|
|
219
|
+
name?: string | undefined;
|
|
220
|
+
stackTrace?: string | undefined;
|
|
221
|
+
} | undefined;
|
|
222
|
+
} | undefined)[];
|
|
223
|
+
updatedAt: Date;
|
|
224
|
+
taskIdentifier: string;
|
|
225
|
+
isQueued: boolean;
|
|
226
|
+
isExecuting: boolean;
|
|
227
|
+
isCompleted: boolean;
|
|
228
|
+
isSuccess: boolean;
|
|
229
|
+
isFailed: boolean;
|
|
230
|
+
isCancelled: boolean;
|
|
231
|
+
payload?: any;
|
|
232
|
+
output?: any;
|
|
233
|
+
schedule?: {
|
|
234
|
+
id: string;
|
|
235
|
+
generator: {
|
|
236
|
+
type: "CRON";
|
|
237
|
+
expression: string;
|
|
238
|
+
description: string;
|
|
239
|
+
};
|
|
240
|
+
externalId?: string | undefined;
|
|
241
|
+
deduplicationKey?: string | undefined;
|
|
242
|
+
} | undefined;
|
|
243
|
+
idempotencyKey?: string | undefined;
|
|
244
|
+
version?: string | undefined;
|
|
245
|
+
startedAt?: Date | undefined;
|
|
246
|
+
finishedAt?: Date | undefined;
|
|
247
|
+
}, "output"> & {
|
|
248
|
+
output?: TRunHandle | undefined;
|
|
249
|
+
})[K]; } : never>;
|
|
250
|
+
|
|
5
251
|
type Context = TaskRunContext;
|
|
6
252
|
type RequireOne<T, K extends keyof T> = {
|
|
7
253
|
[X in Exclude<keyof T, K>]?: T[X];
|
|
@@ -9,9 +255,12 @@ type RequireOne<T, K extends keyof T> = {
|
|
|
9
255
|
[P in K]-?: T[P];
|
|
10
256
|
};
|
|
11
257
|
type Queue = RequireOne<QueueOptions, "name">;
|
|
12
|
-
|
|
258
|
+
declare function queue(options: {
|
|
259
|
+
name: string;
|
|
260
|
+
} & QueueOptions): Queue;
|
|
261
|
+
type TaskOptions<TIdentifier extends string, TPayload = void, TOutput = unknown, TInitOutput extends InitOutput = any> = {
|
|
13
262
|
/** An id for your task. This must be unique inside your project and not change between versions. */
|
|
14
|
-
id:
|
|
263
|
+
id: TIdentifier;
|
|
15
264
|
/** The retry settings when an uncaught error is thrown.
|
|
16
265
|
*
|
|
17
266
|
* If omitted it will use the values in your `trigger.config.ts` file.
|
|
@@ -79,6 +328,7 @@ type TaskOptions<TPayload, TOutput = any, TInitOutput extends InitOutput = any>
|
|
|
79
328
|
* - 1
|
|
80
329
|
* - 2
|
|
81
330
|
* - 4
|
|
331
|
+
* @deprecated use preset instead
|
|
82
332
|
*/
|
|
83
333
|
cpu?: MachineCpu;
|
|
84
334
|
/** In GBs of RAM. The default is 1.
|
|
@@ -90,8 +340,11 @@ type TaskOptions<TPayload, TOutput = any, TInitOutput extends InitOutput = any>
|
|
|
90
340
|
* - 2
|
|
91
341
|
* - 4
|
|
92
342
|
* - 8
|
|
343
|
+
* * @deprecated use preset instead
|
|
93
344
|
*/
|
|
94
345
|
memory?: MachineMemory;
|
|
346
|
+
/** Preset to use for the machine. Defaults to small-1x */
|
|
347
|
+
preset?: "micro" | "small-1x" | "small-2x" | "medium-1x" | "medium-2x" | "large-1x" | "large-2x";
|
|
95
348
|
};
|
|
96
349
|
/** This gets called when a task is triggered. It's where you put the code you want to execute.
|
|
97
350
|
*
|
|
@@ -99,19 +352,64 @@ type TaskOptions<TPayload, TOutput = any, TInitOutput extends InitOutput = any>
|
|
|
99
352
|
* @param params - Metadata about the run.
|
|
100
353
|
*/
|
|
101
354
|
run: (payload: TPayload, params: RunFnParams<TInitOutput>) => Promise<TOutput>;
|
|
355
|
+
/**
|
|
356
|
+
* init is called before the run function is called. It's useful for setting up any global state.
|
|
357
|
+
*/
|
|
102
358
|
init?: (payload: TPayload, params: InitFnParams) => Promise<TInitOutput>;
|
|
103
|
-
|
|
359
|
+
/**
|
|
360
|
+
* cleanup is called after the run function has completed.
|
|
361
|
+
*/
|
|
104
362
|
cleanup?: (payload: TPayload, params: RunFnParams<TInitOutput>) => Promise<void>;
|
|
363
|
+
/**
|
|
364
|
+
* handleError is called when the run function throws an error. It can be used to modify the error or return new retry options.
|
|
365
|
+
*/
|
|
366
|
+
handleError?: (payload: TPayload, error: unknown, params: HandleErrorFnParams<TInitOutput>) => HandleErrorResult;
|
|
367
|
+
/**
|
|
368
|
+
* middleware allows you to run code "around" the run function. This can be useful for logging, metrics, or other cross-cutting concerns.
|
|
369
|
+
*
|
|
370
|
+
* When writing middleware, you should always call `next()` to continue the execution of the task:
|
|
371
|
+
*
|
|
372
|
+
* ```ts
|
|
373
|
+
* export const middlewareTask = task({
|
|
374
|
+
* id: "middleware-task",
|
|
375
|
+
* middleware: async (payload, { ctx, next }) => {
|
|
376
|
+
* console.log("Before run");
|
|
377
|
+
* await next();
|
|
378
|
+
* console.log("After run");
|
|
379
|
+
* },
|
|
380
|
+
* run: async (payload, { ctx }) => {}
|
|
381
|
+
* });
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
105
384
|
middleware?: (payload: TPayload, params: MiddlewareFnParams) => Promise<void>;
|
|
106
|
-
|
|
385
|
+
/**
|
|
386
|
+
* onStart is called the first time a task is executed in a run (not before every retry)
|
|
387
|
+
*/
|
|
388
|
+
onStart?: (payload: TPayload, params: StartFnParams) => Promise<void>;
|
|
389
|
+
/**
|
|
390
|
+
* onSuccess is called after the run function has successfully completed.
|
|
391
|
+
*/
|
|
392
|
+
onSuccess?: (payload: TPayload, output: TOutput, params: SuccessFnParams<TInitOutput>) => Promise<void>;
|
|
393
|
+
/**
|
|
394
|
+
* onFailure is called after a task run has failed (meaning the run function threw an error and won't be retried anymore)
|
|
395
|
+
*/
|
|
396
|
+
onFailure?: (payload: TPayload, error: unknown, params: FailureFnParams<TInitOutput>) => Promise<void>;
|
|
107
397
|
};
|
|
108
|
-
|
|
109
|
-
|
|
398
|
+
declare const __output: unique symbol;
|
|
399
|
+
type BrandOutput<B> = {
|
|
400
|
+
[__output]: B;
|
|
110
401
|
};
|
|
111
|
-
type
|
|
402
|
+
type BrandedOutput<T, B> = T & BrandOutput<B>;
|
|
403
|
+
type RunHandle<TOutput> = BrandedOutput<{
|
|
404
|
+
id: string;
|
|
405
|
+
}, TOutput>;
|
|
406
|
+
/**
|
|
407
|
+
* A BatchRunHandle can be used to retrieve the runs of a batch trigger in a typesafe manner.
|
|
408
|
+
*/
|
|
409
|
+
type BatchRunHandle<TOutput> = BrandedOutput<{
|
|
112
410
|
batchId: string;
|
|
113
|
-
runs:
|
|
114
|
-
}
|
|
411
|
+
runs: Array<RunHandle<TOutput>>;
|
|
412
|
+
}, TOutput>;
|
|
115
413
|
type TaskRunResult<TOutput = any> = {
|
|
116
414
|
ok: true;
|
|
117
415
|
id: string;
|
|
@@ -119,36 +417,85 @@ type TaskRunResult<TOutput = any> = {
|
|
|
119
417
|
} | {
|
|
120
418
|
ok: false;
|
|
121
419
|
id: string;
|
|
122
|
-
error:
|
|
420
|
+
error: unknown;
|
|
123
421
|
};
|
|
124
422
|
type BatchResult<TOutput = any> = {
|
|
125
423
|
id: string;
|
|
126
424
|
runs: TaskRunResult<TOutput>[];
|
|
127
425
|
};
|
|
128
|
-
type
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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>>;
|
|
426
|
+
type BatchItem<TInput> = TInput extends void ? {
|
|
427
|
+
payload?: TInput;
|
|
428
|
+
options?: TaskRunOptions;
|
|
429
|
+
} : {
|
|
430
|
+
payload: TInput;
|
|
431
|
+
options?: TaskRunOptions;
|
|
151
432
|
};
|
|
433
|
+
interface Task<TIdentifier extends string, TInput = void, TOutput = any> {
|
|
434
|
+
/**
|
|
435
|
+
* The id of the task.
|
|
436
|
+
*/
|
|
437
|
+
id: TIdentifier;
|
|
438
|
+
/**
|
|
439
|
+
* 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.
|
|
440
|
+
* @param payload
|
|
441
|
+
* @param options
|
|
442
|
+
* @returns RunHandle
|
|
443
|
+
* - `id` - The id of the triggered task run.
|
|
444
|
+
*/
|
|
445
|
+
trigger: (payload: TInput, options?: TaskRunOptions) => Promise<RunHandle<TOutput>>;
|
|
446
|
+
/**
|
|
447
|
+
* 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.
|
|
448
|
+
* @param items
|
|
449
|
+
* @returns InvokeBatchHandle
|
|
450
|
+
* - `batchId` - The id of the triggered batch.
|
|
451
|
+
* - `runs` - The ids of the triggered task runs.
|
|
452
|
+
*/
|
|
453
|
+
batchTrigger: (items: Array<BatchItem<TInput>>) => Promise<BatchRunHandle<TOutput>>;
|
|
454
|
+
/**
|
|
455
|
+
* Trigger a task with the given payload, and wait for the result. Returns the result of the task run
|
|
456
|
+
* @param payload
|
|
457
|
+
* @param options - Options for the task run
|
|
458
|
+
* @returns TaskRunResult
|
|
459
|
+
* @example
|
|
460
|
+
* ```
|
|
461
|
+
* const result = await task.triggerAndWait({ foo: "bar" });
|
|
462
|
+
*
|
|
463
|
+
* if (result.ok) {
|
|
464
|
+
* console.log(result.output);
|
|
465
|
+
* } else {
|
|
466
|
+
* console.error(result.error);
|
|
467
|
+
* }
|
|
468
|
+
* ```
|
|
469
|
+
*/
|
|
470
|
+
triggerAndWait: (payload: TInput, options?: TaskRunOptions) => Promise<TaskRunResult<TOutput>>;
|
|
471
|
+
/**
|
|
472
|
+
* Batch trigger multiple task runs with the given payloads, and wait for the results. Returns the results of the task runs.
|
|
473
|
+
* @param items
|
|
474
|
+
* @returns BatchResult
|
|
475
|
+
* @example
|
|
476
|
+
* ```
|
|
477
|
+
* const result = await task.batchTriggerAndWait([
|
|
478
|
+
* { payload: { foo: "bar" } },
|
|
479
|
+
* { payload: { foo: "baz" } },
|
|
480
|
+
* ]);
|
|
481
|
+
*
|
|
482
|
+
* for (const run of result.runs) {
|
|
483
|
+
* if (run.ok) {
|
|
484
|
+
* console.log(run.output);
|
|
485
|
+
* } else {
|
|
486
|
+
* console.error(run.error);
|
|
487
|
+
* }
|
|
488
|
+
* }
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
491
|
+
batchTriggerAndWait: (items: Array<BatchItem<TInput>>) => Promise<BatchResult<TOutput>>;
|
|
492
|
+
}
|
|
493
|
+
type AnyTask = Task<string, any, any>;
|
|
494
|
+
type TaskPayload<TTask extends AnyTask> = TTask extends Task<string, infer TInput, any> ? TInput : never;
|
|
495
|
+
type TaskOutput<TTask extends AnyTask> = TTask extends Task<string, any, infer TOutput> ? TOutput : never;
|
|
496
|
+
type TaskOutputHandle<TTask extends AnyTask> = TTask extends Task<string, any, infer TOutput> ? RunHandle<TOutput> : never;
|
|
497
|
+
type TaskBatchOutputHandle<TTask extends AnyTask> = TTask extends Task<string, any, infer TOutput> ? BatchRunHandle<TOutput> : never;
|
|
498
|
+
type TaskIdentifier<TTask extends AnyTask> = TTask extends Task<infer TIdentifier, any, any> ? TIdentifier : never;
|
|
152
499
|
type TaskRunOptions = {
|
|
153
500
|
idempotencyKey?: string;
|
|
154
501
|
maxAttempts?: number;
|
|
@@ -158,9 +505,43 @@ type TaskRunOptions = {
|
|
|
158
505
|
concurrencyKey?: string;
|
|
159
506
|
};
|
|
160
507
|
type TaskRunConcurrencyOptions = Queue;
|
|
161
|
-
type
|
|
162
|
-
|
|
163
|
-
};
|
|
508
|
+
type Prettify<T> = {
|
|
509
|
+
[K in keyof T]: T[K];
|
|
510
|
+
} & {};
|
|
511
|
+
/**
|
|
512
|
+
* Trigger a task by its identifier with the given payload. Returns a typesafe `RunHandle`.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
*
|
|
516
|
+
* ```ts
|
|
517
|
+
* import { tasks, runs } from "@trigger.dev/sdk/v3";
|
|
518
|
+
* import type { myTask } from "./myTasks"; // Import just the type of the task
|
|
519
|
+
*
|
|
520
|
+
* const handle = await tasks.trigger<typeof myTask>("my-task", { foo: "bar" }); // The id and payload are fully typesafe
|
|
521
|
+
* const run = await runs.retrieve(handle);
|
|
522
|
+
* console.log(run.output) // The output is also fully typed
|
|
523
|
+
* ```
|
|
524
|
+
*
|
|
525
|
+
* @returns {RunHandle} An object with the `id` of the run. Can be used to retrieve the completed run output in a typesafe manner.
|
|
526
|
+
*/
|
|
527
|
+
declare function trigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions): Promise<TaskOutputHandle<TTask>>;
|
|
528
|
+
/**
|
|
529
|
+
* Trigger a task by its identifier with the given payload and poll until the run is completed.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
*
|
|
533
|
+
* ```ts
|
|
534
|
+
* import { tasks, runs } from "@trigger.dev/sdk/v3";
|
|
535
|
+
* import type { myTask } from "./myTasks"; // Import just the type of the task
|
|
536
|
+
*
|
|
537
|
+
* const run = await tasks.triggerAndPoll<typeof myTask>("my-task", { foo: "bar" }); // The id and payload are fully typesafe
|
|
538
|
+
* console.log(run.output) // The output is also fully typed
|
|
539
|
+
* ```
|
|
540
|
+
*
|
|
541
|
+
* @returns {Run} The completed run, either successful or failed.
|
|
542
|
+
*/
|
|
543
|
+
declare function triggerAndPoll<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions & PollOptions): Promise<RetrieveRunResult<TaskOutputHandle<TTask>>>;
|
|
544
|
+
declare function batchTrigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, items: Array<BatchItem<TaskPayload<TTask>>>): Promise<TaskBatchOutputHandle<TTask>>;
|
|
164
545
|
|
|
165
546
|
/** Creates a task that can be triggered
|
|
166
547
|
* @param options - Task options
|
|
@@ -180,7 +561,12 @@ type BatchRunOptions = TaskRunOptions & {
|
|
|
180
561
|
*
|
|
181
562
|
* @returns A task that can be triggered
|
|
182
563
|
*/
|
|
183
|
-
declare function task<TInput, TOutput =
|
|
564
|
+
declare function task$1<TIdentifier extends string, TInput = void, TOutput = unknown, TInitOutput extends InitOutput = any>(options: TaskOptions<TIdentifier, TInput, TOutput, TInitOutput>): Task<TIdentifier, TInput, TOutput>;
|
|
565
|
+
declare const tasks: {
|
|
566
|
+
trigger: typeof trigger;
|
|
567
|
+
triggerAndPoll: typeof triggerAndPoll;
|
|
568
|
+
batchTrigger: typeof batchTrigger;
|
|
569
|
+
};
|
|
184
570
|
|
|
185
571
|
type WaitOptions = {
|
|
186
572
|
seconds: number;
|
|
@@ -205,50 +591,196 @@ declare const wait: {
|
|
|
205
591
|
}) => Promise<void>;
|
|
206
592
|
};
|
|
207
593
|
|
|
208
|
-
type
|
|
209
|
-
|
|
210
|
-
|
|
594
|
+
type ComputeUsage = {
|
|
595
|
+
costInCents: number;
|
|
596
|
+
durationMs: number;
|
|
211
597
|
};
|
|
212
|
-
type
|
|
213
|
-
|
|
214
|
-
|
|
598
|
+
type CurrentUsage = {
|
|
599
|
+
compute: {
|
|
600
|
+
attempt: ComputeUsage;
|
|
601
|
+
total: ComputeUsage;
|
|
602
|
+
};
|
|
603
|
+
baseCostInCents: number;
|
|
604
|
+
totalCostInCents: number;
|
|
215
605
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
606
|
+
declare const usage: {
|
|
607
|
+
/**
|
|
608
|
+
* Get the current running usage of this task run.
|
|
609
|
+
*
|
|
610
|
+
* @example
|
|
611
|
+
*
|
|
612
|
+
* ```typescript
|
|
613
|
+
* import { usage, task } from "@trigger.dev/sdk/v3";
|
|
614
|
+
*
|
|
615
|
+
* export const myTask = task({
|
|
616
|
+
* id: "my-task",
|
|
617
|
+
* run: async (payload, { ctx }) => {
|
|
618
|
+
* // ... Do a bunch of work
|
|
619
|
+
*
|
|
620
|
+
* const currentUsage = usage.getCurrent();
|
|
621
|
+
*
|
|
622
|
+
* // You have access to the current compute cost and duration up to this point
|
|
623
|
+
* console.log("Current attempt compute cost and duration", {
|
|
624
|
+
* cost: currentUsage.compute.attempt.costInCents,
|
|
625
|
+
* duration: currentUsage.compute.attempt.durationMs,
|
|
626
|
+
* });
|
|
627
|
+
*
|
|
628
|
+
* // You also can see the total compute cost and duration up to this point in the run, across all attempts
|
|
629
|
+
* console.log("Current total compute cost and duration", {
|
|
630
|
+
* cost: currentUsage.compute.total.costInCents,
|
|
631
|
+
* duration: currentUsage.compute.total.durationMs,
|
|
632
|
+
* });
|
|
633
|
+
*
|
|
634
|
+
* // You can see the base cost of the run, which is the cost of the run before any compute costs
|
|
635
|
+
* console.log("Total cost", {
|
|
636
|
+
* cost: currentUsage.totalCostInCents,
|
|
637
|
+
* baseCost: currentUsage.baseCostInCents,
|
|
638
|
+
* });
|
|
639
|
+
* },
|
|
640
|
+
* });
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
getCurrent: () => CurrentUsage;
|
|
644
|
+
/**
|
|
645
|
+
* Measure the cost and duration of a function.
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
*
|
|
649
|
+
* ```typescript
|
|
650
|
+
* import { usage } from "@trigger.dev/sdk/v3";
|
|
651
|
+
*
|
|
652
|
+
* export const myTask = task({
|
|
653
|
+
* id: "my-task",
|
|
654
|
+
* run: async (payload, { ctx }) => {
|
|
655
|
+
* const { result, compute } = await usage.measure(async () => {
|
|
656
|
+
* // Do some work
|
|
657
|
+
* return "result";
|
|
658
|
+
* });
|
|
659
|
+
*
|
|
660
|
+
* console.log("Result", result);
|
|
661
|
+
* console.log("Cost and duration", { cost: compute.costInCents, duration: compute.durationMs });
|
|
662
|
+
* },
|
|
663
|
+
* });
|
|
664
|
+
* ```
|
|
665
|
+
*/
|
|
666
|
+
measure: <T>(cb: () => Promise<T>) => Promise<{
|
|
667
|
+
result: T;
|
|
668
|
+
compute: ComputeUsage;
|
|
669
|
+
}>;
|
|
222
670
|
};
|
|
223
|
-
|
|
224
|
-
declare
|
|
225
|
-
private _cache;
|
|
226
|
-
get(key: string): Eventually<CacheEntry<Value>>;
|
|
227
|
-
set(key: string, value: CacheEntry<Value>): unknown;
|
|
228
|
-
delete(key: string): unknown;
|
|
229
|
-
}
|
|
671
|
+
|
|
672
|
+
declare function task<TIdentifier extends string, TOutput, TInitOutput extends InitOutput>(params: TaskOptions<TIdentifier, ScheduledTaskPayload, TOutput, TInitOutput>): Task<TIdentifier, ScheduledTaskPayload, TOutput>;
|
|
230
673
|
/**
|
|
231
|
-
*
|
|
232
|
-
* @param
|
|
233
|
-
* @
|
|
674
|
+
* Creates a new schedule
|
|
675
|
+
* @param options
|
|
676
|
+
* @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
|
|
677
|
+
* @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
|
|
678
|
+
* @param options.timezone - An optional timezone for the schedule in the IANA format (e.g. `America/Los_Angeles`). Defaults to "UTC".
|
|
679
|
+
* @param options.externalId - An optional external identifier for the schedule
|
|
680
|
+
* @param options.deduplicationKey - An optional deduplication key for the schedule
|
|
681
|
+
* @returns The created schedule
|
|
234
682
|
*/
|
|
235
|
-
declare function
|
|
683
|
+
declare function create$1(options: CreateScheduleOptions): ApiPromise<ScheduleObject>;
|
|
684
|
+
/**
|
|
685
|
+
* Retrieves a schedule
|
|
686
|
+
* @param scheduleId - The ID of the schedule to retrieve
|
|
687
|
+
* @returns The retrieved schedule
|
|
688
|
+
*/
|
|
689
|
+
declare function retrieve$1(scheduleId: string): ApiPromise<ScheduleObject>;
|
|
690
|
+
/**
|
|
691
|
+
* Updates a schedule
|
|
692
|
+
* @param scheduleId - The ID of the schedule to update
|
|
693
|
+
* @param options - The updated schedule options
|
|
694
|
+
* @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
|
|
695
|
+
* @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
|
|
696
|
+
* @param options.timezone - An optional timezone for the schedule in the IANA format (e.g. `America/Los_Angeles`). Defaults to "UTC".
|
|
697
|
+
* @param options.externalId - An optional external identifier for the schedule
|
|
698
|
+
* @returns The updated schedule
|
|
699
|
+
*/
|
|
700
|
+
declare function update$1(scheduleId: string, options: UpdateScheduleOptions): ApiPromise<ScheduleObject>;
|
|
701
|
+
/**
|
|
702
|
+
* Deletes a schedule
|
|
703
|
+
* @param scheduleId - The ID of the schedule to delete
|
|
704
|
+
*/
|
|
705
|
+
declare function del$1(scheduleId: string): ApiPromise<DeletedScheduleObject>;
|
|
706
|
+
/**
|
|
707
|
+
* Deactivates a schedule
|
|
708
|
+
* @param scheduleId - The ID of the schedule to deactivate
|
|
709
|
+
*/
|
|
710
|
+
declare function deactivate(scheduleId: string): ApiPromise<ScheduleObject>;
|
|
711
|
+
/**
|
|
712
|
+
* Activates a schedule
|
|
713
|
+
* @param scheduleId - The ID of the schedule to activate
|
|
714
|
+
*/
|
|
715
|
+
declare function activate(scheduleId: string): ApiPromise<ScheduleObject>;
|
|
716
|
+
/**
|
|
717
|
+
* Lists schedules
|
|
718
|
+
* @param options - The list options
|
|
719
|
+
* @param options.page - The page number
|
|
720
|
+
* @param options.perPage - The number of schedules per page
|
|
721
|
+
* @returns The list of schedules
|
|
722
|
+
*/
|
|
723
|
+
declare function list$1(options?: ListScheduleOptions): OffsetLimitPagePromise<typeof ScheduleObject>;
|
|
724
|
+
/**
|
|
725
|
+
* Lists the possible timezones we support
|
|
726
|
+
* @param excludeUtc - By default "UTC" is included and is first. If true, "UTC" will be excluded.
|
|
727
|
+
*/
|
|
728
|
+
declare function timezones(options?: {
|
|
729
|
+
excludeUtc?: boolean;
|
|
730
|
+
}): ApiPromise<{
|
|
731
|
+
timezones: string[];
|
|
732
|
+
}>;
|
|
236
733
|
|
|
237
|
-
declare
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
timeoutInMs?: number;
|
|
734
|
+
declare const index_activate: typeof activate;
|
|
735
|
+
declare const index_deactivate: typeof deactivate;
|
|
736
|
+
declare const index_task: typeof task;
|
|
737
|
+
declare const index_timezones: typeof timezones;
|
|
738
|
+
declare namespace index {
|
|
739
|
+
export { index_activate as activate, create$1 as create, index_deactivate as deactivate, del$1 as del, list$1 as list, retrieve$1 as retrieve, index_task as task, index_timezones as timezones, update$1 as update };
|
|
244
740
|
}
|
|
245
|
-
declare function retryFetch(input: RequestInfo | URL, init?: RetryFetchRequestInit | undefined): Promise<Response>;
|
|
246
|
-
declare const retry: {
|
|
247
|
-
onThrow: typeof onThrow;
|
|
248
|
-
fetch: typeof retryFetch;
|
|
249
|
-
interceptFetch: (...handlers: Array<HttpHandler>) => {
|
|
250
|
-
run: <T>(fn: (...args: any[]) => Promise<T>) => Promise<T>;
|
|
251
|
-
};
|
|
252
|
-
};
|
|
253
741
|
|
|
254
|
-
|
|
742
|
+
declare function upload(projectRef: string, slug: string, params: ImportEnvironmentVariablesParams): ApiPromise<EnvironmentVariableResponseBody>;
|
|
743
|
+
declare function upload(params: ImportEnvironmentVariablesParams): ApiPromise<EnvironmentVariableResponseBody>;
|
|
744
|
+
declare function list(projectRef: string, slug: string): ApiPromise<EnvironmentVariables>;
|
|
745
|
+
declare function list(): ApiPromise<EnvironmentVariables>;
|
|
746
|
+
declare function create(projectRef: string, slug: string, params: CreateEnvironmentVariableParams): ApiPromise<EnvironmentVariableResponseBody>;
|
|
747
|
+
declare function create(params: CreateEnvironmentVariableParams): ApiPromise<EnvironmentVariableResponseBody>;
|
|
748
|
+
declare function retrieve(projectRef: string, slug: string, name: string): ApiPromise<EnvironmentVariableValue>;
|
|
749
|
+
declare function retrieve(name: string): ApiPromise<EnvironmentVariableValue>;
|
|
750
|
+
declare function del(projectRef: string, slug: string, name: string): ApiPromise<EnvironmentVariableResponseBody>;
|
|
751
|
+
declare function del(name: string): ApiPromise<EnvironmentVariableResponseBody>;
|
|
752
|
+
declare function update(projectRef: string, slug: string, name: string, params: UpdateEnvironmentVariableParams): ApiPromise<EnvironmentVariableResponseBody>;
|
|
753
|
+
declare function update(name: string, params: UpdateEnvironmentVariableParams): ApiPromise<EnvironmentVariableResponseBody>;
|
|
754
|
+
|
|
755
|
+
declare const envvars_CreateEnvironmentVariableParams: typeof CreateEnvironmentVariableParams;
|
|
756
|
+
declare const envvars_ImportEnvironmentVariablesParams: typeof ImportEnvironmentVariablesParams;
|
|
757
|
+
declare const envvars_create: typeof create;
|
|
758
|
+
declare const envvars_del: typeof del;
|
|
759
|
+
declare const envvars_list: typeof list;
|
|
760
|
+
declare const envvars_retrieve: typeof retrieve;
|
|
761
|
+
declare const envvars_update: typeof update;
|
|
762
|
+
declare const envvars_upload: typeof upload;
|
|
763
|
+
declare namespace envvars {
|
|
764
|
+
export { envvars_CreateEnvironmentVariableParams as CreateEnvironmentVariableParams, envvars_ImportEnvironmentVariablesParams as ImportEnvironmentVariablesParams, envvars_create as create, envvars_del as del, envvars_list as list, envvars_retrieve as retrieve, envvars_update as update, envvars_upload as upload };
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Register the global API client configuration. Alternatively, you can set the `TRIGGER_SECRET_KEY` and `TRIGGER_API_URL` environment variables.
|
|
769
|
+
* @param options The API client configuration.
|
|
770
|
+
* @param options.baseURL The base URL of the Trigger API. (default: `https://api.trigger.dev`)
|
|
771
|
+
* @param options.secretKey The secret key to authenticate with the Trigger API. (default: `process.env.TRIGGER_SECRET_KEY`) This can be found in your Trigger.dev project "API Keys" settings.
|
|
772
|
+
*
|
|
773
|
+
* @example
|
|
774
|
+
*
|
|
775
|
+
* ```typescript
|
|
776
|
+
* import { configure } from "@trigger.dev/sdk/v3";
|
|
777
|
+
*
|
|
778
|
+
* configure({
|
|
779
|
+
* baseURL: "https://api.trigger.dev",
|
|
780
|
+
* secretKey: "tr_dev_1234567890"
|
|
781
|
+
* });
|
|
782
|
+
* ```
|
|
783
|
+
*/
|
|
784
|
+
declare function configure(options: ApiClientConfiguration): void;
|
|
785
|
+
|
|
786
|
+
export { type BatchItem, type BatchResult, type BatchRunHandle, type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type ComputeUsage, type Context, type CurrentUsage, type Eventually, InMemoryCache, type Queue, type RunHandle, type Task, type TaskIdentifier, type TaskOptions, type TaskOutput, type TaskPayload, type TaskRunOptions, type TaskRunResult, type WaitOptions, configure, createCache, envvars, queue, retry, runs, index as schedules, task$1 as task, tasks, usage, wait };
|