@effect/platform-bun 4.0.0-beta.7 → 4.0.0-beta.71
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 +70 -7
- package/dist/BunClusterHttp.d.ts.map +1 -1
- package/dist/BunClusterHttp.js +41 -10
- package/dist/BunClusterHttp.js.map +1 -1
- package/dist/BunClusterSocket.d.ts +54 -9
- package/dist/BunClusterSocket.d.ts.map +1 -1
- package/dist/BunClusterSocket.js +54 -9
- package/dist/BunClusterSocket.js.map +1 -1
- package/dist/BunCrypto.d.ts +10 -0
- package/dist/BunCrypto.d.ts.map +1 -0
- package/dist/BunCrypto.js +22 -0
- package/dist/BunCrypto.js.map +1 -0
- package/dist/BunFileSystem.d.ts +4 -2
- package/dist/BunFileSystem.d.ts.map +1 -1
- package/dist/BunFileSystem.js +27 -3
- 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 +4 -2
- package/dist/BunHttpPlatform.d.ts.map +1 -1
- package/dist/BunHttpPlatform.js +5 -3
- package/dist/BunHttpPlatform.js.map +1 -1
- package/dist/BunHttpServer.d.ts +77 -19
- package/dist/BunHttpServer.d.ts.map +1 -1
- package/dist/BunHttpServer.js +63 -36
- 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 +28 -5
- package/dist/BunMultipart.d.ts.map +1 -1
- package/dist/BunMultipart.js +15 -5
- package/dist/BunMultipart.js.map +1 -1
- package/dist/BunPath.d.ts +12 -6
- package/dist/BunPath.d.ts.map +1 -1
- package/dist/BunPath.js +42 -7
- package/dist/BunPath.js.map +1 -1
- package/dist/BunRedis.d.ts +48 -9
- package/dist/BunRedis.d.ts.map +1 -1
- package/dist/BunRedis.js +51 -12
- package/dist/BunRedis.js.map +1 -1
- package/dist/BunRuntime.d.ts +24 -30
- package/dist/BunRuntime.d.ts.map +1 -1
- package/dist/BunRuntime.js +38 -11
- package/dist/BunRuntime.js.map +1 -1
- package/dist/BunServices.d.ts +32 -5
- package/dist/BunServices.d.ts.map +1 -1
- package/dist/BunServices.js +7 -3
- 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 +5 -2
- package/dist/BunStdio.d.ts.map +1 -1
- package/dist/BunStdio.js +36 -3
- package/dist/BunStdio.js.map +1 -1
- package/dist/BunStream.d.ts +3 -2
- package/dist/BunStream.d.ts.map +1 -1
- package/dist/BunStream.js +34 -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 +41 -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 +46 -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 +41 -5
- package/dist/BunWorkerRunner.js.map +1 -1
- package/dist/index.d.ts +25 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -23
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/BunChildProcessSpawner.ts +1 -1
- package/src/BunClusterHttp.ts +75 -11
- package/src/BunClusterSocket.ts +54 -9
- package/src/BunCrypto.ts +24 -0
- package/src/BunFileSystem.ts +27 -3
- package/src/BunHttpClient.ts +2 -2
- package/src/BunHttpPlatform.ts +28 -4
- package/src/BunHttpServer.ts +128 -56
- package/src/BunHttpServerRequest.ts +26 -2
- package/src/BunMultipart.ts +36 -6
- package/src/BunPath.ts +42 -7
- package/src/BunRedis.ts +53 -14
- package/src/BunRuntime.ts +54 -31
- package/src/BunServices.ts +34 -5
- package/src/BunSink.ts +2 -2
- package/src/BunSocket.ts +30 -4
- package/src/BunSocketServer.ts +2 -2
- package/src/BunStdio.ts +36 -3
- package/src/BunStream.ts +34 -3
- package/src/BunTerminal.ts +41 -3
- package/src/BunWorker.ts +46 -4
- package/src/BunWorkerRunner.ts +41 -5
- package/src/index.ts +26 -23
package/src/BunRuntime.ts
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun process runner for Effect programs.
|
|
3
|
+
*
|
|
4
|
+
* This module exposes Bun's `runMain` entry point. It is the function to call
|
|
5
|
+
* at the outer edge of a Bun CLI, script, server, or worker when a single
|
|
6
|
+
* Effect should become the process main fiber and use Bun's Node-compatible
|
|
7
|
+
* process, signal, and teardown behavior.
|
|
8
|
+
*
|
|
9
|
+
* **Mental model**
|
|
10
|
+
*
|
|
11
|
+
* `runMain` delegates to the shared Node-compatible runner. It starts the
|
|
12
|
+
* supplied Effect as the process root, reports failures through the configured
|
|
13
|
+
* runtime reporting, and translates `SIGINT` or `SIGTERM` into interruption so
|
|
14
|
+
* scoped resources can finalize before teardown chooses an exit code.
|
|
15
|
+
*
|
|
16
|
+
* **Common tasks**
|
|
17
|
+
*
|
|
18
|
+
* - Launch a Bun CLI or one-off script from an Effect.
|
|
19
|
+
* - Start a long-running Bun server or worker under an Effect scope.
|
|
20
|
+
* - Customize error reporting or teardown with `runMain` options.
|
|
21
|
+
* - Provide `BunServices.layer` or narrower layers before calling `runMain`.
|
|
22
|
+
*
|
|
23
|
+
* **Gotchas**
|
|
24
|
+
*
|
|
25
|
+
* This module runs the program; it does not provide filesystem, network,
|
|
26
|
+
* terminal, or other platform services. Long-lived servers, subscriptions, and
|
|
27
|
+
* worker loops should be acquired in Effect scopes so interruption from process
|
|
28
|
+
* signals can release them. Finalizers that never complete can keep shutdown
|
|
29
|
+
* waiting.
|
|
30
|
+
*
|
|
31
|
+
* @since 4.0.0
|
|
3
32
|
*/
|
|
4
33
|
import * as NodeRuntime from "@effect/platform-node-shared/NodeRuntime"
|
|
5
34
|
import type { Effect } from "effect/Effect"
|
|
@@ -8,6 +37,12 @@ import type { Teardown } from "effect/Runtime"
|
|
|
8
37
|
/**
|
|
9
38
|
* Helps you run a main effect with built-in error handling, logging, and signal management.
|
|
10
39
|
*
|
|
40
|
+
* **When to use**
|
|
41
|
+
*
|
|
42
|
+
* Use to run an Effect as your application's main program,
|
|
43
|
+
* especially when you need structured error handling, log management,
|
|
44
|
+
* interrupt support, or advanced teardown capabilities.
|
|
45
|
+
*
|
|
11
46
|
* **Details**
|
|
12
47
|
*
|
|
13
48
|
* This function launches an Effect as the main entry point, setting exit codes
|
|
@@ -16,26 +51,24 @@ import type { Teardown } from "effect/Runtime"
|
|
|
16
51
|
* behaviors can be turned off. You can also provide custom teardown logic to
|
|
17
52
|
* finalize resources or produce different exit codes.
|
|
18
53
|
*
|
|
19
|
-
* **Options**
|
|
20
|
-
*
|
|
21
54
|
* An optional object that can include:
|
|
22
55
|
* - `disableErrorReporting`: Turn off automatic error logging.
|
|
23
56
|
* - `disablePrettyLogger`: Avoid adding the pretty logger.
|
|
24
57
|
* - `teardown`: Provide custom finalization logic.
|
|
25
58
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* Use this function to run an Effect as your application’s main program, especially
|
|
29
|
-
* when you need structured error handling, log management, interrupt support,
|
|
30
|
-
* or advanced teardown capabilities.
|
|
31
|
-
*
|
|
32
|
-
* @since 1.0.0
|
|
33
|
-
* @category Run main
|
|
59
|
+
* @category running
|
|
60
|
+
* @since 4.0.0
|
|
34
61
|
*/
|
|
35
62
|
export const runMain: {
|
|
36
63
|
/**
|
|
37
64
|
* Helps you run a main effect with built-in error handling, logging, and signal management.
|
|
38
65
|
*
|
|
66
|
+
* **When to use**
|
|
67
|
+
*
|
|
68
|
+
* Use to run an Effect as your application's main program,
|
|
69
|
+
* especially when you need structured error handling, log management,
|
|
70
|
+
* interrupt support, or advanced teardown capabilities.
|
|
71
|
+
*
|
|
39
72
|
* **Details**
|
|
40
73
|
*
|
|
41
74
|
* This function launches an Effect as the main entry point, setting exit codes
|
|
@@ -44,21 +77,13 @@ export const runMain: {
|
|
|
44
77
|
* behaviors can be turned off. You can also provide custom teardown logic to
|
|
45
78
|
* finalize resources or produce different exit codes.
|
|
46
79
|
*
|
|
47
|
-
* **Options**
|
|
48
|
-
*
|
|
49
80
|
* An optional object that can include:
|
|
50
81
|
* - `disableErrorReporting`: Turn off automatic error logging.
|
|
51
82
|
* - `disablePrettyLogger`: Avoid adding the pretty logger.
|
|
52
83
|
* - `teardown`: Provide custom finalization logic.
|
|
53
84
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* Use this function to run an Effect as your application’s main program, especially
|
|
57
|
-
* when you need structured error handling, log management, interrupt support,
|
|
58
|
-
* or advanced teardown capabilities.
|
|
59
|
-
*
|
|
60
|
-
* @since 1.0.0
|
|
61
|
-
* @category Run main
|
|
85
|
+
* @category running
|
|
86
|
+
* @since 4.0.0
|
|
62
87
|
*/
|
|
63
88
|
(
|
|
64
89
|
options?: {
|
|
@@ -69,6 +94,12 @@ export const runMain: {
|
|
|
69
94
|
/**
|
|
70
95
|
* Helps you run a main effect with built-in error handling, logging, and signal management.
|
|
71
96
|
*
|
|
97
|
+
* **When to use**
|
|
98
|
+
*
|
|
99
|
+
* Use to run an Effect as your application's main program,
|
|
100
|
+
* especially when you need structured error handling, log management,
|
|
101
|
+
* interrupt support, or advanced teardown capabilities.
|
|
102
|
+
*
|
|
72
103
|
* **Details**
|
|
73
104
|
*
|
|
74
105
|
* This function launches an Effect as the main entry point, setting exit codes
|
|
@@ -77,21 +108,13 @@ export const runMain: {
|
|
|
77
108
|
* behaviors can be turned off. You can also provide custom teardown logic to
|
|
78
109
|
* finalize resources or produce different exit codes.
|
|
79
110
|
*
|
|
80
|
-
* **Options**
|
|
81
|
-
*
|
|
82
111
|
* An optional object that can include:
|
|
83
112
|
* - `disableErrorReporting`: Turn off automatic error logging.
|
|
84
113
|
* - `disablePrettyLogger`: Avoid adding the pretty logger.
|
|
85
114
|
* - `teardown`: Provide custom finalization logic.
|
|
86
115
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* Use this function to run an Effect as your application’s main program, especially
|
|
90
|
-
* when you need structured error handling, log management, interrupt support,
|
|
91
|
-
* or advanced teardown capabilities.
|
|
92
|
-
*
|
|
93
|
-
* @since 1.0.0
|
|
94
|
-
* @category Run main
|
|
116
|
+
* @category running
|
|
117
|
+
* @since 4.0.0
|
|
95
118
|
*/
|
|
96
119
|
<E, A>(
|
|
97
120
|
effect: Effect<A, E>,
|
package/src/BunServices.ts
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
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
|
*/
|
|
24
|
+
import type { Crypto } from "effect/Crypto"
|
|
4
25
|
import type { FileSystem } from "effect/FileSystem"
|
|
5
26
|
import * as Layer from "effect/Layer"
|
|
6
27
|
import type { Path } from "effect/Path"
|
|
@@ -8,24 +29,32 @@ import type { Stdio } from "effect/Stdio"
|
|
|
8
29
|
import type { Terminal } from "effect/Terminal"
|
|
9
30
|
import type { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner"
|
|
10
31
|
import * as BunChildProcessSpawner from "./BunChildProcessSpawner.ts"
|
|
32
|
+
import * as BunCrypto from "./BunCrypto.ts"
|
|
11
33
|
import * as BunFileSystem from "./BunFileSystem.ts"
|
|
12
34
|
import * as BunPath from "./BunPath.ts"
|
|
13
35
|
import * as BunStdio from "./BunStdio.ts"
|
|
14
36
|
import * as BunTerminal from "./BunTerminal.ts"
|
|
15
37
|
|
|
16
38
|
/**
|
|
17
|
-
*
|
|
39
|
+
* The union of core services provided by the Bun platform layer, including child
|
|
40
|
+
* process spawning, filesystem, path, stdio, and terminal services.
|
|
41
|
+
*
|
|
18
42
|
* @category models
|
|
43
|
+
* @since 4.0.0
|
|
19
44
|
*/
|
|
20
|
-
export type BunServices = ChildProcessSpawner | FileSystem | Path | Terminal | Stdio
|
|
45
|
+
export type BunServices = ChildProcessSpawner | Crypto | FileSystem | Path | Terminal | Stdio
|
|
21
46
|
|
|
22
47
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
48
|
+
* Provides the default Bun implementations for child process spawning,
|
|
49
|
+
* filesystem, path, stdio, and terminal services.
|
|
50
|
+
*
|
|
51
|
+
* @category layers
|
|
52
|
+
* @since 4.0.0
|
|
25
53
|
*/
|
|
26
54
|
export const layer: Layer.Layer<BunServices> = BunChildProcessSpawner.layer.pipe(
|
|
27
55
|
Layer.provideMerge(Layer.mergeAll(
|
|
28
56
|
BunFileSystem.layer,
|
|
57
|
+
BunCrypto.layer,
|
|
29
58
|
BunPath.layer,
|
|
30
59
|
BunStdio.layer,
|
|
31
60
|
BunTerminal.layer
|
package/src/BunSink.ts
CHANGED
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,45 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Process stdio for Bun applications.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the Bun layer for Effect's `Stdio` service by adapting
|
|
5
|
+
* the current process arguments and standard streams. Arguments come from
|
|
6
|
+
* `process.argv`, input is read from `process.stdin`, and output and error
|
|
7
|
+
* output write to `process.stdout` and `process.stderr`.
|
|
8
|
+
*
|
|
9
|
+
* **Mental model**
|
|
10
|
+
*
|
|
11
|
+
* `BunStdio.layer` is a thin Bun-facing wrapper around the shared
|
|
12
|
+
* Node-compatible stdio implementation. It does not create private streams for
|
|
13
|
+
* an application; it exposes the global streams owned by the running Bun
|
|
14
|
+
* process through the `Stdio` service.
|
|
15
|
+
*
|
|
16
|
+
* **Common tasks**
|
|
17
|
+
*
|
|
18
|
+
* - Provide `Stdio` for Bun CLIs, scripts, command runners, and tests.
|
|
19
|
+
* - Read process arguments or standard input through Effect services.
|
|
20
|
+
* - Write normal output and diagnostics without depending directly on
|
|
21
|
+
* `process.stdout` or `process.stderr`.
|
|
22
|
+
*
|
|
23
|
+
* **Gotchas**
|
|
24
|
+
*
|
|
25
|
+
* The layer keeps stdin open and does not end stdout or stderr by default,
|
|
26
|
+
* which avoids closing handles that prompts, loggers, or other code may still
|
|
27
|
+
* use. Stdio may be attached to a TTY, pipe, or redirected file, so
|
|
28
|
+
* terminal-specific behavior such as raw mode, echo, colors, cursor control,
|
|
29
|
+
* and terminal dimensions should be handled with terminal APIs such as
|
|
30
|
+
* `BunTerminal`, not inferred from this layer.
|
|
31
|
+
*
|
|
32
|
+
* @since 4.0.0
|
|
3
33
|
*/
|
|
4
34
|
import * as NodeStdio from "@effect/platform-node-shared/NodeStdio"
|
|
5
35
|
import type * as Layer from "effect/Layer"
|
|
6
36
|
import type { Stdio } from "effect/Stdio"
|
|
7
37
|
|
|
8
38
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
39
|
+
* Provides the `Stdio` service backed by the current process arguments,
|
|
40
|
+
* stdin, stdout, and stderr streams.
|
|
41
|
+
*
|
|
42
|
+
* @category layers
|
|
43
|
+
* @since 4.0.0
|
|
11
44
|
*/
|
|
12
45
|
export const layer: Layer.Layer<Stdio> = NodeStdio.layer
|
package/src/BunStream.ts
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun stream interoperability for Effect streams.
|
|
3
|
+
*
|
|
4
|
+
* This module is the Bun entry point for adapting runtime streams into Effect's
|
|
5
|
+
* streaming model. It re-exports the shared Node stream adapters for Bun's
|
|
6
|
+
* Node-compatible stream APIs and adds {@link fromReadableStream}, a Web
|
|
7
|
+
* `ReadableStream` adapter that uses Bun's `readMany` reader method to pull
|
|
8
|
+
* batches of values into an Effect `Stream`.
|
|
9
|
+
*
|
|
10
|
+
* **Mental model**
|
|
11
|
+
*
|
|
12
|
+
* Consuming the returned `Stream` drives reads from the underlying
|
|
13
|
+
* `ReadableStreamDefaultReader`. Each pull asks Bun for the next batch, empty
|
|
14
|
+
* batches are skipped, read failures are translated with `onError`, and the
|
|
15
|
+
* reader is finalized with the surrounding Effect scope.
|
|
16
|
+
*
|
|
17
|
+
* **Common tasks**
|
|
18
|
+
*
|
|
19
|
+
* Use {@link fromReadableStream} for Bun `Request` and `Response` bodies,
|
|
20
|
+
* multipart uploads, and other Web stream sources that should be transformed,
|
|
21
|
+
* decoded, or piped with Effect stream operators. Use the re-exported Node
|
|
22
|
+
* stream adapters for APIs that expose Bun's Node-compatible `stream` types.
|
|
23
|
+
*
|
|
24
|
+
* **Gotchas**
|
|
25
|
+
*
|
|
26
|
+
* Web stream readers hold an exclusive lock. Request and response bodies are
|
|
27
|
+
* also one-shot; once consumed they are disturbed and should not be read through
|
|
28
|
+
* another API. By default finalization cancels the reader; set
|
|
29
|
+
* `releaseLockOnEnd` when the stream is externally owned and only the reader
|
|
30
|
+
* lock should be released.
|
|
31
|
+
*
|
|
32
|
+
* @since 4.0.0
|
|
3
33
|
*/
|
|
4
34
|
import * as Arr from "effect/Array"
|
|
5
35
|
import * as Cause from "effect/Cause"
|
|
@@ -11,7 +41,7 @@ import * as Scope from "effect/Scope"
|
|
|
11
41
|
import * as Stream from "effect/Stream"
|
|
12
42
|
|
|
13
43
|
/**
|
|
14
|
-
* @since
|
|
44
|
+
* @since 4.0.0
|
|
15
45
|
*/
|
|
16
46
|
export * from "@effect/platform-node-shared/NodeStream"
|
|
17
47
|
|
|
@@ -19,7 +49,8 @@ export * from "@effect/platform-node-shared/NodeStream"
|
|
|
19
49
|
* An optimized version of `Stream.fromReadableStream` that uses the Bun
|
|
20
50
|
* .readMany API to read multiple values at once from a `ReadableStream`.
|
|
21
51
|
*
|
|
22
|
-
* @
|
|
52
|
+
* @category constructors
|
|
53
|
+
* @since 4.0.0
|
|
23
54
|
*/
|
|
24
55
|
export const fromReadableStream = <A, E>(
|
|
25
56
|
options: {
|
package/src/BunTerminal.ts
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun-backed implementation of Effect's `Terminal` service.
|
|
3
|
+
*
|
|
4
|
+
* This module adapts Bun's Node-compatible `stdin`, `stdout`, and `readline`
|
|
5
|
+
* support into a scoped `Terminal` service. It is intended for Bun CLIs,
|
|
6
|
+
* prompts, REPLs, and terminal interfaces that need prompt output, line input,
|
|
7
|
+
* keypress input, or terminal dimensions through Effect services.
|
|
8
|
+
*
|
|
9
|
+
* **Mental model**
|
|
10
|
+
*
|
|
11
|
+
* - {@link make} creates a scoped terminal from the current process streams.
|
|
12
|
+
* - {@link layer} provides the default live terminal service for Bun programs.
|
|
13
|
+
* - The implementation reuses the shared Node-compatible terminal adapter, so
|
|
14
|
+
* behavior follows the capabilities of Bun's process streams and readline
|
|
15
|
+
* support.
|
|
16
|
+
*
|
|
17
|
+
* **Common tasks**
|
|
18
|
+
*
|
|
19
|
+
* - Provide terminal access at the edge of a Bun CLI with {@link layer}.
|
|
20
|
+
* - Customize which key ends keypress input by calling {@link make} directly.
|
|
21
|
+
* - Read lines, read keypresses, display prompts, and inspect terminal size
|
|
22
|
+
* through the `Terminal` service once it is provided.
|
|
23
|
+
*
|
|
24
|
+
* **Gotchas**
|
|
25
|
+
*
|
|
26
|
+
* - The service uses global process streams. Acquire it with a scope, or
|
|
27
|
+
* provide {@link layer}, so raw mode and readline listeners are cleaned up.
|
|
28
|
+
* - When `stdin` is a TTY, raw mode is enabled while the terminal is active and
|
|
29
|
+
* restored when the scope closes; this changes how keys are delivered and can
|
|
30
|
+
* affect other stdin consumers.
|
|
31
|
+
* - In pipes, redirected input, or CI, raw mode may be unavailable, keypress
|
|
32
|
+
* input is limited, and stdout dimensions may be reported as zero.
|
|
33
|
+
*
|
|
34
|
+
* @since 4.0.0
|
|
3
35
|
*/
|
|
4
36
|
import * as NodeTerminal from "@effect/platform-node-shared/NodeTerminal"
|
|
5
37
|
import type { Effect } from "effect/Effect"
|
|
@@ -8,13 +40,19 @@ import type { Scope } from "effect/Scope"
|
|
|
8
40
|
import type { Terminal, UserInput } from "effect/Terminal"
|
|
9
41
|
|
|
10
42
|
/**
|
|
11
|
-
*
|
|
43
|
+
* Creates a scoped `Terminal` service backed by process stdin/stdout, using the
|
|
44
|
+
* optional predicate to decide when key input should end the input stream.
|
|
45
|
+
*
|
|
12
46
|
* @category constructors
|
|
47
|
+
* @since 4.0.0
|
|
13
48
|
*/
|
|
14
49
|
export const make: (shouldQuit?: (input: UserInput) => boolean) => Effect<Terminal, never, Scope> = NodeTerminal.make
|
|
15
50
|
|
|
16
51
|
/**
|
|
17
|
-
*
|
|
52
|
+
* Provides the default process-backed `Terminal` service, ending key input on
|
|
53
|
+
* the default quit keys.
|
|
54
|
+
*
|
|
18
55
|
* @category layers
|
|
56
|
+
* @since 4.0.0
|
|
19
57
|
*/
|
|
20
58
|
export const layer: Layer<Terminal> = NodeTerminal.layer
|
package/src/BunWorker.ts
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Parent-side worker support for Bun applications.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the `WorkerPlatform` used by Bun programs that spawn and
|
|
5
|
+
* 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
|
+
* **Mental model**
|
|
12
|
+
*
|
|
13
|
+
* `layer(spawn)` installs both the Bun `WorkerPlatform` and a `Worker.Spawner`.
|
|
14
|
+
* The supplied `spawn` function creates the Bun worker for each numeric worker
|
|
15
|
+
* id. The platform listens for worker messages and errors, wraps outgoing data
|
|
16
|
+
* in the Effect worker protocol, and buffers `send` calls until the worker
|
|
17
|
+
* runner posts its ready signal.
|
|
18
|
+
*
|
|
19
|
+
* **Common tasks**
|
|
20
|
+
*
|
|
21
|
+
* - Run Effect worker clients in a Bun parent process.
|
|
22
|
+
* - Move RPC handlers, CPU-bound computations, or Bun-only services into a
|
|
23
|
+
* dedicated worker.
|
|
24
|
+
* - Provide custom worker creation logic while keeping message handling and
|
|
25
|
+
* cleanup inside Effect scopes.
|
|
26
|
+
*
|
|
27
|
+
* **Gotchas**
|
|
28
|
+
*
|
|
29
|
+
* This module is for the parent side only; the worker entrypoint must start
|
|
30
|
+
* `BunWorkerRunner`. If the runner never starts or never posts readiness,
|
|
31
|
+
* buffered messages will not be delivered. Payloads and transfer lists use
|
|
32
|
+
* Bun's worker cloning and transfer semantics, so they must be accepted by the
|
|
33
|
+
* Bun worker runtime. Scope finalization sends the Effect worker close signal,
|
|
34
|
+
* waits for Bun's `close` event for a short grace period, and then terminates
|
|
35
|
+
* the worker if graceful shutdown does not complete.
|
|
36
|
+
*
|
|
37
|
+
* @since 4.0.0
|
|
3
38
|
*/
|
|
4
39
|
import * as Deferred from "effect/Deferred"
|
|
5
40
|
import * as Effect from "effect/Effect"
|
|
@@ -10,8 +45,11 @@ import * as Worker from "effect/unstable/workers/Worker"
|
|
|
10
45
|
import { WorkerError, WorkerUnknownError } from "effect/unstable/workers/WorkerError"
|
|
11
46
|
|
|
12
47
|
/**
|
|
13
|
-
*
|
|
48
|
+
* Provides the Bun `WorkerPlatform` together with a `Worker.Spawner` created
|
|
49
|
+
* from the supplied worker spawning function.
|
|
50
|
+
*
|
|
14
51
|
* @category layers
|
|
52
|
+
* @since 4.0.0
|
|
15
53
|
*/
|
|
16
54
|
export const layer = (
|
|
17
55
|
spawn: (id: number) => globalThis.Worker
|
|
@@ -22,8 +60,12 @@ export const layer = (
|
|
|
22
60
|
)
|
|
23
61
|
|
|
24
62
|
/**
|
|
25
|
-
*
|
|
63
|
+
* Provides the Bun `WorkerPlatform`, wiring worker messages and errors into
|
|
64
|
+
* Effect workers and requesting graceful worker shutdown during scope
|
|
65
|
+
* finalization before terminating on timeout.
|
|
66
|
+
*
|
|
26
67
|
* @category layers
|
|
68
|
+
* @since 4.0.0
|
|
27
69
|
*/
|
|
28
70
|
export const layerPlatform = Layer.succeed(Worker.WorkerPlatform)(
|
|
29
71
|
Worker.makePlatform<globalThis.Worker>()({
|
|
@@ -59,7 +101,7 @@ export const layerPlatform = Layer.succeed(Worker.WorkerPlatform)(
|
|
|
59
101
|
message: "An error event was emitted",
|
|
60
102
|
cause: event.error ?? event.message
|
|
61
103
|
})
|
|
62
|
-
})
|
|
104
|
+
})
|
|
63
105
|
)
|
|
64
106
|
}
|
|
65
107
|
port.addEventListener("message", onMessage)
|
package/src/BunWorkerRunner.ts
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Worker-entrypoint support for Bun worker runners.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the Bun `WorkerRunnerPlatform` for code already running
|
|
5
|
+
* inside a Bun `Worker`. It receives request messages from the parent-side
|
|
6
|
+
* `BunWorker` platform, runs the handler registered with `WorkerRunner.run`,
|
|
7
|
+
* and posts responses back through Bun's worker `postMessage` channel.
|
|
8
|
+
*
|
|
9
|
+
* **Mental model**
|
|
10
|
+
*
|
|
11
|
+
* The parent process installs `BunWorker.layer`; the worker entrypoint installs
|
|
12
|
+
* this `layer` and starts `WorkerRunner`. Bun exposes one worker port to this
|
|
13
|
+
* runner, so every message uses port id `0`. The first message sent by this
|
|
14
|
+
* layer is the ready signal consumed by the parent platform before buffered
|
|
15
|
+
* sends are flushed.
|
|
16
|
+
*
|
|
17
|
+
* **Common tasks**
|
|
18
|
+
*
|
|
19
|
+
* - Host Effect worker or RPC handlers inside a Bun worker entrypoint.
|
|
20
|
+
* - Move CPU-bound work or Bun-only services behind Effect's worker protocol.
|
|
21
|
+
* - Send structured-clone payloads and transferables back to the parent with
|
|
22
|
+
* `WorkerRunner.send`.
|
|
23
|
+
*
|
|
24
|
+
* **Gotchas**
|
|
25
|
+
*
|
|
26
|
+
* Start this layer only in the worker entrypoint; it fails when
|
|
27
|
+
* `self.postMessage` is unavailable. Parent shutdown arrives as the worker
|
|
28
|
+
* close message and closes the port, so long-running handlers should stay
|
|
29
|
+
* interruptible and keep cleanup in scopes. Payloads, transfer lists, and
|
|
30
|
+
* `messageerror` events follow Bun's worker runtime behavior.
|
|
31
|
+
*
|
|
32
|
+
* @see {@link layer} for the Bun worker-runner platform layer.
|
|
33
|
+
*
|
|
34
|
+
* @since 4.0.0
|
|
3
35
|
*/
|
|
4
36
|
import * as Cause from "effect/Cause"
|
|
5
37
|
import * as Deferred from "effect/Deferred"
|
|
@@ -15,8 +47,12 @@ import * as WorkerRunner from "effect/unstable/workers/WorkerRunner"
|
|
|
15
47
|
declare const self: MessagePort
|
|
16
48
|
|
|
17
49
|
/**
|
|
18
|
-
*
|
|
50
|
+
* Provides the `WorkerRunnerPlatform` for code running inside a Bun worker,
|
|
51
|
+
* routing parent messages to the registered handler and sending responses back
|
|
52
|
+
* through the worker port.
|
|
53
|
+
*
|
|
19
54
|
* @category layers
|
|
55
|
+
* @since 4.0.0
|
|
20
56
|
*/
|
|
21
57
|
export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succeed(WorkerRunner.WorkerRunnerPlatform)({
|
|
22
58
|
start: Effect.fnUntraced(function*<O = unknown, I = unknown>() {
|
|
@@ -32,7 +68,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
|
|
|
32
68
|
Effect.scopedWith(Effect.fnUntraced(function*(scope) {
|
|
33
69
|
const closeLatch = Deferred.makeUnsafe<void, WorkerError>()
|
|
34
70
|
const trackFiber = Fiber.runIn(scope)
|
|
35
|
-
const services = yield* Effect.
|
|
71
|
+
const services = yield* Effect.context<R>()
|
|
36
72
|
const runFork = Effect.runForkWith(services)
|
|
37
73
|
const onExit = (exit: Exit.Exit<any, E>) => {
|
|
38
74
|
if (exit._tag === "Failure" && !Cause.hasInterruptsOnly(exit.cause)) {
|
|
@@ -62,7 +98,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
|
|
|
62
98
|
message: "received messageerror event",
|
|
63
99
|
cause: error.data
|
|
64
100
|
})
|
|
65
|
-
})
|
|
101
|
+
})
|
|
66
102
|
)
|
|
67
103
|
}
|
|
68
104
|
function onError(error: MessageEvent) {
|
|
@@ -73,7 +109,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
|
|
|
73
109
|
message: "received error event",
|
|
74
110
|
cause: error.data
|
|
75
111
|
})
|
|
76
|
-
})
|
|
112
|
+
})
|
|
77
113
|
)
|
|
78
114
|
}
|
|
79
115
|
yield* Scope.addFinalizer(
|