@trigger.dev/core 3.0.0-beta.3 → 3.0.0-beta.31
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/catalog-KbyTBoap.d.ts +2496 -0
- package/dist/catalog-ck7x04PV.d.mts +2496 -0
- package/dist/manager-WNMVbgHf.d.mts +1158 -0
- package/dist/manager-WNMVbgHf.d.ts +1158 -0
- package/dist/messages-vq7Bk4Ap.d.mts +12838 -0
- package/dist/messages-vq7Bk4Ap.d.ts +12838 -0
- package/dist/v3/dev/index.d.mts +28 -0
- package/dist/v3/dev/index.d.ts +28 -0
- package/dist/v3/dev/index.js +93 -0
- package/dist/v3/dev/index.js.map +1 -0
- package/dist/v3/dev/index.mjs +91 -0
- package/dist/v3/dev/index.mjs.map +1 -0
- package/dist/v3/index.d.mts +850 -16919
- package/dist/v3/index.d.ts +850 -16919
- package/dist/v3/index.js +1676 -2763
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +1681 -2767
- package/dist/v3/index.mjs.map +1 -1
- package/dist/v3/otel/index.js +83 -45
- package/dist/v3/otel/index.js.map +1 -1
- package/dist/v3/otel/index.mjs +83 -45
- package/dist/v3/otel/index.mjs.map +1 -1
- package/dist/v3/prod/index.d.mts +45 -0
- package/dist/v3/prod/index.d.ts +45 -0
- package/dist/v3/prod/index.js +229 -0
- package/dist/v3/prod/index.js.map +1 -0
- package/dist/v3/prod/index.mjs +227 -0
- package/dist/v3/prod/index.mjs.map +1 -0
- package/dist/v3/utils/structuredLogger.d.mts +31 -0
- package/dist/v3/utils/structuredLogger.d.ts +31 -0
- package/dist/v3/utils/structuredLogger.js +88 -0
- package/dist/v3/utils/structuredLogger.js.map +1 -0
- package/dist/v3/utils/structuredLogger.mjs +86 -0
- package/dist/v3/utils/structuredLogger.mjs.map +1 -0
- package/dist/v3/workers/index.d.mts +95 -0
- package/dist/v3/workers/index.d.ts +95 -0
- package/dist/v3/workers/index.js +2631 -0
- package/dist/v3/workers/index.js.map +1 -0
- package/dist/v3/workers/index.mjs +2615 -0
- package/dist/v3/workers/index.mjs.map +1 -0
- package/dist/v3/zodIpc.d.mts +32 -0
- package/dist/v3/zodIpc.d.ts +32 -0
- package/dist/v3/zodIpc.js +268 -0
- package/dist/v3/zodIpc.js.map +1 -0
- package/dist/v3/zodIpc.mjs +266 -0
- package/dist/v3/zodIpc.mjs.map +1 -0
- package/dist/v3/zodMessageHandler.d.mts +69 -0
- package/dist/v3/zodMessageHandler.d.ts +69 -0
- package/dist/v3/zodMessageHandler.js +168 -0
- package/dist/v3/zodMessageHandler.js.map +1 -0
- package/dist/v3/zodMessageHandler.mjs +163 -0
- package/dist/v3/zodMessageHandler.mjs.map +1 -0
- package/dist/v3/zodNamespace.d.mts +3663 -0
- package/dist/v3/zodNamespace.d.ts +3663 -0
- package/dist/v3/zodNamespace.js +356 -0
- package/dist/v3/zodNamespace.js.map +1 -0
- package/dist/v3/zodNamespace.mjs +354 -0
- package/dist/v3/zodNamespace.mjs.map +1 -0
- package/dist/v3/zodSocket.d.mts +88 -0
- package/dist/v3/zodSocket.d.ts +88 -0
- package/dist/v3/zodSocket.js +309 -0
- package/dist/v3/zodSocket.js.map +1 -0
- package/dist/v3/zodSocket.mjs +305 -0
- package/dist/v3/zodSocket.mjs.map +1 -0
- package/package.json +72 -7
|
@@ -0,0 +1,2615 @@
|
|
|
1
|
+
import { SpanStatusCode, DiagLogLevel, diag, DiagConsoleLogger, propagation, context, SpanKind } from '@opentelemetry/api';
|
|
2
|
+
import { logs, SeverityNumber } from '@opentelemetry/api-logs';
|
|
3
|
+
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';
|
|
4
|
+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
5
|
+
import { registerInstrumentations } from '@opentelemetry/instrumentation';
|
|
6
|
+
import { Resource, detectResourcesSync, processDetectorSync } from '@opentelemetry/resources';
|
|
7
|
+
import { LoggerProvider, BatchLogRecordProcessor, SimpleLogRecordProcessor } from '@opentelemetry/sdk-logs';
|
|
8
|
+
import { NodeTracerProvider, BatchSpanProcessor, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node';
|
|
9
|
+
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { fromZodError } from 'zod-validation-error';
|
|
12
|
+
import { PreciseDate } from '@google-cloud/precise-date';
|
|
13
|
+
import util from 'node:util';
|
|
14
|
+
|
|
15
|
+
var __defProp = Object.defineProperty;
|
|
16
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
18
|
+
var __publicField = (obj, key, value) => {
|
|
19
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
var __accessCheck = (obj, member, msg) => {
|
|
23
|
+
if (!member.has(obj))
|
|
24
|
+
throw TypeError("Cannot " + msg);
|
|
25
|
+
};
|
|
26
|
+
var __privateGet = (obj, member, getter) => {
|
|
27
|
+
__accessCheck(obj, member, "read from private field");
|
|
28
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
29
|
+
};
|
|
30
|
+
var __privateAdd = (obj, member, value) => {
|
|
31
|
+
if (member.has(obj))
|
|
32
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
33
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
34
|
+
};
|
|
35
|
+
var __privateMethod = (obj, member, method) => {
|
|
36
|
+
__accessCheck(obj, member, "access private method");
|
|
37
|
+
return method;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/v3/errors.ts
|
|
41
|
+
function parseError(error) {
|
|
42
|
+
if (error instanceof Error) {
|
|
43
|
+
return {
|
|
44
|
+
type: "BUILT_IN_ERROR",
|
|
45
|
+
name: error.name,
|
|
46
|
+
message: error.message,
|
|
47
|
+
stackTrace: error.stack ?? ""
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (typeof error === "string") {
|
|
51
|
+
return {
|
|
52
|
+
type: "STRING_ERROR",
|
|
53
|
+
raw: error
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
return {
|
|
58
|
+
type: "CUSTOM_ERROR",
|
|
59
|
+
raw: JSON.stringify(error)
|
|
60
|
+
};
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return {
|
|
63
|
+
type: "CUSTOM_ERROR",
|
|
64
|
+
raw: String(error)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
__name(parseError, "parseError");
|
|
69
|
+
|
|
70
|
+
// src/v3/limits.ts
|
|
71
|
+
var OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT = 256;
|
|
72
|
+
var OTEL_LOG_ATTRIBUTE_COUNT_LIMIT = 256;
|
|
73
|
+
var OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = 1028;
|
|
74
|
+
var OTEL_LOG_ATTRIBUTE_VALUE_LENGTH_LIMIT = 1028;
|
|
75
|
+
var OTEL_SPAN_EVENT_COUNT_LIMIT = 10;
|
|
76
|
+
var OTEL_LINK_COUNT_LIMIT = 2;
|
|
77
|
+
var OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT = 10;
|
|
78
|
+
var OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT = 10;
|
|
79
|
+
var OFFLOAD_IO_PACKET_LENGTH_LIMIT = 128 * 1024;
|
|
80
|
+
|
|
81
|
+
// src/v3/semanticInternalAttributes.ts
|
|
82
|
+
var SemanticInternalAttributes = {
|
|
83
|
+
ENVIRONMENT_ID: "ctx.environment.id",
|
|
84
|
+
ENVIRONMENT_TYPE: "ctx.environment.type",
|
|
85
|
+
ORGANIZATION_ID: "ctx.organization.id",
|
|
86
|
+
ORGANIZATION_SLUG: "ctx.organization.slug",
|
|
87
|
+
ORGANIZATION_NAME: "ctx.organization.name",
|
|
88
|
+
PROJECT_ID: "ctx.project.id",
|
|
89
|
+
PROJECT_REF: "ctx.project.ref",
|
|
90
|
+
PROJECT_NAME: "ctx.project.title",
|
|
91
|
+
PROJECT_DIR: "project.dir",
|
|
92
|
+
ATTEMPT_ID: "ctx.attempt.id",
|
|
93
|
+
ATTEMPT_NUMBER: "ctx.attempt.number",
|
|
94
|
+
RUN_ID: "ctx.run.id",
|
|
95
|
+
RUN_IS_TEST: "ctx.run.isTest",
|
|
96
|
+
BATCH_ID: "ctx.batch.id",
|
|
97
|
+
TASK_SLUG: "ctx.task.id",
|
|
98
|
+
TASK_PATH: "ctx.task.filePath",
|
|
99
|
+
TASK_EXPORT_NAME: "ctx.task.exportName",
|
|
100
|
+
QUEUE_NAME: "ctx.queue.name",
|
|
101
|
+
QUEUE_ID: "ctx.queue.id",
|
|
102
|
+
SPAN_PARTIAL: "$span.partial",
|
|
103
|
+
SPAN_ID: "$span.span_id",
|
|
104
|
+
OUTPUT: "$output",
|
|
105
|
+
OUTPUT_TYPE: "$mime_type_output",
|
|
106
|
+
STYLE: "$style",
|
|
107
|
+
STYLE_ICON: "$style.icon",
|
|
108
|
+
STYLE_VARIANT: "$style.variant",
|
|
109
|
+
STYLE_ACCESSORY: "$style.accessory",
|
|
110
|
+
METADATA: "$metadata",
|
|
111
|
+
TRIGGER: "$trigger",
|
|
112
|
+
PAYLOAD: "$payload",
|
|
113
|
+
PAYLOAD_TYPE: "$mime_type_payload",
|
|
114
|
+
SHOW: "$show",
|
|
115
|
+
SHOW_ACTIONS: "$show.actions",
|
|
116
|
+
WORKER_ID: "worker.id",
|
|
117
|
+
WORKER_VERSION: "worker.version",
|
|
118
|
+
CLI_VERSION: "cli.version",
|
|
119
|
+
SDK_VERSION: "sdk.version",
|
|
120
|
+
SDK_LANGUAGE: "sdk.language",
|
|
121
|
+
RETRY_AT: "retry.at",
|
|
122
|
+
RETRY_DELAY: "retry.delay",
|
|
123
|
+
RETRY_COUNT: "retry.count",
|
|
124
|
+
LINK_TITLE: "$link.title",
|
|
125
|
+
IDEMPOTENCY_KEY: "ctx.run.idempotencyKey"
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// src/v3/utils/flattenAttributes.ts
|
|
129
|
+
var NULL_SENTINEL = "$@null((";
|
|
130
|
+
function flattenAttributes(obj, prefix) {
|
|
131
|
+
const result = {};
|
|
132
|
+
if (obj === void 0) {
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
if (obj === null) {
|
|
136
|
+
result[prefix || ""] = NULL_SENTINEL;
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
if (typeof obj === "string") {
|
|
140
|
+
result[prefix || ""] = obj;
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
if (typeof obj === "number") {
|
|
144
|
+
result[prefix || ""] = obj;
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
if (typeof obj === "boolean") {
|
|
148
|
+
result[prefix || ""] = obj;
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
152
|
+
const newPrefix = `${prefix ? `${prefix}.` : ""}${Array.isArray(obj) ? `[${key}]` : key}`;
|
|
153
|
+
if (Array.isArray(value)) {
|
|
154
|
+
for (let i = 0; i < value.length; i++) {
|
|
155
|
+
if (typeof value[i] === "object" && value[i] !== null) {
|
|
156
|
+
Object.assign(result, flattenAttributes(value[i], `${newPrefix}.[${i}]`));
|
|
157
|
+
} else {
|
|
158
|
+
if (value[i] === null) {
|
|
159
|
+
result[`${newPrefix}.[${i}]`] = NULL_SENTINEL;
|
|
160
|
+
} else {
|
|
161
|
+
result[`${newPrefix}.[${i}]`] = value[i];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
} else if (isRecord(value)) {
|
|
166
|
+
Object.assign(result, flattenAttributes(value, newPrefix));
|
|
167
|
+
} else {
|
|
168
|
+
if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
|
|
169
|
+
result[newPrefix] = value;
|
|
170
|
+
} else if (value === null) {
|
|
171
|
+
result[newPrefix] = NULL_SENTINEL;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
__name(flattenAttributes, "flattenAttributes");
|
|
178
|
+
function isRecord(value) {
|
|
179
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
180
|
+
}
|
|
181
|
+
__name(isRecord, "isRecord");
|
|
182
|
+
|
|
183
|
+
// src/v3/utils/platform.ts
|
|
184
|
+
var _globalThis = typeof globalThis === "object" ? globalThis : global;
|
|
185
|
+
|
|
186
|
+
// src/v3/utils/globals.ts
|
|
187
|
+
var GLOBAL_TRIGGER_DOT_DEV_KEY = Symbol.for(`dev.trigger.ts.api`);
|
|
188
|
+
var _global = _globalThis;
|
|
189
|
+
function registerGlobal(type, instance, allowOverride = false) {
|
|
190
|
+
const api = _global[GLOBAL_TRIGGER_DOT_DEV_KEY] = _global[GLOBAL_TRIGGER_DOT_DEV_KEY] ?? {};
|
|
191
|
+
if (!allowOverride && api[type]) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
api[type] = instance;
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
__name(registerGlobal, "registerGlobal");
|
|
198
|
+
function getGlobal(type) {
|
|
199
|
+
return _global[GLOBAL_TRIGGER_DOT_DEV_KEY]?.[type];
|
|
200
|
+
}
|
|
201
|
+
__name(getGlobal, "getGlobal");
|
|
202
|
+
function unregisterGlobal(type) {
|
|
203
|
+
const api = _global[GLOBAL_TRIGGER_DOT_DEV_KEY];
|
|
204
|
+
if (api) {
|
|
205
|
+
delete api[type];
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
__name(unregisterGlobal, "unregisterGlobal");
|
|
209
|
+
|
|
210
|
+
// src/v3/taskContext/index.ts
|
|
211
|
+
var API_NAME = "task-context";
|
|
212
|
+
var _getTaskContext, getTaskContext_fn;
|
|
213
|
+
var _TaskContextAPI = class _TaskContextAPI {
|
|
214
|
+
constructor() {
|
|
215
|
+
__privateAdd(this, _getTaskContext);
|
|
216
|
+
}
|
|
217
|
+
static getInstance() {
|
|
218
|
+
if (!this._instance) {
|
|
219
|
+
this._instance = new _TaskContextAPI();
|
|
220
|
+
}
|
|
221
|
+
return this._instance;
|
|
222
|
+
}
|
|
223
|
+
get isInsideTask() {
|
|
224
|
+
return __privateMethod(this, _getTaskContext, getTaskContext_fn).call(this) !== void 0;
|
|
225
|
+
}
|
|
226
|
+
get ctx() {
|
|
227
|
+
return __privateMethod(this, _getTaskContext, getTaskContext_fn).call(this)?.ctx;
|
|
228
|
+
}
|
|
229
|
+
get worker() {
|
|
230
|
+
return __privateMethod(this, _getTaskContext, getTaskContext_fn).call(this)?.worker;
|
|
231
|
+
}
|
|
232
|
+
get attributes() {
|
|
233
|
+
if (this.ctx) {
|
|
234
|
+
return {
|
|
235
|
+
...this.contextAttributes,
|
|
236
|
+
...this.workerAttributes
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return {};
|
|
240
|
+
}
|
|
241
|
+
get workerAttributes() {
|
|
242
|
+
if (this.worker) {
|
|
243
|
+
return {
|
|
244
|
+
[SemanticInternalAttributes.WORKER_ID]: this.worker.id,
|
|
245
|
+
[SemanticInternalAttributes.WORKER_VERSION]: this.worker.version
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return {};
|
|
249
|
+
}
|
|
250
|
+
get contextAttributes() {
|
|
251
|
+
if (this.ctx) {
|
|
252
|
+
return {
|
|
253
|
+
[SemanticInternalAttributes.ATTEMPT_ID]: this.ctx.attempt.id,
|
|
254
|
+
[SemanticInternalAttributes.ATTEMPT_NUMBER]: this.ctx.attempt.number,
|
|
255
|
+
[SemanticInternalAttributes.TASK_SLUG]: this.ctx.task.id,
|
|
256
|
+
[SemanticInternalAttributes.TASK_PATH]: this.ctx.task.filePath,
|
|
257
|
+
[SemanticInternalAttributes.TASK_EXPORT_NAME]: this.ctx.task.exportName,
|
|
258
|
+
[SemanticInternalAttributes.QUEUE_NAME]: this.ctx.queue.name,
|
|
259
|
+
[SemanticInternalAttributes.QUEUE_ID]: this.ctx.queue.id,
|
|
260
|
+
[SemanticInternalAttributes.ENVIRONMENT_ID]: this.ctx.environment.id,
|
|
261
|
+
[SemanticInternalAttributes.ENVIRONMENT_TYPE]: this.ctx.environment.type,
|
|
262
|
+
[SemanticInternalAttributes.ORGANIZATION_ID]: this.ctx.organization.id,
|
|
263
|
+
[SemanticInternalAttributes.PROJECT_ID]: this.ctx.project.id,
|
|
264
|
+
[SemanticInternalAttributes.PROJECT_REF]: this.ctx.project.ref,
|
|
265
|
+
[SemanticInternalAttributes.PROJECT_NAME]: this.ctx.project.name,
|
|
266
|
+
[SemanticInternalAttributes.RUN_ID]: this.ctx.run.id,
|
|
267
|
+
[SemanticInternalAttributes.RUN_IS_TEST]: this.ctx.run.isTest,
|
|
268
|
+
[SemanticInternalAttributes.ORGANIZATION_SLUG]: this.ctx.organization.slug,
|
|
269
|
+
[SemanticInternalAttributes.ORGANIZATION_NAME]: this.ctx.organization.name,
|
|
270
|
+
[SemanticInternalAttributes.BATCH_ID]: this.ctx.batch?.id,
|
|
271
|
+
[SemanticInternalAttributes.IDEMPOTENCY_KEY]: this.ctx.run.idempotencyKey
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
return {};
|
|
275
|
+
}
|
|
276
|
+
disable() {
|
|
277
|
+
unregisterGlobal(API_NAME);
|
|
278
|
+
}
|
|
279
|
+
setGlobalTaskContext(taskContext2) {
|
|
280
|
+
return registerGlobal(API_NAME, taskContext2);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
_getTaskContext = new WeakSet();
|
|
284
|
+
getTaskContext_fn = /* @__PURE__ */ __name(function() {
|
|
285
|
+
return getGlobal(API_NAME);
|
|
286
|
+
}, "#getTaskContext");
|
|
287
|
+
__name(_TaskContextAPI, "TaskContextAPI");
|
|
288
|
+
var TaskContextAPI = _TaskContextAPI;
|
|
289
|
+
|
|
290
|
+
// src/v3/task-context-api.ts
|
|
291
|
+
var taskContext = TaskContextAPI.getInstance();
|
|
292
|
+
|
|
293
|
+
// src/v3/taskContext/otelProcessors.ts
|
|
294
|
+
var _TaskContextSpanProcessor = class _TaskContextSpanProcessor {
|
|
295
|
+
constructor(innerProcessor) {
|
|
296
|
+
this._innerProcessor = innerProcessor;
|
|
297
|
+
}
|
|
298
|
+
// Called when a span starts
|
|
299
|
+
onStart(span, parentContext) {
|
|
300
|
+
if (taskContext.ctx) {
|
|
301
|
+
span.setAttributes(flattenAttributes({
|
|
302
|
+
[SemanticInternalAttributes.ATTEMPT_ID]: taskContext.ctx.attempt.id,
|
|
303
|
+
[SemanticInternalAttributes.ATTEMPT_NUMBER]: taskContext.ctx.attempt.number
|
|
304
|
+
}, SemanticInternalAttributes.METADATA));
|
|
305
|
+
}
|
|
306
|
+
this._innerProcessor.onStart(span, parentContext);
|
|
307
|
+
}
|
|
308
|
+
// Delegate the rest of the methods to the wrapped processor
|
|
309
|
+
onEnd(span) {
|
|
310
|
+
this._innerProcessor.onEnd(span);
|
|
311
|
+
}
|
|
312
|
+
shutdown() {
|
|
313
|
+
return this._innerProcessor.shutdown();
|
|
314
|
+
}
|
|
315
|
+
forceFlush() {
|
|
316
|
+
return this._innerProcessor.forceFlush();
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
__name(_TaskContextSpanProcessor, "TaskContextSpanProcessor");
|
|
320
|
+
var TaskContextSpanProcessor = _TaskContextSpanProcessor;
|
|
321
|
+
var _TaskContextLogProcessor = class _TaskContextLogProcessor {
|
|
322
|
+
constructor(innerProcessor) {
|
|
323
|
+
this._innerProcessor = innerProcessor;
|
|
324
|
+
}
|
|
325
|
+
forceFlush() {
|
|
326
|
+
return this._innerProcessor.forceFlush();
|
|
327
|
+
}
|
|
328
|
+
onEmit(logRecord, context2) {
|
|
329
|
+
if (taskContext.ctx) {
|
|
330
|
+
logRecord.setAttributes(flattenAttributes({
|
|
331
|
+
[SemanticInternalAttributes.ATTEMPT_ID]: taskContext.ctx.attempt.id,
|
|
332
|
+
[SemanticInternalAttributes.ATTEMPT_NUMBER]: taskContext.ctx.attempt.number
|
|
333
|
+
}, SemanticInternalAttributes.METADATA));
|
|
334
|
+
}
|
|
335
|
+
this._innerProcessor.onEmit(logRecord, context2);
|
|
336
|
+
}
|
|
337
|
+
shutdown() {
|
|
338
|
+
return this._innerProcessor.shutdown();
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
__name(_TaskContextLogProcessor, "TaskContextLogProcessor");
|
|
342
|
+
var TaskContextLogProcessor = _TaskContextLogProcessor;
|
|
343
|
+
|
|
344
|
+
// src/v3/utils/getEnv.ts
|
|
345
|
+
function getEnvVar(name) {
|
|
346
|
+
if (typeof process !== "undefined" && typeof process.env === "object" && process.env !== null) {
|
|
347
|
+
return process.env[name];
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
__name(getEnvVar, "getEnvVar");
|
|
351
|
+
|
|
352
|
+
// src/v3/otel/tracingSDK.ts
|
|
353
|
+
var _a;
|
|
354
|
+
var AsyncResourceDetector = (_a = class {
|
|
355
|
+
constructor() {
|
|
356
|
+
__publicField(this, "_resolved", false);
|
|
357
|
+
this._promise = new Promise((resolver) => {
|
|
358
|
+
this._resolver = resolver;
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
detect(_config) {
|
|
362
|
+
return new Resource({}, this._promise);
|
|
363
|
+
}
|
|
364
|
+
resolveWithAttributes(attributes) {
|
|
365
|
+
if (!this._resolver) {
|
|
366
|
+
throw new Error("Resolver not available");
|
|
367
|
+
}
|
|
368
|
+
if (this._resolved) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
this._resolved = true;
|
|
372
|
+
this._resolver(attributes);
|
|
373
|
+
}
|
|
374
|
+
}, __name(_a, "AsyncResourceDetector"), _a);
|
|
375
|
+
var _TracingSDK = class _TracingSDK {
|
|
376
|
+
constructor(config) {
|
|
377
|
+
this.config = config;
|
|
378
|
+
this.asyncResourceDetector = new AsyncResourceDetector();
|
|
379
|
+
setLogLevel(config.diagLogLevel ?? "none");
|
|
380
|
+
const envResourceAttributesSerialized = getEnvVar("OTEL_RESOURCE_ATTRIBUTES");
|
|
381
|
+
const envResourceAttributes = envResourceAttributesSerialized ? JSON.parse(envResourceAttributesSerialized) : {};
|
|
382
|
+
const commonResources = detectResourcesSync({
|
|
383
|
+
detectors: [
|
|
384
|
+
this.asyncResourceDetector,
|
|
385
|
+
processDetectorSync
|
|
386
|
+
]
|
|
387
|
+
}).merge(new Resource({
|
|
388
|
+
[SemanticResourceAttributes.CLOUD_PROVIDER]: "trigger.dev",
|
|
389
|
+
[SemanticInternalAttributes.TRIGGER]: true
|
|
390
|
+
})).merge(config.resource ?? new Resource({})).merge(new Resource(envResourceAttributes));
|
|
391
|
+
const traceProvider = new NodeTracerProvider({
|
|
392
|
+
forceFlushTimeoutMillis: config.forceFlushTimeoutMillis ?? 500,
|
|
393
|
+
resource: commonResources,
|
|
394
|
+
spanLimits: {
|
|
395
|
+
attributeCountLimit: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
|
|
396
|
+
attributeValueLengthLimit: OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT,
|
|
397
|
+
eventCountLimit: OTEL_SPAN_EVENT_COUNT_LIMIT,
|
|
398
|
+
attributePerEventCountLimit: OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT,
|
|
399
|
+
linkCountLimit: OTEL_LINK_COUNT_LIMIT,
|
|
400
|
+
attributePerLinkCountLimit: OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
const spanExporter = new OTLPTraceExporter({
|
|
404
|
+
url: `${config.url}/v1/traces`,
|
|
405
|
+
timeoutMillis: config.forceFlushTimeoutMillis ?? 1e3
|
|
406
|
+
});
|
|
407
|
+
traceProvider.addSpanProcessor(new TaskContextSpanProcessor(getEnvVar("OTEL_BATCH_PROCESSING_ENABLED") === "1" ? new BatchSpanProcessor(spanExporter, {
|
|
408
|
+
maxExportBatchSize: parseInt(getEnvVar("OTEL_SPAN_MAX_EXPORT_BATCH_SIZE") ?? "64"),
|
|
409
|
+
scheduledDelayMillis: parseInt(getEnvVar("OTEL_SPAN_SCHEDULED_DELAY_MILLIS") ?? "200"),
|
|
410
|
+
exportTimeoutMillis: parseInt(getEnvVar("OTEL_SPAN_EXPORT_TIMEOUT_MILLIS") ?? "30000"),
|
|
411
|
+
maxQueueSize: parseInt(getEnvVar("OTEL_SPAN_MAX_QUEUE_SIZE") ?? "512")
|
|
412
|
+
}) : new SimpleSpanProcessor(spanExporter)));
|
|
413
|
+
traceProvider.register();
|
|
414
|
+
registerInstrumentations({
|
|
415
|
+
instrumentations: config.instrumentations ?? [],
|
|
416
|
+
tracerProvider: traceProvider
|
|
417
|
+
});
|
|
418
|
+
const logExporter = new OTLPLogExporter({
|
|
419
|
+
url: `${config.url}/v1/logs`
|
|
420
|
+
});
|
|
421
|
+
const loggerProvider = new LoggerProvider({
|
|
422
|
+
resource: commonResources,
|
|
423
|
+
logRecordLimits: {
|
|
424
|
+
attributeCountLimit: OTEL_LOG_ATTRIBUTE_COUNT_LIMIT,
|
|
425
|
+
attributeValueLengthLimit: OTEL_LOG_ATTRIBUTE_VALUE_LENGTH_LIMIT
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
loggerProvider.addLogRecordProcessor(new TaskContextLogProcessor(getEnvVar("OTEL_BATCH_PROCESSING_ENABLED") === "1" ? new BatchLogRecordProcessor(logExporter, {
|
|
429
|
+
maxExportBatchSize: parseInt(getEnvVar("OTEL_LOG_MAX_EXPORT_BATCH_SIZE") ?? "64"),
|
|
430
|
+
scheduledDelayMillis: parseInt(getEnvVar("OTEL_LOG_SCHEDULED_DELAY_MILLIS") ?? "200"),
|
|
431
|
+
exportTimeoutMillis: parseInt(getEnvVar("OTEL_LOG_EXPORT_TIMEOUT_MILLIS") ?? "30000"),
|
|
432
|
+
maxQueueSize: parseInt(getEnvVar("OTEL_LOG_MAX_QUEUE_SIZE") ?? "512")
|
|
433
|
+
}) : new SimpleLogRecordProcessor(logExporter)));
|
|
434
|
+
this._logProvider = loggerProvider;
|
|
435
|
+
this._spanExporter = spanExporter;
|
|
436
|
+
this._traceProvider = traceProvider;
|
|
437
|
+
logs.setGlobalLoggerProvider(loggerProvider);
|
|
438
|
+
this.getLogger = loggerProvider.getLogger.bind(loggerProvider);
|
|
439
|
+
this.getTracer = traceProvider.getTracer.bind(traceProvider);
|
|
440
|
+
}
|
|
441
|
+
async flush() {
|
|
442
|
+
await this._traceProvider.forceFlush();
|
|
443
|
+
await this._logProvider.forceFlush();
|
|
444
|
+
}
|
|
445
|
+
async shutdown() {
|
|
446
|
+
await this._traceProvider.shutdown();
|
|
447
|
+
await this._logProvider.shutdown();
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
__name(_TracingSDK, "TracingSDK");
|
|
451
|
+
var TracingSDK = _TracingSDK;
|
|
452
|
+
function setLogLevel(level) {
|
|
453
|
+
let diagLogLevel;
|
|
454
|
+
switch (level) {
|
|
455
|
+
case "none":
|
|
456
|
+
diagLogLevel = DiagLogLevel.NONE;
|
|
457
|
+
break;
|
|
458
|
+
case "error":
|
|
459
|
+
diagLogLevel = DiagLogLevel.ERROR;
|
|
460
|
+
break;
|
|
461
|
+
case "warn":
|
|
462
|
+
diagLogLevel = DiagLogLevel.WARN;
|
|
463
|
+
break;
|
|
464
|
+
case "info":
|
|
465
|
+
diagLogLevel = DiagLogLevel.INFO;
|
|
466
|
+
break;
|
|
467
|
+
case "debug":
|
|
468
|
+
diagLogLevel = DiagLogLevel.DEBUG;
|
|
469
|
+
break;
|
|
470
|
+
case "verbose":
|
|
471
|
+
diagLogLevel = DiagLogLevel.VERBOSE;
|
|
472
|
+
break;
|
|
473
|
+
case "all":
|
|
474
|
+
diagLogLevel = DiagLogLevel.ALL;
|
|
475
|
+
break;
|
|
476
|
+
default:
|
|
477
|
+
diagLogLevel = DiagLogLevel.NONE;
|
|
478
|
+
}
|
|
479
|
+
diag.setLogger(new DiagConsoleLogger(), diagLogLevel);
|
|
480
|
+
}
|
|
481
|
+
__name(setLogLevel, "setLogLevel");
|
|
482
|
+
|
|
483
|
+
// src/v3/otel/index.ts
|
|
484
|
+
function recordSpanException(span, error) {
|
|
485
|
+
if (error instanceof Error) {
|
|
486
|
+
span.recordException(error);
|
|
487
|
+
} else if (typeof error === "string") {
|
|
488
|
+
span.recordException(new Error(error));
|
|
489
|
+
} else {
|
|
490
|
+
span.recordException(new Error(JSON.stringify(error)));
|
|
491
|
+
}
|
|
492
|
+
span.setStatus({
|
|
493
|
+
code: SpanStatusCode.ERROR
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
__name(recordSpanException, "recordSpanException");
|
|
497
|
+
var TaskRunBuiltInError = z.object({
|
|
498
|
+
type: z.literal("BUILT_IN_ERROR"),
|
|
499
|
+
name: z.string(),
|
|
500
|
+
message: z.string(),
|
|
501
|
+
stackTrace: z.string()
|
|
502
|
+
});
|
|
503
|
+
var TaskRunCustomErrorObject = z.object({
|
|
504
|
+
type: z.literal("CUSTOM_ERROR"),
|
|
505
|
+
raw: z.string()
|
|
506
|
+
});
|
|
507
|
+
var TaskRunStringError = z.object({
|
|
508
|
+
type: z.literal("STRING_ERROR"),
|
|
509
|
+
raw: z.string()
|
|
510
|
+
});
|
|
511
|
+
var TaskRunErrorCodes = {
|
|
512
|
+
COULD_NOT_FIND_EXECUTOR: "COULD_NOT_FIND_EXECUTOR",
|
|
513
|
+
COULD_NOT_FIND_TASK: "COULD_NOT_FIND_TASK",
|
|
514
|
+
CONFIGURED_INCORRECTLY: "CONFIGURED_INCORRECTLY",
|
|
515
|
+
TASK_ALREADY_RUNNING: "TASK_ALREADY_RUNNING",
|
|
516
|
+
TASK_EXECUTION_FAILED: "TASK_EXECUTION_FAILED",
|
|
517
|
+
TASK_EXECUTION_ABORTED: "TASK_EXECUTION_ABORTED",
|
|
518
|
+
TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE: "TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE",
|
|
519
|
+
TASK_RUN_CANCELLED: "TASK_RUN_CANCELLED",
|
|
520
|
+
TASK_OUTPUT_ERROR: "TASK_OUTPUT_ERROR",
|
|
521
|
+
HANDLE_ERROR_ERROR: "HANDLE_ERROR_ERROR",
|
|
522
|
+
GRACEFUL_EXIT_TIMEOUT: "GRACEFUL_EXIT_TIMEOUT"
|
|
523
|
+
};
|
|
524
|
+
var TaskRunInternalError = z.object({
|
|
525
|
+
type: z.literal("INTERNAL_ERROR"),
|
|
526
|
+
code: z.enum([
|
|
527
|
+
"COULD_NOT_FIND_EXECUTOR",
|
|
528
|
+
"COULD_NOT_FIND_TASK",
|
|
529
|
+
"CONFIGURED_INCORRECTLY",
|
|
530
|
+
"TASK_ALREADY_RUNNING",
|
|
531
|
+
"TASK_EXECUTION_FAILED",
|
|
532
|
+
"TASK_EXECUTION_ABORTED",
|
|
533
|
+
"TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE",
|
|
534
|
+
"TASK_RUN_CANCELLED",
|
|
535
|
+
"TASK_OUTPUT_ERROR",
|
|
536
|
+
"HANDLE_ERROR_ERROR",
|
|
537
|
+
"GRACEFUL_EXIT_TIMEOUT"
|
|
538
|
+
]),
|
|
539
|
+
message: z.string().optional()
|
|
540
|
+
});
|
|
541
|
+
var TaskRunError = z.discriminatedUnion("type", [
|
|
542
|
+
TaskRunBuiltInError,
|
|
543
|
+
TaskRunCustomErrorObject,
|
|
544
|
+
TaskRunStringError,
|
|
545
|
+
TaskRunInternalError
|
|
546
|
+
]);
|
|
547
|
+
var TaskRun = z.object({
|
|
548
|
+
id: z.string(),
|
|
549
|
+
payload: z.string(),
|
|
550
|
+
payloadType: z.string(),
|
|
551
|
+
context: z.any(),
|
|
552
|
+
tags: z.array(z.string()),
|
|
553
|
+
isTest: z.boolean().default(false),
|
|
554
|
+
createdAt: z.coerce.date(),
|
|
555
|
+
idempotencyKey: z.string().optional()
|
|
556
|
+
});
|
|
557
|
+
var TaskRunExecutionTask = z.object({
|
|
558
|
+
id: z.string(),
|
|
559
|
+
filePath: z.string(),
|
|
560
|
+
exportName: z.string()
|
|
561
|
+
});
|
|
562
|
+
var TaskRunExecutionAttempt = z.object({
|
|
563
|
+
id: z.string(),
|
|
564
|
+
number: z.number(),
|
|
565
|
+
startedAt: z.coerce.date(),
|
|
566
|
+
backgroundWorkerId: z.string(),
|
|
567
|
+
backgroundWorkerTaskId: z.string(),
|
|
568
|
+
status: z.string()
|
|
569
|
+
});
|
|
570
|
+
var TaskRunExecutionEnvironment = z.object({
|
|
571
|
+
id: z.string(),
|
|
572
|
+
slug: z.string(),
|
|
573
|
+
type: z.enum([
|
|
574
|
+
"PRODUCTION",
|
|
575
|
+
"STAGING",
|
|
576
|
+
"DEVELOPMENT",
|
|
577
|
+
"PREVIEW"
|
|
578
|
+
])
|
|
579
|
+
});
|
|
580
|
+
var TaskRunExecutionOrganization = z.object({
|
|
581
|
+
id: z.string(),
|
|
582
|
+
slug: z.string(),
|
|
583
|
+
name: z.string()
|
|
584
|
+
});
|
|
585
|
+
var TaskRunExecutionProject = z.object({
|
|
586
|
+
id: z.string(),
|
|
587
|
+
ref: z.string(),
|
|
588
|
+
slug: z.string(),
|
|
589
|
+
name: z.string()
|
|
590
|
+
});
|
|
591
|
+
var TaskRunExecutionQueue = z.object({
|
|
592
|
+
id: z.string(),
|
|
593
|
+
name: z.string()
|
|
594
|
+
});
|
|
595
|
+
var TaskRunExecutionBatch = z.object({
|
|
596
|
+
id: z.string()
|
|
597
|
+
});
|
|
598
|
+
var TaskRunExecution = z.object({
|
|
599
|
+
task: TaskRunExecutionTask,
|
|
600
|
+
attempt: TaskRunExecutionAttempt,
|
|
601
|
+
run: TaskRun,
|
|
602
|
+
queue: TaskRunExecutionQueue,
|
|
603
|
+
environment: TaskRunExecutionEnvironment,
|
|
604
|
+
organization: TaskRunExecutionOrganization,
|
|
605
|
+
project: TaskRunExecutionProject,
|
|
606
|
+
batch: TaskRunExecutionBatch.optional()
|
|
607
|
+
});
|
|
608
|
+
var TaskRunContext = z.object({
|
|
609
|
+
task: TaskRunExecutionTask,
|
|
610
|
+
attempt: TaskRunExecutionAttempt.omit({
|
|
611
|
+
backgroundWorkerId: true,
|
|
612
|
+
backgroundWorkerTaskId: true
|
|
613
|
+
}),
|
|
614
|
+
run: TaskRun.omit({
|
|
615
|
+
payload: true,
|
|
616
|
+
payloadType: true
|
|
617
|
+
}),
|
|
618
|
+
queue: TaskRunExecutionQueue,
|
|
619
|
+
environment: TaskRunExecutionEnvironment,
|
|
620
|
+
organization: TaskRunExecutionOrganization,
|
|
621
|
+
project: TaskRunExecutionProject,
|
|
622
|
+
batch: TaskRunExecutionBatch.optional()
|
|
623
|
+
});
|
|
624
|
+
var TaskRunExecutionRetry = z.object({
|
|
625
|
+
timestamp: z.number(),
|
|
626
|
+
delay: z.number(),
|
|
627
|
+
error: z.unknown().optional()
|
|
628
|
+
});
|
|
629
|
+
var TaskRunFailedExecutionResult = z.object({
|
|
630
|
+
ok: z.literal(false),
|
|
631
|
+
id: z.string(),
|
|
632
|
+
error: TaskRunError,
|
|
633
|
+
retry: TaskRunExecutionRetry.optional(),
|
|
634
|
+
skippedRetrying: z.boolean().optional()
|
|
635
|
+
});
|
|
636
|
+
var TaskRunSuccessfulExecutionResult = z.object({
|
|
637
|
+
ok: z.literal(true),
|
|
638
|
+
id: z.string(),
|
|
639
|
+
output: z.string().optional(),
|
|
640
|
+
outputType: z.string()
|
|
641
|
+
});
|
|
642
|
+
var TaskRunExecutionResult = z.discriminatedUnion("ok", [
|
|
643
|
+
TaskRunSuccessfulExecutionResult,
|
|
644
|
+
TaskRunFailedExecutionResult
|
|
645
|
+
]);
|
|
646
|
+
var BatchTaskRunExecutionResult = z.object({
|
|
647
|
+
id: z.string(),
|
|
648
|
+
items: TaskRunExecutionResult.array()
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
// src/v3/schemas/schemas.ts
|
|
652
|
+
z.enum([
|
|
653
|
+
"PRODUCTION",
|
|
654
|
+
"STAGING",
|
|
655
|
+
"DEVELOPMENT",
|
|
656
|
+
"PREVIEW"
|
|
657
|
+
]);
|
|
658
|
+
var MachineCpu = z.union([
|
|
659
|
+
z.literal(0.25),
|
|
660
|
+
z.literal(0.5),
|
|
661
|
+
z.literal(1),
|
|
662
|
+
z.literal(2),
|
|
663
|
+
z.literal(4)
|
|
664
|
+
]).default(0.5);
|
|
665
|
+
var MachineMemory = z.union([
|
|
666
|
+
z.literal(0.25),
|
|
667
|
+
z.literal(0.5),
|
|
668
|
+
z.literal(1),
|
|
669
|
+
z.literal(2),
|
|
670
|
+
z.literal(4),
|
|
671
|
+
z.literal(8)
|
|
672
|
+
]).default(1);
|
|
673
|
+
var Machine = z.object({
|
|
674
|
+
version: z.literal("v1").default("v1"),
|
|
675
|
+
cpu: MachineCpu,
|
|
676
|
+
memory: MachineMemory
|
|
677
|
+
});
|
|
678
|
+
z.object({
|
|
679
|
+
execution: TaskRunExecution,
|
|
680
|
+
traceContext: z.record(z.unknown()),
|
|
681
|
+
environment: z.record(z.string()).optional()
|
|
682
|
+
});
|
|
683
|
+
var ProdTaskRunExecution = TaskRunExecution.extend({
|
|
684
|
+
worker: z.object({
|
|
685
|
+
id: z.string(),
|
|
686
|
+
contentHash: z.string(),
|
|
687
|
+
version: z.string()
|
|
688
|
+
})
|
|
689
|
+
});
|
|
690
|
+
z.object({
|
|
691
|
+
execution: ProdTaskRunExecution,
|
|
692
|
+
traceContext: z.record(z.unknown()),
|
|
693
|
+
environment: z.record(z.string()).optional()
|
|
694
|
+
});
|
|
695
|
+
var FixedWindowRateLimit = z.object({
|
|
696
|
+
type: z.literal("fixed-window"),
|
|
697
|
+
limit: z.number(),
|
|
698
|
+
window: z.union([
|
|
699
|
+
z.object({
|
|
700
|
+
seconds: z.number()
|
|
701
|
+
}),
|
|
702
|
+
z.object({
|
|
703
|
+
minutes: z.number()
|
|
704
|
+
}),
|
|
705
|
+
z.object({
|
|
706
|
+
hours: z.number()
|
|
707
|
+
})
|
|
708
|
+
])
|
|
709
|
+
});
|
|
710
|
+
var SlidingWindowRateLimit = z.object({
|
|
711
|
+
type: z.literal("sliding-window"),
|
|
712
|
+
limit: z.number(),
|
|
713
|
+
window: z.union([
|
|
714
|
+
z.object({
|
|
715
|
+
seconds: z.number()
|
|
716
|
+
}),
|
|
717
|
+
z.object({
|
|
718
|
+
minutes: z.number()
|
|
719
|
+
}),
|
|
720
|
+
z.object({
|
|
721
|
+
hours: z.number()
|
|
722
|
+
})
|
|
723
|
+
])
|
|
724
|
+
});
|
|
725
|
+
var RateLimitOptions = z.discriminatedUnion("type", [
|
|
726
|
+
FixedWindowRateLimit,
|
|
727
|
+
SlidingWindowRateLimit
|
|
728
|
+
]);
|
|
729
|
+
var RetryOptions = z.object({
|
|
730
|
+
/** The number of attempts before giving up */
|
|
731
|
+
maxAttempts: z.number().int().optional(),
|
|
732
|
+
/** The exponential factor to use when calculating the next retry time.
|
|
733
|
+
*
|
|
734
|
+
* Each subsequent retry will be calculated as `previousTimeout * factor`
|
|
735
|
+
*/
|
|
736
|
+
factor: z.number().optional(),
|
|
737
|
+
/** The minimum time to wait before retrying */
|
|
738
|
+
minTimeoutInMs: z.number().int().optional(),
|
|
739
|
+
/** The maximum time to wait before retrying */
|
|
740
|
+
maxTimeoutInMs: z.number().int().optional(),
|
|
741
|
+
/** Randomize the timeout between retries.
|
|
742
|
+
*
|
|
743
|
+
* This can be useful to prevent the thundering herd problem where all retries happen at the same time.
|
|
744
|
+
*/
|
|
745
|
+
randomize: z.boolean().optional()
|
|
746
|
+
});
|
|
747
|
+
var QueueOptions = z.object({
|
|
748
|
+
/** You can define a shared queue and then pass the name in to your task.
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
*
|
|
752
|
+
* ```ts
|
|
753
|
+
* const myQueue = queue({
|
|
754
|
+
name: "my-queue",
|
|
755
|
+
concurrencyLimit: 1,
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
export const task1 = task({
|
|
759
|
+
id: "task-1",
|
|
760
|
+
queue: {
|
|
761
|
+
name: "my-queue",
|
|
762
|
+
},
|
|
763
|
+
run: async (payload: { message: string }) => {
|
|
764
|
+
// ...
|
|
765
|
+
},
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
export const task2 = task({
|
|
769
|
+
id: "task-2",
|
|
770
|
+
queue: {
|
|
771
|
+
name: "my-queue",
|
|
772
|
+
},
|
|
773
|
+
run: async (payload: { message: string }) => {
|
|
774
|
+
// ...
|
|
775
|
+
},
|
|
776
|
+
});
|
|
777
|
+
* ```
|
|
778
|
+
*/
|
|
779
|
+
name: z.string().optional(),
|
|
780
|
+
/** An optional property that specifies the maximum number of concurrent run executions.
|
|
781
|
+
*
|
|
782
|
+
* If this property is omitted, the task can potentially use up the full concurrency of an environment. */
|
|
783
|
+
concurrencyLimit: z.number().int().min(0).max(1e3).optional(),
|
|
784
|
+
/** @deprecated This feature is coming soon */
|
|
785
|
+
rateLimit: RateLimitOptions.optional()
|
|
786
|
+
});
|
|
787
|
+
var TaskMetadata = z.object({
|
|
788
|
+
id: z.string(),
|
|
789
|
+
packageVersion: z.string(),
|
|
790
|
+
queue: QueueOptions.optional(),
|
|
791
|
+
retry: RetryOptions.optional(),
|
|
792
|
+
machine: Machine.partial().optional(),
|
|
793
|
+
triggerSource: z.string().optional()
|
|
794
|
+
});
|
|
795
|
+
var TaskFileMetadata = z.object({
|
|
796
|
+
filePath: z.string(),
|
|
797
|
+
exportName: z.string()
|
|
798
|
+
});
|
|
799
|
+
TaskMetadata.merge(TaskFileMetadata);
|
|
800
|
+
z.enum([
|
|
801
|
+
"index",
|
|
802
|
+
"create",
|
|
803
|
+
"restore"
|
|
804
|
+
]);
|
|
805
|
+
z.enum([
|
|
806
|
+
"terminate"
|
|
807
|
+
]);
|
|
808
|
+
var RegexSchema = z.custom((val) => {
|
|
809
|
+
try {
|
|
810
|
+
return typeof val.test === "function";
|
|
811
|
+
} catch {
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
z.object({
|
|
816
|
+
project: z.string(),
|
|
817
|
+
triggerDirectories: z.string().array().optional(),
|
|
818
|
+
triggerUrl: z.string().optional(),
|
|
819
|
+
projectDir: z.string().optional(),
|
|
820
|
+
tsconfigPath: z.string().optional(),
|
|
821
|
+
retries: z.object({
|
|
822
|
+
enabledInDev: z.boolean().default(true),
|
|
823
|
+
default: RetryOptions.optional()
|
|
824
|
+
}).optional(),
|
|
825
|
+
additionalPackages: z.string().array().optional(),
|
|
826
|
+
additionalFiles: z.string().array().optional(),
|
|
827
|
+
dependenciesToBundle: z.array(z.union([
|
|
828
|
+
z.string(),
|
|
829
|
+
RegexSchema
|
|
830
|
+
])).optional(),
|
|
831
|
+
logLevel: z.string().optional(),
|
|
832
|
+
enableConsoleLogging: z.boolean().optional(),
|
|
833
|
+
postInstall: z.string().optional()
|
|
834
|
+
});
|
|
835
|
+
z.enum([
|
|
836
|
+
"WAIT_FOR_DURATION",
|
|
837
|
+
"WAIT_FOR_TASK",
|
|
838
|
+
"WAIT_FOR_BATCH"
|
|
839
|
+
]);
|
|
840
|
+
|
|
841
|
+
// src/v3/schemas/resources.ts
|
|
842
|
+
var TaskResource = z.object({
|
|
843
|
+
id: z.string(),
|
|
844
|
+
filePath: z.string(),
|
|
845
|
+
exportName: z.string(),
|
|
846
|
+
queue: QueueOptions.optional(),
|
|
847
|
+
retry: RetryOptions.optional(),
|
|
848
|
+
machine: Machine.partial().optional(),
|
|
849
|
+
triggerSource: z.string().optional()
|
|
850
|
+
});
|
|
851
|
+
var BackgroundWorkerMetadata = z.object({
|
|
852
|
+
packageVersion: z.string(),
|
|
853
|
+
contentHash: z.string(),
|
|
854
|
+
cliPackageVersion: z.string().optional(),
|
|
855
|
+
tasks: z.array(TaskResource)
|
|
856
|
+
});
|
|
857
|
+
z.object({
|
|
858
|
+
contentHash: z.string(),
|
|
859
|
+
imageTag: z.string()
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
// src/v3/schemas/api.ts
|
|
863
|
+
z.object({
|
|
864
|
+
userId: z.string(),
|
|
865
|
+
email: z.string().email(),
|
|
866
|
+
dashboardUrl: z.string()
|
|
867
|
+
});
|
|
868
|
+
var GetProjectResponseBody = z.object({
|
|
869
|
+
id: z.string(),
|
|
870
|
+
externalRef: z.string(),
|
|
871
|
+
name: z.string(),
|
|
872
|
+
slug: z.string(),
|
|
873
|
+
createdAt: z.coerce.date(),
|
|
874
|
+
organization: z.object({
|
|
875
|
+
id: z.string(),
|
|
876
|
+
title: z.string(),
|
|
877
|
+
slug: z.string(),
|
|
878
|
+
createdAt: z.coerce.date()
|
|
879
|
+
})
|
|
880
|
+
});
|
|
881
|
+
z.array(GetProjectResponseBody);
|
|
882
|
+
z.object({
|
|
883
|
+
apiKey: z.string(),
|
|
884
|
+
name: z.string(),
|
|
885
|
+
apiUrl: z.string()
|
|
886
|
+
});
|
|
887
|
+
z.object({
|
|
888
|
+
localOnly: z.boolean(),
|
|
889
|
+
metadata: BackgroundWorkerMetadata
|
|
890
|
+
});
|
|
891
|
+
z.object({
|
|
892
|
+
id: z.string(),
|
|
893
|
+
version: z.string(),
|
|
894
|
+
contentHash: z.string()
|
|
895
|
+
});
|
|
896
|
+
var TriggerTaskRequestBody = z.object({
|
|
897
|
+
payload: z.any(),
|
|
898
|
+
context: z.any(),
|
|
899
|
+
options: z.object({
|
|
900
|
+
dependentAttempt: z.string().optional(),
|
|
901
|
+
dependentBatch: z.string().optional(),
|
|
902
|
+
lockToVersion: z.string().optional(),
|
|
903
|
+
queue: QueueOptions.optional(),
|
|
904
|
+
concurrencyKey: z.string().optional(),
|
|
905
|
+
idempotencyKey: z.string().optional(),
|
|
906
|
+
test: z.boolean().optional(),
|
|
907
|
+
payloadType: z.string().optional()
|
|
908
|
+
}).optional()
|
|
909
|
+
});
|
|
910
|
+
var TriggerTaskResponse = z.object({
|
|
911
|
+
id: z.string()
|
|
912
|
+
});
|
|
913
|
+
z.object({
|
|
914
|
+
items: TriggerTaskRequestBody.array(),
|
|
915
|
+
dependentAttempt: z.string().optional()
|
|
916
|
+
});
|
|
917
|
+
var BatchTriggerTaskResponse = z.object({
|
|
918
|
+
batchId: z.string(),
|
|
919
|
+
runs: z.string().array()
|
|
920
|
+
});
|
|
921
|
+
z.object({
|
|
922
|
+
id: z.string(),
|
|
923
|
+
items: z.array(z.object({
|
|
924
|
+
id: z.string(),
|
|
925
|
+
taskRunId: z.string(),
|
|
926
|
+
status: z.enum([
|
|
927
|
+
"PENDING",
|
|
928
|
+
"CANCELED",
|
|
929
|
+
"COMPLETED",
|
|
930
|
+
"FAILED"
|
|
931
|
+
])
|
|
932
|
+
}))
|
|
933
|
+
});
|
|
934
|
+
z.object({
|
|
935
|
+
variables: z.record(z.string())
|
|
936
|
+
});
|
|
937
|
+
z.object({
|
|
938
|
+
imageReference: z.string(),
|
|
939
|
+
selfHosted: z.boolean().optional()
|
|
940
|
+
});
|
|
941
|
+
z.object({
|
|
942
|
+
id: z.string(),
|
|
943
|
+
contentHash: z.string()
|
|
944
|
+
});
|
|
945
|
+
var ExternalBuildData = z.object({
|
|
946
|
+
buildId: z.string(),
|
|
947
|
+
buildToken: z.string(),
|
|
948
|
+
projectId: z.string()
|
|
949
|
+
});
|
|
950
|
+
z.object({
|
|
951
|
+
id: z.string(),
|
|
952
|
+
contentHash: z.string(),
|
|
953
|
+
shortCode: z.string(),
|
|
954
|
+
version: z.string(),
|
|
955
|
+
imageTag: z.string(),
|
|
956
|
+
externalBuildData: ExternalBuildData.optional().nullable(),
|
|
957
|
+
registryHost: z.string().optional()
|
|
958
|
+
});
|
|
959
|
+
z.object({
|
|
960
|
+
contentHash: z.string(),
|
|
961
|
+
userId: z.string().optional()
|
|
962
|
+
});
|
|
963
|
+
var DeploymentErrorData = z.object({
|
|
964
|
+
name: z.string(),
|
|
965
|
+
message: z.string(),
|
|
966
|
+
stack: z.string().optional()
|
|
967
|
+
});
|
|
968
|
+
z.object({
|
|
969
|
+
id: z.string(),
|
|
970
|
+
status: z.enum([
|
|
971
|
+
"PENDING",
|
|
972
|
+
"BUILDING",
|
|
973
|
+
"DEPLOYING",
|
|
974
|
+
"DEPLOYED",
|
|
975
|
+
"FAILED",
|
|
976
|
+
"CANCELED",
|
|
977
|
+
"TIMED_OUT"
|
|
978
|
+
]),
|
|
979
|
+
contentHash: z.string(),
|
|
980
|
+
shortCode: z.string(),
|
|
981
|
+
version: z.string(),
|
|
982
|
+
imageReference: z.string().optional(),
|
|
983
|
+
errorData: DeploymentErrorData.optional().nullable(),
|
|
984
|
+
worker: z.object({
|
|
985
|
+
id: z.string(),
|
|
986
|
+
version: z.string(),
|
|
987
|
+
tasks: z.array(z.object({
|
|
988
|
+
id: z.string(),
|
|
989
|
+
slug: z.string(),
|
|
990
|
+
filePath: z.string(),
|
|
991
|
+
exportName: z.string()
|
|
992
|
+
}))
|
|
993
|
+
}).optional()
|
|
994
|
+
});
|
|
995
|
+
var CreateUploadPayloadUrlResponseBody = z.object({
|
|
996
|
+
presignedUrl: z.string()
|
|
997
|
+
});
|
|
998
|
+
var ReplayRunResponse = z.object({
|
|
999
|
+
id: z.string()
|
|
1000
|
+
});
|
|
1001
|
+
var CanceledRunResponse = z.object({
|
|
1002
|
+
message: z.string()
|
|
1003
|
+
});
|
|
1004
|
+
z.object({
|
|
1005
|
+
/** The schedule id associated with this run (you can have many schedules for the same task).
|
|
1006
|
+
You can use this to remove the schedule, update it, etc */
|
|
1007
|
+
scheduleId: z.string(),
|
|
1008
|
+
/** When the task was scheduled to run.
|
|
1009
|
+
* Note this will be slightly different from `new Date()` because it takes a few ms to run the task. */
|
|
1010
|
+
timestamp: z.date(),
|
|
1011
|
+
/** When the task was last run (it has been).
|
|
1012
|
+
This can be undefined if it's never been run */
|
|
1013
|
+
lastTimestamp: z.date().optional(),
|
|
1014
|
+
/** You can optionally provide an external id when creating the schedule.
|
|
1015
|
+
Usually you would use a userId or some other unique identifier.
|
|
1016
|
+
This defaults to undefined if you didn't provide one. */
|
|
1017
|
+
externalId: z.string().optional(),
|
|
1018
|
+
/** The next 5 dates this task is scheduled to run */
|
|
1019
|
+
upcoming: z.array(z.date())
|
|
1020
|
+
});
|
|
1021
|
+
z.object({
|
|
1022
|
+
/** The id of the task you want to attach to. */
|
|
1023
|
+
task: z.string(),
|
|
1024
|
+
/** The schedule in CRON format.
|
|
1025
|
+
*
|
|
1026
|
+
* ```txt
|
|
1027
|
+
* * * * * *
|
|
1028
|
+
┬ ┬ ┬ ┬ ┬
|
|
1029
|
+
│ │ │ │ |
|
|
1030
|
+
│ │ │ │ └ day of week (0 - 7, 1L - 7L) (0 or 7 is Sun)
|
|
1031
|
+
│ │ │ └───── month (1 - 12)
|
|
1032
|
+
│ │ └────────── day of month (1 - 31, L)
|
|
1033
|
+
│ └─────────────── hour (0 - 23)
|
|
1034
|
+
└──────────────────── minute (0 - 59)
|
|
1035
|
+
* ```
|
|
1036
|
+
|
|
1037
|
+
"L" means the last. In the "day of week" field, 1L means the last Monday of the month. In the day of month field, L means the last day of the month.
|
|
1038
|
+
|
|
1039
|
+
*/
|
|
1040
|
+
cron: z.string(),
|
|
1041
|
+
/** (Optional) You can only create one schedule with this key. If you use it twice, the second call will update the schedule.
|
|
1042
|
+
*
|
|
1043
|
+
* This is useful if you don't want to create duplicate schedules for a user. */
|
|
1044
|
+
deduplicationKey: z.string().optional(),
|
|
1045
|
+
/** Optionally, you can specify your own IDs (like a user ID) and then use it inside the run function of your task.
|
|
1046
|
+
*
|
|
1047
|
+
* This allows you to have per-user CRON tasks.
|
|
1048
|
+
*/
|
|
1049
|
+
externalId: z.string().optional()
|
|
1050
|
+
});
|
|
1051
|
+
var ScheduleObject = z.object({
|
|
1052
|
+
id: z.string(),
|
|
1053
|
+
task: z.string(),
|
|
1054
|
+
active: z.boolean(),
|
|
1055
|
+
deduplicationKey: z.string().nullish(),
|
|
1056
|
+
externalId: z.string().nullish(),
|
|
1057
|
+
generator: z.object({
|
|
1058
|
+
type: z.literal("CRON"),
|
|
1059
|
+
expression: z.string(),
|
|
1060
|
+
description: z.string()
|
|
1061
|
+
}),
|
|
1062
|
+
nextRun: z.coerce.date().nullish(),
|
|
1063
|
+
environments: z.array(z.object({
|
|
1064
|
+
id: z.string(),
|
|
1065
|
+
type: z.string(),
|
|
1066
|
+
userName: z.string().nullish()
|
|
1067
|
+
}))
|
|
1068
|
+
});
|
|
1069
|
+
var DeletedScheduleObject = z.object({
|
|
1070
|
+
id: z.string()
|
|
1071
|
+
});
|
|
1072
|
+
var ListSchedulesResult = z.object({
|
|
1073
|
+
data: z.array(ScheduleObject),
|
|
1074
|
+
pagination: z.object({
|
|
1075
|
+
currentPage: z.number(),
|
|
1076
|
+
totalPages: z.number(),
|
|
1077
|
+
count: z.number()
|
|
1078
|
+
})
|
|
1079
|
+
});
|
|
1080
|
+
z.object({
|
|
1081
|
+
page: z.number().optional(),
|
|
1082
|
+
perPage: z.number().optional()
|
|
1083
|
+
});
|
|
1084
|
+
var RunStatus = z.enum([
|
|
1085
|
+
"PENDING",
|
|
1086
|
+
"EXECUTING",
|
|
1087
|
+
"PAUSED",
|
|
1088
|
+
"COMPLETED",
|
|
1089
|
+
"FAILED",
|
|
1090
|
+
"CANCELED"
|
|
1091
|
+
]);
|
|
1092
|
+
var AttemptStatus = z.enum([
|
|
1093
|
+
"PENDING",
|
|
1094
|
+
"EXECUTING",
|
|
1095
|
+
"PAUSED",
|
|
1096
|
+
"COMPLETED",
|
|
1097
|
+
"FAILED",
|
|
1098
|
+
"CANCELED"
|
|
1099
|
+
]);
|
|
1100
|
+
var RetrieveRunResponse = z.object({
|
|
1101
|
+
id: z.string(),
|
|
1102
|
+
status: RunStatus,
|
|
1103
|
+
taskIdentifier: z.string(),
|
|
1104
|
+
idempotencyKey: z.string().optional(),
|
|
1105
|
+
version: z.string().optional(),
|
|
1106
|
+
createdAt: z.coerce.date(),
|
|
1107
|
+
updatedAt: z.coerce.date(),
|
|
1108
|
+
attempts: z.array(z.object({
|
|
1109
|
+
id: z.string(),
|
|
1110
|
+
status: AttemptStatus,
|
|
1111
|
+
createdAt: z.coerce.date(),
|
|
1112
|
+
updatedAt: z.coerce.date(),
|
|
1113
|
+
startedAt: z.coerce.date().optional(),
|
|
1114
|
+
completedAt: z.coerce.date().optional()
|
|
1115
|
+
}).optional())
|
|
1116
|
+
});
|
|
1117
|
+
|
|
1118
|
+
// src/v3/apiErrors.ts
|
|
1119
|
+
var _APIError = class _APIError extends Error {
|
|
1120
|
+
constructor(status, error, message, headers) {
|
|
1121
|
+
super(`${_APIError.makeMessage(status, error, message)}`);
|
|
1122
|
+
this.status = status;
|
|
1123
|
+
this.headers = headers;
|
|
1124
|
+
const data = error;
|
|
1125
|
+
this.error = data;
|
|
1126
|
+
this.code = data?.["code"];
|
|
1127
|
+
this.param = data?.["param"];
|
|
1128
|
+
this.type = data?.["type"];
|
|
1129
|
+
}
|
|
1130
|
+
static makeMessage(status, error, message) {
|
|
1131
|
+
const msg = error?.message ? typeof error.message === "string" ? error.message : JSON.stringify(error.message) : error ? JSON.stringify(error) : message;
|
|
1132
|
+
if (status && msg) {
|
|
1133
|
+
return `${status} ${msg}`;
|
|
1134
|
+
}
|
|
1135
|
+
if (status) {
|
|
1136
|
+
return `${status} status code (no body)`;
|
|
1137
|
+
}
|
|
1138
|
+
if (msg) {
|
|
1139
|
+
return msg;
|
|
1140
|
+
}
|
|
1141
|
+
return "(no status code or body)";
|
|
1142
|
+
}
|
|
1143
|
+
static generate(status, errorResponse, message, headers) {
|
|
1144
|
+
if (!status) {
|
|
1145
|
+
return new APIConnectionError({
|
|
1146
|
+
cause: castToError(errorResponse)
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
const error = errorResponse?.["error"];
|
|
1150
|
+
if (status === 400) {
|
|
1151
|
+
return new BadRequestError(status, error, message, headers);
|
|
1152
|
+
}
|
|
1153
|
+
if (status === 401) {
|
|
1154
|
+
return new AuthenticationError(status, error, message, headers);
|
|
1155
|
+
}
|
|
1156
|
+
if (status === 403) {
|
|
1157
|
+
return new PermissionDeniedError(status, error, message, headers);
|
|
1158
|
+
}
|
|
1159
|
+
if (status === 404) {
|
|
1160
|
+
return new NotFoundError(status, error, message, headers);
|
|
1161
|
+
}
|
|
1162
|
+
if (status === 409) {
|
|
1163
|
+
return new ConflictError(status, error, message, headers);
|
|
1164
|
+
}
|
|
1165
|
+
if (status === 422) {
|
|
1166
|
+
return new UnprocessableEntityError(status, error, message, headers);
|
|
1167
|
+
}
|
|
1168
|
+
if (status === 429) {
|
|
1169
|
+
return new RateLimitError(status, error, message, headers);
|
|
1170
|
+
}
|
|
1171
|
+
if (status >= 500) {
|
|
1172
|
+
return new InternalServerError(status, error, message, headers);
|
|
1173
|
+
}
|
|
1174
|
+
return new _APIError(status, error, message, headers);
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
__name(_APIError, "APIError");
|
|
1178
|
+
var APIError = _APIError;
|
|
1179
|
+
var _APIConnectionError = class _APIConnectionError extends APIError {
|
|
1180
|
+
constructor({ message, cause }) {
|
|
1181
|
+
super(void 0, void 0, message || "Connection error.", void 0);
|
|
1182
|
+
__publicField(this, "status");
|
|
1183
|
+
if (cause)
|
|
1184
|
+
this.cause = cause;
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
__name(_APIConnectionError, "APIConnectionError");
|
|
1188
|
+
var APIConnectionError = _APIConnectionError;
|
|
1189
|
+
var _BadRequestError = class _BadRequestError extends APIError {
|
|
1190
|
+
constructor() {
|
|
1191
|
+
super(...arguments);
|
|
1192
|
+
__publicField(this, "status", 400);
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
__name(_BadRequestError, "BadRequestError");
|
|
1196
|
+
var BadRequestError = _BadRequestError;
|
|
1197
|
+
var _AuthenticationError = class _AuthenticationError extends APIError {
|
|
1198
|
+
constructor() {
|
|
1199
|
+
super(...arguments);
|
|
1200
|
+
__publicField(this, "status", 401);
|
|
1201
|
+
}
|
|
1202
|
+
};
|
|
1203
|
+
__name(_AuthenticationError, "AuthenticationError");
|
|
1204
|
+
var AuthenticationError = _AuthenticationError;
|
|
1205
|
+
var _PermissionDeniedError = class _PermissionDeniedError extends APIError {
|
|
1206
|
+
constructor() {
|
|
1207
|
+
super(...arguments);
|
|
1208
|
+
__publicField(this, "status", 403);
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
__name(_PermissionDeniedError, "PermissionDeniedError");
|
|
1212
|
+
var PermissionDeniedError = _PermissionDeniedError;
|
|
1213
|
+
var _NotFoundError = class _NotFoundError extends APIError {
|
|
1214
|
+
constructor() {
|
|
1215
|
+
super(...arguments);
|
|
1216
|
+
__publicField(this, "status", 404);
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
__name(_NotFoundError, "NotFoundError");
|
|
1220
|
+
var NotFoundError = _NotFoundError;
|
|
1221
|
+
var _ConflictError = class _ConflictError extends APIError {
|
|
1222
|
+
constructor() {
|
|
1223
|
+
super(...arguments);
|
|
1224
|
+
__publicField(this, "status", 409);
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
__name(_ConflictError, "ConflictError");
|
|
1228
|
+
var ConflictError = _ConflictError;
|
|
1229
|
+
var _UnprocessableEntityError = class _UnprocessableEntityError extends APIError {
|
|
1230
|
+
constructor() {
|
|
1231
|
+
super(...arguments);
|
|
1232
|
+
__publicField(this, "status", 422);
|
|
1233
|
+
}
|
|
1234
|
+
};
|
|
1235
|
+
__name(_UnprocessableEntityError, "UnprocessableEntityError");
|
|
1236
|
+
var UnprocessableEntityError = _UnprocessableEntityError;
|
|
1237
|
+
var _RateLimitError = class _RateLimitError extends APIError {
|
|
1238
|
+
constructor() {
|
|
1239
|
+
super(...arguments);
|
|
1240
|
+
__publicField(this, "status", 429);
|
|
1241
|
+
}
|
|
1242
|
+
};
|
|
1243
|
+
__name(_RateLimitError, "RateLimitError");
|
|
1244
|
+
var RateLimitError = _RateLimitError;
|
|
1245
|
+
var _InternalServerError = class _InternalServerError extends APIError {
|
|
1246
|
+
};
|
|
1247
|
+
__name(_InternalServerError, "InternalServerError");
|
|
1248
|
+
var InternalServerError = _InternalServerError;
|
|
1249
|
+
function castToError(err) {
|
|
1250
|
+
if (err instanceof Error)
|
|
1251
|
+
return err;
|
|
1252
|
+
return new Error(err);
|
|
1253
|
+
}
|
|
1254
|
+
__name(castToError, "castToError");
|
|
1255
|
+
|
|
1256
|
+
// src/v3/utils/retries.ts
|
|
1257
|
+
var defaultRetryOptions = {
|
|
1258
|
+
maxAttempts: 3,
|
|
1259
|
+
factor: 2,
|
|
1260
|
+
minTimeoutInMs: 1e3,
|
|
1261
|
+
maxTimeoutInMs: 6e4,
|
|
1262
|
+
randomize: true
|
|
1263
|
+
};
|
|
1264
|
+
function calculateNextRetryDelay(options, attempt) {
|
|
1265
|
+
const opts = {
|
|
1266
|
+
...defaultRetryOptions,
|
|
1267
|
+
...options
|
|
1268
|
+
};
|
|
1269
|
+
if (attempt >= opts.maxAttempts) {
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
|
|
1273
|
+
const random = randomize ? Math.random() + 1 : 1;
|
|
1274
|
+
const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
|
|
1275
|
+
return Math.round(timeout);
|
|
1276
|
+
}
|
|
1277
|
+
__name(calculateNextRetryDelay, "calculateNextRetryDelay");
|
|
1278
|
+
|
|
1279
|
+
// src/v3/zodfetch.ts
|
|
1280
|
+
var defaultRetryOptions2 = {
|
|
1281
|
+
maxAttempts: 3,
|
|
1282
|
+
factor: 2,
|
|
1283
|
+
minTimeoutInMs: 1e3,
|
|
1284
|
+
maxTimeoutInMs: 6e4,
|
|
1285
|
+
randomize: false
|
|
1286
|
+
};
|
|
1287
|
+
async function zodfetch(schema, url, requestInit, options) {
|
|
1288
|
+
return await _doZodFetch(schema, url, requestInit, options);
|
|
1289
|
+
}
|
|
1290
|
+
__name(zodfetch, "zodfetch");
|
|
1291
|
+
async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
|
|
1292
|
+
try {
|
|
1293
|
+
const response = await fetch(url, requestInitWithCache(requestInit));
|
|
1294
|
+
const responseHeaders = createResponseHeaders(response.headers);
|
|
1295
|
+
if (!response.ok) {
|
|
1296
|
+
const retryResult = shouldRetry(response, attempt, options?.retry);
|
|
1297
|
+
if (retryResult.retry) {
|
|
1298
|
+
await new Promise((resolve) => setTimeout(resolve, retryResult.delay));
|
|
1299
|
+
return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
|
|
1300
|
+
} else {
|
|
1301
|
+
const errText = await response.text().catch((e) => castToError2(e).message);
|
|
1302
|
+
const errJSON = safeJsonParse(errText);
|
|
1303
|
+
const errMessage = errJSON ? void 0 : errText;
|
|
1304
|
+
throw APIError.generate(response.status, errJSON, errMessage, responseHeaders);
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
const jsonBody = await response.json();
|
|
1308
|
+
const parsedResult = schema.safeParse(jsonBody);
|
|
1309
|
+
if (parsedResult.success) {
|
|
1310
|
+
return parsedResult.data;
|
|
1311
|
+
}
|
|
1312
|
+
throw fromZodError(parsedResult.error);
|
|
1313
|
+
} catch (error) {
|
|
1314
|
+
if (error instanceof APIError) {
|
|
1315
|
+
throw error;
|
|
1316
|
+
}
|
|
1317
|
+
if (options?.retry) {
|
|
1318
|
+
const retry = {
|
|
1319
|
+
...defaultRetryOptions2,
|
|
1320
|
+
...options.retry
|
|
1321
|
+
};
|
|
1322
|
+
const delay = calculateNextRetryDelay(retry, attempt);
|
|
1323
|
+
if (delay) {
|
|
1324
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1325
|
+
return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
throw new APIConnectionError({
|
|
1329
|
+
cause: castToError2(error)
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
__name(_doZodFetch, "_doZodFetch");
|
|
1334
|
+
function castToError2(err) {
|
|
1335
|
+
if (err instanceof Error)
|
|
1336
|
+
return err;
|
|
1337
|
+
return new Error(err);
|
|
1338
|
+
}
|
|
1339
|
+
__name(castToError2, "castToError");
|
|
1340
|
+
function shouldRetry(response, attempt, retryOptions) {
|
|
1341
|
+
function shouldRetryForOptions() {
|
|
1342
|
+
const retry = {
|
|
1343
|
+
...defaultRetryOptions2,
|
|
1344
|
+
...retryOptions
|
|
1345
|
+
};
|
|
1346
|
+
const delay = calculateNextRetryDelay(retry, attempt);
|
|
1347
|
+
if (delay) {
|
|
1348
|
+
return {
|
|
1349
|
+
retry: true,
|
|
1350
|
+
delay
|
|
1351
|
+
};
|
|
1352
|
+
} else {
|
|
1353
|
+
return {
|
|
1354
|
+
retry: false
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
__name(shouldRetryForOptions, "shouldRetryForOptions");
|
|
1359
|
+
const shouldRetryHeader = response.headers.get("x-should-retry");
|
|
1360
|
+
if (shouldRetryHeader === "true")
|
|
1361
|
+
return shouldRetryForOptions();
|
|
1362
|
+
if (shouldRetryHeader === "false")
|
|
1363
|
+
return {
|
|
1364
|
+
retry: false
|
|
1365
|
+
};
|
|
1366
|
+
if (response.status === 408)
|
|
1367
|
+
return shouldRetryForOptions();
|
|
1368
|
+
if (response.status === 409)
|
|
1369
|
+
return shouldRetryForOptions();
|
|
1370
|
+
if (response.status === 429)
|
|
1371
|
+
return shouldRetryForOptions();
|
|
1372
|
+
if (response.status >= 500)
|
|
1373
|
+
return shouldRetryForOptions();
|
|
1374
|
+
return {
|
|
1375
|
+
retry: false
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
__name(shouldRetry, "shouldRetry");
|
|
1379
|
+
function safeJsonParse(text) {
|
|
1380
|
+
try {
|
|
1381
|
+
return JSON.parse(text);
|
|
1382
|
+
} catch (e) {
|
|
1383
|
+
return void 0;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
__name(safeJsonParse, "safeJsonParse");
|
|
1387
|
+
function createResponseHeaders(headers) {
|
|
1388
|
+
return new Proxy(Object.fromEntries(
|
|
1389
|
+
// @ts-ignore
|
|
1390
|
+
headers.entries()
|
|
1391
|
+
), {
|
|
1392
|
+
get(target, name) {
|
|
1393
|
+
const key = name.toString();
|
|
1394
|
+
return target[key.toLowerCase()] || target[key];
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
__name(createResponseHeaders, "createResponseHeaders");
|
|
1399
|
+
function requestInitWithCache(requestInit) {
|
|
1400
|
+
try {
|
|
1401
|
+
const withCache = {
|
|
1402
|
+
...requestInit,
|
|
1403
|
+
cache: "no-cache"
|
|
1404
|
+
};
|
|
1405
|
+
const _ = new Request("http://localhost", withCache);
|
|
1406
|
+
return withCache;
|
|
1407
|
+
} catch (error) {
|
|
1408
|
+
return requestInit ?? {};
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
__name(requestInitWithCache, "requestInitWithCache");
|
|
1412
|
+
|
|
1413
|
+
// src/v3/apiClient/index.ts
|
|
1414
|
+
var zodFetchOptions = {
|
|
1415
|
+
retry: {
|
|
1416
|
+
maxAttempts: 3,
|
|
1417
|
+
minTimeoutInMs: 1e3,
|
|
1418
|
+
maxTimeoutInMs: 3e4,
|
|
1419
|
+
factor: 2,
|
|
1420
|
+
randomize: false
|
|
1421
|
+
}
|
|
1422
|
+
};
|
|
1423
|
+
var _getHeaders, getHeaders_fn;
|
|
1424
|
+
var _ApiClient = class _ApiClient {
|
|
1425
|
+
constructor(baseUrl, accessToken) {
|
|
1426
|
+
__privateAdd(this, _getHeaders);
|
|
1427
|
+
this.accessToken = accessToken;
|
|
1428
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
1429
|
+
}
|
|
1430
|
+
async getRunResult(runId) {
|
|
1431
|
+
try {
|
|
1432
|
+
return await zodfetch(TaskRunExecutionResult, `${this.baseUrl}/api/v1/runs/${runId}/result`, {
|
|
1433
|
+
method: "GET",
|
|
1434
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1435
|
+
}, zodFetchOptions);
|
|
1436
|
+
} catch (error) {
|
|
1437
|
+
if (error instanceof APIError) {
|
|
1438
|
+
if (error.status === 404) {
|
|
1439
|
+
return void 0;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
throw error;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
async getBatchResults(batchId) {
|
|
1446
|
+
return await zodfetch(BatchTaskRunExecutionResult, `${this.baseUrl}/api/v1/batches/${batchId}/results`, {
|
|
1447
|
+
method: "GET",
|
|
1448
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1449
|
+
}, zodFetchOptions);
|
|
1450
|
+
}
|
|
1451
|
+
triggerTask(taskId, body, options) {
|
|
1452
|
+
return zodfetch(TriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${taskId}/trigger`, {
|
|
1453
|
+
method: "POST",
|
|
1454
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
|
|
1455
|
+
body: JSON.stringify(body)
|
|
1456
|
+
}, zodFetchOptions);
|
|
1457
|
+
}
|
|
1458
|
+
batchTriggerTask(taskId, body, options) {
|
|
1459
|
+
return zodfetch(BatchTriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${taskId}/batch`, {
|
|
1460
|
+
method: "POST",
|
|
1461
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
|
|
1462
|
+
body: JSON.stringify(body)
|
|
1463
|
+
}, zodFetchOptions);
|
|
1464
|
+
}
|
|
1465
|
+
createUploadPayloadUrl(filename) {
|
|
1466
|
+
return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
|
|
1467
|
+
method: "PUT",
|
|
1468
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1469
|
+
}, zodFetchOptions);
|
|
1470
|
+
}
|
|
1471
|
+
getPayloadUrl(filename) {
|
|
1472
|
+
return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
|
|
1473
|
+
method: "GET",
|
|
1474
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1475
|
+
}, zodFetchOptions);
|
|
1476
|
+
}
|
|
1477
|
+
retrieveRun(runId) {
|
|
1478
|
+
return zodfetch(RetrieveRunResponse, `${this.baseUrl}/api/v3/runs/${runId}`, {
|
|
1479
|
+
method: "GET",
|
|
1480
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1481
|
+
}, zodFetchOptions);
|
|
1482
|
+
}
|
|
1483
|
+
replayRun(runId) {
|
|
1484
|
+
return zodfetch(ReplayRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/replay`, {
|
|
1485
|
+
method: "POST",
|
|
1486
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1487
|
+
}, zodFetchOptions);
|
|
1488
|
+
}
|
|
1489
|
+
cancelRun(runId) {
|
|
1490
|
+
return zodfetch(CanceledRunResponse, `${this.baseUrl}/api/v2/runs/${runId}/cancel`, {
|
|
1491
|
+
method: "POST",
|
|
1492
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1493
|
+
}, zodFetchOptions);
|
|
1494
|
+
}
|
|
1495
|
+
createSchedule(options) {
|
|
1496
|
+
return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules`, {
|
|
1497
|
+
method: "POST",
|
|
1498
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
|
|
1499
|
+
body: JSON.stringify(options)
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
listSchedules(options) {
|
|
1503
|
+
const searchParams = new URLSearchParams();
|
|
1504
|
+
if (options?.page) {
|
|
1505
|
+
searchParams.append("page", options.page.toString());
|
|
1506
|
+
}
|
|
1507
|
+
if (options?.perPage) {
|
|
1508
|
+
searchParams.append("perPage", options.perPage.toString());
|
|
1509
|
+
}
|
|
1510
|
+
return zodfetch(ListSchedulesResult, `${this.baseUrl}/api/v1/schedules${searchParams.size > 0 ? `?${searchParams}` : ""}`, {
|
|
1511
|
+
method: "GET",
|
|
1512
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
retrieveSchedule(scheduleId) {
|
|
1516
|
+
return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
|
|
1517
|
+
method: "GET",
|
|
1518
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
updateSchedule(scheduleId, options) {
|
|
1522
|
+
return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
|
|
1523
|
+
method: "PUT",
|
|
1524
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
|
|
1525
|
+
body: JSON.stringify(options)
|
|
1526
|
+
});
|
|
1527
|
+
}
|
|
1528
|
+
deactivateSchedule(scheduleId) {
|
|
1529
|
+
return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}/deactivate`, {
|
|
1530
|
+
method: "POST",
|
|
1531
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
activateSchedule(scheduleId) {
|
|
1535
|
+
return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}/activate`, {
|
|
1536
|
+
method: "POST",
|
|
1537
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
deleteSchedule(scheduleId) {
|
|
1541
|
+
return zodfetch(DeletedScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
|
|
1542
|
+
method: "DELETE",
|
|
1543
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
_getHeaders = new WeakSet();
|
|
1548
|
+
getHeaders_fn = /* @__PURE__ */ __name(function(spanParentAsLink) {
|
|
1549
|
+
const headers = {
|
|
1550
|
+
"Content-Type": "application/json",
|
|
1551
|
+
Authorization: `Bearer ${this.accessToken}`
|
|
1552
|
+
};
|
|
1553
|
+
if (taskContext.isInsideTask) {
|
|
1554
|
+
propagation.inject(context.active(), headers);
|
|
1555
|
+
if (spanParentAsLink) {
|
|
1556
|
+
headers["x-trigger-span-parent-as-link"] = "1";
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
return headers;
|
|
1560
|
+
}, "#getHeaders");
|
|
1561
|
+
__name(_ApiClient, "ApiClient");
|
|
1562
|
+
var ApiClient = _ApiClient;
|
|
1563
|
+
|
|
1564
|
+
// src/v3/apiClientManager/index.ts
|
|
1565
|
+
var API_NAME2 = "api-client";
|
|
1566
|
+
var _getConfig, getConfig_fn;
|
|
1567
|
+
var _APIClientManagerAPI = class _APIClientManagerAPI {
|
|
1568
|
+
constructor() {
|
|
1569
|
+
__privateAdd(this, _getConfig);
|
|
1570
|
+
}
|
|
1571
|
+
static getInstance() {
|
|
1572
|
+
if (!this._instance) {
|
|
1573
|
+
this._instance = new _APIClientManagerAPI();
|
|
1574
|
+
}
|
|
1575
|
+
return this._instance;
|
|
1576
|
+
}
|
|
1577
|
+
disable() {
|
|
1578
|
+
unregisterGlobal(API_NAME2);
|
|
1579
|
+
}
|
|
1580
|
+
setGlobalAPIClientConfiguration(config) {
|
|
1581
|
+
return registerGlobal(API_NAME2, config);
|
|
1582
|
+
}
|
|
1583
|
+
get baseURL() {
|
|
1584
|
+
const store = __privateMethod(this, _getConfig, getConfig_fn).call(this);
|
|
1585
|
+
return store?.baseURL ?? getEnvVar("TRIGGER_API_URL") ?? "https://api.trigger.dev";
|
|
1586
|
+
}
|
|
1587
|
+
get accessToken() {
|
|
1588
|
+
const store = __privateMethod(this, _getConfig, getConfig_fn).call(this);
|
|
1589
|
+
return store?.secretKey ?? getEnvVar("TRIGGER_SECRET_KEY");
|
|
1590
|
+
}
|
|
1591
|
+
get client() {
|
|
1592
|
+
if (!this.baseURL || !this.accessToken) {
|
|
1593
|
+
return void 0;
|
|
1594
|
+
}
|
|
1595
|
+
return new ApiClient(this.baseURL, this.accessToken);
|
|
1596
|
+
}
|
|
1597
|
+
};
|
|
1598
|
+
_getConfig = new WeakSet();
|
|
1599
|
+
getConfig_fn = /* @__PURE__ */ __name(function() {
|
|
1600
|
+
return getGlobal(API_NAME2);
|
|
1601
|
+
}, "#getConfig");
|
|
1602
|
+
__name(_APIClientManagerAPI, "APIClientManagerAPI");
|
|
1603
|
+
var APIClientManagerAPI = _APIClientManagerAPI;
|
|
1604
|
+
|
|
1605
|
+
// src/v3/apiClientManager-api.ts
|
|
1606
|
+
var apiClientManager = APIClientManagerAPI.getInstance();
|
|
1607
|
+
|
|
1608
|
+
// src/v3/utils/ioSerialization.ts
|
|
1609
|
+
async function parsePacket(value) {
|
|
1610
|
+
if (!value.data) {
|
|
1611
|
+
return void 0;
|
|
1612
|
+
}
|
|
1613
|
+
switch (value.dataType) {
|
|
1614
|
+
case "application/json":
|
|
1615
|
+
return JSON.parse(value.data);
|
|
1616
|
+
case "application/super+json":
|
|
1617
|
+
const { parse } = await loadSuperJSON();
|
|
1618
|
+
return parse(value.data);
|
|
1619
|
+
case "text/plain":
|
|
1620
|
+
return value.data;
|
|
1621
|
+
case "application/store":
|
|
1622
|
+
throw new Error(`Cannot parse an application/store packet (${value.data}). Needs to be imported first.`);
|
|
1623
|
+
default:
|
|
1624
|
+
return value.data;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
__name(parsePacket, "parsePacket");
|
|
1628
|
+
async function stringifyIO(value) {
|
|
1629
|
+
if (value === void 0) {
|
|
1630
|
+
return {
|
|
1631
|
+
dataType: "application/json"
|
|
1632
|
+
};
|
|
1633
|
+
}
|
|
1634
|
+
if (typeof value === "string") {
|
|
1635
|
+
return {
|
|
1636
|
+
data: value,
|
|
1637
|
+
dataType: "text/plain"
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
try {
|
|
1641
|
+
const { stringify } = await loadSuperJSON();
|
|
1642
|
+
const data = stringify(value);
|
|
1643
|
+
return {
|
|
1644
|
+
data,
|
|
1645
|
+
dataType: "application/super+json"
|
|
1646
|
+
};
|
|
1647
|
+
} catch {
|
|
1648
|
+
return {
|
|
1649
|
+
data: value,
|
|
1650
|
+
dataType: "application/json"
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
__name(stringifyIO, "stringifyIO");
|
|
1655
|
+
async function conditionallyExportPacket(packet, pathPrefix, tracer) {
|
|
1656
|
+
if (apiClientManager.client) {
|
|
1657
|
+
const { needsOffloading, size } = packetRequiresOffloading(packet);
|
|
1658
|
+
if (needsOffloading) {
|
|
1659
|
+
if (!tracer) {
|
|
1660
|
+
return await exportPacket(packet, pathPrefix);
|
|
1661
|
+
} else {
|
|
1662
|
+
const result = await tracer.startActiveSpan("store.uploadOutput", async (span) => {
|
|
1663
|
+
return await exportPacket(packet, pathPrefix);
|
|
1664
|
+
}, {
|
|
1665
|
+
attributes: {
|
|
1666
|
+
byteLength: size,
|
|
1667
|
+
[SemanticInternalAttributes.STYLE_ICON]: "cloud-upload"
|
|
1668
|
+
}
|
|
1669
|
+
});
|
|
1670
|
+
return result ?? packet;
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
return packet;
|
|
1675
|
+
}
|
|
1676
|
+
__name(conditionallyExportPacket, "conditionallyExportPacket");
|
|
1677
|
+
function packetRequiresOffloading(packet) {
|
|
1678
|
+
if (!packet.data) {
|
|
1679
|
+
return {
|
|
1680
|
+
needsOffloading: false,
|
|
1681
|
+
size: 0
|
|
1682
|
+
};
|
|
1683
|
+
}
|
|
1684
|
+
const byteSize = Buffer.byteLength(packet.data, "utf8");
|
|
1685
|
+
return {
|
|
1686
|
+
needsOffloading: byteSize >= OFFLOAD_IO_PACKET_LENGTH_LIMIT,
|
|
1687
|
+
size: byteSize
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1690
|
+
__name(packetRequiresOffloading, "packetRequiresOffloading");
|
|
1691
|
+
async function exportPacket(packet, pathPrefix) {
|
|
1692
|
+
const filename = `${pathPrefix}.${getPacketExtension(packet.dataType)}`;
|
|
1693
|
+
const presignedResponse = await apiClientManager.client.createUploadPayloadUrl(filename);
|
|
1694
|
+
const uploadResponse = await fetch(presignedResponse.presignedUrl, {
|
|
1695
|
+
method: "PUT",
|
|
1696
|
+
headers: {
|
|
1697
|
+
"Content-Type": packet.dataType
|
|
1698
|
+
},
|
|
1699
|
+
body: packet.data
|
|
1700
|
+
});
|
|
1701
|
+
if (!uploadResponse.ok) {
|
|
1702
|
+
throw new Error(`Failed to upload output to ${presignedResponse.presignedUrl}: ${uploadResponse.statusText}`);
|
|
1703
|
+
}
|
|
1704
|
+
return {
|
|
1705
|
+
data: filename,
|
|
1706
|
+
dataType: "application/store"
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
__name(exportPacket, "exportPacket");
|
|
1710
|
+
async function conditionallyImportPacket(packet, tracer) {
|
|
1711
|
+
if (packet.dataType !== "application/store") {
|
|
1712
|
+
return packet;
|
|
1713
|
+
}
|
|
1714
|
+
if (!tracer) {
|
|
1715
|
+
return await importPacket(packet);
|
|
1716
|
+
} else {
|
|
1717
|
+
const result = await tracer.startActiveSpan("store.downloadPayload", async (span) => {
|
|
1718
|
+
return await importPacket(packet, span);
|
|
1719
|
+
}, {
|
|
1720
|
+
attributes: {
|
|
1721
|
+
[SemanticInternalAttributes.STYLE_ICON]: "cloud-download"
|
|
1722
|
+
}
|
|
1723
|
+
});
|
|
1724
|
+
return result ?? packet;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
__name(conditionallyImportPacket, "conditionallyImportPacket");
|
|
1728
|
+
async function importPacket(packet, span) {
|
|
1729
|
+
if (!packet.data) {
|
|
1730
|
+
return packet;
|
|
1731
|
+
}
|
|
1732
|
+
if (!apiClientManager.client) {
|
|
1733
|
+
return packet;
|
|
1734
|
+
}
|
|
1735
|
+
const presignedResponse = await apiClientManager.client.getPayloadUrl(packet.data);
|
|
1736
|
+
const response = await fetch(presignedResponse.presignedUrl);
|
|
1737
|
+
if (!response.ok) {
|
|
1738
|
+
throw new Error(`Failed to import packet ${presignedResponse.presignedUrl}: ${response.statusText}`);
|
|
1739
|
+
}
|
|
1740
|
+
const data = await response.text();
|
|
1741
|
+
span?.setAttribute("size", Buffer.byteLength(data, "utf8"));
|
|
1742
|
+
return {
|
|
1743
|
+
data,
|
|
1744
|
+
dataType: response.headers.get("content-type") ?? "application/json"
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
__name(importPacket, "importPacket");
|
|
1748
|
+
async function createPacketAttributes(packet, dataKey, dataTypeKey) {
|
|
1749
|
+
if (!packet.data) {
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1752
|
+
switch (packet.dataType) {
|
|
1753
|
+
case "application/json":
|
|
1754
|
+
return {
|
|
1755
|
+
...flattenAttributes(packet, dataKey),
|
|
1756
|
+
[dataTypeKey]: packet.dataType
|
|
1757
|
+
};
|
|
1758
|
+
case "application/super+json":
|
|
1759
|
+
const { parse } = await loadSuperJSON();
|
|
1760
|
+
if (typeof packet.data === "undefined" || packet.data === null) {
|
|
1761
|
+
return;
|
|
1762
|
+
}
|
|
1763
|
+
try {
|
|
1764
|
+
const parsed = parse(packet.data);
|
|
1765
|
+
const jsonified = JSON.parse(JSON.stringify(parsed, safeReplacer));
|
|
1766
|
+
const result = {
|
|
1767
|
+
...flattenAttributes(jsonified, dataKey),
|
|
1768
|
+
[dataTypeKey]: "application/json"
|
|
1769
|
+
};
|
|
1770
|
+
return result;
|
|
1771
|
+
} catch (e) {
|
|
1772
|
+
return;
|
|
1773
|
+
}
|
|
1774
|
+
case "application/store":
|
|
1775
|
+
return {
|
|
1776
|
+
[dataKey]: packet.data,
|
|
1777
|
+
[dataTypeKey]: packet.dataType
|
|
1778
|
+
};
|
|
1779
|
+
case "text/plain":
|
|
1780
|
+
return {
|
|
1781
|
+
[dataKey]: packet.data,
|
|
1782
|
+
[dataTypeKey]: packet.dataType
|
|
1783
|
+
};
|
|
1784
|
+
default:
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
__name(createPacketAttributes, "createPacketAttributes");
|
|
1789
|
+
function safeReplacer(key, value) {
|
|
1790
|
+
if (typeof value === "bigint") {
|
|
1791
|
+
return value.toString();
|
|
1792
|
+
}
|
|
1793
|
+
if (value instanceof RegExp) {
|
|
1794
|
+
return value.toString();
|
|
1795
|
+
}
|
|
1796
|
+
if (value instanceof Set) {
|
|
1797
|
+
return Array.from(value);
|
|
1798
|
+
}
|
|
1799
|
+
if (value instanceof Map) {
|
|
1800
|
+
const obj = {};
|
|
1801
|
+
value.forEach((v, k) => {
|
|
1802
|
+
obj[k] = v;
|
|
1803
|
+
});
|
|
1804
|
+
return obj;
|
|
1805
|
+
}
|
|
1806
|
+
return value;
|
|
1807
|
+
}
|
|
1808
|
+
__name(safeReplacer, "safeReplacer");
|
|
1809
|
+
function getPacketExtension(outputType) {
|
|
1810
|
+
switch (outputType) {
|
|
1811
|
+
case "application/json":
|
|
1812
|
+
return "json";
|
|
1813
|
+
case "application/super+json":
|
|
1814
|
+
return "json";
|
|
1815
|
+
case "text/plain":
|
|
1816
|
+
return "txt";
|
|
1817
|
+
default:
|
|
1818
|
+
return "txt";
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
__name(getPacketExtension, "getPacketExtension");
|
|
1822
|
+
async function loadSuperJSON() {
|
|
1823
|
+
return await import('superjson');
|
|
1824
|
+
}
|
|
1825
|
+
__name(loadSuperJSON, "loadSuperJSON");
|
|
1826
|
+
|
|
1827
|
+
// src/v3/utils/styleAttributes.ts
|
|
1828
|
+
function accessoryAttributes(accessory) {
|
|
1829
|
+
return flattenAttributes(accessory, SemanticInternalAttributes.STYLE_ACCESSORY);
|
|
1830
|
+
}
|
|
1831
|
+
__name(accessoryAttributes, "accessoryAttributes");
|
|
1832
|
+
|
|
1833
|
+
// src/v3/workers/taskExecutor.ts
|
|
1834
|
+
var _callRun, callRun_fn, _callInitFunctions, callInitFunctions_fn, _callConfigInit, callConfigInit_fn, _callOnSuccessFunctions, callOnSuccessFunctions_fn, _callOnSuccessFunction, callOnSuccessFunction_fn, _callOnFailureFunctions, callOnFailureFunctions_fn, _callOnFailureFunction, callOnFailureFunction_fn, _callOnStartFunctions, callOnStartFunctions_fn, _callOnStartFunction, callOnStartFunction_fn, _callTaskCleanup, callTaskCleanup_fn, _handleError, handleError_fn;
|
|
1835
|
+
var _TaskExecutor = class _TaskExecutor {
|
|
1836
|
+
constructor(task, options) {
|
|
1837
|
+
__privateAdd(this, _callRun);
|
|
1838
|
+
__privateAdd(this, _callInitFunctions);
|
|
1839
|
+
__privateAdd(this, _callConfigInit);
|
|
1840
|
+
__privateAdd(this, _callOnSuccessFunctions);
|
|
1841
|
+
__privateAdd(this, _callOnSuccessFunction);
|
|
1842
|
+
__privateAdd(this, _callOnFailureFunctions);
|
|
1843
|
+
__privateAdd(this, _callOnFailureFunction);
|
|
1844
|
+
__privateAdd(this, _callOnStartFunctions);
|
|
1845
|
+
__privateAdd(this, _callOnStartFunction);
|
|
1846
|
+
__privateAdd(this, _callTaskCleanup);
|
|
1847
|
+
__privateAdd(this, _handleError);
|
|
1848
|
+
this.task = task;
|
|
1849
|
+
this._tracingSDK = options.tracingSDK;
|
|
1850
|
+
this._tracer = options.tracer;
|
|
1851
|
+
this._consoleInterceptor = options.consoleInterceptor;
|
|
1852
|
+
this._config = options.projectConfig;
|
|
1853
|
+
this._importedConfig = options.importedConfig;
|
|
1854
|
+
this._handleErrorFn = options.handleErrorFn;
|
|
1855
|
+
}
|
|
1856
|
+
async execute(execution, worker, traceContext) {
|
|
1857
|
+
const ctx = TaskRunContext.parse(execution);
|
|
1858
|
+
const attemptMessage = `Attempt ${execution.attempt.number}`;
|
|
1859
|
+
const originalPacket = {
|
|
1860
|
+
data: execution.run.payload,
|
|
1861
|
+
dataType: execution.run.payloadType
|
|
1862
|
+
};
|
|
1863
|
+
taskContext.setGlobalTaskContext({
|
|
1864
|
+
ctx,
|
|
1865
|
+
worker
|
|
1866
|
+
});
|
|
1867
|
+
this._tracingSDK.asyncResourceDetector.resolveWithAttributes({
|
|
1868
|
+
...taskContext.attributes,
|
|
1869
|
+
[SemanticInternalAttributes.SDK_VERSION]: this.task.packageVersion,
|
|
1870
|
+
[SemanticInternalAttributes.SDK_LANGUAGE]: "typescript"
|
|
1871
|
+
});
|
|
1872
|
+
const result = await this._tracer.startActiveSpan(attemptMessage, async (span) => {
|
|
1873
|
+
return await this._consoleInterceptor.intercept(console, async () => {
|
|
1874
|
+
let parsedPayload;
|
|
1875
|
+
let initOutput;
|
|
1876
|
+
try {
|
|
1877
|
+
const payloadPacket = await conditionallyImportPacket(originalPacket, this._tracer);
|
|
1878
|
+
parsedPayload = await parsePacket(payloadPacket);
|
|
1879
|
+
if (execution.attempt.number === 1) {
|
|
1880
|
+
await __privateMethod(this, _callOnStartFunctions, callOnStartFunctions_fn).call(this, parsedPayload, ctx);
|
|
1881
|
+
}
|
|
1882
|
+
initOutput = await __privateMethod(this, _callInitFunctions, callInitFunctions_fn).call(this, parsedPayload, ctx);
|
|
1883
|
+
const output = await __privateMethod(this, _callRun, callRun_fn).call(this, parsedPayload, ctx, initOutput);
|
|
1884
|
+
await __privateMethod(this, _callOnSuccessFunctions, callOnSuccessFunctions_fn).call(this, parsedPayload, output, ctx, initOutput);
|
|
1885
|
+
try {
|
|
1886
|
+
const stringifiedOutput = await stringifyIO(output);
|
|
1887
|
+
const finalOutput = await conditionallyExportPacket(stringifiedOutput, `${execution.attempt.id}/output`, this._tracer);
|
|
1888
|
+
const attributes = await createPacketAttributes(finalOutput, SemanticInternalAttributes.OUTPUT, SemanticInternalAttributes.OUTPUT_TYPE);
|
|
1889
|
+
if (attributes) {
|
|
1890
|
+
span.setAttributes(attributes);
|
|
1891
|
+
}
|
|
1892
|
+
return {
|
|
1893
|
+
ok: true,
|
|
1894
|
+
id: execution.run.id,
|
|
1895
|
+
output: finalOutput.data,
|
|
1896
|
+
outputType: finalOutput.dataType
|
|
1897
|
+
};
|
|
1898
|
+
} catch (stringifyError) {
|
|
1899
|
+
recordSpanException(span, stringifyError);
|
|
1900
|
+
return {
|
|
1901
|
+
ok: false,
|
|
1902
|
+
id: execution.run.id,
|
|
1903
|
+
error: {
|
|
1904
|
+
type: "INTERNAL_ERROR",
|
|
1905
|
+
code: TaskRunErrorCodes.TASK_OUTPUT_ERROR,
|
|
1906
|
+
message: stringifyError instanceof Error ? stringifyError.message : typeof stringifyError === "string" ? stringifyError : void 0
|
|
1907
|
+
}
|
|
1908
|
+
};
|
|
1909
|
+
}
|
|
1910
|
+
} catch (runError) {
|
|
1911
|
+
try {
|
|
1912
|
+
const handleErrorResult = await __privateMethod(this, _handleError, handleError_fn).call(this, execution, runError, parsedPayload, ctx);
|
|
1913
|
+
recordSpanException(span, handleErrorResult.error ?? runError);
|
|
1914
|
+
if (handleErrorResult.status !== "retry") {
|
|
1915
|
+
await __privateMethod(this, _callOnFailureFunctions, callOnFailureFunctions_fn).call(this, parsedPayload, handleErrorResult.error ?? runError, ctx, initOutput);
|
|
1916
|
+
}
|
|
1917
|
+
return {
|
|
1918
|
+
id: execution.run.id,
|
|
1919
|
+
ok: false,
|
|
1920
|
+
error: handleErrorResult.error ? parseError(handleErrorResult.error) : parseError(runError),
|
|
1921
|
+
retry: handleErrorResult.status === "retry" ? handleErrorResult.retry : void 0,
|
|
1922
|
+
skippedRetrying: handleErrorResult.status === "skipped"
|
|
1923
|
+
};
|
|
1924
|
+
} catch (handleErrorError) {
|
|
1925
|
+
recordSpanException(span, handleErrorError);
|
|
1926
|
+
return {
|
|
1927
|
+
ok: false,
|
|
1928
|
+
id: execution.run.id,
|
|
1929
|
+
error: {
|
|
1930
|
+
type: "INTERNAL_ERROR",
|
|
1931
|
+
code: TaskRunErrorCodes.HANDLE_ERROR_ERROR,
|
|
1932
|
+
message: handleErrorError instanceof Error ? handleErrorError.message : typeof handleErrorError === "string" ? handleErrorError : void 0
|
|
1933
|
+
}
|
|
1934
|
+
};
|
|
1935
|
+
}
|
|
1936
|
+
} finally {
|
|
1937
|
+
await __privateMethod(this, _callTaskCleanup, callTaskCleanup_fn).call(this, parsedPayload, ctx, initOutput);
|
|
1938
|
+
}
|
|
1939
|
+
});
|
|
1940
|
+
}, {
|
|
1941
|
+
kind: SpanKind.CONSUMER,
|
|
1942
|
+
attributes: {
|
|
1943
|
+
[SemanticInternalAttributes.STYLE_ICON]: "attempt",
|
|
1944
|
+
...accessoryAttributes({
|
|
1945
|
+
items: [
|
|
1946
|
+
{
|
|
1947
|
+
text: ctx.task.filePath
|
|
1948
|
+
},
|
|
1949
|
+
{
|
|
1950
|
+
text: `${ctx.task.exportName}.run()`
|
|
1951
|
+
}
|
|
1952
|
+
],
|
|
1953
|
+
style: "codepath"
|
|
1954
|
+
})
|
|
1955
|
+
}
|
|
1956
|
+
}, this._tracer.extractContext(traceContext));
|
|
1957
|
+
return result;
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
_callRun = new WeakSet();
|
|
1961
|
+
callRun_fn = /* @__PURE__ */ __name(async function(payload, ctx, init) {
|
|
1962
|
+
const runFn = this.task.fns.run;
|
|
1963
|
+
const middlewareFn = this.task.fns.middleware;
|
|
1964
|
+
if (!runFn) {
|
|
1965
|
+
throw new Error("Task does not have a run function");
|
|
1966
|
+
}
|
|
1967
|
+
if (!middlewareFn) {
|
|
1968
|
+
return runFn(payload, {
|
|
1969
|
+
ctx
|
|
1970
|
+
});
|
|
1971
|
+
}
|
|
1972
|
+
return middlewareFn(payload, {
|
|
1973
|
+
ctx,
|
|
1974
|
+
next: async () => runFn(payload, {
|
|
1975
|
+
ctx,
|
|
1976
|
+
init
|
|
1977
|
+
})
|
|
1978
|
+
});
|
|
1979
|
+
}, "#callRun");
|
|
1980
|
+
_callInitFunctions = new WeakSet();
|
|
1981
|
+
callInitFunctions_fn = /* @__PURE__ */ __name(async function(payload1, ctx1) {
|
|
1982
|
+
await __privateMethod(this, _callConfigInit, callConfigInit_fn).call(this, payload1, ctx1);
|
|
1983
|
+
const initFn = this.task.fns.init;
|
|
1984
|
+
if (!initFn) {
|
|
1985
|
+
return {};
|
|
1986
|
+
}
|
|
1987
|
+
return this._tracer.startActiveSpan("init", async (span) => {
|
|
1988
|
+
return await initFn(payload1, {
|
|
1989
|
+
ctx: ctx1
|
|
1990
|
+
});
|
|
1991
|
+
}, {
|
|
1992
|
+
attributes: {
|
|
1993
|
+
[SemanticInternalAttributes.STYLE_ICON]: "function"
|
|
1994
|
+
}
|
|
1995
|
+
});
|
|
1996
|
+
}, "#callInitFunctions");
|
|
1997
|
+
_callConfigInit = new WeakSet();
|
|
1998
|
+
callConfigInit_fn = /* @__PURE__ */ __name(async function(payload2, ctx2) {
|
|
1999
|
+
const initFn = this._importedConfig?.init;
|
|
2000
|
+
if (!initFn) {
|
|
2001
|
+
return {};
|
|
2002
|
+
}
|
|
2003
|
+
return this._tracer.startActiveSpan("config.init", async (span) => {
|
|
2004
|
+
return await initFn(payload2, {
|
|
2005
|
+
ctx: ctx2
|
|
2006
|
+
});
|
|
2007
|
+
}, {
|
|
2008
|
+
attributes: {
|
|
2009
|
+
[SemanticInternalAttributes.STYLE_ICON]: "function"
|
|
2010
|
+
}
|
|
2011
|
+
});
|
|
2012
|
+
}, "#callConfigInit");
|
|
2013
|
+
_callOnSuccessFunctions = new WeakSet();
|
|
2014
|
+
callOnSuccessFunctions_fn = /* @__PURE__ */ __name(async function(payload3, output, ctx3, initOutput) {
|
|
2015
|
+
await __privateMethod(this, _callOnSuccessFunction, callOnSuccessFunction_fn).call(this, this.task.fns.onSuccess, "task.onSuccess", payload3, output, ctx3, initOutput);
|
|
2016
|
+
await __privateMethod(this, _callOnSuccessFunction, callOnSuccessFunction_fn).call(this, this._importedConfig?.onSuccess, "config.onSuccess", payload3, output, ctx3, initOutput);
|
|
2017
|
+
}, "#callOnSuccessFunctions");
|
|
2018
|
+
_callOnSuccessFunction = new WeakSet();
|
|
2019
|
+
callOnSuccessFunction_fn = /* @__PURE__ */ __name(async function(onSuccessFn, name, payload4, output1, ctx4, initOutput1) {
|
|
2020
|
+
if (!onSuccessFn) {
|
|
2021
|
+
return;
|
|
2022
|
+
}
|
|
2023
|
+
try {
|
|
2024
|
+
await this._tracer.startActiveSpan(name, async (span) => {
|
|
2025
|
+
return await onSuccessFn(payload4, output1, {
|
|
2026
|
+
ctx: ctx4,
|
|
2027
|
+
init: initOutput1
|
|
2028
|
+
});
|
|
2029
|
+
}, {
|
|
2030
|
+
attributes: {
|
|
2031
|
+
[SemanticInternalAttributes.STYLE_ICON]: "function"
|
|
2032
|
+
}
|
|
2033
|
+
});
|
|
2034
|
+
} catch {
|
|
2035
|
+
}
|
|
2036
|
+
}, "#callOnSuccessFunction");
|
|
2037
|
+
_callOnFailureFunctions = new WeakSet();
|
|
2038
|
+
callOnFailureFunctions_fn = /* @__PURE__ */ __name(async function(payload5, error, ctx5, initOutput2) {
|
|
2039
|
+
await __privateMethod(this, _callOnFailureFunction, callOnFailureFunction_fn).call(this, this.task.fns.onFailure, "task.onFailure", payload5, error, ctx5, initOutput2);
|
|
2040
|
+
await __privateMethod(this, _callOnFailureFunction, callOnFailureFunction_fn).call(this, this._importedConfig?.onFailure, "config.onFailure", payload5, error, ctx5, initOutput2);
|
|
2041
|
+
}, "#callOnFailureFunctions");
|
|
2042
|
+
_callOnFailureFunction = new WeakSet();
|
|
2043
|
+
callOnFailureFunction_fn = /* @__PURE__ */ __name(async function(onFailureFn, name1, payload6, error1, ctx6, initOutput3) {
|
|
2044
|
+
if (!onFailureFn) {
|
|
2045
|
+
return;
|
|
2046
|
+
}
|
|
2047
|
+
try {
|
|
2048
|
+
return await this._tracer.startActiveSpan(name1, async (span) => {
|
|
2049
|
+
return await onFailureFn(payload6, error1, {
|
|
2050
|
+
ctx: ctx6,
|
|
2051
|
+
init: initOutput3
|
|
2052
|
+
});
|
|
2053
|
+
}, {
|
|
2054
|
+
attributes: {
|
|
2055
|
+
[SemanticInternalAttributes.STYLE_ICON]: "function"
|
|
2056
|
+
}
|
|
2057
|
+
});
|
|
2058
|
+
} catch (e) {
|
|
2059
|
+
}
|
|
2060
|
+
}, "#callOnFailureFunction");
|
|
2061
|
+
_callOnStartFunctions = new WeakSet();
|
|
2062
|
+
callOnStartFunctions_fn = /* @__PURE__ */ __name(async function(payload7, ctx7) {
|
|
2063
|
+
await __privateMethod(this, _callOnStartFunction, callOnStartFunction_fn).call(this, this._importedConfig?.onStart, "config.onStart", payload7, ctx7, {});
|
|
2064
|
+
await __privateMethod(this, _callOnStartFunction, callOnStartFunction_fn).call(this, this.task.fns.onStart, "task.onStart", payload7, ctx7, {});
|
|
2065
|
+
}, "#callOnStartFunctions");
|
|
2066
|
+
_callOnStartFunction = new WeakSet();
|
|
2067
|
+
callOnStartFunction_fn = /* @__PURE__ */ __name(async function(onStartFn, name2, payload8, ctx8, initOutput4) {
|
|
2068
|
+
if (!onStartFn) {
|
|
2069
|
+
return;
|
|
2070
|
+
}
|
|
2071
|
+
try {
|
|
2072
|
+
await this._tracer.startActiveSpan(name2, async (span) => {
|
|
2073
|
+
return await onStartFn(payload8, {
|
|
2074
|
+
ctx: ctx8
|
|
2075
|
+
});
|
|
2076
|
+
}, {
|
|
2077
|
+
attributes: {
|
|
2078
|
+
[SemanticInternalAttributes.STYLE_ICON]: "function"
|
|
2079
|
+
}
|
|
2080
|
+
});
|
|
2081
|
+
} catch {
|
|
2082
|
+
}
|
|
2083
|
+
}, "#callOnStartFunction");
|
|
2084
|
+
_callTaskCleanup = new WeakSet();
|
|
2085
|
+
callTaskCleanup_fn = /* @__PURE__ */ __name(async function(payload9, ctx9, init1) {
|
|
2086
|
+
const cleanupFn = this.task.fns.cleanup;
|
|
2087
|
+
if (!cleanupFn) {
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
return this._tracer.startActiveSpan("cleanup", async (span) => {
|
|
2091
|
+
return await cleanupFn(payload9, {
|
|
2092
|
+
ctx: ctx9,
|
|
2093
|
+
init: init1
|
|
2094
|
+
});
|
|
2095
|
+
});
|
|
2096
|
+
}, "#callTaskCleanup");
|
|
2097
|
+
_handleError = new WeakSet();
|
|
2098
|
+
handleError_fn = /* @__PURE__ */ __name(async function(execution, error2, payload10, ctx10) {
|
|
2099
|
+
const retriesConfig = this._importedConfig?.retries ?? this._config.retries;
|
|
2100
|
+
const retry = this.task.retry ?? retriesConfig?.default;
|
|
2101
|
+
if (!retry) {
|
|
2102
|
+
return {
|
|
2103
|
+
status: "noop"
|
|
2104
|
+
};
|
|
2105
|
+
}
|
|
2106
|
+
const delay = calculateNextRetryDelay(retry, execution.attempt.number);
|
|
2107
|
+
if (execution.environment.type === "DEVELOPMENT" && typeof retriesConfig?.enabledInDev === "boolean" && !retriesConfig.enabledInDev) {
|
|
2108
|
+
return {
|
|
2109
|
+
status: "skipped"
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
return this._tracer.startActiveSpan("handleError()", async (span) => {
|
|
2113
|
+
const handleErrorResult = this.task.fns.handleError ? await this.task.fns.handleError(payload10, error2, {
|
|
2114
|
+
ctx: ctx10,
|
|
2115
|
+
retry,
|
|
2116
|
+
retryDelayInMs: delay,
|
|
2117
|
+
retryAt: delay ? new Date(Date.now() + delay) : void 0
|
|
2118
|
+
}) : this._importedConfig ? await this._handleErrorFn?.(payload10, error2, {
|
|
2119
|
+
ctx: ctx10,
|
|
2120
|
+
retry,
|
|
2121
|
+
retryDelayInMs: delay,
|
|
2122
|
+
retryAt: delay ? new Date(Date.now() + delay) : void 0
|
|
2123
|
+
}) : void 0;
|
|
2124
|
+
if (!handleErrorResult) {
|
|
2125
|
+
return typeof delay === "undefined" ? {
|
|
2126
|
+
status: "noop"
|
|
2127
|
+
} : {
|
|
2128
|
+
status: "retry",
|
|
2129
|
+
retry: {
|
|
2130
|
+
timestamp: Date.now() + delay,
|
|
2131
|
+
delay
|
|
2132
|
+
}
|
|
2133
|
+
};
|
|
2134
|
+
}
|
|
2135
|
+
if (handleErrorResult.skipRetrying) {
|
|
2136
|
+
return {
|
|
2137
|
+
status: "skipped",
|
|
2138
|
+
error: handleErrorResult.error
|
|
2139
|
+
};
|
|
2140
|
+
}
|
|
2141
|
+
if (typeof handleErrorResult.retryAt !== "undefined") {
|
|
2142
|
+
return {
|
|
2143
|
+
status: "retry",
|
|
2144
|
+
retry: {
|
|
2145
|
+
timestamp: handleErrorResult.retryAt.getTime(),
|
|
2146
|
+
delay: handleErrorResult.retryAt.getTime() - Date.now()
|
|
2147
|
+
},
|
|
2148
|
+
error: handleErrorResult.error
|
|
2149
|
+
};
|
|
2150
|
+
}
|
|
2151
|
+
if (typeof handleErrorResult.retryDelayInMs === "number") {
|
|
2152
|
+
return {
|
|
2153
|
+
status: "retry",
|
|
2154
|
+
retry: {
|
|
2155
|
+
timestamp: Date.now() + handleErrorResult.retryDelayInMs,
|
|
2156
|
+
delay: handleErrorResult.retryDelayInMs
|
|
2157
|
+
},
|
|
2158
|
+
error: handleErrorResult.error
|
|
2159
|
+
};
|
|
2160
|
+
}
|
|
2161
|
+
if (handleErrorResult.retry && typeof handleErrorResult.retry === "object") {
|
|
2162
|
+
const delay2 = calculateNextRetryDelay(handleErrorResult.retry, execution.attempt.number);
|
|
2163
|
+
return typeof delay2 === "undefined" ? {
|
|
2164
|
+
status: "noop",
|
|
2165
|
+
error: handleErrorResult.error
|
|
2166
|
+
} : {
|
|
2167
|
+
status: "retry",
|
|
2168
|
+
retry: {
|
|
2169
|
+
timestamp: Date.now() + delay2,
|
|
2170
|
+
delay: delay2
|
|
2171
|
+
},
|
|
2172
|
+
error: handleErrorResult.error
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
return {
|
|
2176
|
+
status: "noop",
|
|
2177
|
+
error: handleErrorResult.error
|
|
2178
|
+
};
|
|
2179
|
+
}, {
|
|
2180
|
+
attributes: {
|
|
2181
|
+
[SemanticInternalAttributes.STYLE_ICON]: "exclamation-circle"
|
|
2182
|
+
}
|
|
2183
|
+
});
|
|
2184
|
+
}, "#handleError");
|
|
2185
|
+
__name(_TaskExecutor, "TaskExecutor");
|
|
2186
|
+
var TaskExecutor = _TaskExecutor;
|
|
2187
|
+
var _originClockTime, originClockTime_get, _originPreciseDate, originPreciseDate_get;
|
|
2188
|
+
var _PreciseWallClock = class _PreciseWallClock {
|
|
2189
|
+
constructor(options = {}) {
|
|
2190
|
+
__privateAdd(this, _originClockTime);
|
|
2191
|
+
__privateAdd(this, _originPreciseDate);
|
|
2192
|
+
this._origin = {
|
|
2193
|
+
clockTime: options.origin ?? process.hrtime(),
|
|
2194
|
+
preciseDate: options.now ?? new PreciseDate()
|
|
2195
|
+
};
|
|
2196
|
+
}
|
|
2197
|
+
preciseNow() {
|
|
2198
|
+
const elapsedHrTime = process.hrtime(__privateGet(this, _originClockTime, originClockTime_get));
|
|
2199
|
+
const elapsedNanoseconds = BigInt(elapsedHrTime[0]) * BigInt(1e9) + BigInt(elapsedHrTime[1]);
|
|
2200
|
+
const preciseDate = new PreciseDate(__privateGet(this, _originPreciseDate, originPreciseDate_get).getFullTime() + elapsedNanoseconds);
|
|
2201
|
+
const dateStruct = preciseDate.toStruct();
|
|
2202
|
+
return [
|
|
2203
|
+
dateStruct.seconds,
|
|
2204
|
+
dateStruct.nanos
|
|
2205
|
+
];
|
|
2206
|
+
}
|
|
2207
|
+
reset() {
|
|
2208
|
+
this._origin = {
|
|
2209
|
+
clockTime: process.hrtime(),
|
|
2210
|
+
preciseDate: new PreciseDate()
|
|
2211
|
+
};
|
|
2212
|
+
}
|
|
2213
|
+
};
|
|
2214
|
+
_originClockTime = new WeakSet();
|
|
2215
|
+
originClockTime_get = /* @__PURE__ */ __name(function() {
|
|
2216
|
+
return this._origin.clockTime;
|
|
2217
|
+
}, "#originClockTime");
|
|
2218
|
+
_originPreciseDate = new WeakSet();
|
|
2219
|
+
originPreciseDate_get = /* @__PURE__ */ __name(function() {
|
|
2220
|
+
return this._origin.preciseDate;
|
|
2221
|
+
}, "#originPreciseDate");
|
|
2222
|
+
__name(_PreciseWallClock, "PreciseWallClock");
|
|
2223
|
+
var PreciseWallClock = _PreciseWallClock;
|
|
2224
|
+
function iconStringForSeverity(severityNumber) {
|
|
2225
|
+
switch (severityNumber) {
|
|
2226
|
+
case SeverityNumber.UNSPECIFIED:
|
|
2227
|
+
return void 0;
|
|
2228
|
+
case SeverityNumber.TRACE:
|
|
2229
|
+
case SeverityNumber.TRACE2:
|
|
2230
|
+
case SeverityNumber.TRACE3:
|
|
2231
|
+
case SeverityNumber.TRACE4:
|
|
2232
|
+
return "trace";
|
|
2233
|
+
case SeverityNumber.DEBUG:
|
|
2234
|
+
case SeverityNumber.DEBUG2:
|
|
2235
|
+
case SeverityNumber.DEBUG3:
|
|
2236
|
+
case SeverityNumber.DEBUG4:
|
|
2237
|
+
return "debug";
|
|
2238
|
+
case SeverityNumber.INFO:
|
|
2239
|
+
case SeverityNumber.INFO2:
|
|
2240
|
+
case SeverityNumber.INFO3:
|
|
2241
|
+
case SeverityNumber.INFO4:
|
|
2242
|
+
return "info";
|
|
2243
|
+
case SeverityNumber.WARN:
|
|
2244
|
+
case SeverityNumber.WARN2:
|
|
2245
|
+
case SeverityNumber.WARN3:
|
|
2246
|
+
case SeverityNumber.WARN4:
|
|
2247
|
+
return "warn";
|
|
2248
|
+
case SeverityNumber.ERROR:
|
|
2249
|
+
case SeverityNumber.ERROR2:
|
|
2250
|
+
case SeverityNumber.ERROR3:
|
|
2251
|
+
case SeverityNumber.ERROR4:
|
|
2252
|
+
return "error";
|
|
2253
|
+
case SeverityNumber.FATAL:
|
|
2254
|
+
case SeverityNumber.FATAL2:
|
|
2255
|
+
case SeverityNumber.FATAL3:
|
|
2256
|
+
case SeverityNumber.FATAL4:
|
|
2257
|
+
return "fatal";
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
__name(iconStringForSeverity, "iconStringForSeverity");
|
|
2261
|
+
var _SimpleClock = class _SimpleClock {
|
|
2262
|
+
preciseNow() {
|
|
2263
|
+
const now = new PreciseDate();
|
|
2264
|
+
const nowStruct = now.toStruct();
|
|
2265
|
+
return [
|
|
2266
|
+
nowStruct.seconds,
|
|
2267
|
+
nowStruct.nanos
|
|
2268
|
+
];
|
|
2269
|
+
}
|
|
2270
|
+
reset() {
|
|
2271
|
+
}
|
|
2272
|
+
};
|
|
2273
|
+
__name(_SimpleClock, "SimpleClock");
|
|
2274
|
+
var SimpleClock = _SimpleClock;
|
|
2275
|
+
|
|
2276
|
+
// src/v3/clock/index.ts
|
|
2277
|
+
var API_NAME3 = "clock";
|
|
2278
|
+
var SIMPLE_CLOCK = new SimpleClock();
|
|
2279
|
+
var _getClock, getClock_fn;
|
|
2280
|
+
var _ClockAPI = class _ClockAPI {
|
|
2281
|
+
constructor() {
|
|
2282
|
+
__privateAdd(this, _getClock);
|
|
2283
|
+
}
|
|
2284
|
+
static getInstance() {
|
|
2285
|
+
if (!this._instance) {
|
|
2286
|
+
this._instance = new _ClockAPI();
|
|
2287
|
+
}
|
|
2288
|
+
return this._instance;
|
|
2289
|
+
}
|
|
2290
|
+
setGlobalClock(clock2) {
|
|
2291
|
+
return registerGlobal(API_NAME3, clock2);
|
|
2292
|
+
}
|
|
2293
|
+
preciseNow() {
|
|
2294
|
+
return __privateMethod(this, _getClock, getClock_fn).call(this).preciseNow();
|
|
2295
|
+
}
|
|
2296
|
+
reset() {
|
|
2297
|
+
__privateMethod(this, _getClock, getClock_fn).call(this).reset();
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
_getClock = new WeakSet();
|
|
2301
|
+
getClock_fn = /* @__PURE__ */ __name(function() {
|
|
2302
|
+
return getGlobal(API_NAME3) ?? SIMPLE_CLOCK;
|
|
2303
|
+
}, "#getClock");
|
|
2304
|
+
__name(_ClockAPI, "ClockAPI");
|
|
2305
|
+
var ClockAPI = _ClockAPI;
|
|
2306
|
+
|
|
2307
|
+
// src/v3/clock-api.ts
|
|
2308
|
+
var clock = ClockAPI.getInstance();
|
|
2309
|
+
|
|
2310
|
+
// src/v3/logger/taskLogger.ts
|
|
2311
|
+
var logLevels = [
|
|
2312
|
+
"none",
|
|
2313
|
+
"error",
|
|
2314
|
+
"warn",
|
|
2315
|
+
"info",
|
|
2316
|
+
"debug"
|
|
2317
|
+
];
|
|
2318
|
+
var _emitLog, emitLog_fn, _getTimestampInHrTime, getTimestampInHrTime_fn;
|
|
2319
|
+
var _OtelTaskLogger = class _OtelTaskLogger {
|
|
2320
|
+
constructor(_config) {
|
|
2321
|
+
__privateAdd(this, _emitLog);
|
|
2322
|
+
__privateAdd(this, _getTimestampInHrTime);
|
|
2323
|
+
this._config = _config;
|
|
2324
|
+
this._level = logLevels.indexOf(_config.level);
|
|
2325
|
+
}
|
|
2326
|
+
debug(message, properties) {
|
|
2327
|
+
if (this._level < 4)
|
|
2328
|
+
return;
|
|
2329
|
+
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "debug", SeverityNumber.DEBUG, properties);
|
|
2330
|
+
}
|
|
2331
|
+
log(message, properties) {
|
|
2332
|
+
if (this._level < 3)
|
|
2333
|
+
return;
|
|
2334
|
+
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "log", SeverityNumber.INFO, properties);
|
|
2335
|
+
}
|
|
2336
|
+
info(message, properties) {
|
|
2337
|
+
if (this._level < 3)
|
|
2338
|
+
return;
|
|
2339
|
+
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "info", SeverityNumber.INFO, properties);
|
|
2340
|
+
}
|
|
2341
|
+
warn(message, properties) {
|
|
2342
|
+
if (this._level < 2)
|
|
2343
|
+
return;
|
|
2344
|
+
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "warn", SeverityNumber.WARN, properties);
|
|
2345
|
+
}
|
|
2346
|
+
error(message, properties) {
|
|
2347
|
+
if (this._level < 1)
|
|
2348
|
+
return;
|
|
2349
|
+
__privateMethod(this, _emitLog, emitLog_fn).call(this, message, __privateMethod(this, _getTimestampInHrTime, getTimestampInHrTime_fn).call(this), "error", SeverityNumber.ERROR, properties);
|
|
2350
|
+
}
|
|
2351
|
+
trace(name, fn, options) {
|
|
2352
|
+
return this._config.tracer.startActiveSpan(name, fn, options);
|
|
2353
|
+
}
|
|
2354
|
+
};
|
|
2355
|
+
_emitLog = new WeakSet();
|
|
2356
|
+
emitLog_fn = /* @__PURE__ */ __name(function(message, timestamp, severityText, severityNumber, properties) {
|
|
2357
|
+
let attributes = {
|
|
2358
|
+
...flattenAttributes(safeJsonProcess(properties))
|
|
2359
|
+
};
|
|
2360
|
+
const icon = iconStringForSeverity(severityNumber);
|
|
2361
|
+
if (icon !== void 0) {
|
|
2362
|
+
attributes[SemanticInternalAttributes.STYLE_ICON] = icon;
|
|
2363
|
+
}
|
|
2364
|
+
this._config.logger.emit({
|
|
2365
|
+
severityNumber,
|
|
2366
|
+
severityText,
|
|
2367
|
+
body: message,
|
|
2368
|
+
attributes,
|
|
2369
|
+
timestamp
|
|
2370
|
+
});
|
|
2371
|
+
}, "#emitLog");
|
|
2372
|
+
_getTimestampInHrTime = new WeakSet();
|
|
2373
|
+
getTimestampInHrTime_fn = /* @__PURE__ */ __name(function() {
|
|
2374
|
+
return clock.preciseNow();
|
|
2375
|
+
}, "#getTimestampInHrTime");
|
|
2376
|
+
__name(_OtelTaskLogger, "OtelTaskLogger");
|
|
2377
|
+
var OtelTaskLogger = _OtelTaskLogger;
|
|
2378
|
+
function safeJsonProcess(value) {
|
|
2379
|
+
try {
|
|
2380
|
+
return JSON.parse(JSON.stringify(value, jsonErrorReplacer));
|
|
2381
|
+
} catch {
|
|
2382
|
+
return value;
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
__name(safeJsonProcess, "safeJsonProcess");
|
|
2386
|
+
function jsonErrorReplacer(key, value) {
|
|
2387
|
+
if (value instanceof Error) {
|
|
2388
|
+
return {
|
|
2389
|
+
name: value.name,
|
|
2390
|
+
message: value.message,
|
|
2391
|
+
stack: value.stack
|
|
2392
|
+
};
|
|
2393
|
+
}
|
|
2394
|
+
return value;
|
|
2395
|
+
}
|
|
2396
|
+
__name(jsonErrorReplacer, "jsonErrorReplacer");
|
|
2397
|
+
var _handleLog, handleLog_fn, _getTimestampInHrTime2, getTimestampInHrTime_fn2, _getAttributes, getAttributes_fn;
|
|
2398
|
+
var _ConsoleInterceptor = class _ConsoleInterceptor {
|
|
2399
|
+
constructor(logger, sendToStdIO) {
|
|
2400
|
+
__privateAdd(this, _handleLog);
|
|
2401
|
+
__privateAdd(this, _getTimestampInHrTime2);
|
|
2402
|
+
__privateAdd(this, _getAttributes);
|
|
2403
|
+
this.logger = logger;
|
|
2404
|
+
this.sendToStdIO = sendToStdIO;
|
|
2405
|
+
}
|
|
2406
|
+
// Intercept the console and send logs to the OpenTelemetry logger
|
|
2407
|
+
// during the execution of the callback
|
|
2408
|
+
async intercept(console2, callback) {
|
|
2409
|
+
const originalConsole = {
|
|
2410
|
+
log: console2.log,
|
|
2411
|
+
info: console2.info,
|
|
2412
|
+
warn: console2.warn,
|
|
2413
|
+
error: console2.error,
|
|
2414
|
+
debug: console2.debug
|
|
2415
|
+
};
|
|
2416
|
+
console2.log = this.log.bind(this);
|
|
2417
|
+
console2.info = this.info.bind(this);
|
|
2418
|
+
console2.warn = this.warn.bind(this);
|
|
2419
|
+
console2.error = this.error.bind(this);
|
|
2420
|
+
console2.debug = this.debug.bind(this);
|
|
2421
|
+
try {
|
|
2422
|
+
return await callback();
|
|
2423
|
+
} finally {
|
|
2424
|
+
console2.log = originalConsole.log;
|
|
2425
|
+
console2.info = originalConsole.info;
|
|
2426
|
+
console2.warn = originalConsole.warn;
|
|
2427
|
+
console2.error = originalConsole.error;
|
|
2428
|
+
console2.debug = originalConsole.debug;
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
debug(...args) {
|
|
2432
|
+
__privateMethod(this, _handleLog, handleLog_fn).call(this, SeverityNumber.DEBUG, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Debug", ...args);
|
|
2433
|
+
}
|
|
2434
|
+
log(...args) {
|
|
2435
|
+
__privateMethod(this, _handleLog, handleLog_fn).call(this, SeverityNumber.INFO, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Log", ...args);
|
|
2436
|
+
}
|
|
2437
|
+
info(...args) {
|
|
2438
|
+
__privateMethod(this, _handleLog, handleLog_fn).call(this, SeverityNumber.INFO, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Info", ...args);
|
|
2439
|
+
}
|
|
2440
|
+
warn(...args) {
|
|
2441
|
+
__privateMethod(this, _handleLog, handleLog_fn).call(this, SeverityNumber.WARN, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Warn", ...args);
|
|
2442
|
+
}
|
|
2443
|
+
error(...args) {
|
|
2444
|
+
__privateMethod(this, _handleLog, handleLog_fn).call(this, SeverityNumber.ERROR, __privateMethod(this, _getTimestampInHrTime2, getTimestampInHrTime_fn2).call(this), "Error", ...args);
|
|
2445
|
+
}
|
|
2446
|
+
};
|
|
2447
|
+
_handleLog = new WeakSet();
|
|
2448
|
+
handleLog_fn = /* @__PURE__ */ __name(function(severityNumber, timestamp, severityText, ...args) {
|
|
2449
|
+
const body = util.format(...args);
|
|
2450
|
+
if (this.sendToStdIO) {
|
|
2451
|
+
if (severityNumber === SeverityNumber.ERROR) {
|
|
2452
|
+
process.stderr.write(body);
|
|
2453
|
+
} else {
|
|
2454
|
+
process.stdout.write(body);
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
const parsed = tryParseJSON(body);
|
|
2458
|
+
if (parsed.ok) {
|
|
2459
|
+
this.logger.emit({
|
|
2460
|
+
severityNumber,
|
|
2461
|
+
severityText,
|
|
2462
|
+
body: getLogMessage(parsed.value, severityText),
|
|
2463
|
+
attributes: {
|
|
2464
|
+
...__privateMethod(this, _getAttributes, getAttributes_fn).call(this, severityNumber),
|
|
2465
|
+
...flattenAttributes(parsed.value)
|
|
2466
|
+
},
|
|
2467
|
+
timestamp
|
|
2468
|
+
});
|
|
2469
|
+
return;
|
|
2470
|
+
}
|
|
2471
|
+
this.logger.emit({
|
|
2472
|
+
severityNumber,
|
|
2473
|
+
severityText,
|
|
2474
|
+
body,
|
|
2475
|
+
attributes: __privateMethod(this, _getAttributes, getAttributes_fn).call(this, severityNumber),
|
|
2476
|
+
timestamp
|
|
2477
|
+
});
|
|
2478
|
+
}, "#handleLog");
|
|
2479
|
+
_getTimestampInHrTime2 = new WeakSet();
|
|
2480
|
+
getTimestampInHrTime_fn2 = /* @__PURE__ */ __name(function() {
|
|
2481
|
+
return clock.preciseNow();
|
|
2482
|
+
}, "#getTimestampInHrTime");
|
|
2483
|
+
_getAttributes = new WeakSet();
|
|
2484
|
+
getAttributes_fn = /* @__PURE__ */ __name(function(severityNumber1) {
|
|
2485
|
+
const icon = iconStringForSeverity(severityNumber1);
|
|
2486
|
+
let result = {};
|
|
2487
|
+
if (icon !== void 0) {
|
|
2488
|
+
result[SemanticInternalAttributes.STYLE_ICON] = icon;
|
|
2489
|
+
}
|
|
2490
|
+
return result;
|
|
2491
|
+
}, "#getAttributes");
|
|
2492
|
+
__name(_ConsoleInterceptor, "ConsoleInterceptor");
|
|
2493
|
+
var ConsoleInterceptor = _ConsoleInterceptor;
|
|
2494
|
+
function getLogMessage(value, fallback) {
|
|
2495
|
+
if (typeof value["message"] === "string") {
|
|
2496
|
+
return value["message"];
|
|
2497
|
+
}
|
|
2498
|
+
if (typeof value["msg"] === "string") {
|
|
2499
|
+
return value["msg"];
|
|
2500
|
+
}
|
|
2501
|
+
if (typeof value["body"] === "string") {
|
|
2502
|
+
return value["body"];
|
|
2503
|
+
}
|
|
2504
|
+
if (typeof value["error"] === "string") {
|
|
2505
|
+
return value["error"];
|
|
2506
|
+
}
|
|
2507
|
+
return fallback;
|
|
2508
|
+
}
|
|
2509
|
+
__name(getLogMessage, "getLogMessage");
|
|
2510
|
+
function tryParseJSON(value) {
|
|
2511
|
+
try {
|
|
2512
|
+
const parsed = JSON.parse(value);
|
|
2513
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
2514
|
+
return {
|
|
2515
|
+
ok: true,
|
|
2516
|
+
value: parsed
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2519
|
+
return {
|
|
2520
|
+
ok: false,
|
|
2521
|
+
value
|
|
2522
|
+
};
|
|
2523
|
+
} catch (e) {
|
|
2524
|
+
return {
|
|
2525
|
+
ok: false,
|
|
2526
|
+
value
|
|
2527
|
+
};
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
__name(tryParseJSON, "tryParseJSON");
|
|
2531
|
+
|
|
2532
|
+
// src/v3/task-catalog/standardTaskCatalog.ts
|
|
2533
|
+
var _StandardTaskCatalog = class _StandardTaskCatalog {
|
|
2534
|
+
constructor() {
|
|
2535
|
+
__publicField(this, "_taskMetadata", /* @__PURE__ */ new Map());
|
|
2536
|
+
__publicField(this, "_taskFunctions", /* @__PURE__ */ new Map());
|
|
2537
|
+
__publicField(this, "_taskFileMetadata", /* @__PURE__ */ new Map());
|
|
2538
|
+
}
|
|
2539
|
+
registerTaskMetadata(task) {
|
|
2540
|
+
const { fns, ...metadata } = task;
|
|
2541
|
+
this._taskMetadata.set(task.id, metadata);
|
|
2542
|
+
this._taskFunctions.set(task.id, fns);
|
|
2543
|
+
}
|
|
2544
|
+
updateTaskMetadata(id, updates) {
|
|
2545
|
+
const existingMetadata = this._taskMetadata.get(id);
|
|
2546
|
+
if (existingMetadata) {
|
|
2547
|
+
this._taskMetadata.set(id, {
|
|
2548
|
+
...existingMetadata,
|
|
2549
|
+
...updates
|
|
2550
|
+
});
|
|
2551
|
+
}
|
|
2552
|
+
if (updates.fns) {
|
|
2553
|
+
const existingFunctions = this._taskFunctions.get(id);
|
|
2554
|
+
if (existingFunctions) {
|
|
2555
|
+
this._taskFunctions.set(id, {
|
|
2556
|
+
...existingFunctions,
|
|
2557
|
+
...updates.fns
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
registerTaskFileMetadata(id, metadata) {
|
|
2563
|
+
this._taskFileMetadata.set(id, metadata);
|
|
2564
|
+
}
|
|
2565
|
+
// Return all the tasks, without the functions
|
|
2566
|
+
getAllTaskMetadata() {
|
|
2567
|
+
const result = [];
|
|
2568
|
+
for (const [id, metadata] of this._taskMetadata) {
|
|
2569
|
+
const fileMetadata = this._taskFileMetadata.get(id);
|
|
2570
|
+
if (!fileMetadata) {
|
|
2571
|
+
continue;
|
|
2572
|
+
}
|
|
2573
|
+
result.push({
|
|
2574
|
+
...metadata,
|
|
2575
|
+
...fileMetadata
|
|
2576
|
+
});
|
|
2577
|
+
}
|
|
2578
|
+
return result;
|
|
2579
|
+
}
|
|
2580
|
+
getTaskMetadata(id) {
|
|
2581
|
+
const metadata = this._taskMetadata.get(id);
|
|
2582
|
+
const fileMetadata = this._taskFileMetadata.get(id);
|
|
2583
|
+
if (!metadata || !fileMetadata) {
|
|
2584
|
+
return void 0;
|
|
2585
|
+
}
|
|
2586
|
+
return {
|
|
2587
|
+
...metadata,
|
|
2588
|
+
...fileMetadata
|
|
2589
|
+
};
|
|
2590
|
+
}
|
|
2591
|
+
getTask(id) {
|
|
2592
|
+
const metadata = this._taskMetadata.get(id);
|
|
2593
|
+
const fileMetadata = this._taskFileMetadata.get(id);
|
|
2594
|
+
const fns = this._taskFunctions.get(id);
|
|
2595
|
+
if (!metadata || !fns || !fileMetadata) {
|
|
2596
|
+
return void 0;
|
|
2597
|
+
}
|
|
2598
|
+
return {
|
|
2599
|
+
...metadata,
|
|
2600
|
+
...fileMetadata,
|
|
2601
|
+
fns
|
|
2602
|
+
};
|
|
2603
|
+
}
|
|
2604
|
+
taskExists(id) {
|
|
2605
|
+
return this._taskMetadata.has(id);
|
|
2606
|
+
}
|
|
2607
|
+
disable() {
|
|
2608
|
+
}
|
|
2609
|
+
};
|
|
2610
|
+
__name(_StandardTaskCatalog, "StandardTaskCatalog");
|
|
2611
|
+
var StandardTaskCatalog = _StandardTaskCatalog;
|
|
2612
|
+
|
|
2613
|
+
export { ConsoleInterceptor, PreciseWallClock as DurableClock, OtelTaskLogger, StandardTaskCatalog, TaskContextLogProcessor, TaskContextSpanProcessor, TaskExecutor, TracingSDK, getEnvVar, logLevels, recordSpanException };
|
|
2614
|
+
//# sourceMappingURL=out.js.map
|
|
2615
|
+
//# sourceMappingURL=index.mjs.map
|