@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.
package/dist/v3/index.mjs CHANGED
@@ -1,8 +1,9 @@
1
- import { TriggerTracer, SemanticInternalAttributes, runtime, accessoryAttributes, usage as usage$1, taskContext, apiClientManager, taskCatalog, TimezonesResult, defaultRetryOptions, calculateNextRetryDelay, defaultFetchRetryOptions, calculateResetAt, eventFilterMatches, flattenAttributes, stringifyIO, logger, conditionallyImportPacket, parsePacket, createErrorTaskError } from '@trigger.dev/core/v3';
1
+ import { TriggerTracer, SemanticInternalAttributes, apiClientManager, runtime, accessoryAttributes, usage as usage$1, taskContext, taskCatalog, TimezonesResult, defaultRetryOptions, calculateNextRetryDelay, defaultFetchRetryOptions, calculateResetAt, eventFilterMatches, flattenAttributes, stringifyIO, logger, conditionallyImportPacket, parsePacket, createErrorTaskError } from '@trigger.dev/core/v3';
2
2
  export { ApiError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError, logger } from '@trigger.dev/core/v3';
3
3
  import { trace, context, SpanStatusCode, SpanKind } from '@opentelemetry/api';
4
4
  import { SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_URL, SEMATTRS_HTTP_HOST, SEMATTRS_HTTP_SCHEME, SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH, SEMATTRS_MESSAGING_OPERATION, SEMATTRS_MESSAGING_DESTINATION, SEMATTRS_MESSAGING_SYSTEM } from '@opentelemetry/semantic-conventions';
5
5
  import { AsyncLocalStorage } from 'node:async_hooks';
6
+ import { setTimeout as setTimeout$1 } from 'timers/promises';
6
7
  import { zodfetch } from '@trigger.dev/core/v3/zodfetch';
7
8
 
8
9
  var __defProp = Object.defineProperty;
@@ -18,7 +19,7 @@ var __publicField = (obj, key, value) => {
18
19
  };
19
20
 
20
21
  // package.json
21
- var version = "3.0.0-beta.40";
22
+ var version = "3.0.0-beta.41";
22
23
 
23
24
  // src/v3/tracer.ts
24
25
  var tracer = new TriggerTracer({
@@ -501,6 +502,64 @@ var retry = {
501
502
  fetch: retryFetch,
502
503
  interceptFetch
503
504
  };
505
+ var runs = {
506
+ replay: replayRun,
507
+ cancel: cancelRun,
508
+ retrieve: retrieveRun,
509
+ list: listRuns,
510
+ poll
511
+ };
512
+ function listRuns(paramsOrProjectRef, params) {
513
+ const apiClient = apiClientManager.client;
514
+ if (!apiClient) {
515
+ throw apiClientMissingError();
516
+ }
517
+ if (typeof paramsOrProjectRef === "string") {
518
+ return apiClient.listProjectRuns(paramsOrProjectRef, params);
519
+ }
520
+ return apiClient.listRuns(params);
521
+ }
522
+ __name(listRuns, "listRuns");
523
+ function retrieveRun(runId) {
524
+ const apiClient = apiClientManager.client;
525
+ if (!apiClient) {
526
+ throw apiClientMissingError();
527
+ }
528
+ if (typeof runId === "string") {
529
+ return apiClient.retrieveRun(runId);
530
+ } else {
531
+ return apiClient.retrieveRun(runId.id);
532
+ }
533
+ }
534
+ __name(retrieveRun, "retrieveRun");
535
+ function replayRun(runId) {
536
+ const apiClient = apiClientManager.client;
537
+ if (!apiClient) {
538
+ throw apiClientMissingError();
539
+ }
540
+ return apiClient.replayRun(runId);
541
+ }
542
+ __name(replayRun, "replayRun");
543
+ function cancelRun(runId) {
544
+ const apiClient = apiClientManager.client;
545
+ if (!apiClient) {
546
+ throw apiClientMissingError();
547
+ }
548
+ return apiClient.cancelRun(runId);
549
+ }
550
+ __name(cancelRun, "cancelRun");
551
+ async function poll(handle, options) {
552
+ while (true) {
553
+ const run = await runs.retrieve(handle);
554
+ if (run.isCompleted) {
555
+ return run;
556
+ }
557
+ await setTimeout$1(Math.max(options?.pollIntervalMs ?? 5e3, 1e3));
558
+ }
559
+ }
560
+ __name(poll, "poll");
561
+
562
+ // src/v3/shared.ts
504
563
  function queue(options) {
505
564
  return options;
506
565
  }
@@ -576,7 +635,13 @@ function createTask(params) {
576
635
  spanParentAsLink: true
577
636
  });
578
637
  span.setAttribute("messaging.message.id", response2.batchId);
579
- return response2;
638
+ const handle = {
639
+ batchId: response2.batchId,
640
+ runs: response2.runs.map((id) => ({
641
+ id
642
+ }))
643
+ };
644
+ return handle;
580
645
  }, {
581
646
  kind: SpanKind.PRODUCER,
582
647
  attributes: {
@@ -778,6 +843,59 @@ function createTask(params) {
778
843
  return task3;
779
844
  }
780
845
  __name(createTask, "createTask");
846
+ async function trigger(id, payload, options) {
847
+ const apiClient = apiClientManager.client;
848
+ if (!apiClient) {
849
+ throw apiClientMissingError();
850
+ }
851
+ const payloadPacket = await stringifyIO(payload);
852
+ const handle = await apiClient.triggerTask(id, {
853
+ payload: payloadPacket.data,
854
+ options: {
855
+ queue: options?.queue,
856
+ concurrencyKey: options?.concurrencyKey,
857
+ test: taskContext.ctx?.run.isTest,
858
+ payloadType: payloadPacket.dataType,
859
+ idempotencyKey: options?.idempotencyKey
860
+ }
861
+ });
862
+ return handle;
863
+ }
864
+ __name(trigger, "trigger");
865
+ async function triggerAndPoll(id, payload, options) {
866
+ const handle = await trigger(id, payload, options);
867
+ return runs.poll(handle);
868
+ }
869
+ __name(triggerAndPoll, "triggerAndPoll");
870
+ async function batchTrigger(id, items) {
871
+ const apiClient = apiClientManager.client;
872
+ if (!apiClient) {
873
+ throw apiClientMissingError();
874
+ }
875
+ const response = await apiClient.batchTriggerTask(id, {
876
+ items: await Promise.all(items.map(async (item) => {
877
+ const payloadPacket = await stringifyIO(item.payload);
878
+ return {
879
+ payload: payloadPacket.data,
880
+ options: {
881
+ queue: item.options?.queue,
882
+ concurrencyKey: item.options?.concurrencyKey,
883
+ test: taskContext.ctx?.run.isTest,
884
+ payloadType: payloadPacket.dataType,
885
+ idempotencyKey: item.options?.idempotencyKey
886
+ }
887
+ };
888
+ }))
889
+ });
890
+ const handle = {
891
+ batchId: response.batchId,
892
+ runs: response.runs.map((id2) => ({
893
+ id: id2
894
+ }))
895
+ };
896
+ return handle;
897
+ }
898
+ __name(batchTrigger, "batchTrigger");
781
899
  async function handleBatchTaskRunExecutionResult(items) {
782
900
  const someObjectStoreOutputs = items.some((item) => item.ok && item.outputType === "application/store");
783
901
  if (!someObjectStoreOutputs) {
@@ -837,6 +955,11 @@ function task(options) {
837
955
  return createTask(options);
838
956
  }
839
957
  __name(task, "task");
958
+ var tasks = {
959
+ trigger,
960
+ triggerAndPoll,
961
+ batchTrigger
962
+ };
840
963
  var wait = {
841
964
  for: async (options) => {
842
965
  return tracer.startActiveSpan(`wait.for()`, async (span) => {
@@ -1041,47 +1164,6 @@ var usage = {
1041
1164
  };
1042
1165
  }
1043
1166
  };
1044
- var runs = {
1045
- replay: replayRun,
1046
- cancel: cancelRun,
1047
- retrieve: retrieveRun,
1048
- list: listRuns
1049
- };
1050
- function listRuns(paramsOrProjectRef, params) {
1051
- const apiClient = apiClientManager.client;
1052
- if (!apiClient) {
1053
- throw apiClientMissingError();
1054
- }
1055
- if (typeof paramsOrProjectRef === "string") {
1056
- return apiClient.listProjectRuns(paramsOrProjectRef, params);
1057
- }
1058
- return apiClient.listRuns(params);
1059
- }
1060
- __name(listRuns, "listRuns");
1061
- function retrieveRun(runId) {
1062
- const apiClient = apiClientManager.client;
1063
- if (!apiClient) {
1064
- throw apiClientMissingError();
1065
- }
1066
- return apiClient.retrieveRun(runId);
1067
- }
1068
- __name(retrieveRun, "retrieveRun");
1069
- function replayRun(runId) {
1070
- const apiClient = apiClientManager.client;
1071
- if (!apiClient) {
1072
- throw apiClientMissingError();
1073
- }
1074
- return apiClient.replayRun(runId);
1075
- }
1076
- __name(replayRun, "replayRun");
1077
- function cancelRun(runId) {
1078
- const apiClient = apiClientManager.client;
1079
- if (!apiClient) {
1080
- throw apiClientMissingError();
1081
- }
1082
- return apiClient.cancelRun(runId);
1083
- }
1084
- __name(cancelRun, "cancelRun");
1085
1167
 
1086
1168
  // src/v3/schedules/index.ts
1087
1169
  var schedules_exports = {};
@@ -1377,6 +1459,6 @@ function configure(options) {
1377
1459
  }
1378
1460
  __name(configure, "configure");
1379
1461
 
1380
- export { InMemoryCache, configure, createCache, envvars_exports as envvars, queue, retry, runs, schedules_exports as schedules, task, usage, wait };
1462
+ export { InMemoryCache, configure, createCache, envvars_exports as envvars, queue, retry, runs, schedules_exports as schedules, task, tasks, usage, wait };
1381
1463
  //# sourceMappingURL=out.js.map
1382
1464
  //# sourceMappingURL=index.mjs.map