@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/node.cjs
CHANGED
|
@@ -88,7 +88,7 @@ var __version__, __packageName__;
|
|
|
88
88
|
var init_version_generated = __esm({
|
|
89
89
|
"src/version.generated.ts"() {
|
|
90
90
|
"use strict";
|
|
91
|
-
__version__ = "0.38.
|
|
91
|
+
__version__ = "0.38.5";
|
|
92
92
|
__packageName__ = "@bitfab/sdk";
|
|
93
93
|
}
|
|
94
94
|
});
|
|
@@ -2194,11 +2194,16 @@ function normalizeMockOverrides(mockOverride) {
|
|
|
2194
2194
|
if (mockOverride === void 0) {
|
|
2195
2195
|
return [];
|
|
2196
2196
|
}
|
|
2197
|
-
|
|
2197
|
+
const overrides = Array.isArray(mockOverride) ? mockOverride : [mockOverride];
|
|
2198
|
+
return overrides.map(
|
|
2199
|
+
(override) => typeof override === "function" ? { match: () => true, value: override } : override
|
|
2200
|
+
);
|
|
2198
2201
|
}
|
|
2202
|
+
var NO_MOCK_OVERRIDE;
|
|
2199
2203
|
var init_mockOverride = __esm({
|
|
2200
2204
|
"src/mockOverride.ts"() {
|
|
2201
2205
|
"use strict";
|
|
2206
|
+
NO_MOCK_OVERRIDE = /* @__PURE__ */ Symbol("bitfab.noMockOverride");
|
|
2202
2207
|
}
|
|
2203
2208
|
});
|
|
2204
2209
|
|
|
@@ -3140,6 +3145,7 @@ __export(node_exports, {
|
|
|
3140
3145
|
DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
|
|
3141
3146
|
DbBranchReplayError: () => DbBranchReplayError,
|
|
3142
3147
|
HttpClient: () => HttpClient,
|
|
3148
|
+
NO_MOCK_OVERRIDE: () => NO_MOCK_OVERRIDE,
|
|
3143
3149
|
ReplayError: () => ReplayError,
|
|
3144
3150
|
SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
|
|
3145
3151
|
__version__: () => __version__,
|
|
@@ -3802,6 +3808,29 @@ function runWithAutoTraceContext(context, fn, depth = 0) {
|
|
|
3802
3808
|
autoTraceState.browserScope = previous;
|
|
3803
3809
|
}
|
|
3804
3810
|
}
|
|
3811
|
+
function runWithAutoTraceNodeConfiguration(nodeConfiguration, fn) {
|
|
3812
|
+
const scope = currentAutoTraceScope();
|
|
3813
|
+
if (!scope) {
|
|
3814
|
+
return fn();
|
|
3815
|
+
}
|
|
3816
|
+
const configuredScope = { ...scope, nodeConfiguration };
|
|
3817
|
+
let result;
|
|
3818
|
+
if (autoTraceState.storage) {
|
|
3819
|
+
result = autoTraceState.storage.run(configuredScope, fn);
|
|
3820
|
+
} else {
|
|
3821
|
+
const previous = autoTraceState.browserScope;
|
|
3822
|
+
autoTraceState.browserScope = configuredScope;
|
|
3823
|
+
try {
|
|
3824
|
+
result = fn();
|
|
3825
|
+
} finally {
|
|
3826
|
+
autoTraceState.browserScope = previous;
|
|
3827
|
+
}
|
|
3828
|
+
}
|
|
3829
|
+
if (isAutoTraceAsyncGenerator(result)) {
|
|
3830
|
+
return wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, result);
|
|
3831
|
+
}
|
|
3832
|
+
return result;
|
|
3833
|
+
}
|
|
3805
3834
|
function runWithAutoTraceRootContext(context, fn) {
|
|
3806
3835
|
autoTraceState.activeRoots += 1;
|
|
3807
3836
|
let result;
|
|
@@ -3840,6 +3869,29 @@ function wrapAutoTraceAsyncGenerator(context, source) {
|
|
|
3840
3869
|
};
|
|
3841
3870
|
return wrapped;
|
|
3842
3871
|
}
|
|
3872
|
+
function wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, source) {
|
|
3873
|
+
const step = (method, value) => runWithAutoTraceNodeConfiguration(
|
|
3874
|
+
nodeConfiguration,
|
|
3875
|
+
() => source[method](value)
|
|
3876
|
+
);
|
|
3877
|
+
const wrapped = {
|
|
3878
|
+
next: (value) => step("next", value),
|
|
3879
|
+
return: (value) => step("return", value),
|
|
3880
|
+
throw: (error) => step("throw", error),
|
|
3881
|
+
[Symbol.asyncIterator]: () => wrapped
|
|
3882
|
+
};
|
|
3883
|
+
return wrapped;
|
|
3884
|
+
}
|
|
3885
|
+
function __bitfabAutoTraceActive() {
|
|
3886
|
+
if (autoTraceState.activeRoots === 0) {
|
|
3887
|
+
return false;
|
|
3888
|
+
}
|
|
3889
|
+
return currentAutoTraceScope() !== void 0;
|
|
3890
|
+
}
|
|
3891
|
+
function currentAutoTraceScope() {
|
|
3892
|
+
initializeAutoTraceStorage();
|
|
3893
|
+
return autoTraceState.storage?.getStore() ?? autoTraceState.browserScope;
|
|
3894
|
+
}
|
|
3843
3895
|
function __setBitfabAutoTraceCapturePolicy(client, traceFunctionKey, functionIds) {
|
|
3844
3896
|
const policies = autoTraceState.capturePolicies.get(client) ?? /* @__PURE__ */ new Map();
|
|
3845
3897
|
policies.set(traceFunctionKey, new Set(functionIds));
|
|
@@ -5692,6 +5744,102 @@ var Bitfab = class {
|
|
|
5692
5744
|
const name = fn.name !== "" ? fn.name : traceFunctionKey;
|
|
5693
5745
|
return this.createAutoTraceRoot(traceFunctionKey, name, options, fn);
|
|
5694
5746
|
}
|
|
5747
|
+
/**
|
|
5748
|
+
* Configure a transformed class method when it is discovered beneath a
|
|
5749
|
+
* {@link Bitfab.trace} root.
|
|
5750
|
+
*
|
|
5751
|
+
* The decorator creates no span or trace by itself. Beneath an active trace,
|
|
5752
|
+
* it can rename or retype the discovered call, capture its contents, mark it
|
|
5753
|
+
* for recorded-output replay, finalize its output, or omit it while leaving
|
|
5754
|
+
* captured descendants attached to the nearest captured parent.
|
|
5755
|
+
*
|
|
5756
|
+
* @param options - Trace-owned call configuration.
|
|
5757
|
+
* @experimental Automatic child-call instrumentation is experimental.
|
|
5758
|
+
*/
|
|
5759
|
+
node(options = {}) {
|
|
5760
|
+
const configuration = this.resolveNodeConfiguration(options);
|
|
5761
|
+
const decorator = (...args) => {
|
|
5762
|
+
if (args.length === 3) {
|
|
5763
|
+
const descriptor = args[2];
|
|
5764
|
+
if (!descriptor || typeof descriptor.value !== "function") {
|
|
5765
|
+
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
5766
|
+
}
|
|
5767
|
+
if (!this.explicitlyEnabled) {
|
|
5768
|
+
return;
|
|
5769
|
+
}
|
|
5770
|
+
descriptor.value = this.createAutoTraceNode(
|
|
5771
|
+
configuration,
|
|
5772
|
+
descriptor.value,
|
|
5773
|
+
String(args[1])
|
|
5774
|
+
);
|
|
5775
|
+
return;
|
|
5776
|
+
}
|
|
5777
|
+
const method = args[0];
|
|
5778
|
+
const context = args[1];
|
|
5779
|
+
if (typeof method !== "function" || context?.kind !== "method") {
|
|
5780
|
+
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
5781
|
+
}
|
|
5782
|
+
if (!this.explicitlyEnabled) {
|
|
5783
|
+
return method;
|
|
5784
|
+
}
|
|
5785
|
+
return this.createAutoTraceNode(
|
|
5786
|
+
configuration,
|
|
5787
|
+
method,
|
|
5788
|
+
String(context.name)
|
|
5789
|
+
);
|
|
5790
|
+
};
|
|
5791
|
+
return decorator;
|
|
5792
|
+
}
|
|
5793
|
+
withNode(optionsOrFn, maybeFn, internalFunctionName) {
|
|
5794
|
+
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
5795
|
+
const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
|
|
5796
|
+
if (!fn) {
|
|
5797
|
+
throw new BitfabError("bitfab.withNode requires a function");
|
|
5798
|
+
}
|
|
5799
|
+
const configuration = this.resolveNodeConfiguration(options);
|
|
5800
|
+
if (!this.explicitlyEnabled) {
|
|
5801
|
+
return fn;
|
|
5802
|
+
}
|
|
5803
|
+
const functionName = internalFunctionName ?? fn.name;
|
|
5804
|
+
if (functionName === "") {
|
|
5805
|
+
throw new BitfabError(
|
|
5806
|
+
"bitfab.withNode requires a named function so the subtree transform can bind its configuration to the correct call."
|
|
5807
|
+
);
|
|
5808
|
+
}
|
|
5809
|
+
return this.createAutoTraceNode(configuration, fn, functionName);
|
|
5810
|
+
}
|
|
5811
|
+
resolveNodeConfiguration(options) {
|
|
5812
|
+
const capture = options.capture ?? true;
|
|
5813
|
+
if (!capture && options.mockOnReplay === true) {
|
|
5814
|
+
throw new BitfabError(
|
|
5815
|
+
"bitfab.node({ capture: false }) cannot use mockOnReplay: true because an uncaptured node has no recorded output."
|
|
5816
|
+
);
|
|
5817
|
+
}
|
|
5818
|
+
return {
|
|
5819
|
+
capture,
|
|
5820
|
+
type: options.type ?? "custom",
|
|
5821
|
+
...options.name !== void 0 && { name: options.name },
|
|
5822
|
+
...options.testRunId !== void 0 && {
|
|
5823
|
+
testRunId: options.testRunId
|
|
5824
|
+
},
|
|
5825
|
+
...options.mockOnReplay !== void 0 && {
|
|
5826
|
+
mockOnReplay: options.mockOnReplay
|
|
5827
|
+
},
|
|
5828
|
+
...options.finalize !== void 0 && { finalize: options.finalize }
|
|
5829
|
+
};
|
|
5830
|
+
}
|
|
5831
|
+
createAutoTraceNode(configuration, fn, functionName) {
|
|
5832
|
+
const nodeConfiguration = { ...configuration, functionName };
|
|
5833
|
+
return function(...args) {
|
|
5834
|
+
if (!__bitfabAutoTraceActive()) {
|
|
5835
|
+
return fn.apply(this, args);
|
|
5836
|
+
}
|
|
5837
|
+
return runWithAutoTraceNodeConfiguration(
|
|
5838
|
+
nodeConfiguration,
|
|
5839
|
+
() => fn.apply(this, args)
|
|
5840
|
+
);
|
|
5841
|
+
};
|
|
5842
|
+
}
|
|
5695
5843
|
createAutoTraceRoot(traceFunctionKey, name, options, fn) {
|
|
5696
5844
|
const self = this;
|
|
5697
5845
|
const maxDepth = autoTraceLimit(
|
|
@@ -5730,29 +5878,51 @@ var Bitfab = class {
|
|
|
5730
5878
|
);
|
|
5731
5879
|
};
|
|
5732
5880
|
const autoTraceContext = {
|
|
5733
|
-
invoke(definition, inputs, invokeFn, depth) {
|
|
5881
|
+
invoke(definition, inputs, invokeFn, depth, nodeConfiguration) {
|
|
5734
5882
|
const nameParts = definition.name.split(".");
|
|
5735
5883
|
const simpleName = nameParts[nameParts.length - 1];
|
|
5736
|
-
|
|
5737
|
-
|
|
5884
|
+
const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
|
|
5885
|
+
if (excluded.has(definition.name) || simpleName !== void 0 && excluded.has(simpleName) || nodeConfiguration === void 0 && definition.wrapper === true && !includeWrappers) {
|
|
5886
|
+
return invokeWithoutNode();
|
|
5887
|
+
}
|
|
5888
|
+
if (nodeConfiguration?.capture === false) {
|
|
5889
|
+
return runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
|
|
5738
5890
|
}
|
|
5739
5891
|
if (depth >= maxDepth || spansUsed >= maxSpans) {
|
|
5740
5892
|
warnTruncated();
|
|
5741
|
-
return
|
|
5893
|
+
return invokeWithoutNode();
|
|
5742
5894
|
}
|
|
5743
5895
|
spansUsed += 1;
|
|
5744
5896
|
const childOptions = {
|
|
5745
|
-
name: definition.name,
|
|
5746
|
-
type: "function",
|
|
5897
|
+
name: nodeConfiguration?.name ?? definition.name,
|
|
5898
|
+
type: nodeConfiguration?.type ?? "function",
|
|
5747
5899
|
captureWhen: "nested",
|
|
5748
5900
|
functionId: definition.id,
|
|
5749
|
-
captureContent: capturePolicy.has(definition.id),
|
|
5750
|
-
autoTraceDefinition: definition
|
|
5901
|
+
captureContent: nodeConfiguration !== void 0 || capturePolicy.has(definition.id),
|
|
5902
|
+
autoTraceDefinition: definition,
|
|
5903
|
+
...nodeConfiguration?.testRunId !== void 0 && {
|
|
5904
|
+
testRunId: nodeConfiguration.testRunId
|
|
5905
|
+
},
|
|
5906
|
+
...nodeConfiguration?.mockOnReplay !== void 0 && {
|
|
5907
|
+
mockOnReplay: nodeConfiguration.mockOnReplay
|
|
5908
|
+
},
|
|
5909
|
+
...nodeConfiguration?.finalize !== void 0 && {
|
|
5910
|
+
finalize: nodeConfiguration.finalize
|
|
5911
|
+
}
|
|
5751
5912
|
};
|
|
5913
|
+
const invokeWithAutoTraceContext = () => runWithAutoTraceContext(autoTraceContext, invokeFn, depth + 1);
|
|
5914
|
+
if (definition.async === true) {
|
|
5915
|
+
const tracedAsyncChild = self.withSpan(
|
|
5916
|
+
traceFunctionKey,
|
|
5917
|
+
childOptions,
|
|
5918
|
+
async (..._inputs) => await invokeWithAutoTraceContext()
|
|
5919
|
+
);
|
|
5920
|
+
return tracedAsyncChild(...inputs);
|
|
5921
|
+
}
|
|
5752
5922
|
const tracedChild = self.withSpan(
|
|
5753
5923
|
traceFunctionKey,
|
|
5754
5924
|
childOptions,
|
|
5755
|
-
(..._inputs) =>
|
|
5925
|
+
(..._inputs) => invokeWithAutoTraceContext()
|
|
5756
5926
|
);
|
|
5757
5927
|
return tracedChild(...inputs);
|
|
5758
5928
|
}
|
|
@@ -6322,18 +6492,17 @@ var Bitfab = class {
|
|
|
6322
6492
|
newStack = [...currentStack, newContext];
|
|
6323
6493
|
const inputs = args;
|
|
6324
6494
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6495
|
+
const replayCtxAtStart = getReplayContext();
|
|
6496
|
+
const testRunId = replayCtxAtStart?.testRunId ?? options.testRunId;
|
|
6325
6497
|
if (isRootSpan && !activeTraceStates.has(traceId)) {
|
|
6326
|
-
const replayCtxAtRoot = getReplayContext();
|
|
6327
6498
|
const dbSnapshotRef = buildSnapshotRef(self.dbSnapshot, startedAt);
|
|
6328
6499
|
activeTraceStates.set(traceId, {
|
|
6329
6500
|
traceId,
|
|
6330
6501
|
startedAt,
|
|
6331
6502
|
contexts: [],
|
|
6332
|
-
...
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
...replayCtxAtRoot?.inputSourceTraceId && {
|
|
6336
|
-
inputSourceTraceId: replayCtxAtRoot.inputSourceTraceId
|
|
6503
|
+
...testRunId !== void 0 && { testRunId },
|
|
6504
|
+
...replayCtxAtStart?.inputSourceTraceId && {
|
|
6505
|
+
inputSourceTraceId: replayCtxAtStart.inputSourceTraceId
|
|
6337
6506
|
},
|
|
6338
6507
|
dbSnapshotRef
|
|
6339
6508
|
});
|
|
@@ -6366,9 +6535,7 @@ var Bitfab = class {
|
|
|
6366
6535
|
contexts: newContext.contexts,
|
|
6367
6536
|
prompt: newContext.prompt,
|
|
6368
6537
|
endedAt,
|
|
6369
|
-
...
|
|
6370
|
-
testRunId: replayCtx.testRunId
|
|
6371
|
-
},
|
|
6538
|
+
...testRunId !== void 0 && { testRunId },
|
|
6372
6539
|
...replayCtx?.inputSourceSpanId && {
|
|
6373
6540
|
inputSourceSpanId: replayCtx.inputSourceSpanId
|
|
6374
6541
|
}
|
|
@@ -6408,6 +6575,49 @@ var Bitfab = class {
|
|
|
6408
6575
|
} catch {
|
|
6409
6576
|
}
|
|
6410
6577
|
};
|
|
6578
|
+
const recordSpan = (result) => {
|
|
6579
|
+
if (options.finalize) {
|
|
6580
|
+
void self.httpClient.trackDeferred(
|
|
6581
|
+
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
6582
|
+
(error) => sendSpan({
|
|
6583
|
+
result: void 0,
|
|
6584
|
+
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
6585
|
+
})
|
|
6586
|
+
)
|
|
6587
|
+
);
|
|
6588
|
+
} else {
|
|
6589
|
+
void sendSpan({ result });
|
|
6590
|
+
}
|
|
6591
|
+
};
|
|
6592
|
+
executeWithContext = () => {
|
|
6593
|
+
let result;
|
|
6594
|
+
try {
|
|
6595
|
+
result = fn.apply(this, args);
|
|
6596
|
+
} catch (error) {
|
|
6597
|
+
void sendSpan({
|
|
6598
|
+
result: void 0,
|
|
6599
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6600
|
+
});
|
|
6601
|
+
throw error;
|
|
6602
|
+
}
|
|
6603
|
+
if (result instanceof Promise) {
|
|
6604
|
+
return result.then((resolvedResult) => {
|
|
6605
|
+
recordSpan(resolvedResult);
|
|
6606
|
+
return resolvedResult;
|
|
6607
|
+
}).catch((error) => {
|
|
6608
|
+
void sendSpan({
|
|
6609
|
+
result: void 0,
|
|
6610
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6611
|
+
});
|
|
6612
|
+
throw error;
|
|
6613
|
+
});
|
|
6614
|
+
}
|
|
6615
|
+
if (isAsyncGenerator(result)) {
|
|
6616
|
+
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
6617
|
+
}
|
|
6618
|
+
recordSpan(result);
|
|
6619
|
+
return result;
|
|
6620
|
+
};
|
|
6411
6621
|
const replayCtxForMock = getReplayContext();
|
|
6412
6622
|
if (replayCtxForMock?.mockTree && !isRootSpan) {
|
|
6413
6623
|
const counters = replayCtxForMock.callCounters;
|
|
@@ -6466,6 +6676,7 @@ var Bitfab = class {
|
|
|
6466
6676
|
}
|
|
6467
6677
|
return output;
|
|
6468
6678
|
};
|
|
6679
|
+
const shouldMockWithBaseStrategy = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
|
|
6469
6680
|
if (replayCtxForMock.mockOverrides?.length) {
|
|
6470
6681
|
const nodeMeta = {
|
|
6471
6682
|
traceFunctionKey,
|
|
@@ -6473,28 +6684,75 @@ var Bitfab = class {
|
|
|
6473
6684
|
type: options.type ?? "custom",
|
|
6474
6685
|
originalSpanId: mockSpan?.sourceSpanId
|
|
6475
6686
|
};
|
|
6476
|
-
const
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6485
|
-
|
|
6486
|
-
|
|
6687
|
+
const overrideCtx = {
|
|
6688
|
+
node: nodeMeta,
|
|
6689
|
+
inputs: args,
|
|
6690
|
+
getOriginalOutput: () => Promise.resolve(resolveRecordedOutput())
|
|
6691
|
+
};
|
|
6692
|
+
const resolveOverrideFrom = (startIndex) => {
|
|
6693
|
+
for (let index = startIndex; index < replayCtxForMock.mockOverrides.length; index += 1) {
|
|
6694
|
+
const override = replayCtxForMock.mockOverrides[index];
|
|
6695
|
+
if (!override?.match(nodeMeta)) {
|
|
6696
|
+
continue;
|
|
6697
|
+
}
|
|
6698
|
+
const injected = resolveMockValue(override.value, overrideCtx);
|
|
6699
|
+
if (injected instanceof Promise) {
|
|
6700
|
+
return injected.then(
|
|
6701
|
+
(output) => output === NO_MOCK_OVERRIDE ? resolveOverrideFrom(index + 1) : { matched: true, output }
|
|
6702
|
+
);
|
|
6703
|
+
}
|
|
6704
|
+
if (injected !== NO_MOCK_OVERRIDE) {
|
|
6705
|
+
return { matched: true, output: injected };
|
|
6706
|
+
}
|
|
6707
|
+
}
|
|
6708
|
+
return { matched: false };
|
|
6709
|
+
};
|
|
6710
|
+
const resolution = resolveOverrideFrom(0);
|
|
6711
|
+
if (resolution instanceof Promise) {
|
|
6712
|
+
if (!fnReturnsPromise) {
|
|
6713
|
+
throw new BitfabError(
|
|
6714
|
+
`Cannot resolve an asynchronous mock override for synchronous span "${traceFunctionKey}". Make the wrapped function async or return NO_MOCK_OVERRIDE synchronously.`
|
|
6715
|
+
);
|
|
6487
6716
|
}
|
|
6488
|
-
return
|
|
6717
|
+
return runWithSpanStack(newStack, async () => {
|
|
6718
|
+
const resolved = await resolution;
|
|
6719
|
+
if (resolved.matched) {
|
|
6720
|
+
void sendSpan({
|
|
6721
|
+
result: resolved.output,
|
|
6722
|
+
mocked: true,
|
|
6723
|
+
mockTarget: "output",
|
|
6724
|
+
mockSource: "override"
|
|
6725
|
+
});
|
|
6726
|
+
return resolved.output;
|
|
6727
|
+
}
|
|
6728
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
6729
|
+
throw new BitfabError(
|
|
6730
|
+
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
6731
|
+
);
|
|
6732
|
+
}
|
|
6733
|
+
if (shouldMockWithBaseStrategy) {
|
|
6734
|
+
const output = await resolveRecordedOutput();
|
|
6735
|
+
void sendSpan({
|
|
6736
|
+
result: output,
|
|
6737
|
+
mocked: true,
|
|
6738
|
+
mockTarget: "output",
|
|
6739
|
+
mockSource: "recorded"
|
|
6740
|
+
});
|
|
6741
|
+
return output;
|
|
6742
|
+
}
|
|
6743
|
+
return executeWithContext();
|
|
6744
|
+
});
|
|
6745
|
+
}
|
|
6746
|
+
if (resolution.matched) {
|
|
6747
|
+
return emitMock(resolution.output, "override");
|
|
6489
6748
|
}
|
|
6490
6749
|
}
|
|
6491
|
-
|
|
6492
|
-
if (shouldMock && !mockSpan) {
|
|
6750
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
6493
6751
|
throw new BitfabError(
|
|
6494
6752
|
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
6495
6753
|
);
|
|
6496
6754
|
}
|
|
6497
|
-
if (
|
|
6755
|
+
if (shouldMockWithBaseStrategy) {
|
|
6498
6756
|
const recorded = resolveRecordedOutput();
|
|
6499
6757
|
if (recorded instanceof Promise) {
|
|
6500
6758
|
return emitMockAsync(recorded, "recorded");
|
|
@@ -6502,49 +6760,6 @@ var Bitfab = class {
|
|
|
6502
6760
|
return emitMock(recorded, "recorded");
|
|
6503
6761
|
}
|
|
6504
6762
|
}
|
|
6505
|
-
const recordSpan = (result) => {
|
|
6506
|
-
if (options.finalize) {
|
|
6507
|
-
void self.httpClient.trackDeferred(
|
|
6508
|
-
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
6509
|
-
(error) => sendSpan({
|
|
6510
|
-
result: void 0,
|
|
6511
|
-
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
6512
|
-
})
|
|
6513
|
-
)
|
|
6514
|
-
);
|
|
6515
|
-
} else {
|
|
6516
|
-
void sendSpan({ result });
|
|
6517
|
-
}
|
|
6518
|
-
};
|
|
6519
|
-
executeWithContext = () => {
|
|
6520
|
-
let result;
|
|
6521
|
-
try {
|
|
6522
|
-
result = fn.apply(this, args);
|
|
6523
|
-
} catch (error) {
|
|
6524
|
-
void sendSpan({
|
|
6525
|
-
result: void 0,
|
|
6526
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6527
|
-
});
|
|
6528
|
-
throw error;
|
|
6529
|
-
}
|
|
6530
|
-
if (result instanceof Promise) {
|
|
6531
|
-
return result.then((resolvedResult) => {
|
|
6532
|
-
recordSpan(resolvedResult);
|
|
6533
|
-
return resolvedResult;
|
|
6534
|
-
}).catch((error) => {
|
|
6535
|
-
void sendSpan({
|
|
6536
|
-
result: void 0,
|
|
6537
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6538
|
-
});
|
|
6539
|
-
throw error;
|
|
6540
|
-
});
|
|
6541
|
-
}
|
|
6542
|
-
if (isAsyncGenerator(result)) {
|
|
6543
|
-
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
6544
|
-
}
|
|
6545
|
-
recordSpan(result);
|
|
6546
|
-
return result;
|
|
6547
|
-
};
|
|
6548
6763
|
} catch (setupError) {
|
|
6549
6764
|
if (registeredTraceId) {
|
|
6550
6765
|
activeTraceStates.delete(registeredTraceId);
|
|
@@ -6831,8 +7046,40 @@ var Bitfab = class {
|
|
|
6831
7046
|
...params.mockSource && { mockSource: params.mockSource }
|
|
6832
7047
|
});
|
|
6833
7048
|
}
|
|
6834
|
-
registerMockOverride(
|
|
6835
|
-
|
|
7049
|
+
registerMockOverride(overrideOrResolverOrMatch, ...values) {
|
|
7050
|
+
let override;
|
|
7051
|
+
if (typeof overrideOrResolverOrMatch === "string") {
|
|
7052
|
+
const keyedOverride = values[0];
|
|
7053
|
+
if (values.length !== 1 || keyedOverride === void 0) {
|
|
7054
|
+
throw new BitfabError(
|
|
7055
|
+
"registerMockOverride(traceFunctionKey, override) requires a resolver function or { match, value } override."
|
|
7056
|
+
);
|
|
7057
|
+
}
|
|
7058
|
+
if (typeof keyedOverride === "function") {
|
|
7059
|
+
override = {
|
|
7060
|
+
match: (node) => node.traceFunctionKey === overrideOrResolverOrMatch,
|
|
7061
|
+
value: keyedOverride
|
|
7062
|
+
};
|
|
7063
|
+
} else if (typeof keyedOverride === "object" && keyedOverride !== null && "match" in keyedOverride && "value" in keyedOverride) {
|
|
7064
|
+
override = {
|
|
7065
|
+
match: (node) => node.traceFunctionKey === overrideOrResolverOrMatch && keyedOverride.match(node),
|
|
7066
|
+
value: keyedOverride.value
|
|
7067
|
+
};
|
|
7068
|
+
} else {
|
|
7069
|
+
throw new BitfabError(
|
|
7070
|
+
"registerMockOverride(traceFunctionKey, override) requires a resolver function or { match, value } override."
|
|
7071
|
+
);
|
|
7072
|
+
}
|
|
7073
|
+
} else if (typeof overrideOrResolverOrMatch !== "function") {
|
|
7074
|
+
override = overrideOrResolverOrMatch;
|
|
7075
|
+
} else if (values.length === 0) {
|
|
7076
|
+
override = { match: () => true, value: overrideOrResolverOrMatch };
|
|
7077
|
+
} else {
|
|
7078
|
+
override = {
|
|
7079
|
+
match: overrideOrResolverOrMatch,
|
|
7080
|
+
value: values[0]
|
|
7081
|
+
};
|
|
7082
|
+
}
|
|
6836
7083
|
this.mockOverrides.push(override);
|
|
6837
7084
|
}
|
|
6838
7085
|
/** Remove all overrides registered via {@link registerMockOverride}. */
|
|
@@ -7082,6 +7329,7 @@ var finalizers = {
|
|
|
7082
7329
|
|
|
7083
7330
|
// src/index.ts
|
|
7084
7331
|
init_http();
|
|
7332
|
+
init_mockOverride();
|
|
7085
7333
|
init_replay();
|
|
7086
7334
|
|
|
7087
7335
|
// src/replayRegistry.ts
|
|
@@ -7109,6 +7357,7 @@ assertAsyncStorageRegistered();
|
|
|
7109
7357
|
DEFAULT_SERVICE_URL,
|
|
7110
7358
|
DbBranchReplayError,
|
|
7111
7359
|
HttpClient,
|
|
7360
|
+
NO_MOCK_OVERRIDE,
|
|
7112
7361
|
ReplayError,
|
|
7113
7362
|
SUPPORTED_PROVIDERS,
|
|
7114
7363
|
__version__,
|