@effect/platform-node 4.0.0-beta.7 → 4.0.0-beta.70
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/Mime.d.ts +3 -3
- package/dist/Mime.js +3 -3
- package/dist/NodeChildProcessSpawner.d.ts +1 -1
- package/dist/NodeChildProcessSpawner.js +1 -1
- package/dist/NodeClusterHttp.d.ts +49 -7
- package/dist/NodeClusterHttp.d.ts.map +1 -1
- package/dist/NodeClusterHttp.js +20 -10
- package/dist/NodeClusterHttp.js.map +1 -1
- package/dist/NodeClusterSocket.d.ts +57 -11
- package/dist/NodeClusterSocket.d.ts.map +1 -1
- package/dist/NodeClusterSocket.js +57 -11
- package/dist/NodeClusterSocket.js.map +1 -1
- package/dist/NodeCrypto.d.ts +10 -0
- package/dist/NodeCrypto.d.ts.map +1 -0
- package/dist/NodeCrypto.js +14 -0
- package/dist/NodeCrypto.js.map +1 -0
- package/dist/NodeFileSystem.d.ts +4 -2
- package/dist/NodeFileSystem.d.ts.map +1 -1
- package/dist/NodeFileSystem.js +22 -3
- package/dist/NodeFileSystem.js.map +1 -1
- package/dist/NodeHttpClient.d.ts +102 -24
- package/dist/NodeHttpClient.d.ts.map +1 -1
- package/dist/NodeHttpClient.js +124 -28
- package/dist/NodeHttpClient.js.map +1 -1
- package/dist/NodeHttpIncomingMessage.d.ts +30 -9
- package/dist/NodeHttpIncomingMessage.d.ts.map +1 -1
- package/dist/NodeHttpIncomingMessage.js +34 -8
- package/dist/NodeHttpIncomingMessage.js.map +1 -1
- package/dist/NodeHttpPlatform.d.ts +10 -4
- package/dist/NodeHttpPlatform.d.ts.map +1 -1
- package/dist/NodeHttpPlatform.js +34 -7
- package/dist/NodeHttpPlatform.js.map +1 -1
- package/dist/NodeHttpServer.d.ts +56 -16
- package/dist/NodeHttpServer.d.ts.map +1 -1
- package/dist/NodeHttpServer.js +117 -49
- package/dist/NodeHttpServer.js.map +1 -1
- package/dist/NodeHttpServerRequest.d.ts +29 -3
- package/dist/NodeHttpServerRequest.d.ts.map +1 -1
- package/dist/NodeHttpServerRequest.js +9 -2
- package/dist/NodeHttpServerRequest.js.map +1 -1
- package/dist/NodeMultipart.d.ts +32 -4
- package/dist/NodeMultipart.d.ts.map +1 -1
- package/dist/NodeMultipart.js +32 -4
- package/dist/NodeMultipart.js.map +1 -1
- package/dist/NodePath.d.ts +15 -6
- package/dist/NodePath.d.ts.map +1 -1
- package/dist/NodePath.js +30 -7
- package/dist/NodePath.js.map +1 -1
- package/dist/NodeRedis.d.ts +38 -9
- package/dist/NodeRedis.d.ts.map +1 -1
- package/dist/NodeRedis.js +41 -12
- package/dist/NodeRedis.js.map +1 -1
- package/dist/NodeRuntime.d.ts +27 -36
- package/dist/NodeRuntime.d.ts.map +1 -1
- package/dist/NodeRuntime.js +24 -13
- package/dist/NodeRuntime.js.map +1 -1
- package/dist/NodeServices.d.ts +29 -5
- package/dist/NodeServices.d.ts.map +1 -1
- package/dist/NodeServices.js +7 -3
- package/dist/NodeServices.js.map +1 -1
- package/dist/NodeSink.d.ts +2 -2
- package/dist/NodeSink.js +2 -2
- package/dist/NodeSocket.d.ts +18 -3
- package/dist/NodeSocket.d.ts.map +1 -1
- package/dist/NodeSocket.js +36 -4
- package/dist/NodeSocket.js.map +1 -1
- package/dist/NodeSocketServer.d.ts +2 -2
- package/dist/NodeSocketServer.js +2 -2
- package/dist/NodeStdio.d.ts +5 -2
- package/dist/NodeStdio.d.ts.map +1 -1
- package/dist/NodeStdio.js +22 -3
- package/dist/NodeStdio.js.map +1 -1
- package/dist/NodeStream.d.ts +2 -2
- package/dist/NodeStream.js +2 -2
- package/dist/NodeTerminal.d.ts +8 -2
- package/dist/NodeTerminal.d.ts.map +1 -1
- package/dist/NodeTerminal.js +19 -3
- package/dist/NodeTerminal.js.map +1 -1
- package/dist/NodeWorker.d.ts +9 -2
- package/dist/NodeWorker.d.ts.map +1 -1
- package/dist/NodeWorker.js +31 -6
- package/dist/NodeWorker.js.map +1 -1
- package/dist/NodeWorkerRunner.d.ts +5 -1
- package/dist/NodeWorkerRunner.d.ts.map +1 -1
- package/dist/NodeWorkerRunner.js +27 -5
- package/dist/NodeWorkerRunner.js.map +1 -1
- package/dist/Undici.d.ts +3 -3
- package/dist/Undici.js +3 -3
- package/dist/index.d.ts +376 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +376 -24
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/Mime.ts +3 -3
- package/src/NodeChildProcessSpawner.ts +1 -1
- package/src/NodeClusterHttp.ts +54 -11
- package/src/NodeClusterSocket.ts +57 -11
- package/src/NodeCrypto.ts +16 -0
- package/src/NodeFileSystem.ts +22 -3
- package/src/NodeHttpClient.ts +132 -33
- package/src/NodeHttpIncomingMessage.ts +42 -12
- package/src/NodeHttpPlatform.ts +35 -6
- package/src/NodeHttpServer.ts +139 -53
- package/src/NodeHttpServerRequest.ts +29 -3
- package/src/NodeMultipart.ts +32 -4
- package/src/NodePath.ts +30 -7
- package/src/NodeRedis.ts +43 -14
- package/src/NodeRuntime.ts +42 -37
- package/src/NodeServices.ts +31 -5
- package/src/NodeSink.ts +2 -2
- package/src/NodeSocket.ts +41 -4
- package/src/NodeSocketServer.ts +2 -2
- package/src/NodeStdio.ts +22 -3
- package/src/NodeStream.ts +2 -2
- package/src/NodeTerminal.ts +19 -3
- package/src/NodeWorker.ts +31 -6
- package/src/NodeWorkerRunner.ts +27 -5
- package/src/Undici.ts +3 -3
- package/src/index.ts +377 -24
package/src/NodeRuntime.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Node.js entry-point helpers for running Effect programs.
|
|
3
|
+
*
|
|
4
|
+
* This module exposes `runMain`, the Node runtime launcher used at the edge of
|
|
5
|
+
* CLI tools, scripts, servers, and worker processes. It runs an already
|
|
6
|
+
* self-contained Effect as the process main program, with built-in error
|
|
7
|
+
* reporting and Node signal handling.
|
|
8
|
+
*
|
|
9
|
+
* `NodeRuntime` does not provide application services by itself. Provide any
|
|
10
|
+
* required layers, such as `NodeServices.layer` or narrower service-specific
|
|
11
|
+
* layers, before passing the effect to `runMain`. On `SIGINT` or `SIGTERM`,
|
|
12
|
+
* the main fiber is interrupted so scoped resources and finalizers can shut
|
|
13
|
+
* down; keep long-running work attached to that scope and avoid finalizers that
|
|
14
|
+
* never complete, otherwise process shutdown can be delayed.
|
|
15
|
+
*
|
|
16
|
+
* @since 4.0.0
|
|
3
17
|
*/
|
|
4
18
|
import * as NodeRuntime from "@effect/platform-node-shared/NodeRuntime"
|
|
5
19
|
import type { Effect } from "effect/Effect"
|
|
@@ -8,6 +22,12 @@ import type * as Runtime from "effect/Runtime"
|
|
|
8
22
|
/**
|
|
9
23
|
* Helps you run a main effect with built-in error handling, logging, and signal management.
|
|
10
24
|
*
|
|
25
|
+
* **When to use**
|
|
26
|
+
*
|
|
27
|
+
* Use this function to run an Effect as your application's main program, especially
|
|
28
|
+
* when you need structured error handling, log management, interrupt support,
|
|
29
|
+
* or advanced teardown capabilities.
|
|
30
|
+
*
|
|
11
31
|
* **Details**
|
|
12
32
|
*
|
|
13
33
|
* This function launches an Effect as the main entry point, setting exit codes
|
|
@@ -16,26 +36,23 @@ import type * as Runtime from "effect/Runtime"
|
|
|
16
36
|
* behaviors can be turned off. You can also provide custom teardown logic to
|
|
17
37
|
* finalize resources or produce different exit codes.
|
|
18
38
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* An optional object that can include:
|
|
39
|
+
* The optional configuration object can include:
|
|
22
40
|
* - `disableErrorReporting`: Turn off automatic error logging.
|
|
23
|
-
* - `disablePrettyLogger`: Avoid adding the pretty logger.
|
|
24
41
|
* - `teardown`: Provide custom finalization logic.
|
|
25
42
|
*
|
|
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
|
|
43
|
+
* @category running
|
|
44
|
+
* @since 4.0.0
|
|
34
45
|
*/
|
|
35
46
|
export const runMain: {
|
|
36
47
|
/**
|
|
37
48
|
* Helps you run a main effect with built-in error handling, logging, and signal management.
|
|
38
49
|
*
|
|
50
|
+
* **When to use**
|
|
51
|
+
*
|
|
52
|
+
* Use this function to run an Effect as your application's main program, especially
|
|
53
|
+
* when you need structured error handling, log management, interrupt support,
|
|
54
|
+
* or advanced teardown capabilities.
|
|
55
|
+
*
|
|
39
56
|
* **Details**
|
|
40
57
|
*
|
|
41
58
|
* This function launches an Effect as the main entry point, setting exit codes
|
|
@@ -44,21 +61,12 @@ export const runMain: {
|
|
|
44
61
|
* behaviors can be turned off. You can also provide custom teardown logic to
|
|
45
62
|
* finalize resources or produce different exit codes.
|
|
46
63
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* An optional object that can include:
|
|
64
|
+
* The optional configuration object can include:
|
|
50
65
|
* - `disableErrorReporting`: Turn off automatic error logging.
|
|
51
|
-
* - `disablePrettyLogger`: Avoid adding the pretty logger.
|
|
52
66
|
* - `teardown`: Provide custom finalization logic.
|
|
53
67
|
*
|
|
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
|
|
68
|
+
* @category running
|
|
69
|
+
* @since 4.0.0
|
|
62
70
|
*/
|
|
63
71
|
(
|
|
64
72
|
options?: {
|
|
@@ -69,6 +77,12 @@ export const runMain: {
|
|
|
69
77
|
/**
|
|
70
78
|
* Helps you run a main effect with built-in error handling, logging, and signal management.
|
|
71
79
|
*
|
|
80
|
+
* **When to use**
|
|
81
|
+
*
|
|
82
|
+
* Use this function to run an Effect as your application's main program, especially
|
|
83
|
+
* when you need structured error handling, log management, interrupt support,
|
|
84
|
+
* or advanced teardown capabilities.
|
|
85
|
+
*
|
|
72
86
|
* **Details**
|
|
73
87
|
*
|
|
74
88
|
* This function launches an Effect as the main entry point, setting exit codes
|
|
@@ -77,21 +91,12 @@ export const runMain: {
|
|
|
77
91
|
* behaviors can be turned off. You can also provide custom teardown logic to
|
|
78
92
|
* finalize resources or produce different exit codes.
|
|
79
93
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* An optional object that can include:
|
|
94
|
+
* The optional configuration object can include:
|
|
83
95
|
* - `disableErrorReporting`: Turn off automatic error logging.
|
|
84
|
-
* - `disablePrettyLogger`: Avoid adding the pretty logger.
|
|
85
96
|
* - `teardown`: Provide custom finalization logic.
|
|
86
97
|
*
|
|
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
|
|
98
|
+
* @category running
|
|
99
|
+
* @since 4.0.0
|
|
95
100
|
*/
|
|
96
101
|
<E, A>(
|
|
97
102
|
effect: Effect<A, E>,
|
package/src/NodeServices.ts
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides the aggregate Node platform services layer for applications that run
|
|
3
|
+
* on the Node.js runtime.
|
|
4
|
+
*
|
|
5
|
+
* This module is useful when an application needs the standard Node-backed
|
|
6
|
+
* implementations of filesystem access, path operations, stdio, terminal
|
|
7
|
+
* interaction, and child process spawning from a single layer. Provide
|
|
8
|
+
* `NodeServices.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 `NodeServices`; it does
|
|
13
|
+
* not provide unrelated platform services such as HTTP clients or servers.
|
|
14
|
+
* Libraries should continue to depend on the individual service tags they use,
|
|
15
|
+
* while applications, CLIs, and tests can choose this layer or narrower
|
|
16
|
+
* service-specific layers depending on how much of the Node runtime they want to
|
|
17
|
+
* expose.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
21
|
+
import type { Crypto } from "effect/Crypto"
|
|
4
22
|
import type { FileSystem } from "effect/FileSystem"
|
|
5
23
|
import * as Layer from "effect/Layer"
|
|
6
24
|
import type { Path } from "effect/Path"
|
|
@@ -8,25 +26,33 @@ import type { Stdio } from "effect/Stdio"
|
|
|
8
26
|
import type { Terminal } from "effect/Terminal"
|
|
9
27
|
import type { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner"
|
|
10
28
|
import * as NodeChildProcessSpawner from "./NodeChildProcessSpawner.ts"
|
|
29
|
+
import * as NodeCrypto from "./NodeCrypto.ts"
|
|
11
30
|
import * as NodeFileSystem from "./NodeFileSystem.ts"
|
|
12
31
|
import * as NodePath from "./NodePath.ts"
|
|
13
32
|
import * as NodeStdio from "./NodeStdio.ts"
|
|
14
33
|
import * as NodeTerminal from "./NodeTerminal.ts"
|
|
15
34
|
|
|
16
35
|
/**
|
|
17
|
-
*
|
|
36
|
+
* The union of core services provided by the Node platform layer, including
|
|
37
|
+
* child process spawning, filesystem, path, stdio, and terminal services.
|
|
38
|
+
*
|
|
18
39
|
* @category models
|
|
40
|
+
* @since 4.0.0
|
|
19
41
|
*/
|
|
20
|
-
export type NodeServices = ChildProcessSpawner | FileSystem | Path | Stdio | Terminal
|
|
42
|
+
export type NodeServices = ChildProcessSpawner | Crypto | FileSystem | Path | Stdio | Terminal
|
|
21
43
|
|
|
22
44
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
45
|
+
* Provides the default Node implementations for child process spawning,
|
|
46
|
+
* filesystem, path, stdio, and terminal services.
|
|
47
|
+
*
|
|
48
|
+
* @category layers
|
|
49
|
+
* @since 4.0.0
|
|
25
50
|
*/
|
|
26
51
|
export const layer: Layer.Layer<NodeServices> = Layer.provideMerge(
|
|
27
52
|
NodeChildProcessSpawner.layer,
|
|
28
53
|
Layer.mergeAll(
|
|
29
54
|
NodeFileSystem.layer,
|
|
55
|
+
NodeCrypto.layer,
|
|
30
56
|
NodePath.layer,
|
|
31
57
|
NodeStdio.layer,
|
|
32
58
|
NodeTerminal.layer
|
package/src/NodeSink.ts
CHANGED
package/src/NodeSocket.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Node platform socket entry point for Effect sockets backed by Node streams
|
|
3
|
+
* and WebSocket implementations.
|
|
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 Node-specific WebSocket constructor layers. Use it when connecting
|
|
8
|
+
* to raw socket protocols, wiring RPC transports over TCP or Unix sockets, or
|
|
9
|
+
* opening WebSocket clients in Node.
|
|
10
|
+
*
|
|
11
|
+
* TCP and Unix socket behavior comes from the shared Node layer: Unix sockets
|
|
12
|
+
* are selected with `NetConnectOpts.path`, scoped sockets close or destroy the
|
|
13
|
+
* underlying stream on finalization, and Node open, read, write, and close
|
|
14
|
+
* events are translated into `SocketError` values. For WebSockets,
|
|
15
|
+
* `layerWebSocketConstructor` prefers `globalThis.WebSocket` when available
|
|
16
|
+
* and falls back to `ws`; use `layerWebSocketConstructorWS` when you need the
|
|
17
|
+
* `ws` implementation consistently across Node versions.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
4
21
|
import { NodeWS as WS } from "@effect/platform-node-shared/NodeSocket"
|
|
5
22
|
import type * as Duration from "effect/Duration"
|
|
@@ -9,13 +26,16 @@ import * as Layer from "effect/Layer"
|
|
|
9
26
|
import * as Socket from "effect/unstable/socket/Socket"
|
|
10
27
|
|
|
11
28
|
/**
|
|
12
|
-
* @since
|
|
29
|
+
* @since 4.0.0
|
|
13
30
|
*/
|
|
14
31
|
export * from "@effect/platform-node-shared/NodeSocket"
|
|
15
32
|
|
|
16
33
|
/**
|
|
17
|
-
*
|
|
34
|
+
* Provides a `Socket.WebSocketConstructor`, using `globalThis.WebSocket` when
|
|
35
|
+
* available and falling back to the `ws` package otherwise.
|
|
36
|
+
*
|
|
18
37
|
* @category layers
|
|
38
|
+
* @since 4.0.0
|
|
19
39
|
*/
|
|
20
40
|
export const layerWebSocketConstructor: Layer.Layer<
|
|
21
41
|
Socket.WebSocketConstructor
|
|
@@ -27,8 +47,25 @@ export const layerWebSocketConstructor: Layer.Layer<
|
|
|
27
47
|
})
|
|
28
48
|
|
|
29
49
|
/**
|
|
30
|
-
*
|
|
50
|
+
* Provides a `Socket.WebSocketConstructor` backed explicitly by the `ws`
|
|
51
|
+
* package.
|
|
52
|
+
*
|
|
31
53
|
* @category layers
|
|
54
|
+
* @since 4.0.0
|
|
55
|
+
*/
|
|
56
|
+
export const layerWebSocketConstructorWS: Layer.Layer<
|
|
57
|
+
Socket.WebSocketConstructor
|
|
58
|
+
> = Layer.succeed(Socket.WebSocketConstructor)(
|
|
59
|
+
(url, protocols) => new WS.WebSocket(url, protocols) as unknown as globalThis.WebSocket
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Creates a `Socket.Socket` layer for a WebSocket URL using the Node WebSocket
|
|
64
|
+
* constructor layer, honoring protocol, open-timeout, and close-code error
|
|
65
|
+
* options.
|
|
66
|
+
*
|
|
67
|
+
* @category layers
|
|
68
|
+
* @since 4.0.0
|
|
32
69
|
*/
|
|
33
70
|
export const layerWebSocket: (
|
|
34
71
|
url: string | Effect.Effect<string>,
|
package/src/NodeSocketServer.ts
CHANGED
package/src/NodeStdio.ts
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Node.js implementation of the Effect `Stdio` service.
|
|
3
|
+
*
|
|
4
|
+
* This module exposes a layer that connects `Stdio` to the current process:
|
|
5
|
+
* command-line arguments come from `process.argv`, input is read from
|
|
6
|
+
* `process.stdin`, and output and error output write to `process.stdout` and
|
|
7
|
+
* `process.stderr`. It is intended for CLIs, scripts, command runners, and
|
|
8
|
+
* other process-oriented programs that need standard input and output through
|
|
9
|
+
* Effect services.
|
|
10
|
+
*
|
|
11
|
+
* The underlying streams are owned by the Node process. The layer keeps stdin
|
|
12
|
+
* open and does not end stdout or stderr when a stream finishes, which avoids
|
|
13
|
+
* closing global process handles that other code may still use. Be mindful that
|
|
14
|
+
* stdio may be a pipe, file, or TTY, so terminal-specific behavior such as raw
|
|
15
|
+
* mode, echo, colors, and cursor control should be handled with the terminal
|
|
16
|
+
* APIs instead of assuming an interactive console.
|
|
17
|
+
*
|
|
18
|
+
* @since 4.0.0
|
|
3
19
|
*/
|
|
4
20
|
import * as NodeStdio from "@effect/platform-node-shared/NodeStdio"
|
|
5
21
|
import type * as Layer from "effect/Layer"
|
|
6
22
|
import type { Stdio } from "effect/Stdio"
|
|
7
23
|
|
|
8
24
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
25
|
+
* Provides the `Stdio` service backed by the current process arguments,
|
|
26
|
+
* stdin, stdout, and stderr streams.
|
|
27
|
+
*
|
|
28
|
+
* @category layers
|
|
29
|
+
* @since 4.0.0
|
|
11
30
|
*/
|
|
12
31
|
export const layer: Layer.Layer<Stdio> = NodeStdio.layer
|
package/src/NodeStream.ts
CHANGED
package/src/NodeTerminal.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides the Node.js `Terminal` service for interactive command-line
|
|
3
|
+
* programs, prompts, and tools that need to read lines, react to key presses,
|
|
4
|
+
* write to stdout, or inspect terminal dimensions.
|
|
5
|
+
*
|
|
6
|
+
* The implementation is backed by the current process' stdin and stdout. When
|
|
7
|
+
* stdin is a TTY, key input temporarily enables raw mode for the scope of the
|
|
8
|
+
* service, so callers should acquire it with a scope or use the provided layer
|
|
9
|
+
* to ensure terminal state is restored. In non-TTY environments, terminal
|
|
10
|
+
* dimensions may be reported as zero and raw-mode key handling is unavailable.
|
|
11
|
+
*
|
|
12
|
+
* @since 4.0.0
|
|
3
13
|
*/
|
|
4
14
|
import * as NodeTerminal from "@effect/platform-node-shared/NodeTerminal"
|
|
5
15
|
import type { Effect } from "effect/Effect"
|
|
@@ -8,13 +18,19 @@ import type { Scope } from "effect/Scope"
|
|
|
8
18
|
import type { Terminal, UserInput } from "effect/Terminal"
|
|
9
19
|
|
|
10
20
|
/**
|
|
11
|
-
*
|
|
21
|
+
* Creates a scoped `Terminal` service backed by process stdin/stdout, using the
|
|
22
|
+
* optional predicate to decide when key input should end the input stream.
|
|
23
|
+
*
|
|
12
24
|
* @category constructors
|
|
25
|
+
* @since 4.0.0
|
|
13
26
|
*/
|
|
14
27
|
export const make: (shouldQuit?: (input: UserInput) => boolean) => Effect<Terminal, never, Scope> = NodeTerminal.make
|
|
15
28
|
|
|
16
29
|
/**
|
|
17
|
-
*
|
|
30
|
+
* Provides the default process-backed `Terminal` service, ending key input on
|
|
31
|
+
* the default quit keys.
|
|
32
|
+
*
|
|
18
33
|
* @category layers
|
|
34
|
+
* @since 4.0.0
|
|
19
35
|
*/
|
|
20
36
|
export const layer: Layer<Terminal> = NodeTerminal.layer
|
package/src/NodeWorker.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Parent-side Node.js support for Effect workers.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the `WorkerPlatform` used by Node programs that spawn
|
|
5
|
+
* and communicate with `node:worker_threads` workers or IPC-enabled child
|
|
6
|
+
* processes through Effect's worker protocol. Pair it with `NodeWorkerRunner`
|
|
7
|
+
* in the worker entrypoint when building worker-backed RPC clients, offloading
|
|
8
|
+
* CPU-bound work, isolating Node resources, or hosting services that should
|
|
9
|
+
* exchange typed messages with the parent process.
|
|
10
|
+
*
|
|
11
|
+
* Worker-thread spawners can use `postMessage` transfer lists for values such
|
|
12
|
+
* as `ArrayBuffer` and `MessagePort`, but transferring moves ownership and
|
|
13
|
+
* invalid transfer lists surface as worker send or receive failures.
|
|
14
|
+
* Child-process spawners must provide an IPC channel, for example via
|
|
15
|
+
* `child_process.fork` or `stdio: "ipc"`; their messages use Node IPC
|
|
16
|
+
* serialization and this module does not forward transfer lists to
|
|
17
|
+
* `ChildProcess.send`. Scope finalization sends the worker close signal and
|
|
18
|
+
* waits for exit before falling back to `terminate()` or `SIGKILL`.
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
4
22
|
import * as Deferred from "effect/Deferred"
|
|
5
23
|
import * as Effect from "effect/Effect"
|
|
@@ -12,8 +30,12 @@ import type * as ChildProcess from "node:child_process"
|
|
|
12
30
|
import type * as WorkerThreads from "node:worker_threads"
|
|
13
31
|
|
|
14
32
|
/**
|
|
15
|
-
*
|
|
33
|
+
* Provides the Node `WorkerPlatform` for `worker_threads` workers and child
|
|
34
|
+
* process workers, wiring messages, errors, and exits into Effect workers and
|
|
35
|
+
* terminating the worker if graceful shutdown times out.
|
|
36
|
+
*
|
|
16
37
|
* @category layers
|
|
38
|
+
* @since 4.0.0
|
|
17
39
|
*/
|
|
18
40
|
export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(Worker.WorkerPlatform)(
|
|
19
41
|
Worker.makePlatform<WorkerThreads.Worker | ChildProcess.ChildProcess>()({
|
|
@@ -63,7 +85,7 @@ export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(W
|
|
|
63
85
|
message: "An messageerror event was emitted",
|
|
64
86
|
cause
|
|
65
87
|
})
|
|
66
|
-
})
|
|
88
|
+
})
|
|
67
89
|
)
|
|
68
90
|
})
|
|
69
91
|
port.worker.on("error", (cause) => {
|
|
@@ -74,7 +96,7 @@ export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(W
|
|
|
74
96
|
message: "An error event was emitted",
|
|
75
97
|
cause
|
|
76
98
|
})
|
|
77
|
-
})
|
|
99
|
+
})
|
|
78
100
|
)
|
|
79
101
|
})
|
|
80
102
|
port.worker.on("exit", (code) => {
|
|
@@ -84,7 +106,7 @@ export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(W
|
|
|
84
106
|
reason: new WorkerReceiveError({
|
|
85
107
|
message: "The worker has exited with code: " + code
|
|
86
108
|
})
|
|
87
|
-
})
|
|
109
|
+
})
|
|
88
110
|
)
|
|
89
111
|
})
|
|
90
112
|
return Effect.void
|
|
@@ -93,8 +115,11 @@ export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(W
|
|
|
93
115
|
)
|
|
94
116
|
|
|
95
117
|
/**
|
|
96
|
-
*
|
|
118
|
+
* Provides the Node `WorkerPlatform` together with a `Worker.Spawner` created
|
|
119
|
+
* from the supplied worker or child-process spawning function.
|
|
120
|
+
*
|
|
97
121
|
* @category layers
|
|
122
|
+
* @since 4.0.0
|
|
98
123
|
*/
|
|
99
124
|
export const layer = (
|
|
100
125
|
spawn: (id: number) => WorkerThreads.Worker | ChildProcess.ChildProcess
|
package/src/NodeWorkerRunner.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Runtime support for Effect workers that are executed by Node.js.
|
|
3
|
+
*
|
|
4
|
+
* This module is intended to be installed in the program running inside a
|
|
5
|
+
* `node:worker_threads` worker or an IPC-enabled child process. It provides the
|
|
6
|
+
* `WorkerRunnerPlatform` used by `WorkerRunner` to receive request messages
|
|
7
|
+
* from the parent, run the registered Effect handler, and send responses back
|
|
8
|
+
* over the parent channel.
|
|
9
|
+
*
|
|
10
|
+
* Use it when the parent side is created with `NodeWorker` and the worker code
|
|
11
|
+
* needs to perform CPU-bound work, isolate Node resources, or host services that
|
|
12
|
+
* should communicate through the Effect worker protocol. The runner must be
|
|
13
|
+
* started from an actual worker context: `parentPort` is required for worker
|
|
14
|
+
* threads, while child processes must be spawned with an IPC channel so
|
|
15
|
+
* `process.send` is available. Transfer lists only apply to worker-thread
|
|
16
|
+
* `postMessage`; child-process messages go through Node IPC serialization.
|
|
17
|
+
* Shutdown is coordinated by the parent message protocol, so long-running
|
|
18
|
+
* handlers should remain interruptible and keep resource cleanup in scopes.
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
4
22
|
import * as Cause from "effect/Cause"
|
|
5
23
|
import * as Deferred from "effect/Deferred"
|
|
@@ -12,8 +30,12 @@ import * as WorkerRunner from "effect/unstable/workers/WorkerRunner"
|
|
|
12
30
|
import * as WorkerThreads from "node:worker_threads"
|
|
13
31
|
|
|
14
32
|
/**
|
|
15
|
-
*
|
|
33
|
+
* Provides the `WorkerRunnerPlatform` for code running inside a Node worker
|
|
34
|
+
* thread or child process, routing parent messages to the registered handler
|
|
35
|
+
* and sending responses back through the parent channel.
|
|
36
|
+
*
|
|
16
37
|
* @category layers
|
|
38
|
+
* @since 4.0.0
|
|
17
39
|
*/
|
|
18
40
|
export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succeed(WorkerRunner.WorkerRunnerPlatform)({
|
|
19
41
|
start<O = unknown, I = unknown>() {
|
|
@@ -36,7 +58,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
|
|
|
36
58
|
Effect.scopedWith(Effect.fnUntraced(function*(scope) {
|
|
37
59
|
const closeLatch = Deferred.makeUnsafe<void, WorkerError>()
|
|
38
60
|
const trackFiber = Fiber.runIn(scope)
|
|
39
|
-
const services = yield* Effect.
|
|
61
|
+
const services = yield* Effect.context<R>()
|
|
40
62
|
const runFork = Effect.runForkWith(services)
|
|
41
63
|
const onExit = (exit: Exit.Exit<any, E>) => {
|
|
42
64
|
if (exit._tag === "Failure" && !Cause.hasInterruptsOnly(exit.cause)) {
|
|
@@ -70,7 +92,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
|
|
|
70
92
|
message: "received messageerror event",
|
|
71
93
|
cause
|
|
72
94
|
})
|
|
73
|
-
})
|
|
95
|
+
})
|
|
74
96
|
)
|
|
75
97
|
})
|
|
76
98
|
WorkerThreads.parentPort.on("error", (cause) => {
|
|
@@ -81,7 +103,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
|
|
|
81
103
|
message: "received messageerror event",
|
|
82
104
|
cause
|
|
83
105
|
})
|
|
84
|
-
})
|
|
106
|
+
})
|
|
85
107
|
)
|
|
86
108
|
})
|
|
87
109
|
}
|
package/src/Undici.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
import Undici from "undici"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @since 1.0.0
|
|
8
7
|
* @category undici
|
|
8
|
+
* @since 4.0.0
|
|
9
9
|
*/
|
|
10
10
|
export * from "undici"
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @since 1.0.0
|
|
14
13
|
* @category undici
|
|
14
|
+
* @since 4.0.0
|
|
15
15
|
*/
|
|
16
16
|
export default Undici
|