bitfab 0.38.4 → 0.38.6
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 +8 -1
- package/dist/autoTrace.cjs.map +1 -1
- package/dist/autoTrace.d.cts +2 -2
- package/dist/autoTrace.d.ts +2 -2
- package/dist/autoTrace.js +1 -1
- package/dist/{chunk-LHFNHB2J.js → chunk-O75EYGVO.js} +8 -3
- package/dist/chunk-O75EYGVO.js.map +1 -0
- package/dist/{chunk-PXAL7PPD.js → chunk-YCTQONNS.js} +154 -68
- package/dist/chunk-YCTQONNS.js.map +1 -0
- package/dist/{chunk-J47KPS77.js → chunk-ZUD7OFYB.js} +9 -2
- package/dist/{chunk-J47KPS77.js.map → chunk-ZUD7OFYB.js.map} +1 -1
- package/dist/index.cjs +167 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -11
- package/dist/index.d.ts +41 -11
- package/dist/index.js +5 -3
- package/dist/node.cjs +167 -67
- 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-BYW5MCLO.js → replay-K3UMQAKO.js} +2 -2
- package/dist/replayCli.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-LHFNHB2J.js.map +0 -1
- package/dist/chunk-PXAL7PPD.js.map +0 -1
- /package/dist/{replay-BYW5MCLO.js.map → replay-K3UMQAKO.js.map} +0 -0
|
@@ -5,11 +5,12 @@ import {
|
|
|
5
5
|
runWithAutoTraceContext,
|
|
6
6
|
runWithAutoTraceNodeConfiguration,
|
|
7
7
|
runWithAutoTraceRootContext
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ZUD7OFYB.js";
|
|
9
9
|
import {
|
|
10
10
|
BitfabError,
|
|
11
11
|
DEFAULT_SERVICE_URL,
|
|
12
12
|
HttpClient,
|
|
13
|
+
NO_MOCK_OVERRIDE,
|
|
13
14
|
deserializeValue,
|
|
14
15
|
getReplayContext,
|
|
15
16
|
randomUuid,
|
|
@@ -18,7 +19,7 @@ import {
|
|
|
18
19
|
toJsonSafe,
|
|
19
20
|
toJsonSafeReport,
|
|
20
21
|
warnOnce
|
|
21
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-O75EYGVO.js";
|
|
22
23
|
import {
|
|
23
24
|
__privateAdd,
|
|
24
25
|
__privateGet,
|
|
@@ -2392,8 +2393,9 @@ var Bitfab = class {
|
|
|
2392
2393
|
* Decorate a class method as an automatically expanded trace root.
|
|
2393
2394
|
*
|
|
2394
2395
|
* Build instrumentation turns repository functions called beneath this
|
|
2395
|
-
* method into nested spans
|
|
2396
|
-
*
|
|
2396
|
+
* method into nested spans that capture inputs, outputs, and errors by
|
|
2397
|
+
* default. A confirmed capture policy can narrow rich capture to selected
|
|
2398
|
+
* function IDs.
|
|
2397
2399
|
* Without a compatible build transform, this still records the decorated
|
|
2398
2400
|
* method as a normal rich root span but cannot discover child calls.
|
|
2399
2401
|
*
|
|
@@ -2603,7 +2605,7 @@ var Bitfab = class {
|
|
|
2603
2605
|
type: nodeConfiguration?.type ?? "function",
|
|
2604
2606
|
captureWhen: "nested",
|
|
2605
2607
|
functionId: definition.id,
|
|
2606
|
-
captureContent: nodeConfiguration !== void 0 || capturePolicy.has(definition.id),
|
|
2608
|
+
captureContent: nodeConfiguration !== void 0 || capturePolicy === void 0 || capturePolicy.has(definition.id),
|
|
2607
2609
|
autoTraceDefinition: definition,
|
|
2608
2610
|
...nodeConfiguration?.testRunId !== void 0 && {
|
|
2609
2611
|
testRunId: nodeConfiguration.testRunId
|
|
@@ -2668,7 +2670,11 @@ var Bitfab = class {
|
|
|
2668
2670
|
const functionIds = Array.isArray(policy.functionIds) ? policy.functionIds.filter(
|
|
2669
2671
|
(id) => typeof id === "string" && id.startsWith(`${AUTO_TRACE_PROTOCOL}:`)
|
|
2670
2672
|
).slice(0, DEFAULT_AUTO_TRACE_MAX_SPANS) : [];
|
|
2671
|
-
__setBitfabAutoTraceCapturePolicy(
|
|
2673
|
+
__setBitfabAutoTraceCapturePolicy(
|
|
2674
|
+
this,
|
|
2675
|
+
traceFunctionKey,
|
|
2676
|
+
policy.revision === null ? void 0 : functionIds
|
|
2677
|
+
);
|
|
2672
2678
|
state.refreshAfter = Date.now() + AUTO_TRACE_POLICY_REFRESH_MS;
|
|
2673
2679
|
}).catch(() => {
|
|
2674
2680
|
state.refreshAfter = Date.now() + AUTO_TRACE_POLICY_RETRY_MS;
|
|
@@ -3280,6 +3286,49 @@ var Bitfab = class {
|
|
|
3280
3286
|
} catch {
|
|
3281
3287
|
}
|
|
3282
3288
|
};
|
|
3289
|
+
const recordSpan = (result) => {
|
|
3290
|
+
if (options.finalize) {
|
|
3291
|
+
void self.httpClient.trackDeferred(
|
|
3292
|
+
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
3293
|
+
(error) => sendSpan({
|
|
3294
|
+
result: void 0,
|
|
3295
|
+
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
3296
|
+
})
|
|
3297
|
+
)
|
|
3298
|
+
);
|
|
3299
|
+
} else {
|
|
3300
|
+
void sendSpan({ result });
|
|
3301
|
+
}
|
|
3302
|
+
};
|
|
3303
|
+
executeWithContext = () => {
|
|
3304
|
+
let result;
|
|
3305
|
+
try {
|
|
3306
|
+
result = fn.apply(this, args);
|
|
3307
|
+
} catch (error) {
|
|
3308
|
+
void sendSpan({
|
|
3309
|
+
result: void 0,
|
|
3310
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3311
|
+
});
|
|
3312
|
+
throw error;
|
|
3313
|
+
}
|
|
3314
|
+
if (result instanceof Promise) {
|
|
3315
|
+
return result.then((resolvedResult) => {
|
|
3316
|
+
recordSpan(resolvedResult);
|
|
3317
|
+
return resolvedResult;
|
|
3318
|
+
}).catch((error) => {
|
|
3319
|
+
void sendSpan({
|
|
3320
|
+
result: void 0,
|
|
3321
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3322
|
+
});
|
|
3323
|
+
throw error;
|
|
3324
|
+
});
|
|
3325
|
+
}
|
|
3326
|
+
if (isAsyncGenerator(result)) {
|
|
3327
|
+
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
3328
|
+
}
|
|
3329
|
+
recordSpan(result);
|
|
3330
|
+
return result;
|
|
3331
|
+
};
|
|
3283
3332
|
const replayCtxForMock = getReplayContext();
|
|
3284
3333
|
if (replayCtxForMock?.mockTree && !isRootSpan) {
|
|
3285
3334
|
const counters = replayCtxForMock.callCounters;
|
|
@@ -3338,6 +3387,7 @@ var Bitfab = class {
|
|
|
3338
3387
|
}
|
|
3339
3388
|
return output;
|
|
3340
3389
|
};
|
|
3390
|
+
const shouldMockWithBaseStrategy = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
|
|
3341
3391
|
if (replayCtxForMock.mockOverrides?.length) {
|
|
3342
3392
|
const nodeMeta = {
|
|
3343
3393
|
traceFunctionKey,
|
|
@@ -3345,28 +3395,75 @@ var Bitfab = class {
|
|
|
3345
3395
|
type: options.type ?? "custom",
|
|
3346
3396
|
originalSpanId: mockSpan?.sourceSpanId
|
|
3347
3397
|
};
|
|
3348
|
-
const
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3398
|
+
const overrideCtx = {
|
|
3399
|
+
node: nodeMeta,
|
|
3400
|
+
inputs: args,
|
|
3401
|
+
getOriginalOutput: () => Promise.resolve(resolveRecordedOutput())
|
|
3402
|
+
};
|
|
3403
|
+
const resolveOverrideFrom = (startIndex) => {
|
|
3404
|
+
for (let index = startIndex; index < replayCtxForMock.mockOverrides.length; index += 1) {
|
|
3405
|
+
const override = replayCtxForMock.mockOverrides[index];
|
|
3406
|
+
if (!override?.match(nodeMeta)) {
|
|
3407
|
+
continue;
|
|
3408
|
+
}
|
|
3409
|
+
const injected = resolveMockValue(override.value, overrideCtx);
|
|
3410
|
+
if (injected instanceof Promise) {
|
|
3411
|
+
return injected.then(
|
|
3412
|
+
(output) => output === NO_MOCK_OVERRIDE ? resolveOverrideFrom(index + 1) : { matched: true, output }
|
|
3413
|
+
);
|
|
3414
|
+
}
|
|
3415
|
+
if (injected !== NO_MOCK_OVERRIDE) {
|
|
3416
|
+
return { matched: true, output: injected };
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
return { matched: false };
|
|
3420
|
+
};
|
|
3421
|
+
const resolution = resolveOverrideFrom(0);
|
|
3422
|
+
if (resolution instanceof Promise) {
|
|
3423
|
+
if (!fnReturnsPromise) {
|
|
3424
|
+
throw new BitfabError(
|
|
3425
|
+
`Cannot resolve an asynchronous mock override for synchronous span "${traceFunctionKey}". Make the wrapped function async or return NO_MOCK_OVERRIDE synchronously.`
|
|
3426
|
+
);
|
|
3359
3427
|
}
|
|
3360
|
-
return
|
|
3428
|
+
return runWithSpanStack(newStack, async () => {
|
|
3429
|
+
const resolved = await resolution;
|
|
3430
|
+
if (resolved.matched) {
|
|
3431
|
+
void sendSpan({
|
|
3432
|
+
result: resolved.output,
|
|
3433
|
+
mocked: true,
|
|
3434
|
+
mockTarget: "output",
|
|
3435
|
+
mockSource: "override"
|
|
3436
|
+
});
|
|
3437
|
+
return resolved.output;
|
|
3438
|
+
}
|
|
3439
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
3440
|
+
throw new BitfabError(
|
|
3441
|
+
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
3442
|
+
);
|
|
3443
|
+
}
|
|
3444
|
+
if (shouldMockWithBaseStrategy) {
|
|
3445
|
+
const output = await resolveRecordedOutput();
|
|
3446
|
+
void sendSpan({
|
|
3447
|
+
result: output,
|
|
3448
|
+
mocked: true,
|
|
3449
|
+
mockTarget: "output",
|
|
3450
|
+
mockSource: "recorded"
|
|
3451
|
+
});
|
|
3452
|
+
return output;
|
|
3453
|
+
}
|
|
3454
|
+
return executeWithContext();
|
|
3455
|
+
});
|
|
3456
|
+
}
|
|
3457
|
+
if (resolution.matched) {
|
|
3458
|
+
return emitMock(resolution.output, "override");
|
|
3361
3459
|
}
|
|
3362
3460
|
}
|
|
3363
|
-
|
|
3364
|
-
if (shouldMock && !mockSpan) {
|
|
3461
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
3365
3462
|
throw new BitfabError(
|
|
3366
3463
|
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
3367
3464
|
);
|
|
3368
3465
|
}
|
|
3369
|
-
if (
|
|
3466
|
+
if (shouldMockWithBaseStrategy) {
|
|
3370
3467
|
const recorded = resolveRecordedOutput();
|
|
3371
3468
|
if (recorded instanceof Promise) {
|
|
3372
3469
|
return emitMockAsync(recorded, "recorded");
|
|
@@ -3374,49 +3471,6 @@ var Bitfab = class {
|
|
|
3374
3471
|
return emitMock(recorded, "recorded");
|
|
3375
3472
|
}
|
|
3376
3473
|
}
|
|
3377
|
-
const recordSpan = (result) => {
|
|
3378
|
-
if (options.finalize) {
|
|
3379
|
-
void self.httpClient.trackDeferred(
|
|
3380
|
-
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
3381
|
-
(error) => sendSpan({
|
|
3382
|
-
result: void 0,
|
|
3383
|
-
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
3384
|
-
})
|
|
3385
|
-
)
|
|
3386
|
-
);
|
|
3387
|
-
} else {
|
|
3388
|
-
void sendSpan({ result });
|
|
3389
|
-
}
|
|
3390
|
-
};
|
|
3391
|
-
executeWithContext = () => {
|
|
3392
|
-
let result;
|
|
3393
|
-
try {
|
|
3394
|
-
result = fn.apply(this, args);
|
|
3395
|
-
} catch (error) {
|
|
3396
|
-
void sendSpan({
|
|
3397
|
-
result: void 0,
|
|
3398
|
-
error: error instanceof Error ? error.message : String(error)
|
|
3399
|
-
});
|
|
3400
|
-
throw error;
|
|
3401
|
-
}
|
|
3402
|
-
if (result instanceof Promise) {
|
|
3403
|
-
return result.then((resolvedResult) => {
|
|
3404
|
-
recordSpan(resolvedResult);
|
|
3405
|
-
return resolvedResult;
|
|
3406
|
-
}).catch((error) => {
|
|
3407
|
-
void sendSpan({
|
|
3408
|
-
result: void 0,
|
|
3409
|
-
error: error instanceof Error ? error.message : String(error)
|
|
3410
|
-
});
|
|
3411
|
-
throw error;
|
|
3412
|
-
});
|
|
3413
|
-
}
|
|
3414
|
-
if (isAsyncGenerator(result)) {
|
|
3415
|
-
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
3416
|
-
}
|
|
3417
|
-
recordSpan(result);
|
|
3418
|
-
return result;
|
|
3419
|
-
};
|
|
3420
3474
|
} catch (setupError) {
|
|
3421
3475
|
if (registeredTraceId) {
|
|
3422
3476
|
activeTraceStates.delete(registeredTraceId);
|
|
@@ -3703,8 +3757,40 @@ var Bitfab = class {
|
|
|
3703
3757
|
...params.mockSource && { mockSource: params.mockSource }
|
|
3704
3758
|
});
|
|
3705
3759
|
}
|
|
3706
|
-
registerMockOverride(
|
|
3707
|
-
|
|
3760
|
+
registerMockOverride(overrideOrResolverOrMatch, ...values) {
|
|
3761
|
+
let override;
|
|
3762
|
+
if (typeof overrideOrResolverOrMatch === "string") {
|
|
3763
|
+
const keyedOverride = values[0];
|
|
3764
|
+
if (values.length !== 1 || keyedOverride === void 0) {
|
|
3765
|
+
throw new BitfabError(
|
|
3766
|
+
"registerMockOverride(traceFunctionKey, override) requires a resolver function or { match, value } override."
|
|
3767
|
+
);
|
|
3768
|
+
}
|
|
3769
|
+
if (typeof keyedOverride === "function") {
|
|
3770
|
+
override = {
|
|
3771
|
+
match: (node) => node.traceFunctionKey === overrideOrResolverOrMatch,
|
|
3772
|
+
value: keyedOverride
|
|
3773
|
+
};
|
|
3774
|
+
} else if (typeof keyedOverride === "object" && keyedOverride !== null && "match" in keyedOverride && "value" in keyedOverride) {
|
|
3775
|
+
override = {
|
|
3776
|
+
match: (node) => node.traceFunctionKey === overrideOrResolverOrMatch && keyedOverride.match(node),
|
|
3777
|
+
value: keyedOverride.value
|
|
3778
|
+
};
|
|
3779
|
+
} else {
|
|
3780
|
+
throw new BitfabError(
|
|
3781
|
+
"registerMockOverride(traceFunctionKey, override) requires a resolver function or { match, value } override."
|
|
3782
|
+
);
|
|
3783
|
+
}
|
|
3784
|
+
} else if (typeof overrideOrResolverOrMatch !== "function") {
|
|
3785
|
+
override = overrideOrResolverOrMatch;
|
|
3786
|
+
} else if (values.length === 0) {
|
|
3787
|
+
override = { match: () => true, value: overrideOrResolverOrMatch };
|
|
3788
|
+
} else {
|
|
3789
|
+
override = {
|
|
3790
|
+
match: overrideOrResolverOrMatch,
|
|
3791
|
+
value: values[0]
|
|
3792
|
+
};
|
|
3793
|
+
}
|
|
3708
3794
|
this.mockOverrides.push(override);
|
|
3709
3795
|
}
|
|
3710
3796
|
/** Remove all overrides registered via {@link registerMockOverride}. */
|
|
@@ -3725,7 +3811,7 @@ var Bitfab = class {
|
|
|
3725
3811
|
`Function is wrapped with trace function key '${wrappedKey}' but replay was called with '${traceFunctionKey}'. Pass matching keys, or pass the unwrapped function to replay it under the explicit key.`
|
|
3726
3812
|
);
|
|
3727
3813
|
}
|
|
3728
|
-
const { replay: doReplay } = await import("./replay-
|
|
3814
|
+
const { replay: doReplay } = await import("./replay-K3UMQAKO.js");
|
|
3729
3815
|
return doReplay(
|
|
3730
3816
|
this.httpClient,
|
|
3731
3817
|
this.serviceUrl,
|
|
@@ -3969,4 +4055,4 @@ export {
|
|
|
3969
4055
|
finalizers,
|
|
3970
4056
|
defineReplayRegistry
|
|
3971
4057
|
};
|
|
3972
|
-
//# sourceMappingURL=chunk-
|
|
4058
|
+
//# sourceMappingURL=chunk-YCTQONNS.js.map
|