@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
@@ -1,5 +1,24 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Bun-specific helpers for parsing HTTP `multipart/form-data` request bodies.
3
+ *
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.
20
+ *
21
+ * @since 4.0.0
3
22
  */
4
23
  import type * as Effect from "effect/Effect"
5
24
  import type { FileSystem } from "effect/FileSystem"
@@ -10,20 +29,31 @@ import * as Multipart from "effect/unstable/http/Multipart"
10
29
  import * as BunStream from "./BunStream.ts"
11
30
 
12
31
  /**
13
- * @since 1.0.0
14
- * @category Constructors
32
+ * Parses a Bun `Request` body as multipart data and returns a stream of multipart parts.
33
+ *
34
+ * @category constructors
35
+ * @since 4.0.0
15
36
  */
16
37
  export const stream = (source: Request): Stream.Stream<Multipart.Part, Multipart.MultipartError> =>
17
38
  BunStream.fromReadableStream({
18
- evaluate: () => source.body!,
39
+ evaluate: () => source.body ?? emptyReadbleStream,
19
40
  onError: (cause) => Multipart.MultipartError.fromReason("InternalError", cause)
20
41
  }).pipe(
21
42
  Stream.pipeThroughChannel(Multipart.makeChannel(Object.fromEntries(source.headers)))
22
43
  )
23
44
 
45
+ const emptyReadbleStream = new ReadableStream({
46
+ start(controller) {
47
+ controller.enqueue(new Uint8Array())
48
+ controller.close()
49
+ }
50
+ })
51
+
24
52
  /**
25
- * @since 1.0.0
26
- * @category Constructors
53
+ * Parses and persists multipart data from a Bun `Request`, requiring file-system, path, and scope services.
54
+ *
55
+ * @category constructors
56
+ * @since 4.0.0
27
57
  */
28
58
  export const persisted = (
29
59
  source: Request
package/src/BunPath.ts CHANGED
@@ -1,24 +1,47 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Bun layers for Effect's `Path` service.
3
+ *
4
+ * Use this module when an Effect program running on Bun needs path
5
+ * manipulation from the `Path` service, such as joining and normalizing local
6
+ * filesystem locations, resolving configuration or static asset paths, handling
7
+ * CLI path arguments, or converting between filesystem paths and `file:` URLs.
8
+ *
9
+ * Bun exposes Node-compatible path behavior, so these layers reuse the shared
10
+ * Node path implementation. The default `layer` follows the host operating
11
+ * system's path rules, including separators, absolute paths, drive letters, and
12
+ * UNC paths where applicable. Use `layerPosix` or `layerWin32` when code needs
13
+ * stable POSIX or Windows semantics regardless of where Bun is running. These
14
+ * layers only manipulate path strings; they do not read the filesystem, validate
15
+ * that paths exist, or turn request URLs into safe local paths. `BunServices`
16
+ * already includes the default Bun path layer, so provide this module directly
17
+ * when you need only `Path` or one of the platform-specific variants.
18
+ *
19
+ * @since 4.0.0
3
20
  */
4
21
  import * as NodePath from "@effect/platform-node-shared/NodePath"
5
22
  import type * as Layer from "effect/Layer"
6
23
  import type { Path } from "effect/Path"
7
24
 
8
25
  /**
9
- * @since 1.0.0
10
- * @category layer
26
+ * Layer that provides the default `Path` service for Bun using the shared Node path implementation.
27
+ *
28
+ * @category layers
29
+ * @since 4.0.0
11
30
  */
12
31
  export const layer: Layer.Layer<Path> = NodePath.layer
13
32
 
14
33
  /**
15
- * @since 1.0.0
16
- * @category layer
34
+ * Layer that provides the POSIX `Path` service for Bun using the shared Node path implementation.
35
+ *
36
+ * @category layers
37
+ * @since 4.0.0
17
38
  */
18
39
  export const layerPosix: Layer.Layer<Path> = NodePath.layerPosix
19
40
 
20
41
  /**
21
- * @since 1.0.0
22
- * @category layer
42
+ * Layer that provides the Win32 `Path` service for Bun using the shared Node path implementation.
43
+ *
44
+ * @category layers
45
+ * @since 4.0.0
23
46
  */
24
47
  export const layerWin32: Layer.Layer<Path> = NodePath.layerWin32
package/src/BunRedis.ts CHANGED
@@ -1,20 +1,46 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Bun Redis integration backed by Bun's built-in `RedisClient`.
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,
8
+ * distributed rate limiting, custom Redis commands, or Bun Redis features such
9
+ * as pub/sub through the raw client.
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.
19
+ *
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.
25
+ *
26
+ * @since 4.0.0
3
27
  */
4
28
  import { RedisClient, type RedisOptions } from "bun"
5
29
  import * as Config from "effect/Config"
30
+ import * as Context from "effect/Context"
6
31
  import * as Effect from "effect/Effect"
7
32
  import * as Fn from "effect/Function"
8
33
  import * as Layer from "effect/Layer"
9
34
  import * as Scope from "effect/Scope"
10
- import * as ServiceMap from "effect/ServiceMap"
11
35
  import * as Redis from "effect/unstable/persistence/Redis"
12
36
 
13
37
  /**
14
- * @since 1.0.0
15
- * @category Service
38
+ * Service tag for Bun Redis integration, exposing the raw `RedisClient` and a `use` helper that maps client promise failures to `RedisError`.
39
+ *
40
+ * @category services
41
+ * @since 4.0.0
16
42
  */
17
- export class BunRedis extends ServiceMap.Service<BunRedis, {
43
+ export class BunRedis extends Context.Service<BunRedis, {
18
44
  readonly client: RedisClient
19
45
  readonly use: <A>(f: (client: RedisClient) => Promise<A>) => Effect.Effect<A, Redis.RedisError>
20
46
  }>()("@effect/platform-bun/BunRedis") {}
@@ -47,28 +73,32 @@ const make = Effect.fnUntraced(function*(
47
73
  use
48
74
  })
49
75
 
50
- return ServiceMap.make(BunRedis, bunRedis).pipe(
51
- ServiceMap.add(Redis.Redis, redis)
76
+ return Context.make(BunRedis, bunRedis).pipe(
77
+ Context.add(Redis.Redis, redis)
52
78
  )
53
79
  })
54
80
 
55
81
  /**
56
- * @since 1.0.0
57
- * @category Layers
82
+ * Creates scoped Bun Redis layers for `Redis.Redis` and `BunRedis`, closing the underlying client when the scope finalizes.
83
+ *
84
+ * @category layers
85
+ * @since 4.0.0
58
86
  */
59
87
  export const layer = (
60
88
  options?: ({ readonly url?: string } & RedisOptions) | undefined
61
- ): Layer.Layer<Redis.Redis | BunRedis> => Layer.effectServices(make(options))
89
+ ): Layer.Layer<Redis.Redis | BunRedis> => Layer.effectContext(make(options))
62
90
 
63
91
  /**
64
- * @since 1.0.0
65
- * @category Layers
92
+ * Creates scoped Bun Redis layers from configurable Redis options, closing the underlying client when the scope finalizes.
93
+ *
94
+ * @category layers
95
+ * @since 4.0.0
66
96
  */
67
97
  export const layerConfig = (
68
98
  options: Config.Wrap<{ readonly url?: string } & RedisOptions>
69
99
  ): Layer.Layer<Redis.Redis | BunRedis, Config.ConfigError> =>
70
- Layer.effectServices(
71
- Config.unwrap(options).asEffect().pipe(
100
+ Layer.effectContext(
101
+ Config.unwrap(options).pipe(
72
102
  Effect.flatMap(make)
73
103
  )
74
104
  )
package/src/BunRuntime.ts CHANGED
@@ -1,5 +1,21 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Bun entry-point helpers for running Effect programs.
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.
9
+ *
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.
17
+ *
18
+ * @since 4.0.0
3
19
  */
4
20
  import * as NodeRuntime from "@effect/platform-node-shared/NodeRuntime"
5
21
  import type { Effect } from "effect/Effect"
@@ -8,6 +24,12 @@ import type { Teardown } from "effect/Runtime"
8
24
  /**
9
25
  * Helps you run a main effect with built-in error handling, logging, and signal management.
10
26
  *
27
+ * **When to use**
28
+ *
29
+ * Use this function to run an Effect as your application's main program,
30
+ * especially when you need structured error handling, log management,
31
+ * interrupt support, or advanced teardown capabilities.
32
+ *
11
33
  * **Details**
12
34
  *
13
35
  * This function launches an Effect as the main entry point, setting exit codes
@@ -16,26 +38,24 @@ import type { Teardown } from "effect/Runtime"
16
38
  * behaviors can be turned off. You can also provide custom teardown logic to
17
39
  * finalize resources or produce different exit codes.
18
40
  *
19
- * **Options**
20
- *
21
41
  * An optional object that can include:
22
42
  * - `disableErrorReporting`: Turn off automatic error logging.
23
43
  * - `disablePrettyLogger`: Avoid adding the pretty logger.
24
44
  * - `teardown`: Provide custom finalization logic.
25
45
  *
26
- * **When to Use**
27
- *
28
- * Use this function to run an Effect as your application’s main program, especially
29
- * when you need structured error handling, log management, interrupt support,
30
- * or advanced teardown capabilities.
31
- *
32
- * @since 1.0.0
33
- * @category Run main
46
+ * @category running
47
+ * @since 4.0.0
34
48
  */
35
49
  export const runMain: {
36
50
  /**
37
51
  * Helps you run a main effect with built-in error handling, logging, and signal management.
38
52
  *
53
+ * **When to use**
54
+ *
55
+ * Use this function to run an Effect as your application's main program,
56
+ * especially when you need structured error handling, log management,
57
+ * interrupt support, or advanced teardown capabilities.
58
+ *
39
59
  * **Details**
40
60
  *
41
61
  * This function launches an Effect as the main entry point, setting exit codes
@@ -44,21 +64,13 @@ export const runMain: {
44
64
  * behaviors can be turned off. You can also provide custom teardown logic to
45
65
  * finalize resources or produce different exit codes.
46
66
  *
47
- * **Options**
48
- *
49
67
  * An optional object that can include:
50
68
  * - `disableErrorReporting`: Turn off automatic error logging.
51
69
  * - `disablePrettyLogger`: Avoid adding the pretty logger.
52
70
  * - `teardown`: Provide custom finalization logic.
53
71
  *
54
- * **When to Use**
55
- *
56
- * Use this function to run an Effect as your application’s main program, especially
57
- * when you need structured error handling, log management, interrupt support,
58
- * or advanced teardown capabilities.
59
- *
60
- * @since 1.0.0
61
- * @category Run main
72
+ * @category running
73
+ * @since 4.0.0
62
74
  */
63
75
  (
64
76
  options?: {
@@ -69,6 +81,12 @@ export const runMain: {
69
81
  /**
70
82
  * Helps you run a main effect with built-in error handling, logging, and signal management.
71
83
  *
84
+ * **When to use**
85
+ *
86
+ * Use this function to run an Effect as your application's main program,
87
+ * especially when you need structured error handling, log management,
88
+ * interrupt support, or advanced teardown capabilities.
89
+ *
72
90
  * **Details**
73
91
  *
74
92
  * This function launches an Effect as the main entry point, setting exit codes
@@ -77,21 +95,13 @@ export const runMain: {
77
95
  * behaviors can be turned off. You can also provide custom teardown logic to
78
96
  * finalize resources or produce different exit codes.
79
97
  *
80
- * **Options**
81
- *
82
98
  * An optional object that can include:
83
99
  * - `disableErrorReporting`: Turn off automatic error logging.
84
100
  * - `disablePrettyLogger`: Avoid adding the pretty logger.
85
101
  * - `teardown`: Provide custom finalization logic.
86
102
  *
87
- * **When to Use**
88
- *
89
- * Use this function to run an Effect as your application’s main program, especially
90
- * when you need structured error handling, log management, interrupt support,
91
- * or advanced teardown capabilities.
92
- *
93
- * @since 1.0.0
94
- * @category Run main
103
+ * @category running
104
+ * @since 4.0.0
95
105
  */
96
106
  <E, A>(
97
107
  effect: Effect<A, E>,
@@ -1,6 +1,27 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Provides the aggregate Bun platform services layer for applications that run
3
+ * on the Bun runtime.
4
+ *
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.
21
+ *
22
+ * @since 4.0.0
3
23
  */
24
+ import type { Crypto } from "effect/Crypto"
4
25
  import type { FileSystem } from "effect/FileSystem"
5
26
  import * as Layer from "effect/Layer"
6
27
  import type { Path } from "effect/Path"
@@ -8,24 +29,32 @@ import type { Stdio } from "effect/Stdio"
8
29
  import type { Terminal } from "effect/Terminal"
9
30
  import type { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner"
10
31
  import * as BunChildProcessSpawner from "./BunChildProcessSpawner.ts"
32
+ import * as BunCrypto from "./BunCrypto.ts"
11
33
  import * as BunFileSystem from "./BunFileSystem.ts"
12
34
  import * as BunPath from "./BunPath.ts"
13
35
  import * as BunStdio from "./BunStdio.ts"
14
36
  import * as BunTerminal from "./BunTerminal.ts"
15
37
 
16
38
  /**
17
- * @since 1.0.0
39
+ * The union of core services provided by the Bun platform layer, including child
40
+ * process spawning, filesystem, path, stdio, and terminal services.
41
+ *
18
42
  * @category models
43
+ * @since 4.0.0
19
44
  */
20
- export type BunServices = ChildProcessSpawner | FileSystem | Path | Terminal | Stdio
45
+ export type BunServices = ChildProcessSpawner | Crypto | FileSystem | Path | Terminal | Stdio
21
46
 
22
47
  /**
23
- * @since 1.0.0
24
- * @category layer
48
+ * Provides the default Bun implementations for child process spawning,
49
+ * filesystem, path, stdio, and terminal services.
50
+ *
51
+ * @category layers
52
+ * @since 4.0.0
25
53
  */
26
54
  export const layer: Layer.Layer<BunServices> = BunChildProcessSpawner.layer.pipe(
27
55
  Layer.provideMerge(Layer.mergeAll(
28
56
  BunFileSystem.layer,
57
+ BunCrypto.layer,
29
58
  BunPath.layer,
30
59
  BunStdio.layer,
31
60
  BunTerminal.layer
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