@effect/platform-node-shared 4.0.0-beta.66 → 4.0.0-beta.68
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/NodeChildProcessSpawner.d.ts +3 -3
- package/dist/NodeChildProcessSpawner.js +2 -2
- package/dist/NodeClusterSocket.d.ts +10 -4
- package/dist/NodeClusterSocket.d.ts.map +1 -1
- package/dist/NodeClusterSocket.js +29 -5
- package/dist/NodeClusterSocket.js.map +1 -1
- package/dist/NodeCrypto.d.ts +22 -0
- package/dist/NodeCrypto.d.ts.map +1 -0
- package/dist/NodeCrypto.js +50 -0
- package/dist/NodeCrypto.js.map +1 -0
- package/dist/NodeFileSystem.d.ts +5 -2
- package/dist/NodeFileSystem.d.ts.map +1 -1
- package/dist/NodeFileSystem.js +24 -3
- package/dist/NodeFileSystem.js.map +1 -1
- package/dist/NodePath.d.ts +15 -6
- package/dist/NodePath.d.ts.map +1 -1
- package/dist/NodePath.js +30 -7
- package/dist/NodePath.js.map +1 -1
- package/dist/NodeRuntime.d.ts +36 -7
- package/dist/NodeRuntime.d.ts.map +1 -1
- package/dist/NodeRuntime.js +6 -2
- package/dist/NodeRuntime.js.map +1 -1
- package/dist/NodeSink.d.ts +34 -4
- package/dist/NodeSink.d.ts.map +1 -1
- package/dist/NodeSink.js +16 -3
- package/dist/NodeSink.js.map +1 -1
- package/dist/NodeSocket.d.ts +38 -7
- package/dist/NodeSocket.d.ts.map +1 -1
- package/dist/NodeSocket.js +23 -6
- package/dist/NodeSocket.js.map +1 -1
- package/dist/NodeSocketServer.d.ts +22 -5
- package/dist/NodeSocketServer.d.ts.map +1 -1
- package/dist/NodeSocketServer.js +22 -5
- package/dist/NodeSocketServer.js.map +1 -1
- package/dist/NodeStdio.d.ts +6 -2
- package/dist/NodeStdio.d.ts.map +1 -1
- package/dist/NodeStdio.js +23 -3
- package/dist/NodeStdio.js.map +1 -1
- package/dist/NodeStream.d.ts +84 -20
- package/dist/NodeStream.d.ts.map +1 -1
- package/dist/NodeStream.js +68 -16
- package/dist/NodeStream.js.map +1 -1
- package/dist/NodeTerminal.d.ts +9 -2
- package/dist/NodeTerminal.d.ts.map +1 -1
- package/dist/NodeTerminal.js +11 -2
- package/dist/NodeTerminal.js.map +1 -1
- package/package.json +5 -5
- package/src/NodeChildProcessSpawner.ts +3 -3
- package/src/NodeClusterSocket.ts +29 -5
- package/src/NodeCrypto.ts +55 -0
- package/src/NodeFileSystem.ts +24 -3
- package/src/NodePath.ts +30 -7
- package/src/NodeRuntime.ts +36 -7
- package/src/NodeSink.ts +34 -4
- package/src/NodeSocket.ts +38 -7
- package/src/NodeSocketServer.ts +40 -6
- package/src/NodeStdio.ts +23 -3
- package/src/NodeStream.ts +84 -20
- package/src/NodeTerminal.ts +29 -3
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js implementation of the Crypto service.
|
|
3
|
+
*
|
|
4
|
+
* @since 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as EffectCrypto from "effect/Crypto"
|
|
7
|
+
import * as Effect from "effect/Effect"
|
|
8
|
+
import * as Layer from "effect/Layer"
|
|
9
|
+
import * as PlatformError from "effect/PlatformError"
|
|
10
|
+
import * as NodeCrypto from "node:crypto"
|
|
11
|
+
|
|
12
|
+
const toHashAlgorithm = (algorithm: EffectCrypto.DigestAlgorithm): string => {
|
|
13
|
+
switch (algorithm) {
|
|
14
|
+
case "SHA-1":
|
|
15
|
+
return "sha1"
|
|
16
|
+
case "SHA-256":
|
|
17
|
+
return "sha256"
|
|
18
|
+
case "SHA-384":
|
|
19
|
+
return "sha384"
|
|
20
|
+
case "SHA-512":
|
|
21
|
+
return "sha512"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const digest: EffectCrypto.Crypto["digest"] = (algorithm, data) =>
|
|
26
|
+
Effect.try({
|
|
27
|
+
try: () => Uint8Array.from(NodeCrypto.createHash(toHashAlgorithm(algorithm)).update(data).digest()),
|
|
28
|
+
catch: (cause) =>
|
|
29
|
+
PlatformError.systemError({
|
|
30
|
+
module: "Crypto",
|
|
31
|
+
method: "digest",
|
|
32
|
+
_tag: "Unknown",
|
|
33
|
+
description: "Could not compute digest",
|
|
34
|
+
cause
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The default Node.js Crypto service implementation.
|
|
40
|
+
*
|
|
41
|
+
* @category constructors
|
|
42
|
+
* @since 1.0.0
|
|
43
|
+
*/
|
|
44
|
+
export const make: EffectCrypto.Crypto = EffectCrypto.make({
|
|
45
|
+
randomBytes: NodeCrypto.randomBytes,
|
|
46
|
+
digest
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A layer that provides the Node.js Crypto service implementation.
|
|
51
|
+
*
|
|
52
|
+
* @category layers
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
*/
|
|
55
|
+
export const layer: Layer.Layer<EffectCrypto.Crypto> = Layer.succeed(EffectCrypto.Crypto, make)
|
package/src/NodeFileSystem.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shared Node-compatible implementation of Effect's `FileSystem` service.
|
|
3
|
+
*
|
|
4
|
+
* This module adapts Node's `node:fs`, `node:os`, and `node:path` APIs into a
|
|
5
|
+
* layer that can be provided to Effect programs running on Node-compatible
|
|
6
|
+
* runtimes. It is used by platform packages to provide file and directory I/O,
|
|
7
|
+
* permissions, links, metadata, temporary files and directories, and file
|
|
8
|
+
* watching through the `FileSystem` service.
|
|
9
|
+
*
|
|
10
|
+
* Paths are passed to Node filesystem APIs, so relative paths are resolved by
|
|
11
|
+
* the current working directory and platform path rules still apply. Node
|
|
12
|
+
* filesystem failures are translated into `PlatformError` values, while invalid
|
|
13
|
+
* arguments become `BadArgument` failures. Open files are scoped resources with
|
|
14
|
+
* tracked read and write positions; append mode lets the operating system choose
|
|
15
|
+
* the write offset. File watching is exposed as a stream and follows
|
|
16
|
+
* `node:fs.watch` semantics unless a `WatchBackend` is provided, so recursive
|
|
17
|
+
* support, event coalescing, and reported paths can vary by runtime and
|
|
18
|
+
* platform.
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
4
22
|
import * as Cause from "effect/Cause"
|
|
5
23
|
import * as Effect from "effect/Effect"
|
|
@@ -635,7 +653,10 @@ const makeFileSystem = Effect.map(Effect.serviceOption(FileSystem.WatchBackend),
|
|
|
635
653
|
}))
|
|
636
654
|
|
|
637
655
|
/**
|
|
638
|
-
*
|
|
639
|
-
*
|
|
656
|
+
* Provides the `FileSystem` service backed by Node filesystem APIs, including
|
|
657
|
+
* file operations, directory operations, links, metadata, and file watching.
|
|
658
|
+
*
|
|
659
|
+
* @category layers
|
|
660
|
+
* @since 4.0.0
|
|
640
661
|
*/
|
|
641
662
|
export const layer: Layer.Layer<FileSystem.FileSystem> = Layer.effect(FileSystem.FileSystem)(makeFileSystem)
|
package/src/NodePath.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shared Node-compatible implementation of Effect's `Path` service.
|
|
3
|
+
*
|
|
4
|
+
* This module adapts Node's `node:path` and `node:url` APIs into layers that
|
|
5
|
+
* can be provided to Effect programs needing path manipulation, such as
|
|
6
|
+
* resolving configuration files, building file system locations, parsing
|
|
7
|
+
* names and extensions, or converting between file paths and `file:` URLs.
|
|
8
|
+
*
|
|
9
|
+
* The default layer follows the host platform semantics exposed by
|
|
10
|
+
* `node:path`, while `layerPosix` and `layerWin32` provide stable POSIX or
|
|
11
|
+
* Windows behavior regardless of the current runtime. Path operations are
|
|
12
|
+
* syntactic and do not check whether files exist; separators, drive letters,
|
|
13
|
+
* UNC paths, and URL encoding rules can also differ by platform. Invalid
|
|
14
|
+
* file URL conversions are reported through `BadArgument`.
|
|
15
|
+
*
|
|
16
|
+
* @since 4.0.0
|
|
3
17
|
*/
|
|
4
18
|
import * as Effect from "effect/Effect"
|
|
5
19
|
import * as Layer from "effect/Layer"
|
|
@@ -31,8 +45,11 @@ const toFileUrl = (path: string): Effect.Effect<URL, BadArgument> =>
|
|
|
31
45
|
})
|
|
32
46
|
|
|
33
47
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
48
|
+
* Provides the `Path` service using Node's POSIX path implementation plus
|
|
49
|
+
* file URL conversion helpers.
|
|
50
|
+
*
|
|
51
|
+
* @category layers
|
|
52
|
+
* @since 4.0.0
|
|
36
53
|
*/
|
|
37
54
|
export const layerPosix: Layer.Layer<Path> = Layer.succeed(Path)({
|
|
38
55
|
[TypeId]: TypeId,
|
|
@@ -42,8 +59,11 @@ export const layerPosix: Layer.Layer<Path> = Layer.succeed(Path)({
|
|
|
42
59
|
})
|
|
43
60
|
|
|
44
61
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
62
|
+
* Provides the `Path` service using Node's Windows path implementation plus
|
|
63
|
+
* file URL conversion helpers.
|
|
64
|
+
*
|
|
65
|
+
* @category layers
|
|
66
|
+
* @since 4.0.0
|
|
47
67
|
*/
|
|
48
68
|
export const layerWin32: Layer.Layer<Path> = Layer.succeed(Path)({
|
|
49
69
|
[TypeId]: TypeId,
|
|
@@ -53,8 +73,11 @@ export const layerWin32: Layer.Layer<Path> = Layer.succeed(Path)({
|
|
|
53
73
|
})
|
|
54
74
|
|
|
55
75
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
76
|
+
* Provides the default `Path` service using the host platform's Node path
|
|
77
|
+
* implementation plus file URL conversion helpers.
|
|
78
|
+
*
|
|
79
|
+
* @category layers
|
|
80
|
+
* @since 4.0.0
|
|
58
81
|
*/
|
|
59
82
|
export const layer: Layer.Layer<Path> = Layer.succeed(Path)({
|
|
60
83
|
[TypeId]: TypeId,
|
package/src/NodeRuntime.ts
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shared runtime helpers for running Effect programs as Node-compatible
|
|
3
|
+
* process entry points.
|
|
4
|
+
*
|
|
5
|
+
* This module provides the common `runMain` implementation used by
|
|
6
|
+
* Node-compatible platform packages. It is intended for CLIs, scripts,
|
|
7
|
+
* workers, servers, and other process-oriented programs that should run an
|
|
8
|
+
* Effect as their main fiber while still following Node process conventions.
|
|
9
|
+
*
|
|
10
|
+
* The runner installs `SIGINT` and `SIGTERM` handlers for the lifetime of the
|
|
11
|
+
* main fiber, translating those process signals into fiber interruption so
|
|
12
|
+
* Effect finalizers and the configured teardown can run. When the fiber exits,
|
|
13
|
+
* the signal listeners are removed and teardown determines the exit code. Clean
|
|
14
|
+
* success lets the Node event loop drain naturally instead of forcing
|
|
15
|
+
* `process.exit(0)`, while signal-triggered or non-zero exits call
|
|
16
|
+
* `process.exit` after teardown, so long-running resources should be modeled
|
|
17
|
+
* in the Effect scope and finalized explicitly.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
4
21
|
import type { Effect } from "effect/Effect"
|
|
5
22
|
import * as Runtime from "effect/Runtime"
|
|
6
23
|
|
|
7
24
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
25
|
+
* Runs an Effect as the Node process main program, interrupting the fiber on
|
|
26
|
+
* `SIGINT` or `SIGTERM` and invoking the configured teardown to determine the
|
|
27
|
+
* process exit code.
|
|
28
|
+
*
|
|
29
|
+
* @category running
|
|
30
|
+
* @since 4.0.0
|
|
10
31
|
*/
|
|
11
32
|
export const runMain: {
|
|
12
33
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
34
|
+
* Runs an Effect as the Node process main program, interrupting the fiber on
|
|
35
|
+
* `SIGINT` or `SIGTERM` and invoking the configured teardown to determine the
|
|
36
|
+
* process exit code.
|
|
37
|
+
*
|
|
38
|
+
* @category running
|
|
39
|
+
* @since 4.0.0
|
|
15
40
|
*/
|
|
16
41
|
(
|
|
17
42
|
options?: {
|
|
@@ -20,8 +45,12 @@ export const runMain: {
|
|
|
20
45
|
}
|
|
21
46
|
): <E, A>(effect: Effect<A, E>) => void
|
|
22
47
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
48
|
+
* Runs an Effect as the Node process main program, interrupting the fiber on
|
|
49
|
+
* `SIGINT` or `SIGTERM` and invoking the configured teardown to determine the
|
|
50
|
+
* process exit code.
|
|
51
|
+
*
|
|
52
|
+
* @category running
|
|
53
|
+
* @since 4.0.0
|
|
25
54
|
*/
|
|
26
55
|
<E, A>(
|
|
27
56
|
effect: Effect<A, E>,
|
package/src/NodeSink.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Sink adapters for writing Effect stream chunks into Node writable streams.
|
|
3
|
+
*
|
|
4
|
+
* This module is used at the boundary where Effect `Stream`s or `Channel`s need
|
|
5
|
+
* to push data into Node's writable side: file streams, HTTP request or
|
|
6
|
+
* response bodies, process stdio, sockets, and transform inputs such as
|
|
7
|
+
* compression or encryption streams. It exposes both a `Sink` constructor for
|
|
8
|
+
* ordinary stream pipelines and lower-level `Channel` and pull helpers used by
|
|
9
|
+
* other Node stream adapters.
|
|
10
|
+
*
|
|
11
|
+
* The implementation follows Node writable semantics. Chunks are written in
|
|
12
|
+
* order; when `write` returns `false`, pulling pauses until `drain` so upstream
|
|
13
|
+
* producers do not overrun the writable buffer. Writable `error` events are
|
|
14
|
+
* mapped through `onError`, and the writable is ended and awaited via `finish`
|
|
15
|
+
* when upstream completes unless `endOnDone` is `false`. Use `endOnDone: false`
|
|
16
|
+
* for externally owned or long-lived writables, and make sure `onError` keeps
|
|
17
|
+
* Node's untyped errors meaningful for the calling Effect workflow.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
4
21
|
import type { NonEmptyReadonlyArray } from "effect/Array"
|
|
5
22
|
import * as Cause from "effect/Cause"
|
|
@@ -11,8 +28,12 @@ import * as Sink from "effect/Sink"
|
|
|
11
28
|
import type { Writable } from "node:stream"
|
|
12
29
|
|
|
13
30
|
/**
|
|
31
|
+
* Creates a `Sink` that writes chunks to a Node writable stream, respecting
|
|
32
|
+
* backpressure, mapping writable errors with `onError`, and ending the stream
|
|
33
|
+
* on completion unless `endOnDone` is `false`.
|
|
34
|
+
*
|
|
14
35
|
* @category constructors
|
|
15
|
-
* @since
|
|
36
|
+
* @since 4.0.0
|
|
16
37
|
*/
|
|
17
38
|
export const fromWritable = <E, A = Uint8Array | string>(
|
|
18
39
|
options: {
|
|
@@ -25,8 +46,12 @@ export const fromWritable = <E, A = Uint8Array | string>(
|
|
|
25
46
|
Sink.fromChannel(Channel.mapDone(fromWritableChannel<never, E, A>(options), (_) => [_]))
|
|
26
47
|
|
|
27
48
|
/**
|
|
49
|
+
* Creates a `Channel` that pulls chunks from upstream and writes them to a
|
|
50
|
+
* Node writable stream, respecting backpressure and optionally ending the
|
|
51
|
+
* writable when upstream is done.
|
|
52
|
+
*
|
|
28
53
|
* @category constructors
|
|
29
|
-
* @since
|
|
54
|
+
* @since 4.0.0
|
|
30
55
|
*/
|
|
31
56
|
export const fromWritableChannel = <IE, E, A = Uint8Array | string>(
|
|
32
57
|
options: {
|
|
@@ -42,7 +67,12 @@ export const fromWritableChannel = <IE, E, A = Uint8Array | string>(
|
|
|
42
67
|
})
|
|
43
68
|
|
|
44
69
|
/**
|
|
45
|
-
*
|
|
70
|
+
* Repeatedly pulls non-empty chunks and writes them to a Node writable stream,
|
|
71
|
+
* waiting for `drain` when needed, failing on writable errors, and ending the
|
|
72
|
+
* writable on upstream completion unless disabled.
|
|
73
|
+
*
|
|
74
|
+
* @category converting
|
|
75
|
+
* @since 4.0.0
|
|
46
76
|
*/
|
|
47
77
|
export const pullIntoWritable = <A, IE, E>(options: {
|
|
48
78
|
readonly pull: Pull.Pull<NonEmptyReadonlyArray<A>, IE, unknown>
|
package/src/NodeSocket.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shared Node socket constructors for adapting `node:net` connections and
|
|
3
|
+
* other Node `Duplex` streams to Effect's `Socket.Socket` interface.
|
|
4
|
+
*
|
|
5
|
+
* Use this module when building TCP clients, Unix domain socket clients, or
|
|
6
|
+
* higher-level protocols that already expose a Node `Duplex`. Connections are
|
|
7
|
+
* scoped, so finalizers close or destroy the underlying stream, open timeouts
|
|
8
|
+
* are reported as socket open errors, and Node read, write, and close events
|
|
9
|
+
* are translated into `SocketError` values.
|
|
10
|
+
*
|
|
11
|
+
* Node sockets have a few operational details worth keeping in mind: Unix
|
|
12
|
+
* socket paths are supplied through `NetConnectOpts.path`, writes complete only
|
|
13
|
+
* after Node accepts or flushes the chunk, and abnormal close events are
|
|
14
|
+
* surfaced as close errors while normal remote ends complete the socket run.
|
|
15
|
+
*
|
|
16
|
+
* @since 4.0.0
|
|
3
17
|
*/
|
|
4
18
|
import type { Array } from "effect"
|
|
5
19
|
import * as Channel from "effect/Channel"
|
|
@@ -18,22 +32,29 @@ import * as Net from "node:net"
|
|
|
18
32
|
import type { Duplex } from "node:stream"
|
|
19
33
|
|
|
20
34
|
/**
|
|
21
|
-
* @since 1.0.0
|
|
22
35
|
* @category re-exports
|
|
36
|
+
* @since 4.0.0
|
|
23
37
|
*/
|
|
24
38
|
export * as NodeWS from "ws"
|
|
25
39
|
|
|
26
40
|
/**
|
|
27
|
-
*
|
|
41
|
+
* Service tag for the underlying Node `net.Socket` associated with the current
|
|
42
|
+
* socket connection.
|
|
43
|
+
*
|
|
28
44
|
* @category tags
|
|
45
|
+
* @since 4.0.0
|
|
29
46
|
*/
|
|
30
47
|
export class NetSocket extends Context.Service<NetSocket, Net.Socket>()(
|
|
31
48
|
"@effect/platform-node/NodeSocket/NetSocket"
|
|
32
49
|
) {}
|
|
33
50
|
|
|
34
51
|
/**
|
|
35
|
-
*
|
|
52
|
+
* Opens a TCP connection with Node `net.createConnection` and exposes it as a
|
|
53
|
+
* `Socket.Socket`, supporting `openTimeout` and closing or destroying the
|
|
54
|
+
* socket when the enclosing scope is finalized.
|
|
55
|
+
*
|
|
36
56
|
* @category constructors
|
|
57
|
+
* @since 4.0.0
|
|
37
58
|
*/
|
|
38
59
|
export const makeNet = (
|
|
39
60
|
options: Net.NetConnectOpts & {
|
|
@@ -77,8 +98,12 @@ export const makeNet = (
|
|
|
77
98
|
)
|
|
78
99
|
|
|
79
100
|
/**
|
|
80
|
-
*
|
|
101
|
+
* Adapts a Node `Duplex` into a `Socket.Socket`, wiring data events to socket
|
|
102
|
+
* handlers, providing a scoped writer, and mapping open, read, write, and close
|
|
103
|
+
* failures to `SocketError`.
|
|
104
|
+
*
|
|
81
105
|
* @category constructors
|
|
106
|
+
* @since 4.0.0
|
|
82
107
|
*/
|
|
83
108
|
export const fromDuplex = <RO>(
|
|
84
109
|
open: Effect.Effect<Duplex, Socket.SocketError, RO>,
|
|
@@ -212,8 +237,11 @@ export const fromDuplex = <RO>(
|
|
|
212
237
|
})
|
|
213
238
|
|
|
214
239
|
/**
|
|
215
|
-
*
|
|
240
|
+
* Creates a `Channel` over a TCP socket, reading arrays of `Uint8Array`
|
|
241
|
+
* chunks and writing arrays of bytes, strings, or socket close events.
|
|
242
|
+
*
|
|
216
243
|
* @category constructors
|
|
244
|
+
* @since 4.0.0
|
|
217
245
|
*/
|
|
218
246
|
export const makeNetChannel = <IE = never>(
|
|
219
247
|
options: Net.NetConnectOpts
|
|
@@ -229,8 +257,11 @@ export const makeNetChannel = <IE = never>(
|
|
|
229
257
|
)
|
|
230
258
|
|
|
231
259
|
/**
|
|
232
|
-
*
|
|
260
|
+
* Provides a `Socket.Socket` by opening a TCP connection with the supplied
|
|
261
|
+
* Node `net` connection options.
|
|
262
|
+
*
|
|
233
263
|
* @category layers
|
|
264
|
+
* @since 4.0.0
|
|
234
265
|
*/
|
|
235
266
|
export const layerNet: (options: Net.NetConnectOpts) => Layer.Layer<
|
|
236
267
|
Socket.Socket,
|
package/src/NodeSocketServer.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shared Node socket server constructors for exposing `node:net` servers and
|
|
3
|
+
* `ws` WebSocket servers as Effect `SocketServer.SocketServer` services.
|
|
4
|
+
*
|
|
5
|
+
* Use this module when implementing TCP services, Unix domain socket services,
|
|
6
|
+
* WebSocket endpoints, or higher-level protocols such as RPC transports that
|
|
7
|
+
* need to accept incoming connections through Effect's socket APIs. TCP
|
|
8
|
+
* connections are adapted through `NodeSocket.fromDuplex`, while WebSocket
|
|
9
|
+
* handlers also receive the underlying `WebSocket` and Node `IncomingMessage`
|
|
10
|
+
* in their fiber context.
|
|
11
|
+
*
|
|
12
|
+
* The server starts listening before the constructor returns, and the exported
|
|
13
|
+
* `address` is derived from the actual Node server after binding. Prefer that
|
|
14
|
+
* address when using port `0`, wildcard hosts, or Unix socket paths. Incoming
|
|
15
|
+
* connections accepted before `run` is installed are queued and then handed to
|
|
16
|
+
* the handler, each `run` call owns the scope for its connection fibers, and
|
|
17
|
+
* the enclosing scope closes the underlying Node server.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
4
21
|
import type { Cause } from "effect/Cause"
|
|
5
22
|
import * as Context from "effect/Context"
|
|
@@ -20,8 +37,11 @@ import * as NodeSocket from "./NodeSocket.ts"
|
|
|
20
37
|
import { NodeWS } from "./NodeSocket.ts"
|
|
21
38
|
|
|
22
39
|
/**
|
|
23
|
-
*
|
|
40
|
+
* Service tag for the Node `IncomingMessage` associated with the current
|
|
41
|
+
* WebSocket server connection.
|
|
42
|
+
*
|
|
24
43
|
* @category tags
|
|
44
|
+
* @since 4.0.0
|
|
25
45
|
*/
|
|
26
46
|
export class IncomingMessage extends Context.Service<
|
|
27
47
|
IncomingMessage,
|
|
@@ -29,8 +49,12 @@ export class IncomingMessage extends Context.Service<
|
|
|
29
49
|
>()("@effect/platform-node-shared/NodeSocketServer/IncomingMessage") {}
|
|
30
50
|
|
|
31
51
|
/**
|
|
32
|
-
*
|
|
52
|
+
* Creates a scoped TCP `SocketServer` from a Node `net.Server`, starts
|
|
53
|
+
* listening with the supplied options, queues pending connections until `run`
|
|
54
|
+
* is called, and closes the server when the scope ends.
|
|
55
|
+
*
|
|
33
56
|
* @category constructors
|
|
57
|
+
* @since 4.0.0
|
|
34
58
|
*/
|
|
35
59
|
export const make = Effect.fnUntraced(function*(
|
|
36
60
|
options: Net.ServerOpts & Net.ListenOptions
|
|
@@ -144,8 +168,11 @@ export const make = Effect.fnUntraced(function*(
|
|
|
144
168
|
})
|
|
145
169
|
|
|
146
170
|
/**
|
|
147
|
-
*
|
|
171
|
+
* Provides a TCP `SocketServer` by creating and managing a scoped Node
|
|
172
|
+
* `net.Server` with the supplied server and listen options.
|
|
173
|
+
*
|
|
148
174
|
* @category layers
|
|
175
|
+
* @since 4.0.0
|
|
149
176
|
*/
|
|
150
177
|
export const layer: (
|
|
151
178
|
options: Net.ServerOpts & Net.ListenOptions
|
|
@@ -155,8 +182,12 @@ export const layer: (
|
|
|
155
182
|
> = Function.flow(make, Layer.effect(SocketServer.SocketServer))
|
|
156
183
|
|
|
157
184
|
/**
|
|
158
|
-
*
|
|
185
|
+
* Creates a scoped WebSocket `SocketServer` backed by the `ws` package,
|
|
186
|
+
* providing the WebSocket and its Node `IncomingMessage` to connection
|
|
187
|
+
* handlers and closing the server when the scope ends.
|
|
188
|
+
*
|
|
159
189
|
* @category constructors
|
|
190
|
+
* @since 4.0.0
|
|
160
191
|
*/
|
|
161
192
|
export const makeWebSocket: (
|
|
162
193
|
options: NodeWS.ServerOptions<typeof NodeWS.WebSocket, typeof Http.IncomingMessage>
|
|
@@ -255,8 +286,11 @@ export const makeWebSocket: (
|
|
|
255
286
|
})
|
|
256
287
|
|
|
257
288
|
/**
|
|
258
|
-
*
|
|
289
|
+
* Provides a WebSocket `SocketServer` backed by the `ws` package and managed
|
|
290
|
+
* with the supplied server options.
|
|
291
|
+
*
|
|
259
292
|
* @category layers
|
|
293
|
+
* @since 4.0.0
|
|
260
294
|
*/
|
|
261
295
|
export const layerWebSocket: (
|
|
262
296
|
options: NodeSocket.NodeWS.ServerOptions<typeof NodeSocket.NodeWS.WebSocket, typeof Http.IncomingMessage>
|
package/src/NodeStdio.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shared Node.js implementation of the Effect `Stdio` service.
|
|
3
|
+
*
|
|
4
|
+
* This module builds the `Stdio` layer used by Node platform packages by
|
|
5
|
+
* wiring the service to the current process: command-line arguments come from
|
|
6
|
+
* `process.argv`, input is read from `process.stdin`, and output and error
|
|
7
|
+
* output are written to `process.stdout` and `process.stderr`. It is intended
|
|
8
|
+
* for CLIs, scripts, command runners, test harnesses, and other
|
|
9
|
+
* process-oriented programs that need standard I/O through Effect services.
|
|
10
|
+
*
|
|
11
|
+
* The process stdio streams are global resources owned by Node. This layer
|
|
12
|
+
* leaves stdin open and does not end stdout or stderr by default, avoiding
|
|
13
|
+
* accidental closure of handles other code in the process may still use. Those
|
|
14
|
+
* streams may be pipes, files, or TTYs; interactive terminal behavior such as
|
|
15
|
+
* raw mode, echo, colors, and cursor movement should be coordinated with the
|
|
16
|
+
* terminal APIs instead of assuming this layer has exclusive control.
|
|
17
|
+
*
|
|
18
|
+
* @since 4.0.0
|
|
3
19
|
*/
|
|
4
20
|
import * as Effect from "effect/Effect"
|
|
5
21
|
import * as Layer from "effect/Layer"
|
|
@@ -9,8 +25,12 @@ import { fromWritable } from "./NodeSink.ts"
|
|
|
9
25
|
import { fromReadable } from "./NodeStream.ts"
|
|
10
26
|
|
|
11
27
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
28
|
+
* Provides `Stdio` from `process.argv`, `process.stdin`, `process.stdout`,
|
|
29
|
+
* and `process.stderr`; stdin remains open and stdout/stderr are not ended by
|
|
30
|
+
* default.
|
|
31
|
+
*
|
|
32
|
+
* @category layers
|
|
33
|
+
* @since 4.0.0
|
|
14
34
|
*/
|
|
15
35
|
export const layer: Layer.Layer<Stdio.Stdio> = Layer.succeed(
|
|
16
36
|
Stdio.Stdio,
|