@effect/platform-node 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.
Files changed (123) hide show
  1. package/dist/Mime.d.ts +9 -3
  2. package/dist/Mime.d.ts.map +1 -1
  3. package/dist/Mime.js +9 -3
  4. package/dist/Mime.js.map +1 -1
  5. package/dist/NodeChildProcessSpawner.d.ts +1 -1
  6. package/dist/NodeChildProcessSpawner.js +1 -1
  7. package/dist/NodeClusterHttp.d.ts +49 -7
  8. package/dist/NodeClusterHttp.d.ts.map +1 -1
  9. package/dist/NodeClusterHttp.js +20 -10
  10. package/dist/NodeClusterHttp.js.map +1 -1
  11. package/dist/NodeClusterSocket.d.ts +57 -11
  12. package/dist/NodeClusterSocket.d.ts.map +1 -1
  13. package/dist/NodeClusterSocket.js +57 -11
  14. package/dist/NodeClusterSocket.js.map +1 -1
  15. package/dist/NodeCrypto.d.ts +10 -0
  16. package/dist/NodeCrypto.d.ts.map +1 -0
  17. package/dist/NodeCrypto.js +22 -0
  18. package/dist/NodeCrypto.js.map +1 -0
  19. package/dist/NodeFileSystem.d.ts +4 -2
  20. package/dist/NodeFileSystem.d.ts.map +1 -1
  21. package/dist/NodeFileSystem.js +30 -3
  22. package/dist/NodeFileSystem.js.map +1 -1
  23. package/dist/NodeHttpClient.d.ts +111 -24
  24. package/dist/NodeHttpClient.d.ts.map +1 -1
  25. package/dist/NodeHttpClient.js +133 -28
  26. package/dist/NodeHttpClient.js.map +1 -1
  27. package/dist/NodeHttpIncomingMessage.d.ts +43 -9
  28. package/dist/NodeHttpIncomingMessage.d.ts.map +1 -1
  29. package/dist/NodeHttpIncomingMessage.js +47 -8
  30. package/dist/NodeHttpIncomingMessage.js.map +1 -1
  31. package/dist/NodeHttpPlatform.d.ts +10 -4
  32. package/dist/NodeHttpPlatform.d.ts.map +1 -1
  33. package/dist/NodeHttpPlatform.js +34 -7
  34. package/dist/NodeHttpPlatform.js.map +1 -1
  35. package/dist/NodeHttpServer.d.ts +56 -16
  36. package/dist/NodeHttpServer.d.ts.map +1 -1
  37. package/dist/NodeHttpServer.js +117 -49
  38. package/dist/NodeHttpServer.js.map +1 -1
  39. package/dist/NodeHttpServerRequest.d.ts +29 -3
  40. package/dist/NodeHttpServerRequest.d.ts.map +1 -1
  41. package/dist/NodeHttpServerRequest.js +9 -2
  42. package/dist/NodeHttpServerRequest.js.map +1 -1
  43. package/dist/NodeMultipart.d.ts +47 -4
  44. package/dist/NodeMultipart.d.ts.map +1 -1
  45. package/dist/NodeMultipart.js +47 -4
  46. package/dist/NodeMultipart.js.map +1 -1
  47. package/dist/NodePath.d.ts +15 -6
  48. package/dist/NodePath.d.ts.map +1 -1
  49. package/dist/NodePath.js +43 -7
  50. package/dist/NodePath.js.map +1 -1
  51. package/dist/NodeRedis.d.ts +56 -9
  52. package/dist/NodeRedis.d.ts.map +1 -1
  53. package/dist/NodeRedis.js +59 -12
  54. package/dist/NodeRedis.js.map +1 -1
  55. package/dist/NodeRuntime.d.ts +27 -36
  56. package/dist/NodeRuntime.d.ts.map +1 -1
  57. package/dist/NodeRuntime.js +38 -13
  58. package/dist/NodeRuntime.js.map +1 -1
  59. package/dist/NodeServices.d.ts +44 -5
  60. package/dist/NodeServices.d.ts.map +1 -1
  61. package/dist/NodeServices.js +7 -3
  62. package/dist/NodeServices.js.map +1 -1
  63. package/dist/NodeSink.d.ts +2 -2
  64. package/dist/NodeSink.js +2 -2
  65. package/dist/NodeSocket.d.ts +18 -3
  66. package/dist/NodeSocket.d.ts.map +1 -1
  67. package/dist/NodeSocket.js +51 -4
  68. package/dist/NodeSocket.js.map +1 -1
  69. package/dist/NodeSocketServer.d.ts +2 -2
  70. package/dist/NodeSocketServer.js +2 -2
  71. package/dist/NodeStdio.d.ts +5 -2
  72. package/dist/NodeStdio.d.ts.map +1 -1
  73. package/dist/NodeStdio.js +30 -3
  74. package/dist/NodeStdio.js.map +1 -1
  75. package/dist/NodeStream.d.ts +2 -2
  76. package/dist/NodeStream.js +2 -2
  77. package/dist/NodeTerminal.d.ts +8 -2
  78. package/dist/NodeTerminal.d.ts.map +1 -1
  79. package/dist/NodeTerminal.js +29 -3
  80. package/dist/NodeTerminal.js.map +1 -1
  81. package/dist/NodeWorker.d.ts +9 -2
  82. package/dist/NodeWorker.d.ts.map +1 -1
  83. package/dist/NodeWorker.js +45 -6
  84. package/dist/NodeWorker.js.map +1 -1
  85. package/dist/NodeWorkerRunner.d.ts +5 -1
  86. package/dist/NodeWorkerRunner.d.ts.map +1 -1
  87. package/dist/NodeWorkerRunner.js +47 -5
  88. package/dist/NodeWorkerRunner.js.map +1 -1
  89. package/dist/Undici.d.ts +16 -3
  90. package/dist/Undici.d.ts.map +1 -1
  91. package/dist/Undici.js +16 -3
  92. package/dist/Undici.js.map +1 -1
  93. package/dist/index.d.ts +28 -26
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.js +28 -26
  96. package/dist/index.js.map +1 -1
  97. package/package.json +9 -9
  98. package/src/Mime.ts +10 -3
  99. package/src/NodeChildProcessSpawner.ts +1 -1
  100. package/src/NodeClusterHttp.ts +54 -11
  101. package/src/NodeClusterSocket.ts +57 -11
  102. package/src/NodeCrypto.ts +24 -0
  103. package/src/NodeFileSystem.ts +30 -3
  104. package/src/NodeHttpClient.ts +141 -33
  105. package/src/NodeHttpIncomingMessage.ts +55 -12
  106. package/src/NodeHttpPlatform.ts +35 -6
  107. package/src/NodeHttpServer.ts +139 -53
  108. package/src/NodeHttpServerRequest.ts +29 -3
  109. package/src/NodeMultipart.ts +47 -4
  110. package/src/NodePath.ts +43 -7
  111. package/src/NodeRedis.ts +61 -14
  112. package/src/NodeRuntime.ts +56 -37
  113. package/src/NodeServices.ts +46 -5
  114. package/src/NodeSink.ts +2 -2
  115. package/src/NodeSocket.ts +56 -4
  116. package/src/NodeSocketServer.ts +2 -2
  117. package/src/NodeStdio.ts +30 -3
  118. package/src/NodeStream.ts +2 -2
  119. package/src/NodeTerminal.ts +29 -3
  120. package/src/NodeWorker.ts +45 -6
  121. package/src/NodeWorkerRunner.ts +47 -5
  122. package/src/Undici.ts +16 -3
  123. package/src/index.ts +29 -26
@@ -1,5 +1,33 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Node.js process runner for starting an Effect program at the application
3
+ * edge.
4
+ *
5
+ * This module exposes `runMain`, the launcher used by Node CLIs, scripts,
6
+ * servers, and workers when a single Effect should become the process root. It
7
+ * handles runtime error reporting, Node process signals, and teardown so the
8
+ * rest of the program can stay inside Effect.
9
+ *
10
+ * **Mental model**
11
+ *
12
+ * `runMain` is the last call in `main.ts`: build the effect, provide the layers
13
+ * it needs, then hand the self-contained program to this module. The function
14
+ * does not provide Node services itself; use `NodeServices.layer` or narrower
15
+ * platform layers before launching.
16
+ *
17
+ * **Common tasks**
18
+ *
19
+ * - Run a CLI command or script and let failures become process failures.
20
+ * - Keep a server or worker fiber alive as the process main program.
21
+ * - Override teardown or disable automatic error reporting at the boundary.
22
+ *
23
+ * **Gotchas**
24
+ *
25
+ * `SIGINT` and `SIGTERM` interrupt the main fiber so scoped finalizers can run.
26
+ * Clean success lets the event loop drain naturally, while signal-triggered
27
+ * interruption or a non-zero teardown code exits the process. Keep long-lived
28
+ * resources in Effect scopes and avoid finalizers that never complete.
29
+ *
30
+ * @since 4.0.0
3
31
  */
4
32
  import * as NodeRuntime from "@effect/platform-node-shared/NodeRuntime"
5
33
  import type { Effect } from "effect/Effect"
@@ -8,6 +36,12 @@ import type * as Runtime from "effect/Runtime"
8
36
  /**
9
37
  * Helps you run a main effect with built-in error handling, logging, and signal management.
10
38
  *
39
+ * **When to use**
40
+ *
41
+ * Use to run an Effect as your application's main program, especially
42
+ * when you need structured error handling, log management, interrupt support,
43
+ * or advanced teardown capabilities.
44
+ *
11
45
  * **Details**
12
46
  *
13
47
  * This function launches an Effect as the main entry point, setting exit codes
@@ -16,26 +50,23 @@ import type * as Runtime from "effect/Runtime"
16
50
  * behaviors can be turned off. You can also provide custom teardown logic to
17
51
  * finalize resources or produce different exit codes.
18
52
  *
19
- * **Options**
20
- *
21
- * An optional object that can include:
53
+ * The optional configuration object can include:
22
54
  * - `disableErrorReporting`: Turn off automatic error logging.
23
- * - `disablePrettyLogger`: Avoid adding the pretty logger.
24
55
  * - `teardown`: Provide custom finalization logic.
25
56
  *
26
- * **When to Use**
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
57
+ * @category running
58
+ * @since 4.0.0
34
59
  */
35
60
  export const runMain: {
36
61
  /**
37
62
  * Helps you run a main effect with built-in error handling, logging, and signal management.
38
63
  *
64
+ * **When to use**
65
+ *
66
+ * Use to run an Effect as your application's main program, especially
67
+ * when you need structured error handling, log management, interrupt support,
68
+ * or advanced teardown capabilities.
69
+ *
39
70
  * **Details**
40
71
  *
41
72
  * This function launches an Effect as the main entry point, setting exit codes
@@ -44,21 +75,12 @@ export const runMain: {
44
75
  * behaviors can be turned off. You can also provide custom teardown logic to
45
76
  * finalize resources or produce different exit codes.
46
77
  *
47
- * **Options**
48
- *
49
- * An optional object that can include:
78
+ * The optional configuration object can include:
50
79
  * - `disableErrorReporting`: Turn off automatic error logging.
51
- * - `disablePrettyLogger`: Avoid adding the pretty logger.
52
80
  * - `teardown`: Provide custom finalization logic.
53
81
  *
54
- * **When to Use**
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
82
+ * @category running
83
+ * @since 4.0.0
62
84
  */
63
85
  (
64
86
  options?: {
@@ -69,6 +91,12 @@ export const runMain: {
69
91
  /**
70
92
  * Helps you run a main effect with built-in error handling, logging, and signal management.
71
93
  *
94
+ * **When to use**
95
+ *
96
+ * Use to run an Effect as your application's main program, especially
97
+ * when you need structured error handling, log management, interrupt support,
98
+ * or advanced teardown capabilities.
99
+ *
72
100
  * **Details**
73
101
  *
74
102
  * This function launches an Effect as the main entry point, setting exit codes
@@ -77,21 +105,12 @@ export const runMain: {
77
105
  * behaviors can be turned off. You can also provide custom teardown logic to
78
106
  * finalize resources or produce different exit codes.
79
107
  *
80
- * **Options**
81
- *
82
- * An optional object that can include:
108
+ * The optional configuration object can include:
83
109
  * - `disableErrorReporting`: Turn off automatic error logging.
84
- * - `disablePrettyLogger`: Avoid adding the pretty logger.
85
110
  * - `teardown`: Provide custom finalization logic.
86
111
  *
87
- * **When to Use**
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
112
+ * @category running
113
+ * @since 4.0.0
95
114
  */
96
115
  <E, A>(
97
116
  effect: Effect<A, E>,
@@ -1,6 +1,39 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Standard Node.js service bundle for Effect applications.
3
+ *
4
+ * `NodeServices.layer` provides the Node implementations of the core services
5
+ * most command-line programs and server entrypoints need: child process
6
+ * spawning, cryptography, filesystem access, path operations, stdio, terminal
7
+ * interaction, and related process I/O.
8
+ *
9
+ * **Mental model**
10
+ *
11
+ * Application code should depend on the individual Effect service tags it uses,
12
+ * such as `FileSystem`, `Path`, or `Stdio`. This module is the composition
13
+ * point for a Node runtime: provide the aggregate layer once near the program
14
+ * boundary, and those service requirements are satisfied by Node-backed
15
+ * implementations.
16
+ *
17
+ * **Common tasks**
18
+ *
19
+ * - Install the default Node platform services for a CLI, script, or process
20
+ * entrypoint with {@link layer}
21
+ * - Use narrower modules such as `NodeFileSystem`, `NodePath`, or `NodeStdio`
22
+ * when a test or embedded runtime should expose only one service
23
+ * - Keep libraries platform-independent by requiring service tags instead of
24
+ * importing this module directly
25
+ *
26
+ * **Gotchas**
27
+ *
28
+ * This is not every Node integration in `@effect/platform-node`. HTTP clients,
29
+ * HTTP servers, sockets, workers, Redis, and other specialized integrations
30
+ * still have their own modules and layers. Providing this layer also means
31
+ * effects can reach real process resources such as the filesystem, stdio,
32
+ * terminal handles, and child processes.
33
+ *
34
+ * @since 4.0.0
3
35
  */
36
+ import type { Crypto } from "effect/Crypto"
4
37
  import type { FileSystem } from "effect/FileSystem"
5
38
  import * as Layer from "effect/Layer"
6
39
  import type { Path } from "effect/Path"
@@ -8,25 +41,33 @@ import type { Stdio } from "effect/Stdio"
8
41
  import type { Terminal } from "effect/Terminal"
9
42
  import type { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner"
10
43
  import * as NodeChildProcessSpawner from "./NodeChildProcessSpawner.ts"
44
+ import * as NodeCrypto from "./NodeCrypto.ts"
11
45
  import * as NodeFileSystem from "./NodeFileSystem.ts"
12
46
  import * as NodePath from "./NodePath.ts"
13
47
  import * as NodeStdio from "./NodeStdio.ts"
14
48
  import * as NodeTerminal from "./NodeTerminal.ts"
15
49
 
16
50
  /**
17
- * @since 1.0.0
51
+ * The union of core services provided by the Node platform layer, including
52
+ * child process spawning, filesystem, path, stdio, and terminal services.
53
+ *
18
54
  * @category models
55
+ * @since 4.0.0
19
56
  */
20
- export type NodeServices = ChildProcessSpawner | FileSystem | Path | Stdio | Terminal
57
+ export type NodeServices = ChildProcessSpawner | Crypto | FileSystem | Path | Stdio | Terminal
21
58
 
22
59
  /**
23
- * @since 1.0.0
24
- * @category layer
60
+ * Provides the default Node implementations for child process spawning,
61
+ * filesystem, path, stdio, and terminal services.
62
+ *
63
+ * @category layers
64
+ * @since 4.0.0
25
65
  */
26
66
  export const layer: Layer.Layer<NodeServices> = Layer.provideMerge(
27
67
  NodeChildProcessSpawner.layer,
28
68
  Layer.mergeAll(
29
69
  NodeFileSystem.layer,
70
+ NodeCrypto.layer,
30
71
  NodePath.layer,
31
72
  NodeStdio.layer,
32
73
  NodeTerminal.layer
package/src/NodeSink.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  /**
6
- * @since 1.0.0
6
+ * @since 4.0.0
7
7
  */
8
8
  export * from "@effect/platform-node-shared/NodeSink"
package/src/NodeSocket.ts CHANGED
@@ -1,5 +1,37 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Node.js socket constructors and layers for Effect sockets.
3
+ *
4
+ * This module combines shared Node stream-backed socket support with
5
+ * Node-specific WebSocket constructor layers. Use it to open TCP clients, Unix
6
+ * domain socket clients, adapt existing Node `Duplex` streams, or provide
7
+ * WebSocket clients to protocols built on Effect's `Socket.Socket`.
8
+ *
9
+ * **Mental model**
10
+ *
11
+ * TCP and Unix sockets come from `node:net` and are exposed as scoped
12
+ * `Socket.Socket` values. Stream open, read, write, and close events are
13
+ * translated to `SocketError` values, and finalization closes or destroys the
14
+ * underlying stream. WebSocket layers provide only the constructor service used
15
+ * by `Socket.makeWebSocket`; `layerWebSocket` combines that constructor with a
16
+ * URL to provide a socket layer.
17
+ *
18
+ * **Common tasks**
19
+ *
20
+ * - Use `makeNet`, `makeNetChannel`, or `layerNet` for TCP connections.
21
+ * - Set `NetConnectOpts.path` for Unix domain sockets.
22
+ * - Use `fromDuplex` when another library already owns a Node `Duplex`.
23
+ * - Use `layerWebSocketConstructor` for the native WebSocket when present, with
24
+ * fallback to `ws`; use `layerWebSocketConstructorWS` to force `ws`.
25
+ *
26
+ * **Gotchas**
27
+ *
28
+ * Socket lifetime is scoped, so release the layer or scope to close the
29
+ * connection. Writes complete when Node accepts or flushes the chunk, not when
30
+ * a peer processes it. Remote `end` events complete the socket run, while
31
+ * abnormal closes, open timeouts, and stream errors surface through
32
+ * `SocketError`; handle them in the Effect that runs the socket.
33
+ *
34
+ * @since 4.0.0
3
35
  */
4
36
  import { NodeWS as WS } from "@effect/platform-node-shared/NodeSocket"
5
37
  import type * as Duration from "effect/Duration"
@@ -9,13 +41,16 @@ import * as Layer from "effect/Layer"
9
41
  import * as Socket from "effect/unstable/socket/Socket"
10
42
 
11
43
  /**
12
- * @since 1.0.0
44
+ * @since 4.0.0
13
45
  */
14
46
  export * from "@effect/platform-node-shared/NodeSocket"
15
47
 
16
48
  /**
17
- * @since 1.0.0
49
+ * Provides a `Socket.WebSocketConstructor`, using `globalThis.WebSocket` when
50
+ * available and falling back to the `ws` package otherwise.
51
+ *
18
52
  * @category layers
53
+ * @since 4.0.0
19
54
  */
20
55
  export const layerWebSocketConstructor: Layer.Layer<
21
56
  Socket.WebSocketConstructor
@@ -27,8 +62,25 @@ export const layerWebSocketConstructor: Layer.Layer<
27
62
  })
28
63
 
29
64
  /**
30
- * @since 1.0.0
65
+ * Provides a `Socket.WebSocketConstructor` backed explicitly by the `ws`
66
+ * package.
67
+ *
31
68
  * @category layers
69
+ * @since 4.0.0
70
+ */
71
+ export const layerWebSocketConstructorWS: Layer.Layer<
72
+ Socket.WebSocketConstructor
73
+ > = Layer.succeed(Socket.WebSocketConstructor)(
74
+ (url, protocols) => new WS.WebSocket(url, protocols) as unknown as globalThis.WebSocket
75
+ )
76
+
77
+ /**
78
+ * Creates a `Socket.Socket` layer for a WebSocket URL using the Node WebSocket
79
+ * constructor layer, honoring protocol, open-timeout, and close-code error
80
+ * options.
81
+ *
82
+ * @category layers
83
+ * @since 4.0.0
32
84
  */
33
85
  export const layerWebSocket: (
34
86
  url: string | Effect.Effect<string>,
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  /**
6
- * @since 1.0.0
6
+ * @since 4.0.0
7
7
  */
8
8
  export * from "@effect/platform-node-shared/NodeSocketServer"
package/src/NodeStdio.ts CHANGED
@@ -1,12 +1,39 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Node.js `Stdio` layer for the current process.
3
+ *
4
+ * The exported layer satisfies the platform-independent `Stdio` service by
5
+ * reading command-line arguments from `process.argv`, consuming input from
6
+ * `process.stdin`, and writing output streams to `process.stdout` and
7
+ * `process.stderr`. It is the stdio bridge used by CLIs, scripts, command
8
+ * runners, and tests that intentionally communicate through the host process.
9
+ *
10
+ * **Mental model**
11
+ *
12
+ * Effects should depend on `Stdio`; this module decides that the backing
13
+ * streams are the global Node process handles. Provide `NodeStdio.layer` when a
14
+ * program only needs standard input and output, or `NodeServices.layer` when the
15
+ * same entrypoint also needs the other default Node services.
16
+ *
17
+ * **Gotchas**
18
+ *
19
+ * The process stdio streams are shared resources. The layer leaves stdin open
20
+ * and does not end stdout or stderr by default, avoiding accidental closure of
21
+ * handles that other code in the same process may still use. Stdio might be a
22
+ * pipe, file, or TTY; terminal-specific behavior such as raw mode, echo, color
23
+ * detection, and cursor movement belongs with terminal APIs rather than this
24
+ * service.
25
+ *
26
+ * @since 4.0.0
3
27
  */
4
28
  import * as NodeStdio from "@effect/platform-node-shared/NodeStdio"
5
29
  import type * as Layer from "effect/Layer"
6
30
  import type { Stdio } from "effect/Stdio"
7
31
 
8
32
  /**
9
- * @since 1.0.0
10
- * @category layer
33
+ * Provides the `Stdio` service backed by the current process arguments,
34
+ * stdin, stdout, and stderr streams.
35
+ *
36
+ * @category layers
37
+ * @since 4.0.0
11
38
  */
12
39
  export const layer: Layer.Layer<Stdio> = NodeStdio.layer
package/src/NodeStream.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  /**
6
- * @since 1.0.0
6
+ * @since 4.0.0
7
7
  */
8
8
  export * from "@effect/platform-node-shared/NodeStream"
@@ -1,5 +1,25 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Node.js implementation of the Effect `Terminal` service.
3
+ *
4
+ * `NodeTerminal` connects `Terminal` to the current process' stdin and stdout
5
+ * so Node programs can read lines, stream key presses, write display output,
6
+ * and inspect terminal dimensions through the Effect service environment.
7
+ *
8
+ * **Mental model**
9
+ *
10
+ * `make` acquires a scoped terminal backed by process streams, and `layer`
11
+ * provides that service with the default key sequence for quitting input. When
12
+ * stdin is a TTY, low-level key input temporarily enables raw mode for the
13
+ * lifetime of the scope; finalization restores the previous terminal state.
14
+ *
15
+ * **Gotchas**
16
+ *
17
+ * In non-TTY environments such as CI, pipes, or redirected input, terminal
18
+ * dimensions may be reported as zero and raw-mode key handling is unavailable.
19
+ * For plain stdin/stdout byte streams, use the standard I/O service instead of
20
+ * the interactive terminal service.
21
+ *
22
+ * @since 4.0.0
3
23
  */
4
24
  import * as NodeTerminal from "@effect/platform-node-shared/NodeTerminal"
5
25
  import type { Effect } from "effect/Effect"
@@ -8,13 +28,19 @@ import type { Scope } from "effect/Scope"
8
28
  import type { Terminal, UserInput } from "effect/Terminal"
9
29
 
10
30
  /**
11
- * @since 1.0.0
31
+ * Creates a scoped `Terminal` service backed by process stdin/stdout, using the
32
+ * optional predicate to decide when key input should end the input stream.
33
+ *
12
34
  * @category constructors
35
+ * @since 4.0.0
13
36
  */
14
37
  export const make: (shouldQuit?: (input: UserInput) => boolean) => Effect<Terminal, never, Scope> = NodeTerminal.make
15
38
 
16
39
  /**
17
- * @since 1.0.0
40
+ * Provides the default process-backed `Terminal` service, ending key input on
41
+ * the default quit keys.
42
+ *
18
43
  * @category layers
44
+ * @since 4.0.0
19
45
  */
20
46
  export const layer: Layer<Terminal> = NodeTerminal.layer
package/src/NodeWorker.ts CHANGED
@@ -1,5 +1,37 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Parent-side Node.js support for Effect workers.
3
+ *
4
+ * This module installs the `WorkerPlatform` used by a Node program that owns
5
+ * workers. It supports both `node:worker_threads` workers and IPC-enabled child
6
+ * processes, routing messages through Effect's worker protocol so higher-level
7
+ * worker clients can treat either runtime as the same parent-side transport.
8
+ *
9
+ * **Mental model**
10
+ *
11
+ * `NodeWorker` runs in the parent process. The worker entrypoint should install
12
+ * `NodeWorkerRunner`, which receives parent messages, runs the registered
13
+ * Effect handler, and sends replies back over the same channel. Use `layer`
14
+ * when you want this module to provide both the platform and a `Worker.Spawner`;
15
+ * use `layerPlatform` when the spawner is provided elsewhere.
16
+ *
17
+ * **Common tasks**
18
+ *
19
+ * - Spawn CPU-bound or resource-isolated work in `worker_threads`.
20
+ * - Spawn a child process that was created with an IPC channel.
21
+ * - Share one parent-side worker implementation across both Node transports.
22
+ *
23
+ * **Gotchas**
24
+ *
25
+ * Worker-thread spawners can use `postMessage` transfer lists for values such as
26
+ * `ArrayBuffer` and `MessagePort`; transferring moves ownership, and invalid
27
+ * transfer lists surface as send or receive failures. Child-process spawners
28
+ * must provide an IPC channel, for example via `child_process.fork` or
29
+ * `stdio: "ipc"`; their messages use Node IPC serialization and transfer lists
30
+ * are not forwarded to `ChildProcess.send`. Scope finalization sends the worker
31
+ * close signal and waits for exit before falling back to `terminate()` or
32
+ * `SIGKILL`.
33
+ *
34
+ * @since 4.0.0
3
35
  */
4
36
  import * as Deferred from "effect/Deferred"
5
37
  import * as Effect from "effect/Effect"
@@ -12,8 +44,12 @@ import type * as ChildProcess from "node:child_process"
12
44
  import type * as WorkerThreads from "node:worker_threads"
13
45
 
14
46
  /**
15
- * @since 1.0.0
47
+ * Provides the Node `WorkerPlatform` for `worker_threads` workers and child
48
+ * process workers, wiring messages, errors, and exits into Effect workers and
49
+ * terminating the worker if graceful shutdown times out.
50
+ *
16
51
  * @category layers
52
+ * @since 4.0.0
17
53
  */
18
54
  export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(Worker.WorkerPlatform)(
19
55
  Worker.makePlatform<WorkerThreads.Worker | ChildProcess.ChildProcess>()({
@@ -63,7 +99,7 @@ export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(W
63
99
  message: "An messageerror event was emitted",
64
100
  cause
65
101
  })
66
- }).asEffect()
102
+ })
67
103
  )
68
104
  })
69
105
  port.worker.on("error", (cause) => {
@@ -74,7 +110,7 @@ export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(W
74
110
  message: "An error event was emitted",
75
111
  cause
76
112
  })
77
- }).asEffect()
113
+ })
78
114
  )
79
115
  })
80
116
  port.worker.on("exit", (code) => {
@@ -84,7 +120,7 @@ export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(W
84
120
  reason: new WorkerReceiveError({
85
121
  message: "The worker has exited with code: " + code
86
122
  })
87
- }).asEffect()
123
+ })
88
124
  )
89
125
  })
90
126
  return Effect.void
@@ -93,8 +129,11 @@ export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(W
93
129
  )
94
130
 
95
131
  /**
96
- * @since 1.0.0
132
+ * Provides the Node `WorkerPlatform` together with a `Worker.Spawner` created
133
+ * from the supplied worker or child-process spawning function.
134
+ *
97
135
  * @category layers
136
+ * @since 4.0.0
98
137
  */
99
138
  export const layer = (
100
139
  spawn: (id: number) => WorkerThreads.Worker | ChildProcess.ChildProcess
@@ -1,5 +1,43 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Node.js runtime support for workers that serve Effect worker requests.
3
+ *
4
+ * `NodeWorkerRunner` supplies the Node implementation of the Effect worker
5
+ * runner platform. Install {@link layer} inside code that is already running in
6
+ * a `node:worker_threads` worker or in a child process with an IPC channel. The
7
+ * layer listens for parent messages, runs handlers registered through
8
+ * `WorkerRunner`, and replies over the same parent channel.
9
+ *
10
+ * **Mental model**
11
+ *
12
+ * - The parent process creates a worker with the Node worker APIs.
13
+ * - The worker process provides this module's {@link layer} to its runner program.
14
+ * - Startup sends a ready message to the parent, then request messages are
15
+ * dispatched to the registered Effect handler.
16
+ * - Responses are sent with Node `postMessage` for worker threads or
17
+ * `process.send` for child processes.
18
+ * - Shutdown is initiated by the parent protocol and closes or unreferences the
19
+ * parent channel.
20
+ *
21
+ * **Common tasks**
22
+ *
23
+ * - Provide {@link layer} in the worker entrypoint before running `WorkerRunner`.
24
+ * - Host CPU-bound work or isolated Node resources behind the Effect worker protocol.
25
+ * - Return transferable values when using `worker_threads`.
26
+ *
27
+ * **Gotchas**
28
+ *
29
+ * - The runner must start inside an actual worker context; otherwise the layer
30
+ * fails because neither `parentPort` nor `process.send` is available.
31
+ * - Transfer lists only apply to `worker_threads`; child-process IPC uses Node
32
+ * serialization.
33
+ * - Long-running handlers should remain interruptible and keep cleanup in
34
+ * scopes so parent-driven shutdown can release resources.
35
+ *
36
+ * **See also**
37
+ *
38
+ * - {@link layer} for the Node worker runner platform.
39
+ *
40
+ * @since 4.0.0
3
41
  */
4
42
  import * as Cause from "effect/Cause"
5
43
  import * as Deferred from "effect/Deferred"
@@ -12,8 +50,12 @@ import * as WorkerRunner from "effect/unstable/workers/WorkerRunner"
12
50
  import * as WorkerThreads from "node:worker_threads"
13
51
 
14
52
  /**
15
- * @since 1.0.0
53
+ * Provides the `WorkerRunnerPlatform` for code running inside a Node worker
54
+ * thread or child process, routing parent messages to the registered handler
55
+ * and sending responses back through the parent channel.
56
+ *
16
57
  * @category layers
58
+ * @since 4.0.0
17
59
  */
18
60
  export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succeed(WorkerRunner.WorkerRunnerPlatform)({
19
61
  start<O = unknown, I = unknown>() {
@@ -36,7 +78,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
36
78
  Effect.scopedWith(Effect.fnUntraced(function*(scope) {
37
79
  const closeLatch = Deferred.makeUnsafe<void, WorkerError>()
38
80
  const trackFiber = Fiber.runIn(scope)
39
- const services = yield* Effect.services<R>()
81
+ const services = yield* Effect.context<R>()
40
82
  const runFork = Effect.runForkWith(services)
41
83
  const onExit = (exit: Exit.Exit<any, E>) => {
42
84
  if (exit._tag === "Failure" && !Cause.hasInterruptsOnly(exit.cause)) {
@@ -70,7 +112,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
70
112
  message: "received messageerror event",
71
113
  cause
72
114
  })
73
- }).asEffect()
115
+ })
74
116
  )
75
117
  })
76
118
  WorkerThreads.parentPort.on("error", (cause) => {
@@ -81,7 +123,7 @@ export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.succe
81
123
  message: "received messageerror event",
82
124
  cause
83
125
  })
84
- }).asEffect()
126
+ })
85
127
  )
86
128
  })
87
129
  }
package/src/Undici.ts CHANGED
@@ -1,16 +1,29 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Re-export of the Undici HTTP client package used by the Node platform.
3
+ *
4
+ * This module gives Effect applications a package-local import for Undici
5
+ * primitives while working with `@effect/platform-node`. Import named Undici
6
+ * APIs from here when configuring Node HTTP client dispatchers, creating agents
7
+ * or mock agents, setting the process-global dispatcher, or sharing the same
8
+ * Undici types with integrations that use the platform HTTP client.
9
+ *
10
+ * The module does not wrap or reinterpret Undici behavior. It forwards the
11
+ * installed `undici` named exports and default export, so connection pooling,
12
+ * dispatcher lifetimes, mocking, aborts, and request options follow Undici's
13
+ * own semantics.
14
+ *
15
+ * @since 4.0.0
3
16
  */
4
17
  import Undici from "undici"
5
18
 
6
19
  /**
7
- * @since 1.0.0
8
20
  * @category undici
21
+ * @since 4.0.0
9
22
  */
10
23
  export * from "undici"
11
24
 
12
25
  /**
13
- * @since 1.0.0
14
26
  * @category undici
27
+ * @since 4.0.0
15
28
  */
16
29
  export default Undici