@effect/platform-node 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.
Files changed (81) hide show
  1. package/dist/Mime.d.ts +6 -0
  2. package/dist/Mime.d.ts.map +1 -1
  3. package/dist/Mime.js +6 -0
  4. package/dist/Mime.js.map +1 -1
  5. package/dist/NodeCrypto.d.ts +1 -1
  6. package/dist/NodeCrypto.d.ts.map +1 -1
  7. package/dist/NodeCrypto.js +10 -2
  8. package/dist/NodeCrypto.js.map +1 -1
  9. package/dist/NodeFileSystem.d.ts.map +1 -1
  10. package/dist/NodeFileSystem.js +22 -14
  11. package/dist/NodeFileSystem.js.map +1 -1
  12. package/dist/NodeHttpClient.d.ts +44 -26
  13. package/dist/NodeHttpClient.d.ts.map +1 -1
  14. package/dist/NodeHttpClient.js +42 -24
  15. package/dist/NodeHttpClient.js.map +1 -1
  16. package/dist/NodeHttpIncomingMessage.d.ts +35 -14
  17. package/dist/NodeHttpIncomingMessage.d.ts.map +1 -1
  18. package/dist/NodeHttpIncomingMessage.js +34 -13
  19. package/dist/NodeHttpIncomingMessage.js.map +1 -1
  20. package/dist/NodeHttpServerRequest.d.ts +2 -2
  21. package/dist/NodeHttpServerRequest.js +2 -2
  22. package/dist/NodeMultipart.d.ts +31 -16
  23. package/dist/NodeMultipart.d.ts.map +1 -1
  24. package/dist/NodeMultipart.js +29 -14
  25. package/dist/NodeMultipart.js.map +1 -1
  26. package/dist/NodePath.d.ts.map +1 -1
  27. package/dist/NodePath.js +24 -11
  28. package/dist/NodePath.js.map +1 -1
  29. package/dist/NodeRedis.d.ts +34 -16
  30. package/dist/NodeRedis.d.ts.map +1 -1
  31. package/dist/NodeRedis.js +33 -15
  32. package/dist/NodeRedis.js.map +1 -1
  33. package/dist/NodeRuntime.d.ts +3 -3
  34. package/dist/NodeRuntime.d.ts.map +1 -1
  35. package/dist/NodeRuntime.js +26 -12
  36. package/dist/NodeRuntime.js.map +1 -1
  37. package/dist/NodeServices.d.ts +31 -16
  38. package/dist/NodeServices.d.ts.map +1 -1
  39. package/dist/NodeServices.js.map +1 -1
  40. package/dist/NodeSocket.d.ts.map +1 -1
  41. package/dist/NodeSocket.js +31 -16
  42. package/dist/NodeSocket.js.map +1 -1
  43. package/dist/NodeStdio.d.ts.map +1 -1
  44. package/dist/NodeStdio.js +21 -13
  45. package/dist/NodeStdio.js.map +1 -1
  46. package/dist/NodeTerminal.d.ts.map +1 -1
  47. package/dist/NodeTerminal.js +18 -8
  48. package/dist/NodeTerminal.js.map +1 -1
  49. package/dist/NodeWorker.d.ts.map +1 -1
  50. package/dist/NodeWorker.js +28 -14
  51. package/dist/NodeWorker.js.map +1 -1
  52. package/dist/NodeWorkerRunner.d.ts.map +1 -1
  53. package/dist/NodeWorkerRunner.js +35 -15
  54. package/dist/NodeWorkerRunner.js.map +1 -1
  55. package/dist/Undici.d.ts +13 -0
  56. package/dist/Undici.d.ts.map +1 -1
  57. package/dist/Undici.js +13 -0
  58. package/dist/Undici.js.map +1 -1
  59. package/dist/index.d.ts +0 -350
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +0 -350
  62. package/dist/index.js.map +1 -1
  63. package/package.json +4 -4
  64. package/src/Mime.ts +7 -0
  65. package/src/NodeCrypto.ts +10 -2
  66. package/src/NodeFileSystem.ts +22 -14
  67. package/src/NodeHttpClient.ts +42 -24
  68. package/src/NodeHttpIncomingMessage.ts +34 -13
  69. package/src/NodeHttpServerRequest.ts +2 -2
  70. package/src/NodeMultipart.ts +29 -14
  71. package/src/NodePath.ts +24 -11
  72. package/src/NodeRedis.ts +33 -15
  73. package/src/NodeRuntime.ts +28 -14
  74. package/src/NodeServices.ts +31 -16
  75. package/src/NodeSocket.ts +29 -14
  76. package/src/NodeStdio.ts +21 -13
  77. package/src/NodeTerminal.ts +18 -8
  78. package/src/NodeWorker.ts +28 -14
  79. package/src/NodeWorkerRunner.ts +35 -15
  80. package/src/Undici.ts +13 -0
  81. package/src/index.ts +0 -350
@@ -1,15 +1,28 @@
1
1
  /**
2
- * Utilities for adapting Node `http.IncomingMessage` values to the Effect HTTP
3
- * incoming message interface used by the platform Node server and client
4
- * implementations.
2
+ * Adapter base for exposing Node `http.IncomingMessage` values as Effect HTTP
3
+ * incoming messages.
5
4
  *
6
- * This module is useful when code needs to keep access to Node's request or
7
- * response object while also exposing Effect's typed headers, remote address,
8
- * body decoders, and stream interface. The body helpers consume Node's readable
9
- * stream, cache decoded text and array-buffer results, and honor the
10
- * `HttpIncomingMessage.MaxBodySize` fiber ref. Prefer a single body access
11
- * strategy per message: raw `stream` access is not cached, and Node request
12
- * bodies cannot be replayed once the underlying stream has been consumed.
5
+ * Server requests and Node client responses both arrive as Node readable
6
+ * streams with raw header objects, socket metadata, and one-shot body
7
+ * consumption. This module's `NodeHttpIncomingMessage` class keeps the original
8
+ * Node message available while presenting Effect's `HttpIncomingMessage` shape:
9
+ * typed headers, remote address lookup, stream access, and text, JSON,
10
+ * URL-encoded, and array-buffer body readers.
11
+ *
12
+ * **Mental model**
13
+ *
14
+ * The Node message remains the source of truth. The adapter translates headers
15
+ * and remote address on demand, delegates raw streaming to `NodeStream`, and
16
+ * lets subclasses choose how unknown Node errors are mapped into their HTTP
17
+ * error type.
18
+ *
19
+ * **Gotchas**
20
+ *
21
+ * Node request and response bodies are one-shot streams. The `text` and
22
+ * `arrayBuffer` readers are cached and share decoded values with each other,
23
+ * but direct `stream` access is not cached and can consume the underlying Node
24
+ * stream before a decoder reads it. Body readers honor
25
+ * `HttpIncomingMessage.MaxBodySize`.
13
26
  *
14
27
  * @since 4.0.0
15
28
  */
@@ -25,9 +38,17 @@ import type * as Http from "node:http"
25
38
  import * as NodeStream from "./NodeStream.ts"
26
39
 
27
40
  /**
28
- * Base adapter from Node `IncomingMessage` to Effect HTTP incoming messages,
29
- * exposing headers, remote address, stream access, and cached text, JSON, URL
30
- * parameter, and array-buffer body decoders with caller-provided error mapping.
41
+ * Adapts a Node `IncomingMessage` to Effect HTTP incoming messages.
42
+ *
43
+ * **When to use**
44
+ *
45
+ * Use to implement Node HTTP request or response adapters that expose the
46
+ * Effect HTTP incoming-message interface.
47
+ *
48
+ * **Details**
49
+ *
50
+ * The adapter exposes headers, remote address, stream access, and cached body
51
+ * decoders. Subclasses provide the error mapping for unknown Node errors.
31
52
  *
32
53
  * @category constructors
33
54
  * @since 4.0.0
@@ -27,7 +27,7 @@ import type * as Http from "node:http"
27
27
  * Returns the underlying Node `IncomingMessage` for a platform Node
28
28
  * `HttpServerRequest`.
29
29
  *
30
- * @category Accessors
30
+ * @category accessors
31
31
  * @since 4.0.0
32
32
  */
33
33
  export const toIncomingMessage = (self: HttpServerRequest): Http.IncomingMessage => self.source as any
@@ -37,7 +37,7 @@ export const toIncomingMessage = (self: HttpServerRequest): Http.IncomingMessage
37
37
  * `HttpServerRequest`, evaluating the stored response thunk when the response
38
38
  * was created lazily.
39
39
  *
40
- * @category Accessors
40
+ * @category accessors
41
41
  * @since 4.0.0
42
42
  */
43
43
  export const toServerResponse = (self: HttpServerRequest): Http.ServerResponse => {
@@ -1,20 +1,35 @@
1
1
  /**
2
- * Node-specific helpers for parsing HTTP `multipart/form-data` request bodies.
2
+ * Node.js multipart parsing for HTTP `multipart/form-data` request bodies.
3
3
  *
4
- * This module adapts a Node `Readable` request body plus its incoming headers
5
- * into the shared `Multipart` model. Use `stream` when an HTTP server route
6
- * wants to handle form fields and uploaded files incrementally, for example API
7
- * endpoints that validate text fields while piping file parts to storage. Use
8
- * `persisted` when the whole form should be collected into a record and uploaded
9
- * files should be written into scoped temporary files through the current
10
- * `FileSystem` and `Path` services.
4
+ * `NodeMultipart` adapts a Node `Readable` plus incoming HTTP headers into
5
+ * Effect's shared multipart model. It can expose form parts as a stream for
6
+ * incremental processing, or collect a complete persisted form by writing file
7
+ * uploads to scoped temporary files through the current `FileSystem` and `Path`
8
+ * services.
11
9
  *
12
- * Node request bodies are one-shot streams, so consume either `stream` or
13
- * `persisted`, and make sure file parts are drained, piped, or otherwise
14
- * deliberately handled. `contentEffect` loads a file into memory and should be
15
- * reserved for small uploads. Persisted paths live only for the surrounding
16
- * `Scope`, and filenames supplied by clients should be treated as metadata, not
17
- * trusted filesystem paths.
10
+ * **Mental model**
11
+ *
12
+ * Multipart request bodies are one-shot byte streams. {@link stream} parses the
13
+ * body as it arrives: fields are decoded to strings and file parts keep their
14
+ * underlying Node readable stream. {@link persisted} consumes the same kind of
15
+ * body, builds a `Multipart.Persisted` record, and ties temporary upload files
16
+ * to the surrounding `Scope`.
17
+ *
18
+ * **Common tasks**
19
+ *
20
+ * - Use {@link stream} when a route validates fields while piping file uploads
21
+ * to storage.
22
+ * - Use {@link persisted} when a route needs a complete form value with scoped
23
+ * temporary files.
24
+ * - Use {@link fileToReadable} when a downstream Node library expects a
25
+ * `Readable`.
26
+ *
27
+ * **Gotchas**
28
+ *
29
+ * Consume a request body with only one parser. File parts must be drained,
30
+ * piped, or persisted so the request can finish reading. `contentEffect` loads
31
+ * an uploaded file into memory, so reserve it for small files. Client-supplied
32
+ * filenames are metadata, not trusted filesystem paths.
18
33
  *
19
34
  * @since 4.0.0
20
35
  */
package/src/NodePath.ts CHANGED
@@ -1,17 +1,30 @@
1
1
  /**
2
2
  * Node.js layers for Effect's `Path` service.
3
3
  *
4
- * Use this module when an Effect program running on Node needs path operations
5
- * from the `Path` service, such as joining and normalizing filesystem
6
- * locations, resolving configuration or static asset paths, working with CLI
7
- * path arguments, or converting between file paths and `file:` URLs.
8
- *
9
- * `layer` follows the host platform's `node:path` semantics. Use `layerPosix`
10
- * or `layerWin32` when code needs stable POSIX or Windows behavior regardless
11
- * of the operating system. These layers provide only path manipulation; they do
12
- * not read the filesystem or validate that paths exist. `NodeServices.layer`
13
- * already includes the default Node path layer, so provide this module directly
14
- * when you want the narrower service or one of the platform-specific variants.
4
+ * This module adapts Node's path and file URL behavior to the
5
+ * platform-independent `Path` service. Provide one of its layers when a Node
6
+ * program needs to build, normalize, parse, resolve, or convert paths without
7
+ * depending directly on `node:path`.
8
+ *
9
+ * **Mental model**
10
+ *
11
+ * `Path` is a syntactic service: it manipulates strings and `file:` URLs. It
12
+ * does not read the filesystem, check permissions, or validate that paths
13
+ * exist. The selected layer decides which separator, drive-letter, UNC, and URL
14
+ * conversion rules are used.
15
+ *
16
+ * **Common tasks**
17
+ *
18
+ * Use `layer` for host-platform Node semantics, `layerPosix` for stable POSIX
19
+ * behavior, and `layerWin32` for stable Windows behavior. `NodeServices.layer`
20
+ * already includes `layer`, so import this module directly when a program wants
21
+ * only path support or a platform-specific variant.
22
+ *
23
+ * **Gotchas**
24
+ *
25
+ * Results that are correct on one platform may not be portable to another.
26
+ * `fromFileUrl` and `toFileUrl` use Node's `node:url` conversion rules and
27
+ * report invalid conversions as `BadArgument` failures.
15
28
  *
16
29
  * @since 4.0.0
17
30
  */
package/src/NodeRedis.ts CHANGED
@@ -1,22 +1,40 @@
1
1
  /**
2
2
  * Node.js Redis integration backed by `ioredis`.
3
3
  *
4
- * This module provides scoped layers that create an `ioredis` client and expose
5
- * both the low-level `Redis` service used by Effect persistence modules and the
6
- * `NodeRedis` service for direct access to the underlying client. It is useful
7
- * for Node applications that want Redis-backed persistence, persisted queues,
8
- * distributed rate limiting, or custom Redis commands alongside the Effect
9
- * services that build on Redis.
4
+ * This module creates a scoped `ioredis` client and exposes it in two forms:
5
+ * the generic `Redis` service consumed by Effect persistence modules, and the
6
+ * {@link NodeRedis} service for code that needs direct access to the underlying
7
+ * client.
10
8
  *
11
- * The client is acquired when the layer is built and closed with `quit` when
12
- * the layer scope ends, so install the layer at the lifetime you want for the
13
- * connection and pass `ioredis` options, or `layerConfig`, for connection,
14
- * TLS, database, retry, and reconnect settings. Persistence and rate limiter
15
- * stores build their own keys and Lua scripts on top of this service; choose
16
- * stable prefixes and store ids to avoid collisions, account for persisted
17
- * values that may fail to decode after schema changes, and avoid unbounded
18
- * high-cardinality rate-limit keys unless you have a cleanup or bounding
19
- * strategy.
9
+ * **Mental model**
10
+ *
11
+ * - {@link layer} creates one `ioredis` client from explicit client options
12
+ * - {@link layerConfig} reads the same options from `Config`
13
+ * - Building the layer opens the client, and closing the layer scope calls
14
+ * `quit`
15
+ * - The generic `Redis` service sends command strings through `client.call`
16
+ * - {@link NodeRedis} exposes the raw client plus `use`, which maps promise
17
+ * failures into `RedisError`
18
+ *
19
+ * **Common tasks**
20
+ *
21
+ * - Provide Redis-backed persistence, persisted queues, or distributed rate
22
+ * limiting in Node.js
23
+ * - Configure connection, TLS, database, retry, and reconnect behavior with
24
+ * standard `ioredis` options
25
+ * - Run custom Redis commands through {@link NodeRedis} when the generic
26
+ * `Redis` service does not cover the command shape you need
27
+ *
28
+ * **Gotchas**
29
+ *
30
+ * - Install the layer at the lifetime you want for the connection; a short
31
+ * scope opens and closes a Redis client for that scope
32
+ * - Persistence and rate limiter stores create their own keys and Lua scripts
33
+ * on top of this service, so choose stable prefixes and store ids
34
+ * - Persisted values may fail to decode after schema changes; plan migrations
35
+ * or cleanup for long-lived Redis data
36
+ * - Avoid unbounded high-cardinality rate-limit keys unless another process or
37
+ * key policy bounds their lifetime
20
38
  *
21
39
  * @since 4.0.0
22
40
  */
@@ -1,17 +1,31 @@
1
1
  /**
2
- * Node.js entry-point helpers for running Effect programs.
2
+ * Node.js process runner for starting an Effect program at the application
3
+ * edge.
3
4
  *
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.
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.
8
9
  *
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.
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.
15
29
  *
16
30
  * @since 4.0.0
17
31
  */
@@ -24,7 +38,7 @@ import type * as Runtime from "effect/Runtime"
24
38
  *
25
39
  * **When to use**
26
40
  *
27
- * Use this function to run an Effect as your application's main program, especially
41
+ * Use to run an Effect as your application's main program, especially
28
42
  * when you need structured error handling, log management, interrupt support,
29
43
  * or advanced teardown capabilities.
30
44
  *
@@ -49,7 +63,7 @@ export const runMain: {
49
63
  *
50
64
  * **When to use**
51
65
  *
52
- * Use this function to run an Effect as your application's main program, especially
66
+ * Use to run an Effect as your application's main program, especially
53
67
  * when you need structured error handling, log management, interrupt support,
54
68
  * or advanced teardown capabilities.
55
69
  *
@@ -79,7 +93,7 @@ export const runMain: {
79
93
  *
80
94
  * **When to use**
81
95
  *
82
- * Use this function to run an Effect as your application's main program, especially
96
+ * Use to run an Effect as your application's main program, especially
83
97
  * when you need structured error handling, log management, interrupt support,
84
98
  * or advanced teardown capabilities.
85
99
  *
@@ -1,20 +1,35 @@
1
1
  /**
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.
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.
18
33
  *
19
34
  * @since 4.0.0
20
35
  */
package/src/NodeSocket.ts CHANGED
@@ -1,20 +1,35 @@
1
1
  /**
2
- * Node platform socket entry point for Effect sockets backed by Node streams
3
- * and WebSocket implementations.
2
+ * Node.js socket constructors and layers for Effect sockets.
4
3
  *
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.
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`.
10
8
  *
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.
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.
18
33
  *
19
34
  * @since 4.0.0
20
35
  */
package/src/NodeStdio.ts CHANGED
@@ -1,19 +1,27 @@
1
1
  /**
2
- * Node.js implementation of the Effect `Stdio` service.
2
+ * Node.js `Stdio` layer for the current process.
3
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.
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.
10
9
  *
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.
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.
17
25
  *
18
26
  * @since 4.0.0
19
27
  */
@@ -1,13 +1,23 @@
1
1
  /**
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
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
10
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.
11
21
  *
12
22
  * @since 4.0.0
13
23
  */
package/src/NodeWorker.ts CHANGED
@@ -1,21 +1,35 @@
1
1
  /**
2
2
  * Parent-side Node.js support for Effect workers.
3
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.
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.
10
8
  *
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`.
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`.
19
33
  *
20
34
  * @since 4.0.0
21
35
  */
@@ -1,21 +1,41 @@
1
1
  /**
2
- * Runtime support for Effect workers that are executed by Node.js.
2
+ * Node.js runtime support for workers that serve Effect worker requests.
3
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.
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
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.
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.
19
39
  *
20
40
  * @since 4.0.0
21
41
  */
package/src/Undici.ts CHANGED
@@ -1,4 +1,17 @@
1
1
  /**
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
+ *
2
15
  * @since 4.0.0
3
16
  */
4
17
  import Undici from "undici"