@bitfab/sdk 0.38.3 → 0.38.5
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 +48 -1
- package/dist/autoTrace.cjs.map +1 -1
- package/dist/autoTrace.d.cts +13 -2
- package/dist/autoTrace.d.ts +13 -2
- package/dist/autoTrace.js +3 -1
- package/dist/{chunk-GFBQ2AMO.js → chunk-J47KPS77.js} +48 -2
- package/dist/chunk-J47KPS77.js.map +1 -0
- package/dist/{chunk-WX6AEFCP.js → chunk-VVI573UU.js} +8 -3
- package/dist/{chunk-WX6AEFCP.js.map → chunk-VVI573UU.js.map} +1 -1
- package/dist/{chunk-RJPHMJWO.js → chunk-Z3GIZGS5.js} +280 -82
- package/dist/chunk-Z3GIZGS5.js.map +1 -0
- package/dist/index.cjs +329 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -7
- package/dist/index.d.ts +75 -7
- package/dist/index.js +5 -3
- package/dist/node.cjs +329 -80
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +5 -3
- package/dist/node.js.map +1 -1
- package/dist/{replay-FAO7D7CG.js → replay-Z6DON4SP.js} +2 -2
- package/dist/replayCli.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-GFBQ2AMO.js.map +0 -1
- package/dist/chunk-RJPHMJWO.js.map +0 -1
- /package/dist/{replay-FAO7D7CG.js.map → replay-Z6DON4SP.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -42,7 +42,7 @@ var __version__, __packageName__;
|
|
|
42
42
|
var init_version_generated = __esm({
|
|
43
43
|
"src/version.generated.ts"() {
|
|
44
44
|
"use strict";
|
|
45
|
-
__version__ = "0.38.
|
|
45
|
+
__version__ = "0.38.5";
|
|
46
46
|
__packageName__ = "@bitfab/sdk";
|
|
47
47
|
}
|
|
48
48
|
});
|
|
@@ -2187,11 +2187,16 @@ function normalizeMockOverrides(mockOverride) {
|
|
|
2187
2187
|
if (mockOverride === void 0) {
|
|
2188
2188
|
return [];
|
|
2189
2189
|
}
|
|
2190
|
-
|
|
2190
|
+
const overrides = Array.isArray(mockOverride) ? mockOverride : [mockOverride];
|
|
2191
|
+
return overrides.map(
|
|
2192
|
+
(override) => typeof override === "function" ? { match: () => true, value: override } : override
|
|
2193
|
+
);
|
|
2191
2194
|
}
|
|
2195
|
+
var NO_MOCK_OVERRIDE;
|
|
2192
2196
|
var init_mockOverride = __esm({
|
|
2193
2197
|
"src/mockOverride.ts"() {
|
|
2194
2198
|
"use strict";
|
|
2199
|
+
NO_MOCK_OVERRIDE = /* @__PURE__ */ Symbol("bitfab.noMockOverride");
|
|
2195
2200
|
}
|
|
2196
2201
|
});
|
|
2197
2202
|
|
|
@@ -3133,6 +3138,7 @@ __export(index_exports, {
|
|
|
3133
3138
|
DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
|
|
3134
3139
|
DbBranchReplayError: () => DbBranchReplayError,
|
|
3135
3140
|
HttpClient: () => HttpClient,
|
|
3141
|
+
NO_MOCK_OVERRIDE: () => NO_MOCK_OVERRIDE,
|
|
3136
3142
|
ReplayError: () => ReplayError,
|
|
3137
3143
|
SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
|
|
3138
3144
|
__version__: () => __version__,
|
|
@@ -3788,6 +3794,29 @@ function runWithAutoTraceContext(context, fn, depth = 0) {
|
|
|
3788
3794
|
autoTraceState.browserScope = previous;
|
|
3789
3795
|
}
|
|
3790
3796
|
}
|
|
3797
|
+
function runWithAutoTraceNodeConfiguration(nodeConfiguration, fn) {
|
|
3798
|
+
const scope = currentAutoTraceScope();
|
|
3799
|
+
if (!scope) {
|
|
3800
|
+
return fn();
|
|
3801
|
+
}
|
|
3802
|
+
const configuredScope = { ...scope, nodeConfiguration };
|
|
3803
|
+
let result;
|
|
3804
|
+
if (autoTraceState.storage) {
|
|
3805
|
+
result = autoTraceState.storage.run(configuredScope, fn);
|
|
3806
|
+
} else {
|
|
3807
|
+
const previous = autoTraceState.browserScope;
|
|
3808
|
+
autoTraceState.browserScope = configuredScope;
|
|
3809
|
+
try {
|
|
3810
|
+
result = fn();
|
|
3811
|
+
} finally {
|
|
3812
|
+
autoTraceState.browserScope = previous;
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
if (isAutoTraceAsyncGenerator(result)) {
|
|
3816
|
+
return wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, result);
|
|
3817
|
+
}
|
|
3818
|
+
return result;
|
|
3819
|
+
}
|
|
3791
3820
|
function runWithAutoTraceRootContext(context, fn) {
|
|
3792
3821
|
autoTraceState.activeRoots += 1;
|
|
3793
3822
|
let result;
|
|
@@ -3826,6 +3855,29 @@ function wrapAutoTraceAsyncGenerator(context, source) {
|
|
|
3826
3855
|
};
|
|
3827
3856
|
return wrapped;
|
|
3828
3857
|
}
|
|
3858
|
+
function wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, source) {
|
|
3859
|
+
const step = (method, value) => runWithAutoTraceNodeConfiguration(
|
|
3860
|
+
nodeConfiguration,
|
|
3861
|
+
() => source[method](value)
|
|
3862
|
+
);
|
|
3863
|
+
const wrapped = {
|
|
3864
|
+
next: (value) => step("next", value),
|
|
3865
|
+
return: (value) => step("return", value),
|
|
3866
|
+
throw: (error) => step("throw", error),
|
|
3867
|
+
[Symbol.asyncIterator]: () => wrapped
|
|
3868
|
+
};
|
|
3869
|
+
return wrapped;
|
|
3870
|
+
}
|
|
3871
|
+
function __bitfabAutoTraceActive() {
|
|
3872
|
+
if (autoTraceState.activeRoots === 0) {
|
|
3873
|
+
return false;
|
|
3874
|
+
}
|
|
3875
|
+
return currentAutoTraceScope() !== void 0;
|
|
3876
|
+
}
|
|
3877
|
+
function currentAutoTraceScope() {
|
|
3878
|
+
initializeAutoTraceStorage();
|
|
3879
|
+
return autoTraceState.storage?.getStore() ?? autoTraceState.browserScope;
|
|
3880
|
+
}
|
|
3829
3881
|
function __setBitfabAutoTraceCapturePolicy(client, traceFunctionKey, functionIds) {
|
|
3830
3882
|
const policies = autoTraceState.capturePolicies.get(client) ?? /* @__PURE__ */ new Map();
|
|
3831
3883
|
policies.set(traceFunctionKey, new Set(functionIds));
|
|
@@ -5678,6 +5730,102 @@ var Bitfab = class {
|
|
|
5678
5730
|
const name = fn.name !== "" ? fn.name : traceFunctionKey;
|
|
5679
5731
|
return this.createAutoTraceRoot(traceFunctionKey, name, options, fn);
|
|
5680
5732
|
}
|
|
5733
|
+
/**
|
|
5734
|
+
* Configure a transformed class method when it is discovered beneath a
|
|
5735
|
+
* {@link Bitfab.trace} root.
|
|
5736
|
+
*
|
|
5737
|
+
* The decorator creates no span or trace by itself. Beneath an active trace,
|
|
5738
|
+
* it can rename or retype the discovered call, capture its contents, mark it
|
|
5739
|
+
* for recorded-output replay, finalize its output, or omit it while leaving
|
|
5740
|
+
* captured descendants attached to the nearest captured parent.
|
|
5741
|
+
*
|
|
5742
|
+
* @param options - Trace-owned call configuration.
|
|
5743
|
+
* @experimental Automatic child-call instrumentation is experimental.
|
|
5744
|
+
*/
|
|
5745
|
+
node(options = {}) {
|
|
5746
|
+
const configuration = this.resolveNodeConfiguration(options);
|
|
5747
|
+
const decorator = (...args) => {
|
|
5748
|
+
if (args.length === 3) {
|
|
5749
|
+
const descriptor = args[2];
|
|
5750
|
+
if (!descriptor || typeof descriptor.value !== "function") {
|
|
5751
|
+
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
5752
|
+
}
|
|
5753
|
+
if (!this.explicitlyEnabled) {
|
|
5754
|
+
return;
|
|
5755
|
+
}
|
|
5756
|
+
descriptor.value = this.createAutoTraceNode(
|
|
5757
|
+
configuration,
|
|
5758
|
+
descriptor.value,
|
|
5759
|
+
String(args[1])
|
|
5760
|
+
);
|
|
5761
|
+
return;
|
|
5762
|
+
}
|
|
5763
|
+
const method = args[0];
|
|
5764
|
+
const context = args[1];
|
|
5765
|
+
if (typeof method !== "function" || context?.kind !== "method") {
|
|
5766
|
+
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
5767
|
+
}
|
|
5768
|
+
if (!this.explicitlyEnabled) {
|
|
5769
|
+
return method;
|
|
5770
|
+
}
|
|
5771
|
+
return this.createAutoTraceNode(
|
|
5772
|
+
configuration,
|
|
5773
|
+
method,
|
|
5774
|
+
String(context.name)
|
|
5775
|
+
);
|
|
5776
|
+
};
|
|
5777
|
+
return decorator;
|
|
5778
|
+
}
|
|
5779
|
+
withNode(optionsOrFn, maybeFn, internalFunctionName) {
|
|
5780
|
+
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
5781
|
+
const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
|
|
5782
|
+
if (!fn) {
|
|
5783
|
+
throw new BitfabError("bitfab.withNode requires a function");
|
|
5784
|
+
}
|
|
5785
|
+
const configuration = this.resolveNodeConfiguration(options);
|
|
5786
|
+
if (!this.explicitlyEnabled) {
|
|
5787
|
+
return fn;
|
|
5788
|
+
}
|
|
5789
|
+
const functionName = internalFunctionName ?? fn.name;
|
|
5790
|
+
if (functionName === "") {
|
|
5791
|
+
throw new BitfabError(
|
|
5792
|
+
"bitfab.withNode requires a named function so the subtree transform can bind its configuration to the correct call."
|
|
5793
|
+
);
|
|
5794
|
+
}
|
|
5795
|
+
return this.createAutoTraceNode(configuration, fn, functionName);
|
|
5796
|
+
}
|
|
5797
|
+
resolveNodeConfiguration(options) {
|
|
5798
|
+
const capture = options.capture ?? true;
|
|
5799
|
+
if (!capture && options.mockOnReplay === true) {
|
|
5800
|
+
throw new BitfabError(
|
|
5801
|
+
"bitfab.node({ capture: false }) cannot use mockOnReplay: true because an uncaptured node has no recorded output."
|
|
5802
|
+
);
|
|
5803
|
+
}
|
|
5804
|
+
return {
|
|
5805
|
+
capture,
|
|
5806
|
+
type: options.type ?? "custom",
|
|
5807
|
+
...options.name !== void 0 && { name: options.name },
|
|
5808
|
+
...options.testRunId !== void 0 && {
|
|
5809
|
+
testRunId: options.testRunId
|
|
5810
|
+
},
|
|
5811
|
+
...options.mockOnReplay !== void 0 && {
|
|
5812
|
+
mockOnReplay: options.mockOnReplay
|
|
5813
|
+
},
|
|
5814
|
+
...options.finalize !== void 0 && { finalize: options.finalize }
|
|
5815
|
+
};
|
|
5816
|
+
}
|
|
5817
|
+
createAutoTraceNode(configuration, fn, functionName) {
|
|
5818
|
+
const nodeConfiguration = { ...configuration, functionName };
|
|
5819
|
+
return function(...args) {
|
|
5820
|
+
if (!__bitfabAutoTraceActive()) {
|
|
5821
|
+
return fn.apply(this, args);
|
|
5822
|
+
}
|
|
5823
|
+
return runWithAutoTraceNodeConfiguration(
|
|
5824
|
+
nodeConfiguration,
|
|
5825
|
+
() => fn.apply(this, args)
|
|
5826
|
+
);
|
|
5827
|
+
};
|
|
5828
|
+
}
|
|
5681
5829
|
createAutoTraceRoot(traceFunctionKey, name, options, fn) {
|
|
5682
5830
|
const self = this;
|
|
5683
5831
|
const maxDepth = autoTraceLimit(
|
|
@@ -5716,29 +5864,51 @@ var Bitfab = class {
|
|
|
5716
5864
|
);
|
|
5717
5865
|
};
|
|
5718
5866
|
const autoTraceContext = {
|
|
5719
|
-
invoke(definition, inputs, invokeFn, depth) {
|
|
5867
|
+
invoke(definition, inputs, invokeFn, depth, nodeConfiguration) {
|
|
5720
5868
|
const nameParts = definition.name.split(".");
|
|
5721
5869
|
const simpleName = nameParts[nameParts.length - 1];
|
|
5722
|
-
|
|
5723
|
-
|
|
5870
|
+
const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
|
|
5871
|
+
if (excluded.has(definition.name) || simpleName !== void 0 && excluded.has(simpleName) || nodeConfiguration === void 0 && definition.wrapper === true && !includeWrappers) {
|
|
5872
|
+
return invokeWithoutNode();
|
|
5873
|
+
}
|
|
5874
|
+
if (nodeConfiguration?.capture === false) {
|
|
5875
|
+
return runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
|
|
5724
5876
|
}
|
|
5725
5877
|
if (depth >= maxDepth || spansUsed >= maxSpans) {
|
|
5726
5878
|
warnTruncated();
|
|
5727
|
-
return
|
|
5879
|
+
return invokeWithoutNode();
|
|
5728
5880
|
}
|
|
5729
5881
|
spansUsed += 1;
|
|
5730
5882
|
const childOptions = {
|
|
5731
|
-
name: definition.name,
|
|
5732
|
-
type: "function",
|
|
5883
|
+
name: nodeConfiguration?.name ?? definition.name,
|
|
5884
|
+
type: nodeConfiguration?.type ?? "function",
|
|
5733
5885
|
captureWhen: "nested",
|
|
5734
5886
|
functionId: definition.id,
|
|
5735
|
-
captureContent: capturePolicy.has(definition.id),
|
|
5736
|
-
autoTraceDefinition: definition
|
|
5887
|
+
captureContent: nodeConfiguration !== void 0 || capturePolicy.has(definition.id),
|
|
5888
|
+
autoTraceDefinition: definition,
|
|
5889
|
+
...nodeConfiguration?.testRunId !== void 0 && {
|
|
5890
|
+
testRunId: nodeConfiguration.testRunId
|
|
5891
|
+
},
|
|
5892
|
+
...nodeConfiguration?.mockOnReplay !== void 0 && {
|
|
5893
|
+
mockOnReplay: nodeConfiguration.mockOnReplay
|
|
5894
|
+
},
|
|
5895
|
+
...nodeConfiguration?.finalize !== void 0 && {
|
|
5896
|
+
finalize: nodeConfiguration.finalize
|
|
5897
|
+
}
|
|
5737
5898
|
};
|
|
5899
|
+
const invokeWithAutoTraceContext = () => runWithAutoTraceContext(autoTraceContext, invokeFn, depth + 1);
|
|
5900
|
+
if (definition.async === true) {
|
|
5901
|
+
const tracedAsyncChild = self.withSpan(
|
|
5902
|
+
traceFunctionKey,
|
|
5903
|
+
childOptions,
|
|
5904
|
+
async (..._inputs) => await invokeWithAutoTraceContext()
|
|
5905
|
+
);
|
|
5906
|
+
return tracedAsyncChild(...inputs);
|
|
5907
|
+
}
|
|
5738
5908
|
const tracedChild = self.withSpan(
|
|
5739
5909
|
traceFunctionKey,
|
|
5740
5910
|
childOptions,
|
|
5741
|
-
(..._inputs) =>
|
|
5911
|
+
(..._inputs) => invokeWithAutoTraceContext()
|
|
5742
5912
|
);
|
|
5743
5913
|
return tracedChild(...inputs);
|
|
5744
5914
|
}
|
|
@@ -6308,18 +6478,17 @@ var Bitfab = class {
|
|
|
6308
6478
|
newStack = [...currentStack, newContext];
|
|
6309
6479
|
const inputs = args;
|
|
6310
6480
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6481
|
+
const replayCtxAtStart = getReplayContext();
|
|
6482
|
+
const testRunId = replayCtxAtStart?.testRunId ?? options.testRunId;
|
|
6311
6483
|
if (isRootSpan && !activeTraceStates.has(traceId)) {
|
|
6312
|
-
const replayCtxAtRoot = getReplayContext();
|
|
6313
6484
|
const dbSnapshotRef = buildSnapshotRef(self.dbSnapshot, startedAt);
|
|
6314
6485
|
activeTraceStates.set(traceId, {
|
|
6315
6486
|
traceId,
|
|
6316
6487
|
startedAt,
|
|
6317
6488
|
contexts: [],
|
|
6318
|
-
...
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
...replayCtxAtRoot?.inputSourceTraceId && {
|
|
6322
|
-
inputSourceTraceId: replayCtxAtRoot.inputSourceTraceId
|
|
6489
|
+
...testRunId !== void 0 && { testRunId },
|
|
6490
|
+
...replayCtxAtStart?.inputSourceTraceId && {
|
|
6491
|
+
inputSourceTraceId: replayCtxAtStart.inputSourceTraceId
|
|
6323
6492
|
},
|
|
6324
6493
|
dbSnapshotRef
|
|
6325
6494
|
});
|
|
@@ -6352,9 +6521,7 @@ var Bitfab = class {
|
|
|
6352
6521
|
contexts: newContext.contexts,
|
|
6353
6522
|
prompt: newContext.prompt,
|
|
6354
6523
|
endedAt,
|
|
6355
|
-
...
|
|
6356
|
-
testRunId: replayCtx.testRunId
|
|
6357
|
-
},
|
|
6524
|
+
...testRunId !== void 0 && { testRunId },
|
|
6358
6525
|
...replayCtx?.inputSourceSpanId && {
|
|
6359
6526
|
inputSourceSpanId: replayCtx.inputSourceSpanId
|
|
6360
6527
|
}
|
|
@@ -6394,6 +6561,49 @@ var Bitfab = class {
|
|
|
6394
6561
|
} catch {
|
|
6395
6562
|
}
|
|
6396
6563
|
};
|
|
6564
|
+
const recordSpan = (result) => {
|
|
6565
|
+
if (options.finalize) {
|
|
6566
|
+
void self.httpClient.trackDeferred(
|
|
6567
|
+
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
6568
|
+
(error) => sendSpan({
|
|
6569
|
+
result: void 0,
|
|
6570
|
+
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
6571
|
+
})
|
|
6572
|
+
)
|
|
6573
|
+
);
|
|
6574
|
+
} else {
|
|
6575
|
+
void sendSpan({ result });
|
|
6576
|
+
}
|
|
6577
|
+
};
|
|
6578
|
+
executeWithContext = () => {
|
|
6579
|
+
let result;
|
|
6580
|
+
try {
|
|
6581
|
+
result = fn.apply(this, args);
|
|
6582
|
+
} catch (error) {
|
|
6583
|
+
void sendSpan({
|
|
6584
|
+
result: void 0,
|
|
6585
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6586
|
+
});
|
|
6587
|
+
throw error;
|
|
6588
|
+
}
|
|
6589
|
+
if (result instanceof Promise) {
|
|
6590
|
+
return result.then((resolvedResult) => {
|
|
6591
|
+
recordSpan(resolvedResult);
|
|
6592
|
+
return resolvedResult;
|
|
6593
|
+
}).catch((error) => {
|
|
6594
|
+
void sendSpan({
|
|
6595
|
+
result: void 0,
|
|
6596
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6597
|
+
});
|
|
6598
|
+
throw error;
|
|
6599
|
+
});
|
|
6600
|
+
}
|
|
6601
|
+
if (isAsyncGenerator(result)) {
|
|
6602
|
+
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
6603
|
+
}
|
|
6604
|
+
recordSpan(result);
|
|
6605
|
+
return result;
|
|
6606
|
+
};
|
|
6397
6607
|
const replayCtxForMock = getReplayContext();
|
|
6398
6608
|
if (replayCtxForMock?.mockTree && !isRootSpan) {
|
|
6399
6609
|
const counters = replayCtxForMock.callCounters;
|
|
@@ -6452,6 +6662,7 @@ var Bitfab = class {
|
|
|
6452
6662
|
}
|
|
6453
6663
|
return output;
|
|
6454
6664
|
};
|
|
6665
|
+
const shouldMockWithBaseStrategy = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
|
|
6455
6666
|
if (replayCtxForMock.mockOverrides?.length) {
|
|
6456
6667
|
const nodeMeta = {
|
|
6457
6668
|
traceFunctionKey,
|
|
@@ -6459,28 +6670,75 @@ var Bitfab = class {
|
|
|
6459
6670
|
type: options.type ?? "custom",
|
|
6460
6671
|
originalSpanId: mockSpan?.sourceSpanId
|
|
6461
6672
|
};
|
|
6462
|
-
const
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6673
|
+
const overrideCtx = {
|
|
6674
|
+
node: nodeMeta,
|
|
6675
|
+
inputs: args,
|
|
6676
|
+
getOriginalOutput: () => Promise.resolve(resolveRecordedOutput())
|
|
6677
|
+
};
|
|
6678
|
+
const resolveOverrideFrom = (startIndex) => {
|
|
6679
|
+
for (let index = startIndex; index < replayCtxForMock.mockOverrides.length; index += 1) {
|
|
6680
|
+
const override = replayCtxForMock.mockOverrides[index];
|
|
6681
|
+
if (!override?.match(nodeMeta)) {
|
|
6682
|
+
continue;
|
|
6683
|
+
}
|
|
6684
|
+
const injected = resolveMockValue(override.value, overrideCtx);
|
|
6685
|
+
if (injected instanceof Promise) {
|
|
6686
|
+
return injected.then(
|
|
6687
|
+
(output) => output === NO_MOCK_OVERRIDE ? resolveOverrideFrom(index + 1) : { matched: true, output }
|
|
6688
|
+
);
|
|
6689
|
+
}
|
|
6690
|
+
if (injected !== NO_MOCK_OVERRIDE) {
|
|
6691
|
+
return { matched: true, output: injected };
|
|
6692
|
+
}
|
|
6693
|
+
}
|
|
6694
|
+
return { matched: false };
|
|
6695
|
+
};
|
|
6696
|
+
const resolution = resolveOverrideFrom(0);
|
|
6697
|
+
if (resolution instanceof Promise) {
|
|
6698
|
+
if (!fnReturnsPromise) {
|
|
6699
|
+
throw new BitfabError(
|
|
6700
|
+
`Cannot resolve an asynchronous mock override for synchronous span "${traceFunctionKey}". Make the wrapped function async or return NO_MOCK_OVERRIDE synchronously.`
|
|
6701
|
+
);
|
|
6473
6702
|
}
|
|
6474
|
-
return
|
|
6703
|
+
return runWithSpanStack(newStack, async () => {
|
|
6704
|
+
const resolved = await resolution;
|
|
6705
|
+
if (resolved.matched) {
|
|
6706
|
+
void sendSpan({
|
|
6707
|
+
result: resolved.output,
|
|
6708
|
+
mocked: true,
|
|
6709
|
+
mockTarget: "output",
|
|
6710
|
+
mockSource: "override"
|
|
6711
|
+
});
|
|
6712
|
+
return resolved.output;
|
|
6713
|
+
}
|
|
6714
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
6715
|
+
throw new BitfabError(
|
|
6716
|
+
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
6717
|
+
);
|
|
6718
|
+
}
|
|
6719
|
+
if (shouldMockWithBaseStrategy) {
|
|
6720
|
+
const output = await resolveRecordedOutput();
|
|
6721
|
+
void sendSpan({
|
|
6722
|
+
result: output,
|
|
6723
|
+
mocked: true,
|
|
6724
|
+
mockTarget: "output",
|
|
6725
|
+
mockSource: "recorded"
|
|
6726
|
+
});
|
|
6727
|
+
return output;
|
|
6728
|
+
}
|
|
6729
|
+
return executeWithContext();
|
|
6730
|
+
});
|
|
6731
|
+
}
|
|
6732
|
+
if (resolution.matched) {
|
|
6733
|
+
return emitMock(resolution.output, "override");
|
|
6475
6734
|
}
|
|
6476
6735
|
}
|
|
6477
|
-
|
|
6478
|
-
if (shouldMock && !mockSpan) {
|
|
6736
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
6479
6737
|
throw new BitfabError(
|
|
6480
6738
|
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
6481
6739
|
);
|
|
6482
6740
|
}
|
|
6483
|
-
if (
|
|
6741
|
+
if (shouldMockWithBaseStrategy) {
|
|
6484
6742
|
const recorded = resolveRecordedOutput();
|
|
6485
6743
|
if (recorded instanceof Promise) {
|
|
6486
6744
|
return emitMockAsync(recorded, "recorded");
|
|
@@ -6488,49 +6746,6 @@ var Bitfab = class {
|
|
|
6488
6746
|
return emitMock(recorded, "recorded");
|
|
6489
6747
|
}
|
|
6490
6748
|
}
|
|
6491
|
-
const recordSpan = (result) => {
|
|
6492
|
-
if (options.finalize) {
|
|
6493
|
-
void self.httpClient.trackDeferred(
|
|
6494
|
-
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
6495
|
-
(error) => sendSpan({
|
|
6496
|
-
result: void 0,
|
|
6497
|
-
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
6498
|
-
})
|
|
6499
|
-
)
|
|
6500
|
-
);
|
|
6501
|
-
} else {
|
|
6502
|
-
void sendSpan({ result });
|
|
6503
|
-
}
|
|
6504
|
-
};
|
|
6505
|
-
executeWithContext = () => {
|
|
6506
|
-
let result;
|
|
6507
|
-
try {
|
|
6508
|
-
result = fn.apply(this, args);
|
|
6509
|
-
} catch (error) {
|
|
6510
|
-
void sendSpan({
|
|
6511
|
-
result: void 0,
|
|
6512
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6513
|
-
});
|
|
6514
|
-
throw error;
|
|
6515
|
-
}
|
|
6516
|
-
if (result instanceof Promise) {
|
|
6517
|
-
return result.then((resolvedResult) => {
|
|
6518
|
-
recordSpan(resolvedResult);
|
|
6519
|
-
return resolvedResult;
|
|
6520
|
-
}).catch((error) => {
|
|
6521
|
-
void sendSpan({
|
|
6522
|
-
result: void 0,
|
|
6523
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6524
|
-
});
|
|
6525
|
-
throw error;
|
|
6526
|
-
});
|
|
6527
|
-
}
|
|
6528
|
-
if (isAsyncGenerator(result)) {
|
|
6529
|
-
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
6530
|
-
}
|
|
6531
|
-
recordSpan(result);
|
|
6532
|
-
return result;
|
|
6533
|
-
};
|
|
6534
6749
|
} catch (setupError) {
|
|
6535
6750
|
if (registeredTraceId) {
|
|
6536
6751
|
activeTraceStates.delete(registeredTraceId);
|
|
@@ -6817,8 +7032,40 @@ var Bitfab = class {
|
|
|
6817
7032
|
...params.mockSource && { mockSource: params.mockSource }
|
|
6818
7033
|
});
|
|
6819
7034
|
}
|
|
6820
|
-
registerMockOverride(
|
|
6821
|
-
|
|
7035
|
+
registerMockOverride(overrideOrResolverOrMatch, ...values) {
|
|
7036
|
+
let override;
|
|
7037
|
+
if (typeof overrideOrResolverOrMatch === "string") {
|
|
7038
|
+
const keyedOverride = values[0];
|
|
7039
|
+
if (values.length !== 1 || keyedOverride === void 0) {
|
|
7040
|
+
throw new BitfabError(
|
|
7041
|
+
"registerMockOverride(traceFunctionKey, override) requires a resolver function or { match, value } override."
|
|
7042
|
+
);
|
|
7043
|
+
}
|
|
7044
|
+
if (typeof keyedOverride === "function") {
|
|
7045
|
+
override = {
|
|
7046
|
+
match: (node) => node.traceFunctionKey === overrideOrResolverOrMatch,
|
|
7047
|
+
value: keyedOverride
|
|
7048
|
+
};
|
|
7049
|
+
} else if (typeof keyedOverride === "object" && keyedOverride !== null && "match" in keyedOverride && "value" in keyedOverride) {
|
|
7050
|
+
override = {
|
|
7051
|
+
match: (node) => node.traceFunctionKey === overrideOrResolverOrMatch && keyedOverride.match(node),
|
|
7052
|
+
value: keyedOverride.value
|
|
7053
|
+
};
|
|
7054
|
+
} else {
|
|
7055
|
+
throw new BitfabError(
|
|
7056
|
+
"registerMockOverride(traceFunctionKey, override) requires a resolver function or { match, value } override."
|
|
7057
|
+
);
|
|
7058
|
+
}
|
|
7059
|
+
} else if (typeof overrideOrResolverOrMatch !== "function") {
|
|
7060
|
+
override = overrideOrResolverOrMatch;
|
|
7061
|
+
} else if (values.length === 0) {
|
|
7062
|
+
override = { match: () => true, value: overrideOrResolverOrMatch };
|
|
7063
|
+
} else {
|
|
7064
|
+
override = {
|
|
7065
|
+
match: overrideOrResolverOrMatch,
|
|
7066
|
+
value: values[0]
|
|
7067
|
+
};
|
|
7068
|
+
}
|
|
6822
7069
|
this.mockOverrides.push(override);
|
|
6823
7070
|
}
|
|
6824
7071
|
/** Remove all overrides registered via {@link registerMockOverride}. */
|
|
@@ -7068,6 +7315,7 @@ var finalizers = {
|
|
|
7068
7315
|
|
|
7069
7316
|
// src/index.ts
|
|
7070
7317
|
init_http();
|
|
7318
|
+
init_mockOverride();
|
|
7071
7319
|
init_replay();
|
|
7072
7320
|
|
|
7073
7321
|
// src/replayRegistry.ts
|
|
@@ -7091,6 +7339,7 @@ function defineReplayRegistry(registry) {
|
|
|
7091
7339
|
DEFAULT_SERVICE_URL,
|
|
7092
7340
|
DbBranchReplayError,
|
|
7093
7341
|
HttpClient,
|
|
7342
|
+
NO_MOCK_OVERRIDE,
|
|
7094
7343
|
ReplayError,
|
|
7095
7344
|
SUPPORTED_PROVIDERS,
|
|
7096
7345
|
__version__,
|