@trigger.dev/core 0.0.0-v3-prerelease-20240708183321 → 0.0.0-v3-prerelease-20240730135037
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/api-Pl9fxB8v.d.mts +13879 -0
- package/dist/api-sNoooMbT.d.ts +13879 -0
- package/dist/{catalog-NxVZnWZh.d.ts → catalog-H7yFiZ60.d.mts} +12 -34
- package/dist/{catalog-N-X0Te3W.d.mts → catalog-h79CG5Wy.d.ts} +12 -34
- package/dist/{common-fIyU5pmz.d.mts → common-CLW82lkt.d.mts} +1 -1
- package/dist/{common-fIyU5pmz.d.ts → common-CLW82lkt.d.ts} +1 -1
- package/dist/{eventFilterMatches-2kHImluE.d.mts → eventFilter-66NaBAMi.d.mts} +1 -3
- package/dist/{eventFilterMatches-2kHImluE.d.ts → eventFilter-66NaBAMi.d.ts} +1 -3
- package/dist/eventFilterMatches.d.mts +6 -0
- package/dist/eventFilterMatches.d.ts +6 -0
- package/dist/eventFilterMatches.js +165 -0
- package/dist/eventFilterMatches.js.map +1 -0
- package/dist/eventFilterMatches.mjs +163 -0
- package/dist/eventFilterMatches.mjs.map +1 -0
- package/dist/index.d.mts +14 -16716
- package/dist/index.d.ts +14 -16716
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/json-DBPEJQRe.d.mts +16 -0
- package/dist/json-DBPEJQRe.d.ts +16 -0
- package/dist/{manager-X_HrWQ7_.d.mts → manager-KvCabW1a.d.mts} +1 -1
- package/dist/{manager-2ZQ3_twq.d.ts → manager-OBA35PzR.d.ts} +1 -1
- package/dist/{messages-Sggr4tid.d.mts → messages-mhHZiNGN.d.mts} +234 -32
- package/dist/{messages-Sggr4tid.d.ts → messages-mhHZiNGN.d.ts} +234 -32
- package/dist/replacements.d.mts +22 -0
- package/dist/replacements.d.ts +22 -0
- package/dist/replacements.js +33 -0
- package/dist/replacements.js.map +1 -0
- package/dist/replacements.mjs +28 -0
- package/dist/replacements.mjs.map +1 -0
- package/dist/requestFilter-HNZQEpQb.d.ts +180 -0
- package/dist/requestFilter-b5W2_1oP.d.mts +180 -0
- package/dist/requestFilterMatches.d.mts +13 -0
- package/dist/requestFilterMatches.d.ts +13 -0
- package/dist/requestFilterMatches.js +238 -0
- package/dist/requestFilterMatches.js.map +1 -0
- package/dist/requestFilterMatches.mjs +235 -0
- package/dist/requestFilterMatches.mjs.map +1 -0
- package/dist/retry.d.mts +10 -0
- package/dist/retry.d.ts +10 -0
- package/dist/retry.js +100 -0
- package/dist/retry.js.map +1 -0
- package/dist/retry.mjs +97 -0
- package/dist/retry.mjs.map +1 -0
- package/dist/schemas/index.d.mts +2611 -0
- package/dist/schemas/index.d.ts +2611 -0
- package/dist/schemas/index.js +1630 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/index.mjs +1463 -0
- package/dist/schemas/index.mjs.map +1 -0
- package/dist/{schemas-Zy7mGFgD.d.mts → schemas-C9ssfehv.d.mts} +50 -1
- package/dist/{schemas-Zy7mGFgD.d.ts → schemas-C9ssfehv.d.ts} +50 -1
- package/dist/taskLogger-CzADe4je.d.ts +33 -0
- package/dist/taskLogger-r_AFTX45.d.mts +33 -0
- package/dist/types.d.mts +11 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +3 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.d.mts +7 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +33 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +30 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/v3/dev/index.d.mts +2 -2
- package/dist/v3/dev/index.d.ts +2 -2
- package/dist/v3/errors.d.mts +39 -0
- package/dist/v3/errors.d.ts +39 -0
- package/dist/v3/errors.js +204 -0
- package/dist/v3/errors.js.map +1 -0
- package/dist/v3/errors.mjs +195 -0
- package/dist/v3/errors.mjs.map +1 -0
- package/dist/v3/index.d.mts +88 -233
- package/dist/v3/index.d.ts +88 -233
- package/dist/v3/index.js +67 -5
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +64 -6
- package/dist/v3/index.mjs.map +1 -1
- package/dist/v3/logger-api.d.mts +24 -0
- package/dist/v3/logger-api.d.ts +24 -0
- package/dist/v3/logger-api.js +118 -0
- package/dist/v3/logger-api.js.map +1 -0
- package/dist/v3/logger-api.mjs +116 -0
- package/dist/v3/logger-api.mjs.map +1 -0
- package/dist/v3/otel/index.js +1 -1
- package/dist/v3/otel/index.js.map +1 -1
- package/dist/v3/otel/index.mjs +1 -1
- package/dist/v3/otel/index.mjs.map +1 -1
- package/dist/v3/prod/index.d.mts +3 -3
- package/dist/v3/prod/index.d.ts +3 -3
- package/dist/v3/schemas/index.d.mts +273 -111
- package/dist/v3/schemas/index.d.ts +273 -111
- package/dist/v3/schemas/index.js +54 -4
- package/dist/v3/schemas/index.js.map +1 -1
- package/dist/v3/schemas/index.mjs +51 -5
- package/dist/v3/schemas/index.mjs.map +1 -1
- package/dist/v3/semanticInternalAttributes.d.mts +56 -0
- package/dist/v3/semanticInternalAttributes.d.ts +56 -0
- package/dist/v3/semanticInternalAttributes.js +61 -0
- package/dist/v3/semanticInternalAttributes.js.map +1 -0
- package/dist/v3/semanticInternalAttributes.mjs +59 -0
- package/dist/v3/semanticInternalAttributes.mjs.map +1 -0
- package/dist/v3/utils/flattenAttributes.d.mts +8 -0
- package/dist/v3/utils/flattenAttributes.d.ts +8 -0
- package/dist/v3/utils/flattenAttributes.js +131 -0
- package/dist/v3/utils/flattenAttributes.js.map +1 -0
- package/dist/v3/utils/flattenAttributes.mjs +126 -0
- package/dist/v3/utils/flattenAttributes.mjs.map +1 -0
- package/dist/v3/utils/ioSerialization.d.mts +21 -0
- package/dist/v3/utils/ioSerialization.d.ts +21 -0
- package/dist/v3/utils/ioSerialization.js +2392 -0
- package/dist/v3/utils/ioSerialization.js.map +1 -0
- package/dist/v3/utils/ioSerialization.mjs +2383 -0
- package/dist/v3/utils/ioSerialization.mjs.map +1 -0
- package/dist/v3/utils/omit.d.mts +3 -0
- package/dist/v3/utils/omit.d.ts +3 -0
- package/dist/v3/utils/omit.js +20 -0
- package/dist/v3/utils/omit.js.map +1 -0
- package/dist/v3/utils/omit.mjs +18 -0
- package/dist/v3/utils/omit.mjs.map +1 -0
- package/dist/v3/utils/retries.d.mts +46 -0
- package/dist/v3/utils/retries.d.ts +46 -0
- package/dist/v3/utils/retries.js +118 -0
- package/dist/v3/utils/retries.js.map +1 -0
- package/dist/v3/utils/retries.mjs +113 -0
- package/dist/v3/utils/retries.mjs.map +1 -0
- package/dist/v3/workers/index.d.mts +7 -6
- package/dist/v3/workers/index.d.ts +7 -6
- package/dist/v3/workers/index.js +50 -5
- package/dist/v3/workers/index.js.map +1 -1
- package/dist/v3/workers/index.mjs +50 -5
- package/dist/v3/workers/index.mjs.map +1 -1
- package/dist/v3/zodIpc.js.map +1 -1
- package/dist/v3/zodIpc.mjs.map +1 -1
- package/dist/v3/zodMessageHandler.d.mts +15 -2
- package/dist/v3/zodMessageHandler.d.ts +15 -2
- package/dist/v3/zodMessageHandler.js +59 -13
- package/dist/v3/zodMessageHandler.js.map +1 -1
- package/dist/v3/zodMessageHandler.mjs +59 -13
- package/dist/v3/zodMessageHandler.mjs.map +1 -1
- package/dist/v3/zodNamespace.js.map +1 -1
- package/dist/v3/zodNamespace.mjs.map +1 -1
- package/dist/v3/zodfetch.d.mts +1 -1
- package/dist/v3/zodfetch.d.ts +1 -1
- package/dist/versions.d.mts +11 -0
- package/dist/versions.d.ts +11 -0
- package/dist/versions.js +31 -0
- package/dist/versions.js.map +1 -0
- package/dist/versions.mjs +27 -0
- package/dist/versions.mjs.map +1 -0
- package/package.json +139 -19
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { R as RetryOptions } from '../../schemas-C9ssfehv.js';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
declare const defaultRetryOptions: {
|
|
5
|
+
maxAttempts: number;
|
|
6
|
+
factor: number;
|
|
7
|
+
minTimeoutInMs: number;
|
|
8
|
+
maxTimeoutInMs: number;
|
|
9
|
+
randomize: true;
|
|
10
|
+
};
|
|
11
|
+
declare const defaultFetchRetryOptions: {
|
|
12
|
+
byStatus: {
|
|
13
|
+
"429,408,409,5xx": {
|
|
14
|
+
maxAttempts: number;
|
|
15
|
+
factor: number;
|
|
16
|
+
minTimeoutInMs: number;
|
|
17
|
+
maxTimeoutInMs: number;
|
|
18
|
+
randomize: true;
|
|
19
|
+
strategy: "backoff";
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
connectionError: {
|
|
23
|
+
maxAttempts: number;
|
|
24
|
+
factor: number;
|
|
25
|
+
minTimeoutInMs: number;
|
|
26
|
+
maxTimeoutInMs: number;
|
|
27
|
+
randomize: true;
|
|
28
|
+
};
|
|
29
|
+
timeout: {
|
|
30
|
+
maxAttempts: number;
|
|
31
|
+
factor: number;
|
|
32
|
+
minTimeoutInMs: number;
|
|
33
|
+
maxTimeoutInMs: number;
|
|
34
|
+
randomize: true;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param options
|
|
40
|
+
* @param attempt - The current attempt number. If the first attempt has failed, this will be 1.
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
declare function calculateNextRetryDelay(options: RetryOptions, attempt: number): number | undefined;
|
|
44
|
+
declare function calculateResetAt(resets: string | undefined | null, format: "unix_timestamp" | "iso_8601" | "iso_8601_duration_openai_variant" | "unix_timestamp_in_ms", now?: number): number | undefined;
|
|
45
|
+
|
|
46
|
+
export { calculateNextRetryDelay, calculateResetAt, defaultFetchRetryOptions, defaultRetryOptions };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
|
|
6
|
+
// src/retry.ts
|
|
7
|
+
function calculateResetAt(resets, format, now = /* @__PURE__ */ new Date()) {
|
|
8
|
+
if (!resets)
|
|
9
|
+
return;
|
|
10
|
+
switch (format) {
|
|
11
|
+
case "iso_8601_duration_openai_variant": {
|
|
12
|
+
return calculateISO8601DurationOpenAIVariantResetAt(resets, now);
|
|
13
|
+
}
|
|
14
|
+
case "iso_8601": {
|
|
15
|
+
return calculateISO8601ResetAt(resets, now);
|
|
16
|
+
}
|
|
17
|
+
case "unix_timestamp": {
|
|
18
|
+
return calculateUnixTimestampResetAt(resets, now);
|
|
19
|
+
}
|
|
20
|
+
case "unix_timestamp_in_ms": {
|
|
21
|
+
return calculateUnixTimestampInMsResetAt(resets, now);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
__name(calculateResetAt, "calculateResetAt");
|
|
26
|
+
function calculateUnixTimestampResetAt(resets, now = /* @__PURE__ */ new Date()) {
|
|
27
|
+
if (!resets)
|
|
28
|
+
return void 0;
|
|
29
|
+
const resetAt = parseInt(resets, 10);
|
|
30
|
+
if (isNaN(resetAt))
|
|
31
|
+
return void 0;
|
|
32
|
+
return new Date(resetAt * 1e3);
|
|
33
|
+
}
|
|
34
|
+
__name(calculateUnixTimestampResetAt, "calculateUnixTimestampResetAt");
|
|
35
|
+
function calculateUnixTimestampInMsResetAt(resets, now = /* @__PURE__ */ new Date()) {
|
|
36
|
+
if (!resets)
|
|
37
|
+
return void 0;
|
|
38
|
+
const resetAt = parseInt(resets, 10);
|
|
39
|
+
if (isNaN(resetAt))
|
|
40
|
+
return void 0;
|
|
41
|
+
return new Date(resetAt);
|
|
42
|
+
}
|
|
43
|
+
__name(calculateUnixTimestampInMsResetAt, "calculateUnixTimestampInMsResetAt");
|
|
44
|
+
function calculateISO8601ResetAt(resets, now = /* @__PURE__ */ new Date()) {
|
|
45
|
+
if (!resets)
|
|
46
|
+
return void 0;
|
|
47
|
+
const resetAt = new Date(resets);
|
|
48
|
+
if (isNaN(resetAt.getTime()))
|
|
49
|
+
return void 0;
|
|
50
|
+
return resetAt;
|
|
51
|
+
}
|
|
52
|
+
__name(calculateISO8601ResetAt, "calculateISO8601ResetAt");
|
|
53
|
+
function calculateISO8601DurationOpenAIVariantResetAt(resets, now = /* @__PURE__ */ new Date()) {
|
|
54
|
+
if (!resets)
|
|
55
|
+
return void 0;
|
|
56
|
+
const pattern = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+)ms)?$/;
|
|
57
|
+
const match = resets.match(pattern);
|
|
58
|
+
if (!match)
|
|
59
|
+
return void 0;
|
|
60
|
+
const days = parseInt(match[1], 10) || 0;
|
|
61
|
+
const hours = parseInt(match[2], 10) || 0;
|
|
62
|
+
const minutes = parseInt(match[3], 10) || 0;
|
|
63
|
+
const seconds = parseFloat(match[4]) || 0;
|
|
64
|
+
const milliseconds = parseInt(match[5], 10) || 0;
|
|
65
|
+
const resetAt = new Date(now);
|
|
66
|
+
resetAt.setDate(resetAt.getDate() + days);
|
|
67
|
+
resetAt.setHours(resetAt.getHours() + hours);
|
|
68
|
+
resetAt.setMinutes(resetAt.getMinutes() + minutes);
|
|
69
|
+
resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));
|
|
70
|
+
resetAt.setMilliseconds(resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1e3 + milliseconds);
|
|
71
|
+
return resetAt;
|
|
72
|
+
}
|
|
73
|
+
__name(calculateISO8601DurationOpenAIVariantResetAt, "calculateISO8601DurationOpenAIVariantResetAt");
|
|
74
|
+
|
|
75
|
+
// src/v3/utils/retries.ts
|
|
76
|
+
var defaultRetryOptions = {
|
|
77
|
+
maxAttempts: 3,
|
|
78
|
+
factor: 2,
|
|
79
|
+
minTimeoutInMs: 1e3,
|
|
80
|
+
maxTimeoutInMs: 6e4,
|
|
81
|
+
randomize: true
|
|
82
|
+
};
|
|
83
|
+
var defaultFetchRetryOptions = {
|
|
84
|
+
byStatus: {
|
|
85
|
+
"429,408,409,5xx": {
|
|
86
|
+
strategy: "backoff",
|
|
87
|
+
...defaultRetryOptions
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
connectionError: defaultRetryOptions,
|
|
91
|
+
timeout: defaultRetryOptions
|
|
92
|
+
};
|
|
93
|
+
function calculateNextRetryDelay(options, attempt) {
|
|
94
|
+
const opts = {
|
|
95
|
+
...defaultRetryOptions,
|
|
96
|
+
...options
|
|
97
|
+
};
|
|
98
|
+
if (attempt >= opts.maxAttempts) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
|
|
102
|
+
const random = randomize ? Math.random() + 1 : 1;
|
|
103
|
+
const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
|
|
104
|
+
return Math.round(timeout);
|
|
105
|
+
}
|
|
106
|
+
__name(calculateNextRetryDelay, "calculateNextRetryDelay");
|
|
107
|
+
function calculateResetAt2(resets, format, now = Date.now()) {
|
|
108
|
+
const resetAt = calculateResetAt(resets, format, new Date(now));
|
|
109
|
+
return resetAt?.getTime();
|
|
110
|
+
}
|
|
111
|
+
__name(calculateResetAt2, "calculateResetAt");
|
|
112
|
+
|
|
113
|
+
exports.calculateNextRetryDelay = calculateNextRetryDelay;
|
|
114
|
+
exports.calculateResetAt = calculateResetAt2;
|
|
115
|
+
exports.defaultFetchRetryOptions = defaultFetchRetryOptions;
|
|
116
|
+
exports.defaultRetryOptions = defaultRetryOptions;
|
|
117
|
+
//# sourceMappingURL=out.js.map
|
|
118
|
+
//# sourceMappingURL=retries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/retry.ts","../../../src/v3/utils/retries.ts"],"names":["calculateResetAt","resets","format","now","Date","calculateISO8601DurationOpenAIVariantResetAt","calculateISO8601ResetAt","calculateUnixTimestampResetAt","calculateUnixTimestampInMsResetAt","undefined","resetAt","parseInt","isNaN","getTime","pattern","match","days","hours","minutes","seconds","parseFloat","milliseconds","setDate","getDate","setHours","getHours","setMinutes","getMinutes","setSeconds","getSeconds","Math","floor","setMilliseconds","getMilliseconds","defaultRetryOptions","maxAttempts","factor","minTimeoutInMs","maxTimeoutInMs","randomize","defaultFetchRetryOptions","byStatus","strategy","connectionError","timeout","calculateNextRetryDelay","options","attempt","opts","random","min","pow","round","calculateResetAtInternal"],"mappings":"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","sourcesContent":["import { RetryOptions } from \"./schemas\";\n\nconst DEFAULT_RETRY_OPTIONS = {\n limit: 5,\n factor: 1.8,\n minTimeoutInMs: 1000,\n maxTimeoutInMs: 60000,\n randomize: true,\n} satisfies RetryOptions;\n\nexport function calculateRetryAt(retryOptions: RetryOptions, attempts: number): Date | undefined {\n const options = {\n ...DEFAULT_RETRY_OPTIONS,\n ...retryOptions,\n };\n\n const retryCount = attempts + 1;\n\n if (retryCount >= options.limit) {\n return;\n }\n\n const random = options.randomize ? Math.random() + 1 : 1;\n\n let timeoutInMs = Math.round(\n random *\n Math.max(options.minTimeoutInMs, 1) *\n Math.pow(options.factor, Math.max(attempts - 1, 0))\n );\n\n timeoutInMs = Math.min(timeoutInMs, options.maxTimeoutInMs);\n\n return new Date(Date.now() + timeoutInMs);\n}\n\nexport function calculateResetAt(\n resets: string | undefined | null,\n format:\n | \"unix_timestamp\"\n | \"iso_8601\"\n | \"iso_8601_duration_openai_variant\"\n | \"unix_timestamp_in_ms\",\n now: Date = new Date()\n): Date | undefined {\n if (!resets) return;\n\n switch (format) {\n case \"iso_8601_duration_openai_variant\": {\n return calculateISO8601DurationOpenAIVariantResetAt(resets, now);\n }\n case \"iso_8601\": {\n return calculateISO8601ResetAt(resets, now);\n }\n case \"unix_timestamp\": {\n return calculateUnixTimestampResetAt(resets, now);\n }\n case \"unix_timestamp_in_ms\": {\n return calculateUnixTimestampInMsResetAt(resets, now);\n }\n }\n}\n\nfunction calculateUnixTimestampResetAt(resets: string, now: Date = new Date()): Date | undefined {\n // Check if the input is null or undefined\n if (!resets) return undefined;\n\n // Convert the string to a number\n const resetAt = parseInt(resets, 10);\n\n // If the string doesn't match the expected format, return undefined\n if (isNaN(resetAt)) return undefined;\n\n // Return the date\n return new Date(resetAt * 1000);\n}\n\nfunction calculateUnixTimestampInMsResetAt(\n resets: string,\n now: Date = new Date()\n): Date | undefined {\n // Check if the input is null or undefined\n if (!resets) return undefined;\n\n // Convert the string to a number\n const resetAt = parseInt(resets, 10);\n\n // If the string doesn't match the expected format, return undefined\n if (isNaN(resetAt)) return undefined;\n\n // Return the date\n return new Date(resetAt);\n}\n\nfunction calculateISO8601ResetAt(resets: string, now: Date = new Date()): Date | undefined {\n // Check if the input is null or undefined\n if (!resets) return undefined;\n\n // Parse the date\n const resetAt = new Date(resets);\n\n // If the string doesn't match the expected format, return undefined\n if (isNaN(resetAt.getTime())) return undefined;\n\n return resetAt;\n}\n\nfunction calculateISO8601DurationOpenAIVariantResetAt(\n resets: string,\n now: Date = new Date()\n): Date | undefined {\n // Check if the input is null or undefined\n if (!resets) return undefined;\n\n // Regular expression to match the duration string pattern\n const pattern = /^(?:(\\d+)d)?(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+(?:\\.\\d+)?)s)?(?:(\\d+)ms)?$/;\n const match = resets.match(pattern);\n\n // If the string doesn't match the expected format, return undefined\n if (!match) return undefined;\n\n // Extract days, hours, minutes, seconds, and milliseconds from the string\n const days = parseInt(match[1], 10) || 0;\n const hours = parseInt(match[2], 10) || 0;\n const minutes = parseInt(match[3], 10) || 0;\n const seconds = parseFloat(match[4]) || 0;\n const milliseconds = parseInt(match[5], 10) || 0;\n\n // Calculate the future date based on the current date plus the extracted time\n const resetAt = new Date(now);\n resetAt.setDate(resetAt.getDate() + days);\n resetAt.setHours(resetAt.getHours() + hours);\n resetAt.setMinutes(resetAt.getMinutes() + minutes);\n resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));\n resetAt.setMilliseconds(\n resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1000 + milliseconds\n );\n\n return resetAt;\n}\n","import { calculateResetAt as calculateResetAtInternal } from \"../../retry\";\nimport { FetchRetryOptions, type RetryOptions } from \"../schemas\";\n\nexport const defaultRetryOptions = {\n maxAttempts: 3,\n factor: 2,\n minTimeoutInMs: 1000,\n maxTimeoutInMs: 60000,\n randomize: true,\n} satisfies RetryOptions;\n\nexport const defaultFetchRetryOptions = {\n byStatus: {\n \"429,408,409,5xx\": {\n strategy: \"backoff\",\n ...defaultRetryOptions,\n },\n },\n connectionError: defaultRetryOptions,\n timeout: defaultRetryOptions,\n} satisfies FetchRetryOptions;\n\n/**\n *\n * @param options\n * @param attempt - The current attempt number. If the first attempt has failed, this will be 1.\n * @returns\n */\nexport function calculateNextRetryDelay(options: RetryOptions, attempt: number) {\n const opts = { ...defaultRetryOptions, ...options };\n\n if (attempt >= opts.maxAttempts) {\n return;\n }\n\n const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;\n\n const random = randomize ? Math.random() + 1 : 1;\n\n const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));\n\n // Round to the nearest integer\n return Math.round(timeout);\n}\n\nexport function calculateResetAt(\n resets: string | undefined | null,\n format:\n | \"unix_timestamp\"\n | \"iso_8601\"\n | \"iso_8601_duration_openai_variant\"\n | \"unix_timestamp_in_ms\",\n now: number = Date.now()\n): number | undefined {\n const resetAt = calculateResetAtInternal(resets, format, new Date(now));\n\n return resetAt?.getTime();\n}\n"]}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/retry.ts
|
|
5
|
+
function calculateResetAt(resets, format, now = /* @__PURE__ */ new Date()) {
|
|
6
|
+
if (!resets)
|
|
7
|
+
return;
|
|
8
|
+
switch (format) {
|
|
9
|
+
case "iso_8601_duration_openai_variant": {
|
|
10
|
+
return calculateISO8601DurationOpenAIVariantResetAt(resets, now);
|
|
11
|
+
}
|
|
12
|
+
case "iso_8601": {
|
|
13
|
+
return calculateISO8601ResetAt(resets, now);
|
|
14
|
+
}
|
|
15
|
+
case "unix_timestamp": {
|
|
16
|
+
return calculateUnixTimestampResetAt(resets, now);
|
|
17
|
+
}
|
|
18
|
+
case "unix_timestamp_in_ms": {
|
|
19
|
+
return calculateUnixTimestampInMsResetAt(resets, now);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
__name(calculateResetAt, "calculateResetAt");
|
|
24
|
+
function calculateUnixTimestampResetAt(resets, now = /* @__PURE__ */ new Date()) {
|
|
25
|
+
if (!resets)
|
|
26
|
+
return void 0;
|
|
27
|
+
const resetAt = parseInt(resets, 10);
|
|
28
|
+
if (isNaN(resetAt))
|
|
29
|
+
return void 0;
|
|
30
|
+
return new Date(resetAt * 1e3);
|
|
31
|
+
}
|
|
32
|
+
__name(calculateUnixTimestampResetAt, "calculateUnixTimestampResetAt");
|
|
33
|
+
function calculateUnixTimestampInMsResetAt(resets, now = /* @__PURE__ */ new Date()) {
|
|
34
|
+
if (!resets)
|
|
35
|
+
return void 0;
|
|
36
|
+
const resetAt = parseInt(resets, 10);
|
|
37
|
+
if (isNaN(resetAt))
|
|
38
|
+
return void 0;
|
|
39
|
+
return new Date(resetAt);
|
|
40
|
+
}
|
|
41
|
+
__name(calculateUnixTimestampInMsResetAt, "calculateUnixTimestampInMsResetAt");
|
|
42
|
+
function calculateISO8601ResetAt(resets, now = /* @__PURE__ */ new Date()) {
|
|
43
|
+
if (!resets)
|
|
44
|
+
return void 0;
|
|
45
|
+
const resetAt = new Date(resets);
|
|
46
|
+
if (isNaN(resetAt.getTime()))
|
|
47
|
+
return void 0;
|
|
48
|
+
return resetAt;
|
|
49
|
+
}
|
|
50
|
+
__name(calculateISO8601ResetAt, "calculateISO8601ResetAt");
|
|
51
|
+
function calculateISO8601DurationOpenAIVariantResetAt(resets, now = /* @__PURE__ */ new Date()) {
|
|
52
|
+
if (!resets)
|
|
53
|
+
return void 0;
|
|
54
|
+
const pattern = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+)ms)?$/;
|
|
55
|
+
const match = resets.match(pattern);
|
|
56
|
+
if (!match)
|
|
57
|
+
return void 0;
|
|
58
|
+
const days = parseInt(match[1], 10) || 0;
|
|
59
|
+
const hours = parseInt(match[2], 10) || 0;
|
|
60
|
+
const minutes = parseInt(match[3], 10) || 0;
|
|
61
|
+
const seconds = parseFloat(match[4]) || 0;
|
|
62
|
+
const milliseconds = parseInt(match[5], 10) || 0;
|
|
63
|
+
const resetAt = new Date(now);
|
|
64
|
+
resetAt.setDate(resetAt.getDate() + days);
|
|
65
|
+
resetAt.setHours(resetAt.getHours() + hours);
|
|
66
|
+
resetAt.setMinutes(resetAt.getMinutes() + minutes);
|
|
67
|
+
resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));
|
|
68
|
+
resetAt.setMilliseconds(resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1e3 + milliseconds);
|
|
69
|
+
return resetAt;
|
|
70
|
+
}
|
|
71
|
+
__name(calculateISO8601DurationOpenAIVariantResetAt, "calculateISO8601DurationOpenAIVariantResetAt");
|
|
72
|
+
|
|
73
|
+
// src/v3/utils/retries.ts
|
|
74
|
+
var defaultRetryOptions = {
|
|
75
|
+
maxAttempts: 3,
|
|
76
|
+
factor: 2,
|
|
77
|
+
minTimeoutInMs: 1e3,
|
|
78
|
+
maxTimeoutInMs: 6e4,
|
|
79
|
+
randomize: true
|
|
80
|
+
};
|
|
81
|
+
var defaultFetchRetryOptions = {
|
|
82
|
+
byStatus: {
|
|
83
|
+
"429,408,409,5xx": {
|
|
84
|
+
strategy: "backoff",
|
|
85
|
+
...defaultRetryOptions
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
connectionError: defaultRetryOptions,
|
|
89
|
+
timeout: defaultRetryOptions
|
|
90
|
+
};
|
|
91
|
+
function calculateNextRetryDelay(options, attempt) {
|
|
92
|
+
const opts = {
|
|
93
|
+
...defaultRetryOptions,
|
|
94
|
+
...options
|
|
95
|
+
};
|
|
96
|
+
if (attempt >= opts.maxAttempts) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
|
|
100
|
+
const random = randomize ? Math.random() + 1 : 1;
|
|
101
|
+
const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
|
|
102
|
+
return Math.round(timeout);
|
|
103
|
+
}
|
|
104
|
+
__name(calculateNextRetryDelay, "calculateNextRetryDelay");
|
|
105
|
+
function calculateResetAt2(resets, format, now = Date.now()) {
|
|
106
|
+
const resetAt = calculateResetAt(resets, format, new Date(now));
|
|
107
|
+
return resetAt?.getTime();
|
|
108
|
+
}
|
|
109
|
+
__name(calculateResetAt2, "calculateResetAt");
|
|
110
|
+
|
|
111
|
+
export { calculateNextRetryDelay, calculateResetAt2 as calculateResetAt, defaultFetchRetryOptions, defaultRetryOptions };
|
|
112
|
+
//# sourceMappingURL=out.js.map
|
|
113
|
+
//# sourceMappingURL=retries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/retry.ts","../../../src/v3/utils/retries.ts"],"names":["calculateResetAt","resets","format","now","Date","calculateISO8601DurationOpenAIVariantResetAt","calculateISO8601ResetAt","calculateUnixTimestampResetAt","calculateUnixTimestampInMsResetAt","undefined","resetAt","parseInt","isNaN","getTime","pattern","match","days","hours","minutes","seconds","parseFloat","milliseconds","setDate","getDate","setHours","getHours","setMinutes","getMinutes","setSeconds","getSeconds","Math","floor","setMilliseconds","getMilliseconds","defaultRetryOptions","maxAttempts","factor","minTimeoutInMs","maxTimeoutInMs","randomize","defaultFetchRetryOptions","byStatus","strategy","connectionError","timeout","calculateNextRetryDelay","options","attempt","opts","random","min","pow","round","calculateResetAtInternal"],"mappings":"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","sourcesContent":["import { RetryOptions } from \"./schemas\";\n\nconst DEFAULT_RETRY_OPTIONS = {\n limit: 5,\n factor: 1.8,\n minTimeoutInMs: 1000,\n maxTimeoutInMs: 60000,\n randomize: true,\n} satisfies RetryOptions;\n\nexport function calculateRetryAt(retryOptions: RetryOptions, attempts: number): Date | undefined {\n const options = {\n ...DEFAULT_RETRY_OPTIONS,\n ...retryOptions,\n };\n\n const retryCount = attempts + 1;\n\n if (retryCount >= options.limit) {\n return;\n }\n\n const random = options.randomize ? Math.random() + 1 : 1;\n\n let timeoutInMs = Math.round(\n random *\n Math.max(options.minTimeoutInMs, 1) *\n Math.pow(options.factor, Math.max(attempts - 1, 0))\n );\n\n timeoutInMs = Math.min(timeoutInMs, options.maxTimeoutInMs);\n\n return new Date(Date.now() + timeoutInMs);\n}\n\nexport function calculateResetAt(\n resets: string | undefined | null,\n format:\n | \"unix_timestamp\"\n | \"iso_8601\"\n | \"iso_8601_duration_openai_variant\"\n | \"unix_timestamp_in_ms\",\n now: Date = new Date()\n): Date | undefined {\n if (!resets) return;\n\n switch (format) {\n case \"iso_8601_duration_openai_variant\": {\n return calculateISO8601DurationOpenAIVariantResetAt(resets, now);\n }\n case \"iso_8601\": {\n return calculateISO8601ResetAt(resets, now);\n }\n case \"unix_timestamp\": {\n return calculateUnixTimestampResetAt(resets, now);\n }\n case \"unix_timestamp_in_ms\": {\n return calculateUnixTimestampInMsResetAt(resets, now);\n }\n }\n}\n\nfunction calculateUnixTimestampResetAt(resets: string, now: Date = new Date()): Date | undefined {\n // Check if the input is null or undefined\n if (!resets) return undefined;\n\n // Convert the string to a number\n const resetAt = parseInt(resets, 10);\n\n // If the string doesn't match the expected format, return undefined\n if (isNaN(resetAt)) return undefined;\n\n // Return the date\n return new Date(resetAt * 1000);\n}\n\nfunction calculateUnixTimestampInMsResetAt(\n resets: string,\n now: Date = new Date()\n): Date | undefined {\n // Check if the input is null or undefined\n if (!resets) return undefined;\n\n // Convert the string to a number\n const resetAt = parseInt(resets, 10);\n\n // If the string doesn't match the expected format, return undefined\n if (isNaN(resetAt)) return undefined;\n\n // Return the date\n return new Date(resetAt);\n}\n\nfunction calculateISO8601ResetAt(resets: string, now: Date = new Date()): Date | undefined {\n // Check if the input is null or undefined\n if (!resets) return undefined;\n\n // Parse the date\n const resetAt = new Date(resets);\n\n // If the string doesn't match the expected format, return undefined\n if (isNaN(resetAt.getTime())) return undefined;\n\n return resetAt;\n}\n\nfunction calculateISO8601DurationOpenAIVariantResetAt(\n resets: string,\n now: Date = new Date()\n): Date | undefined {\n // Check if the input is null or undefined\n if (!resets) return undefined;\n\n // Regular expression to match the duration string pattern\n const pattern = /^(?:(\\d+)d)?(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+(?:\\.\\d+)?)s)?(?:(\\d+)ms)?$/;\n const match = resets.match(pattern);\n\n // If the string doesn't match the expected format, return undefined\n if (!match) return undefined;\n\n // Extract days, hours, minutes, seconds, and milliseconds from the string\n const days = parseInt(match[1], 10) || 0;\n const hours = parseInt(match[2], 10) || 0;\n const minutes = parseInt(match[3], 10) || 0;\n const seconds = parseFloat(match[4]) || 0;\n const milliseconds = parseInt(match[5], 10) || 0;\n\n // Calculate the future date based on the current date plus the extracted time\n const resetAt = new Date(now);\n resetAt.setDate(resetAt.getDate() + days);\n resetAt.setHours(resetAt.getHours() + hours);\n resetAt.setMinutes(resetAt.getMinutes() + minutes);\n resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));\n resetAt.setMilliseconds(\n resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1000 + milliseconds\n );\n\n return resetAt;\n}\n","import { calculateResetAt as calculateResetAtInternal } from \"../../retry\";\nimport { FetchRetryOptions, type RetryOptions } from \"../schemas\";\n\nexport const defaultRetryOptions = {\n maxAttempts: 3,\n factor: 2,\n minTimeoutInMs: 1000,\n maxTimeoutInMs: 60000,\n randomize: true,\n} satisfies RetryOptions;\n\nexport const defaultFetchRetryOptions = {\n byStatus: {\n \"429,408,409,5xx\": {\n strategy: \"backoff\",\n ...defaultRetryOptions,\n },\n },\n connectionError: defaultRetryOptions,\n timeout: defaultRetryOptions,\n} satisfies FetchRetryOptions;\n\n/**\n *\n * @param options\n * @param attempt - The current attempt number. If the first attempt has failed, this will be 1.\n * @returns\n */\nexport function calculateNextRetryDelay(options: RetryOptions, attempt: number) {\n const opts = { ...defaultRetryOptions, ...options };\n\n if (attempt >= opts.maxAttempts) {\n return;\n }\n\n const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;\n\n const random = randomize ? Math.random() + 1 : 1;\n\n const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));\n\n // Round to the nearest integer\n return Math.round(timeout);\n}\n\nexport function calculateResetAt(\n resets: string | undefined | null,\n format:\n | \"unix_timestamp\"\n | \"iso_8601\"\n | \"iso_8601_duration_openai_variant\"\n | \"unix_timestamp_in_ms\",\n now: number = Date.now()\n): number | undefined {\n const resetAt = calculateResetAtInternal(resets, format, new Date(now));\n\n return resetAt?.getTime();\n}\n"]}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as logsAPI from '@opentelemetry/api-logs';
|
|
2
2
|
import { TracingSDK } from '../otel/index.mjs';
|
|
3
3
|
export { TracingDiagnosticLogLevel, recordSpanException } from '../otel/index.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import { B as BackgroundWorkerProperties } from '../../messages-
|
|
6
|
-
import { C as Config,
|
|
7
|
-
import { P as ProjectConfig, H as HandleErrorFunction, T as TaskMetadataWithFunctions, U as UsageMeasurement, C as Clock, a as ClockTime, b as TaskCatalog, c as UsageManager, d as UsageSample } from '../../catalog-
|
|
8
|
-
export {
|
|
4
|
+
import { c as TaskRunExecution, T as TaskRunExecutionResult } from '../../common-CLW82lkt.mjs';
|
|
5
|
+
import { B as BackgroundWorkerProperties } from '../../messages-mhHZiNGN.mjs';
|
|
6
|
+
import { C as Config, a as TaskFileMetadata, b as TaskMetadataWithFilePath } from '../../schemas-C9ssfehv.mjs';
|
|
7
|
+
import { P as ProjectConfig, H as HandleErrorFunction, T as TaskMetadataWithFunctions, U as UsageMeasurement, C as Clock, a as ClockTime, b as TaskCatalog, c as UsageManager, d as UsageSample } from '../../catalog-H7yFiZ60.mjs';
|
|
8
|
+
export { u as usage } from '../../catalog-H7yFiZ60.mjs';
|
|
9
9
|
import { T as TriggerTracer } from '../../tracer-N0p2Fuuv.mjs';
|
|
10
|
-
export { R as RuntimeManager } from '../../manager-
|
|
10
|
+
export { R as RuntimeManager } from '../../manager-KvCabW1a.mjs';
|
|
11
11
|
import { PreciseDate } from '@google-cloud/precise-date';
|
|
12
|
+
export { O as OtelTaskLogger, l as logLevels } from '../../taskLogger-r_AFTX45.mjs';
|
|
12
13
|
import { LogRecordProcessor, LogRecord } from '@opentelemetry/sdk-logs';
|
|
13
14
|
import { SpanProcessor, Span } from '@opentelemetry/sdk-trace-base';
|
|
14
15
|
import { Context } from '@opentelemetry/api';
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as logsAPI from '@opentelemetry/api-logs';
|
|
2
2
|
import { TracingSDK } from '../otel/index.js';
|
|
3
3
|
export { TracingDiagnosticLogLevel, recordSpanException } from '../otel/index.js';
|
|
4
|
-
import {
|
|
5
|
-
import { B as BackgroundWorkerProperties } from '../../messages-
|
|
6
|
-
import { C as Config,
|
|
7
|
-
import { P as ProjectConfig, H as HandleErrorFunction, T as TaskMetadataWithFunctions, U as UsageMeasurement, C as Clock, a as ClockTime, b as TaskCatalog, c as UsageManager, d as UsageSample } from '../../catalog-
|
|
8
|
-
export {
|
|
4
|
+
import { c as TaskRunExecution, T as TaskRunExecutionResult } from '../../common-CLW82lkt.js';
|
|
5
|
+
import { B as BackgroundWorkerProperties } from '../../messages-mhHZiNGN.js';
|
|
6
|
+
import { C as Config, a as TaskFileMetadata, b as TaskMetadataWithFilePath } from '../../schemas-C9ssfehv.js';
|
|
7
|
+
import { P as ProjectConfig, H as HandleErrorFunction, T as TaskMetadataWithFunctions, U as UsageMeasurement, C as Clock, a as ClockTime, b as TaskCatalog, c as UsageManager, d as UsageSample } from '../../catalog-h79CG5Wy.js';
|
|
8
|
+
export { u as usage } from '../../catalog-h79CG5Wy.js';
|
|
9
9
|
import { T as TriggerTracer } from '../../tracer-N0p2Fuuv.js';
|
|
10
|
-
export { R as RuntimeManager } from '../../manager-
|
|
10
|
+
export { R as RuntimeManager } from '../../manager-OBA35PzR.js';
|
|
11
11
|
import { PreciseDate } from '@google-cloud/precise-date';
|
|
12
|
+
export { O as OtelTaskLogger, l as logLevels } from '../../taskLogger-CzADe4je.js';
|
|
12
13
|
import { LogRecordProcessor, LogRecord } from '@opentelemetry/sdk-logs';
|
|
13
14
|
import { SpanProcessor, Span } from '@opentelemetry/sdk-trace-base';
|
|
14
15
|
import { Context } from '@opentelemetry/api';
|
package/dist/v3/workers/index.js
CHANGED
|
@@ -406,7 +406,7 @@ function getEnvVar(name) {
|
|
|
406
406
|
__name(getEnvVar, "getEnvVar");
|
|
407
407
|
|
|
408
408
|
// package.json
|
|
409
|
-
var version = "0.0.0-v3-prerelease-
|
|
409
|
+
var version = "0.0.0-v3-prerelease-20240730135037";
|
|
410
410
|
|
|
411
411
|
// src/v3/otel/tracingSDK.ts
|
|
412
412
|
var _a;
|
|
@@ -892,13 +892,18 @@ var QueueOptions = zod.z.object({
|
|
|
892
892
|
/** @deprecated This feature is coming soon */
|
|
893
893
|
rateLimit: RateLimitOptions.optional()
|
|
894
894
|
});
|
|
895
|
+
var ScheduleMetadata = zod.z.object({
|
|
896
|
+
cron: zod.z.string(),
|
|
897
|
+
timezone: zod.z.string()
|
|
898
|
+
});
|
|
895
899
|
zod.z.object({
|
|
896
900
|
id: zod.z.string(),
|
|
897
901
|
packageVersion: zod.z.string(),
|
|
898
902
|
queue: QueueOptions.optional(),
|
|
899
903
|
retry: RetryOptions.optional(),
|
|
900
904
|
machine: MachineConfig.optional(),
|
|
901
|
-
triggerSource: zod.z.string().optional()
|
|
905
|
+
triggerSource: zod.z.string().optional(),
|
|
906
|
+
schedule: ScheduleMetadata.optional()
|
|
902
907
|
});
|
|
903
908
|
zod.z.object({
|
|
904
909
|
filePath: zod.z.string(),
|
|
@@ -911,6 +916,7 @@ zod.z.object({
|
|
|
911
916
|
retry: RetryOptions.optional(),
|
|
912
917
|
machine: MachineConfig.optional(),
|
|
913
918
|
triggerSource: zod.z.string().optional(),
|
|
919
|
+
schedule: ScheduleMetadata.optional(),
|
|
914
920
|
filePath: zod.z.string(),
|
|
915
921
|
exportName: zod.z.string()
|
|
916
922
|
});
|
|
@@ -947,7 +953,8 @@ zod.z.object({
|
|
|
947
953
|
])).optional(),
|
|
948
954
|
logLevel: zod.z.string().optional(),
|
|
949
955
|
enableConsoleLogging: zod.z.boolean().optional(),
|
|
950
|
-
postInstall: zod.z.string().optional()
|
|
956
|
+
postInstall: zod.z.string().optional(),
|
|
957
|
+
extraCACerts: zod.z.string().optional()
|
|
951
958
|
});
|
|
952
959
|
zod.z.enum([
|
|
953
960
|
"WAIT_FOR_DURATION",
|
|
@@ -971,7 +978,8 @@ var TaskResource = zod.z.object({
|
|
|
971
978
|
queue: QueueOptions.optional(),
|
|
972
979
|
retry: RetryOptions.optional(),
|
|
973
980
|
machine: MachineConfig.optional(),
|
|
974
|
-
triggerSource: zod.z.string().optional()
|
|
981
|
+
triggerSource: zod.z.string().optional(),
|
|
982
|
+
schedule: ScheduleMetadata.optional()
|
|
975
983
|
});
|
|
976
984
|
var BackgroundWorkerMetadata = zod.z.object({
|
|
977
985
|
packageVersion: zod.z.string(),
|
|
@@ -1019,6 +1027,11 @@ zod.z.object({
|
|
|
1019
1027
|
version: zod.z.string(),
|
|
1020
1028
|
contentHash: zod.z.string()
|
|
1021
1029
|
});
|
|
1030
|
+
var RunTag = zod.z.string().max(64, "Tags must be less than 64 characters");
|
|
1031
|
+
var RunTags = zod.z.union([
|
|
1032
|
+
RunTag,
|
|
1033
|
+
RunTag.array().max(3, "You can only set a maximum of 3 tags on a run.")
|
|
1034
|
+
]);
|
|
1022
1035
|
var TriggerTaskRequestBody = zod.z.object({
|
|
1023
1036
|
payload: zod.z.any(),
|
|
1024
1037
|
context: zod.z.any(),
|
|
@@ -1033,6 +1046,7 @@ var TriggerTaskRequestBody = zod.z.object({
|
|
|
1033
1046
|
payloadType: zod.z.string().optional(),
|
|
1034
1047
|
delay: zod.z.string().or(zod.z.coerce.date()).optional(),
|
|
1035
1048
|
ttl: zod.z.string().or(zod.z.number().nonnegative().int()).optional(),
|
|
1049
|
+
tags: RunTags.optional(),
|
|
1036
1050
|
maxAttempts: zod.z.number().int().optional()
|
|
1037
1051
|
}).optional()
|
|
1038
1052
|
});
|
|
@@ -1060,6 +1074,9 @@ zod.z.object({
|
|
|
1060
1074
|
])
|
|
1061
1075
|
}))
|
|
1062
1076
|
});
|
|
1077
|
+
zod.z.object({
|
|
1078
|
+
tags: RunTags
|
|
1079
|
+
});
|
|
1063
1080
|
zod.z.object({
|
|
1064
1081
|
delay: zod.z.string().or(zod.z.coerce.date())
|
|
1065
1082
|
});
|
|
@@ -1134,10 +1151,21 @@ var ReplayRunResponse = zod.z.object({
|
|
|
1134
1151
|
var CanceledRunResponse = zod.z.object({
|
|
1135
1152
|
id: zod.z.string()
|
|
1136
1153
|
});
|
|
1154
|
+
var ScheduleType = zod.z.union([
|
|
1155
|
+
zod.z.literal("DECLARATIVE"),
|
|
1156
|
+
zod.z.literal("IMPERATIVE")
|
|
1157
|
+
]);
|
|
1137
1158
|
zod.z.object({
|
|
1138
1159
|
/** The schedule id associated with this run (you can have many schedules for the same task).
|
|
1139
1160
|
You can use this to remove the schedule, update it, etc */
|
|
1140
1161
|
scheduleId: zod.z.string(),
|
|
1162
|
+
/** The type of schedule – `"DECLARATIVE"` or `"IMPERATIVE"`.
|
|
1163
|
+
*
|
|
1164
|
+
* **DECLARATIVE** – defined inline on your `schedules.task` using the `cron` property. They can only be created, updated or deleted by modifying the `cron` property on your task.
|
|
1165
|
+
*
|
|
1166
|
+
* **IMPERATIVE** – created using the `schedules.create` functions or in the dashboard.
|
|
1167
|
+
*/
|
|
1168
|
+
type: ScheduleType,
|
|
1141
1169
|
/** When the task was scheduled to run.
|
|
1142
1170
|
* Note this will be slightly different from `new Date()` because it takes a few ms to run the task.
|
|
1143
1171
|
*
|
|
@@ -1213,6 +1241,7 @@ var ScheduleGenerator = zod.z.object({
|
|
|
1213
1241
|
});
|
|
1214
1242
|
var ScheduleObject = zod.z.object({
|
|
1215
1243
|
id: zod.z.string(),
|
|
1244
|
+
type: ScheduleType,
|
|
1216
1245
|
task: zod.z.string(),
|
|
1217
1246
|
active: zod.z.boolean(),
|
|
1218
1247
|
deduplicationKey: zod.z.string().nullish(),
|
|
@@ -1310,7 +1339,11 @@ var CommonRunFields = {
|
|
|
1310
1339
|
finishedAt: zod.z.coerce.date().optional(),
|
|
1311
1340
|
delayedUntil: zod.z.coerce.date().optional(),
|
|
1312
1341
|
ttl: zod.z.string().optional(),
|
|
1313
|
-
expiredAt: zod.z.coerce.date().optional()
|
|
1342
|
+
expiredAt: zod.z.coerce.date().optional(),
|
|
1343
|
+
tags: zod.z.string().array(),
|
|
1344
|
+
costInCents: zod.z.number(),
|
|
1345
|
+
baseCostInCents: zod.z.number(),
|
|
1346
|
+
durationMs: zod.z.number()
|
|
1314
1347
|
};
|
|
1315
1348
|
var RetrieveRunResponse = zod.z.object({
|
|
1316
1349
|
...CommonRunFields,
|
|
@@ -2137,6 +2170,15 @@ var _ApiClient = class _ApiClient {
|
|
|
2137
2170
|
body: JSON.stringify(body)
|
|
2138
2171
|
}, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
|
|
2139
2172
|
}
|
|
2173
|
+
addTags(runId, body, requestOptions) {
|
|
2174
|
+
return zodfetch(zod.z.object({
|
|
2175
|
+
message: zod.z.string()
|
|
2176
|
+
}), `${this.baseUrl}/api/v1/runs/${runId}/tags`, {
|
|
2177
|
+
method: "POST",
|
|
2178
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
|
|
2179
|
+
body: JSON.stringify(body)
|
|
2180
|
+
}, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
|
|
2181
|
+
}
|
|
2140
2182
|
createSchedule(options, requestOptions) {
|
|
2141
2183
|
return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules`, {
|
|
2142
2184
|
method: "POST",
|
|
@@ -2264,6 +2306,9 @@ function createSearchQueryForListRuns(query) {
|
|
|
2264
2306
|
if (query.bulkAction) {
|
|
2265
2307
|
searchParams.append("filter[bulkAction]", query.bulkAction);
|
|
2266
2308
|
}
|
|
2309
|
+
if (query.tag) {
|
|
2310
|
+
searchParams.append("filter[tag]", Array.isArray(query.tag) ? query.tag.join(",") : query.tag);
|
|
2311
|
+
}
|
|
2267
2312
|
if (query.schedule) {
|
|
2268
2313
|
searchParams.append("filter[schedule]", query.schedule);
|
|
2269
2314
|
}
|