apps 0.0.1-beta.14 → 0.0.1-beta.141

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 (201) hide show
  1. package/README.md +60 -42
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-M3B3DE4K.js → chunk-2XDCAXAR.js} +612 -246
  4. package/js/{chunk-IPI4MFSN.js → chunk-34RH47V5.js} +2 -2
  5. package/js/chunk-5JBDHSLK.js +449 -0
  6. package/js/{chunk-KUMBKVJD.js → chunk-6QZVXLF2.js} +2 -2
  7. package/js/chunk-7MPPHKRW.js +5418 -0
  8. package/js/chunk-DQ6FIDC3.js +335 -0
  9. package/js/{chunk-5T57N25Q.js → chunk-EKXBHVMR.js} +697 -70
  10. package/js/chunk-EYZHR4UA.js +1945 -0
  11. package/js/chunk-GJG5G6CH.js +1022 -0
  12. package/js/chunk-H2K7OZ47.js +90 -0
  13. package/js/chunk-I6QAWNUM.js +161 -0
  14. package/js/{chunk-ODEIDRGW.js → chunk-JH3MOQZR.js} +1166 -504
  15. package/js/{chunk-QS6CAHKC.js → chunk-JHAHT26O.js} +4 -3
  16. package/js/{chunk-RFVIONFX.js → chunk-JIXIOWZP.js} +136 -45
  17. package/js/chunk-LSOHA2RH.js +88 -0
  18. package/js/{chunk-UK573G7W.js → chunk-MB6L5YZE.js} +1817 -632
  19. package/js/chunk-OBT33ZDK.js +95 -0
  20. package/js/{chunk-JU7VHODU.js → chunk-QTX7OUFH.js} +65 -10
  21. package/js/chunk-RBSXSRPU.js +175 -0
  22. package/js/chunk-SB2DNKDL.js +593 -0
  23. package/js/{chunk-VFZKSM3T.js → chunk-VX36SA7Y.js} +3 -3
  24. package/js/chunk-YF7TYPDS.js +49 -0
  25. package/js/{chunk-CDL5PM2Q.js → chunk-YFSOSNF3.js} +17265 -12477
  26. package/js/{chunk-IJX4CYZO.js → chunk-YVN2AMAU.js} +976 -447
  27. package/js/chunk-Z6DSU4VL.js +724 -0
  28. package/js/client.js +333 -98
  29. package/js/contracts.js +154 -21
  30. package/js/effect.js +18 -19
  31. package/js/graphql.js +231 -188
  32. package/js/host.js +138 -80
  33. package/js/index.js +153 -300
  34. package/js/mcp/effect.js +21 -21
  35. package/js/mcp.js +91 -57
  36. package/js/openapi.js +4950 -4201
  37. package/js/react.js +2 -3
  38. package/js/skills/effect.js +6 -3
  39. package/js/skills.js +220 -81
  40. package/js/storage/facet.js +1 -540
  41. package/js/ui/auth/contracts.js +2 -2
  42. package/js/ui/auth.js +5 -5
  43. package/js/ui/contracts.js +9 -8
  44. package/js/ui/serving.js +8624 -235
  45. package/package.json +3 -8
  46. package/runtime.json +1 -1
  47. package/types/app-cache/src/contracts/cache.d.ts +18 -0
  48. package/types/app-cache/src/index.d.ts +34 -2
  49. package/types/apps/src/contracts/api-response-error.d.ts +4 -0
  50. package/types/apps/src/contracts/app.d.ts +56 -11
  51. package/types/apps/src/contracts/cache.d.ts +20 -0
  52. package/types/apps/src/contracts/context.d.ts +60 -17
  53. package/types/apps/src/contracts/elicitation.d.ts +23 -7
  54. package/types/apps/src/contracts/events.d.ts +94 -0
  55. package/types/apps/src/contracts/failure.d.ts +30 -1
  56. package/types/apps/src/contracts/graphql.d.ts +40 -2
  57. package/types/apps/src/contracts/help-text.d.ts +31 -0
  58. package/types/apps/src/contracts/host.d.ts +1493 -20
  59. package/types/apps/src/contracts/icons.d.ts +28 -0
  60. package/types/apps/src/contracts/live.d.ts +2 -0
  61. package/types/apps/src/contracts/mcp.d.ts +81 -20
  62. package/types/apps/src/contracts/network.d.ts +120 -0
  63. package/types/apps/src/contracts/openapi-compile.d.ts +82 -3
  64. package/types/apps/src/contracts/openapi-document.d.ts +1 -1
  65. package/types/apps/src/contracts/openapi.d.ts +47 -8
  66. package/types/apps/src/contracts/operations.d.ts +14 -7
  67. package/types/apps/src/contracts/placement.d.ts +102 -0
  68. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  69. package/types/apps/src/contracts/protocols/1.d.ts +513 -15
  70. package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
  71. package/types/apps/src/contracts/protocols/11.d.ts +1149 -0
  72. package/types/apps/src/contracts/protocols/12.d.ts +3310 -0
  73. package/types/apps/src/contracts/protocols/13.d.ts +6001 -0
  74. package/types/apps/src/contracts/protocols/2.d.ts +9 -8
  75. package/types/apps/src/contracts/protocols/3.d.ts +73 -15
  76. package/types/apps/src/contracts/protocols/4.d.ts +22 -15
  77. package/types/apps/src/contracts/protocols/5.d.ts +37 -11
  78. package/types/apps/src/contracts/protocols/6.d.ts +1629 -0
  79. package/types/apps/src/contracts/protocols/7.d.ts +1785 -0
  80. package/types/apps/src/contracts/protocols/8.d.ts +1182 -0
  81. package/types/apps/src/contracts/protocols/9.d.ts +1104 -0
  82. package/types/apps/src/contracts/protocols/current.d.ts +7114 -0
  83. package/types/apps/src/contracts/protocols/oauth-6.d.ts +74 -0
  84. package/types/apps/src/contracts/protocols/oauth.d.ts +134 -0
  85. package/types/apps/src/contracts/provider-error.d.ts +9 -0
  86. package/types/apps/src/contracts/provider.d.ts +56 -0
  87. package/types/apps/src/contracts/router.d.ts +2 -1
  88. package/types/apps/src/contracts/schedules.d.ts +7 -1
  89. package/types/apps/src/contracts/schema.d.ts +21 -0
  90. package/types/apps/src/contracts/shared-catalog.d.ts +11 -0
  91. package/types/apps/src/contracts/skills.d.ts +50 -13
  92. package/types/apps/src/contracts/sql.d.ts +63 -0
  93. package/types/apps/src/contracts/ui.d.ts +70 -30
  94. package/types/apps/src/contracts/webhooks.d.ts +24 -7
  95. package/types/apps/src/contracts/workflows.d.ts +56 -34
  96. package/types/apps/src/facet.d.ts +4 -5
  97. package/types/apps/src/host.d.ts +5 -0
  98. package/types/apps/src/implementation/account-router.d.ts +20 -3
  99. package/types/apps/src/implementation/app.d.ts +41 -14
  100. package/types/apps/src/implementation/authoring.d.ts +25 -5
  101. package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
  102. package/types/apps/src/implementation/cache.d.ts +29 -2
  103. package/types/apps/src/implementation/catalog-cache.d.ts +35 -4
  104. package/types/apps/src/implementation/elicitation.d.ts +16 -13
  105. package/types/apps/src/implementation/events.d.ts +64 -0
  106. package/types/apps/src/implementation/failure-detail.d.ts +28 -5
  107. package/types/apps/src/implementation/graphql-catalog.d.ts +3 -3
  108. package/types/apps/src/implementation/graphql.d.ts +4 -3
  109. package/types/apps/src/implementation/help-text.d.ts +5 -0
  110. package/types/apps/src/implementation/input-problems.d.ts +6 -2
  111. package/types/apps/src/implementation/invocation-timing.d.ts +18 -0
  112. package/types/apps/src/implementation/live.d.ts +2 -2
  113. package/types/apps/src/implementation/mcp-call.d.ts +6 -5
  114. package/types/apps/src/implementation/mcp-catalog.d.ts +6 -4
  115. package/types/apps/src/implementation/mcp-client.d.ts +17 -9
  116. package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
  117. package/types/apps/src/implementation/mcp.d.ts +20 -9
  118. package/types/apps/src/implementation/network.d.ts +16 -0
  119. package/types/apps/src/implementation/openapi-compile.d.ts +33 -5
  120. package/types/apps/src/implementation/openapi-document.d.ts +35 -18
  121. package/types/apps/src/implementation/openapi-names.d.ts +9 -4
  122. package/types/apps/src/implementation/openapi-request.d.ts +2 -1
  123. package/types/apps/src/implementation/openapi-source.d.ts +23 -1
  124. package/types/apps/src/implementation/operations.d.ts +58 -7
  125. package/types/apps/src/implementation/optimistic.d.ts +1 -1
  126. package/types/apps/src/implementation/placement.d.ts +60 -0
  127. package/types/apps/src/implementation/protocol-operations.d.ts +3 -0
  128. package/types/apps/src/implementation/provider-error.d.ts +28 -1
  129. package/types/apps/src/implementation/provider.d.ts +20 -4
  130. package/types/apps/src/implementation/query-commit.d.ts +1 -1
  131. package/types/apps/src/implementation/router-catalog.d.ts +22 -97
  132. package/types/apps/src/implementation/router.d.ts +26 -6
  133. package/types/apps/src/implementation/schedules.d.ts +39 -8
  134. package/types/apps/src/implementation/schema.d.ts +148 -17
  135. package/types/apps/src/implementation/skills.d.ts +18 -24
  136. package/types/apps/src/implementation/sql.d.ts +71 -0
  137. package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
  138. package/types/apps/src/implementation/ui-auth.d.ts +1 -1
  139. package/types/apps/src/implementation/ui-client.d.ts +3 -3
  140. package/types/apps/src/implementation/ui-document.d.ts +5 -0
  141. package/types/apps/src/implementation/ui-errors.d.ts +1 -1
  142. package/types/apps/src/implementation/ui-serving.d.ts +38 -12
  143. package/types/apps/src/implementation/upstream-error.d.ts +17 -0
  144. package/types/apps/src/implementation/webhooks.d.ts +15 -6
  145. package/types/apps/src/implementation/workflow-context.d.ts +6 -2
  146. package/types/apps/src/implementation/workflows.d.ts +11 -4
  147. package/types/apps/src/index.d.ts +67 -17
  148. package/types/apps/src/mcp.d.ts +20 -1
  149. package/types/apps/src/openapi.d.ts +22 -1
  150. package/types/apps/src/react.d.ts +1 -1
  151. package/types/apps/src/skills.d.ts +10 -8
  152. package/types/apps/src/ui-serving.d.ts +1 -2
  153. package/types/telemetry/src/app-records.d.ts +42 -0
  154. package/types/telemetry/src/browser-operations.d.ts +2 -2
  155. package/types/telemetry/src/browser.d.ts +8 -3
  156. package/types/telemetry/src/config.d.ts +2 -2
  157. package/types/telemetry/src/index.d.ts +3 -2
  158. package/types/telemetry/src/keepalive.d.ts +53 -0
  159. package/types/telemetry/src/layer.d.ts +10 -4
  160. package/types/telemetry/src/measurements.d.ts +6 -2
  161. package/types/telemetry/src/ownership.d.ts +60 -0
  162. package/types/telemetry/src/recorded-failure.d.ts +29 -0
  163. package/types/telemetry/src/relay.d.ts +32 -7
  164. package/types/telemetry/src/span-attributes.d.ts +22 -3
  165. package/types/telemetry/src/transport.d.ts +10 -1
  166. package/types/utils/src/api-error.d.ts +55 -0
  167. package/types/utils/src/connection-failure.d.ts +33 -0
  168. package/types/utils/src/legacy-keys.d.ts +20 -0
  169. package/types/utils/src/random-uuid.d.ts +6 -0
  170. package/types/utils/src/recorded-message.d.ts +18 -0
  171. package/types/utils/src/schema-definitions.d.ts +13 -0
  172. package/types/utils/src/user-facing-error.d.ts +83 -0
  173. package/js/chunk-27F7W2LG.js +0 -34
  174. package/js/chunk-4ASNKGCV.js +0 -242
  175. package/js/chunk-4DWF4ZWI.js +0 -1280
  176. package/js/chunk-57RKNWL2.js +0 -75
  177. package/js/chunk-6HSH75OI.js +0 -2688
  178. package/js/chunk-G4FT53I7.js +0 -224
  179. package/js/chunk-MKWZPDR6.js +0 -63
  180. package/js/chunk-N7YDVXYJ.js +0 -186
  181. package/js/chunk-NKLWZJLE.js +0 -172
  182. package/js/chunk-PJJ24GU7.js +0 -877
  183. package/js/chunk-PZB6T6KU.js +0 -19
  184. package/js/chunk-R3EV5FTO.js +0 -97
  185. package/js/chunk-S73JGVR5.js +0 -507
  186. package/js/chunk-TG6DOCRO.js +0 -299
  187. package/js/chunk-YPKG2QO5.js +0 -209
  188. package/js/chunk-ZQINWV4W.js +0 -630
  189. package/js/mcp/stdio.js +0 -128
  190. package/types/app-data/src/implementation/cursor.d.ts +0 -10
  191. package/types/app-data/src/implementation/index-key.d.ts +0 -7
  192. package/types/app-data/src/implementation/promise.d.ts +0 -68
  193. package/types/app-data/src/implementation/range.d.ts +0 -8
  194. package/types/app-data/src/implementation/schema.d.ts +0 -18
  195. package/types/app-data/src/implementation/sqlite.d.ts +0 -11
  196. package/types/app-data/src/index.d.ts +0 -4
  197. package/types/apps/src/contracts/storage.d.ts +0 -68
  198. package/types/apps/src/implementation/mcp-stdio.d.ts +0 -4
  199. package/types/apps/src/implementation/storage.d.ts +0 -15
  200. package/types/apps/src/implementation/ui-watch.d.ts +0 -2
  201. package/types/apps/src/mcp-stdio.d.ts +0 -5
@@ -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,
@@ -62,11 +76,13 @@ import {
62
76
  empty5 as empty4,
63
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,9 +120,11 @@ 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,
@@ -111,17 +133,23 @@ import {
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,46 +158,59 @@ 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
- provideContext2 as provideContext,
198
+ provideContext,
164
199
  provideMerge,
200
+ provideService,
201
+ provideServiceEffect,
165
202
  redact,
203
+ redactUrl,
166
204
  remove2 as remove,
167
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
215
  set2 as set,
175
216
  set3 as set2,
@@ -178,24 +219,36 @@ import {
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-CDL5PM2Q.js";
271
+ } from "./chunk-YFSOSNF3.js";
215
272
  import {
216
273
  __export
217
274
  } from "./chunk-CZ7CSFO4.js";
218
275
 
219
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/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@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/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,
@@ -284,6 +343,7 @@ __export(HttpBody_exports, {
284
343
  formData: () => formData,
285
344
  formDataRecord: () => formDataRecord,
286
345
  isHttpBody: () => isHttpBody,
346
+ isHttpBodyError: () => isHttpBodyError,
287
347
  json: () => json,
288
348
  jsonSchema: () => jsonSchema,
289
349
  jsonUnsafe: () => jsonUnsafe,
@@ -300,10 +360,12 @@ var HttpBodyError = class extends (/* @__PURE__ */ TaggedError("HttpBodyError"))
300
360
  /**
301
361
  * Marks this value as an HTTP body error for runtime guards.
302
362
  *
363
+ * @stability unstable
303
364
  * @since 4.0.0
304
365
  */
305
366
  [HttpBodyErrorTypeId] = HttpBodyErrorTypeId;
306
367
  };
368
+ var isHttpBodyError = (u) => hasProperty(u, HttpBodyErrorTypeId);
307
369
  var Proto = class {
308
370
  [TypeId];
309
371
  constructor() {
@@ -333,10 +395,10 @@ var Raw = class extends Proto {
333
395
  body;
334
396
  contentType;
335
397
  contentLength;
336
- constructor(body, contentType, contentLength) {
398
+ constructor(body, contentType2, contentLength) {
337
399
  super();
338
400
  this.body = body;
339
- this.contentType = contentType;
401
+ this.contentType = contentType2;
340
402
  this.contentLength = contentLength;
341
403
  }
342
404
  toJSON() {
@@ -357,11 +419,11 @@ var Uint8Array2 = class extends Proto {
357
419
  /** Original text retained for adapters that can skip encoding. */
358
420
  text;
359
421
  _body;
360
- constructor(body, contentType, contentLength, text3) {
422
+ constructor(body, contentType2, contentLength, text3) {
361
423
  super();
362
424
  this._body = body;
363
425
  this.text = text3;
364
- this.contentType = contentType;
426
+ this.contentType = contentType2;
365
427
  this.contentLength = contentLength;
366
428
  }
367
429
  get body() {
@@ -378,23 +440,23 @@ var Uint8Array2 = class extends Proto {
378
440
  };
379
441
  }
380
442
  };
381
- 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);
382
444
  var encoder = /* @__PURE__ */ new TextEncoder();
383
445
  var buffer = globalThis.Buffer;
384
446
  var encodeText2 = buffer !== void 0 ? (body) => buffer.from(body, "utf8") : (body) => encoder.encode(body);
385
- var text = (body, contentType) => {
447
+ var text = (body, contentType2) => {
386
448
  if (typeof body !== "string") {
387
449
  body = body === void 0 ? "" : String(body);
388
450
  }
389
451
  if (buffer !== void 0) {
390
- 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);
391
453
  }
392
454
  const bytes = encoder.encode(body);
393
- return new Uint8Array2(bytes, contentType ?? "text/plain", bytes.length, body);
455
+ return new Uint8Array2(bytes, contentType2 ?? "text/plain", bytes.length, body);
394
456
  };
395
- var jsonUnsafe = (body, contentType) => text(JSON.stringify(body), contentType ?? "application/json");
396
- var json = (body, contentType) => try_2({
397
- 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"),
398
460
  catch: (cause) => new HttpBodyError({
399
461
  reason: {
400
462
  _tag: "JsonError"
@@ -403,16 +465,16 @@ var json = (body, contentType) => try_2({
403
465
  })
404
466
  });
405
467
  var jsonSchema = (schema, options3) => {
406
- const encode = encodeUnknownEffect(toCodecJson(schema));
407
- 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({
408
470
  reason: {
409
471
  _tag: "SchemaError",
410
472
  issue
411
473
  },
412
474
  cause: issue
413
- })), flatMap((body2) => json(body2, contentType)));
475
+ })), flatMap((body2) => json(body2, contentType2)));
414
476
  };
415
- 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");
416
478
  var FormData2 = class extends Proto {
417
479
  _tag = "FormData";
418
480
  contentType = void 0;
@@ -459,10 +521,10 @@ var Stream = class extends Proto {
459
521
  stream;
460
522
  contentType;
461
523
  contentLength;
462
- constructor(stream4, contentType, contentLength) {
524
+ constructor(stream4, contentType2, contentLength) {
463
525
  super();
464
526
  this.stream = stream4;
465
- this.contentType = contentType;
527
+ this.contentType = contentType2;
466
528
  this.contentLength = contentLength;
467
529
  }
468
530
  toJSON() {
@@ -474,10 +536,10 @@ var Stream = class extends Proto {
474
536
  };
475
537
  }
476
538
  };
477
- 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);
478
540
  var fileRangeSize = (input, field, method) => {
479
541
  const size = fromInput(input);
480
- return isSome(size) ? succeed2(size.value) : fail3(badArgument({
542
+ return isSome(size) ? succeed4(size.value) : fail3(badArgument({
481
543
  module: "HttpBody",
482
544
  method,
483
545
  description: `Invalid ${field}: ${input}`
@@ -500,17 +562,47 @@ var fileContentLength = /* @__PURE__ */ fnUntraced(function* (size, method, opti
500
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))));
501
563
  var fileFromInfo = (path, info, options3) => flatMap(FileSystem, (fs) => map(fileContentLength(info.size, "fileFromInfo", options3), (contentLength) => stream(fs.stream(path, options3), options3?.contentType, contentLength)));
502
564
 
503
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpMethod.js
504
- 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
+ }
505
569
  var allShort = [["GET", "get"], ["POST", "post"], ["PUT", "put"], ["DELETE", "del"], ["PATCH", "patch"], ["HEAD", "head"], ["OPTIONS", "options"], ["TRACE", "trace"], ["QUERY", "query"]];
506
570
 
507
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/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
508
596
  var updateHeaders = (headers, body) => {
509
597
  if (body._tag === "Empty" || body._tag === "FormData") {
510
598
  return remove2(remove2(headers, "content-type"), "content-length");
511
599
  }
512
600
  headers = body.contentType === void 0 ? remove2(headers, "content-type") : set2(headers, "content-type", body.contentType);
513
- 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());
514
606
  };
515
607
  var parseContentLength = (contentLength) => {
516
608
  if (contentLength === null || contentLength === void 0 || !/^\d+$/.test(contentLength)) {
@@ -520,7 +612,7 @@ var parseContentLength = (contentLength) => {
520
612
  return Number.isSafeInteger(parsed) ? parsed : void 0;
521
613
  };
522
614
 
523
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/Url.js
615
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/Url.js
524
616
  var UrlError = class extends (/* @__PURE__ */ TaggedError("UrlError")) {
525
617
  };
526
618
  var make = (url, params, hash) => try_({
@@ -529,7 +621,7 @@ var make = (url, params, hash) => try_({
529
621
  for (let i = 0; i < params.params.length; i++) {
530
622
  const [key, value] = params.params[i];
531
623
  if (value !== void 0) {
532
- urlInstance.searchParams.append(key, value);
624
+ urlInstance.searchParams.append(key, unwrap(value));
533
625
  }
534
626
  }
535
627
  if (hash !== void 0) {
@@ -543,12 +635,21 @@ var make = (url, params, hash) => try_({
543
635
  });
544
636
  var baseUrl = () => {
545
637
  if ("location" in globalThis && globalThis.location !== void 0 && globalThis.location.origin !== void 0 && globalThis.location.pathname !== void 0) {
546
- 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
+ }
547
644
  }
548
645
  return void 0;
549
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
+ });
550
651
 
551
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpClientRequest.js
652
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpClientRequest.js
552
653
  var TypeId2 = "~effect/http/HttpClientRequest";
553
654
  var isHttpClientRequest = (u) => hasProperty(u, TypeId2);
554
655
  var Proto2 = {
@@ -558,7 +659,7 @@ var Proto2 = {
558
659
  return {
559
660
  _id: "HttpClientRequest",
560
661
  method: this.method,
561
- url: this.url,
662
+ url: redactUrl(this.url),
562
663
  urlParams: this.urlParams,
563
664
  hash: this.hash,
564
665
  headers: redact(this.headers),
@@ -627,10 +728,11 @@ var setHeader = /* @__PURE__ */ dual(3, (self, key, value) => makeWith(self.meth
627
728
  var setHeaders = /* @__PURE__ */ dual(2, (self, input) => makeWith(self.method, self.url, self.urlParams, self.hash, setAll2(self.headers, input), self.body));
628
729
  var updateHeaders2 = /* @__PURE__ */ dual(2, (self, f) => makeWith(self.method, self.url, self.urlParams, self.hash, f(self.headers), self.body));
629
730
  var removeHeader = /* @__PURE__ */ dual(2, (self, key) => updateHeaders2(self, remove2(key)));
630
- 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)}`)}`));
631
732
  var bearerToken = /* @__PURE__ */ dual(2, (self, token) => setHeader(self, "Authorization", `Bearer ${stringOrRedacted(token)}`));
632
733
  var accept = /* @__PURE__ */ dual(2, (self, mediaType) => setHeader(self, "Accept", mediaType));
633
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));
634
736
  var setUrl = /* @__PURE__ */ dual(2, (self, url) => {
635
737
  if (typeof url === "string") {
636
738
  return makeWith(self.method, url, self.urlParams, self.hash, self.headers, self.body);
@@ -667,13 +769,19 @@ var removeHash = (self) => makeWith(self.method, self.url, self.urlParams, none(
667
769
  var setBody = /* @__PURE__ */ dual(2, (self, body) => {
668
770
  return makeWith(self.method, self.url, self.urlParams, self.hash, updateHeaders(self.headers, body), body);
669
771
  });
670
- var bodyUint8Array = /* @__PURE__ */ dual((args) => isHttpClientRequest(args[0]), (self, body, contentType) => setBody(self, uint8Array(body, contentType)));
671
- 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)));
672
780
  var bodyJson = /* @__PURE__ */ dual(2, (self, body) => map(json(body), (body2) => setBody(self, body2)));
673
781
  var bodyJsonUnsafe = /* @__PURE__ */ dual(2, (self, body) => setBody(self, jsonUnsafe(body)));
674
782
  var schemaBodyJson = (schema, options3) => {
675
- const encode = jsonSchema(schema, options3);
676
- 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)));
677
785
  };
678
786
  var bodyUrlParams = /* @__PURE__ */ dual(2, (self, input) => setBody(self, urlParams(fromInput3(input))));
679
787
  var bodyFormData = /* @__PURE__ */ dual(2, (self, body) => setBody(self, formData(body)));
@@ -689,8 +797,7 @@ function toUrl(self) {
689
797
  }
690
798
  var fromWeb = (request) => {
691
799
  const method = request.method.toUpperCase();
692
- return modify(empty8, {
693
- method,
800
+ return modify(makeWith(method, "", empty5, none(), empty4, empty7), {
694
801
  url: new URL(request.url),
695
802
  headers: request.headers,
696
803
  body: fromWebBody(request, method)
@@ -739,7 +846,7 @@ var toWebResult = (self, options3) => {
739
846
  break;
740
847
  }
741
848
  case "Stream": {
742
- requestInit.body = toReadableStreamWith(self.body.stream, options3?.context ?? empty2());
849
+ requestInit.body = toReadableStreamWith(self.body.stream, options3?.context ?? empty());
743
850
  requestInit.duplex = "half";
744
851
  break;
745
852
  }
@@ -758,7 +865,7 @@ var toWeb = (self, options3) => contextWith((context2) => fromResult(toWebResult
758
865
  signal: options3?.signal
759
866
  })));
760
867
 
761
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpClient.js
868
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpClient.js
762
869
  var HttpClient_exports = {};
763
870
  __export(HttpClient_exports, {
764
871
  HttpClient: () => HttpClient,
@@ -769,6 +876,7 @@ __export(HttpClient_exports, {
769
876
  catch: () => catch_2,
770
877
  catchTag: () => catchTag2,
771
878
  catchTags: () => catchTags2,
879
+ circuitBreakerClassifier: () => circuitBreakerClassifier,
772
880
  del: () => del2,
773
881
  execute: () => execute,
774
882
  filterOrElse: () => filterOrElse2,
@@ -779,6 +887,8 @@ __export(HttpClient_exports, {
779
887
  get: () => get5,
780
888
  head: () => head2,
781
889
  isHttpClient: () => isHttpClient,
890
+ isTransientError: () => isTransientError,
891
+ isTransientResponse: () => isTransientResponse,
782
892
  layerMergedContext: () => layerMergedContext,
783
893
  make: () => make3,
784
894
  makeWith: () => makeWith2,
@@ -796,14 +906,16 @@ __export(HttpClient_exports, {
796
906
  tap: () => tap2,
797
907
  tapError: () => tapError2,
798
908
  tapRequest: () => tapRequest,
909
+ timeout: () => timeout,
799
910
  transform: () => transform,
800
911
  transformResponse: () => transformResponse,
912
+ withCircuitBreaker: () => withCircuitBreaker,
801
913
  withCookiesRef: () => withCookiesRef,
802
914
  withRateLimiter: () => withRateLimiter,
803
915
  withScope: () => withScope
804
916
  });
805
917
 
806
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpClientError.js
918
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpClientError.js
807
919
  var HttpClientError_exports = {};
808
920
  __export(HttpClientError_exports, {
809
921
  DecodeError: () => DecodeError,
@@ -814,6 +926,8 @@ __export(HttpClientError_exports, {
814
926
  InvalidUrlError: () => InvalidUrlError,
815
927
  StatusCodeError: () => StatusCodeError,
816
928
  TransportError: () => TransportError,
929
+ addFailureRedactedNames: () => addFailureRedactedNames,
930
+ addResponseRedactedNames: () => addResponseRedactedNames,
817
931
  isHttpClientError: () => isHttpClientError
818
932
  });
819
933
  var TypeId3 = "~effect/http/HttpClientError";
@@ -832,12 +946,14 @@ var HttpClientError = class extends (/* @__PURE__ */ TaggedError("HttpClientErro
832
946
  /**
833
947
  * Marks this value as an HTTP client error for runtime guards.
834
948
  *
949
+ * @stability unstable
835
950
  * @since 4.0.0
836
951
  */
837
952
  [TypeId3] = TypeId3;
838
953
  /**
839
954
  * HTTP request associated with the client failure.
840
955
  *
956
+ * @stability unstable
841
957
  * @since 4.0.0
842
958
  */
843
959
  get request() {
@@ -846,6 +962,7 @@ var HttpClientError = class extends (/* @__PURE__ */ TaggedError("HttpClientErro
846
962
  /**
847
963
  * HTTP response associated with the client failure, when one was received.
848
964
  *
965
+ * @stability unstable
849
966
  * @since 4.0.0
850
967
  */
851
968
  get response() {
@@ -857,116 +974,187 @@ var HttpClientError = class extends (/* @__PURE__ */ TaggedError("HttpClientErro
857
974
  };
858
975
  var formatReason = (tag2) => tag2.endsWith("Error") ? tag2.slice(0, -5) : tag2;
859
976
  var formatMessage = (reason, description, info) => description ? `${reason}: ${description} (${info})` : `${reason} error (${info})`;
860
- 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")) {
861
1019
  /**
862
1020
  * Formats the request method and URL for transport error messages.
863
1021
  *
1022
+ * @stability unstable
864
1023
  * @since 4.0.0
865
1024
  */
866
1025
  get methodAndUrl() {
867
- return `${this.request.method} ${this.request.url}`;
1026
+ return formatMethodAndUrl(this);
868
1027
  }
869
1028
  /**
870
1029
  * Builds the transport error message from the optional description and request details.
871
1030
  *
1031
+ * @stability unstable
872
1032
  * @since 4.0.0
873
1033
  */
874
1034
  get message() {
875
1035
  return formatMessage(formatReason(this._tag), this.description, this.methodAndUrl);
876
1036
  }
1037
+ toJSON() {
1038
+ return reasonToJSON(this, super.toJSON());
1039
+ }
877
1040
  };
878
- var EncodeError = class extends (/* @__PURE__ */ TaggedError("EncodeError")) {
1041
+ var EncodeError = class extends (/* @__PURE__ */ ReasonError("EncodeError")) {
879
1042
  /**
880
1043
  * Formats the request method and URL for request encoding error messages.
881
1044
  *
1045
+ * @stability unstable
882
1046
  * @since 4.0.0
883
1047
  */
884
1048
  get methodAndUrl() {
885
- return `${this.request.method} ${this.request.url}`;
1049
+ return formatMethodAndUrl(this);
886
1050
  }
887
1051
  /**
888
1052
  * Builds the request encoding error message from the optional description and request details.
889
1053
  *
1054
+ * @stability unstable
890
1055
  * @since 4.0.0
891
1056
  */
892
1057
  get message() {
893
1058
  return formatMessage(formatReason(this._tag), this.description, this.methodAndUrl);
894
1059
  }
1060
+ toJSON() {
1061
+ return reasonToJSON(this, super.toJSON());
1062
+ }
895
1063
  };
896
- var InvalidUrlError = class extends (/* @__PURE__ */ TaggedError("InvalidUrlError")) {
1064
+ var InvalidUrlError = class extends (/* @__PURE__ */ ReasonError("InvalidUrlError")) {
897
1065
  /**
898
1066
  * Formats the request method and URL for invalid URL error messages.
899
1067
  *
1068
+ * @stability unstable
900
1069
  * @since 4.0.0
901
1070
  */
902
1071
  get methodAndUrl() {
903
- return `${this.request.method} ${this.request.url}`;
1072
+ return formatMethodAndUrl(this);
904
1073
  }
905
1074
  /**
906
1075
  * Builds the invalid URL error message from the optional description and request details.
907
1076
  *
1077
+ * @stability unstable
908
1078
  * @since 4.0.0
909
1079
  */
910
1080
  get message() {
911
1081
  return formatMessage(formatReason(this._tag), this.description, this.methodAndUrl);
912
1082
  }
1083
+ toJSON() {
1084
+ return reasonToJSON(this, super.toJSON());
1085
+ }
913
1086
  };
914
- var StatusCodeError = class extends (/* @__PURE__ */ TaggedError("StatusCodeError")) {
1087
+ var StatusCodeError = class extends (/* @__PURE__ */ ReasonError("StatusCodeError")) {
915
1088
  /**
916
1089
  * Formats the request method and URL for status code error messages.
917
1090
  *
1091
+ * @stability unstable
918
1092
  * @since 4.0.0
919
1093
  */
920
1094
  get methodAndUrl() {
921
- return `${this.request.method} ${this.request.url}`;
1095
+ return formatMethodAndUrl(this);
922
1096
  }
923
1097
  /**
924
1098
  * Builds the status code error message from the response status, optional description, and request details.
925
1099
  *
1100
+ * @stability unstable
926
1101
  * @since 4.0.0
927
1102
  */
928
1103
  get message() {
929
1104
  const info = `${this.response.status} ${this.methodAndUrl}`;
930
1105
  return formatMessage(formatReason(this._tag), this.description, info);
931
1106
  }
1107
+ toJSON() {
1108
+ return reasonToJSON(this, super.toJSON());
1109
+ }
932
1110
  };
933
- var DecodeError = class extends (/* @__PURE__ */ TaggedError("DecodeError")) {
1111
+ var DecodeError = class extends (/* @__PURE__ */ ReasonError("DecodeError")) {
934
1112
  /**
935
1113
  * Formats the request method and URL for response decoding error messages.
936
1114
  *
1115
+ * @stability unstable
937
1116
  * @since 4.0.0
938
1117
  */
939
1118
  get methodAndUrl() {
940
- return `${this.request.method} ${this.request.url}`;
1119
+ return formatMethodAndUrl(this);
941
1120
  }
942
1121
  /**
943
1122
  * Builds the response decoding error message from the response status, optional description, and request details.
944
1123
  *
1124
+ * @stability unstable
945
1125
  * @since 4.0.0
946
1126
  */
947
1127
  get message() {
948
1128
  const info = `${this.response.status} ${this.methodAndUrl}`;
949
1129
  return formatMessage(formatReason(this._tag), this.description, info);
950
1130
  }
1131
+ toJSON() {
1132
+ return reasonToJSON(this, super.toJSON());
1133
+ }
951
1134
  };
952
- var EmptyBodyError = class extends (/* @__PURE__ */ TaggedError("EmptyBodyError")) {
1135
+ var EmptyBodyError = class extends (/* @__PURE__ */ ReasonError("EmptyBodyError")) {
953
1136
  /**
954
1137
  * Formats the request method and URL for empty response body error messages.
955
1138
  *
1139
+ * @stability unstable
956
1140
  * @since 4.0.0
957
1141
  */
958
1142
  get methodAndUrl() {
959
- return `${this.request.method} ${this.request.url}`;
1143
+ return formatMethodAndUrl(this);
960
1144
  }
961
1145
  /**
962
1146
  * Builds the empty body error message from the response status, optional description, and request details.
963
1147
  *
1148
+ * @stability unstable
964
1149
  * @since 4.0.0
965
1150
  */
966
1151
  get message() {
967
1152
  const info = `${this.response.status} ${this.methodAndUrl}`;
968
1153
  return formatMessage(formatReason(this._tag), this.description, info);
969
1154
  }
1155
+ toJSON() {
1156
+ return reasonToJSON(this, super.toJSON());
1157
+ }
970
1158
  };
971
1159
  var HttpClientErrorSchema = class _HttpClientErrorSchema extends (/* @__PURE__ */ Error3(TypeId3)({
972
1160
  _tag: /* @__PURE__ */ tag("HttpError"),
@@ -976,6 +1164,7 @@ var HttpClientErrorSchema = class _HttpClientErrorSchema extends (/* @__PURE__ *
976
1164
  /**
977
1165
  * Builds the serializable schema representation for an HTTP client error.
978
1166
  *
1167
+ * @stability unstable
979
1168
  * @since 4.0.0
980
1169
  */
981
1170
  static fromHttpClientError(error) {
@@ -985,9 +1174,13 @@ var HttpClientErrorSchema = class _HttpClientErrorSchema extends (/* @__PURE__ *
985
1174
  cause: error.reason
986
1175
  });
987
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
+ }
988
1181
  };
989
1182
 
990
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpIncomingMessage.js
1183
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpIncomingMessage.js
991
1184
  var TypeId4 = "~effect/http/HttpIncomingMessage";
992
1185
  var schemaBodyJson2 = (schema, options3) => {
993
1186
  const decode = decodeEffect(toCodecJson(schema));
@@ -1002,41 +1195,28 @@ var MaxBodySize = /* @__PURE__ */ Reference("effect/http/HttpIncomingMessage/Max
1002
1195
  defaultValue: () => void 0
1003
1196
  });
1004
1197
  var inspect = (self, that) => {
1005
- const contentType = self.headers["content-type"] ?? "";
1006
- let body;
1007
- if (contentType.includes("application/json")) {
1008
- try {
1009
- body = runSync(self.json);
1010
- } catch (_) {
1011
- }
1012
- } else if (contentType.includes("text/") || contentType.includes("urlencoded")) {
1013
- try {
1014
- body = runSync(self.text);
1015
- } catch (_) {
1016
- }
1017
- }
1018
- const obj = {
1198
+ return {
1019
1199
  ...that,
1020
1200
  headers: redact(self.headers),
1021
1201
  remoteAddress: self.remoteAddress
1022
1202
  };
1023
- if (body !== void 0) {
1024
- obj.body = body;
1025
- }
1026
- return obj;
1027
1203
  };
1028
1204
 
1029
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/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
1030
1210
  var TypeId5 = "~effect/http/HttpClientResponse";
1031
1211
  var fromWeb2 = (request, source) => new WebHttpClientResponse(request, source);
1032
- 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({
1033
1213
  reason: new StatusCodeError({
1034
1214
  response: self,
1035
1215
  request: self.request,
1036
1216
  description: "invalid status code"
1037
1217
  })
1038
1218
  }))));
1039
- 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({
1040
1220
  reason: new StatusCodeError({
1041
1221
  response: self,
1042
1222
  request: self.request,
@@ -1080,11 +1260,14 @@ var WebHttpClientResponse = class extends Class {
1080
1260
  if (this.cachedCookies) {
1081
1261
  return this.cachedCookies;
1082
1262
  }
1083
- return this.cachedCookies = fromSetCookie(this.source.headers.getSetCookie());
1263
+ return this.cachedCookies = fromSetCookie(this.source.headers.getSetCookie?.() ?? []);
1084
1264
  }
1085
1265
  get remoteAddress() {
1086
1266
  return none();
1087
1267
  }
1268
+ [WebSourceSymbol]() {
1269
+ return this.source;
1270
+ }
1088
1271
  get stream() {
1089
1272
  return this.source.body ? fromReadableStream({
1090
1273
  evaluate: () => this.source.body,
@@ -1120,8 +1303,8 @@ var WebHttpClientResponse = class extends Class {
1120
1303
  return this.textBody ??= map(this.arrayBuffer, (_) => new TextDecoder().decode(_));
1121
1304
  }
1122
1305
  get urlParamsBody() {
1123
- return flatMap(this.text, (_) => try_2({
1124
- try: () => fromInput3(new URLSearchParams(_)),
1306
+ return flatMap(this.arrayBuffer, (bytes) => try_2({
1307
+ try: () => fromInput3(fromBody(bytes)),
1125
1308
  catch: (cause) => new HttpClientError({
1126
1309
  reason: new DecodeError({
1127
1310
  request: this.request,
@@ -1161,12 +1344,21 @@ var WebHttpClientResponse = class extends Class {
1161
1344
  }).pipe(cached, runSync);
1162
1345
  return this.arrayBufferBody;
1163
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
+ }
1164
1356
  pipe() {
1165
1357
  return pipeArguments(this, arguments);
1166
1358
  }
1167
1359
  };
1168
1360
 
1169
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpTraceContext.js
1361
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpTraceContext.js
1170
1362
  var HttpTraceContext_exports = {};
1171
1363
  __export(HttpTraceContext_exports, {
1172
1364
  b3: () => b3,
@@ -1180,7 +1372,7 @@ var toHeaders = (span) => fromRecordUnsafe({
1180
1372
  onNone: () => "",
1181
1373
  onSome: (parent) => `-${parent.spanId}`
1182
1374
  })}`,
1183
- traceparent: `00-${span.traceId}-${span.spanId}-${span.sampled ? "01" : "00"}`
1375
+ traceparent: `00-${span.traceId.padStart(32, "0")}-${span.spanId}-${span.sampled ? "01" : "00"}`
1184
1376
  });
1185
1377
  var fromHeaders = (headers) => {
1186
1378
  let span = w3c(headers);
@@ -1198,27 +1390,30 @@ var b3 = (headers) => {
1198
1390
  return none();
1199
1391
  }
1200
1392
  const parts = headers["b3"].split("-");
1201
- if (parts.length < 2) {
1393
+ if (parts.length < 2 || isB3Ids(parts[0], parts[1]) === false) {
1202
1394
  return none();
1203
1395
  }
1204
1396
  return some(externalSpan({
1205
1397
  traceId: parts[0],
1206
1398
  spanId: parts[1],
1207
- sampled: parts[2] ? parts[2] === "1" : true
1399
+ sampled: parts[2] ? parts[2] === "1" || parts[2] === "d" : true
1208
1400
  }));
1209
1401
  };
1210
1402
  var xb3 = (headers) => {
1211
- 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) {
1212
1404
  return none();
1213
1405
  }
1214
1406
  return some(externalSpan({
1215
1407
  traceId: headers["x-b3-traceid"],
1216
1408
  spanId: headers["x-b3-spanid"],
1217
- sampled: headers["x-b3-sampled"] ? headers["x-b3-sampled"] === "1" : true
1409
+ sampled: headers["x-b3-flags"] === "1" || (headers["x-b3-sampled"] ? headers["x-b3-sampled"] === "1" || headers["x-b3-sampled"] === "true" : true)
1218
1410
  }));
1219
1411
  };
1220
- var w3cTraceId = /^[0-9a-f]{32}$/i;
1221
- 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);
1222
1417
  var w3c = (headers) => {
1223
1418
  if (!headers["traceparent"]) {
1224
1419
  return none();
@@ -1230,7 +1425,7 @@ var w3c = (headers) => {
1230
1425
  const [version, traceId, spanId, flags] = parts;
1231
1426
  switch (version) {
1232
1427
  case "00": {
1233
- if (w3cTraceId.test(traceId) === false || w3cSpanId.test(spanId) === false) {
1428
+ if (w3cTraceId.test(traceId) === false || w3cSpanId.test(spanId) === false || w3cTraceFlags.test(flags) === false || traceId === "00000000000000000000000000000000" || spanId === "0000000000000000") {
1234
1429
  return none();
1235
1430
  }
1236
1431
  return some(externalSpan({
@@ -1245,7 +1440,41 @@ var w3c = (headers) => {
1245
1440
  }
1246
1441
  };
1247
1442
 
1248
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/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
1249
1478
  var TypeId6 = "~effect/http/HttpClient";
1250
1479
  var isHttpClient = (u) => hasProperty(u, TypeId6);
1251
1480
  var HttpClient = /* @__PURE__ */ Service("effect/HttpClient");
@@ -1259,10 +1488,16 @@ var patch2 = /* @__PURE__ */ accessor("patch");
1259
1488
  var put2 = /* @__PURE__ */ accessor("put");
1260
1489
  var del2 = /* @__PURE__ */ accessor("del");
1261
1490
  var options2 = /* @__PURE__ */ accessor("options");
1262
- 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));
1263
1492
  var transformResponse = /* @__PURE__ */ dual(2, (self, f) => makeWith2((request) => f(self.postprocess(request)), self.preprocess));
1264
1493
  var catch_2 = /* @__PURE__ */ dual(2, (self, f) => transformResponse(self, catch_(f)));
1265
- 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
+ ));
1266
1501
  var catchTags2 = /* @__PURE__ */ dual(2, (self, cases) => transformResponse(self, catchTags(cases)));
1267
1502
  var filterOrElse2 = /* @__PURE__ */ dual(3, (self, f, orElse) => transformResponse(self, filterOrElse(f, orElse)));
1268
1503
  var filterOrFail2 = /* @__PURE__ */ dual(3, (self, f, orFailWith) => transformResponse(self, filterOrFail(f, orFailWith)));
@@ -1293,8 +1528,9 @@ var Proto3 = {
1293
1528
  }]))
1294
1529
  };
1295
1530
  var make3 = (f) => makeWith2((effect2) => flatMap(effect2, (request) => withFiber((fiber) => {
1296
- const scopedController = scopedRequests.get(request);
1297
- const controller = scopedController ?? new AbortController();
1531
+ const scope2 = fiber.getRef(RequestScope);
1532
+ const controller = new AbortController();
1533
+ const urlParamsRedactedNames = fiber.getRef(CurrentRedactedNames2);
1298
1534
  const urlResult = make(request.url, request.urlParams, getOrUndefined(request.hash));
1299
1535
  if (isFailure(urlResult)) {
1300
1536
  return fail3(new HttpClientError({
@@ -1305,67 +1541,62 @@ var make3 = (f) => makeWith2((effect2) => flatMap(effect2, (request) => withFibe
1305
1541
  }));
1306
1542
  }
1307
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
+ }));
1308
1559
  const tracerDisabled = fiber.getRef(DisablePropagation) || fiber.getRef(TracerDisabledWhen)(request);
1309
1560
  if (tracerDisabled) {
1310
- const effect3 = f(request, url, controller.signal, fiber);
1311
- if (scopedController) return effect3;
1312
- return uninterruptibleMask((restore) => matchCauseEffect(restore(effect3), {
1313
- onSuccess(response) {
1314
- responseRegistry.register(response, controller);
1315
- return succeed2(new InterruptibleResponse(response, controller));
1316
- },
1317
- onFailure(cause) {
1318
- if (hasInterrupts(cause)) {
1319
- controller.abort();
1320
- }
1321
- return failCause2(cause);
1322
- }
1323
- }));
1561
+ return exchange(request);
1324
1562
  }
1325
1563
  return useSpan(fiber.getRef(SpanNameGenerator)(request), {
1326
1564
  kind: "client"
1327
1565
  }, (span) => {
1328
1566
  span.attribute("http.request.method", request.method);
1329
- span.attribute("server.address", url.origin);
1330
- if (url.port !== "") {
1331
- span.attribute("server.port", +url.port);
1332
- }
1333
- span.attribute("url.full", url.toString());
1334
- span.attribute("url.path", url.pathname);
1335
- span.attribute("url.scheme", url.protocol.slice(0, -1));
1336
- const query3 = url.search.slice(1);
1337
- if (query3 !== "") {
1338
- span.attribute("url.query", query3);
1339
- }
1340
1567
  const redactedHeaderNames = fiber.getRef(CurrentRedactedNames);
1568
+ addUrlAttributes(span, url, redactedNames(request.urlParams, urlParamsRedactedNames));
1341
1569
  const headerFilter = fiber.getRef(TracerHeaderFilter);
1342
- for (const name in request.headers) {
1343
- if (!headerFilter(name, "request")) continue;
1344
- span.attribute(`http.request.header.${name}`, isRedactedName(name, redactedHeaderNames) ? "<redacted>" : request.headers[name]);
1345
- }
1570
+ addHeaderAttributes(span, "request", request.headers, headerFilter, redactedHeaderNames);
1346
1571
  request = fiber.getRef(TracerPropagationEnabled) ? setHeaders(request, toHeaders(span)) : request;
1347
- return uninterruptibleMask((restore) => restore(f(request, url, controller.signal, fiber)).pipe(withParentSpan(span, {
1348
- captureStackTrace: false
1349
- }), matchCauseEffect({
1350
- onSuccess: (response) => {
1351
- span.attribute("http.response.status_code", response.status);
1352
- for (const name in response.headers) {
1353
- if (!headerFilter(name, "response")) continue;
1354
- span.attribute(`http.response.header.${name}`, isRedactedName(name, redactedHeaderNames) ? "<redacted>" : response.headers[name]);
1355
- }
1356
- if (scopedController) return succeed2(response);
1357
- responseRegistry.register(response, controller);
1358
- return succeed2(new InterruptibleResponse(response, controller));
1359
- },
1360
- onFailure(cause) {
1361
- if (!scopedController && hasInterrupts(cause)) {
1362
- controller.abort();
1363
- }
1364
- 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);
1365
1578
  }
1366
- })));
1579
+ }), span, {
1580
+ captureStackTrace: false
1581
+ });
1367
1582
  });
1368
- })), 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
+ };
1369
1600
  var mapRequest = /* @__PURE__ */ dual(2, (self, f) => makeWith2(self.postprocess, (request) => map(self.preprocess(request), f)));
1370
1601
  var mapRequestEffect = /* @__PURE__ */ dual(2, (self, f) => makeWith2(self.postprocess, (request) => flatMap(self.preprocess(request), f)));
1371
1602
  var mapRequestInput = /* @__PURE__ */ dual(2, (self, f) => makeWith2(self.postprocess, (request) => self.preprocess(f(request))));
@@ -1374,11 +1605,10 @@ var retry2 = /* @__PURE__ */ dual(2, (self, policy) => transformResponse(self, r
1374
1605
  var retryTransient = /* @__PURE__ */ dual(2, (self, options3) => {
1375
1606
  const isOnlySchedule = isSchedule(options3);
1376
1607
  const retryOn = isOnlySchedule ? "errors-and-responses" : options3.retryOn ?? "errors-and-responses";
1377
- const schedule = isOnlySchedule ? options3 : options3.schedule;
1378
- const passthroughSchedule = schedule && passthrough(schedule);
1608
+ const schedule = withRetryAfter(isOnlySchedule ? options3 : options3.schedule ?? forever);
1379
1609
  const times = isOnlySchedule ? void 0 : options3.times;
1380
1610
  return transformResponse(self, flow(retryOn === "errors-only" ? identity : repeat({
1381
- schedule: passthroughSchedule,
1611
+ schedule,
1382
1612
  times,
1383
1613
  while: isTransientResponse
1384
1614
  }), retryOn === "response-only" ? identity : retry({
@@ -1387,6 +1617,20 @@ var retryTransient = /* @__PURE__ */ dual(2, (self, options3) => {
1387
1617
  times
1388
1618
  })));
1389
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
+ });
1390
1634
  var withRateLimiter = /* @__PURE__ */ dual(2, (self, options3) => {
1391
1635
  const initialState = {
1392
1636
  initial: true,
@@ -1408,35 +1652,66 @@ var withRateLimiter = /* @__PURE__ */ dual(2, (self, options3) => {
1408
1652
  states.set(key, initialState);
1409
1653
  return initialState;
1410
1654
  };
1411
- 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) => {
1412
1670
  const current = getState(key);
1413
1671
  const next = parseRateLimiterState(current, clock, headers, tokens, headerNames);
1414
1672
  if (next.limit !== current.limit || !equals(next.window, current.window)) {
1415
1673
  states.set(key, next);
1416
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
+ }
1417
1686
  };
1418
1687
  return transform(self, function loop(effect2, request, retries = 0) {
1419
1688
  const fiber = getCurrent();
1420
1689
  const clock = fiber.getRef(Clock);
1421
1690
  const key = resolveKey(request);
1422
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;
1423
1698
  const current = getState(key);
1424
1699
  const canRetry = options3.times === void 0 || retries < options3.times;
1425
1700
  function retry3(retryAfter) {
1426
1701
  return retryAfter ? flatMap(sleep(retryAfter), () => loop(effect2, request, retries + 1)) : loop(effect2, request, retries + 1);
1427
1702
  }
1428
1703
  const inspectResponse = (response, adaptive) => {
1429
- onResponse?.(clock, key, response.headers, tokens);
1704
+ onResponse?.(clock, key, response.headers, tokens, sent);
1430
1705
  if (options3.disableResponseInspection || response.status !== 429) {
1431
- return succeed2(void 0);
1706
+ return succeed4(void 0);
1432
1707
  }
1433
- const retryAfter = parseRetryAfter(clock, getHeader(response.headers, ...headerNames.retryAfter));
1708
+ const retryAfter = parseRetryAfter2(clock.currentTimeMillisUnsafe(), getHeader(response.headers, ...headerNames.retryAfter));
1434
1709
  if (retryAfter === void 0) {
1435
- return succeed2(void 0);
1710
+ return succeed4(void 0);
1436
1711
  }
1437
1712
  const delay2 = parseRateLimitWindow(clock, response.headers, headerNames) ?? retryAfter;
1438
1713
  if (adaptive === void 0) {
1439
- return succeed2(delay2);
1714
+ return succeed4(delay2);
1440
1715
  }
1441
1716
  return as(options3.limiter.adaptiveFeedback({
1442
1717
  key,
@@ -1461,7 +1736,7 @@ var withRateLimiter = /* @__PURE__ */ dual(2, (self, options3) => {
1461
1736
  const request2 = matchEffect(effect2, {
1462
1737
  onSuccess(response) {
1463
1738
  return flatMap(inspectResponse(response, adaptive), (retryAfter) => {
1464
- if (response.status !== 429 || !canRetry) return succeed2(response);
1739
+ if (response.status !== 429 || !canRetry) return succeed4(response);
1465
1740
  return retry3(retryAfter);
1466
1741
  });
1467
1742
  },
@@ -1493,6 +1768,70 @@ var withRateLimiter = /* @__PURE__ */ dual(2, (self, options3) => {
1493
1768
  });
1494
1769
  });
1495
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";
1496
1835
  var resolveRateLimiterHeaderNames = (responseHeaders) => ({
1497
1836
  limit: responseHeaders?.limit === void 0 ? ["ratelimit-limit", "x-ratelimit-limit"] : [responseHeaders.limit.toLowerCase()],
1498
1837
  remaining: responseHeaders?.remaining === void 0 ? ["ratelimit-remaining", "x-ratelimit-remaining"] : [responseHeaders.remaining.toLowerCase()],
@@ -1536,23 +1875,12 @@ var parseRateLimitWindow = (clock, headers, headerNames) => {
1536
1875
  }
1537
1876
  return parseResetHeader(clock, getHeader(headers, ...headerNames.reset));
1538
1877
  };
1539
- var parseRetryAfter = (clock, value) => {
1878
+ var parseRetryAfter2 = (nowMillis, value) => {
1540
1879
  if (value === void 0) {
1541
1880
  return void 0;
1542
1881
  }
1543
- const numeric = parseNumberHeader(value);
1544
- if (numeric !== void 0) {
1545
- return max(seconds(numeric), millis(1));
1546
- }
1547
- const parsedDate = Date.parse(value);
1548
- if (Number.isNaN(parsedDate)) {
1549
- return void 0;
1550
- }
1551
- const millis2 = parsedDate - clock.currentTimeMillisUnsafe();
1552
- if (millis2 <= 0) {
1553
- return millis(1);
1554
- }
1555
- return millis(millis2);
1882
+ const retryAfter = parseRetryAfter(value);
1883
+ return isSuccess(retryAfter) ? max(retryAfterDelay(retryAfter.success, nowMillis), millis(1)) : void 0;
1556
1884
  };
1557
1885
  var parseResetAfter = (value) => {
1558
1886
  const numeric = parseNumberHeader(value);
@@ -1598,12 +1926,16 @@ var getHeader = (headers, ...keys) => {
1598
1926
  var tap2 = /* @__PURE__ */ dual(2, (self, f) => transformResponse(self, tap(f)));
1599
1927
  var tapError2 = /* @__PURE__ */ dual(2, (self, f) => transformResponse(self, tapError(f)));
1600
1928
  var tapRequest = /* @__PURE__ */ dual(2, (self, f) => makeWith2(self.postprocess, (request) => tap(self.preprocess(request), f)));
1601
- 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))))));
1602
- var withScope = (self) => transform(self, (effect2, request) => {
1603
- const controller = new AbortController();
1604
- scopedRequests.set(request, controller);
1605
- 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);
1606
1937
  });
1938
+ var withScope = (self) => transformResponse(self, provideServiceEffect(RequestScope, scope));
1607
1939
  var followRedirects = /* @__PURE__ */ dual((args) => isHttpClient(args[0]), (self, maxRedirects) => makeWith2((request) => {
1608
1940
  const loop = (request2, redirects) => suspend(() => {
1609
1941
  let currentRequest;
@@ -1612,21 +1944,31 @@ var followRedirects = /* @__PURE__ */ dual((args) => isHttpClient(args[0]), (sel
1612
1944
  return request3;
1613
1945
  })), (response) => {
1614
1946
  if (response.status < 300 || response.status >= 400 || !response.headers.location || redirects >= (maxRedirects ?? 10)) {
1615
- 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);
1616
1952
  }
1617
- const url = new URL(response.headers.location, response.request.url);
1953
+ const url = urlResult.success;
1618
1954
  const request3 = currentRequest ?? response.request;
1619
1955
  let nextRequest = request3;
1620
1956
  if ((response.status === 301 || response.status === 302) && request3.method === "POST" || response.status === 303 && request3.method !== "GET" && request3.method !== "HEAD") {
1621
1957
  nextRequest = setMethod(nextRequest, "GET");
1622
1958
  nextRequest = setBody(nextRequest, empty7);
1959
+ nextRequest = removeHeader(nextRequest, "content-encoding");
1960
+ nextRequest = removeHeader(nextRequest, "content-language");
1961
+ nextRequest = removeHeader(nextRequest, "content-location");
1623
1962
  }
1624
1963
  if (url.origin !== new URL(response.request.url).origin) {
1625
1964
  nextRequest = removeHeader(nextRequest, "authorization");
1626
1965
  nextRequest = removeHeader(nextRequest, "proxy-authorization");
1627
1966
  nextRequest = removeHeader(nextRequest, "cookie");
1628
1967
  }
1629
- 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));
1630
1972
  });
1631
1973
  });
1632
1974
  return loop(request, 0);
@@ -1635,19 +1977,22 @@ var TracerDisabledWhen = /* @__PURE__ */ Reference("effect/http/HttpClient/Trace
1635
1977
  defaultValue: () => constFalse
1636
1978
  });
1637
1979
  var TracerHeaderFilter = /* @__PURE__ */ Reference("effect/http/HttpClient/TracerHeaderFilter", {
1638
- defaultValue: () => constTrue
1980
+ defaultValue: () => constFalse
1639
1981
  });
1640
1982
  var TracerPropagationEnabled = /* @__PURE__ */ Reference("effect/http/HttpClient/TracerPropagationEnabled", {
1641
1983
  defaultValue: constTrue
1642
1984
  });
1643
1985
  var SpanNameGenerator = /* @__PURE__ */ Reference("effect/http/HttpClient/SpanNameGenerator", {
1644
- defaultValue: () => (request) => `http.client ${request.method}`
1986
+ defaultValue: () => (request) => request.method
1645
1987
  });
1646
1988
  var layerMergedContext = (effect2) => effect(HttpClient)(contextWith((context2) => map(effect2, (client) => transformResponse(client, updateContext((input) => merge(context2, input))))));
1647
1989
  var responseRegistry = /* @__PURE__ */ (() => {
1648
1990
  if ("FinalizationRegistry" in globalThis && globalThis.FinalizationRegistry) {
1649
1991
  const registry = /* @__PURE__ */ new FinalizationRegistry((controller) => {
1650
- controller.abort();
1992
+ try {
1993
+ controller.abort();
1994
+ } catch {
1995
+ }
1651
1996
  });
1652
1997
  return {
1653
1998
  register(response, controller) {
@@ -1658,7 +2003,7 @@ var responseRegistry = /* @__PURE__ */ (() => {
1658
2003
  }
1659
2004
  };
1660
2005
  }
1661
- const timers = /* @__PURE__ */ new Map();
2006
+ const timers = /* @__PURE__ */ new WeakMap();
1662
2007
  return {
1663
2008
  register(response, controller) {
1664
2009
  timers.set(response, setTimeout(() => controller.abort(), 5e3));
@@ -1671,7 +2016,20 @@ var responseRegistry = /* @__PURE__ */ (() => {
1671
2016
  }
1672
2017
  };
1673
2018
  })();
1674
- 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
+ };
1675
2033
  var InterruptibleResponse = class {
1676
2034
  original;
1677
2035
  controller;
@@ -1722,6 +2080,14 @@ var InterruptibleResponse = class {
1722
2080
  get arrayBuffer() {
1723
2081
  return this.applyInterrupt(this.original.arrayBuffer);
1724
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
+ }
1725
2091
  get stream() {
1726
2092
  return suspend2(() => {
1727
2093
  responseRegistry.unregister(this.original);
@@ -1742,10 +2108,21 @@ var InterruptibleResponse = class {
1742
2108
  };
1743
2109
  var isTransientError = (error) => isTimeoutError(error) || isTransientHttpError(error);
1744
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
+ }));
1745
2122
  var isTooManyRequestsHttpClientError = (error) => isHttpClientError(error) && error.reason._tag === "StatusCodeError" && error.reason.response.status === 429;
1746
2123
  var isTransientResponse = (response) => response.status === 408 || response.status === 429 || response.status === 500 || response.status === 502 || response.status === 503 || response.status === 504;
1747
2124
 
1748
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/Template.js
2125
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/Template.js
1749
2126
  function make4(strings, ...args) {
1750
2127
  const argsLength = args.length;
1751
2128
  const values = new Array(argsLength);
@@ -1754,7 +2131,7 @@ function make4(strings, ...args) {
1754
2131
  const arg = args[i];
1755
2132
  if (isOption(arg)) {
1756
2133
  values[i] = arg._tag === "Some" ? primitiveToString(arg.value) : "";
1757
- } else if (isSuccess2(arg)) {
2134
+ } else if (isSuccess3(arg)) {
1758
2135
  values[i] = primitiveToString(arg.value);
1759
2136
  } else if (isEffect(arg)) {
1760
2137
  effects.push([i, arg]);
@@ -1763,7 +2140,7 @@ function make4(strings, ...args) {
1763
2140
  }
1764
2141
  }
1765
2142
  if (effects.length === 0) {
1766
- return succeed2(consolidate(strings, values));
2143
+ return succeed4(consolidate(strings, values));
1767
2144
  }
1768
2145
  return map(forEach(effects, ([index, effect2]) => tap(effect2, (value) => sync(() => {
1769
2146
  values[index] = primitiveToString(value);
@@ -1780,7 +2157,7 @@ function stream2(strings, ...args) {
1780
2157
  const arg = args[i];
1781
2158
  if (isOption(arg)) {
1782
2159
  buffer2 += arg._tag === "Some" ? primitiveToString(arg.value) : "";
1783
- } else if (isSuccess2(arg)) {
2160
+ } else if (isSuccess3(arg)) {
1784
2161
  buffer2 += primitiveToString(arg.value);
1785
2162
  } else if (isEffect(arg)) {
1786
2163
  if (buffer2.length > 0) {
@@ -1803,9 +2180,9 @@ function stream2(strings, ...args) {
1803
2180
  chunks.push(buffer2);
1804
2181
  buffer2 = "";
1805
2182
  }
1806
- return fromIterable2(chunks).pipe(mapEffect((chunk) => isEffect(chunk) ? chunk : succeed2(chunk), {
2183
+ return fromIterable2(chunks).pipe(mapEffect((chunk) => isEffect(chunk) ? chunk : succeed4(chunk), {
1807
2184
  concurrency: "unbounded"
1808
- }), flatMap2((chunk) => typeof chunk === "string" ? succeed3(chunk) : chunk));
2185
+ }), flatMap2((chunk) => typeof chunk === "string" ? succeed5(chunk) : chunk));
1809
2186
  }
1810
2187
  function primitiveToString(value) {
1811
2188
  if (Array.isArray(value)) {
@@ -1835,11 +2212,11 @@ function consolidate(strings, values) {
1835
2212
  }
1836
2213
  return out + strings[strings.length - 1];
1837
2214
  }
1838
- function isSuccess2(u) {
2215
+ function isSuccess3(u) {
1839
2216
  return isExit(u) && u._tag === "Success";
1840
2217
  }
1841
2218
 
1842
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpServerResponse.js
2219
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpServerResponse.js
1843
2220
  var HttpServerResponse_exports = {};
1844
2221
  __export(HttpServerResponse_exports, {
1845
2222
  empty: () => empty9,
@@ -1881,11 +2258,11 @@ __export(HttpServerResponse_exports, {
1881
2258
  urlParams: () => urlParams2
1882
2259
  });
1883
2260
 
1884
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/internal/headers.js
2261
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/internal/headers.js
1885
2262
  var Proto4 = /* @__PURE__ */ Object.getPrototypeOf(empty4);
1886
2263
  var emptyMutableUnsafe = () => Object.create(Proto4);
1887
2264
 
1888
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpServerResponse.js
2265
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpServerResponse.js
1889
2266
  var TypeId7 = "~effect/http/HttpServerResponse";
1890
2267
  var isHttpServerResponse = (u) => hasProperty(u, TypeId7);
1891
2268
  var empty9 = (options3) => makeResponse({
@@ -1956,10 +2333,10 @@ var json2 = (body, options3) => {
1956
2333
  }));
1957
2334
  };
1958
2335
  var schemaJson = (schema, options3) => {
1959
- const encode = jsonSchema(schema, options3);
2336
+ const encode2 = jsonSchema(schema, options3);
1960
2337
  return (body, options4) => {
1961
2338
  const headers = options4?.headers ? fromInput2(options4.headers) : empty4;
1962
- return map(encode(body, getContentType(options4, headers)), (body2) => makeResponse({
2339
+ return map(encode2(body, getContentType(options4, headers)), (body2) => makeResponse({
1963
2340
  status: options4?.status ?? 200,
1964
2341
  statusText: options4?.statusText,
1965
2342
  headers,
@@ -2083,6 +2460,17 @@ var setStatus = /* @__PURE__ */ dual((args) => isHttpServerResponse(args[0]), (s
2083
2460
  statusText: statusText ?? self.statusText
2084
2461
  }));
2085
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
+ };
2086
2474
  var toWeb2 = (response, options3) => {
2087
2475
  const headers = new globalThis.Headers(response.headers);
2088
2476
  if (!isEmpty(response.cookies)) {
@@ -2096,27 +2484,25 @@ var toWeb2 = (response, options3) => {
2096
2484
  const withoutBody = outerOmitsBody || options3?.withoutBody === true;
2097
2485
  if (body._tag === "Raw" && body.body instanceof Response) {
2098
2486
  const raw3 = body.body;
2099
- for (const [key, value] of headers) {
2100
- if (key === "set-cookie") {
2101
- raw3.headers.append(key, value);
2102
- } else {
2103
- raw3.headers.set(key, value);
2104
- }
2105
- }
2106
- 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"))) {
2107
2490
  return raw3;
2108
2491
  }
2109
- const source = outerOmitsBody ? response : raw3;
2110
- return new Response(void 0, {
2492
+ const copy = withoutBody ? new Response(void 0, {
2111
2493
  status: source.status,
2112
2494
  statusText: source.statusText,
2113
2495
  headers: raw3.headers
2114
- });
2496
+ }) : new Response(raw3.body, raw3);
2497
+ mergeHeaders(copy.headers, headers);
2498
+ if (omitContentLength) copy.headers.delete("content-length");
2499
+ return copy;
2115
2500
  }
2116
2501
  if (withoutBody) {
2117
2502
  if (body._tag === "Raw" && isReadableStream2(body.body)) {
2118
2503
  body.body.cancel().catch(constVoid);
2119
2504
  }
2505
+ if (omitsContentLength(response.status)) headers.delete("content-length");
2120
2506
  return new Response(void 0, {
2121
2507
  status: response.status,
2122
2508
  statusText: response.statusText,
@@ -2153,7 +2539,9 @@ var toWeb2 = (response, options3) => {
2153
2539
  });
2154
2540
  }
2155
2541
  case "Stream": {
2156
- return new Response(toReadableStreamWith(body.stream, options3?.context ?? empty2()), {
2542
+ return new Response(toReadableStreamWith(body.stream, options3?.context ?? empty(), {
2543
+ signal: options3?.signal
2544
+ }), {
2157
2545
  status: response.status,
2158
2546
  statusText: response.statusText,
2159
2547
  headers
@@ -2211,7 +2599,7 @@ var ServerHttpClientResponse = class extends Class {
2211
2599
  return mapError3(body.stream, (cause) => this.decodeError(cause));
2212
2600
  }
2213
2601
  case "Uint8Array": {
2214
- return succeed3(body.body);
2602
+ return succeed5(body.body);
2215
2603
  }
2216
2604
  case "Raw": {
2217
2605
  const rawBody = body.body;
@@ -2233,7 +2621,7 @@ var ServerHttpClientResponse = class extends Class {
2233
2621
  onError: (cause) => this.decodeError(cause)
2234
2622
  });
2235
2623
  }
2236
- return unwrap2(map(this.bytes, succeed3));
2624
+ return unwrap3(map(this.bytes, succeed5));
2237
2625
  }
2238
2626
  case "FormData": {
2239
2627
  const response = this.getFormDataResponse();
@@ -2260,10 +2648,10 @@ var ServerHttpClientResponse = class extends Class {
2260
2648
  const body = this.response.body;
2261
2649
  switch (body._tag) {
2262
2650
  case "Empty": {
2263
- return succeed2(new Uint8Array(0));
2651
+ return succeed4(new Uint8Array(0));
2264
2652
  }
2265
2653
  case "Uint8Array": {
2266
- return succeed2(body.body);
2654
+ return succeed4(body.body);
2267
2655
  }
2268
2656
  case "Stream": {
2269
2657
  return mkUint8Array2(this.stream);
@@ -2293,8 +2681,8 @@ var ServerHttpClientResponse = class extends Class {
2293
2681
  return map(this.bytes, (bytes) => textDecoder.decode(bytes));
2294
2682
  }
2295
2683
  get urlParamsBody() {
2296
- return flatMap(this.text, (_) => try_2({
2297
- try: () => fromInput3(new URLSearchParams(_)),
2684
+ return flatMap(this.bytes, (bytes) => try_2({
2685
+ try: () => fromInput3(fromBody(bytes)),
2298
2686
  catch: (cause) => new HttpClientError({
2299
2687
  reason: new DecodeError({
2300
2688
  request: this.request,
@@ -2307,7 +2695,7 @@ var ServerHttpClientResponse = class extends Class {
2307
2695
  get formData() {
2308
2696
  const body = this.response.body;
2309
2697
  if (body._tag === "FormData") {
2310
- return succeed2(body.formData);
2698
+ return succeed4(body.formData);
2311
2699
  }
2312
2700
  return contextWith((context2) => {
2313
2701
  const readableStream = toReadableStreamWith(this.stream, context2);
@@ -2339,6 +2727,15 @@ var ServerHttpClientResponse = class extends Class {
2339
2727
  getFormDataResponse() {
2340
2728
  return this.formDataResponse ??= new Response(this.response.body.formData);
2341
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
+ }
2342
2739
  pipe() {
2343
2740
  return pipeArguments(this, arguments);
2344
2741
  }
@@ -2404,19 +2801,85 @@ var fromWeb3 = (response) => {
2404
2801
  cookies: fromSetCookie(setCookieHeaders)
2405
2802
  });
2406
2803
  if (response.body) {
2407
- const contentType = response.headers.get("content-type");
2804
+ const contentType2 = response.headers.get("content-type");
2408
2805
  self = setBody2(self, stream(fromReadableStream({
2409
2806
  evaluate: () => response.body,
2410
2807
  onError: (e) => e
2411
- }), contentType ?? void 0, parseContentLength(response.headers.get("content-length"))));
2808
+ }), contentType2 ?? void 0, parseContentLength(response.headers.get("content-length"))));
2412
2809
  }
2413
2810
  return self;
2414
2811
  };
2415
2812
 
2416
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/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
2417
2880
  var symbol = "~effect/http/HttpServerRespondable";
2418
2881
 
2419
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpServerError.js
2882
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpServerError.js
2420
2883
  var TypeId8 = "~effect/http/HttpServerError";
2421
2884
  var HttpServerError = class extends (/* @__PURE__ */ TaggedError("HttpServerError")) {
2422
2885
  constructor(props) {
@@ -2449,17 +2912,19 @@ var HttpServerError = class extends (/* @__PURE__ */ TaggedError("HttpServerErro
2449
2912
  };
2450
2913
  var RequestParseError = class extends (/* @__PURE__ */ TaggedError("RequestParseError")) {
2451
2914
  /**
2452
- * 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.
2453
2917
  *
2918
+ * @stability unstable
2454
2919
  * @since 4.0.0
2455
2920
  */
2456
2921
  [symbol]() {
2457
- return succeed2(empty9({
2458
- status: 400
2922
+ return succeed4(empty9({
2923
+ status: this.reason === "BodyTooLarge" ? 413 : 400
2459
2924
  }));
2460
2925
  }
2461
2926
  get methodAndUrl() {
2462
- return `${this.request.method} ${this.request.url}`;
2927
+ return formatMethodAndUrl2(this.request);
2463
2928
  }
2464
2929
  get message() {
2465
2930
  return formatRequestMessage(this._tag, this.description, this.methodAndUrl);
@@ -2467,13 +2932,13 @@ var RequestParseError = class extends (/* @__PURE__ */ TaggedError("RequestParse
2467
2932
  };
2468
2933
  var RouteNotFound = class extends (/* @__PURE__ */ TaggedError("RouteNotFound")) {
2469
2934
  [symbol]() {
2470
- return succeed2(empty9({
2935
+ return succeed4(empty9({
2471
2936
  status: 404
2472
2937
  }));
2473
2938
  }
2474
2939
  [ignore] = true;
2475
2940
  get methodAndUrl() {
2476
- return `${this.request.method} ${this.request.url}`;
2941
+ return formatMethodAndUrl2(this.request);
2477
2942
  }
2478
2943
  get message() {
2479
2944
  return formatRequestMessage(this._tag, this.description, this.methodAndUrl);
@@ -2483,15 +2948,16 @@ var InternalError = class extends (/* @__PURE__ */ TaggedError("InternalError"))
2483
2948
  /**
2484
2949
  * Converts the server error into a `500 Internal Server Error` response.
2485
2950
  *
2951
+ * @stability unstable
2486
2952
  * @since 4.0.0
2487
2953
  */
2488
2954
  [symbol]() {
2489
- return succeed2(empty9({
2955
+ return succeed4(empty9({
2490
2956
  status: 500
2491
2957
  }));
2492
2958
  }
2493
2959
  get methodAndUrl() {
2494
- return `${this.request.method} ${this.request.url}`;
2960
+ return formatMethodAndUrl2(this.request);
2495
2961
  }
2496
2962
  get message() {
2497
2963
  return formatRequestMessage(this._tag, this.description, this.methodAndUrl);
@@ -2499,84 +2965,351 @@ var InternalError = class extends (/* @__PURE__ */ TaggedError("InternalError"))
2499
2965
  };
2500
2966
  var ResponseError = class extends (/* @__PURE__ */ TaggedError("ResponseError")) {
2501
2967
  [symbol]() {
2502
- return succeed2(empty9({
2968
+ return succeed4(empty9({
2503
2969
  status: 500
2504
2970
  }));
2505
2971
  }
2506
2972
  get methodAndUrl() {
2507
- return `${this.request.method} ${this.request.url}`;
2973
+ return formatMethodAndUrl2(this.request);
2508
2974
  }
2509
2975
  get message() {
2510
2976
  const info = `${this._tag} (${this.response.status} ${this.methodAndUrl})`;
2511
2977
  return this.description ? `${info}: ${this.description}` : info;
2512
2978
  }
2513
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)}`;
2514
2988
  var formatRequestMessage = (reason, description, info) => {
2515
2989
  const prefix = `${reason} (${info})`;
2516
2990
  return description ? `${prefix}: ${description}` : prefix;
2517
2991
  };
2518
-
2519
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/MultipartParser/internal/contentType.js
2520
- var paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\v\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u{10ffff}]|\\[\v\u0020-\u{10ffff}])*"|[!#$%&'*+.^\w`|~-]+) */gu;
2521
- var quotedPairRE = /\\([\v\u0020-\u{10ffff}])/gu;
2522
- var mediaTypeRE = /^[!#$%&'*+.^\w|~-]+\/[!#$%&'*+.^\w|~-]+$/u;
2523
- var mediaTypeRENoSlash = /^[!#$%&'*+.^\w|~-]+$/u;
2524
- var defaultContentType = {
2525
- value: "",
2526
- parameters: /* @__PURE__ */ Object.create(null)
2527
- };
2528
- function parse(header, withoutSlash = false) {
2529
- if (typeof header !== "string") {
2530
- return defaultContentType;
2531
- }
2532
- let index = header.indexOf(";");
2533
- const type = index !== -1 ? header.slice(0, index).trim() : header.trim();
2534
- const mediaRE = withoutSlash ? mediaTypeRENoSlash : mediaTypeRE;
2535
- if (mediaRE.test(type) === false) {
2536
- return defaultContentType;
2537
- }
2538
- const result = {
2539
- value: type.toLowerCase(),
2540
- parameters: /* @__PURE__ */ Object.create(null)
2541
- };
2542
- if (index === -1) {
2543
- return result;
2544
- }
2545
- let key;
2546
- let match2;
2547
- let value;
2548
- paramRE.lastIndex = index;
2549
- while (match2 = paramRE.exec(header)) {
2550
- if (match2.index !== index) {
2551
- 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;
2552
2998
  }
2553
- index += match2[0].length;
2554
- key = match2[1].toLowerCase();
2555
- value = match2[2];
2556
- if (value[0] === '"') {
2557
- value = value.slice(1, value.length - 1);
2558
- if (!withoutSlash && quotedPairRE.test(value)) {
2559
- 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;
2560
3020
  }
3021
+ return out;
2561
3022
  }
2562
- result.parameters[key] = value;
2563
3023
  }
2564
- if (index !== header.length) {
2565
- 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;
2566
3041
  }
2567
- return result;
2568
- }
2569
-
2570
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/MultipartParser/internal/headers.js
2571
- var constMaxPairs = 100;
2572
- var constMaxSize = 16 * 1024;
2573
- var State = {
2574
- key: 0,
2575
- whitespace: 1,
2576
- value: 2
2577
- };
2578
- var constContinue = {
2579
- _tag: "Continue"
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 = {
3312
+ _tag: "Continue"
2580
3313
  };
2581
3314
  var constNameChars = /* @__PURE__ */ new Uint8Array(256);
2582
3315
  for (const char of "!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") {
@@ -2613,12 +3346,6 @@ function make5() {
2613
3346
  state.size = 0;
2614
3347
  return value;
2615
3348
  }
2616
- function concatUint8Array(a, b) {
2617
- const newUint8Array = new Uint8Array(a.length + b.length);
2618
- newUint8Array.set(a);
2619
- newUint8Array.set(b, a.length);
2620
- return newUint8Array;
2621
- }
2622
3349
  function error(reason) {
2623
3350
  return reset({
2624
3351
  _tag: "Failure",
@@ -2632,11 +3359,8 @@ function make5() {
2632
3359
  if (state.previousChunk !== void 0) {
2633
3360
  endOffset = state.previousChunk.length;
2634
3361
  previousCursor = endOffset;
2635
- const newChunk = new Uint8Array(chunk.length + endOffset);
2636
- newChunk.set(state.previousChunk);
2637
- newChunk.set(chunk, endOffset);
3362
+ chunk = concat([state.previousChunk, chunk]);
2638
3363
  state.previousChunk = void 0;
2639
- chunk = newChunk;
2640
3364
  }
2641
3365
  const end = chunk.length;
2642
3366
  outer: while (start < end) {
@@ -2725,7 +3449,7 @@ function make5() {
2725
3449
  state.previousChunk = chunk.subarray(start);
2726
3450
  return constContinue;
2727
3451
  } else if (state.crlf >= 2) {
2728
- 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)]);
2729
3453
  const value = decoder.decode(state.value);
2730
3454
  if (state.headers[state.key] === void 0) {
2731
3455
  state.headers[state.key] = value;
@@ -2760,7 +3484,7 @@ function make5() {
2760
3484
  }
2761
3485
  }
2762
3486
  if (i === end) {
2763
- 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)]);
2764
3488
  return constContinue;
2765
3489
  }
2766
3490
  }
@@ -2772,7 +3496,7 @@ function make5() {
2772
3496
  };
2773
3497
  }
2774
3498
 
2775
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/MultipartParser/internal/search.js
3499
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/MultipartParser/internal/search.js
2776
3500
  function makeState(needle_) {
2777
3501
  const needle = new TextEncoder().encode(needle_);
2778
3502
  const needleLength = needle.length;
@@ -2892,7 +3616,7 @@ function make6(needle, callback2, seed, minimumChunkLength) {
2892
3616
  };
2893
3617
  }
2894
3618
 
2895
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/MultipartParser/internal/multipart.js
3619
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/MultipartParser/internal/multipart.js
2896
3620
  var State2 = {
2897
3621
  headers: 0,
2898
3622
  body: 1
@@ -2924,8 +3648,8 @@ function defaultIsFile(info) {
2924
3648
  return info.filename !== void 0 || info.contentType === "application/octet-stream";
2925
3649
  }
2926
3650
  function parseBoundary(headers) {
2927
- const contentType = parse(headers["content-type"]);
2928
- return contentType.parameters.boundary;
3651
+ const contentType2 = parse(headers["content-type"]);
3652
+ return contentType2.parameters.boundary;
2929
3653
  }
2930
3654
  function noopOnChunk(_chunk) {
2931
3655
  }
@@ -2997,18 +3721,7 @@ function make7({
2997
3721
  if (state.isFile) {
2998
3722
  state.onChunk(null);
2999
3723
  } else {
3000
- if (state.fieldChunks.length === 1) {
3001
- onField(state.info, state.fieldChunks[0]);
3002
- } else {
3003
- const buf = new Uint8Array(state.fieldSize);
3004
- let offset = 0;
3005
- for (let i = 0; i < state.fieldChunks.length; i++) {
3006
- const chunk2 = state.fieldChunks[i];
3007
- buf.set(chunk2, offset);
3008
- offset += chunk2.length;
3009
- }
3010
- onField(state.info, buf);
3011
- }
3724
+ onField(state.info, state.fieldChunks.length === 1 ? state.fieldChunks[0] : concat(state.fieldChunks));
3012
3725
  state.fieldSize = 0;
3013
3726
  state.fieldChunks = [];
3014
3727
  }
@@ -3041,28 +3754,17 @@ function make7({
3041
3754
  error: result
3042
3755
  });
3043
3756
  }
3044
- const contentType = parse(result.headers["content-type"]);
3045
- const contentDisposition = parse(result.headers["content-disposition"], true);
3046
- 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)) {
3047
3760
  skipBody();
3048
3761
  return onError(errInvalidDisposition);
3049
3762
  }
3050
- let encodedFilename;
3051
- if ("filename*" in contentDisposition.parameters) {
3052
- const parts = contentDisposition.parameters["filename*"].split("''");
3053
- if (parts.length === 2) {
3054
- try {
3055
- encodedFilename = decodeURIComponent(parts[1]);
3056
- } catch {
3057
- encodedFilename = parts[1];
3058
- }
3059
- }
3060
- }
3061
3763
  state.info = {
3062
3764
  name: contentDisposition.parameters.name ?? "",
3063
- filename: encodedFilename ?? contentDisposition.parameters.filename,
3064
- contentType: contentType.value === "" ? contentDisposition.parameters.filename !== void 0 ? "application/octet-stream" : "text/plain" : contentType.value,
3065
- 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,
3066
3768
  contentDisposition: contentDisposition.value,
3067
3769
  contentDispositionParameters: contentDisposition.parameters,
3068
3770
  headers: result.headers
@@ -3136,15 +3838,15 @@ function decodeField(info, value) {
3136
3838
  return getDecoder(info.contentTypeParameters.charset ?? "utf-8").decode(value);
3137
3839
  }
3138
3840
 
3139
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/MultipartParser.js
3841
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/MultipartParser.js
3140
3842
  var make8 = make7;
3141
3843
  var defaultIsFile2 = defaultIsFile;
3142
3844
  var decodeField2 = decodeField;
3143
3845
 
3144
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/Multipart.js
3145
- 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";
3146
3848
  var MultipartErrorTypeId = "~effect/http/Multipart/MultipartError";
3147
- var toMultipartError = (cause) => hasProperty(cause, MultipartErrorTypeId) ? cause : MultipartError.fromReason("InternalError", cause);
3849
+ var toMultipartError = (cause) => isMultipartError(cause) ? cause : MultipartError.fromReason("InternalError", cause);
3148
3850
  var MultipartErrorReason = class extends Error2 {
3149
3851
  };
3150
3852
  var responseStatusByReason = {
@@ -3159,6 +3861,7 @@ var MultipartError = class _MultipartError extends (/* @__PURE__ */ TaggedError(
3159
3861
  /**
3160
3862
  * Creates a multipart error from a reason tag and optional cause.
3161
3863
  *
3864
+ * @stability unstable
3162
3865
  * @since 4.0.0
3163
3866
  */
3164
3867
  static fromReason(reason, cause) {
@@ -3172,6 +3875,7 @@ var MultipartError = class _MultipartError extends (/* @__PURE__ */ TaggedError(
3172
3875
  /**
3173
3876
  * Marks this value as a multipart error for runtime guards.
3174
3877
  *
3878
+ * @stability unstable
3175
3879
  * @since 4.0.0
3176
3880
  */
3177
3881
  [MultipartErrorTypeId] = MultipartErrorTypeId;
@@ -3184,22 +3888,25 @@ var MultipartError = class _MultipartError extends (/* @__PURE__ */ TaggedError(
3184
3888
  * Parse errors produce `400`, size and part-count limits produce `413`, and
3185
3889
  * internal errors produce `500`.
3186
3890
  *
3891
+ * @stability unstable
3187
3892
  * @since 4.0.0
3188
3893
  */
3189
3894
  [symbol]() {
3190
- return succeed2(empty9({
3895
+ return succeed4(empty9({
3191
3896
  status: responseStatusByReason[this.reason._tag]
3192
3897
  }));
3193
3898
  }
3194
3899
  /**
3195
3900
  * Uses the concrete multipart error reason as the public message.
3196
3901
  *
3902
+ * @stability unstable
3197
3903
  * @since 4.0.0
3198
3904
  */
3199
3905
  get message() {
3200
3906
  return this.reason._tag;
3201
3907
  }
3202
3908
  };
3909
+ var isMultipartError = (u) => hasProperty(u, MultipartErrorTypeId);
3203
3910
  var schemaPersisted = (schema) => decodeUnknownEffect(schema);
3204
3911
  var schemaJson2 = (schema, options3) => {
3205
3912
  const fromJson = fromJsonString(schema, options3);
@@ -3209,7 +3916,7 @@ var schemaJson2 = (schema, options3) => {
3209
3916
  };
3210
3917
  var makeConfig = (headers) => withFiber((fiber) => {
3211
3918
  const mimeTypes = get(fiber.context, FieldMimeTypes);
3212
- return succeed2({
3919
+ return succeed4({
3213
3920
  headers,
3214
3921
  maxParts: fiber.getRef(MaxParts),
3215
3922
  maxFieldSize: fiber.getRef(MaxFieldSize),
@@ -3230,7 +3937,7 @@ var makeChannel = (headers) => fromTransform((upstream) => map(makeConfig(header
3230
3937
  onFile(info) {
3231
3938
  let chunks = [];
3232
3939
  let finished = false;
3233
- const pullChunks = fromPull(succeed2(suspend(function loop() {
3940
+ const pullChunks = fromPull(succeed4(suspend(function loop() {
3234
3941
  if (!isReadonlyArrayNonEmpty(chunks)) {
3235
3942
  if (finished) {
3236
3943
  return done();
@@ -3242,7 +3949,7 @@ var makeChannel = (headers) => fromTransform((upstream) => map(makeConfig(header
3242
3949
  }
3243
3950
  const chunk = chunks;
3244
3951
  chunks = [];
3245
- return succeed2(chunk);
3952
+ return succeed4(chunk);
3246
3953
  })));
3247
3954
  partsBuffer.push(new FileImpl(info, mapError2(pullChunks, toMultipartError)));
3248
3955
  return function(chunk) {
@@ -3278,7 +3985,7 @@ var makeChannel = (headers) => fromTransform((upstream) => map(makeConfig(header
3278
3985
  }
3279
3986
  return void_2;
3280
3987
  }));
3281
- return pump.pipe(flatMap(function loop() {
3988
+ return suspend(function loop() {
3282
3989
  if (!isReadonlyArrayNonEmpty(partsBuffer)) {
3283
3990
  if (isSome(exit2)) {
3284
3991
  return exit2.value;
@@ -3287,8 +3994,8 @@ var makeChannel = (headers) => fromTransform((upstream) => map(makeConfig(header
3287
3994
  }
3288
3995
  const parts = partsBuffer;
3289
3996
  partsBuffer = [];
3290
- return succeed2(parts);
3291
- }));
3997
+ return succeed4(parts);
3998
+ });
3292
3999
  }));
3293
4000
  function convertError(cause) {
3294
4001
  switch (cause._tag) {
@@ -3314,10 +4021,10 @@ function convertError(cause) {
3314
4021
  }
3315
4022
  }
3316
4023
  var PartBase = class extends Class {
3317
- [TypeId9];
4024
+ [TypeId10];
3318
4025
  constructor() {
3319
4026
  super();
3320
- this[TypeId9] = TypeId9;
4027
+ this[TypeId10] = TypeId10;
3321
4028
  }
3322
4029
  };
3323
4030
  var FieldImpl = class extends PartBase {
@@ -3325,10 +4032,10 @@ var FieldImpl = class extends PartBase {
3325
4032
  key;
3326
4033
  contentType;
3327
4034
  value;
3328
- constructor(key, contentType, value) {
4035
+ constructor(key, contentType2, value) {
3329
4036
  super();
3330
4037
  this.key = key;
3331
- this.contentType = contentType;
4038
+ this.contentType = contentType2;
3332
4039
  this.value = value;
3333
4040
  }
3334
4041
  toJSON() {
@@ -3367,6 +4074,19 @@ var FileImpl = class extends PartBase {
3367
4074
  }
3368
4075
  };
3369
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
+ };
3370
4090
  var toPersisted = (stream4, writeFile = defaultWriteFile) => gen(function* () {
3371
4091
  const fs = yield* FileSystem;
3372
4092
  const path_ = yield* Path;
@@ -3389,7 +4109,7 @@ var toPersisted = (stream4, writeFile = defaultWriteFile) => gen(function* () {
3389
4109
  return void_2;
3390
4110
  }
3391
4111
  const file3 = part;
3392
- const fileName = path_.basename(file3.name).slice(-128);
4112
+ const fileName = persistedFileName(path_.basename(file3.name));
3393
4113
  let path = path_.join(dir, fileName);
3394
4114
  while (usedPaths.has(path)) {
3395
4115
  path = path_.join(dir, `${fileIndex++}-${fileName}`);
@@ -3412,11 +4132,11 @@ var PersistedFileImpl = class extends PartBase {
3412
4132
  name;
3413
4133
  contentType;
3414
4134
  path;
3415
- constructor(key, name, contentType, path) {
4135
+ constructor(key, name, contentType2, path) {
3416
4136
  super();
3417
4137
  this.key = key;
3418
4138
  this.name = name;
3419
- this.contentType = contentType;
4139
+ this.contentType = contentType2;
3420
4140
  this.path = path;
3421
4141
  }
3422
4142
  toJSON() {
@@ -3443,13 +4163,13 @@ var FieldMimeTypes = /* @__PURE__ */ Reference("effect/http/Multipart/FieldMimeT
3443
4163
  defaultValue: /* @__PURE__ */ constant(["application/json"])
3444
4164
  });
3445
4165
 
3446
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpServerRequest.js
4166
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpServerRequest.js
3447
4167
  var HttpServerRequest_exports = {};
3448
4168
  __export(HttpServerRequest_exports, {
3449
4169
  HttpServerRequest: () => HttpServerRequest,
3450
4170
  MaxBodySize: () => MaxBodySize,
3451
4171
  ParsedSearchParams: () => ParsedSearchParams,
3452
- TypeId: () => TypeId10,
4172
+ TypeId: () => TypeId11,
3453
4173
  fromClientRequest: () => fromClientRequest,
3454
4174
  fromWeb: () => fromWeb4,
3455
4175
  schemaBodyForm: () => schemaBodyForm,
@@ -3468,191 +4188,29 @@ __export(HttpServerRequest_exports, {
3468
4188
  upgradeChannel: () => upgradeChannel
3469
4189
  });
3470
4190
 
3471
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/socket/Socket.js
3472
- var encoder2 = /* @__PURE__ */ new TextEncoder();
3473
- var readerBytes = (self) => map(self.reader, ({
3474
- pull
3475
- }) => map(pull, (chunk) => {
3476
- for (let i = 0; i < chunk.length; i++) {
3477
- if (typeof chunk[i] === "string") {
3478
- const out = new Array(chunk.length);
3479
- for (let j = 0; j < chunk.length; j++) {
3480
- const item = chunk[j];
3481
- out[j] = typeof item === "string" ? encoder2.encode(item) : item;
3482
- }
3483
- return out;
3484
- }
3485
- }
3486
- return chunk;
3487
- }));
3488
- var CloseEventTypeId = "~effect/socket/Socket/CloseEvent";
3489
- var CloseEvent = class {
3490
- /**
3491
- * Marks this value as a socket close event for runtime guards.
3492
- *
3493
- * @since 4.0.0
3494
- */
3495
- [CloseEventTypeId];
3496
- code;
3497
- reason;
3498
- constructor(code = 1e3, reason) {
3499
- this[CloseEventTypeId] = CloseEventTypeId;
3500
- this.code = code;
3501
- this.reason = reason;
3502
- }
3503
- /**
3504
- * Formats the close code and optional reason for display.
3505
- *
3506
- * @since 4.0.0
3507
- */
3508
- toString() {
3509
- return this.reason ? `${this.code}: ${this.reason}` : `${this.code}`;
3510
- }
3511
- };
3512
- var isCloseEvent = (u) => hasProperty(u, CloseEventTypeId);
3513
- var SocketErrorTypeId = "~effect/socket/Socket/SocketError";
3514
- var isSocketError = (u) => hasProperty(u, SocketErrorTypeId);
3515
- var SocketReadError = class extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketReadError")({
3516
- _tag: /* @__PURE__ */ tag("SocketReadError"),
3517
- cause: /* @__PURE__ */ Defect()
3518
- })) {
3519
- /**
3520
- * Default message used for socket read failures.
3521
- *
3522
- * @since 4.0.0
3523
- */
3524
- message = `An error occurred during Read`;
3525
- };
3526
- var SocketWriteError = class extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketWriteError")({
3527
- _tag: /* @__PURE__ */ tag("SocketWriteError"),
3528
- cause: /* @__PURE__ */ Defect()
3529
- })) {
3530
- /**
3531
- * Default message used for socket write failures.
3532
- *
3533
- * @since 4.0.0
3534
- */
3535
- message = `An error occurred during Write`;
3536
- };
3537
- var SocketOpenError = class extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketOpenError")({
3538
- _tag: /* @__PURE__ */ tag("SocketOpenError"),
3539
- kind: /* @__PURE__ */ Literals(["Unknown", "Timeout"]),
3540
- cause: /* @__PURE__ */ Defect()
3541
- })) {
3542
- /**
3543
- * Formats timeout and unknown open failures for display.
3544
- *
3545
- * @since 4.0.0
3546
- */
3547
- get message() {
3548
- return this.kind === "Timeout" ? `timeout waiting for "open"` : `An error occurred during Open`;
3549
- }
3550
- };
3551
- var SocketUpgradeError = class _SocketUpgradeError extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketUpgradeError")({
3552
- _tag: /* @__PURE__ */ tag("SocketUpgradeError"),
3553
- cause: /* @__PURE__ */ optional(/* @__PURE__ */ Defect())
3554
- })) {
3555
- /**
3556
- * An upgrade implementation for transports that cannot wrap the connection
3557
- * with TLS.
3558
- *
3559
- * @since 4.0.0
3560
- */
3561
- static unsupported = () => fail3(new SocketError({
3562
- reason: new _SocketUpgradeError({})
3563
- }));
3564
- get message() {
3565
- return this.cause === void 0 ? `Socket does not support TLS upgrade` : `An error occurred during TLS upgrade`;
3566
- }
3567
- };
3568
- var SocketCloseError = class extends (/* @__PURE__ */ Error3("effect/socket/Socket/SocketCloseError")({
3569
- _tag: /* @__PURE__ */ tag("SocketCloseError"),
3570
- code: Int,
3571
- closeReason: /* @__PURE__ */ optional(String2)
3572
- })) {
3573
- get message() {
3574
- if (this.closeReason) {
3575
- return `${this.code}: ${this.closeReason}`;
3576
- }
3577
- return `${this.code}`;
3578
- }
3579
- };
3580
- var SocketErrorReason = /* @__PURE__ */ Union([SocketReadError, SocketWriteError, SocketOpenError, SocketUpgradeError, SocketCloseError]);
3581
- var SocketError = class extends (/* @__PURE__ */ TaggedError2(SocketErrorTypeId)("SocketError", {
3582
- _tag: /* @__PURE__ */ tag("SocketError"),
3583
- reason: SocketErrorReason
3584
- })) {
3585
- // @effect-diagnostics-next-line overriddenSchemaConstructor:off
3586
- constructor(props) {
3587
- if ("cause" in props.reason) {
3588
- super({
3589
- ...props,
3590
- cause: props.reason.cause
3591
- });
3592
- } else {
3593
- super(props);
3594
- }
3595
- }
3596
- /**
3597
- * Marks this value as a socket error wrapper for runtime guards.
3598
- *
3599
- * @since 4.0.0
3600
- */
3601
- [SocketErrorTypeId] = SocketErrorTypeId;
3602
- /**
3603
- * Returns `true` when the value is a `SocketError`.
3604
- *
3605
- * @since 4.0.0
3606
- */
3607
- static is(u) {
3608
- return isSocketError(u);
3609
- }
3610
- message = this.reason.message;
3611
- };
3612
- var writeChunk = (writer, chunk) => {
3613
- for (let i = 0; i < chunk.length; i++) {
3614
- if (isCloseEvent(chunk[i])) {
3615
- return gen(function* () {
3616
- for (let index = 0; index <= i; index++) {
3617
- yield* writer.write(chunk[index]);
3618
- }
3619
- });
3620
- }
3621
- }
3622
- return writer.writeAll(chunk);
3623
- };
3624
- var toChannelWithReader = (self, reader) => fromTransform(fnUntraced(function* (upstream, scope2) {
3625
- const readScope = yield* fork(scope2);
3626
- const pull = yield* provide(reader, readScope);
3627
- const writeScope = yield* fork(scope2);
3628
- const writer = yield* provide(self.writer, writeScope);
3629
- let writeFailure;
3630
- yield* upstream.pipe(flatMap((chunk) => writeChunk(writer, chunk)), forever({
3631
- disableYield: true
3632
- }), catchCauseFilter(filterNoDone, (cause) => suspend(() => {
3633
- writeFailure = cause;
3634
- return close(readScope, void_);
3635
- })), ensuring(close(writeScope, void_)), forkIn(scope2));
3636
- return catchCause(suspend(() => writeFailure !== void 0 ? failCause2(writeFailure) : pull), (cause) => failCause2(writeFailure ?? cause));
3637
- }));
3638
- var toChannel = (self) => toChannelWithReader(self, readerBytes(self));
3639
- var toChannelWith = () => (self) => toChannel(self);
3640
- var defaultHighWaterMark = 64 * 1024;
3641
-
3642
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpServerRequest.js
3643
- var TypeId10 = "~effect/http/HttpServerRequest";
3644
- var HttpServerRequest = /* @__PURE__ */ Service("effect/http/HttpServerRequest");
3645
- var ParsedSearchParams = class extends (/* @__PURE__ */ Service()("effect/http/ParsedSearchParams")) {
3646
- };
3647
- var searchParamsFromURL = (url) => {
3648
- const out = {};
3649
- for (const [key, value] of url.searchParams.entries()) {
3650
- if (Object.hasOwn(out, key)) {
3651
- const entry = out[key];
3652
- if (Array.isArray(entry)) {
3653
- entry.push(value);
3654
- } else {
3655
- assignProperty(out, key, [entry, value]);
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;
4197
+ }));
4198
+ })));
4199
+
4200
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpServerRequest.js
4201
+ var TypeId11 = "~effect/http/HttpServerRequest";
4202
+ var HttpServerRequest = /* @__PURE__ */ Service("effect/http/HttpServerRequest");
4203
+ var ParsedSearchParams = class extends (/* @__PURE__ */ Service()("effect/http/ParsedSearchParams")) {
4204
+ };
4205
+ var searchParamsFromURL = (url) => {
4206
+ const out = {};
4207
+ for (const [key, value] of url.searchParams.entries()) {
4208
+ if (Object.hasOwn(out, key)) {
4209
+ const entry = out[key];
4210
+ if (Array.isArray(entry)) {
4211
+ entry.push(value);
4212
+ } else {
4213
+ assignProperty(out, key, [entry, value]);
3656
4214
  }
3657
4215
  } else {
3658
4216
  assignProperty(out, key, value);
@@ -3660,7 +4218,7 @@ var searchParamsFromURL = (url) => {
3660
4218
  }
3661
4219
  return out;
3662
4220
  };
3663
- var upgradeChannel = () => HttpServerRequest.pipe(flatMap((_) => _.upgrade), map(toChannelWith()), unwrap);
4221
+ var upgradeChannel = () => HttpServerRequest.pipe(flatMap((_) => _.upgrade), map(toChannelWith()), unwrap2);
3664
4222
  var schemaCookies = (schema, options3) => {
3665
4223
  const parse2 = decodeUnknownEffect(schema);
3666
4224
  return flatMap(HttpServerRequest, (req) => parse2(req.cookies, options3));
@@ -3741,30 +4299,34 @@ var removeHost = (url) => {
3741
4299
  return index === -1 ? "/" : url.slice(index);
3742
4300
  };
3743
4301
  var ServerRequestImpl = class _ServerRequestImpl extends Class {
3744
- [TypeId10];
4302
+ [TypeId11];
3745
4303
  [TypeId4];
3746
4304
  source;
3747
4305
  url;
3748
4306
  headersOverride;
3749
4307
  remoteAddressOverride;
3750
- constructor(source, url, headersOverride, remoteAddressOverride) {
4308
+ peerAddressOverride;
4309
+ protocol;
4310
+ constructor(source, url, headersOverride, remoteAddressOverride, peerAddressOverride, protocol) {
3751
4311
  super();
3752
- this[TypeId10] = TypeId10;
4312
+ this[TypeId11] = TypeId11;
3753
4313
  this[TypeId4] = TypeId4;
3754
4314
  this.source = source;
3755
4315
  this.url = url;
3756
4316
  this.headersOverride = headersOverride;
3757
4317
  this.remoteAddressOverride = remoteAddressOverride;
4318
+ this.peerAddressOverride = peerAddressOverride;
4319
+ this.protocol = protocol;
3758
4320
  }
3759
4321
  toJSON() {
3760
4322
  return inspect(this, {
3761
4323
  _id: "HttpServerRequest",
3762
4324
  method: this.method,
3763
- url: this.originalUrl
4325
+ url: redactUrl(this.originalUrl)
3764
4326
  });
3765
4327
  }
3766
4328
  modify(options3) {
3767
- 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);
3768
4330
  }
3769
4331
  get method() {
3770
4332
  return this.source.method.toUpperCase();
@@ -3775,6 +4337,9 @@ var ServerRequestImpl = class _ServerRequestImpl extends Class {
3775
4337
  get remoteAddress() {
3776
4338
  return this.remoteAddressOverride ?? none();
3777
4339
  }
4340
+ get peerAddress() {
4341
+ return this.peerAddressOverride ?? this.remoteAddress;
4342
+ }
3778
4343
  get headers() {
3779
4344
  this.headersOverride ??= fromInput2(this.source.headers);
3780
4345
  return this.headersOverride;
@@ -3787,36 +4352,11 @@ var ServerRequestImpl = class _ServerRequestImpl extends Class {
3787
4352
  return this.cachedCookies = parseHeader(this.headers.cookie ?? "");
3788
4353
  }
3789
4354
  get stream() {
3790
- return this.source.body ? fromReadableStream({
3791
- evaluate: () => this.source.body,
3792
- onError: (cause) => new HttpServerError({
3793
- reason: new RequestParseError({
3794
- request: this,
3795
- cause
3796
- })
3797
- })
3798
- }) : fail4(new HttpServerError({
3799
- reason: new RequestParseError({
3800
- request: this,
3801
- description: "can not create stream from empty body"
3802
- })
3803
- }));
4355
+ return streamFromReadable(this, this.source.body);
3804
4356
  }
3805
4357
  textEffect;
3806
4358
  get text() {
3807
- if (this.textEffect) {
3808
- return this.textEffect;
3809
- }
3810
- this.textEffect = runSync(cached(tryPromise({
3811
- try: () => this.source.text(),
3812
- catch: (cause) => new HttpServerError({
3813
- reason: new RequestParseError({
3814
- request: this,
3815
- cause
3816
- })
3817
- })
3818
- })));
3819
- return this.textEffect;
4359
+ return this.textEffect ??= map(this.arrayBuffer, (buffer2) => textDecoder2.decode(buffer2));
3820
4360
  }
3821
4361
  get json() {
3822
4362
  return flatMap(this.text, (text3) => try_2({
@@ -3830,8 +4370,8 @@ var ServerRequestImpl = class _ServerRequestImpl extends Class {
3830
4370
  }));
3831
4371
  }
3832
4372
  get urlParamsBody() {
3833
- return flatMap(this.text, (_) => try_2({
3834
- try: () => fromInput3(new URLSearchParams(_)),
4373
+ return flatMap(this.arrayBuffer, (bytes) => try_2({
4374
+ try: () => fromInput3(fromBody(bytes)),
3835
4375
  catch: (cause) => new HttpServerError({
3836
4376
  reason: new RequestParseError({
3837
4377
  request: this,
@@ -3856,18 +4396,25 @@ var ServerRequestImpl = class _ServerRequestImpl extends Class {
3856
4396
  if (this.arrayBufferEffect) {
3857
4397
  return this.arrayBufferEffect;
3858
4398
  }
3859
- this.arrayBufferEffect = runSync(cached(tryPromise({
3860
- try: () => this.source.arrayBuffer(),
3861
- catch: (cause) => new HttpServerError({
3862
- reason: new RequestParseError({
3863
- request: this,
3864
- 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
+ })
3865
4409
  })
3866
- })
3867
- })));
4410
+ });
4411
+ }).pipe(cached, runSync);
3868
4412
  return this.arrayBufferEffect;
3869
4413
  }
3870
4414
  get upgrade() {
4415
+ return this.upgradeWith({});
4416
+ }
4417
+ upgradeWith(_options) {
3871
4418
  return fail3(new HttpServerError({
3872
4419
  reason: new RequestParseError({
3873
4420
  request: this,
@@ -3877,32 +4424,36 @@ var ServerRequestImpl = class _ServerRequestImpl extends Class {
3877
4424
  }
3878
4425
  };
3879
4426
  var ClientRequestImpl = class _ClientRequestImpl extends Class {
3880
- [TypeId10];
4427
+ [TypeId11];
3881
4428
  [TypeId4];
3882
4429
  source;
3883
4430
  originalUrl;
3884
4431
  headersOverride;
3885
4432
  remoteAddressOverride;
4433
+ peerAddressOverride;
4434
+ protocol;
3886
4435
  urlOverride;
3887
- constructor(source, originalUrl, urlOverride, headersOverride, remoteAddressOverride) {
4436
+ constructor(source, originalUrl, urlOverride, headersOverride, remoteAddressOverride, peerAddressOverride, protocol) {
3888
4437
  super();
3889
- this[TypeId10] = TypeId10;
4438
+ this[TypeId11] = TypeId11;
3890
4439
  this[TypeId4] = TypeId4;
3891
4440
  this.source = source;
3892
4441
  this.originalUrl = originalUrl;
3893
4442
  this.urlOverride = urlOverride;
3894
4443
  this.headersOverride = headersOverride;
3895
4444
  this.remoteAddressOverride = remoteAddressOverride;
4445
+ this.peerAddressOverride = peerAddressOverride;
4446
+ this.protocol = protocol;
3896
4447
  }
3897
4448
  toJSON() {
3898
4449
  return inspect(this, {
3899
4450
  _id: "HttpServerRequest",
3900
4451
  method: this.method,
3901
- url: this.originalUrl
4452
+ url: redactUrl(this.originalUrl)
3902
4453
  });
3903
4454
  }
3904
4455
  modify(options3) {
3905
- 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);
3906
4457
  }
3907
4458
  get method() {
3908
4459
  return this.source.method;
@@ -3913,6 +4464,9 @@ var ClientRequestImpl = class _ClientRequestImpl extends Class {
3913
4464
  get remoteAddress() {
3914
4465
  return this.remoteAddressOverride ?? none();
3915
4466
  }
4467
+ get peerAddress() {
4468
+ return this.peerAddressOverride ?? this.remoteAddress;
4469
+ }
3916
4470
  get headers() {
3917
4471
  return this.headersOverride ??= this.source.headers;
3918
4472
  }
@@ -3930,7 +4484,7 @@ var ClientRequestImpl = class _ClientRequestImpl extends Class {
3930
4484
  return empty6;
3931
4485
  }
3932
4486
  case "Uint8Array": {
3933
- return succeed3(body.body);
4487
+ return succeed5(body.body);
3934
4488
  }
3935
4489
  case "Stream": {
3936
4490
  return mapError3(body.stream, (cause) => requestParseError(this, void 0, cause));
@@ -3948,32 +4502,31 @@ var ClientRequestImpl = class _ClientRequestImpl extends Class {
3948
4502
  if (this.bytesEffect) {
3949
4503
  return this.bytesEffect;
3950
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) {
3951
4512
  const body = this.source.body;
3952
- let effect2;
3953
4513
  switch (body._tag) {
3954
4514
  case "Empty": {
3955
- effect2 = succeed2(new Uint8Array(0));
3956
- break;
4515
+ return succeed4(new Uint8Array(0));
3957
4516
  }
3958
4517
  case "Uint8Array": {
3959
- effect2 = succeed2(body.body);
3960
- break;
4518
+ return maxBytes !== void 0 && body.body.byteLength > maxBytes ? fail3(bodyTooLargeError(this, new BodyTooLargeError(maxBytes))) : succeed4(body.body);
3961
4519
  }
3962
4520
  case "FormData": {
3963
- effect2 = bytesFromBodyInit(this, body.formData);
3964
- break;
4521
+ return bytesFromWeb(this, () => new Response(body.formData), maxBytes);
3965
4522
  }
3966
4523
  case "Stream": {
3967
- effect2 = mkUint8Array2(this.stream);
3968
- break;
4524
+ return mkUint8Array2(maxBytes === void 0 ? this.stream : limitStream(this, this.stream, maxBytes));
3969
4525
  }
3970
4526
  case "Raw": {
3971
- effect2 = rawBodyBytes(this, body.body);
3972
- break;
4527
+ return rawBodyBytes(this, body.body, maxBytes);
3973
4528
  }
3974
4529
  }
3975
- this.bytesEffect = runSync(cached(effect2));
3976
- return this.bytesEffect;
3977
4530
  }
3978
4531
  get text() {
3979
4532
  return map(this.bytes, (bytes) => textDecoder2.decode(bytes));
@@ -3985,8 +4538,8 @@ var ClientRequestImpl = class _ClientRequestImpl extends Class {
3985
4538
  }));
3986
4539
  }
3987
4540
  get urlParamsBody() {
3988
- return flatMap(this.text, (_) => try_2({
3989
- try: () => fromInput3(new URLSearchParams(_)),
4541
+ return flatMap(this.bytes, (bytes) => try_2({
4542
+ try: () => fromInput3(fromBody(bytes)),
3990
4543
  catch: (cause) => requestParseError(this, void 0, cause)
3991
4544
  }));
3992
4545
  }
@@ -4013,6 +4566,9 @@ var ClientRequestImpl = class _ClientRequestImpl extends Class {
4013
4566
  );
4014
4567
  }
4015
4568
  get upgrade() {
4569
+ return this.upgradeWith({});
4570
+ }
4571
+ upgradeWith(_options) {
4016
4572
  return fail3(requestParseError(this, "Not an upgradeable ServerRequest"));
4017
4573
  }
4018
4574
  };
@@ -4041,21 +4597,22 @@ var rawBodyStream = (request, body) => {
4041
4597
  }
4042
4598
  return fail4(requestParseError(request, "Unsupported body type"));
4043
4599
  };
4044
- var rawBodyBytes = (request, body) => {
4600
+ var rawBodyBytes = (request, body, maxBytes) => {
4045
4601
  if (body instanceof Request) {
4046
- return tryPromise({
4047
- try: () => body.arrayBuffer().then((buffer2) => new Uint8Array(buffer2)),
4048
- catch: (cause) => requestParseError(request, void 0, cause)
4049
- });
4602
+ return bytesFromWeb(request, () => body, maxBytes);
4050
4603
  }
4051
4604
  if (isBodyInit(body)) {
4052
- return bytesFromBodyInit(request, body);
4605
+ return bytesFromWeb(request, () => new Response(body), maxBytes);
4053
4606
  }
4054
4607
  return fail3(requestParseError(request, "Unsupported body type"));
4055
4608
  };
4056
- var bytesFromBodyInit = (request, body) => tryPromise({
4057
- try: () => new Response(body).arrayBuffer().then((buffer2) => new Uint8Array(buffer2)),
4058
- 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)
4059
4616
  });
4060
4617
  var streamFromReadable = (request, body) => body ? fromReadableStream({
4061
4618
  evaluate: () => body,
@@ -4072,6 +4629,20 @@ var requestParseError = (request, description, cause) => new HttpServerError({
4072
4629
  }
4073
4630
  })
4074
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
+ });
4075
4646
  var formDataToParts = (formData3) => {
4076
4647
  const parts = [];
4077
4648
  for (const [key, value] of formData3.entries()) {
@@ -4080,14 +4651,14 @@ var formDataToParts = (formData3) => {
4080
4651
  return parts;
4081
4652
  };
4082
4653
  var MultipartFieldPart = class extends Class {
4083
- [TypeId9];
4654
+ [TypeId10];
4084
4655
  _tag = "Field";
4085
4656
  contentType = "text/plain";
4086
4657
  key;
4087
4658
  value;
4088
4659
  constructor(key, value) {
4089
4660
  super();
4090
- this[TypeId9] = TypeId9;
4661
+ this[TypeId10] = TypeId10;
4091
4662
  this.key = key;
4092
4663
  this.value = value;
4093
4664
  }
@@ -4102,7 +4673,7 @@ var MultipartFieldPart = class extends Class {
4102
4673
  }
4103
4674
  };
4104
4675
  var MultipartFilePart = class extends Class {
4105
- [TypeId9];
4676
+ [TypeId10];
4106
4677
  _tag = "File";
4107
4678
  key;
4108
4679
  name;
@@ -4111,7 +4682,7 @@ var MultipartFilePart = class extends Class {
4111
4682
  contentEffect;
4112
4683
  constructor(key, file3) {
4113
4684
  super();
4114
- this[TypeId9] = TypeId9;
4685
+ this[TypeId10] = TypeId10;
4115
4686
  this.key = key;
4116
4687
  this.name = file3.name;
4117
4688
  this.contentType = file3.type;
@@ -4138,11 +4709,62 @@ var isReadableStream3 = (u) => typeof ReadableStream !== "undefined" && u instan
4138
4709
  var isFormData = (u) => typeof FormData !== "undefined" && u instanceof FormData;
4139
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);
4140
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
+ };
4141
4763
  var toURL = (self) => {
4142
4764
  const host = self.headers.host ?? "localhost";
4143
- const protocol = self.headers["x-forwarded-proto"] === "https" ? "https" : "http";
4765
+ const protocol = self.protocol ?? (/^https:/i.test(self.originalUrl) ? "https" : "http");
4144
4766
  try {
4145
- return some(new URL(self.url, `${protocol}://${host}`));
4767
+ return some(new URL(self.url.startsWith("/") ? `.${self.url}` : self.url, `${protocol}://${host}`));
4146
4768
  } catch {
4147
4769
  return none();
4148
4770
  }
@@ -4166,7 +4788,11 @@ var toWebResult2 = (self, options3) => {
4166
4788
  requestInit.signal = options3.signal;
4167
4789
  }
4168
4790
  if (hasBody(self.method)) {
4169
- requestInit.body = toReadableStreamWith(self.stream, options3?.context ?? empty2());
4791
+ requestInit.body = toReadableStreamWith(openOnFirstPull(self.stream), options3?.context ?? empty(), {
4792
+ strategy: {
4793
+ highWaterMark: 0
4794
+ }
4795
+ });
4170
4796
  requestInit.duplex = "half";
4171
4797
  }
4172
4798
  return succeed(new Request(url.value, requestInit));
@@ -4176,15 +4802,557 @@ var toWeb3 = (self, options3) => contextWith((context2) => fromResult(toWebResul
4176
4802
  signal: options3?.signal
4177
4803
  })));
4178
4804
 
4179
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpMiddleware.js
4180
- 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;
4181
4983
  var withLoggerDisabled = (self) => withFiber((fiber) => {
4182
- const request = getUnsafe(fiber.context, HttpServerRequest);
4183
- loggerDisabledRequests.add(request.source);
4984
+ const state = getOrUndefined2(fiber.context, CurrentRequestState);
4985
+ if (state !== void 0) state.loggerDisabled = true;
4184
4986
  return self;
4185
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;
4186
5335
 
4187
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/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
4188
5356
  var HttpRouter = /* @__PURE__ */ Service("effect/http/HttpRouter");
4189
5357
  var removeTrailingSlash = (path) => path.endsWith("/") ? path.slice(0, -1) : path;
4190
5358
  var prefixPath = /* @__PURE__ */ dual(2, (self, prefix) => {
@@ -4238,7 +5406,7 @@ var middlewareCache = /* @__PURE__ */ new WeakMap();
4238
5406
  var getMiddleware = (context2) => {
4239
5407
  let arr = middlewareCache.get(context2);
4240
5408
  if (arr) return arr;
4241
- const topLevel = empty();
5409
+ const topLevel = empty2();
4242
5410
  let maxLength = 0;
4243
5411
  for (const [key, value] of context2.mapUnsafe) {
4244
5412
  if (key.startsWith("effect/http/HttpRouter/Middleware-")) {
@@ -4266,7 +5434,7 @@ var getMiddleware = (context2) => {
4266
5434
  };
4267
5435
  var disableLogger = middleware(withLoggerDisabled).layer;
4268
5436
 
4269
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/http/HttpStatus.js
5437
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/http/HttpStatus.js
4270
5438
  var codeByLiteral = {
4271
5439
  Continue: 100,
4272
5440
  SwitchingProtocols: 101,
@@ -4333,16 +5501,23 @@ var codeByLiteral = {
4333
5501
  };
4334
5502
  var fromLiteral = (literal) => codeByLiteral[literal];
4335
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
+
4336
5510
  export {
4337
5511
  isHttpBody,
4338
5512
  uint8Array,
4339
5513
  text,
4340
- jsonUnsafe,
4341
5514
  urlParams,
5515
+ stream,
4342
5516
  HttpBody_exports,
4343
5517
  isHttpClientError,
4344
5518
  HttpClientError,
4345
5519
  TransportError,
5520
+ EncodeError,
4346
5521
  StatusCodeError,
4347
5522
  DecodeError,
4348
5523
  HttpClientError_exports,
@@ -4351,10 +5526,12 @@ export {
4351
5526
  get4 as get,
4352
5527
  post,
4353
5528
  setHeaders,
5529
+ upgrade,
4354
5530
  setUrl,
4355
5531
  prependUrl,
4356
5532
  appendUrlParams,
4357
5533
  setBody,
5534
+ compressBody2 as compressBody,
4358
5535
  bodyFormData,
4359
5536
  HttpClientRequest_exports,
4360
5537
  fromWeb2 as fromWeb,
@@ -4365,11 +5542,19 @@ export {
4365
5542
  make3 as make2,
4366
5543
  mapRequest,
4367
5544
  retryTransient,
5545
+ tap2 as tap,
5546
+ tapError2 as tapError,
4368
5547
  TracerPropagationEnabled,
4369
5548
  layerMergedContext,
4370
5549
  HttpClient_exports,
5550
+ getClosingParenthensePosition,
4371
5551
  HttpServerResponse_exports,
5552
+ isSocket,
4372
5553
  HttpServerRequest_exports,
5554
+ HttpMiddleware_exports,
4373
5555
  prefixPath,
4374
- fromLiteral
5556
+ fromLiteral,
5557
+ contentType,
5558
+ blankType,
5559
+ fixedMember
4375
5560
  };