@trigger.dev/sdk
Advanced tools
Comparing version 0.2.12 to 0.2.13
@@ -680,8 +680,18 @@ "use strict"; | ||
]; | ||
var _name, _level; | ||
var _name, _tags, _level, _formatName, formatName_fn, _formatTags, formatTags_fn; | ||
var Logger = class { | ||
constructor(name2, level = "disabled") { | ||
constructor(name2, level = "log") { | ||
__privateAdd(this, _formatName); | ||
__privateAdd(this, _formatTags); | ||
__privateAdd(this, _name, void 0); | ||
__privateAdd(this, _tags, void 0); | ||
__privateAdd(this, _level, void 0); | ||
__privateSet(this, _name, name2); | ||
if (typeof name2 === "string") { | ||
__privateSet(this, _name, name2); | ||
__privateSet(this, _tags, []); | ||
} else { | ||
const [n, ...tags] = name2; | ||
__privateSet(this, _name, n); | ||
__privateSet(this, _tags, tags); | ||
} | ||
__privateSet(this, _level, logLevels.indexOf(process.env.TRIGGER_LOG_LEVEL ?? level)); | ||
@@ -692,3 +702,6 @@ } | ||
return; | ||
console.log(`[${__privateGet(this, _name)}] `, ...args); | ||
console.log(`${__privateMethod(this, _formatName, formatName_fn).call(this)} `, ...[ | ||
...args, | ||
...__privateMethod(this, _formatTags, formatTags_fn).call(this) | ||
]); | ||
} | ||
@@ -698,3 +711,6 @@ error(...args) { | ||
return; | ||
console.error(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args); | ||
console.error(`[${formattedDateTime()}] ${__privateMethod(this, _formatName, formatName_fn).call(this)} `, ...[ | ||
...args, | ||
...__privateMethod(this, _formatTags, formatTags_fn).call(this) | ||
]); | ||
} | ||
@@ -704,3 +720,6 @@ warn(...args) { | ||
return; | ||
console.warn(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args); | ||
console.warn(`[${formattedDateTime()}] ${__privateMethod(this, _formatName, formatName_fn).call(this)} `, ...[ | ||
...args, | ||
...__privateMethod(this, _formatTags, formatTags_fn).call(this) | ||
]); | ||
} | ||
@@ -710,3 +729,6 @@ info(...args) { | ||
return; | ||
console.info(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args); | ||
console.info(`[${formattedDateTime()}] ${__privateMethod(this, _formatName, formatName_fn).call(this)} `, ...[ | ||
...args, | ||
...__privateMethod(this, _formatTags, formatTags_fn).call(this) | ||
]); | ||
} | ||
@@ -716,3 +738,6 @@ debug(...args) { | ||
return; | ||
console.debug(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args); | ||
console.debug(`[${formattedDateTime()}] ${__privateMethod(this, _formatName, formatName_fn).call(this)} `, ...[ | ||
...args, | ||
...__privateMethod(this, _formatTags, formatTags_fn).call(this) | ||
]); | ||
} | ||
@@ -722,3 +747,15 @@ }; | ||
_name = new WeakMap(); | ||
_tags = new WeakMap(); | ||
_level = new WeakMap(); | ||
_formatName = new WeakSet(); | ||
formatName_fn = /* @__PURE__ */ __name(function() { | ||
if (Array.isArray(__privateGet(this, _name))) { | ||
return __privateGet(this, _name).map((name2) => `[${name2}]`).join(""); | ||
} | ||
return `[${__privateGet(this, _name)}]`; | ||
}, "#formatName"); | ||
_formatTags = new WeakSet(); | ||
formatTags_fn = /* @__PURE__ */ __name(function() { | ||
return __privateGet(this, _tags).map((tag) => `[${tag}]`); | ||
}, "#formatTags"); | ||
function formattedDateTime() { | ||
@@ -917,3 +954,3 @@ const date = new Date(); | ||
var name = "@trigger.dev/sdk"; | ||
var version = "0.2.12"; | ||
var version = "0.2.13"; | ||
@@ -1205,8 +1242,17 @@ // src/connection.ts | ||
__privateSet(this, _endpoint, __privateGet(this, _options).endpoint ?? "wss://wss.trigger.dev/ws"); | ||
__privateSet(this, _logger3, new Logger("trigger.dev", __privateGet(this, _options).logLevel)); | ||
__privateSet(this, _logger3, new Logger([ | ||
"trigger.dev", | ||
__privateGet(this, _options).id | ||
], __privateGet(this, _options).logLevel)); | ||
} | ||
async listen(instanceId) { | ||
await __privateMethod(this, _initializeConnection, initializeConnection_fn).call(this, instanceId); | ||
__privateMethod(this, _initializeRPC, initializeRPC_fn).call(this); | ||
__privateMethod(this, _initializeHost, initializeHost_fn).call(this); | ||
try { | ||
await __privateMethod(this, _initializeConnection, initializeConnection_fn).call(this, instanceId); | ||
__privateMethod(this, _initializeRPC, initializeRPC_fn).call(this); | ||
await __privateMethod(this, _initializeHost, initializeHost_fn).call(this); | ||
__privateGet(this, _logger3).log(`\u2728 Connected and listening for events`); | ||
} catch (error) { | ||
__privateGet(this, _logger3).log(`\u{1F6A9} Could not connect to trigger.dev`); | ||
this.close(); | ||
} | ||
} | ||
@@ -1563,3 +1609,3 @@ close() { | ||
return __privateGet(this, _trigger).options.run(eventData, ctx).then((output) => { | ||
__privateGet(this, _logger3).log(`Completed workflow '${__privateGet(this, _options).name}', run ${data.id} \u{1F3C3}`); | ||
__privateGet(this, _logger3).log(`Run ${data.id} complete \u{1F3C3}`); | ||
return serverRPC.send("COMPLETE_WORKFLOW_RUN", { | ||
@@ -1566,0 +1612,0 @@ runId: data.id, |
{ | ||
"name": "@trigger.dev/sdk", | ||
"version": "0.2.12", | ||
"version": "0.2.13", | ||
"description": "trigger.dev Node.JS SDK", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
210889
2329