@effect/platform-bun 4.0.0-beta.78 → 4.0.0-beta.79

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 (70) hide show
  1. package/dist/BunClusterHttp.d.ts +5 -31
  2. package/dist/BunClusterHttp.d.ts.map +1 -1
  3. package/dist/BunClusterHttp.js.map +1 -1
  4. package/dist/BunClusterSocket.d.ts +6 -33
  5. package/dist/BunClusterSocket.d.ts.map +1 -1
  6. package/dist/BunClusterSocket.js +6 -33
  7. package/dist/BunClusterSocket.js.map +1 -1
  8. package/dist/BunFileSystem.d.ts.map +1 -1
  9. package/dist/BunFileSystem.js +3 -19
  10. package/dist/BunFileSystem.js.map +1 -1
  11. package/dist/BunHttpPlatform.d.ts.map +1 -1
  12. package/dist/BunHttpPlatform.js.map +1 -1
  13. package/dist/BunHttpServer.d.ts +7 -28
  14. package/dist/BunHttpServer.d.ts.map +1 -1
  15. package/dist/BunHttpServer.js.map +1 -1
  16. package/dist/BunHttpServerRequest.d.ts +4 -20
  17. package/dist/BunHttpServerRequest.d.ts.map +1 -1
  18. package/dist/BunHttpServerRequest.js.map +1 -1
  19. package/dist/BunMultipart.d.ts +3 -15
  20. package/dist/BunMultipart.d.ts.map +1 -1
  21. package/dist/BunMultipart.js.map +1 -1
  22. package/dist/BunPath.d.ts.map +1 -1
  23. package/dist/BunPath.js +0 -22
  24. package/dist/BunPath.js.map +1 -1
  25. package/dist/BunRedis.d.ts +4 -29
  26. package/dist/BunRedis.d.ts.map +1 -1
  27. package/dist/BunRedis.js +4 -29
  28. package/dist/BunRedis.js.map +1 -1
  29. package/dist/BunRuntime.d.ts.map +1 -1
  30. package/dist/BunRuntime.js +3 -26
  31. package/dist/BunRuntime.js.map +1 -1
  32. package/dist/BunServices.d.ts +5 -18
  33. package/dist/BunServices.d.ts.map +1 -1
  34. package/dist/BunServices.js.map +1 -1
  35. package/dist/BunSocket.d.ts +4 -16
  36. package/dist/BunSocket.d.ts.map +1 -1
  37. package/dist/BunSocket.js.map +1 -1
  38. package/dist/BunStdio.d.ts.map +1 -1
  39. package/dist/BunStdio.js +4 -27
  40. package/dist/BunStdio.js.map +1 -1
  41. package/dist/BunStream.d.ts.map +1 -1
  42. package/dist/BunStream.js +0 -22
  43. package/dist/BunStream.js.map +1 -1
  44. package/dist/BunTerminal.d.ts.map +1 -1
  45. package/dist/BunTerminal.js +3 -29
  46. package/dist/BunTerminal.js.map +1 -1
  47. package/dist/BunWorker.d.ts.map +1 -1
  48. package/dist/BunWorker.js +6 -32
  49. package/dist/BunWorker.js.map +1 -1
  50. package/dist/BunWorkerRunner.d.ts.map +1 -1
  51. package/dist/BunWorkerRunner.js +5 -29
  52. package/dist/BunWorkerRunner.js.map +1 -1
  53. package/package.json +4 -4
  54. package/src/BunClusterHttp.ts +5 -31
  55. package/src/BunClusterSocket.ts +6 -33
  56. package/src/BunFileSystem.ts +3 -19
  57. package/src/BunHttpPlatform.ts +5 -19
  58. package/src/BunHttpServer.ts +7 -28
  59. package/src/BunHttpServerRequest.ts +4 -20
  60. package/src/BunMultipart.ts +3 -15
  61. package/src/BunPath.ts +0 -22
  62. package/src/BunRedis.ts +4 -29
  63. package/src/BunRuntime.ts +3 -26
  64. package/src/BunServices.ts +5 -18
  65. package/src/BunSocket.ts +4 -16
  66. package/src/BunStdio.ts +4 -27
  67. package/src/BunStream.ts +0 -22
  68. package/src/BunTerminal.ts +3 -29
  69. package/src/BunWorker.ts +6 -32
  70. package/src/BunWorkerRunner.ts +5 -29
@@ -1,25 +1,9 @@
1
1
  /**
2
2
  * Bun layer for Effect's `FileSystem` service.
3
3
  *
4
- * Use this module at the edge of Bun applications, CLIs, scripts, and tests
5
- * that need real local filesystem access through `effect/FileSystem`: reading
6
- * and writing files, creating directories and temporary files, inspecting
7
- * metadata, managing links, or watching paths for changes. It exposes only the
8
- * Bun `FileSystem` layer; the operations themselves are accessed from the
9
- * `FileSystem` service once the layer is provided, or from `BunServices.layer`
10
- * when the program also needs the standard Bun path, stdio, terminal, and child
11
- * process services.
12
- *
13
- * Bun supports Node-compatible filesystem APIs, so this layer reuses the shared
14
- * Node filesystem implementation. Paths therefore follow the current process and
15
- * host platform rules: relative paths are resolved from the current working
16
- * directory, separators and drive/UNC behavior are platform-dependent, and
17
- * request URLs should be decoded and validated before being mapped to local
18
- * paths. The service works with bytes, scoped file handles, and Effect
19
- * streams/sinks; use `FileSystem.stream` for large files instead of
20
- * `readFile`, and remember that stream offsets and lengths are byte positions.
21
- * Bun `File` and `Blob` values are not filesystem handles here; path-based HTTP
22
- * file responses are handled by the Bun HTTP platform adapter with `Bun.file`.
4
+ * This module exposes one `layer` that provides `FileSystem` in Bun by using
5
+ * the shared Node file-system implementation. Once the layer is provided,
6
+ * programs use the standard `effect/FileSystem` service operations.
23
7
  *
24
8
  * @since 4.0.0
25
9
  */
@@ -1,25 +1,11 @@
1
1
  /**
2
2
  * Bun implementation of the Effect HTTP platform service.
3
3
  *
4
- * This module connects the portable `HttpPlatform` file response helpers to
5
- * Bun's Web-compatible runtime. `BunHttpServer` provides this layer when
6
- * applications serve local files, public assets, downloads, byte ranges, or
7
- * Web `File` values from Effect `HttpServerResponse` constructors.
8
- *
9
- * Path-based responses are backed by `Bun.file`, and Web `File` responses are
10
- * returned directly as raw response bodies. The shared `HttpPlatform` service
11
- * still computes file metadata such as ETags and last-modified headers, while
12
- * this adapter lets Bun's `Response` implementation handle the platform body.
13
- *
14
- * Because the Bun server adapter sits on top of Web `Request` and `Response`,
15
- * request bodies follow the usual single-consumption rules: choose the
16
- * streamed, text, URL-encoded, or multipart view that matches the route. For
17
- * `FormData` responses, let the `Response` constructor create the multipart
18
- * content type and boundary unless you intentionally override it. File
19
- * responses take filesystem paths, not request URLs; Bun request URLs are
20
- * absolute at the runtime edge, and route paths are normalized by
21
- * `BunHttpServer`, so decode and validate URL pathnames before mapping them to
22
- * files.
4
+ * This module provides one `layer` for `HttpPlatform`. It implements file
5
+ * responses with `Bun.file`, supports sliced file responses for byte ranges,
6
+ * and returns Web `File` values as raw HTTP server responses. The layer also
7
+ * provides the Bun file-system layer and ETag generator required by
8
+ * `HttpPlatform`.
23
9
  *
24
10
  * @since 4.0.0
25
11
  */
@@ -1,34 +1,13 @@
1
1
  /**
2
2
  * Bun implementation of the Effect `HttpServer`.
3
3
  *
4
- * This module builds an Effect HTTP server from `Bun.serve`, translating Bun's
5
- * Web `Request` objects into `HttpServerRequest` values and Effect
6
- * `HttpServerResponse` values back into Web `Response` objects. It is the Bun
7
- * runtime entry point for serving `HttpApp`s, streaming responses, file
8
- * responses through `BunHttpPlatform`, multipart requests, and websocket
9
- * endpoints through `HttpServerRequest.upgrade`.
10
- *
11
- * Common use cases include using {@link layer} or {@link layerConfig} to serve
12
- * an application from Bun configuration, {@link layerServer} when only the
13
- * `HttpServer` service is needed, and {@link layerTest} for tests that need an
14
- * ephemeral Bun listener and fetch-compatible client.
15
- *
16
- * Bun supplies absolute request URLs and Web-standard request bodies. This
17
- * adapter stores the normalized path-and-query URL on `HttpServerRequest.url`,
18
- * while the underlying `Request` still follows Web body rules: pick the
19
- * streamed, text, JSON, URL-encoded, or multipart view that matches the route
20
- * instead of consuming the same body in incompatible ways. Because `Bun.serve`
21
- * has a single active `fetch` handler, each `serve` call reloads that handler
22
- * and restores the previous one when the serve scope finalizes.
23
- *
24
- * WebSocket upgrades must happen from the Bun request handler. The
25
- * `HttpServerRequest.upgrade` effect calls `server.upgrade`, fails when Bun says
26
- * the request is not upgradeable, buffers messages that arrive before the
27
- * Effect socket handler is installed, and maps non-normal close codes into
28
- * `Socket` errors. The server is stopped with `server.stop()` when its
29
- * acquisition scope closes; unless preemptive shutdown is disabled, finalizing
30
- * a serve scope also starts that stop with the configured graceful shutdown
31
- * timeout or the default timeout.
4
+ * `make` creates a scoped HTTP server from `Bun.serve`, converting Bun
5
+ * `Request` values into `HttpServerRequest` values and Effect
6
+ * `HttpServerResponse` values back into Web `Response` values. The server
7
+ * supports streaming bodies, multipart requests, file responses through
8
+ * `BunHttpPlatform`, and WebSocket upgrades. This module also provides layers
9
+ * for the server alone, the Bun HTTP support services, the combined server,
10
+ * configurable server options, and a test server with an HTTP client.
32
11
  *
33
12
  * @since 4.0.0
34
13
  */
@@ -1,25 +1,9 @@
1
1
  /**
2
- * Accessors for the Bun `Request` object backing a platform Bun
3
- * `HttpServerRequest`.
2
+ * Accessor for the Bun request behind an Effect HTTP server request.
4
3
  *
5
- * Use this module at interop boundaries when an Effect HTTP handler needs the
6
- * original `Bun.BunRequest`, for example to read Bun route parameters, pass the
7
- * request to Bun-specific APIs, inspect Web `Request` fields that are not
8
- * exposed by the portable `HttpServerRequest` interface, or coordinate with code
9
- * that already works directly with Bun's server request type.
10
- *
11
- * The returned request is the original Web request supplied by `Bun.serve`. It
12
- * does not reflect Effect request overrides made by middleware, such as a
13
- * rewritten URL, adjusted headers, or a substituted remote address. Its body is
14
- * the same one-shot Web `ReadableStream` used by the Effect body helpers, so
15
- * calling `text`, `json`, `formData`, `arrayBuffer`, or reading `body` directly
16
- * can disturb the request and conflict with Effect body, multipart, or stream
17
- * helpers unless ownership of the body is clear.
18
- *
19
- * Bun stores client IP information on the server rather than on the request
20
- * object. Prefer `HttpServerRequest.remoteAddress` when you need the address
21
- * seen by Effect or middleware; the raw request returned here will not expose
22
- * middleware-provided remote address overrides.
4
+ * This module exports `toBunServerRequest`, which returns the underlying
5
+ * `Bun.BunRequest` stored inside a Bun-backed `HttpServerRequest`. It is meant
6
+ * for code that needs to interoperate with Bun-specific request APIs.
23
7
  *
24
8
  * @since 4.0.0
25
9
  */
@@ -2,21 +2,9 @@
2
2
  * Bun-specific helpers for parsing HTTP `multipart/form-data` request bodies.
3
3
  *
4
4
  * This module adapts a Bun `Request` body and headers into the shared
5
- * `Multipart` model. Use `stream` from Bun HTTP handlers when form fields and
6
- * uploaded files should be consumed incrementally, for example validating text
7
- * fields while piping large file parts to storage. Use `persisted` when the
8
- * whole form should be collected into a record and file parts should be written
9
- * to scoped temporary files through the current `FileSystem`, `Path`, and
10
- * `Scope` services.
11
- *
12
- * Bun requests expose one-shot web streams, so choose one body reader and do
13
- * not call `formData`, `text`, `json`, or `arrayBuffer` before using this
14
- * module. Incoming `FormData` uploads must include a `multipart/form-data`
15
- * content type with the boundary generated by the client; when constructing
16
- * `FormData` requests, let the runtime set that header. Stream file content for
17
- * large uploads, reserve `contentEffect` for small files, and treat client
18
- * filenames as metadata rather than trusted filesystem paths. Persisted file
19
- * paths remain valid only for the surrounding scope.
5
+ * `Multipart` model. `stream` returns multipart parts as a `Stream`, while
6
+ * `persisted` collects the form and writes file parts to scoped temporary files
7
+ * through the current `FileSystem`, `Path`, and `Scope` services.
20
8
  *
21
9
  * @since 4.0.0
22
10
  */
package/src/BunPath.ts CHANGED
@@ -6,28 +6,6 @@
6
6
  * Bun code should receive path operations from the Effect environment instead
7
7
  * of importing runtime path helpers directly.
8
8
  *
9
- * **Mental model**
10
- *
11
- * Bun exposes Node-compatible path and file URL behavior, so the default
12
- * {@link layer} follows the host operating system's rules. The
13
- * {@link layerPosix} and {@link layerWin32} variants pin parsing and formatting
14
- * to POSIX or Windows semantics for portable tests, generated paths, and
15
- * cross-platform tooling.
16
- *
17
- * **Common tasks**
18
- *
19
- * Use {@link layer} for normal Bun applications and CLIs. Use
20
- * {@link layerPosix} or {@link layerWin32} when code must produce stable path
21
- * syntax regardless of the machine running Bun. `BunServices.layer` already
22
- * includes {@link layer}, so import this module directly when only `Path` or a
23
- * fixed platform variant is needed.
24
- *
25
- * **Gotchas**
26
- *
27
- * Path operations are syntactic. They normalize and convert strings and
28
- * `file:` URLs, but they do not read the filesystem, check permissions, confirm
29
- * that a path exists, or make request URLs safe to use as local paths.
30
- *
31
9
  * @since 4.0.0
32
10
  */
33
11
  import * as NodePath from "@effect/platform-node-shared/NodePath"
package/src/BunRedis.ts CHANGED
@@ -2,35 +2,10 @@
2
2
  * Bun Redis integration backed by Bun's built-in `RedisClient`.
3
3
  *
4
4
  * This module creates scoped Bun `RedisClient` connections and exposes them as
5
- * both the portable `Redis` service used by Effect persistence modules and the
6
- * Bun-specific `BunRedis` service for direct access to the raw client. Use it in
7
- * Bun applications that need Redis-backed persistence, persisted queues,
8
- * distributed rate limiting, custom Redis commands, or Bun Redis features such
9
- * as pub/sub.
10
- *
11
- * **Mental model**
12
- *
13
- * `layer` and `layerConfig` acquire one `RedisClient` for the layer scope. The
14
- * same client backs the portable `Redis.Redis` command interface and the
15
- * `BunRedis` service, and it is closed with `close` when the scope finalizes.
16
- * Install the layer at the lifetime you want for that connection.
17
- *
18
- * **Common tasks**
19
- *
20
- * Pass a Redis URL or Bun `RedisOptions` to `layer` for direct configuration,
21
- * or use `layerConfig` when connection settings should come from Effect
22
- * configuration. Depend on `Redis.Redis` for persistence and rate limiter
23
- * stores. Depend on `BunRedis` when you need `RedisClient` features that are
24
- * not exposed by the portable service, including custom commands and pub/sub.
25
- *
26
- * **Gotchas**
27
- *
28
- * Pub/sub should normally use a separately scoped client so a subscription does
29
- * not interfere with ordinary command traffic. Persistence and rate limiter
30
- * stores build keys and Lua scripts on top of this service, so choose stable
31
- * prefixes and store ids, account for persisted values that may fail to decode
32
- * after schema changes, and avoid unbounded high-cardinality rate-limit keys
33
- * without a cleanup or bounding strategy.
5
+ * both the portable `Redis` service and the Bun-specific `BunRedis` service for
6
+ * direct access to the raw client. The `layer` helper accepts Redis options
7
+ * directly, while `layerConfig` reads them from Effect config. Both close the
8
+ * underlying client when the layer scope finalizes.
34
9
  *
35
10
  * @since 4.0.0
36
11
  */
package/src/BunRuntime.ts CHANGED
@@ -1,32 +1,9 @@
1
1
  /**
2
2
  * Bun process runner for Effect programs.
3
3
  *
4
- * This module exposes Bun's `runMain` entry point. It is the function to call
5
- * at the outer edge of a Bun CLI, script, server, or worker when a single
6
- * Effect should become the process main fiber and use Bun's Node-compatible
7
- * process, signal, and teardown behavior.
8
- *
9
- * **Mental model**
10
- *
11
- * `runMain` delegates to the shared Node-compatible runner. It starts the
12
- * supplied Effect as the process root, reports failures through the configured
13
- * runtime reporting, and translates `SIGINT` or `SIGTERM` into interruption so
14
- * scoped resources can finalize before teardown chooses an exit code.
15
- *
16
- * **Common tasks**
17
- *
18
- * - Launch a Bun CLI or one-off script from an Effect.
19
- * - Start a long-running Bun server or worker under an Effect scope.
20
- * - Customize error reporting or teardown with `runMain` options.
21
- * - Provide `BunServices.layer` or narrower layers before calling `runMain`.
22
- *
23
- * **Gotchas**
24
- *
25
- * This module runs the program; it does not provide filesystem, network,
26
- * terminal, or other platform services. Long-lived servers, subscriptions, and
27
- * worker loops should be acquired in Effect scopes so interruption from process
28
- * signals can release them. Finalizers that never complete can keep shutdown
29
- * waiting.
4
+ * This module exports `runMain`, which runs one Effect as the main process
5
+ * fiber in Bun. It reuses the shared Node runtime runner, including its error
6
+ * reporting, signal handling, and optional teardown behavior.
30
7
  *
31
8
  * @since 4.0.0
32
9
  */
@@ -1,23 +1,10 @@
1
1
  /**
2
- * Provides the aggregate Bun platform services layer for applications that run
3
- * on the Bun runtime.
2
+ * Aggregate Bun platform services layer.
4
3
  *
5
- * This module is useful when an application needs the standard Bun-backed
6
- * implementations of filesystem access, path operations, stdio, terminal
7
- * interaction, and child process spawning from a single layer. Provide
8
- * `BunServices.layer` near the edge of a program to satisfy effects that read
9
- * or write files, resolve paths, interact with stdin/stdout/stderr or a
10
- * terminal, or launch subprocesses.
11
- *
12
- * The layer only supplies the runtime services listed by `BunServices`; it does
13
- * not provide unrelated platform services such as HTTP clients, HTTP servers,
14
- * sockets, workers, or Redis. Several of these core Bun services are backed by
15
- * the shared Node-compatible implementations used by the Bun adapters, so the
16
- * default path, stdio, terminal, and subprocess behavior follows the current
17
- * process and host platform. Libraries should continue to depend on the
18
- * individual service tags they use, while Bun applications, CLIs, and tests can
19
- * choose this layer or narrower service-specific layers depending on how much
20
- * of the Bun runtime they want to expose.
4
+ * This module defines the `BunServices` union and a single `layer` that
5
+ * provides Bun-backed child process spawning, crypto, filesystem, path, stdio,
6
+ * and terminal services. Use the layer when a Bun program wants the standard
7
+ * platform services from one place.
21
8
  *
22
9
  * @since 4.0.0
23
10
  */
package/src/BunSocket.ts CHANGED
@@ -1,22 +1,10 @@
1
1
  /**
2
- * Bun platform socket entry point for Effect sockets backed by Bun-compatible
3
- * Node streams and Bun's native WebSocket implementation.
2
+ * Bun platform socket entry point for Effect sockets.
4
3
  *
5
4
  * This module re-exports the shared Node socket constructors for TCP clients,
6
- * Unix domain socket clients, and adapters from existing Node `Duplex` streams,
7
- * then adds Bun-specific WebSocket layers using `globalThis.WebSocket`. Use it
8
- * in Bun applications that connect to raw socket protocols, Unix sockets,
9
- * realtime WebSocket services, or Effect RPC transports that need a
10
- * `Socket.Socket` layer.
11
- *
12
- * TCP lifecycle behavior comes from the shared Node layer: sockets are scoped,
13
- * finalizers close or destroy the underlying stream, open timeouts become
14
- * socket open errors, and read, write, and close events are mapped to
15
- * `SocketError` values. TLS concerns depend on the transport being used: `wss:`
16
- * URLs are handled by Bun's WebSocket implementation, while TLS-wrapped
17
- * `Duplex` streams can be adapted after they have been created elsewhere.
18
- * When closing intentionally, send `Socket.CloseEvent` values so the close code
19
- * and reason are preserved through the socket lifecycle.
5
+ * Unix domain socket clients, and adapters from existing Node `Duplex` streams.
6
+ * It also provides Bun WebSocket layers using `globalThis.WebSocket`, including
7
+ * a constructor layer and a `Socket.Socket` layer for a WebSocket URL.
20
8
  *
21
9
  * @since 4.0.0
22
10
  */
package/src/BunStdio.ts CHANGED
@@ -1,33 +1,10 @@
1
1
  /**
2
2
  * Process stdio for Bun applications.
3
3
  *
4
- * This module provides the Bun layer for Effect's `Stdio` service by adapting
5
- * the current process arguments and standard streams. Arguments come from
6
- * `process.argv`, input is read from `process.stdin`, and output and error
7
- * output write to `process.stdout` and `process.stderr`.
8
- *
9
- * **Mental model**
10
- *
11
- * `BunStdio.layer` is a thin Bun-facing wrapper around the shared
12
- * Node-compatible stdio implementation. It does not create private streams for
13
- * an application; it exposes the global streams owned by the running Bun
14
- * process through the `Stdio` service.
15
- *
16
- * **Common tasks**
17
- *
18
- * - Provide `Stdio` for Bun CLIs, scripts, command runners, and tests.
19
- * - Read process arguments or standard input through Effect services.
20
- * - Write normal output and diagnostics without depending directly on
21
- * `process.stdout` or `process.stderr`.
22
- *
23
- * **Gotchas**
24
- *
25
- * The layer keeps stdin open and does not end stdout or stderr by default,
26
- * which avoids closing handles that prompts, loggers, or other code may still
27
- * use. Stdio may be attached to a TTY, pipe, or redirected file, so
28
- * terminal-specific behavior such as raw mode, echo, colors, cursor control,
29
- * and terminal dimensions should be handled with terminal APIs such as
30
- * `BunTerminal`, not inferred from this layer.
4
+ * This module provides the Bun layer for Effect's `Stdio` service by using the
5
+ * shared Node stdio implementation. Arguments come from `process.argv`, input
6
+ * is read from `process.stdin`, and output and error output write to
7
+ * `process.stdout` and `process.stderr`.
31
8
  *
32
9
  * @since 4.0.0
33
10
  */
package/src/BunStream.ts CHANGED
@@ -7,28 +7,6 @@
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
- * **Mental model**
11
- *
12
- * Consuming the returned `Stream` drives reads from the underlying
13
- * `ReadableStreamDefaultReader`. Each pull asks Bun for the next batch, empty
14
- * batches are skipped, read failures are translated with `onError`, and the
15
- * reader is finalized with the surrounding Effect scope.
16
- *
17
- * **Common tasks**
18
- *
19
- * Use {@link fromReadableStream} for Bun `Request` and `Response` bodies,
20
- * multipart uploads, and other Web stream sources that should be transformed,
21
- * decoded, or piped with Effect stream operators. Use the re-exported Node
22
- * stream adapters for APIs that expose Bun's Node-compatible `stream` types.
23
- *
24
- * **Gotchas**
25
- *
26
- * Web stream readers hold an exclusive lock. Request and response bodies are
27
- * also one-shot; once consumed they are disturbed and should not be read through
28
- * another API. By default finalization cancels the reader; set
29
- * `releaseLockOnEnd` when the stream is externally owned and only the reader
30
- * lock should be released.
31
- *
32
10
  * @since 4.0.0
33
11
  */
34
12
  import * as Arr from "effect/Array"
@@ -1,35 +1,9 @@
1
1
  /**
2
2
  * Bun-backed implementation of Effect's `Terminal` service.
3
3
  *
4
- * This module adapts Bun's Node-compatible `stdin`, `stdout`, and `readline`
5
- * support into a scoped `Terminal` service. It is intended for Bun CLIs,
6
- * prompts, REPLs, and terminal interfaces that need prompt output, line input,
7
- * keypress input, or terminal dimensions through Effect services.
8
- *
9
- * **Mental model**
10
- *
11
- * - {@link make} creates a scoped terminal from the current process streams.
12
- * - {@link layer} provides the default live terminal service for Bun programs.
13
- * - The implementation reuses the shared Node-compatible terminal adapter, so
14
- * behavior follows the capabilities of Bun's process streams and readline
15
- * support.
16
- *
17
- * **Common tasks**
18
- *
19
- * - Provide terminal access at the edge of a Bun CLI with {@link layer}.
20
- * - Customize which key ends keypress input by calling {@link make} directly.
21
- * - Read lines, read keypresses, display prompts, and inspect terminal size
22
- * through the `Terminal` service once it is provided.
23
- *
24
- * **Gotchas**
25
- *
26
- * - The service uses global process streams. Acquire it with a scope, or
27
- * provide {@link layer}, so raw mode and readline listeners are cleaned up.
28
- * - When `stdin` is a TTY, raw mode is enabled while the terminal is active and
29
- * restored when the scope closes; this changes how keys are delivered and can
30
- * affect other stdin consumers.
31
- * - In pipes, redirected input, or CI, raw mode may be unavailable, keypress
32
- * input is limited, and stdout dimensions may be reported as zero.
4
+ * This module reuses the shared Node terminal implementation for Bun. `make`
5
+ * creates a scoped process-backed `Terminal` service, and `layer` provides the
6
+ * default terminal service with the standard quit behavior for key input.
33
7
  *
34
8
  * @since 4.0.0
35
9
  */
package/src/BunWorker.ts CHANGED
@@ -1,38 +1,12 @@
1
1
  /**
2
2
  * Parent-side worker support for Bun applications.
3
3
  *
4
- * This module provides the `WorkerPlatform` used by Bun programs that spawn and
5
- * 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
- * **Mental model**
12
- *
13
- * `layer(spawn)` installs both the Bun `WorkerPlatform` and a `Worker.Spawner`.
14
- * The supplied `spawn` function creates the Bun worker for each numeric worker
15
- * id. The platform listens for worker messages and errors, wraps outgoing data
16
- * in the Effect worker protocol, and buffers `send` calls until the worker
17
- * runner posts its ready signal.
18
- *
19
- * **Common tasks**
20
- *
21
- * - Run Effect worker clients in a Bun parent process.
22
- * - Move RPC handlers, CPU-bound computations, or Bun-only services into a
23
- * dedicated worker.
24
- * - Provide custom worker creation logic while keeping message handling and
25
- * cleanup inside Effect scopes.
26
- *
27
- * **Gotchas**
28
- *
29
- * This module is for the parent side only; the worker entrypoint must start
30
- * `BunWorkerRunner`. If the runner never starts or never posts readiness,
31
- * buffered messages will not be delivered. Payloads and transfer lists use
32
- * Bun's worker cloning and transfer semantics, so they must be accepted by the
33
- * Bun worker runtime. Scope finalization sends the Effect worker close signal,
34
- * waits for Bun's `close` event for a short grace period, and then terminates
35
- * the worker if graceful shutdown does not complete.
4
+ * `layerPlatform` provides the `WorkerPlatform` used to communicate with
5
+ * `globalThis.Worker` instances through Effect's worker protocol. `layer`
6
+ * combines that platform with a `Spawner` built from a callback that creates a
7
+ * worker for each worker id. The platform forwards worker messages and errors,
8
+ * asks workers to close on scope finalization, and terminates them if graceful
9
+ * shutdown times out.
36
10
  *
37
11
  * @since 4.0.0
38
12
  */
@@ -1,35 +1,11 @@
1
1
  /**
2
2
  * Worker-entrypoint support for Bun worker runners.
3
3
  *
4
- * This module provides the Bun `WorkerRunnerPlatform` for code already running
5
- * inside a Bun `Worker`. It receives request messages from the parent-side
6
- * `BunWorker` platform, runs the handler registered with `WorkerRunner.run`,
7
- * and posts responses back through Bun's worker `postMessage` channel.
8
- *
9
- * **Mental model**
10
- *
11
- * The parent process installs `BunWorker.layer`; the worker entrypoint installs
12
- * this `layer` and starts `WorkerRunner`. Bun exposes one worker port to this
13
- * runner, so every message uses port id `0`. The first message sent by this
14
- * layer is the ready signal consumed by the parent platform before buffered
15
- * sends are flushed.
16
- *
17
- * **Common tasks**
18
- *
19
- * - Host Effect worker or RPC handlers inside a Bun worker entrypoint.
20
- * - Move CPU-bound work or Bun-only services behind Effect's worker protocol.
21
- * - Send structured-clone payloads and transferables back to the parent with
22
- * `WorkerRunner.send`.
23
- *
24
- * **Gotchas**
25
- *
26
- * Start this layer only in the worker entrypoint; it fails when
27
- * `self.postMessage` is unavailable. Parent shutdown arrives as the worker
28
- * close message and closes the port, so long-running handlers should stay
29
- * interruptible and keep cleanup in scopes. Payloads, transfer lists, and
30
- * `messageerror` events follow Bun's worker runtime behavior.
31
- *
32
- * @see {@link layer} for the Bun worker-runner platform layer.
4
+ * This module exports a `layer` that provides `WorkerRunnerPlatform` for code
5
+ * already running inside a Bun `Worker`. The platform receives request messages
6
+ * from the parent-side `BunWorker` platform, runs the registered handler, sends
7
+ * responses through the worker `postMessage` channel, and closes when the
8
+ * parent sends the close message.
33
9
  *
34
10
  * @since 4.0.0
35
11
  */