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/node.cjs
CHANGED
|
@@ -97,7 +97,7 @@ var __version__, __packageName__;
|
|
|
97
97
|
var init_version_generated = __esm({
|
|
98
98
|
"src/version.generated.ts"() {
|
|
99
99
|
"use strict";
|
|
100
|
-
__version__ = "0.38.
|
|
100
|
+
__version__ = "0.38.5";
|
|
101
101
|
__packageName__ = "bitfab";
|
|
102
102
|
}
|
|
103
103
|
});
|
|
@@ -2203,11 +2203,16 @@ function normalizeMockOverrides(mockOverride) {
|
|
|
2203
2203
|
if (mockOverride === void 0) {
|
|
2204
2204
|
return [];
|
|
2205
2205
|
}
|
|
2206
|
-
|
|
2206
|
+
const overrides = Array.isArray(mockOverride) ? mockOverride : [mockOverride];
|
|
2207
|
+
return overrides.map(
|
|
2208
|
+
(override) => typeof override === "function" ? { match: () => true, value: override } : override
|
|
2209
|
+
);
|
|
2207
2210
|
}
|
|
2211
|
+
var NO_MOCK_OVERRIDE;
|
|
2208
2212
|
var init_mockOverride = __esm({
|
|
2209
2213
|
"src/mockOverride.ts"() {
|
|
2210
2214
|
"use strict";
|
|
2215
|
+
NO_MOCK_OVERRIDE = /* @__PURE__ */ Symbol("bitfab.noMockOverride");
|
|
2211
2216
|
}
|
|
2212
2217
|
});
|
|
2213
2218
|
|
|
@@ -3149,6 +3154,7 @@ __export(node_exports, {
|
|
|
3149
3154
|
DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
|
|
3150
3155
|
DbBranchReplayError: () => DbBranchReplayError,
|
|
3151
3156
|
HttpClient: () => HttpClient,
|
|
3157
|
+
NO_MOCK_OVERRIDE: () => NO_MOCK_OVERRIDE,
|
|
3152
3158
|
ReplayError: () => ReplayError,
|
|
3153
3159
|
SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
|
|
3154
3160
|
__version__: () => __version__,
|
|
@@ -3811,6 +3817,29 @@ function runWithAutoTraceContext(context, fn, depth = 0) {
|
|
|
3811
3817
|
autoTraceState.browserScope = previous;
|
|
3812
3818
|
}
|
|
3813
3819
|
}
|
|
3820
|
+
function runWithAutoTraceNodeConfiguration(nodeConfiguration, fn) {
|
|
3821
|
+
const scope = currentAutoTraceScope();
|
|
3822
|
+
if (!scope) {
|
|
3823
|
+
return fn();
|
|
3824
|
+
}
|
|
3825
|
+
const configuredScope = { ...scope, nodeConfiguration };
|
|
3826
|
+
let result;
|
|
3827
|
+
if (autoTraceState.storage) {
|
|
3828
|
+
result = autoTraceState.storage.run(configuredScope, fn);
|
|
3829
|
+
} else {
|
|
3830
|
+
const previous = autoTraceState.browserScope;
|
|
3831
|
+
autoTraceState.browserScope = configuredScope;
|
|
3832
|
+
try {
|
|
3833
|
+
result = fn();
|
|
3834
|
+
} finally {
|
|
3835
|
+
autoTraceState.browserScope = previous;
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3838
|
+
if (isAutoTraceAsyncGenerator(result)) {
|
|
3839
|
+
return wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, result);
|
|
3840
|
+
}
|
|
3841
|
+
return result;
|
|
3842
|
+
}
|
|
3814
3843
|
function runWithAutoTraceRootContext(context, fn) {
|
|
3815
3844
|
autoTraceState.activeRoots += 1;
|
|
3816
3845
|
let result;
|
|
@@ -3849,6 +3878,29 @@ function wrapAutoTraceAsyncGenerator(context, source) {
|
|
|
3849
3878
|
};
|
|
3850
3879
|
return wrapped;
|
|
3851
3880
|
}
|
|
3881
|
+
function wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, source) {
|
|
3882
|
+
const step = (method, value) => runWithAutoTraceNodeConfiguration(
|
|
3883
|
+
nodeConfiguration,
|
|
3884
|
+
() => source[method](value)
|
|
3885
|
+
);
|
|
3886
|
+
const wrapped = {
|
|
3887
|
+
next: (value) => step("next", value),
|
|
3888
|
+
return: (value) => step("return", value),
|
|
3889
|
+
throw: (error) => step("throw", error),
|
|
3890
|
+
[Symbol.asyncIterator]: () => wrapped
|
|
3891
|
+
};
|
|
3892
|
+
return wrapped;
|
|
3893
|
+
}
|
|
3894
|
+
function __bitfabAutoTraceActive() {
|
|
3895
|
+
if (autoTraceState.activeRoots === 0) {
|
|
3896
|
+
return false;
|
|
3897
|
+
}
|
|
3898
|
+
return currentAutoTraceScope() !== void 0;
|
|
3899
|
+
}
|
|
3900
|
+
function currentAutoTraceScope() {
|
|
3901
|
+
initializeAutoTraceStorage();
|
|
3902
|
+
return autoTraceState.storage?.getStore() ?? autoTraceState.browserScope;
|
|
3903
|
+
}
|
|
3852
3904
|
function __setBitfabAutoTraceCapturePolicy(client, traceFunctionKey, functionIds) {
|
|
3853
3905
|
const policies = autoTraceState.capturePolicies.get(client) ?? /* @__PURE__ */ new Map();
|
|
3854
3906
|
policies.set(traceFunctionKey, new Set(functionIds));
|
|
@@ -5701,6 +5753,102 @@ var Bitfab = class {
|
|
|
5701
5753
|
const name = fn.name !== "" ? fn.name : traceFunctionKey;
|
|
5702
5754
|
return this.createAutoTraceRoot(traceFunctionKey, name, options, fn);
|
|
5703
5755
|
}
|
|
5756
|
+
/**
|
|
5757
|
+
* Configure a transformed class method when it is discovered beneath a
|
|
5758
|
+
* {@link Bitfab.trace} root.
|
|
5759
|
+
*
|
|
5760
|
+
* The decorator creates no span or trace by itself. Beneath an active trace,
|
|
5761
|
+
* it can rename or retype the discovered call, capture its contents, mark it
|
|
5762
|
+
* for recorded-output replay, finalize its output, or omit it while leaving
|
|
5763
|
+
* captured descendants attached to the nearest captured parent.
|
|
5764
|
+
*
|
|
5765
|
+
* @param options - Trace-owned call configuration.
|
|
5766
|
+
* @experimental Automatic child-call instrumentation is experimental.
|
|
5767
|
+
*/
|
|
5768
|
+
node(options = {}) {
|
|
5769
|
+
const configuration = this.resolveNodeConfiguration(options);
|
|
5770
|
+
const decorator = (...args) => {
|
|
5771
|
+
if (args.length === 3) {
|
|
5772
|
+
const descriptor = args[2];
|
|
5773
|
+
if (!descriptor || typeof descriptor.value !== "function") {
|
|
5774
|
+
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
5775
|
+
}
|
|
5776
|
+
if (!this.explicitlyEnabled) {
|
|
5777
|
+
return;
|
|
5778
|
+
}
|
|
5779
|
+
descriptor.value = this.createAutoTraceNode(
|
|
5780
|
+
configuration,
|
|
5781
|
+
descriptor.value,
|
|
5782
|
+
String(args[1])
|
|
5783
|
+
);
|
|
5784
|
+
return;
|
|
5785
|
+
}
|
|
5786
|
+
const method = args[0];
|
|
5787
|
+
const context = args[1];
|
|
5788
|
+
if (typeof method !== "function" || context?.kind !== "method") {
|
|
5789
|
+
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
5790
|
+
}
|
|
5791
|
+
if (!this.explicitlyEnabled) {
|
|
5792
|
+
return method;
|
|
5793
|
+
}
|
|
5794
|
+
return this.createAutoTraceNode(
|
|
5795
|
+
configuration,
|
|
5796
|
+
method,
|
|
5797
|
+
String(context.name)
|
|
5798
|
+
);
|
|
5799
|
+
};
|
|
5800
|
+
return decorator;
|
|
5801
|
+
}
|
|
5802
|
+
withNode(optionsOrFn, maybeFn, internalFunctionName) {
|
|
5803
|
+
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
5804
|
+
const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
|
|
5805
|
+
if (!fn) {
|
|
5806
|
+
throw new BitfabError("bitfab.withNode requires a function");
|
|
5807
|
+
}
|
|
5808
|
+
const configuration = this.resolveNodeConfiguration(options);
|
|
5809
|
+
if (!this.explicitlyEnabled) {
|
|
5810
|
+
return fn;
|
|
5811
|
+
}
|
|
5812
|
+
const functionName = internalFunctionName ?? fn.name;
|
|
5813
|
+
if (functionName === "") {
|
|
5814
|
+
throw new BitfabError(
|
|
5815
|
+
"bitfab.withNode requires a named function so the subtree transform can bind its configuration to the correct call."
|
|
5816
|
+
);
|
|
5817
|
+
}
|
|
5818
|
+
return this.createAutoTraceNode(configuration, fn, functionName);
|
|
5819
|
+
}
|
|
5820
|
+
resolveNodeConfiguration(options) {
|
|
5821
|
+
const capture = options.capture ?? true;
|
|
5822
|
+
if (!capture && options.mockOnReplay === true) {
|
|
5823
|
+
throw new BitfabError(
|
|
5824
|
+
"bitfab.node({ capture: false }) cannot use mockOnReplay: true because an uncaptured node has no recorded output."
|
|
5825
|
+
);
|
|
5826
|
+
}
|
|
5827
|
+
return {
|
|
5828
|
+
capture,
|
|
5829
|
+
type: options.type ?? "custom",
|
|
5830
|
+
...options.name !== void 0 && { name: options.name },
|
|
5831
|
+
...options.testRunId !== void 0 && {
|
|
5832
|
+
testRunId: options.testRunId
|
|
5833
|
+
},
|
|
5834
|
+
...options.mockOnReplay !== void 0 && {
|
|
5835
|
+
mockOnReplay: options.mockOnReplay
|
|
5836
|
+
},
|
|
5837
|
+
...options.finalize !== void 0 && { finalize: options.finalize }
|
|
5838
|
+
};
|
|
5839
|
+
}
|
|
5840
|
+
createAutoTraceNode(configuration, fn, functionName) {
|
|
5841
|
+
const nodeConfiguration = { ...configuration, functionName };
|
|
5842
|
+
return function(...args) {
|
|
5843
|
+
if (!__bitfabAutoTraceActive()) {
|
|
5844
|
+
return fn.apply(this, args);
|
|
5845
|
+
}
|
|
5846
|
+
return runWithAutoTraceNodeConfiguration(
|
|
5847
|
+
nodeConfiguration,
|
|
5848
|
+
() => fn.apply(this, args)
|
|
5849
|
+
);
|
|
5850
|
+
};
|
|
5851
|
+
}
|
|
5704
5852
|
createAutoTraceRoot(traceFunctionKey, name, options, fn) {
|
|
5705
5853
|
const self = this;
|
|
5706
5854
|
const maxDepth = autoTraceLimit(
|
|
@@ -5739,29 +5887,51 @@ var Bitfab = class {
|
|
|
5739
5887
|
);
|
|
5740
5888
|
};
|
|
5741
5889
|
const autoTraceContext = {
|
|
5742
|
-
invoke(definition, inputs, invokeFn, depth) {
|
|
5890
|
+
invoke(definition, inputs, invokeFn, depth, nodeConfiguration) {
|
|
5743
5891
|
const nameParts = definition.name.split(".");
|
|
5744
5892
|
const simpleName = nameParts[nameParts.length - 1];
|
|
5745
|
-
|
|
5746
|
-
|
|
5893
|
+
const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
|
|
5894
|
+
if (excluded.has(definition.name) || simpleName !== void 0 && excluded.has(simpleName) || nodeConfiguration === void 0 && definition.wrapper === true && !includeWrappers) {
|
|
5895
|
+
return invokeWithoutNode();
|
|
5896
|
+
}
|
|
5897
|
+
if (nodeConfiguration?.capture === false) {
|
|
5898
|
+
return runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
|
|
5747
5899
|
}
|
|
5748
5900
|
if (depth >= maxDepth || spansUsed >= maxSpans) {
|
|
5749
5901
|
warnTruncated();
|
|
5750
|
-
return
|
|
5902
|
+
return invokeWithoutNode();
|
|
5751
5903
|
}
|
|
5752
5904
|
spansUsed += 1;
|
|
5753
5905
|
const childOptions = {
|
|
5754
|
-
name: definition.name,
|
|
5755
|
-
type: "function",
|
|
5906
|
+
name: nodeConfiguration?.name ?? definition.name,
|
|
5907
|
+
type: nodeConfiguration?.type ?? "function",
|
|
5756
5908
|
captureWhen: "nested",
|
|
5757
5909
|
functionId: definition.id,
|
|
5758
|
-
captureContent: capturePolicy.has(definition.id),
|
|
5759
|
-
autoTraceDefinition: definition
|
|
5910
|
+
captureContent: nodeConfiguration !== void 0 || capturePolicy.has(definition.id),
|
|
5911
|
+
autoTraceDefinition: definition,
|
|
5912
|
+
...nodeConfiguration?.testRunId !== void 0 && {
|
|
5913
|
+
testRunId: nodeConfiguration.testRunId
|
|
5914
|
+
},
|
|
5915
|
+
...nodeConfiguration?.mockOnReplay !== void 0 && {
|
|
5916
|
+
mockOnReplay: nodeConfiguration.mockOnReplay
|
|
5917
|
+
},
|
|
5918
|
+
...nodeConfiguration?.finalize !== void 0 && {
|
|
5919
|
+
finalize: nodeConfiguration.finalize
|
|
5920
|
+
}
|
|
5760
5921
|
};
|
|
5922
|
+
const invokeWithAutoTraceContext = () => runWithAutoTraceContext(autoTraceContext, invokeFn, depth + 1);
|
|
5923
|
+
if (definition.async === true) {
|
|
5924
|
+
const tracedAsyncChild = self.withSpan(
|
|
5925
|
+
traceFunctionKey,
|
|
5926
|
+
childOptions,
|
|
5927
|
+
async (..._inputs) => await invokeWithAutoTraceContext()
|
|
5928
|
+
);
|
|
5929
|
+
return tracedAsyncChild(...inputs);
|
|
5930
|
+
}
|
|
5761
5931
|
const tracedChild = self.withSpan(
|
|
5762
5932
|
traceFunctionKey,
|
|
5763
5933
|
childOptions,
|
|
5764
|
-
(..._inputs) =>
|
|
5934
|
+
(..._inputs) => invokeWithAutoTraceContext()
|
|
5765
5935
|
);
|
|
5766
5936
|
return tracedChild(...inputs);
|
|
5767
5937
|
}
|
|
@@ -6331,18 +6501,17 @@ var Bitfab = class {
|
|
|
6331
6501
|
newStack = [...currentStack, newContext];
|
|
6332
6502
|
const inputs = args;
|
|
6333
6503
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6504
|
+
const replayCtxAtStart = getReplayContext();
|
|
6505
|
+
const testRunId = replayCtxAtStart?.testRunId ?? options.testRunId;
|
|
6334
6506
|
if (isRootSpan && !activeTraceStates.has(traceId)) {
|
|
6335
|
-
const replayCtxAtRoot = getReplayContext();
|
|
6336
6507
|
const dbSnapshotRef = buildSnapshotRef(self.dbSnapshot, startedAt);
|
|
6337
6508
|
activeTraceStates.set(traceId, {
|
|
6338
6509
|
traceId,
|
|
6339
6510
|
startedAt,
|
|
6340
6511
|
contexts: [],
|
|
6341
|
-
...
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
...replayCtxAtRoot?.inputSourceTraceId && {
|
|
6345
|
-
inputSourceTraceId: replayCtxAtRoot.inputSourceTraceId
|
|
6512
|
+
...testRunId !== void 0 && { testRunId },
|
|
6513
|
+
...replayCtxAtStart?.inputSourceTraceId && {
|
|
6514
|
+
inputSourceTraceId: replayCtxAtStart.inputSourceTraceId
|
|
6346
6515
|
},
|
|
6347
6516
|
dbSnapshotRef
|
|
6348
6517
|
});
|
|
@@ -6375,9 +6544,7 @@ var Bitfab = class {
|
|
|
6375
6544
|
contexts: newContext.contexts,
|
|
6376
6545
|
prompt: newContext.prompt,
|
|
6377
6546
|
endedAt,
|
|
6378
|
-
...
|
|
6379
|
-
testRunId: replayCtx.testRunId
|
|
6380
|
-
},
|
|
6547
|
+
...testRunId !== void 0 && { testRunId },
|
|
6381
6548
|
...replayCtx?.inputSourceSpanId && {
|
|
6382
6549
|
inputSourceSpanId: replayCtx.inputSourceSpanId
|
|
6383
6550
|
}
|
|
@@ -6417,6 +6584,49 @@ var Bitfab = class {
|
|
|
6417
6584
|
} catch {
|
|
6418
6585
|
}
|
|
6419
6586
|
};
|
|
6587
|
+
const recordSpan = (result) => {
|
|
6588
|
+
if (options.finalize) {
|
|
6589
|
+
void self.httpClient.trackDeferred(
|
|
6590
|
+
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
6591
|
+
(error) => sendSpan({
|
|
6592
|
+
result: void 0,
|
|
6593
|
+
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
6594
|
+
})
|
|
6595
|
+
)
|
|
6596
|
+
);
|
|
6597
|
+
} else {
|
|
6598
|
+
void sendSpan({ result });
|
|
6599
|
+
}
|
|
6600
|
+
};
|
|
6601
|
+
executeWithContext = () => {
|
|
6602
|
+
let result;
|
|
6603
|
+
try {
|
|
6604
|
+
result = fn.apply(this, args);
|
|
6605
|
+
} catch (error) {
|
|
6606
|
+
void sendSpan({
|
|
6607
|
+
result: void 0,
|
|
6608
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6609
|
+
});
|
|
6610
|
+
throw error;
|
|
6611
|
+
}
|
|
6612
|
+
if (result instanceof Promise) {
|
|
6613
|
+
return result.then((resolvedResult) => {
|
|
6614
|
+
recordSpan(resolvedResult);
|
|
6615
|
+
return resolvedResult;
|
|
6616
|
+
}).catch((error) => {
|
|
6617
|
+
void sendSpan({
|
|
6618
|
+
result: void 0,
|
|
6619
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6620
|
+
});
|
|
6621
|
+
throw error;
|
|
6622
|
+
});
|
|
6623
|
+
}
|
|
6624
|
+
if (isAsyncGenerator(result)) {
|
|
6625
|
+
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
6626
|
+
}
|
|
6627
|
+
recordSpan(result);
|
|
6628
|
+
return result;
|
|
6629
|
+
};
|
|
6420
6630
|
const replayCtxForMock = getReplayContext();
|
|
6421
6631
|
if (replayCtxForMock?.mockTree && !isRootSpan) {
|
|
6422
6632
|
const counters = replayCtxForMock.callCounters;
|
|
@@ -6475,6 +6685,7 @@ var Bitfab = class {
|
|
|
6475
6685
|
}
|
|
6476
6686
|
return output;
|
|
6477
6687
|
};
|
|
6688
|
+
const shouldMockWithBaseStrategy = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
|
|
6478
6689
|
if (replayCtxForMock.mockOverrides?.length) {
|
|
6479
6690
|
const nodeMeta = {
|
|
6480
6691
|
traceFunctionKey,
|
|
@@ -6482,28 +6693,75 @@ var Bitfab = class {
|
|
|
6482
6693
|
type: options.type ?? "custom",
|
|
6483
6694
|
originalSpanId: mockSpan?.sourceSpanId
|
|
6484
6695
|
};
|
|
6485
|
-
const
|
|
6486
|
-
|
|
6487
|
-
|
|
6488
|
-
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
|
|
6495
|
-
|
|
6696
|
+
const overrideCtx = {
|
|
6697
|
+
node: nodeMeta,
|
|
6698
|
+
inputs: args,
|
|
6699
|
+
getOriginalOutput: () => Promise.resolve(resolveRecordedOutput())
|
|
6700
|
+
};
|
|
6701
|
+
const resolveOverrideFrom = (startIndex) => {
|
|
6702
|
+
for (let index = startIndex; index < replayCtxForMock.mockOverrides.length; index += 1) {
|
|
6703
|
+
const override = replayCtxForMock.mockOverrides[index];
|
|
6704
|
+
if (!override?.match(nodeMeta)) {
|
|
6705
|
+
continue;
|
|
6706
|
+
}
|
|
6707
|
+
const injected = resolveMockValue(override.value, overrideCtx);
|
|
6708
|
+
if (injected instanceof Promise) {
|
|
6709
|
+
return injected.then(
|
|
6710
|
+
(output) => output === NO_MOCK_OVERRIDE ? resolveOverrideFrom(index + 1) : { matched: true, output }
|
|
6711
|
+
);
|
|
6712
|
+
}
|
|
6713
|
+
if (injected !== NO_MOCK_OVERRIDE) {
|
|
6714
|
+
return { matched: true, output: injected };
|
|
6715
|
+
}
|
|
6716
|
+
}
|
|
6717
|
+
return { matched: false };
|
|
6718
|
+
};
|
|
6719
|
+
const resolution = resolveOverrideFrom(0);
|
|
6720
|
+
if (resolution instanceof Promise) {
|
|
6721
|
+
if (!fnReturnsPromise) {
|
|
6722
|
+
throw new BitfabError(
|
|
6723
|
+
`Cannot resolve an asynchronous mock override for synchronous span "${traceFunctionKey}". Make the wrapped function async or return NO_MOCK_OVERRIDE synchronously.`
|
|
6724
|
+
);
|
|
6496
6725
|
}
|
|
6497
|
-
return
|
|
6726
|
+
return runWithSpanStack(newStack, async () => {
|
|
6727
|
+
const resolved = await resolution;
|
|
6728
|
+
if (resolved.matched) {
|
|
6729
|
+
void sendSpan({
|
|
6730
|
+
result: resolved.output,
|
|
6731
|
+
mocked: true,
|
|
6732
|
+
mockTarget: "output",
|
|
6733
|
+
mockSource: "override"
|
|
6734
|
+
});
|
|
6735
|
+
return resolved.output;
|
|
6736
|
+
}
|
|
6737
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
6738
|
+
throw new BitfabError(
|
|
6739
|
+
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
6740
|
+
);
|
|
6741
|
+
}
|
|
6742
|
+
if (shouldMockWithBaseStrategy) {
|
|
6743
|
+
const output = await resolveRecordedOutput();
|
|
6744
|
+
void sendSpan({
|
|
6745
|
+
result: output,
|
|
6746
|
+
mocked: true,
|
|
6747
|
+
mockTarget: "output",
|
|
6748
|
+
mockSource: "recorded"
|
|
6749
|
+
});
|
|
6750
|
+
return output;
|
|
6751
|
+
}
|
|
6752
|
+
return executeWithContext();
|
|
6753
|
+
});
|
|
6754
|
+
}
|
|
6755
|
+
if (resolution.matched) {
|
|
6756
|
+
return emitMock(resolution.output, "override");
|
|
6498
6757
|
}
|
|
6499
6758
|
}
|
|
6500
|
-
|
|
6501
|
-
if (shouldMock && !mockSpan) {
|
|
6759
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
6502
6760
|
throw new BitfabError(
|
|
6503
6761
|
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
6504
6762
|
);
|
|
6505
6763
|
}
|
|
6506
|
-
if (
|
|
6764
|
+
if (shouldMockWithBaseStrategy) {
|
|
6507
6765
|
const recorded = resolveRecordedOutput();
|
|
6508
6766
|
if (recorded instanceof Promise) {
|
|
6509
6767
|
return emitMockAsync(recorded, "recorded");
|
|
@@ -6511,49 +6769,6 @@ var Bitfab = class {
|
|
|
6511
6769
|
return emitMock(recorded, "recorded");
|
|
6512
6770
|
}
|
|
6513
6771
|
}
|
|
6514
|
-
const recordSpan = (result) => {
|
|
6515
|
-
if (options.finalize) {
|
|
6516
|
-
void self.httpClient.trackDeferred(
|
|
6517
|
-
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
6518
|
-
(error) => sendSpan({
|
|
6519
|
-
result: void 0,
|
|
6520
|
-
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
6521
|
-
})
|
|
6522
|
-
)
|
|
6523
|
-
);
|
|
6524
|
-
} else {
|
|
6525
|
-
void sendSpan({ result });
|
|
6526
|
-
}
|
|
6527
|
-
};
|
|
6528
|
-
executeWithContext = () => {
|
|
6529
|
-
let result;
|
|
6530
|
-
try {
|
|
6531
|
-
result = fn.apply(this, args);
|
|
6532
|
-
} catch (error) {
|
|
6533
|
-
void sendSpan({
|
|
6534
|
-
result: void 0,
|
|
6535
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6536
|
-
});
|
|
6537
|
-
throw error;
|
|
6538
|
-
}
|
|
6539
|
-
if (result instanceof Promise) {
|
|
6540
|
-
return result.then((resolvedResult) => {
|
|
6541
|
-
recordSpan(resolvedResult);
|
|
6542
|
-
return resolvedResult;
|
|
6543
|
-
}).catch((error) => {
|
|
6544
|
-
void sendSpan({
|
|
6545
|
-
result: void 0,
|
|
6546
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6547
|
-
});
|
|
6548
|
-
throw error;
|
|
6549
|
-
});
|
|
6550
|
-
}
|
|
6551
|
-
if (isAsyncGenerator(result)) {
|
|
6552
|
-
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
6553
|
-
}
|
|
6554
|
-
recordSpan(result);
|
|
6555
|
-
return result;
|
|
6556
|
-
};
|
|
6557
6772
|
} catch (setupError) {
|
|
6558
6773
|
if (registeredTraceId) {
|
|
6559
6774
|
activeTraceStates.delete(registeredTraceId);
|
|
@@ -6840,8 +7055,40 @@ var Bitfab = class {
|
|
|
6840
7055
|
...params.mockSource && { mockSource: params.mockSource }
|
|
6841
7056
|
});
|
|
6842
7057
|
}
|
|
6843
|
-
registerMockOverride(
|
|
6844
|
-
|
|
7058
|
+
registerMockOverride(overrideOrResolverOrMatch, ...values) {
|
|
7059
|
+
let override;
|
|
7060
|
+
if (typeof overrideOrResolverOrMatch === "string") {
|
|
7061
|
+
const keyedOverride = values[0];
|
|
7062
|
+
if (values.length !== 1 || keyedOverride === void 0) {
|
|
7063
|
+
throw new BitfabError(
|
|
7064
|
+
"registerMockOverride(traceFunctionKey, override) requires a resolver function or { match, value } override."
|
|
7065
|
+
);
|
|
7066
|
+
}
|
|
7067
|
+
if (typeof keyedOverride === "function") {
|
|
7068
|
+
override = {
|
|
7069
|
+
match: (node) => node.traceFunctionKey === overrideOrResolverOrMatch,
|
|
7070
|
+
value: keyedOverride
|
|
7071
|
+
};
|
|
7072
|
+
} else if (typeof keyedOverride === "object" && keyedOverride !== null && "match" in keyedOverride && "value" in keyedOverride) {
|
|
7073
|
+
override = {
|
|
7074
|
+
match: (node) => node.traceFunctionKey === overrideOrResolverOrMatch && keyedOverride.match(node),
|
|
7075
|
+
value: keyedOverride.value
|
|
7076
|
+
};
|
|
7077
|
+
} else {
|
|
7078
|
+
throw new BitfabError(
|
|
7079
|
+
"registerMockOverride(traceFunctionKey, override) requires a resolver function or { match, value } override."
|
|
7080
|
+
);
|
|
7081
|
+
}
|
|
7082
|
+
} else if (typeof overrideOrResolverOrMatch !== "function") {
|
|
7083
|
+
override = overrideOrResolverOrMatch;
|
|
7084
|
+
} else if (values.length === 0) {
|
|
7085
|
+
override = { match: () => true, value: overrideOrResolverOrMatch };
|
|
7086
|
+
} else {
|
|
7087
|
+
override = {
|
|
7088
|
+
match: overrideOrResolverOrMatch,
|
|
7089
|
+
value: values[0]
|
|
7090
|
+
};
|
|
7091
|
+
}
|
|
6845
7092
|
this.mockOverrides.push(override);
|
|
6846
7093
|
}
|
|
6847
7094
|
/** Remove all overrides registered via {@link registerMockOverride}. */
|
|
@@ -7091,6 +7338,7 @@ var finalizers = {
|
|
|
7091
7338
|
|
|
7092
7339
|
// src/index.ts
|
|
7093
7340
|
init_http();
|
|
7341
|
+
init_mockOverride();
|
|
7094
7342
|
init_replay();
|
|
7095
7343
|
|
|
7096
7344
|
// src/replayRegistry.ts
|
|
@@ -7118,6 +7366,7 @@ assertAsyncStorageRegistered();
|
|
|
7118
7366
|
DEFAULT_SERVICE_URL,
|
|
7119
7367
|
DbBranchReplayError,
|
|
7120
7368
|
HttpClient,
|
|
7369
|
+
NO_MOCK_OVERRIDE,
|
|
7121
7370
|
ReplayError,
|
|
7122
7371
|
SUPPORTED_PROVIDERS,
|
|
7123
7372
|
__version__,
|