@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.
- package/dist/BunClusterHttp.d.ts +26 -2
- package/dist/BunClusterHttp.d.ts.map +1 -1
- package/dist/BunClusterHttp.js +26 -2
- package/dist/BunClusterHttp.js.map +1 -1
- package/dist/BunCrypto.d.ts +1 -1
- package/dist/BunCrypto.d.ts.map +1 -1
- package/dist/BunCrypto.js +10 -2
- package/dist/BunCrypto.js.map +1 -1
- package/dist/BunHttpServer.d.ts +1 -1
- package/dist/BunHttpServer.js +1 -1
- package/dist/BunHttpServerRequest.d.ts +1 -1
- package/dist/BunHttpServerRequest.js +1 -1
- package/dist/BunPath.d.ts.map +1 -1
- package/dist/BunPath.js +28 -16
- package/dist/BunPath.js.map +1 -1
- package/dist/BunRedis.d.ts +27 -18
- package/dist/BunRedis.d.ts.map +1 -1
- package/dist/BunRedis.js +27 -18
- package/dist/BunRedis.js.map +1 -1
- package/dist/BunRuntime.d.ts +3 -3
- package/dist/BunRuntime.d.ts.map +1 -1
- package/dist/BunRuntime.js +29 -16
- package/dist/BunRuntime.js.map +1 -1
- package/dist/BunStdio.d.ts.map +1 -1
- package/dist/BunStdio.js +23 -11
- package/dist/BunStdio.js.map +1 -1
- package/dist/BunStream.d.ts +2 -2
- package/dist/BunStream.d.ts.map +1 -1
- package/dist/BunStream.js +27 -18
- package/dist/BunStream.js.map +1 -1
- package/dist/BunTerminal.d.ts.map +1 -1
- package/dist/BunTerminal.js +29 -11
- package/dist/BunTerminal.js.map +1 -1
- package/dist/BunWorker.d.ts.map +1 -1
- package/dist/BunWorker.js +28 -11
- package/dist/BunWorker.js.map +1 -1
- package/dist/BunWorkerRunner.d.ts.map +1 -1
- package/dist/BunWorkerRunner.js +29 -15
- package/dist/BunWorkerRunner.js.map +1 -1
- package/dist/index.d.ts +0 -373
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -373
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/BunClusterHttp.ts +26 -2
- package/src/BunCrypto.ts +10 -2
- package/src/BunHttpServer.ts +1 -1
- package/src/BunHttpServerRequest.ts +1 -1
- package/src/BunPath.ts +28 -16
- package/src/BunRedis.ts +27 -18
- package/src/BunRuntime.ts +29 -16
- package/src/BunStdio.ts +23 -11
- package/src/BunStream.ts +27 -18
- package/src/BunTerminal.ts +29 -11
- package/src/BunWorker.ts +28 -11
- package/src/BunWorkerRunner.ts +29 -15
- package/src/index.ts +0 -373
package/src/index.ts
CHANGED
|
@@ -5,120 +5,26 @@
|
|
|
5
5
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Node.js implementation of `ChildProcessSpawner`.
|
|
9
|
-
*
|
|
10
8
|
* @since 4.0.0
|
|
11
9
|
*/
|
|
12
10
|
export * as BunChildProcessSpawner from "./BunChildProcessSpawner.ts"
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
|
-
* The `BunClusterHttp` module provides the Bun HTTP and WebSocket transports
|
|
16
|
-
* for Effect Cluster runners. It wires `HttpRunner` to the Bun HTTP server,
|
|
17
|
-
* supplies Fetch and Bun WebSocket client protocols, and builds a complete
|
|
18
|
-
* sharding layer with serialization, runner health, runner storage, and message
|
|
19
|
-
* storage.
|
|
20
|
-
*
|
|
21
|
-
* **Common tasks**
|
|
22
|
-
*
|
|
23
|
-
* - Run a Bun process as a cluster runner over HTTP or WebSocket with
|
|
24
|
-
* {@link layer}
|
|
25
|
-
* - Connect a client-only process to an existing HTTP cluster without starting
|
|
26
|
-
* a runner server
|
|
27
|
-
* - Use SQL-backed storage for durable multi-process clusters, `local` storage
|
|
28
|
-
* for short-lived development, or `byo` storage when the deployment owns the
|
|
29
|
-
* persistence boundary
|
|
30
|
-
* - Check runner health with protocol pings or Kubernetes pod readiness through
|
|
31
|
-
* {@link layerK8sHttpClient}
|
|
32
|
-
*
|
|
33
|
-
* **Gotchas**
|
|
34
|
-
*
|
|
35
|
-
* - `runnerAddress` is the host and port advertised to other runners; set
|
|
36
|
-
* `runnerListenAddress` when the local bind address differs from the
|
|
37
|
-
* externally reachable address
|
|
38
|
-
* - The HTTP and WebSocket transports serve runner RPCs at the default
|
|
39
|
-
* `HttpRunner` route, so proxies and load balancers must preserve the path
|
|
40
|
-
* and allow WebSocket upgrades when `transport` is `"websocket"`
|
|
41
|
-
* - `clientOnly` does not start an HTTP server or receive shard assignments
|
|
42
|
-
* - SQL storage is the default; `local` storage is in-memory/noop and `byo`
|
|
43
|
-
* requires the surrounding application to provide both runner and message
|
|
44
|
-
* storage services
|
|
45
|
-
* - Ping health checks use the selected transport and serialization, so route,
|
|
46
|
-
* port, proxy, or codec mismatches can make a runner appear unhealthy
|
|
47
|
-
*
|
|
48
13
|
* @since 4.0.0
|
|
49
14
|
*/
|
|
50
15
|
export * as BunClusterHttp from "./BunClusterHttp.ts"
|
|
51
16
|
|
|
52
17
|
/**
|
|
53
|
-
* The `BunClusterSocket` module provides the Bun socket transport for Effect
|
|
54
|
-
* Cluster runners. It wires `SocketRunner` to Bun-compatible TCP sockets,
|
|
55
|
-
* supplies RPC client and server protocol layers, and builds a complete
|
|
56
|
-
* sharding layer with serialization, runner health, runner storage, and message
|
|
57
|
-
* storage.
|
|
58
|
-
*
|
|
59
|
-
* **Common tasks**
|
|
60
|
-
*
|
|
61
|
-
* - Run a Bun process as a cluster runner over raw TCP sockets with
|
|
62
|
-
* {@link layer}
|
|
63
|
-
* - Connect a client-only process to an existing socket cluster without
|
|
64
|
-
* starting a runner server
|
|
65
|
-
* - Use SQL-backed storage for durable multi-process clusters, `local` storage
|
|
66
|
-
* for short-lived development, or `byo` storage when the deployment owns the
|
|
67
|
-
* persistence boundary
|
|
68
|
-
* - Check runner health with socket pings or Kubernetes pod readiness through
|
|
69
|
-
* {@link layerK8sHttpClient}
|
|
70
|
-
*
|
|
71
|
-
* **Gotchas**
|
|
72
|
-
*
|
|
73
|
-
* - `runnerAddress` is the host and port advertised to other runners; set
|
|
74
|
-
* `runnerListenAddress` when the local bind address differs from the
|
|
75
|
-
* externally reachable address
|
|
76
|
-
* - The socket transport is point-to-point RPC, not cluster gossip: runner
|
|
77
|
-
* membership, shard ownership, and persisted delivery are coordinated through
|
|
78
|
-
* `RunnerStorage`, `MessageStorage`, and `RunnerHealth`
|
|
79
|
-
* - `clientOnly` does not start a socket server or receive shard assignments
|
|
80
|
-
* - SQL storage is the default; `local` storage is in-memory/noop and `byo`
|
|
81
|
-
* requires the surrounding application to provide both runner and message
|
|
82
|
-
* storage services
|
|
83
|
-
* - Ping health checks use the same socket protocol, so unreachable ports,
|
|
84
|
-
* firewalls, or serialization mismatches can make a runner appear unhealthy
|
|
85
|
-
* - Kubernetes health checks use Bun's Fetch-backed HTTP client and the service
|
|
86
|
-
* account CA certificate when it is available
|
|
87
|
-
*
|
|
88
18
|
* @since 4.0.0
|
|
89
19
|
*/
|
|
90
20
|
export * as BunClusterSocket from "./BunClusterSocket.ts"
|
|
91
21
|
|
|
92
22
|
/**
|
|
93
|
-
* Bun platform Crypto service layer.
|
|
94
|
-
*
|
|
95
23
|
* @since 1.0.0
|
|
96
24
|
*/
|
|
97
25
|
export * as BunCrypto from "./BunCrypto.ts"
|
|
98
26
|
|
|
99
27
|
/**
|
|
100
|
-
* Bun layer for Effect's `FileSystem` service.
|
|
101
|
-
*
|
|
102
|
-
* Use this module at the edge of Bun applications, CLIs, scripts, and tests
|
|
103
|
-
* that need real local filesystem access through `effect/FileSystem`: reading
|
|
104
|
-
* and writing files, creating directories and temporary files, inspecting
|
|
105
|
-
* metadata, managing links, or watching paths for changes. It exposes only the
|
|
106
|
-
* Bun `FileSystem` layer; the operations themselves are accessed from the
|
|
107
|
-
* `FileSystem` service once the layer is provided, or from `BunServices.layer`
|
|
108
|
-
* when the program also needs the standard Bun path, stdio, terminal, and child
|
|
109
|
-
* process services.
|
|
110
|
-
*
|
|
111
|
-
* Bun supports Node-compatible filesystem APIs, so this layer reuses the shared
|
|
112
|
-
* Node filesystem implementation. Paths therefore follow the current process and
|
|
113
|
-
* host platform rules: relative paths are resolved from the current working
|
|
114
|
-
* directory, separators and drive/UNC behavior are platform-dependent, and
|
|
115
|
-
* request URLs should be decoded and validated before being mapped to local
|
|
116
|
-
* paths. The service works with bytes, scoped file handles, and Effect
|
|
117
|
-
* streams/sinks; use `FileSystem.stream` for large files instead of
|
|
118
|
-
* `readFile`, and remember that stream offsets and lengths are byte positions.
|
|
119
|
-
* Bun `File` and `Blob` values are not filesystem handles here; path-based HTTP
|
|
120
|
-
* file responses are handled by the Bun HTTP platform adapter with `Bun.file`.
|
|
121
|
-
*
|
|
122
28
|
* @since 4.0.0
|
|
123
29
|
*/
|
|
124
30
|
export * as BunFileSystem from "./BunFileSystem.ts"
|
|
@@ -129,212 +35,41 @@ export * as BunFileSystem from "./BunFileSystem.ts"
|
|
|
129
35
|
export * as BunHttpClient from "./BunHttpClient.ts"
|
|
130
36
|
|
|
131
37
|
/**
|
|
132
|
-
* Bun implementation of the Effect HTTP platform service.
|
|
133
|
-
*
|
|
134
|
-
* This module connects the portable `HttpPlatform` file response helpers to
|
|
135
|
-
* Bun's Web-compatible runtime. `BunHttpServer` provides this layer when
|
|
136
|
-
* applications serve local files, public assets, downloads, byte ranges, or
|
|
137
|
-
* Web `File` values from Effect `HttpServerResponse` constructors.
|
|
138
|
-
*
|
|
139
|
-
* Path-based responses are backed by `Bun.file`, and Web `File` responses are
|
|
140
|
-
* returned directly as raw response bodies. The shared `HttpPlatform` service
|
|
141
|
-
* still computes file metadata such as ETags and last-modified headers, while
|
|
142
|
-
* this adapter lets Bun's `Response` implementation handle the platform body.
|
|
143
|
-
*
|
|
144
|
-
* Because the Bun server adapter sits on top of Web `Request` and `Response`,
|
|
145
|
-
* request bodies follow the usual single-consumption rules: choose the
|
|
146
|
-
* streamed, text, URL-encoded, or multipart view that matches the route. For
|
|
147
|
-
* `FormData` responses, let the `Response` constructor create the multipart
|
|
148
|
-
* content type and boundary unless you intentionally override it. File
|
|
149
|
-
* responses take filesystem paths, not request URLs; Bun request URLs are
|
|
150
|
-
* absolute at the runtime edge, and route paths are normalized by
|
|
151
|
-
* `BunHttpServer`, so decode and validate URL pathnames before mapping them to
|
|
152
|
-
* files.
|
|
153
|
-
*
|
|
154
38
|
* @since 4.0.0
|
|
155
39
|
*/
|
|
156
40
|
export * as BunHttpPlatform from "./BunHttpPlatform.ts"
|
|
157
41
|
|
|
158
42
|
/**
|
|
159
|
-
* Bun implementation of the Effect `HttpServer`.
|
|
160
|
-
*
|
|
161
|
-
* This module builds an Effect HTTP server from `Bun.serve`, translating Bun's
|
|
162
|
-
* Web `Request` objects into `HttpServerRequest` values and Effect
|
|
163
|
-
* `HttpServerResponse` values back into Web `Response` objects. It is the Bun
|
|
164
|
-
* runtime entry point for serving `HttpApp`s, streaming responses, file
|
|
165
|
-
* responses through `BunHttpPlatform`, multipart requests, and websocket
|
|
166
|
-
* endpoints through `HttpServerRequest.upgrade`.
|
|
167
|
-
*
|
|
168
|
-
* Common use cases include using {@link layer} or {@link layerConfig} to serve
|
|
169
|
-
* an application from Bun configuration, {@link layerServer} when only the
|
|
170
|
-
* `HttpServer` service is needed, and {@link layerTest} for tests that need an
|
|
171
|
-
* ephemeral Bun listener and fetch-compatible client.
|
|
172
|
-
*
|
|
173
|
-
* Bun supplies absolute request URLs and Web-standard request bodies. This
|
|
174
|
-
* adapter stores the normalized path-and-query URL on `HttpServerRequest.url`,
|
|
175
|
-
* while the underlying `Request` still follows Web body rules: pick the
|
|
176
|
-
* streamed, text, JSON, URL-encoded, or multipart view that matches the route
|
|
177
|
-
* instead of consuming the same body in incompatible ways. Because `Bun.serve`
|
|
178
|
-
* has a single active `fetch` handler, each `serve` call reloads that handler
|
|
179
|
-
* and restores the previous one when the serve scope finalizes.
|
|
180
|
-
*
|
|
181
|
-
* WebSocket upgrades must happen from the Bun request handler. The
|
|
182
|
-
* `HttpServerRequest.upgrade` effect calls `server.upgrade`, fails when Bun says
|
|
183
|
-
* the request is not upgradeable, buffers messages that arrive before the
|
|
184
|
-
* Effect socket handler is installed, and maps non-normal close codes into
|
|
185
|
-
* `Socket` errors. The server is stopped with `server.stop()` when its
|
|
186
|
-
* acquisition scope closes; unless preemptive shutdown is disabled, finalizing
|
|
187
|
-
* a serve scope also starts that stop with the configured graceful shutdown
|
|
188
|
-
* timeout or the default timeout.
|
|
189
|
-
*
|
|
190
43
|
* @since 4.0.0
|
|
191
44
|
*/
|
|
192
45
|
export * as BunHttpServer from "./BunHttpServer.ts"
|
|
193
46
|
|
|
194
47
|
/**
|
|
195
|
-
* Accessors for the Bun `Request` object backing a platform Bun
|
|
196
|
-
* `HttpServerRequest`.
|
|
197
|
-
*
|
|
198
|
-
* Use this module at interop boundaries when an Effect HTTP handler needs the
|
|
199
|
-
* original `Bun.BunRequest`, for example to read Bun route parameters, pass the
|
|
200
|
-
* request to Bun-specific APIs, inspect Web `Request` fields that are not
|
|
201
|
-
* exposed by the portable `HttpServerRequest` interface, or coordinate with code
|
|
202
|
-
* that already works directly with Bun's server request type.
|
|
203
|
-
*
|
|
204
|
-
* The returned request is the original Web request supplied by `Bun.serve`. It
|
|
205
|
-
* does not reflect Effect request overrides made by middleware, such as a
|
|
206
|
-
* rewritten URL, adjusted headers, or a substituted remote address. Its body is
|
|
207
|
-
* the same one-shot Web `ReadableStream` used by the Effect body helpers, so
|
|
208
|
-
* calling `text`, `json`, `formData`, `arrayBuffer`, or reading `body` directly
|
|
209
|
-
* can disturb the request and conflict with Effect body, multipart, or stream
|
|
210
|
-
* helpers unless ownership of the body is clear.
|
|
211
|
-
*
|
|
212
|
-
* Bun stores client IP information on the server rather than on the request
|
|
213
|
-
* object. Prefer `HttpServerRequest.remoteAddress` when you need the address
|
|
214
|
-
* seen by Effect or middleware; the raw request returned here will not expose
|
|
215
|
-
* middleware-provided remote address overrides.
|
|
216
|
-
*
|
|
217
48
|
* @since 4.0.0
|
|
218
49
|
*/
|
|
219
50
|
export * as BunHttpServerRequest from "./BunHttpServerRequest.ts"
|
|
220
51
|
|
|
221
52
|
/**
|
|
222
|
-
* Bun-specific helpers for parsing HTTP `multipart/form-data` request bodies.
|
|
223
|
-
*
|
|
224
|
-
* This module adapts a Bun `Request` body and headers into the shared
|
|
225
|
-
* `Multipart` model. Use `stream` from Bun HTTP handlers when form fields and
|
|
226
|
-
* uploaded files should be consumed incrementally, for example validating text
|
|
227
|
-
* fields while piping large file parts to storage. Use `persisted` when the
|
|
228
|
-
* whole form should be collected into a record and file parts should be written
|
|
229
|
-
* to scoped temporary files through the current `FileSystem`, `Path`, and
|
|
230
|
-
* `Scope` services.
|
|
231
|
-
*
|
|
232
|
-
* Bun requests expose one-shot web streams, so choose one body reader and do
|
|
233
|
-
* not call `formData`, `text`, `json`, or `arrayBuffer` before using this
|
|
234
|
-
* module. Incoming `FormData` uploads must include a `multipart/form-data`
|
|
235
|
-
* content type with the boundary generated by the client; when constructing
|
|
236
|
-
* `FormData` requests, let the runtime set that header. Stream file content for
|
|
237
|
-
* large uploads, reserve `contentEffect` for small files, and treat client
|
|
238
|
-
* filenames as metadata rather than trusted filesystem paths. Persisted file
|
|
239
|
-
* paths remain valid only for the surrounding scope.
|
|
240
|
-
*
|
|
241
53
|
* @since 4.0.0
|
|
242
54
|
*/
|
|
243
55
|
export * as BunMultipart from "./BunMultipart.ts"
|
|
244
56
|
|
|
245
57
|
/**
|
|
246
|
-
* Bun layers for Effect's `Path` service.
|
|
247
|
-
*
|
|
248
|
-
* Use this module when an Effect program running on Bun needs path
|
|
249
|
-
* manipulation from the `Path` service, such as joining and normalizing local
|
|
250
|
-
* filesystem locations, resolving configuration or static asset paths, handling
|
|
251
|
-
* CLI path arguments, or converting between filesystem paths and `file:` URLs.
|
|
252
|
-
*
|
|
253
|
-
* Bun exposes Node-compatible path behavior, so these layers reuse the shared
|
|
254
|
-
* Node path implementation. The default `layer` follows the host operating
|
|
255
|
-
* system's path rules, including separators, absolute paths, drive letters, and
|
|
256
|
-
* UNC paths where applicable. Use `layerPosix` or `layerWin32` when code needs
|
|
257
|
-
* stable POSIX or Windows semantics regardless of where Bun is running. These
|
|
258
|
-
* layers only manipulate path strings; they do not read the filesystem, validate
|
|
259
|
-
* that paths exist, or turn request URLs into safe local paths. `BunServices`
|
|
260
|
-
* already includes the default Bun path layer, so provide this module directly
|
|
261
|
-
* when you need only `Path` or one of the platform-specific variants.
|
|
262
|
-
*
|
|
263
58
|
* @since 4.0.0
|
|
264
59
|
*/
|
|
265
60
|
export * as BunPath from "./BunPath.ts"
|
|
266
61
|
|
|
267
62
|
/**
|
|
268
|
-
* Bun Redis integration backed by Bun's built-in `RedisClient`.
|
|
269
|
-
*
|
|
270
|
-
* This module provides scoped layers that create a Bun `RedisClient` and expose
|
|
271
|
-
* both the low-level `Redis` service used by Effect persistence modules and the
|
|
272
|
-
* `BunRedis` service for direct access to the underlying client. Use it in Bun
|
|
273
|
-
* applications that need Redis-backed persistence, persisted queues,
|
|
274
|
-
* distributed rate limiting, custom Redis commands, or Bun Redis features such
|
|
275
|
-
* as pub/sub through the raw client.
|
|
276
|
-
*
|
|
277
|
-
* The client is acquired when the layer is built and closed with `close` when
|
|
278
|
-
* the layer scope ends, so install the layer at the lifetime you want for the
|
|
279
|
-
* connection and pass a Redis URL, Bun `RedisOptions`, or `layerConfig` for
|
|
280
|
-
* connection settings. The portable `Redis` service sends ordinary commands
|
|
281
|
-
* through `RedisClient.send`; pub/sub is available through `BunRedis.client`
|
|
282
|
-
* or `BunRedis.use` and should normally use a separately scoped client so a
|
|
283
|
-
* subscription does not interfere with command traffic used by persistence or
|
|
284
|
-
* rate limiter stores.
|
|
285
|
-
*
|
|
286
|
-
* Persistence and rate limiter stores build keys and Lua scripts on top of this
|
|
287
|
-
* service. Choose stable prefixes and store ids to avoid collisions, account
|
|
288
|
-
* for persisted values that may fail to decode after schema changes, and avoid
|
|
289
|
-
* unbounded high-cardinality rate-limit keys unless you have a cleanup or
|
|
290
|
-
* bounding strategy.
|
|
291
|
-
*
|
|
292
63
|
* @since 4.0.0
|
|
293
64
|
*/
|
|
294
65
|
export * as BunRedis from "./BunRedis.ts"
|
|
295
66
|
|
|
296
67
|
/**
|
|
297
|
-
* Bun entry-point helpers for running Effect programs.
|
|
298
|
-
*
|
|
299
|
-
* This module exposes `runMain`, the Bun runtime launcher used at the edge of
|
|
300
|
-
* CLIs, scripts, servers, and worker processes. It runs an already
|
|
301
|
-
* self-contained Effect as the process main program, using the shared
|
|
302
|
-
* Node-compatible runtime implementation for error reporting, teardown, and
|
|
303
|
-
* `process` signal handling available in Bun.
|
|
304
|
-
*
|
|
305
|
-
* `BunRuntime` does not provide application services by itself. Provide any
|
|
306
|
-
* required layers, such as `BunServices.layer` or narrower service-specific
|
|
307
|
-
* layers, before passing the effect to `runMain`. On `SIGINT` or `SIGTERM`,
|
|
308
|
-
* the main fiber is interrupted so scoped resources and finalizers can shut
|
|
309
|
-
* down; keep long-running servers, workers, and subscriptions attached to that
|
|
310
|
-
* scope and avoid finalizers that never complete, otherwise process shutdown
|
|
311
|
-
* can be delayed.
|
|
312
|
-
*
|
|
313
68
|
* @since 4.0.0
|
|
314
69
|
*/
|
|
315
70
|
export * as BunRuntime from "./BunRuntime.ts"
|
|
316
71
|
|
|
317
72
|
/**
|
|
318
|
-
* Provides the aggregate Bun platform services layer for applications that run
|
|
319
|
-
* on the Bun runtime.
|
|
320
|
-
*
|
|
321
|
-
* This module is useful when an application needs the standard Bun-backed
|
|
322
|
-
* implementations of filesystem access, path operations, stdio, terminal
|
|
323
|
-
* interaction, and child process spawning from a single layer. Provide
|
|
324
|
-
* `BunServices.layer` near the edge of a program to satisfy effects that read
|
|
325
|
-
* or write files, resolve paths, interact with stdin/stdout/stderr or a
|
|
326
|
-
* terminal, or launch subprocesses.
|
|
327
|
-
*
|
|
328
|
-
* The layer only supplies the runtime services listed by `BunServices`; it does
|
|
329
|
-
* not provide unrelated platform services such as HTTP clients, HTTP servers,
|
|
330
|
-
* sockets, workers, or Redis. Several of these core Bun services are backed by
|
|
331
|
-
* the shared Node-compatible implementations used by the Bun adapters, so the
|
|
332
|
-
* default path, stdio, terminal, and subprocess behavior follows the current
|
|
333
|
-
* process and host platform. Libraries should continue to depend on the
|
|
334
|
-
* individual service tags they use, while Bun applications, CLIs, and tests can
|
|
335
|
-
* choose this layer or narrower service-specific layers depending on how much
|
|
336
|
-
* of the Bun runtime they want to expose.
|
|
337
|
-
*
|
|
338
73
|
* @since 4.0.0
|
|
339
74
|
*/
|
|
340
75
|
export * as BunServices from "./BunServices.ts"
|
|
@@ -345,25 +80,6 @@ export * as BunServices from "./BunServices.ts"
|
|
|
345
80
|
export * as BunSink from "./BunSink.ts"
|
|
346
81
|
|
|
347
82
|
/**
|
|
348
|
-
* Bun platform socket entry point for Effect sockets backed by Bun-compatible
|
|
349
|
-
* Node streams and Bun's native WebSocket implementation.
|
|
350
|
-
*
|
|
351
|
-
* This module re-exports the shared Node socket constructors for TCP clients,
|
|
352
|
-
* Unix domain socket clients, and adapters from existing Node `Duplex` streams,
|
|
353
|
-
* then adds Bun-specific WebSocket layers using `globalThis.WebSocket`. Use it
|
|
354
|
-
* in Bun applications that connect to raw socket protocols, Unix sockets,
|
|
355
|
-
* realtime WebSocket services, or Effect RPC transports that need a
|
|
356
|
-
* `Socket.Socket` layer.
|
|
357
|
-
*
|
|
358
|
-
* TCP lifecycle behavior comes from the shared Node layer: sockets are scoped,
|
|
359
|
-
* finalizers close or destroy the underlying stream, open timeouts become
|
|
360
|
-
* socket open errors, and read, write, and close events are mapped to
|
|
361
|
-
* `SocketError` values. TLS concerns depend on the transport being used: `wss:`
|
|
362
|
-
* URLs are handled by Bun's WebSocket implementation, while TLS-wrapped
|
|
363
|
-
* `Duplex` streams can be adapted after they have been created elsewhere.
|
|
364
|
-
* When closing intentionally, send `Socket.CloseEvent` values so the close code
|
|
365
|
-
* and reason are preserved through the socket lifecycle.
|
|
366
|
-
*
|
|
367
83
|
* @since 4.0.0
|
|
368
84
|
*/
|
|
369
85
|
export * as BunSocket from "./BunSocket.ts"
|
|
@@ -374,115 +90,26 @@ export * as BunSocket from "./BunSocket.ts"
|
|
|
374
90
|
export * as BunSocketServer from "./BunSocketServer.ts"
|
|
375
91
|
|
|
376
92
|
/**
|
|
377
|
-
* Bun-backed implementation of Effect's `Stdio` service.
|
|
378
|
-
*
|
|
379
|
-
* This module provides the process stdio layer for Bun applications by reusing
|
|
380
|
-
* the shared Node-compatible implementation. The layer connects `Stdio` to the
|
|
381
|
-
* current Bun process: arguments come from `process.argv`, input is read from
|
|
382
|
-
* `process.stdin`, and output and error output write to `process.stdout` and
|
|
383
|
-
* `process.stderr`. It is intended for CLIs, scripts, command runners, test
|
|
384
|
-
* harnesses, and other process-oriented programs that need standard input and
|
|
385
|
-
* output through Effect services.
|
|
386
|
-
*
|
|
387
|
-
* The underlying stdio streams are global resources owned by the Bun process.
|
|
388
|
-
* The layer keeps stdin open and does not end stdout or stderr by default,
|
|
389
|
-
* which avoids closing handles that prompts, loggers, or other code may still
|
|
390
|
-
* use. Stdio may be attached to a TTY, pipe, or redirected file, so
|
|
391
|
-
* terminal-specific behavior such as raw mode, echo, colors, cursor control,
|
|
392
|
-
* and terminal dimensions should be coordinated with terminal APIs rather than
|
|
393
|
-
* assumed from this layer.
|
|
394
|
-
*
|
|
395
93
|
* @since 4.0.0
|
|
396
94
|
*/
|
|
397
95
|
export * as BunStdio from "./BunStdio.ts"
|
|
398
96
|
|
|
399
97
|
/**
|
|
400
|
-
* Bun stream interoperability for Effect streams.
|
|
401
|
-
*
|
|
402
|
-
* This module provides Bun-specific adapters for working with streaming data at
|
|
403
|
-
* the boundary between Bun APIs and Effect. It re-exports the shared Node stream
|
|
404
|
-
* adapters for Bun's Node-compatible stream APIs, and adds an optimized
|
|
405
|
-
* `ReadableStream` constructor that uses Bun's `readMany` support to pull
|
|
406
|
-
* batches of Web Stream values into an Effect `Stream`.
|
|
407
|
-
*
|
|
408
|
-
* Common uses include adapting Bun `Request` and `Response` bodies, multipart
|
|
409
|
-
* uploads, and other Web `ReadableStream` sources so they can be transformed,
|
|
410
|
-
* decoded, or piped with Effect stream operators. Pulling from the Effect stream
|
|
411
|
-
* drives reads from the underlying reader, while Bun and the Web Streams runtime
|
|
412
|
-
* still control their own internal buffering and source backpressure.
|
|
413
|
-
*
|
|
414
|
-
* Web `ReadableStream` readers take an exclusive lock on the source. Request and
|
|
415
|
-
* response bodies are also one-shot: once consumed they become disturbed and
|
|
416
|
-
* should not be read through another API. The adapter cancels the reader when
|
|
417
|
-
* the consuming scope is finalized by default; set `releaseLockOnEnd` when the
|
|
418
|
-
* stream is externally owned and should only have its lock released. Read errors
|
|
419
|
-
* are mapped through the provided `onError` function.
|
|
420
|
-
*
|
|
421
98
|
* @since 4.0.0
|
|
422
99
|
*/
|
|
423
100
|
export * as BunStream from "./BunStream.ts"
|
|
424
101
|
|
|
425
102
|
/**
|
|
426
|
-
* Bun-backed implementation of Effect's `Terminal` service.
|
|
427
|
-
*
|
|
428
|
-
* This module provides a scoped, process-backed terminal for Bun programs by
|
|
429
|
-
* adapting the runtime's Node-compatible stdin, stdout, and `readline` support.
|
|
430
|
-
* It is useful for CLIs, prompts, REPLs, and terminal interfaces that need
|
|
431
|
-
* prompt output, line input, keypress input, or terminal dimensions.
|
|
432
|
-
*
|
|
433
|
-
* The service uses the current process streams, so acquire it with a scope or
|
|
434
|
-
* provide `layer` to ensure cleanup. When stdin is attached to a TTY, raw mode
|
|
435
|
-
* is enabled while the terminal is active and restored when the scope closes;
|
|
436
|
-
* this changes how keys are delivered and can affect other consumers of stdin.
|
|
437
|
-
* In pipes, redirected input, or CI, raw mode may be unavailable, keypress input
|
|
438
|
-
* is limited, and stdout dimensions may be reported as zero.
|
|
439
|
-
*
|
|
440
103
|
* @since 4.0.0
|
|
441
104
|
*/
|
|
442
105
|
export * as BunTerminal from "./BunTerminal.ts"
|
|
443
106
|
|
|
444
107
|
/**
|
|
445
|
-
* Parent-side Bun support for Effect workers.
|
|
446
|
-
*
|
|
447
|
-
* This module provides the `WorkerPlatform` used by Bun programs that spawn
|
|
448
|
-
* and communicate with `globalThis.Worker` instances through Effect's worker
|
|
449
|
-
* protocol. Pair it with `BunWorkerRunner` in the worker entrypoint when
|
|
450
|
-
* building worker-backed RPC clients, moving CPU-bound work off the main
|
|
451
|
-
* thread, isolating Bun-only services, or hosting long-lived handlers behind a
|
|
452
|
-
* typed message boundary.
|
|
453
|
-
*
|
|
454
|
-
* The supplied spawner is responsible for creating the Bun worker for each
|
|
455
|
-
* numeric worker id. Messages follow Bun's worker cloning and transfer
|
|
456
|
-
* semantics, so payloads and transfer lists must be accepted by the Bun worker
|
|
457
|
-
* runtime. Calls to `send` are buffered until the worker runner posts its ready
|
|
458
|
-
* signal; if the worker entrypoint never starts `BunWorkerRunner`, those
|
|
459
|
-
* buffered messages will not be delivered. Scope finalization sends the Effect
|
|
460
|
-
* worker close signal, waits for Bun's `close` event for a short grace period,
|
|
461
|
-
* and then terminates the worker if graceful shutdown does not complete.
|
|
462
|
-
*
|
|
463
108
|
* @since 4.0.0
|
|
464
109
|
*/
|
|
465
110
|
export * as BunWorker from "./BunWorker.ts"
|
|
466
111
|
|
|
467
112
|
/**
|
|
468
|
-
* Bun runtime support for Effect worker runners.
|
|
469
|
-
*
|
|
470
|
-
* This module is intended for code that is already executing inside a Bun
|
|
471
|
-
* `Worker`. It provides the `WorkerRunnerPlatform` used by `WorkerRunner` to
|
|
472
|
-
* receive request messages from the parent, run the registered Effect handler,
|
|
473
|
-
* and send responses back over Bun's worker `postMessage` channel.
|
|
474
|
-
*
|
|
475
|
-
* Use it with `BunWorker` when a Bun program needs to move RPC handlers,
|
|
476
|
-
* CPU-bound computations, or Bun-only services into an isolated worker while
|
|
477
|
-
* communicating through the Effect worker protocol. The runner must be started
|
|
478
|
-
* from the worker entrypoint, not the parent process; startup fails when the
|
|
479
|
-
* current global worker scope does not expose `postMessage`. Shutdown is driven
|
|
480
|
-
* by the parent protocol message, which closes the worker port, so long-running
|
|
481
|
-
* handlers should remain interruptible and keep resource cleanup in scopes.
|
|
482
|
-
* Messages follow Bun's worker cloning and transfer semantics, so payload
|
|
483
|
-
* schemas, transfer lists, `messageerror` events, and worker `error` events
|
|
484
|
-
* should be considered at the boundary.
|
|
485
|
-
*
|
|
486
113
|
* @since 4.0.0
|
|
487
114
|
*/
|
|
488
115
|
export * as BunWorkerRunner from "./BunWorkerRunner.ts"
|