brass-runtime 1.19.2 → 1.20.0

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.
@@ -5638,14 +5638,14 @@ function noopInvalidate(_key) {
5638
5638
  }
5639
5639
  function noopClear() {
5640
5640
  }
5641
- function buildLifecycleClient(fn2, tracker, internals) {
5642
- const client = (req) => trackRequest(fn2, req, tracker, internals);
5641
+ function buildLifecycleClient(fn3, tracker, internals) {
5642
+ const client = (req) => trackRequest(fn3, req, tracker, internals);
5643
5643
  const stats = () => {
5644
5644
  tracker.setQueueDepth(internals.queueDepth?.() ?? 0);
5645
5645
  return tracker.snapshot();
5646
5646
  };
5647
5647
  const withMw = (mw) => {
5648
- const wrappedFn = mw(withLifecycleMetadata(fn2, internals));
5648
+ const wrappedFn = mw(withLifecycleMetadata(fn3, internals));
5649
5649
  return buildLifecycleClient(wrappedFn, tracker, internals);
5650
5650
  };
5651
5651
  const lifecycleClient = Object.assign(client, {
@@ -5661,9 +5661,9 @@ function buildLifecycleClient(fn2, tracker, internals) {
5661
5661
  });
5662
5662
  return lifecycleClient;
5663
5663
  }
5664
- function withLifecycleMetadata(fn2, internals) {
5665
- if (!internals.adaptiveLimiter) return fn2;
5666
- return Object.assign(((req) => fn2(req)), {
5664
+ function withLifecycleMetadata(fn3, internals) {
5665
+ if (!internals.adaptiveLimiter) return fn3;
5666
+ return Object.assign(((req) => fn3(req)), {
5667
5667
  adaptiveLimiter: internals.adaptiveLimiter
5668
5668
  });
5669
5669
  }
@@ -5684,7 +5684,7 @@ function shutdownClient(activeCancelers, prewarmMgr, wireShutdown) {
5684
5684
  wireShutdown?.();
5685
5685
  return asyncSucceed(void 0);
5686
5686
  }
5687
- function trackRequest(fn2, req, tracker, internals) {
5687
+ function trackRequest(fn3, req, tracker, internals) {
5688
5688
  return {
5689
5689
  _tag: "Async",
5690
5690
  register: (env, cb) => {
@@ -5746,7 +5746,7 @@ function trackRequest(fn2, req, tracker, internals) {
5746
5746
  return () => void 0;
5747
5747
  }
5748
5748
  try {
5749
- cancelInner = registerHttpEffect(fn2(req), env, finish);
5749
+ cancelInner = registerHttpEffect(fn3(req), env, finish);
5750
5750
  } catch (error) {
5751
5751
  finish({
5752
5752
  _tag: "Failure",
@@ -6168,6 +6168,190 @@ function previewJson(value) {
6168
6168
  }
6169
6169
  }
6170
6170
 
6171
+ // src/http/bareMetalClient.ts
6172
+ var fn2 = Schema.custom(
6173
+ (value) => typeof value === "function",
6174
+ "function"
6175
+ );
6176
+ var poolConfig2 = Schema.union([
6177
+ Schema.literal(false),
6178
+ Schema.object(
6179
+ {
6180
+ concurrency: Schema.number({ min: 1, int: true }).optional(),
6181
+ maxQueue: Schema.number({ min: 0, int: true }).optional(),
6182
+ queueTimeoutMs: Schema.number({ min: 1, int: true }).optional(),
6183
+ key: Schema.union([
6184
+ Schema.enum(["global", "origin", "host"]),
6185
+ fn2
6186
+ ]).optional(),
6187
+ engine: Schema.enum(["ts", "wasm"]).optional(),
6188
+ wasm: Schema.boolean().optional()
6189
+ },
6190
+ { unknownKeys: "passthrough" }
6191
+ )
6192
+ ]);
6193
+ var adaptiveLimiterConfig2 = Schema.union([
6194
+ Schema.literal(false),
6195
+ Schema.object(
6196
+ {
6197
+ preset: Schema.enum(["conservative", "balanced", "aggressive"]).optional(),
6198
+ initialLimit: Schema.number({ min: 1, int: true }).optional(),
6199
+ minLimit: Schema.number({ min: 1, int: true }).optional(),
6200
+ maxLimit: Schema.number({ min: 1, int: true }).optional(),
6201
+ smoothingFactor: Schema.number({ min: 0, max: 1 }).refine((n) => n > 0, "smoothingFactor must be in (0, 1]").optional(),
6202
+ probeInterval: Schema.number({ min: 1, int: true }).optional(),
6203
+ probeJitterRatio: Schema.number({ min: 0, max: 1 }).optional(),
6204
+ windowSize: Schema.number({ min: 2, int: true }).optional(),
6205
+ minSamples: Schema.number({ min: 1, int: true }).optional(),
6206
+ baselineStrategy: Schema.enum(["min", "p5", "ema-low"]).optional(),
6207
+ decreaseCooldownSamples: Schema.number({ min: 0, int: true }).optional(),
6208
+ historySize: Schema.number({ min: 0, int: true }).optional(),
6209
+ windowDecayFactor: Schema.number({ min: 0, max: 1 }).refine((n) => n > 0, "windowDecayFactor must be in (0, 1]").optional(),
6210
+ errorWeight: Schema.number({ min: 0, max: 1 }).optional(),
6211
+ errorSmoothingFactor: Schema.number({ min: 0, max: 1 }).refine((n) => n > 0, "errorSmoothingFactor must be in (0, 1]").optional(),
6212
+ errorStatusThreshold: Schema.number({ min: 100, max: 599, int: true }).optional(),
6213
+ queueStrategy: Schema.enum(["fifo", "priority"]).optional(),
6214
+ queueLoadShedding: Schema.enum(["reject-new", "priority-evict"]).optional(),
6215
+ rejectionBackoffThreshold: Schema.number({ min: 1, int: true }).optional(),
6216
+ rejectionBackoffMs: Schema.number({ min: 1, int: true }).optional(),
6217
+ stateTtlMs: Schema.union([Schema.literal(false), Schema.number({ min: 1, int: true })]).optional(),
6218
+ warmupRequests: Schema.number({ min: 0, int: true }).optional(),
6219
+ decreaseThreshold: Schema.number({ min: 0, max: 1 }).refine((n) => n > 0, "decreaseThreshold must be in (0, 1]").optional(),
6220
+ increaseThreshold: Schema.number({ min: 1 }).optional(),
6221
+ maxDecreaseRatio: Schema.number({ min: 0, max: 1 }).refine((n) => n > 0, "maxDecreaseRatio must be in (0, 1]").optional(),
6222
+ headroomStrategy: Schema.union([
6223
+ Schema.number({ min: 1 }),
6224
+ Schema.enum(["fixed", "proportional"]),
6225
+ fn2,
6226
+ Schema.object({ type: Schema.literal("fixed"), value: Schema.number({ min: 1 }).optional() }, { unknownKeys: "passthrough" }),
6227
+ Schema.object({
6228
+ type: Schema.literal("proportional"),
6229
+ ratio: Schema.number({ min: 0 }).refine((n) => n > 0, "ratio must be > 0").optional(),
6230
+ min: Schema.number({ min: 1 }).optional(),
6231
+ max: Schema.number({ min: 1 }).optional()
6232
+ }, { unknownKeys: "passthrough" })
6233
+ ]).optional(),
6234
+ slowStartRecovery: Schema.boolean().optional(),
6235
+ slowStartSaturationThreshold: Schema.number({ min: 0, max: 1 }).refine((n) => n > 0, "slowStartSaturationThreshold must be in (0, 1]").optional(),
6236
+ slowStartSaturationSamples: Schema.number({ min: 1, int: true }).optional(),
6237
+ key: Schema.union([Schema.enum(["global", "origin", "host"]), fn2]).optional(),
6238
+ maxQueue: Schema.number({ min: 0, int: true }).optional(),
6239
+ queueTimeoutMs: Schema.number({ min: 1, int: true }).optional(),
6240
+ onLimitChange: fn2.optional(),
6241
+ percentile: Schema.enum(["p50", "p99"]).optional()
6242
+ },
6243
+ { unknownKeys: "passthrough" }
6244
+ )
6245
+ ]);
6246
+ var bareMetalConfigSchema = Schema.object(
6247
+ {
6248
+ baseUrl: Schema.string().optional(),
6249
+ headers: Schema.record(Schema.string()).optional(),
6250
+ timeoutMs: Schema.number({ min: 1, int: true }).optional(),
6251
+ transport: fn2.optional(),
6252
+ streamTransport: fn2.optional(),
6253
+ pool: poolConfig2.optional(),
6254
+ adaptiveLimiter: adaptiveLimiterConfig2.optional(),
6255
+ onEvent: fn2.optional()
6256
+ },
6257
+ { unknownKeys: "passthrough" }
6258
+ );
6259
+ function validateBareMetalConfig(config) {
6260
+ parseConfig("BareMetalHttpConfig", bareMetalConfigSchema, config);
6261
+ }
6262
+ var transportDestroy2 = (transport) => {
6263
+ const destroy = transport.destroy;
6264
+ return typeof destroy === "function" ? () => destroy.call(transport) : void 0;
6265
+ };
6266
+ function makeBareMetalHttp(cfg = {}) {
6267
+ validateBareMetalConfig(cfg);
6268
+ const baseUrl = cfg.baseUrl ?? "";
6269
+ const defaultHeaders = cfg.headers ?? {};
6270
+ const normalize = normalizeRequest(defaultHeaders);
6271
+ const adaptiveLimiter = makeAdaptiveLimiter(cfg);
6272
+ const pool = adaptiveLimiter ? void 0 : makePool(cfg);
6273
+ const metrics = makeHttpStats(pool, adaptiveLimiter);
6274
+ const transport = cfg.transport ?? makeFetchTransport();
6275
+ const destroyTransport = transportDestroy2(transport);
6276
+ const run = (req0) => {
6277
+ const req = normalize(req0);
6278
+ const url = resolveRequestUrl(req, baseUrl);
6279
+ if (!(url instanceof URL)) return asyncFail(url);
6280
+ const timeoutMs = resolvePositiveTimeout(req.timeoutMs ?? cfg.timeoutMs);
6281
+ if (!adaptiveLimiter && !pool && timeoutMs === void 0) {
6282
+ return runDirectTransport(req, url, transport, metrics);
6283
+ }
6284
+ return runPoolTransport(req, url, transport, metrics, pool, adaptiveLimiter, void 0, timeoutMs);
6285
+ };
6286
+ const metadata = {};
6287
+ if (adaptiveLimiter) metadata.adaptiveLimiter = adaptiveLimiter;
6288
+ if (adaptiveLimiter || destroyTransport) {
6289
+ metadata.destroy = () => {
6290
+ adaptiveLimiter?.destroy();
6291
+ destroyTransport?.();
6292
+ };
6293
+ metadata.shutdown = () => {
6294
+ adaptiveLimiter?.shutdown();
6295
+ destroyTransport?.();
6296
+ };
6297
+ }
6298
+ return decorate(run, metrics.snapshot, metadata);
6299
+ }
6300
+ function makeBareMetalHttpStream(cfg = {}) {
6301
+ validateBareMetalConfig(cfg);
6302
+ const baseUrl = cfg.baseUrl ?? "";
6303
+ const defaultHeaders = cfg.headers ?? {};
6304
+ const normalize = normalizeRequest(defaultHeaders);
6305
+ const adaptiveLimiter = makeAdaptiveLimiter(cfg);
6306
+ const pool = adaptiveLimiter ? void 0 : makePool(cfg);
6307
+ const metrics = makeHttpStats(pool, adaptiveLimiter);
6308
+ const transport = cfg.streamTransport ?? makeFetchStreamTransport();
6309
+ const run = (req0) => {
6310
+ const req = normalize(req0);
6311
+ const url = resolveRequestUrl(req, baseUrl);
6312
+ if (!(url instanceof URL)) return asyncFail(url);
6313
+ const timeoutMs = resolvePositiveTimeout(req.timeoutMs ?? cfg.timeoutMs);
6314
+ return fromPromiseAbortable(
6315
+ async (signal, env) => {
6316
+ let lease;
6317
+ const linkedSignal = linkAbortSignals(signal, req.init?.signal);
6318
+ try {
6319
+ if (linkedSignal.signal.aborted) throw abortErrorForSignal(linkedSignal.signal);
6320
+ if (adaptiveLimiter) {
6321
+ const key = resolveHttpPoolKey(adaptiveLimiter.keyResolver, req, url);
6322
+ lease = await adaptiveLimiter.acquire(key, linkedSignal.signal, { priority: requestPriority(req) });
6323
+ } else if (pool) {
6324
+ const key = resolveHttpPoolKey(pool.keyResolver, req, url);
6325
+ lease = await pool.acquire(key, linkedSignal.signal);
6326
+ }
6327
+ const response = await runTransportEffect(
6328
+ transport({ request: req, url, signal: linkedSignal.signal }),
6329
+ env,
6330
+ linkedSignal.signal
6331
+ );
6332
+ releaseSuccess(lease, adaptiveLimiter, response);
6333
+ lease = void 0;
6334
+ return response;
6335
+ } finally {
6336
+ linkedSignal.cleanup();
6337
+ if (lease) {
6338
+ releaseFailure(lease, adaptiveLimiter);
6339
+ }
6340
+ }
6341
+ },
6342
+ normalizeHttpError,
6343
+ {
6344
+ label: fetchLabel(req, url),
6345
+ timeoutMs,
6346
+ timeoutReason: timeoutMs ? () => timeoutReason(req, url, timeoutMs) : void 0,
6347
+ onStart: metrics.onStart,
6348
+ onFinish: metrics.onFinish
6349
+ }
6350
+ );
6351
+ };
6352
+ return decorateStream(run, metrics.snapshot);
6353
+ }
6354
+
6171
6355
  // src/http/requestBuilder.ts
6172
6356
  var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
6173
6357
  function splitHttpRequestInit(init) {
@@ -6265,7 +6449,8 @@ var PRESET_CONFIGS = {
6265
6449
  highThroughputProxy: PROXY_PRESET_CONFIG,
6266
6450
  balanced: BALANCED_PRESET_CONFIG,
6267
6451
  default: DEFAULT_PRESET_CONFIG,
6268
- production: DEFAULT_PRESET_CONFIG
6452
+ production: DEFAULT_PRESET_CONFIG,
6453
+ bareMetal: {}
6269
6454
  };
6270
6455
  function isDefaultCacheableResponse(req, res) {
6271
6456
  if (!DEFAULT_CACHEABLE_METHODS.has(req.method)) return false;
@@ -6292,6 +6477,9 @@ function makeDefaultHttpClient(config = {}) {
6292
6477
  policyPresets,
6293
6478
  ...lifecycleOverrides
6294
6479
  } = config;
6480
+ if (preset === "bareMetal") {
6481
+ return buildBareMetalBranch(lifecycleOverrides, middleware, config);
6482
+ }
6295
6483
  const lifecycleConfig2 = mergeLifecycleConfig(PRESET_CONFIGS[preset], lifecycleOverrides);
6296
6484
  let wire = makeLifecycleClient(lifecycleConfig2);
6297
6485
  const compressionResult = compression === false || compression === void 0 && isLeanPreset(preset) ? void 0 : makeCompressionMiddleware(compression === void 0 ? void 0 : compression);
@@ -6315,6 +6503,160 @@ function makeDefaultHttpClient(config = {}) {
6315
6503
  useInlineDecode
6316
6504
  });
6317
6505
  }
6506
+ var LIFECYCLE_KEYS = [
6507
+ "dedup",
6508
+ "batch",
6509
+ "cache",
6510
+ "priority",
6511
+ "retry",
6512
+ "prewarm",
6513
+ "adaptiveLimiter",
6514
+ "compression"
6515
+ ];
6516
+ function findIgnoredLifecycleKeys(overrides) {
6517
+ const found = [];
6518
+ for (const key of LIFECYCLE_KEYS) {
6519
+ if (key in overrides && overrides[key] !== void 0 && overrides[key] !== false) {
6520
+ found.push(key);
6521
+ }
6522
+ }
6523
+ return found;
6524
+ }
6525
+ function extractBareMetalConfig(config) {
6526
+ return {
6527
+ baseUrl: config.baseUrl,
6528
+ headers: config.headers,
6529
+ timeoutMs: config.timeoutMs,
6530
+ transport: config.transport,
6531
+ streamTransport: config.streamTransport,
6532
+ pool: config.pool,
6533
+ adaptiveLimiter: void 0,
6534
+ // bare-metal ignores adaptiveLimiter from lifecycle overrides
6535
+ onEvent: config.onEvent
6536
+ };
6537
+ }
6538
+ function buildBareMetalBranch(lifecycleOverrides, middleware, config) {
6539
+ const ignored = findIgnoredLifecycleKeys(lifecycleOverrides);
6540
+ if (ignored.length > 0 && config.onEvent) {
6541
+ config.onEvent({
6542
+ type: "warning",
6543
+ message: `bareMetal preset ignores: ${ignored.join(", ")}`
6544
+ });
6545
+ }
6546
+ let bareWire = makeBareMetalHttp(extractBareMetalConfig(config));
6547
+ for (const mw of middleware) {
6548
+ bareWire = bareWire.with(mw);
6549
+ }
6550
+ const features = Object.freeze({
6551
+ dedup: false,
6552
+ batch: false,
6553
+ cache: false,
6554
+ priority: false,
6555
+ retry: false,
6556
+ prewarm: false,
6557
+ adaptiveLimiter: false,
6558
+ compression: false,
6559
+ middleware: middleware.length
6560
+ });
6561
+ return buildBareMetalDefaultClient(bareWire, { preset: "bareMetal", features });
6562
+ }
6563
+ function buildBareMetalDefaultClient(bareWire, meta) {
6564
+ const withPromise = (eff) => withAsyncPromise((e, env) => toPromise(e, env))(eff);
6565
+ const requestRaw = (req) => bareWire(req);
6566
+ const request = (req) => withPromise(requestRaw(req));
6567
+ const get = (url, init) => request(buildHttpRequest("GET", url, init));
6568
+ const post = (url, body, init) => request(buildHttpRequest("POST", url, init, body));
6569
+ const getText = (url, init) => {
6570
+ const req = buildHttpRequest("GET", url, init);
6571
+ return withPromise(
6572
+ mapTryAsync(requestRaw(req), (w) => toResponse(w, w.bodyText))
6573
+ );
6574
+ };
6575
+ const getJson = ((url, init) => {
6576
+ const req = setHeaderIfMissing("accept", "application/json")(
6577
+ buildHttpRequest("GET", url, init)
6578
+ );
6579
+ return withPromise(
6580
+ asyncFlatMap(requestRaw(req), (w) => decodeResponse(w, init?.schema, init?.schemaName))
6581
+ );
6582
+ });
6583
+ const postJson = ((url, bodyObj, init) => {
6584
+ return withPromise(
6585
+ asyncFlatMap(
6586
+ encodeJsonBodyEffect(bodyObj, init?.bodySchema, { schemaName: init?.bodySchemaName }),
6587
+ (bodyText) => {
6588
+ const req = setHeaderIfMissing("content-type", "application/json")(
6589
+ setHeaderIfMissing("accept", "application/json")(
6590
+ buildHttpRequest("POST", url, init, bodyText)
6591
+ )
6592
+ );
6593
+ return asyncFlatMap(requestRaw(req), (w) => decodeResponse(w, init?.schema, init?.schemaName));
6594
+ }
6595
+ )
6596
+ );
6597
+ });
6598
+ const wireAsLifecycle = Object.assign(
6599
+ (req) => bareWire(req),
6600
+ {
6601
+ with: (mw) => {
6602
+ const newBare = bareWire.with(mw);
6603
+ return buildBareMetalDefaultClient(newBare, {
6604
+ ...meta,
6605
+ features: { ...meta.features, middleware: meta.features.middleware + 1 }
6606
+ }).wire;
6607
+ },
6608
+ stats: () => ({
6609
+ cacheHits: 0,
6610
+ cacheMisses: 0,
6611
+ cacheEvictions: 0,
6612
+ dedupHits: 0,
6613
+ dedupActive: 0,
6614
+ queueDepth: 0,
6615
+ requestsStarted: 0,
6616
+ requestsCompleted: 0,
6617
+ requestsFailed: 0,
6618
+ retries: 0,
6619
+ batchDispatches: 0,
6620
+ batchedRequests: 0,
6621
+ wire: bareWire.stats()
6622
+ }),
6623
+ cancelAll: () => asyncSucceed(void 0),
6624
+ shutdown: () => {
6625
+ bareWire.shutdown?.();
6626
+ return asyncSucceed(void 0);
6627
+ },
6628
+ cache: {
6629
+ invalidate: () => {
6630
+ },
6631
+ clear: () => {
6632
+ }
6633
+ },
6634
+ ...bareWire.adaptiveLimiter ? { adaptiveLimiter: bareWire.adaptiveLimiter } : {}
6635
+ }
6636
+ );
6637
+ return {
6638
+ request,
6639
+ get,
6640
+ post,
6641
+ getText,
6642
+ getJson,
6643
+ postJson,
6644
+ with: (mw) => buildBareMetalDefaultClient(bareWire.with(mw), {
6645
+ ...meta,
6646
+ features: {
6647
+ ...meta.features,
6648
+ middleware: meta.features.middleware + 1
6649
+ }
6650
+ }),
6651
+ wire: wireAsLifecycle,
6652
+ stats: () => wireAsLifecycle.stats(),
6653
+ cache: wireAsLifecycle.cache,
6654
+ cancelAll: wireAsLifecycle.cancelAll,
6655
+ shutdown: wireAsLifecycle.shutdown,
6656
+ preset: meta.preset,
6657
+ features: meta.features
6658
+ };
6659
+ }
6318
6660
  function buildDefaultClient(wire, meta) {
6319
6661
  const withPromise = (eff) => withAsyncPromise((e, env) => toPromise(e, env))(eff);
6320
6662
  const requestRaw = (req) => wire(req);
@@ -6495,7 +6837,7 @@ function isEnabled(value) {
6495
6837
  return value !== void 0 && value !== false;
6496
6838
  }
6497
6839
  function isLeanPreset(preset) {
6498
- return preset === "minimal" || preset === "proxy" || preset === "highThroughputProxy";
6840
+ return preset === "minimal" || preset === "proxy" || preset === "highThroughputProxy" || preset === "bareMetal";
6499
6841
  }
6500
6842
 
6501
6843
  // src/http/layer.ts
@@ -6573,9 +6915,24 @@ export {
6573
6915
  makeFetchStreamTransport,
6574
6916
  decorate,
6575
6917
  withMiddleware,
6918
+ decorateStream,
6576
6919
  normalizeHeadersInit,
6920
+ normalizeRequest,
6921
+ resolvePositiveTimeout,
6922
+ makeHttpStats,
6923
+ makePool,
6924
+ makeAdaptiveLimiter,
6925
+ resolveRequestUrl,
6926
+ fetchLabel,
6927
+ timeoutReason,
6928
+ requestPriority,
6929
+ runTransportEffect,
6930
+ runDirectTransport,
6931
+ releaseSuccess,
6932
+ releaseFailure,
6577
6933
  makeHttpStream,
6578
6934
  noopSignal,
6935
+ runPoolTransport,
6579
6936
  makeHttp,
6580
6937
  withRetryStream,
6581
6938
  SEPARATOR,
@@ -6611,6 +6968,9 @@ export {
6611
6968
  validatedJson,
6612
6969
  validatedJsonResponse,
6613
6970
  buildHttpRequest,
6971
+ validateBareMetalConfig,
6972
+ makeBareMetalHttp,
6973
+ makeBareMetalHttpStream,
6614
6974
  defaultHttpClientPreset,
6615
6975
  makeDefaultHttpClient,
6616
6976
  HttpClientService,
@@ -20,7 +20,7 @@ import {
20
20
  httpErrorStatus,
21
21
  isRetryableHttpError,
22
22
  makeDefaultHttpClient
23
- } from "./chunk-HKLZJ5UK.js";
23
+ } from "./chunk-POH2WZBI.js";
24
24
  import {
25
25
  registerHttpEffect
26
26
  } from "./chunk-TRM4JUZQ.js";
@@ -1,4 +1,4 @@
1
- import { A as Async, D as AsyncWithPromise } from './effect-DbEMiMvv.js';
1
+ import { A as Async, u as AbortablePromiseFinish, D as AsyncWithPromise } from './effect-DbEMiMvv.js';
2
2
  import { Z as ZStream } from './stream-B8c_UKZq.js';
3
3
  import { l as Schedule, r as ScheduleObserver, d as CircuitBreakerError } from './layer-CsNGeVee.js';
4
4
  import { SchemaIssue, JsonSchemaLike, AnyJsonSchemaLike, InferJsonSchema } from './schema/index.js';
@@ -713,6 +713,63 @@ declare function promiseHttpTransport(): PromiseHttpTransportStartBuilder;
713
713
  declare function makeFetchTransport(): HttpTransport;
714
714
  declare function makeFetchStreamTransport(): HttpStreamTransport;
715
715
 
716
+ interface TimerWheelConfig {
717
+ /** Tick resolution in ms. Default: 10. Range: [1, 16]. Values outside are clamped. */
718
+ readonly tickMs?: number;
719
+ /** Number of wheel slots. Default: 512. Must be power of 2. */
720
+ readonly slots?: number;
721
+ /** Fine tick resolution in ms for short deadlines. Default: 4. Range: [1, 16]. */
722
+ readonly fineTickMs?: number;
723
+ /** Deadline threshold in ms: entries with deadline ≤ this use fine tick. Default: 50. */
724
+ readonly fineThresholdMs?: number;
725
+ }
726
+ interface TimerHandle {
727
+ cancel(): void;
728
+ }
729
+ declare class TimerWheel {
730
+ private readonly tickMs;
731
+ private readonly mask;
732
+ private readonly wheel;
733
+ private currentTick;
734
+ private timer;
735
+ private pending;
736
+ private readonly fineTickMs;
737
+ private readonly fineThresholdMs;
738
+ private fineHead;
739
+ private fineTimer;
740
+ private finePending;
741
+ constructor(config?: TimerWheelConfig);
742
+ /**
743
+ * Schedule a timeout. Returns a cancel handle. O(1).
744
+ * @param timeoutMs - Timeout duration in milliseconds.
745
+ * @param cb - Callback to invoke on expiry.
746
+ * @param now - Optional pre-captured `performance.now()` value to avoid an extra call.
747
+ */
748
+ schedule(timeoutMs: number, cb: () => void, now?: number): TimerHandle;
749
+ /** Schedule on the normal (coarse) wheel path. */
750
+ private scheduleNormal;
751
+ /** Schedule on the fine-resolution path for short deadlines. */
752
+ private scheduleFine;
753
+ /** Advance the wheel, expiring due entries. Called by internal setTimeout. */
754
+ private tick;
755
+ /** Tick the fine-resolution linked list, expiring due entries. */
756
+ private fineTick;
757
+ /** Start the background timer if not running. */
758
+ private ensureTimer;
759
+ /** Start the fine-tick timer if not running. */
760
+ private ensureFineTimer;
761
+ /** Stop the background timer if no entries pending. */
762
+ private maybeStopTimer;
763
+ /** Stop the fine-tick timer if no fine entries pending. */
764
+ private maybeStopFineTimer;
765
+ /** Cancel all pending entries and stop. */
766
+ destroy(): void;
767
+ /** Unlink an entry from its slot's doubly-linked list. O(1). */
768
+ private unlink;
769
+ /** Unlink an entry from the fine-tick linked list. O(1). */
770
+ private unlinkFine;
771
+ }
772
+
716
773
  type HttpError = {
717
774
  _tag: "Abort";
718
775
  } | {
@@ -835,13 +892,54 @@ type HttpClient = HttpClientFn & {
835
892
  type HttpClientMetadata = Pick<HttpClient, "adaptiveLimiter" | "destroy" | "shutdown">;
836
893
  declare const decorate: (run: HttpClientFn, stats?: () => HttpClientStats, metadata?: HttpClientMetadata) => HttpClient;
837
894
  declare const withMiddleware: (mw: HttpMiddleware) => (c: HttpClient) => HttpClient;
895
+ declare const decorateStream: (run: HttpClientStreamFn, stats?: () => HttpClientStats) => HttpClientStream;
838
896
  declare const normalizeHeadersInit: (h: any) => Record<string, string> | undefined;
897
+ declare const normalizeRequest: (defaultHeaders: Record<string, string>) => (req0: HttpRequest) => HttpRequest;
898
+ declare const resolvePositiveTimeout: (value: number | undefined) => number | undefined;
899
+ declare const makeHttpStats: (pool: HttpConcurrencyPool | undefined, adaptiveLimiter: AdaptiveLimiter | undefined) => {
900
+ onStart: () => void;
901
+ onFinish: (finish: AbortablePromiseFinish) => void;
902
+ snapshot: () => HttpClientStats;
903
+ };
904
+ type HttpMetrics = ReturnType<typeof makeHttpStats>;
905
+ declare const makePool: (cfg: MakeHttpConfig) => HttpConcurrencyPool | undefined;
906
+ declare const makeAdaptiveLimiter: (cfg: MakeHttpConfig) => AdaptiveLimiter | undefined;
907
+ declare const resolveRequestUrl: (req: HttpRequest, baseUrl: string) => URL | HttpError;
908
+ declare const fetchLabel: (req: HttpRequest, url: URL) => string;
909
+ declare const timeoutReason: (req: HttpRequest, url: URL, timeoutMs: number) => HttpError;
910
+ declare const requestPriority: (req: HttpRequest) => number | undefined;
911
+ declare const runTransportEffect: <A>(effect: Async<unknown, HttpError, A>, env: unknown, signal: AbortSignal) => Promise<A>;
912
+ declare const runDirectTransport: (req: HttpRequest, url: URL, transport: HttpTransport, metrics: HttpMetrics) => Async<unknown, HttpError, HttpWireResponse>;
913
+ type HttpLease = {
914
+ release: (...args: any[]) => void;
915
+ };
916
+ declare const releaseSuccess: (lease: HttpLease | undefined, adaptiveLimiter: AdaptiveLimiter | undefined, response: {
917
+ readonly status: number;
918
+ readonly ms: number;
919
+ }) => undefined;
920
+ declare const releaseFailure: (lease: HttpLease | undefined, adaptiveLimiter: AdaptiveLimiter | undefined) => undefined;
839
921
  declare function makeHttpStream(cfg?: MakeHttpConfig): HttpClientStream;
840
922
  /**
841
923
  * Shared no-op AbortSignal used when no external signal is present.
842
924
  * This avoids allocating a new AbortController per request in the common case.
843
925
  */
844
926
  declare const noopSignal: AbortSignal;
927
+ /**
928
+ * Synchronous fast-path for pool/adaptive-limiter + timeout requests.
929
+ *
930
+ * When the pool/limiter acquire is uncontended (tryAcquireSync succeeds) and the
931
+ * transport effect resolves synchronously, this avoids ALL Promise/microtask
932
+ * boundaries — the entire request completes in a single call frame.
933
+ *
934
+ * Falls back to async acquire when contended (pool full or limiter at limit).
935
+ *
936
+ * Closure budget for uncontended sync path:
937
+ * 1. The cancel function returned to caller
938
+ * 2. The transport completion callback (success/failure handler)
939
+ * 3. The timeout callback (when timeoutMs is set)
940
+ * All other functions are methods on PoolRequestState — no per-request closure allocation.
941
+ */
942
+ declare const runPoolTransport: (req: HttpRequest, url: URL, transport: HttpTransport, metrics: HttpMetrics, pool: HttpConcurrencyPool | undefined, adaptiveLimiter: AdaptiveLimiter | undefined, timerWheel: TimerWheel | undefined, timeoutMs: number | undefined) => Async<unknown, HttpError, HttpWireResponse>;
845
943
  declare function makeHttp(cfg?: MakeHttpConfig): HttpClient;
846
944
  declare const withRetryStream: (p: RetryPolicy) => (next: HttpClientStream) => HttpClientStream;
847
945
 
@@ -1583,7 +1681,7 @@ type DefaultPostJson = {
1583
1681
  <Validator extends AnyJsonSchemaLike>(url: string, bodyObj: unknown, init: HttpPostJsonInit<Validator>): AsyncWithPromise<unknown, HttpError | ValidationError, HttpResponse<InferJsonSchema<Validator>>>;
1584
1682
  <A = unknown>(url: string, bodyObj: unknown, init?: PostJsonInitNoSchema): AsyncWithPromise<unknown, HttpError | ValidationError, HttpResponse<A>>;
1585
1683
  };
1586
- type DefaultHttpClientPreset = "minimal" | "proxy" | "highThroughputProxy" | "balanced" | "default" | "production";
1684
+ type DefaultHttpClientPreset = "minimal" | "proxy" | "highThroughputProxy" | "balanced" | "default" | "production" | "bareMetal";
1587
1685
  type DefaultHttpClientFeatures = {
1588
1686
  readonly dedup: boolean;
1589
1687
  readonly batch: boolean;
@@ -1645,4 +1743,4 @@ declare const defaultHttpClientPreset: DefaultHttpClientPreset;
1645
1743
  */
1646
1744
  declare function makeDefaultHttpClient(config?: DefaultHttpClientConfig): DefaultHttpClient;
1647
1745
 
1648
- export { type DefaultHttpClientFeatures as $, type AdaptiveLimiterStats as A, type BatchConfig as B, type CompressionConfig as C, type DefaultHttpClient as D, type AdaptiveLimiterPreset as E, type HttpPoolConfig as F, type AdaptiveAcquireOptions as G, type HttpRequest as H, type AdaptiveBaselineStrategy as I, type AdaptiveHeadroomContext as J, type AdaptiveHeadroomMode as K, type LifecycleClientConfig as L, type AdaptiveHeadroomStrategy as M, type AdaptiveLease as N, type AdaptiveLimiterDiagnostics as O, type PrewarmResult as P, type AdaptiveLimiterKeySnapshot as Q, type RequestCompressionConfig as R, type AdaptiveQueueLoadShedding as S, type AdaptiveQueueStrategy as T, type AdaptiveReleaseInfo as U, type BatchFunction as V, type CachePolicyResult as W, type CompressionStats as X, type DecompressResult as Y, type Decompressor as Z, type DefaultGetJson as _, type HttpClient as a, abortErrorForSignal as a$, type DefaultPostJson as a0, type Dx as a1, type HttpBody as a2, type HttpClientStream as a3, type HttpClientStreamFn as a4, HttpConcurrencyPool as a5, type HttpErrorHandlers as a6, type HttpInit as a7, type HttpJsonInit as a8, type HttpMeta as a9, type PerRequestRetryOverride as aA, type PrewarmEvent as aB, type PrewarmEventType as aC, type PrewarmOriginStatus as aD, type PrewarmResultStatus as aE, type PromiseHttpTransportBodyBuilder as aF, type PromiseHttpTransportBodySelector as aG, type PromiseHttpTransportConfig as aH, type PromiseHttpTransportConfigWithSignal as aI, type PromiseHttpTransportFluentResponseBuilder as aJ, type PromiseHttpTransportRequestConfigBuilder as aK, type PromiseHttpTransportRequestConfigContext as aL, type PromiseHttpTransportRequestConfigMapper as aM, type PromiseHttpTransportResponse as aN, type PromiseHttpTransportResponseInfo as aO, type PromiseHttpTransportResponseInfoMapper as aP, type PromiseHttpTransportStartBuilder as aQ, type RequestCompressionStats as aR, type ResolveHttpRequestPolicyOptions as aS, type ResolvedConfig as aT, type RetryEvent as aU, type RetryScheduleInput as aV, type RetryableHttpErrorOptions as aW, SUPPORTED_ENCODINGS as aX, type SupportedEncoding as aY, type ToHttpErrorOptions as aZ, type ValidationError as a_, type HttpPolicyPreset as aa, type HttpPolicyPresets as ab, type HttpPoolKeyResolver as ac, type HttpPoolKeyStats as ad, type HttpPoolLease as ae, type HttpPoolStats as af, type HttpPostJsonBodyInit as ag, type HttpPostJsonInit as ah, type HttpPostJsonSchemaBodyInit as ai, type HttpRequestPolicy as aj, type HttpRequestPolicyRef as ak, type HttpRequestRetryOverride as al, type HttpResponse as am, type HttpResponseWithMeta as an, type HttpRetryScheduleInput as ao, type HttpStreamTransport as ap, type HttpTransportContext as aq, type HttpTransportTiming as ar, type HttpWireResponseStream as as, type HttpWireWithMeta as at, type JsonDecodeResult as au, type KnownHttpError as av, type KnownHttpErrorTag as aw, type LifecycleRequestOptions as ax, type LimitChangeEvent as ay, type MakeHttpConfig as az, type HttpWireResponse as b, adaptiveLimiterPresets as b0, backoffDelayMs as b1, decodeJsonBody as b2, decodeJsonBodyEffect as b3, decorate as b4, defaultHttpClientPreset as b5, defaultRetryOnError as b6, defaultRetryOnStatus as b7, defaultRetryableMethods as b8, defineHttpPolicyPresets as b9, makeFetchStreamTransport as bA, makeFetchTransport as bB, makeHttp as bC, makeHttpStream as bD, makeJsonParseValidationError as bE, makePromiseHttpTransport as bF, matchHttpError as bG, noopSignal as bH, normalizeHeadersInit as bI, normalizeHttpError as bJ, normalizeHttpHeaders as bK, normalizeRetryBudget as bL, promiseHttpTransport as bM, resolveConfig as bN, resolveHttpPoolKey as bO, resolveHttpRequestPolicyPresets as bP, retryAfterMs as bQ, toHttpError as bR, validateConfig as bS, validatedJson as bT, validatedJsonResponse as bU, withBatch as bV, withHttpPolicyPresets as bW, withHttpRequestPolicy as bX, withMiddleware as bY, withRetry as bZ, withRetryStream as b_, encodeJsonBodyEffect as ba, formatHttpError as bb, getHttpRequestPolicy as bc, headersOf as bd, httpClient as be, httpClientStream as bf, httpClientWithMeta as bg, httpErrorStatus as bh, httpPolicy as bi, isAbortError as bj, isAbortHttpError as bk, isCircuitBreakerOpen as bl, isExternalAbortError as bm, isExternalTimeoutError as bn, isFetchHttpError as bo, isHttpError as bp, isKnownHttpError as bq, isPromiseTransportDirect as br, isRetryableHttpError as bs, isRetryableHttpStatus as bt, isTaggedHttpError as bu, isTimeoutHttpError as bv, isValidationError as bw, linkAbortSignals as bx, makeAdaptiveLimiterConfig as by, makeDefaultHttpClient as bz, type HttpError as c, type HttpMiddleware as d, type DefaultHttpClientConfig as e, type CompressionMiddlewareResult as f, type RequestCompressionMiddlewareResult as g, type HttpTransport as h, AdaptiveLimiter as i, type LifecycleClient as j, type LifecycleEvent as k, type HttpClientStats as l, type LifecycleEventType as m, type LifecycleStats as n, type PrewarmStatusSnapshot as o, type PrewarmConfig as p, type HttpClientFn as q, type PrewarmOriginState as r, type HttpMethod as s, type DefaultHttpClientPreset as t, type DedupConfig as u, type CacheConfig as v, type PriorityConfig as w, type RetryPolicy as x, type PrewarmLifecycleConfig as y, type AdaptiveLimiterConfig as z };
1746
+ export { type Decompressor as $, type AdaptiveLimiterStats as A, type BatchConfig as B, type CompressionConfig as C, type DefaultHttpClient as D, type PriorityConfig as E, type RetryPolicy as F, type PrewarmLifecycleConfig as G, type HttpRequest as H, type AdaptiveLimiterPreset as I, type AdaptiveAcquireOptions as J, type AdaptiveBaselineStrategy as K, type LifecycleClientConfig as L, type AdaptiveHeadroomContext as M, type AdaptiveHeadroomMode as N, type AdaptiveHeadroomStrategy as O, type PrewarmResult as P, type AdaptiveLease as Q, type RequestCompressionConfig as R, type AdaptiveLimiterDiagnostics as S, type AdaptiveLimiterKeySnapshot as T, type AdaptiveQueueLoadShedding as U, type AdaptiveQueueStrategy as V, type AdaptiveReleaseInfo as W, type BatchFunction as X, type CachePolicyResult as Y, type CompressionStats as Z, type DecompressResult as _, type HttpClient as a, abortErrorForSignal as a$, type DefaultGetJson as a0, type DefaultHttpClientFeatures as a1, type DefaultPostJson as a2, type Dx as a3, type HttpBody as a4, type HttpClientStreamFn as a5, HttpConcurrencyPool as a6, type HttpErrorHandlers as a7, type HttpInit as a8, type HttpJsonInit as a9, type PerRequestRetryOverride as aA, type PrewarmEvent as aB, type PrewarmEventType as aC, type PrewarmOriginStatus as aD, type PrewarmResultStatus as aE, type PromiseHttpTransportBodyBuilder as aF, type PromiseHttpTransportBodySelector as aG, type PromiseHttpTransportConfig as aH, type PromiseHttpTransportConfigWithSignal as aI, type PromiseHttpTransportFluentResponseBuilder as aJ, type PromiseHttpTransportRequestConfigBuilder as aK, type PromiseHttpTransportRequestConfigContext as aL, type PromiseHttpTransportRequestConfigMapper as aM, type PromiseHttpTransportResponse as aN, type PromiseHttpTransportResponseInfo as aO, type PromiseHttpTransportResponseInfoMapper as aP, type PromiseHttpTransportStartBuilder as aQ, type RequestCompressionStats as aR, type ResolveHttpRequestPolicyOptions as aS, type ResolvedConfig as aT, type RetryEvent as aU, type RetryScheduleInput as aV, type RetryableHttpErrorOptions as aW, SUPPORTED_ENCODINGS as aX, type SupportedEncoding as aY, type ToHttpErrorOptions as aZ, type ValidationError as a_, type HttpMeta as aa, type HttpPolicyPreset as ab, type HttpPolicyPresets as ac, type HttpPoolKeyResolver as ad, type HttpPoolKeyStats as ae, type HttpPoolLease as af, type HttpPoolStats as ag, type HttpPostJsonBodyInit as ah, type HttpPostJsonInit as ai, type HttpPostJsonSchemaBodyInit as aj, type HttpRequestPolicy as ak, type HttpRequestPolicyRef as al, type HttpRequestRetryOverride as am, type HttpResponse as an, type HttpResponseWithMeta as ao, type HttpRetryScheduleInput as ap, type HttpTransportContext as aq, type HttpTransportTiming as ar, type HttpWireResponseStream as as, type HttpWireWithMeta as at, type JsonDecodeResult as au, type KnownHttpError as av, type KnownHttpErrorTag as aw, type LifecycleRequestOptions as ax, type LimitChangeEvent as ay, type MakeHttpConfig as az, type HttpWireResponse as b, retryAfterMs as b$, adaptiveLimiterPresets as b0, backoffDelayMs as b1, decodeJsonBody as b2, decodeJsonBodyEffect as b3, decorate as b4, decorateStream as b5, defaultHttpClientPreset as b6, defaultRetryOnError as b7, defaultRetryOnStatus as b8, defaultRetryableMethods as b9, makeAdaptiveLimiter as bA, makeAdaptiveLimiterConfig as bB, makeDefaultHttpClient as bC, makeFetchStreamTransport as bD, makeFetchTransport as bE, makeHttp as bF, makeHttpStats as bG, makeHttpStream as bH, makeJsonParseValidationError as bI, makePool as bJ, makePromiseHttpTransport as bK, matchHttpError as bL, noopSignal as bM, normalizeHeadersInit as bN, normalizeHttpError as bO, normalizeHttpHeaders as bP, normalizeRequest as bQ, normalizeRetryBudget as bR, promiseHttpTransport as bS, releaseFailure as bT, releaseSuccess as bU, requestPriority as bV, resolveConfig as bW, resolveHttpPoolKey as bX, resolveHttpRequestPolicyPresets as bY, resolvePositiveTimeout as bZ, resolveRequestUrl as b_, defineHttpPolicyPresets as ba, encodeJsonBodyEffect as bb, fetchLabel as bc, formatHttpError as bd, getHttpRequestPolicy as be, headersOf as bf, httpClient as bg, httpClientStream as bh, httpClientWithMeta as bi, httpErrorStatus as bj, httpPolicy as bk, isAbortError as bl, isAbortHttpError as bm, isCircuitBreakerOpen as bn, isExternalAbortError as bo, isExternalTimeoutError as bp, isFetchHttpError as bq, isHttpError as br, isKnownHttpError as bs, isPromiseTransportDirect as bt, isRetryableHttpError as bu, isRetryableHttpStatus as bv, isTaggedHttpError as bw, isTimeoutHttpError as bx, isValidationError as by, linkAbortSignals as bz, type HttpError as c, runDirectTransport as c0, runPoolTransport as c1, runTransportEffect as c2, timeoutReason as c3, toHttpError as c4, validateConfig as c5, validatedJson as c6, validatedJsonResponse as c7, withBatch as c8, withHttpPolicyPresets as c9, withHttpRequestPolicy as ca, withMiddleware as cb, withRetry as cc, withRetryStream as cd, type HttpMiddleware as d, type DefaultHttpClientConfig as e, type CompressionMiddlewareResult as f, type RequestCompressionMiddlewareResult as g, type HttpTransport as h, AdaptiveLimiter as i, type LifecycleClient as j, type LifecycleEvent as k, type HttpClientStats as l, type LifecycleEventType as m, type LifecycleStats as n, type PrewarmStatusSnapshot as o, type PrewarmConfig as p, type HttpClientFn as q, type PrewarmOriginState as r, type HttpMethod as s, type HttpStreamTransport as t, type HttpPoolConfig as u, type AdaptiveLimiterConfig as v, type HttpClientStream as w, type DefaultHttpClientPreset as x, type DedupConfig as y, type CacheConfig as z };