apps 0.0.1-beta.125 → 0.0.1-beta.127

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 (46) hide show
  1. package/framework-reference.json +1 -1
  2. package/js/{chunk-7TDDMSZI.js → chunk-2XVGONUX.js} +6 -6
  3. package/js/{chunk-V3HWVVFZ.js → chunk-3CDTMIVU.js} +3 -3
  4. package/js/{chunk-7ASLJHSD.js → chunk-3II7MIAQ.js} +6 -6
  5. package/js/{chunk-3KNB4HRA.js → chunk-53GRY7ZE.js} +3 -3
  6. package/js/{chunk-7ZYZWLXS.js → chunk-5CMAHXQD.js} +60 -61
  7. package/js/{chunk-VXBCDIWD.js → chunk-5H5IO2NZ.js} +778 -213
  8. package/js/{chunk-2AI3RZXP.js → chunk-5WCWPY23.js} +10 -10
  9. package/js/{chunk-MJUHAHDG.js → chunk-67DM7ASO.js} +2 -2
  10. package/js/{chunk-QUFLMMTG.js → chunk-DJNOADLI.js} +182 -61
  11. package/js/{chunk-KJW5IPM4.js → chunk-FXJUHTFE.js} +1 -1
  12. package/js/{chunk-VEQDEM6J.js → chunk-J3CZECVS.js} +13 -13
  13. package/js/{chunk-SO33LZ7J.js → chunk-KKKUQPWD.js} +2 -2
  14. package/js/{chunk-CCJUTN55.js → chunk-LC6YCEVL.js} +1 -1
  15. package/js/chunk-N7HXZNBD.js +161 -0
  16. package/js/{chunk-5TYZML5C.js → chunk-NGL6EJL6.js} +1775 -626
  17. package/js/{chunk-2EEUUSL7.js → chunk-NMSQJSBM.js} +308 -331
  18. package/js/{chunk-TTMRK64V.js → chunk-O46YT2VS.js} +2 -2
  19. package/js/{chunk-5LGG5YSE.js → chunk-PZBT2QO5.js} +2 -2
  20. package/js/{chunk-U2GHFWX2.js → chunk-QYHUNAWH.js} +7415 -3500
  21. package/js/{chunk-EPZ3P7IX.js → chunk-SA7FJGUX.js} +2 -2
  22. package/js/{chunk-LOHZM4RK.js → chunk-UJWZMRV6.js} +5 -5
  23. package/js/{chunk-MVAS3VFK.js → chunk-V2TAC4IJ.js} +8 -8
  24. package/js/{chunk-NCOPALJZ.js → chunk-WE4FZOSH.js} +1 -1
  25. package/js/{chunk-GWAA3COO.js → chunk-ZU2ECYYF.js} +4 -4
  26. package/js/{chunk-55QLA7T7.js → chunk-ZU77L7HU.js} +6 -6
  27. package/js/client.js +75 -18
  28. package/js/contracts.js +7 -7
  29. package/js/effect.js +18 -18
  30. package/js/graphql.js +20 -20
  31. package/js/host.js +18 -18
  32. package/js/index.js +13 -13
  33. package/js/mcp/effect.js +19 -19
  34. package/js/mcp.js +21 -21
  35. package/js/openapi.js +16 -16
  36. package/js/react.js +2 -2
  37. package/js/skills/effect.js +6 -6
  38. package/js/skills.js +15 -15
  39. package/js/ui/auth/contracts.js +2 -2
  40. package/js/ui/auth.js +5 -5
  41. package/js/ui/contracts.js +5 -5
  42. package/js/ui/serving.js +10 -10
  43. package/package.json +2 -2
  44. package/runtime.json +1 -1
  45. package/types/telemetry/src/layer.d.ts +1 -1
  46. package/js/chunk-EAPSQBFN.js +0 -75
@@ -4,29 +4,38 @@ import {
4
4
  Clock,
5
5
  CurrentMemoMap,
6
6
  CurrentRedactedNames,
7
+ CurrentRedactedNames2,
7
8
  Defect,
8
9
  DisablePropagation,
9
10
  Done,
10
11
  Error as Error2,
11
12
  Error2 as Error3,
12
13
  FileSystem,
14
+ IllegalArgumentError,
13
15
  Int,
14
16
  JsonFromUrlParamsField,
15
17
  Literals,
16
18
  NodeInspectSymbol,
19
+ ParentSpan,
17
20
  Path,
18
21
  PipeInspectableProto,
19
22
  RecordFromUrlParams,
20
23
  Reference,
21
24
  Scope,
22
25
  Service,
26
+ StackTrace,
23
27
  String as String2,
24
28
  Struct,
25
29
  TaggedError,
26
30
  TaggedError2,
27
- Union,
28
- addFinalizer2 as addFinalizer,
31
+ TimeoutError,
32
+ Tracer,
33
+ TracerTimingEnabled,
34
+ Union2 as Union,
35
+ add,
36
+ addFinalizer,
29
37
  andThen,
38
+ annotateLogs,
30
39
  append,
31
40
  appendAll2 as appendAll,
32
41
  as,
@@ -36,19 +45,24 @@ import {
36
45
  cached,
37
46
  catchCause,
38
47
  catchCauseFilter,
48
+ catchDecoding,
39
49
  catchIf,
40
50
  catchTag,
41
51
  catchTags,
42
52
  catch_,
53
+ clockWith,
43
54
  close,
55
+ concat,
44
56
  constFalse,
45
57
  constTrue,
58
+ constUndefined,
46
59
  constVoid,
47
60
  constant,
61
+ contains,
48
62
  context,
49
63
  contextWith,
50
64
  decodeEffect,
51
- decodeTo,
65
+ decodeTo2 as decodeTo,
52
66
  decodeUnknownEffect2 as decodeUnknownEffect,
53
67
  delay,
54
68
  done,
@@ -58,15 +72,17 @@ import {
58
72
  effectDiscard,
59
73
  empty,
60
74
  empty2,
61
- empty3,
62
- empty4,
63
- empty5,
75
+ empty4 as empty3,
76
+ empty5 as empty4,
77
+ empty6 as empty5,
64
78
  empty7 as empty6,
79
+ encode,
65
80
  encodeText,
66
81
  encodeUnknownEffect,
67
82
  ensuring,
68
83
  ensuring2,
69
84
  equals2 as equals,
85
+ exit,
70
86
  expireCookie,
71
87
  expireCookieUnsafe,
72
88
  externalSpan,
@@ -84,10 +100,14 @@ import {
84
100
  flow,
85
101
  fnUntraced,
86
102
  forEach,
87
- forever2 as forever,
103
+ forever,
104
+ forever2,
88
105
  fork,
89
106
  forkIn,
90
107
  format,
108
+ format2,
109
+ formatIp,
110
+ fromBody,
91
111
  fromChannel,
92
112
  fromInput,
93
113
  fromInput2,
@@ -100,28 +120,36 @@ import {
100
120
  fromNullishOr,
101
121
  fromPull,
102
122
  fromReadableStream,
123
+ fromReasons,
103
124
  fromRecordUnsafe,
104
125
  fromResult,
105
126
  fromSetCookie,
127
+ fromStep,
106
128
  fromTransform,
107
129
  gen,
108
130
  get,
109
- get2,
131
+ get3 as get2,
110
132
  get4 as get3,
111
133
  getCurrent,
112
134
  getOrElse,
113
135
  getOrUndefined,
136
+ getOrUndefined2,
114
137
  getOrUndefinedUnsafe,
138
+ getStackTraceLimit,
115
139
  getUnsafe,
116
140
  hasInterrupts,
117
141
  hasProperty,
118
142
  identity,
119
143
  ignore2 as ignore,
144
+ inetAddressFromString,
145
+ ipFromString,
120
146
  isDoneCause,
121
147
  isEffect,
122
148
  isEmpty,
123
149
  isExit,
150
+ isFailReason,
124
151
  isFailure,
152
+ isFailure2,
125
153
  isNone,
126
154
  isOption,
127
155
  isReadonlyArrayNonEmpty,
@@ -130,72 +158,97 @@ import {
130
158
  isSome,
131
159
  isStream,
132
160
  isSuccess,
161
+ isSuccess2,
133
162
  isTimeoutError,
134
163
  isZero,
164
+ log,
165
+ makeSpanUnsafe,
135
166
  makeUnsafe,
136
- map3 as map,
137
- map4 as map2,
167
+ map4 as map,
168
+ map6 as map2,
138
169
  mapEffect,
139
170
  mapError,
140
171
  mapError2,
141
172
  mapError3,
142
173
  match,
143
174
  matchCauseEffect,
144
- matchEffect,
175
+ matchEffect2 as matchEffect,
145
176
  max,
146
177
  mebibytes,
147
178
  merge,
148
179
  merge2,
149
180
  merge3,
181
+ mergeIntoArray,
150
182
  millis,
151
183
  mkUint8Array,
152
184
  mkUint8Array2,
185
+ nativeTracer,
153
186
  none,
187
+ onExitUnsafe,
154
188
  onInterrupt,
155
189
  optional,
156
190
  or,
157
191
  parseHeader,
158
- passthrough,
192
+ parseRetryAfter,
159
193
  pipeArguments,
160
194
  pipeThroughChannel,
195
+ promise,
161
196
  provide,
162
197
  provide2,
163
198
  provideContext,
164
199
  provideMerge,
200
+ provideService,
201
+ provideServiceEffect,
165
202
  redact,
166
- remove,
167
- remove2,
203
+ redactUrl,
204
+ remove2 as remove,
205
+ remove3 as remove2,
206
+ removeMany,
168
207
  repeat,
169
208
  retry,
209
+ retryAfterDelay,
170
210
  run,
171
211
  runForEach,
172
212
  runSync,
213
+ scope,
173
214
  seconds,
174
- set,
175
- set2,
176
- set3,
215
+ set2 as set,
216
+ set3 as set2,
217
+ set4 as set3,
177
218
  setAll,
178
219
  setAll2,
179
220
  setAll3,
180
221
  setAllUnsafe,
222
+ setStackTraceLimit,
181
223
  setUnsafe,
182
224
  sleep,
183
225
  some,
184
226
  stringOrRedacted,
227
+ stripSearchAndHash,
185
228
  succeed,
186
- succeed4 as succeed2,
187
- succeed5 as succeed3,
229
+ succeed2,
230
+ succeed3,
231
+ succeed4,
232
+ succeed5,
188
233
  succeedContext,
234
+ succeedSome,
189
235
  suspend,
190
236
  suspend2,
191
237
  sync2 as sync,
192
238
  tag,
193
239
  tap,
194
240
  tapError,
241
+ timeoutOrElse,
242
+ toCanonical,
195
243
  toCodecJson,
196
- toCookieHeader,
244
+ toMillis,
245
+ toPath,
246
+ toPullScoped,
247
+ toReadableStream,
197
248
  toReadableStreamWith,
249
+ toRequestCookieHeader,
198
250
  toSetCookieHeaders,
251
+ toStep,
199
252
  toString,
200
253
  tryPromise,
201
254
  try_,
@@ -203,20 +256,24 @@ import {
203
256
  uninterruptibleMask,
204
257
  unwrap2 as unwrap,
205
258
  unwrap3 as unwrap2,
259
+ unwrap4 as unwrap3,
206
260
  update,
207
261
  updateContext,
262
+ updateService,
208
263
  useSpan,
209
264
  void_,
210
265
  void_2,
266
+ withDecodingDefaultKey,
211
267
  withFiber,
268
+ withLogSpan,
212
269
  withParentSpan,
213
270
  zero2 as zero
214
- } from "./chunk-U2GHFWX2.js";
271
+ } from "./chunk-QYHUNAWH.js";
215
272
  import {
216
273
  __export
217
274
  } from "./chunk-CZ7CSFO4.js";
218
275
 
219
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpClientRequest.js
276
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpClientRequest.js
220
277
  var HttpClientRequest_exports = {};
221
278
  __export(HttpClientRequest_exports, {
222
279
  accept: () => accept,
@@ -235,6 +292,7 @@ __export(HttpClientRequest_exports, {
235
292
  bodyText: () => bodyText,
236
293
  bodyUint8Array: () => bodyUint8Array,
237
294
  bodyUrlParams: () => bodyUrlParams,
295
+ compressBody: () => compressBody2,
238
296
  delete: () => del,
239
297
  empty: () => empty8,
240
298
  fromWeb: () => fromWeb,
@@ -266,10 +324,11 @@ __export(HttpClientRequest_exports, {
266
324
  toWebResult: () => toWebResult,
267
325
  trace: () => trace,
268
326
  updateHeaders: () => updateHeaders2,
269
- updateUrl: () => updateUrl
327
+ updateUrl: () => updateUrl,
328
+ upgrade: () => upgrade
270
329
  });
271
330
 
272
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpBody.js
331
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpBody.js
273
332
  var HttpBody_exports = {};
274
333
  __export(HttpBody_exports, {
275
334
  Empty: () => Empty,
@@ -336,10 +395,10 @@ var Raw = class extends Proto {
336
395
  body;
337
396
  contentType;
338
397
  contentLength;
339
- constructor(body, contentType, contentLength) {
398
+ constructor(body, contentType2, contentLength) {
340
399
  super();
341
400
  this.body = body;
342
- this.contentType = contentType;
401
+ this.contentType = contentType2;
343
402
  this.contentLength = contentLength;
344
403
  }
345
404
  toJSON() {
@@ -360,11 +419,11 @@ var Uint8Array2 = class extends Proto {
360
419
  /** Original text retained for adapters that can skip encoding. */
361
420
  text;
362
421
  _body;
363
- constructor(body, contentType, contentLength, text3) {
422
+ constructor(body, contentType2, contentLength, text3) {
364
423
  super();
365
424
  this._body = body;
366
425
  this.text = text3;
367
- this.contentType = contentType;
426
+ this.contentType = contentType2;
368
427
  this.contentLength = contentLength;
369
428
  }
370
429
  get body() {
@@ -381,23 +440,23 @@ var Uint8Array2 = class extends Proto {
381
440
  };
382
441
  }
383
442
  };
384
- var uint8Array = (body, contentType) => new Uint8Array2(body, contentType ?? "application/octet-stream", body.length);
443
+ var uint8Array = (body, contentType2) => new Uint8Array2(body, contentType2 ?? "application/octet-stream", body.length);
385
444
  var encoder = /* @__PURE__ */ new TextEncoder();
386
445
  var buffer = globalThis.Buffer;
387
446
  var encodeText2 = buffer !== void 0 ? (body) => buffer.from(body, "utf8") : (body) => encoder.encode(body);
388
- var text = (body, contentType) => {
447
+ var text = (body, contentType2) => {
389
448
  if (typeof body !== "string") {
390
449
  body = body === void 0 ? "" : String(body);
391
450
  }
392
451
  if (buffer !== void 0) {
393
- return new Uint8Array2(void 0, contentType ?? "text/plain", buffer.byteLength(body, "utf8"), body);
452
+ return new Uint8Array2(void 0, contentType2 ?? "text/plain", buffer.byteLength(body, "utf8"), body);
394
453
  }
395
454
  const bytes = encoder.encode(body);
396
- return new Uint8Array2(bytes, contentType ?? "text/plain", bytes.length, body);
455
+ return new Uint8Array2(bytes, contentType2 ?? "text/plain", bytes.length, body);
397
456
  };
398
- var jsonUnsafe = (body, contentType) => text(JSON.stringify(body), contentType ?? "application/json");
399
- var json = (body, contentType) => try_2({
400
- try: () => text(JSON.stringify(body), contentType ?? "application/json"),
457
+ var jsonUnsafe = (body, contentType2) => text(JSON.stringify(body), contentType2 ?? "application/json");
458
+ var json = (body, contentType2) => try_2({
459
+ try: () => text(JSON.stringify(body), contentType2 ?? "application/json"),
401
460
  catch: (cause) => new HttpBodyError({
402
461
  reason: {
403
462
  _tag: "JsonError"
@@ -406,16 +465,16 @@ var json = (body, contentType) => try_2({
406
465
  })
407
466
  });
408
467
  var jsonSchema = (schema, options3) => {
409
- const encode = encodeUnknownEffect(toCodecJson(schema));
410
- return (body, contentType) => encode(body, options3).pipe(mapError((issue) => new HttpBodyError({
468
+ const encode2 = encodeUnknownEffect(toCodecJson(schema));
469
+ return (body, contentType2) => encode2(body, options3).pipe(mapError((issue) => new HttpBodyError({
411
470
  reason: {
412
471
  _tag: "SchemaError",
413
472
  issue
414
473
  },
415
474
  cause: issue
416
- })), flatMap((body2) => json(body2, contentType)));
475
+ })), flatMap((body2) => json(body2, contentType2)));
417
476
  };
418
- var urlParams = (urlParams3, contentType) => text(toString(fromInput3(urlParams3)), contentType ?? "application/x-www-form-urlencoded");
477
+ var urlParams = (urlParams3, contentType2) => text(toString(fromInput3(urlParams3)), contentType2 ?? "application/x-www-form-urlencoded");
419
478
  var FormData2 = class extends Proto {
420
479
  _tag = "FormData";
421
480
  contentType = void 0;
@@ -462,10 +521,10 @@ var Stream = class extends Proto {
462
521
  stream;
463
522
  contentType;
464
523
  contentLength;
465
- constructor(stream4, contentType, contentLength) {
524
+ constructor(stream4, contentType2, contentLength) {
466
525
  super();
467
526
  this.stream = stream4;
468
- this.contentType = contentType;
527
+ this.contentType = contentType2;
469
528
  this.contentLength = contentLength;
470
529
  }
471
530
  toJSON() {
@@ -477,10 +536,10 @@ var Stream = class extends Proto {
477
536
  };
478
537
  }
479
538
  };
480
- var stream = (body, contentType, contentLength) => new Stream(body, contentType ?? "application/octet-stream", contentLength);
539
+ var stream = (body, contentType2, contentLength) => new Stream(body, contentType2 ?? "application/octet-stream", contentLength);
481
540
  var fileRangeSize = (input, field, method) => {
482
541
  const size = fromInput(input);
483
- return isSome(size) ? succeed2(size.value) : fail3(badArgument({
542
+ return isSome(size) ? succeed4(size.value) : fail3(badArgument({
484
543
  module: "HttpBody",
485
544
  method,
486
545
  description: `Invalid ${field}: ${input}`
@@ -503,17 +562,47 @@ var fileContentLength = /* @__PURE__ */ fnUntraced(function* (size, method, opti
503
562
  var file = (path, options3) => flatMap(FileSystem, (fs) => flatMap(fs.stat(path), (info) => map(fileContentLength(info.size, "file", options3), (contentLength) => stream(fs.stream(path, options3), options3?.contentType, contentLength))));
504
563
  var fileFromInfo = (path, info, options3) => flatMap(FileSystem, (fs) => map(fileContentLength(info.size, "fileFromInfo", options3), (contentLength) => stream(fs.stream(path, options3), options3?.contentType, contentLength)));
505
564
 
506
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpMethod.js
507
- var hasBody = (method) => method !== "GET" && method !== "HEAD" && method !== "OPTIONS" && method !== "TRACE";
565
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpMethod.js
566
+ function hasBody(method) {
567
+ return method !== "GET" && method !== "HEAD" && method !== "OPTIONS" && method !== "TRACE";
568
+ }
508
569
  var allShort = [["GET", "get"], ["POST", "post"], ["PUT", "put"], ["DELETE", "del"], ["PATCH", "patch"], ["HEAD", "head"], ["OPTIONS", "options"], ["TRACE", "trace"], ["QUERY", "query"]];
509
570
 
510
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/internal/httpBody.js
571
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/internal/compressionBody.js
572
+ var compressionTransformWeb = (format3) => (stream4) => stream4.pipeThrough(new CompressionStream(format3));
573
+ var singleChunkStream = (data) => new ReadableStream({
574
+ start(controller) {
575
+ controller.enqueue(data);
576
+ controller.close();
577
+ }
578
+ });
579
+ var compressBody = (body, algorithm, options3) => {
580
+ if (body._tag !== "Uint8Array" && body._tag !== "Stream") {
581
+ return succeed4(body);
582
+ }
583
+ if (body.contentLength !== void 0 && body.contentLength < (options3?.minSize ?? 1024)) {
584
+ return succeed4(body);
585
+ }
586
+ if (body._tag === "Uint8Array") {
587
+ return map(promise(() => new globalThis.Response(compressionTransformWeb(algorithm)(singleChunkStream(body.body))).arrayBuffer()), (buffer2) => uint8Array(new Uint8Array(buffer2), body.contentType));
588
+ }
589
+ return succeed4(stream(fromReadableStream({
590
+ evaluate: () => compressionTransformWeb(algorithm)(toReadableStream(body.stream)),
591
+ onError: identity
592
+ }), body.contentType));
593
+ };
594
+
595
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/internal/httpBody.js
511
596
  var updateHeaders = (headers, body) => {
512
597
  if (body._tag === "Empty" || body._tag === "FormData") {
513
598
  return remove2(remove2(headers, "content-type"), "content-length");
514
599
  }
515
600
  headers = body.contentType === void 0 ? remove2(headers, "content-type") : set2(headers, "content-type", body.contentType);
516
- return body.contentLength === void 0 ? remove2(headers, "content-length") : set2(headers, "content-length", body.contentLength.toString());
601
+ return updateContentLength(headers, body);
602
+ };
603
+ var updateContentLength = (headers, body) => {
604
+ const contentLength = body._tag === "Empty" || body._tag === "FormData" ? void 0 : body.contentLength;
605
+ return contentLength === void 0 ? remove2(headers, "content-length") : set2(headers, "content-length", contentLength.toString());
517
606
  };
518
607
  var parseContentLength = (contentLength) => {
519
608
  if (contentLength === null || contentLength === void 0 || !/^\d+$/.test(contentLength)) {
@@ -523,7 +612,7 @@ var parseContentLength = (contentLength) => {
523
612
  return Number.isSafeInteger(parsed) ? parsed : void 0;
524
613
  };
525
614
 
526
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/Url.js
615
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/Url.js
527
616
  var UrlError = class extends (/* @__PURE__ */ TaggedError("UrlError")) {
528
617
  };
529
618
  var make = (url, params, hash) => try_({
@@ -532,7 +621,7 @@ var make = (url, params, hash) => try_({
532
621
  for (let i = 0; i < params.params.length; i++) {
533
622
  const [key, value] = params.params[i];
534
623
  if (value !== void 0) {
535
- urlInstance.searchParams.append(key, value);
624
+ urlInstance.searchParams.append(key, unwrap(value));
536
625
  }
537
626
  }
538
627
  if (hash !== void 0) {
@@ -546,12 +635,21 @@ var make = (url, params, hash) => try_({
546
635
  });
547
636
  var baseUrl = () => {
548
637
  if ("location" in globalThis && globalThis.location !== void 0 && globalThis.location.origin !== void 0 && globalThis.location.pathname !== void 0) {
549
- return location.origin + location.pathname;
638
+ const base = location.origin + location.pathname;
639
+ try {
640
+ return new URL(base).href;
641
+ } catch {
642
+ return void 0;
643
+ }
550
644
  }
551
645
  return void 0;
552
646
  };
647
+ var fromString = (url, base) => try_({
648
+ try: () => new URL(url, base),
649
+ catch: () => new IllegalArgumentError(`Invalid URL: "${url}"${base !== void 0 ? ` with base "${base}"` : ""}`)
650
+ });
553
651
 
554
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpClientRequest.js
652
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpClientRequest.js
555
653
  var TypeId2 = "~effect/http/HttpClientRequest";
556
654
  var isHttpClientRequest = (u) => hasProperty(u, TypeId2);
557
655
  var Proto2 = {
@@ -561,7 +659,7 @@ var Proto2 = {
561
659
  return {
562
660
  _id: "HttpClientRequest",
563
661
  method: this.method,
564
- url: this.url,
662
+ url: redactUrl(this.url),
565
663
  urlParams: this.urlParams,
566
664
  hash: this.hash,
567
665
  headers: redact(this.headers),
@@ -630,10 +728,11 @@ var setHeader = /* @__PURE__ */ dual(3, (self, key, value) => makeWith(self.meth
630
728
  var setHeaders = /* @__PURE__ */ dual(2, (self, input) => makeWith(self.method, self.url, self.urlParams, self.hash, setAll2(self.headers, input), self.body));
631
729
  var updateHeaders2 = /* @__PURE__ */ dual(2, (self, f) => makeWith(self.method, self.url, self.urlParams, self.hash, f(self.headers), self.body));
632
730
  var removeHeader = /* @__PURE__ */ dual(2, (self, key) => updateHeaders2(self, remove2(key)));
633
- var basicAuth = /* @__PURE__ */ dual(3, (self, username, password) => setHeader(self, "Authorization", `Basic ${btoa(`${stringOrRedacted(username)}:${stringOrRedacted(password)}`)}`));
731
+ var basicAuth = /* @__PURE__ */ dual(3, (self, username, password) => setHeader(self, "Authorization", `Basic ${encode(`${stringOrRedacted(username)}:${stringOrRedacted(password)}`)}`));
634
732
  var bearerToken = /* @__PURE__ */ dual(2, (self, token) => setHeader(self, "Authorization", `Bearer ${stringOrRedacted(token)}`));
635
733
  var accept = /* @__PURE__ */ dual(2, (self, mediaType) => setHeader(self, "Accept", mediaType));
636
734
  var acceptJson = /* @__PURE__ */ accept("application/json");
735
+ var upgrade = /* @__PURE__ */ dual(2, (self, protocol) => makeWith(self.method, self.url, self.urlParams, self.hash, set2(set2(self.headers, "connection", "Upgrade"), "upgrade", protocol), self.body));
637
736
  var setUrl = /* @__PURE__ */ dual(2, (self, url) => {
638
737
  if (typeof url === "string") {
639
738
  return makeWith(self.method, url, self.urlParams, self.hash, self.headers, self.body);
@@ -670,13 +769,19 @@ var removeHash = (self) => makeWith(self.method, self.url, self.urlParams, none(
670
769
  var setBody = /* @__PURE__ */ dual(2, (self, body) => {
671
770
  return makeWith(self.method, self.url, self.urlParams, self.hash, updateHeaders(self.headers, body), body);
672
771
  });
673
- var bodyUint8Array = /* @__PURE__ */ dual((args) => isHttpClientRequest(args[0]), (self, body, contentType) => setBody(self, uint8Array(body, contentType)));
674
- var bodyText = /* @__PURE__ */ dual((args) => isHttpClientRequest(args[0]), (self, body, contentType) => setBody(self, text(body, contentType)));
772
+ var compressBody2 = /* @__PURE__ */ dual((args) => isHttpClientRequest(args[0]), (self, algorithm, options3) => {
773
+ if (self.headers["content-encoding"] !== void 0) {
774
+ return succeed4(self);
775
+ }
776
+ return map(compressBody(self.body, algorithm, options3), (body) => body === self.body ? self : makeWith(self.method, self.url, self.urlParams, self.hash, set2(updateContentLength(self.headers, body), "content-encoding", algorithm), body));
777
+ });
778
+ var bodyUint8Array = /* @__PURE__ */ dual((args) => isHttpClientRequest(args[0]), (self, body, contentType2) => setBody(self, uint8Array(body, contentType2)));
779
+ var bodyText = /* @__PURE__ */ dual((args) => isHttpClientRequest(args[0]), (self, body, contentType2) => setBody(self, text(body, contentType2)));
675
780
  var bodyJson = /* @__PURE__ */ dual(2, (self, body) => map(json(body), (body2) => setBody(self, body2)));
676
781
  var bodyJsonUnsafe = /* @__PURE__ */ dual(2, (self, body) => setBody(self, jsonUnsafe(body)));
677
782
  var schemaBodyJson = (schema, options3) => {
678
- const encode = jsonSchema(schema, options3);
679
- return dual(2, (self, body) => map(encode(body), (body2) => setBody(self, body2)));
783
+ const encode2 = jsonSchema(schema, options3);
784
+ return dual(2, (self, body) => map(encode2(body), (body2) => setBody(self, body2)));
680
785
  };
681
786
  var bodyUrlParams = /* @__PURE__ */ dual(2, (self, input) => setBody(self, urlParams(fromInput3(input))));
682
787
  var bodyFormData = /* @__PURE__ */ dual(2, (self, body) => setBody(self, formData(body)));
@@ -692,8 +797,7 @@ function toUrl(self) {
692
797
  }
693
798
  var fromWeb = (request) => {
694
799
  const method = request.method.toUpperCase();
695
- return modify(empty8, {
696
- method,
800
+ return modify(makeWith(method, "", empty5, none(), empty4, empty7), {
697
801
  url: new URL(request.url),
698
802
  headers: request.headers,
699
803
  body: fromWebBody(request, method)
@@ -761,7 +865,7 @@ var toWeb = (self, options3) => contextWith((context2) => fromResult(toWebResult
761
865
  signal: options3?.signal
762
866
  })));
763
867
 
764
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpClient.js
868
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpClient.js
765
869
  var HttpClient_exports = {};
766
870
  __export(HttpClient_exports, {
767
871
  HttpClient: () => HttpClient,
@@ -772,6 +876,7 @@ __export(HttpClient_exports, {
772
876
  catch: () => catch_2,
773
877
  catchTag: () => catchTag2,
774
878
  catchTags: () => catchTags2,
879
+ circuitBreakerClassifier: () => circuitBreakerClassifier,
775
880
  del: () => del2,
776
881
  execute: () => execute,
777
882
  filterOrElse: () => filterOrElse2,
@@ -782,6 +887,8 @@ __export(HttpClient_exports, {
782
887
  get: () => get5,
783
888
  head: () => head2,
784
889
  isHttpClient: () => isHttpClient,
890
+ isTransientError: () => isTransientError,
891
+ isTransientResponse: () => isTransientResponse,
785
892
  layerMergedContext: () => layerMergedContext,
786
893
  make: () => make3,
787
894
  makeWith: () => makeWith2,
@@ -799,14 +906,16 @@ __export(HttpClient_exports, {
799
906
  tap: () => tap2,
800
907
  tapError: () => tapError2,
801
908
  tapRequest: () => tapRequest,
909
+ timeout: () => timeout,
802
910
  transform: () => transform,
803
911
  transformResponse: () => transformResponse,
912
+ withCircuitBreaker: () => withCircuitBreaker,
804
913
  withCookiesRef: () => withCookiesRef,
805
914
  withRateLimiter: () => withRateLimiter,
806
915
  withScope: () => withScope
807
916
  });
808
917
 
809
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpClientError.js
918
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpClientError.js
810
919
  var HttpClientError_exports = {};
811
920
  __export(HttpClientError_exports, {
812
921
  DecodeError: () => DecodeError,
@@ -817,6 +926,8 @@ __export(HttpClientError_exports, {
817
926
  InvalidUrlError: () => InvalidUrlError,
818
927
  StatusCodeError: () => StatusCodeError,
819
928
  TransportError: () => TransportError,
929
+ addFailureRedactedNames: () => addFailureRedactedNames,
930
+ addResponseRedactedNames: () => addResponseRedactedNames,
820
931
  isHttpClientError: () => isHttpClientError
821
932
  });
822
933
  var TypeId3 = "~effect/http/HttpClientError";
@@ -863,7 +974,48 @@ var HttpClientError = class extends (/* @__PURE__ */ TaggedError("HttpClientErro
863
974
  };
864
975
  var formatReason = (tag2) => tag2.endsWith("Error") ? tag2.slice(0, -5) : tag2;
865
976
  var formatMessage = (reason, description, info) => description ? `${reason}: ${description} (${info})` : `${reason} error (${info})`;
866
- var TransportError = class extends (/* @__PURE__ */ TaggedError("TransportError")) {
977
+ var responseRedactedNames = /* @__PURE__ */ new WeakMap();
978
+ var redactedUrls = /* @__PURE__ */ new WeakMap();
979
+ var addRedactedNames = (reason, names) => {
980
+ const url = redactedUrls.get(reason);
981
+ if (url !== void 0 && names !== void 0) redactedUrls.set(reason, redactUrl(url, names));
982
+ };
983
+ var addResponseRedactedNames = (response, names) => {
984
+ const existing = responseRedactedNames.get(response);
985
+ responseRedactedNames.set(response, existing === void 0 ? names : [...existing, ...names]);
986
+ };
987
+ var addFailureRedactedNames = (cause, names) => {
988
+ for (const reason of cause.reasons) {
989
+ if (isFailReason(reason) && isHttpClientError(reason.error)) addRedactedNames(reason.error.reason, names);
990
+ }
991
+ };
992
+ var ReasonError = (tag2) => {
993
+ class Base extends TaggedError(tag2) {
994
+ constructor(props) {
995
+ super(props);
996
+ redactedUrls.set(this, redactUrl(props.request.url));
997
+ if (props.response !== void 0) addRedactedNames(this, responseRedactedNames.get(props.response));
998
+ }
999
+ }
1000
+ return Base;
1001
+ };
1002
+ var redactedUrl = (reason) => redactUrl(redactedUrls.get(reason) ?? reason.request.url);
1003
+ var formatMethodAndUrl = (reason) => `${reason.request.method} ${redactedUrl(reason)}`;
1004
+ var reasonToJSON = (reason, json3) => ({
1005
+ ...json3,
1006
+ request: {
1007
+ _id: "HttpClientRequest",
1008
+ method: reason.request.method,
1009
+ url: redactedUrl(reason)
1010
+ },
1011
+ ..."response" in reason ? {
1012
+ response: {
1013
+ _id: "HttpClientResponse",
1014
+ status: reason.response.status
1015
+ }
1016
+ } : void 0
1017
+ });
1018
+ var TransportError = class extends (/* @__PURE__ */ ReasonError("TransportError")) {
867
1019
  /**
868
1020
  * Formats the request method and URL for transport error messages.
869
1021
  *
@@ -871,7 +1023,7 @@ var TransportError = class extends (/* @__PURE__ */ TaggedError("TransportError"
871
1023
  * @since 4.0.0
872
1024
  */
873
1025
  get methodAndUrl() {
874
- return `${this.request.method} ${this.request.url}`;
1026
+ return formatMethodAndUrl(this);
875
1027
  }
876
1028
  /**
877
1029
  * Builds the transport error message from the optional description and request details.
@@ -882,8 +1034,11 @@ var TransportError = class extends (/* @__PURE__ */ TaggedError("TransportError"
882
1034
  get message() {
883
1035
  return formatMessage(formatReason(this._tag), this.description, this.methodAndUrl);
884
1036
  }
1037
+ toJSON() {
1038
+ return reasonToJSON(this, super.toJSON());
1039
+ }
885
1040
  };
886
- var EncodeError = class extends (/* @__PURE__ */ TaggedError("EncodeError")) {
1041
+ var EncodeError = class extends (/* @__PURE__ */ ReasonError("EncodeError")) {
887
1042
  /**
888
1043
  * Formats the request method and URL for request encoding error messages.
889
1044
  *
@@ -891,7 +1046,7 @@ var EncodeError = class extends (/* @__PURE__ */ TaggedError("EncodeError")) {
891
1046
  * @since 4.0.0
892
1047
  */
893
1048
  get methodAndUrl() {
894
- return `${this.request.method} ${this.request.url}`;
1049
+ return formatMethodAndUrl(this);
895
1050
  }
896
1051
  /**
897
1052
  * Builds the request encoding error message from the optional description and request details.
@@ -902,8 +1057,11 @@ var EncodeError = class extends (/* @__PURE__ */ TaggedError("EncodeError")) {
902
1057
  get message() {
903
1058
  return formatMessage(formatReason(this._tag), this.description, this.methodAndUrl);
904
1059
  }
1060
+ toJSON() {
1061
+ return reasonToJSON(this, super.toJSON());
1062
+ }
905
1063
  };
906
- var InvalidUrlError = class extends (/* @__PURE__ */ TaggedError("InvalidUrlError")) {
1064
+ var InvalidUrlError = class extends (/* @__PURE__ */ ReasonError("InvalidUrlError")) {
907
1065
  /**
908
1066
  * Formats the request method and URL for invalid URL error messages.
909
1067
  *
@@ -911,7 +1069,7 @@ var InvalidUrlError = class extends (/* @__PURE__ */ TaggedError("InvalidUrlErro
911
1069
  * @since 4.0.0
912
1070
  */
913
1071
  get methodAndUrl() {
914
- return `${this.request.method} ${this.request.url}`;
1072
+ return formatMethodAndUrl(this);
915
1073
  }
916
1074
  /**
917
1075
  * Builds the invalid URL error message from the optional description and request details.
@@ -922,8 +1080,11 @@ var InvalidUrlError = class extends (/* @__PURE__ */ TaggedError("InvalidUrlErro
922
1080
  get message() {
923
1081
  return formatMessage(formatReason(this._tag), this.description, this.methodAndUrl);
924
1082
  }
1083
+ toJSON() {
1084
+ return reasonToJSON(this, super.toJSON());
1085
+ }
925
1086
  };
926
- var StatusCodeError = class extends (/* @__PURE__ */ TaggedError("StatusCodeError")) {
1087
+ var StatusCodeError = class extends (/* @__PURE__ */ ReasonError("StatusCodeError")) {
927
1088
  /**
928
1089
  * Formats the request method and URL for status code error messages.
929
1090
  *
@@ -931,7 +1092,7 @@ var StatusCodeError = class extends (/* @__PURE__ */ TaggedError("StatusCodeErro
931
1092
  * @since 4.0.0
932
1093
  */
933
1094
  get methodAndUrl() {
934
- return `${this.request.method} ${this.request.url}`;
1095
+ return formatMethodAndUrl(this);
935
1096
  }
936
1097
  /**
937
1098
  * Builds the status code error message from the response status, optional description, and request details.
@@ -943,8 +1104,11 @@ var StatusCodeError = class extends (/* @__PURE__ */ TaggedError("StatusCodeErro
943
1104
  const info = `${this.response.status} ${this.methodAndUrl}`;
944
1105
  return formatMessage(formatReason(this._tag), this.description, info);
945
1106
  }
1107
+ toJSON() {
1108
+ return reasonToJSON(this, super.toJSON());
1109
+ }
946
1110
  };
947
- var DecodeError = class extends (/* @__PURE__ */ TaggedError("DecodeError")) {
1111
+ var DecodeError = class extends (/* @__PURE__ */ ReasonError("DecodeError")) {
948
1112
  /**
949
1113
  * Formats the request method and URL for response decoding error messages.
950
1114
  *
@@ -952,7 +1116,7 @@ var DecodeError = class extends (/* @__PURE__ */ TaggedError("DecodeError")) {
952
1116
  * @since 4.0.0
953
1117
  */
954
1118
  get methodAndUrl() {
955
- return `${this.request.method} ${this.request.url}`;
1119
+ return formatMethodAndUrl(this);
956
1120
  }
957
1121
  /**
958
1122
  * Builds the response decoding error message from the response status, optional description, and request details.
@@ -964,8 +1128,11 @@ var DecodeError = class extends (/* @__PURE__ */ TaggedError("DecodeError")) {
964
1128
  const info = `${this.response.status} ${this.methodAndUrl}`;
965
1129
  return formatMessage(formatReason(this._tag), this.description, info);
966
1130
  }
1131
+ toJSON() {
1132
+ return reasonToJSON(this, super.toJSON());
1133
+ }
967
1134
  };
968
- var EmptyBodyError = class extends (/* @__PURE__ */ TaggedError("EmptyBodyError")) {
1135
+ var EmptyBodyError = class extends (/* @__PURE__ */ ReasonError("EmptyBodyError")) {
969
1136
  /**
970
1137
  * Formats the request method and URL for empty response body error messages.
971
1138
  *
@@ -973,7 +1140,7 @@ var EmptyBodyError = class extends (/* @__PURE__ */ TaggedError("EmptyBodyError"
973
1140
  * @since 4.0.0
974
1141
  */
975
1142
  get methodAndUrl() {
976
- return `${this.request.method} ${this.request.url}`;
1143
+ return formatMethodAndUrl(this);
977
1144
  }
978
1145
  /**
979
1146
  * Builds the empty body error message from the response status, optional description, and request details.
@@ -985,6 +1152,9 @@ var EmptyBodyError = class extends (/* @__PURE__ */ TaggedError("EmptyBodyError"
985
1152
  const info = `${this.response.status} ${this.methodAndUrl}`;
986
1153
  return formatMessage(formatReason(this._tag), this.description, info);
987
1154
  }
1155
+ toJSON() {
1156
+ return reasonToJSON(this, super.toJSON());
1157
+ }
988
1158
  };
989
1159
  var HttpClientErrorSchema = class _HttpClientErrorSchema extends (/* @__PURE__ */ Error3(TypeId3)({
990
1160
  _tag: /* @__PURE__ */ tag("HttpError"),
@@ -1004,9 +1174,13 @@ var HttpClientErrorSchema = class _HttpClientErrorSchema extends (/* @__PURE__ *
1004
1174
  cause: error.reason
1005
1175
  });
1006
1176
  }
1177
+ get message() {
1178
+ const message = hasProperty(this.cause, "message") ? this.cause.message : void 0;
1179
+ return typeof message === "string" && message !== "" ? message : this.kind;
1180
+ }
1007
1181
  };
1008
1182
 
1009
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpIncomingMessage.js
1183
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpIncomingMessage.js
1010
1184
  var TypeId4 = "~effect/http/HttpIncomingMessage";
1011
1185
  var schemaBodyJson2 = (schema, options3) => {
1012
1186
  const decode = decodeEffect(toCodecJson(schema));
@@ -1021,41 +1195,28 @@ var MaxBodySize = /* @__PURE__ */ Reference("effect/http/HttpIncomingMessage/Max
1021
1195
  defaultValue: () => void 0
1022
1196
  });
1023
1197
  var inspect = (self, that) => {
1024
- const contentType = self.headers["content-type"] ?? "";
1025
- let body;
1026
- if (contentType.includes("application/json")) {
1027
- try {
1028
- body = runSync(self.json);
1029
- } catch (_) {
1030
- }
1031
- } else if (contentType.includes("text/") || contentType.includes("urlencoded")) {
1032
- try {
1033
- body = runSync(self.text);
1034
- } catch (_) {
1035
- }
1036
- }
1037
- const obj = {
1198
+ return {
1038
1199
  ...that,
1039
1200
  headers: redact(self.headers),
1040
1201
  remoteAddress: self.remoteAddress
1041
1202
  };
1042
- if (body !== void 0) {
1043
- obj.body = body;
1044
- }
1045
- return obj;
1046
1203
  };
1047
1204
 
1048
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpClientResponse.js
1205
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/internal/webResponse.js
1206
+ var WebSourceSymbol = "~effect/http/HttpClientResponse/WebSource";
1207
+ var getWebSource = (self) => self[WebSourceSymbol]?.();
1208
+
1209
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpClientResponse.js
1049
1210
  var TypeId5 = "~effect/http/HttpClientResponse";
1050
1211
  var fromWeb2 = (request, source) => new WebHttpClientResponse(request, source);
1051
- var filterStatus = /* @__PURE__ */ dual(2, (self, f) => suspend(() => f(self.status) ? succeed2(self) : fail3(new HttpClientError({
1212
+ var filterStatus = /* @__PURE__ */ dual(2, (self, f) => suspend(() => f(self.status) ? succeed4(self) : fail3(new HttpClientError({
1052
1213
  reason: new StatusCodeError({
1053
1214
  response: self,
1054
1215
  request: self.request,
1055
1216
  description: "invalid status code"
1056
1217
  })
1057
1218
  }))));
1058
- var filterStatusOk = (self) => self.status >= 200 && self.status < 300 ? succeed2(self) : fail3(new HttpClientError({
1219
+ var filterStatusOk = (self) => self.status >= 200 && self.status < 300 ? succeed4(self) : fail3(new HttpClientError({
1059
1220
  reason: new StatusCodeError({
1060
1221
  response: self,
1061
1222
  request: self.request,
@@ -1099,11 +1260,14 @@ var WebHttpClientResponse = class extends Class {
1099
1260
  if (this.cachedCookies) {
1100
1261
  return this.cachedCookies;
1101
1262
  }
1102
- return this.cachedCookies = fromSetCookie(this.source.headers.getSetCookie());
1263
+ return this.cachedCookies = fromSetCookie(this.source.headers.getSetCookie?.() ?? []);
1103
1264
  }
1104
1265
  get remoteAddress() {
1105
1266
  return none();
1106
1267
  }
1268
+ [WebSourceSymbol]() {
1269
+ return this.source;
1270
+ }
1107
1271
  get stream() {
1108
1272
  return this.source.body ? fromReadableStream({
1109
1273
  evaluate: () => this.source.body,
@@ -1139,8 +1303,8 @@ var WebHttpClientResponse = class extends Class {
1139
1303
  return this.textBody ??= map(this.arrayBuffer, (_) => new TextDecoder().decode(_));
1140
1304
  }
1141
1305
  get urlParamsBody() {
1142
- return flatMap(this.text, (_) => try_2({
1143
- try: () => fromInput3(new URLSearchParams(_)),
1306
+ return flatMap(this.arrayBuffer, (bytes) => try_2({
1307
+ try: () => fromInput3(fromBody(bytes)),
1144
1308
  catch: (cause) => new HttpClientError({
1145
1309
  reason: new DecodeError({
1146
1310
  request: this.request,
@@ -1180,12 +1344,21 @@ var WebHttpClientResponse = class extends Class {
1180
1344
  }).pipe(cached, runSync);
1181
1345
  return this.arrayBufferBody;
1182
1346
  }
1347
+ get upgrade() {
1348
+ return fail3(new HttpClientError({
1349
+ reason: new StatusCodeError({
1350
+ request: this.request,
1351
+ response: this,
1352
+ description: "fetch cannot hand over the connection of an HTTP upgrade"
1353
+ })
1354
+ }));
1355
+ }
1183
1356
  pipe() {
1184
1357
  return pipeArguments(this, arguments);
1185
1358
  }
1186
1359
  };
1187
1360
 
1188
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpTraceContext.js
1361
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpTraceContext.js
1189
1362
  var HttpTraceContext_exports = {};
1190
1363
  __export(HttpTraceContext_exports, {
1191
1364
  b3: () => b3,
@@ -1199,7 +1372,7 @@ var toHeaders = (span) => fromRecordUnsafe({
1199
1372
  onNone: () => "",
1200
1373
  onSome: (parent) => `-${parent.spanId}`
1201
1374
  })}`,
1202
- traceparent: `00-${span.traceId}-${span.spanId}-${span.sampled ? "01" : "00"}`
1375
+ traceparent: `00-${span.traceId.padStart(32, "0")}-${span.spanId}-${span.sampled ? "01" : "00"}`
1203
1376
  });
1204
1377
  var fromHeaders = (headers) => {
1205
1378
  let span = w3c(headers);
@@ -1217,7 +1390,7 @@ var b3 = (headers) => {
1217
1390
  return none();
1218
1391
  }
1219
1392
  const parts = headers["b3"].split("-");
1220
- if (parts.length < 2) {
1393
+ if (parts.length < 2 || isB3Ids(parts[0], parts[1]) === false) {
1221
1394
  return none();
1222
1395
  }
1223
1396
  return some(externalSpan({
@@ -1227,7 +1400,7 @@ var b3 = (headers) => {
1227
1400
  }));
1228
1401
  };
1229
1402
  var xb3 = (headers) => {
1230
- if (!headers["x-b3-traceid"] || !headers["x-b3-spanid"]) {
1403
+ if (!headers["x-b3-traceid"] || !headers["x-b3-spanid"] || isB3Ids(headers["x-b3-traceid"], headers["x-b3-spanid"]) === false) {
1231
1404
  return none();
1232
1405
  }
1233
1406
  return some(externalSpan({
@@ -1236,8 +1409,11 @@ var xb3 = (headers) => {
1236
1409
  sampled: headers["x-b3-flags"] === "1" || (headers["x-b3-sampled"] ? headers["x-b3-sampled"] === "1" || headers["x-b3-sampled"] === "true" : true)
1237
1410
  }));
1238
1411
  };
1239
- var w3cTraceId = /^[0-9a-f]{32}$/i;
1240
- var w3cSpanId = /^[0-9a-f]{16}$/i;
1412
+ var w3cTraceId = /^[0-9a-f]{32}$/;
1413
+ var w3cSpanId = /^[0-9a-f]{16}$/;
1414
+ var w3cTraceFlags = /^[0-9a-f]{2}$/;
1415
+ var b3TraceId = /^(?:[0-9a-f]{16}|[0-9a-f]{32})$/;
1416
+ var isB3Ids = (traceId, spanId) => b3TraceId.test(traceId) && w3cSpanId.test(spanId);
1241
1417
  var w3c = (headers) => {
1242
1418
  if (!headers["traceparent"]) {
1243
1419
  return none();
@@ -1249,7 +1425,7 @@ var w3c = (headers) => {
1249
1425
  const [version, traceId, spanId, flags] = parts;
1250
1426
  switch (version) {
1251
1427
  case "00": {
1252
- if (w3cTraceId.test(traceId) === false || w3cSpanId.test(spanId) === false || traceId === "00000000000000000000000000000000" || spanId === "0000000000000000") {
1428
+ if (w3cTraceId.test(traceId) === false || w3cSpanId.test(spanId) === false || w3cTraceFlags.test(flags) === false || traceId === "00000000000000000000000000000000" || spanId === "0000000000000000") {
1253
1429
  return none();
1254
1430
  }
1255
1431
  return some(externalSpan({
@@ -1264,7 +1440,41 @@ var w3c = (headers) => {
1264
1440
  }
1265
1441
  };
1266
1442
 
1267
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpClient.js
1443
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/internal/tracing.js
1444
+ var defaultPorts = {
1445
+ "http:": 80,
1446
+ "https:": 443,
1447
+ "ws:": 80,
1448
+ "wss:": 443
1449
+ };
1450
+ var addUrlAttributes = (span, url, redactedNames2) => {
1451
+ const query3 = redactUrl(url.search, redactedNames2).slice(1);
1452
+ span.attribute("url.full", redactUrl(url.href, redactedNames2));
1453
+ span.attribute("url.path", url.pathname);
1454
+ if (query3 !== "") {
1455
+ span.attribute("url.query", query3);
1456
+ }
1457
+ span.attribute("url.scheme", url.protocol.slice(0, -1));
1458
+ if (url.hostname !== "") {
1459
+ span.attribute("server.address", url.hostname.startsWith("[") ? url.hostname.slice(1, -1) : url.hostname);
1460
+ const port = url.port === "" ? defaultPorts[url.protocol] : Number(url.port);
1461
+ if (port !== void 0) {
1462
+ span.attribute("server.port", port);
1463
+ }
1464
+ }
1465
+ };
1466
+ var redactedNames = (urlParams3, redactedNames2) => {
1467
+ const keys = urlParams3.params.filter(([, value]) => typeof value !== "string").map(([key]) => key);
1468
+ return keys.length === 0 ? redactedNames2 : [...redactedNames2, ...new URLSearchParams(keys.map((key) => [key, ""])).keys()];
1469
+ };
1470
+ var addHeaderAttributes = (span, phase, headers, filter, redactedNames2) => {
1471
+ for (const name in headers) {
1472
+ if (!filter(name, phase)) continue;
1473
+ span.attribute(`http.${phase}.header.${name}`, isRedactedName(name, redactedNames2) ? "<redacted>" : headers[name]);
1474
+ }
1475
+ };
1476
+
1477
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpClient.js
1268
1478
  var TypeId6 = "~effect/http/HttpClient";
1269
1479
  var isHttpClient = (u) => hasProperty(u, TypeId6);
1270
1480
  var HttpClient = /* @__PURE__ */ Service("effect/HttpClient");
@@ -1278,10 +1488,16 @@ var patch2 = /* @__PURE__ */ accessor("patch");
1278
1488
  var put2 = /* @__PURE__ */ accessor("put");
1279
1489
  var del2 = /* @__PURE__ */ accessor("del");
1280
1490
  var options2 = /* @__PURE__ */ accessor("options");
1281
- var transform = /* @__PURE__ */ dual(2, (self, f) => makeWith2(flatMap((request) => f(self.postprocess(succeed2(request)), request)), self.preprocess));
1491
+ var transform = /* @__PURE__ */ dual(2, (self, f) => makeWith2(flatMap((request) => f(self.postprocess(succeed4(request)), request)), self.preprocess));
1282
1492
  var transformResponse = /* @__PURE__ */ dual(2, (self, f) => makeWith2((request) => f(self.postprocess(request)), self.preprocess));
1283
1493
  var catch_2 = /* @__PURE__ */ dual(2, (self, f) => transformResponse(self, catch_(f)));
1284
- var catchTag2 = /* @__PURE__ */ dual(3, (self, tag2, f) => transformResponse(self, (effect2) => catchTag(effect2, tag2, f)));
1494
+ var catchTag2 = /* @__PURE__ */ dual(3, (self, tag2, f) => transformResponse(
1495
+ self,
1496
+ // TypeScript 7.1 does not relate the error type `Effect.catchTag` returns
1497
+ // to the `ExcludeTag` declared here, because each declares its own copy
1498
+ // of the conditional on `K`. The assertion restates the declared type.
1499
+ (effect2) => catchTag(effect2, tag2, f)
1500
+ ));
1285
1501
  var catchTags2 = /* @__PURE__ */ dual(2, (self, cases) => transformResponse(self, catchTags(cases)));
1286
1502
  var filterOrElse2 = /* @__PURE__ */ dual(3, (self, f, orElse) => transformResponse(self, filterOrElse(f, orElse)));
1287
1503
  var filterOrFail2 = /* @__PURE__ */ dual(3, (self, f, orFailWith) => transformResponse(self, filterOrFail(f, orFailWith)));
@@ -1312,8 +1528,9 @@ var Proto3 = {
1312
1528
  }]))
1313
1529
  };
1314
1530
  var make3 = (f) => makeWith2((effect2) => flatMap(effect2, (request) => withFiber((fiber) => {
1315
- const scopedController = scopedRequests.get(request);
1316
- const controller = scopedController ?? new AbortController();
1531
+ const scope2 = fiber.getRef(RequestScope);
1532
+ const controller = new AbortController();
1533
+ const urlParamsRedactedNames = fiber.getRef(CurrentRedactedNames2);
1317
1534
  const urlResult = make(request.url, request.urlParams, getOrUndefined(request.hash));
1318
1535
  if (isFailure(urlResult)) {
1319
1536
  return fail3(new HttpClientError({
@@ -1324,67 +1541,62 @@ var make3 = (f) => makeWith2((effect2) => flatMap(effect2, (request) => withFibe
1324
1541
  }));
1325
1542
  }
1326
1543
  const url = urlResult.success;
1544
+ const send = (request2) => scope2 === void 0 ? f(request2, url, controller.signal, fiber) : flatMap(addFinalizer(scope2, sync(() => controller.abort())), () => f(request2, url, controller.signal, fiber));
1545
+ const exchange = (request2, onResponse) => uninterruptibleMask((restore) => matchCauseEffect(restore(send(request2)), {
1546
+ onSuccess: (response) => {
1547
+ response = trackResponse(response, controller, scope2 !== void 0, urlParamsRedactedNames);
1548
+ onResponse?.(response);
1549
+ return succeed4(response);
1550
+ },
1551
+ onFailure: (cause) => {
1552
+ if (hasInterrupts(cause)) {
1553
+ controller.abort();
1554
+ }
1555
+ addFailureRedactedNames(cause, urlParamsRedactedNames);
1556
+ return failCause2(cause);
1557
+ }
1558
+ }));
1327
1559
  const tracerDisabled = fiber.getRef(DisablePropagation) || fiber.getRef(TracerDisabledWhen)(request);
1328
1560
  if (tracerDisabled) {
1329
- const effect3 = f(request, url, controller.signal, fiber);
1330
- if (scopedController) return effect3;
1331
- return uninterruptibleMask((restore) => matchCauseEffect(restore(effect3), {
1332
- onSuccess(response) {
1333
- responseRegistry.register(response, controller);
1334
- return succeed2(new InterruptibleResponse(response, controller));
1335
- },
1336
- onFailure(cause) {
1337
- if (hasInterrupts(cause)) {
1338
- controller.abort();
1339
- }
1340
- return failCause2(cause);
1341
- }
1342
- }));
1561
+ return exchange(request);
1343
1562
  }
1344
1563
  return useSpan(fiber.getRef(SpanNameGenerator)(request), {
1345
1564
  kind: "client"
1346
1565
  }, (span) => {
1347
1566
  span.attribute("http.request.method", request.method);
1348
- span.attribute("server.address", url.origin);
1349
- if (url.port !== "") {
1350
- span.attribute("server.port", +url.port);
1351
- }
1352
- span.attribute("url.full", url.toString());
1353
- span.attribute("url.path", url.pathname);
1354
- span.attribute("url.scheme", url.protocol.slice(0, -1));
1355
- const query3 = url.search.slice(1);
1356
- if (query3 !== "") {
1357
- span.attribute("url.query", query3);
1358
- }
1359
1567
  const redactedHeaderNames = fiber.getRef(CurrentRedactedNames);
1568
+ addUrlAttributes(span, url, redactedNames(request.urlParams, urlParamsRedactedNames));
1360
1569
  const headerFilter = fiber.getRef(TracerHeaderFilter);
1361
- for (const name in request.headers) {
1362
- if (!headerFilter(name, "request")) continue;
1363
- span.attribute(`http.request.header.${name}`, isRedactedName(name, redactedHeaderNames) ? "<redacted>" : request.headers[name]);
1364
- }
1570
+ addHeaderAttributes(span, "request", request.headers, headerFilter, redactedHeaderNames);
1365
1571
  request = fiber.getRef(TracerPropagationEnabled) ? setHeaders(request, toHeaders(span)) : request;
1366
- return uninterruptibleMask((restore) => restore(f(request, url, controller.signal, fiber)).pipe(withParentSpan(span, {
1367
- captureStackTrace: false
1368
- }), matchCauseEffect({
1369
- onSuccess: (response) => {
1370
- span.attribute("http.response.status_code", response.status);
1371
- for (const name in response.headers) {
1372
- if (!headerFilter(name, "response")) continue;
1373
- span.attribute(`http.response.header.${name}`, isRedactedName(name, redactedHeaderNames) ? "<redacted>" : response.headers[name]);
1374
- }
1375
- if (scopedController) return succeed2(response);
1376
- responseRegistry.register(response, controller);
1377
- return succeed2(new InterruptibleResponse(response, controller));
1378
- },
1379
- onFailure(cause) {
1380
- if (!scopedController && hasInterrupts(cause)) {
1381
- controller.abort();
1382
- }
1383
- return failCause2(cause);
1572
+ return withParentSpan(exchange(request, (response) => {
1573
+ span.attribute("http.response.status_code", response.status);
1574
+ addHeaderAttributes(span, "response", response.headers, headerFilter, redactedHeaderNames);
1575
+ if (response.status >= 400 && response.status < 600) {
1576
+ span.attribute("error.type", String(response.status));
1577
+ endSpanWithStatusError(fiber, span, request, response);
1384
1578
  }
1385
- })));
1579
+ }), span, {
1580
+ captureStackTrace: false
1581
+ });
1386
1582
  });
1387
- })), succeed2);
1583
+ })), succeed4);
1584
+ var endSpanWithStatusError = (fiber, span, request, response) => {
1585
+ const stackTraceLimit = getStackTraceLimit();
1586
+ setStackTraceLimit(0);
1587
+ let exit2;
1588
+ try {
1589
+ exit2 = fail2(new HttpClientError({
1590
+ reason: new StatusCodeError({
1591
+ request,
1592
+ response
1593
+ })
1594
+ }));
1595
+ } finally {
1596
+ setStackTraceLimit(stackTraceLimit);
1597
+ }
1598
+ span.end(fiber.getRef(TracerTimingEnabled) ? fiber.getRef(Clock).currentTimeNanosUnsafe() : BigInt(0), exit2);
1599
+ };
1388
1600
  var mapRequest = /* @__PURE__ */ dual(2, (self, f) => makeWith2(self.postprocess, (request) => map(self.preprocess(request), f)));
1389
1601
  var mapRequestEffect = /* @__PURE__ */ dual(2, (self, f) => makeWith2(self.postprocess, (request) => flatMap(self.preprocess(request), f)));
1390
1602
  var mapRequestInput = /* @__PURE__ */ dual(2, (self, f) => makeWith2(self.postprocess, (request) => self.preprocess(f(request))));
@@ -1393,11 +1605,10 @@ var retry2 = /* @__PURE__ */ dual(2, (self, policy) => transformResponse(self, r
1393
1605
  var retryTransient = /* @__PURE__ */ dual(2, (self, options3) => {
1394
1606
  const isOnlySchedule = isSchedule(options3);
1395
1607
  const retryOn = isOnlySchedule ? "errors-and-responses" : options3.retryOn ?? "errors-and-responses";
1396
- const schedule = isOnlySchedule ? options3 : options3.schedule;
1397
- const passthroughSchedule = schedule && passthrough(schedule);
1608
+ const schedule = withRetryAfter(isOnlySchedule ? options3 : options3.schedule ?? forever);
1398
1609
  const times = isOnlySchedule ? void 0 : options3.times;
1399
1610
  return transformResponse(self, flow(retryOn === "errors-only" ? identity : repeat({
1400
- schedule: passthroughSchedule,
1611
+ schedule,
1401
1612
  times,
1402
1613
  while: isTransientResponse
1403
1614
  }), retryOn === "response-only" ? identity : retry({
@@ -1406,6 +1617,20 @@ var retryTransient = /* @__PURE__ */ dual(2, (self, options3) => {
1406
1617
  times
1407
1618
  })));
1408
1619
  });
1620
+ var timeout = /* @__PURE__ */ dual(2, (self, duration) => {
1621
+ const decoded = fromInputUnsafe(duration);
1622
+ const description = `timed out after ${format2(decoded)}`;
1623
+ return transform(self, (effect2, request) => timeoutOrElse(effect2, {
1624
+ duration: decoded,
1625
+ orElse: () => fail3(new HttpClientError({
1626
+ reason: new TransportError({
1627
+ request,
1628
+ cause: new TimeoutError(`Operation ${description}`),
1629
+ description
1630
+ })
1631
+ }))
1632
+ }));
1633
+ });
1409
1634
  var withRateLimiter = /* @__PURE__ */ dual(2, (self, options3) => {
1410
1635
  const initialState = {
1411
1636
  initial: true,
@@ -1427,35 +1652,66 @@ var withRateLimiter = /* @__PURE__ */ dual(2, (self, options3) => {
1427
1652
  states.set(key, initialState);
1428
1653
  return initialState;
1429
1654
  };
1430
- const onResponse = options3.disableResponseInspection ? void 0 : (clock, key, headers, tokens) => {
1655
+ const budgets = /* @__PURE__ */ new Map();
1656
+ const getBudget = (key) => {
1657
+ let budget = budgets.get(key);
1658
+ if (budget === void 0) {
1659
+ budget = {
1660
+ sent: 0,
1661
+ observed: 0,
1662
+ remaining: 0,
1663
+ resetAt: 0
1664
+ };
1665
+ budgets.set(key, budget);
1666
+ }
1667
+ return budget;
1668
+ };
1669
+ const onResponse = options3.disableResponseInspection ? void 0 : (clock, key, headers, tokens, sent) => {
1431
1670
  const current = getState(key);
1432
1671
  const next = parseRateLimiterState(current, clock, headers, tokens, headerNames);
1433
1672
  if (next.limit !== current.limit || !equals(next.window, current.window)) {
1434
1673
  states.set(key, next);
1435
1674
  }
1675
+ const remaining = parseRateLimitRemaining(headers, headerNames);
1676
+ const budget = getBudget(key);
1677
+ if (remaining === void 0 || sent <= budget.observed) {
1678
+ return;
1679
+ }
1680
+ const resetAfter = parseRateLimitWindow(clock, headers, headerNames);
1681
+ budget.observed = sent;
1682
+ budget.remaining = remaining;
1683
+ if (resetAfter !== void 0) {
1684
+ budget.resetAt = clock.currentTimeMillisUnsafe() + toMillis(resetAfter);
1685
+ }
1436
1686
  };
1437
1687
  return transform(self, function loop(effect2, request, retries = 0) {
1438
1688
  const fiber = getCurrent();
1439
1689
  const clock = fiber.getRef(Clock);
1440
1690
  const key = resolveKey(request);
1441
1691
  const tokens = Math.max(resolveTokens(request), 1);
1692
+ const budget = getBudget(key);
1693
+ const now = clock.currentTimeMillisUnsafe();
1694
+ if (budget.resetAt > now && budget.remaining - (budget.sent - budget.observed) < tokens) {
1695
+ return flatMap(sleep(budget.resetAt - now), () => loop(effect2, request, retries));
1696
+ }
1697
+ const sent = budget.sent += tokens;
1442
1698
  const current = getState(key);
1443
1699
  const canRetry = options3.times === void 0 || retries < options3.times;
1444
1700
  function retry3(retryAfter) {
1445
1701
  return retryAfter ? flatMap(sleep(retryAfter), () => loop(effect2, request, retries + 1)) : loop(effect2, request, retries + 1);
1446
1702
  }
1447
1703
  const inspectResponse = (response, adaptive) => {
1448
- onResponse?.(clock, key, response.headers, tokens);
1704
+ onResponse?.(clock, key, response.headers, tokens, sent);
1449
1705
  if (options3.disableResponseInspection || response.status !== 429) {
1450
- return succeed2(void 0);
1706
+ return succeed4(void 0);
1451
1707
  }
1452
- const retryAfter = parseRetryAfter(clock, getHeader(response.headers, ...headerNames.retryAfter));
1708
+ const retryAfter = parseRetryAfter2(clock.currentTimeMillisUnsafe(), getHeader(response.headers, ...headerNames.retryAfter));
1453
1709
  if (retryAfter === void 0) {
1454
- return succeed2(void 0);
1710
+ return succeed4(void 0);
1455
1711
  }
1456
1712
  const delay2 = parseRateLimitWindow(clock, response.headers, headerNames) ?? retryAfter;
1457
1713
  if (adaptive === void 0) {
1458
- return succeed2(delay2);
1714
+ return succeed4(delay2);
1459
1715
  }
1460
1716
  return as(options3.limiter.adaptiveFeedback({
1461
1717
  key,
@@ -1480,7 +1736,7 @@ var withRateLimiter = /* @__PURE__ */ dual(2, (self, options3) => {
1480
1736
  const request2 = matchEffect(effect2, {
1481
1737
  onSuccess(response) {
1482
1738
  return flatMap(inspectResponse(response, adaptive), (retryAfter) => {
1483
- if (response.status !== 429 || !canRetry) return succeed2(response);
1739
+ if (response.status !== 429 || !canRetry) return succeed4(response);
1484
1740
  return retry3(retryAfter);
1485
1741
  });
1486
1742
  },
@@ -1512,6 +1768,70 @@ var withRateLimiter = /* @__PURE__ */ dual(2, (self, options3) => {
1512
1768
  });
1513
1769
  });
1514
1770
  });
1771
+ var withCircuitBreaker = /* @__PURE__ */ dual(2, (self, options3) => {
1772
+ const keyOption = options3.key;
1773
+ const resolveKey = typeof keyOption === "function" ? keyOption : keyOption === void 0 ? requestOrigin : constant(keyOption);
1774
+ const classify = options3.classify ?? circuitBreakerClassifier;
1775
+ return transform(self, (effect2, request) => options3.breaker.execute(effect2, {
1776
+ key: resolveKey(request),
1777
+ classify
1778
+ }));
1779
+ });
1780
+ var requestOrigin = (request) => match(toUrl(request), {
1781
+ onNone: () => request.url,
1782
+ onSome: (url) => url.origin
1783
+ });
1784
+ var circuitBreakerClassifier = (exit2) => clockWith((clock) => succeed4(classifyCircuitBreakerExit(exit2, clock.currentTimeMillisUnsafe())));
1785
+ var classifyCircuitBreakerExit = (exit2, nowMillis) => {
1786
+ if (isSuccess2(exit2)) {
1787
+ const outcome = circuitBreakerStatusOutcome(exit2.value.status);
1788
+ return outcome === "Failure" ? circuitBreakerFailure(retryAfterOf(exit2.value, nowMillis)) : {
1789
+ _tag: outcome
1790
+ };
1791
+ }
1792
+ let failed = false;
1793
+ let succeeded = false;
1794
+ let retryAfter;
1795
+ for (const reason of exit2.cause.reasons) {
1796
+ if (!isFailReason(reason)) {
1797
+ continue;
1798
+ }
1799
+ const outcome = circuitBreakerErrorOutcome(reason.error);
1800
+ if (outcome === "Failure") {
1801
+ failed = true;
1802
+ const hint = retryAfterOf(reason.error, nowMillis);
1803
+ if (hint !== void 0) {
1804
+ retryAfter = retryAfter === void 0 ? hint : max(retryAfter, hint);
1805
+ }
1806
+ } else if (outcome === "Success") {
1807
+ succeeded = true;
1808
+ }
1809
+ }
1810
+ return failed ? circuitBreakerFailure(retryAfter) : {
1811
+ _tag: succeeded ? "Success" : "Ignored"
1812
+ };
1813
+ };
1814
+ var circuitBreakerFailure = (retryAfter) => ({
1815
+ _tag: "Failure",
1816
+ retryAfter
1817
+ });
1818
+ var circuitBreakerErrorOutcome = (error) => {
1819
+ if (isTimeoutError(error)) {
1820
+ return "Failure";
1821
+ }
1822
+ if (!isHttpClientError(error)) {
1823
+ return "Ignored";
1824
+ }
1825
+ switch (error.reason._tag) {
1826
+ case "TransportError":
1827
+ return "Failure";
1828
+ case "StatusCodeError":
1829
+ return circuitBreakerStatusOutcome(error.reason.response.status);
1830
+ default:
1831
+ return "Ignored";
1832
+ }
1833
+ };
1834
+ var circuitBreakerStatusOutcome = (status) => status === 429 ? "Ignored" : status === 408 || status === 500 || status === 502 || status === 503 || status === 504 ? "Failure" : "Success";
1515
1835
  var resolveRateLimiterHeaderNames = (responseHeaders) => ({
1516
1836
  limit: responseHeaders?.limit === void 0 ? ["ratelimit-limit", "x-ratelimit-limit"] : [responseHeaders.limit.toLowerCase()],
1517
1837
  remaining: responseHeaders?.remaining === void 0 ? ["ratelimit-remaining", "x-ratelimit-remaining"] : [responseHeaders.remaining.toLowerCase()],
@@ -1555,23 +1875,12 @@ var parseRateLimitWindow = (clock, headers, headerNames) => {
1555
1875
  }
1556
1876
  return parseResetHeader(clock, getHeader(headers, ...headerNames.reset));
1557
1877
  };
1558
- var parseRetryAfter = (clock, value) => {
1878
+ var parseRetryAfter2 = (nowMillis, value) => {
1559
1879
  if (value === void 0) {
1560
1880
  return void 0;
1561
1881
  }
1562
- const numeric = parseNumberHeader(value);
1563
- if (numeric !== void 0) {
1564
- return max(seconds(numeric), millis(1));
1565
- }
1566
- const parsedDate = Date.parse(value);
1567
- if (Number.isNaN(parsedDate)) {
1568
- return void 0;
1569
- }
1570
- const millis2 = parsedDate - clock.currentTimeMillisUnsafe();
1571
- if (millis2 <= 0) {
1572
- return millis(1);
1573
- }
1574
- return millis(millis2);
1882
+ const retryAfter = parseRetryAfter(value);
1883
+ return isSuccess(retryAfter) ? max(retryAfterDelay(retryAfter.success, nowMillis), millis(1)) : void 0;
1575
1884
  };
1576
1885
  var parseResetAfter = (value) => {
1577
1886
  const numeric = parseNumberHeader(value);
@@ -1617,12 +1926,16 @@ var getHeader = (headers, ...keys) => {
1617
1926
  var tap2 = /* @__PURE__ */ dual(2, (self, f) => transformResponse(self, tap(f)));
1618
1927
  var tapError2 = /* @__PURE__ */ dual(2, (self, f) => transformResponse(self, tapError(f)));
1619
1928
  var tapRequest = /* @__PURE__ */ dual(2, (self, f) => makeWith2(self.postprocess, (request) => tap(self.preprocess(request), f)));
1620
- var withCookiesRef = /* @__PURE__ */ dual(2, (self, ref) => makeWith2((request) => tap(self.postprocess(request), (response) => update(ref, (cookies) => merge2(cookies, response.cookies))), (request) => flatMap(self.preprocess(request), (request2) => map(get3(ref), (cookies) => isEmpty(cookies) ? request2 : setHeader(request2, "cookie", toCookieHeader(cookies))))));
1621
- var withScope = (self) => transform(self, (effect2, request) => {
1622
- const controller = new AbortController();
1623
- scopedRequests.set(request, controller);
1624
- return andThen(addFinalizer(() => sync(() => controller.abort())), effect2);
1929
+ var withCookiesRef = /* @__PURE__ */ dual(2, (self, ref) => {
1930
+ const now = () => getCurrent().getRef(Clock).currentTimeMillisUnsafe();
1931
+ const addCookies = (request) => map(get3(ref), (cookies) => {
1932
+ const header = toRequestCookieHeader(cookies, request.url, now());
1933
+ if (header === void 0) return request;
1934
+ return setHeader(request, "cookie", header);
1935
+ });
1936
+ return makeWith2((request) => tap(self.postprocess(flatMap(request, addCookies)), (response) => update(ref, mergeIntoArray(response.url, response.cookies, now()))), self.preprocess);
1625
1937
  });
1938
+ var withScope = (self) => transformResponse(self, provideServiceEffect(RequestScope, scope));
1626
1939
  var followRedirects = /* @__PURE__ */ dual((args) => isHttpClient(args[0]), (self, maxRedirects) => makeWith2((request) => {
1627
1940
  const loop = (request2, redirects) => suspend(() => {
1628
1941
  let currentRequest;
@@ -1631,21 +1944,31 @@ var followRedirects = /* @__PURE__ */ dual((args) => isHttpClient(args[0]), (sel
1631
1944
  return request3;
1632
1945
  })), (response) => {
1633
1946
  if (response.status < 300 || response.status >= 400 || !response.headers.location || redirects >= (maxRedirects ?? 10)) {
1634
- return succeed2(response);
1947
+ return succeed4(response);
1948
+ }
1949
+ const urlResult = fromString(response.headers.location, response.request.url);
1950
+ if (isFailure(urlResult)) {
1951
+ return succeed4(response);
1635
1952
  }
1636
- const url = new URL(response.headers.location, response.request.url);
1953
+ const url = urlResult.success;
1637
1954
  const request3 = currentRequest ?? response.request;
1638
1955
  let nextRequest = request3;
1639
1956
  if ((response.status === 301 || response.status === 302) && request3.method === "POST" || response.status === 303 && request3.method !== "GET" && request3.method !== "HEAD") {
1640
1957
  nextRequest = setMethod(nextRequest, "GET");
1641
1958
  nextRequest = setBody(nextRequest, empty7);
1959
+ nextRequest = removeHeader(nextRequest, "content-encoding");
1960
+ nextRequest = removeHeader(nextRequest, "content-language");
1961
+ nextRequest = removeHeader(nextRequest, "content-location");
1642
1962
  }
1643
1963
  if (url.origin !== new URL(response.request.url).origin) {
1644
1964
  nextRequest = removeHeader(nextRequest, "authorization");
1645
1965
  nextRequest = removeHeader(nextRequest, "proxy-authorization");
1646
1966
  nextRequest = removeHeader(nextRequest, "cookie");
1647
1967
  }
1648
- return loop(succeed2(setUrl(nextRequest, url)), redirects + 1);
1968
+ const hash = url.hash === "" ? none() : some(url.hash.slice(1));
1969
+ url.hash = "";
1970
+ nextRequest = makeWith(nextRequest.method, url.href, empty5, hash, nextRequest.headers, nextRequest.body);
1971
+ return andThen(sync(() => responseControllers.get(response)?.abort()), loop(succeed4(nextRequest), redirects + 1));
1649
1972
  });
1650
1973
  });
1651
1974
  return loop(request, 0);
@@ -1654,19 +1977,22 @@ var TracerDisabledWhen = /* @__PURE__ */ Reference("effect/http/HttpClient/Trace
1654
1977
  defaultValue: () => constFalse
1655
1978
  });
1656
1979
  var TracerHeaderFilter = /* @__PURE__ */ Reference("effect/http/HttpClient/TracerHeaderFilter", {
1657
- defaultValue: () => constTrue
1980
+ defaultValue: () => constFalse
1658
1981
  });
1659
1982
  var TracerPropagationEnabled = /* @__PURE__ */ Reference("effect/http/HttpClient/TracerPropagationEnabled", {
1660
1983
  defaultValue: constTrue
1661
1984
  });
1662
1985
  var SpanNameGenerator = /* @__PURE__ */ Reference("effect/http/HttpClient/SpanNameGenerator", {
1663
- defaultValue: () => (request) => `http.client ${request.method}`
1986
+ defaultValue: () => (request) => request.method
1664
1987
  });
1665
1988
  var layerMergedContext = (effect2) => effect(HttpClient)(contextWith((context2) => map(effect2, (client) => transformResponse(client, updateContext((input) => merge(context2, input))))));
1666
1989
  var responseRegistry = /* @__PURE__ */ (() => {
1667
1990
  if ("FinalizationRegistry" in globalThis && globalThis.FinalizationRegistry) {
1668
1991
  const registry = /* @__PURE__ */ new FinalizationRegistry((controller) => {
1669
- controller.abort();
1992
+ try {
1993
+ controller.abort();
1994
+ } catch {
1995
+ }
1670
1996
  });
1671
1997
  return {
1672
1998
  register(response, controller) {
@@ -1677,7 +2003,7 @@ var responseRegistry = /* @__PURE__ */ (() => {
1677
2003
  }
1678
2004
  };
1679
2005
  }
1680
- const timers = /* @__PURE__ */ new Map();
2006
+ const timers = /* @__PURE__ */ new WeakMap();
1681
2007
  return {
1682
2008
  register(response, controller) {
1683
2009
  timers.set(response, setTimeout(() => controller.abort(), 5e3));
@@ -1690,7 +2016,20 @@ var responseRegistry = /* @__PURE__ */ (() => {
1690
2016
  }
1691
2017
  };
1692
2018
  })();
1693
- var scopedRequests = /* @__PURE__ */ new WeakMap();
2019
+ var RequestScope = /* @__PURE__ */ Reference("effect/http/HttpClient/RequestScope", {
2020
+ defaultValue: () => void 0
2021
+ });
2022
+ var responseControllers = /* @__PURE__ */ new WeakMap();
2023
+ var trackResponse = (response, controller, scoped, urlParamsRedactedNames) => {
2024
+ addResponseRedactedNames(response, urlParamsRedactedNames);
2025
+ if (!scoped) {
2026
+ responseRegistry.register(response, controller);
2027
+ response = new InterruptibleResponse(response, controller);
2028
+ addResponseRedactedNames(response, urlParamsRedactedNames);
2029
+ }
2030
+ responseControllers.set(response, controller);
2031
+ return response;
2032
+ };
1694
2033
  var InterruptibleResponse = class {
1695
2034
  original;
1696
2035
  controller;
@@ -1741,6 +2080,14 @@ var InterruptibleResponse = class {
1741
2080
  get arrayBuffer() {
1742
2081
  return this.applyInterrupt(this.original.arrayBuffer);
1743
2082
  }
2083
+ get upgrade() {
2084
+ return this.applyInterrupt(this.original.upgrade);
2085
+ }
2086
+ [WebSourceSymbol]() {
2087
+ const source = getWebSource(this.original);
2088
+ if (source !== void 0) responseRegistry.unregister(this.original);
2089
+ return source;
2090
+ }
1744
2091
  get stream() {
1745
2092
  return suspend2(() => {
1746
2093
  responseRegistry.unregister(this.original);
@@ -1761,10 +2108,21 @@ var InterruptibleResponse = class {
1761
2108
  };
1762
2109
  var isTransientError = (error) => isTimeoutError(error) || isTransientHttpError(error);
1763
2110
  var isTransientHttpError = (error) => isHttpClientError(error) && (error.reason._tag === "TransportError" || error.reason._tag === "StatusCodeError" && isTransientResponse(error.reason.response));
2111
+ var retryAfterOf = (input, nowMillis) => {
2112
+ const response = isHttpClientError(input) ? input.response : hasProperty(input, TypeId5) ? input : void 0;
2113
+ return parseRetryAfter2(nowMillis, response?.headers["retry-after"]);
2114
+ };
2115
+ var withRetryAfter = (schedule) => fromStep(map(toStep(schedule), (step) => (now, input) => {
2116
+ const retryAfter = retryAfterOf(input, now);
2117
+ if (retryAfter === void 0) {
2118
+ return step(now, input);
2119
+ }
2120
+ return map(step(now, input), ([output, delay2]) => [output, max(delay2, retryAfter)]);
2121
+ }));
1764
2122
  var isTooManyRequestsHttpClientError = (error) => isHttpClientError(error) && error.reason._tag === "StatusCodeError" && error.reason.response.status === 429;
1765
2123
  var isTransientResponse = (response) => response.status === 408 || response.status === 429 || response.status === 500 || response.status === 502 || response.status === 503 || response.status === 504;
1766
2124
 
1767
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/Template.js
2125
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/Template.js
1768
2126
  function make4(strings, ...args) {
1769
2127
  const argsLength = args.length;
1770
2128
  const values = new Array(argsLength);
@@ -1773,7 +2131,7 @@ function make4(strings, ...args) {
1773
2131
  const arg = args[i];
1774
2132
  if (isOption(arg)) {
1775
2133
  values[i] = arg._tag === "Some" ? primitiveToString(arg.value) : "";
1776
- } else if (isSuccess2(arg)) {
2134
+ } else if (isSuccess3(arg)) {
1777
2135
  values[i] = primitiveToString(arg.value);
1778
2136
  } else if (isEffect(arg)) {
1779
2137
  effects.push([i, arg]);
@@ -1782,7 +2140,7 @@ function make4(strings, ...args) {
1782
2140
  }
1783
2141
  }
1784
2142
  if (effects.length === 0) {
1785
- return succeed2(consolidate(strings, values));
2143
+ return succeed4(consolidate(strings, values));
1786
2144
  }
1787
2145
  return map(forEach(effects, ([index, effect2]) => tap(effect2, (value) => sync(() => {
1788
2146
  values[index] = primitiveToString(value);
@@ -1799,7 +2157,7 @@ function stream2(strings, ...args) {
1799
2157
  const arg = args[i];
1800
2158
  if (isOption(arg)) {
1801
2159
  buffer2 += arg._tag === "Some" ? primitiveToString(arg.value) : "";
1802
- } else if (isSuccess2(arg)) {
2160
+ } else if (isSuccess3(arg)) {
1803
2161
  buffer2 += primitiveToString(arg.value);
1804
2162
  } else if (isEffect(arg)) {
1805
2163
  if (buffer2.length > 0) {
@@ -1822,9 +2180,9 @@ function stream2(strings, ...args) {
1822
2180
  chunks.push(buffer2);
1823
2181
  buffer2 = "";
1824
2182
  }
1825
- return fromIterable2(chunks).pipe(mapEffect((chunk) => isEffect(chunk) ? chunk : succeed2(chunk), {
2183
+ return fromIterable2(chunks).pipe(mapEffect((chunk) => isEffect(chunk) ? chunk : succeed4(chunk), {
1826
2184
  concurrency: "unbounded"
1827
- }), flatMap2((chunk) => typeof chunk === "string" ? succeed3(chunk) : chunk));
2185
+ }), flatMap2((chunk) => typeof chunk === "string" ? succeed5(chunk) : chunk));
1828
2186
  }
1829
2187
  function primitiveToString(value) {
1830
2188
  if (Array.isArray(value)) {
@@ -1854,11 +2212,11 @@ function consolidate(strings, values) {
1854
2212
  }
1855
2213
  return out + strings[strings.length - 1];
1856
2214
  }
1857
- function isSuccess2(u) {
2215
+ function isSuccess3(u) {
1858
2216
  return isExit(u) && u._tag === "Success";
1859
2217
  }
1860
2218
 
1861
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpServerResponse.js
2219
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpServerResponse.js
1862
2220
  var HttpServerResponse_exports = {};
1863
2221
  __export(HttpServerResponse_exports, {
1864
2222
  empty: () => empty9,
@@ -1900,11 +2258,11 @@ __export(HttpServerResponse_exports, {
1900
2258
  urlParams: () => urlParams2
1901
2259
  });
1902
2260
 
1903
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/internal/headers.js
2261
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/internal/headers.js
1904
2262
  var Proto4 = /* @__PURE__ */ Object.getPrototypeOf(empty4);
1905
2263
  var emptyMutableUnsafe = () => Object.create(Proto4);
1906
2264
 
1907
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpServerResponse.js
2265
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpServerResponse.js
1908
2266
  var TypeId7 = "~effect/http/HttpServerResponse";
1909
2267
  var isHttpServerResponse = (u) => hasProperty(u, TypeId7);
1910
2268
  var empty9 = (options3) => makeResponse({
@@ -1975,10 +2333,10 @@ var json2 = (body, options3) => {
1975
2333
  }));
1976
2334
  };
1977
2335
  var schemaJson = (schema, options3) => {
1978
- const encode = jsonSchema(schema, options3);
2336
+ const encode2 = jsonSchema(schema, options3);
1979
2337
  return (body, options4) => {
1980
2338
  const headers = options4?.headers ? fromInput2(options4.headers) : empty4;
1981
- return map(encode(body, getContentType(options4, headers)), (body2) => makeResponse({
2339
+ return map(encode2(body, getContentType(options4, headers)), (body2) => makeResponse({
1982
2340
  status: options4?.status ?? 200,
1983
2341
  statusText: options4?.statusText,
1984
2342
  headers,
@@ -2102,6 +2460,17 @@ var setStatus = /* @__PURE__ */ dual((args) => isHttpServerResponse(args[0]), (s
2102
2460
  statusText: statusText ?? self.statusText
2103
2461
  }));
2104
2462
  var omitsBody = (response, withoutBody = false) => withoutBody || response.status === 204 || response.status === 205 || response.status === 304;
2463
+ var omitsContentLength = (status) => status === 204 || status === 205;
2464
+ var mergeHeaders = (target, headers) => {
2465
+ for (const [key, value] of headers) {
2466
+ if (key === "set-cookie") {
2467
+ target.append(key, value);
2468
+ } else {
2469
+ target.set(key, value);
2470
+ }
2471
+ }
2472
+ return target;
2473
+ };
2105
2474
  var toWeb2 = (response, options3) => {
2106
2475
  const headers = new globalThis.Headers(response.headers);
2107
2476
  if (!isEmpty(response.cookies)) {
@@ -2115,27 +2484,25 @@ var toWeb2 = (response, options3) => {
2115
2484
  const withoutBody = outerOmitsBody || options3?.withoutBody === true;
2116
2485
  if (body._tag === "Raw" && body.body instanceof Response) {
2117
2486
  const raw3 = body.body;
2118
- for (const [key, value] of headers) {
2119
- if (key === "set-cookie") {
2120
- raw3.headers.append(key, value);
2121
- } else {
2122
- raw3.headers.set(key, value);
2123
- }
2124
- }
2125
- if (!withoutBody) {
2487
+ const source = outerOmitsBody ? response : raw3;
2488
+ const omitContentLength = omitsContentLength(source.status);
2489
+ if (!withoutBody && headers.keys().next().done && !(omitContentLength && raw3.headers.has("content-length"))) {
2126
2490
  return raw3;
2127
2491
  }
2128
- const source = outerOmitsBody ? response : raw3;
2129
- return new Response(void 0, {
2492
+ const copy = withoutBody ? new Response(void 0, {
2130
2493
  status: source.status,
2131
2494
  statusText: source.statusText,
2132
2495
  headers: raw3.headers
2133
- });
2496
+ }) : new Response(raw3.body, raw3);
2497
+ mergeHeaders(copy.headers, headers);
2498
+ if (omitContentLength) copy.headers.delete("content-length");
2499
+ return copy;
2134
2500
  }
2135
2501
  if (withoutBody) {
2136
2502
  if (body._tag === "Raw" && isReadableStream2(body.body)) {
2137
2503
  body.body.cancel().catch(constVoid);
2138
2504
  }
2505
+ if (omitsContentLength(response.status)) headers.delete("content-length");
2139
2506
  return new Response(void 0, {
2140
2507
  status: response.status,
2141
2508
  statusText: response.statusText,
@@ -2172,7 +2539,9 @@ var toWeb2 = (response, options3) => {
2172
2539
  });
2173
2540
  }
2174
2541
  case "Stream": {
2175
- return new Response(toReadableStreamWith(body.stream, options3?.context ?? empty()), {
2542
+ return new Response(toReadableStreamWith(body.stream, options3?.context ?? empty(), {
2543
+ signal: options3?.signal
2544
+ }), {
2176
2545
  status: response.status,
2177
2546
  statusText: response.statusText,
2178
2547
  headers
@@ -2230,7 +2599,7 @@ var ServerHttpClientResponse = class extends Class {
2230
2599
  return mapError3(body.stream, (cause) => this.decodeError(cause));
2231
2600
  }
2232
2601
  case "Uint8Array": {
2233
- return succeed3(body.body);
2602
+ return succeed5(body.body);
2234
2603
  }
2235
2604
  case "Raw": {
2236
2605
  const rawBody = body.body;
@@ -2252,7 +2621,7 @@ var ServerHttpClientResponse = class extends Class {
2252
2621
  onError: (cause) => this.decodeError(cause)
2253
2622
  });
2254
2623
  }
2255
- return unwrap2(map(this.bytes, succeed3));
2624
+ return unwrap3(map(this.bytes, succeed5));
2256
2625
  }
2257
2626
  case "FormData": {
2258
2627
  const response = this.getFormDataResponse();
@@ -2279,10 +2648,10 @@ var ServerHttpClientResponse = class extends Class {
2279
2648
  const body = this.response.body;
2280
2649
  switch (body._tag) {
2281
2650
  case "Empty": {
2282
- return succeed2(new Uint8Array(0));
2651
+ return succeed4(new Uint8Array(0));
2283
2652
  }
2284
2653
  case "Uint8Array": {
2285
- return succeed2(body.body);
2654
+ return succeed4(body.body);
2286
2655
  }
2287
2656
  case "Stream": {
2288
2657
  return mkUint8Array2(this.stream);
@@ -2312,8 +2681,8 @@ var ServerHttpClientResponse = class extends Class {
2312
2681
  return map(this.bytes, (bytes) => textDecoder.decode(bytes));
2313
2682
  }
2314
2683
  get urlParamsBody() {
2315
- return flatMap(this.text, (_) => try_2({
2316
- try: () => fromInput3(new URLSearchParams(_)),
2684
+ return flatMap(this.bytes, (bytes) => try_2({
2685
+ try: () => fromInput3(fromBody(bytes)),
2317
2686
  catch: (cause) => new HttpClientError({
2318
2687
  reason: new DecodeError({
2319
2688
  request: this.request,
@@ -2326,7 +2695,7 @@ var ServerHttpClientResponse = class extends Class {
2326
2695
  get formData() {
2327
2696
  const body = this.response.body;
2328
2697
  if (body._tag === "FormData") {
2329
- return succeed2(body.formData);
2698
+ return succeed4(body.formData);
2330
2699
  }
2331
2700
  return contextWith((context2) => {
2332
2701
  const readableStream = toReadableStreamWith(this.stream, context2);
@@ -2358,6 +2727,15 @@ var ServerHttpClientResponse = class extends Class {
2358
2727
  getFormDataResponse() {
2359
2728
  return this.formDataResponse ??= new Response(this.response.body.formData);
2360
2729
  }
2730
+ get upgrade() {
2731
+ return fail3(new HttpClientError({
2732
+ reason: new StatusCodeError({
2733
+ request: this.request,
2734
+ response: this,
2735
+ description: "a server response has no connection to hand over"
2736
+ })
2737
+ }));
2738
+ }
2361
2739
  pipe() {
2362
2740
  return pipeArguments(this, arguments);
2363
2741
  }
@@ -2423,19 +2801,85 @@ var fromWeb3 = (response) => {
2423
2801
  cookies: fromSetCookie(setCookieHeaders)
2424
2802
  });
2425
2803
  if (response.body) {
2426
- const contentType = response.headers.get("content-type");
2804
+ const contentType2 = response.headers.get("content-type");
2427
2805
  self = setBody2(self, stream(fromReadableStream({
2428
2806
  evaluate: () => response.body,
2429
2807
  onError: (e) => e
2430
- }), contentType ?? void 0, parseContentLength(response.headers.get("content-length"))));
2808
+ }), contentType2 ?? void 0, parseContentLength(response.headers.get("content-length"))));
2431
2809
  }
2432
2810
  return self;
2433
2811
  };
2434
2812
 
2435
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpServerRespondable.js
2813
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/internal/compression.js
2814
+ var varyWith = (headers, dimension) => {
2815
+ const vary = headers["vary"];
2816
+ if (vary === void 0) {
2817
+ return dimension;
2818
+ }
2819
+ const members = vary.split(",").map((member) => member.trim().toLowerCase());
2820
+ return members.includes("*") || members.includes(dimension.toLowerCase()) ? vary : `${vary}, ${dimension}`;
2821
+ };
2822
+ var defaultCompressible = (contentType2) => {
2823
+ const semi = contentType2.indexOf(";");
2824
+ const type = (semi === -1 ? contentType2 : contentType2.slice(0, semi)).trim().toLowerCase();
2825
+ if (type.startsWith("text/")) {
2826
+ return true;
2827
+ }
2828
+ switch (type) {
2829
+ case "application/json":
2830
+ case "application/javascript":
2831
+ case "application/xml":
2832
+ case "image/svg+xml":
2833
+ case "application/wasm": {
2834
+ return true;
2835
+ }
2836
+ }
2837
+ return type.endsWith("+json") || type.endsWith("+xml");
2838
+ };
2839
+ var acceptMember = /^([a-z0-9!#$%&'*+.^_`|~-]+)(?:;q=(0(?:\.[0-9]{0,3})?|1(?:\.0{0,3})?))?$/;
2840
+ var parseAcceptEncoding = (header) => {
2841
+ const accepted = /* @__PURE__ */ new Map();
2842
+ for (const part of header.split(",")) {
2843
+ const member = part.trim().toLowerCase().replace(/[ \t]*;[ \t]*/g, ";");
2844
+ if (member === "") {
2845
+ continue;
2846
+ }
2847
+ const match2 = acceptMember.exec(member);
2848
+ if (match2 === null) {
2849
+ return void 0;
2850
+ }
2851
+ accepted.set(match2[1], match2[2] === void 0 ? 1 : Number(match2[2]));
2852
+ }
2853
+ return accepted;
2854
+ };
2855
+ var negotiate = (header, preferred, supported) => {
2856
+ if (header === void 0) {
2857
+ return void 0;
2858
+ }
2859
+ const accepted = parseAcceptEncoding(header);
2860
+ if (accepted === void 0) {
2861
+ return void 0;
2862
+ }
2863
+ for (const algorithm of preferred) {
2864
+ if (!supported.has(algorithm)) {
2865
+ continue;
2866
+ }
2867
+ const quality = accepted.get(algorithm) ?? accepted.get("*");
2868
+ if (quality !== void 0 && quality > 0) {
2869
+ return algorithm;
2870
+ }
2871
+ }
2872
+ return void 0;
2873
+ };
2874
+
2875
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpPlatform.js
2876
+ var HttpPlatform = class extends (/* @__PURE__ */ Service()("effect/http/HttpPlatform")) {
2877
+ };
2878
+
2879
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpServerRespondable.js
2436
2880
  var symbol = "~effect/http/HttpServerRespondable";
2437
2881
 
2438
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpServerError.js
2882
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpServerError.js
2439
2883
  var TypeId8 = "~effect/http/HttpServerError";
2440
2884
  var HttpServerError = class extends (/* @__PURE__ */ TaggedError("HttpServerError")) {
2441
2885
  constructor(props) {
@@ -2468,18 +2912,19 @@ var HttpServerError = class extends (/* @__PURE__ */ TaggedError("HttpServerErro
2468
2912
  };
2469
2913
  var RequestParseError = class extends (/* @__PURE__ */ TaggedError("RequestParseError")) {
2470
2914
  /**
2471
- * Converts the request error into a `400 Bad Request` response.
2915
+ * Converts the request error into a `413 Content Too Large` response for body
2916
+ * size breaches, or a `400 Bad Request` response for other parse failures.
2472
2917
  *
2473
2918
  * @stability unstable
2474
2919
  * @since 4.0.0
2475
2920
  */
2476
2921
  [symbol]() {
2477
- return succeed2(empty9({
2478
- status: 400
2922
+ return succeed4(empty9({
2923
+ status: this.reason === "BodyTooLarge" ? 413 : 400
2479
2924
  }));
2480
2925
  }
2481
2926
  get methodAndUrl() {
2482
- return `${this.request.method} ${this.request.url}`;
2927
+ return formatMethodAndUrl2(this.request);
2483
2928
  }
2484
2929
  get message() {
2485
2930
  return formatRequestMessage(this._tag, this.description, this.methodAndUrl);
@@ -2487,13 +2932,13 @@ var RequestParseError = class extends (/* @__PURE__ */ TaggedError("RequestParse
2487
2932
  };
2488
2933
  var RouteNotFound = class extends (/* @__PURE__ */ TaggedError("RouteNotFound")) {
2489
2934
  [symbol]() {
2490
- return succeed2(empty9({
2935
+ return succeed4(empty9({
2491
2936
  status: 404
2492
2937
  }));
2493
2938
  }
2494
2939
  [ignore] = true;
2495
2940
  get methodAndUrl() {
2496
- return `${this.request.method} ${this.request.url}`;
2941
+ return formatMethodAndUrl2(this.request);
2497
2942
  }
2498
2943
  get message() {
2499
2944
  return formatRequestMessage(this._tag, this.description, this.methodAndUrl);
@@ -2507,12 +2952,12 @@ var InternalError = class extends (/* @__PURE__ */ TaggedError("InternalError"))
2507
2952
  * @since 4.0.0
2508
2953
  */
2509
2954
  [symbol]() {
2510
- return succeed2(empty9({
2955
+ return succeed4(empty9({
2511
2956
  status: 500
2512
2957
  }));
2513
2958
  }
2514
2959
  get methodAndUrl() {
2515
- return `${this.request.method} ${this.request.url}`;
2960
+ return formatMethodAndUrl2(this.request);
2516
2961
  }
2517
2962
  get message() {
2518
2963
  return formatRequestMessage(this._tag, this.description, this.methodAndUrl);
@@ -2520,83 +2965,350 @@ var InternalError = class extends (/* @__PURE__ */ TaggedError("InternalError"))
2520
2965
  };
2521
2966
  var ResponseError = class extends (/* @__PURE__ */ TaggedError("ResponseError")) {
2522
2967
  [symbol]() {
2523
- return succeed2(empty9({
2968
+ return succeed4(empty9({
2524
2969
  status: 500
2525
2970
  }));
2526
2971
  }
2527
2972
  get methodAndUrl() {
2528
- return `${this.request.method} ${this.request.url}`;
2973
+ return formatMethodAndUrl2(this.request);
2529
2974
  }
2530
2975
  get message() {
2531
2976
  const info = `${this._tag} (${this.response.status} ${this.methodAndUrl})`;
2532
2977
  return this.description ? `${info}: ${this.description}` : info;
2533
2978
  }
2534
2979
  };
2980
+ var ClientAbort = class extends (/* @__PURE__ */ Service()("effect/http/HttpServerError/ClientAbort")) {
2981
+ static annotation = /* @__PURE__ */ this.context(true).pipe(/* @__PURE__ */ add(StackTrace, {
2982
+ name: "ClientAbort",
2983
+ stack: constUndefined,
2984
+ parent: void 0
2985
+ }));
2986
+ };
2987
+ var formatMethodAndUrl2 = (request) => `${request.method} ${toPath(request.url)}`;
2535
2988
  var formatRequestMessage = (reason, description, info) => {
2536
2989
  const prefix = `${reason} (${info})`;
2537
2990
  return description ? `${prefix}: ${description}` : prefix;
2538
2991
  };
2539
-
2540
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/MultipartParser/internal/contentType.js
2541
- var paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\v\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u{10ffff}]|\\[\v\u0020-\u{10ffff}])*"|[!#$%&'*+.^\w`|~-]+) */gu;
2542
- var quotedPairRE = /\\([\v\u0020-\u{10ffff}])/gu;
2543
- var mediaTypeRE = /^[!#$%&'*+.^\w|~-]+\/[!#$%&'*+.^\w|~-]+$/u;
2544
- var mediaTypeRENoSlash = /^[!#$%&'*+.^\w|~-]+$/u;
2545
- var defaultContentType = {
2546
- value: "",
2547
- parameters: /* @__PURE__ */ Object.create(null)
2548
- };
2549
- function parse(header, withoutSlash = false) {
2550
- if (typeof header !== "string") {
2551
- return defaultContentType;
2552
- }
2553
- let index = header.indexOf(";");
2554
- const type = index !== -1 ? header.slice(0, index).trim() : header.trim();
2555
- const mediaRE = withoutSlash ? mediaTypeRENoSlash : mediaTypeRE;
2556
- if (mediaRE.test(type) === false) {
2557
- return defaultContentType;
2558
- }
2559
- const result = {
2560
- value: type.toLowerCase(),
2561
- parameters: /* @__PURE__ */ Object.create(null)
2562
- };
2563
- if (index === -1) {
2564
- return result;
2565
- }
2566
- let key;
2567
- let match2;
2568
- let value;
2569
- paramRE.lastIndex = index;
2570
- while (match2 = paramRE.exec(header)) {
2571
- if (match2.index !== index) {
2572
- return defaultContentType;
2992
+ var causeResponseStripped = (cause) => {
2993
+ let response;
2994
+ const failures = cause.reasons.filter((f) => {
2995
+ if (f._tag === "Die" && isHttpServerResponse(f.defect)) {
2996
+ response = f.defect;
2997
+ return false;
2573
2998
  }
2574
- index += match2[0].length;
2575
- key = match2[1].toLowerCase();
2576
- value = match2[2];
2577
- if (value[0] === '"') {
2578
- value = value.slice(1, value.length - 1);
2579
- if (!withoutSlash && quotedPairRE.test(value)) {
2580
- value = value.replace(quotedPairRE, "$1");
2999
+ return true;
3000
+ });
3001
+ return [response ?? internalServerError, failures.length > 0 ? some(fromReasons(failures)) : none()];
3002
+ };
3003
+ var internalServerError = /* @__PURE__ */ empty9({
3004
+ status: 500
3005
+ });
3006
+
3007
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/socket/Socket.js
3008
+ var TypeId9 = "~effect/socket/Socket";
3009
+ var isSocket = (u) => hasProperty(u, TypeId9);
3010
+ var encoder2 = /* @__PURE__ */ new TextEncoder();
3011
+ var readerBytes = (self) => map(self.reader, ({
3012
+ pull
3013
+ }) => map(pull, (chunk) => {
3014
+ for (let i = 0; i < chunk.length; i++) {
3015
+ if (typeof chunk[i] === "string") {
3016
+ const out = new Array(chunk.length);
3017
+ for (let j = 0; j < chunk.length; j++) {
3018
+ const item = chunk[j];
3019
+ out[j] = typeof item === "string" ? encoder2.encode(item) : item;
2581
3020
  }
3021
+ return out;
2582
3022
  }
2583
- result.parameters[key] = value;
2584
3023
  }
2585
- if (index !== header.length) {
2586
- return defaultContentType;
3024
+ return chunk;
3025
+ }));
3026
+ var CloseEventTypeId = "~effect/socket/Socket/CloseEvent";
3027
+ var CloseEvent = class {
3028
+ /**
3029
+ * Marks this value as a socket close event for runtime guards.
3030
+ *
3031
+ * @stability unstable
3032
+ * @since 4.0.0
3033
+ */
3034
+ [CloseEventTypeId];
3035
+ code;
3036
+ reason;
3037
+ constructor(code = 1e3, reason) {
3038
+ this[CloseEventTypeId] = CloseEventTypeId;
3039
+ this.code = code;
3040
+ this.reason = reason;
2587
3041
  }
2588
- return result;
2589
- }
2590
-
2591
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/MultipartParser/internal/headers.js
2592
- var constMaxPairs = 100;
2593
- var constMaxSize = 16 * 1024;
2594
- var State = {
2595
- key: 0,
2596
- whitespace: 1,
2597
- value: 2
2598
- };
2599
- var constContinue = {
3042
+ /**
3043
+ * Formats the close code and optional reason for display.
3044
+ *
3045
+ * @stability unstable
3046
+ * @since 4.0.0
3047
+ */
3048
+ toString() {
3049
+ return this.reason ? `${this.code}: ${this.reason}` : `${this.code}`;
3050
+ }
3051
+ };
3052
+ var isCloseEvent = (u) => hasProperty(u, CloseEventTypeId);
3053
+ var SocketErrorTypeId = "~effect/socket/Socket/SocketError";
3054
+ var isSocketError = (u) => hasProperty(u, SocketErrorTypeId);
3055
+ var SocketReadError = class extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketReadError")({
3056
+ _tag: /* @__PURE__ */ tag("SocketReadError"),
3057
+ cause: /* @__PURE__ */ Defect()
3058
+ })) {
3059
+ /**
3060
+ * Default message used for socket read failures.
3061
+ *
3062
+ * @stability unstable
3063
+ * @since 4.0.0
3064
+ */
3065
+ message = `An error occurred during Read`;
3066
+ };
3067
+ var SocketWriteError = class extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketWriteError")({
3068
+ _tag: /* @__PURE__ */ tag("SocketWriteError"),
3069
+ cause: /* @__PURE__ */ Defect()
3070
+ })) {
3071
+ /**
3072
+ * Default message used for socket write failures.
3073
+ *
3074
+ * @stability unstable
3075
+ * @since 4.0.0
3076
+ */
3077
+ message = `An error occurred during Write`;
3078
+ };
3079
+ var SocketOpenError = class extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketOpenError")({
3080
+ _tag: /* @__PURE__ */ tag("SocketOpenError"),
3081
+ kind: /* @__PURE__ */ Literals(["Unknown", "Timeout"]),
3082
+ cause: /* @__PURE__ */ Defect()
3083
+ })) {
3084
+ /**
3085
+ * Formats timeout and unknown open failures for display.
3086
+ *
3087
+ * @stability unstable
3088
+ * @since 4.0.0
3089
+ */
3090
+ get message() {
3091
+ return this.kind === "Timeout" ? `timeout waiting for "open"` : `An error occurred during Open`;
3092
+ }
3093
+ };
3094
+ var SocketUpgradeError = class _SocketUpgradeError extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketUpgradeError")({
3095
+ _tag: /* @__PURE__ */ tag("SocketUpgradeError"),
3096
+ cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
3097
+ })) {
3098
+ /**
3099
+ * An upgrade implementation for transports that cannot wrap the connection
3100
+ * with TLS.
3101
+ *
3102
+ * @stability unstable
3103
+ * @since 4.0.0
3104
+ */
3105
+ static unsupported = () => fail3(new SocketError({
3106
+ reason: new _SocketUpgradeError({})
3107
+ }));
3108
+ get message() {
3109
+ return this.cause === void 0 ? `Socket does not support TLS upgrade` : `An error occurred during TLS upgrade`;
3110
+ }
3111
+ };
3112
+ var SocketCloseError = class extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketCloseError")({
3113
+ _tag: /* @__PURE__ */ tag("SocketCloseError"),
3114
+ code: Int,
3115
+ closeReason: /* @__PURE__ */ optional(String2)
3116
+ })) {
3117
+ get message() {
3118
+ if (this.closeReason) {
3119
+ return `${this.code}: ${this.closeReason}`;
3120
+ }
3121
+ return `${this.code}`;
3122
+ }
3123
+ };
3124
+ var SocketErrorReason = /* @__PURE__ */ Union([SocketReadError, SocketWriteError, SocketOpenError, SocketUpgradeError, SocketCloseError]);
3125
+ var SocketError = class extends (/* @__PURE__ */ TaggedError2(SocketErrorTypeId)("SocketError", {
3126
+ _tag: /* @__PURE__ */ tag("SocketError"),
3127
+ reason: SocketErrorReason
3128
+ })) {
3129
+ // @effect-diagnostics-next-line overriddenSchemaConstructor:off
3130
+ constructor(props) {
3131
+ if ("cause" in props.reason) {
3132
+ super({
3133
+ ...props,
3134
+ cause: props.reason.cause
3135
+ });
3136
+ } else {
3137
+ super(props);
3138
+ }
3139
+ }
3140
+ /**
3141
+ * Marks this value as a socket error wrapper for runtime guards.
3142
+ *
3143
+ * @stability unstable
3144
+ * @since 4.0.0
3145
+ */
3146
+ [SocketErrorTypeId] = SocketErrorTypeId;
3147
+ /**
3148
+ * Returns `true` when the value is a `SocketError`.
3149
+ *
3150
+ * @stability unstable
3151
+ * @since 4.0.0
3152
+ */
3153
+ static is(u) {
3154
+ return isSocketError(u);
3155
+ }
3156
+ message = this.reason.message;
3157
+ };
3158
+ var writeChunk = (writer, chunk) => {
3159
+ for (let i = 0; i < chunk.length; i++) {
3160
+ if (isCloseEvent(chunk[i])) {
3161
+ return gen(function* () {
3162
+ for (let index = 0; index <= i; index++) {
3163
+ yield* writer.write(chunk[index]);
3164
+ }
3165
+ });
3166
+ }
3167
+ }
3168
+ return writer.writeAll(chunk);
3169
+ };
3170
+ var toChannelWithReader = (self, reader) => fromTransform(fnUntraced(function* (upstream, scope2) {
3171
+ const readScope = yield* fork(scope2);
3172
+ const pull = yield* provide(reader, readScope);
3173
+ const writeScope = yield* fork(scope2);
3174
+ const writer = yield* provide(self.writer, writeScope);
3175
+ let writeFailure;
3176
+ yield* upstream.pipe(flatMap((chunk) => writeChunk(writer, chunk)), forever2({
3177
+ disableYield: true
3178
+ }), catchCauseFilter(filterNoDone, (cause) => suspend(() => {
3179
+ writeFailure = cause;
3180
+ return close(readScope, void_);
3181
+ })), ensuring(close(writeScope, void_)), forkIn(scope2));
3182
+ return catchCause(suspend(() => writeFailure !== void 0 ? failCause2(writeFailure) : pull), (cause) => failCause2(writeFailure ?? cause));
3183
+ }));
3184
+ var toChannel = (self) => toChannelWithReader(self, readerBytes(self));
3185
+ var toChannelWith = () => (self) => toChannel(self);
3186
+ var defaultHighWaterMark = 64 * 1024;
3187
+
3188
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/MultipartParser/internal/contentType.js
3189
+ var paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\t\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u{10ffff}]|\\[\t\u0020-\u{10ffff}])*"|[!#$%&'*+.^\w`|~-]+) */gu;
3190
+ var dispositionParamRE = /;[ \t]*([!#$%&'*+.^\w`|~-]+)[ \t]*=[ \t]*("(?:[\t\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u{10ffff}]|\\[\t\u0020-\u{10ffff}])*"|[!#$%&'*+.^\w`|~-]+)[ \t]*/gu;
3191
+ var quotedPairRE = /\\([\t\u0020-\u{10ffff}])/gu;
3192
+ var mediaTypeRE = /^[!#$%&'*+.^\w|~-]+\/[!#$%&'*+.^\w|~-]+$/u;
3193
+ var dispositionTypeRE = /^[!#$%&'*+.^\w|~-]+$/u;
3194
+ var defaultContentType = {
3195
+ value: "",
3196
+ parameters: /* @__PURE__ */ Object.create(null)
3197
+ };
3198
+ function parse(header) {
3199
+ if (typeof header !== "string") {
3200
+ return defaultContentType;
3201
+ }
3202
+ let index = header.indexOf(";");
3203
+ const type = index !== -1 ? header.slice(0, index).trim() : header.trim();
3204
+ if (mediaTypeRE.test(type) === false) {
3205
+ return defaultContentType;
3206
+ }
3207
+ const result = {
3208
+ value: type.toLowerCase(),
3209
+ parameters: /* @__PURE__ */ Object.create(null)
3210
+ };
3211
+ if (index === -1) {
3212
+ return result;
3213
+ }
3214
+ let key;
3215
+ let match2;
3216
+ let value;
3217
+ paramRE.lastIndex = index;
3218
+ while (match2 = paramRE.exec(header)) {
3219
+ if (match2.index !== index) {
3220
+ return defaultContentType;
3221
+ }
3222
+ index += match2[0].length;
3223
+ key = match2[1].toLowerCase();
3224
+ value = match2[2];
3225
+ if (value[0] === '"') {
3226
+ value = value.slice(1, value.length - 1);
3227
+ if (quotedPairRE.test(value)) {
3228
+ value = value.replace(quotedPairRE, "$1");
3229
+ }
3230
+ }
3231
+ result.parameters[key] = value;
3232
+ }
3233
+ if (index !== header.length) {
3234
+ return defaultContentType;
3235
+ }
3236
+ return result;
3237
+ }
3238
+ var extValueRE = /^(utf-8|iso-8859-1)'[a-z0-9-]*'((?:%[0-9a-f]{2}|[!#$&+.^_`|~\w-])*)$/i;
3239
+ var pctEncodedRE = /%([0-9a-f]{2})/gi;
3240
+ function decodeExtValue(value) {
3241
+ const match2 = extValueRE.exec(value);
3242
+ if (match2 === null) {
3243
+ return void 0;
3244
+ }
3245
+ if (match2[1].toLowerCase() === "iso-8859-1") {
3246
+ return match2[2].replace(pctEncodedRE, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
3247
+ }
3248
+ try {
3249
+ return decodeURIComponent(match2[2]);
3250
+ } catch {
3251
+ return void 0;
3252
+ }
3253
+ }
3254
+ var defaultContentDisposition = {
3255
+ ...defaultContentType,
3256
+ filename: void 0
3257
+ };
3258
+ function parseDisposition(header) {
3259
+ if (header === void 0) {
3260
+ return defaultContentDisposition;
3261
+ } else if (typeof header !== "string") {
3262
+ return void 0;
3263
+ }
3264
+ let index = header.indexOf(";");
3265
+ const type = index !== -1 ? header.slice(0, index).trim() : header.trim();
3266
+ if (dispositionTypeRE.test(type) === false) {
3267
+ return void 0;
3268
+ }
3269
+ const parameters = /* @__PURE__ */ Object.create(null);
3270
+ if (index !== -1) {
3271
+ let match2;
3272
+ dispositionParamRE.lastIndex = index;
3273
+ while (match2 = dispositionParamRE.exec(header)) {
3274
+ if (match2.index !== index) {
3275
+ return void 0;
3276
+ }
3277
+ index += match2[0].length;
3278
+ const key = match2[1].toLowerCase();
3279
+ const value = match2[2];
3280
+ if (key in parameters) {
3281
+ return void 0;
3282
+ }
3283
+ parameters[key] = value[0] === '"' ? value.slice(1, value.length - 1) : value;
3284
+ }
3285
+ if (index !== header.length) {
3286
+ return void 0;
3287
+ }
3288
+ }
3289
+ let filename = parameters.filename;
3290
+ if ("filename*" in parameters) {
3291
+ filename = decodeExtValue(parameters["filename*"]);
3292
+ if (filename === void 0) {
3293
+ return void 0;
3294
+ }
3295
+ }
3296
+ return {
3297
+ value: type.toLowerCase(),
3298
+ parameters,
3299
+ filename
3300
+ };
3301
+ }
3302
+
3303
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/MultipartParser/internal/headers.js
3304
+ var constMaxPairs = 100;
3305
+ var constMaxSize = 16 * 1024;
3306
+ var State = {
3307
+ key: 0,
3308
+ whitespace: 1,
3309
+ value: 2
3310
+ };
3311
+ var constContinue = {
2600
3312
  _tag: "Continue"
2601
3313
  };
2602
3314
  var constNameChars = /* @__PURE__ */ new Uint8Array(256);
@@ -2634,12 +3346,6 @@ function make5() {
2634
3346
  state.size = 0;
2635
3347
  return value;
2636
3348
  }
2637
- function concatUint8Array(a, b) {
2638
- const newUint8Array = new Uint8Array(a.length + b.length);
2639
- newUint8Array.set(a);
2640
- newUint8Array.set(b, a.length);
2641
- return newUint8Array;
2642
- }
2643
3349
  function error(reason) {
2644
3350
  return reset({
2645
3351
  _tag: "Failure",
@@ -2653,11 +3359,8 @@ function make5() {
2653
3359
  if (state.previousChunk !== void 0) {
2654
3360
  endOffset = state.previousChunk.length;
2655
3361
  previousCursor = endOffset;
2656
- const newChunk = new Uint8Array(chunk.length + endOffset);
2657
- newChunk.set(state.previousChunk);
2658
- newChunk.set(chunk, endOffset);
3362
+ chunk = concat([state.previousChunk, chunk]);
2659
3363
  state.previousChunk = void 0;
2660
- chunk = newChunk;
2661
3364
  }
2662
3365
  const end = chunk.length;
2663
3366
  outer: while (start < end) {
@@ -2746,7 +3449,7 @@ function make5() {
2746
3449
  state.previousChunk = chunk.subarray(start);
2747
3450
  return constContinue;
2748
3451
  } else if (state.crlf >= 2) {
2749
- state.value = state.value === void 0 ? chunk.subarray(start, i - state.crlf) : concatUint8Array(state.value, chunk.subarray(start, i - state.crlf));
3452
+ state.value = state.value === void 0 ? chunk.subarray(start, i - state.crlf) : concat([state.value, chunk.subarray(start, i - state.crlf)]);
2750
3453
  const value = decoder.decode(state.value);
2751
3454
  if (state.headers[state.key] === void 0) {
2752
3455
  state.headers[state.key] = value;
@@ -2781,7 +3484,7 @@ function make5() {
2781
3484
  }
2782
3485
  }
2783
3486
  if (i === end) {
2784
- state.value = state.value === void 0 ? chunk.subarray(start, end) : concatUint8Array(state.value, chunk.subarray(start, end));
3487
+ state.value = state.value === void 0 ? chunk.subarray(start, end) : concat([state.value, chunk.subarray(start, end)]);
2785
3488
  return constContinue;
2786
3489
  }
2787
3490
  }
@@ -2793,7 +3496,7 @@ function make5() {
2793
3496
  };
2794
3497
  }
2795
3498
 
2796
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/MultipartParser/internal/search.js
3499
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/MultipartParser/internal/search.js
2797
3500
  function makeState(needle_) {
2798
3501
  const needle = new TextEncoder().encode(needle_);
2799
3502
  const needleLength = needle.length;
@@ -2913,7 +3616,7 @@ function make6(needle, callback2, seed, minimumChunkLength) {
2913
3616
  };
2914
3617
  }
2915
3618
 
2916
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/MultipartParser/internal/multipart.js
3619
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/MultipartParser/internal/multipart.js
2917
3620
  var State2 = {
2918
3621
  headers: 0,
2919
3622
  body: 1
@@ -2945,8 +3648,8 @@ function defaultIsFile(info) {
2945
3648
  return info.filename !== void 0 || info.contentType === "application/octet-stream";
2946
3649
  }
2947
3650
  function parseBoundary(headers) {
2948
- const contentType = parse(headers["content-type"]);
2949
- return contentType.parameters.boundary;
3651
+ const contentType2 = parse(headers["content-type"]);
3652
+ return contentType2.parameters.boundary;
2950
3653
  }
2951
3654
  function noopOnChunk(_chunk) {
2952
3655
  }
@@ -3018,18 +3721,7 @@ function make7({
3018
3721
  if (state.isFile) {
3019
3722
  state.onChunk(null);
3020
3723
  } else {
3021
- if (state.fieldChunks.length === 1) {
3022
- onField(state.info, state.fieldChunks[0]);
3023
- } else {
3024
- const buf = new Uint8Array(state.fieldSize);
3025
- let offset = 0;
3026
- for (let i = 0; i < state.fieldChunks.length; i++) {
3027
- const chunk2 = state.fieldChunks[i];
3028
- buf.set(chunk2, offset);
3029
- offset += chunk2.length;
3030
- }
3031
- onField(state.info, buf);
3032
- }
3724
+ onField(state.info, state.fieldChunks.length === 1 ? state.fieldChunks[0] : concat(state.fieldChunks));
3033
3725
  state.fieldSize = 0;
3034
3726
  state.fieldChunks = [];
3035
3727
  }
@@ -3062,28 +3754,17 @@ function make7({
3062
3754
  error: result
3063
3755
  });
3064
3756
  }
3065
- const contentType = parse(result.headers["content-type"]);
3066
- const contentDisposition = parse(result.headers["content-disposition"], true);
3067
- if ("form-data" === contentDisposition.value && !("name" in contentDisposition.parameters)) {
3757
+ const contentType2 = parse(result.headers["content-type"]);
3758
+ const contentDisposition = parseDisposition(result.headers["content-disposition"]);
3759
+ if (contentDisposition === void 0 || "form-data" === contentDisposition.value && !("name" in contentDisposition.parameters)) {
3068
3760
  skipBody();
3069
3761
  return onError(errInvalidDisposition);
3070
3762
  }
3071
- let encodedFilename;
3072
- if ("filename*" in contentDisposition.parameters) {
3073
- const parts = contentDisposition.parameters["filename*"].split("''");
3074
- if (parts.length === 2) {
3075
- try {
3076
- encodedFilename = decodeURIComponent(parts[1]);
3077
- } catch {
3078
- encodedFilename = parts[1];
3079
- }
3080
- }
3081
- }
3082
3763
  state.info = {
3083
3764
  name: contentDisposition.parameters.name ?? "",
3084
- filename: encodedFilename ?? contentDisposition.parameters.filename,
3085
- contentType: contentType.value === "" ? contentDisposition.parameters.filename !== void 0 ? "application/octet-stream" : "text/plain" : contentType.value,
3086
- contentTypeParameters: contentType.parameters,
3765
+ filename: contentDisposition.filename,
3766
+ contentType: contentType2.value === "" ? contentDisposition.filename !== void 0 ? "application/octet-stream" : "text/plain" : contentType2.value,
3767
+ contentTypeParameters: contentType2.parameters,
3087
3768
  contentDisposition: contentDisposition.value,
3088
3769
  contentDispositionParameters: contentDisposition.parameters,
3089
3770
  headers: result.headers
@@ -3157,13 +3838,13 @@ function decodeField(info, value) {
3157
3838
  return getDecoder(info.contentTypeParameters.charset ?? "utf-8").decode(value);
3158
3839
  }
3159
3840
 
3160
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/MultipartParser.js
3841
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/MultipartParser.js
3161
3842
  var make8 = make7;
3162
3843
  var defaultIsFile2 = defaultIsFile;
3163
3844
  var decodeField2 = decodeField;
3164
3845
 
3165
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/Multipart.js
3166
- var TypeId9 = "~effect/http/Multipart";
3846
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/Multipart.js
3847
+ var TypeId10 = "~effect/http/Multipart";
3167
3848
  var MultipartErrorTypeId = "~effect/http/Multipart/MultipartError";
3168
3849
  var toMultipartError = (cause) => isMultipartError(cause) ? cause : MultipartError.fromReason("InternalError", cause);
3169
3850
  var MultipartErrorReason = class extends Error2 {
@@ -3211,7 +3892,7 @@ var MultipartError = class _MultipartError extends (/* @__PURE__ */ TaggedError(
3211
3892
  * @since 4.0.0
3212
3893
  */
3213
3894
  [symbol]() {
3214
- return succeed2(empty9({
3895
+ return succeed4(empty9({
3215
3896
  status: responseStatusByReason[this.reason._tag]
3216
3897
  }));
3217
3898
  }
@@ -3235,7 +3916,7 @@ var schemaJson2 = (schema, options3) => {
3235
3916
  };
3236
3917
  var makeConfig = (headers) => withFiber((fiber) => {
3237
3918
  const mimeTypes = get(fiber.context, FieldMimeTypes);
3238
- return succeed2({
3919
+ return succeed4({
3239
3920
  headers,
3240
3921
  maxParts: fiber.getRef(MaxParts),
3241
3922
  maxFieldSize: fiber.getRef(MaxFieldSize),
@@ -3256,7 +3937,7 @@ var makeChannel = (headers) => fromTransform((upstream) => map(makeConfig(header
3256
3937
  onFile(info) {
3257
3938
  let chunks = [];
3258
3939
  let finished = false;
3259
- const pullChunks = fromPull(succeed2(suspend(function loop() {
3940
+ const pullChunks = fromPull(succeed4(suspend(function loop() {
3260
3941
  if (!isReadonlyArrayNonEmpty(chunks)) {
3261
3942
  if (finished) {
3262
3943
  return done();
@@ -3268,7 +3949,7 @@ var makeChannel = (headers) => fromTransform((upstream) => map(makeConfig(header
3268
3949
  }
3269
3950
  const chunk = chunks;
3270
3951
  chunks = [];
3271
- return succeed2(chunk);
3952
+ return succeed4(chunk);
3272
3953
  })));
3273
3954
  partsBuffer.push(new FileImpl(info, mapError2(pullChunks, toMultipartError)));
3274
3955
  return function(chunk) {
@@ -3313,7 +3994,7 @@ var makeChannel = (headers) => fromTransform((upstream) => map(makeConfig(header
3313
3994
  }
3314
3995
  const parts = partsBuffer;
3315
3996
  partsBuffer = [];
3316
- return succeed2(parts);
3997
+ return succeed4(parts);
3317
3998
  });
3318
3999
  }));
3319
4000
  function convertError(cause) {
@@ -3340,10 +4021,10 @@ function convertError(cause) {
3340
4021
  }
3341
4022
  }
3342
4023
  var PartBase = class extends Class {
3343
- [TypeId9];
4024
+ [TypeId10];
3344
4025
  constructor() {
3345
4026
  super();
3346
- this[TypeId9] = TypeId9;
4027
+ this[TypeId10] = TypeId10;
3347
4028
  }
3348
4029
  };
3349
4030
  var FieldImpl = class extends PartBase {
@@ -3351,10 +4032,10 @@ var FieldImpl = class extends PartBase {
3351
4032
  key;
3352
4033
  contentType;
3353
4034
  value;
3354
- constructor(key, contentType, value) {
4035
+ constructor(key, contentType2, value) {
3355
4036
  super();
3356
4037
  this.key = key;
3357
- this.contentType = contentType;
4038
+ this.contentType = contentType2;
3358
4039
  this.value = value;
3359
4040
  }
3360
4041
  toJSON() {
@@ -3393,6 +4074,19 @@ var FileImpl = class extends PartBase {
3393
4074
  }
3394
4075
  };
3395
4076
  var defaultWriteFile = (path, file3) => flatMap(FileSystem, (fs) => mapError(run(file3.content, fs.sink(path)), toMultipartError));
4077
+ var maxPersistedFileNameBytes = 128;
4078
+ var fileNameEncoder = /* @__PURE__ */ new TextEncoder();
4079
+ var persistedFileName = (baseName) => {
4080
+ const codePoints = Array.from(baseName);
4081
+ let fileName = "";
4082
+ let bytes = 0;
4083
+ for (let i = codePoints.length - 1; i >= 0; i--) {
4084
+ bytes += fileNameEncoder.encode(codePoints[i]).length;
4085
+ if (bytes > maxPersistedFileNameBytes) break;
4086
+ fileName = codePoints[i] + fileName;
4087
+ }
4088
+ return fileName === "" || fileName === "." || fileName === ".." ? "file" : fileName;
4089
+ };
3396
4090
  var toPersisted = (stream4, writeFile = defaultWriteFile) => gen(function* () {
3397
4091
  const fs = yield* FileSystem;
3398
4092
  const path_ = yield* Path;
@@ -3415,7 +4109,7 @@ var toPersisted = (stream4, writeFile = defaultWriteFile) => gen(function* () {
3415
4109
  return void_2;
3416
4110
  }
3417
4111
  const file3 = part;
3418
- const fileName = path_.basename(file3.name).slice(-128);
4112
+ const fileName = persistedFileName(path_.basename(file3.name));
3419
4113
  let path = path_.join(dir, fileName);
3420
4114
  while (usedPaths.has(path)) {
3421
4115
  path = path_.join(dir, `${fileIndex++}-${fileName}`);
@@ -3438,11 +4132,11 @@ var PersistedFileImpl = class extends PartBase {
3438
4132
  name;
3439
4133
  contentType;
3440
4134
  path;
3441
- constructor(key, name, contentType, path) {
4135
+ constructor(key, name, contentType2, path) {
3442
4136
  super();
3443
4137
  this.key = key;
3444
4138
  this.name = name;
3445
- this.contentType = contentType;
4139
+ this.contentType = contentType2;
3446
4140
  this.path = path;
3447
4141
  }
3448
4142
  toJSON() {
@@ -3469,13 +4163,13 @@ var FieldMimeTypes = /* @__PURE__ */ Reference("effect/http/Multipart/FieldMimeT
3469
4163
  defaultValue: /* @__PURE__ */ constant(["application/json"])
3470
4164
  });
3471
4165
 
3472
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpServerRequest.js
4166
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpServerRequest.js
3473
4167
  var HttpServerRequest_exports = {};
3474
4168
  __export(HttpServerRequest_exports, {
3475
4169
  HttpServerRequest: () => HttpServerRequest,
3476
4170
  MaxBodySize: () => MaxBodySize,
3477
4171
  ParsedSearchParams: () => ParsedSearchParams,
3478
- TypeId: () => TypeId10,
4172
+ TypeId: () => TypeId11,
3479
4173
  fromClientRequest: () => fromClientRequest,
3480
4174
  fromWeb: () => fromWeb4,
3481
4175
  schemaBodyForm: () => schemaBodyForm,
@@ -3494,187 +4188,17 @@ __export(HttpServerRequest_exports, {
3494
4188
  upgradeChannel: () => upgradeChannel
3495
4189
  });
3496
4190
 
3497
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/socket/Socket.js
3498
- var encoder2 = /* @__PURE__ */ new TextEncoder();
3499
- var readerBytes = (self) => map(self.reader, ({
3500
- pull
3501
- }) => map(pull, (chunk) => {
3502
- for (let i = 0; i < chunk.length; i++) {
3503
- if (typeof chunk[i] === "string") {
3504
- const out = new Array(chunk.length);
3505
- for (let j = 0; j < chunk.length; j++) {
3506
- const item = chunk[j];
3507
- out[j] = typeof item === "string" ? encoder2.encode(item) : item;
3508
- }
3509
- return out;
3510
- }
3511
- }
3512
- return chunk;
3513
- }));
3514
- var CloseEventTypeId = "~effect/socket/Socket/CloseEvent";
3515
- var CloseEvent = class {
3516
- /**
3517
- * Marks this value as a socket close event for runtime guards.
3518
- *
3519
- * @stability unstable
3520
- * @since 4.0.0
3521
- */
3522
- [CloseEventTypeId];
3523
- code;
3524
- reason;
3525
- constructor(code = 1e3, reason) {
3526
- this[CloseEventTypeId] = CloseEventTypeId;
3527
- this.code = code;
3528
- this.reason = reason;
3529
- }
3530
- /**
3531
- * Formats the close code and optional reason for display.
3532
- *
3533
- * @stability unstable
3534
- * @since 4.0.0
3535
- */
3536
- toString() {
3537
- return this.reason ? `${this.code}: ${this.reason}` : `${this.code}`;
3538
- }
3539
- };
3540
- var isCloseEvent = (u) => hasProperty(u, CloseEventTypeId);
3541
- var SocketErrorTypeId = "~effect/socket/Socket/SocketError";
3542
- var isSocketError = (u) => hasProperty(u, SocketErrorTypeId);
3543
- var SocketReadError = class extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketReadError")({
3544
- _tag: /* @__PURE__ */ tag("SocketReadError"),
3545
- cause: /* @__PURE__ */ Defect()
3546
- })) {
3547
- /**
3548
- * Default message used for socket read failures.
3549
- *
3550
- * @stability unstable
3551
- * @since 4.0.0
3552
- */
3553
- message = `An error occurred during Read`;
3554
- };
3555
- var SocketWriteError = class extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketWriteError")({
3556
- _tag: /* @__PURE__ */ tag("SocketWriteError"),
3557
- cause: /* @__PURE__ */ Defect()
3558
- })) {
3559
- /**
3560
- * Default message used for socket write failures.
3561
- *
3562
- * @stability unstable
3563
- * @since 4.0.0
3564
- */
3565
- message = `An error occurred during Write`;
3566
- };
3567
- var SocketOpenError = class extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketOpenError")({
3568
- _tag: /* @__PURE__ */ tag("SocketOpenError"),
3569
- kind: /* @__PURE__ */ Literals(["Unknown", "Timeout"]),
3570
- cause: /* @__PURE__ */ Defect()
3571
- })) {
3572
- /**
3573
- * Formats timeout and unknown open failures for display.
3574
- *
3575
- * @stability unstable
3576
- * @since 4.0.0
3577
- */
3578
- get message() {
3579
- return this.kind === "Timeout" ? `timeout waiting for "open"` : `An error occurred during Open`;
3580
- }
3581
- };
3582
- var SocketUpgradeError = class _SocketUpgradeError extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketUpgradeError")({
3583
- _tag: /* @__PURE__ */ tag("SocketUpgradeError"),
3584
- cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
3585
- })) {
3586
- /**
3587
- * An upgrade implementation for transports that cannot wrap the connection
3588
- * with TLS.
3589
- *
3590
- * @stability unstable
3591
- * @since 4.0.0
3592
- */
3593
- static unsupported = () => fail3(new SocketError({
3594
- reason: new _SocketUpgradeError({})
4191
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/internal/lazyStream.js
4192
+ var openOnFirstPull = (stream4) => fromChannel(fromTransform((_, scope2) => sync(() => {
4193
+ let pull;
4194
+ return suspend(() => pull ?? flatMap(toPullScoped(stream4.channel, scope2), (upstream) => {
4195
+ pull = upstream;
4196
+ return upstream;
3595
4197
  }));
3596
- get message() {
3597
- return this.cause === void 0 ? `Socket does not support TLS upgrade` : `An error occurred during TLS upgrade`;
3598
- }
3599
- };
3600
- var SocketCloseError = class extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketCloseError")({
3601
- _tag: /* @__PURE__ */ tag("SocketCloseError"),
3602
- code: Int,
3603
- closeReason: /* @__PURE__ */ optional(String2)
3604
- })) {
3605
- get message() {
3606
- if (this.closeReason) {
3607
- return `${this.code}: ${this.closeReason}`;
3608
- }
3609
- return `${this.code}`;
3610
- }
3611
- };
3612
- var SocketErrorReason = /* @__PURE__ */ Union([SocketReadError, SocketWriteError, SocketOpenError, SocketUpgradeError, SocketCloseError]);
3613
- var SocketError = class extends (/* @__PURE__ */ TaggedError2(SocketErrorTypeId)("SocketError", {
3614
- _tag: /* @__PURE__ */ tag("SocketError"),
3615
- reason: SocketErrorReason
3616
- })) {
3617
- // @effect-diagnostics-next-line overriddenSchemaConstructor:off
3618
- constructor(props) {
3619
- if ("cause" in props.reason) {
3620
- super({
3621
- ...props,
3622
- cause: props.reason.cause
3623
- });
3624
- } else {
3625
- super(props);
3626
- }
3627
- }
3628
- /**
3629
- * Marks this value as a socket error wrapper for runtime guards.
3630
- *
3631
- * @stability unstable
3632
- * @since 4.0.0
3633
- */
3634
- [SocketErrorTypeId] = SocketErrorTypeId;
3635
- /**
3636
- * Returns `true` when the value is a `SocketError`.
3637
- *
3638
- * @stability unstable
3639
- * @since 4.0.0
3640
- */
3641
- static is(u) {
3642
- return isSocketError(u);
3643
- }
3644
- message = this.reason.message;
3645
- };
3646
- var writeChunk = (writer, chunk) => {
3647
- for (let i = 0; i < chunk.length; i++) {
3648
- if (isCloseEvent(chunk[i])) {
3649
- return gen(function* () {
3650
- for (let index = 0; index <= i; index++) {
3651
- yield* writer.write(chunk[index]);
3652
- }
3653
- });
3654
- }
3655
- }
3656
- return writer.writeAll(chunk);
3657
- };
3658
- var toChannelWithReader = (self, reader) => fromTransform(fnUntraced(function* (upstream, scope2) {
3659
- const readScope = yield* fork(scope2);
3660
- const pull = yield* provide(reader, readScope);
3661
- const writeScope = yield* fork(scope2);
3662
- const writer = yield* provide(self.writer, writeScope);
3663
- let writeFailure;
3664
- yield* upstream.pipe(flatMap((chunk) => writeChunk(writer, chunk)), forever({
3665
- disableYield: true
3666
- }), catchCauseFilter(filterNoDone, (cause) => suspend(() => {
3667
- writeFailure = cause;
3668
- return close(readScope, void_);
3669
- })), ensuring(close(writeScope, void_)), forkIn(scope2));
3670
- return catchCause(suspend(() => writeFailure !== void 0 ? failCause2(writeFailure) : pull), (cause) => failCause2(writeFailure ?? cause));
3671
- }));
3672
- var toChannel = (self) => toChannelWithReader(self, readerBytes(self));
3673
- var toChannelWith = () => (self) => toChannel(self);
3674
- var defaultHighWaterMark = 64 * 1024;
4198
+ })));
3675
4199
 
3676
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpServerRequest.js
3677
- var TypeId10 = "~effect/http/HttpServerRequest";
4200
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpServerRequest.js
4201
+ var TypeId11 = "~effect/http/HttpServerRequest";
3678
4202
  var HttpServerRequest = /* @__PURE__ */ Service("effect/http/HttpServerRequest");
3679
4203
  var ParsedSearchParams = class extends (/* @__PURE__ */ Service()("effect/http/ParsedSearchParams")) {
3680
4204
  };
@@ -3694,7 +4218,7 @@ var searchParamsFromURL = (url) => {
3694
4218
  }
3695
4219
  return out;
3696
4220
  };
3697
- var upgradeChannel = () => HttpServerRequest.pipe(flatMap((_) => _.upgrade), map(toChannelWith()), unwrap);
4221
+ var upgradeChannel = () => HttpServerRequest.pipe(flatMap((_) => _.upgrade), map(toChannelWith()), unwrap2);
3698
4222
  var schemaCookies = (schema, options3) => {
3699
4223
  const parse2 = decodeUnknownEffect(schema);
3700
4224
  return flatMap(HttpServerRequest, (req) => parse2(req.cookies, options3));
@@ -3775,30 +4299,34 @@ var removeHost = (url) => {
3775
4299
  return index === -1 ? "/" : url.slice(index);
3776
4300
  };
3777
4301
  var ServerRequestImpl = class _ServerRequestImpl extends Class {
3778
- [TypeId10];
4302
+ [TypeId11];
3779
4303
  [TypeId4];
3780
4304
  source;
3781
4305
  url;
3782
4306
  headersOverride;
3783
4307
  remoteAddressOverride;
3784
- constructor(source, url, headersOverride, remoteAddressOverride) {
4308
+ peerAddressOverride;
4309
+ protocol;
4310
+ constructor(source, url, headersOverride, remoteAddressOverride, peerAddressOverride, protocol) {
3785
4311
  super();
3786
- this[TypeId10] = TypeId10;
4312
+ this[TypeId11] = TypeId11;
3787
4313
  this[TypeId4] = TypeId4;
3788
4314
  this.source = source;
3789
4315
  this.url = url;
3790
4316
  this.headersOverride = headersOverride;
3791
4317
  this.remoteAddressOverride = remoteAddressOverride;
4318
+ this.peerAddressOverride = peerAddressOverride;
4319
+ this.protocol = protocol;
3792
4320
  }
3793
4321
  toJSON() {
3794
4322
  return inspect(this, {
3795
4323
  _id: "HttpServerRequest",
3796
4324
  method: this.method,
3797
- url: this.originalUrl
4325
+ url: redactUrl(this.originalUrl)
3798
4326
  });
3799
4327
  }
3800
4328
  modify(options3) {
3801
- return new _ServerRequestImpl(this.source, options3.url ?? this.url, options3.headers ?? this.headersOverride, "remoteAddress" in options3 ? options3.remoteAddress : this.remoteAddressOverride);
4329
+ return new _ServerRequestImpl(this.source, options3.url ?? this.url, options3.headers ?? this.headersOverride, "remoteAddress" in options3 ? options3.remoteAddress : this.remoteAddressOverride, options3.peerAddress ?? this.peerAddressOverride, options3.protocol ?? this.protocol);
3802
4330
  }
3803
4331
  get method() {
3804
4332
  return this.source.method.toUpperCase();
@@ -3809,6 +4337,9 @@ var ServerRequestImpl = class _ServerRequestImpl extends Class {
3809
4337
  get remoteAddress() {
3810
4338
  return this.remoteAddressOverride ?? none();
3811
4339
  }
4340
+ get peerAddress() {
4341
+ return this.peerAddressOverride ?? this.remoteAddress;
4342
+ }
3812
4343
  get headers() {
3813
4344
  this.headersOverride ??= fromInput2(this.source.headers);
3814
4345
  return this.headersOverride;
@@ -3821,36 +4352,11 @@ var ServerRequestImpl = class _ServerRequestImpl extends Class {
3821
4352
  return this.cachedCookies = parseHeader(this.headers.cookie ?? "");
3822
4353
  }
3823
4354
  get stream() {
3824
- return this.source.body ? fromReadableStream({
3825
- evaluate: () => this.source.body,
3826
- onError: (cause) => new HttpServerError({
3827
- reason: new RequestParseError({
3828
- request: this,
3829
- cause
3830
- })
3831
- })
3832
- }) : fail4(new HttpServerError({
3833
- reason: new RequestParseError({
3834
- request: this,
3835
- description: "can not create stream from empty body"
3836
- })
3837
- }));
4355
+ return streamFromReadable(this, this.source.body);
3838
4356
  }
3839
4357
  textEffect;
3840
4358
  get text() {
3841
- if (this.textEffect) {
3842
- return this.textEffect;
3843
- }
3844
- this.textEffect = runSync(cached(tryPromise({
3845
- try: () => this.source.text(),
3846
- catch: (cause) => new HttpServerError({
3847
- reason: new RequestParseError({
3848
- request: this,
3849
- cause
3850
- })
3851
- })
3852
- })));
3853
- return this.textEffect;
4359
+ return this.textEffect ??= map(this.arrayBuffer, (buffer2) => textDecoder2.decode(buffer2));
3854
4360
  }
3855
4361
  get json() {
3856
4362
  return flatMap(this.text, (text3) => try_2({
@@ -3864,8 +4370,8 @@ var ServerRequestImpl = class _ServerRequestImpl extends Class {
3864
4370
  }));
3865
4371
  }
3866
4372
  get urlParamsBody() {
3867
- return flatMap(this.text, (_) => try_2({
3868
- try: () => fromInput3(new URLSearchParams(_)),
4373
+ return flatMap(this.arrayBuffer, (bytes) => try_2({
4374
+ try: () => fromInput3(fromBody(bytes)),
3869
4375
  catch: (cause) => new HttpServerError({
3870
4376
  reason: new RequestParseError({
3871
4377
  request: this,
@@ -3890,18 +4396,25 @@ var ServerRequestImpl = class _ServerRequestImpl extends Class {
3890
4396
  if (this.arrayBufferEffect) {
3891
4397
  return this.arrayBufferEffect;
3892
4398
  }
3893
- this.arrayBufferEffect = runSync(cached(tryPromise({
3894
- try: () => this.source.arrayBuffer(),
3895
- catch: (cause) => new HttpServerError({
3896
- reason: new RequestParseError({
3897
- request: this,
3898
- cause
4399
+ this.arrayBufferEffect = withFiber((fiber) => {
4400
+ const maxBodySize = fiber.getRef(MaxBodySize);
4401
+ return tryPromise({
4402
+ try: (signal) => maxBodySize === void 0 ? this.source.arrayBuffer() : readArrayBufferLimited(this.source, Number(maxBodySize), signal),
4403
+ catch: (cause) => new HttpServerError({
4404
+ reason: new RequestParseError({
4405
+ request: this,
4406
+ reason: cause instanceof BodyTooLargeError ? "BodyTooLarge" : "Parse",
4407
+ cause
4408
+ })
3899
4409
  })
3900
- })
3901
- })));
4410
+ });
4411
+ }).pipe(cached, runSync);
3902
4412
  return this.arrayBufferEffect;
3903
4413
  }
3904
4414
  get upgrade() {
4415
+ return this.upgradeWith({});
4416
+ }
4417
+ upgradeWith(_options) {
3905
4418
  return fail3(new HttpServerError({
3906
4419
  reason: new RequestParseError({
3907
4420
  request: this,
@@ -3911,32 +4424,36 @@ var ServerRequestImpl = class _ServerRequestImpl extends Class {
3911
4424
  }
3912
4425
  };
3913
4426
  var ClientRequestImpl = class _ClientRequestImpl extends Class {
3914
- [TypeId10];
4427
+ [TypeId11];
3915
4428
  [TypeId4];
3916
4429
  source;
3917
4430
  originalUrl;
3918
4431
  headersOverride;
3919
4432
  remoteAddressOverride;
4433
+ peerAddressOverride;
4434
+ protocol;
3920
4435
  urlOverride;
3921
- constructor(source, originalUrl, urlOverride, headersOverride, remoteAddressOverride) {
4436
+ constructor(source, originalUrl, urlOverride, headersOverride, remoteAddressOverride, peerAddressOverride, protocol) {
3922
4437
  super();
3923
- this[TypeId10] = TypeId10;
4438
+ this[TypeId11] = TypeId11;
3924
4439
  this[TypeId4] = TypeId4;
3925
4440
  this.source = source;
3926
4441
  this.originalUrl = originalUrl;
3927
4442
  this.urlOverride = urlOverride;
3928
4443
  this.headersOverride = headersOverride;
3929
4444
  this.remoteAddressOverride = remoteAddressOverride;
4445
+ this.peerAddressOverride = peerAddressOverride;
4446
+ this.protocol = protocol;
3930
4447
  }
3931
4448
  toJSON() {
3932
4449
  return inspect(this, {
3933
4450
  _id: "HttpServerRequest",
3934
4451
  method: this.method,
3935
- url: this.originalUrl
4452
+ url: redactUrl(this.originalUrl)
3936
4453
  });
3937
4454
  }
3938
4455
  modify(options3) {
3939
- return new _ClientRequestImpl(this.source, this.originalUrl, options3.url ?? this.url, options3.headers ?? this.headersOverride, "remoteAddress" in options3 ? options3.remoteAddress : this.remoteAddressOverride);
4456
+ return new _ClientRequestImpl(this.source, this.originalUrl, options3.url ?? this.url, options3.headers ?? this.headersOverride, "remoteAddress" in options3 ? options3.remoteAddress : this.remoteAddressOverride, options3.peerAddress ?? this.peerAddressOverride, options3.protocol ?? this.protocol);
3940
4457
  }
3941
4458
  get method() {
3942
4459
  return this.source.method;
@@ -3947,6 +4464,9 @@ var ClientRequestImpl = class _ClientRequestImpl extends Class {
3947
4464
  get remoteAddress() {
3948
4465
  return this.remoteAddressOverride ?? none();
3949
4466
  }
4467
+ get peerAddress() {
4468
+ return this.peerAddressOverride ?? this.remoteAddress;
4469
+ }
3950
4470
  get headers() {
3951
4471
  return this.headersOverride ??= this.source.headers;
3952
4472
  }
@@ -3964,7 +4484,7 @@ var ClientRequestImpl = class _ClientRequestImpl extends Class {
3964
4484
  return empty6;
3965
4485
  }
3966
4486
  case "Uint8Array": {
3967
- return succeed3(body.body);
4487
+ return succeed5(body.body);
3968
4488
  }
3969
4489
  case "Stream": {
3970
4490
  return mapError3(body.stream, (cause) => requestParseError(this, void 0, cause));
@@ -3982,32 +4502,31 @@ var ClientRequestImpl = class _ClientRequestImpl extends Class {
3982
4502
  if (this.bytesEffect) {
3983
4503
  return this.bytesEffect;
3984
4504
  }
4505
+ this.bytesEffect = withFiber((fiber) => {
4506
+ const maxBodySize = fiber.getRef(MaxBodySize);
4507
+ return this.readBytes(maxBodySize === void 0 ? void 0 : Number(maxBodySize));
4508
+ }).pipe(cached, runSync);
4509
+ return this.bytesEffect;
4510
+ }
4511
+ readBytes(maxBytes) {
3985
4512
  const body = this.source.body;
3986
- let effect2;
3987
4513
  switch (body._tag) {
3988
4514
  case "Empty": {
3989
- effect2 = succeed2(new Uint8Array(0));
3990
- break;
4515
+ return succeed4(new Uint8Array(0));
3991
4516
  }
3992
4517
  case "Uint8Array": {
3993
- effect2 = succeed2(body.body);
3994
- break;
4518
+ return maxBytes !== void 0 && body.body.byteLength > maxBytes ? fail3(bodyTooLargeError(this, new BodyTooLargeError(maxBytes))) : succeed4(body.body);
3995
4519
  }
3996
4520
  case "FormData": {
3997
- effect2 = bytesFromBodyInit(this, body.formData);
3998
- break;
4521
+ return bytesFromWeb(this, () => new Response(body.formData), maxBytes);
3999
4522
  }
4000
4523
  case "Stream": {
4001
- effect2 = mkUint8Array2(this.stream);
4002
- break;
4524
+ return mkUint8Array2(maxBytes === void 0 ? this.stream : limitStream(this, this.stream, maxBytes));
4003
4525
  }
4004
4526
  case "Raw": {
4005
- effect2 = rawBodyBytes(this, body.body);
4006
- break;
4527
+ return rawBodyBytes(this, body.body, maxBytes);
4007
4528
  }
4008
4529
  }
4009
- this.bytesEffect = runSync(cached(effect2));
4010
- return this.bytesEffect;
4011
4530
  }
4012
4531
  get text() {
4013
4532
  return map(this.bytes, (bytes) => textDecoder2.decode(bytes));
@@ -4019,8 +4538,8 @@ var ClientRequestImpl = class _ClientRequestImpl extends Class {
4019
4538
  }));
4020
4539
  }
4021
4540
  get urlParamsBody() {
4022
- return flatMap(this.text, (_) => try_2({
4023
- try: () => fromInput3(new URLSearchParams(_)),
4541
+ return flatMap(this.bytes, (bytes) => try_2({
4542
+ try: () => fromInput3(fromBody(bytes)),
4024
4543
  catch: (cause) => requestParseError(this, void 0, cause)
4025
4544
  }));
4026
4545
  }
@@ -4047,6 +4566,9 @@ var ClientRequestImpl = class _ClientRequestImpl extends Class {
4047
4566
  );
4048
4567
  }
4049
4568
  get upgrade() {
4569
+ return this.upgradeWith({});
4570
+ }
4571
+ upgradeWith(_options) {
4050
4572
  return fail3(requestParseError(this, "Not an upgradeable ServerRequest"));
4051
4573
  }
4052
4574
  };
@@ -4075,21 +4597,22 @@ var rawBodyStream = (request, body) => {
4075
4597
  }
4076
4598
  return fail4(requestParseError(request, "Unsupported body type"));
4077
4599
  };
4078
- var rawBodyBytes = (request, body) => {
4600
+ var rawBodyBytes = (request, body, maxBytes) => {
4079
4601
  if (body instanceof Request) {
4080
- return tryPromise({
4081
- try: () => body.arrayBuffer().then((buffer2) => new Uint8Array(buffer2)),
4082
- catch: (cause) => requestParseError(request, void 0, cause)
4083
- });
4602
+ return bytesFromWeb(request, () => body, maxBytes);
4084
4603
  }
4085
4604
  if (isBodyInit(body)) {
4086
- return bytesFromBodyInit(request, body);
4605
+ return bytesFromWeb(request, () => new Response(body), maxBytes);
4087
4606
  }
4088
4607
  return fail3(requestParseError(request, "Unsupported body type"));
4089
4608
  };
4090
- var bytesFromBodyInit = (request, body) => tryPromise({
4091
- try: () => new Response(body).arrayBuffer().then((buffer2) => new Uint8Array(buffer2)),
4092
- catch: (cause) => requestParseError(request, void 0, cause)
4609
+ var bytesFromWeb = (request, evaluate, maxBytes) => tryPromise({
4610
+ try: async (signal) => {
4611
+ const source = evaluate();
4612
+ const buffer2 = maxBytes === void 0 ? await source.arrayBuffer() : await readArrayBufferLimited(source, maxBytes, signal);
4613
+ return new Uint8Array(buffer2);
4614
+ },
4615
+ catch: (cause) => cause instanceof BodyTooLargeError ? bodyTooLargeError(request, cause) : requestParseError(request, void 0, cause)
4093
4616
  });
4094
4617
  var streamFromReadable = (request, body) => body ? fromReadableStream({
4095
4618
  evaluate: () => body,
@@ -4106,6 +4629,20 @@ var requestParseError = (request, description, cause) => new HttpServerError({
4106
4629
  }
4107
4630
  })
4108
4631
  });
4632
+ var limitStream = (request, stream4, maxBytes) => suspend2(() => {
4633
+ let bytes = 0;
4634
+ return mapEffect(stream4, (chunk) => {
4635
+ bytes += chunk.byteLength;
4636
+ return bytes > maxBytes ? fail3(bodyTooLargeError(request, new BodyTooLargeError(maxBytes))) : succeed4(chunk);
4637
+ });
4638
+ });
4639
+ var bodyTooLargeError = (request, cause) => new HttpServerError({
4640
+ reason: new RequestParseError({
4641
+ request,
4642
+ reason: "BodyTooLarge",
4643
+ cause
4644
+ })
4645
+ });
4109
4646
  var formDataToParts = (formData3) => {
4110
4647
  const parts = [];
4111
4648
  for (const [key, value] of formData3.entries()) {
@@ -4114,14 +4651,14 @@ var formDataToParts = (formData3) => {
4114
4651
  return parts;
4115
4652
  };
4116
4653
  var MultipartFieldPart = class extends Class {
4117
- [TypeId9];
4654
+ [TypeId10];
4118
4655
  _tag = "Field";
4119
4656
  contentType = "text/plain";
4120
4657
  key;
4121
4658
  value;
4122
4659
  constructor(key, value) {
4123
4660
  super();
4124
- this[TypeId9] = TypeId9;
4661
+ this[TypeId10] = TypeId10;
4125
4662
  this.key = key;
4126
4663
  this.value = value;
4127
4664
  }
@@ -4136,7 +4673,7 @@ var MultipartFieldPart = class extends Class {
4136
4673
  }
4137
4674
  };
4138
4675
  var MultipartFilePart = class extends Class {
4139
- [TypeId9];
4676
+ [TypeId10];
4140
4677
  _tag = "File";
4141
4678
  key;
4142
4679
  name;
@@ -4145,7 +4682,7 @@ var MultipartFilePart = class extends Class {
4145
4682
  contentEffect;
4146
4683
  constructor(key, file3) {
4147
4684
  super();
4148
- this[TypeId9] = TypeId9;
4685
+ this[TypeId10] = TypeId10;
4149
4686
  this.key = key;
4150
4687
  this.name = file3.name;
4151
4688
  this.contentType = file3.type;
@@ -4172,11 +4709,62 @@ var isReadableStream3 = (u) => typeof ReadableStream !== "undefined" && u instan
4172
4709
  var isFormData = (u) => typeof FormData !== "undefined" && u instanceof FormData;
4173
4710
  var isBodyInit = (u) => typeof u === "string" || typeof ArrayBuffer !== "undefined" && (u instanceof ArrayBuffer || ArrayBuffer.isView(u)) || typeof Blob !== "undefined" && u instanceof Blob || isFormData(u) || typeof URLSearchParams !== "undefined" && u instanceof URLSearchParams || isReadableStream3(u);
4174
4711
  var textDecoder2 = /* @__PURE__ */ new TextDecoder();
4712
+ var BodyTooLargeError = class extends Error {
4713
+ constructor(maxBytes) {
4714
+ super(`Request body exceeds ${maxBytes} bytes`);
4715
+ }
4716
+ };
4717
+ var readArrayBufferLimited = async (source, maxBytes, signal) => {
4718
+ const header = source.headers.get("content-length");
4719
+ const contentLength = header !== null && /^\d+$/.test(header) ? Number(header) : void 0;
4720
+ if (contentLength !== void 0 && contentLength > maxBytes) {
4721
+ throw new BodyTooLargeError(maxBytes);
4722
+ }
4723
+ if (source.body === null) {
4724
+ return new ArrayBuffer(0);
4725
+ }
4726
+ const limit = contentLength ?? maxBytes;
4727
+ const reader = source.body.getReader();
4728
+ const cancel = () => {
4729
+ reader.cancel().catch(() => {
4730
+ });
4731
+ };
4732
+ signal.addEventListener("abort", cancel, {
4733
+ once: true
4734
+ });
4735
+ const chunks = [];
4736
+ let bytes = 0;
4737
+ try {
4738
+ while (true) {
4739
+ const {
4740
+ done: done2,
4741
+ value
4742
+ } = await reader.read();
4743
+ if (done2) break;
4744
+ bytes += value.byteLength;
4745
+ if (bytes > limit) {
4746
+ cancel();
4747
+ throw bytes > maxBytes ? new BodyTooLargeError(maxBytes) : new Error(`Request body is longer than its content-length of ${contentLength}`);
4748
+ }
4749
+ chunks.push(value);
4750
+ }
4751
+ } finally {
4752
+ signal.removeEventListener("abort", cancel);
4753
+ reader.releaseLock();
4754
+ }
4755
+ const buffer2 = new Uint8Array(bytes);
4756
+ let offset = 0;
4757
+ for (const chunk of chunks) {
4758
+ buffer2.set(chunk, offset);
4759
+ offset += chunk.byteLength;
4760
+ }
4761
+ return buffer2.buffer;
4762
+ };
4175
4763
  var toURL = (self) => {
4176
4764
  const host = self.headers.host ?? "localhost";
4177
- const protocol = self.headers["x-forwarded-proto"] === "https" ? "https" : "http";
4765
+ const protocol = self.protocol ?? (/^https:/i.test(self.originalUrl) ? "https" : "http");
4178
4766
  try {
4179
- return some(new URL(self.url, `${protocol}://${host}`));
4767
+ return some(new URL(self.url.startsWith("/") ? `.${self.url}` : self.url, `${protocol}://${host}`));
4180
4768
  } catch {
4181
4769
  return none();
4182
4770
  }
@@ -4200,7 +4788,11 @@ var toWebResult2 = (self, options3) => {
4200
4788
  requestInit.signal = options3.signal;
4201
4789
  }
4202
4790
  if (hasBody(self.method)) {
4203
- requestInit.body = toReadableStreamWith(self.stream, options3?.context ?? empty());
4791
+ requestInit.body = toReadableStreamWith(openOnFirstPull(self.stream), options3?.context ?? empty(), {
4792
+ strategy: {
4793
+ highWaterMark: 0
4794
+ }
4795
+ });
4204
4796
  requestInit.duplex = "half";
4205
4797
  }
4206
4798
  return succeed(new Request(url.value, requestInit));
@@ -4210,15 +4802,557 @@ var toWeb3 = (self, options3) => contextWith((context2) => fromResult(toWebResul
4210
4802
  signal: options3?.signal
4211
4803
  })));
4212
4804
 
4213
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpMiddleware.js
4214
- var loggerDisabledRequests = /* @__PURE__ */ new WeakSet();
4805
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpMiddleware.js
4806
+ var HttpMiddleware_exports = {};
4807
+ __export(HttpMiddleware_exports, {
4808
+ SpanNameGenerator: () => SpanNameGenerator2,
4809
+ TracerDisabledWhen: () => TracerDisabledWhen2,
4810
+ TracerHeaderFilter: () => TracerHeaderFilter2,
4811
+ compression: () => compression,
4812
+ cors: () => cors,
4813
+ decompression: () => decompression,
4814
+ isTracerDisabledUnsafe: () => isTracerDisabledUnsafe,
4815
+ layerTracerDisabledForUrls: () => layerTracerDisabledForUrls,
4816
+ logger: () => logger,
4817
+ make: () => make9,
4818
+ searchParamsParser: () => searchParamsParser,
4819
+ tracer: () => tracer,
4820
+ withLoggerDisabled: () => withLoggerDisabled,
4821
+ xForwardedHeaders: () => xForwardedHeaders
4822
+ });
4823
+
4824
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/internal/decompression.js
4825
+ var defaultMaxDecompressedSize = /* @__PURE__ */ mebibytes(10);
4826
+ var parseContentEncoding = (header) => {
4827
+ const codings = [];
4828
+ for (const member of header.split(",")) {
4829
+ const coding = member.trim().toLowerCase();
4830
+ if (coding === "" || coding === "identity") continue;
4831
+ if (coding !== "gzip" && coding !== "deflate") return void 0;
4832
+ codings.push(coding);
4833
+ }
4834
+ return codings;
4835
+ };
4836
+ var DecompressedRequest = class _DecompressedRequest extends Class {
4837
+ [TypeId11];
4838
+ [TypeId4];
4839
+ inner;
4840
+ codings;
4841
+ maxDecompressedSize;
4842
+ headers;
4843
+ constructor(inner, codings, maxDecompressedSize) {
4844
+ super();
4845
+ this[TypeId11] = TypeId11;
4846
+ this[TypeId4] = TypeId4;
4847
+ this.inner = inner;
4848
+ this.codings = codings;
4849
+ this.maxDecompressedSize = maxDecompressedSize;
4850
+ this.headers = removeMany(inner.headers, ["content-encoding", "content-length"]);
4851
+ }
4852
+ toJSON() {
4853
+ return inspect(this, {
4854
+ _id: "HttpServerRequest",
4855
+ method: this.method,
4856
+ url: this.originalUrl
4857
+ });
4858
+ }
4859
+ modify(options3) {
4860
+ return new _DecompressedRequest(this.inner.modify(options3), this.codings, this.maxDecompressedSize);
4861
+ }
4862
+ get source() {
4863
+ return this.inner.source;
4864
+ }
4865
+ get url() {
4866
+ return this.inner.url;
4867
+ }
4868
+ get originalUrl() {
4869
+ return this.inner.originalUrl;
4870
+ }
4871
+ get method() {
4872
+ return this.inner.method;
4873
+ }
4874
+ get cookies() {
4875
+ return this.inner.cookies;
4876
+ }
4877
+ get remoteAddress() {
4878
+ return this.inner.remoteAddress;
4879
+ }
4880
+ get peerAddress() {
4881
+ return this.inner.peerAddress;
4882
+ }
4883
+ get protocol() {
4884
+ return this.inner.protocol;
4885
+ }
4886
+ get upgrade() {
4887
+ return this.inner.upgrade;
4888
+ }
4889
+ upgradeWith(options3) {
4890
+ return this.inner.upgradeWith(options3);
4891
+ }
4892
+ // Platform accessors such as `NodeHttpServerRequest.toServerResponse` read
4893
+ // the response handle from the request.
4894
+ get response() {
4895
+ return this.inner.response;
4896
+ }
4897
+ get stream() {
4898
+ return openOnFirstPull(unwrap3(withFiber((fiber) => {
4899
+ const limit = this.maxDecompressedSize ?? fiber.getRef(MaxBodySize) ?? defaultMaxDecompressedSize;
4900
+ return succeed4(fromReadableStream({
4901
+ evaluate: () => {
4902
+ let body = toReadableStreamWith(this.inner.stream, fiber.context);
4903
+ for (let i = this.codings.length - 1; i >= 0; i--) {
4904
+ body = body.pipeThrough(new DecompressionStream(this.codings[i]));
4905
+ }
4906
+ let size = 0;
4907
+ return body.pipeThrough(new TransformStream({
4908
+ transform: (chunk, controller) => {
4909
+ size += chunk.byteLength;
4910
+ if (size > limit) {
4911
+ controller.error(this.parseError(void 0, `Decompressed request body exceeds ${limit} bytes`, "BodyTooLarge"));
4912
+ } else {
4913
+ controller.enqueue(chunk);
4914
+ }
4915
+ }
4916
+ }));
4917
+ },
4918
+ onError: (cause) => cause instanceof HttpServerError ? cause : this.parseError(cause)
4919
+ }));
4920
+ })));
4921
+ }
4922
+ bytesEffect;
4923
+ get bytes() {
4924
+ return this.bytesEffect ??= runSync(cached(mkUint8Array2(this.stream)));
4925
+ }
4926
+ get text() {
4927
+ return map(this.bytes, (bytes) => textDecoder3.decode(bytes));
4928
+ }
4929
+ get json() {
4930
+ return flatMap(this.text, (text3) => try_2({
4931
+ try: () => text3 === "" ? null : JSON.parse(text3),
4932
+ catch: (cause) => this.parseError(cause)
4933
+ }));
4934
+ }
4935
+ get urlParamsBody() {
4936
+ return flatMap(this.bytes, (bytes) => try_2({
4937
+ try: () => fromInput3(fromBody(bytes)),
4938
+ catch: (cause) => this.parseError(cause)
4939
+ }));
4940
+ }
4941
+ get arrayBuffer() {
4942
+ return map(this.bytes, (bytes) => bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength));
4943
+ }
4944
+ get multipartStream() {
4945
+ return pipeThroughChannel(mapError3(this.stream, (cause) => (
4946
+ // Failures raised by this request come from the client's data. Failures
4947
+ // passed through from the inner request are transport errors.
4948
+ MultipartError.fromReason(cause.reason instanceof RequestParseError && cause.reason.request === this ? cause.reason.reason ?? "Parse" : "InternalError", cause)
4949
+ )), makeChannel(this.headers));
4950
+ }
4951
+ multipartEffect;
4952
+ get multipart() {
4953
+ return this.multipartEffect ??= runSync(cached(toPersisted(this.multipartStream)));
4954
+ }
4955
+ parseError(cause, description, reason = "Parse") {
4956
+ return new HttpServerError({
4957
+ reason: new RequestParseError({
4958
+ request: this,
4959
+ reason,
4960
+ ...description === void 0 ? void 0 : {
4961
+ description
4962
+ },
4963
+ ...cause === void 0 ? void 0 : {
4964
+ cause
4965
+ }
4966
+ })
4967
+ });
4968
+ }
4969
+ };
4970
+ var textDecoder3 = /* @__PURE__ */ new TextDecoder();
4971
+
4972
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/internal/requestState.js
4973
+ var CurrentRequestState = /* @__PURE__ */ Service("effect/http/HttpEffect/CurrentRequestState");
4974
+ var appendPreResponseHandlerUnsafe = (context2, handler) => {
4975
+ const state = getOrUndefined2(context2, CurrentRequestState);
4976
+ if (state === void 0) return;
4977
+ const prev = state.preResponseHandler;
4978
+ state.preResponseHandler = prev ? (request, response) => flatMap(prev(request, response), (response2) => handler(request, response2)) : handler;
4979
+ };
4980
+
4981
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpMiddleware.js
4982
+ var make9 = (middleware2) => middleware2;
4215
4983
  var withLoggerDisabled = (self) => withFiber((fiber) => {
4216
- const request = getUnsafe(fiber.context, HttpServerRequest);
4217
- loggerDisabledRequests.add(request.source);
4984
+ const state = getOrUndefined2(fiber.context, CurrentRequestState);
4985
+ if (state !== void 0) state.loggerDisabled = true;
4218
4986
  return self;
4219
4987
  });
4988
+ var TracerDisabledWhen2 = /* @__PURE__ */ Reference("effect/http/HttpMiddleware/TracerDisabledWhen", {
4989
+ defaultValue: () => constFalse
4990
+ });
4991
+ var layerTracerDisabledForUrls = (urls) => succeed3(TracerDisabledWhen2)((req) => urls.includes(req.url));
4992
+ var SpanNameGenerator2 = /* @__PURE__ */ Reference("@effect/platform/HttpMiddleware/SpanNameGenerator", {
4993
+ defaultValue: () => (request) => request.method
4994
+ });
4995
+ var TracerHeaderFilter2 = /* @__PURE__ */ Reference("effect/http/HttpMiddleware/TracerHeaderFilter", {
4996
+ defaultValue: () => constFalse
4997
+ });
4998
+ var logger = /* @__PURE__ */ make9((httpApp) => withFiber((fiber) => {
4999
+ const request = getUnsafe(fiber.context, HttpServerRequest);
5000
+ const state = getOrUndefined2(fiber.context, CurrentRequestState);
5001
+ const path = stripSearchAndHash(request.url);
5002
+ return withLogSpan(flatMap(exit(httpApp), (exit2) => {
5003
+ if (state?.loggerDisabled) {
5004
+ return exit2;
5005
+ } else if (exit2._tag === "Failure") {
5006
+ const [response, cause] = causeResponseStripped(exit2.cause);
5007
+ const message = isSome(cause) && !cause.value.reasons.every((reason) => reason._tag === "Interrupt" && reason.annotations.has(ClientAbort.key)) ? cause.value : "Sent HTTP response";
5008
+ return andThen(annotateLogs(log(message), {
5009
+ "http.method": request.method,
5010
+ "http.url": path,
5011
+ "http.status": response.status
5012
+ }), exit2);
5013
+ }
5014
+ return andThen(annotateLogs(log("Sent HTTP response"), {
5015
+ "http.method": request.method,
5016
+ "http.url": path,
5017
+ "http.status": exit2.value.status
5018
+ }), exit2);
5019
+ }), "http.span");
5020
+ }));
5021
+ var isTracerDisabledUnsafe = (fiber, request) => !fiber.cache.tracerEnabled || fiber.getRef(TracerDisabledWhen2)(request);
5022
+ var responseSpanExit = (fiber, request, response) => {
5023
+ if (!(response.status >= 500 && response.status < 600)) {
5024
+ return succeed2(response);
5025
+ }
5026
+ const url = redactUrl(request.url, fiber.getRef(CurrentRedactedNames2));
5027
+ if (url !== request.url) {
5028
+ request = request.modify({
5029
+ url
5030
+ });
5031
+ }
5032
+ const stackTraceLimit = getStackTraceLimit();
5033
+ setStackTraceLimit(0);
5034
+ try {
5035
+ return fail2(new HttpServerError({
5036
+ reason: new ResponseError({
5037
+ request,
5038
+ response
5039
+ })
5040
+ }));
5041
+ } finally {
5042
+ setStackTraceLimit(stackTraceLimit);
5043
+ }
5044
+ };
5045
+ var withStateNames = (names, stateNames) => stateNames === void 0 || stateNames.length === 0 ? names : [...names, ...stateNames];
5046
+ var tracer = /* @__PURE__ */ make9((httpApp) => withFiber((fiber) => {
5047
+ const request = getUnsafe(fiber.context, HttpServerRequest);
5048
+ if (isTracerDisabledUnsafe(fiber, request)) {
5049
+ return httpApp;
5050
+ }
5051
+ const nameGenerator = fiber.getRef(SpanNameGenerator2);
5052
+ const span = makeSpanUnsafe(fiber, nameGenerator(request), {
5053
+ parent: getOrUndefined(fromHeaders(request.headers)),
5054
+ kind: "server"
5055
+ });
5056
+ const prevServices = fiber.context;
5057
+ fiber.setContext(add(fiber.context, ParentSpan, span));
5058
+ onExitUnsafe(fiber, (exit2) => {
5059
+ fiber.setContext(prevServices);
5060
+ const endTime = fiber.getRef(Clock).currentTimeNanosUnsafe();
5061
+ if (isSuccess2(exit2) && (!span.sampled || fiber.getRef(Tracer) === nativeTracer)) {
5062
+ span.end(endTime, responseSpanExit(fiber, request, exit2.value));
5063
+ return void 0;
5064
+ }
5065
+ const state = getOrUndefined2(prevServices, CurrentRequestState);
5066
+ const redactedHeaderNames = withStateNames(fiber.getRef(CurrentRedactedNames), state?.redactedHeaderNames);
5067
+ const headerFilter = fiber.getRef(TracerHeaderFilter2);
5068
+ let response;
5069
+ let spanExit;
5070
+ if (isFailure2(exit2)) {
5071
+ const [failureResponse, cause] = causeResponseStripped(exit2.cause);
5072
+ response = failureResponse;
5073
+ spanExit = isSome(cause) && (response.status >= 500 || hasInterrupts(cause.value)) ? failCause(cause.value) : responseSpanExit(fiber, request, response);
5074
+ } else {
5075
+ response = exit2.value;
5076
+ spanExit = responseSpanExit(fiber, request, response);
5077
+ }
5078
+ if (span.sampled) {
5079
+ span.attribute("http.request.method", request.method);
5080
+ const url = toURL(request);
5081
+ if (isSome(url)) {
5082
+ addUrlAttributes(span, url.value, withStateNames(fiber.getRef(CurrentRedactedNames2), state?.redactedUrlParamNames));
5083
+ }
5084
+ if (request.headers["user-agent"] !== void 0) {
5085
+ span.attribute("user_agent.original", request.headers["user-agent"]);
5086
+ }
5087
+ addHeaderAttributes(span, "request", request.headers, headerFilter, redactedHeaderNames);
5088
+ if (isSome(request.remoteAddress)) {
5089
+ span.attribute("client.address", request.remoteAddress.value);
5090
+ }
5091
+ span.attribute("http.response.status_code", response.status);
5092
+ addHeaderAttributes(span, "response", response.headers, headerFilter, redactedHeaderNames);
5093
+ }
5094
+ span.end(endTime, spanExit);
5095
+ return void 0;
5096
+ });
5097
+ return httpApp;
5098
+ }));
5099
+ var xForwardedHeaders = (options3) => {
5100
+ const {
5101
+ trustedProxies
5102
+ } = options3;
5103
+ const isTrusted = typeof trustedProxies === "function" ? trustedProxies : (address) => trustedProxies.some((network) => contains(network, address));
5104
+ return make9((httpApp) => updateService(httpApp, HttpServerRequest, (request) => applyXForwarded(request, isTrusted)));
5105
+ };
5106
+ var applyXForwarded = (request, isTrusted) => {
5107
+ const peer = parseForwardedAddress(getOrUndefined(request.peerAddress));
5108
+ if (peer === void 0 || !isTrusted(peer)) return request;
5109
+ const addresses = splitList(request.headers["x-forwarded-for"]);
5110
+ if (addresses === void 0) return request;
5111
+ for (let index = addresses.length - 1; index >= 0; index--) {
5112
+ const address = parseForwardedAddress(addresses[index]);
5113
+ if (address === void 0) return request;
5114
+ if (index > 0 && isTrusted(address)) continue;
5115
+ const host = alignedValue(request.headers["x-forwarded-host"], addresses.length, index);
5116
+ const protocol = alignedValue(request.headers["x-forwarded-proto"], addresses.length, index)?.toLowerCase();
5117
+ return request.modify({
5118
+ remoteAddress: some(formatIp(address)),
5119
+ peerAddress: request.peerAddress,
5120
+ ...host !== void 0 && isValidHost(host) ? {
5121
+ headers: set2(request.headers, "host", host)
5122
+ } : {},
5123
+ ...protocol === "http" || protocol === "https" ? {
5124
+ protocol
5125
+ } : {}
5126
+ });
5127
+ }
5128
+ return request;
5129
+ };
5130
+ var splitList = (value) => value?.split(",").map((_) => _.trim());
5131
+ var alignedValue = (header, length, index) => {
5132
+ const values = splitList(header);
5133
+ return values?.length === length ? values[index] : void 0;
5134
+ };
5135
+ var parseForwardedAddress = (input) => {
5136
+ if (input === void 0) return void 0;
5137
+ const ip = ipFromString(input.startsWith("[") && input.endsWith("]") ? input.slice(1, -1) : input);
5138
+ if (isSuccess(ip)) return toCanonical(ip.success);
5139
+ const inet = inetAddressFromString(input);
5140
+ return isSuccess(inet) ? toCanonical(inet.success.address) : void 0;
5141
+ };
5142
+ var hostShape = /^(?:\[[0-9a-f:.]+\]|[a-z0-9._-]+)(?::\d{1,5})?$/i;
5143
+ var isValidHost = (host) => hostShape.test(host) && URL.canParse(`http://${host}`);
5144
+ var searchParamsParser = (httpApp) => withFiber((fiber) => {
5145
+ const services = fiber.context;
5146
+ const request = getUnsafe(services, HttpServerRequest);
5147
+ const params = searchParamsFromURL(new URL(request.originalUrl));
5148
+ return provideService(httpApp, ParsedSearchParams, params);
5149
+ });
5150
+ var cors = (options3) => {
5151
+ const opts = {
5152
+ allowedOrigins: options3?.allowedOrigins ?? [],
5153
+ allowedMethods: options3?.allowedMethods ?? ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
5154
+ allowedHeaders: options3?.allowedHeaders ?? [],
5155
+ exposedHeaders: options3?.exposedHeaders ?? [],
5156
+ credentials: options3?.credentials ?? false,
5157
+ maxAge: options3?.maxAge
5158
+ };
5159
+ const isAllowedOrigin = typeof opts.allowedOrigins === "function" ? opts.allowedOrigins : (origin) => opts.allowedOrigins.includes(origin);
5160
+ const allowOrigin = typeof opts.allowedOrigins === "function" || opts.allowedOrigins.length > 1 ? (originHeader) => {
5161
+ if (originHeader === void 0 || !isAllowedOrigin(originHeader)) return {
5162
+ vary: "Origin"
5163
+ };
5164
+ return {
5165
+ "access-control-allow-origin": originHeader,
5166
+ vary: "Origin"
5167
+ };
5168
+ } : opts.allowedOrigins.length === 0 ? constant({
5169
+ "access-control-allow-origin": "*"
5170
+ }) : constant({
5171
+ "access-control-allow-origin": opts.allowedOrigins[0],
5172
+ vary: "Origin"
5173
+ });
5174
+ const allowMethods = opts.allowedMethods.length > 0 ? {
5175
+ "access-control-allow-methods": opts.allowedMethods.join(", ")
5176
+ } : void 0;
5177
+ const allowCredentials = opts.credentials ? {
5178
+ "access-control-allow-credentials": "true"
5179
+ } : void 0;
5180
+ const allowHeaders = (accessControlRequestHeaders) => {
5181
+ if (opts.allowedHeaders.length === 0 && accessControlRequestHeaders) {
5182
+ return {
5183
+ vary: "Access-Control-Request-Headers",
5184
+ "access-control-allow-headers": accessControlRequestHeaders
5185
+ };
5186
+ }
5187
+ if (opts.allowedHeaders) {
5188
+ return {
5189
+ "access-control-allow-headers": opts.allowedHeaders.join(",")
5190
+ };
5191
+ }
5192
+ return void 0;
5193
+ };
5194
+ const exposeHeaders = opts.exposedHeaders.length > 0 ? {
5195
+ "access-control-expose-headers": opts.exposedHeaders.join(",")
5196
+ } : void 0;
5197
+ const maxAge = opts.maxAge ? {
5198
+ "access-control-max-age": opts.maxAge.toString()
5199
+ } : void 0;
5200
+ const headersFromRequest = (request) => {
5201
+ const origin = request.headers["origin"];
5202
+ return fromRecordUnsafe({
5203
+ ...allowOrigin(origin),
5204
+ ...allowCredentials,
5205
+ ...exposeHeaders
5206
+ });
5207
+ };
5208
+ const headersFromRequestOptions = (request) => {
5209
+ const origin = request.headers["origin"];
5210
+ const accessControlRequestHeaders = request.headers["access-control-request-headers"];
5211
+ const headers = fromRecordUnsafe({
5212
+ ...allowOrigin(origin),
5213
+ ...allowCredentials,
5214
+ ...exposeHeaders,
5215
+ ...allowMethods,
5216
+ ...maxAge
5217
+ });
5218
+ const accessControlHeaders = allowHeaders(accessControlRequestHeaders);
5219
+ if (accessControlHeaders === void 0) return headers;
5220
+ const vary = accessControlHeaders["vary"];
5221
+ return setAll2(headers, vary === void 0 ? accessControlHeaders : {
5222
+ ...accessControlHeaders,
5223
+ vary: varyWith(headers, vary)
5224
+ });
5225
+ };
5226
+ const preResponseHandler = (request, response) => {
5227
+ const headers = headersFromRequest(request);
5228
+ return succeed4(setHeaders2(response, headers["vary"] === void 0 ? headers : set2(headers, "vary", varyWith(response.headers, "Origin"))));
5229
+ };
5230
+ return (httpApp) => withFiber((fiber) => {
5231
+ const request = getUnsafe(fiber.context, HttpServerRequest);
5232
+ if (request.method === "OPTIONS") {
5233
+ return succeed4(empty9({
5234
+ status: 204,
5235
+ headers: headersFromRequestOptions(request)
5236
+ }));
5237
+ }
5238
+ appendPreResponseHandlerUnsafe(fiber.context, preResponseHandler);
5239
+ return httpApp;
5240
+ });
5241
+ };
5242
+ var compression = (options3) => {
5243
+ const preferred = options3?.algorithms ?? defaultAlgorithms;
5244
+ const minSize = options3?.minSize ?? 1024;
5245
+ const compressible = options3?.compressible ?? defaultCompressible;
5246
+ const levels = {
5247
+ ...defaultLevels,
5248
+ ...options3?.levels
5249
+ };
5250
+ const levelOptions = {
5251
+ gzip: {
5252
+ level: levels.gzip
5253
+ },
5254
+ deflate: {
5255
+ level: levels.deflate
5256
+ },
5257
+ br: {
5258
+ level: levels.br
5259
+ },
5260
+ zstd: {
5261
+ level: levels.zstd
5262
+ }
5263
+ };
5264
+ const transform2 = (compression2, acceptEncoding, response) => {
5265
+ if (response.status < 200 || response.status === 204 || response.status === 206 || response.status === 304) {
5266
+ return succeed4(response);
5267
+ }
5268
+ const currentEncoding = response.headers["content-encoding"];
5269
+ if (currentEncoding !== void 0) {
5270
+ return succeed4(currentEncoding.trim().toLowerCase() === "identity" ? removeHeader2(response, "content-encoding") : response);
5271
+ }
5272
+ const body = response.body;
5273
+ if (body._tag === "Empty" || body._tag === "FormData") {
5274
+ return succeed4(response);
5275
+ }
5276
+ const cacheControl = response.headers["cache-control"];
5277
+ if (cacheControl !== void 0 && noTransformRegex.test(cacheControl)) {
5278
+ return succeed4(response);
5279
+ }
5280
+ const contentType2 = response.headers["content-type"] ?? body.contentType;
5281
+ if (contentType2 === void 0 || !compressible(contentType2)) {
5282
+ return succeed4(response);
5283
+ }
5284
+ const algorithm = negotiate(acceptEncoding, preferred, compression2.algorithms);
5285
+ if (algorithm === void 0) {
5286
+ return succeed4(withVary(response));
5287
+ }
5288
+ const contentLength = body.contentLength ?? parseContentLength(response.headers["content-length"]);
5289
+ if (contentLength !== void 0 && contentLength < minSize) {
5290
+ return succeed4(withVary(response));
5291
+ }
5292
+ return compression2.compressResponse(response, algorithm, levelOptions[algorithm]);
5293
+ };
5294
+ return (httpApp) => withFiber((fiber) => {
5295
+ const compression2 = getUnsafe(fiber.context, HttpPlatform).compression;
5296
+ appendPreResponseHandlerUnsafe(fiber.context, (request, response) => transform2(compression2, request.headers["accept-encoding"], response));
5297
+ return httpApp;
5298
+ });
5299
+ };
5300
+ var decompression = (options3) => {
5301
+ const maxDecompressedSize = options3?.maxDecompressedSize === void 0 ? void 0 : fromInputUnsafe2(options3.maxDecompressedSize);
5302
+ return (httpApp) => withFiber((fiber) => {
5303
+ const request = getUnsafe(fiber.context, HttpServerRequest);
5304
+ const contentEncoding = request.headers["content-encoding"];
5305
+ if (contentEncoding === void 0 || !hasBody(request.method)) {
5306
+ return httpApp;
5307
+ }
5308
+ const codings = parseContentEncoding(contentEncoding);
5309
+ if (codings === void 0) {
5310
+ return succeed4(empty9({
5311
+ status: 415,
5312
+ headers: {
5313
+ "accept-encoding": "gzip, deflate"
5314
+ }
5315
+ }));
5316
+ }
5317
+ if (codings.length === 0) {
5318
+ return httpApp;
5319
+ }
5320
+ return provideService(httpApp, HttpServerRequest, new DecompressedRequest(request, codings, maxDecompressedSize));
5321
+ });
5322
+ };
5323
+ var withVary = (response) => {
5324
+ const vary = varyWith(response.headers, "Accept-Encoding");
5325
+ return setHeader2(response, "vary", vary);
5326
+ };
5327
+ var defaultAlgorithms = ["br", "gzip", "deflate"];
5328
+ var defaultLevels = {
5329
+ gzip: 6,
5330
+ deflate: 6,
5331
+ br: 4,
5332
+ zstd: 3
5333
+ };
5334
+ var noTransformRegex = /(?:^|[\s,])no-transform(?:$|[\s,;])/i;
4220
5335
 
4221
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpRouter.js
5336
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/FindMyWay/internal/router.js
5337
+ function getClosingParenthensePosition(path, idx) {
5338
+ let parentheses = 1;
5339
+ while (idx < path.length) {
5340
+ idx++;
5341
+ if (path[idx] === "\\") {
5342
+ idx++;
5343
+ continue;
5344
+ }
5345
+ if (path[idx] === ")") {
5346
+ parentheses--;
5347
+ } else if (path[idx] === "(") {
5348
+ parentheses++;
5349
+ }
5350
+ if (!parentheses) return idx;
5351
+ }
5352
+ throw new TypeError('Invalid regexp expression in "' + path + '"');
5353
+ }
5354
+
5355
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpRouter.js
4222
5356
  var HttpRouter = /* @__PURE__ */ Service("effect/http/HttpRouter");
4223
5357
  var removeTrailingSlash = (path) => path.endsWith("/") ? path.slice(0, -1) : path;
4224
5358
  var prefixPath = /* @__PURE__ */ dual(2, (self, prefix) => {
@@ -4300,7 +5434,7 @@ var getMiddleware = (context2) => {
4300
5434
  };
4301
5435
  var disableLogger = middleware(withLoggerDisabled).layer;
4302
5436
 
4303
- // ../../node_modules/.bun/effect@4.0.1/node_modules/effect/dist/http/HttpStatus.js
5437
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpStatus.js
4304
5438
  var codeByLiteral = {
4305
5439
  Continue: 100,
4306
5440
  SwitchingProtocols: 101,
@@ -4367,16 +5501,23 @@ var codeByLiteral = {
4367
5501
  };
4368
5502
  var fromLiteral = (literal) => codeByLiteral[literal];
4369
5503
 
5504
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/ProblemDetails.js
5505
+ var contentType = "application/problem+json";
5506
+ var blankType = "about:blank";
5507
+ var withFallback = (schema, value) => withDecodingDefaultKey(succeed4(value))(schema).pipe(catchDecoding(() => succeedSome(value)));
5508
+ var fixedMember = (value) => withFallback(tag(value), value);
5509
+
4370
5510
  export {
4371
5511
  isHttpBody,
4372
5512
  uint8Array,
4373
5513
  text,
4374
- jsonUnsafe,
4375
5514
  urlParams,
5515
+ stream,
4376
5516
  HttpBody_exports,
4377
5517
  isHttpClientError,
4378
5518
  HttpClientError,
4379
5519
  TransportError,
5520
+ EncodeError,
4380
5521
  StatusCodeError,
4381
5522
  DecodeError,
4382
5523
  HttpClientError_exports,
@@ -4385,10 +5526,12 @@ export {
4385
5526
  get4 as get,
4386
5527
  post,
4387
5528
  setHeaders,
5529
+ upgrade,
4388
5530
  setUrl,
4389
5531
  prependUrl,
4390
5532
  appendUrlParams,
4391
5533
  setBody,
5534
+ compressBody2 as compressBody,
4392
5535
  bodyFormData,
4393
5536
  HttpClientRequest_exports,
4394
5537
  fromWeb2 as fromWeb,
@@ -4404,8 +5547,14 @@ export {
4404
5547
  TracerPropagationEnabled,
4405
5548
  layerMergedContext,
4406
5549
  HttpClient_exports,
5550
+ getClosingParenthensePosition,
4407
5551
  HttpServerResponse_exports,
5552
+ isSocket,
4408
5553
  HttpServerRequest_exports,
5554
+ HttpMiddleware_exports,
4409
5555
  prefixPath,
4410
- fromLiteral
5556
+ fromLiteral,
5557
+ contentType,
5558
+ blankType,
5559
+ fixedMember
4411
5560
  };