@trigger.dev/sdk 3.0.0-beta.40 → 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.
@@ -1,4 +1,4 @@
1
- import { RetryOptions, FetchRetryOptions, TaskRunContext, QueueOptions, InitOutput, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, StartFnParams, SuccessFnParams, FailureFnParams, ListProjectRunsQueryParams, CursorPagePromise, ListRunResponseItem, ListRunsQueryParams, ApiPromise, ReplayRunResponse, CanceledRunResponse, RetrieveRunResponse, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, OffsetLimitPagePromise, ImportEnvironmentVariablesParams, EnvironmentVariableResponseBody, EnvironmentVariables, CreateEnvironmentVariableParams, EnvironmentVariableValue, UpdateEnvironmentVariableParams, ApiClientConfiguration } 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
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
 
@@ -48,6 +48,206 @@ declare const retry: {
48
48
  };
49
49
  };
50
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
+
51
251
  type Context = TaskRunContext;
52
252
  type RequireOne<T, K extends keyof T> = {
53
253
  [X in Exclude<keyof T, K>]?: T[X];
@@ -58,9 +258,9 @@ type Queue = RequireOne<QueueOptions, "name">;
58
258
  declare function queue(options: {
59
259
  name: string;
60
260
  } & QueueOptions): Queue;
61
- type TaskOptions<TPayload = void, TOutput = unknown, TInitOutput extends InitOutput = any> = {
261
+ type TaskOptions<TIdentifier extends string, TPayload = void, TOutput = unknown, TInitOutput extends InitOutput = any> = {
62
262
  /** An id for your task. This must be unique inside your project and not change between versions. */
63
- id: string;
263
+ id: TIdentifier;
64
264
  /** The retry settings when an uncaught error is thrown.
65
265
  *
66
266
  * If omitted it will use the values in your `trigger.config.ts` file.
@@ -195,13 +395,21 @@ type TaskOptions<TPayload = void, TOutput = unknown, TInitOutput extends InitOut
195
395
  */
196
396
  onFailure?: (payload: TPayload, error: unknown, params: FailureFnParams<TInitOutput>) => Promise<void>;
197
397
  };
198
- type InvokeHandle = {
199
- id: string;
398
+ declare const __output: unique symbol;
399
+ type BrandOutput<B> = {
400
+ [__output]: B;
200
401
  };
201
- type InvokeBatchHandle = {
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<{
202
410
  batchId: string;
203
- runs: string[];
204
- };
411
+ runs: Array<RunHandle<TOutput>>;
412
+ }, TOutput>;
205
413
  type TaskRunResult<TOutput = any> = {
206
414
  ok: true;
207
415
  id: string;
@@ -222,19 +430,19 @@ type BatchItem<TInput> = TInput extends void ? {
222
430
  payload: TInput;
223
431
  options?: TaskRunOptions;
224
432
  };
225
- interface Task<TInput = void, TOutput = any> {
433
+ interface Task<TIdentifier extends string, TInput = void, TOutput = any> {
226
434
  /**
227
435
  * The id of the task.
228
436
  */
229
- id: string;
437
+ id: TIdentifier;
230
438
  /**
231
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.
232
440
  * @param payload
233
441
  * @param options
234
- * @returns InvokeHandle
442
+ * @returns RunHandle
235
443
  * - `id` - The id of the triggered task run.
236
444
  */
237
- trigger: (payload: TInput, options?: TaskRunOptions) => Promise<InvokeHandle>;
445
+ trigger: (payload: TInput, options?: TaskRunOptions) => Promise<RunHandle<TOutput>>;
238
446
  /**
239
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.
240
448
  * @param items
@@ -242,7 +450,7 @@ interface Task<TInput = void, TOutput = any> {
242
450
  * - `batchId` - The id of the triggered batch.
243
451
  * - `runs` - The ids of the triggered task runs.
244
452
  */
245
- batchTrigger: (items: Array<BatchItem<TInput>>) => Promise<InvokeBatchHandle>;
453
+ batchTrigger: (items: Array<BatchItem<TInput>>) => Promise<BatchRunHandle<TOutput>>;
246
454
  /**
247
455
  * Trigger a task with the given payload, and wait for the result. Returns the result of the task run
248
456
  * @param payload
@@ -282,6 +490,12 @@ interface Task<TInput = void, TOutput = any> {
282
490
  */
283
491
  batchTriggerAndWait: (items: Array<BatchItem<TInput>>) => Promise<BatchResult<TOutput>>;
284
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;
285
499
  type TaskRunOptions = {
286
500
  idempotencyKey?: string;
287
501
  maxAttempts?: number;
@@ -291,6 +505,43 @@ type TaskRunOptions = {
291
505
  concurrencyKey?: string;
292
506
  };
293
507
  type TaskRunConcurrencyOptions = Queue;
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>>;
294
545
 
295
546
  /** Creates a task that can be triggered
296
547
  * @param options - Task options
@@ -310,7 +561,12 @@ type TaskRunConcurrencyOptions = Queue;
310
561
  *
311
562
  * @returns A task that can be triggered
312
563
  */
313
- declare function task$1<TInput = void, TOutput = unknown, TInitOutput extends InitOutput = any>(options: TaskOptions<TInput, TOutput, TInitOutput>): 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
+ };
314
570
 
315
571
  type WaitOptions = {
316
572
  seconds: number;
@@ -413,20 +669,7 @@ declare const usage: {
413
669
  }>;
414
670
  };
415
671
 
416
- type RetrieveRunResult = RetrieveRunResponse;
417
- declare const runs: {
418
- replay: typeof replayRun;
419
- cancel: typeof cancelRun;
420
- retrieve: typeof retrieveRun;
421
- list: typeof listRuns;
422
- };
423
- declare function listRuns(projectRef: string, params?: ListProjectRunsQueryParams): CursorPagePromise<typeof ListRunResponseItem>;
424
- declare function listRuns(params?: ListRunsQueryParams): CursorPagePromise<typeof ListRunResponseItem>;
425
- declare function retrieveRun(runId: string): ApiPromise<RetrieveRunResult>;
426
- declare function replayRun(runId: string): ApiPromise<ReplayRunResponse>;
427
- declare function cancelRun(runId: string): ApiPromise<CanceledRunResponse>;
428
-
429
- declare function task<TOutput, TInitOutput extends InitOutput>(params: TaskOptions<ScheduledTaskPayload, TOutput, TInitOutput>): Task<ScheduledTaskPayload, TOutput>;
672
+ declare function task<TIdentifier extends string, TOutput, TInitOutput extends InitOutput>(params: TaskOptions<TIdentifier, ScheduledTaskPayload, TOutput, TInitOutput>): Task<TIdentifier, ScheduledTaskPayload, TOutput>;
430
673
  /**
431
674
  * Creates a new schedule
432
675
  * @param options
@@ -540,4 +783,4 @@ declare namespace envvars {
540
783
  */
541
784
  declare function configure(options: ApiClientConfiguration): void;
542
785
 
543
- export { type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type ComputeUsage, type Context, type CurrentUsage, type Eventually, InMemoryCache, type Task, type TaskOptions, type WaitOptions, configure, createCache, envvars, queue, retry, runs, index as schedules, task$1 as task, usage, wait };
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 };
package/dist/v3/index.js CHANGED
@@ -4,6 +4,7 @@ var v3 = require('@trigger.dev/core/v3');
4
4
  var api = require('@opentelemetry/api');
5
5
  var semanticConventions = require('@opentelemetry/semantic-conventions');
6
6
  var node_async_hooks = require('node:async_hooks');
7
+ var promises = require('timers/promises');
7
8
  var zodfetch = require('@trigger.dev/core/v3/zodfetch');
8
9
 
9
10
  var __defProp = Object.defineProperty;
@@ -19,7 +20,7 @@ var __publicField = (obj, key, value) => {
19
20
  };
20
21
 
21
22
  // package.json
22
- var version = "3.0.0-beta.40";
23
+ var version = "3.0.0-beta.41";
23
24
 
24
25
  // src/v3/tracer.ts
25
26
  var tracer = new v3.TriggerTracer({
@@ -502,6 +503,64 @@ var retry = {
502
503
  fetch: retryFetch,
503
504
  interceptFetch
504
505
  };
506
+ var runs = {
507
+ replay: replayRun,
508
+ cancel: cancelRun,
509
+ retrieve: retrieveRun,
510
+ list: listRuns,
511
+ poll
512
+ };
513
+ function listRuns(paramsOrProjectRef, params) {
514
+ const apiClient = v3.apiClientManager.client;
515
+ if (!apiClient) {
516
+ throw apiClientMissingError();
517
+ }
518
+ if (typeof paramsOrProjectRef === "string") {
519
+ return apiClient.listProjectRuns(paramsOrProjectRef, params);
520
+ }
521
+ return apiClient.listRuns(params);
522
+ }
523
+ __name(listRuns, "listRuns");
524
+ function retrieveRun(runId) {
525
+ const apiClient = v3.apiClientManager.client;
526
+ if (!apiClient) {
527
+ throw apiClientMissingError();
528
+ }
529
+ if (typeof runId === "string") {
530
+ return apiClient.retrieveRun(runId);
531
+ } else {
532
+ return apiClient.retrieveRun(runId.id);
533
+ }
534
+ }
535
+ __name(retrieveRun, "retrieveRun");
536
+ function replayRun(runId) {
537
+ const apiClient = v3.apiClientManager.client;
538
+ if (!apiClient) {
539
+ throw apiClientMissingError();
540
+ }
541
+ return apiClient.replayRun(runId);
542
+ }
543
+ __name(replayRun, "replayRun");
544
+ function cancelRun(runId) {
545
+ const apiClient = v3.apiClientManager.client;
546
+ if (!apiClient) {
547
+ throw apiClientMissingError();
548
+ }
549
+ return apiClient.cancelRun(runId);
550
+ }
551
+ __name(cancelRun, "cancelRun");
552
+ async function poll(handle, options) {
553
+ while (true) {
554
+ const run = await runs.retrieve(handle);
555
+ if (run.isCompleted) {
556
+ return run;
557
+ }
558
+ await promises.setTimeout(Math.max(options?.pollIntervalMs ?? 5e3, 1e3));
559
+ }
560
+ }
561
+ __name(poll, "poll");
562
+
563
+ // src/v3/shared.ts
505
564
  function queue(options) {
506
565
  return options;
507
566
  }
@@ -577,7 +636,13 @@ function createTask(params) {
577
636
  spanParentAsLink: true
578
637
  });
579
638
  span.setAttribute("messaging.message.id", response2.batchId);
580
- return response2;
639
+ const handle = {
640
+ batchId: response2.batchId,
641
+ runs: response2.runs.map((id) => ({
642
+ id
643
+ }))
644
+ };
645
+ return handle;
581
646
  }, {
582
647
  kind: api.SpanKind.PRODUCER,
583
648
  attributes: {
@@ -779,6 +844,59 @@ function createTask(params) {
779
844
  return task3;
780
845
  }
781
846
  __name(createTask, "createTask");
847
+ async function trigger(id, payload, options) {
848
+ const apiClient = v3.apiClientManager.client;
849
+ if (!apiClient) {
850
+ throw apiClientMissingError();
851
+ }
852
+ const payloadPacket = await v3.stringifyIO(payload);
853
+ const handle = await apiClient.triggerTask(id, {
854
+ payload: payloadPacket.data,
855
+ options: {
856
+ queue: options?.queue,
857
+ concurrencyKey: options?.concurrencyKey,
858
+ test: v3.taskContext.ctx?.run.isTest,
859
+ payloadType: payloadPacket.dataType,
860
+ idempotencyKey: options?.idempotencyKey
861
+ }
862
+ });
863
+ return handle;
864
+ }
865
+ __name(trigger, "trigger");
866
+ async function triggerAndPoll(id, payload, options) {
867
+ const handle = await trigger(id, payload, options);
868
+ return runs.poll(handle);
869
+ }
870
+ __name(triggerAndPoll, "triggerAndPoll");
871
+ async function batchTrigger(id, items) {
872
+ const apiClient = v3.apiClientManager.client;
873
+ if (!apiClient) {
874
+ throw apiClientMissingError();
875
+ }
876
+ const response = await apiClient.batchTriggerTask(id, {
877
+ items: await Promise.all(items.map(async (item) => {
878
+ const payloadPacket = await v3.stringifyIO(item.payload);
879
+ return {
880
+ payload: payloadPacket.data,
881
+ options: {
882
+ queue: item.options?.queue,
883
+ concurrencyKey: item.options?.concurrencyKey,
884
+ test: v3.taskContext.ctx?.run.isTest,
885
+ payloadType: payloadPacket.dataType,
886
+ idempotencyKey: item.options?.idempotencyKey
887
+ }
888
+ };
889
+ }))
890
+ });
891
+ const handle = {
892
+ batchId: response.batchId,
893
+ runs: response.runs.map((id2) => ({
894
+ id: id2
895
+ }))
896
+ };
897
+ return handle;
898
+ }
899
+ __name(batchTrigger, "batchTrigger");
782
900
  async function handleBatchTaskRunExecutionResult(items) {
783
901
  const someObjectStoreOutputs = items.some((item) => item.ok && item.outputType === "application/store");
784
902
  if (!someObjectStoreOutputs) {
@@ -838,6 +956,11 @@ function task(options) {
838
956
  return createTask(options);
839
957
  }
840
958
  __name(task, "task");
959
+ var tasks = {
960
+ trigger,
961
+ triggerAndPoll,
962
+ batchTrigger
963
+ };
841
964
  var wait = {
842
965
  for: async (options) => {
843
966
  return tracer.startActiveSpan(`wait.for()`, async (span) => {
@@ -1042,47 +1165,6 @@ var usage = {
1042
1165
  };
1043
1166
  }
1044
1167
  };
1045
- var runs = {
1046
- replay: replayRun,
1047
- cancel: cancelRun,
1048
- retrieve: retrieveRun,
1049
- list: listRuns
1050
- };
1051
- function listRuns(paramsOrProjectRef, params) {
1052
- const apiClient = v3.apiClientManager.client;
1053
- if (!apiClient) {
1054
- throw apiClientMissingError();
1055
- }
1056
- if (typeof paramsOrProjectRef === "string") {
1057
- return apiClient.listProjectRuns(paramsOrProjectRef, params);
1058
- }
1059
- return apiClient.listRuns(params);
1060
- }
1061
- __name(listRuns, "listRuns");
1062
- function retrieveRun(runId) {
1063
- const apiClient = v3.apiClientManager.client;
1064
- if (!apiClient) {
1065
- throw apiClientMissingError();
1066
- }
1067
- return apiClient.retrieveRun(runId);
1068
- }
1069
- __name(retrieveRun, "retrieveRun");
1070
- function replayRun(runId) {
1071
- const apiClient = v3.apiClientManager.client;
1072
- if (!apiClient) {
1073
- throw apiClientMissingError();
1074
- }
1075
- return apiClient.replayRun(runId);
1076
- }
1077
- __name(replayRun, "replayRun");
1078
- function cancelRun(runId) {
1079
- const apiClient = v3.apiClientManager.client;
1080
- if (!apiClient) {
1081
- throw apiClientMissingError();
1082
- }
1083
- return apiClient.cancelRun(runId);
1084
- }
1085
- __name(cancelRun, "cancelRun");
1086
1168
 
1087
1169
  // src/v3/schedules/index.ts
1088
1170
  var schedules_exports = {};
@@ -1378,43 +1460,43 @@ function configure(options) {
1378
1460
  }
1379
1461
  __name(configure, "configure");
1380
1462
 
1381
- Object.defineProperty(exports, 'ApiError', {
1463
+ Object.defineProperty(exports, "ApiError", {
1382
1464
  enumerable: true,
1383
1465
  get: function () { return v3.ApiError; }
1384
1466
  });
1385
- Object.defineProperty(exports, 'AuthenticationError', {
1467
+ Object.defineProperty(exports, "AuthenticationError", {
1386
1468
  enumerable: true,
1387
1469
  get: function () { return v3.AuthenticationError; }
1388
1470
  });
1389
- Object.defineProperty(exports, 'BadRequestError', {
1471
+ Object.defineProperty(exports, "BadRequestError", {
1390
1472
  enumerable: true,
1391
1473
  get: function () { return v3.BadRequestError; }
1392
1474
  });
1393
- Object.defineProperty(exports, 'ConflictError', {
1475
+ Object.defineProperty(exports, "ConflictError", {
1394
1476
  enumerable: true,
1395
1477
  get: function () { return v3.ConflictError; }
1396
1478
  });
1397
- Object.defineProperty(exports, 'InternalServerError', {
1479
+ Object.defineProperty(exports, "InternalServerError", {
1398
1480
  enumerable: true,
1399
1481
  get: function () { return v3.InternalServerError; }
1400
1482
  });
1401
- Object.defineProperty(exports, 'NotFoundError', {
1483
+ Object.defineProperty(exports, "NotFoundError", {
1402
1484
  enumerable: true,
1403
1485
  get: function () { return v3.NotFoundError; }
1404
1486
  });
1405
- Object.defineProperty(exports, 'PermissionDeniedError', {
1487
+ Object.defineProperty(exports, "PermissionDeniedError", {
1406
1488
  enumerable: true,
1407
1489
  get: function () { return v3.PermissionDeniedError; }
1408
1490
  });
1409
- Object.defineProperty(exports, 'RateLimitError', {
1491
+ Object.defineProperty(exports, "RateLimitError", {
1410
1492
  enumerable: true,
1411
1493
  get: function () { return v3.RateLimitError; }
1412
1494
  });
1413
- Object.defineProperty(exports, 'UnprocessableEntityError', {
1495
+ Object.defineProperty(exports, "UnprocessableEntityError", {
1414
1496
  enumerable: true,
1415
1497
  get: function () { return v3.UnprocessableEntityError; }
1416
1498
  });
1417
- Object.defineProperty(exports, 'logger', {
1499
+ Object.defineProperty(exports, "logger", {
1418
1500
  enumerable: true,
1419
1501
  get: function () { return v3.logger; }
1420
1502
  });
@@ -1427,6 +1509,7 @@ exports.retry = retry;
1427
1509
  exports.runs = runs;
1428
1510
  exports.schedules = schedules_exports;
1429
1511
  exports.task = task;
1512
+ exports.tasks = tasks;
1430
1513
  exports.usage = usage;
1431
1514
  exports.wait = wait;
1432
1515
  //# sourceMappingURL=out.js.map