@effect/platform-bun 4.0.0-beta.9 → 4.0.0-beta.90
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 +44 -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 +27 -9
- package/dist/BunClusterSocket.d.ts.map +1 -1
- package/dist/BunClusterSocket.js +27 -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 +11 -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 +57 -20
- 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 +11 -3
- package/dist/BunHttpServerRequest.d.ts.map +1 -1
- package/dist/BunHttpServerRequest.js +4 -2
- package/dist/BunHttpServerRequest.js.map +1 -1
- package/dist/BunMultipart.d.ts +16 -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 +20 -7
- package/dist/BunPath.js.map +1 -1
- package/dist/BunRedis.d.ts +23 -9
- package/dist/BunRedis.d.ts.map +1 -1
- package/dist/BunRedis.js +26 -12
- package/dist/BunRedis.js.map +1 -1
- package/dist/BunRuntime.d.ts +21 -30
- package/dist/BunRuntime.d.ts.map +1 -1
- package/dist/BunRuntime.js +14 -11
- package/dist/BunRuntime.js.map +1 -1
- package/dist/BunServices.d.ts +19 -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 +18 -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 +13 -3
- package/dist/BunStdio.js.map +1 -1
- package/dist/BunStream.d.ts +5 -4
- package/dist/BunStream.d.ts.map +1 -1
- package/dist/BunStream.js +14 -5
- 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 +15 -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 +20 -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 +17 -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 +49 -11
- package/src/BunClusterSocket.ts +27 -9
- package/src/BunCrypto.ts +24 -0
- package/src/BunFileSystem.ts +11 -3
- package/src/BunHttpClient.ts +2 -2
- package/src/BunHttpPlatform.ts +14 -4
- package/src/BunHttpServer.ts +108 -57
- package/src/BunHttpServerRequest.ts +11 -3
- package/src/BunMultipart.ts +24 -6
- package/src/BunPath.ts +20 -7
- package/src/BunRedis.ts +28 -14
- package/src/BunRuntime.ts +28 -31
- package/src/BunServices.ts +21 -5
- package/src/BunSink.ts +2 -2
- package/src/BunSocket.ts +18 -4
- package/src/BunSocketServer.ts +2 -2
- package/src/BunStdio.ts +13 -3
- package/src/BunStream.ts +14 -5
- package/src/BunTerminal.ts +15 -3
- package/src/BunWorker.ts +20 -4
- package/src/BunWorkerRunner.ts +17 -5
- package/src/index.ts +26 -23
package/src/BunPath.ts
CHANGED
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* Bun-backed layers for Effect's {@link Path} service.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the `Path` service for Bun programs by reusing the
|
|
5
|
+
* shared Node-compatible path implementation. Provide one of these layers when
|
|
6
|
+
* Bun code should receive path operations from the Effect environment instead
|
|
7
|
+
* of importing runtime path helpers directly.
|
|
8
|
+
*
|
|
9
|
+
* @since 4.0.0
|
|
3
10
|
*/
|
|
4
11
|
import * as NodePath from "@effect/platform-node-shared/NodePath"
|
|
5
12
|
import type * as Layer from "effect/Layer"
|
|
6
13
|
import type { Path } from "effect/Path"
|
|
7
14
|
|
|
8
15
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
16
|
+
* Layer that provides the default `Path` service for Bun using the shared Node path implementation.
|
|
17
|
+
*
|
|
18
|
+
* @category layers
|
|
19
|
+
* @since 4.0.0
|
|
11
20
|
*/
|
|
12
21
|
export const layer: Layer.Layer<Path> = NodePath.layer
|
|
13
22
|
|
|
14
23
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
24
|
+
* Layer that provides the POSIX `Path` service for Bun using the shared Node path implementation.
|
|
25
|
+
*
|
|
26
|
+
* @category layers
|
|
27
|
+
* @since 4.0.0
|
|
17
28
|
*/
|
|
18
29
|
export const layerPosix: Layer.Layer<Path> = NodePath.layerPosix
|
|
19
30
|
|
|
20
31
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
32
|
+
* Layer that provides the Win32 `Path` service for Bun using the shared Node path implementation.
|
|
33
|
+
*
|
|
34
|
+
* @category layers
|
|
35
|
+
* @since 4.0.0
|
|
23
36
|
*/
|
|
24
37
|
export const layerWin32: Layer.Layer<Path> = NodePath.layerWin32
|
package/src/BunRedis.ts
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun Redis integration backed by Bun's built-in `RedisClient`.
|
|
3
|
+
*
|
|
4
|
+
* This module creates scoped Bun `RedisClient` connections and exposes them as
|
|
5
|
+
* both the portable `Redis` service and the Bun-specific `BunRedis` service for
|
|
6
|
+
* direct access to the raw client. The `layer` helper accepts Redis options
|
|
7
|
+
* directly, while `layerConfig` reads them from Effect config. Both close the
|
|
8
|
+
* underlying client when the layer scope finalizes.
|
|
9
|
+
*
|
|
10
|
+
* @since 4.0.0
|
|
3
11
|
*/
|
|
4
12
|
import { RedisClient, type RedisOptions } from "bun"
|
|
5
13
|
import * as Config from "effect/Config"
|
|
14
|
+
import * as Context from "effect/Context"
|
|
6
15
|
import * as Effect from "effect/Effect"
|
|
7
16
|
import * as Fn from "effect/Function"
|
|
8
17
|
import * as Layer from "effect/Layer"
|
|
9
18
|
import * as Scope from "effect/Scope"
|
|
10
|
-
import * as ServiceMap from "effect/ServiceMap"
|
|
11
19
|
import * as Redis from "effect/unstable/persistence/Redis"
|
|
12
20
|
|
|
13
21
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
22
|
+
* Service tag for Bun Redis integration, exposing the raw `RedisClient` and a `use` helper that maps client promise failures to `RedisError`.
|
|
23
|
+
*
|
|
24
|
+
* @category services
|
|
25
|
+
* @since 4.0.0
|
|
16
26
|
*/
|
|
17
|
-
export class BunRedis extends
|
|
27
|
+
export class BunRedis extends Context.Service<BunRedis, {
|
|
18
28
|
readonly client: RedisClient
|
|
19
29
|
readonly use: <A>(f: (client: RedisClient) => Promise<A>) => Effect.Effect<A, Redis.RedisError>
|
|
20
30
|
}>()("@effect/platform-bun/BunRedis") {}
|
|
@@ -47,28 +57,32 @@ const make = Effect.fnUntraced(function*(
|
|
|
47
57
|
use
|
|
48
58
|
})
|
|
49
59
|
|
|
50
|
-
return
|
|
51
|
-
|
|
60
|
+
return Context.make(BunRedis, bunRedis).pipe(
|
|
61
|
+
Context.add(Redis.Redis, redis)
|
|
52
62
|
)
|
|
53
63
|
})
|
|
54
64
|
|
|
55
65
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
66
|
+
* Creates scoped Bun Redis layers for `Redis.Redis` and `BunRedis`, closing the underlying client when the scope finalizes.
|
|
67
|
+
*
|
|
68
|
+
* @category layers
|
|
69
|
+
* @since 4.0.0
|
|
58
70
|
*/
|
|
59
71
|
export const layer = (
|
|
60
72
|
options?: ({ readonly url?: string } & RedisOptions) | undefined
|
|
61
|
-
): Layer.Layer<Redis.Redis | BunRedis> => Layer.
|
|
73
|
+
): Layer.Layer<Redis.Redis | BunRedis> => Layer.effectContext(make(options))
|
|
62
74
|
|
|
63
75
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
76
|
+
* Creates scoped Bun Redis layers from configurable Redis options, closing the underlying client when the scope finalizes.
|
|
77
|
+
*
|
|
78
|
+
* @category layers
|
|
79
|
+
* @since 4.0.0
|
|
66
80
|
*/
|
|
67
81
|
export const layerConfig = (
|
|
68
82
|
options: Config.Wrap<{ readonly url?: string } & RedisOptions>
|
|
69
83
|
): Layer.Layer<Redis.Redis | BunRedis, Config.ConfigError> =>
|
|
70
|
-
Layer.
|
|
71
|
-
Config.unwrap(options).
|
|
84
|
+
Layer.effectContext(
|
|
85
|
+
Config.unwrap(options).pipe(
|
|
72
86
|
Effect.flatMap(make)
|
|
73
87
|
)
|
|
74
88
|
)
|
package/src/BunRuntime.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun process runner for Effect programs.
|
|
3
|
+
*
|
|
4
|
+
* This module exports `runMain`, which runs one Effect as the main process
|
|
5
|
+
* fiber in Bun. It reuses the shared Node runtime runner, including its error
|
|
6
|
+
* reporting, signal handling, and optional teardown behavior.
|
|
7
|
+
*
|
|
8
|
+
* @since 4.0.0
|
|
3
9
|
*/
|
|
4
10
|
import * as NodeRuntime from "@effect/platform-node-shared/NodeRuntime"
|
|
5
11
|
import type { Effect } from "effect/Effect"
|
|
@@ -8,6 +14,11 @@ import type { Teardown } from "effect/Runtime"
|
|
|
8
14
|
/**
|
|
9
15
|
* Helps you run a main effect with built-in error handling, logging, and signal management.
|
|
10
16
|
*
|
|
17
|
+
* **When to use**
|
|
18
|
+
*
|
|
19
|
+
* Use to run a Bun application's main Effect with structured error handling,
|
|
20
|
+
* log management, interrupt support, or advanced teardown capabilities.
|
|
21
|
+
*
|
|
11
22
|
* **Details**
|
|
12
23
|
*
|
|
13
24
|
* This function launches an Effect as the main entry point, setting exit codes
|
|
@@ -16,26 +27,23 @@ import type { Teardown } from "effect/Runtime"
|
|
|
16
27
|
* behaviors can be turned off. You can also provide custom teardown logic to
|
|
17
28
|
* finalize resources or produce different exit codes.
|
|
18
29
|
*
|
|
19
|
-
* **Options**
|
|
20
|
-
*
|
|
21
30
|
* An optional object that can include:
|
|
22
31
|
* - `disableErrorReporting`: Turn off automatic error logging.
|
|
23
32
|
* - `disablePrettyLogger`: Avoid adding the pretty logger.
|
|
24
33
|
* - `teardown`: Provide custom finalization logic.
|
|
25
34
|
*
|
|
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
|
|
35
|
+
* @category running
|
|
36
|
+
* @since 4.0.0
|
|
34
37
|
*/
|
|
35
38
|
export const runMain: {
|
|
36
39
|
/**
|
|
37
40
|
* Helps you run a main effect with built-in error handling, logging, and signal management.
|
|
38
41
|
*
|
|
42
|
+
* **When to use**
|
|
43
|
+
*
|
|
44
|
+
* Use to run a Bun application's main Effect with structured error handling,
|
|
45
|
+
* log management, interrupt support, or advanced teardown capabilities.
|
|
46
|
+
*
|
|
39
47
|
* **Details**
|
|
40
48
|
*
|
|
41
49
|
* This function launches an Effect as the main entry point, setting exit codes
|
|
@@ -44,21 +52,13 @@ export const runMain: {
|
|
|
44
52
|
* behaviors can be turned off. You can also provide custom teardown logic to
|
|
45
53
|
* finalize resources or produce different exit codes.
|
|
46
54
|
*
|
|
47
|
-
* **Options**
|
|
48
|
-
*
|
|
49
55
|
* An optional object that can include:
|
|
50
56
|
* - `disableErrorReporting`: Turn off automatic error logging.
|
|
51
57
|
* - `disablePrettyLogger`: Avoid adding the pretty logger.
|
|
52
58
|
* - `teardown`: Provide custom finalization logic.
|
|
53
59
|
*
|
|
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
|
|
60
|
+
* @category running
|
|
61
|
+
* @since 4.0.0
|
|
62
62
|
*/
|
|
63
63
|
(
|
|
64
64
|
options?: {
|
|
@@ -69,6 +69,11 @@ export const runMain: {
|
|
|
69
69
|
/**
|
|
70
70
|
* Helps you run a main effect with built-in error handling, logging, and signal management.
|
|
71
71
|
*
|
|
72
|
+
* **When to use**
|
|
73
|
+
*
|
|
74
|
+
* Use to run a Bun application's main Effect with structured error handling,
|
|
75
|
+
* log management, interrupt support, or advanced teardown capabilities.
|
|
76
|
+
*
|
|
72
77
|
* **Details**
|
|
73
78
|
*
|
|
74
79
|
* This function launches an Effect as the main entry point, setting exit codes
|
|
@@ -77,21 +82,13 @@ export const runMain: {
|
|
|
77
82
|
* behaviors can be turned off. You can also provide custom teardown logic to
|
|
78
83
|
* finalize resources or produce different exit codes.
|
|
79
84
|
*
|
|
80
|
-
* **Options**
|
|
81
|
-
*
|
|
82
85
|
* An optional object that can include:
|
|
83
86
|
* - `disableErrorReporting`: Turn off automatic error logging.
|
|
84
87
|
* - `disablePrettyLogger`: Avoid adding the pretty logger.
|
|
85
88
|
* - `teardown`: Provide custom finalization logic.
|
|
86
89
|
*
|
|
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
|
|
90
|
+
* @category running
|
|
91
|
+
* @since 4.0.0
|
|
95
92
|
*/
|
|
96
93
|
<E, A>(
|
|
97
94
|
effect: Effect<A, E>,
|
package/src/BunServices.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Aggregate Bun platform services layer.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the `BunServices` union and a single `layer` that
|
|
5
|
+
* provides Bun-backed child process spawning, crypto, filesystem, path, stdio,
|
|
6
|
+
* and terminal services. Use the layer when a Bun program wants the standard
|
|
7
|
+
* platform services from one place.
|
|
8
|
+
*
|
|
9
|
+
* @since 4.0.0
|
|
3
10
|
*/
|
|
11
|
+
import type { Crypto } from "effect/Crypto"
|
|
4
12
|
import type { FileSystem } from "effect/FileSystem"
|
|
5
13
|
import * as Layer from "effect/Layer"
|
|
6
14
|
import type { Path } from "effect/Path"
|
|
@@ -8,24 +16,32 @@ import type { Stdio } from "effect/Stdio"
|
|
|
8
16
|
import type { Terminal } from "effect/Terminal"
|
|
9
17
|
import type { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner"
|
|
10
18
|
import * as BunChildProcessSpawner from "./BunChildProcessSpawner.ts"
|
|
19
|
+
import * as BunCrypto from "./BunCrypto.ts"
|
|
11
20
|
import * as BunFileSystem from "./BunFileSystem.ts"
|
|
12
21
|
import * as BunPath from "./BunPath.ts"
|
|
13
22
|
import * as BunStdio from "./BunStdio.ts"
|
|
14
23
|
import * as BunTerminal from "./BunTerminal.ts"
|
|
15
24
|
|
|
16
25
|
/**
|
|
17
|
-
*
|
|
26
|
+
* The union of core services provided by the Bun platform layer, including child
|
|
27
|
+
* process spawning, filesystem, path, stdio, and terminal services.
|
|
28
|
+
*
|
|
18
29
|
* @category models
|
|
30
|
+
* @since 4.0.0
|
|
19
31
|
*/
|
|
20
|
-
export type BunServices = ChildProcessSpawner | FileSystem | Path | Terminal | Stdio
|
|
32
|
+
export type BunServices = ChildProcessSpawner | Crypto | FileSystem | Path | Terminal | Stdio
|
|
21
33
|
|
|
22
34
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
35
|
+
* Provides the default Bun implementations for child process spawning,
|
|
36
|
+
* filesystem, path, stdio, and terminal services.
|
|
37
|
+
*
|
|
38
|
+
* @category layers
|
|
39
|
+
* @since 4.0.0
|
|
25
40
|
*/
|
|
26
41
|
export const layer: Layer.Layer<BunServices> = BunChildProcessSpawner.layer.pipe(
|
|
27
42
|
Layer.provideMerge(Layer.mergeAll(
|
|
28
43
|
BunFileSystem.layer,
|
|
44
|
+
BunCrypto.layer,
|
|
29
45
|
BunPath.layer,
|
|
30
46
|
BunStdio.layer,
|
|
31
47
|
BunTerminal.layer
|
package/src/BunSink.ts
CHANGED
package/src/BunSocket.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun platform socket entry point for Effect sockets.
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports the shared Node socket constructors for TCP clients,
|
|
5
|
+
* Unix domain socket clients, and adapters from existing Node `Duplex` streams.
|
|
6
|
+
* It also provides Bun WebSocket layers using `globalThis.WebSocket`, including
|
|
7
|
+
* a constructor layer and a `Socket.Socket` layer for a WebSocket URL.
|
|
8
|
+
*
|
|
9
|
+
* @since 4.0.0
|
|
3
10
|
*/
|
|
4
11
|
import type * as Duration from "effect/Duration"
|
|
5
12
|
import type { Effect } from "effect/Effect"
|
|
@@ -8,13 +15,16 @@ import * as Layer from "effect/Layer"
|
|
|
8
15
|
import * as Socket from "effect/unstable/socket/Socket"
|
|
9
16
|
|
|
10
17
|
/**
|
|
11
|
-
* @since
|
|
18
|
+
* @since 4.0.0
|
|
12
19
|
*/
|
|
13
20
|
export * from "@effect/platform-node-shared/NodeSocket"
|
|
14
21
|
|
|
15
22
|
/**
|
|
16
|
-
*
|
|
23
|
+
* Provides a `Socket.WebSocketConstructor` backed by Bun's global
|
|
24
|
+
* `WebSocket` implementation.
|
|
25
|
+
*
|
|
17
26
|
* @category layers
|
|
27
|
+
* @since 4.0.0
|
|
18
28
|
*/
|
|
19
29
|
export const layerWebSocketConstructor: Layer.Layer<
|
|
20
30
|
Socket.WebSocketConstructor
|
|
@@ -23,8 +33,12 @@ export const layerWebSocketConstructor: Layer.Layer<
|
|
|
23
33
|
)
|
|
24
34
|
|
|
25
35
|
/**
|
|
26
|
-
*
|
|
36
|
+
* Creates a `Socket.Socket` layer for a WebSocket URL using Bun's global
|
|
37
|
+
* `WebSocket` constructor, honoring protocol, open-timeout, and close-code
|
|
38
|
+
* error options.
|
|
39
|
+
*
|
|
27
40
|
* @category layers
|
|
41
|
+
* @since 4.0.0
|
|
28
42
|
*/
|
|
29
43
|
export const layerWebSocket: (
|
|
30
44
|
url: string | Effect<string>,
|
package/src/BunSocketServer.ts
CHANGED
package/src/BunStdio.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Process stdio for Bun applications.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the Bun layer for Effect's `Stdio` service by using the
|
|
5
|
+
* shared Node stdio implementation. Arguments come from `process.argv`, input
|
|
6
|
+
* is read from `process.stdin`, and output and error output write to
|
|
7
|
+
* `process.stdout` and `process.stderr`.
|
|
8
|
+
*
|
|
9
|
+
* @since 4.0.0
|
|
3
10
|
*/
|
|
4
11
|
import * as NodeStdio from "@effect/platform-node-shared/NodeStdio"
|
|
5
12
|
import type * as Layer from "effect/Layer"
|
|
6
13
|
import type { Stdio } from "effect/Stdio"
|
|
7
14
|
|
|
8
15
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
16
|
+
* Provides the `Stdio` service backed by the current process arguments,
|
|
17
|
+
* stdin, stdout, and stderr streams.
|
|
18
|
+
*
|
|
19
|
+
* @category layers
|
|
20
|
+
* @since 4.0.0
|
|
11
21
|
*/
|
|
12
22
|
export const layer: Layer.Layer<Stdio> = NodeStdio.layer
|
package/src/BunStream.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
* @since 4.0.0
|
|
3
11
|
*/
|
|
4
12
|
import * as Arr from "effect/Array"
|
|
5
13
|
import * as Cause from "effect/Cause"
|
|
@@ -11,15 +19,16 @@ import * as Scope from "effect/Scope"
|
|
|
11
19
|
import * as Stream from "effect/Stream"
|
|
12
20
|
|
|
13
21
|
/**
|
|
14
|
-
* @since
|
|
22
|
+
* @since 4.0.0
|
|
15
23
|
*/
|
|
16
24
|
export * from "@effect/platform-node-shared/NodeStream"
|
|
17
25
|
|
|
18
26
|
/**
|
|
19
|
-
*
|
|
20
|
-
* .
|
|
27
|
+
* Creates a stream from a `ReadableStream` using Bun's optimized `.readMany`
|
|
28
|
+
* API.
|
|
21
29
|
*
|
|
22
|
-
* @
|
|
30
|
+
* @category constructors
|
|
31
|
+
* @since 4.0.0
|
|
23
32
|
*/
|
|
24
33
|
export const fromReadableStream = <A, E>(
|
|
25
34
|
options: {
|
package/src/BunTerminal.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bun-backed implementation of Effect's `Terminal` service.
|
|
3
|
+
*
|
|
4
|
+
* This module reuses the shared Node terminal implementation for Bun. `make`
|
|
5
|
+
* creates a scoped process-backed `Terminal` service, and `layer` provides the
|
|
6
|
+
* default terminal service with the standard quit behavior for key input.
|
|
7
|
+
*
|
|
8
|
+
* @since 4.0.0
|
|
3
9
|
*/
|
|
4
10
|
import * as NodeTerminal from "@effect/platform-node-shared/NodeTerminal"
|
|
5
11
|
import type { Effect } from "effect/Effect"
|
|
@@ -8,13 +14,19 @@ import type { Scope } from "effect/Scope"
|
|
|
8
14
|
import type { Terminal, UserInput } from "effect/Terminal"
|
|
9
15
|
|
|
10
16
|
/**
|
|
11
|
-
*
|
|
17
|
+
* Creates a scoped `Terminal` service backed by process stdin/stdout, using the
|
|
18
|
+
* optional predicate to decide when key input should end the input stream.
|
|
19
|
+
*
|
|
12
20
|
* @category constructors
|
|
21
|
+
* @since 4.0.0
|
|
13
22
|
*/
|
|
14
23
|
export const make: (shouldQuit?: (input: UserInput) => boolean) => Effect<Terminal, never, Scope> = NodeTerminal.make
|
|
15
24
|
|
|
16
25
|
/**
|
|
17
|
-
*
|
|
26
|
+
* Provides the default process-backed `Terminal` service, ending key input on
|
|
27
|
+
* the default quit keys.
|
|
28
|
+
*
|
|
18
29
|
* @category layers
|
|
30
|
+
* @since 4.0.0
|
|
19
31
|
*/
|
|
20
32
|
export const layer: Layer<Terminal> = NodeTerminal.layer
|
package/src/BunWorker.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Parent-side worker support for Bun applications.
|
|
3
|
+
*
|
|
4
|
+
* `layerPlatform` provides the `WorkerPlatform` used to communicate with
|
|
5
|
+
* `globalThis.Worker` instances through Effect's worker protocol. `layer`
|
|
6
|
+
* combines that platform with a `Spawner` built from a callback that creates a
|
|
7
|
+
* worker for each worker id. The platform forwards worker messages and errors,
|
|
8
|
+
* asks workers to close on scope finalization, and terminates them if graceful
|
|
9
|
+
* shutdown times out.
|
|
10
|
+
*
|
|
11
|
+
* @since 4.0.0
|
|
3
12
|
*/
|
|
4
13
|
import * as Deferred from "effect/Deferred"
|
|
5
14
|
import * as Effect from "effect/Effect"
|
|
@@ -10,8 +19,11 @@ import * as Worker from "effect/unstable/workers/Worker"
|
|
|
10
19
|
import { WorkerError, WorkerUnknownError } from "effect/unstable/workers/WorkerError"
|
|
11
20
|
|
|
12
21
|
/**
|
|
13
|
-
*
|
|
22
|
+
* Provides the Bun `WorkerPlatform` together with a `Worker.Spawner` created
|
|
23
|
+
* from the supplied worker spawning function.
|
|
24
|
+
*
|
|
14
25
|
* @category layers
|
|
26
|
+
* @since 4.0.0
|
|
15
27
|
*/
|
|
16
28
|
export const layer = (
|
|
17
29
|
spawn: (id: number) => globalThis.Worker
|
|
@@ -22,8 +34,12 @@ export const layer = (
|
|
|
22
34
|
)
|
|
23
35
|
|
|
24
36
|
/**
|
|
25
|
-
*
|
|
37
|
+
* Provides the Bun `WorkerPlatform`, wiring worker messages and errors into
|
|
38
|
+
* Effect workers and requesting graceful worker shutdown during scope
|
|
39
|
+
* finalization before terminating on timeout.
|
|
40
|
+
*
|
|
26
41
|
* @category layers
|
|
42
|
+
* @since 4.0.0
|
|
27
43
|
*/
|
|
28
44
|
export const layerPlatform = Layer.succeed(Worker.WorkerPlatform)(
|
|
29
45
|
Worker.makePlatform<globalThis.Worker>()({
|
|
@@ -59,7 +75,7 @@ export const layerPlatform = Layer.succeed(Worker.WorkerPlatform)(
|
|
|
59
75
|
message: "An error event was emitted",
|
|
60
76
|
cause: event.error ?? event.message
|
|
61
77
|
})
|
|
62
|
-
})
|
|
78
|
+
})
|
|
63
79
|
)
|
|
64
80
|
}
|
|
65
81
|
port.addEventListener("message", onMessage)
|
package/src/BunWorkerRunner.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Worker-entrypoint support for Bun worker runners.
|
|
3
|
+
*
|
|
4
|
+
* This module exports a `layer` that provides `WorkerRunnerPlatform` for code
|
|
5
|
+
* already running inside a Bun `Worker`. The platform receives request messages
|
|
6
|
+
* from the parent-side `BunWorker` platform, runs the registered handler, sends
|
|
7
|
+
* responses through the worker `postMessage` channel, and closes when the
|
|
8
|
+
* parent sends the close message.
|
|
9
|
+
*
|
|
10
|
+
* @since 4.0.0
|
|
3
11
|
*/
|
|
4
12
|
import * as Cause from "effect/Cause"
|
|
5
13
|
import * as Deferred from "effect/Deferred"
|
|
@@ -15,8 +23,12 @@ import * as WorkerRunner from "effect/unstable/workers/WorkerRunner"
|
|
|
15
23
|
declare const self: MessagePort
|
|
16
24
|
|
|
17
25
|
/**
|
|
18
|
-
*
|
|
26
|
+
* Provides the `WorkerRunnerPlatform` for code running inside a Bun worker,
|
|
27
|
+
* routing parent messages to the registered handler and sending responses back
|
|
28
|
+
* through the worker port.
|
|
29
|
+
*
|
|
19
30
|
* @category layers
|
|
31
|
+
* @since 4.0.0
|
|
20
32
|
*/
|
|
21
33
|
export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succeed(WorkerRunner.WorkerRunnerPlatform)({
|
|
22
34
|
start: Effect.fnUntraced(function*<O = unknown, I = unknown>() {
|
|
@@ -32,7 +44,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
|
|
|
32
44
|
Effect.scopedWith(Effect.fnUntraced(function*(scope) {
|
|
33
45
|
const closeLatch = Deferred.makeUnsafe<void, WorkerError>()
|
|
34
46
|
const trackFiber = Fiber.runIn(scope)
|
|
35
|
-
const services = yield* Effect.
|
|
47
|
+
const services = yield* Effect.context<R>()
|
|
36
48
|
const runFork = Effect.runForkWith(services)
|
|
37
49
|
const onExit = (exit: Exit.Exit<any, E>) => {
|
|
38
50
|
if (exit._tag === "Failure" && !Cause.hasInterruptsOnly(exit.cause)) {
|
|
@@ -62,7 +74,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
|
|
|
62
74
|
message: "received messageerror event",
|
|
63
75
|
cause: error.data
|
|
64
76
|
})
|
|
65
|
-
})
|
|
77
|
+
})
|
|
66
78
|
)
|
|
67
79
|
}
|
|
68
80
|
function onError(error: MessageEvent) {
|
|
@@ -73,7 +85,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
|
|
|
73
85
|
message: "received error event",
|
|
74
86
|
cause: error.data
|
|
75
87
|
})
|
|
76
|
-
})
|
|
88
|
+
})
|
|
77
89
|
)
|
|
78
90
|
}
|
|
79
91
|
yield* Scope.addFinalizer(
|