@trigger.dev/sdk 3.0.0-beta.4 → 3.0.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +221 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +221 -69
- package/dist/index.mjs.map +1 -1
- package/dist/v3/index.d.mts +361 -72
- package/dist/v3/index.d.ts +361 -72
- package/dist/v3/index.js +1018 -477
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +978 -479
- package/dist/v3/index.mjs.map +1 -1
- package/package.json +7 -14
package/dist/v3/index.mjs
CHANGED
|
@@ -1,523 +1,147 @@
|
|
|
1
|
-
import {
|
|
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';
|
|
2
|
+
export { ApiError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError, logger } from '@trigger.dev/core/v3';
|
|
3
|
+
import { trace, context, SpanStatusCode, SpanKind } from '@opentelemetry/api';
|
|
2
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';
|
|
3
|
-
import { TriggerTracer, runtime, SemanticInternalAttributes, accessoryAttributes, defaultRetryOptions, conditionallyImportPacket, parsePacket, createErrorTaskError, apiClientManager, calculateNextRetryDelay, defaultFetchRetryOptions, calculateResetAt, eventFilterMatches, flattenAttributes, taskContextManager } from '@trigger.dev/core/v3';
|
|
4
|
-
export { logger } from '@trigger.dev/core/v3';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
|
+
import { zodfetch } from '@trigger.dev/core/v3/zodfetch';
|
|
6
7
|
|
|
7
8
|
var __defProp = Object.defineProperty;
|
|
8
9
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
10
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
10
15
|
var __publicField = (obj, key, value) => {
|
|
11
16
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12
17
|
return value;
|
|
13
18
|
};
|
|
14
19
|
|
|
15
20
|
// package.json
|
|
16
|
-
var version = "3.0.0-beta.
|
|
21
|
+
var version = "3.0.0-beta.40";
|
|
22
|
+
|
|
23
|
+
// src/v3/tracer.ts
|
|
17
24
|
var tracer = new TriggerTracer({
|
|
18
25
|
name: "@trigger.dev/sdk",
|
|
19
26
|
version
|
|
20
27
|
});
|
|
21
28
|
|
|
22
|
-
// src/v3/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
// src/v3/cache.ts
|
|
30
|
+
var _InMemoryCache = class _InMemoryCache {
|
|
31
|
+
constructor() {
|
|
32
|
+
__publicField(this, "_cache", /* @__PURE__ */ new Map());
|
|
33
|
+
}
|
|
34
|
+
get(key) {
|
|
35
|
+
return this._cache.get(key);
|
|
36
|
+
}
|
|
37
|
+
set(key, value) {
|
|
38
|
+
this._cache.set(key, value);
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
delete(key) {
|
|
42
|
+
this._cache.delete(key);
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
__name(_InMemoryCache, "InMemoryCache");
|
|
47
|
+
var InMemoryCache = _InMemoryCache;
|
|
48
|
+
function createCache(store) {
|
|
49
|
+
return /* @__PURE__ */ __name(function cache(cacheKey, fn) {
|
|
50
|
+
return tracer.startActiveSpan("cache", async (span) => {
|
|
51
|
+
span.setAttribute("cache.key", cacheKey);
|
|
52
|
+
span.setAttribute(SemanticInternalAttributes.STYLE_ICON, "device-sd-card");
|
|
53
|
+
const cacheEntry = await store.get(cacheKey);
|
|
54
|
+
if (cacheEntry) {
|
|
55
|
+
span.updateName(`cache.hit ${cacheKey}`);
|
|
56
|
+
return cacheEntry.value;
|
|
29
57
|
}
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
payload,
|
|
34
|
-
options: {
|
|
35
|
-
queue: params.queue,
|
|
36
|
-
concurrencyKey: options?.concurrencyKey,
|
|
37
|
-
test: taskContextManager.ctx?.run.isTest
|
|
38
|
-
}
|
|
39
|
-
}, {
|
|
40
|
-
spanParentAsLink: true
|
|
41
|
-
});
|
|
42
|
-
if (!response.ok) {
|
|
43
|
-
throw new Error(response.error);
|
|
44
|
-
}
|
|
45
|
-
span.setAttribute("messaging.message.id", response.data.id);
|
|
46
|
-
return response.data;
|
|
58
|
+
span.updateName(`cache.miss ${cacheKey}`);
|
|
59
|
+
const value = await tracer.startActiveSpan("cache.getFreshValue", async (span2) => {
|
|
60
|
+
return await fn();
|
|
47
61
|
}, {
|
|
48
|
-
kind: SpanKind.PRODUCER,
|
|
49
62
|
attributes: {
|
|
50
|
-
|
|
51
|
-
[SemanticInternalAttributes.STYLE_ICON]: "
|
|
52
|
-
["messaging.client_id"]: taskContextManager.worker?.id,
|
|
53
|
-
[SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
54
|
-
["messaging.message.body.size"]: JSON.stringify(payload).length,
|
|
55
|
-
[SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
56
|
-
...taskMetadata ? accessoryAttributes({
|
|
57
|
-
items: [
|
|
58
|
-
{
|
|
59
|
-
text: `${taskMetadata.exportName}.trigger()`,
|
|
60
|
-
variant: "normal"
|
|
61
|
-
}
|
|
62
|
-
],
|
|
63
|
-
style: "codepath"
|
|
64
|
-
}) : {}
|
|
63
|
+
"cache.key": cacheKey,
|
|
64
|
+
[SemanticInternalAttributes.STYLE_ICON]: "device-sd-card"
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
const taskMetadata = runtime.getTaskMetadata(params.id);
|
|
75
|
-
const response = await tracer.startActiveSpan(taskMetadata ? "Batch trigger" : `${params.id} batchTrigger()`, async (span) => {
|
|
76
|
-
const response2 = await apiClient.batchTriggerTask(params.id, {
|
|
77
|
-
items: items.map((item) => ({
|
|
78
|
-
payload: item.payload,
|
|
79
|
-
options: {
|
|
80
|
-
queue: item.options?.queue ?? params.queue,
|
|
81
|
-
concurrencyKey: item.options?.concurrencyKey,
|
|
82
|
-
test: taskContextManager.ctx?.run.isTest
|
|
83
|
-
}
|
|
84
|
-
}))
|
|
85
|
-
}, {
|
|
86
|
-
spanParentAsLink: true
|
|
67
|
+
await tracer.startActiveSpan("cache.set", async (span2) => {
|
|
68
|
+
await store.set(cacheKey, {
|
|
69
|
+
value,
|
|
70
|
+
metadata: {
|
|
71
|
+
createdTime: Date.now()
|
|
72
|
+
}
|
|
87
73
|
});
|
|
88
|
-
if (!response2.ok) {
|
|
89
|
-
throw new Error(response2.error);
|
|
90
|
-
}
|
|
91
|
-
span.setAttribute("messaging.message.id", response2.data.batchId);
|
|
92
|
-
return response2.data;
|
|
93
74
|
}, {
|
|
94
|
-
kind: SpanKind.PRODUCER,
|
|
95
75
|
attributes: {
|
|
96
|
-
|
|
97
|
-
[
|
|
98
|
-
["messaging.client_id"]: taskContextManager.worker?.id,
|
|
99
|
-
[SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
100
|
-
["messaging.message.body.size"]: items.map((item) => JSON.stringify(item.payload)).join("").length,
|
|
101
|
-
[SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
102
|
-
[SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
103
|
-
...taskMetadata ? accessoryAttributes({
|
|
104
|
-
items: [
|
|
105
|
-
{
|
|
106
|
-
text: `${taskMetadata.exportName}.batchTrigger()`,
|
|
107
|
-
variant: "normal"
|
|
108
|
-
}
|
|
109
|
-
],
|
|
110
|
-
style: "codepath"
|
|
111
|
-
}) : {}
|
|
76
|
+
"cache.key": cacheKey,
|
|
77
|
+
[SemanticInternalAttributes.STYLE_ICON]: "device-sd-card"
|
|
112
78
|
}
|
|
113
79
|
});
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
payload,
|
|
129
|
-
options: {
|
|
130
|
-
dependentAttempt: ctx.attempt.id,
|
|
131
|
-
lockToVersion: taskContextManager.worker?.version,
|
|
132
|
-
queue: params.queue,
|
|
133
|
-
concurrencyKey: options?.concurrencyKey,
|
|
134
|
-
test: taskContextManager.ctx?.run.isTest
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
if (!response.ok) {
|
|
138
|
-
throw new Error(response.error);
|
|
139
|
-
}
|
|
140
|
-
span.setAttribute("messaging.message.id", response.data.id);
|
|
141
|
-
const result = await runtime.waitForTask({
|
|
142
|
-
id: response.data.id,
|
|
143
|
-
ctx
|
|
144
|
-
});
|
|
145
|
-
const runResult = await handleTaskRunExecutionResult(result);
|
|
146
|
-
if (!runResult.ok) {
|
|
147
|
-
throw runResult.error;
|
|
148
|
-
}
|
|
149
|
-
return runResult.output;
|
|
150
|
-
}, {
|
|
151
|
-
kind: SpanKind.PRODUCER,
|
|
80
|
+
return value;
|
|
81
|
+
});
|
|
82
|
+
}, "cache");
|
|
83
|
+
}
|
|
84
|
+
__name(createCache, "createCache");
|
|
85
|
+
function onThrow(fn, options) {
|
|
86
|
+
const opts = {
|
|
87
|
+
...defaultRetryOptions,
|
|
88
|
+
...options
|
|
89
|
+
};
|
|
90
|
+
return tracer.startActiveSpan(`retry.onThrow()`, async (span) => {
|
|
91
|
+
let attempt = 1;
|
|
92
|
+
while (attempt <= opts.maxAttempts) {
|
|
93
|
+
const innerSpan = tracer.startSpan("retry.fn()", {
|
|
152
94
|
attributes: {
|
|
153
|
-
[SemanticInternalAttributes.STYLE_ICON]: "
|
|
154
|
-
|
|
155
|
-
["messaging.client_id"]: taskContextManager.worker?.id,
|
|
156
|
-
[SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
157
|
-
[SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
158
|
-
...taskMetadata ? accessoryAttributes({
|
|
95
|
+
[SemanticInternalAttributes.STYLE_ICON]: "function",
|
|
96
|
+
...accessoryAttributes({
|
|
159
97
|
items: [
|
|
160
98
|
{
|
|
161
|
-
text: `${
|
|
99
|
+
text: `${attempt}/${opts.maxAttempts}`,
|
|
162
100
|
variant: "normal"
|
|
163
101
|
}
|
|
164
102
|
],
|
|
165
103
|
style: "codepath"
|
|
166
|
-
})
|
|
104
|
+
})
|
|
167
105
|
}
|
|
168
106
|
});
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (!apiClient) {
|
|
177
|
-
throw apiClientMissingError();
|
|
178
|
-
}
|
|
179
|
-
const taskMetadata = runtime.getTaskMetadata(params.id);
|
|
180
|
-
return await tracer.startActiveSpan(taskMetadata ? "Batch trigger" : `${params.id} batchTriggerAndWait()`, async (span) => {
|
|
181
|
-
const response = await apiClient.batchTriggerTask(params.id, {
|
|
182
|
-
items: items.map((item) => ({
|
|
183
|
-
payload: item.payload,
|
|
184
|
-
options: {
|
|
185
|
-
lockToVersion: taskContextManager.worker?.version,
|
|
186
|
-
queue: item.options?.queue ?? params.queue,
|
|
187
|
-
concurrencyKey: item.options?.concurrencyKey,
|
|
188
|
-
test: taskContextManager.ctx?.run.isTest
|
|
189
|
-
}
|
|
190
|
-
})),
|
|
191
|
-
dependentAttempt: ctx.attempt.id
|
|
107
|
+
const contextWithSpanSet = trace.setSpan(context.active(), innerSpan);
|
|
108
|
+
try {
|
|
109
|
+
const result = await context.with(contextWithSpanSet, async () => {
|
|
110
|
+
return fn({
|
|
111
|
+
attempt,
|
|
112
|
+
maxAttempts: opts.maxAttempts
|
|
113
|
+
});
|
|
192
114
|
});
|
|
193
|
-
|
|
194
|
-
|
|
115
|
+
innerSpan.end();
|
|
116
|
+
return result;
|
|
117
|
+
} catch (e) {
|
|
118
|
+
if (e instanceof Error || typeof e === "string") {
|
|
119
|
+
innerSpan.recordException(e);
|
|
120
|
+
} else {
|
|
121
|
+
innerSpan.recordException(String(e));
|
|
195
122
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
id: response.data.batchId,
|
|
199
|
-
runs: response.data.runs,
|
|
200
|
-
ctx
|
|
123
|
+
innerSpan.setStatus({
|
|
124
|
+
code: SpanStatusCode.ERROR
|
|
201
125
|
});
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
};
|
|
207
|
-
}, {
|
|
208
|
-
kind: SpanKind.PRODUCER,
|
|
209
|
-
attributes: {
|
|
210
|
-
[SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
211
|
-
["messaging.batch.message_count"]: items.length,
|
|
212
|
-
["messaging.client_id"]: taskContextManager.worker?.id,
|
|
213
|
-
[SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
214
|
-
["messaging.message.body.size"]: items.map((item) => JSON.stringify(item.payload)).join("").length,
|
|
215
|
-
[SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
216
|
-
[SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
217
|
-
...taskMetadata ? accessoryAttributes({
|
|
218
|
-
items: [
|
|
219
|
-
{
|
|
220
|
-
text: `${taskMetadata.exportName}.batchTriggerAndWait()`,
|
|
221
|
-
variant: "normal"
|
|
222
|
-
}
|
|
223
|
-
],
|
|
224
|
-
style: "codepath"
|
|
225
|
-
}) : {}
|
|
126
|
+
const nextRetryDelay = calculateNextRetryDelay(opts, attempt);
|
|
127
|
+
if (!nextRetryDelay) {
|
|
128
|
+
innerSpan.end();
|
|
129
|
+
throw e;
|
|
226
130
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
queue: params.queue,
|
|
235
|
-
retry: params.retry ? {
|
|
236
|
-
...defaultRetryOptions,
|
|
237
|
-
...params.retry
|
|
238
|
-
} : void 0,
|
|
239
|
-
machine: params.machine,
|
|
240
|
-
fns: {
|
|
241
|
-
run: params.run,
|
|
242
|
-
init: params.init,
|
|
243
|
-
cleanup: params.cleanup,
|
|
244
|
-
middleware: params.middleware,
|
|
245
|
-
handleError: params.handleError
|
|
131
|
+
innerSpan.setAttribute(SemanticInternalAttributes.RETRY_AT, new Date(Date.now() + nextRetryDelay).toISOString());
|
|
132
|
+
innerSpan.setAttribute(SemanticInternalAttributes.RETRY_COUNT, attempt);
|
|
133
|
+
innerSpan.setAttribute(SemanticInternalAttributes.RETRY_DELAY, `${nextRetryDelay}ms`);
|
|
134
|
+
innerSpan.end();
|
|
135
|
+
await runtime.waitForDuration(nextRetryDelay);
|
|
136
|
+
} finally {
|
|
137
|
+
attempt++;
|
|
246
138
|
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
});
|
|
250
|
-
return task2;
|
|
251
|
-
}
|
|
252
|
-
__name(createTask, "createTask");
|
|
253
|
-
async function handleBatchTaskRunExecutionResult(items) {
|
|
254
|
-
const someObjectStoreOutputs = items.some((item) => item.ok && item.outputType === "application/store");
|
|
255
|
-
if (!someObjectStoreOutputs) {
|
|
256
|
-
const results = await Promise.all(items.map(async (item) => {
|
|
257
|
-
return await handleTaskRunExecutionResult(item);
|
|
258
|
-
}));
|
|
259
|
-
return results;
|
|
260
|
-
}
|
|
261
|
-
return await tracer.startActiveSpan("store.downloadPayloads", async (span) => {
|
|
262
|
-
const results = await Promise.all(items.map(async (item) => {
|
|
263
|
-
return await handleTaskRunExecutionResult(item);
|
|
264
|
-
}));
|
|
265
|
-
return results;
|
|
139
|
+
}
|
|
140
|
+
throw new Error("Max attempts reached");
|
|
266
141
|
}, {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
__name(handleBatchTaskRunExecutionResult, "handleBatchTaskRunExecutionResult");
|
|
272
|
-
async function handleTaskRunExecutionResult(execution) {
|
|
273
|
-
if (execution.ok) {
|
|
274
|
-
const outputPacket = {
|
|
275
|
-
data: execution.output,
|
|
276
|
-
dataType: execution.outputType
|
|
277
|
-
};
|
|
278
|
-
const importedPacket = await conditionallyImportPacket(outputPacket, tracer);
|
|
279
|
-
return {
|
|
280
|
-
ok: true,
|
|
281
|
-
id: execution.id,
|
|
282
|
-
output: await parsePacket(importedPacket)
|
|
283
|
-
};
|
|
284
|
-
} else {
|
|
285
|
-
return {
|
|
286
|
-
ok: false,
|
|
287
|
-
id: execution.id,
|
|
288
|
-
error: createErrorTaskError(execution.error)
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
__name(handleTaskRunExecutionResult, "handleTaskRunExecutionResult");
|
|
293
|
-
function apiClientMissingError() {
|
|
294
|
-
const hasBaseUrl = !!apiClientManager.baseURL;
|
|
295
|
-
const hasAccessToken = !!apiClientManager.accessToken;
|
|
296
|
-
if (!hasBaseUrl && !hasAccessToken) {
|
|
297
|
-
return `You need to set the TRIGGER_API_URL and TRIGGER_SECRET_KEY environment variables.`;
|
|
298
|
-
} else if (!hasBaseUrl) {
|
|
299
|
-
return `You need to set the TRIGGER_API_URL environment variable.`;
|
|
300
|
-
} else if (!hasAccessToken) {
|
|
301
|
-
return `You need to set the TRIGGER_SECRET_KEY environment variable.`;
|
|
302
|
-
}
|
|
303
|
-
return `Unknown error`;
|
|
304
|
-
}
|
|
305
|
-
__name(apiClientMissingError, "apiClientMissingError");
|
|
306
|
-
|
|
307
|
-
// src/v3/tasks.ts
|
|
308
|
-
function task(options) {
|
|
309
|
-
return createTask(options);
|
|
310
|
-
}
|
|
311
|
-
__name(task, "task");
|
|
312
|
-
var wait = {
|
|
313
|
-
for: async (options) => {
|
|
314
|
-
return tracer.startActiveSpan(`wait.for()`, async (span) => {
|
|
315
|
-
const durationInMs = calculateDurationInMs(options);
|
|
316
|
-
await runtime.waitForDuration(durationInMs);
|
|
317
|
-
}, {
|
|
318
|
-
attributes: {
|
|
319
|
-
[SemanticInternalAttributes.STYLE_ICON]: "wait",
|
|
320
|
-
...accessoryAttributes({
|
|
321
|
-
items: [
|
|
322
|
-
{
|
|
323
|
-
text: nameForWaitOptions(options),
|
|
324
|
-
variant: "normal"
|
|
325
|
-
}
|
|
326
|
-
],
|
|
327
|
-
style: "codepath"
|
|
328
|
-
})
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
},
|
|
332
|
-
until: async (options) => {
|
|
333
|
-
return tracer.startActiveSpan(`wait.until()`, async (span) => {
|
|
334
|
-
const start = Date.now();
|
|
335
|
-
if (options.throwIfInThePast && options.date < /* @__PURE__ */ new Date()) {
|
|
336
|
-
throw new Error("Date is in the past");
|
|
337
|
-
}
|
|
338
|
-
const durationInMs = options.date.getTime() - start;
|
|
339
|
-
await runtime.waitForDuration(durationInMs);
|
|
340
|
-
}, {
|
|
341
|
-
attributes: {
|
|
342
|
-
[SemanticInternalAttributes.STYLE_ICON]: "wait",
|
|
343
|
-
...accessoryAttributes({
|
|
344
|
-
items: [
|
|
345
|
-
{
|
|
346
|
-
text: options.date.toISOString(),
|
|
347
|
-
variant: "normal"
|
|
348
|
-
}
|
|
349
|
-
],
|
|
350
|
-
style: "codepath"
|
|
351
|
-
})
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
function nameForWaitOptions(options) {
|
|
357
|
-
if ("seconds" in options) {
|
|
358
|
-
return options.seconds === 1 ? `1 second` : `${options.seconds} seconds`;
|
|
359
|
-
}
|
|
360
|
-
if ("minutes" in options) {
|
|
361
|
-
return options.minutes === 1 ? `1 minute` : `${options.minutes} minutes`;
|
|
362
|
-
}
|
|
363
|
-
if ("hours" in options) {
|
|
364
|
-
return options.hours === 1 ? `1 hour` : `${options.hours} hours`;
|
|
365
|
-
}
|
|
366
|
-
if ("days" in options) {
|
|
367
|
-
return options.days === 1 ? `1 day` : `${options.days} days`;
|
|
368
|
-
}
|
|
369
|
-
if ("weeks" in options) {
|
|
370
|
-
return options.weeks === 1 ? `1 week` : `${options.weeks} weeks`;
|
|
371
|
-
}
|
|
372
|
-
if ("months" in options) {
|
|
373
|
-
return options.months === 1 ? `1 month` : `${options.months} months`;
|
|
374
|
-
}
|
|
375
|
-
if ("years" in options) {
|
|
376
|
-
return options.years === 1 ? `1 year` : `${options.years} years`;
|
|
377
|
-
}
|
|
378
|
-
return "NaN";
|
|
379
|
-
}
|
|
380
|
-
__name(nameForWaitOptions, "nameForWaitOptions");
|
|
381
|
-
function calculateDurationInMs(options) {
|
|
382
|
-
if ("seconds" in options) {
|
|
383
|
-
return options.seconds * 1e3;
|
|
384
|
-
}
|
|
385
|
-
if ("minutes" in options) {
|
|
386
|
-
return options.minutes * 1e3 * 60;
|
|
387
|
-
}
|
|
388
|
-
if ("hours" in options) {
|
|
389
|
-
return options.hours * 1e3 * 60 * 60;
|
|
390
|
-
}
|
|
391
|
-
if ("days" in options) {
|
|
392
|
-
return options.days * 1e3 * 60 * 60 * 24;
|
|
393
|
-
}
|
|
394
|
-
if ("weeks" in options) {
|
|
395
|
-
return options.weeks * 1e3 * 60 * 60 * 24 * 7;
|
|
396
|
-
}
|
|
397
|
-
if ("months" in options) {
|
|
398
|
-
return options.months * 1e3 * 60 * 60 * 24 * 30;
|
|
399
|
-
}
|
|
400
|
-
if ("years" in options) {
|
|
401
|
-
return options.years * 1e3 * 60 * 60 * 24 * 365;
|
|
402
|
-
}
|
|
403
|
-
throw new Error("Invalid options");
|
|
404
|
-
}
|
|
405
|
-
__name(calculateDurationInMs, "calculateDurationInMs");
|
|
406
|
-
var _InMemoryCache = class _InMemoryCache {
|
|
407
|
-
constructor() {
|
|
408
|
-
__publicField(this, "_cache", /* @__PURE__ */ new Map());
|
|
409
|
-
}
|
|
410
|
-
get(key) {
|
|
411
|
-
return this._cache.get(key);
|
|
412
|
-
}
|
|
413
|
-
set(key, value) {
|
|
414
|
-
this._cache.set(key, value);
|
|
415
|
-
return void 0;
|
|
416
|
-
}
|
|
417
|
-
delete(key) {
|
|
418
|
-
this._cache.delete(key);
|
|
419
|
-
return void 0;
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
__name(_InMemoryCache, "InMemoryCache");
|
|
423
|
-
var InMemoryCache = _InMemoryCache;
|
|
424
|
-
function createCache(store) {
|
|
425
|
-
return /* @__PURE__ */ __name(function cache(cacheKey, fn) {
|
|
426
|
-
return tracer.startActiveSpan("cache", async (span) => {
|
|
427
|
-
span.setAttribute("cache.key", cacheKey);
|
|
428
|
-
span.setAttribute(SemanticInternalAttributes.STYLE_ICON, "device-sd-card");
|
|
429
|
-
const cacheEntry = await store.get(cacheKey);
|
|
430
|
-
if (cacheEntry) {
|
|
431
|
-
span.updateName(`cache.hit ${cacheKey}`);
|
|
432
|
-
return cacheEntry.value;
|
|
433
|
-
}
|
|
434
|
-
span.updateName(`cache.miss ${cacheKey}`);
|
|
435
|
-
const value = await tracer.startActiveSpan("cache.getFreshValue", async (span2) => {
|
|
436
|
-
return await fn();
|
|
437
|
-
}, {
|
|
438
|
-
attributes: {
|
|
439
|
-
"cache.key": cacheKey,
|
|
440
|
-
[SemanticInternalAttributes.STYLE_ICON]: "device-sd-card"
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
await tracer.startActiveSpan("cache.set", async (span2) => {
|
|
444
|
-
await store.set(cacheKey, {
|
|
445
|
-
value,
|
|
446
|
-
metadata: {
|
|
447
|
-
createdTime: Date.now()
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
}, {
|
|
451
|
-
attributes: {
|
|
452
|
-
"cache.key": cacheKey,
|
|
453
|
-
[SemanticInternalAttributes.STYLE_ICON]: "device-sd-card"
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
return value;
|
|
457
|
-
});
|
|
458
|
-
}, "cache");
|
|
459
|
-
}
|
|
460
|
-
__name(createCache, "createCache");
|
|
461
|
-
function onThrow(fn, options) {
|
|
462
|
-
const opts = {
|
|
463
|
-
...defaultRetryOptions,
|
|
464
|
-
...options
|
|
465
|
-
};
|
|
466
|
-
return tracer.startActiveSpan(`retry.onThrow()`, async (span) => {
|
|
467
|
-
let attempt = 1;
|
|
468
|
-
while (attempt <= opts.maxAttempts) {
|
|
469
|
-
const innerSpan = tracer.startSpan("retry.fn()", {
|
|
470
|
-
attributes: {
|
|
471
|
-
[SemanticInternalAttributes.STYLE_ICON]: "function",
|
|
472
|
-
...accessoryAttributes({
|
|
473
|
-
items: [
|
|
474
|
-
{
|
|
475
|
-
text: `${attempt}/${opts.maxAttempts}`,
|
|
476
|
-
variant: "normal"
|
|
477
|
-
}
|
|
478
|
-
],
|
|
479
|
-
style: "codepath"
|
|
480
|
-
})
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
const contextWithSpanSet = trace.setSpan(context.active(), innerSpan);
|
|
484
|
-
try {
|
|
485
|
-
const result = await context.with(contextWithSpanSet, async () => {
|
|
486
|
-
return fn({
|
|
487
|
-
attempt,
|
|
488
|
-
maxAttempts: opts.maxAttempts
|
|
489
|
-
});
|
|
490
|
-
});
|
|
491
|
-
innerSpan.end();
|
|
492
|
-
return result;
|
|
493
|
-
} catch (e) {
|
|
494
|
-
if (e instanceof Error || typeof e === "string") {
|
|
495
|
-
innerSpan.recordException(e);
|
|
496
|
-
} else {
|
|
497
|
-
innerSpan.recordException(String(e));
|
|
498
|
-
}
|
|
499
|
-
innerSpan.setStatus({
|
|
500
|
-
code: SpanStatusCode.ERROR
|
|
501
|
-
});
|
|
502
|
-
const nextRetryDelay = calculateNextRetryDelay(opts, attempt);
|
|
503
|
-
if (!nextRetryDelay) {
|
|
504
|
-
innerSpan.end();
|
|
505
|
-
throw e;
|
|
506
|
-
}
|
|
507
|
-
innerSpan.setAttribute(SemanticInternalAttributes.RETRY_AT, new Date(Date.now() + nextRetryDelay).toISOString());
|
|
508
|
-
innerSpan.setAttribute(SemanticInternalAttributes.RETRY_COUNT, attempt);
|
|
509
|
-
innerSpan.setAttribute(SemanticInternalAttributes.RETRY_DELAY, `${nextRetryDelay}ms`);
|
|
510
|
-
innerSpan.end();
|
|
511
|
-
await runtime.waitForDuration(nextRetryDelay);
|
|
512
|
-
} finally {
|
|
513
|
-
attempt++;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
throw new Error("Max attempts reached");
|
|
517
|
-
}, {
|
|
518
|
-
attributes: {
|
|
519
|
-
[SemanticInternalAttributes.STYLE_ICON]: "arrow-capsule"
|
|
520
|
-
}
|
|
142
|
+
attributes: {
|
|
143
|
+
[SemanticInternalAttributes.STYLE_ICON]: "arrow-capsule"
|
|
144
|
+
}
|
|
521
145
|
});
|
|
522
146
|
}
|
|
523
147
|
__name(onThrow, "onThrow");
|
|
@@ -877,7 +501,882 @@ var retry = {
|
|
|
877
501
|
fetch: retryFetch,
|
|
878
502
|
interceptFetch
|
|
879
503
|
};
|
|
504
|
+
function queue(options) {
|
|
505
|
+
return options;
|
|
506
|
+
}
|
|
507
|
+
__name(queue, "queue");
|
|
508
|
+
function createTask(params) {
|
|
509
|
+
const task3 = {
|
|
510
|
+
id: params.id,
|
|
511
|
+
trigger: async (payload, options) => {
|
|
512
|
+
const apiClient = apiClientManager.client;
|
|
513
|
+
if (!apiClient) {
|
|
514
|
+
throw apiClientMissingError();
|
|
515
|
+
}
|
|
516
|
+
const taskMetadata = taskCatalog.getTaskMetadata(params.id);
|
|
517
|
+
const payloadPacket = await stringifyIO(payload);
|
|
518
|
+
const handle = await tracer.startActiveSpan(taskMetadata ? "Trigger" : `${params.id} trigger()`, async (span) => {
|
|
519
|
+
const response = await apiClient.triggerTask(params.id, {
|
|
520
|
+
payload: payloadPacket.data,
|
|
521
|
+
options: {
|
|
522
|
+
queue: options?.queue ?? params.queue,
|
|
523
|
+
concurrencyKey: options?.concurrencyKey,
|
|
524
|
+
test: taskContext.ctx?.run.isTest,
|
|
525
|
+
payloadType: payloadPacket.dataType,
|
|
526
|
+
idempotencyKey: options?.idempotencyKey
|
|
527
|
+
}
|
|
528
|
+
}, {
|
|
529
|
+
spanParentAsLink: true
|
|
530
|
+
});
|
|
531
|
+
span.setAttribute("messaging.message.id", response.id);
|
|
532
|
+
return response;
|
|
533
|
+
}, {
|
|
534
|
+
kind: SpanKind.PRODUCER,
|
|
535
|
+
attributes: {
|
|
536
|
+
[SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
537
|
+
[SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
538
|
+
["messaging.client_id"]: taskContext.worker?.id,
|
|
539
|
+
[SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
540
|
+
[SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
541
|
+
...taskMetadata ? accessoryAttributes({
|
|
542
|
+
items: [
|
|
543
|
+
{
|
|
544
|
+
text: `${taskMetadata.exportName}.trigger()`,
|
|
545
|
+
variant: "normal"
|
|
546
|
+
}
|
|
547
|
+
],
|
|
548
|
+
style: "codepath"
|
|
549
|
+
}) : {}
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
return handle;
|
|
553
|
+
},
|
|
554
|
+
batchTrigger: async (items) => {
|
|
555
|
+
const apiClient = apiClientManager.client;
|
|
556
|
+
if (!apiClient) {
|
|
557
|
+
throw apiClientMissingError();
|
|
558
|
+
}
|
|
559
|
+
const taskMetadata = taskCatalog.getTaskMetadata(params.id);
|
|
560
|
+
const response = await tracer.startActiveSpan(taskMetadata ? "Batch trigger" : `${params.id} batchTrigger()`, async (span) => {
|
|
561
|
+
const response2 = await apiClient.batchTriggerTask(params.id, {
|
|
562
|
+
items: await Promise.all(items.map(async (item) => {
|
|
563
|
+
const payloadPacket = await stringifyIO(item.payload);
|
|
564
|
+
return {
|
|
565
|
+
payload: payloadPacket.data,
|
|
566
|
+
options: {
|
|
567
|
+
queue: item.options?.queue ?? params.queue,
|
|
568
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
569
|
+
test: taskContext.ctx?.run.isTest,
|
|
570
|
+
payloadType: payloadPacket.dataType,
|
|
571
|
+
idempotencyKey: item.options?.idempotencyKey
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
}))
|
|
575
|
+
}, {
|
|
576
|
+
spanParentAsLink: true
|
|
577
|
+
});
|
|
578
|
+
span.setAttribute("messaging.message.id", response2.batchId);
|
|
579
|
+
return response2;
|
|
580
|
+
}, {
|
|
581
|
+
kind: SpanKind.PRODUCER,
|
|
582
|
+
attributes: {
|
|
583
|
+
[SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
584
|
+
["messaging.batch.message_count"]: items.length,
|
|
585
|
+
["messaging.client_id"]: taskContext.worker?.id,
|
|
586
|
+
[SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
587
|
+
[SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
588
|
+
[SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
589
|
+
...taskMetadata ? accessoryAttributes({
|
|
590
|
+
items: [
|
|
591
|
+
{
|
|
592
|
+
text: `${taskMetadata.exportName}.batchTrigger()`,
|
|
593
|
+
variant: "normal"
|
|
594
|
+
}
|
|
595
|
+
],
|
|
596
|
+
style: "codepath"
|
|
597
|
+
}) : {}
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
return response;
|
|
601
|
+
},
|
|
602
|
+
triggerAndWait: async (payload, options) => {
|
|
603
|
+
const ctx = taskContext.ctx;
|
|
604
|
+
if (!ctx) {
|
|
605
|
+
throw new Error("triggerAndWait can only be used from inside a task.run()");
|
|
606
|
+
}
|
|
607
|
+
const apiClient = apiClientManager.client;
|
|
608
|
+
if (!apiClient) {
|
|
609
|
+
throw apiClientMissingError();
|
|
610
|
+
}
|
|
611
|
+
const taskMetadata = taskCatalog.getTaskMetadata(params.id);
|
|
612
|
+
const payloadPacket = await stringifyIO(payload);
|
|
613
|
+
return await tracer.startActiveSpan(taskMetadata ? "Trigger" : `${params.id} triggerAndWait()`, async (span) => {
|
|
614
|
+
const response = await apiClient.triggerTask(params.id, {
|
|
615
|
+
payload: payloadPacket.data,
|
|
616
|
+
options: {
|
|
617
|
+
dependentAttempt: ctx.attempt.id,
|
|
618
|
+
lockToVersion: taskContext.worker?.version,
|
|
619
|
+
queue: options?.queue ?? params.queue,
|
|
620
|
+
concurrencyKey: options?.concurrencyKey,
|
|
621
|
+
test: taskContext.ctx?.run.isTest,
|
|
622
|
+
payloadType: payloadPacket.dataType,
|
|
623
|
+
idempotencyKey: options?.idempotencyKey
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
span.setAttribute("messaging.message.id", response.id);
|
|
627
|
+
if (options?.idempotencyKey) {
|
|
628
|
+
const result2 = await apiClient.getRunResult(response.id);
|
|
629
|
+
if (result2) {
|
|
630
|
+
logger.log(`Result reused from previous task run with idempotency key '${options.idempotencyKey}'.`, {
|
|
631
|
+
runId: response.id,
|
|
632
|
+
idempotencyKey: options.idempotencyKey
|
|
633
|
+
});
|
|
634
|
+
return await handleTaskRunExecutionResult(result2);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
const result = await runtime.waitForTask({
|
|
638
|
+
id: response.id,
|
|
639
|
+
ctx
|
|
640
|
+
});
|
|
641
|
+
return await handleTaskRunExecutionResult(result);
|
|
642
|
+
}, {
|
|
643
|
+
kind: SpanKind.PRODUCER,
|
|
644
|
+
attributes: {
|
|
645
|
+
[SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
646
|
+
[SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
647
|
+
["messaging.client_id"]: taskContext.worker?.id,
|
|
648
|
+
[SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
649
|
+
[SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
650
|
+
...taskMetadata ? accessoryAttributes({
|
|
651
|
+
items: [
|
|
652
|
+
{
|
|
653
|
+
text: `${taskMetadata.exportName}.triggerAndWait()`,
|
|
654
|
+
variant: "normal"
|
|
655
|
+
}
|
|
656
|
+
],
|
|
657
|
+
style: "codepath"
|
|
658
|
+
}) : {}
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
},
|
|
662
|
+
batchTriggerAndWait: async (items) => {
|
|
663
|
+
const ctx = taskContext.ctx;
|
|
664
|
+
if (!ctx) {
|
|
665
|
+
throw new Error("batchTriggerAndWait can only be used from inside a task.run()");
|
|
666
|
+
}
|
|
667
|
+
const apiClient = apiClientManager.client;
|
|
668
|
+
if (!apiClient) {
|
|
669
|
+
throw apiClientMissingError();
|
|
670
|
+
}
|
|
671
|
+
const taskMetadata = taskCatalog.getTaskMetadata(params.id);
|
|
672
|
+
return await tracer.startActiveSpan(taskMetadata ? "Batch trigger" : `${params.id} batchTriggerAndWait()`, async (span) => {
|
|
673
|
+
const response = await apiClient.batchTriggerTask(params.id, {
|
|
674
|
+
items: await Promise.all(items.map(async (item) => {
|
|
675
|
+
const payloadPacket = await stringifyIO(item.payload);
|
|
676
|
+
return {
|
|
677
|
+
payload: payloadPacket.data,
|
|
678
|
+
options: {
|
|
679
|
+
lockToVersion: taskContext.worker?.version,
|
|
680
|
+
queue: item.options?.queue ?? params.queue,
|
|
681
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
682
|
+
test: taskContext.ctx?.run.isTest,
|
|
683
|
+
payloadType: payloadPacket.dataType,
|
|
684
|
+
idempotencyKey: item.options?.idempotencyKey
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
})),
|
|
688
|
+
dependentAttempt: ctx.attempt.id
|
|
689
|
+
});
|
|
690
|
+
span.setAttribute("messaging.message.id", response.batchId);
|
|
691
|
+
const getBatchResults = /* @__PURE__ */ __name(async () => {
|
|
692
|
+
const hasIdempotencyKey = items.some((item) => item.options?.idempotencyKey);
|
|
693
|
+
if (hasIdempotencyKey) {
|
|
694
|
+
const results = await apiClient.getBatchResults(response.batchId);
|
|
695
|
+
if (results) {
|
|
696
|
+
return results;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return {
|
|
700
|
+
id: response.batchId,
|
|
701
|
+
items: []
|
|
702
|
+
};
|
|
703
|
+
}, "getBatchResults");
|
|
704
|
+
const existingResults = await getBatchResults();
|
|
705
|
+
const incompleteRuns = response.runs.filter((runId) => !existingResults.items.some((item) => item.id === runId));
|
|
706
|
+
if (incompleteRuns.length === 0) {
|
|
707
|
+
logger.log(`Results reused from previous task runs because of the provided idempotency keys.`);
|
|
708
|
+
const runs3 = await handleBatchTaskRunExecutionResult(existingResults.items);
|
|
709
|
+
return {
|
|
710
|
+
id: existingResults.id,
|
|
711
|
+
runs: runs3
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
const result = await runtime.waitForBatch({
|
|
715
|
+
id: response.batchId,
|
|
716
|
+
runs: incompleteRuns,
|
|
717
|
+
ctx
|
|
718
|
+
});
|
|
719
|
+
const combinedItems = [];
|
|
720
|
+
for (const runId of response.runs) {
|
|
721
|
+
const existingItem = existingResults.items.find((item) => item.id === runId);
|
|
722
|
+
if (existingItem) {
|
|
723
|
+
combinedItems.push(existingItem);
|
|
724
|
+
} else {
|
|
725
|
+
const newItem = result.items.find((item) => item.id === runId);
|
|
726
|
+
if (newItem) {
|
|
727
|
+
combinedItems.push(newItem);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
const runs2 = await handleBatchTaskRunExecutionResult(combinedItems);
|
|
732
|
+
return {
|
|
733
|
+
id: result.id,
|
|
734
|
+
runs: runs2
|
|
735
|
+
};
|
|
736
|
+
}, {
|
|
737
|
+
kind: SpanKind.PRODUCER,
|
|
738
|
+
attributes: {
|
|
739
|
+
[SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
740
|
+
["messaging.batch.message_count"]: items.length,
|
|
741
|
+
["messaging.client_id"]: taskContext.worker?.id,
|
|
742
|
+
[SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
743
|
+
[SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
744
|
+
[SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
745
|
+
...taskMetadata ? accessoryAttributes({
|
|
746
|
+
items: [
|
|
747
|
+
{
|
|
748
|
+
text: `${taskMetadata.exportName}.batchTriggerAndWait()`,
|
|
749
|
+
variant: "normal"
|
|
750
|
+
}
|
|
751
|
+
],
|
|
752
|
+
style: "codepath"
|
|
753
|
+
}) : {}
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
taskCatalog.registerTaskMetadata({
|
|
759
|
+
id: params.id,
|
|
760
|
+
packageVersion: version,
|
|
761
|
+
queue: params.queue,
|
|
762
|
+
retry: params.retry ? {
|
|
763
|
+
...defaultRetryOptions,
|
|
764
|
+
...params.retry
|
|
765
|
+
} : void 0,
|
|
766
|
+
machine: params.machine,
|
|
767
|
+
fns: {
|
|
768
|
+
run: params.run,
|
|
769
|
+
init: params.init,
|
|
770
|
+
cleanup: params.cleanup,
|
|
771
|
+
middleware: params.middleware,
|
|
772
|
+
handleError: params.handleError,
|
|
773
|
+
onSuccess: params.onSuccess,
|
|
774
|
+
onFailure: params.onFailure,
|
|
775
|
+
onStart: params.onStart
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
return task3;
|
|
779
|
+
}
|
|
780
|
+
__name(createTask, "createTask");
|
|
781
|
+
async function handleBatchTaskRunExecutionResult(items) {
|
|
782
|
+
const someObjectStoreOutputs = items.some((item) => item.ok && item.outputType === "application/store");
|
|
783
|
+
if (!someObjectStoreOutputs) {
|
|
784
|
+
const results = await Promise.all(items.map(async (item) => {
|
|
785
|
+
return await handleTaskRunExecutionResult(item);
|
|
786
|
+
}));
|
|
787
|
+
return results;
|
|
788
|
+
}
|
|
789
|
+
return await tracer.startActiveSpan("store.downloadPayloads", async (span) => {
|
|
790
|
+
const results = await Promise.all(items.map(async (item) => {
|
|
791
|
+
return await handleTaskRunExecutionResult(item);
|
|
792
|
+
}));
|
|
793
|
+
return results;
|
|
794
|
+
}, {
|
|
795
|
+
kind: SpanKind.INTERNAL,
|
|
796
|
+
[SemanticInternalAttributes.STYLE_ICON]: "cloud-download"
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
__name(handleBatchTaskRunExecutionResult, "handleBatchTaskRunExecutionResult");
|
|
800
|
+
async function handleTaskRunExecutionResult(execution) {
|
|
801
|
+
if (execution.ok) {
|
|
802
|
+
const outputPacket = {
|
|
803
|
+
data: execution.output,
|
|
804
|
+
dataType: execution.outputType
|
|
805
|
+
};
|
|
806
|
+
const importedPacket = await conditionallyImportPacket(outputPacket, tracer);
|
|
807
|
+
return {
|
|
808
|
+
ok: true,
|
|
809
|
+
id: execution.id,
|
|
810
|
+
output: await parsePacket(importedPacket)
|
|
811
|
+
};
|
|
812
|
+
} else {
|
|
813
|
+
return {
|
|
814
|
+
ok: false,
|
|
815
|
+
id: execution.id,
|
|
816
|
+
error: createErrorTaskError(execution.error)
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
__name(handleTaskRunExecutionResult, "handleTaskRunExecutionResult");
|
|
821
|
+
function apiClientMissingError() {
|
|
822
|
+
const hasBaseUrl = !!apiClientManager.baseURL;
|
|
823
|
+
const hasAccessToken = !!apiClientManager.accessToken;
|
|
824
|
+
if (!hasBaseUrl && !hasAccessToken) {
|
|
825
|
+
return `You need to set the TRIGGER_API_URL and TRIGGER_SECRET_KEY environment variables.`;
|
|
826
|
+
} else if (!hasBaseUrl) {
|
|
827
|
+
return `You need to set the TRIGGER_API_URL environment variable.`;
|
|
828
|
+
} else if (!hasAccessToken) {
|
|
829
|
+
return `You need to set the TRIGGER_SECRET_KEY environment variable.`;
|
|
830
|
+
}
|
|
831
|
+
return `Unknown error`;
|
|
832
|
+
}
|
|
833
|
+
__name(apiClientMissingError, "apiClientMissingError");
|
|
834
|
+
|
|
835
|
+
// src/v3/tasks.ts
|
|
836
|
+
function task(options) {
|
|
837
|
+
return createTask(options);
|
|
838
|
+
}
|
|
839
|
+
__name(task, "task");
|
|
840
|
+
var wait = {
|
|
841
|
+
for: async (options) => {
|
|
842
|
+
return tracer.startActiveSpan(`wait.for()`, async (span) => {
|
|
843
|
+
const durationInMs = calculateDurationInMs(options);
|
|
844
|
+
await runtime.waitForDuration(durationInMs);
|
|
845
|
+
}, {
|
|
846
|
+
attributes: {
|
|
847
|
+
[SemanticInternalAttributes.STYLE_ICON]: "wait",
|
|
848
|
+
...accessoryAttributes({
|
|
849
|
+
items: [
|
|
850
|
+
{
|
|
851
|
+
text: nameForWaitOptions(options),
|
|
852
|
+
variant: "normal"
|
|
853
|
+
}
|
|
854
|
+
],
|
|
855
|
+
style: "codepath"
|
|
856
|
+
})
|
|
857
|
+
}
|
|
858
|
+
});
|
|
859
|
+
},
|
|
860
|
+
until: async (options) => {
|
|
861
|
+
return tracer.startActiveSpan(`wait.until()`, async (span) => {
|
|
862
|
+
const start = Date.now();
|
|
863
|
+
if (options.throwIfInThePast && options.date < /* @__PURE__ */ new Date()) {
|
|
864
|
+
throw new Error("Date is in the past");
|
|
865
|
+
}
|
|
866
|
+
const durationInMs = options.date.getTime() - start;
|
|
867
|
+
await runtime.waitForDuration(durationInMs);
|
|
868
|
+
}, {
|
|
869
|
+
attributes: {
|
|
870
|
+
[SemanticInternalAttributes.STYLE_ICON]: "wait",
|
|
871
|
+
...accessoryAttributes({
|
|
872
|
+
items: [
|
|
873
|
+
{
|
|
874
|
+
text: options.date.toISOString(),
|
|
875
|
+
variant: "normal"
|
|
876
|
+
}
|
|
877
|
+
],
|
|
878
|
+
style: "codepath"
|
|
879
|
+
})
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
function nameForWaitOptions(options) {
|
|
885
|
+
if ("seconds" in options) {
|
|
886
|
+
return options.seconds === 1 ? `1 second` : `${options.seconds} seconds`;
|
|
887
|
+
}
|
|
888
|
+
if ("minutes" in options) {
|
|
889
|
+
return options.minutes === 1 ? `1 minute` : `${options.minutes} minutes`;
|
|
890
|
+
}
|
|
891
|
+
if ("hours" in options) {
|
|
892
|
+
return options.hours === 1 ? `1 hour` : `${options.hours} hours`;
|
|
893
|
+
}
|
|
894
|
+
if ("days" in options) {
|
|
895
|
+
return options.days === 1 ? `1 day` : `${options.days} days`;
|
|
896
|
+
}
|
|
897
|
+
if ("weeks" in options) {
|
|
898
|
+
return options.weeks === 1 ? `1 week` : `${options.weeks} weeks`;
|
|
899
|
+
}
|
|
900
|
+
if ("months" in options) {
|
|
901
|
+
return options.months === 1 ? `1 month` : `${options.months} months`;
|
|
902
|
+
}
|
|
903
|
+
if ("years" in options) {
|
|
904
|
+
return options.years === 1 ? `1 year` : `${options.years} years`;
|
|
905
|
+
}
|
|
906
|
+
return "NaN";
|
|
907
|
+
}
|
|
908
|
+
__name(nameForWaitOptions, "nameForWaitOptions");
|
|
909
|
+
function calculateDurationInMs(options) {
|
|
910
|
+
if ("seconds" in options) {
|
|
911
|
+
return options.seconds * 1e3;
|
|
912
|
+
}
|
|
913
|
+
if ("minutes" in options) {
|
|
914
|
+
return options.minutes * 1e3 * 60;
|
|
915
|
+
}
|
|
916
|
+
if ("hours" in options) {
|
|
917
|
+
return options.hours * 1e3 * 60 * 60;
|
|
918
|
+
}
|
|
919
|
+
if ("days" in options) {
|
|
920
|
+
return options.days * 1e3 * 60 * 60 * 24;
|
|
921
|
+
}
|
|
922
|
+
if ("weeks" in options) {
|
|
923
|
+
return options.weeks * 1e3 * 60 * 60 * 24 * 7;
|
|
924
|
+
}
|
|
925
|
+
if ("months" in options) {
|
|
926
|
+
return options.months * 1e3 * 60 * 60 * 24 * 30;
|
|
927
|
+
}
|
|
928
|
+
if ("years" in options) {
|
|
929
|
+
return options.years * 1e3 * 60 * 60 * 24 * 365;
|
|
930
|
+
}
|
|
931
|
+
throw new Error("Invalid options");
|
|
932
|
+
}
|
|
933
|
+
__name(calculateDurationInMs, "calculateDurationInMs");
|
|
934
|
+
var usage = {
|
|
935
|
+
/**
|
|
936
|
+
* Get the current running usage of this task run.
|
|
937
|
+
*
|
|
938
|
+
* @example
|
|
939
|
+
*
|
|
940
|
+
* ```typescript
|
|
941
|
+
* import { usage, task } from "@trigger.dev/sdk/v3";
|
|
942
|
+
*
|
|
943
|
+
* export const myTask = task({
|
|
944
|
+
* id: "my-task",
|
|
945
|
+
* run: async (payload, { ctx }) => {
|
|
946
|
+
* // ... Do a bunch of work
|
|
947
|
+
*
|
|
948
|
+
* const currentUsage = usage.getCurrent();
|
|
949
|
+
*
|
|
950
|
+
* // You have access to the current compute cost and duration up to this point
|
|
951
|
+
* console.log("Current attempt compute cost and duration", {
|
|
952
|
+
* cost: currentUsage.compute.attempt.costInCents,
|
|
953
|
+
* duration: currentUsage.compute.attempt.durationMs,
|
|
954
|
+
* });
|
|
955
|
+
*
|
|
956
|
+
* // You also can see the total compute cost and duration up to this point in the run, across all attempts
|
|
957
|
+
* console.log("Current total compute cost and duration", {
|
|
958
|
+
* cost: currentUsage.compute.total.costInCents,
|
|
959
|
+
* duration: currentUsage.compute.total.durationMs,
|
|
960
|
+
* });
|
|
961
|
+
*
|
|
962
|
+
* // You can see the base cost of the run, which is the cost of the run before any compute costs
|
|
963
|
+
* console.log("Total cost", {
|
|
964
|
+
* cost: currentUsage.totalCostInCents,
|
|
965
|
+
* baseCost: currentUsage.baseCostInCents,
|
|
966
|
+
* });
|
|
967
|
+
* },
|
|
968
|
+
* });
|
|
969
|
+
* ```
|
|
970
|
+
*/
|
|
971
|
+
getCurrent: () => {
|
|
972
|
+
const sample = usage$1.sample();
|
|
973
|
+
const machine = taskContext.ctx?.machine;
|
|
974
|
+
const run = taskContext.ctx?.run;
|
|
975
|
+
if (!sample) {
|
|
976
|
+
return {
|
|
977
|
+
compute: {
|
|
978
|
+
attempt: {
|
|
979
|
+
costInCents: 0,
|
|
980
|
+
durationMs: 0
|
|
981
|
+
},
|
|
982
|
+
total: {
|
|
983
|
+
costInCents: run?.costInCents ?? 0,
|
|
984
|
+
durationMs: run?.durationMs ?? 0
|
|
985
|
+
}
|
|
986
|
+
},
|
|
987
|
+
baseCostInCents: run?.baseCostInCents ?? 0,
|
|
988
|
+
totalCostInCents: (run?.costInCents ?? 0) + (run?.baseCostInCents ?? 0)
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
const currentCostInCents = machine?.centsPerMs ? sample.cpuTime * machine.centsPerMs : 0;
|
|
992
|
+
return {
|
|
993
|
+
compute: {
|
|
994
|
+
attempt: {
|
|
995
|
+
costInCents: currentCostInCents,
|
|
996
|
+
durationMs: sample.cpuTime
|
|
997
|
+
},
|
|
998
|
+
total: {
|
|
999
|
+
costInCents: (run?.costInCents ?? 0) + currentCostInCents,
|
|
1000
|
+
durationMs: (run?.durationMs ?? 0) + sample.cpuTime
|
|
1001
|
+
}
|
|
1002
|
+
},
|
|
1003
|
+
baseCostInCents: run?.baseCostInCents ?? 0,
|
|
1004
|
+
totalCostInCents: (run?.costInCents ?? 0) + currentCostInCents + (run?.baseCostInCents ?? 0)
|
|
1005
|
+
};
|
|
1006
|
+
},
|
|
1007
|
+
/**
|
|
1008
|
+
* Measure the cost and duration of a function.
|
|
1009
|
+
*
|
|
1010
|
+
* @example
|
|
1011
|
+
*
|
|
1012
|
+
* ```typescript
|
|
1013
|
+
* import { usage } from "@trigger.dev/sdk/v3";
|
|
1014
|
+
*
|
|
1015
|
+
* export const myTask = task({
|
|
1016
|
+
* id: "my-task",
|
|
1017
|
+
* run: async (payload, { ctx }) => {
|
|
1018
|
+
* const { result, compute } = await usage.measure(async () => {
|
|
1019
|
+
* // Do some work
|
|
1020
|
+
* return "result";
|
|
1021
|
+
* });
|
|
1022
|
+
*
|
|
1023
|
+
* console.log("Result", result);
|
|
1024
|
+
* console.log("Cost and duration", { cost: compute.costInCents, duration: compute.durationMs });
|
|
1025
|
+
* },
|
|
1026
|
+
* });
|
|
1027
|
+
* ```
|
|
1028
|
+
*/
|
|
1029
|
+
measure: async (cb) => {
|
|
1030
|
+
const measurement = usage$1.start();
|
|
1031
|
+
const result = await cb();
|
|
1032
|
+
const sample = usage$1.stop(measurement);
|
|
1033
|
+
const machine = taskContext.ctx?.machine;
|
|
1034
|
+
const costInCents = machine?.centsPerMs ? sample.cpuTime * machine.centsPerMs : 0;
|
|
1035
|
+
return {
|
|
1036
|
+
result,
|
|
1037
|
+
compute: {
|
|
1038
|
+
costInCents,
|
|
1039
|
+
durationMs: sample.cpuTime
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
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
|
+
|
|
1086
|
+
// src/v3/schedules/index.ts
|
|
1087
|
+
var schedules_exports = {};
|
|
1088
|
+
__export(schedules_exports, {
|
|
1089
|
+
activate: () => activate,
|
|
1090
|
+
create: () => create,
|
|
1091
|
+
deactivate: () => deactivate,
|
|
1092
|
+
del: () => del,
|
|
1093
|
+
list: () => list,
|
|
1094
|
+
retrieve: () => retrieve,
|
|
1095
|
+
task: () => task2,
|
|
1096
|
+
timezones: () => timezones,
|
|
1097
|
+
update: () => update
|
|
1098
|
+
});
|
|
1099
|
+
function task2(params) {
|
|
1100
|
+
const task3 = createTask(params);
|
|
1101
|
+
taskCatalog.updateTaskMetadata(task3.id, {
|
|
1102
|
+
triggerSource: "schedule"
|
|
1103
|
+
});
|
|
1104
|
+
return task3;
|
|
1105
|
+
}
|
|
1106
|
+
__name(task2, "task");
|
|
1107
|
+
function create(options) {
|
|
1108
|
+
const apiClient = apiClientManager.client;
|
|
1109
|
+
if (!apiClient) {
|
|
1110
|
+
throw apiClientMissingError();
|
|
1111
|
+
}
|
|
1112
|
+
return apiClient.createSchedule(options);
|
|
1113
|
+
}
|
|
1114
|
+
__name(create, "create");
|
|
1115
|
+
function retrieve(scheduleId) {
|
|
1116
|
+
const apiClient = apiClientManager.client;
|
|
1117
|
+
if (!apiClient) {
|
|
1118
|
+
throw apiClientMissingError();
|
|
1119
|
+
}
|
|
1120
|
+
return apiClient.retrieveSchedule(scheduleId);
|
|
1121
|
+
}
|
|
1122
|
+
__name(retrieve, "retrieve");
|
|
1123
|
+
function update(scheduleId, options) {
|
|
1124
|
+
const apiClient = apiClientManager.client;
|
|
1125
|
+
if (!apiClient) {
|
|
1126
|
+
throw apiClientMissingError();
|
|
1127
|
+
}
|
|
1128
|
+
return apiClient.updateSchedule(scheduleId, options);
|
|
1129
|
+
}
|
|
1130
|
+
__name(update, "update");
|
|
1131
|
+
function del(scheduleId) {
|
|
1132
|
+
const apiClient = apiClientManager.client;
|
|
1133
|
+
if (!apiClient) {
|
|
1134
|
+
throw apiClientMissingError();
|
|
1135
|
+
}
|
|
1136
|
+
return apiClient.deleteSchedule(scheduleId);
|
|
1137
|
+
}
|
|
1138
|
+
__name(del, "del");
|
|
1139
|
+
function deactivate(scheduleId) {
|
|
1140
|
+
const apiClient = apiClientManager.client;
|
|
1141
|
+
if (!apiClient) {
|
|
1142
|
+
throw apiClientMissingError();
|
|
1143
|
+
}
|
|
1144
|
+
return apiClient.deactivateSchedule(scheduleId);
|
|
1145
|
+
}
|
|
1146
|
+
__name(deactivate, "deactivate");
|
|
1147
|
+
function activate(scheduleId) {
|
|
1148
|
+
const apiClient = apiClientManager.client;
|
|
1149
|
+
if (!apiClient) {
|
|
1150
|
+
throw apiClientMissingError();
|
|
1151
|
+
}
|
|
1152
|
+
return apiClient.activateSchedule(scheduleId);
|
|
1153
|
+
}
|
|
1154
|
+
__name(activate, "activate");
|
|
1155
|
+
function list(options) {
|
|
1156
|
+
const apiClient = apiClientManager.client;
|
|
1157
|
+
if (!apiClient) {
|
|
1158
|
+
throw apiClientMissingError();
|
|
1159
|
+
}
|
|
1160
|
+
return apiClient.listSchedules(options);
|
|
1161
|
+
}
|
|
1162
|
+
__name(list, "list");
|
|
1163
|
+
function timezones(options) {
|
|
1164
|
+
const baseUrl = apiClientManager.baseURL;
|
|
1165
|
+
if (!baseUrl) {
|
|
1166
|
+
throw apiClientMissingError();
|
|
1167
|
+
}
|
|
1168
|
+
return zodfetch(TimezonesResult, `${baseUrl}/api/v1/timezones${options?.excludeUtc === true ? "?excludeUtc=true" : ""}`, {
|
|
1169
|
+
method: "GET",
|
|
1170
|
+
headers: {
|
|
1171
|
+
"Content-Type": "application/json"
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
__name(timezones, "timezones");
|
|
1176
|
+
|
|
1177
|
+
// src/v3/envvars.ts
|
|
1178
|
+
var envvars_exports = {};
|
|
1179
|
+
__export(envvars_exports, {
|
|
1180
|
+
create: () => create2,
|
|
1181
|
+
del: () => del2,
|
|
1182
|
+
list: () => list2,
|
|
1183
|
+
retrieve: () => retrieve2,
|
|
1184
|
+
update: () => update2,
|
|
1185
|
+
upload: () => upload
|
|
1186
|
+
});
|
|
1187
|
+
function upload(projectRefOrParams, slug, params) {
|
|
1188
|
+
let $projectRef;
|
|
1189
|
+
let $params;
|
|
1190
|
+
let $slug;
|
|
1191
|
+
if (taskContext.ctx) {
|
|
1192
|
+
if (typeof projectRefOrParams === "string") {
|
|
1193
|
+
$projectRef = projectRefOrParams;
|
|
1194
|
+
$slug = slug ?? taskContext.ctx.environment.slug;
|
|
1195
|
+
if (!params) {
|
|
1196
|
+
throw new Error("params is required");
|
|
1197
|
+
}
|
|
1198
|
+
$params = params;
|
|
1199
|
+
} else {
|
|
1200
|
+
$params = projectRefOrParams;
|
|
1201
|
+
$projectRef = taskContext.ctx.project.ref;
|
|
1202
|
+
$slug = taskContext.ctx.environment.slug;
|
|
1203
|
+
}
|
|
1204
|
+
} else {
|
|
1205
|
+
if (typeof projectRefOrParams !== "string") {
|
|
1206
|
+
throw new Error("projectRef is required");
|
|
1207
|
+
}
|
|
1208
|
+
if (!slug) {
|
|
1209
|
+
throw new Error("slug is required");
|
|
1210
|
+
}
|
|
1211
|
+
if (!params) {
|
|
1212
|
+
throw new Error("params is required");
|
|
1213
|
+
}
|
|
1214
|
+
$projectRef = projectRefOrParams;
|
|
1215
|
+
$slug = slug;
|
|
1216
|
+
$params = params;
|
|
1217
|
+
}
|
|
1218
|
+
const apiClient = apiClientManager.client;
|
|
1219
|
+
if (!apiClient) {
|
|
1220
|
+
throw apiClientMissingError();
|
|
1221
|
+
}
|
|
1222
|
+
return apiClient.importEnvVars($projectRef, $slug, $params);
|
|
1223
|
+
}
|
|
1224
|
+
__name(upload, "upload");
|
|
1225
|
+
function list2(projectRef, slug) {
|
|
1226
|
+
const $projectRef = projectRef ?? taskContext.ctx?.project.ref;
|
|
1227
|
+
const $slug = slug ?? taskContext.ctx?.environment.slug;
|
|
1228
|
+
if (!$projectRef) {
|
|
1229
|
+
throw new Error("projectRef is required");
|
|
1230
|
+
}
|
|
1231
|
+
if (!$slug) {
|
|
1232
|
+
throw new Error("slug is required");
|
|
1233
|
+
}
|
|
1234
|
+
const apiClient = apiClientManager.client;
|
|
1235
|
+
if (!apiClient) {
|
|
1236
|
+
throw apiClientMissingError();
|
|
1237
|
+
}
|
|
1238
|
+
return apiClient.listEnvVars($projectRef, $slug);
|
|
1239
|
+
}
|
|
1240
|
+
__name(list2, "list");
|
|
1241
|
+
function create2(projectRefOrParams, slug, params) {
|
|
1242
|
+
let $projectRef;
|
|
1243
|
+
let $slug;
|
|
1244
|
+
let $params;
|
|
1245
|
+
if (taskContext.ctx) {
|
|
1246
|
+
if (typeof projectRefOrParams === "string") {
|
|
1247
|
+
$projectRef = projectRefOrParams;
|
|
1248
|
+
$slug = slug ?? taskContext.ctx.environment.slug;
|
|
1249
|
+
if (!params) {
|
|
1250
|
+
throw new Error("params is required");
|
|
1251
|
+
}
|
|
1252
|
+
$params = params;
|
|
1253
|
+
} else {
|
|
1254
|
+
$params = projectRefOrParams;
|
|
1255
|
+
$projectRef = taskContext.ctx.project.ref;
|
|
1256
|
+
$slug = taskContext.ctx.environment.slug;
|
|
1257
|
+
}
|
|
1258
|
+
} else {
|
|
1259
|
+
if (typeof projectRefOrParams !== "string") {
|
|
1260
|
+
throw new Error("projectRef is required");
|
|
1261
|
+
}
|
|
1262
|
+
if (!slug) {
|
|
1263
|
+
throw new Error("slug is required");
|
|
1264
|
+
}
|
|
1265
|
+
if (!params) {
|
|
1266
|
+
throw new Error("params is required");
|
|
1267
|
+
}
|
|
1268
|
+
$projectRef = projectRefOrParams;
|
|
1269
|
+
$slug = slug;
|
|
1270
|
+
$params = params;
|
|
1271
|
+
}
|
|
1272
|
+
const apiClient = apiClientManager.client;
|
|
1273
|
+
if (!apiClient) {
|
|
1274
|
+
throw apiClientMissingError();
|
|
1275
|
+
}
|
|
1276
|
+
return apiClient.createEnvVar($projectRef, $slug, $params);
|
|
1277
|
+
}
|
|
1278
|
+
__name(create2, "create");
|
|
1279
|
+
function retrieve2(projectRefOrName, slug, name) {
|
|
1280
|
+
let $projectRef;
|
|
1281
|
+
let $slug;
|
|
1282
|
+
let $name;
|
|
1283
|
+
if (typeof name === "string") {
|
|
1284
|
+
$projectRef = projectRefOrName;
|
|
1285
|
+
$slug = slug;
|
|
1286
|
+
$name = name;
|
|
1287
|
+
} else {
|
|
1288
|
+
$projectRef = taskContext.ctx?.project.ref;
|
|
1289
|
+
$slug = taskContext.ctx?.environment.slug;
|
|
1290
|
+
$name = projectRefOrName;
|
|
1291
|
+
}
|
|
1292
|
+
if (!$projectRef) {
|
|
1293
|
+
throw new Error("projectRef is required");
|
|
1294
|
+
}
|
|
1295
|
+
if (!$slug) {
|
|
1296
|
+
throw new Error("slug is required");
|
|
1297
|
+
}
|
|
1298
|
+
const apiClient = apiClientManager.client;
|
|
1299
|
+
if (!apiClient) {
|
|
1300
|
+
throw apiClientMissingError();
|
|
1301
|
+
}
|
|
1302
|
+
return apiClient.retrieveEnvVar($projectRef, $slug, $name);
|
|
1303
|
+
}
|
|
1304
|
+
__name(retrieve2, "retrieve");
|
|
1305
|
+
function del2(projectRefOrName, slug, name) {
|
|
1306
|
+
let $projectRef;
|
|
1307
|
+
let $slug;
|
|
1308
|
+
let $name;
|
|
1309
|
+
if (typeof name === "string") {
|
|
1310
|
+
$projectRef = projectRefOrName;
|
|
1311
|
+
$slug = slug;
|
|
1312
|
+
$name = name;
|
|
1313
|
+
} else {
|
|
1314
|
+
$projectRef = taskContext.ctx?.project.ref;
|
|
1315
|
+
$slug = taskContext.ctx?.environment.slug;
|
|
1316
|
+
$name = projectRefOrName;
|
|
1317
|
+
}
|
|
1318
|
+
if (!$projectRef) {
|
|
1319
|
+
throw new Error("projectRef is required");
|
|
1320
|
+
}
|
|
1321
|
+
if (!$slug) {
|
|
1322
|
+
throw new Error("slug is required");
|
|
1323
|
+
}
|
|
1324
|
+
const apiClient = apiClientManager.client;
|
|
1325
|
+
if (!apiClient) {
|
|
1326
|
+
throw apiClientMissingError();
|
|
1327
|
+
}
|
|
1328
|
+
return apiClient.deleteEnvVar($projectRef, $slug, $name);
|
|
1329
|
+
}
|
|
1330
|
+
__name(del2, "del");
|
|
1331
|
+
function update2(projectRefOrName, slugOrParams, name, params) {
|
|
1332
|
+
let $projectRef;
|
|
1333
|
+
let $slug;
|
|
1334
|
+
let $name;
|
|
1335
|
+
let $params;
|
|
1336
|
+
if (taskContext.ctx) {
|
|
1337
|
+
if (typeof slugOrParams === "string") {
|
|
1338
|
+
$projectRef = slugOrParams;
|
|
1339
|
+
$slug = slugOrParams ?? taskContext.ctx.environment.slug;
|
|
1340
|
+
$name = name;
|
|
1341
|
+
if (!params) {
|
|
1342
|
+
throw new Error("params is required");
|
|
1343
|
+
}
|
|
1344
|
+
$params = params;
|
|
1345
|
+
} else {
|
|
1346
|
+
$params = slugOrParams;
|
|
1347
|
+
$projectRef = taskContext.ctx.project.ref;
|
|
1348
|
+
$slug = taskContext.ctx.environment.slug;
|
|
1349
|
+
$name = projectRefOrName;
|
|
1350
|
+
}
|
|
1351
|
+
} else {
|
|
1352
|
+
if (typeof slugOrParams !== "string") {
|
|
1353
|
+
throw new Error("slug is required");
|
|
1354
|
+
}
|
|
1355
|
+
if (!projectRefOrName) {
|
|
1356
|
+
throw new Error("projectRef is required");
|
|
1357
|
+
}
|
|
1358
|
+
if (!params) {
|
|
1359
|
+
throw new Error("params is required");
|
|
1360
|
+
}
|
|
1361
|
+
$projectRef = projectRefOrName;
|
|
1362
|
+
$slug = slugOrParams;
|
|
1363
|
+
$name = name;
|
|
1364
|
+
$params = params;
|
|
1365
|
+
}
|
|
1366
|
+
const apiClient = apiClientManager.client;
|
|
1367
|
+
if (!apiClient) {
|
|
1368
|
+
throw apiClientMissingError();
|
|
1369
|
+
}
|
|
1370
|
+
return apiClient.updateEnvVar($projectRef, $slug, $name, $params);
|
|
1371
|
+
}
|
|
1372
|
+
__name(update2, "update");
|
|
1373
|
+
|
|
1374
|
+
// src/v3/index.ts
|
|
1375
|
+
function configure(options) {
|
|
1376
|
+
apiClientManager.setGlobalAPIClientConfiguration(options);
|
|
1377
|
+
}
|
|
1378
|
+
__name(configure, "configure");
|
|
880
1379
|
|
|
881
|
-
export { InMemoryCache, createCache, retry, task, wait };
|
|
1380
|
+
export { InMemoryCache, configure, createCache, envvars_exports as envvars, queue, retry, runs, schedules_exports as schedules, task, usage, wait };
|
|
882
1381
|
//# sourceMappingURL=out.js.map
|
|
883
1382
|
//# sourceMappingURL=index.mjs.map
|