brass-runtime 1.18.0 → 1.18.2

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.
Files changed (84) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/agent/cli/main.cjs +31 -31
  3. package/dist/agent/cli/main.js +3 -3
  4. package/dist/agent/cli/main.mjs +3 -3
  5. package/dist/agent/index.cjs +4 -4
  6. package/dist/agent/index.d.ts +1 -1
  7. package/dist/agent/index.js +3 -3
  8. package/dist/agent/index.mjs +3 -3
  9. package/dist/{chunk-PSEU65ND.js → chunk-2R3RVNS2.js} +6 -6
  10. package/dist/{chunk-ITZQ526U.mjs → chunk-3NKXUX4T.mjs} +2 -2
  11. package/dist/{chunk-JH4GI3DW.js → chunk-4PKBNG2H.js} +38 -18
  12. package/dist/{chunk-Z3PSSXP3.mjs → chunk-5RVHSBJ6.mjs} +292 -36
  13. package/dist/{chunk-QZ6QFJNM.mjs → chunk-5UBJT4RW.mjs} +4 -4
  14. package/dist/{chunk-7TXQJFZX.cjs → chunk-6STX4PS3.cjs} +13 -13
  15. package/dist/{chunk-VIFA4DPN.cjs → chunk-7FZUTJM3.cjs} +508 -252
  16. package/dist/{chunk-4YQHPIWJ.js → chunk-A6EG5WRL.js} +3 -3
  17. package/dist/{chunk-XSAHV5HQ.js → chunk-APQBU7TM.js} +264 -133
  18. package/dist/{chunk-RREBJX2S.mjs → chunk-AQQQFNYD.mjs} +38 -18
  19. package/dist/{chunk-AADFFVYS.js → chunk-B2VXVNIS.js} +1 -1
  20. package/dist/{chunk-R6WDSZA6.mjs → chunk-BLXBZ6RE.mjs} +1 -1
  21. package/dist/{chunk-ITG6I7ZS.js → chunk-C3CWI42G.js} +1 -1
  22. package/dist/{chunk-LXBU5E77.cjs → chunk-DV644N7P.cjs} +85 -85
  23. package/dist/{chunk-G5JTCFMI.mjs → chunk-EKLEDIVJ.mjs} +2 -2
  24. package/dist/{chunk-IBRHSH5H.js → chunk-EXBGIC66.js} +1 -1
  25. package/dist/{chunk-W6WR37HN.js → chunk-FC5N5QHJ.js} +2 -2
  26. package/dist/{chunk-6MLAZPBL.mjs → chunk-FNWOH2T2.js} +18 -6
  27. package/dist/{chunk-AJMKZXRB.cjs → chunk-FYWWU3Z7.cjs} +2 -2
  28. package/dist/{chunk-IFRBVMWJ.cjs → chunk-GOEO763K.cjs} +21 -21
  29. package/dist/{chunk-S4HHFUYP.js → chunk-GXOIUBKE.js} +2 -2
  30. package/dist/{chunk-BG5RNEA2.js → chunk-H4ZRUQZL.js} +4 -4
  31. package/dist/{chunk-OI4ESUMC.mjs → chunk-HW2CLRJ3.mjs} +6 -6
  32. package/dist/{chunk-3PHU7FWS.js → chunk-JWFOWPMB.js} +163 -155
  33. package/dist/{chunk-OT2TESZU.mjs → chunk-KAPZHDO4.mjs} +1 -1
  34. package/dist/{chunk-ELLF55ER.mjs → chunk-KDXNWGPB.mjs} +1 -1
  35. package/dist/{chunk-UUMKZJRJ.cjs → chunk-KPOL2YEO.cjs} +18 -6
  36. package/dist/{chunk-2SLT3X6G.cjs → chunk-MA74OYCI.cjs} +6 -6
  37. package/dist/{chunk-2QNREG6K.mjs → chunk-MUMBUXU6.mjs} +264 -133
  38. package/dist/{chunk-YTX2JYYP.cjs → chunk-NQW3YUFN.cjs} +18 -18
  39. package/dist/{chunk-3PFZGP23.cjs → chunk-OO7BGCC3.cjs} +54 -34
  40. package/dist/{chunk-QCOLAHU3.mjs → chunk-OX6MF7SZ.mjs} +163 -155
  41. package/dist/{chunk-KHACHFBQ.cjs → chunk-QBVS3UYN.cjs} +245 -237
  42. package/dist/{chunk-H5GYX7RZ.js → chunk-RZGB3DXR.js} +292 -36
  43. package/dist/{chunk-KRYP6CAE.mjs → chunk-URVS2OE2.mjs} +3 -3
  44. package/dist/{chunk-HCJ4S3YB.js → chunk-UZQ3BB6W.mjs} +18 -6
  45. package/dist/{chunk-N6QNSTWD.cjs → chunk-YQWZ7FZX.cjs} +5 -5
  46. package/dist/{chunk-5XADBMSU.cjs → chunk-Z2YIDHRI.cjs} +5 -5
  47. package/dist/{chunk-SSQJKDN3.cjs → chunk-ZDZNV6NA.cjs} +286 -155
  48. package/dist/core/index.cjs +14 -8
  49. package/dist/core/index.d.ts +6 -6
  50. package/dist/core/index.js +13 -7
  51. package/dist/core/index.mjs +13 -7
  52. package/dist/{defaultClient-DhpCQW9m.d.ts → defaultClient-Cid0JoUR.d.ts} +29 -4
  53. package/dist/{effect-CtUDl5M5.d.ts → effect-DnGUuhw6.d.ts} +22 -1
  54. package/dist/http/index.cjs +58 -54
  55. package/dist/http/index.d.ts +8 -8
  56. package/dist/http/index.js +11 -7
  57. package/dist/http/index.mjs +11 -7
  58. package/dist/http/testing.cjs +9 -9
  59. package/dist/http/testing.d.ts +4 -4
  60. package/dist/http/testing.js +5 -5
  61. package/dist/http/testing.mjs +5 -5
  62. package/dist/index.cjs +92 -86
  63. package/dist/index.d.ts +7 -7
  64. package/dist/index.js +14 -8
  65. package/dist/index.mjs +14 -8
  66. package/dist/{layer-BalPI6cN.d.ts → layer-D2LFcBVx.d.ts} +1 -1
  67. package/dist/observability/index.cjs +10 -10
  68. package/dist/observability/index.d.ts +7 -7
  69. package/dist/observability/index.js +9 -9
  70. package/dist/observability/index.mjs +9 -9
  71. package/dist/perf/cli.cjs +26 -26
  72. package/dist/perf/cli.js +11 -11
  73. package/dist/perf/cli.mjs +11 -11
  74. package/dist/perf/index.cjs +13 -13
  75. package/dist/perf/index.js +11 -11
  76. package/dist/perf/index.mjs +11 -11
  77. package/dist/schema/index.cjs +2 -2
  78. package/dist/schema/index.js +1 -1
  79. package/dist/schema/index.mjs +1 -1
  80. package/dist/{server-C1zVmqE6.d.ts → server-Bf1zNYZk.d.ts} +4 -4
  81. package/dist/{stream-Bb4FTejt.d.ts → stream-I7bkvF7a.d.ts} +1 -1
  82. package/dist/{tracer-DzfuE6um.d.ts → tracer-DF83nLn6.d.ts} +2 -2
  83. package/dist/{tracing-BABA5arE.d.ts → tracing-CWV4gT0u.d.ts} +1 -1
  84. package/package.json +3 -2
@@ -3,18 +3,18 @@ import {
3
3
  } from "./chunk-TRM4JUZQ.js";
4
4
  import {
5
5
  streamFromReadableStream
6
- } from "./chunk-JH4GI3DW.js";
6
+ } from "./chunk-4PKBNG2H.js";
7
7
  import {
8
8
  layerEffect,
9
9
  makeScheduleDriver,
10
10
  makeServiceTag,
11
11
  sleep
12
- } from "./chunk-IBRHSH5H.js";
12
+ } from "./chunk-EXBGIC66.js";
13
13
  import {
14
14
  fromPromiseAbortable,
15
15
  resolveWasmModule,
16
16
  toPromise
17
- } from "./chunk-XSAHV5HQ.js";
17
+ } from "./chunk-APQBU7TM.js";
18
18
  import {
19
19
  Cause,
20
20
  asyncEffect,
@@ -33,7 +33,7 @@ import {
33
33
  makeSchemaIssue,
34
34
  parseConfig,
35
35
  validateValue
36
- } from "./chunk-HCJ4S3YB.js";
36
+ } from "./chunk-FNWOH2T2.js";
37
37
  import {
38
38
  __require
39
39
  } from "./chunk-3RG5ZIWI.js";
@@ -678,6 +678,18 @@ var HttpConcurrencyPool = class {
678
678
  acquire(key, signal) {
679
679
  return this.wasm ? this.acquireWasm(key, signal) : this.acquireJs(key, signal);
680
680
  }
681
+ /** Try synchronous acquire. Returns lease directly or undefined if contended. */
682
+ tryAcquireSync(key, signal) {
683
+ if (this.wasm) return void 0;
684
+ if (signal.aborted) return void 0;
685
+ const state = this.getState(key);
686
+ if (state.running < this.concurrency) {
687
+ state.running++;
688
+ state.acquired++;
689
+ return this.makeLease(state);
690
+ }
691
+ return void 0;
692
+ }
681
693
  stats() {
682
694
  const keys = Array.from(this.states.values()).map((state) => ({
683
695
  key: state.key,
@@ -1516,6 +1528,24 @@ var AdaptiveLimiter = class {
1516
1528
  this.enqueueWaiter(state, waiter);
1517
1529
  });
1518
1530
  }
1531
+ /**
1532
+ * Try to acquire a concurrency slot synchronously.
1533
+ * Returns a lease directly if under the limit, or undefined if contended/aborted/destroyed.
1534
+ * This avoids Promise.resolve() allocation and microtask scheduling on the uncontended path.
1535
+ */
1536
+ tryAcquireSync(key, signal) {
1537
+ if (this.destroyed) return void 0;
1538
+ if (signal.aborted) return void 0;
1539
+ const state = this.getOrCreateState(key);
1540
+ this.touch(state);
1541
+ if (state.inFlight < state.limit) {
1542
+ state.inFlight++;
1543
+ state.acquired++;
1544
+ state.rejectionStreak = 0;
1545
+ return this.makeLease(state);
1546
+ }
1547
+ return void 0;
1548
+ }
1519
1549
  /**
1520
1550
  * Get stats for a specific key, or aggregate stats if no key is provided.
1521
1551
  */
@@ -2194,6 +2224,9 @@ var mergeHeadersUnder = (under) => (req) => Lens.over(Request.headers, (h) => ({
2194
2224
  var setHeaderIfMissing = (k, v) => (req) => Lens.over(Request.headers, (h) => h[k] ? h : { ...h, [k]: v })(req);
2195
2225
 
2196
2226
  // src/http/transport.ts
2227
+ function isPromiseTransportDirect(transport) {
2228
+ return transport.__promiseTransport === true;
2229
+ }
2197
2230
  var isTaggedHttpError = (error) => {
2198
2231
  return isHttpError(error);
2199
2232
  };
@@ -2281,6 +2314,7 @@ var linkAbortSignals = (...signals) => {
2281
2314
  };
2282
2315
  };
2283
2316
  var nowMs = () => typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
2317
+ var isThenable = (value) => value !== null && typeof value === "object" && typeof value.then === "function";
2284
2318
  var hasMethod = (value, name) => typeof value === "object" && value !== null && typeof value[name] === "function";
2285
2319
  var defaultPromiseBody = (response, mode) => {
2286
2320
  if (mode === "json" && hasMethod(response, "json")) return response.json();
@@ -2325,49 +2359,107 @@ var toPromiseTransportResponse = (bodyText, info) => ({
2325
2359
  ...info.transportMeta !== void 0 ? { transportMeta: info.transportMeta } : {}
2326
2360
  });
2327
2361
  function makePromiseHttpTransport(config) {
2328
- return (context) => asyncEffect((_env, cb) => {
2362
+ const transport = (context) => asyncEffect((_env, cb) => {
2329
2363
  let done = false;
2364
+ const signal = context.signal;
2365
+ const needsAbortListener = signal !== globalThis.__brassNoopSignal;
2366
+ let abort;
2330
2367
  const finish = (exit) => {
2331
2368
  if (done) return;
2332
2369
  done = true;
2333
- context.signal.removeEventListener("abort", abort);
2370
+ if (needsAbortListener && abort) signal.removeEventListener("abort", abort);
2334
2371
  cb(exit);
2335
2372
  };
2336
2373
  const fail = (error) => finish({ _tag: "Failure", cause: Cause.fail(error) });
2337
- const abort = () => fail(abortErrorForSignal(context.signal));
2338
- if (context.signal.aborted) {
2339
- abort();
2374
+ if (signal.aborted) {
2375
+ fail(abortErrorForSignal(signal));
2340
2376
  return;
2341
2377
  }
2342
- context.signal.addEventListener("abort", abort, { once: true });
2343
- const run = async () => {
2344
- const startedAt = nowMs();
2345
- try {
2346
- const raw = await config.request(context);
2378
+ if (needsAbortListener) {
2379
+ abort = () => fail(abortErrorForSignal(signal));
2380
+ signal.addEventListener("abort", abort, { once: true });
2381
+ }
2382
+ const startedAt = nowMs();
2383
+ let requestPromise;
2384
+ try {
2385
+ const result = config.request(context);
2386
+ requestPromise = isThenable(result) ? result : Promise.resolve(result);
2387
+ } catch (error) {
2388
+ if (signal.aborted) {
2389
+ fail(abortErrorForSignal(signal));
2390
+ return;
2391
+ }
2392
+ fail(config.error?.(error, context) ?? normalizeHttpError(error, { signal }));
2393
+ return;
2394
+ }
2395
+ requestPromise.then(
2396
+ (raw) => {
2397
+ if (done) return;
2347
2398
  const durationMs = Math.round(nowMs() - startedAt);
2348
- const mapped = await config.response(raw, context, { startedAt, durationMs });
2349
- finish({
2350
- _tag: "Success",
2351
- value: {
2352
- ...mapped,
2353
- ms: mapped.ms ?? durationMs
2399
+ try {
2400
+ const r = config.response(raw, context, { startedAt, durationMs });
2401
+ if (!isThenable(r)) {
2402
+ const mapped = r;
2403
+ finish({
2404
+ _tag: "Success",
2405
+ value: mapped.ms !== void 0 ? mapped : { ...mapped, ms: durationMs }
2406
+ });
2407
+ return;
2354
2408
  }
2355
- });
2356
- } catch (error) {
2357
- if (context.signal.aborted) {
2358
- fail(abortErrorForSignal(context.signal));
2409
+ r.then(
2410
+ (m) => {
2411
+ if (done) return;
2412
+ finish({
2413
+ _tag: "Success",
2414
+ value: m.ms !== void 0 ? m : { ...m, ms: durationMs }
2415
+ });
2416
+ },
2417
+ (error) => {
2418
+ if (done) return;
2419
+ if (signal.aborted) {
2420
+ fail(abortErrorForSignal(signal));
2421
+ return;
2422
+ }
2423
+ fail(config.error?.(error, context) ?? normalizeHttpError(error, { signal }));
2424
+ }
2425
+ );
2426
+ } catch (error) {
2427
+ if (signal.aborted) {
2428
+ fail(abortErrorForSignal(signal));
2429
+ return;
2430
+ }
2431
+ fail(config.error?.(error, context) ?? normalizeHttpError(error, { signal }));
2432
+ }
2433
+ },
2434
+ (error) => {
2435
+ if (done) return;
2436
+ if (signal.aborted) {
2437
+ fail(abortErrorForSignal(signal));
2359
2438
  return;
2360
2439
  }
2361
- fail(config.error?.(error, context) ?? normalizeHttpError(error, { signal: context.signal }));
2440
+ fail(config.error?.(error, context) ?? normalizeHttpError(error, { signal }));
2362
2441
  }
2363
- };
2364
- void run();
2442
+ );
2365
2443
  return () => {
2366
2444
  if (done) return;
2367
2445
  done = true;
2368
- context.signal.removeEventListener("abort", abort);
2446
+ if (needsAbortListener && abort) signal.removeEventListener("abort", abort);
2369
2447
  };
2370
2448
  });
2449
+ const marked = transport;
2450
+ marked.__promiseTransport = true;
2451
+ marked.requestDirect = async (context) => {
2452
+ const startedAt = nowMs();
2453
+ try {
2454
+ const raw = await config.request(context);
2455
+ const durationMs = Math.round(nowMs() - startedAt);
2456
+ const mapped = await config.response(raw, context, { startedAt, durationMs });
2457
+ return { ...mapped, ms: mapped.ms ?? durationMs };
2458
+ } catch (error) {
2459
+ throw config.error?.(error, context) ?? normalizeHttpError(error, { signal: context.signal });
2460
+ }
2461
+ };
2462
+ return marked;
2371
2463
  }
2372
2464
  function makePromiseHttpTransportBodyBuilder(config) {
2373
2465
  const makeBodyTransport = (mode, body, responseMapper, currentConfig = config) => makePromiseHttpTransport({
@@ -3083,6 +3175,13 @@ function makeHttpStream(cfg = {}) {
3083
3175
  };
3084
3176
  return decorateStream(run, metrics.snapshot);
3085
3177
  }
3178
+ var ONCE_OPTIONS = Object.freeze({ once: true });
3179
+ var noopSignal = (() => {
3180
+ const c = new AbortController();
3181
+ const s = c.signal;
3182
+ globalThis.__brassNoopSignal = s;
3183
+ return s;
3184
+ })();
3086
3185
  function makeHttp(cfg = {}) {
3087
3186
  validateMakeHttpConfig(cfg);
3088
3187
  const baseUrl = cfg.baseUrl ?? "";
@@ -3226,6 +3325,53 @@ function httpBodyKeyPart(body) {
3226
3325
  // src/http/lifecycle/cacheKey.ts
3227
3326
  var SEPARATOR = "\0";
3228
3327
  var DEFAULT_CACHE_RELEVANT_HEADERS = ["accept", "authorization", "content-type"];
3328
+ function makeCacheKeyContext(baseUrl, extraHeaders = []) {
3329
+ const relevantSet = new Set(DEFAULT_CACHE_RELEVANT_HEADERS);
3330
+ for (let i = 0; i < extraHeaders.length; i++) {
3331
+ relevantSet.add(extraHeaders[i].toLowerCase());
3332
+ }
3333
+ return {
3334
+ baseUrl,
3335
+ relevantSet,
3336
+ cachedOrigin: baseUrl ? absoluteOrigin(baseUrl) : void 0
3337
+ };
3338
+ }
3339
+ function computeCacheKeyFast(req, ctx) {
3340
+ const m = req.method;
3341
+ const method = m === "GET" || m === "POST" || m === "PUT" || m === "DELETE" || m === "PATCH" || m === "HEAD" || m === "OPTIONS" ? m : m.toUpperCase();
3342
+ let resolvedUrl;
3343
+ const url = req.url;
3344
+ if (ctx.cachedOrigin && url.length > 0 && url.charCodeAt(0) === 47 && url.charCodeAt(1) !== 47) {
3345
+ resolvedUrl = ctx.cachedOrigin + url;
3346
+ } else {
3347
+ resolvedUrl = new URL(url, ctx.baseUrl || void 0).toString();
3348
+ }
3349
+ const headers = req.headers;
3350
+ let sortedHeaders = "";
3351
+ if (headers) {
3352
+ const keys = Object.keys(headers);
3353
+ if (keys.length > 0) {
3354
+ const matched = [];
3355
+ for (let i = 0; i < keys.length; i++) {
3356
+ const k = keys[i];
3357
+ const lk = k.toLowerCase();
3358
+ if (ctx.relevantSet.has(lk)) {
3359
+ matched.push(`${lk}:${headers[k]}`);
3360
+ }
3361
+ }
3362
+ if (matched.length > 0) {
3363
+ if (matched.length === 1) {
3364
+ sortedHeaders = matched[0];
3365
+ } else {
3366
+ matched.sort();
3367
+ sortedHeaders = matched.join(",");
3368
+ }
3369
+ }
3370
+ }
3371
+ }
3372
+ const body = httpBodyKeyPart(req.body);
3373
+ return `${method}${SEPARATOR}${resolvedUrl}${SEPARATOR}${sortedHeaders}${SEPARATOR}${body}`;
3374
+ }
3229
3375
  function computeCacheKey(req, baseUrl, extraHeaders = []) {
3230
3376
  const method = req.method.toUpperCase();
3231
3377
  const resolvedUrl = resolveKeyUrl(req.url, baseUrl);
@@ -3279,6 +3425,48 @@ var HOP_BY_HOP = /* @__PURE__ */ new Set([
3279
3425
  "upgrade"
3280
3426
  ]);
3281
3427
  var SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
3428
+ function makeDedupKeyContext(baseUrl) {
3429
+ return {
3430
+ baseUrl,
3431
+ cachedOrigin: baseUrl ? absoluteOrigin(baseUrl) : void 0
3432
+ };
3433
+ }
3434
+ function computeDedupKeyFast(req, ctx) {
3435
+ const m = req.method;
3436
+ const method = m === "GET" || m === "POST" || m === "PUT" || m === "DELETE" || m === "PATCH" || m === "HEAD" || m === "OPTIONS" ? m : m.toUpperCase();
3437
+ let resolvedUrl;
3438
+ const url = req.url;
3439
+ if (ctx.cachedOrigin && url.length > 0 && url.charCodeAt(0) === 47 && url.charCodeAt(1) !== 47) {
3440
+ resolvedUrl = ctx.cachedOrigin + url;
3441
+ } else {
3442
+ resolvedUrl = resolveKeyUrl(url, ctx.baseUrl);
3443
+ }
3444
+ const headers = req.headers;
3445
+ let sortedHeaders = "";
3446
+ if (headers) {
3447
+ const keys = Object.keys(headers);
3448
+ if (keys.length > 0) {
3449
+ const matched = [];
3450
+ for (let i = 0; i < keys.length; i++) {
3451
+ const k = keys[i];
3452
+ const lk = k.toLowerCase();
3453
+ if (!HOP_BY_HOP.has(lk) && lk !== "authorization") {
3454
+ matched.push(`${lk}:${headers[k]}`);
3455
+ }
3456
+ }
3457
+ if (matched.length > 0) {
3458
+ if (matched.length === 1) {
3459
+ sortedHeaders = matched[0];
3460
+ } else {
3461
+ matched.sort();
3462
+ sortedHeaders = matched.join(",");
3463
+ }
3464
+ }
3465
+ }
3466
+ }
3467
+ const body = httpBodyKeyPart(req.body);
3468
+ return `${method}${SEPARATOR}${resolvedUrl}${SEPARATOR}${sortedHeaders}${SEPARATOR}${body}`;
3469
+ }
3282
3470
  function computeDedupKey(req, baseUrl) {
3283
3471
  const method = req.method.toUpperCase();
3284
3472
  const resolvedUrl = resolveKeyUrl(req.url, baseUrl);
@@ -3308,6 +3496,7 @@ function withDedup(config) {
3308
3496
  const inFlight = /* @__PURE__ */ new Map();
3309
3497
  const customKeyFn = config?.dedupKey;
3310
3498
  const onEvent = config?.onEvent;
3499
+ const dedupKeyCtx = makeDedupKeyContext("");
3311
3500
  return (next) => {
3312
3501
  return (req) => {
3313
3502
  if (!SAFE_METHODS.has(req.method.toUpperCase())) {
@@ -3330,7 +3519,7 @@ function withDedup(config) {
3330
3519
  return next(req);
3331
3520
  }
3332
3521
  } else {
3333
- key = computeDedupKey(req, "");
3522
+ key = computeDedupKeyFast(req, dedupKeyCtx);
3334
3523
  }
3335
3524
  return {
3336
3525
  _tag: "Async",
@@ -3859,6 +4048,7 @@ function withCache(config) {
3859
4048
  const baseUrl = config?.baseUrl ?? "";
3860
4049
  const onEvent = config?.onEvent;
3861
4050
  const onLifecycleEvent = config?.onLifecycleEvent;
4051
+ const cacheKeyCtx = makeCacheKeyContext(baseUrl, cacheRelevantHeaders);
3862
4052
  const cache = new LRUCache({
3863
4053
  maxEntries,
3864
4054
  onEvict: (count) => onLifecycleEvent?.({ type: "cache-eviction", count })
@@ -3876,7 +4066,7 @@ function withCache(config) {
3876
4066
  if (!SAFE_METHODS.has(method) && !cachePolicy) {
3877
4067
  return next(req);
3878
4068
  }
3879
- const key = computeCacheKey(req, baseUrl, cacheRelevantHeaders);
4069
+ const key = computeCacheKeyFast(req, cacheKeyCtx);
3880
4070
  return {
3881
4071
  _tag: "Async",
3882
4072
  register: (env, cb) => {
@@ -3935,7 +4125,7 @@ function withCache(config) {
3935
4125
  if (!SAFE_METHODS.has(method) && !cachePolicy) {
3936
4126
  return next(req);
3937
4127
  }
3938
- const key = computeCacheKey(req, baseUrl, cacheRelevantHeaders);
4128
+ const key = computeCacheKeyFast(req, cacheKeyCtx);
3939
4129
  return {
3940
4130
  _tag: "Async",
3941
4131
  register: (env, cb) => {
@@ -5649,16 +5839,21 @@ function decodeJsonBody(bodyText, validator, options = {}) {
5649
5839
  };
5650
5840
  }
5651
5841
  if (!validator) return { success: true, data: parsed };
5842
+ let validation;
5652
5843
  let legacyMessage;
5653
- const validation = isSchema(validator) ? validator.safeParse(parsed) : (() => {
5844
+ if (isSchema(validator)) {
5845
+ validation = validator.safeParse(parsed);
5846
+ } else {
5654
5847
  const result = validator(parsed);
5655
- if (result.success) return { success: true, data: result.data };
5848
+ if (result.success) {
5849
+ return { success: true, data: result.data };
5850
+ }
5656
5851
  legacyMessage = result.error;
5657
- return {
5852
+ validation = {
5658
5853
  success: false,
5659
5854
  issues: result.issues ?? [makeSchemaIssue([], "valid JSON shape", parsed, result.error)]
5660
5855
  };
5661
- })();
5856
+ }
5662
5857
  if (validation.success) return { success: true, data: validation.data };
5663
5858
  return {
5664
5859
  success: false,
@@ -5702,6 +5897,13 @@ function encodeJsonBodyEffect(bodyObj, validator, options = {}) {
5702
5897
  }
5703
5898
  }
5704
5899
  function decodeJsonBodyEffect(bodyText, validator, options) {
5900
+ if (!validator) {
5901
+ try {
5902
+ return asyncSucceed(JSON.parse(bodyText));
5903
+ } catch (error) {
5904
+ return asyncFail(makeJsonParseValidationError(bodyText, error, options ?? {}));
5905
+ }
5906
+ }
5705
5907
  const result = decodeJsonBody(bodyText, validator, options);
5706
5908
  return result.success ? asyncSucceed(result.data) : asyncFail(result.error);
5707
5909
  }
@@ -5867,10 +6069,14 @@ function makeDefaultHttpClient(config = {}) {
5867
6069
  wire = wire.with(withHttpPolicyPresets(policyPresets));
5868
6070
  }
5869
6071
  const features = featureSnapshot(lifecycleConfig2, compressionResult !== void 0, middleware.length);
6072
+ const hasMiddleware = compressionResult !== void 0 || middleware.length > 0 || policyPresets !== void 0 && Object.keys(policyPresets).length > 0;
6073
+ const transport = lifecycleConfig2.transport;
6074
+ const useInlineDecode = !hasMiddleware && transport !== void 0;
5870
6075
  return buildDefaultClient(wire, {
5871
6076
  preset,
5872
6077
  features,
5873
- compressionStats: compressionResult?.stats
6078
+ compressionStats: compressionResult?.stats,
6079
+ useInlineDecode
5874
6080
  });
5875
6081
  }
5876
6082
  function buildDefaultClient(wire, meta) {
@@ -5889,6 +6095,11 @@ function buildDefaultClient(wire, meta) {
5889
6095
  const req = setHeaderIfMissing("accept", "application/json")(
5890
6096
  buildHttpRequest("GET", url, init)
5891
6097
  );
6098
+ if (meta.useInlineDecode) {
6099
+ return withPromise(
6100
+ fusedWireAndDecode(requestRaw(req), init?.schema, init?.schemaName)
6101
+ );
6102
+ }
5892
6103
  return withPromise(
5893
6104
  asyncFlatMap(requestRaw(req), (w) => decodeResponse(w, init?.schema, init?.schemaName))
5894
6105
  );
@@ -5917,6 +6128,7 @@ function buildDefaultClient(wire, meta) {
5917
6128
  postJson,
5918
6129
  with: (mw) => buildDefaultClient(wire.with(mw), {
5919
6130
  ...meta,
6131
+ useInlineDecode: false,
5920
6132
  features: {
5921
6133
  ...meta.features,
5922
6134
  middleware: meta.features.middleware + 1
@@ -5944,6 +6156,48 @@ function toResponse(wire, body) {
5944
6156
  body
5945
6157
  };
5946
6158
  }
6159
+ function fusedWireAndDecode(wireEffect, schema, schemaName) {
6160
+ return {
6161
+ _tag: "Async",
6162
+ register: (env, cb) => {
6163
+ const innerEffect = wireEffect;
6164
+ if (innerEffect._tag === "Async" && innerEffect.register) {
6165
+ return innerEffect.register(env, (exit) => {
6166
+ if (exit._tag !== "Success") {
6167
+ cb(exit);
6168
+ return;
6169
+ }
6170
+ const wire = exit.value;
6171
+ inlineDecodeJson(wire, schema, schemaName, cb);
6172
+ });
6173
+ }
6174
+ const decoded = asyncFlatMap(wireEffect, (w) => decodeResponse(w, schema, schemaName));
6175
+ if (decoded._tag === "Async" && decoded.register) {
6176
+ return decoded.register(env, cb);
6177
+ }
6178
+ cb({ _tag: "Failure", cause: Cause.fail({ _tag: "ValidationError", message: "Internal: unexpected effect shape", body: "", issues: [], phase: "response" }) });
6179
+ }
6180
+ };
6181
+ }
6182
+ function inlineDecodeJson(wire, schema, schemaName, cb) {
6183
+ if (!schema) {
6184
+ let parsed;
6185
+ try {
6186
+ parsed = JSON.parse(wire.bodyText);
6187
+ } catch (error) {
6188
+ cb({ _tag: "Failure", cause: Cause.fail(makeJsonParseValidationError(wire.bodyText, error, { schemaName })) });
6189
+ return;
6190
+ }
6191
+ cb({ _tag: "Success", value: toResponse(wire, parsed) });
6192
+ return;
6193
+ }
6194
+ const result = decodeJsonBody(wire.bodyText, schema, { schemaName });
6195
+ if (result.success) {
6196
+ cb({ _tag: "Success", value: toResponse(wire, result.data) });
6197
+ } else {
6198
+ cb({ _tag: "Failure", cause: Cause.fail(result.error) });
6199
+ }
6200
+ }
5947
6201
  function decodeResponse(wire, schema, schemaName) {
5948
6202
  if (!schema) {
5949
6203
  try {
@@ -6069,6 +6323,7 @@ export {
6069
6323
  validateConfig,
6070
6324
  resolveConfig,
6071
6325
  AdaptiveLimiter,
6326
+ isPromiseTransportDirect,
6072
6327
  isTaggedHttpError,
6073
6328
  isAbortError,
6074
6329
  normalizeHttpError,
@@ -6084,6 +6339,7 @@ export {
6084
6339
  withMiddleware,
6085
6340
  normalizeHeadersInit,
6086
6341
  makeHttpStream,
6342
+ noopSignal,
6087
6343
  makeHttp,
6088
6344
  withRetryStream,
6089
6345
  SEPARATOR,
@@ -2,14 +2,14 @@ import {
2
2
  EventBus,
3
3
  InMemoryTracer,
4
4
  makeMetrics
5
- } from "./chunk-OT2TESZU.mjs";
5
+ } from "./chunk-KAPZHDO4.mjs";
6
6
  import {
7
7
  Runtime,
8
8
  ctxExtend,
9
9
  ctxToObject,
10
10
  emptyContext,
11
11
  getCurrentFiber
12
- } from "./chunk-2QNREG6K.mjs";
12
+ } from "./chunk-MUMBUXU6.mjs";
13
13
  import {
14
14
  asyncFail,
15
15
  asyncFlatMap,
@@ -20,7 +20,7 @@ import {
20
20
  import {
21
21
  Schema,
22
22
  parseConfig
23
- } from "./chunk-6MLAZPBL.mjs";
23
+ } from "./chunk-UZQ3BB6W.mjs";
24
24
 
25
25
  // src/observability/health.ts
26
26
  function snapshotRuntimeHealth(options = {}) {
@@ -237,7 +237,14 @@ function arraySchema(item) {
237
237
  function objectSchema(shape, options = {}) {
238
238
  const unknownKeys = options.unknownKeys ?? "strip";
239
239
  const shapeEntries = Object.entries(shape);
240
- const knownKeys = unknownKeys === "strict" ? new Set(shapeEntries.map(([key]) => key)) : void 0;
240
+ const fieldKeys = new Array(shapeEntries.length);
241
+ const fieldSchemas = new Array(shapeEntries.length);
242
+ for (let i = 0; i < shapeEntries.length; i++) {
243
+ fieldKeys[i] = shapeEntries[i][0];
244
+ fieldSchemas[i] = shapeEntries[i][1];
245
+ }
246
+ const fieldCount = fieldKeys.length;
247
+ const knownKeys = unknownKeys === "strict" ? new Set(fieldKeys) : void 0;
241
248
  return makeSchema("object", false, (input, path) => {
242
249
  if (typeof input !== "object" || input === null || Array.isArray(input)) {
243
250
  return fail([makeSchemaIssue(path, options.name ?? "object", input)]);
@@ -246,11 +253,13 @@ function objectSchema(shape, options = {}) {
246
253
  const out = unknownKeys === "passthrough" ? { ...source } : {};
247
254
  const childPath = path.length === 0 ? [] : [...path];
248
255
  let issues;
249
- for (const [key, fieldSchema] of shapeEntries) {
256
+ for (let i = 0; i < fieldCount; i++) {
257
+ const key = fieldKeys[i];
258
+ const fieldSchema = fieldSchemas[i];
250
259
  childPath.push(key);
251
260
  if (!(key in source)) {
252
261
  if (!fieldSchema.isOptional) {
253
- issues ??= [];
262
+ if (!issues) issues = [];
254
263
  issues.push(makeSchemaIssue(childPath, fieldSchema.name ?? fieldSchema.kind, void 0, "Required field is missing"));
255
264
  }
256
265
  childPath.pop();
@@ -261,15 +270,18 @@ function objectSchema(shape, options = {}) {
261
270
  if (result.success) {
262
271
  out[key] = result.data;
263
272
  } else {
264
- issues ??= [];
265
- issues.push(...result.issues);
273
+ if (!issues) issues = [];
274
+ const resultIssues = result.issues;
275
+ for (let j = 0; j < resultIssues.length; j++) {
276
+ issues.push(resultIssues[j]);
277
+ }
266
278
  }
267
279
  }
268
280
  if (knownKeys) {
269
281
  for (const key of Object.keys(source)) {
270
282
  if (!knownKeys.has(key)) {
271
283
  childPath.push(key);
272
- issues ??= [];
284
+ if (!issues) issues = [];
273
285
  issues.push(makeSchemaIssue(childPath, "known key", source[key], "Unknown key is not allowed"));
274
286
  childPath.pop();
275
287
  }
@@ -1,10 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkAJMKZXRBcjs = require('./chunk-AJMKZXRB.cjs');
3
+ var _chunkFYWWU3Z7cjs = require('./chunk-FYWWU3Z7.cjs');
4
4
 
5
5
 
6
6
 
7
- var _chunkSSQJKDN3cjs = require('./chunk-SSQJKDN3.cjs');
7
+ var _chunkZDZNV6NAcjs = require('./chunk-ZDZNV6NA.cjs');
8
8
 
9
9
 
10
10
 
@@ -73,9 +73,9 @@ function fiberRefSnapshot() {
73
73
  return new Map(currentFiberRefs(false));
74
74
  }
75
75
  function currentFiberRefs(create) {
76
- const fiber = _chunkSSQJKDN3cjs.getCurrentFiber.call(void 0, );
76
+ const fiber = _chunkZDZNV6NAcjs.getCurrentFiber.call(void 0, );
77
77
  if (!fiber) return void 0;
78
- fiber.fiberContext ??= { log: _chunkSSQJKDN3cjs.emptyContext, trace: null };
78
+ fiber.fiberContext ??= { log: _chunkZDZNV6NAcjs.emptyContext, trace: null };
79
79
  if (!fiber.fiberContext.fiberRefs && create) fiber.fiberContext.fiberRefs = /* @__PURE__ */ new Map();
80
80
  return fiber.fiberContext.fiberRefs;
81
81
  }
@@ -98,7 +98,7 @@ function makeRuntimeRecorder(options = {}) {
98
98
  return out;
99
99
  };
100
100
  const emit = (ev, ctx) => {
101
- records[next] = _chunkAJMKZXRBcjs.makeRuntimeEventRecord.call(void 0, ev, ctx, seq++);
101
+ records[next] = _chunkFYWWU3Z7cjs.makeRuntimeEventRecord.call(void 0, ev, ctx, seq++);
102
102
  next = (next + 1) % capacity;
103
103
  if (size < capacity) size++;
104
104
  else dropped++;
@@ -1,22 +1,22 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunk7TXQJFZXcjs = require('./chunk-7TXQJFZX.cjs');
4
+ var _chunk6STX4PS3cjs = require('./chunk-6STX4PS3.cjs');
5
5
 
6
6
 
7
- var _chunkSSQJKDN3cjs = require('./chunk-SSQJKDN3.cjs');
7
+ var _chunkZDZNV6NAcjs = require('./chunk-ZDZNV6NA.cjs');
8
8
 
9
9
 
10
10
  var _chunkMVGUEJ5Zcjs = require('./chunk-MVGUEJ5Z.cjs');
11
11
 
12
12
  // src/core/runtime/runtimeLayer.ts
13
- var RuntimeService = _chunk7TXQJFZXcjs.makeServiceTag.call(void 0, "Runtime");
13
+ var RuntimeService = _chunk6STX4PS3cjs.makeServiceTag.call(void 0, "Runtime");
14
14
  function makeRuntimeLayer(env = {}, options = {}) {
15
15
  const { tag = RuntimeService, ...runtimeOptions } = options;
16
- return _chunk7TXQJFZXcjs.layerEffect.call(void 0,
16
+ return _chunk6STX4PS3cjs.layerEffect.call(void 0,
17
17
  tag,
18
18
  (context) => _chunkMVGUEJ5Zcjs.asyncSync.call(void 0,
19
- () => new (0, _chunkSSQJKDN3cjs.Runtime)({
19
+ () => new (0, _chunkZDZNV6NAcjs.Runtime)({
20
20
  ...runtimeOptions,
21
21
  env: resolveRuntimeLayerEnv(env, context)
22
22
  })