@effect/platform-bun 4.0.0-beta.66 → 4.0.0-beta.68

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 +44 -7
  4. package/dist/BunClusterHttp.d.ts.map +1 -1
  5. package/dist/BunClusterHttp.js +10 -6
  6. package/dist/BunClusterHttp.js.map +1 -1
  7. package/dist/BunClusterSocket.d.ts +48 -9
  8. package/dist/BunClusterSocket.d.ts.map +1 -1
  9. package/dist/BunClusterSocket.js +48 -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 +59 -14
  26. package/dist/BunHttpServer.d.ts.map +1 -1
  27. package/dist/BunHttpServer.js +24 -12
  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 +8 -4
  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 +37 -7
  42. package/dist/BunRedis.d.ts.map +1 -1
  43. package/dist/BunRedis.js +37 -7
  44. package/dist/BunRedis.js.map +1 -1
  45. package/dist/BunRuntime.d.ts +6 -6
  46. package/dist/BunRuntime.d.ts.map +1 -1
  47. package/dist/BunRuntime.js +19 -3
  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 +28 -3
  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 +24 -2
  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 +44 -7
  88. package/src/BunClusterSocket.ts +48 -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 +59 -14
  94. package/src/BunHttpServerRequest.ts +26 -2
  95. package/src/BunMultipart.ts +28 -5
  96. package/src/BunPath.ts +30 -7
  97. package/src/BunRedis.ts +37 -7
  98. package/src/BunRuntime.ts +23 -7
  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 +28 -3
  107. package/src/BunWorkerRunner.ts +24 -2
  108. package/src/index.ts +397 -21
package/src/BunSink.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  /**
6
- * @since 1.0.0
6
+ * @since 4.0.0
7
7
  */
8
8
  export * from "@effect/platform-node-shared/NodeSink"
package/src/BunSocket.ts CHANGED
@@ -1,5 +1,24 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Bun platform socket entry point for Effect sockets backed by Bun-compatible
3
+ * Node streams and Bun's native WebSocket implementation.
4
+ *
5
+ * 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.
20
+ *
21
+ * @since 4.0.0
3
22
  */
4
23
  import type * as Duration from "effect/Duration"
5
24
  import type { Effect } from "effect/Effect"
@@ -8,13 +27,16 @@ import * as Layer from "effect/Layer"
8
27
  import * as Socket from "effect/unstable/socket/Socket"
9
28
 
10
29
  /**
11
- * @since 1.0.0
30
+ * @since 4.0.0
12
31
  */
13
32
  export * from "@effect/platform-node-shared/NodeSocket"
14
33
 
15
34
  /**
16
- * @since 1.0.0
35
+ * Provides a `Socket.WebSocketConstructor` backed by Bun's global
36
+ * `WebSocket` implementation.
37
+ *
17
38
  * @category layers
39
+ * @since 4.0.0
18
40
  */
19
41
  export const layerWebSocketConstructor: Layer.Layer<
20
42
  Socket.WebSocketConstructor
@@ -23,8 +45,12 @@ export const layerWebSocketConstructor: Layer.Layer<
23
45
  )
24
46
 
25
47
  /**
26
- * @since 1.0.0
48
+ * Creates a `Socket.Socket` layer for a WebSocket URL using Bun's global
49
+ * `WebSocket` constructor, honoring protocol, open-timeout, and close-code
50
+ * error options.
51
+ *
27
52
  * @category layers
53
+ * @since 4.0.0
28
54
  */
29
55
  export const layerWebSocket: (
30
56
  url: string | Effect<string>,
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  /**
6
- * @since 1.0.0
6
+ * @since 4.0.0
7
7
  */
8
8
  export * from "@effect/platform-node-shared/NodeSocketServer"
package/src/BunStdio.ts CHANGED
@@ -1,12 +1,33 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Bun-backed implementation of Effect's `Stdio` service.
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.
11
+ *
12
+ * The underlying stdio streams are global resources owned by the Bun process.
13
+ * The layer keeps stdin open and does not end stdout or stderr by default,
14
+ * which avoids closing handles that prompts, loggers, or other code may still
15
+ * use. Stdio may be attached to a TTY, pipe, or redirected file, so
16
+ * 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.
19
+ *
20
+ * @since 4.0.0
3
21
  */
4
22
  import * as NodeStdio from "@effect/platform-node-shared/NodeStdio"
5
23
  import type * as Layer from "effect/Layer"
6
24
  import type { Stdio } from "effect/Stdio"
7
25
 
8
26
  /**
9
- * @since 1.0.0
10
- * @category layer
27
+ * Provides the `Stdio` service backed by the current process arguments,
28
+ * stdin, stdout, and stderr streams.
29
+ *
30
+ * @category layers
31
+ * @since 4.0.0
11
32
  */
12
33
  export const layer: Layer.Layer<Stdio> = NodeStdio.layer
package/src/BunStream.ts CHANGED
@@ -1,5 +1,26 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Bun stream interoperability for Effect streams.
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`.
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.
15
+ *
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.
22
+ *
23
+ * @since 4.0.0
3
24
  */
4
25
  import * as Arr from "effect/Array"
5
26
  import * as Cause from "effect/Cause"
@@ -11,7 +32,7 @@ import * as Scope from "effect/Scope"
11
32
  import * as Stream from "effect/Stream"
12
33
 
13
34
  /**
14
- * @since 1.0.0
35
+ * @since 4.0.0
15
36
  */
16
37
  export * from "@effect/platform-node-shared/NodeStream"
17
38
 
@@ -19,7 +40,8 @@ export * from "@effect/platform-node-shared/NodeStream"
19
40
  * An optimized version of `Stream.fromReadableStream` that uses the Bun
20
41
  * .readMany API to read multiple values at once from a `ReadableStream`.
21
42
  *
22
- * @since 1.0.0
43
+ * @category constructors
44
+ * @since 4.0.0
23
45
  */
24
46
  export const fromReadableStream = <A, E>(
25
47
  options: {
@@ -1,5 +1,19 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Bun-backed implementation of Effect's `Terminal` service.
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.
15
+ *
16
+ * @since 4.0.0
3
17
  */
4
18
  import * as NodeTerminal from "@effect/platform-node-shared/NodeTerminal"
5
19
  import type { Effect } from "effect/Effect"
@@ -8,13 +22,19 @@ import type { Scope } from "effect/Scope"
8
22
  import type { Terminal, UserInput } from "effect/Terminal"
9
23
 
10
24
  /**
11
- * @since 1.0.0
25
+ * Creates a scoped `Terminal` service backed by process stdin/stdout, using the
26
+ * optional predicate to decide when key input should end the input stream.
27
+ *
12
28
  * @category constructors
29
+ * @since 4.0.0
13
30
  */
14
31
  export const make: (shouldQuit?: (input: UserInput) => boolean) => Effect<Terminal, never, Scope> = NodeTerminal.make
15
32
 
16
33
  /**
17
- * @since 1.0.0
34
+ * Provides the default process-backed `Terminal` service, ending key input on
35
+ * the default quit keys.
36
+ *
18
37
  * @category layers
38
+ * @since 4.0.0
19
39
  */
20
40
  export const layer: Layer<Terminal> = NodeTerminal.layer
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>()({
@@ -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>() {