@sailfish-ai/sf-veritas 0.2.13 → 0.2.16

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 (33) hide show
  1. package/dist/contextManager-Cx03mw7l.js +258 -0
  2. package/dist/contextManager-CxQqBCEA.cjs +1 -0
  3. package/dist/funcSpanTransformer-Byqzu4B1.js +231 -0
  4. package/dist/funcSpanTransformer-CDh0o-AP.cjs +1 -0
  5. package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
  6. package/dist/plugins/funcspanEsbuildPlugin.mjs +2 -2
  7. package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
  8. package/dist/plugins/funcspanRollupPlugin.mjs +2 -2
  9. package/dist/plugins/funcspanTscPlugin.cjs +1 -1
  10. package/dist/plugins/funcspanTscPlugin.mjs +2 -2
  11. package/dist/plugins/funcspanVitePlugin.cjs +1 -1
  12. package/dist/plugins/funcspanVitePlugin.mjs +2 -2
  13. package/dist/plugins/funcspanWebpackLoader.cjs +1 -1
  14. package/dist/plugins/funcspanWebpackLoader.mjs +1 -1
  15. package/dist/plugins/funcspanWebpackPlugin.cjs +1 -1
  16. package/dist/plugins/funcspanWebpackPlugin.mjs +1 -1
  17. package/dist/{runtimeConfig-CgLfwL3X.js → runtimeConfig-DndXTWki.js} +130 -127
  18. package/dist/{runtimeConfig-DIsq-KCn.cjs → runtimeConfig-TWzqPe1S.cjs} +7 -7
  19. package/dist/sf-veritas.cjs +37 -12
  20. package/dist/sf-veritas.mjs +574 -509
  21. package/dist/types/funcSpanConfig.d.ts +0 -4
  22. package/dist/types/funcSpanConfigLoader.d.ts +1 -1
  23. package/dist/types/networkRequestTransmitter.d.ts +4 -0
  24. package/dist/types/setupConfig.d.ts +35 -0
  25. package/dist/worker-pool-capture.cjs +1 -1
  26. package/dist/worker-pool-capture.mjs +1 -1
  27. package/dist/{workerPoolSpanCapture-D85i6nhQ.cjs → workerPoolSpanCapture-COwiNikM.cjs} +2 -2
  28. package/dist/{workerPoolSpanCapture-BYaf3NOr.js → workerPoolSpanCapture-d-8ExI18.js} +84 -82
  29. package/package.json +2 -1
  30. package/dist/contextManager-BkETRITg.cjs +0 -1
  31. package/dist/contextManager-CEPhVu9T.js +0 -197
  32. package/dist/funcSpanTransformer-B9WWl-g1.cjs +0 -1
  33. package/dist/funcSpanTransformer-CWNEWRxq.js +0 -225
@@ -1,197 +0,0 @@
1
- var L = Object.defineProperty;
2
- var _ = (n, e, t) => e in n ? L(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var r = (n, e, t) => _(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { AsyncLocalStorage as T } from "async_hooks";
5
- const a = [];
6
- for (let n = 0; n < 256; ++n) a.push((n + 256).toString(16).slice(1));
7
- let C;
8
- const U = new Uint8Array(16), f = { randomUUID: typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
9
- function l(n, e, t) {
10
- if (f.randomUUID && !n) return f.randomUUID();
11
- const o = (n = n || {}).random ?? n.rng?.() ?? (function() {
12
- if (!C) {
13
- if (typeof crypto > "u" || !crypto.getRandomValues) throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
14
- C = crypto.getRandomValues.bind(crypto);
15
- }
16
- return C(U);
17
- })();
18
- if (o.length < 16) throw new Error("Random bytes length must be >= 16");
19
- return o[6] = 15 & o[6] | 64, o[8] = 63 & o[8] | 128, (function(i, s = 0) {
20
- return (a[i[s + 0]] + a[i[s + 1]] + a[i[s + 2]] + a[i[s + 3]] + "-" + a[i[s + 4]] + a[i[s + 5]] + "-" + a[i[s + 6]] + a[i[s + 7]] + "-" + a[i[s + 8]] + a[i[s + 9]] + "-" + a[i[s + 10]] + a[i[s + 11]] + a[i[s + 12]] + a[i[s + 13]] + a[i[s + 14]] + a[i[s + 15]]).toLowerCase();
21
- })(o);
22
- }
23
- class b {
24
- constructor(e) {
25
- r(this, "apiKey");
26
- r(this, "apiGraphqlEndpoint");
27
- r(this, "sfDebug");
28
- r(this, "serviceIdentifier");
29
- r(this, "serviceVersion");
30
- r(this, "serviceUUID");
31
- r(this, "serviceAdditionalMetadata");
32
- r(this, "profilingModeEnabled");
33
- r(this, "profilingMaxDepth");
34
- r(this, "profilingMaxVariableSizeKb");
35
- r(this, "domainsToNotPropagateHeadersTo");
36
- r(this, "nodeModulesToCollectLocalVariablesOn");
37
- r(this, "printConfigurationStatuses");
38
- r(this, "logLevel");
39
- r(this, "stackDepthLocals");
40
- r(this, "stackDepthCodeTraceDepth");
41
- r(this, "packageLibraryType");
42
- r(this, "version");
43
- r(this, "gitSha");
44
- r(this, "_serviceIdentificationReceived", !1);
45
- this.apiKey = e.apiKey, this.apiGraphqlEndpoint = e?.apiGraphqlEndpoint || process.env.SAILFISH_GRAPHQL_ENDPOINT || "https://api-service.sailfishqa.com/graphql/", this.sfDebug = e?.debug === !0 || process.env.SF_DEBUG === "true", this.serviceIdentifier = e?.serviceIdentifier || process.env.SERVICE_IDENTIFIER, this.serviceUUID = l(), this.serviceVersion = e?.serviceVersion || process.env.SERVICE_VERSION, this.gitSha = e?.gitSha || process.env.GIT_SHA || process.env.VERCEL_GIT_COMMIT_SHA, this.serviceAdditionalMetadata = e?.serviceAdditionalMetadata || {}, this.profilingModeEnabled = e?.profilingModeEnabled ?? !1, this.profilingMaxDepth = e?.profilingMaxDepth ?? 5, this.profilingMaxVariableSizeKb = e?.profilingMaxVariableSizeKb ?? 25, this.domainsToNotPropagateHeadersTo = e?.domainsToNotPropagateHeadersTo || [], this.nodeModulesToCollectLocalVariablesOn = e?.nodeModulesToCollectLocalVariablesOn || ["_all_"], this.printConfigurationStatuses = process.env.PRINT_CONFIGURATION_STATUSES || "true", this.logLevel = process.env.LOG_LEVEL || "INFO", this.stackDepthLocals = process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS !== void 0 ? parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS, 10) : 5, isNaN(this.stackDepthLocals) && (this.stackDepthLocals = -1), this.stackDepthCodeTraceDepth = process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH !== void 0 ? parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH, 10) : -1, isNaN(this.stackDepthCodeTraceDepth) && (this.stackDepthCodeTraceDepth = -1), this.packageLibraryType = "JS/TS BACKEND", this.version = this.getPackageVersion();
46
- }
47
- getPackageVersion() {
48
- return "0.1.15";
49
- }
50
- get serviceIdentificationReceived() {
51
- return this._serviceIdentificationReceived;
52
- }
53
- setServiceIdentificationReceived(e) {
54
- this._serviceIdentificationReceived = e;
55
- }
56
- }
57
- const x = Symbol.for("sailfish.sf_config");
58
- function m() {
59
- return globalThis[x];
60
- }
61
- function P(n) {
62
- const e = m();
63
- if (e) return { config: e };
64
- const t = new b(n);
65
- return (function(o) {
66
- globalThis[x] = o;
67
- })(t), t.sfDebug && console.log("[[getOrCreateConfig]] Created global config:", t), { config: t };
68
- }
69
- function I() {
70
- const n = m();
71
- if (!n) throw new Error("Configuration has not been initialized. Call getOrCreateConfig(options) first.");
72
- return n;
73
- }
74
- const D = Symbol.for("sf.ctx.storeAls"), c = globalThis, S = c[D] ?? (c[D] = new T()), y = ["identitytoolkit.googleapis.com", "t.co", "*.twitter.com", "*.gravatar.com", "*.googleapis.com", "*.amazonaws.com", "*.smooch.io", "*.zendesk.com"], E = Symbol.for("sf.ctx.als"), p = c[E] ?? (c[E] = new T()), v = Symbol.for("sf.ctx.sessionRegistry"), u = c[v] ?? (c[v] = /* @__PURE__ */ new Map()), g = { handledExceptions: /* @__PURE__ */ new Set(), reentrancyGuardLoggingActive: !1, reentrancyGuardLoggingPreActive: !1, reentrancyGuardPrintActive: !1, reentrancyGuardPrintPreActive: !1, reentrancyGuardExceptionActive: !1, reentrancyGuardExceptionPreActive: !1, excludedDomains: new Set(y), supportedDomains: /* @__PURE__ */ new Set() }, d = class d {
75
- constructor() {
76
- }
77
- current() {
78
- return S.getStore();
79
- }
80
- ensureStore() {
81
- const e = this.current();
82
- if (e) return e;
83
- const t = /* @__PURE__ */ new Map();
84
- return S.enterWith(t), t;
85
- }
86
- runWith(e, t) {
87
- const o = this.current() ?? /* @__PURE__ */ new Map(), i = new Map(o);
88
- for (const [s, A] of Object.entries(e)) i.set(s, A);
89
- return S.run(i, t);
90
- }
91
- static getInstance() {
92
- return c[d.GLOBAL_MANAGER_SYMBOL] || (c[d.GLOBAL_MANAGER_SYMBOL] = new d()), c[d.GLOBAL_MANAGER_SYMBOL];
93
- }
94
- getCurrentContext() {
95
- return p.getStore() || g;
96
- }
97
- setCurrentContext(e) {
98
- const t = p.getStore() || g;
99
- p.enterWith({ ...t, ...e });
100
- }
101
- ensureSession(e) {
102
- let t = u.get(e);
103
- return t || (t = { ...g }, u.set(e, t)), t;
104
- }
105
- getContextFor(e) {
106
- return u.get(e) ?? g;
107
- }
108
- updateContextFor(e, t) {
109
- const o = this.ensureSession(e);
110
- u.set(e, { ...o, ...t });
111
- }
112
- runWithSession(e, t) {
113
- const o = { ...this.ensureSession(e) };
114
- return p.run(o, t);
115
- }
116
- deleteSession(e) {
117
- u.delete(e);
118
- }
119
- getTraceId() {
120
- return this.getCurrentContext().traceId;
121
- }
122
- getPageVisitUUID() {
123
- return this.getCurrentContext().pageVisitUUID;
124
- }
125
- setTraceId(e) {
126
- this.setCurrentContext({ traceId: e });
127
- }
128
- setPageVisitUUID(e) {
129
- this.setCurrentContext({ pageVisitUUID: e });
130
- }
131
- getCurrentFunctionSpanId() {
132
- return this.getCurrentContext().currentFunctionSpanId;
133
- }
134
- setCurrentFunctionSpanId(e) {
135
- this.setCurrentContext({ currentFunctionSpanId: e });
136
- }
137
- clearCurrentFunctionSpanId() {
138
- this.setCurrentContext({ currentFunctionSpanId: void 0 });
139
- }
140
- getOrSetSfTraceId(e, t = !1) {
141
- let o = this.getTraceId();
142
- return o || (o = e || (t ? l() : `nonsession-applogs-v3/${I().apiKey}/${l()}`), this.setTraceId(o), I().sfDebug && console.log(" Created new trace ID:", o), o);
143
- }
144
- getOrSetPageVisitUUID() {
145
- let e = this.getPageVisitUUID();
146
- return e || (e = l(), this.setPageVisitUUID(e), I().sfDebug && console.log(" Created new page visit UUID:", e), e);
147
- }
148
- getHandledExceptions() {
149
- return this.getCurrentContext().handledExceptions;
150
- }
151
- markExceptionHandled(e) {
152
- const t = this.getHandledExceptions();
153
- t.add(e), this.setCurrentContext({ handledExceptions: t });
154
- }
155
- hasHandledException(e) {
156
- return this.getHandledExceptions().has(e);
157
- }
158
- resetHandledExceptions() {
159
- this.setCurrentContext({ handledExceptions: /* @__PURE__ */ new Set() });
160
- }
161
- getExcludedDomains() {
162
- return this.getCurrentContext().excludedDomains;
163
- }
164
- getSupportedDomains() {
165
- return this.getCurrentContext().supportedDomains;
166
- }
167
- addSupportedDomains(e) {
168
- this.getCurrentContext().supportedDomains.add(e.toLowerCase().trim());
169
- }
170
- setTraceIdFor(e, t) {
171
- this.updateContextFor(e, { traceId: t });
172
- }
173
- setPageVisitUUIDFor(e, t) {
174
- this.updateContextFor(e, { pageVisitUUID: t });
175
- }
176
- };
177
- r(d, "GLOBAL_MANAGER_SYMBOL", Symbol.for("sf.ctx.manager"));
178
- let h = d;
179
- function V(n) {
180
- const e = { ...h.getInstance().getCurrentContext() };
181
- p.run(e, () => {
182
- n();
183
- });
184
- }
185
- function w() {
186
- return h.getInstance().getCurrentFunctionSpanId();
187
- }
188
- export {
189
- h as C,
190
- y as D,
191
- m as a,
192
- w as b,
193
- P as c,
194
- I as g,
195
- V as r,
196
- l as v
197
- };
@@ -1 +0,0 @@
1
- "use strict";const O=require("@babel/parser"),w=require("@babel/traverse"),C=require("@babel/generator"),K=require("@babel/types"),F=require("path"),R=require("fs"),z=require("./source-map-rHHEdpre.cjs");function V(d){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(d){for(const o in d)if(o!=="default"){const L=Object.getOwnPropertyDescriptor(d,o);Object.defineProperty(t,o,L.get?L:{enumerable:!0,get:()=>d[o]})}}return t.default=d,Object.freeze(t)}const e=V(K),W=new Set(["register","setupInterceptors","initializeConfigLoader","initializeWorkerPoolPatching"]),M=[/instrumentation\.(ts|js|tsx|jsx)$/,/unifiedInterceptor\.(ts|js)$/];let D=!1;const _=w.default||w,q=C.default||C;function $(d){const t=[];for(const o of d)e.isIdentifier(o)?t.push(o.name):e.isRestElement(o)&&e.isIdentifier(o.argument)?t.push(`...${o.argument.name}`):e.isAssignmentPattern(o)&&e.isIdentifier(o.left)?t.push(o.left.name):e.isObjectPattern(o)?t.push("{}"):e.isArrayPattern(o)?t.push("[]"):t.push("_");return t}function A(d){let t=!1;return _(d,{ImportDeclaration(o){e.isStringLiteral(o.node.source)&&o.node.source.value==="@sailfish-ai/sf-veritas"&&o.node.specifiers.some(L=>e.isImportSpecifier(L)&&e.isIdentifier(L.imported)&&L.imported.name==="captureFunctionSpan")&&(t=!0,o.stop())},VariableDeclarator(o){if(e.isObjectPattern(o.node.id)&&e.isCallExpression(o.node.init)&&e.isIdentifier(o.node.init.callee)&&o.node.init.callee.name==="require"){const L=o.node.init.arguments;L.length>0&&e.isStringLiteral(L[0])&&L[0].value==="@sailfish-ai/sf-veritas"&&o.node.id.properties.some(I=>e.isObjectProperty(I)&&e.isIdentifier(I.key)&&I.key.name==="captureFunctionSpan")&&(t=!0,o.stop())}}}),t}function G(d){let t=!1;return _(d,{CallExpression(o){e.isIdentifier(o.node.callee)&&o.node.callee.name==="require"&&(t=!0,o.stop())},MemberExpression(o){!e.isIdentifier(o.node.object)||o.node.object.name!=="module"&&o.node.object.name!=="exports"||(t=!0,o.stop())}}),t}exports.setSkipTypeScriptPlugin=function(d){D=d},exports.transformFunctionSpans=async function(d,t,o={}){const{projectRoot:L=process.cwd(),includeNodeModules:I=[],debug:u=!1}=o;if(t.includes("node_modules")&&!I.some(n=>t.includes(`node_modules/${n}`)))return{code:d,modified:!1,functionsWrapped:0};if(M.some(n=>n.test(t)))return u&&console.log(`[FuncSpan Transform] SKIPPING instrumentation entry point file: ${t}`),{code:d,modified:!1,functionsWrapped:0};const k=F.relative(L,t).replace(/\\/g,"/");let h;u&&console.log(`[FuncSpan Transform] Processing: ${k}`);try{h=O.parse(d,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy","classProperties","objectRestSpread","asyncGenerators","dynamicImport","optionalCatchBinding","optionalChaining","nullishCoalescingOperator"]})}catch(n){return u&&console.error(`[FuncSpan Transform] Parse error in ${k}:`,n),{code:d,modified:!1,functionsWrapped:0}}let v=null,T=null;try{const n=R.readFileSync(`${t}.map`,"utf-8");v=await new z.sourceMapExports.SourceMapConsumer(JSON.parse(n))}catch{}const E=(n,r)=>{if(v){const i=v.originalPositionFor({line:n,column:r});if(i.line!==null&&i.column!==null)return!T&&i.source&&(T=i.source),{line:i.line,column:i.column,source:i.source||void 0}}return{line:n,column:r}};let x=!1,S=0;const g=new Set;if(_(h,{FunctionDeclaration(n){const r=n.node.id?.name;if(!r)return;if(W.has(r))return void(u&&console.log(`[FuncSpan Transform] SKIPPING entry point function: ${r}`));const i=`decl_${r}`;if(g.has(i))return;u&&console.log(`[FuncSpan Transform] Wrapping function declaration: ${r}`);const s=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,l=E(s,a),{line:m,column:c}=l;let p=t;l.source&&(p=F.resolve(F.dirname(t),l.source)),!u||m===s&&c===a||console.log(`[FuncSpan Transform] Mapped ${s}:${a} → ${m}:${c} in ${p}`);const y=$(n.node.params),f=e.callExpression(e.identifier("captureFunctionSpan"),[e.identifier(r),e.stringLiteral(r),e.stringLiteral(p),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(c)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(j=>e.stringLiteral(j))))])]),b=e.expressionStatement(e.assignmentExpression("=",e.identifier(r),f));n.insertAfter(b),x=!0,S++,g.add(i)},VariableDeclarator(n){const r=n.node.id,i=n.node.init;if(!e.isIdentifier(r)||!i||!e.isFunctionExpression(i)&&!e.isArrowFunctionExpression(i))return;const s=r.name;if(W.has(s))return void(u&&console.log(`[FuncSpan Transform] SKIPPING entry point function: ${s}`));const a=`var_${s}`;if(g.has(a))return;u&&console.log(`[FuncSpan Transform] Wrapping variable function: ${s}`);const l=i.loc?.start.line??0,m=i.loc?.start.column??0,c=E(l,m),{line:p,column:y}=c;let f=t;c.source&&(f=F.resolve(F.dirname(t),c.source)),!u||p===l&&y===m||console.log(`[FuncSpan Transform] Mapped ${l}:${m} → ${p}:${y} in ${f}`);const b=$(i.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[i,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.init=j,x=!0,S++,g.add(a)},ClassMethod(n){if(n.node.kind==="constructor"||n.node.kind==="get"||n.node.kind==="set")return;const r=e.isIdentifier(n.node.key)?n.node.key.name:"anonymous",i=`method_${r}_${n.node.start}`;if(g.has(i))return;u&&console.log(`[FuncSpan Transform] Wrapping class method: ${r}`);const s=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,l=E(s,a),{line:m,column:c}=l,p=t,y=$(n.node.params),f=n.node.body,b=e.functionExpression(null,n.node.params,f,n.node.generator,n.node.async),j=e.callExpression(e.identifier("captureFunctionSpan"),[b,e.stringLiteral(r),e.stringLiteral(p),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(c)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(N=>e.stringLiteral(N))))])]),P=e.blockStatement([e.returnStatement(e.callExpression(e.memberExpression(j,e.identifier("call")),[e.thisExpression(),e.spreadElement(e.identifier("arguments"))]))]);n.node.body=P,x=!0,S++,g.add(i)},ObjectMethod(n){if(n.node.kind==="get"||n.node.kind==="set")return;const r=e.isIdentifier(n.node.key)?n.node.key.name:e.isStringLiteral(n.node.key)?n.node.key.value:"anonymous",i=`objmethod_${r}_${n.node.start}`;if(g.has(i))return;u&&console.log(`[FuncSpan Transform] Wrapping object method: ${r}`);const s=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,l=E(s,a),{line:m,column:c}=l;let p=t;l.source&&(p=F.resolve(F.dirname(t),l.source));const y=$(n.node.params),f=e.functionExpression(e.identifier(r),n.node.params,n.node.body,n.node.generator,n.node.async),b=e.callExpression(e.identifier("captureFunctionSpan"),[f,e.stringLiteral(r),e.stringLiteral(p),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(c)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(P=>e.stringLiteral(P))))])]),j=e.objectProperty(n.node.key,b,n.node.computed,!1);n.replaceWith(j),x=!0,S++,g.add(i)},ClassProperty(n){const r=n.node.key,i=n.node.value;if(!e.isIdentifier(r)||!i||!e.isFunctionExpression(i)&&!e.isArrowFunctionExpression(i))return;const s=r.name,a=`classprop_${s}_${n.node.start}`;if(g.has(a))return;u&&console.log(`[FuncSpan Transform] Wrapping class property function: ${s}`);const l=i.loc?.start.line??0,m=i.loc?.start.column??0,c=E(l,m),{line:p,column:y}=c;let f=t;c.source&&(f=F.resolve(F.dirname(t),c.source));const b=$(i.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[i,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.value=j,x=!0,S++,g.add(a)},ObjectProperty(n){const r=n.node.key,i=n.node.value;if(!e.isIdentifier(r)&&!e.isStringLiteral(r)||!i||!e.isFunctionExpression(i)&&!e.isArrowFunctionExpression(i))return;const s=e.isIdentifier(r)?r.name:r.value,a=`objprop_${s}_${n.node.start}`;if(g.has(a))return;u&&console.log(`[FuncSpan Transform] Wrapping object property function: ${s}`);const l=i.loc?.start.line??0,m=i.loc?.start.column??0,c=E(l,m),{line:p,column:y}=c;let f=t;c.source&&(f=F.resolve(F.dirname(t),c.source));const b=$(i.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[i,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.value=j,x=!0,S++,g.add(a)}}),x&&!A(h))if(G(h)){const n=e.variableDeclaration("const",[e.variableDeclarator(e.objectPattern([e.objectProperty(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"),!1,!0)]),e.callExpression(e.identifier("require"),[e.stringLiteral("@sailfish-ai/sf-veritas")]))]);h.program.body.unshift(n)}else{const n=e.importDeclaration([e.importSpecifier(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"))],e.stringLiteral("@sailfish-ai/sf-veritas"));h.program.body.unshift(n)}if(S>0){const n=q(h,{retainLines:!0,compact:!1,sourceMaps:!0,sourceFileName:t},d);return u&&console.log(`[FuncSpan Transform] ✅ Wrapped ${S} functions in ${k}`),{code:n.code,map:n.map,modified:!0,functionsWrapped:S}}return{code:d,modified:!1,functionsWrapped:0}},exports.transformFunctionSpansSync=function(d,t,o={}){const{projectRoot:L=process.cwd(),includeNodeModules:I=[],debug:u=!1,parseAsJavaScript:k=!1}=o;if(t.includes("node_modules")&&!I.some(n=>t.includes(`node_modules/${n}`)))return{code:d,modified:!1,functionsWrapped:0};if(M.some(n=>n.test(t)))return u&&console.log(`[FuncSpan Transform] SKIPPING instrumentation entry point file: ${t}`),{code:d,modified:!1,functionsWrapped:0};const h=F.relative(L,t).replace(/\\/g,"/");let v;u&&console.log(`[FuncSpan Transform] Processing: ${h}`);const T=["jsx","decorators-legacy","classProperties","objectRestSpread","asyncGenerators","dynamicImport","optionalCatchBinding","optionalChaining","nullishCoalescingOperator"];D||k||T.unshift("typescript");try{v=O.parse(d,{sourceType:"module",plugins:T})}catch(n){return u&&console.error(`[FuncSpan Transform] Parse error in ${h}:`,n),{code:d,modified:!1,functionsWrapped:0}}const E=(n,r)=>({line:n,column:r});let x=!1,S=0;const g=new Set;if(_(v,{FunctionDeclaration(n){const r=n.node.id?.name;if(!r)return;if(W.has(r))return void(u&&console.log(`[FuncSpan Transform] SKIPPING entry point function: ${r}`));const i=`decl_${r}`;if(g.has(i))return;u&&console.log(`[FuncSpan Transform] Wrapping function declaration: ${r}`);const s=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,l=E(s,a),{line:m,column:c}=l,p=t,y=$(n.node.params),f=e.callExpression(e.identifier("captureFunctionSpan"),[e.identifier(r),e.stringLiteral(r),e.stringLiteral(p),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(c)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(j=>e.stringLiteral(j))))])]),b=e.expressionStatement(e.assignmentExpression("=",e.identifier(r),f));n.insertAfter(b),x=!0,S++,g.add(i)},VariableDeclarator(n){const r=n.node.id,i=n.node.init;if(!e.isIdentifier(r)||!i||!e.isFunctionExpression(i)&&!e.isArrowFunctionExpression(i))return;const s=r.name;if(W.has(s))return void(u&&console.log(`[FuncSpan Transform] SKIPPING entry point function: ${s}`));const a=`var_${s}`;if(g.has(a))return;u&&console.log(`[FuncSpan Transform] Wrapping variable function: ${s}`);const l=i.loc?.start.line??0,m=i.loc?.start.column??0,c=E(l,m),{line:p,column:y}=c,f=t,b=$(i.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[i,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.init=j,x=!0,S++,g.add(a)},ClassMethod(n){if(n.node.kind==="constructor"||n.node.kind==="get"||n.node.kind==="set")return;const r=e.isIdentifier(n.node.key)?n.node.key.name:"anonymous",i=`method_${r}_${n.node.start}`;if(g.has(i))return;u&&console.log(`[FuncSpan Transform] Wrapping class method: ${r}`);const s=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,l=E(s,a),{line:m,column:c}=l,p=t,y=$(n.node.params),f=n.node.body,b=e.functionExpression(null,n.node.params,f,n.node.generator,n.node.async),j=e.callExpression(e.identifier("captureFunctionSpan"),[b,e.stringLiteral(r),e.stringLiteral(p),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(c)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(N=>e.stringLiteral(N))))])]),P=e.blockStatement([e.returnStatement(e.callExpression(e.memberExpression(j,e.identifier("call")),[e.thisExpression(),e.spreadElement(e.identifier("arguments"))]))]);n.node.body=P,x=!0,S++,g.add(i)},ObjectMethod(n){if(n.node.kind==="get"||n.node.kind==="set")return;const r=e.isIdentifier(n.node.key)?n.node.key.name:e.isStringLiteral(n.node.key)?n.node.key.value:"anonymous",i=`objmethod_${r}_${n.node.start}`;if(g.has(i))return;u&&console.log(`[FuncSpan Transform] Wrapping object method: ${r}`);const s=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,l=E(s,a),{line:m,column:c}=l,p=t,y=$(n.node.params),f=e.functionExpression(e.identifier(r),n.node.params,n.node.body,n.node.generator,n.node.async),b=e.callExpression(e.identifier("captureFunctionSpan"),[f,e.stringLiteral(r),e.stringLiteral(p),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(c)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(P=>e.stringLiteral(P))))])]),j=e.objectProperty(n.node.key,b,n.node.computed,!1);n.replaceWith(j),x=!0,S++,g.add(i)},ClassProperty(n){const r=n.node.key,i=n.node.value;if(!e.isIdentifier(r)||!i||!e.isFunctionExpression(i)&&!e.isArrowFunctionExpression(i))return;const s=r.name,a=`classprop_${s}_${n.node.start}`;if(g.has(a))return;u&&console.log(`[FuncSpan Transform] Wrapping class property function: ${s}`);const l=i.loc?.start.line??0,m=i.loc?.start.column??0,c=E(l,m),{line:p,column:y}=c,f=t,b=$(i.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[i,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.value=j,x=!0,S++,g.add(a)},ObjectProperty(n){const r=n.node.key,i=n.node.value;if(!e.isIdentifier(r)&&!e.isStringLiteral(r)||!i||!e.isFunctionExpression(i)&&!e.isArrowFunctionExpression(i))return;const s=e.isIdentifier(r)?r.name:r.value,a=`objprop_${s}_${n.node.start}`;if(g.has(a))return;u&&console.log(`[FuncSpan Transform] Wrapping object property function: ${s}`);const l=i.loc?.start.line??0,m=i.loc?.start.column??0,c=E(l,m),{line:p,column:y}=c,f=t,b=$(i.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[i,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.value=j,x=!0,S++,g.add(a)}}),x&&!A(v))if(G(v)){const n=e.variableDeclaration("const",[e.variableDeclarator(e.objectPattern([e.objectProperty(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"),!1,!0)]),e.callExpression(e.identifier("require"),[e.stringLiteral("@sailfish-ai/sf-veritas")]))]);v.program.body.unshift(n)}else{const n=e.importDeclaration([e.importSpecifier(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"))],e.stringLiteral("@sailfish-ai/sf-veritas"));v.program.body.unshift(n)}if(S>0){const n=q(v,{retainLines:!0,compact:!1,sourceMaps:!0,sourceFileName:t},d);return u&&console.log(`[FuncSpan Transform] ✅ Wrapped ${S} functions in ${h}`),{code:n.code,map:n.map,modified:!0,functionsWrapped:S}}return{code:d,modified:!1,functionsWrapped:0}};
@@ -1,225 +0,0 @@
1
- import { parse as M } from "@babel/parser";
2
- import w from "@babel/traverse";
3
- import D from "@babel/generator";
4
- import * as e from "@babel/types";
5
- import { relative as A, resolve as T, dirname as W } from "path";
6
- import { readFileSync as V } from "fs";
7
- import { s as z } from "./source-map-Cr6YkjTd.js";
8
- const _ = /* @__PURE__ */ new Set(["register", "setupInterceptors", "initializeConfigLoader", "initializeWorkerPoolPatching"]), O = [/instrumentation\.(ts|js|tsx|jsx)$/, /unifiedInterceptor\.(ts|js)$/];
9
- let G = !1;
10
- function Y(j) {
11
- G = j;
12
- }
13
- const N = w.default || w, K = D.default || D;
14
- async function Z(j, t, s = {}) {
15
- const { projectRoot: F = process.cwd(), includeNodeModules: I = [], debug: d = !1 } = s;
16
- if (t.includes("node_modules") && !I.some((n) => t.includes(`node_modules/${n}`))) return { code: j, modified: !1, functionsWrapped: 0 };
17
- if (O.some((n) => n.test(t))) return d && console.log(`[FuncSpan Transform] SKIPPING instrumentation entry point file: ${t}`), { code: j, modified: !1, functionsWrapped: 0 };
18
- const v = A(F, t).replace(/\\/g, "/");
19
- let $;
20
- d && console.log(`[FuncSpan Transform] Processing: ${v}`);
21
- try {
22
- $ = M(j, { sourceType: "module", plugins: ["typescript", "jsx", "decorators-legacy", "classProperties", "objectRestSpread", "asyncGenerators", "dynamicImport", "optionalCatchBinding", "optionalChaining", "nullishCoalescingOperator"] });
23
- } catch (n) {
24
- return d && console.error(`[FuncSpan Transform] Parse error in ${v}:`, n), { code: j, modified: !1, functionsWrapped: 0 };
25
- }
26
- let h = null, k = null;
27
- try {
28
- const n = V(`${t}.map`, "utf-8");
29
- h = await new z.SourceMapConsumer(JSON.parse(n));
30
- } catch {
31
- }
32
- const P = (n, r) => {
33
- if (h) {
34
- const i = h.originalPositionFor({ line: n, column: r });
35
- if (i.line !== null && i.column !== null) return !k && i.source && (k = i.source), { line: i.line, column: i.column, source: i.source || void 0 };
36
- }
37
- return { line: n, column: r };
38
- };
39
- let L = !1, S = 0;
40
- const f = /* @__PURE__ */ new Set();
41
- if (N($, { FunctionDeclaration(n) {
42
- const r = n.node.id?.name;
43
- if (!r) return;
44
- if (_.has(r)) return void (d && console.log(`[FuncSpan Transform] SKIPPING entry point function: ${r}`));
45
- const i = `decl_${r}`;
46
- if (f.has(i)) return;
47
- d && console.log(`[FuncSpan Transform] Wrapping function declaration: ${r}`);
48
- const o = n.node.loc?.start.line ?? 0, a = n.node.loc?.start.column ?? 0, l = P(o, a), { line: u, column: c } = l;
49
- let p = t;
50
- l.source && (p = T(W(t), l.source)), !d || u === o && c === a || console.log(`[FuncSpan Transform] Mapped ${o}:${a} → ${u}:${c} in ${p}`);
51
- const g = E(n.node.params), m = e.callExpression(e.identifier("captureFunctionSpan"), [e.identifier(r), e.stringLiteral(r), e.stringLiteral(p), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(u)), e.objectProperty(e.identifier("column"), e.numericLiteral(c)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(g.map((b) => e.stringLiteral(b))))])]), y = e.expressionStatement(e.assignmentExpression("=", e.identifier(r), m));
52
- n.insertAfter(y), L = !0, S++, f.add(i);
53
- }, VariableDeclarator(n) {
54
- const r = n.node.id, i = n.node.init;
55
- if (!e.isIdentifier(r) || !i || !e.isFunctionExpression(i) && !e.isArrowFunctionExpression(i)) return;
56
- const o = r.name;
57
- if (_.has(o)) return void (d && console.log(`[FuncSpan Transform] SKIPPING entry point function: ${o}`));
58
- const a = `var_${o}`;
59
- if (f.has(a)) return;
60
- d && console.log(`[FuncSpan Transform] Wrapping variable function: ${o}`);
61
- const l = i.loc?.start.line ?? 0, u = i.loc?.start.column ?? 0, c = P(l, u), { line: p, column: g } = c;
62
- let m = t;
63
- c.source && (m = T(W(t), c.source)), !d || p === l && g === u || console.log(`[FuncSpan Transform] Mapped ${l}:${u} → ${p}:${g} in ${m}`);
64
- const y = E(i.params), b = e.callExpression(e.identifier("captureFunctionSpan"), [i, e.stringLiteral(o), e.stringLiteral(m), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(p)), e.objectProperty(e.identifier("column"), e.numericLiteral(g)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(y.map((x) => e.stringLiteral(x))))])]);
65
- n.node.init = b, L = !0, S++, f.add(a);
66
- }, ClassMethod(n) {
67
- if (n.node.kind === "constructor" || n.node.kind === "get" || n.node.kind === "set") return;
68
- const r = e.isIdentifier(n.node.key) ? n.node.key.name : "anonymous", i = `method_${r}_${n.node.start}`;
69
- if (f.has(i)) return;
70
- d && console.log(`[FuncSpan Transform] Wrapping class method: ${r}`);
71
- const o = n.node.loc?.start.line ?? 0, a = n.node.loc?.start.column ?? 0, l = P(o, a), { line: u, column: c } = l, p = t, g = E(n.node.params), m = n.node.body, y = e.functionExpression(null, n.node.params, m, n.node.generator, n.node.async), b = e.callExpression(e.identifier("captureFunctionSpan"), [y, e.stringLiteral(r), e.stringLiteral(p), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(u)), e.objectProperty(e.identifier("column"), e.numericLiteral(c)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(g.map((C) => e.stringLiteral(C))))])]), x = e.blockStatement([e.returnStatement(e.callExpression(e.memberExpression(b, e.identifier("call")), [e.thisExpression(), e.spreadElement(e.identifier("arguments"))]))]);
72
- n.node.body = x, L = !0, S++, f.add(i);
73
- }, ObjectMethod(n) {
74
- if (n.node.kind === "get" || n.node.kind === "set") return;
75
- const r = e.isIdentifier(n.node.key) ? n.node.key.name : e.isStringLiteral(n.node.key) ? n.node.key.value : "anonymous", i = `objmethod_${r}_${n.node.start}`;
76
- if (f.has(i)) return;
77
- d && console.log(`[FuncSpan Transform] Wrapping object method: ${r}`);
78
- const o = n.node.loc?.start.line ?? 0, a = n.node.loc?.start.column ?? 0, l = P(o, a), { line: u, column: c } = l;
79
- let p = t;
80
- l.source && (p = T(W(t), l.source));
81
- const g = E(n.node.params), m = e.functionExpression(e.identifier(r), n.node.params, n.node.body, n.node.generator, n.node.async), y = e.callExpression(e.identifier("captureFunctionSpan"), [m, e.stringLiteral(r), e.stringLiteral(p), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(u)), e.objectProperty(e.identifier("column"), e.numericLiteral(c)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(g.map((x) => e.stringLiteral(x))))])]), b = e.objectProperty(n.node.key, y, n.node.computed, !1);
82
- n.replaceWith(b), L = !0, S++, f.add(i);
83
- }, ClassProperty(n) {
84
- const r = n.node.key, i = n.node.value;
85
- if (!e.isIdentifier(r) || !i || !e.isFunctionExpression(i) && !e.isArrowFunctionExpression(i)) return;
86
- const o = r.name, a = `classprop_${o}_${n.node.start}`;
87
- if (f.has(a)) return;
88
- d && console.log(`[FuncSpan Transform] Wrapping class property function: ${o}`);
89
- const l = i.loc?.start.line ?? 0, u = i.loc?.start.column ?? 0, c = P(l, u), { line: p, column: g } = c;
90
- let m = t;
91
- c.source && (m = T(W(t), c.source));
92
- const y = E(i.params), b = e.callExpression(e.identifier("captureFunctionSpan"), [i, e.stringLiteral(o), e.stringLiteral(m), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(p)), e.objectProperty(e.identifier("column"), e.numericLiteral(g)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(y.map((x) => e.stringLiteral(x))))])]);
93
- n.node.value = b, L = !0, S++, f.add(a);
94
- }, ObjectProperty(n) {
95
- const r = n.node.key, i = n.node.value;
96
- if (!e.isIdentifier(r) && !e.isStringLiteral(r) || !i || !e.isFunctionExpression(i) && !e.isArrowFunctionExpression(i)) return;
97
- const o = e.isIdentifier(r) ? r.name : r.value, a = `objprop_${o}_${n.node.start}`;
98
- if (f.has(a)) return;
99
- d && console.log(`[FuncSpan Transform] Wrapping object property function: ${o}`);
100
- const l = i.loc?.start.line ?? 0, u = i.loc?.start.column ?? 0, c = P(l, u), { line: p, column: g } = c;
101
- let m = t;
102
- c.source && (m = T(W(t), c.source));
103
- const y = E(i.params), b = e.callExpression(e.identifier("captureFunctionSpan"), [i, e.stringLiteral(o), e.stringLiteral(m), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(p)), e.objectProperty(e.identifier("column"), e.numericLiteral(g)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(y.map((x) => e.stringLiteral(x))))])]);
104
- n.node.value = b, L = !0, S++, f.add(a);
105
- } }), L && !R($)) if (q($)) {
106
- const n = e.variableDeclaration("const", [e.variableDeclarator(e.objectPattern([e.objectProperty(e.identifier("captureFunctionSpan"), e.identifier("captureFunctionSpan"), !1, !0)]), e.callExpression(e.identifier("require"), [e.stringLiteral("@sailfish-ai/sf-veritas")]))]);
107
- $.program.body.unshift(n);
108
- } else {
109
- const n = e.importDeclaration([e.importSpecifier(e.identifier("captureFunctionSpan"), e.identifier("captureFunctionSpan"))], e.stringLiteral("@sailfish-ai/sf-veritas"));
110
- $.program.body.unshift(n);
111
- }
112
- if (S > 0) {
113
- const n = K($, { retainLines: !0, compact: !1, sourceMaps: !0, sourceFileName: t }, j);
114
- return d && console.log(`[FuncSpan Transform] ✅ Wrapped ${S} functions in ${v}`), { code: n.code, map: n.map, modified: !0, functionsWrapped: S };
115
- }
116
- return { code: j, modified: !1, functionsWrapped: 0 };
117
- }
118
- function ee(j, t, s = {}) {
119
- const { projectRoot: F = process.cwd(), includeNodeModules: I = [], debug: d = !1, parseAsJavaScript: v = !1 } = s;
120
- if (t.includes("node_modules") && !I.some((n) => t.includes(`node_modules/${n}`))) return { code: j, modified: !1, functionsWrapped: 0 };
121
- if (O.some((n) => n.test(t))) return d && console.log(`[FuncSpan Transform] SKIPPING instrumentation entry point file: ${t}`), { code: j, modified: !1, functionsWrapped: 0 };
122
- const $ = A(F, t).replace(/\\/g, "/");
123
- let h;
124
- d && console.log(`[FuncSpan Transform] Processing: ${$}`);
125
- const k = ["jsx", "decorators-legacy", "classProperties", "objectRestSpread", "asyncGenerators", "dynamicImport", "optionalCatchBinding", "optionalChaining", "nullishCoalescingOperator"];
126
- G || v || k.unshift("typescript");
127
- try {
128
- h = M(j, { sourceType: "module", plugins: k });
129
- } catch (n) {
130
- return d && console.error(`[FuncSpan Transform] Parse error in ${$}:`, n), { code: j, modified: !1, functionsWrapped: 0 };
131
- }
132
- const P = (n, r) => ({ line: n, column: r });
133
- let L = !1, S = 0;
134
- const f = /* @__PURE__ */ new Set();
135
- if (N(h, { FunctionDeclaration(n) {
136
- const r = n.node.id?.name;
137
- if (!r) return;
138
- if (_.has(r)) return void (d && console.log(`[FuncSpan Transform] SKIPPING entry point function: ${r}`));
139
- const i = `decl_${r}`;
140
- if (f.has(i)) return;
141
- d && console.log(`[FuncSpan Transform] Wrapping function declaration: ${r}`);
142
- const o = n.node.loc?.start.line ?? 0, a = n.node.loc?.start.column ?? 0, l = P(o, a), { line: u, column: c } = l, p = t, g = E(n.node.params), m = e.callExpression(e.identifier("captureFunctionSpan"), [e.identifier(r), e.stringLiteral(r), e.stringLiteral(p), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(u)), e.objectProperty(e.identifier("column"), e.numericLiteral(c)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(g.map((b) => e.stringLiteral(b))))])]), y = e.expressionStatement(e.assignmentExpression("=", e.identifier(r), m));
143
- n.insertAfter(y), L = !0, S++, f.add(i);
144
- }, VariableDeclarator(n) {
145
- const r = n.node.id, i = n.node.init;
146
- if (!e.isIdentifier(r) || !i || !e.isFunctionExpression(i) && !e.isArrowFunctionExpression(i)) return;
147
- const o = r.name;
148
- if (_.has(o)) return void (d && console.log(`[FuncSpan Transform] SKIPPING entry point function: ${o}`));
149
- const a = `var_${o}`;
150
- if (f.has(a)) return;
151
- d && console.log(`[FuncSpan Transform] Wrapping variable function: ${o}`);
152
- const l = i.loc?.start.line ?? 0, u = i.loc?.start.column ?? 0, c = P(l, u), { line: p, column: g } = c, m = t, y = E(i.params), b = e.callExpression(e.identifier("captureFunctionSpan"), [i, e.stringLiteral(o), e.stringLiteral(m), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(p)), e.objectProperty(e.identifier("column"), e.numericLiteral(g)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(y.map((x) => e.stringLiteral(x))))])]);
153
- n.node.init = b, L = !0, S++, f.add(a);
154
- }, ClassMethod(n) {
155
- if (n.node.kind === "constructor" || n.node.kind === "get" || n.node.kind === "set") return;
156
- const r = e.isIdentifier(n.node.key) ? n.node.key.name : "anonymous", i = `method_${r}_${n.node.start}`;
157
- if (f.has(i)) return;
158
- d && console.log(`[FuncSpan Transform] Wrapping class method: ${r}`);
159
- const o = n.node.loc?.start.line ?? 0, a = n.node.loc?.start.column ?? 0, l = P(o, a), { line: u, column: c } = l, p = t, g = E(n.node.params), m = n.node.body, y = e.functionExpression(null, n.node.params, m, n.node.generator, n.node.async), b = e.callExpression(e.identifier("captureFunctionSpan"), [y, e.stringLiteral(r), e.stringLiteral(p), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(u)), e.objectProperty(e.identifier("column"), e.numericLiteral(c)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(g.map((C) => e.stringLiteral(C))))])]), x = e.blockStatement([e.returnStatement(e.callExpression(e.memberExpression(b, e.identifier("call")), [e.thisExpression(), e.spreadElement(e.identifier("arguments"))]))]);
160
- n.node.body = x, L = !0, S++, f.add(i);
161
- }, ObjectMethod(n) {
162
- if (n.node.kind === "get" || n.node.kind === "set") return;
163
- const r = e.isIdentifier(n.node.key) ? n.node.key.name : e.isStringLiteral(n.node.key) ? n.node.key.value : "anonymous", i = `objmethod_${r}_${n.node.start}`;
164
- if (f.has(i)) return;
165
- d && console.log(`[FuncSpan Transform] Wrapping object method: ${r}`);
166
- const o = n.node.loc?.start.line ?? 0, a = n.node.loc?.start.column ?? 0, l = P(o, a), { line: u, column: c } = l, p = t, g = E(n.node.params), m = e.functionExpression(e.identifier(r), n.node.params, n.node.body, n.node.generator, n.node.async), y = e.callExpression(e.identifier("captureFunctionSpan"), [m, e.stringLiteral(r), e.stringLiteral(p), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(u)), e.objectProperty(e.identifier("column"), e.numericLiteral(c)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(g.map((x) => e.stringLiteral(x))))])]), b = e.objectProperty(n.node.key, y, n.node.computed, !1);
167
- n.replaceWith(b), L = !0, S++, f.add(i);
168
- }, ClassProperty(n) {
169
- const r = n.node.key, i = n.node.value;
170
- if (!e.isIdentifier(r) || !i || !e.isFunctionExpression(i) && !e.isArrowFunctionExpression(i)) return;
171
- const o = r.name, a = `classprop_${o}_${n.node.start}`;
172
- if (f.has(a)) return;
173
- d && console.log(`[FuncSpan Transform] Wrapping class property function: ${o}`);
174
- const l = i.loc?.start.line ?? 0, u = i.loc?.start.column ?? 0, c = P(l, u), { line: p, column: g } = c, m = t, y = E(i.params), b = e.callExpression(e.identifier("captureFunctionSpan"), [i, e.stringLiteral(o), e.stringLiteral(m), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(p)), e.objectProperty(e.identifier("column"), e.numericLiteral(g)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(y.map((x) => e.stringLiteral(x))))])]);
175
- n.node.value = b, L = !0, S++, f.add(a);
176
- }, ObjectProperty(n) {
177
- const r = n.node.key, i = n.node.value;
178
- if (!e.isIdentifier(r) && !e.isStringLiteral(r) || !i || !e.isFunctionExpression(i) && !e.isArrowFunctionExpression(i)) return;
179
- const o = e.isIdentifier(r) ? r.name : r.value, a = `objprop_${o}_${n.node.start}`;
180
- if (f.has(a)) return;
181
- d && console.log(`[FuncSpan Transform] Wrapping object property function: ${o}`);
182
- const l = i.loc?.start.line ?? 0, u = i.loc?.start.column ?? 0, c = P(l, u), { line: p, column: g } = c, m = t, y = E(i.params), b = e.callExpression(e.identifier("captureFunctionSpan"), [i, e.stringLiteral(o), e.stringLiteral(m), e.objectExpression([e.objectProperty(e.identifier("line"), e.numericLiteral(p)), e.objectProperty(e.identifier("column"), e.numericLiteral(g)), e.objectProperty(e.identifier("paramNames"), e.arrayExpression(y.map((x) => e.stringLiteral(x))))])]);
183
- n.node.value = b, L = !0, S++, f.add(a);
184
- } }), L && !R(h)) if (q(h)) {
185
- const n = e.variableDeclaration("const", [e.variableDeclarator(e.objectPattern([e.objectProperty(e.identifier("captureFunctionSpan"), e.identifier("captureFunctionSpan"), !1, !0)]), e.callExpression(e.identifier("require"), [e.stringLiteral("@sailfish-ai/sf-veritas")]))]);
186
- h.program.body.unshift(n);
187
- } else {
188
- const n = e.importDeclaration([e.importSpecifier(e.identifier("captureFunctionSpan"), e.identifier("captureFunctionSpan"))], e.stringLiteral("@sailfish-ai/sf-veritas"));
189
- h.program.body.unshift(n);
190
- }
191
- if (S > 0) {
192
- const n = K(h, { retainLines: !0, compact: !1, sourceMaps: !0, sourceFileName: t }, j);
193
- return d && console.log(`[FuncSpan Transform] ✅ Wrapped ${S} functions in ${$}`), { code: n.code, map: n.map, modified: !0, functionsWrapped: S };
194
- }
195
- return { code: j, modified: !1, functionsWrapped: 0 };
196
- }
197
- function E(j) {
198
- const t = [];
199
- for (const s of j) e.isIdentifier(s) ? t.push(s.name) : e.isRestElement(s) && e.isIdentifier(s.argument) ? t.push(`...${s.argument.name}`) : e.isAssignmentPattern(s) && e.isIdentifier(s.left) ? t.push(s.left.name) : e.isObjectPattern(s) ? t.push("{}") : e.isArrayPattern(s) ? t.push("[]") : t.push("_");
200
- return t;
201
- }
202
- function R(j) {
203
- let t = !1;
204
- return N(j, { ImportDeclaration(s) {
205
- e.isStringLiteral(s.node.source) && s.node.source.value === "@sailfish-ai/sf-veritas" && s.node.specifiers.some((F) => e.isImportSpecifier(F) && e.isIdentifier(F.imported) && F.imported.name === "captureFunctionSpan") && (t = !0, s.stop());
206
- }, VariableDeclarator(s) {
207
- if (e.isObjectPattern(s.node.id) && e.isCallExpression(s.node.init) && e.isIdentifier(s.node.init.callee) && s.node.init.callee.name === "require") {
208
- const F = s.node.init.arguments;
209
- F.length > 0 && e.isStringLiteral(F[0]) && F[0].value === "@sailfish-ai/sf-veritas" && s.node.id.properties.some((I) => e.isObjectProperty(I) && e.isIdentifier(I.key) && I.key.name === "captureFunctionSpan") && (t = !0, s.stop());
210
- }
211
- } }), t;
212
- }
213
- function q(j) {
214
- let t = !1;
215
- return N(j, { CallExpression(s) {
216
- e.isIdentifier(s.node.callee) && s.node.callee.name === "require" && (t = !0, s.stop());
217
- }, MemberExpression(s) {
218
- !e.isIdentifier(s.node.object) || s.node.object.name !== "module" && s.node.object.name !== "exports" || (t = !0, s.stop());
219
- } }), t;
220
- }
221
- export {
222
- ee as a,
223
- Y as s,
224
- Z as t
225
- };