@effect/platform-bun 4.0.0-beta.70 → 4.0.0-beta.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BunClusterHttp.d.ts +26 -2
- package/dist/BunClusterHttp.d.ts.map +1 -1
- package/dist/BunClusterHttp.js +26 -2
- package/dist/BunClusterHttp.js.map +1 -1
- package/dist/BunCrypto.d.ts +1 -1
- package/dist/BunCrypto.d.ts.map +1 -1
- package/dist/BunCrypto.js +10 -2
- package/dist/BunCrypto.js.map +1 -1
- package/dist/BunHttpServer.d.ts +1 -1
- package/dist/BunHttpServer.js +1 -1
- package/dist/BunHttpServerRequest.d.ts +1 -1
- package/dist/BunHttpServerRequest.js +1 -1
- package/dist/BunPath.d.ts.map +1 -1
- package/dist/BunPath.js +28 -16
- package/dist/BunPath.js.map +1 -1
- package/dist/BunRedis.d.ts +27 -18
- package/dist/BunRedis.d.ts.map +1 -1
- package/dist/BunRedis.js +27 -18
- package/dist/BunRedis.js.map +1 -1
- package/dist/BunRuntime.d.ts +3 -3
- package/dist/BunRuntime.d.ts.map +1 -1
- package/dist/BunRuntime.js +29 -16
- package/dist/BunRuntime.js.map +1 -1
- package/dist/BunStdio.d.ts.map +1 -1
- package/dist/BunStdio.js +23 -11
- package/dist/BunStdio.js.map +1 -1
- package/dist/BunStream.d.ts +2 -2
- package/dist/BunStream.d.ts.map +1 -1
- package/dist/BunStream.js +27 -18
- package/dist/BunStream.js.map +1 -1
- package/dist/BunTerminal.d.ts.map +1 -1
- package/dist/BunTerminal.js +29 -11
- package/dist/BunTerminal.js.map +1 -1
- package/dist/BunWorker.d.ts.map +1 -1
- package/dist/BunWorker.js +28 -11
- package/dist/BunWorker.js.map +1 -1
- package/dist/BunWorkerRunner.d.ts.map +1 -1
- package/dist/BunWorkerRunner.js +29 -15
- package/dist/BunWorkerRunner.js.map +1 -1
- package/dist/index.d.ts +0 -373
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -373
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/BunClusterHttp.ts +26 -2
- package/src/BunCrypto.ts +10 -2
- package/src/BunHttpServer.ts +1 -1
- package/src/BunHttpServerRequest.ts +1 -1
- package/src/BunPath.ts +28 -16
- package/src/BunRedis.ts +27 -18
- package/src/BunRuntime.ts +29 -16
- package/src/BunStdio.ts +23 -11
- package/src/BunStream.ts +27 -18
- package/src/BunTerminal.ts +29 -11
- package/src/BunWorker.ts +28 -11
- package/src/BunWorkerRunner.ts +29 -15
- package/src/index.ts +0 -373
package/src/BunRedis.ts
CHANGED
|
@@ -1,27 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bun Redis integration backed by Bun's built-in `RedisClient`.
|
|
3
3
|
*
|
|
4
|
-
* This module
|
|
5
|
-
* both the
|
|
6
|
-
* `BunRedis` service for direct access to the
|
|
7
|
-
* applications that need Redis-backed persistence, persisted queues,
|
|
4
|
+
* This module creates scoped Bun `RedisClient` connections and exposes them as
|
|
5
|
+
* both the portable `Redis` service used by Effect persistence modules and the
|
|
6
|
+
* Bun-specific `BunRedis` service for direct access to the raw client. Use it in
|
|
7
|
+
* Bun applications that need Redis-backed persistence, persisted queues,
|
|
8
8
|
* distributed rate limiting, custom Redis commands, or Bun Redis features such
|
|
9
|
-
* as pub/sub
|
|
9
|
+
* as pub/sub.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
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.
|
|
11
|
+
* **Mental model**
|
|
19
12
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
13
|
+
* `layer` and `layerConfig` acquire one `RedisClient` for the layer scope. The
|
|
14
|
+
* same client backs the portable `Redis.Redis` command interface and the
|
|
15
|
+
* `BunRedis` service, and it is closed with `close` when the scope finalizes.
|
|
16
|
+
* Install the layer at the lifetime you want for that connection.
|
|
17
|
+
*
|
|
18
|
+
* **Common tasks**
|
|
19
|
+
*
|
|
20
|
+
* Pass a Redis URL or Bun `RedisOptions` to `layer` for direct configuration,
|
|
21
|
+
* or use `layerConfig` when connection settings should come from Effect
|
|
22
|
+
* configuration. Depend on `Redis.Redis` for persistence and rate limiter
|
|
23
|
+
* stores. Depend on `BunRedis` when you need `RedisClient` features that are
|
|
24
|
+
* not exposed by the portable service, including custom commands and pub/sub.
|
|
25
|
+
*
|
|
26
|
+
* **Gotchas**
|
|
27
|
+
*
|
|
28
|
+
* Pub/sub should normally use a separately scoped client so a subscription does
|
|
29
|
+
* not interfere with ordinary command traffic. Persistence and rate limiter
|
|
30
|
+
* stores build keys and Lua scripts on top of this service, so choose stable
|
|
31
|
+
* prefixes and store ids, account for persisted values that may fail to decode
|
|
32
|
+
* after schema changes, and avoid unbounded high-cardinality rate-limit keys
|
|
33
|
+
* without a cleanup or bounding strategy.
|
|
25
34
|
*
|
|
26
35
|
* @since 4.0.0
|
|
27
36
|
*/
|
package/src/BunRuntime.ts
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Bun
|
|
2
|
+
* Bun process runner for Effect programs.
|
|
3
3
|
*
|
|
4
|
-
* This module exposes `runMain
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `process` signal handling available in Bun.
|
|
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.
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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.
|
|
17
30
|
*
|
|
18
31
|
* @since 4.0.0
|
|
19
32
|
*/
|
|
@@ -26,7 +39,7 @@ import type { Teardown } from "effect/Runtime"
|
|
|
26
39
|
*
|
|
27
40
|
* **When to use**
|
|
28
41
|
*
|
|
29
|
-
* Use
|
|
42
|
+
* Use to run an Effect as your application's main program,
|
|
30
43
|
* especially when you need structured error handling, log management,
|
|
31
44
|
* interrupt support, or advanced teardown capabilities.
|
|
32
45
|
*
|
|
@@ -52,7 +65,7 @@ export const runMain: {
|
|
|
52
65
|
*
|
|
53
66
|
* **When to use**
|
|
54
67
|
*
|
|
55
|
-
* Use
|
|
68
|
+
* Use to run an Effect as your application's main program,
|
|
56
69
|
* especially when you need structured error handling, log management,
|
|
57
70
|
* interrupt support, or advanced teardown capabilities.
|
|
58
71
|
*
|
|
@@ -83,7 +96,7 @@ export const runMain: {
|
|
|
83
96
|
*
|
|
84
97
|
* **When to use**
|
|
85
98
|
*
|
|
86
|
-
* Use
|
|
99
|
+
* Use to run an Effect as your application's main program,
|
|
87
100
|
* especially when you need structured error handling, log management,
|
|
88
101
|
* interrupt support, or advanced teardown capabilities.
|
|
89
102
|
*
|
package/src/BunStdio.ts
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Process stdio for Bun applications.
|
|
3
3
|
*
|
|
4
|
-
* This module provides the
|
|
5
|
-
* the
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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**
|
|
11
24
|
*
|
|
12
|
-
* The underlying stdio streams are global resources owned by the Bun process.
|
|
13
25
|
* The layer keeps stdin open and does not end stdout or stderr by default,
|
|
14
26
|
* which avoids closing handles that prompts, loggers, or other code may still
|
|
15
27
|
* use. Stdio may be attached to a TTY, pipe, or redirected file, so
|
|
16
28
|
* terminal-specific behavior such as raw mode, echo, colors, cursor control,
|
|
17
|
-
* and terminal dimensions should be
|
|
18
|
-
*
|
|
29
|
+
* and terminal dimensions should be handled with terminal APIs such as
|
|
30
|
+
* `BunTerminal`, not inferred from this layer.
|
|
19
31
|
*
|
|
20
32
|
* @since 4.0.0
|
|
21
33
|
*/
|
package/src/BunStream.ts
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bun stream interoperability for Effect streams.
|
|
3
3
|
*
|
|
4
|
-
* This module
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `ReadableStream`
|
|
8
|
-
* batches of
|
|
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
9
|
*
|
|
10
|
-
*
|
|
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.
|
|
10
|
+
* **Mental model**
|
|
15
11
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
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.
|
|
22
31
|
*
|
|
23
32
|
* @since 4.0.0
|
|
24
33
|
*/
|
|
@@ -37,8 +46,8 @@ import * as Stream from "effect/Stream"
|
|
|
37
46
|
export * from "@effect/platform-node-shared/NodeStream"
|
|
38
47
|
|
|
39
48
|
/**
|
|
40
|
-
*
|
|
41
|
-
* .
|
|
49
|
+
* Creates a stream from a `ReadableStream` using Bun's optimized `.readMany`
|
|
50
|
+
* API.
|
|
42
51
|
*
|
|
43
52
|
* @category constructors
|
|
44
53
|
* @since 4.0.0
|
package/src/BunTerminal.ts
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bun-backed implementation of Effect's `Terminal` service.
|
|
3
3
|
*
|
|
4
|
-
* This module
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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.
|
|
15
33
|
*
|
|
16
34
|
* @since 4.0.0
|
|
17
35
|
*/
|
package/src/BunWorker.ts
CHANGED
|
@@ -1,21 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Parent-side
|
|
2
|
+
* Parent-side worker support for Bun applications.
|
|
3
3
|
*
|
|
4
|
-
* This module provides the `WorkerPlatform` used by Bun programs that spawn
|
|
5
|
-
*
|
|
4
|
+
* This module provides the `WorkerPlatform` used by Bun programs that spawn and
|
|
5
|
+
* communicate with `globalThis.Worker` instances through Effect's worker
|
|
6
6
|
* protocol. Pair it with `BunWorkerRunner` in the worker entrypoint when
|
|
7
7
|
* building worker-backed RPC clients, moving CPU-bound work off the main
|
|
8
8
|
* thread, isolating Bun-only services, or hosting long-lived handlers behind a
|
|
9
9
|
* typed message boundary.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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.
|
|
19
36
|
*
|
|
20
37
|
* @since 4.0.0
|
|
21
38
|
*/
|
package/src/BunWorkerRunner.ts
CHANGED
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Worker-entrypoint support for Bun worker runners.
|
|
3
3
|
*
|
|
4
|
-
* This module
|
|
5
|
-
* `Worker`. It
|
|
6
|
-
*
|
|
7
|
-
* and
|
|
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
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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.
|
|
19
33
|
*
|
|
20
34
|
* @since 4.0.0
|
|
21
35
|
*/
|