bitfab 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-GSTRSZRO.js → chunk-LQDCJPVV.js} +280 -82
- package/dist/chunk-LQDCJPVV.js.map +1 -0
- package/dist/{chunk-QNPM27RY.js → chunk-ZXJ3VQLF.js} +8 -3
- package/dist/chunk-ZXJ3VQLF.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-4GLNUPTB.js → replay-HTVEYGC5.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-GSTRSZRO.js.map +0 -1
- package/dist/chunk-QNPM27RY.js.map +0 -1
- /package/dist/{replay-4GLNUPTB.js.map → replay-HTVEYGC5.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -51,7 +51,7 @@ var __version__, __packageName__;
|
|
|
51
51
|
var init_version_generated = __esm({
|
|
52
52
|
"src/version.generated.ts"() {
|
|
53
53
|
"use strict";
|
|
54
|
-
__version__ = "0.38.
|
|
54
|
+
__version__ = "0.38.5";
|
|
55
55
|
__packageName__ = "bitfab";
|
|
56
56
|
}
|
|
57
57
|
});
|
|
@@ -2196,11 +2196,16 @@ function normalizeMockOverrides(mockOverride) {
|
|
|
2196
2196
|
if (mockOverride === void 0) {
|
|
2197
2197
|
return [];
|
|
2198
2198
|
}
|
|
2199
|
-
|
|
2199
|
+
const overrides = Array.isArray(mockOverride) ? mockOverride : [mockOverride];
|
|
2200
|
+
return overrides.map(
|
|
2201
|
+
(override) => typeof override === "function" ? { match: () => true, value: override } : override
|
|
2202
|
+
);
|
|
2200
2203
|
}
|
|
2204
|
+
var NO_MOCK_OVERRIDE;
|
|
2201
2205
|
var init_mockOverride = __esm({
|
|
2202
2206
|
"src/mockOverride.ts"() {
|
|
2203
2207
|
"use strict";
|
|
2208
|
+
NO_MOCK_OVERRIDE = /* @__PURE__ */ Symbol("bitfab.noMockOverride");
|
|
2204
2209
|
}
|
|
2205
2210
|
});
|
|
2206
2211
|
|
|
@@ -3142,6 +3147,7 @@ __export(index_exports, {
|
|
|
3142
3147
|
DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
|
|
3143
3148
|
DbBranchReplayError: () => DbBranchReplayError,
|
|
3144
3149
|
HttpClient: () => HttpClient,
|
|
3150
|
+
NO_MOCK_OVERRIDE: () => NO_MOCK_OVERRIDE,
|
|
3145
3151
|
ReplayError: () => ReplayError,
|
|
3146
3152
|
SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
|
|
3147
3153
|
__version__: () => __version__,
|
|
@@ -3797,6 +3803,29 @@ function runWithAutoTraceContext(context, fn, depth = 0) {
|
|
|
3797
3803
|
autoTraceState.browserScope = previous;
|
|
3798
3804
|
}
|
|
3799
3805
|
}
|
|
3806
|
+
function runWithAutoTraceNodeConfiguration(nodeConfiguration, fn) {
|
|
3807
|
+
const scope = currentAutoTraceScope();
|
|
3808
|
+
if (!scope) {
|
|
3809
|
+
return fn();
|
|
3810
|
+
}
|
|
3811
|
+
const configuredScope = { ...scope, nodeConfiguration };
|
|
3812
|
+
let result;
|
|
3813
|
+
if (autoTraceState.storage) {
|
|
3814
|
+
result = autoTraceState.storage.run(configuredScope, fn);
|
|
3815
|
+
} else {
|
|
3816
|
+
const previous = autoTraceState.browserScope;
|
|
3817
|
+
autoTraceState.browserScope = configuredScope;
|
|
3818
|
+
try {
|
|
3819
|
+
result = fn();
|
|
3820
|
+
} finally {
|
|
3821
|
+
autoTraceState.browserScope = previous;
|
|
3822
|
+
}
|
|
3823
|
+
}
|
|
3824
|
+
if (isAutoTraceAsyncGenerator(result)) {
|
|
3825
|
+
return wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, result);
|
|
3826
|
+
}
|
|
3827
|
+
return result;
|
|
3828
|
+
}
|
|
3800
3829
|
function runWithAutoTraceRootContext(context, fn) {
|
|
3801
3830
|
autoTraceState.activeRoots += 1;
|
|
3802
3831
|
let result;
|
|
@@ -3835,6 +3864,29 @@ function wrapAutoTraceAsyncGenerator(context, source) {
|
|
|
3835
3864
|
};
|
|
3836
3865
|
return wrapped;
|
|
3837
3866
|
}
|
|
3867
|
+
function wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, source) {
|
|
3868
|
+
const step = (method, value) => runWithAutoTraceNodeConfiguration(
|
|
3869
|
+
nodeConfiguration,
|
|
3870
|
+
() => source[method](value)
|
|
3871
|
+
);
|
|
3872
|
+
const wrapped = {
|
|
3873
|
+
next: (value) => step("next", value),
|
|
3874
|
+
return: (value) => step("return", value),
|
|
3875
|
+
throw: (error) => step("throw", error),
|
|
3876
|
+
[Symbol.asyncIterator]: () => wrapped
|
|
3877
|
+
};
|
|
3878
|
+
return wrapped;
|
|
3879
|
+
}
|
|
3880
|
+
function __bitfabAutoTraceActive() {
|
|
3881
|
+
if (autoTraceState.activeRoots === 0) {
|
|
3882
|
+
return false;
|
|
3883
|
+
}
|
|
3884
|
+
return currentAutoTraceScope() !== void 0;
|
|
3885
|
+
}
|
|
3886
|
+
function currentAutoTraceScope() {
|
|
3887
|
+
initializeAutoTraceStorage();
|
|
3888
|
+
return autoTraceState.storage?.getStore() ?? autoTraceState.browserScope;
|
|
3889
|
+
}
|
|
3838
3890
|
function __setBitfabAutoTraceCapturePolicy(client, traceFunctionKey, functionIds) {
|
|
3839
3891
|
const policies = autoTraceState.capturePolicies.get(client) ?? /* @__PURE__ */ new Map();
|
|
3840
3892
|
policies.set(traceFunctionKey, new Set(functionIds));
|
|
@@ -5687,6 +5739,102 @@ var Bitfab = class {
|
|
|
5687
5739
|
const name = fn.name !== "" ? fn.name : traceFunctionKey;
|
|
5688
5740
|
return this.createAutoTraceRoot(traceFunctionKey, name, options, fn);
|
|
5689
5741
|
}
|
|
5742
|
+
/**
|
|
5743
|
+
* Configure a transformed class method when it is discovered beneath a
|
|
5744
|
+
* {@link Bitfab.trace} root.
|
|
5745
|
+
*
|
|
5746
|
+
* The decorator creates no span or trace by itself. Beneath an active trace,
|
|
5747
|
+
* it can rename or retype the discovered call, capture its contents, mark it
|
|
5748
|
+
* for recorded-output replay, finalize its output, or omit it while leaving
|
|
5749
|
+
* captured descendants attached to the nearest captured parent.
|
|
5750
|
+
*
|
|
5751
|
+
* @param options - Trace-owned call configuration.
|
|
5752
|
+
* @experimental Automatic child-call instrumentation is experimental.
|
|
5753
|
+
*/
|
|
5754
|
+
node(options = {}) {
|
|
5755
|
+
const configuration = this.resolveNodeConfiguration(options);
|
|
5756
|
+
const decorator = (...args) => {
|
|
5757
|
+
if (args.length === 3) {
|
|
5758
|
+
const descriptor = args[2];
|
|
5759
|
+
if (!descriptor || typeof descriptor.value !== "function") {
|
|
5760
|
+
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
5761
|
+
}
|
|
5762
|
+
if (!this.explicitlyEnabled) {
|
|
5763
|
+
return;
|
|
5764
|
+
}
|
|
5765
|
+
descriptor.value = this.createAutoTraceNode(
|
|
5766
|
+
configuration,
|
|
5767
|
+
descriptor.value,
|
|
5768
|
+
String(args[1])
|
|
5769
|
+
);
|
|
5770
|
+
return;
|
|
5771
|
+
}
|
|
5772
|
+
const method = args[0];
|
|
5773
|
+
const context = args[1];
|
|
5774
|
+
if (typeof method !== "function" || context?.kind !== "method") {
|
|
5775
|
+
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
5776
|
+
}
|
|
5777
|
+
if (!this.explicitlyEnabled) {
|
|
5778
|
+
return method;
|
|
5779
|
+
}
|
|
5780
|
+
return this.createAutoTraceNode(
|
|
5781
|
+
configuration,
|
|
5782
|
+
method,
|
|
5783
|
+
String(context.name)
|
|
5784
|
+
);
|
|
5785
|
+
};
|
|
5786
|
+
return decorator;
|
|
5787
|
+
}
|
|
5788
|
+
withNode(optionsOrFn, maybeFn, internalFunctionName) {
|
|
5789
|
+
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
5790
|
+
const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
|
|
5791
|
+
if (!fn) {
|
|
5792
|
+
throw new BitfabError("bitfab.withNode requires a function");
|
|
5793
|
+
}
|
|
5794
|
+
const configuration = this.resolveNodeConfiguration(options);
|
|
5795
|
+
if (!this.explicitlyEnabled) {
|
|
5796
|
+
return fn;
|
|
5797
|
+
}
|
|
5798
|
+
const functionName = internalFunctionName ?? fn.name;
|
|
5799
|
+
if (functionName === "") {
|
|
5800
|
+
throw new BitfabError(
|
|
5801
|
+
"bitfab.withNode requires a named function so the subtree transform can bind its configuration to the correct call."
|
|
5802
|
+
);
|
|
5803
|
+
}
|
|
5804
|
+
return this.createAutoTraceNode(configuration, fn, functionName);
|
|
5805
|
+
}
|
|
5806
|
+
resolveNodeConfiguration(options) {
|
|
5807
|
+
const capture = options.capture ?? true;
|
|
5808
|
+
if (!capture && options.mockOnReplay === true) {
|
|
5809
|
+
throw new BitfabError(
|
|
5810
|
+
"bitfab.node({ capture: false }) cannot use mockOnReplay: true because an uncaptured node has no recorded output."
|
|
5811
|
+
);
|
|
5812
|
+
}
|
|
5813
|
+
return {
|
|
5814
|
+
capture,
|
|
5815
|
+
type: options.type ?? "custom",
|
|
5816
|
+
...options.name !== void 0 && { name: options.name },
|
|
5817
|
+
...options.testRunId !== void 0 && {
|
|
5818
|
+
testRunId: options.testRunId
|
|
5819
|
+
},
|
|
5820
|
+
...options.mockOnReplay !== void 0 && {
|
|
5821
|
+
mockOnReplay: options.mockOnReplay
|
|
5822
|
+
},
|
|
5823
|
+
...options.finalize !== void 0 && { finalize: options.finalize }
|
|
5824
|
+
};
|
|
5825
|
+
}
|
|
5826
|
+
createAutoTraceNode(configuration, fn, functionName) {
|
|
5827
|
+
const nodeConfiguration = { ...configuration, functionName };
|
|
5828
|
+
return function(...args) {
|
|
5829
|
+
if (!__bitfabAutoTraceActive()) {
|
|
5830
|
+
return fn.apply(this, args);
|
|
5831
|
+
}
|
|
5832
|
+
return runWithAutoTraceNodeConfiguration(
|
|
5833
|
+
nodeConfiguration,
|
|
5834
|
+
() => fn.apply(this, args)
|
|
5835
|
+
);
|
|
5836
|
+
};
|
|
5837
|
+
}
|
|
5690
5838
|
createAutoTraceRoot(traceFunctionKey, name, options, fn) {
|
|
5691
5839
|
const self = this;
|
|
5692
5840
|
const maxDepth = autoTraceLimit(
|
|
@@ -5725,29 +5873,51 @@ var Bitfab = class {
|
|
|
5725
5873
|
);
|
|
5726
5874
|
};
|
|
5727
5875
|
const autoTraceContext = {
|
|
5728
|
-
invoke(definition, inputs, invokeFn, depth) {
|
|
5876
|
+
invoke(definition, inputs, invokeFn, depth, nodeConfiguration) {
|
|
5729
5877
|
const nameParts = definition.name.split(".");
|
|
5730
5878
|
const simpleName = nameParts[nameParts.length - 1];
|
|
5731
|
-
|
|
5732
|
-
|
|
5879
|
+
const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
|
|
5880
|
+
if (excluded.has(definition.name) || simpleName !== void 0 && excluded.has(simpleName) || nodeConfiguration === void 0 && definition.wrapper === true && !includeWrappers) {
|
|
5881
|
+
return invokeWithoutNode();
|
|
5882
|
+
}
|
|
5883
|
+
if (nodeConfiguration?.capture === false) {
|
|
5884
|
+
return runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
|
|
5733
5885
|
}
|
|
5734
5886
|
if (depth >= maxDepth || spansUsed >= maxSpans) {
|
|
5735
5887
|
warnTruncated();
|
|
5736
|
-
return
|
|
5888
|
+
return invokeWithoutNode();
|
|
5737
5889
|
}
|
|
5738
5890
|
spansUsed += 1;
|
|
5739
5891
|
const childOptions = {
|
|
5740
|
-
name: definition.name,
|
|
5741
|
-
type: "function",
|
|
5892
|
+
name: nodeConfiguration?.name ?? definition.name,
|
|
5893
|
+
type: nodeConfiguration?.type ?? "function",
|
|
5742
5894
|
captureWhen: "nested",
|
|
5743
5895
|
functionId: definition.id,
|
|
5744
|
-
captureContent: capturePolicy.has(definition.id),
|
|
5745
|
-
autoTraceDefinition: definition
|
|
5896
|
+
captureContent: nodeConfiguration !== void 0 || capturePolicy.has(definition.id),
|
|
5897
|
+
autoTraceDefinition: definition,
|
|
5898
|
+
...nodeConfiguration?.testRunId !== void 0 && {
|
|
5899
|
+
testRunId: nodeConfiguration.testRunId
|
|
5900
|
+
},
|
|
5901
|
+
...nodeConfiguration?.mockOnReplay !== void 0 && {
|
|
5902
|
+
mockOnReplay: nodeConfiguration.mockOnReplay
|
|
5903
|
+
},
|
|
5904
|
+
...nodeConfiguration?.finalize !== void 0 && {
|
|
5905
|
+
finalize: nodeConfiguration.finalize
|
|
5906
|
+
}
|
|
5746
5907
|
};
|
|
5908
|
+
const invokeWithAutoTraceContext = () => runWithAutoTraceContext(autoTraceContext, invokeFn, depth + 1);
|
|
5909
|
+
if (definition.async === true) {
|
|
5910
|
+
const tracedAsyncChild = self.withSpan(
|
|
5911
|
+
traceFunctionKey,
|
|
5912
|
+
childOptions,
|
|
5913
|
+
async (..._inputs) => await invokeWithAutoTraceContext()
|
|
5914
|
+
);
|
|
5915
|
+
return tracedAsyncChild(...inputs);
|
|
5916
|
+
}
|
|
5747
5917
|
const tracedChild = self.withSpan(
|
|
5748
5918
|
traceFunctionKey,
|
|
5749
5919
|
childOptions,
|
|
5750
|
-
(..._inputs) =>
|
|
5920
|
+
(..._inputs) => invokeWithAutoTraceContext()
|
|
5751
5921
|
);
|
|
5752
5922
|
return tracedChild(...inputs);
|
|
5753
5923
|
}
|
|
@@ -6317,18 +6487,17 @@ var Bitfab = class {
|
|
|
6317
6487
|
newStack = [...currentStack, newContext];
|
|
6318
6488
|
const inputs = args;
|
|
6319
6489
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6490
|
+
const replayCtxAtStart = getReplayContext();
|
|
6491
|
+
const testRunId = replayCtxAtStart?.testRunId ?? options.testRunId;
|
|
6320
6492
|
if (isRootSpan && !activeTraceStates.has(traceId)) {
|
|
6321
|
-
const replayCtxAtRoot = getReplayContext();
|
|
6322
6493
|
const dbSnapshotRef = buildSnapshotRef(self.dbSnapshot, startedAt);
|
|
6323
6494
|
activeTraceStates.set(traceId, {
|
|
6324
6495
|
traceId,
|
|
6325
6496
|
startedAt,
|
|
6326
6497
|
contexts: [],
|
|
6327
|
-
...
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
...replayCtxAtRoot?.inputSourceTraceId && {
|
|
6331
|
-
inputSourceTraceId: replayCtxAtRoot.inputSourceTraceId
|
|
6498
|
+
...testRunId !== void 0 && { testRunId },
|
|
6499
|
+
...replayCtxAtStart?.inputSourceTraceId && {
|
|
6500
|
+
inputSourceTraceId: replayCtxAtStart.inputSourceTraceId
|
|
6332
6501
|
},
|
|
6333
6502
|
dbSnapshotRef
|
|
6334
6503
|
});
|
|
@@ -6361,9 +6530,7 @@ var Bitfab = class {
|
|
|
6361
6530
|
contexts: newContext.contexts,
|
|
6362
6531
|
prompt: newContext.prompt,
|
|
6363
6532
|
endedAt,
|
|
6364
|
-
...
|
|
6365
|
-
testRunId: replayCtx.testRunId
|
|
6366
|
-
},
|
|
6533
|
+
...testRunId !== void 0 && { testRunId },
|
|
6367
6534
|
...replayCtx?.inputSourceSpanId && {
|
|
6368
6535
|
inputSourceSpanId: replayCtx.inputSourceSpanId
|
|
6369
6536
|
}
|
|
@@ -6403,6 +6570,49 @@ var Bitfab = class {
|
|
|
6403
6570
|
} catch {
|
|
6404
6571
|
}
|
|
6405
6572
|
};
|
|
6573
|
+
const recordSpan = (result) => {
|
|
6574
|
+
if (options.finalize) {
|
|
6575
|
+
void self.httpClient.trackDeferred(
|
|
6576
|
+
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
6577
|
+
(error) => sendSpan({
|
|
6578
|
+
result: void 0,
|
|
6579
|
+
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
6580
|
+
})
|
|
6581
|
+
)
|
|
6582
|
+
);
|
|
6583
|
+
} else {
|
|
6584
|
+
void sendSpan({ result });
|
|
6585
|
+
}
|
|
6586
|
+
};
|
|
6587
|
+
executeWithContext = () => {
|
|
6588
|
+
let result;
|
|
6589
|
+
try {
|
|
6590
|
+
result = fn.apply(this, args);
|
|
6591
|
+
} catch (error) {
|
|
6592
|
+
void sendSpan({
|
|
6593
|
+
result: void 0,
|
|
6594
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6595
|
+
});
|
|
6596
|
+
throw error;
|
|
6597
|
+
}
|
|
6598
|
+
if (result instanceof Promise) {
|
|
6599
|
+
return result.then((resolvedResult) => {
|
|
6600
|
+
recordSpan(resolvedResult);
|
|
6601
|
+
return resolvedResult;
|
|
6602
|
+
}).catch((error) => {
|
|
6603
|
+
void sendSpan({
|
|
6604
|
+
result: void 0,
|
|
6605
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6606
|
+
});
|
|
6607
|
+
throw error;
|
|
6608
|
+
});
|
|
6609
|
+
}
|
|
6610
|
+
if (isAsyncGenerator(result)) {
|
|
6611
|
+
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
6612
|
+
}
|
|
6613
|
+
recordSpan(result);
|
|
6614
|
+
return result;
|
|
6615
|
+
};
|
|
6406
6616
|
const replayCtxForMock = getReplayContext();
|
|
6407
6617
|
if (replayCtxForMock?.mockTree && !isRootSpan) {
|
|
6408
6618
|
const counters = replayCtxForMock.callCounters;
|
|
@@ -6461,6 +6671,7 @@ var Bitfab = class {
|
|
|
6461
6671
|
}
|
|
6462
6672
|
return output;
|
|
6463
6673
|
};
|
|
6674
|
+
const shouldMockWithBaseStrategy = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
|
|
6464
6675
|
if (replayCtxForMock.mockOverrides?.length) {
|
|
6465
6676
|
const nodeMeta = {
|
|
6466
6677
|
traceFunctionKey,
|
|
@@ -6468,28 +6679,75 @@ var Bitfab = class {
|
|
|
6468
6679
|
type: options.type ?? "custom",
|
|
6469
6680
|
originalSpanId: mockSpan?.sourceSpanId
|
|
6470
6681
|
};
|
|
6471
|
-
const
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6682
|
+
const overrideCtx = {
|
|
6683
|
+
node: nodeMeta,
|
|
6684
|
+
inputs: args,
|
|
6685
|
+
getOriginalOutput: () => Promise.resolve(resolveRecordedOutput())
|
|
6686
|
+
};
|
|
6687
|
+
const resolveOverrideFrom = (startIndex) => {
|
|
6688
|
+
for (let index = startIndex; index < replayCtxForMock.mockOverrides.length; index += 1) {
|
|
6689
|
+
const override = replayCtxForMock.mockOverrides[index];
|
|
6690
|
+
if (!override?.match(nodeMeta)) {
|
|
6691
|
+
continue;
|
|
6692
|
+
}
|
|
6693
|
+
const injected = resolveMockValue(override.value, overrideCtx);
|
|
6694
|
+
if (injected instanceof Promise) {
|
|
6695
|
+
return injected.then(
|
|
6696
|
+
(output) => output === NO_MOCK_OVERRIDE ? resolveOverrideFrom(index + 1) : { matched: true, output }
|
|
6697
|
+
);
|
|
6698
|
+
}
|
|
6699
|
+
if (injected !== NO_MOCK_OVERRIDE) {
|
|
6700
|
+
return { matched: true, output: injected };
|
|
6701
|
+
}
|
|
6702
|
+
}
|
|
6703
|
+
return { matched: false };
|
|
6704
|
+
};
|
|
6705
|
+
const resolution = resolveOverrideFrom(0);
|
|
6706
|
+
if (resolution instanceof Promise) {
|
|
6707
|
+
if (!fnReturnsPromise) {
|
|
6708
|
+
throw new BitfabError(
|
|
6709
|
+
`Cannot resolve an asynchronous mock override for synchronous span "${traceFunctionKey}". Make the wrapped function async or return NO_MOCK_OVERRIDE synchronously.`
|
|
6710
|
+
);
|
|
6482
6711
|
}
|
|
6483
|
-
return
|
|
6712
|
+
return runWithSpanStack(newStack, async () => {
|
|
6713
|
+
const resolved = await resolution;
|
|
6714
|
+
if (resolved.matched) {
|
|
6715
|
+
void sendSpan({
|
|
6716
|
+
result: resolved.output,
|
|
6717
|
+
mocked: true,
|
|
6718
|
+
mockTarget: "output",
|
|
6719
|
+
mockSource: "override"
|
|
6720
|
+
});
|
|
6721
|
+
return resolved.output;
|
|
6722
|
+
}
|
|
6723
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
6724
|
+
throw new BitfabError(
|
|
6725
|
+
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
6726
|
+
);
|
|
6727
|
+
}
|
|
6728
|
+
if (shouldMockWithBaseStrategy) {
|
|
6729
|
+
const output = await resolveRecordedOutput();
|
|
6730
|
+
void sendSpan({
|
|
6731
|
+
result: output,
|
|
6732
|
+
mocked: true,
|
|
6733
|
+
mockTarget: "output",
|
|
6734
|
+
mockSource: "recorded"
|
|
6735
|
+
});
|
|
6736
|
+
return output;
|
|
6737
|
+
}
|
|
6738
|
+
return executeWithContext();
|
|
6739
|
+
});
|
|
6740
|
+
}
|
|
6741
|
+
if (resolution.matched) {
|
|
6742
|
+
return emitMock(resolution.output, "override");
|
|
6484
6743
|
}
|
|
6485
6744
|
}
|
|
6486
|
-
|
|
6487
|
-
if (shouldMock && !mockSpan) {
|
|
6745
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
6488
6746
|
throw new BitfabError(
|
|
6489
6747
|
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
6490
6748
|
);
|
|
6491
6749
|
}
|
|
6492
|
-
if (
|
|
6750
|
+
if (shouldMockWithBaseStrategy) {
|
|
6493
6751
|
const recorded = resolveRecordedOutput();
|
|
6494
6752
|
if (recorded instanceof Promise) {
|
|
6495
6753
|
return emitMockAsync(recorded, "recorded");
|
|
@@ -6497,49 +6755,6 @@ var Bitfab = class {
|
|
|
6497
6755
|
return emitMock(recorded, "recorded");
|
|
6498
6756
|
}
|
|
6499
6757
|
}
|
|
6500
|
-
const recordSpan = (result) => {
|
|
6501
|
-
if (options.finalize) {
|
|
6502
|
-
void self.httpClient.trackDeferred(
|
|
6503
|
-
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
6504
|
-
(error) => sendSpan({
|
|
6505
|
-
result: void 0,
|
|
6506
|
-
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
6507
|
-
})
|
|
6508
|
-
)
|
|
6509
|
-
);
|
|
6510
|
-
} else {
|
|
6511
|
-
void sendSpan({ result });
|
|
6512
|
-
}
|
|
6513
|
-
};
|
|
6514
|
-
executeWithContext = () => {
|
|
6515
|
-
let result;
|
|
6516
|
-
try {
|
|
6517
|
-
result = fn.apply(this, args);
|
|
6518
|
-
} catch (error) {
|
|
6519
|
-
void sendSpan({
|
|
6520
|
-
result: void 0,
|
|
6521
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6522
|
-
});
|
|
6523
|
-
throw error;
|
|
6524
|
-
}
|
|
6525
|
-
if (result instanceof Promise) {
|
|
6526
|
-
return result.then((resolvedResult) => {
|
|
6527
|
-
recordSpan(resolvedResult);
|
|
6528
|
-
return resolvedResult;
|
|
6529
|
-
}).catch((error) => {
|
|
6530
|
-
void sendSpan({
|
|
6531
|
-
result: void 0,
|
|
6532
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6533
|
-
});
|
|
6534
|
-
throw error;
|
|
6535
|
-
});
|
|
6536
|
-
}
|
|
6537
|
-
if (isAsyncGenerator(result)) {
|
|
6538
|
-
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
6539
|
-
}
|
|
6540
|
-
recordSpan(result);
|
|
6541
|
-
return result;
|
|
6542
|
-
};
|
|
6543
6758
|
} catch (setupError) {
|
|
6544
6759
|
if (registeredTraceId) {
|
|
6545
6760
|
activeTraceStates.delete(registeredTraceId);
|
|
@@ -6826,8 +7041,40 @@ var Bitfab = class {
|
|
|
6826
7041
|
...params.mockSource && { mockSource: params.mockSource }
|
|
6827
7042
|
});
|
|
6828
7043
|
}
|
|
6829
|
-
registerMockOverride(
|
|
6830
|
-
|
|
7044
|
+
registerMockOverride(overrideOrResolverOrMatch, ...values) {
|
|
7045
|
+
let override;
|
|
7046
|
+
if (typeof overrideOrResolverOrMatch === "string") {
|
|
7047
|
+
const keyedOverride = values[0];
|
|
7048
|
+
if (values.length !== 1 || keyedOverride === void 0) {
|
|
7049
|
+
throw new BitfabError(
|
|
7050
|
+
"registerMockOverride(traceFunctionKey, override) requires a resolver function or { match, value } override."
|
|
7051
|
+
);
|
|
7052
|
+
}
|
|
7053
|
+
if (typeof keyedOverride === "function") {
|
|
7054
|
+
override = {
|
|
7055
|
+
match: (node) => node.traceFunctionKey === overrideOrResolverOrMatch,
|
|
7056
|
+
value: keyedOverride
|
|
7057
|
+
};
|
|
7058
|
+
} else if (typeof keyedOverride === "object" && keyedOverride !== null && "match" in keyedOverride && "value" in keyedOverride) {
|
|
7059
|
+
override = {
|
|
7060
|
+
match: (node) => node.traceFunctionKey === overrideOrResolverOrMatch && keyedOverride.match(node),
|
|
7061
|
+
value: keyedOverride.value
|
|
7062
|
+
};
|
|
7063
|
+
} else {
|
|
7064
|
+
throw new BitfabError(
|
|
7065
|
+
"registerMockOverride(traceFunctionKey, override) requires a resolver function or { match, value } override."
|
|
7066
|
+
);
|
|
7067
|
+
}
|
|
7068
|
+
} else if (typeof overrideOrResolverOrMatch !== "function") {
|
|
7069
|
+
override = overrideOrResolverOrMatch;
|
|
7070
|
+
} else if (values.length === 0) {
|
|
7071
|
+
override = { match: () => true, value: overrideOrResolverOrMatch };
|
|
7072
|
+
} else {
|
|
7073
|
+
override = {
|
|
7074
|
+
match: overrideOrResolverOrMatch,
|
|
7075
|
+
value: values[0]
|
|
7076
|
+
};
|
|
7077
|
+
}
|
|
6831
7078
|
this.mockOverrides.push(override);
|
|
6832
7079
|
}
|
|
6833
7080
|
/** Remove all overrides registered via {@link registerMockOverride}. */
|
|
@@ -7077,6 +7324,7 @@ var finalizers = {
|
|
|
7077
7324
|
|
|
7078
7325
|
// src/index.ts
|
|
7079
7326
|
init_http();
|
|
7327
|
+
init_mockOverride();
|
|
7080
7328
|
init_replay();
|
|
7081
7329
|
|
|
7082
7330
|
// src/replayRegistry.ts
|
|
@@ -7100,6 +7348,7 @@ function defineReplayRegistry(registry) {
|
|
|
7100
7348
|
DEFAULT_SERVICE_URL,
|
|
7101
7349
|
DbBranchReplayError,
|
|
7102
7350
|
HttpClient,
|
|
7351
|
+
NO_MOCK_OVERRIDE,
|
|
7103
7352
|
ReplayError,
|
|
7104
7353
|
SUPPORTED_PROVIDERS,
|
|
7105
7354
|
__version__,
|