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

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 (57) hide show
  1. package/dist/BunClusterHttp.d.ts +26 -2
  2. package/dist/BunClusterHttp.d.ts.map +1 -1
  3. package/dist/BunClusterHttp.js +26 -2
  4. package/dist/BunClusterHttp.js.map +1 -1
  5. package/dist/BunCrypto.d.ts +1 -1
  6. package/dist/BunCrypto.d.ts.map +1 -1
  7. package/dist/BunCrypto.js +10 -2
  8. package/dist/BunCrypto.js.map +1 -1
  9. package/dist/BunHttpServer.d.ts +1 -1
  10. package/dist/BunHttpServer.js +1 -1
  11. package/dist/BunHttpServerRequest.d.ts +1 -1
  12. package/dist/BunHttpServerRequest.js +1 -1
  13. package/dist/BunPath.d.ts.map +1 -1
  14. package/dist/BunPath.js +28 -16
  15. package/dist/BunPath.js.map +1 -1
  16. package/dist/BunRedis.d.ts +27 -18
  17. package/dist/BunRedis.d.ts.map +1 -1
  18. package/dist/BunRedis.js +27 -18
  19. package/dist/BunRedis.js.map +1 -1
  20. package/dist/BunRuntime.d.ts +3 -3
  21. package/dist/BunRuntime.d.ts.map +1 -1
  22. package/dist/BunRuntime.js +29 -16
  23. package/dist/BunRuntime.js.map +1 -1
  24. package/dist/BunStdio.d.ts.map +1 -1
  25. package/dist/BunStdio.js +23 -11
  26. package/dist/BunStdio.js.map +1 -1
  27. package/dist/BunStream.d.ts +2 -2
  28. package/dist/BunStream.d.ts.map +1 -1
  29. package/dist/BunStream.js +27 -18
  30. package/dist/BunStream.js.map +1 -1
  31. package/dist/BunTerminal.d.ts.map +1 -1
  32. package/dist/BunTerminal.js +29 -11
  33. package/dist/BunTerminal.js.map +1 -1
  34. package/dist/BunWorker.d.ts.map +1 -1
  35. package/dist/BunWorker.js +28 -11
  36. package/dist/BunWorker.js.map +1 -1
  37. package/dist/BunWorkerRunner.d.ts.map +1 -1
  38. package/dist/BunWorkerRunner.js +29 -15
  39. package/dist/BunWorkerRunner.js.map +1 -1
  40. package/dist/index.d.ts +0 -373
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +0 -373
  43. package/dist/index.js.map +1 -1
  44. package/package.json +4 -4
  45. package/src/BunClusterHttp.ts +26 -2
  46. package/src/BunCrypto.ts +10 -2
  47. package/src/BunHttpServer.ts +1 -1
  48. package/src/BunHttpServerRequest.ts +1 -1
  49. package/src/BunPath.ts +28 -16
  50. package/src/BunRedis.ts +27 -18
  51. package/src/BunRuntime.ts +29 -16
  52. package/src/BunStdio.ts +23 -11
  53. package/src/BunStream.ts +27 -18
  54. package/src/BunTerminal.ts +29 -11
  55. package/src/BunWorker.ts +28 -11
  56. package/src/BunWorkerRunner.ts +29 -15
  57. package/src/index.ts +0 -373
package/src/BunRedis.ts CHANGED
@@ -1,27 +1,36 @@
1
1
  /**
2
2
  * Bun Redis integration backed by Bun's built-in `RedisClient`.
3
3
  *
4
- * This module provides scoped layers that create a Bun `RedisClient` and expose
5
- * both the low-level `Redis` service used by Effect persistence modules and the
6
- * `BunRedis` service for direct access to the underlying client. Use it in Bun
7
- * applications that need Redis-backed persistence, persisted queues,
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
8
  * distributed rate limiting, custom Redis commands, or Bun Redis features such
9
- * as pub/sub through the raw client.
9
+ * as pub/sub.
10
10
  *
11
- * The client is acquired when the layer is built and closed with `close` when
12
- * the layer scope ends, so install the layer at the lifetime you want for the
13
- * connection and pass a Redis URL, Bun `RedisOptions`, or `layerConfig` for
14
- * connection settings. The portable `Redis` service sends ordinary commands
15
- * through `RedisClient.send`; pub/sub is available through `BunRedis.client`
16
- * or `BunRedis.use` and should normally use a separately scoped client so a
17
- * subscription does not interfere with command traffic used by persistence or
18
- * rate limiter stores.
11
+ * **Mental model**
19
12
  *
20
- * Persistence and rate limiter stores build keys and Lua scripts on top of this
21
- * service. Choose stable prefixes and store ids to avoid collisions, account
22
- * for persisted values that may fail to decode after schema changes, and avoid
23
- * unbounded high-cardinality rate-limit keys unless you have a cleanup or
24
- * bounding strategy.
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.
25
34
  *
26
35
  * @since 4.0.0
27
36
  */
package/src/BunRuntime.ts CHANGED
@@ -1,19 +1,32 @@
1
1
  /**
2
- * Bun entry-point helpers for running Effect programs.
2
+ * Bun process runner for Effect programs.
3
3
  *
4
- * This module exposes `runMain`, the Bun runtime launcher used at the edge of
5
- * CLIs, scripts, servers, and worker processes. It runs an already
6
- * self-contained Effect as the process main program, using the shared
7
- * Node-compatible runtime implementation for error reporting, teardown, and
8
- * `process` signal handling available in Bun.
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.
9
8
  *
10
- * `BunRuntime` does not provide application services by itself. Provide any
11
- * required layers, such as `BunServices.layer` or narrower service-specific
12
- * layers, before passing the effect to `runMain`. On `SIGINT` or `SIGTERM`,
13
- * the main fiber is interrupted so scoped resources and finalizers can shut
14
- * down; keep long-running servers, workers, and subscriptions attached to that
15
- * scope and avoid finalizers that never complete, otherwise process shutdown
16
- * can be delayed.
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.
17
30
  *
18
31
  * @since 4.0.0
19
32
  */
@@ -26,7 +39,7 @@ import type { Teardown } from "effect/Runtime"
26
39
  *
27
40
  * **When to use**
28
41
  *
29
- * Use this function to run an Effect as your application's main program,
42
+ * Use to run an Effect as your application's main program,
30
43
  * especially when you need structured error handling, log management,
31
44
  * interrupt support, or advanced teardown capabilities.
32
45
  *
@@ -52,7 +65,7 @@ export const runMain: {
52
65
  *
53
66
  * **When to use**
54
67
  *
55
- * Use this function to run an Effect as your application's main program,
68
+ * Use to run an Effect as your application's main program,
56
69
  * especially when you need structured error handling, log management,
57
70
  * interrupt support, or advanced teardown capabilities.
58
71
  *
@@ -83,7 +96,7 @@ export const runMain: {
83
96
  *
84
97
  * **When to use**
85
98
  *
86
- * Use this function to run an Effect as your application's main program,
99
+ * Use to run an Effect as your application's main program,
87
100
  * especially when you need structured error handling, log management,
88
101
  * interrupt support, or advanced teardown capabilities.
89
102
  *
package/src/BunStdio.ts CHANGED
@@ -1,21 +1,33 @@
1
1
  /**
2
- * Bun-backed implementation of Effect's `Stdio` service.
2
+ * Process stdio for Bun applications.
3
3
  *
4
- * This module provides the process stdio layer for Bun applications by reusing
5
- * the shared Node-compatible implementation. The layer connects `Stdio` to the
6
- * current Bun process: arguments come from `process.argv`, input is read from
7
- * `process.stdin`, and output and error output write to `process.stdout` and
8
- * `process.stderr`. It is intended for CLIs, scripts, command runners, test
9
- * harnesses, and other process-oriented programs that need standard input and
10
- * output through Effect services.
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**
11
24
  *
12
- * The underlying stdio streams are global resources owned by the Bun process.
13
25
  * The layer keeps stdin open and does not end stdout or stderr by default,
14
26
  * which avoids closing handles that prompts, loggers, or other code may still
15
27
  * use. Stdio may be attached to a TTY, pipe, or redirected file, so
16
28
  * terminal-specific behavior such as raw mode, echo, colors, cursor control,
17
- * and terminal dimensions should be coordinated with terminal APIs rather than
18
- * assumed from this layer.
29
+ * and terminal dimensions should be handled with terminal APIs such as
30
+ * `BunTerminal`, not inferred from this layer.
19
31
  *
20
32
  * @since 4.0.0
21
33
  */
package/src/BunStream.ts CHANGED
@@ -1,24 +1,33 @@
1
1
  /**
2
2
  * Bun stream interoperability for Effect streams.
3
3
  *
4
- * This module provides Bun-specific adapters for working with streaming data at
5
- * the boundary between Bun APIs and Effect. It re-exports the shared Node stream
6
- * adapters for Bun's Node-compatible stream APIs, and adds an optimized
7
- * `ReadableStream` constructor that uses Bun's `readMany` support to pull
8
- * batches of Web Stream values into an Effect `Stream`.
4
+ * This module is the Bun entry point for adapting runtime streams into Effect's
5
+ * streaming model. It re-exports the shared Node stream adapters for Bun's
6
+ * Node-compatible stream APIs and adds {@link fromReadableStream}, a Web
7
+ * `ReadableStream` adapter that uses Bun's `readMany` reader method to pull
8
+ * batches of values into an Effect `Stream`.
9
9
  *
10
- * Common uses include adapting Bun `Request` and `Response` bodies, multipart
11
- * uploads, and other Web `ReadableStream` sources so they can be transformed,
12
- * decoded, or piped with Effect stream operators. Pulling from the Effect stream
13
- * drives reads from the underlying reader, while Bun and the Web Streams runtime
14
- * still control their own internal buffering and source backpressure.
10
+ * **Mental model**
15
11
  *
16
- * Web `ReadableStream` readers take an exclusive lock on the source. Request and
17
- * response bodies are also one-shot: once consumed they become disturbed and
18
- * should not be read through another API. The adapter cancels the reader when
19
- * the consuming scope is finalized by default; set `releaseLockOnEnd` when the
20
- * stream is externally owned and should only have its lock released. Read errors
21
- * are mapped through the provided `onError` function.
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.
22
31
  *
23
32
  * @since 4.0.0
24
33
  */
@@ -37,8 +46,8 @@ import * as Stream from "effect/Stream"
37
46
  export * from "@effect/platform-node-shared/NodeStream"
38
47
 
39
48
  /**
40
- * An optimized version of `Stream.fromReadableStream` that uses the Bun
41
- * .readMany API to read multiple values at once from a `ReadableStream`.
49
+ * Creates a stream from a `ReadableStream` using Bun's optimized `.readMany`
50
+ * API.
42
51
  *
43
52
  * @category constructors
44
53
  * @since 4.0.0
@@ -1,17 +1,35 @@
1
1
  /**
2
2
  * Bun-backed implementation of Effect's `Terminal` service.
3
3
  *
4
- * This module provides a scoped, process-backed terminal for Bun programs by
5
- * adapting the runtime's Node-compatible stdin, stdout, and `readline` support.
6
- * It is useful for CLIs, prompts, REPLs, and terminal interfaces that need
7
- * prompt output, line input, keypress input, or terminal dimensions.
8
- *
9
- * The service uses the current process streams, so acquire it with a scope or
10
- * provide `layer` to ensure cleanup. When stdin is attached to a TTY, raw mode
11
- * is enabled while the terminal is active and restored when the scope closes;
12
- * this changes how keys are delivered and can affect other consumers of stdin.
13
- * In pipes, redirected input, or CI, raw mode may be unavailable, keypress input
14
- * is limited, and stdout dimensions may be reported as zero.
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.
15
33
  *
16
34
  * @since 4.0.0
17
35
  */
package/src/BunWorker.ts CHANGED
@@ -1,21 +1,38 @@
1
1
  /**
2
- * Parent-side Bun support for Effect workers.
2
+ * Parent-side worker support for Bun applications.
3
3
  *
4
- * This module provides the `WorkerPlatform` used by Bun programs that spawn
5
- * and communicate with `globalThis.Worker` instances through Effect's worker
4
+ * This module provides the `WorkerPlatform` used by Bun programs that spawn and
5
+ * communicate with `globalThis.Worker` instances through Effect's worker
6
6
  * protocol. Pair it with `BunWorkerRunner` in the worker entrypoint when
7
7
  * building worker-backed RPC clients, moving CPU-bound work off the main
8
8
  * thread, isolating Bun-only services, or hosting long-lived handlers behind a
9
9
  * typed message boundary.
10
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.
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.
19
36
  *
20
37
  * @since 4.0.0
21
38
  */
@@ -1,21 +1,35 @@
1
1
  /**
2
- * Bun runtime support for Effect worker runners.
2
+ * Worker-entrypoint support for Bun worker runners.
3
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.
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
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.
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.
19
33
  *
20
34
  * @since 4.0.0
21
35
  */