@trigger.dev/core 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,197 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var node_process = require('node:process');
4
- var node_buffer = require('node:buffer');
5
3
  var ulidx = require('ulidx');
6
4
  var zod = require('zod');
7
5
 
8
6
  var __defProp = Object.defineProperty;
9
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
- var __accessCheck = (obj, member, msg) => {
11
- if (!member.has(obj))
12
- throw TypeError("Cannot " + msg);
13
- };
14
- var __privateGet = (obj, member, getter) => {
15
- __accessCheck(obj, member, "read from private field");
16
- return getter ? getter.call(obj) : member.get(obj);
17
- };
18
- var __privateAdd = (obj, member, value) => {
19
- if (member.has(obj))
20
- throw TypeError("Cannot add the same private member more than once");
21
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
22
- };
23
- var __privateSet = (obj, member, value, setter) => {
24
- __accessCheck(obj, member, "write to private field");
25
- setter ? setter.call(obj, value) : member.set(obj, value);
26
- return value;
27
- };
28
- var __privateMethod = (obj, member, method) => {
29
- __accessCheck(obj, member, "access private method");
30
- return method;
31
- };
32
- var logLevels = [
33
- "log",
34
- "error",
35
- "warn",
36
- "info",
37
- "debug"
38
- ];
39
- var _name, _level, _filteredKeys, _jsonReplacer, _additionalFields, _structuredLog, structuredLog_fn;
40
- var _Logger = class _Logger {
41
- constructor(name, level = "info", filteredKeys = [], jsonReplacer, additionalFields) {
42
- __privateAdd(this, _structuredLog);
43
- __privateAdd(this, _name, void 0);
44
- __privateAdd(this, _level, void 0);
45
- __privateAdd(this, _filteredKeys, []);
46
- __privateAdd(this, _jsonReplacer, void 0);
47
- __privateAdd(this, _additionalFields, void 0);
48
- __privateSet(this, _name, name);
49
- __privateSet(this, _level, logLevels.indexOf(node_process.env.TRIGGER_LOG_LEVEL ?? level));
50
- __privateSet(this, _filteredKeys, filteredKeys);
51
- __privateSet(this, _jsonReplacer, createReplacer(jsonReplacer));
52
- __privateSet(this, _additionalFields, additionalFields ?? (() => ({})));
53
- }
54
- // Return a new Logger instance with the same name and a new log level
55
- // but filter out the keys from the log messages (at any level)
56
- filter(...keys) {
57
- return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys, __privateGet(this, _jsonReplacer));
58
- }
59
- static satisfiesLogLevel(logLevel, setLevel) {
60
- return logLevels.indexOf(logLevel) <= logLevels.indexOf(setLevel);
61
- }
62
- log(message, ...args) {
63
- if (__privateGet(this, _level) < 0)
64
- return;
65
- __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.log, message, "log", ...args);
66
- }
67
- error(message, ...args) {
68
- if (__privateGet(this, _level) < 1)
69
- return;
70
- __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.error, message, "error", ...args);
71
- }
72
- warn(message, ...args) {
73
- if (__privateGet(this, _level) < 2)
74
- return;
75
- __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.warn, message, "warn", ...args);
76
- }
77
- info(message, ...args) {
78
- if (__privateGet(this, _level) < 3)
79
- return;
80
- __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.info, message, "info", ...args);
81
- }
82
- debug(message, ...args) {
83
- if (__privateGet(this, _level) < 4)
84
- return;
85
- __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.debug, message, "debug", ...args);
86
- }
87
- };
88
- _name = new WeakMap();
89
- _level = new WeakMap();
90
- _filteredKeys = new WeakMap();
91
- _jsonReplacer = new WeakMap();
92
- _additionalFields = new WeakMap();
93
- _structuredLog = new WeakSet();
94
- structuredLog_fn = /* @__PURE__ */ __name(function(loggerFunction, message, level, ...args) {
95
- const structuredLog = {
96
- ...structureArgs(safeJsonClone(args), __privateGet(this, _filteredKeys)),
97
- ...__privateGet(this, _additionalFields).call(this),
98
- timestamp: /* @__PURE__ */ new Date(),
99
- name: __privateGet(this, _name),
100
- message,
101
- level
102
- };
103
- loggerFunction(JSON.stringify(structuredLog, __privateGet(this, _jsonReplacer)));
104
- }, "#structuredLog");
105
- __name(_Logger, "Logger");
106
- var Logger = _Logger;
107
- function createReplacer(replacer) {
108
- return (key, value) => {
109
- if (typeof value === "bigint") {
110
- return value.toString();
111
- }
112
- if (replacer) {
113
- return replacer(key, value);
114
- }
115
- return value;
116
- };
117
- }
118
- __name(createReplacer, "createReplacer");
119
- function bigIntReplacer(_key, value) {
120
- if (typeof value === "bigint") {
121
- return value.toString();
122
- }
123
- return value;
124
- }
125
- __name(bigIntReplacer, "bigIntReplacer");
126
- function safeJsonClone(obj) {
127
- try {
128
- return JSON.parse(JSON.stringify(obj, bigIntReplacer));
129
- } catch (e) {
130
- return;
131
- }
132
- }
133
- __name(safeJsonClone, "safeJsonClone");
134
- function structureArgs(args, filteredKeys = []) {
135
- if (!args) {
136
- return;
137
- }
138
- if (args.length === 0) {
139
- return;
140
- }
141
- if (args.length === 1 && typeof args[0] === "object") {
142
- return filterKeys(JSON.parse(JSON.stringify(args[0], bigIntReplacer)), filteredKeys);
143
- }
144
- return args;
145
- }
146
- __name(structureArgs, "structureArgs");
147
- function filterKeys(obj, keys) {
148
- if (typeof obj !== "object" || obj === null) {
149
- return obj;
150
- }
151
- if (Array.isArray(obj)) {
152
- return obj.map((item) => filterKeys(item, keys));
153
- }
154
- const filteredObj = {};
155
- for (const [key, value] of Object.entries(obj)) {
156
- if (keys.includes(key)) {
157
- if (value) {
158
- filteredObj[key] = `[filtered ${prettyPrintBytes(value)}]`;
159
- } else {
160
- filteredObj[key] = value;
161
- }
162
- continue;
163
- }
164
- filteredObj[key] = filterKeys(value, keys);
165
- }
166
- return filteredObj;
167
- }
168
- __name(filterKeys, "filterKeys");
169
- function prettyPrintBytes(value) {
170
- if (node_process.env.NODE_ENV === "production") {
171
- return "skipped size";
172
- }
173
- const sizeInBytes = getSizeInBytes(value);
174
- if (sizeInBytes < 1024) {
175
- return `${sizeInBytes} bytes`;
176
- }
177
- if (sizeInBytes < 1024 * 1024) {
178
- return `${(sizeInBytes / 1024).toFixed(2)} KB`;
179
- }
180
- if (sizeInBytes < 1024 * 1024 * 1024) {
181
- return `${(sizeInBytes / (1024 * 1024)).toFixed(2)} MB`;
182
- }
183
- return `${(sizeInBytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
184
- }
185
- __name(prettyPrintBytes, "prettyPrintBytes");
186
- function getSizeInBytes(value) {
187
- const jsonString = JSON.stringify(value);
188
- if (typeof window === "undefined") {
189
- return node_buffer.Buffer.byteLength(jsonString, "utf8");
190
- } else {
191
- return new TextEncoder().encode(jsonString).length;
192
- }
193
- }
194
- __name(getSizeInBytes, "getSizeInBytes");
195
8
 
196
9
  // src/schemas/addMissingVersionField.ts
197
10
  function addMissingVersionField(val) {
@@ -2093,7 +1906,6 @@ exports.JobMetadataSchema = JobMetadataSchema;
2093
1906
  exports.JobRunStatusRecordSchema = JobRunStatusRecordSchema;
2094
1907
  exports.KeyValueStoreResponseBodySchema = KeyValueStoreResponseBodySchema;
2095
1908
  exports.LogMessageSchema = LogMessageSchema;
2096
- exports.Logger = Logger;
2097
1909
  exports.MISSING_CONNECTION_NOTIFICATION = MISSING_CONNECTION_NOTIFICATION;
2098
1910
  exports.MISSING_CONNECTION_RESOLVED_NOTIFICATION = MISSING_CONNECTION_RESOLVED_NOTIFICATION;
2099
1911
  exports.MissingConnectionNotificationPayloadSchema = MissingConnectionNotificationPayloadSchema;