@effect/platform-bun 4.0.1 → 4.0.3

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 (128) hide show
  1. package/ai-docs/package.json +2 -2
  2. package/ai-docs/tsconfig.json +2 -1
  3. package/dist/BunAddressResolver.d.ts +15 -0
  4. package/dist/BunAddressResolver.d.ts.map +1 -0
  5. package/dist/BunAddressResolver.js +15 -0
  6. package/dist/BunAddressResolver.js.map +1 -0
  7. package/dist/BunChildProcessSpawner.d.ts +1 -0
  8. package/dist/BunChildProcessSpawner.d.ts.map +1 -1
  9. package/dist/BunChildProcessSpawner.js +1 -0
  10. package/dist/BunChildProcessSpawner.js.map +1 -1
  11. package/dist/BunClusterHttp.d.ts +3 -0
  12. package/dist/BunClusterHttp.d.ts.map +1 -1
  13. package/dist/BunClusterHttp.js +4 -0
  14. package/dist/BunClusterHttp.js.map +1 -1
  15. package/dist/BunClusterSocket.d.ts +5 -0
  16. package/dist/BunClusterSocket.d.ts.map +1 -1
  17. package/dist/BunClusterSocket.js +5 -0
  18. package/dist/BunClusterSocket.js.map +1 -1
  19. package/dist/BunCrypto.d.ts +1 -0
  20. package/dist/BunCrypto.d.ts.map +1 -1
  21. package/dist/BunCrypto.js +2 -0
  22. package/dist/BunCrypto.js.map +1 -1
  23. package/dist/BunDatagramSocket.d.ts +227 -0
  24. package/dist/BunDatagramSocket.d.ts.map +1 -0
  25. package/dist/BunDatagramSocket.js +502 -0
  26. package/dist/BunDatagramSocket.js.map +1 -0
  27. package/dist/BunDns.d.ts +72 -0
  28. package/dist/BunDns.d.ts.map +1 -0
  29. package/dist/BunDns.js +66 -0
  30. package/dist/BunDns.js.map +1 -0
  31. package/dist/BunFileSystem.d.ts +1 -0
  32. package/dist/BunFileSystem.d.ts.map +1 -1
  33. package/dist/BunFileSystem.js +2 -0
  34. package/dist/BunFileSystem.js.map +1 -1
  35. package/dist/BunHttpClient.d.ts +1 -0
  36. package/dist/BunHttpClient.d.ts.map +1 -1
  37. package/dist/BunHttpClient.js +1 -0
  38. package/dist/BunHttpClient.js.map +1 -1
  39. package/dist/BunHttpPlatform.d.ts +1 -0
  40. package/dist/BunHttpPlatform.d.ts.map +1 -1
  41. package/dist/BunHttpPlatform.js +2 -0
  42. package/dist/BunHttpPlatform.js.map +1 -1
  43. package/dist/BunHttpServer.d.ts +10 -1
  44. package/dist/BunHttpServer.d.ts.map +1 -1
  45. package/dist/BunHttpServer.js +16 -2
  46. package/dist/BunHttpServer.js.map +1 -1
  47. package/dist/BunHttpServerRequest.d.ts +2 -0
  48. package/dist/BunHttpServerRequest.d.ts.map +1 -1
  49. package/dist/BunHttpServerRequest.js +1 -0
  50. package/dist/BunHttpServerRequest.js.map +1 -1
  51. package/dist/BunMultipart.d.ts +3 -0
  52. package/dist/BunMultipart.d.ts.map +1 -1
  53. package/dist/BunMultipart.js +2 -0
  54. package/dist/BunMultipart.js.map +1 -1
  55. package/dist/BunPath.d.ts +3 -0
  56. package/dist/BunPath.d.ts.map +1 -1
  57. package/dist/BunPath.js +4 -0
  58. package/dist/BunPath.js.map +1 -1
  59. package/dist/BunRuntime.d.ts +3 -0
  60. package/dist/BunRuntime.d.ts.map +1 -1
  61. package/dist/BunRuntime.js +2 -0
  62. package/dist/BunRuntime.js.map +1 -1
  63. package/dist/BunServices.d.ts +3 -0
  64. package/dist/BunServices.d.ts.map +1 -1
  65. package/dist/BunServices.js +1 -0
  66. package/dist/BunServices.js.map +1 -1
  67. package/dist/BunSink.d.ts +1 -0
  68. package/dist/BunSink.d.ts.map +1 -1
  69. package/dist/BunSink.js +1 -0
  70. package/dist/BunSink.js.map +1 -1
  71. package/dist/BunSocket.d.ts +7 -2
  72. package/dist/BunSocket.d.ts.map +1 -1
  73. package/dist/BunSocket.js +18 -6
  74. package/dist/BunSocket.js.map +1 -1
  75. package/dist/BunSocketServer.d.ts +1 -0
  76. package/dist/BunSocketServer.d.ts.map +1 -1
  77. package/dist/BunSocketServer.js +1 -0
  78. package/dist/BunSocketServer.js.map +1 -1
  79. package/dist/BunStdio.d.ts +1 -0
  80. package/dist/BunStdio.d.ts.map +1 -1
  81. package/dist/BunStdio.js +2 -0
  82. package/dist/BunStdio.js.map +1 -1
  83. package/dist/BunStream.d.ts +1 -0
  84. package/dist/BunStream.d.ts.map +1 -1
  85. package/dist/BunStream.js +2 -0
  86. package/dist/BunStream.js.map +1 -1
  87. package/dist/BunTerminal.d.ts +6 -3
  88. package/dist/BunTerminal.d.ts.map +1 -1
  89. package/dist/BunTerminal.js +7 -3
  90. package/dist/BunTerminal.js.map +1 -1
  91. package/dist/BunWorker.d.ts +2 -0
  92. package/dist/BunWorker.d.ts.map +1 -1
  93. package/dist/BunWorker.js +3 -0
  94. package/dist/BunWorker.js.map +1 -1
  95. package/dist/BunWorkerRunner.d.ts +1 -0
  96. package/dist/BunWorkerRunner.d.ts.map +1 -1
  97. package/dist/BunWorkerRunner.js +2 -1
  98. package/dist/BunWorkerRunner.js.map +1 -1
  99. package/dist/index.d.ts +37 -0
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +37 -0
  102. package/dist/index.js.map +1 -1
  103. package/package.json +7 -5
  104. package/src/BunAddressResolver.ts +15 -0
  105. package/src/BunChildProcessSpawner.ts +1 -0
  106. package/src/BunClusterHttp.ts +4 -0
  107. package/src/BunClusterSocket.ts +5 -0
  108. package/src/BunCrypto.ts +2 -0
  109. package/src/BunDatagramSocket.ts +666 -0
  110. package/src/BunDns.ts +82 -0
  111. package/src/BunFileSystem.ts +2 -0
  112. package/src/BunHttpClient.ts +1 -0
  113. package/src/BunHttpPlatform.ts +2 -0
  114. package/src/BunHttpServer.ts +19 -1
  115. package/src/BunHttpServerRequest.ts +2 -0
  116. package/src/BunMultipart.ts +3 -0
  117. package/src/BunPath.ts +4 -0
  118. package/src/BunRuntime.ts +4 -0
  119. package/src/BunServices.ts +3 -0
  120. package/src/BunSink.ts +1 -0
  121. package/src/BunSocket.ts +28 -6
  122. package/src/BunSocketServer.ts +1 -0
  123. package/src/BunStdio.ts +2 -0
  124. package/src/BunStream.ts +2 -0
  125. package/src/BunTerminal.ts +7 -3
  126. package/src/BunWorker.ts +3 -0
  127. package/src/BunWorkerRunner.ts +2 -1
  128. package/src/index.ts +40 -0
package/src/BunDns.ts ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Bun implementation of Effect's `Dns` service.
3
+ *
4
+ * Address lookups use `Bun.dns.lookup` with the `system` backend, which calls
5
+ * the operating system resolver (`getaddrinfo`) and therefore also reads the
6
+ * hosts file. Bun's `node:dns` lookup uses c-ares instead, which bypasses the
7
+ * system's name service configuration. Record queries and reverse lookups use
8
+ * `NodeDns.resolver` without the UTF-8 correction of `NodeDns.make`,
9
+ * because Bun already decodes TXT and CAA character strings as UTF-8.
10
+ *
11
+ * **Gotchas**
12
+ *
13
+ * Bun returns each character string of a TXT record as a separate record, so
14
+ * a record made of several strings arrives as several TXT records whose chunks
15
+ * cannot be reassembled (https://github.com/oven-sh/bun/issues/44692).
16
+ *
17
+ * Bun's resolver cannot query TLSA records, so TLSA queries fail with
18
+ * `Unsupported`.
19
+ *
20
+ * @stability experimental
21
+ * @since 4.0.0
22
+ */
23
+ import * as NodeDns from "@effect/platform-node-shared/NodeDns"
24
+ import * as Config from "effect/Config"
25
+ import * as Effect from "effect/Effect"
26
+ import * as Layer from "effect/Layer"
27
+ import * as Dns from "effect/net/Dns"
28
+ import type * as NetAddress from "effect/net/NetAddress"
29
+
30
+ export type {
31
+ /**
32
+ * Options for the Bun `Dns` service: name servers, timeout, and tries for
33
+ * record queries and reverse lookups.
34
+ *
35
+ * @stability experimental
36
+ * @category re-exports
37
+ * @since 4.0.0
38
+ */
39
+ Options
40
+ } from "@effect/platform-node-shared/NodeDns"
41
+
42
+ /**
43
+ * Creates a Bun `Dns` service whose resolver lives as long as the scope.
44
+ *
45
+ * @stability experimental
46
+ * @category constructors
47
+ * @since 4.0.0
48
+ */
49
+ export const make = Effect.fnUntraced(function*(options?: NodeDns.Options) {
50
+ const resolve = yield* NodeDns.resolver(options)
51
+ return Dns.make({
52
+ lookup: (host, family) =>
53
+ Effect.tryPromise({
54
+ try: () => Bun.dns.lookup(host, { family: NodeDns.toFamily(family), backend: "system" }),
55
+ catch: (cause) => NodeDns.dnsErrorFromCause(cause, "lookup", host)
56
+ }).pipe(Effect.map(NodeDns.addressesFromLookup)),
57
+ resolve
58
+ })
59
+ })
60
+
61
+ /**
62
+ * Layer that provides the Bun `Dns` service using the system resolver
63
+ * configuration.
64
+ *
65
+ * @stability experimental
66
+ * @category layers
67
+ * @since 4.0.0
68
+ */
69
+ export const layer: Layer.Layer<Dns.Dns> = Layer.effect(Dns.Dns, Effect.orDie(make()))
70
+
71
+ /**
72
+ * Creates a layer that provides the Bun `Dns` service with options read
73
+ * from configuration.
74
+ *
75
+ * @stability experimental
76
+ * @category layers
77
+ * @since 4.0.0
78
+ */
79
+ export const layerConfig = (
80
+ options: Config.Wrap<NodeDns.Options>
81
+ ): Layer.Layer<Dns.Dns, Config.ConfigError | NetAddress.NetAddressError> =>
82
+ Layer.effect(Dns.Dns, Effect.flatMap(Config.unwrap(options), make))
@@ -5,6 +5,7 @@
5
5
  * the shared Node file-system implementation. Once the layer is provided,
6
6
  * programs use the standard `effect/FileSystem` service operations.
7
7
  *
8
+ * @stability unstable
8
9
  * @since 4.0.0
9
10
  */
10
11
  import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem"
@@ -14,6 +15,7 @@ import type * as Layer from "effect/Layer"
14
15
  /**
15
16
  * Layer that provides the `FileSystem` service for Bun using the shared Node file-system implementation.
16
17
  *
18
+ * @stability unstable
17
19
  * @category layers
18
20
  * @since 4.0.0
19
21
  */
@@ -1,4 +1,5 @@
1
1
  /**
2
+ * @stability unstable
2
3
  * @since 4.0.0
3
4
  */
4
5
 
@@ -7,6 +7,7 @@
7
7
  * provides the Bun file-system layer and ETag generator required by
8
8
  * `HttpPlatform`.
9
9
  *
10
+ * @stability unstable
10
11
  * @since 4.0.0
11
12
  */
12
13
  import * as NodeHttpCompression from "@effect/platform-node-shared/NodeHttpCompression"
@@ -60,6 +61,7 @@ const make: Effect.Effect<
60
61
  /**
61
62
  * Layer that provides the Bun `HttpPlatform`, including file responses backed by `Bun.file`.
62
63
  *
64
+ * @stability unstable
63
65
  * @category layers
64
66
  * @since 4.0.0
65
67
  */
@@ -9,6 +9,7 @@
9
9
  * for the server alone, the Bun HTTP support services, the combined server,
10
10
  * configurable server options, and a test server with an HTTP client.
11
11
  *
12
+ * @stability unstable
12
13
  * @since 4.0.0
13
14
  */
14
15
  import type { Server as BunServer, ServerWebSocket } from "bun"
@@ -60,6 +61,7 @@ import * as BunStream from "./BunStream.ts"
60
61
  /**
61
62
  * Bun serve options accepted by the HTTP server, extended with typed route definitions.
62
63
  *
64
+ * @stability unstable
63
65
  * @category options
64
66
  * @since 4.0.0
65
67
  */
@@ -85,6 +87,7 @@ export type ServeOptions<R extends string> =
85
87
  * that is compressed when per-message deflate is negotiated. It defaults to
86
88
  * 1024, matching the default threshold of Node's `ws` server.
87
89
  *
90
+ * @stability unstable
88
91
  * @category options
89
92
  * @since 4.0.0
90
93
  */
@@ -106,6 +109,7 @@ export type WebSocketOptions =
106
109
  /**
107
110
  * Creates a scoped Bun `HttpServer` from `Bun.serve` options, stopping the server on scope finalization with optional graceful shutdown settings.
108
111
  *
112
+ * @stability unstable
109
113
  * @category constructors
110
114
  * @since 4.0.0
111
115
  */
@@ -189,7 +193,9 @@ export const make = Effect.fnUntraced(
189
193
 
190
194
  const httpEffect = HttpEffect.toHandled(httpApp, (request, response) =>
191
195
  Effect.sync(() => {
192
- ;(request as BunServerRequest).resolve(makeResponse(request, response, services, scope))
196
+ const bunRequest = request as BunServerRequest
197
+ bunRequest.resolve(makeResponse(request, response, services, scope))
198
+ if (upgradedSources.has(bunRequest.source)) return upgradedResponse
193
199
  }), middleware)
194
200
 
195
201
  function handler(request: Request, server: BunServer<WebSocketContext>) {
@@ -227,6 +233,12 @@ export const make = Effect.fnUntraced(
227
233
 
228
234
  const MIN_COMPRESSIBLE_SIZE = 1024
229
235
 
236
+ // Reported to middleware in place of the handler's discarded response.
237
+ const upgradedResponse = ServerResponse.empty({ status: 101 })
238
+
239
+ // Keyed by source so request copies from `modify` share the upgrade state.
240
+ const upgradedSources = new WeakSet<Request>()
241
+
230
242
  const makeResponse = (
231
243
  request: ServerRequest.HttpServerRequest,
232
244
  response: ServerResponse.HttpServerResponse,
@@ -294,6 +306,7 @@ const makeResponse = (
294
306
  /**
295
307
  * Layer that provides only `HttpServer` by constructing a scoped Bun server from the supplied serve options.
296
308
  *
309
+ * @stability unstable
297
310
  * @category layers
298
311
  * @since 4.0.0
299
312
  */
@@ -308,6 +321,7 @@ export const layerServer: <R extends string>(
308
321
  /**
309
322
  * Layer that provides Bun HTTP support services: `HttpPlatform`, weak ETag generation, and `BunServices`.
310
323
  *
324
+ * @stability unstable
311
325
  * @category layers
312
326
  * @since 4.0.0
313
327
  */
@@ -324,6 +338,7 @@ export const layerHttpServices: Layer.Layer<
324
338
  /**
325
339
  * Layer that provides a Bun `HttpServer` together with the Bun HTTP platform, ETag generator, and Bun services.
326
340
  *
341
+ * @stability unstable
327
342
  * @category layers
328
343
  * @since 4.0.0
329
344
  */
@@ -344,6 +359,7 @@ export const layer = <R extends string>(
344
359
  /**
345
360
  * Layer that starts a Bun HTTP server on an ephemeral port for tests.
346
361
  *
362
+ * @stability unstable
347
363
  * @category testing
348
364
  * @since 4.0.0
349
365
  */
@@ -359,6 +375,7 @@ export const layerTest: Layer.Layer<
359
375
  /**
360
376
  * Creates the Bun HTTP server and support-services layer from configurable serve options.
361
377
  *
378
+ * @stability unstable
362
379
  * @category layers
363
380
  * @since 4.0.0
364
381
  */
@@ -613,6 +630,7 @@ class BunServerRequest extends Inspectable.Class implements ServerRequest.HttpSe
613
630
  ))
614
631
  return
615
632
  }
633
+ upgradedSources.add(this.source)
616
634
  const compressionThreshold = this.compressionThreshold
617
635
  resume(Effect.map(Deferred.await(deferred), (ws) => {
618
636
  const write = (chunk: Uint8Array | string | Socket.CloseEvent) =>
@@ -5,6 +5,7 @@
5
5
  * `Bun.BunRequest` stored inside a Bun-backed `HttpServerRequest`. It is meant
6
6
  * for code that needs to interoperate with Bun-specific request APIs.
7
7
  *
8
+ * @stability unstable
8
9
  * @since 4.0.0
9
10
  */
10
11
  import type { HttpServerRequest } from "effect/http/HttpServerRequest"
@@ -12,6 +13,7 @@ import type { HttpServerRequest } from "effect/http/HttpServerRequest"
12
13
  /**
13
14
  * Returns the underlying `Bun.BunRequest` from an Effect `HttpServerRequest`.
14
15
  *
16
+ * @stability unstable
15
17
  * @category accessors
16
18
  * @since 4.0.0
17
19
  */
@@ -6,6 +6,7 @@
6
6
  * `persisted` collects the form and writes file parts to scoped temporary files
7
7
  * through the current `FileSystem`, `Path`, and `Scope` services.
8
8
  *
9
+ * @stability unstable
9
10
  * @since 4.0.0
10
11
  */
11
12
  import type * as Effect from "effect/Effect"
@@ -19,6 +20,7 @@ import * as BunStream from "./BunStream.ts"
19
20
  /**
20
21
  * Parses a Bun `Request` body as multipart data and returns a stream of multipart parts.
21
22
  *
23
+ * @stability unstable
22
24
  * @category constructors
23
25
  * @since 4.0.0
24
26
  */
@@ -39,6 +41,7 @@ export const stream = (source: Request): Stream.Stream<Multipart.Part, Multipart
39
41
  /**
40
42
  * Parses and persists multipart data from a Bun `Request`, requiring file-system, path, and scope services.
41
43
  *
44
+ * @stability unstable
42
45
  * @category constructors
43
46
  * @since 4.0.0
44
47
  */
package/src/BunPath.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  * Bun code should receive path operations from the Effect environment instead
7
7
  * of importing runtime path helpers directly.
8
8
  *
9
+ * @stability unstable
9
10
  * @since 4.0.0
10
11
  */
11
12
  import * as NodePath from "@effect/platform-node-shared/NodePath"
@@ -15,6 +16,7 @@ import type { Path } from "effect/Path"
15
16
  /**
16
17
  * Layer that provides the default `Path` service for Bun using the shared Node path implementation.
17
18
  *
19
+ * @stability unstable
18
20
  * @category layers
19
21
  * @since 4.0.0
20
22
  */
@@ -23,6 +25,7 @@ export const layer: Layer.Layer<Path> = NodePath.layer
23
25
  /**
24
26
  * Layer that provides the POSIX `Path` service for Bun using the shared Node path implementation.
25
27
  *
28
+ * @stability unstable
26
29
  * @category layers
27
30
  * @since 4.0.0
28
31
  */
@@ -31,6 +34,7 @@ export const layerPosix: Layer.Layer<Path> = NodePath.layerPosix
31
34
  /**
32
35
  * Layer that provides the Win32 `Path` service for Bun using the shared Node path implementation.
33
36
  *
37
+ * @stability unstable
34
38
  * @category layers
35
39
  * @since 4.0.0
36
40
  */
package/src/BunRuntime.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  * fiber in Bun. It reuses the shared Node runtime runner, including its error
6
6
  * reporting, signal handling, and optional teardown behavior.
7
7
  *
8
+ * @stability unstable
8
9
  * @since 4.0.0
9
10
  */
10
11
  import * as NodeRuntime from "@effect/platform-node-shared/NodeRuntime"
@@ -32,6 +33,7 @@ import type { Teardown } from "effect/Runtime"
32
33
  * - `disablePrettyLogger`: Avoid adding the pretty logger.
33
34
  * - `teardown`: Provide custom finalization logic.
34
35
  *
36
+ * @stability unstable
35
37
  * @category running
36
38
  * @since 4.0.0
37
39
  */
@@ -57,6 +59,7 @@ export const runMain: {
57
59
  * - `disablePrettyLogger`: Avoid adding the pretty logger.
58
60
  * - `teardown`: Provide custom finalization logic.
59
61
  *
62
+ * @stability unstable
60
63
  * @category running
61
64
  * @since 4.0.0
62
65
  */
@@ -87,6 +90,7 @@ export const runMain: {
87
90
  * - `disablePrettyLogger`: Avoid adding the pretty logger.
88
91
  * - `teardown`: Provide custom finalization logic.
89
92
  *
93
+ * @stability unstable
90
94
  * @category running
91
95
  * @since 4.0.0
92
96
  */
@@ -6,6 +6,7 @@
6
6
  * and terminal services. Use the layer when a Bun program wants the standard
7
7
  * platform services from one place.
8
8
  *
9
+ * @stability unstable
9
10
  * @since 4.0.0
10
11
  */
11
12
  import type { Crypto } from "effect/Crypto"
@@ -26,6 +27,7 @@ import * as BunTerminal from "./BunTerminal.ts"
26
27
  * The union of core services provided by the Bun platform layer, including child
27
28
  * process spawning, filesystem, path, stdio, and terminal services.
28
29
  *
30
+ * @stability unstable
29
31
  * @category models
30
32
  * @since 4.0.0
31
33
  */
@@ -35,6 +37,7 @@ export type BunServices = ChildProcessSpawner | Crypto | FileSystem | Path | Ter
35
37
  * Provides the default Bun implementations for child process spawning,
36
38
  * filesystem, path, stdio, and terminal services.
37
39
  *
40
+ * @stability unstable
38
41
  * @category layers
39
42
  * @since 4.0.0
40
43
  */
package/src/BunSink.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /**
2
+ * @stability unstable
2
3
  * @since 4.0.0
3
4
  */
4
5
 
package/src/BunSocket.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  * It also provides Bun WebSocket layers using `globalThis.WebSocket`, including
7
7
  * a constructor layer and a `Socket.Socket` layer for a WebSocket URL.
8
8
  *
9
+ * @stability unstable
9
10
  * @since 4.0.0
10
11
  */
11
12
  import type * as Duration from "effect/Duration"
@@ -21,25 +22,45 @@ export * from "@effect/platform-node-shared/NodeSocket"
21
22
 
22
23
  /**
23
24
  * Provides a `Socket.WebSocketConstructor` backed by Bun's global
24
- * `WebSocket` implementation.
25
+ * `WebSocket` implementation, supporting handshake headers and subprotocols
26
+ * together in client options objects.
25
27
  *
28
+ * @stability unstable
26
29
  * @category layers
27
30
  * @since 4.0.0
28
31
  */
29
32
  export const layerWebSocketConstructor: Layer.Layer<
30
33
  Socket.WebSocketConstructor
31
34
  > = Layer.succeed(Socket.WebSocketConstructor)(
32
- (url, options) =>
33
- // Bun accepts `WebSocketOptions`, but `bun-types` selects the DOM overload
34
- // when `lib.dom` is loaded and hides those constructor options.
35
- new globalThis.WebSocket(url, options as string | Array<string> | undefined)
35
+ (url, options) => {
36
+ if (options === undefined || typeof options === "string" || Array.isArray(options)) {
37
+ return new globalThis.WebSocket(url, options)
38
+ }
39
+ // Bun accepts `WebSocketOptions`, but `bun-types` selects the DOM
40
+ // overload when `lib.dom` is loaded and hides those constructor options.
41
+ const WebSocket = globalThis.WebSocket as unknown as {
42
+ new(
43
+ url: string,
44
+ options: {
45
+ protocols?: Array<string> | undefined
46
+ headers?: Readonly<Record<string, string>> | undefined
47
+ }
48
+ ): globalThis.WebSocket
49
+ }
50
+ return new WebSocket(url, {
51
+ // Bun requires a sequence for `protocols` in its options object.
52
+ protocols: typeof options.protocols === "string" ? [options.protocols] : options.protocols,
53
+ headers: options.headers
54
+ })
55
+ }
36
56
  )
37
57
 
38
58
  /**
39
59
  * Creates a `Socket.Socket` layer for a WebSocket URL using Bun's global
40
- * `WebSocket` constructor, honoring protocol, open-timeout, and
60
+ * `WebSocket` constructor, honoring protocol, handshake-header, open-timeout, and
41
61
  * high-water-mark options.
42
62
  *
63
+ * @stability unstable
43
64
  * @category layers
44
65
  * @since 4.0.0
45
66
  */
@@ -48,6 +69,7 @@ export const layerWebSocket: (
48
69
  options?: {
49
70
  readonly openTimeout?: Duration.Input | undefined
50
71
  readonly protocols?: string | Array<string> | undefined
72
+ readonly headers?: Readonly<Record<string, string>> | undefined
51
73
  readonly highWaterMark?: number | undefined
52
74
  } | undefined
53
75
  ) => Layer.Layer<Socket.Socket, never, never> = flow(
@@ -1,4 +1,5 @@
1
1
  /**
2
+ * @stability unstable
2
3
  * @since 4.0.0
3
4
  */
4
5
 
package/src/BunStdio.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  * is read from `process.stdin`, and output and error output write to
7
7
  * `process.stdout` and `process.stderr`.
8
8
  *
9
+ * @stability unstable
9
10
  * @since 4.0.0
10
11
  */
11
12
  import * as NodeStdio from "@effect/platform-node-shared/NodeStdio"
@@ -16,6 +17,7 @@ import type { Stdio } from "effect/Stdio"
16
17
  * Provides the `Stdio` service backed by the current process arguments,
17
18
  * stdin, stdout, and stderr streams.
18
19
  *
20
+ * @stability unstable
19
21
  * @category layers
20
22
  * @since 4.0.0
21
23
  */
package/src/BunStream.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  * `ReadableStream` adapter that uses Bun's `readMany` reader method to pull
8
8
  * batches of values into an Effect `Stream`.
9
9
  *
10
+ * @stability unstable
10
11
  * @since 4.0.0
11
12
  */
12
13
  import * as Arr from "effect/Array"
@@ -27,6 +28,7 @@ export * from "@effect/platform-node-shared/NodeStream"
27
28
  * Creates a stream from a `ReadableStream` using Bun's optimized `.readMany`
28
29
  * API.
29
30
  *
31
+ * @stability unstable
30
32
  * @category constructors
31
33
  * @since 4.0.0
32
34
  */
@@ -5,6 +5,7 @@
5
5
  * creates a scoped process-backed `Terminal` service, and `layer` provides the
6
6
  * default terminal service with the standard quit behavior for key input.
7
7
  *
8
+ * @stability unstable
8
9
  * @since 4.0.0
9
10
  */
10
11
  import * as NodeTerminal from "@effect/platform-node-shared/NodeTerminal"
@@ -14,9 +15,11 @@ import type { Scope } from "effect/Scope"
14
15
  import type { Terminal, UserInput } from "effect/Terminal"
15
16
 
16
17
  /**
17
- * Creates a scoped `Terminal` service backed by process stdin/stdout, using the
18
- * optional predicate to decide when key input should end the input stream.
18
+ * Creates a scoped `Terminal` service backed by process stdin/stdout.
19
+ * By default, Esc, Ctrl+C, and Ctrl+D end key input. Supply `shouldQuit` to
20
+ * override these quit keys.
19
21
  *
22
+ * @stability unstable
20
23
  * @category constructors
21
24
  * @since 4.0.0
22
25
  */
@@ -24,8 +27,9 @@ export const make: (shouldQuit?: (input: UserInput) => boolean) => Effect<Termin
24
27
 
25
28
  /**
26
29
  * Provides the default process-backed `Terminal` service, ending key input on
27
- * the default quit keys.
30
+ * bare Esc, Ctrl+C, or Ctrl+D.
28
31
  *
32
+ * @stability unstable
29
33
  * @category layers
30
34
  * @since 4.0.0
31
35
  */
package/src/BunWorker.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  * asks workers to close on scope finalization, and terminates them if graceful
9
9
  * shutdown times out.
10
10
  *
11
+ * @stability unstable
11
12
  * @since 4.0.0
12
13
  */
13
14
  import * as Deferred from "effect/Deferred"
@@ -22,6 +23,7 @@ import { WorkerError, WorkerUnknownError } from "effect/workers/WorkerError"
22
23
  * Provides the Bun `WorkerPlatform` together with a `Worker.Spawner` created
23
24
  * from the supplied worker spawning function.
24
25
  *
26
+ * @stability unstable
25
27
  * @category layers
26
28
  * @since 4.0.0
27
29
  */
@@ -38,6 +40,7 @@ export const layer = (
38
40
  * Effect workers and requesting graceful worker shutdown during scope
39
41
  * finalization before terminating on timeout.
40
42
  *
43
+ * @stability unstable
41
44
  * @category layers
42
45
  * @since 4.0.0
43
46
  */
@@ -7,6 +7,7 @@
7
7
  * responses through the worker `postMessage` channel, and closes when the
8
8
  * parent sends the close message.
9
9
  *
10
+ * @stability unstable
10
11
  * @since 4.0.0
11
12
  */
12
13
  import * as Cause from "effect/Cause"
@@ -27,6 +28,7 @@ declare const self: MessagePort
27
28
  * routing parent messages to the registered handler and sending responses back
28
29
  * through the worker port.
29
30
  *
31
+ * @stability unstable
30
32
  * @category layers
31
33
  * @since 4.0.0
32
34
  */
@@ -62,7 +64,6 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
62
64
  trackFiber(fiber)
63
65
  }
64
66
  } else {
65
- port.close()
66
67
  Deferred.doneUnsafe(closeLatch, Exit.void)
67
68
  }
68
69
  }