@sailfish-ai/sf-veritas 0.2.21 → 0.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.
Files changed (41) hide show
  1. package/README.md +53 -0
  2. package/dist/consoleLocationTransformer-BSSB5msZ.cjs +1 -0
  3. package/dist/consoleLocationTransformer-DZu_9MDA.js +51 -0
  4. package/dist/contextManager-BsolAr_q.cjs +1 -0
  5. package/dist/{contextManager-RxrMXs5c.js → contextManager-D2ijKL-E.js} +105 -102
  6. package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
  7. package/dist/plugins/funcspanEsbuildPlugin.mjs +20 -16
  8. package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
  9. package/dist/plugins/funcspanRollupPlugin.mjs +17 -13
  10. package/dist/plugins/funcspanTscPlugin.cjs +1 -1
  11. package/dist/plugins/funcspanTscPlugin.mjs +34 -30
  12. package/dist/plugins/funcspanVitePlugin.cjs +1 -1
  13. package/dist/plugins/funcspanVitePlugin.mjs +16 -12
  14. package/dist/plugins/funcspanWebpackLoader.cjs +1 -1
  15. package/dist/plugins/funcspanWebpackLoader.mjs +55 -50
  16. package/dist/plugins/funcspanWebpackPlugin.cjs +1 -1
  17. package/dist/plugins/funcspanWebpackPlugin.mjs +1 -1
  18. package/dist/runtimeConfig-C4mv7SVM.js +484 -0
  19. package/dist/runtimeConfig-XIm4yAFB.cjs +6 -0
  20. package/dist/sf-veritas.cjs +13 -13
  21. package/dist/sf-veritas.mjs +532 -388
  22. package/dist/telemetryWorker.cjs +1 -0
  23. package/dist/types/dataTransmitter.d.ts +6 -5
  24. package/dist/types/exceptionTransmitter.d.ts +2 -1
  25. package/dist/types/networkHopTransmitter.d.ts +2 -1
  26. package/dist/types/networkRequestTransmitter.d.ts +2 -1
  27. package/dist/types/plugins/consoleLocationTransformer.d.ts +37 -0
  28. package/dist/types/requestTransmitter.d.ts +45 -0
  29. package/dist/types/requestUtils.d.ts +17 -6
  30. package/dist/types/setupConfig.d.ts +21 -0
  31. package/dist/types/sourceLocation.d.ts +19 -19
  32. package/dist/types/telemetryWorker.d.ts +1 -0
  33. package/dist/worker-pool-capture.cjs +1 -1
  34. package/dist/worker-pool-capture.mjs +1 -1
  35. package/dist/workerPoolSpanCapture-DzCJnMDA.cjs +83 -0
  36. package/dist/{workerPoolSpanCapture-DVYmzgbN.js → workerPoolSpanCapture-hyxgVqUF.js} +222 -168
  37. package/package.json +17 -1
  38. package/dist/contextManager-0D8uHQ1_.cjs +0 -1
  39. package/dist/runtimeConfig-CB57auSb.js +0 -444
  40. package/dist/runtimeConfig-sm_7bnKx.cjs +0 -9
  41. package/dist/workerPoolSpanCapture-DFnbcpkU.cjs +0 -83
@@ -1,26 +1,28 @@
1
- var W = Object.defineProperty;
2
- var V = (n, t, a) => t in n ? W(n, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : n[t] = a;
3
- var S = (n, t, a) => V(n, typeof t != "symbol" ? t + "" : t, a);
4
- import { AsyncLocalStorage as J, AsyncResource as z } from "async_hooks";
5
- import { appendFileSync as x } from "fs";
6
- import { threadId as T } from "worker_threads";
7
- import { g as f, C as P, v as L, a as O } from "./contextManager-RxrMXs5c.js";
8
- class j {
1
+ var Q = Object.defineProperty;
2
+ var X = (n, t, s) => t in n ? Q(n, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[t] = s;
3
+ var y = (n, t, s) => X(n, typeof t != "symbol" ? t + "" : t, s);
4
+ import { AsyncLocalStorage as Z, AsyncResource as Y } from "async_hooks";
5
+ import { appendFileSync as ee } from "fs";
6
+ import { Worker as te, threadId as O } from "worker_threads";
7
+ import { g as S, C as L, v as j, a as M } from "./contextManager-D2ijKL-E.js";
8
+ import { dirname as ne, join as re } from "path";
9
+ import { fileURLToPath as se } from "url";
10
+ class oe {
9
11
  constructor() {
10
- S(this, "apiKey");
11
- S(this, "endpoint");
12
- S(this, "queryType", "mutation");
13
- S(this, "operationName", "");
14
- S(this, "serviceUUID", f().serviceUUID);
15
- S(this, "contextManager");
16
- this.apiKey = f().apiKey, this.endpoint = f().apiGraphqlEndpoint, this.contextManager = P.getInstance();
12
+ y(this, "apiKey");
13
+ y(this, "endpoint");
14
+ y(this, "queryType", "mutation");
15
+ y(this, "operationName", "");
16
+ y(this, "serviceUUID", S().serviceUUID);
17
+ y(this, "contextManager");
18
+ this.apiKey = S().apiKey, this.endpoint = S().apiGraphqlEndpoint, this.contextManager = L.getInstance();
17
19
  }
18
20
  get queryName() {
19
21
  return this.operationName ? this.operationName.charAt(0).toLowerCase() + this.operationName.slice(1) : "";
20
22
  }
21
23
  getDefaultVariables() {
22
- const t = Date.now().toString(), a = this.contextManager.getOrSetSfTraceId(), o = this.contextManager.getCurrentFunctionSpanId();
23
- return { apiKey: this.apiKey, serviceUuid: this.serviceUUID, sessionId: a, timestampMs: t, parentSpanId: o };
24
+ const t = Date.now().toString(), s = this.contextManager.getOrSetSfTraceId(), a = this.contextManager.getCurrentFunctionSpanId();
25
+ return { apiKey: this.apiKey, serviceUuid: this.serviceUUID, sessionId: s, timestampMs: t, parentSpanId: a };
24
26
  }
25
27
  getVariables(t = {}) {
26
28
  return { ...this.getDefaultVariables(), ...t };
@@ -35,44 +37,95 @@ class j {
35
37
  this.serviceUUID = t;
36
38
  }
37
39
  }
38
- const q = fetch;
39
- let $ = !1;
40
- function te() {
41
- return $;
40
+ const ae = typeof __dirname < "u" ? __dirname : ne(se(import.meta.url)), ie = fetch;
41
+ let b = !1;
42
+ function ye() {
43
+ return b;
42
44
  }
43
- async function E(n, t, a, o) {
45
+ const ue = process.env.SF_NBPOST_DISABLE_BATCHING === "1", A = parseInt(process.env.SF_MAIN_BATCH_SIZE || "0", 10);
46
+ let m = null, k = !1;
47
+ function B() {
48
+ if (k) return null;
49
+ if (m) return m;
44
50
  try {
45
- const s = f();
51
+ const n = re(ae, "telemetryWorker.cjs");
52
+ return m = new te(n, { env: { ...process.env, SF_NBPOST_BATCH_MAX: process.env.SF_NBPOST_BATCH_MAX || "50", SF_FLUSH_TELEMETRY_IN_BATCH: process.env.SF_FLUSH_TELEMETRY_IN_BATCH || "0", SF_BATCH_FLUSH_INTERVAL_MS: process.env.SF_BATCH_FLUSH_INTERVAL_MS || "50", SF_WORKER_MAX_CONCURRENT: process.env.SF_WORKER_MAX_CONCURRENT || "10" } }), m.unref(), m.on("error", () => {
53
+ k = !0, m = null;
54
+ }), m.on("exit", () => {
55
+ m = null;
56
+ }), m;
57
+ } catch {
58
+ return k = !0, null;
59
+ }
60
+ }
61
+ let g = [], v = !1;
62
+ function R() {
63
+ if (g.length === 0) return;
64
+ const n = B();
65
+ if (!n) {
66
+ for (const t of g) U(t.url, t.item.operationName, t.item.query, t.item.variables);
67
+ return g = [], void (v = !1);
68
+ }
69
+ g.length === 1 ? n.postMessage(g[0]) : n.postMessage({ batch: g }), g = [], v = !1;
70
+ }
71
+ async function V(n, t, s, a) {
72
+ if (ue) return U(n, t, s, a);
73
+ const o = { url: n, item: { query: s, variables: a, operationName: t } };
74
+ if (A === 1) {
75
+ const i = B();
76
+ return i ? void i.postMessage(o) : U(n, t, s, a);
77
+ }
78
+ g.push(o), A > 1 && g.length >= A ? R() : v || (v = !0, queueMicrotask(R));
79
+ }
80
+ async function U(n, t, s, a) {
81
+ try {
82
+ const o = S();
46
83
  let i;
47
84
  try {
48
- i = JSON.stringify({ query: a, variables: o, operationName: t });
85
+ i = JSON.stringify({ query: s, variables: a, operationName: t });
49
86
  } catch {
50
- i = JSON.stringify({ query: a, operationName: t });
87
+ i = JSON.stringify({ query: s, operationName: t });
51
88
  }
52
- $ = !0, q(n, { method: "POST", headers: { "Content-Type": "application/json" }, body: i }).then(async (e) => {
53
- if ($ = !1, !e.ok) return void (s.sfDebug && console.error(`GraphQL request failed with status ${e.status} for ${t}`));
89
+ b = !0, ie(n, { method: "POST", headers: { "Content-Type": "application/json" }, body: i }).then(async (e) => {
90
+ if (b = !1, !e.ok) return void (o.sfDebug && console.error(`GraphQL request failed with status ${e.status} for ${t}`));
54
91
  const r = await e.json();
55
92
  r.errors?.length ? (function(u, d, l) {
56
93
  const p = u && typeof u == "object" && !Array.isArray(u) ? Object.keys(u)[0] : void 0;
57
94
  console.error(p === "identifyServiceDetails" ? `IdentifyServiceDetails NOT sent successfully for service: UUID=${l.serviceUUID}` : `GraphQL request failed with errors: ${JSON.stringify(d)} for operation key ${p}`);
58
- })(r.data, r.errors, s) : s.sfDebug && (function(u, d, l) {
95
+ })(r.data, r.errors, o) : o.sfDebug && (function(u, d, l) {
59
96
  const p = u && typeof u == "object" && !Array.isArray(u) ? Object.keys(u)[0] : void 0, c = u[p] || !1;
60
- p === "identifyServiceDetails" && (l.setServiceIdentificationReceived(c), f().sfDebug && console.log(`IdentifyServiceDetails sent successfully for service: UUID=${l.serviceUUID}; serviceIdentificationReceived=${p === "identifyServiceDetails" ? c : "N/A"}`));
61
- })(r.data, 0, s);
97
+ p === "identifyServiceDetails" && (l.setServiceIdentificationReceived(c), S().sfDebug && console.log(`IdentifyServiceDetails sent successfully for service: UUID=${l.serviceUUID}; serviceIdentificationReceived=${p === "identifyServiceDetails" ? c : "N/A"}`));
98
+ })(r.data, 0, o);
62
99
  }).catch((e) => {
63
- $ = !1, s.sfDebug && (console.error(`[RequestUtils] Fetch error for ${t} to ${n}:`, e), e.cause && console.error("[RequestUtils] Error cause:", e.cause));
100
+ b = !1, o.sfDebug && (console.error(`[RequestUtils] Fetch error for ${t} to ${n}:`, e), e.cause && console.error("[RequestUtils] Error cause:", e.cause));
64
101
  });
65
- } catch (s) {
66
- $ = !1, f().sfDebug && console.error("Error sending data to GraphQL server:", s);
102
+ } catch (o) {
103
+ b = !1, S().sfDebug && console.error("Error sending data to GraphQL server:", o);
67
104
  }
68
105
  }
69
- function ne() {
70
- return { capture_arguments: _(process.env.SF_FUNCSPAN_CAPTURE_ARGUMENTS, !0), capture_return_value: _(process.env.SF_FUNCSPAN_CAPTURE_RETURN_VALUE, !0), arg_limit_mb: parseInt(process.env.SF_FUNCSPAN_ARG_LIMIT_MB || "1", 10), return_limit_mb: parseInt(process.env.SF_FUNCSPAN_RETURN_LIMIT_MB || "1", 10), autocapture_all_child_functions: _(process.env.SF_FUNCSPAN_AUTOCAPTURE_ALL_CHILD_FUNCTIONS, !1), sample_rate: parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE || "1.0"), enable_sampling: _(process.env.SF_FUNCSPAN_ENABLE_SAMPLING, !1), capture_sf_veritas: _(process.env.SF_FUNCSPAN_CAPTURE_SF_VERITAS, !1), parse_json_strings: _(process.env.SF_FUNCSPAN_PARSE_JSON_STRINGS, !1) };
106
+ let J = !1;
107
+ function Ne() {
108
+ if (J) return;
109
+ J = !0;
110
+ const n = () => {
111
+ try {
112
+ (function() {
113
+ R();
114
+ const t = B();
115
+ t && t.postMessage("flush");
116
+ })();
117
+ } catch {
118
+ }
119
+ };
120
+ process.on("beforeExit", n), process.on("SIGTERM", n), process.on("SIGINT", n);
121
+ }
122
+ function he() {
123
+ return { capture_arguments: $(process.env.SF_FUNCSPAN_CAPTURE_ARGUMENTS, !0), capture_return_value: $(process.env.SF_FUNCSPAN_CAPTURE_RETURN_VALUE, !0), arg_limit_mb: parseInt(process.env.SF_FUNCSPAN_ARG_LIMIT_MB || "1", 10), return_limit_mb: parseInt(process.env.SF_FUNCSPAN_RETURN_LIMIT_MB || "1", 10), autocapture_all_child_functions: $(process.env.SF_FUNCSPAN_AUTOCAPTURE_ALL_CHILD_FUNCTIONS, !1), sample_rate: parseFloat(process.env.SF_FUNCSPAN_SAMPLE_RATE || "1.0"), enable_sampling: $(process.env.SF_FUNCSPAN_ENABLE_SAMPLING, !1), capture_sf_veritas: $(process.env.SF_FUNCSPAN_CAPTURE_SF_VERITAS, !1), parse_json_strings: $(process.env.SF_FUNCSPAN_PARSE_JSON_STRINGS, !1) };
71
124
  }
72
- function re() {
125
+ function $e() {
73
126
  return { capture_arguments: !1, capture_return_value: !1, arg_limit_mb: 1, return_limit_mb: 1, autocapture_all_child_functions: !1, sample_rate: 0, enable_sampling: !1, capture_sf_veritas: !1, parse_json_strings: !1 };
74
127
  }
75
- function ae(n) {
128
+ function Ie(n) {
76
129
  try {
77
130
  const t = n.split("-");
78
131
  return t.length !== 9 ? (console.error(`[FuncSpan] Invalid header format: expected 9 parts, got ${t.length}`), null) : { capture_arguments: t[0] === "1", capture_return_value: t[1] === "1", arg_limit_mb: parseInt(t[2], 10), return_limit_mb: parseInt(t[3], 10), autocapture_all_child_functions: t[4] === "1", sample_rate: parseFloat(t[5]), enable_sampling: t[6] === "1", capture_sf_veritas: t[7] === "1", parse_json_strings: t[8] === "1" };
@@ -80,50 +133,50 @@ function ae(n) {
80
133
  return console.error(`[FuncSpan] Failed to parse header override "${n}":`, t), null;
81
134
  }
82
135
  }
83
- function _(n, t) {
136
+ function $(n, t) {
84
137
  if (!n) return t;
85
- const a = n.toLowerCase();
86
- return a === "true" || a === "1" || a === "yes";
138
+ const s = n.toLowerCase();
139
+ return s === "true" || s === "1" || s === "yes";
87
140
  }
88
- const F = "__sf_funcspanOverrideStorage";
89
- globalThis[F] || (globalThis[F] = new J());
90
- const w = globalThis[F];
91
- function se(n) {
92
- w.enterWith(n);
141
+ const C = "__sf_funcspanOverrideStorage";
142
+ globalThis[C] || (globalThis[C] = new Z());
143
+ const z = globalThis[C];
144
+ function be(n) {
145
+ z.enterWith(n);
93
146
  }
94
- function oe() {
95
- return w.getStore();
147
+ function ve() {
148
+ return z.getStore();
96
149
  }
97
- function ie() {
150
+ function Te() {
98
151
  }
99
- function ue(...n) {
152
+ function Fe(...n) {
100
153
  const t = {};
101
- for (const a of n) for (const o in a) a[o] !== void 0 && (t[o] = a[o]);
154
+ for (const s of n) for (const a in s) s[a] !== void 0 && (t[a] = s[a]);
102
155
  return t;
103
156
  }
104
- function K(n, t) {
157
+ function q(n, t) {
105
158
  try {
106
- const a = JSON.stringify(n).length / 1048576;
107
- return a <= t ? n : { _truncated: !0, _originalSizeMB: a.toFixed(2), _limitMB: t, _preview: JSON.stringify(n).substring(0, 500) + "..." };
159
+ const s = JSON.stringify(n).length / 1048576;
160
+ return s <= t ? n : { _truncated: !0, _originalSizeMB: s.toFixed(2), _limitMB: t, _preview: JSON.stringify(n).substring(0, 500) + "..." };
108
161
  } catch {
109
162
  return { _error: "Failed to serialize data", _type: typeof n };
110
163
  }
111
164
  }
112
- function y(n, t) {
113
- const a = process.env[n];
114
- return a === void 0 ? t : a === "true" || a === "1";
165
+ function N(n, t) {
166
+ const s = process.env[n];
167
+ return s === void 0 ? t : s === "true" || s === "1";
115
168
  }
116
- function D(n, t) {
117
- const a = process.env[n];
118
- if (a === void 0) return t;
119
- const o = parseFloat(a);
120
- return isNaN(o) ? t : o;
169
+ function x(n, t) {
170
+ const s = process.env[n];
171
+ if (s === void 0) return t;
172
+ const a = parseFloat(s);
173
+ return isNaN(a) ? t : a;
121
174
  }
122
- function A() {
123
- return { enabled: y("SF_WORKER_POOL_ENABLED", !0), trackFs: y("SF_WORKER_POOL_TRACK_FS", !1), trackDns: y("SF_WORKER_POOL_TRACK_DNS", !1), trackCrypto: y("SF_WORKER_POOL_TRACK_CRYPTO", !1), trackZlib: y("SF_WORKER_POOL_TRACK_ZLIB", !1), captureArguments: y("SF_WORKER_POOL_CAPTURE_ARGUMENTS", !0), captureReturnValue: y("SF_WORKER_POOL_CAPTURE_RETURN_VALUE", !0), argLimitMb: D("SF_WORKER_POOL_ARG_LIMIT_MB", 1), returnLimitMb: D("SF_WORKER_POOL_RETURN_LIMIT_MB", 1) };
175
+ function D() {
176
+ return { enabled: N("SF_WORKER_POOL_ENABLED", !0), trackFs: N("SF_WORKER_POOL_TRACK_FS", !1), trackDns: N("SF_WORKER_POOL_TRACK_DNS", !1), trackCrypto: N("SF_WORKER_POOL_TRACK_CRYPTO", !1), trackZlib: N("SF_WORKER_POOL_TRACK_ZLIB", !1), captureArguments: N("SF_WORKER_POOL_CAPTURE_ARGUMENTS", !0), captureReturnValue: N("SF_WORKER_POOL_CAPTURE_RETURN_VALUE", !0), argLimitMb: x("SF_WORKER_POOL_ARG_LIMIT_MB", 1), returnLimitMb: x("SF_WORKER_POOL_RETURN_LIMIT_MB", 1) };
124
177
  }
125
- function le(n) {
126
- const t = A();
178
+ function Ae(n) {
179
+ const t = D();
127
180
  if (!t.enabled) return !1;
128
181
  switch (n) {
129
182
  case "fs":
@@ -138,12 +191,12 @@ function le(n) {
138
191
  return !1;
139
192
  }
140
193
  }
141
- function B(n, t, a, o) {
142
- let s;
194
+ function G(n, t, s, a) {
195
+ let o;
143
196
  try {
144
197
  switch (n) {
145
198
  case "fs":
146
- s = (function(i, e) {
199
+ o = (function(i, e) {
147
200
  const r = {};
148
201
  switch (i) {
149
202
  case "readFile":
@@ -179,10 +232,10 @@ function B(n, t, a, o) {
179
232
  r.argsCount = e.length - 1;
180
233
  }
181
234
  return r;
182
- })(t, a);
235
+ })(t, s);
183
236
  break;
184
237
  case "dns":
185
- s = (function(i, e) {
238
+ o = (function(i, e) {
186
239
  const r = {};
187
240
  switch (i) {
188
241
  case "lookup":
@@ -204,10 +257,10 @@ function B(n, t, a, o) {
204
257
  r.argsCount = e.length - 1;
205
258
  }
206
259
  return r;
207
- })(t, a);
260
+ })(t, s);
208
261
  break;
209
262
  case "crypto":
210
- s = (function(i, e) {
263
+ o = (function(i, e) {
211
264
  const r = {};
212
265
  switch (i) {
213
266
  case "pbkdf2":
@@ -226,28 +279,28 @@ function B(n, t, a, o) {
226
279
  r.argsCount = e.length - 1;
227
280
  }
228
281
  return r;
229
- })(t, a);
282
+ })(t, s);
230
283
  break;
231
284
  case "zlib":
232
- s = (function(i, e) {
285
+ o = (function(i, e) {
233
286
  const r = {};
234
287
  return Buffer.isBuffer(e[0]) ? (r.inputType = "Buffer", r.inputSize = e[0].length) : typeof e[0] == "string" ? (r.inputType = "string", r.inputSize = e[0].length) : r.inputType = typeof e[0], e[1] && typeof e[1] == "object" && typeof e[1] != "function" && (r.options = { ...e[1] }), r;
235
- })(0, a);
288
+ })(0, s);
236
289
  break;
237
290
  default:
238
291
  return null;
239
292
  }
240
- return o > 0 ? K(s, o) : s;
293
+ return a > 0 ? q(o, a) : o;
241
294
  } catch {
242
- return { error: "Failed to capture arguments", argsCount: a.length - 1 };
295
+ return { error: "Failed to capture arguments", argsCount: s.length - 1 };
243
296
  }
244
297
  }
245
- function M(n, t, a, o) {
246
- let s;
298
+ function H(n, t, s, a) {
299
+ let o;
247
300
  try {
248
301
  switch (n) {
249
302
  case "fs":
250
- s = (function(i, e) {
303
+ o = (function(i, e) {
251
304
  if (!e) return null;
252
305
  switch (i) {
253
306
  case "readFile":
@@ -267,10 +320,10 @@ function M(n, t, a, o) {
267
320
  default:
268
321
  return e;
269
322
  }
270
- })(t, a);
323
+ })(t, s);
271
324
  break;
272
325
  case "dns":
273
- s = (function(i, e) {
326
+ o = (function(i, e) {
274
327
  if (!e) return null;
275
328
  switch (i) {
276
329
  case "lookup":
@@ -288,10 +341,10 @@ function M(n, t, a, o) {
288
341
  default:
289
342
  return e;
290
343
  }
291
- })(t, a);
344
+ })(t, s);
292
345
  break;
293
346
  case "crypto":
294
- s = (function(i, e) {
347
+ o = (function(i, e) {
295
348
  if (!e) return null;
296
349
  switch (i) {
297
350
  case "pbkdf2":
@@ -303,59 +356,59 @@ function M(n, t, a, o) {
303
356
  default:
304
357
  return e;
305
358
  }
306
- })(t, a);
359
+ })(t, s);
307
360
  break;
308
361
  case "zlib":
309
- s = (function(i, e) {
362
+ o = (function(i, e) {
310
363
  return e ? Buffer.isBuffer(e) ? { type: "Buffer", size: e.length } : typeof e == "string" ? { type: "string", size: e.length } : { type: typeof e } : null;
311
- })(0, a);
364
+ })(0, s);
312
365
  break;
313
366
  default:
314
367
  return null;
315
368
  }
316
- return o > 0 ? K(s, o) : s;
369
+ return a > 0 ? q(o, a) : o;
317
370
  } catch {
318
- return { error: "Failed to capture result", type: typeof a };
371
+ return { error: "Failed to capture result", type: typeof s };
319
372
  }
320
373
  }
321
- function G(n) {
374
+ function le(n) {
322
375
  return n.operationType === "worker_pool";
323
376
  }
324
- class Q extends j {
377
+ class ce extends oe {
325
378
  constructor() {
326
379
  super(), this.operationName = "CollectFunctionSpans";
327
380
  }
328
381
  send(t) {
329
- const a = f().sfDebug;
330
- a && console.log(`[FunctionSpanTransmitter] Preparing to send ${t.length} function span(s)`);
331
- for (const o of t) try {
332
- if (G(o)) {
333
- this.sendWorkerPoolSpan(o, a);
382
+ const s = S().sfDebug;
383
+ s && console.log(`[FunctionSpanTransmitter] Preparing to send ${t.length} function span(s)`);
384
+ for (const a of t) try {
385
+ if (le(a)) {
386
+ this.sendWorkerPoolSpan(a, s);
334
387
  continue;
335
388
  }
336
- const s = o;
389
+ const o = a;
337
390
  let i;
338
- if (s.result !== void 0 && s.result !== null) {
339
- const r = typeof s.result;
340
- i = JSON.stringify({ type: r, has_value: !0, value: s.result });
341
- } else i = s.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
342
- const e = this.getVariables({ library: "JS/TS BACKEND", version: f().version, spanId: s.spanId, parentSpanId: s.parentSpanId, filePath: s.filePath, lineNumber: s.metadata.line, columnNumber: s.metadata.column, functionName: s.functionName, arguments: JSON.stringify(s.args || {}), returnValue: i, startTimeNs: (1e6 * Date.now() - 1e6 * s.duration).toString(), durationNs: (1e6 * s.duration).toString() });
343
- a && (console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(e, null, 2))), E(this.endpoint, this.operationName, this.getQuery(), e), a && console.log(`[FunctionSpanTransmitter] Queued function span for ${s.functionName}`);
344
- } catch (s) {
345
- console.error(`[FunctionSpanTransmitter] Error preparing function span for ${o.functionName}:`, s);
391
+ if (o.result !== void 0 && o.result !== null) {
392
+ const r = typeof o.result;
393
+ i = JSON.stringify({ type: r, has_value: !0, value: o.result });
394
+ } else i = o.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
395
+ const e = this.getVariables({ library: "JS/TS BACKEND", version: S().version, spanId: o.spanId, parentSpanId: o.parentSpanId, filePath: o.filePath, lineNumber: o.metadata.line, columnNumber: o.metadata.column, functionName: o.functionName, arguments: JSON.stringify(o.args || {}), returnValue: i, startTimeNs: (1e6 * Date.now() - 1e6 * o.duration).toString(), durationNs: (1e6 * o.duration).toString() });
396
+ s && (console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(e, null, 2))), V(this.endpoint, this.operationName, this.getQuery(), e), s && console.log(`[FunctionSpanTransmitter] Queued function span for ${o.functionName}`);
397
+ } catch (o) {
398
+ console.error(`[FunctionSpanTransmitter] Error preparing function span for ${a.functionName}:`, o);
346
399
  }
347
400
  }
348
- sendWorkerPoolSpan(t, a) {
401
+ sendWorkerPoolSpan(t, s) {
349
402
  try {
350
- let o;
403
+ let a;
351
404
  if (t.result !== void 0 && t.result !== null) {
352
405
  const i = typeof t.result;
353
- o = JSON.stringify({ type: i, has_value: !0, value: t.result });
354
- } else o = t.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
355
- const s = this.getVariables({ library: "JS/TS BACKEND", version: f().version, spanId: t.spanId, operationName: t.operationName, moduleName: t.moduleName, methodName: t.methodName, startTimeNs: t.startTimeNs, durationNs: t.durationNs, arguments: JSON.stringify(t.args || {}), returnValue: o, error: t.error, pid: t.pid, threadId: t.threadId });
356
- a && (console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(s, null, 2))), E(this.endpoint, "CollectWorkerPoolSpans", this.getWorkerPoolQuery(), s), a && console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${t.operationName}`);
357
- } catch (o) {
358
- console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${t.operationName}:`, o);
406
+ a = JSON.stringify({ type: i, has_value: !0, value: t.result });
407
+ } else a = t.result === null ? JSON.stringify({ type: "null", has_value: !0, value: null }) : JSON.stringify({ type: "undefined", has_value: !1, value: null });
408
+ const o = this.getVariables({ library: "JS/TS BACKEND", version: S().version, spanId: t.spanId, operationName: t.operationName, moduleName: t.moduleName, methodName: t.methodName, startTimeNs: t.startTimeNs, durationNs: t.durationNs, arguments: JSON.stringify(t.args || {}), returnValue: a, error: t.error, pid: t.pid, threadId: t.threadId });
409
+ s && (console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`), console.log("[FunctionSpanTransmitter] Variables:", JSON.stringify(o, null, 2))), V(this.endpoint, "CollectWorkerPoolSpans", this.getWorkerPoolQuery(), o), s && console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${t.operationName}`);
410
+ } catch (a) {
411
+ console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${t.operationName}:`, a);
359
412
  }
360
413
  }
361
414
  getWorkerPoolQuery() {
@@ -445,77 +498,78 @@ class Q extends j {
445
498
  `;
446
499
  }
447
500
  }
448
- let v = null;
449
- function ce(n, t, a, o, s) {
450
- const i = O(), e = i?.sfDebug || !1;
501
+ let P = null;
502
+ function ke(n, t, s, a, o) {
503
+ const i = M(), e = i?.sfDebug || !1;
451
504
  e && console.log(`[WorkerPool] Capturing ${n}.${t}`);
452
- const r = A(), u = P.getInstance().getCurrentFunctionSpanId(), d = L();
505
+ const r = D(), u = L.getInstance().getCurrentFunctionSpanId(), d = j();
453
506
  e && console.log(`[WorkerPool] Span ID: ${d}, Parent: ${u || "none"}`);
454
- const l = new z("WorkerPoolOperation"), p = process.hrtime.bigint();
507
+ const l = new Y("WorkerPoolOperation"), p = process.hrtime.bigint();
455
508
  let c = null;
456
- r.captureArguments && (c = B(n, t, o, r.argLimitMb));
457
- const g = o.findIndex((N) => typeof N == "function");
458
- if (g === -1) return e && console.log(`[WorkerPool] No callback found for ${n}.${t}`), a.apply(s, o);
459
- const m = o[g], h = [...o];
460
- return h[g] = function(N, ...b) {
461
- const I = process.hrtime.bigint() - p, U = Number(I) / 1e6;
462
- m(N, ...b), l.runInAsyncScope(() => {
463
- e && console.log(`[WorkerPool] ${n}.${t} completed in ${U.toFixed(3)}ms (${I}ns)`);
464
- let R = null, C = null;
465
- N ? C = N?.message || String(N) : r.captureReturnValue && b.length > 0 && (R = M(n, t, b[0], r.returnLimitMb)), k({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: U, durationNs: I.toString(), startTimeNs: p.toString(), args: c, result: R, error: C, spanId: d, parentSpanId: u, pid: process.pid, threadId: T });
509
+ r.captureArguments && (c = G(n, t, a, r.argLimitMb));
510
+ const f = a.findIndex((h) => typeof h == "function");
511
+ if (f === -1) return e && console.log(`[WorkerPool] No callback found for ${n}.${t}`), s.apply(o, a);
512
+ const _ = a[f], I = [...a];
513
+ return I[f] = function(h, ...T) {
514
+ const F = process.hrtime.bigint() - p, w = Number(F) / 1e6;
515
+ _(h, ...T), l.runInAsyncScope(() => {
516
+ e && console.log(`[WorkerPool] ${n}.${t} completed in ${w.toFixed(3)}ms (${F}ns)`);
517
+ let W = null, K = null;
518
+ h ? K = h?.message || String(h) : r.captureReturnValue && T.length > 0 && (W = H(n, t, T[0], r.returnLimitMb)), E({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: w, durationNs: F.toString(), startTimeNs: p.toString(), args: c, result: W, error: K, spanId: d, parentSpanId: u, pid: process.pid, threadId: O });
466
519
  }), l.emitDestroy();
467
- }, a.apply(s, h);
520
+ }, s.apply(o, I);
468
521
  }
469
- function pe(n, t, a, o, s) {
470
- const i = O(), e = i?.sfDebug || !1;
522
+ function Pe(n, t, s, a, o) {
523
+ const i = M(), e = i?.sfDebug || !1;
471
524
  e && console.log(`[WorkerPool] Capturing ${n}.${t} (Promise)`);
472
- const r = A(), u = P.getInstance().getCurrentFunctionSpanId(), d = L();
525
+ const r = D(), u = L.getInstance().getCurrentFunctionSpanId(), d = j();
473
526
  e && console.log(`[WorkerPool] Span ID: ${d}, Parent: ${u || "none"}`);
474
527
  const l = process.hrtime.bigint();
475
528
  let p = null;
476
- return r.captureArguments && (p = B(n, t, o, r.argLimitMb)), a.apply(s, o).then((c) => {
477
- const g = process.hrtime.bigint() - l, m = Number(g) / 1e6;
478
- e && console.log(`[WorkerPool] ${n}.${t} completed in ${m.toFixed(3)}ms (${g}ns)`);
479
- let h = null;
480
- return r.captureReturnValue && (h = M(n, t, c, r.returnLimitMb)), k({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: m, durationNs: g.toString(), startTimeNs: l.toString(), args: p, result: h, error: null, spanId: d, parentSpanId: u, pid: process.pid, threadId: T }), c;
529
+ return r.captureArguments && (p = G(n, t, a, r.argLimitMb)), s.apply(o, a).then((c) => {
530
+ const f = process.hrtime.bigint() - l, _ = Number(f) / 1e6;
531
+ e && console.log(`[WorkerPool] ${n}.${t} completed in ${_.toFixed(3)}ms (${f}ns)`);
532
+ let I = null;
533
+ return r.captureReturnValue && (I = H(n, t, c, r.returnLimitMb)), E({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: _, durationNs: f.toString(), startTimeNs: l.toString(), args: p, result: I, error: null, spanId: d, parentSpanId: u, pid: process.pid, threadId: O }), c;
481
534
  }, (c) => {
482
- const g = process.hrtime.bigint() - l, m = Number(g) / 1e6;
483
- throw e && console.log(`[WorkerPool] ${n}.${t} failed in ${m.toFixed(3)}ms: ${c?.message || c}`), k({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: m, durationNs: g.toString(), startTimeNs: l.toString(), args: p, result: null, error: c?.message || String(c), spanId: d, parentSpanId: u, pid: process.pid, threadId: T }), c;
535
+ const f = process.hrtime.bigint() - l, _ = Number(f) / 1e6;
536
+ throw e && console.log(`[WorkerPool] ${n}.${t} failed in ${_.toFixed(3)}ms: ${c?.message || c}`), E({ operationType: "worker_pool", operationName: `${n}.${t}`, moduleName: n, methodName: t, duration: _, durationNs: f.toString(), startTimeNs: l.toString(), args: p, result: null, error: c?.message || String(c), spanId: d, parentSpanId: u, pid: process.pid, threadId: O }), c;
484
537
  });
485
538
  }
486
- function k(n) {
487
- const t = O(), a = t?.sfDebug || !1;
488
- a && console.log("[WorkerPool] Capturing span:", { operation: n.operationName, duration: `${n.duration}ms`, error: n.error, spanId: n.spanId, parentSpanId: n.parentSpanId }), process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
539
+ function E(n) {
540
+ const t = M(), s = t?.sfDebug || !1;
541
+ s && console.log("[WorkerPool] Capturing span:", { operation: n.operationName, duration: `${n.duration}ms`, error: n.error, spanId: n.spanId, parentSpanId: n.parentSpanId }), process.env.SF_FUNCSPAN_CONSOLE_OUTPUT === "true" && console.log(`
489
542
  ⚙️ Worker Pool Operation:`, { operation: n.operationName, duration: `${n.duration.toFixed(2)}ms`, arguments: n.args, result: n.error ? `Error: ${n.error}` : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId || "none" });
490
- const o = process.env.SF_FUNCSPAN_JSONL_FILE;
491
- if (o) try {
492
- const s = o === "true" || o === "1" ? "funcspans.jsonl" : o, i = Date.now(), e = process.hrtime.bigint(), r = BigInt(n.startTimeNs), u = Number(e - r) / 1e6, d = new Date(i - u).toISOString(), l = JSON.stringify({ timestamp: d, operationType: n.operationType, operationName: n.operationName, moduleName: n.moduleName, methodName: n.methodName, duration: n.duration, durationNs: n.durationNs, startTimeNs: n.startTimeNs, arguments: n.args, returnValue: n.error ? { error: String(n.error) } : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId, pid: n.pid, threadId: n.threadId }) + `
543
+ const a = process.env.SF_FUNCSPAN_JSONL_FILE;
544
+ if (a) try {
545
+ const o = a === "true" || a === "1" ? "funcspans.jsonl" : a, i = Date.now(), e = process.hrtime.bigint(), r = BigInt(n.startTimeNs), u = Number(e - r) / 1e6, d = new Date(i - u).toISOString(), l = JSON.stringify({ timestamp: d, operationType: n.operationType, operationName: n.operationName, moduleName: n.moduleName, methodName: n.methodName, duration: n.duration, durationNs: n.durationNs, startTimeNs: n.startTimeNs, arguments: n.args, returnValue: n.error ? { error: String(n.error) } : n.result, spanId: n.spanId, parentSpanId: n.parentSpanId, pid: n.pid, threadId: n.threadId }) + `
493
546
  `;
494
- x(s, l, "utf-8");
495
- } catch (s) {
496
- console.error("[WorkerPool] Error writing to JSONL file:", s);
547
+ ee(o, l, "utf-8");
548
+ } catch (o) {
549
+ console.error("[WorkerPool] Error writing to JSONL file:", o);
497
550
  }
498
- if (a && console.log("[WorkerPool] Sending span to transmitter"), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
499
- (v || (v = new Q()), v).send([n]), a && console.log("[WorkerPool] Span sent successfully");
500
- } catch (s) {
501
- a && console.error("[WorkerPool] Error sending span:", s);
551
+ if (s && console.log("[WorkerPool] Sending span to transmitter"), process.env.SF_FUNCSPAN_SKIP_BACKEND !== "true") try {
552
+ (P || (P = new ce()), P).send([n]), s && console.log("[WorkerPool] Span sent successfully");
553
+ } catch (o) {
554
+ s && console.error("[WorkerPool] Error sending span:", o);
502
555
  }
503
556
  }
504
557
  export {
505
- j as B,
506
- Q as F,
507
- re as a,
508
- ne as b,
509
- ce as c,
510
- pe as d,
511
- le as e,
512
- w as f,
513
- oe as g,
514
- ie as h,
515
- te as i,
516
- ue as m,
517
- E as n,
518
- ae as p,
519
- se as s,
520
- K as t
558
+ oe as B,
559
+ ce as F,
560
+ $e as a,
561
+ he as b,
562
+ ke as c,
563
+ Pe as d,
564
+ Ae as e,
565
+ z as f,
566
+ ve as g,
567
+ Te as h,
568
+ ye as i,
569
+ Fe as m,
570
+ V as n,
571
+ Ie as p,
572
+ Ne as r,
573
+ be as s,
574
+ q as t
521
575
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailfish-ai/sf-veritas",
3
- "version": "0.2.21",
3
+ "version": "0.3.1",
4
4
  "publishPublicly": true,
5
5
  "description": "A versatile Edge Runtime-compatible package for JavaScript and TypeScript backend systems and scripts.",
6
6
  "main": "./dist/sf-veritas.cjs",
@@ -102,19 +102,35 @@
102
102
  }
103
103
  },
104
104
  "devDependencies": {
105
+ "@apollo/server": "^5.5.0",
106
+ "@hapi/hapi": "^21.4.8",
107
+ "@nestjs/common": "^11.1.19",
108
+ "@nestjs/core": "^11.1.19",
109
+ "@nestjs/platform-express": "^11.1.19",
105
110
  "@rollup/plugin-terser": "^0.4.4",
106
111
  "@types/babel__core": "^7.20.5",
107
112
  "@types/babel__generator": "^7.6.8",
108
113
  "@types/babel__traverse": "^7.20.6",
114
+ "@types/express": "^5.0.6",
109
115
  "@types/js-yaml": "^4.0.9",
116
+ "@types/koa": "^3.0.2",
110
117
  "@types/node": "^22.13.10",
111
118
  "@types/uuid": "^10.0.0",
112
119
  "@types/webpack": "^5.28.5",
113
120
  "esbuild": "^0.23.0",
114
121
  "eslint": "^9.22.0",
115
122
  "eslint-config-next": "^15.2.3",
123
+ "express": "^5.2.1",
124
+ "fastify": "^5.8.5",
125
+ "graphql": "^16.13.2",
126
+ "graphql-http": "^1.22.4",
127
+ "graphql-yoga": "^5.21.0",
128
+ "koa": "^3.2.0",
129
+ "mercurius": "^16.9.0",
130
+ "reflect-metadata": "^0.2.2",
116
131
  "rollup": "^3.29.5",
117
132
  "rollup-plugin-dts": "^5.3.1",
133
+ "rxjs": "^7.8.2",
118
134
  "ts-node": "^10.9.2",
119
135
  "typescript": "^5.8.2",
120
136
  "vite": "^6.2.2",