@effect/platform-bun 4.0.0-beta.65 → 4.0.0-beta.67
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/BunChildProcessSpawner.d.ts +1 -1
- package/dist/BunChildProcessSpawner.js +1 -1
- package/dist/BunClusterHttp.d.ts +41 -4
- package/dist/BunClusterHttp.d.ts.map +1 -1
- package/dist/BunClusterHttp.js +7 -3
- package/dist/BunClusterHttp.js.map +1 -1
- package/dist/BunClusterSocket.d.ts +44 -5
- package/dist/BunClusterSocket.d.ts.map +1 -1
- package/dist/BunClusterSocket.js +44 -5
- package/dist/BunClusterSocket.js.map +1 -1
- package/dist/BunFileSystem.d.ts +3 -1
- package/dist/BunFileSystem.d.ts.map +1 -1
- package/dist/BunFileSystem.js +26 -2
- package/dist/BunFileSystem.js.map +1 -1
- package/dist/BunHttpClient.d.ts +2 -2
- package/dist/BunHttpClient.js +2 -2
- package/dist/BunHttpPlatform.d.ts +3 -1
- package/dist/BunHttpPlatform.d.ts.map +1 -1
- package/dist/BunHttpPlatform.js +4 -2
- package/dist/BunHttpPlatform.js.map +1 -1
- package/dist/BunHttpServer.d.ts +53 -8
- package/dist/BunHttpServer.d.ts.map +1 -1
- package/dist/BunHttpServer.js +19 -7
- package/dist/BunHttpServer.js.map +1 -1
- package/dist/BunHttpServerRequest.d.ts +26 -2
- package/dist/BunHttpServerRequest.d.ts.map +1 -1
- package/dist/BunHttpServerRequest.js +3 -1
- package/dist/BunHttpServerRequest.js.map +1 -1
- package/dist/BunMultipart.d.ts +26 -3
- package/dist/BunMultipart.d.ts.map +1 -1
- package/dist/BunMultipart.js +6 -2
- package/dist/BunMultipart.js.map +1 -1
- package/dist/BunPath.d.ts +9 -3
- package/dist/BunPath.d.ts.map +1 -1
- package/dist/BunPath.js +27 -4
- package/dist/BunPath.js.map +1 -1
- package/dist/BunRedis.d.ts +34 -4
- package/dist/BunRedis.d.ts.map +1 -1
- package/dist/BunRedis.js +35 -5
- 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 +18 -2
- package/dist/BunRuntime.js.map +1 -1
- package/dist/BunServices.d.ts +29 -3
- package/dist/BunServices.d.ts.map +1 -1
- package/dist/BunServices.js +4 -1
- package/dist/BunServices.js.map +1 -1
- package/dist/BunSink.d.ts +2 -2
- package/dist/BunSink.js +2 -2
- package/dist/BunSocket.d.ts +30 -4
- package/dist/BunSocket.d.ts.map +1 -1
- package/dist/BunSocket.js +10 -3
- package/dist/BunSocket.js.map +1 -1
- package/dist/BunSocketServer.d.ts +2 -2
- package/dist/BunSocketServer.js +2 -2
- package/dist/BunStdio.d.ts +4 -1
- package/dist/BunStdio.d.ts.map +1 -1
- package/dist/BunStdio.js +23 -2
- 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 +24 -3
- package/dist/BunStream.js.map +1 -1
- package/dist/BunTerminal.d.ts +8 -2
- package/dist/BunTerminal.d.ts.map +1 -1
- package/dist/BunTerminal.js +23 -3
- package/dist/BunTerminal.js.map +1 -1
- package/dist/BunWorker.d.ts +9 -2
- package/dist/BunWorker.d.ts.map +1 -1
- package/dist/BunWorker.js +29 -4
- package/dist/BunWorker.js.map +1 -1
- package/dist/BunWorkerRunner.d.ts +5 -1
- package/dist/BunWorkerRunner.d.ts.map +1 -1
- package/dist/BunWorkerRunner.js +26 -4
- package/dist/BunWorkerRunner.js.map +1 -1
- package/dist/index.d.ts +22 -22
- package/dist/index.js +22 -22
- package/package.json +5 -5
- package/src/BunChildProcessSpawner.ts +1 -1
- package/src/BunClusterHttp.ts +41 -4
- package/src/BunClusterSocket.ts +44 -5
- package/src/BunFileSystem.ts +26 -2
- package/src/BunHttpClient.ts +2 -2
- package/src/BunHttpPlatform.ts +27 -3
- package/src/BunHttpServer.ts +54 -9
- package/src/BunHttpServerRequest.ts +26 -2
- package/src/BunMultipart.ts +26 -3
- package/src/BunPath.ts +27 -4
- package/src/BunRedis.ts +35 -5
- package/src/BunRuntime.ts +20 -4
- package/src/BunServices.ts +29 -3
- package/src/BunSink.ts +2 -2
- package/src/BunSocket.ts +30 -4
- package/src/BunSocketServer.ts +2 -2
- package/src/BunStdio.ts +23 -2
- package/src/BunStream.ts +24 -3
- package/src/BunTerminal.ts +23 -3
- package/src/BunWorker.ts +29 -4
- package/src/BunWorkerRunner.ts +26 -4
- package/src/index.ts +22 -22
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
-
*
|
|
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
|
package/src/BunMultipart.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
-
*
|
|
32
|
+
* Parses a Bun `Request` body as multipart data and returns a stream of multipart parts.
|
|
33
|
+
*
|
|
14
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
|
-
*
|
|
53
|
+
* Parses and persists multipart data from a Bun `Request`, requiring file-system, path, and scope services.
|
|
54
|
+
*
|
|
33
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
|
-
*
|
|
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
|
-
*
|
|
26
|
+
* Layer that provides the default `Path` service for Bun using the shared Node path implementation.
|
|
27
|
+
*
|
|
10
28
|
* @category layer
|
|
29
|
+
* @since 4.0.0
|
|
11
30
|
*/
|
|
12
31
|
export const layer: Layer.Layer<Path> = NodePath.layer
|
|
13
32
|
|
|
14
33
|
/**
|
|
15
|
-
*
|
|
34
|
+
* Layer that provides the POSIX `Path` service for Bun using the shared Node path implementation.
|
|
35
|
+
*
|
|
16
36
|
* @category layer
|
|
37
|
+
* @since 4.0.0
|
|
17
38
|
*/
|
|
18
39
|
export const layerPosix: Layer.Layer<Path> = NodePath.layerPosix
|
|
19
40
|
|
|
20
41
|
/**
|
|
21
|
-
*
|
|
42
|
+
* Layer that provides the Win32 `Path` service for Bun using the shared Node path implementation.
|
|
43
|
+
*
|
|
22
44
|
* @category layer
|
|
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
|
-
*
|
|
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
|
-
*
|
|
38
|
+
* Service tag for Bun Redis integration, exposing the raw `RedisClient` and a `use` helper that maps client promise failures to `RedisError`.
|
|
39
|
+
*
|
|
15
40
|
* @category Service
|
|
41
|
+
* @since 4.0.0
|
|
16
42
|
*/
|
|
17
43
|
export class BunRedis extends Context.Service<BunRedis, {
|
|
18
44
|
readonly client: RedisClient
|
|
@@ -53,22 +79,26 @@ const make = Effect.fnUntraced(function*(
|
|
|
53
79
|
})
|
|
54
80
|
|
|
55
81
|
/**
|
|
56
|
-
*
|
|
82
|
+
* Creates scoped Bun Redis layers for `Redis.Redis` and `BunRedis`, closing the underlying client when the scope finalizes.
|
|
83
|
+
*
|
|
57
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
|
-
*
|
|
92
|
+
* Creates scoped Bun Redis layers from configurable Redis options, closing the underlying client when the scope finalizes.
|
|
93
|
+
*
|
|
65
94
|
* @category Layers
|
|
95
|
+
* @since 4.0.0
|
|
66
96
|
*/
|
|
67
97
|
export const layerConfig = (
|
|
68
98
|
options: Config.Wrap<{ readonly url?: string } & RedisOptions>
|
|
69
99
|
): Layer.Layer<Redis.Redis | BunRedis, Config.ConfigError> =>
|
|
70
100
|
Layer.effectContext(
|
|
71
|
-
Config.unwrap(options).
|
|
101
|
+
Config.unwrap(options).pipe(
|
|
72
102
|
Effect.flatMap(make)
|
|
73
103
|
)
|
|
74
104
|
)
|
package/src/BunRuntime.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
48
|
* @category Run main
|
|
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
76
|
* @category Run main
|
|
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
109
|
* @category Run main
|
|
110
|
+
* @since 4.0.0
|
|
95
111
|
*/
|
|
96
112
|
<E, A>(
|
|
97
113
|
effect: Effect<A, E>,
|
package/src/BunServices.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
*/
|
|
4
24
|
import type { FileSystem } from "effect/FileSystem"
|
|
5
25
|
import * as Layer from "effect/Layer"
|
|
@@ -14,14 +34,20 @@ import * as BunStdio from "./BunStdio.ts"
|
|
|
14
34
|
import * as BunTerminal from "./BunTerminal.ts"
|
|
15
35
|
|
|
16
36
|
/**
|
|
17
|
-
*
|
|
37
|
+
* The union of core services provided by the Bun platform layer, including child
|
|
38
|
+
* process spawning, filesystem, path, stdio, and terminal services.
|
|
39
|
+
*
|
|
18
40
|
* @category models
|
|
41
|
+
* @since 4.0.0
|
|
19
42
|
*/
|
|
20
43
|
export type BunServices = ChildProcessSpawner | FileSystem | Path | Terminal | Stdio
|
|
21
44
|
|
|
22
45
|
/**
|
|
23
|
-
*
|
|
46
|
+
* Provides the default Bun implementations for child process spawning,
|
|
47
|
+
* filesystem, path, stdio, and terminal services.
|
|
48
|
+
*
|
|
24
49
|
* @category layer
|
|
50
|
+
* @since 4.0.0
|
|
25
51
|
*/
|
|
26
52
|
export const layer: Layer.Layer<BunServices> = BunChildProcessSpawner.layer.pipe(
|
|
27
53
|
Layer.provideMerge(Layer.mergeAll(
|
package/src/BunSink.ts
CHANGED
package/src/BunSocket.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun platform socket entry point for Effect sockets backed by Bun-compatible
|
|
3
|
+
* Node streams and Bun's native WebSocket implementation.
|
|
4
|
+
*
|
|
5
|
+
* This module re-exports the shared Node socket constructors for TCP clients,
|
|
6
|
+
* Unix domain socket clients, and adapters from existing Node `Duplex` streams,
|
|
7
|
+
* then adds Bun-specific WebSocket layers using `globalThis.WebSocket`. Use it
|
|
8
|
+
* in Bun applications that connect to raw socket protocols, Unix sockets,
|
|
9
|
+
* realtime WebSocket services, or Effect RPC transports that need a
|
|
10
|
+
* `Socket.Socket` layer.
|
|
11
|
+
*
|
|
12
|
+
* TCP lifecycle behavior comes from the shared Node layer: sockets are scoped,
|
|
13
|
+
* finalizers close or destroy the underlying stream, open timeouts become
|
|
14
|
+
* socket open errors, and read, write, and close events are mapped to
|
|
15
|
+
* `SocketError` values. TLS concerns depend on the transport being used: `wss:`
|
|
16
|
+
* URLs are handled by Bun's WebSocket implementation, while TLS-wrapped
|
|
17
|
+
* `Duplex` streams can be adapted after they have been created elsewhere.
|
|
18
|
+
* When closing intentionally, send `Socket.CloseEvent` values so the close code
|
|
19
|
+
* and reason are preserved through the socket lifecycle.
|
|
20
|
+
*
|
|
21
|
+
* @since 4.0.0
|
|
3
22
|
*/
|
|
4
23
|
import type * as Duration from "effect/Duration"
|
|
5
24
|
import type { Effect } from "effect/Effect"
|
|
@@ -8,13 +27,16 @@ import * as Layer from "effect/Layer"
|
|
|
8
27
|
import * as Socket from "effect/unstable/socket/Socket"
|
|
9
28
|
|
|
10
29
|
/**
|
|
11
|
-
* @since
|
|
30
|
+
* @since 4.0.0
|
|
12
31
|
*/
|
|
13
32
|
export * from "@effect/platform-node-shared/NodeSocket"
|
|
14
33
|
|
|
15
34
|
/**
|
|
16
|
-
*
|
|
35
|
+
* Provides a `Socket.WebSocketConstructor` backed by Bun's global
|
|
36
|
+
* `WebSocket` implementation.
|
|
37
|
+
*
|
|
17
38
|
* @category layers
|
|
39
|
+
* @since 4.0.0
|
|
18
40
|
*/
|
|
19
41
|
export const layerWebSocketConstructor: Layer.Layer<
|
|
20
42
|
Socket.WebSocketConstructor
|
|
@@ -23,8 +45,12 @@ export const layerWebSocketConstructor: Layer.Layer<
|
|
|
23
45
|
)
|
|
24
46
|
|
|
25
47
|
/**
|
|
26
|
-
*
|
|
48
|
+
* Creates a `Socket.Socket` layer for a WebSocket URL using Bun's global
|
|
49
|
+
* `WebSocket` constructor, honoring protocol, open-timeout, and close-code
|
|
50
|
+
* error options.
|
|
51
|
+
*
|
|
27
52
|
* @category layers
|
|
53
|
+
* @since 4.0.0
|
|
28
54
|
*/
|
|
29
55
|
export const layerWebSocket: (
|
|
30
56
|
url: string | Effect<string>,
|
package/src/BunSocketServer.ts
CHANGED
package/src/BunStdio.ts
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun-backed implementation of Effect's `Stdio` service.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the process stdio layer for Bun applications by reusing
|
|
5
|
+
* the shared Node-compatible implementation. The layer connects `Stdio` to the
|
|
6
|
+
* current Bun process: arguments come from `process.argv`, input is read from
|
|
7
|
+
* `process.stdin`, and output and error output write to `process.stdout` and
|
|
8
|
+
* `process.stderr`. It is intended for CLIs, scripts, command runners, test
|
|
9
|
+
* harnesses, and other process-oriented programs that need standard input and
|
|
10
|
+
* output through Effect services.
|
|
11
|
+
*
|
|
12
|
+
* The underlying stdio streams are global resources owned by the Bun process.
|
|
13
|
+
* The layer keeps stdin open and does not end stdout or stderr by default,
|
|
14
|
+
* which avoids closing handles that prompts, loggers, or other code may still
|
|
15
|
+
* use. Stdio may be attached to a TTY, pipe, or redirected file, so
|
|
16
|
+
* terminal-specific behavior such as raw mode, echo, colors, cursor control,
|
|
17
|
+
* and terminal dimensions should be coordinated with terminal APIs rather than
|
|
18
|
+
* assumed from this layer.
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
4
22
|
import * as NodeStdio from "@effect/platform-node-shared/NodeStdio"
|
|
5
23
|
import type * as Layer from "effect/Layer"
|
|
6
24
|
import type { Stdio } from "effect/Stdio"
|
|
7
25
|
|
|
8
26
|
/**
|
|
9
|
-
*
|
|
27
|
+
* Provides the `Stdio` service backed by the current process arguments,
|
|
28
|
+
* stdin, stdout, and stderr streams.
|
|
29
|
+
*
|
|
10
30
|
* @category layer
|
|
31
|
+
* @since 4.0.0
|
|
11
32
|
*/
|
|
12
33
|
export const layer: Layer.Layer<Stdio> = NodeStdio.layer
|
package/src/BunStream.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun stream interoperability for Effect streams.
|
|
3
|
+
*
|
|
4
|
+
* This module provides Bun-specific adapters for working with streaming data at
|
|
5
|
+
* the boundary between Bun APIs and Effect. It re-exports the shared Node stream
|
|
6
|
+
* adapters for Bun's Node-compatible stream APIs, and adds an optimized
|
|
7
|
+
* `ReadableStream` constructor that uses Bun's `readMany` support to pull
|
|
8
|
+
* batches of Web Stream values into an Effect `Stream`.
|
|
9
|
+
*
|
|
10
|
+
* Common uses include adapting Bun `Request` and `Response` bodies, multipart
|
|
11
|
+
* uploads, and other Web `ReadableStream` sources so they can be transformed,
|
|
12
|
+
* decoded, or piped with Effect stream operators. Pulling from the Effect stream
|
|
13
|
+
* drives reads from the underlying reader, while Bun and the Web Streams runtime
|
|
14
|
+
* still control their own internal buffering and source backpressure.
|
|
15
|
+
*
|
|
16
|
+
* Web `ReadableStream` readers take an exclusive lock on the source. Request and
|
|
17
|
+
* response bodies are also one-shot: once consumed they become disturbed and
|
|
18
|
+
* should not be read through another API. The adapter cancels the reader when
|
|
19
|
+
* the consuming scope is finalized by default; set `releaseLockOnEnd` when the
|
|
20
|
+
* stream is externally owned and should only have its lock released. Read errors
|
|
21
|
+
* are mapped through the provided `onError` function.
|
|
22
|
+
*
|
|
23
|
+
* @since 4.0.0
|
|
3
24
|
*/
|
|
4
25
|
import * as Arr from "effect/Array"
|
|
5
26
|
import * as Cause from "effect/Cause"
|
|
@@ -11,7 +32,7 @@ import * as Scope from "effect/Scope"
|
|
|
11
32
|
import * as Stream from "effect/Stream"
|
|
12
33
|
|
|
13
34
|
/**
|
|
14
|
-
* @since
|
|
35
|
+
* @since 4.0.0
|
|
15
36
|
*/
|
|
16
37
|
export * from "@effect/platform-node-shared/NodeStream"
|
|
17
38
|
|
|
@@ -19,7 +40,7 @@ export * from "@effect/platform-node-shared/NodeStream"
|
|
|
19
40
|
* An optimized version of `Stream.fromReadableStream` that uses the Bun
|
|
20
41
|
* .readMany API to read multiple values at once from a `ReadableStream`.
|
|
21
42
|
*
|
|
22
|
-
* @since
|
|
43
|
+
* @since 4.0.0
|
|
23
44
|
*/
|
|
24
45
|
export const fromReadableStream = <A, E>(
|
|
25
46
|
options: {
|
package/src/BunTerminal.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun-backed implementation of Effect's `Terminal` service.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a scoped, process-backed terminal for Bun programs by
|
|
5
|
+
* adapting the runtime's Node-compatible stdin, stdout, and `readline` support.
|
|
6
|
+
* It is useful for CLIs, prompts, REPLs, and terminal interfaces that need
|
|
7
|
+
* prompt output, line input, keypress input, or terminal dimensions.
|
|
8
|
+
*
|
|
9
|
+
* The service uses the current process streams, so acquire it with a scope or
|
|
10
|
+
* provide `layer` to ensure cleanup. When stdin is attached to a TTY, raw mode
|
|
11
|
+
* is enabled while the terminal is active and restored when the scope closes;
|
|
12
|
+
* this changes how keys are delivered and can affect other consumers of stdin.
|
|
13
|
+
* In pipes, redirected input, or CI, raw mode may be unavailable, keypress input
|
|
14
|
+
* is limited, and stdout dimensions may be reported as zero.
|
|
15
|
+
*
|
|
16
|
+
* @since 4.0.0
|
|
3
17
|
*/
|
|
4
18
|
import * as NodeTerminal from "@effect/platform-node-shared/NodeTerminal"
|
|
5
19
|
import type { Effect } from "effect/Effect"
|
|
@@ -8,13 +22,19 @@ import type { Scope } from "effect/Scope"
|
|
|
8
22
|
import type { Terminal, UserInput } from "effect/Terminal"
|
|
9
23
|
|
|
10
24
|
/**
|
|
11
|
-
*
|
|
25
|
+
* Creates a scoped `Terminal` service backed by process stdin/stdout, using the
|
|
26
|
+
* optional predicate to decide when key input should end the input stream.
|
|
27
|
+
*
|
|
12
28
|
* @category constructors
|
|
29
|
+
* @since 4.0.0
|
|
13
30
|
*/
|
|
14
31
|
export const make: (shouldQuit?: (input: UserInput) => boolean) => Effect<Terminal, never, Scope> = NodeTerminal.make
|
|
15
32
|
|
|
16
33
|
/**
|
|
17
|
-
*
|
|
34
|
+
* Provides the default process-backed `Terminal` service, ending key input on
|
|
35
|
+
* the default quit keys.
|
|
36
|
+
*
|
|
18
37
|
* @category layers
|
|
38
|
+
* @since 4.0.0
|
|
19
39
|
*/
|
|
20
40
|
export const layer: Layer<Terminal> = NodeTerminal.layer
|
package/src/BunWorker.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Parent-side Bun support for Effect workers.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the `WorkerPlatform` used by Bun programs that spawn
|
|
5
|
+
* and communicate with `globalThis.Worker` instances through Effect's worker
|
|
6
|
+
* protocol. Pair it with `BunWorkerRunner` in the worker entrypoint when
|
|
7
|
+
* building worker-backed RPC clients, moving CPU-bound work off the main
|
|
8
|
+
* thread, isolating Bun-only services, or hosting long-lived handlers behind a
|
|
9
|
+
* typed message boundary.
|
|
10
|
+
*
|
|
11
|
+
* The supplied spawner is responsible for creating the Bun worker for each
|
|
12
|
+
* numeric worker id. Messages follow Bun's worker cloning and transfer
|
|
13
|
+
* semantics, so payloads and transfer lists must be accepted by the Bun worker
|
|
14
|
+
* runtime. Calls to `send` are buffered until the worker runner posts its ready
|
|
15
|
+
* signal; if the worker entrypoint never starts `BunWorkerRunner`, those
|
|
16
|
+
* buffered messages will not be delivered. Scope finalization sends the Effect
|
|
17
|
+
* worker close signal, waits for Bun's `close` event for a short grace period,
|
|
18
|
+
* and then terminates the worker if graceful shutdown does not complete.
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
4
22
|
import * as Deferred from "effect/Deferred"
|
|
5
23
|
import * as Effect from "effect/Effect"
|
|
@@ -10,8 +28,11 @@ import * as Worker from "effect/unstable/workers/Worker"
|
|
|
10
28
|
import { WorkerError, WorkerUnknownError } from "effect/unstable/workers/WorkerError"
|
|
11
29
|
|
|
12
30
|
/**
|
|
13
|
-
*
|
|
31
|
+
* Provides the Bun `WorkerPlatform` together with a `Worker.Spawner` created
|
|
32
|
+
* from the supplied worker spawning function.
|
|
33
|
+
*
|
|
14
34
|
* @category layers
|
|
35
|
+
* @since 4.0.0
|
|
15
36
|
*/
|
|
16
37
|
export const layer = (
|
|
17
38
|
spawn: (id: number) => globalThis.Worker
|
|
@@ -22,8 +43,12 @@ export const layer = (
|
|
|
22
43
|
)
|
|
23
44
|
|
|
24
45
|
/**
|
|
25
|
-
*
|
|
46
|
+
* Provides the Bun `WorkerPlatform`, wiring worker messages and errors into
|
|
47
|
+
* Effect workers and requesting graceful worker shutdown during scope
|
|
48
|
+
* finalization before terminating on timeout.
|
|
49
|
+
*
|
|
26
50
|
* @category layers
|
|
51
|
+
* @since 4.0.0
|
|
27
52
|
*/
|
|
28
53
|
export const layerPlatform = Layer.succeed(Worker.WorkerPlatform)(
|
|
29
54
|
Worker.makePlatform<globalThis.Worker>()({
|
|
@@ -59,7 +84,7 @@ export const layerPlatform = Layer.succeed(Worker.WorkerPlatform)(
|
|
|
59
84
|
message: "An error event was emitted",
|
|
60
85
|
cause: event.error ?? event.message
|
|
61
86
|
})
|
|
62
|
-
})
|
|
87
|
+
})
|
|
63
88
|
)
|
|
64
89
|
}
|
|
65
90
|
port.addEventListener("message", onMessage)
|
package/src/BunWorkerRunner.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun runtime support for Effect worker runners.
|
|
3
|
+
*
|
|
4
|
+
* This module is intended for code that is already executing inside a Bun
|
|
5
|
+
* `Worker`. It provides the `WorkerRunnerPlatform` used by `WorkerRunner` to
|
|
6
|
+
* receive request messages from the parent, run the registered Effect handler,
|
|
7
|
+
* and send responses back over Bun's worker `postMessage` channel.
|
|
8
|
+
*
|
|
9
|
+
* Use it with `BunWorker` when a Bun program needs to move RPC handlers,
|
|
10
|
+
* CPU-bound computations, or Bun-only services into an isolated worker while
|
|
11
|
+
* communicating through the Effect worker protocol. The runner must be started
|
|
12
|
+
* from the worker entrypoint, not the parent process; startup fails when the
|
|
13
|
+
* current global worker scope does not expose `postMessage`. Shutdown is driven
|
|
14
|
+
* by the parent protocol message, which closes the worker port, so long-running
|
|
15
|
+
* handlers should remain interruptible and keep resource cleanup in scopes.
|
|
16
|
+
* Messages follow Bun's worker cloning and transfer semantics, so payload
|
|
17
|
+
* schemas, transfer lists, `messageerror` events, and worker `error` events
|
|
18
|
+
* should be considered at the boundary.
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
4
22
|
import * as Cause from "effect/Cause"
|
|
5
23
|
import * as Deferred from "effect/Deferred"
|
|
@@ -15,8 +33,12 @@ import * as WorkerRunner from "effect/unstable/workers/WorkerRunner"
|
|
|
15
33
|
declare const self: MessagePort
|
|
16
34
|
|
|
17
35
|
/**
|
|
18
|
-
*
|
|
36
|
+
* Provides the `WorkerRunnerPlatform` for code running inside a Bun worker,
|
|
37
|
+
* routing parent messages to the registered handler and sending responses back
|
|
38
|
+
* through the worker port.
|
|
39
|
+
*
|
|
19
40
|
* @category layers
|
|
41
|
+
* @since 4.0.0
|
|
20
42
|
*/
|
|
21
43
|
export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succeed(WorkerRunner.WorkerRunnerPlatform)({
|
|
22
44
|
start: Effect.fnUntraced(function*<O = unknown, I = unknown>() {
|
|
@@ -62,7 +84,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
|
|
|
62
84
|
message: "received messageerror event",
|
|
63
85
|
cause: error.data
|
|
64
86
|
})
|
|
65
|
-
})
|
|
87
|
+
})
|
|
66
88
|
)
|
|
67
89
|
}
|
|
68
90
|
function onError(error: MessageEvent) {
|
|
@@ -73,7 +95,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
|
|
|
73
95
|
message: "received error event",
|
|
74
96
|
cause: error.data
|
|
75
97
|
})
|
|
76
|
-
})
|
|
98
|
+
})
|
|
77
99
|
)
|
|
78
100
|
}
|
|
79
101
|
yield* Scope.addFinalizer(
|