@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
@@ -1,5 +1,40 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * The `BunClusterSocket` module provides the Bun socket transport for Effect
3
+ * Cluster runners. It wires `SocketRunner` to Bun-compatible TCP sockets,
4
+ * supplies RPC client and server protocol layers, and builds a complete
5
+ * sharding layer with serialization, runner health, runner storage, and message
6
+ * storage.
7
+ *
8
+ * **Common tasks**
9
+ *
10
+ * - Run a Bun process as a cluster runner over raw TCP sockets with
11
+ * {@link layer}
12
+ * - Connect a client-only process to an existing socket cluster without
13
+ * starting a runner server
14
+ * - Use SQL-backed storage for durable multi-process clusters, `local` storage
15
+ * for short-lived development, or `byo` storage when the deployment owns the
16
+ * persistence boundary
17
+ * - Check runner health with socket pings or Kubernetes pod readiness through
18
+ * {@link layerK8sHttpClient}
19
+ *
20
+ * **Gotchas**
21
+ *
22
+ * - `runnerAddress` is the host and port advertised to other runners; set
23
+ * `runnerListenAddress` when the local bind address differs from the
24
+ * externally reachable address
25
+ * - The socket transport is point-to-point RPC, not cluster gossip: runner
26
+ * membership, shard ownership, and persisted delivery are coordinated through
27
+ * `RunnerStorage`, `MessageStorage`, and `RunnerHealth`
28
+ * - `clientOnly` does not start a socket server or receive shard assignments
29
+ * - SQL storage is the default; `local` storage is in-memory/noop and `byo`
30
+ * requires the surrounding application to provide both runner and message
31
+ * storage services
32
+ * - Ping health checks use the same socket protocol, so unreachable ports,
33
+ * firewalls, or serialization mismatches can make a runner appear unhealthy
34
+ * - Kubernetes health checks use Bun's Fetch-backed HTTP client and the service
35
+ * account CA certificate when it is available
36
+ *
37
+ * @since 4.0.0
3
38
  */
4
39
  import { layerClientProtocol, layerSocketServer } from "@effect/platform-node-shared/NodeClusterSocket"
5
40
  import type * as Config from "effect/Config"
@@ -24,20 +59,22 @@ import * as BunFileSystem from "./BunFileSystem.ts"
24
59
 
25
60
  export {
26
61
  /**
27
- * @since 1.0.0
28
- * @category Re-exports
62
+ * @category re-exports
63
+ * @since 4.0.0
29
64
  */
30
65
  layerClientProtocol,
31
66
  /**
32
- * @since 1.0.0
33
- * @category Re-exports
67
+ * @category re-exports
68
+ * @since 4.0.0
34
69
  */
35
70
  layerSocketServer
36
71
  }
37
72
 
38
73
  /**
39
- * @since 1.0.0
40
- * @category Layers
74
+ * Creates Bun socket cluster layers, configuring serialization, storage, runner health, and optional client-only mode.
75
+ *
76
+ * @category layers
77
+ * @since 4.0.0
41
78
  */
42
79
  export const layer = <
43
80
  const ClientOnly extends boolean = false,
@@ -110,8 +147,10 @@ export const layer = <
110
147
  }
111
148
 
112
149
  /**
113
- * @since 1.0.0
114
- * @category Layers
150
+ * Layer that provides `K8sHttpClient`, using the Kubernetes service-account CA certificate when it is available.
151
+ *
152
+ * @category layers
153
+ * @since 4.0.0
115
154
  */
116
155
  export const layerK8sHttpClient: Layer.Layer<K8sHttpClient.K8sHttpClient> = K8sHttpClient.layer.pipe(
117
156
  Layer.provide(Layer.unwrap(Effect.gen(function*() {
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Bun platform Crypto service layer.
3
+ *
4
+ * @since 1.0.0
5
+ */
6
+ import * as NodeCrypto from "@effect/platform-node-shared/NodeCrypto"
7
+ import type * as Crypto from "effect/Crypto"
8
+ import type * as Layer from "effect/Layer"
9
+
10
+ /**
11
+ * A layer that provides the Bun Crypto service implementation.
12
+ *
13
+ * @category layers
14
+ * @since 1.0.0
15
+ */
16
+ export const layer: Layer.Layer<Crypto.Crypto> = NodeCrypto.layer
@@ -1,12 +1,36 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Bun layer for Effect's `FileSystem` service.
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`.
23
+ *
24
+ * @since 4.0.0
3
25
  */
4
26
  import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem"
5
27
  import type { FileSystem } from "effect/FileSystem"
6
28
  import type * as Layer from "effect/Layer"
7
29
 
8
30
  /**
9
- * @since 1.0.0
10
- * @category layer
31
+ * Layer that provides the `FileSystem` service for Bun using the shared Node file-system implementation.
32
+ *
33
+ * @category layers
34
+ * @since 4.0.0
11
35
  */
12
36
  export const layer: Layer.Layer<FileSystem, never, never> = NodeFileSystem.layer
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  /**
6
- * @since 1.0.0
7
6
  * @category re-exports
7
+ * @since 4.0.0
8
8
  */
9
9
  export * from "effect/unstable/http/FetchHttpClient"
@@ -1,5 +1,27 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Bun implementation of the Effect HTTP platform service.
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.
23
+ *
24
+ * @since 4.0.0
3
25
  */
4
26
  import type { Effect } from "effect"
5
27
  import type { FileSystem } from "effect/FileSystem"
@@ -10,8 +32,8 @@ import * as Response from "effect/unstable/http/HttpServerResponse"
10
32
  import * as BunFileSystem from "./BunFileSystem.ts"
11
33
 
12
34
  /**
13
- * @since 1.0.0
14
35
  * @category constructors
36
+ * @since 4.0.0
15
37
  */
16
38
  const make: Effect.Effect<
17
39
  Platform.HttpPlatform["Service"],
@@ -31,8 +53,10 @@ const make: Effect.Effect<
31
53
  })
32
54
 
33
55
  /**
34
- * @since 1.0.0
35
- * @category Layers
56
+ * Layer that provides the Bun `HttpPlatform`, including file responses backed by `Bun.file`.
57
+ *
58
+ * @category layers
59
+ * @since 4.0.0
36
60
  */
37
61
  export const layer = Layer.effect(Platform.HttpPlatform)(make).pipe(
38
62
  Layer.provide(BunFileSystem.layer),
@@ -1,5 +1,36 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Bun implementation of the Effect `HttpServer`.
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.
32
+ *
33
+ * @since 4.0.0
3
34
  */
4
35
  import type { Server as BunServer, ServerWebSocket } from "bun"
5
36
  import * as Config from "effect/Config"
@@ -44,8 +75,10 @@ import * as BunServices from "./BunServices.ts"
44
75
  import * as BunStream from "./BunStream.ts"
45
76
 
46
77
  /**
47
- * @since 1.0.0
78
+ * Bun serve options accepted by the HTTP server, extended with typed route definitions.
79
+ *
48
80
  * @category Options
81
+ * @since 4.0.0
49
82
  */
50
83
  export type ServeOptions<R extends string> =
51
84
  & (
@@ -55,8 +88,10 @@ export type ServeOptions<R extends string> =
55
88
  & { readonly routes?: Bun.Serve.Routes<WebSocketContext, R> }
56
89
 
57
90
  /**
58
- * @since 1.0.0
59
- * @category Constructors
91
+ * Creates a scoped Bun `HttpServer` from `Bun.serve` options, stopping the server on scope finalization with optional graceful shutdown settings.
92
+ *
93
+ * @category constructors
94
+ * @since 4.0.0
60
95
  */
61
96
  export const make = Effect.fnUntraced(
62
97
  function*<R extends string>(
@@ -210,8 +245,10 @@ const makeResponse = (
210
245
  }
211
246
 
212
247
  /**
213
- * @since 1.0.0
214
- * @category Layers
248
+ * Layer that provides only `HttpServer` by constructing a scoped Bun server from the supplied serve options.
249
+ *
250
+ * @category layers
251
+ * @since 4.0.0
215
252
  */
216
253
  export const layerServer: <R extends string>(
217
254
  options: ServeOptions<R> & {
@@ -221,8 +258,10 @@ export const layerServer: <R extends string>(
221
258
  ) => Layer.Layer<Server.HttpServer> = flow(make, Layer.effect(Server.HttpServer)) as any
222
259
 
223
260
  /**
224
- * @since 1.0.0
225
- * @category Layers
261
+ * Layer that provides Bun HTTP support services: `HttpPlatform`, weak ETag generation, and `BunServices`.
262
+ *
263
+ * @category layers
264
+ * @since 4.0.0
226
265
  */
227
266
  export const layerHttpServices: Layer.Layer<
228
267
  | HttpPlatform
@@ -235,8 +274,10 @@ export const layerHttpServices: Layer.Layer<
235
274
  )
236
275
 
237
276
  /**
238
- * @since 1.0.0
239
- * @category Layers
277
+ * Layer that provides a Bun `HttpServer` together with the Bun HTTP platform, ETag generator, and Bun services.
278
+ *
279
+ * @category layers
280
+ * @since 4.0.0
240
281
  */
241
282
  export const layer = <R extends string>(
242
283
  options: ServeOptions<R> & {
@@ -251,8 +292,10 @@ export const layer = <R extends string>(
251
292
  > => Layer.mergeAll(layerServer(options), layerHttpServices)
252
293
 
253
294
  /**
254
- * @since 1.0.0
255
- * @category Layers
295
+ * Test layer that starts a Bun HTTP server on an ephemeral port and provides the HTTP test client dependencies.
296
+ *
297
+ * @category layers
298
+ * @since 4.0.0
256
299
  */
257
300
  export const layerTest: Layer.Layer<
258
301
  Server.HttpServer | HttpPlatform | FileSystem.FileSystem | Etag.Generator | Path.Path | HttpClient
@@ -264,8 +307,10 @@ export const layerTest: Layer.Layer<
264
307
  )
265
308
 
266
309
  /**
267
- * @since 1.0.0
268
- * @category Layers
310
+ * Creates the Bun HTTP server and support-services layer from configurable serve options.
311
+ *
312
+ * @category layers
313
+ * @since 4.0.0
269
314
  */
270
315
  export const layerConfig = <R extends string>(
271
316
  options: Config.Wrap<
@@ -1,11 +1,35 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Accessors for the Bun `Request` object backing a platform Bun
3
+ * `HttpServerRequest`.
4
+ *
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.
23
+ *
24
+ * @since 4.0.0
3
25
  */
4
26
  import type { HttpServerRequest } from "effect/unstable/http/HttpServerRequest"
5
27
 
6
28
  /**
7
- * @since 1.0.0
29
+ * Returns the underlying `Bun.BunRequest` from an Effect `HttpServerRequest`.
30
+ *
8
31
  * @category Accessors
32
+ * @since 4.0.0
9
33
  */
10
34
  export const toBunServerRequest = <T extends string = string>(self: HttpServerRequest): Bun.BunRequest<T> =>
11
35
  (self as any).source
@@ -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,8 +29,10 @@ 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({
@@ -29,8 +50,10 @@ const emptyReadbleStream = new ReadableStream({
29
50
  })
30
51
 
31
52
  /**
32
- * @since 1.0.0
33
- * @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
34
57
  */
35
58
  export const persisted = (
36
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,5 +1,29 @@
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"
@@ -11,8 +35,10 @@ import * as Scope from "effect/Scope"
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
43
  export class BunRedis extends Context.Service<BunRedis, {
18
44
  readonly client: RedisClient
@@ -53,16 +79,20 @@ const make = Effect.fnUntraced(function*(
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
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>
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"
@@ -29,8 +45,8 @@ import type { Teardown } from "effect/Runtime"
29
45
  * when you need structured error handling, log management, interrupt support,
30
46
  * or advanced teardown capabilities.
31
47
  *
32
- * @since 1.0.0
33
- * @category Run main
48
+ * @category running
49
+ * @since 4.0.0
34
50
  */
35
51
  export const runMain: {
36
52
  /**
@@ -57,8 +73,8 @@ export const runMain: {
57
73
  * when you need structured error handling, log management, interrupt support,
58
74
  * or advanced teardown capabilities.
59
75
  *
60
- * @since 1.0.0
61
- * @category Run main
76
+ * @category running
77
+ * @since 4.0.0
62
78
  */
63
79
  (
64
80
  options?: {
@@ -90,8 +106,8 @@ export const runMain: {
90
106
  * when you need structured error handling, log management, interrupt support,
91
107
  * or advanced teardown capabilities.
92
108
  *
93
- * @since 1.0.0
94
- * @category Run main
109
+ * @category running
110
+ * @since 4.0.0
95
111
  */
96
112
  <E, A>(
97
113
  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