@bitfab/sdk 0.38.4 → 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/{chunk-5GWBJGYZ.js → chunk-VVI573UU.js} +8 -3
- package/dist/{chunk-5GWBJGYZ.js.map → chunk-VVI573UU.js.map} +1 -1
- package/dist/{chunk-NKX3EY35.js → chunk-Z3GIZGS5.js} +144 -63
- package/dist/chunk-Z3GIZGS5.js.map +1 -0
- package/dist/index.cjs +150 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -7
- package/dist/index.d.ts +34 -7
- package/dist/index.js +4 -2
- package/dist/node.cjs +150 -62
- 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 +4 -2
- package/dist/node.js.map +1 -1
- package/dist/{replay-O2WFIRM4.js → replay-Z6DON4SP.js} +2 -2
- package/dist/replayCli.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-NKX3EY35.js.map +0 -1
- /package/dist/{replay-O2WFIRM4.js.map → replay-Z6DON4SP.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -147,10 +147,23 @@ interface MockOverrideCtx {
|
|
|
147
147
|
*/
|
|
148
148
|
getOriginalOutput: () => Promise<unknown>;
|
|
149
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Return this from a mock override resolver to decline the override for the
|
|
152
|
+
* current span. Resolution continues with the next override, then the replay's
|
|
153
|
+
* base mock strategy.
|
|
154
|
+
*/
|
|
155
|
+
declare const NO_MOCK_OVERRIDE: unique symbol;
|
|
150
156
|
/** Selects which spans an override applies to. Runs on structural metadata. */
|
|
151
157
|
type NodeMatcher = (node: SpanNodeMeta) => boolean;
|
|
152
158
|
/** The function form of {@link MockValue}, receiving the override context. */
|
|
153
159
|
type MockValueFn = (ctx: MockOverrideCtx) => unknown | Promise<unknown>;
|
|
160
|
+
/**
|
|
161
|
+
* A client-wide, keyed, or per-replay resolver. A global resolver can route on
|
|
162
|
+
* `ctx.node.traceFunctionKey`; a keyed resolver is only invoked for spans with
|
|
163
|
+
* its registered key. Return {@link NO_MOCK_OVERRIDE} for spans the resolver
|
|
164
|
+
* does not want to override.
|
|
165
|
+
*/
|
|
166
|
+
type MockOverrideResolver = (ctx: MockOverrideCtx) => unknown | Promise<unknown>;
|
|
154
167
|
/**
|
|
155
168
|
* The value injected for a matched span: either a flat value used as-is, or a
|
|
156
169
|
* function of the {@link MockOverrideCtx} that returns one (or a Promise of
|
|
@@ -168,6 +181,8 @@ interface MockOverride {
|
|
|
168
181
|
match: NodeMatcher;
|
|
169
182
|
value: MockValue;
|
|
170
183
|
}
|
|
184
|
+
/** Accepted shape for one mock override declaration. */
|
|
185
|
+
type MockOverrideInput = MockOverride | MockOverrideResolver;
|
|
171
186
|
|
|
172
187
|
/**
|
|
173
188
|
* Replay context propagation via AsyncLocalStorage.
|
|
@@ -1268,12 +1283,12 @@ interface ReplayOptions {
|
|
|
1268
1283
|
/**
|
|
1269
1284
|
* Selective mock overrides: inject custom values into specific spans during
|
|
1270
1285
|
* replay, so downstream real code runs against the substituted output. Each
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1273
|
-
*
|
|
1274
|
-
*
|
|
1286
|
+
* Pass `{ match, value }` pairs, or one resolver invoked for every child span.
|
|
1287
|
+
* A resolver can route on `ctx.node.traceFunctionKey` and return
|
|
1288
|
+
* `NO_MOCK_OVERRIDE` to continue to the next override and base strategy.
|
|
1289
|
+
* Per-call overrides take precedence over registrations on the client.
|
|
1275
1290
|
*/
|
|
1276
|
-
mockOverride?:
|
|
1291
|
+
mockOverride?: MockOverrideInput | MockOverrideInput[];
|
|
1277
1292
|
/**
|
|
1278
1293
|
* Run each item against a database branch restored to the state its source
|
|
1279
1294
|
* trace saw. Pass `true` to branch with the mirror project's own sizing, or a
|
|
@@ -2584,10 +2599,22 @@ declare class Bitfab {
|
|
|
2584
2599
|
* (node) => node.traceFunctionKey === "classify-intent",
|
|
2585
2600
|
* ({ inputs }) => ({ label: "refund" }),
|
|
2586
2601
|
* )
|
|
2602
|
+
* // Keyed form: the resolver only sees spans for this trace function key.
|
|
2603
|
+
* bitfab.registerMockOverride("classify-intent", ({ inputs }) => ({
|
|
2604
|
+
* label: String(inputs[0]),
|
|
2605
|
+
* }))
|
|
2606
|
+
* // Or one resolver for every child span:
|
|
2607
|
+
* bitfab.registerMockOverride(({ node }) =>
|
|
2608
|
+
* node.traceFunctionKey === "classify-intent"
|
|
2609
|
+
* ? { label: "refund" }
|
|
2610
|
+
* : NO_MOCK_OVERRIDE,
|
|
2611
|
+
* )
|
|
2587
2612
|
* ```
|
|
2588
2613
|
*/
|
|
2589
2614
|
registerMockOverride(override: MockOverride): void;
|
|
2615
|
+
registerMockOverride(resolver: MockOverrideResolver): void;
|
|
2590
2616
|
registerMockOverride(match: NodeMatcher, value: MockValue): void;
|
|
2617
|
+
registerMockOverride(traceFunctionKey: string, override: MockOverride | MockOverrideResolver): void;
|
|
2591
2618
|
/** Remove all overrides registered via {@link registerMockOverride}. */
|
|
2592
2619
|
clearMockOverrides(): void;
|
|
2593
2620
|
replay<TReturn>(traceFunctionKey: string, fn: (...args: any[]) => TReturn | Promise<TReturn>, options?: ReplayOptions): Promise<ReplayResult<TReturn>>;
|
|
@@ -2759,7 +2786,7 @@ declare class BitfabFunction {
|
|
|
2759
2786
|
/**
|
|
2760
2787
|
* SDK version from package.json (injected at build time)
|
|
2761
2788
|
*/
|
|
2762
|
-
declare const __version__ = "0.38.
|
|
2789
|
+
declare const __version__ = "0.38.5";
|
|
2763
2790
|
|
|
2764
2791
|
/**
|
|
2765
2792
|
* Constants for the Bitfab SDK.
|
|
@@ -2862,4 +2889,4 @@ type ReplayRegistry = Record<string, ReplayRegistration>;
|
|
|
2862
2889
|
*/
|
|
2863
2890
|
declare function defineReplayRegistry<TRegistry extends ReplayRegistry>(registry: TRegistry): TRegistry;
|
|
2864
2891
|
|
|
2865
|
-
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
|
|
2892
|
+
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -147,10 +147,23 @@ interface MockOverrideCtx {
|
|
|
147
147
|
*/
|
|
148
148
|
getOriginalOutput: () => Promise<unknown>;
|
|
149
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Return this from a mock override resolver to decline the override for the
|
|
152
|
+
* current span. Resolution continues with the next override, then the replay's
|
|
153
|
+
* base mock strategy.
|
|
154
|
+
*/
|
|
155
|
+
declare const NO_MOCK_OVERRIDE: unique symbol;
|
|
150
156
|
/** Selects which spans an override applies to. Runs on structural metadata. */
|
|
151
157
|
type NodeMatcher = (node: SpanNodeMeta) => boolean;
|
|
152
158
|
/** The function form of {@link MockValue}, receiving the override context. */
|
|
153
159
|
type MockValueFn = (ctx: MockOverrideCtx) => unknown | Promise<unknown>;
|
|
160
|
+
/**
|
|
161
|
+
* A client-wide, keyed, or per-replay resolver. A global resolver can route on
|
|
162
|
+
* `ctx.node.traceFunctionKey`; a keyed resolver is only invoked for spans with
|
|
163
|
+
* its registered key. Return {@link NO_MOCK_OVERRIDE} for spans the resolver
|
|
164
|
+
* does not want to override.
|
|
165
|
+
*/
|
|
166
|
+
type MockOverrideResolver = (ctx: MockOverrideCtx) => unknown | Promise<unknown>;
|
|
154
167
|
/**
|
|
155
168
|
* The value injected for a matched span: either a flat value used as-is, or a
|
|
156
169
|
* function of the {@link MockOverrideCtx} that returns one (or a Promise of
|
|
@@ -168,6 +181,8 @@ interface MockOverride {
|
|
|
168
181
|
match: NodeMatcher;
|
|
169
182
|
value: MockValue;
|
|
170
183
|
}
|
|
184
|
+
/** Accepted shape for one mock override declaration. */
|
|
185
|
+
type MockOverrideInput = MockOverride | MockOverrideResolver;
|
|
171
186
|
|
|
172
187
|
/**
|
|
173
188
|
* Replay context propagation via AsyncLocalStorage.
|
|
@@ -1268,12 +1283,12 @@ interface ReplayOptions {
|
|
|
1268
1283
|
/**
|
|
1269
1284
|
* Selective mock overrides: inject custom values into specific spans during
|
|
1270
1285
|
* replay, so downstream real code runs against the substituted output. Each
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1273
|
-
*
|
|
1274
|
-
*
|
|
1286
|
+
* Pass `{ match, value }` pairs, or one resolver invoked for every child span.
|
|
1287
|
+
* A resolver can route on `ctx.node.traceFunctionKey` and return
|
|
1288
|
+
* `NO_MOCK_OVERRIDE` to continue to the next override and base strategy.
|
|
1289
|
+
* Per-call overrides take precedence over registrations on the client.
|
|
1275
1290
|
*/
|
|
1276
|
-
mockOverride?:
|
|
1291
|
+
mockOverride?: MockOverrideInput | MockOverrideInput[];
|
|
1277
1292
|
/**
|
|
1278
1293
|
* Run each item against a database branch restored to the state its source
|
|
1279
1294
|
* trace saw. Pass `true` to branch with the mirror project's own sizing, or a
|
|
@@ -2584,10 +2599,22 @@ declare class Bitfab {
|
|
|
2584
2599
|
* (node) => node.traceFunctionKey === "classify-intent",
|
|
2585
2600
|
* ({ inputs }) => ({ label: "refund" }),
|
|
2586
2601
|
* )
|
|
2602
|
+
* // Keyed form: the resolver only sees spans for this trace function key.
|
|
2603
|
+
* bitfab.registerMockOverride("classify-intent", ({ inputs }) => ({
|
|
2604
|
+
* label: String(inputs[0]),
|
|
2605
|
+
* }))
|
|
2606
|
+
* // Or one resolver for every child span:
|
|
2607
|
+
* bitfab.registerMockOverride(({ node }) =>
|
|
2608
|
+
* node.traceFunctionKey === "classify-intent"
|
|
2609
|
+
* ? { label: "refund" }
|
|
2610
|
+
* : NO_MOCK_OVERRIDE,
|
|
2611
|
+
* )
|
|
2587
2612
|
* ```
|
|
2588
2613
|
*/
|
|
2589
2614
|
registerMockOverride(override: MockOverride): void;
|
|
2615
|
+
registerMockOverride(resolver: MockOverrideResolver): void;
|
|
2590
2616
|
registerMockOverride(match: NodeMatcher, value: MockValue): void;
|
|
2617
|
+
registerMockOverride(traceFunctionKey: string, override: MockOverride | MockOverrideResolver): void;
|
|
2591
2618
|
/** Remove all overrides registered via {@link registerMockOverride}. */
|
|
2592
2619
|
clearMockOverrides(): void;
|
|
2593
2620
|
replay<TReturn>(traceFunctionKey: string, fn: (...args: any[]) => TReturn | Promise<TReturn>, options?: ReplayOptions): Promise<ReplayResult<TReturn>>;
|
|
@@ -2759,7 +2786,7 @@ declare class BitfabFunction {
|
|
|
2759
2786
|
/**
|
|
2760
2787
|
* SDK version from package.json (injected at build time)
|
|
2761
2788
|
*/
|
|
2762
|
-
declare const __version__ = "0.38.
|
|
2789
|
+
declare const __version__ = "0.38.5";
|
|
2763
2790
|
|
|
2764
2791
|
/**
|
|
2765
2792
|
* Constants for the Bitfab SDK.
|
|
@@ -2862,4 +2889,4 @@ type ReplayRegistry = Record<string, ReplayRegistration>;
|
|
|
2862
2889
|
*/
|
|
2863
2890
|
declare function defineReplayRegistry<TRegistry extends ReplayRegistry>(registry: TRegistry): TRegistry;
|
|
2864
2891
|
|
|
2865
|
-
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
|
|
2892
|
+
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
getCurrentReplayBranch,
|
|
13
13
|
getCurrentSpan,
|
|
14
14
|
getCurrentTrace
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-Z3GIZGS5.js";
|
|
16
16
|
import "./chunk-J47KPS77.js";
|
|
17
17
|
import {
|
|
18
18
|
BITFAB_PROGRESS_PREFIX,
|
|
@@ -20,12 +20,13 @@ import {
|
|
|
20
20
|
DEFAULT_SERVICE_URL,
|
|
21
21
|
DbBranchReplayError,
|
|
22
22
|
HttpClient,
|
|
23
|
+
NO_MOCK_OVERRIDE,
|
|
23
24
|
ReplayError,
|
|
24
25
|
__version__,
|
|
25
26
|
flushTraces,
|
|
26
27
|
reportReplayProgress,
|
|
27
28
|
serializeReplayResult
|
|
28
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-VVI573UU.js";
|
|
29
30
|
import "./chunk-H6LZRFMN.js";
|
|
30
31
|
export {
|
|
31
32
|
BITFAB_PROGRESS_PREFIX,
|
|
@@ -41,6 +42,7 @@ export {
|
|
|
41
42
|
DEFAULT_SERVICE_URL,
|
|
42
43
|
DbBranchReplayError,
|
|
43
44
|
HttpClient,
|
|
45
|
+
NO_MOCK_OVERRIDE,
|
|
44
46
|
ReplayError,
|
|
45
47
|
SUPPORTED_PROVIDERS,
|
|
46
48
|
__version__,
|
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__,
|
|
@@ -6569,6 +6575,49 @@ var Bitfab = class {
|
|
|
6569
6575
|
} catch {
|
|
6570
6576
|
}
|
|
6571
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
|
+
};
|
|
6572
6621
|
const replayCtxForMock = getReplayContext();
|
|
6573
6622
|
if (replayCtxForMock?.mockTree && !isRootSpan) {
|
|
6574
6623
|
const counters = replayCtxForMock.callCounters;
|
|
@@ -6627,6 +6676,7 @@ var Bitfab = class {
|
|
|
6627
6676
|
}
|
|
6628
6677
|
return output;
|
|
6629
6678
|
};
|
|
6679
|
+
const shouldMockWithBaseStrategy = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
|
|
6630
6680
|
if (replayCtxForMock.mockOverrides?.length) {
|
|
6631
6681
|
const nodeMeta = {
|
|
6632
6682
|
traceFunctionKey,
|
|
@@ -6634,28 +6684,75 @@ var Bitfab = class {
|
|
|
6634
6684
|
type: options.type ?? "custom",
|
|
6635
6685
|
originalSpanId: mockSpan?.sourceSpanId
|
|
6636
6686
|
};
|
|
6637
|
-
const
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
|
|
6641
|
-
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
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
|
+
}
|
|
6648
6707
|
}
|
|
6649
|
-
return
|
|
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
|
+
);
|
|
6716
|
+
}
|
|
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");
|
|
6650
6748
|
}
|
|
6651
6749
|
}
|
|
6652
|
-
|
|
6653
|
-
if (shouldMock && !mockSpan) {
|
|
6750
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
6654
6751
|
throw new BitfabError(
|
|
6655
6752
|
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
6656
6753
|
);
|
|
6657
6754
|
}
|
|
6658
|
-
if (
|
|
6755
|
+
if (shouldMockWithBaseStrategy) {
|
|
6659
6756
|
const recorded = resolveRecordedOutput();
|
|
6660
6757
|
if (recorded instanceof Promise) {
|
|
6661
6758
|
return emitMockAsync(recorded, "recorded");
|
|
@@ -6663,49 +6760,6 @@ var Bitfab = class {
|
|
|
6663
6760
|
return emitMock(recorded, "recorded");
|
|
6664
6761
|
}
|
|
6665
6762
|
}
|
|
6666
|
-
const recordSpan = (result) => {
|
|
6667
|
-
if (options.finalize) {
|
|
6668
|
-
void self.httpClient.trackDeferred(
|
|
6669
|
-
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
6670
|
-
(error) => sendSpan({
|
|
6671
|
-
result: void 0,
|
|
6672
|
-
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
6673
|
-
})
|
|
6674
|
-
)
|
|
6675
|
-
);
|
|
6676
|
-
} else {
|
|
6677
|
-
void sendSpan({ result });
|
|
6678
|
-
}
|
|
6679
|
-
};
|
|
6680
|
-
executeWithContext = () => {
|
|
6681
|
-
let result;
|
|
6682
|
-
try {
|
|
6683
|
-
result = fn.apply(this, args);
|
|
6684
|
-
} catch (error) {
|
|
6685
|
-
void sendSpan({
|
|
6686
|
-
result: void 0,
|
|
6687
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6688
|
-
});
|
|
6689
|
-
throw error;
|
|
6690
|
-
}
|
|
6691
|
-
if (result instanceof Promise) {
|
|
6692
|
-
return result.then((resolvedResult) => {
|
|
6693
|
-
recordSpan(resolvedResult);
|
|
6694
|
-
return resolvedResult;
|
|
6695
|
-
}).catch((error) => {
|
|
6696
|
-
void sendSpan({
|
|
6697
|
-
result: void 0,
|
|
6698
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6699
|
-
});
|
|
6700
|
-
throw error;
|
|
6701
|
-
});
|
|
6702
|
-
}
|
|
6703
|
-
if (isAsyncGenerator(result)) {
|
|
6704
|
-
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
6705
|
-
}
|
|
6706
|
-
recordSpan(result);
|
|
6707
|
-
return result;
|
|
6708
|
-
};
|
|
6709
6763
|
} catch (setupError) {
|
|
6710
6764
|
if (registeredTraceId) {
|
|
6711
6765
|
activeTraceStates.delete(registeredTraceId);
|
|
@@ -6992,8 +7046,40 @@ var Bitfab = class {
|
|
|
6992
7046
|
...params.mockSource && { mockSource: params.mockSource }
|
|
6993
7047
|
});
|
|
6994
7048
|
}
|
|
6995
|
-
registerMockOverride(
|
|
6996
|
-
|
|
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
|
+
}
|
|
6997
7083
|
this.mockOverrides.push(override);
|
|
6998
7084
|
}
|
|
6999
7085
|
/** Remove all overrides registered via {@link registerMockOverride}. */
|
|
@@ -7243,6 +7329,7 @@ var finalizers = {
|
|
|
7243
7329
|
|
|
7244
7330
|
// src/index.ts
|
|
7245
7331
|
init_http();
|
|
7332
|
+
init_mockOverride();
|
|
7246
7333
|
init_replay();
|
|
7247
7334
|
|
|
7248
7335
|
// src/replayRegistry.ts
|
|
@@ -7270,6 +7357,7 @@ assertAsyncStorageRegistered();
|
|
|
7270
7357
|
DEFAULT_SERVICE_URL,
|
|
7271
7358
|
DbBranchReplayError,
|
|
7272
7359
|
HttpClient,
|
|
7360
|
+
NO_MOCK_OVERRIDE,
|
|
7273
7361
|
ReplayError,
|
|
7274
7362
|
SUPPORTED_PROVIDERS,
|
|
7275
7363
|
__version__,
|