@bitfab/sdk 0.38.0 → 0.38.2
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/autoTrace.cjs +187 -0
- package/dist/autoTrace.cjs.map +1 -0
- package/dist/autoTrace.d.cts +39 -0
- package/dist/autoTrace.d.ts +39 -0
- package/dist/autoTrace.js +20 -0
- package/dist/{chunk-LCGQUVKR.js → chunk-CWXCVY75.js} +236 -23
- package/dist/{chunk-LCGQUVKR.js.map → chunk-CWXCVY75.js.map} +1 -1
- package/dist/chunk-GFBQ2AMO.js +129 -0
- package/dist/chunk-GFBQ2AMO.js.map +1 -0
- package/dist/chunk-H6LZRFMN.js +59 -0
- package/dist/chunk-H6LZRFMN.js.map +1 -0
- package/dist/{chunk-SSNTMROV.js → chunk-SU7EAKOV.js} +25 -60
- package/dist/chunk-SU7EAKOV.js.map +1 -0
- package/dist/index.cjs +314 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -2
- package/dist/index.d.ts +56 -2
- package/dist/index.js +4 -2
- package/dist/node.cjs +314 -19
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +7 -4
- package/dist/node.js.map +1 -1
- package/dist/{replay-XWBIMYEE.js → replay-A5UVFNZ3.js} +3 -2
- package/dist/replay-A5UVFNZ3.js.map +1 -0
- package/package.json +12 -1
- package/dist/chunk-SSNTMROV.js.map +0 -1
- /package/dist/{replay-XWBIMYEE.js.map → autoTrace.js.map} +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAsyncLocalStorage
|
|
3
|
+
} from "./chunk-H6LZRFMN.js";
|
|
4
|
+
|
|
5
|
+
// src/autoTrace.ts
|
|
6
|
+
var autoTraceGlobal = globalThis;
|
|
7
|
+
var autoTraceState = autoTraceGlobal.__bitfabAutoTraceStateV3 ?? {
|
|
8
|
+
storage: null,
|
|
9
|
+
browserScope: void 0,
|
|
10
|
+
capturePolicies: /* @__PURE__ */ new WeakMap(),
|
|
11
|
+
activeRoots: 0
|
|
12
|
+
};
|
|
13
|
+
autoTraceGlobal.__bitfabAutoTraceStateV3 = autoTraceState;
|
|
14
|
+
function initializeAutoTraceStorage() {
|
|
15
|
+
autoTraceState.storage ?? (autoTraceState.storage = createAsyncLocalStorage());
|
|
16
|
+
}
|
|
17
|
+
function runWithAutoTraceContext(context, fn, depth = 0) {
|
|
18
|
+
initializeAutoTraceStorage();
|
|
19
|
+
const scope = { context, depth };
|
|
20
|
+
if (autoTraceState.storage) {
|
|
21
|
+
return autoTraceState.storage.run(scope, fn);
|
|
22
|
+
}
|
|
23
|
+
const previous = autoTraceState.browserScope;
|
|
24
|
+
autoTraceState.browserScope = scope;
|
|
25
|
+
try {
|
|
26
|
+
return fn();
|
|
27
|
+
} finally {
|
|
28
|
+
autoTraceState.browserScope = previous;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function runWithAutoTraceRootContext(context, fn) {
|
|
32
|
+
autoTraceState.activeRoots += 1;
|
|
33
|
+
let result;
|
|
34
|
+
try {
|
|
35
|
+
result = runWithAutoTraceContext(context, fn);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
autoTraceState.activeRoots -= 1;
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
if (isAutoTraceAsyncGenerator(result)) {
|
|
41
|
+
autoTraceState.activeRoots -= 1;
|
|
42
|
+
return wrapAutoTraceAsyncGenerator(context, result);
|
|
43
|
+
}
|
|
44
|
+
if (result instanceof Promise) {
|
|
45
|
+
return result.finally(() => {
|
|
46
|
+
autoTraceState.activeRoots -= 1;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
autoTraceState.activeRoots -= 1;
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
function isAutoTraceAsyncGenerator(value) {
|
|
53
|
+
if (value === null || typeof value !== "object") {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const candidate = value;
|
|
57
|
+
return typeof candidate.next === "function" && typeof candidate.return === "function" && typeof candidate.throw === "function" && typeof candidate[Symbol.asyncIterator] === "function";
|
|
58
|
+
}
|
|
59
|
+
function wrapAutoTraceAsyncGenerator(context, source) {
|
|
60
|
+
const step = (method, value) => runWithAutoTraceRootContext(context, () => source[method](value));
|
|
61
|
+
const wrapped = {
|
|
62
|
+
next: (value) => step("next", value),
|
|
63
|
+
return: (value) => step("return", value),
|
|
64
|
+
throw: (error) => step("throw", error),
|
|
65
|
+
[Symbol.asyncIterator]: () => wrapped
|
|
66
|
+
};
|
|
67
|
+
return wrapped;
|
|
68
|
+
}
|
|
69
|
+
function __bitfabAutoSpan(definition, inputs, fn) {
|
|
70
|
+
const scope = currentAutoTraceScope();
|
|
71
|
+
if (!scope) {
|
|
72
|
+
return fn();
|
|
73
|
+
}
|
|
74
|
+
return scope.context.invoke(definition, inputs, fn, scope.depth);
|
|
75
|
+
}
|
|
76
|
+
function __bitfabAutoWrap(definition, fn) {
|
|
77
|
+
if (fn.name === "") {
|
|
78
|
+
const nameParts = definition.name.split(".");
|
|
79
|
+
const inferredName = nameParts[nameParts.length - 1];
|
|
80
|
+
if (inferredName !== void 0) {
|
|
81
|
+
Object.defineProperty(fn, "name", {
|
|
82
|
+
configurable: true,
|
|
83
|
+
value: inferredName
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const target = fn;
|
|
88
|
+
return new Proxy(target, {
|
|
89
|
+
apply(callTarget, thisArg, args) {
|
|
90
|
+
if (!__bitfabAutoTraceActive()) {
|
|
91
|
+
return Reflect.apply(callTarget, thisArg, args);
|
|
92
|
+
}
|
|
93
|
+
return __bitfabAutoSpan(
|
|
94
|
+
definition,
|
|
95
|
+
args,
|
|
96
|
+
() => Reflect.apply(callTarget, thisArg, args)
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function __bitfabAutoTraceActive() {
|
|
102
|
+
if (autoTraceState.activeRoots === 0) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return currentAutoTraceScope() !== void 0;
|
|
106
|
+
}
|
|
107
|
+
function currentAutoTraceScope() {
|
|
108
|
+
initializeAutoTraceStorage();
|
|
109
|
+
return autoTraceState.storage?.getStore() ?? autoTraceState.browserScope;
|
|
110
|
+
}
|
|
111
|
+
function __setBitfabAutoTraceCapturePolicy(client, traceFunctionKey, functionIds) {
|
|
112
|
+
const policies = autoTraceState.capturePolicies.get(client) ?? /* @__PURE__ */ new Map();
|
|
113
|
+
policies.set(traceFunctionKey, new Set(functionIds));
|
|
114
|
+
autoTraceState.capturePolicies.set(client, policies);
|
|
115
|
+
}
|
|
116
|
+
function getAutoTraceCapturePolicy(client, traceFunctionKey) {
|
|
117
|
+
return autoTraceState.capturePolicies.get(client)?.get(traceFunctionKey) ?? /* @__PURE__ */ new Set();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
runWithAutoTraceContext,
|
|
122
|
+
runWithAutoTraceRootContext,
|
|
123
|
+
__bitfabAutoSpan,
|
|
124
|
+
__bitfabAutoWrap,
|
|
125
|
+
__bitfabAutoTraceActive,
|
|
126
|
+
__setBitfabAutoTraceCapturePolicy,
|
|
127
|
+
getAutoTraceCapturePolicy
|
|
128
|
+
};
|
|
129
|
+
//# sourceMappingURL=chunk-GFBQ2AMO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/autoTrace.ts"],"sourcesContent":["import {\n type AsyncLocalStorageLike,\n createAsyncLocalStorage,\n} from \"./asyncStorage.js\"\n\nexport interface AutoTraceFunctionDefinition {\n id: string\n name: string\n file: string\n line: number\n column: number\n wrapper?: boolean\n}\n\nexport interface AutoTraceContext {\n invoke<T>(\n definition: AutoTraceFunctionDefinition,\n inputs: unknown[],\n fn: () => T,\n depth: number,\n ): T\n}\n\ninterface AutoTraceScope {\n context: AutoTraceContext\n depth: number\n}\n\ninterface AutoTraceState {\n storage: AsyncLocalStorageLike<AutoTraceScope> | null\n browserScope: AutoTraceScope | undefined\n capturePolicies: WeakMap<object, Map<string, ReadonlySet<string>>>\n activeRoots: number\n}\n\ninterface AutoTraceGlobal {\n __bitfabAutoTraceStateV3?: AutoTraceState\n}\n\ninterface AutoTraceAsyncGenerator {\n next(value?: unknown): Promise<IteratorResult<unknown, unknown>>\n return(value?: unknown): Promise<IteratorResult<unknown, unknown>>\n throw(error?: unknown): Promise<IteratorResult<unknown, unknown>>\n [Symbol.asyncIterator](): AutoTraceAsyncGenerator\n}\n\nconst autoTraceGlobal = globalThis as unknown as AutoTraceGlobal\nconst autoTraceState: AutoTraceState =\n autoTraceGlobal.__bitfabAutoTraceStateV3 ?? {\n storage: null,\n browserScope: undefined,\n capturePolicies: new WeakMap(),\n activeRoots: 0,\n }\nautoTraceGlobal.__bitfabAutoTraceStateV3 = autoTraceState\n\nfunction initializeAutoTraceStorage(): void {\n autoTraceState.storage ??= createAsyncLocalStorage<AutoTraceScope>()\n}\n\nexport function runWithAutoTraceContext<T>(\n context: AutoTraceContext,\n fn: () => T,\n depth = 0,\n): T {\n initializeAutoTraceStorage()\n const scope = { context, depth }\n if (autoTraceState.storage) {\n return autoTraceState.storage.run(scope, fn)\n }\n\n const previous = autoTraceState.browserScope\n autoTraceState.browserScope = scope\n try {\n return fn()\n } finally {\n autoTraceState.browserScope = previous\n }\n}\n\nexport function runWithAutoTraceRootContext<T>(\n context: AutoTraceContext,\n fn: () => T,\n): T {\n autoTraceState.activeRoots += 1\n let result: T\n try {\n result = runWithAutoTraceContext(context, fn)\n } catch (error) {\n autoTraceState.activeRoots -= 1\n throw error\n }\n\n if (isAutoTraceAsyncGenerator(result)) {\n autoTraceState.activeRoots -= 1\n return wrapAutoTraceAsyncGenerator(context, result) as T\n }\n\n if (result instanceof Promise) {\n return result.finally(() => {\n autoTraceState.activeRoots -= 1\n }) as T\n }\n\n autoTraceState.activeRoots -= 1\n return result\n}\n\nfunction isAutoTraceAsyncGenerator(\n value: unknown,\n): value is AutoTraceAsyncGenerator {\n if (value === null || typeof value !== \"object\") {\n return false\n }\n const candidate = value as Record<PropertyKey, unknown>\n return (\n typeof candidate.next === \"function\" &&\n typeof candidate.return === \"function\" &&\n typeof candidate.throw === \"function\" &&\n typeof candidate[Symbol.asyncIterator] === \"function\"\n )\n}\n\nfunction wrapAutoTraceAsyncGenerator(\n context: AutoTraceContext,\n source: AutoTraceAsyncGenerator,\n): AutoTraceAsyncGenerator {\n const step = (\n method: \"next\" | \"return\" | \"throw\",\n value?: unknown,\n ): Promise<IteratorResult<unknown, unknown>> =>\n runWithAutoTraceRootContext(context, () => source[method](value))\n const wrapped: AutoTraceAsyncGenerator = {\n next: (value) => step(\"next\", value),\n return: (value) => step(\"return\", value),\n throw: (error) => step(\"throw\", error),\n [Symbol.asyncIterator]: () => wrapped,\n }\n return wrapped\n}\n\nexport function __bitfabAutoSpan<T>(\n definition: AutoTraceFunctionDefinition,\n inputs: unknown[],\n fn: () => T,\n): T {\n const scope = currentAutoTraceScope()\n if (!scope) {\n return fn()\n }\n return scope.context.invoke(definition, inputs, fn, scope.depth)\n}\n\n/**\n * Preserve a function's original call arguments for transform cases where\n * parameter bindings discard them, such as destructured arrow parameters.\n *\n * This helper is internal transform/runtime protocol. The proxy preserves the\n * target's callability, arity, async identity, and non-constructibility while\n * only allocating a trace closure beneath an active automatic trace root.\n *\n * @experimental The automatic tracing protocol may change.\n */\nexport function __bitfabAutoWrap<T extends (...args: never[]) => unknown>(\n definition: AutoTraceFunctionDefinition,\n fn: T,\n): T {\n if (fn.name === \"\") {\n const nameParts = definition.name.split(\".\")\n const inferredName = nameParts[nameParts.length - 1]\n if (inferredName !== undefined) {\n Object.defineProperty(fn, \"name\", {\n configurable: true,\n value: inferredName,\n })\n }\n }\n\n const target = fn as unknown as (...args: unknown[]) => unknown\n return new Proxy(target, {\n apply(callTarget, thisArg, args) {\n if (!__bitfabAutoTraceActive()) {\n return Reflect.apply(callTarget, thisArg, args)\n }\n return __bitfabAutoSpan(definition, args, () =>\n Reflect.apply(callTarget, thisArg, args),\n )\n },\n }) as unknown as T\n}\n\n/**\n * Return whether the current call is inside an automatic trace root.\n *\n * Build transforms use this before allocating function metadata, captured\n * inputs, or an invocation closure. It is internal transform/runtime protocol,\n * not a supported application API.\n *\n * @experimental The automatic tracing protocol may change.\n */\nexport function __bitfabAutoTraceActive(): boolean {\n if (autoTraceState.activeRoots === 0) {\n return false\n }\n return currentAutoTraceScope() !== undefined\n}\n\nfunction currentAutoTraceScope(): AutoTraceScope | undefined {\n initializeAutoTraceStorage()\n return autoTraceState.storage?.getStore() ?? autoTraceState.browserScope\n}\n\nexport function __setBitfabAutoTraceCapturePolicy(\n client: object,\n traceFunctionKey: string,\n functionIds: Iterable<string>,\n): void {\n const policies = autoTraceState.capturePolicies.get(client) ?? new Map()\n policies.set(traceFunctionKey, new Set(functionIds))\n autoTraceState.capturePolicies.set(client, policies)\n}\n\nexport function getAutoTraceCapturePolicy(\n client: object,\n traceFunctionKey: string,\n): ReadonlySet<string> {\n return (\n autoTraceState.capturePolicies.get(client)?.get(traceFunctionKey) ??\n new Set()\n )\n}\n"],"mappings":";;;;;AA8CA,IAAM,kBAAkB;AACxB,IAAM,iBACJ,gBAAgB,4BAA4B;AAAA,EAC1C,SAAS;AAAA,EACT,cAAc;AAAA,EACd,iBAAiB,oBAAI,QAAQ;AAAA,EAC7B,aAAa;AACf;AACF,gBAAgB,2BAA2B;AAE3C,SAAS,6BAAmC;AAC1C,iBAAe,YAAf,eAAe,UAAY,wBAAwC;AACrE;AAEO,SAAS,wBACd,SACA,IACA,QAAQ,GACL;AACH,6BAA2B;AAC3B,QAAM,QAAQ,EAAE,SAAS,MAAM;AAC/B,MAAI,eAAe,SAAS;AAC1B,WAAO,eAAe,QAAQ,IAAI,OAAO,EAAE;AAAA,EAC7C;AAEA,QAAM,WAAW,eAAe;AAChC,iBAAe,eAAe;AAC9B,MAAI;AACF,WAAO,GAAG;AAAA,EACZ,UAAE;AACA,mBAAe,eAAe;AAAA,EAChC;AACF;AAEO,SAAS,4BACd,SACA,IACG;AACH,iBAAe,eAAe;AAC9B,MAAI;AACJ,MAAI;AACF,aAAS,wBAAwB,SAAS,EAAE;AAAA,EAC9C,SAAS,OAAO;AACd,mBAAe,eAAe;AAC9B,UAAM;AAAA,EACR;AAEA,MAAI,0BAA0B,MAAM,GAAG;AACrC,mBAAe,eAAe;AAC9B,WAAO,4BAA4B,SAAS,MAAM;AAAA,EACpD;AAEA,MAAI,kBAAkB,SAAS;AAC7B,WAAO,OAAO,QAAQ,MAAM;AAC1B,qBAAe,eAAe;AAAA,IAChC,CAAC;AAAA,EACH;AAEA,iBAAe,eAAe;AAC9B,SAAO;AACT;AAEA,SAAS,0BACP,OACkC;AAClC,MAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;AAC/C,WAAO;AAAA,EACT;AACA,QAAM,YAAY;AAClB,SACE,OAAO,UAAU,SAAS,cAC1B,OAAO,UAAU,WAAW,cAC5B,OAAO,UAAU,UAAU,cAC3B,OAAO,UAAU,OAAO,aAAa,MAAM;AAE/C;AAEA,SAAS,4BACP,SACA,QACyB;AACzB,QAAM,OAAO,CACX,QACA,UAEA,4BAA4B,SAAS,MAAM,OAAO,MAAM,EAAE,KAAK,CAAC;AAClE,QAAM,UAAmC;AAAA,IACvC,MAAM,CAAC,UAAU,KAAK,QAAQ,KAAK;AAAA,IACnC,QAAQ,CAAC,UAAU,KAAK,UAAU,KAAK;AAAA,IACvC,OAAO,CAAC,UAAU,KAAK,SAAS,KAAK;AAAA,IACrC,CAAC,OAAO,aAAa,GAAG,MAAM;AAAA,EAChC;AACA,SAAO;AACT;AAEO,SAAS,iBACd,YACA,QACA,IACG;AACH,QAAM,QAAQ,sBAAsB;AACpC,MAAI,CAAC,OAAO;AACV,WAAO,GAAG;AAAA,EACZ;AACA,SAAO,MAAM,QAAQ,OAAO,YAAY,QAAQ,IAAI,MAAM,KAAK;AACjE;AAYO,SAAS,iBACd,YACA,IACG;AACH,MAAI,GAAG,SAAS,IAAI;AAClB,UAAM,YAAY,WAAW,KAAK,MAAM,GAAG;AAC3C,UAAM,eAAe,UAAU,UAAU,SAAS,CAAC;AACnD,QAAI,iBAAiB,QAAW;AAC9B,aAAO,eAAe,IAAI,QAAQ;AAAA,QAChC,cAAc;AAAA,QACd,OAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,SAAS;AACf,SAAO,IAAI,MAAM,QAAQ;AAAA,IACvB,MAAM,YAAY,SAAS,MAAM;AAC/B,UAAI,CAAC,wBAAwB,GAAG;AAC9B,eAAO,QAAQ,MAAM,YAAY,SAAS,IAAI;AAAA,MAChD;AACA,aAAO;AAAA,QAAiB;AAAA,QAAY;AAAA,QAAM,MACxC,QAAQ,MAAM,YAAY,SAAS,IAAI;AAAA,MACzC;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAWO,SAAS,0BAAmC;AACjD,MAAI,eAAe,gBAAgB,GAAG;AACpC,WAAO;AAAA,EACT;AACA,SAAO,sBAAsB,MAAM;AACrC;AAEA,SAAS,wBAAoD;AAC3D,6BAA2B;AAC3B,SAAO,eAAe,SAAS,SAAS,KAAK,eAAe;AAC9D;AAEO,SAAS,kCACd,QACA,kBACA,aACM;AACN,QAAM,WAAW,eAAe,gBAAgB,IAAI,MAAM,KAAK,oBAAI,IAAI;AACvE,WAAS,IAAI,kBAAkB,IAAI,IAAI,WAAW,CAAC;AACnD,iBAAe,gBAAgB,IAAI,QAAQ,QAAQ;AACrD;AAEO,SAAS,0BACd,QACA,kBACqB;AACrB,SACE,eAAe,gBAAgB,IAAI,MAAM,GAAG,IAAI,gBAAgB,KAChE,oBAAI,IAAI;AAEZ;","names":[]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
|
|
9
|
+
// src/asyncStorage.ts
|
|
10
|
+
var AsyncLocalStorageClass = null;
|
|
11
|
+
var initDone = false;
|
|
12
|
+
function registerAsyncLocalStorageClass(cls) {
|
|
13
|
+
if (!AsyncLocalStorageClass) {
|
|
14
|
+
AsyncLocalStorageClass = cls;
|
|
15
|
+
}
|
|
16
|
+
initDone = true;
|
|
17
|
+
}
|
|
18
|
+
function assertAsyncStorageRegistered() {
|
|
19
|
+
if (!AsyncLocalStorageClass) {
|
|
20
|
+
console.warn(
|
|
21
|
+
"Bitfab: AsyncLocalStorage not available - nested span context will not propagate."
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
var asyncStorageReady = (typeof process !== "undefined" && process.versions?.node ? (
|
|
26
|
+
// The join trick hides "node:async_hooks" from static analysis so
|
|
27
|
+
// bundlers that ban Node.js built-ins don't fail at build time.
|
|
28
|
+
// webpackIgnore tells webpack/turbopack to emit a native import()
|
|
29
|
+
// so Node.js can resolve the module at runtime.
|
|
30
|
+
import(
|
|
31
|
+
/* webpackIgnore: true */
|
|
32
|
+
["node", "async_hooks"].join(":")
|
|
33
|
+
).then(
|
|
34
|
+
(mod) => {
|
|
35
|
+
registerAsyncLocalStorageClass(mod.AsyncLocalStorage);
|
|
36
|
+
}
|
|
37
|
+
).catch(() => {
|
|
38
|
+
})
|
|
39
|
+
) : Promise.resolve()).then(() => {
|
|
40
|
+
initDone = true;
|
|
41
|
+
});
|
|
42
|
+
function isAsyncStorageInitDone() {
|
|
43
|
+
return initDone;
|
|
44
|
+
}
|
|
45
|
+
function createAsyncLocalStorage() {
|
|
46
|
+
return AsyncLocalStorageClass ? new AsyncLocalStorageClass() : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
__privateGet,
|
|
51
|
+
__privateAdd,
|
|
52
|
+
__privateSet,
|
|
53
|
+
registerAsyncLocalStorageClass,
|
|
54
|
+
assertAsyncStorageRegistered,
|
|
55
|
+
asyncStorageReady,
|
|
56
|
+
isAsyncStorageInitDone,
|
|
57
|
+
createAsyncLocalStorage
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=chunk-H6LZRFMN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asyncStorage.ts"],"sourcesContent":["/**\n * Shared AsyncLocalStorage loader.\n *\n * Provides two ways to initialize AsyncLocalStorage:\n *\n * 1. **Synchronous registration** (preferred for Node.js):\n * `asyncStorageNode.ts` calls `registerAsyncLocalStorageClass()` at module\n * evaluation time, so the class is available immediately - no async gap.\n * The `node.ts` entry point imports it before anything else.\n *\n * 2. **Async dynamic import** (fallback for the default entry point):\n * Loads `node:async_hooks` via a bundler-safe dynamic import. This is used\n * by the default `index.ts` entry point so the SDK works in browsers\n * (where the import silently fails) and in Node.js when imported via the\n * default entry point.\n *\n * ## Why the dynamic import looks like this\n *\n * We need to handle three environments:\n *\n * 1. **Pure Node.js** - `import(\"node:async_hooks\")` works natively.\n * 2. **Webpack/Turbopack (Next.js server)** - The bundler processes\n * `import()` calls at build time. The `webpackIgnore` magic comment tells\n * webpack (and turbopack) to emit a native `import()` call instead of\n * trying to resolve it, so Node.js handles it at runtime.\n * 3. **Browsers / Edge** - The `process.versions?.node` guard prevents\n * execution entirely. If it somehow runs, `.catch(() => {})` swallows\n * the failure.\n */\n\nexport interface AsyncLocalStorageLike<T> {\n getStore(): T | undefined\n run<R>(store: T, fn: () => R): R\n}\n\nlet AsyncLocalStorageClass: (new () => AsyncLocalStorageLike<unknown>) | null =\n null\nlet initDone = false\n\n/**\n * Register the AsyncLocalStorage class synchronously.\n *\n * Called by `asyncStorageNode.ts` at module evaluation time so the class\n * is available before any span is created - no async gap, no race condition.\n *\n * Safe to call multiple times; subsequent calls are no-ops.\n */\nexport function registerAsyncLocalStorageClass(\n cls: new () => AsyncLocalStorageLike<unknown>,\n): void {\n if (!AsyncLocalStorageClass) {\n AsyncLocalStorageClass = cls\n }\n initDone = true\n}\n\n/**\n * Assert that AsyncLocalStorage was registered successfully.\n *\n * Called by `node.ts` after importing `asyncStorageNode.ts` to catch\n * import-order bugs at startup rather than silently degrading to the\n * browser fallback (flat spans with no nesting).\n *\n * This should ONLY be called from the Node.js entry point where we\n * know `node:async_hooks` must be available.\n */\nexport function assertAsyncStorageRegistered(): void {\n if (!AsyncLocalStorageClass) {\n console.warn(\n \"Bitfab: AsyncLocalStorage not available - nested span context will not propagate.\",\n )\n }\n}\n\nexport const asyncStorageReady: Promise<void> = (\n typeof process !== \"undefined\" && process.versions?.node\n ? // The join trick hides \"node:async_hooks\" from static analysis so\n // bundlers that ban Node.js built-ins don't fail at build time.\n // webpackIgnore tells webpack/turbopack to emit a native import()\n // so Node.js can resolve the module at runtime.\n import(\n /* webpackIgnore: true */\n [\"node\", \"async_hooks\"].join(\":\")\n )\n .then(\n (mod: {\n AsyncLocalStorage: new () => AsyncLocalStorageLike<unknown>\n }) => {\n registerAsyncLocalStorageClass(mod.AsyncLocalStorage)\n },\n )\n .catch(() => {})\n : Promise.resolve()\n).then(() => {\n initDone = true\n})\n\nexport function isAsyncStorageInitDone(): boolean {\n return initDone\n}\n\nexport function createAsyncLocalStorage<T>(): AsyncLocalStorageLike<T> | null {\n return AsyncLocalStorageClass\n ? (new AsyncLocalStorageClass() as AsyncLocalStorageLike<T>)\n : null\n}\n"],"mappings":";;;;;;;;;AAmCA,IAAI,yBACF;AACF,IAAI,WAAW;AAUR,SAAS,+BACd,KACM;AACN,MAAI,CAAC,wBAAwB;AAC3B,6BAAyB;AAAA,EAC3B;AACA,aAAW;AACb;AAYO,SAAS,+BAAqC;AACnD,MAAI,CAAC,wBAAwB;AAC3B,YAAQ;AAAA,MACN;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,qBACX,OAAO,YAAY,eAAe,QAAQ,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAKhD;AAAA;AAAA,IAEE,CAAC,QAAQ,aAAa,EAAE,KAAK,GAAG;AAAA,IAE/B;AAAA,IACC,CAAC,QAEK;AACJ,qCAA+B,IAAI,iBAAiB;AAAA,IACtD;AAAA,EACF,EACC,MAAM,MAAM;AAAA,EAAC,CAAC;AAAA,IACjB,QAAQ,QAAQ,GACpB,KAAK,MAAM;AACX,aAAW;AACb,CAAC;AAEM,SAAS,yBAAkC;AAChD,SAAO;AACT;AAEO,SAAS,0BAA8D;AAC5E,SAAO,yBACF,IAAI,uBAAuB,IAC5B;AACN;","names":[]}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
1
|
+
import {
|
|
2
|
+
asyncStorageReady,
|
|
3
|
+
createAsyncLocalStorage
|
|
4
|
+
} from "./chunk-H6LZRFMN.js";
|
|
8
5
|
|
|
9
6
|
// src/codeChange.ts
|
|
10
7
|
var MAX_FILES = 60;
|
|
@@ -314,51 +311,12 @@ function encodeRequestBody(body) {
|
|
|
314
311
|
}
|
|
315
312
|
|
|
316
313
|
// src/version.generated.ts
|
|
317
|
-
var __version__ = "0.38.
|
|
314
|
+
var __version__ = "0.38.2";
|
|
315
|
+
var __packageName__ = "@bitfab/sdk";
|
|
318
316
|
|
|
319
317
|
// src/constants.ts
|
|
320
318
|
var DEFAULT_SERVICE_URL = "https://bitfab.ai";
|
|
321
319
|
|
|
322
|
-
// src/asyncStorage.ts
|
|
323
|
-
var AsyncLocalStorageClass = null;
|
|
324
|
-
var initDone = false;
|
|
325
|
-
function registerAsyncLocalStorageClass(cls) {
|
|
326
|
-
if (!AsyncLocalStorageClass) {
|
|
327
|
-
AsyncLocalStorageClass = cls;
|
|
328
|
-
}
|
|
329
|
-
initDone = true;
|
|
330
|
-
}
|
|
331
|
-
function assertAsyncStorageRegistered() {
|
|
332
|
-
if (!AsyncLocalStorageClass) {
|
|
333
|
-
console.warn(
|
|
334
|
-
"Bitfab: AsyncLocalStorage not available - nested span context will not propagate."
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
var asyncStorageReady = (typeof process !== "undefined" && process.versions?.node ? (
|
|
339
|
-
// The join trick hides "node:async_hooks" from static analysis so
|
|
340
|
-
// bundlers that ban Node.js built-ins don't fail at build time.
|
|
341
|
-
// webpackIgnore tells webpack/turbopack to emit a native import()
|
|
342
|
-
// so Node.js can resolve the module at runtime.
|
|
343
|
-
import(
|
|
344
|
-
/* webpackIgnore: true */
|
|
345
|
-
["node", "async_hooks"].join(":")
|
|
346
|
-
).then(
|
|
347
|
-
(mod) => {
|
|
348
|
-
registerAsyncLocalStorageClass(mod.AsyncLocalStorage);
|
|
349
|
-
}
|
|
350
|
-
).catch(() => {
|
|
351
|
-
})
|
|
352
|
-
) : Promise.resolve()).then(() => {
|
|
353
|
-
initDone = true;
|
|
354
|
-
});
|
|
355
|
-
function isAsyncStorageInitDone() {
|
|
356
|
-
return initDone;
|
|
357
|
-
}
|
|
358
|
-
function createAsyncLocalStorage() {
|
|
359
|
-
return AsyncLocalStorageClass ? new AsyncLocalStorageClass() : null;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
320
|
// src/replayContext.ts
|
|
363
321
|
var replayContextStorage = null;
|
|
364
322
|
var REPLAY_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.replayContextStorage");
|
|
@@ -682,7 +640,7 @@ var MAX_REQUEST_BYTES_ENV = "BITFAB_OTEL_MAX_REQUEST_BYTES";
|
|
|
682
640
|
var EXPORT_CONCURRENCY_ENV = "BITFAB_OTEL_EXPORT_CONCURRENCY";
|
|
683
641
|
var MAX_QUEUE_SIZE = 8192;
|
|
684
642
|
var DIRECT_MAX_EXPORT_BATCH_SIZE = 512;
|
|
685
|
-
var DIRECT_MAX_REQUEST_BATCH_SIZE =
|
|
643
|
+
var DIRECT_MAX_REQUEST_BATCH_SIZE = 128;
|
|
686
644
|
var DEFAULT_EXPORT_CONCURRENCY = 32;
|
|
687
645
|
var MAX_EXPORT_CONCURRENCY = 64;
|
|
688
646
|
var SCHEDULE_DELAY_MILLIS = 5e3;
|
|
@@ -1781,6 +1739,12 @@ var HttpClient = class {
|
|
|
1781
1739
|
async lookupFunction(name) {
|
|
1782
1740
|
return this.request("/api/sdk/functions/lookup", { name });
|
|
1783
1741
|
}
|
|
1742
|
+
async getAutoTracePolicy(traceFunctionKey, protocol) {
|
|
1743
|
+
return this.request("/api/sdk/auto-trace/policy", {
|
|
1744
|
+
traceFunctionKey,
|
|
1745
|
+
protocol
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1784
1748
|
async getTraceSpan(traceId, lookup) {
|
|
1785
1749
|
const searchParams = new URLSearchParams();
|
|
1786
1750
|
if (lookup.id !== void 0) {
|
|
@@ -1831,7 +1795,12 @@ var HttpClient = class {
|
|
|
1831
1795
|
* the OTLP carrier has no path to carry it.
|
|
1832
1796
|
*/
|
|
1833
1797
|
sendInternalTrace(functionId, payload) {
|
|
1834
|
-
const body = {
|
|
1798
|
+
const body = {
|
|
1799
|
+
...payload,
|
|
1800
|
+
functionId,
|
|
1801
|
+
sdkPackage: __packageName__,
|
|
1802
|
+
sdkVersion: __version__
|
|
1803
|
+
};
|
|
1835
1804
|
this.getTraceTransport()?.submit(
|
|
1836
1805
|
"internal_trace",
|
|
1837
1806
|
body,
|
|
@@ -1860,7 +1829,11 @@ var HttpClient = class {
|
|
|
1860
1829
|
sendExternalTrace(payload) {
|
|
1861
1830
|
this.getTraceTransport()?.submit(
|
|
1862
1831
|
"external_trace",
|
|
1863
|
-
{
|
|
1832
|
+
{
|
|
1833
|
+
...payload,
|
|
1834
|
+
sdkPackage: __packageName__,
|
|
1835
|
+
sdkVersion: __version__
|
|
1836
|
+
},
|
|
1864
1837
|
this.recordedMeta(
|
|
1865
1838
|
"external_trace",
|
|
1866
1839
|
payload,
|
|
@@ -2923,17 +2896,9 @@ async function writeReplayResultFile(result) {
|
|
|
2923
2896
|
}
|
|
2924
2897
|
|
|
2925
2898
|
export {
|
|
2926
|
-
__privateGet,
|
|
2927
|
-
__privateAdd,
|
|
2928
|
-
__privateSet,
|
|
2929
2899
|
__version__,
|
|
2930
2900
|
DEFAULT_SERVICE_URL,
|
|
2931
2901
|
BitfabError,
|
|
2932
|
-
registerAsyncLocalStorageClass,
|
|
2933
|
-
assertAsyncStorageRegistered,
|
|
2934
|
-
asyncStorageReady,
|
|
2935
|
-
isAsyncStorageInitDone,
|
|
2936
|
-
createAsyncLocalStorage,
|
|
2937
2902
|
getReplayContext,
|
|
2938
2903
|
warnOnce,
|
|
2939
2904
|
flushTraces,
|
|
@@ -2953,4 +2918,4 @@ export {
|
|
|
2953
2918
|
sleepForReplayPersistence,
|
|
2954
2919
|
replay
|
|
2955
2920
|
};
|
|
2956
|
-
//# sourceMappingURL=chunk-
|
|
2921
|
+
//# sourceMappingURL=chunk-SU7EAKOV.js.map
|