@effect/platform-bun 4.0.0-beta.7 → 4.0.0-beta.70

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 (108) hide show
  1. package/dist/BunChildProcessSpawner.d.ts +1 -1
  2. package/dist/BunChildProcessSpawner.js +1 -1
  3. package/dist/BunClusterHttp.d.ts +46 -7
  4. package/dist/BunClusterHttp.d.ts.map +1 -1
  5. package/dist/BunClusterHttp.js +17 -10
  6. package/dist/BunClusterHttp.js.map +1 -1
  7. package/dist/BunClusterSocket.d.ts +54 -9
  8. package/dist/BunClusterSocket.d.ts.map +1 -1
  9. package/dist/BunClusterSocket.js +54 -9
  10. package/dist/BunClusterSocket.js.map +1 -1
  11. package/dist/BunCrypto.d.ts +10 -0
  12. package/dist/BunCrypto.d.ts.map +1 -0
  13. package/dist/BunCrypto.js +14 -0
  14. package/dist/BunCrypto.js.map +1 -0
  15. package/dist/BunFileSystem.d.ts +4 -2
  16. package/dist/BunFileSystem.d.ts.map +1 -1
  17. package/dist/BunFileSystem.js +27 -3
  18. package/dist/BunFileSystem.js.map +1 -1
  19. package/dist/BunHttpClient.d.ts +2 -2
  20. package/dist/BunHttpClient.js +2 -2
  21. package/dist/BunHttpPlatform.d.ts +4 -2
  22. package/dist/BunHttpPlatform.d.ts.map +1 -1
  23. package/dist/BunHttpPlatform.js +5 -3
  24. package/dist/BunHttpPlatform.js.map +1 -1
  25. package/dist/BunHttpServer.d.ts +77 -19
  26. package/dist/BunHttpServer.d.ts.map +1 -1
  27. package/dist/BunHttpServer.js +63 -36
  28. package/dist/BunHttpServer.js.map +1 -1
  29. package/dist/BunHttpServerRequest.d.ts +26 -2
  30. package/dist/BunHttpServerRequest.d.ts.map +1 -1
  31. package/dist/BunHttpServerRequest.js +3 -1
  32. package/dist/BunHttpServerRequest.js.map +1 -1
  33. package/dist/BunMultipart.d.ts +28 -5
  34. package/dist/BunMultipart.d.ts.map +1 -1
  35. package/dist/BunMultipart.js +15 -5
  36. package/dist/BunMultipart.js.map +1 -1
  37. package/dist/BunPath.d.ts +12 -6
  38. package/dist/BunPath.d.ts.map +1 -1
  39. package/dist/BunPath.js +30 -7
  40. package/dist/BunPath.js.map +1 -1
  41. package/dist/BunRedis.d.ts +39 -9
  42. package/dist/BunRedis.d.ts.map +1 -1
  43. package/dist/BunRedis.js +42 -12
  44. package/dist/BunRedis.js.map +1 -1
  45. package/dist/BunRuntime.d.ts +24 -30
  46. package/dist/BunRuntime.d.ts.map +1 -1
  47. package/dist/BunRuntime.js +25 -11
  48. package/dist/BunRuntime.js.map +1 -1
  49. package/dist/BunServices.d.ts +32 -5
  50. package/dist/BunServices.d.ts.map +1 -1
  51. package/dist/BunServices.js +7 -3
  52. package/dist/BunServices.js.map +1 -1
  53. package/dist/BunSink.d.ts +2 -2
  54. package/dist/BunSink.js +2 -2
  55. package/dist/BunSocket.d.ts +30 -4
  56. package/dist/BunSocket.d.ts.map +1 -1
  57. package/dist/BunSocket.js +10 -3
  58. package/dist/BunSocket.js.map +1 -1
  59. package/dist/BunSocketServer.d.ts +2 -2
  60. package/dist/BunSocketServer.js +2 -2
  61. package/dist/BunStdio.d.ts +5 -2
  62. package/dist/BunStdio.d.ts.map +1 -1
  63. package/dist/BunStdio.js +24 -3
  64. package/dist/BunStdio.js.map +1 -1
  65. package/dist/BunStream.d.ts +3 -2
  66. package/dist/BunStream.d.ts.map +1 -1
  67. package/dist/BunStream.js +25 -3
  68. package/dist/BunStream.js.map +1 -1
  69. package/dist/BunTerminal.d.ts +8 -2
  70. package/dist/BunTerminal.d.ts.map +1 -1
  71. package/dist/BunTerminal.js +23 -3
  72. package/dist/BunTerminal.js.map +1 -1
  73. package/dist/BunWorker.d.ts +9 -2
  74. package/dist/BunWorker.d.ts.map +1 -1
  75. package/dist/BunWorker.js +29 -4
  76. package/dist/BunWorker.js.map +1 -1
  77. package/dist/BunWorkerRunner.d.ts +5 -1
  78. package/dist/BunWorkerRunner.d.ts.map +1 -1
  79. package/dist/BunWorkerRunner.js +27 -5
  80. package/dist/BunWorkerRunner.js.map +1 -1
  81. package/dist/index.d.ts +396 -21
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +396 -21
  84. package/dist/index.js.map +1 -1
  85. package/package.json +5 -5
  86. package/src/BunChildProcessSpawner.ts +1 -1
  87. package/src/BunClusterHttp.ts +51 -11
  88. package/src/BunClusterSocket.ts +54 -9
  89. package/src/BunCrypto.ts +16 -0
  90. package/src/BunFileSystem.ts +27 -3
  91. package/src/BunHttpClient.ts +2 -2
  92. package/src/BunHttpPlatform.ts +28 -4
  93. package/src/BunHttpServer.ts +128 -56
  94. package/src/BunHttpServerRequest.ts +26 -2
  95. package/src/BunMultipart.ts +36 -6
  96. package/src/BunPath.ts +30 -7
  97. package/src/BunRedis.ts +44 -14
  98. package/src/BunRuntime.ts +41 -31
  99. package/src/BunServices.ts +34 -5
  100. package/src/BunSink.ts +2 -2
  101. package/src/BunSocket.ts +30 -4
  102. package/src/BunSocketServer.ts +2 -2
  103. package/src/BunStdio.ts +24 -3
  104. package/src/BunStream.ts +25 -3
  105. package/src/BunTerminal.ts +23 -3
  106. package/src/BunWorker.ts +29 -4
  107. package/src/BunWorkerRunner.ts +27 -5
  108. package/src/index.ts +397 -21
package/src/BunWorker.ts CHANGED
@@ -1,5 +1,23 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Parent-side Bun support for Effect workers.
3
+ *
4
+ * This module provides the `WorkerPlatform` used by Bun programs that spawn
5
+ * and communicate with `globalThis.Worker` instances through Effect's worker
6
+ * protocol. Pair it with `BunWorkerRunner` in the worker entrypoint when
7
+ * building worker-backed RPC clients, moving CPU-bound work off the main
8
+ * thread, isolating Bun-only services, or hosting long-lived handlers behind a
9
+ * typed message boundary.
10
+ *
11
+ * The supplied spawner is responsible for creating the Bun worker for each
12
+ * numeric worker id. Messages follow Bun's worker cloning and transfer
13
+ * semantics, so payloads and transfer lists must be accepted by the Bun worker
14
+ * runtime. Calls to `send` are buffered until the worker runner posts its ready
15
+ * signal; if the worker entrypoint never starts `BunWorkerRunner`, those
16
+ * buffered messages will not be delivered. Scope finalization sends the Effect
17
+ * worker close signal, waits for Bun's `close` event for a short grace period,
18
+ * and then terminates the worker if graceful shutdown does not complete.
19
+ *
20
+ * @since 4.0.0
3
21
  */
4
22
  import * as Deferred from "effect/Deferred"
5
23
  import * as Effect from "effect/Effect"
@@ -10,8 +28,11 @@ import * as Worker from "effect/unstable/workers/Worker"
10
28
  import { WorkerError, WorkerUnknownError } from "effect/unstable/workers/WorkerError"
11
29
 
12
30
  /**
13
- * @since 1.0.0
31
+ * Provides the Bun `WorkerPlatform` together with a `Worker.Spawner` created
32
+ * from the supplied worker spawning function.
33
+ *
14
34
  * @category layers
35
+ * @since 4.0.0
15
36
  */
16
37
  export const layer = (
17
38
  spawn: (id: number) => globalThis.Worker
@@ -22,8 +43,12 @@ export const layer = (
22
43
  )
23
44
 
24
45
  /**
25
- * @since 1.0.0
46
+ * Provides the Bun `WorkerPlatform`, wiring worker messages and errors into
47
+ * Effect workers and requesting graceful worker shutdown during scope
48
+ * finalization before terminating on timeout.
49
+ *
26
50
  * @category layers
51
+ * @since 4.0.0
27
52
  */
28
53
  export const layerPlatform = Layer.succeed(Worker.WorkerPlatform)(
29
54
  Worker.makePlatform<globalThis.Worker>()({
@@ -59,7 +84,7 @@ export const layerPlatform = Layer.succeed(Worker.WorkerPlatform)(
59
84
  message: "An error event was emitted",
60
85
  cause: event.error ?? event.message
61
86
  })
62
- }).asEffect()
87
+ })
63
88
  )
64
89
  }
65
90
  port.addEventListener("message", onMessage)
@@ -1,5 +1,23 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Bun runtime support for Effect worker runners.
3
+ *
4
+ * This module is intended for code that is already executing inside a Bun
5
+ * `Worker`. It provides the `WorkerRunnerPlatform` used by `WorkerRunner` to
6
+ * receive request messages from the parent, run the registered Effect handler,
7
+ * and send responses back over Bun's worker `postMessage` channel.
8
+ *
9
+ * Use it with `BunWorker` when a Bun program needs to move RPC handlers,
10
+ * CPU-bound computations, or Bun-only services into an isolated worker while
11
+ * communicating through the Effect worker protocol. The runner must be started
12
+ * from the worker entrypoint, not the parent process; startup fails when the
13
+ * current global worker scope does not expose `postMessage`. Shutdown is driven
14
+ * by the parent protocol message, which closes the worker port, so long-running
15
+ * handlers should remain interruptible and keep resource cleanup in scopes.
16
+ * Messages follow Bun's worker cloning and transfer semantics, so payload
17
+ * schemas, transfer lists, `messageerror` events, and worker `error` events
18
+ * should be considered at the boundary.
19
+ *
20
+ * @since 4.0.0
3
21
  */
4
22
  import * as Cause from "effect/Cause"
5
23
  import * as Deferred from "effect/Deferred"
@@ -15,8 +33,12 @@ import * as WorkerRunner from "effect/unstable/workers/WorkerRunner"
15
33
  declare const self: MessagePort
16
34
 
17
35
  /**
18
- * @since 1.0.0
36
+ * Provides the `WorkerRunnerPlatform` for code running inside a Bun worker,
37
+ * routing parent messages to the registered handler and sending responses back
38
+ * through the worker port.
39
+ *
19
40
  * @category layers
41
+ * @since 4.0.0
20
42
  */
21
43
  export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succeed(WorkerRunner.WorkerRunnerPlatform)({
22
44
  start: Effect.fnUntraced(function*<O = unknown, I = unknown>() {
@@ -32,7 +54,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
32
54
  Effect.scopedWith(Effect.fnUntraced(function*(scope) {
33
55
  const closeLatch = Deferred.makeUnsafe<void, WorkerError>()
34
56
  const trackFiber = Fiber.runIn(scope)
35
- const services = yield* Effect.services<R>()
57
+ const services = yield* Effect.context<R>()
36
58
  const runFork = Effect.runForkWith(services)
37
59
  const onExit = (exit: Exit.Exit<any, E>) => {
38
60
  if (exit._tag === "Failure" && !Cause.hasInterruptsOnly(exit.cause)) {
@@ -62,7 +84,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
62
84
  message: "received messageerror event",
63
85
  cause: error.data
64
86
  })
65
- }).asEffect()
87
+ })
66
88
  )
67
89
  }
68
90
  function onError(error: MessageEvent) {
@@ -73,7 +95,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
73
95
  message: "received error event",
74
96
  cause: error.data
75
97
  })
76
- }).asEffect()
98
+ })
77
99
  )
78
100
  }
79
101
  yield* Scope.addFinalizer(
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  // @barrel: Auto-generated exports. Do not edit manually.
@@ -7,106 +7,482 @@
7
7
  /**
8
8
  * Node.js implementation of `ChildProcessSpawner`.
9
9
  *
10
- * @since 1.0.0
10
+ * @since 4.0.0
11
11
  */
12
12
  export * as BunChildProcessSpawner from "./BunChildProcessSpawner.ts"
13
13
 
14
14
  /**
15
- * @since 1.0.0
15
+ * The `BunClusterHttp` module provides the Bun HTTP and WebSocket transports
16
+ * for Effect Cluster runners. It wires `HttpRunner` to the Bun HTTP server,
17
+ * supplies Fetch and Bun WebSocket client protocols, and builds a complete
18
+ * sharding layer with serialization, runner health, runner storage, and message
19
+ * storage.
20
+ *
21
+ * **Common tasks**
22
+ *
23
+ * - Run a Bun process as a cluster runner over HTTP or WebSocket with
24
+ * {@link layer}
25
+ * - Connect a client-only process to an existing HTTP cluster without starting
26
+ * a runner server
27
+ * - Use SQL-backed storage for durable multi-process clusters, `local` storage
28
+ * for short-lived development, or `byo` storage when the deployment owns the
29
+ * persistence boundary
30
+ * - Check runner health with protocol pings or Kubernetes pod readiness through
31
+ * {@link layerK8sHttpClient}
32
+ *
33
+ * **Gotchas**
34
+ *
35
+ * - `runnerAddress` is the host and port advertised to other runners; set
36
+ * `runnerListenAddress` when the local bind address differs from the
37
+ * externally reachable address
38
+ * - The HTTP and WebSocket transports serve runner RPCs at the default
39
+ * `HttpRunner` route, so proxies and load balancers must preserve the path
40
+ * and allow WebSocket upgrades when `transport` is `"websocket"`
41
+ * - `clientOnly` does not start an HTTP server or receive shard assignments
42
+ * - SQL storage is the default; `local` storage is in-memory/noop and `byo`
43
+ * requires the surrounding application to provide both runner and message
44
+ * storage services
45
+ * - Ping health checks use the selected transport and serialization, so route,
46
+ * port, proxy, or codec mismatches can make a runner appear unhealthy
47
+ *
48
+ * @since 4.0.0
16
49
  */
17
50
  export * as BunClusterHttp from "./BunClusterHttp.ts"
18
51
 
19
52
  /**
20
- * @since 1.0.0
53
+ * The `BunClusterSocket` module provides the Bun socket transport for Effect
54
+ * Cluster runners. It wires `SocketRunner` to Bun-compatible TCP sockets,
55
+ * supplies RPC client and server protocol layers, and builds a complete
56
+ * sharding layer with serialization, runner health, runner storage, and message
57
+ * storage.
58
+ *
59
+ * **Common tasks**
60
+ *
61
+ * - Run a Bun process as a cluster runner over raw TCP sockets with
62
+ * {@link layer}
63
+ * - Connect a client-only process to an existing socket cluster without
64
+ * starting a runner server
65
+ * - Use SQL-backed storage for durable multi-process clusters, `local` storage
66
+ * for short-lived development, or `byo` storage when the deployment owns the
67
+ * persistence boundary
68
+ * - Check runner health with socket pings or Kubernetes pod readiness through
69
+ * {@link layerK8sHttpClient}
70
+ *
71
+ * **Gotchas**
72
+ *
73
+ * - `runnerAddress` is the host and port advertised to other runners; set
74
+ * `runnerListenAddress` when the local bind address differs from the
75
+ * externally reachable address
76
+ * - The socket transport is point-to-point RPC, not cluster gossip: runner
77
+ * membership, shard ownership, and persisted delivery are coordinated through
78
+ * `RunnerStorage`, `MessageStorage`, and `RunnerHealth`
79
+ * - `clientOnly` does not start a socket server or receive shard assignments
80
+ * - SQL storage is the default; `local` storage is in-memory/noop and `byo`
81
+ * requires the surrounding application to provide both runner and message
82
+ * storage services
83
+ * - Ping health checks use the same socket protocol, so unreachable ports,
84
+ * firewalls, or serialization mismatches can make a runner appear unhealthy
85
+ * - Kubernetes health checks use Bun's Fetch-backed HTTP client and the service
86
+ * account CA certificate when it is available
87
+ *
88
+ * @since 4.0.0
21
89
  */
22
90
  export * as BunClusterSocket from "./BunClusterSocket.ts"
23
91
 
24
92
  /**
93
+ * Bun platform Crypto service layer.
94
+ *
25
95
  * @since 1.0.0
26
96
  */
97
+ export * as BunCrypto from "./BunCrypto.ts"
98
+
99
+ /**
100
+ * Bun layer for Effect's `FileSystem` service.
101
+ *
102
+ * Use this module at the edge of Bun applications, CLIs, scripts, and tests
103
+ * that need real local filesystem access through `effect/FileSystem`: reading
104
+ * and writing files, creating directories and temporary files, inspecting
105
+ * metadata, managing links, or watching paths for changes. It exposes only the
106
+ * Bun `FileSystem` layer; the operations themselves are accessed from the
107
+ * `FileSystem` service once the layer is provided, or from `BunServices.layer`
108
+ * when the program also needs the standard Bun path, stdio, terminal, and child
109
+ * process services.
110
+ *
111
+ * Bun supports Node-compatible filesystem APIs, so this layer reuses the shared
112
+ * Node filesystem implementation. Paths therefore follow the current process and
113
+ * host platform rules: relative paths are resolved from the current working
114
+ * directory, separators and drive/UNC behavior are platform-dependent, and
115
+ * request URLs should be decoded and validated before being mapped to local
116
+ * paths. The service works with bytes, scoped file handles, and Effect
117
+ * streams/sinks; use `FileSystem.stream` for large files instead of
118
+ * `readFile`, and remember that stream offsets and lengths are byte positions.
119
+ * Bun `File` and `Blob` values are not filesystem handles here; path-based HTTP
120
+ * file responses are handled by the Bun HTTP platform adapter with `Bun.file`.
121
+ *
122
+ * @since 4.0.0
123
+ */
27
124
  export * as BunFileSystem from "./BunFileSystem.ts"
28
125
 
29
126
  /**
30
- * @since 1.0.0
127
+ * @since 4.0.0
31
128
  */
32
129
  export * as BunHttpClient from "./BunHttpClient.ts"
33
130
 
34
131
  /**
35
- * @since 1.0.0
132
+ * Bun implementation of the Effect HTTP platform service.
133
+ *
134
+ * This module connects the portable `HttpPlatform` file response helpers to
135
+ * Bun's Web-compatible runtime. `BunHttpServer` provides this layer when
136
+ * applications serve local files, public assets, downloads, byte ranges, or
137
+ * Web `File` values from Effect `HttpServerResponse` constructors.
138
+ *
139
+ * Path-based responses are backed by `Bun.file`, and Web `File` responses are
140
+ * returned directly as raw response bodies. The shared `HttpPlatform` service
141
+ * still computes file metadata such as ETags and last-modified headers, while
142
+ * this adapter lets Bun's `Response` implementation handle the platform body.
143
+ *
144
+ * Because the Bun server adapter sits on top of Web `Request` and `Response`,
145
+ * request bodies follow the usual single-consumption rules: choose the
146
+ * streamed, text, URL-encoded, or multipart view that matches the route. For
147
+ * `FormData` responses, let the `Response` constructor create the multipart
148
+ * content type and boundary unless you intentionally override it. File
149
+ * responses take filesystem paths, not request URLs; Bun request URLs are
150
+ * absolute at the runtime edge, and route paths are normalized by
151
+ * `BunHttpServer`, so decode and validate URL pathnames before mapping them to
152
+ * files.
153
+ *
154
+ * @since 4.0.0
36
155
  */
37
156
  export * as BunHttpPlatform from "./BunHttpPlatform.ts"
38
157
 
39
158
  /**
40
- * @since 1.0.0
159
+ * Bun implementation of the Effect `HttpServer`.
160
+ *
161
+ * This module builds an Effect HTTP server from `Bun.serve`, translating Bun's
162
+ * Web `Request` objects into `HttpServerRequest` values and Effect
163
+ * `HttpServerResponse` values back into Web `Response` objects. It is the Bun
164
+ * runtime entry point for serving `HttpApp`s, streaming responses, file
165
+ * responses through `BunHttpPlatform`, multipart requests, and websocket
166
+ * endpoints through `HttpServerRequest.upgrade`.
167
+ *
168
+ * Common use cases include using {@link layer} or {@link layerConfig} to serve
169
+ * an application from Bun configuration, {@link layerServer} when only the
170
+ * `HttpServer` service is needed, and {@link layerTest} for tests that need an
171
+ * ephemeral Bun listener and fetch-compatible client.
172
+ *
173
+ * Bun supplies absolute request URLs and Web-standard request bodies. This
174
+ * adapter stores the normalized path-and-query URL on `HttpServerRequest.url`,
175
+ * while the underlying `Request` still follows Web body rules: pick the
176
+ * streamed, text, JSON, URL-encoded, or multipart view that matches the route
177
+ * instead of consuming the same body in incompatible ways. Because `Bun.serve`
178
+ * has a single active `fetch` handler, each `serve` call reloads that handler
179
+ * and restores the previous one when the serve scope finalizes.
180
+ *
181
+ * WebSocket upgrades must happen from the Bun request handler. The
182
+ * `HttpServerRequest.upgrade` effect calls `server.upgrade`, fails when Bun says
183
+ * the request is not upgradeable, buffers messages that arrive before the
184
+ * Effect socket handler is installed, and maps non-normal close codes into
185
+ * `Socket` errors. The server is stopped with `server.stop()` when its
186
+ * acquisition scope closes; unless preemptive shutdown is disabled, finalizing
187
+ * a serve scope also starts that stop with the configured graceful shutdown
188
+ * timeout or the default timeout.
189
+ *
190
+ * @since 4.0.0
41
191
  */
42
192
  export * as BunHttpServer from "./BunHttpServer.ts"
43
193
 
44
194
  /**
45
- * @since 1.0.0
195
+ * Accessors for the Bun `Request` object backing a platform Bun
196
+ * `HttpServerRequest`.
197
+ *
198
+ * Use this module at interop boundaries when an Effect HTTP handler needs the
199
+ * original `Bun.BunRequest`, for example to read Bun route parameters, pass the
200
+ * request to Bun-specific APIs, inspect Web `Request` fields that are not
201
+ * exposed by the portable `HttpServerRequest` interface, or coordinate with code
202
+ * that already works directly with Bun's server request type.
203
+ *
204
+ * The returned request is the original Web request supplied by `Bun.serve`. It
205
+ * does not reflect Effect request overrides made by middleware, such as a
206
+ * rewritten URL, adjusted headers, or a substituted remote address. Its body is
207
+ * the same one-shot Web `ReadableStream` used by the Effect body helpers, so
208
+ * calling `text`, `json`, `formData`, `arrayBuffer`, or reading `body` directly
209
+ * can disturb the request and conflict with Effect body, multipart, or stream
210
+ * helpers unless ownership of the body is clear.
211
+ *
212
+ * Bun stores client IP information on the server rather than on the request
213
+ * object. Prefer `HttpServerRequest.remoteAddress` when you need the address
214
+ * seen by Effect or middleware; the raw request returned here will not expose
215
+ * middleware-provided remote address overrides.
216
+ *
217
+ * @since 4.0.0
46
218
  */
47
219
  export * as BunHttpServerRequest from "./BunHttpServerRequest.ts"
48
220
 
49
221
  /**
50
- * @since 1.0.0
222
+ * Bun-specific helpers for parsing HTTP `multipart/form-data` request bodies.
223
+ *
224
+ * This module adapts a Bun `Request` body and headers into the shared
225
+ * `Multipart` model. Use `stream` from Bun HTTP handlers when form fields and
226
+ * uploaded files should be consumed incrementally, for example validating text
227
+ * fields while piping large file parts to storage. Use `persisted` when the
228
+ * whole form should be collected into a record and file parts should be written
229
+ * to scoped temporary files through the current `FileSystem`, `Path`, and
230
+ * `Scope` services.
231
+ *
232
+ * Bun requests expose one-shot web streams, so choose one body reader and do
233
+ * not call `formData`, `text`, `json`, or `arrayBuffer` before using this
234
+ * module. Incoming `FormData` uploads must include a `multipart/form-data`
235
+ * content type with the boundary generated by the client; when constructing
236
+ * `FormData` requests, let the runtime set that header. Stream file content for
237
+ * large uploads, reserve `contentEffect` for small files, and treat client
238
+ * filenames as metadata rather than trusted filesystem paths. Persisted file
239
+ * paths remain valid only for the surrounding scope.
240
+ *
241
+ * @since 4.0.0
51
242
  */
52
243
  export * as BunMultipart from "./BunMultipart.ts"
53
244
 
54
245
  /**
55
- * @since 1.0.0
246
+ * Bun layers for Effect's `Path` service.
247
+ *
248
+ * Use this module when an Effect program running on Bun needs path
249
+ * manipulation from the `Path` service, such as joining and normalizing local
250
+ * filesystem locations, resolving configuration or static asset paths, handling
251
+ * CLI path arguments, or converting between filesystem paths and `file:` URLs.
252
+ *
253
+ * Bun exposes Node-compatible path behavior, so these layers reuse the shared
254
+ * Node path implementation. The default `layer` follows the host operating
255
+ * system's path rules, including separators, absolute paths, drive letters, and
256
+ * UNC paths where applicable. Use `layerPosix` or `layerWin32` when code needs
257
+ * stable POSIX or Windows semantics regardless of where Bun is running. These
258
+ * layers only manipulate path strings; they do not read the filesystem, validate
259
+ * that paths exist, or turn request URLs into safe local paths. `BunServices`
260
+ * already includes the default Bun path layer, so provide this module directly
261
+ * when you need only `Path` or one of the platform-specific variants.
262
+ *
263
+ * @since 4.0.0
56
264
  */
57
265
  export * as BunPath from "./BunPath.ts"
58
266
 
59
267
  /**
60
- * @since 1.0.0
268
+ * Bun Redis integration backed by Bun's built-in `RedisClient`.
269
+ *
270
+ * This module provides scoped layers that create a Bun `RedisClient` and expose
271
+ * both the low-level `Redis` service used by Effect persistence modules and the
272
+ * `BunRedis` service for direct access to the underlying client. Use it in Bun
273
+ * applications that need Redis-backed persistence, persisted queues,
274
+ * distributed rate limiting, custom Redis commands, or Bun Redis features such
275
+ * as pub/sub through the raw client.
276
+ *
277
+ * The client is acquired when the layer is built and closed with `close` when
278
+ * the layer scope ends, so install the layer at the lifetime you want for the
279
+ * connection and pass a Redis URL, Bun `RedisOptions`, or `layerConfig` for
280
+ * connection settings. The portable `Redis` service sends ordinary commands
281
+ * through `RedisClient.send`; pub/sub is available through `BunRedis.client`
282
+ * or `BunRedis.use` and should normally use a separately scoped client so a
283
+ * subscription does not interfere with command traffic used by persistence or
284
+ * rate limiter stores.
285
+ *
286
+ * Persistence and rate limiter stores build keys and Lua scripts on top of this
287
+ * service. Choose stable prefixes and store ids to avoid collisions, account
288
+ * for persisted values that may fail to decode after schema changes, and avoid
289
+ * unbounded high-cardinality rate-limit keys unless you have a cleanup or
290
+ * bounding strategy.
291
+ *
292
+ * @since 4.0.0
61
293
  */
62
294
  export * as BunRedis from "./BunRedis.ts"
63
295
 
64
296
  /**
65
- * @since 1.0.0
297
+ * Bun entry-point helpers for running Effect programs.
298
+ *
299
+ * This module exposes `runMain`, the Bun runtime launcher used at the edge of
300
+ * CLIs, scripts, servers, and worker processes. It runs an already
301
+ * self-contained Effect as the process main program, using the shared
302
+ * Node-compatible runtime implementation for error reporting, teardown, and
303
+ * `process` signal handling available in Bun.
304
+ *
305
+ * `BunRuntime` does not provide application services by itself. Provide any
306
+ * required layers, such as `BunServices.layer` or narrower service-specific
307
+ * layers, before passing the effect to `runMain`. On `SIGINT` or `SIGTERM`,
308
+ * the main fiber is interrupted so scoped resources and finalizers can shut
309
+ * down; keep long-running servers, workers, and subscriptions attached to that
310
+ * scope and avoid finalizers that never complete, otherwise process shutdown
311
+ * can be delayed.
312
+ *
313
+ * @since 4.0.0
66
314
  */
67
315
  export * as BunRuntime from "./BunRuntime.ts"
68
316
 
69
317
  /**
70
- * @since 1.0.0
318
+ * Provides the aggregate Bun platform services layer for applications that run
319
+ * on the Bun runtime.
320
+ *
321
+ * This module is useful when an application needs the standard Bun-backed
322
+ * implementations of filesystem access, path operations, stdio, terminal
323
+ * interaction, and child process spawning from a single layer. Provide
324
+ * `BunServices.layer` near the edge of a program to satisfy effects that read
325
+ * or write files, resolve paths, interact with stdin/stdout/stderr or a
326
+ * terminal, or launch subprocesses.
327
+ *
328
+ * The layer only supplies the runtime services listed by `BunServices`; it does
329
+ * not provide unrelated platform services such as HTTP clients, HTTP servers,
330
+ * sockets, workers, or Redis. Several of these core Bun services are backed by
331
+ * the shared Node-compatible implementations used by the Bun adapters, so the
332
+ * default path, stdio, terminal, and subprocess behavior follows the current
333
+ * process and host platform. Libraries should continue to depend on the
334
+ * individual service tags they use, while Bun applications, CLIs, and tests can
335
+ * choose this layer or narrower service-specific layers depending on how much
336
+ * of the Bun runtime they want to expose.
337
+ *
338
+ * @since 4.0.0
71
339
  */
72
340
  export * as BunServices from "./BunServices.ts"
73
341
 
74
342
  /**
75
- * @since 1.0.0
343
+ * @since 4.0.0
76
344
  */
77
345
  export * as BunSink from "./BunSink.ts"
78
346
 
79
347
  /**
80
- * @since 1.0.0
348
+ * Bun platform socket entry point for Effect sockets backed by Bun-compatible
349
+ * Node streams and Bun's native WebSocket implementation.
350
+ *
351
+ * This module re-exports the shared Node socket constructors for TCP clients,
352
+ * Unix domain socket clients, and adapters from existing Node `Duplex` streams,
353
+ * then adds Bun-specific WebSocket layers using `globalThis.WebSocket`. Use it
354
+ * in Bun applications that connect to raw socket protocols, Unix sockets,
355
+ * realtime WebSocket services, or Effect RPC transports that need a
356
+ * `Socket.Socket` layer.
357
+ *
358
+ * TCP lifecycle behavior comes from the shared Node layer: sockets are scoped,
359
+ * finalizers close or destroy the underlying stream, open timeouts become
360
+ * socket open errors, and read, write, and close events are mapped to
361
+ * `SocketError` values. TLS concerns depend on the transport being used: `wss:`
362
+ * URLs are handled by Bun's WebSocket implementation, while TLS-wrapped
363
+ * `Duplex` streams can be adapted after they have been created elsewhere.
364
+ * When closing intentionally, send `Socket.CloseEvent` values so the close code
365
+ * and reason are preserved through the socket lifecycle.
366
+ *
367
+ * @since 4.0.0
81
368
  */
82
369
  export * as BunSocket from "./BunSocket.ts"
83
370
 
84
371
  /**
85
- * @since 1.0.0
372
+ * @since 4.0.0
86
373
  */
87
374
  export * as BunSocketServer from "./BunSocketServer.ts"
88
375
 
89
376
  /**
90
- * @since 1.0.0
377
+ * Bun-backed implementation of Effect's `Stdio` service.
378
+ *
379
+ * This module provides the process stdio layer for Bun applications by reusing
380
+ * the shared Node-compatible implementation. The layer connects `Stdio` to the
381
+ * current Bun process: arguments come from `process.argv`, input is read from
382
+ * `process.stdin`, and output and error output write to `process.stdout` and
383
+ * `process.stderr`. It is intended for CLIs, scripts, command runners, test
384
+ * harnesses, and other process-oriented programs that need standard input and
385
+ * output through Effect services.
386
+ *
387
+ * The underlying stdio streams are global resources owned by the Bun process.
388
+ * The layer keeps stdin open and does not end stdout or stderr by default,
389
+ * which avoids closing handles that prompts, loggers, or other code may still
390
+ * use. Stdio may be attached to a TTY, pipe, or redirected file, so
391
+ * terminal-specific behavior such as raw mode, echo, colors, cursor control,
392
+ * and terminal dimensions should be coordinated with terminal APIs rather than
393
+ * assumed from this layer.
394
+ *
395
+ * @since 4.0.0
91
396
  */
92
397
  export * as BunStdio from "./BunStdio.ts"
93
398
 
94
399
  /**
95
- * @since 1.0.0
400
+ * Bun stream interoperability for Effect streams.
401
+ *
402
+ * This module provides Bun-specific adapters for working with streaming data at
403
+ * the boundary between Bun APIs and Effect. It re-exports the shared Node stream
404
+ * adapters for Bun's Node-compatible stream APIs, and adds an optimized
405
+ * `ReadableStream` constructor that uses Bun's `readMany` support to pull
406
+ * batches of Web Stream values into an Effect `Stream`.
407
+ *
408
+ * Common uses include adapting Bun `Request` and `Response` bodies, multipart
409
+ * uploads, and other Web `ReadableStream` sources so they can be transformed,
410
+ * decoded, or piped with Effect stream operators. Pulling from the Effect stream
411
+ * drives reads from the underlying reader, while Bun and the Web Streams runtime
412
+ * still control their own internal buffering and source backpressure.
413
+ *
414
+ * Web `ReadableStream` readers take an exclusive lock on the source. Request and
415
+ * response bodies are also one-shot: once consumed they become disturbed and
416
+ * should not be read through another API. The adapter cancels the reader when
417
+ * the consuming scope is finalized by default; set `releaseLockOnEnd` when the
418
+ * stream is externally owned and should only have its lock released. Read errors
419
+ * are mapped through the provided `onError` function.
420
+ *
421
+ * @since 4.0.0
96
422
  */
97
423
  export * as BunStream from "./BunStream.ts"
98
424
 
99
425
  /**
100
- * @since 1.0.0
426
+ * Bun-backed implementation of Effect's `Terminal` service.
427
+ *
428
+ * This module provides a scoped, process-backed terminal for Bun programs by
429
+ * adapting the runtime's Node-compatible stdin, stdout, and `readline` support.
430
+ * It is useful for CLIs, prompts, REPLs, and terminal interfaces that need
431
+ * prompt output, line input, keypress input, or terminal dimensions.
432
+ *
433
+ * The service uses the current process streams, so acquire it with a scope or
434
+ * provide `layer` to ensure cleanup. When stdin is attached to a TTY, raw mode
435
+ * is enabled while the terminal is active and restored when the scope closes;
436
+ * this changes how keys are delivered and can affect other consumers of stdin.
437
+ * In pipes, redirected input, or CI, raw mode may be unavailable, keypress input
438
+ * is limited, and stdout dimensions may be reported as zero.
439
+ *
440
+ * @since 4.0.0
101
441
  */
102
442
  export * as BunTerminal from "./BunTerminal.ts"
103
443
 
104
444
  /**
105
- * @since 1.0.0
445
+ * Parent-side Bun support for Effect workers.
446
+ *
447
+ * This module provides the `WorkerPlatform` used by Bun programs that spawn
448
+ * and communicate with `globalThis.Worker` instances through Effect's worker
449
+ * protocol. Pair it with `BunWorkerRunner` in the worker entrypoint when
450
+ * building worker-backed RPC clients, moving CPU-bound work off the main
451
+ * thread, isolating Bun-only services, or hosting long-lived handlers behind a
452
+ * typed message boundary.
453
+ *
454
+ * The supplied spawner is responsible for creating the Bun worker for each
455
+ * numeric worker id. Messages follow Bun's worker cloning and transfer
456
+ * semantics, so payloads and transfer lists must be accepted by the Bun worker
457
+ * runtime. Calls to `send` are buffered until the worker runner posts its ready
458
+ * signal; if the worker entrypoint never starts `BunWorkerRunner`, those
459
+ * buffered messages will not be delivered. Scope finalization sends the Effect
460
+ * worker close signal, waits for Bun's `close` event for a short grace period,
461
+ * and then terminates the worker if graceful shutdown does not complete.
462
+ *
463
+ * @since 4.0.0
106
464
  */
107
465
  export * as BunWorker from "./BunWorker.ts"
108
466
 
109
467
  /**
110
- * @since 1.0.0
468
+ * Bun runtime support for Effect worker runners.
469
+ *
470
+ * This module is intended for code that is already executing inside a Bun
471
+ * `Worker`. It provides the `WorkerRunnerPlatform` used by `WorkerRunner` to
472
+ * receive request messages from the parent, run the registered Effect handler,
473
+ * and send responses back over Bun's worker `postMessage` channel.
474
+ *
475
+ * Use it with `BunWorker` when a Bun program needs to move RPC handlers,
476
+ * CPU-bound computations, or Bun-only services into an isolated worker while
477
+ * communicating through the Effect worker protocol. The runner must be started
478
+ * from the worker entrypoint, not the parent process; startup fails when the
479
+ * current global worker scope does not expose `postMessage`. Shutdown is driven
480
+ * by the parent protocol message, which closes the worker port, so long-running
481
+ * handlers should remain interruptible and keep resource cleanup in scopes.
482
+ * Messages follow Bun's worker cloning and transfer semantics, so payload
483
+ * schemas, transfer lists, `messageerror` events, and worker `error` events
484
+ * should be considered at the boundary.
485
+ *
486
+ * @since 4.0.0
111
487
  */
112
488
  export * as BunWorkerRunner from "./BunWorkerRunner.ts"