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