@trigger.dev/core 3.0.0-beta.2 → 3.0.0-beta.3
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.d.mts +300 -236
- package/dist/v3/index.d.ts +300 -236
- package/dist/v3/index.js +133 -21
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +129 -22
- package/dist/v3/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/v3/index.js
CHANGED
|
@@ -442,7 +442,7 @@ var QueueOptions = zod.z.object({
|
|
|
442
442
|
/** An optional property that specifies the maximum number of concurrent run executions.
|
|
443
443
|
*
|
|
444
444
|
* If this property is omitted, the task can potentially use up the full concurrency of an environment. */
|
|
445
|
-
concurrencyLimit: zod.z.number().int().min(
|
|
445
|
+
concurrencyLimit: zod.z.number().int().min(0).max(1e3).optional(),
|
|
446
446
|
/** @deprecated This feature is coming soon */
|
|
447
447
|
rateLimit: RateLimitOptions.optional()
|
|
448
448
|
});
|
|
@@ -469,6 +469,13 @@ var UncaughtExceptionMessage = zod.z.object({
|
|
|
469
469
|
"unhandledRejection"
|
|
470
470
|
])
|
|
471
471
|
});
|
|
472
|
+
var TaskMetadataFailedToParseData = zod.z.object({
|
|
473
|
+
version: zod.z.literal("v1").default("v1"),
|
|
474
|
+
tasks: zod.z.unknown(),
|
|
475
|
+
zodIssues: zod.z.custom((v) => {
|
|
476
|
+
return Array.isArray(v) && v.every((issue) => typeof issue === "object" && "message" in issue);
|
|
477
|
+
})
|
|
478
|
+
});
|
|
472
479
|
var childToWorkerMessages = {
|
|
473
480
|
TASK_RUN_COMPLETED: zod.z.object({
|
|
474
481
|
version: zod.z.literal("v1").default("v1"),
|
|
@@ -479,6 +486,7 @@ var childToWorkerMessages = {
|
|
|
479
486
|
version: zod.z.literal("v1").default("v1"),
|
|
480
487
|
tasks: TaskMetadataWithFilePath.array()
|
|
481
488
|
}),
|
|
489
|
+
TASKS_FAILED_TO_PARSE: TaskMetadataFailedToParseData,
|
|
482
490
|
TASK_HEARTBEAT: zod.z.object({
|
|
483
491
|
version: zod.z.literal("v1").default("v1"),
|
|
484
492
|
id: zod.z.string()
|
|
@@ -513,6 +521,9 @@ var ProdChildToWorkerMessages = {
|
|
|
513
521
|
tasks: TaskMetadataWithFilePath.array()
|
|
514
522
|
})
|
|
515
523
|
},
|
|
524
|
+
TASKS_FAILED_TO_PARSE: {
|
|
525
|
+
message: TaskMetadataFailedToParseData
|
|
526
|
+
},
|
|
516
527
|
TASK_HEARTBEAT: {
|
|
517
528
|
message: zod.z.object({
|
|
518
529
|
version: zod.z.literal("v1").default("v1"),
|
|
@@ -708,6 +719,11 @@ var InitializeDeploymentRequestBody = zod.z.object({
|
|
|
708
719
|
contentHash: zod.z.string(),
|
|
709
720
|
userId: zod.z.string().optional()
|
|
710
721
|
});
|
|
722
|
+
var DeploymentErrorData = zod.z.object({
|
|
723
|
+
name: zod.z.string(),
|
|
724
|
+
message: zod.z.string(),
|
|
725
|
+
stack: zod.z.string().optional()
|
|
726
|
+
});
|
|
711
727
|
var GetDeploymentResponseBody = zod.z.object({
|
|
712
728
|
id: zod.z.string(),
|
|
713
729
|
status: zod.z.enum([
|
|
@@ -723,11 +739,7 @@ var GetDeploymentResponseBody = zod.z.object({
|
|
|
723
739
|
shortCode: zod.z.string(),
|
|
724
740
|
version: zod.z.string(),
|
|
725
741
|
imageReference: zod.z.string().optional(),
|
|
726
|
-
errorData:
|
|
727
|
-
name: zod.z.string(),
|
|
728
|
-
message: zod.z.string(),
|
|
729
|
-
stack: zod.z.string().optional()
|
|
730
|
-
}).optional().nullable(),
|
|
742
|
+
errorData: DeploymentErrorData.optional().nullable(),
|
|
731
743
|
worker: zod.z.object({
|
|
732
744
|
id: zod.z.string(),
|
|
733
745
|
version: zod.z.string(),
|
|
@@ -772,7 +784,8 @@ var Config = zod.z.object({
|
|
|
772
784
|
dependenciesToBundle: zod.z.array(zod.z.union([
|
|
773
785
|
zod.z.string(),
|
|
774
786
|
RegexSchema
|
|
775
|
-
])).optional()
|
|
787
|
+
])).optional(),
|
|
788
|
+
logLevel: zod.z.string().optional()
|
|
776
789
|
});
|
|
777
790
|
var WaitReason = zod.z.enum([
|
|
778
791
|
"WAIT_FOR_DURATION",
|
|
@@ -1407,7 +1420,11 @@ var SpanMessagingEvent = zod.z.object({
|
|
|
1407
1420
|
});
|
|
1408
1421
|
|
|
1409
1422
|
// src/zodfetch.ts
|
|
1410
|
-
async function zodfetch(schema, url, requestInit) {
|
|
1423
|
+
async function zodfetch(schema, url, requestInit, options) {
|
|
1424
|
+
return await _doZodFetch(schema, url, requestInit, options);
|
|
1425
|
+
}
|
|
1426
|
+
__name(zodfetch, "zodfetch");
|
|
1427
|
+
async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
|
|
1411
1428
|
try {
|
|
1412
1429
|
const response = await fetch(url, requestInit);
|
|
1413
1430
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404) {
|
|
@@ -1416,7 +1433,7 @@ async function zodfetch(schema, url, requestInit) {
|
|
|
1416
1433
|
error: `404: ${response.statusText}`
|
|
1417
1434
|
};
|
|
1418
1435
|
}
|
|
1419
|
-
if (response.status >= 400 && response.status < 500) {
|
|
1436
|
+
if (response.status >= 400 && response.status < 500 && response.status !== 429) {
|
|
1420
1437
|
const body = await response.json();
|
|
1421
1438
|
if (!body.error) {
|
|
1422
1439
|
return {
|
|
@@ -1429,6 +1446,27 @@ async function zodfetch(schema, url, requestInit) {
|
|
|
1429
1446
|
error: body.error
|
|
1430
1447
|
};
|
|
1431
1448
|
}
|
|
1449
|
+
if (response.status === 429 || response.status >= 500) {
|
|
1450
|
+
if (!options?.retry) {
|
|
1451
|
+
return {
|
|
1452
|
+
ok: false,
|
|
1453
|
+
error: `Failed to fetch ${url}, got status code ${response.status}`
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
const retry = {
|
|
1457
|
+
...defaultRetryOptions,
|
|
1458
|
+
...options.retry
|
|
1459
|
+
};
|
|
1460
|
+
if (attempt > retry.maxAttempts) {
|
|
1461
|
+
return {
|
|
1462
|
+
ok: false,
|
|
1463
|
+
error: `Failed to fetch ${url}, got status code ${response.status}`
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
const delay = calculateNextRetryDelay(retry, attempt);
|
|
1467
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1468
|
+
return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
|
|
1469
|
+
}
|
|
1432
1470
|
if (response.status !== 200) {
|
|
1433
1471
|
return {
|
|
1434
1472
|
ok: false,
|
|
@@ -1454,13 +1492,28 @@ async function zodfetch(schema, url, requestInit) {
|
|
|
1454
1492
|
error: parsedResult.error.message
|
|
1455
1493
|
};
|
|
1456
1494
|
} catch (error) {
|
|
1495
|
+
if (options?.retry) {
|
|
1496
|
+
const retry = {
|
|
1497
|
+
...defaultRetryOptions,
|
|
1498
|
+
...options.retry
|
|
1499
|
+
};
|
|
1500
|
+
if (attempt > retry.maxAttempts) {
|
|
1501
|
+
return {
|
|
1502
|
+
ok: false,
|
|
1503
|
+
error: error instanceof Error ? error.message : JSON.stringify(error)
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
const delay = calculateNextRetryDelay(retry, attempt);
|
|
1507
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1508
|
+
return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
|
|
1509
|
+
}
|
|
1457
1510
|
return {
|
|
1458
1511
|
ok: false,
|
|
1459
1512
|
error: error instanceof Error ? error.message : JSON.stringify(error)
|
|
1460
1513
|
};
|
|
1461
1514
|
}
|
|
1462
1515
|
}
|
|
1463
|
-
__name(
|
|
1516
|
+
__name(_doZodFetch, "_doZodFetch");
|
|
1464
1517
|
|
|
1465
1518
|
// src/v3/utils/flattenAttributes.ts
|
|
1466
1519
|
function flattenAttributes(obj, prefix) {
|
|
@@ -1746,6 +1799,15 @@ function getEnvVar(name) {
|
|
|
1746
1799
|
__name(getEnvVar, "getEnvVar");
|
|
1747
1800
|
|
|
1748
1801
|
// src/v3/apiClient/index.ts
|
|
1802
|
+
var zodFetchOptions = {
|
|
1803
|
+
retry: {
|
|
1804
|
+
maxAttempts: 5,
|
|
1805
|
+
minTimeoutInMs: 1e3,
|
|
1806
|
+
maxTimeoutInMs: 3e4,
|
|
1807
|
+
factor: 2,
|
|
1808
|
+
randomize: false
|
|
1809
|
+
}
|
|
1810
|
+
};
|
|
1749
1811
|
var _getHeaders, getHeaders_fn;
|
|
1750
1812
|
var _ApiClient = class _ApiClient {
|
|
1751
1813
|
constructor(baseUrl, accessToken) {
|
|
@@ -1758,26 +1820,26 @@ var _ApiClient = class _ApiClient {
|
|
|
1758
1820
|
method: "POST",
|
|
1759
1821
|
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
|
|
1760
1822
|
body: JSON.stringify(body)
|
|
1761
|
-
});
|
|
1823
|
+
}, zodFetchOptions);
|
|
1762
1824
|
}
|
|
1763
1825
|
batchTriggerTask(taskId, body, options) {
|
|
1764
1826
|
return zodfetch(BatchTriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${taskId}/batch`, {
|
|
1765
1827
|
method: "POST",
|
|
1766
1828
|
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
|
|
1767
1829
|
body: JSON.stringify(body)
|
|
1768
|
-
});
|
|
1830
|
+
}, zodFetchOptions);
|
|
1769
1831
|
}
|
|
1770
1832
|
createUploadPayloadUrl(filename) {
|
|
1771
1833
|
return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
|
|
1772
1834
|
method: "PUT",
|
|
1773
1835
|
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1774
|
-
});
|
|
1836
|
+
}, zodFetchOptions);
|
|
1775
1837
|
}
|
|
1776
1838
|
getPayloadUrl(filename) {
|
|
1777
1839
|
return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
|
|
1778
1840
|
method: "GET",
|
|
1779
1841
|
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1780
|
-
});
|
|
1842
|
+
}, zodFetchOptions);
|
|
1781
1843
|
}
|
|
1782
1844
|
};
|
|
1783
1845
|
_getHeaders = new WeakSet();
|
|
@@ -1827,6 +1889,15 @@ getStore_fn2 = /* @__PURE__ */ __name(function() {
|
|
|
1827
1889
|
__name(_ApiClientManager, "ApiClientManager");
|
|
1828
1890
|
var ApiClientManager = _ApiClientManager;
|
|
1829
1891
|
var apiClientManager = new ApiClientManager();
|
|
1892
|
+
var _ZodSchemaParsedError = class _ZodSchemaParsedError extends Error {
|
|
1893
|
+
constructor(error, payload) {
|
|
1894
|
+
super(error.message);
|
|
1895
|
+
this.error = error;
|
|
1896
|
+
this.payload = payload;
|
|
1897
|
+
}
|
|
1898
|
+
};
|
|
1899
|
+
__name(_ZodSchemaParsedError, "ZodSchemaParsedError");
|
|
1900
|
+
var ZodSchemaParsedError = _ZodSchemaParsedError;
|
|
1830
1901
|
var ZodMessageSchema = zod.z.object({
|
|
1831
1902
|
version: zod.z.literal("v1").default("v1"),
|
|
1832
1903
|
type: zod.z.string(),
|
|
@@ -1923,7 +1994,7 @@ var _ZodMessageSender = class _ZodMessageSender {
|
|
|
1923
1994
|
}
|
|
1924
1995
|
const parsedPayload = schema.safeParse(payload);
|
|
1925
1996
|
if (!parsedPayload.success) {
|
|
1926
|
-
throw new
|
|
1997
|
+
throw new ZodSchemaParsedError(parsedPayload.error, payload);
|
|
1927
1998
|
}
|
|
1928
1999
|
await __privateGet(this, _sender).call(this, {
|
|
1929
2000
|
type,
|
|
@@ -2427,7 +2498,7 @@ var _ZodIpcConnection = class _ZodIpcConnection {
|
|
|
2427
2498
|
}
|
|
2428
2499
|
const parsedPayload = schema.safeParse(payload);
|
|
2429
2500
|
if (!parsedPayload.success) {
|
|
2430
|
-
throw new
|
|
2501
|
+
throw new ZodSchemaParsedError(parsedPayload.error, payload);
|
|
2431
2502
|
}
|
|
2432
2503
|
await __privateMethod(this, _sendPacket, sendPacket_fn).call(this, {
|
|
2433
2504
|
type: "EVENT",
|
|
@@ -2616,6 +2687,41 @@ function correctStackTraceLine(line, projectDir) {
|
|
|
2616
2687
|
return line;
|
|
2617
2688
|
}
|
|
2618
2689
|
__name(correctStackTraceLine, "correctStackTraceLine");
|
|
2690
|
+
function groupTaskMetadataIssuesByTask(tasks, issues) {
|
|
2691
|
+
return issues.reduce((acc, issue) => {
|
|
2692
|
+
if (issue.path.length === 0) {
|
|
2693
|
+
return acc;
|
|
2694
|
+
}
|
|
2695
|
+
const taskIndex = issue.path[1];
|
|
2696
|
+
if (typeof taskIndex !== "number") {
|
|
2697
|
+
return acc;
|
|
2698
|
+
}
|
|
2699
|
+
const task = tasks[taskIndex];
|
|
2700
|
+
if (!task) {
|
|
2701
|
+
return acc;
|
|
2702
|
+
}
|
|
2703
|
+
const restOfPath = issue.path.slice(2);
|
|
2704
|
+
const taskId = task.id;
|
|
2705
|
+
const taskName = task.exportName;
|
|
2706
|
+
const filePath = task.filePath;
|
|
2707
|
+
const key = taskIndex;
|
|
2708
|
+
const existing = acc[key] ?? {
|
|
2709
|
+
id: taskId,
|
|
2710
|
+
exportName: taskName,
|
|
2711
|
+
filePath,
|
|
2712
|
+
issues: []
|
|
2713
|
+
};
|
|
2714
|
+
existing.issues.push({
|
|
2715
|
+
message: issue.message,
|
|
2716
|
+
path: restOfPath.length === 0 ? void 0 : restOfPath.join(".")
|
|
2717
|
+
});
|
|
2718
|
+
return {
|
|
2719
|
+
...acc,
|
|
2720
|
+
[key]: existing
|
|
2721
|
+
};
|
|
2722
|
+
}, {});
|
|
2723
|
+
}
|
|
2724
|
+
__name(groupTaskMetadataIssuesByTask, "groupTaskMetadataIssuesByTask");
|
|
2619
2725
|
|
|
2620
2726
|
// src/v3/utils/platform.ts
|
|
2621
2727
|
var _globalThis = typeof globalThis === "object" ? globalThis : global;
|
|
@@ -2816,6 +2922,7 @@ var clock = ClockAPI.getInstance();
|
|
|
2816
2922
|
|
|
2817
2923
|
// src/v3/logger/taskLogger.ts
|
|
2818
2924
|
var logLevels = [
|
|
2925
|
+
"none",
|
|
2819
2926
|
"error",
|
|
2820
2927
|
"warn",
|
|
2821
2928
|
"log",
|
|
@@ -2831,27 +2938,27 @@ var _OtelTaskLogger = class _OtelTaskLogger {
|
|
|
2831
2938
|
this._level = logLevels.indexOf(_config.level);
|
|
2832
2939
|
}
|
|
2833
2940
|
debug(message, properties) {
|
|
2834
|
-
if (this._level <
|
|
2941
|
+
if (this._level < 5)
|
|
2835
2942
|
return;
|
|
2836
2943
|
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "debug", apiLogs.SeverityNumber.DEBUG, properties);
|
|
2837
2944
|
}
|
|
2838
2945
|
log(message, properties) {
|
|
2839
|
-
if (this._level <
|
|
2946
|
+
if (this._level < 3)
|
|
2840
2947
|
return;
|
|
2841
2948
|
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "log", apiLogs.SeverityNumber.INFO, properties);
|
|
2842
2949
|
}
|
|
2843
2950
|
info(message, properties) {
|
|
2844
|
-
if (this._level <
|
|
2951
|
+
if (this._level < 4)
|
|
2845
2952
|
return;
|
|
2846
2953
|
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "info", apiLogs.SeverityNumber.INFO, properties);
|
|
2847
2954
|
}
|
|
2848
2955
|
warn(message, properties) {
|
|
2849
|
-
if (this._level <
|
|
2956
|
+
if (this._level < 2)
|
|
2850
2957
|
return;
|
|
2851
2958
|
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "warn", apiLogs.SeverityNumber.WARN, properties);
|
|
2852
2959
|
}
|
|
2853
2960
|
error(message, properties) {
|
|
2854
|
-
if (this._level <
|
|
2961
|
+
if (this._level < 1)
|
|
2855
2962
|
return;
|
|
2856
2963
|
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "error", apiLogs.SeverityNumber.ERROR, properties);
|
|
2857
2964
|
}
|
|
@@ -4498,6 +4605,7 @@ exports.CreateAuthorizationCodeResponseSchema = CreateAuthorizationCodeResponseS
|
|
|
4498
4605
|
exports.CreateBackgroundWorkerRequestBody = CreateBackgroundWorkerRequestBody;
|
|
4499
4606
|
exports.CreateBackgroundWorkerResponse = CreateBackgroundWorkerResponse;
|
|
4500
4607
|
exports.CreateUploadPayloadUrlResponseBody = CreateUploadPayloadUrlResponseBody;
|
|
4608
|
+
exports.DeploymentErrorData = DeploymentErrorData;
|
|
4501
4609
|
exports.DevRuntimeManager = DevRuntimeManager;
|
|
4502
4610
|
exports.DurableClock = PreciseWallClock;
|
|
4503
4611
|
exports.EnvironmentType = EnvironmentType;
|
|
@@ -4566,6 +4674,7 @@ exports.TaskContextSpanProcessor = TaskContextSpanProcessor;
|
|
|
4566
4674
|
exports.TaskEventStyle = TaskEventStyle;
|
|
4567
4675
|
exports.TaskExecutor = TaskExecutor;
|
|
4568
4676
|
exports.TaskMetadata = TaskMetadata;
|
|
4677
|
+
exports.TaskMetadataFailedToParseData = TaskMetadataFailedToParseData;
|
|
4569
4678
|
exports.TaskMetadataWithFilePath = TaskMetadataWithFilePath;
|
|
4570
4679
|
exports.TaskResource = TaskResource;
|
|
4571
4680
|
exports.TaskRun = TaskRun;
|
|
@@ -4601,6 +4710,7 @@ exports.ZodMessageHandler = ZodMessageHandler;
|
|
|
4601
4710
|
exports.ZodMessageSchema = ZodMessageSchema;
|
|
4602
4711
|
exports.ZodMessageSender = ZodMessageSender;
|
|
4603
4712
|
exports.ZodNamespace = ZodNamespace;
|
|
4713
|
+
exports.ZodSchemaParsedError = ZodSchemaParsedError;
|
|
4604
4714
|
exports.ZodSocketConnection = ZodSocketConnection;
|
|
4605
4715
|
exports.ZodSocketMessageHandler = ZodSocketMessageHandler;
|
|
4606
4716
|
exports.ZodSocketMessageSender = ZodSocketMessageSender;
|
|
@@ -4627,10 +4737,12 @@ exports.formatDurationInDays = formatDurationInDays;
|
|
|
4627
4737
|
exports.formatDurationMilliseconds = formatDurationMilliseconds;
|
|
4628
4738
|
exports.formatDurationNanoseconds = formatDurationNanoseconds;
|
|
4629
4739
|
exports.getEnvVar = getEnvVar;
|
|
4740
|
+
exports.groupTaskMetadataIssuesByTask = groupTaskMetadataIssuesByTask;
|
|
4630
4741
|
exports.iconStringForSeverity = iconStringForSeverity;
|
|
4631
4742
|
exports.imposeAttributeLimits = imposeAttributeLimits;
|
|
4632
4743
|
exports.isCancellationSpanEvent = isCancellationSpanEvent;
|
|
4633
4744
|
exports.isExceptionSpanEvent = isExceptionSpanEvent;
|
|
4745
|
+
exports.logLevels = logLevels;
|
|
4634
4746
|
exports.logger = logger;
|
|
4635
4747
|
exports.millisecondsToNanoseconds = millisecondsToNanoseconds;
|
|
4636
4748
|
exports.nanosecondsToMilliseconds = nanosecondsToMilliseconds;
|