@effect/platform-node 4.0.0-beta.66 → 4.0.0-beta.67
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 +44 -4
- package/dist/NodeClusterHttp.d.ts.map +1 -1
- package/dist/NodeClusterHttp.js +10 -3
- package/dist/NodeClusterHttp.js.map +1 -1
- package/dist/NodeClusterSocket.d.ts +46 -6
- package/dist/NodeClusterSocket.d.ts.map +1 -1
- package/dist/NodeClusterSocket.js +46 -6
- package/dist/NodeClusterSocket.js.map +1 -1
- package/dist/NodeFileSystem.d.ts +3 -1
- package/dist/NodeFileSystem.d.ts.map +1 -1
- package/dist/NodeFileSystem.js +21 -2
- package/dist/NodeFileSystem.js.map +1 -1
- package/dist/NodeHttpClient.d.ts +91 -19
- package/dist/NodeHttpClient.d.ts.map +1 -1
- package/dist/NodeHttpClient.js +91 -19
- package/dist/NodeHttpClient.js.map +1 -1
- package/dist/NodeHttpIncomingMessage.d.ts +21 -3
- package/dist/NodeHttpIncomingMessage.d.ts.map +1 -1
- package/dist/NodeHttpIncomingMessage.js +21 -3
- package/dist/NodeHttpIncomingMessage.js.map +1 -1
- package/dist/NodeHttpPlatform.d.ts +8 -2
- package/dist/NodeHttpPlatform.d.ts.map +1 -1
- package/dist/NodeHttpPlatform.js +30 -3
- package/dist/NodeHttpPlatform.js.map +1 -1
- package/dist/NodeHttpServer.d.ts +35 -8
- package/dist/NodeHttpServer.d.ts.map +1 -1
- package/dist/NodeHttpServer.js +65 -9
- 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 +31 -4
- package/dist/NodeMultipart.d.ts.map +1 -1
- package/dist/NodeMultipart.js +31 -4
- package/dist/NodeMultipart.js.map +1 -1
- package/dist/NodePath.d.ts +12 -3
- package/dist/NodePath.d.ts.map +1 -1
- package/dist/NodePath.js +27 -4
- package/dist/NodePath.js.map +1 -1
- package/dist/NodeRedis.d.ts +33 -4
- package/dist/NodeRedis.d.ts.map +1 -1
- package/dist/NodeRedis.js +33 -4
- package/dist/NodeRedis.js.map +1 -1
- package/dist/NodeRuntime.d.ts +3 -3
- package/dist/NodeRuntime.d.ts.map +1 -1
- package/dist/NodeRuntime.js +16 -2
- package/dist/NodeRuntime.js.map +1 -1
- package/dist/NodeServices.d.ts +26 -3
- package/dist/NodeServices.d.ts.map +1 -1
- package/dist/NodeServices.js +4 -1
- 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 +14 -4
- package/dist/NodeSocket.d.ts.map +1 -1
- package/dist/NodeSocket.js +32 -5
- 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 +4 -1
- package/dist/NodeStdio.d.ts.map +1 -1
- package/dist/NodeStdio.js +21 -2
- 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 +28 -3
- 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 +24 -2
- 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 +25 -25
- package/dist/index.js +25 -25
- package/package.json +6 -6
- package/src/Mime.ts +3 -3
- package/src/NodeChildProcessSpawner.ts +1 -1
- package/src/NodeClusterHttp.ts +44 -4
- package/src/NodeClusterSocket.ts +46 -6
- package/src/NodeFileSystem.ts +21 -2
- package/src/NodeHttpClient.ts +91 -19
- package/src/NodeHttpIncomingMessage.ts +21 -3
- package/src/NodeHttpPlatform.ts +30 -3
- package/src/NodeHttpServer.ts +65 -9
- package/src/NodeHttpServerRequest.ts +29 -3
- package/src/NodeMultipart.ts +31 -4
- package/src/NodePath.ts +27 -4
- package/src/NodeRedis.ts +33 -4
- package/src/NodeRuntime.ts +18 -4
- package/src/NodeServices.ts +26 -3
- package/src/NodeSink.ts +2 -2
- package/src/NodeSocket.ts +32 -5
- package/src/NodeSocketServer.ts +2 -2
- package/src/NodeStdio.ts +21 -2
- package/src/NodeStream.ts +2 -2
- package/src/NodeTerminal.ts +19 -3
- package/src/NodeWorker.ts +28 -3
- package/src/NodeWorkerRunner.ts +24 -2
- package/src/Undici.ts +3 -3
- package/src/index.ts +25 -25
|
@@ -1,18 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Accessors for the Node.js objects backing a platform Node
|
|
3
|
+
* `HttpServerRequest`.
|
|
4
|
+
*
|
|
5
|
+
* Use this module at interop boundaries when an Effect HTTP handler needs the
|
|
6
|
+
* original `http.IncomingMessage` or `http.ServerResponse` for APIs that are
|
|
7
|
+
* specific to Node, such as existing middleware, socket inspection, raw stream
|
|
8
|
+
* piping, or response customization that cannot be expressed with the portable
|
|
9
|
+
* `HttpServerRequest` and `HttpServerResponse` interfaces.
|
|
10
|
+
*
|
|
11
|
+
* The returned request is the original Node request supplied to the server. It
|
|
12
|
+
* does not reflect Effect request overrides made by middleware, such as a
|
|
13
|
+
* rewritten URL, adjusted headers, or a substituted remote address. Its body is
|
|
14
|
+
* also Node's one-shot readable stream, so avoid mixing raw stream consumption
|
|
15
|
+
* with Effect body, multipart, or stream helpers unless ownership of the body
|
|
16
|
+
* is clear. The returned response is the Node response owned by the platform
|
|
17
|
+
* server; writing to it directly bypasses the usual Effect response writer and
|
|
18
|
+
* must be coordinated carefully to avoid duplicate writes. Upgrade requests may
|
|
19
|
+
* create that response lazily when it is first requested.
|
|
20
|
+
*
|
|
21
|
+
* @since 4.0.0
|
|
3
22
|
*/
|
|
4
23
|
import type { HttpServerRequest } from "effect/unstable/http/HttpServerRequest"
|
|
5
24
|
import type * as Http from "node:http"
|
|
6
25
|
|
|
7
26
|
/**
|
|
8
|
-
*
|
|
27
|
+
* Returns the underlying Node `IncomingMessage` for a platform Node
|
|
28
|
+
* `HttpServerRequest`.
|
|
29
|
+
*
|
|
9
30
|
* @category Accessors
|
|
31
|
+
* @since 4.0.0
|
|
10
32
|
*/
|
|
11
33
|
export const toIncomingMessage = (self: HttpServerRequest): Http.IncomingMessage => self.source as any
|
|
12
34
|
|
|
13
35
|
/**
|
|
14
|
-
*
|
|
36
|
+
* Returns the underlying Node `ServerResponse` for a platform Node
|
|
37
|
+
* `HttpServerRequest`, evaluating the stored response thunk when the response
|
|
38
|
+
* was created lazily.
|
|
39
|
+
*
|
|
15
40
|
* @category Accessors
|
|
41
|
+
* @since 4.0.0
|
|
16
42
|
*/
|
|
17
43
|
export const toServerResponse = (self: HttpServerRequest): Http.ServerResponse => {
|
|
18
44
|
const res = (self as any).response
|
package/src/NodeMultipart.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Node-specific helpers for parsing HTTP `multipart/form-data` request bodies.
|
|
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.
|
|
11
|
+
*
|
|
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.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
4
21
|
import * as Effect from "effect/Effect"
|
|
5
22
|
import type * as FileSystem from "effect/FileSystem"
|
|
@@ -16,8 +33,12 @@ import * as NodeStreamP from "node:stream/promises"
|
|
|
16
33
|
import * as NodeStream from "./NodeStream.ts"
|
|
17
34
|
|
|
18
35
|
/**
|
|
19
|
-
*
|
|
36
|
+
* Parses multipart data from a Node readable request body and headers into a
|
|
37
|
+
* stream of `Multipart.Part` values, converting parser failures to
|
|
38
|
+
* `MultipartError`.
|
|
39
|
+
*
|
|
20
40
|
* @category constructors
|
|
41
|
+
* @since 4.0.0
|
|
21
42
|
*/
|
|
22
43
|
export const stream = (
|
|
23
44
|
source: Readable,
|
|
@@ -39,8 +60,11 @@ export const stream = (
|
|
|
39
60
|
)
|
|
40
61
|
|
|
41
62
|
/**
|
|
42
|
-
*
|
|
63
|
+
* Parses multipart data from a Node readable request body and persists file
|
|
64
|
+
* parts using the current `FileSystem`, `Path`, and `Scope` services.
|
|
65
|
+
*
|
|
43
66
|
* @category constructors
|
|
67
|
+
* @since 4.0.0
|
|
44
68
|
*/
|
|
45
69
|
export const persisted = (
|
|
46
70
|
source: Readable,
|
|
@@ -57,7 +81,10 @@ export const persisted = (
|
|
|
57
81
|
}))
|
|
58
82
|
|
|
59
83
|
/**
|
|
60
|
-
*
|
|
84
|
+
* Returns the underlying Node readable stream for a multipart file produced by
|
|
85
|
+
* the Node multipart parser.
|
|
86
|
+
*
|
|
87
|
+
* @since 4.0.0
|
|
61
88
|
*/
|
|
62
89
|
export const fileToReadable = (file: Multipart.File): Readable => (file as FileImpl).file
|
|
63
90
|
|
package/src/NodePath.ts
CHANGED
|
@@ -1,24 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Node.js layers for Effect's `Path` service.
|
|
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.
|
|
15
|
+
*
|
|
16
|
+
* @since 4.0.0
|
|
3
17
|
*/
|
|
4
18
|
import * as NodePath from "@effect/platform-node-shared/NodePath"
|
|
5
19
|
import type * as Layer from "effect/Layer"
|
|
6
20
|
import type { Path } from "effect/Path"
|
|
7
21
|
|
|
8
22
|
/**
|
|
9
|
-
*
|
|
23
|
+
* Provides the default Node `Path` service using the platform's `node:path`
|
|
24
|
+
* implementation.
|
|
25
|
+
*
|
|
10
26
|
* @category layer
|
|
27
|
+
* @since 4.0.0
|
|
11
28
|
*/
|
|
12
29
|
export const layer: Layer.Layer<Path> = NodePath.layer
|
|
13
30
|
|
|
14
31
|
/**
|
|
15
|
-
*
|
|
32
|
+
* Provides the `Path` service using Node's POSIX path implementation,
|
|
33
|
+
* regardless of the host platform.
|
|
34
|
+
*
|
|
16
35
|
* @category layer
|
|
36
|
+
* @since 4.0.0
|
|
17
37
|
*/
|
|
18
38
|
export const layerPosix: Layer.Layer<Path> = NodePath.layerPosix
|
|
19
39
|
|
|
20
40
|
/**
|
|
21
|
-
*
|
|
41
|
+
* Provides the `Path` service using Node's Windows path implementation,
|
|
42
|
+
* regardless of the host platform.
|
|
43
|
+
*
|
|
22
44
|
* @category layer
|
|
45
|
+
* @since 4.0.0
|
|
23
46
|
*/
|
|
24
47
|
export const layerWin32: Layer.Layer<Path> = NodePath.layerWin32
|
package/src/NodeRedis.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Node.js Redis integration backed by `ioredis`.
|
|
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.
|
|
10
|
+
*
|
|
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.
|
|
20
|
+
*
|
|
21
|
+
* @since 4.0.0
|
|
3
22
|
*/
|
|
4
23
|
import * as Config from "effect/Config"
|
|
5
24
|
import * as Context from "effect/Context"
|
|
@@ -11,8 +30,12 @@ import * as Redis from "effect/unstable/persistence/Redis"
|
|
|
11
30
|
import * as IoRedis from "ioredis"
|
|
12
31
|
|
|
13
32
|
/**
|
|
14
|
-
*
|
|
33
|
+
* Service tag for the Node Redis integration, exposing the underlying
|
|
34
|
+
* `ioredis` client and a `use` helper that maps client failures to
|
|
35
|
+
* `RedisError`.
|
|
36
|
+
*
|
|
15
37
|
* @category Service
|
|
38
|
+
* @since 4.0.0
|
|
16
39
|
*/
|
|
17
40
|
export class NodeRedis extends Context.Service<NodeRedis, {
|
|
18
41
|
readonly client: IoRedis.Redis
|
|
@@ -51,16 +74,22 @@ const make = Effect.fnUntraced(function*(
|
|
|
51
74
|
})
|
|
52
75
|
|
|
53
76
|
/**
|
|
54
|
-
*
|
|
77
|
+
* Provides `Redis` and `NodeRedis` services backed by an `ioredis` client
|
|
78
|
+
* created with the supplied options and closed when the layer scope ends.
|
|
79
|
+
*
|
|
55
80
|
* @category Layers
|
|
81
|
+
* @since 4.0.0
|
|
56
82
|
*/
|
|
57
83
|
export const layer = (
|
|
58
84
|
options?: IoRedis.RedisOptions | undefined
|
|
59
85
|
): Layer.Layer<Redis.Redis | NodeRedis> => Layer.effectContext(make(options))
|
|
60
86
|
|
|
61
87
|
/**
|
|
62
|
-
*
|
|
88
|
+
* Provides `Redis` and `NodeRedis` services from `Config`-backed ioredis
|
|
89
|
+
* options, closing the client when the layer scope ends.
|
|
90
|
+
*
|
|
63
91
|
* @category Layers
|
|
92
|
+
* @since 4.0.0
|
|
64
93
|
*/
|
|
65
94
|
export const layerConfig: (
|
|
66
95
|
options: Config.Wrap<IoRedis.RedisOptions>
|
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"
|
|
@@ -28,8 +42,8 @@ import type * as Runtime from "effect/Runtime"
|
|
|
28
42
|
* when you need structured error handling, log management, interrupt support,
|
|
29
43
|
* or advanced teardown capabilities.
|
|
30
44
|
*
|
|
31
|
-
* @since 1.0.0
|
|
32
45
|
* @category Run main
|
|
46
|
+
* @since 4.0.0
|
|
33
47
|
*/
|
|
34
48
|
export const runMain: {
|
|
35
49
|
/**
|
|
@@ -55,8 +69,8 @@ export const runMain: {
|
|
|
55
69
|
* when you need structured error handling, log management, interrupt support,
|
|
56
70
|
* or advanced teardown capabilities.
|
|
57
71
|
*
|
|
58
|
-
* @since 1.0.0
|
|
59
72
|
* @category Run main
|
|
73
|
+
* @since 4.0.0
|
|
60
74
|
*/
|
|
61
75
|
(
|
|
62
76
|
options?: {
|
|
@@ -87,8 +101,8 @@ export const runMain: {
|
|
|
87
101
|
* when you need structured error handling, log management, interrupt support,
|
|
88
102
|
* or advanced teardown capabilities.
|
|
89
103
|
*
|
|
90
|
-
* @since 1.0.0
|
|
91
104
|
* @category Run main
|
|
105
|
+
* @since 4.0.0
|
|
92
106
|
*/
|
|
93
107
|
<E, A>(
|
|
94
108
|
effect: Effect<A, E>,
|
package/src/NodeServices.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
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
|
*/
|
|
4
21
|
import type { FileSystem } from "effect/FileSystem"
|
|
5
22
|
import * as Layer from "effect/Layer"
|
|
@@ -14,14 +31,20 @@ import * as NodeStdio from "./NodeStdio.ts"
|
|
|
14
31
|
import * as NodeTerminal from "./NodeTerminal.ts"
|
|
15
32
|
|
|
16
33
|
/**
|
|
17
|
-
*
|
|
34
|
+
* The union of core services provided by the Node platform layer, including
|
|
35
|
+
* child process spawning, filesystem, path, stdio, and terminal services.
|
|
36
|
+
*
|
|
18
37
|
* @category models
|
|
38
|
+
* @since 4.0.0
|
|
19
39
|
*/
|
|
20
40
|
export type NodeServices = ChildProcessSpawner | FileSystem | Path | Stdio | Terminal
|
|
21
41
|
|
|
22
42
|
/**
|
|
23
|
-
*
|
|
43
|
+
* Provides the default Node implementations for child process spawning,
|
|
44
|
+
* filesystem, path, stdio, and terminal services.
|
|
45
|
+
*
|
|
24
46
|
* @category layer
|
|
47
|
+
* @since 4.0.0
|
|
25
48
|
*/
|
|
26
49
|
export const layer: Layer.Layer<NodeServices> = Layer.provideMerge(
|
|
27
50
|
NodeChildProcessSpawner.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,11 @@ 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
|
|
32
55
|
*/
|
|
33
56
|
export const layerWebSocketConstructorWS: Layer.Layer<
|
|
34
57
|
Socket.WebSocketConstructor
|
|
@@ -37,8 +60,12 @@ export const layerWebSocketConstructorWS: Layer.Layer<
|
|
|
37
60
|
)
|
|
38
61
|
|
|
39
62
|
/**
|
|
40
|
-
*
|
|
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
|
+
*
|
|
41
67
|
* @category layers
|
|
68
|
+
* @since 4.0.0
|
|
42
69
|
*/
|
|
43
70
|
export const layerWebSocket: (
|
|
44
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
|
-
*
|
|
25
|
+
* Provides the `Stdio` service backed by the current process arguments,
|
|
26
|
+
* stdin, stdout, and stderr streams.
|
|
27
|
+
*
|
|
10
28
|
* @category layer
|
|
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>()({
|
|
@@ -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>() {
|
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
|