@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
package/src/NodeStream.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Interoperability between Node streams and Effect streams and channels.
|
|
3
|
+
*
|
|
4
|
+
* This module adapts `Readable` and `Duplex` instances at the boundary with
|
|
5
|
+
* Node APIs: wrapping sources such as files, HTTP responses, child process
|
|
6
|
+
* output, and compression transforms as Effect `Stream`s or `Channel`s, piping
|
|
7
|
+
* Effect streams through Node duplex transforms, exposing an Effect `Stream`
|
|
8
|
+
* back to Node as a `Readable`, and collecting small readable payloads into
|
|
9
|
+
* strings or binary buffers.
|
|
10
|
+
*
|
|
11
|
+
* The adapters preserve the Node stream semantics that matter for production
|
|
12
|
+
* code. Writes wait for `drain` when a writable side applies backpressure,
|
|
13
|
+
* readable streams are destroyed on scope finalization by default, and stream
|
|
14
|
+
* failures are routed through `onError` or `Cause.UnknownError`. For long-lived
|
|
15
|
+
* or externally owned streams, pass `closeOnDone` or `endOnDone` carefully, and
|
|
16
|
+
* use `maxBytes` on collection helpers to avoid buffering unbounded input.
|
|
17
|
+
*
|
|
18
|
+
* @since 4.0.0
|
|
3
19
|
*/
|
|
4
20
|
import * as Arr from "effect/Array"
|
|
5
21
|
import * as Cause from "effect/Cause"
|
|
@@ -20,8 +36,12 @@ import { Readable } from "node:stream"
|
|
|
20
36
|
import { pullIntoWritable } from "./NodeSink.ts"
|
|
21
37
|
|
|
22
38
|
/**
|
|
39
|
+
* Converts a Node readable stream into an Effect `Stream`, reading chunks with
|
|
40
|
+
* an optional chunk size, mapping stream errors with `onError`, and destroying
|
|
41
|
+
* the readable on completion unless `closeOnDone` is `false`.
|
|
42
|
+
*
|
|
23
43
|
* @category constructors
|
|
24
|
-
* @since
|
|
44
|
+
* @since 4.0.0
|
|
25
45
|
*/
|
|
26
46
|
export const fromReadable = <A = Uint8Array, E = Cause.UnknownError>(options: {
|
|
27
47
|
readonly evaluate: LazyArg<Readable | NodeJS.ReadableStream>
|
|
@@ -32,8 +52,12 @@ export const fromReadable = <A = Uint8Array, E = Cause.UnknownError>(options: {
|
|
|
32
52
|
}): Stream.Stream<A, E> => Stream.fromChannel(fromReadableChannel<A, E>(options))
|
|
33
53
|
|
|
34
54
|
/**
|
|
55
|
+
* Creates a `Channel` that pulls chunks from a Node readable stream, mapping
|
|
56
|
+
* errors with `onError` and destroying the readable on completion unless
|
|
57
|
+
* `closeOnDone` is `false`.
|
|
58
|
+
*
|
|
35
59
|
* @category constructors
|
|
36
|
-
* @since
|
|
60
|
+
* @since 4.0.0
|
|
37
61
|
*/
|
|
38
62
|
export const fromReadableChannel = <A = Uint8Array, E = Cause.UnknownError>(options: {
|
|
39
63
|
readonly evaluate: LazyArg<Readable | NodeJS.ReadableStream>
|
|
@@ -52,8 +76,12 @@ export const fromReadableChannel = <A = Uint8Array, E = Cause.UnknownError>(opti
|
|
|
52
76
|
)
|
|
53
77
|
|
|
54
78
|
/**
|
|
79
|
+
* Creates a `Channel` over a Node `Duplex`, writing upstream chunks with
|
|
80
|
+
* backpressure while emitting chunks read from the duplex and optionally ending
|
|
81
|
+
* the writable side when upstream completes.
|
|
82
|
+
*
|
|
55
83
|
* @category constructors
|
|
56
|
-
* @since
|
|
84
|
+
* @since 4.0.0
|
|
57
85
|
*/
|
|
58
86
|
export const fromDuplex = <IE, I = Uint8Array, O = Uint8Array, E = Cause.UnknownError>(
|
|
59
87
|
options: {
|
|
@@ -95,13 +123,19 @@ export const fromDuplex = <IE, I = Uint8Array, O = Uint8Array, E = Cause.Unknown
|
|
|
95
123
|
})
|
|
96
124
|
|
|
97
125
|
/**
|
|
126
|
+
* Pipes an Effect `Stream` through a Node `Duplex`, writing the stream's
|
|
127
|
+
* chunks to the duplex and emitting chunks read back from it.
|
|
128
|
+
*
|
|
98
129
|
* @category combinators
|
|
99
|
-
* @since
|
|
130
|
+
* @since 4.0.0
|
|
100
131
|
*/
|
|
101
132
|
export const pipeThroughDuplex: {
|
|
102
133
|
/**
|
|
134
|
+
* Pipes an Effect `Stream` through a Node `Duplex`, writing the stream's
|
|
135
|
+
* chunks to the duplex and emitting chunks read back from it.
|
|
136
|
+
*
|
|
103
137
|
* @category combinators
|
|
104
|
-
* @since
|
|
138
|
+
* @since 4.0.0
|
|
105
139
|
*/
|
|
106
140
|
<B = Uint8Array, E2 = Cause.UnknownError>(
|
|
107
141
|
options: {
|
|
@@ -114,8 +148,11 @@ export const pipeThroughDuplex: {
|
|
|
114
148
|
}
|
|
115
149
|
): <R, E, A>(self: Stream.Stream<A, E, R>) => Stream.Stream<B, E2 | E, R>
|
|
116
150
|
/**
|
|
151
|
+
* Pipes an Effect `Stream` through a Node `Duplex`, writing the stream's
|
|
152
|
+
* chunks to the duplex and emitting chunks read back from it.
|
|
153
|
+
*
|
|
117
154
|
* @category combinators
|
|
118
|
-
* @since
|
|
155
|
+
* @since 4.0.0
|
|
119
156
|
*/
|
|
120
157
|
<R, E, A, B = Uint8Array, E2 = Cause.UnknownError>(
|
|
121
158
|
self: Stream.Stream<A, E, R>,
|
|
@@ -145,18 +182,27 @@ export const pipeThroughDuplex: {
|
|
|
145
182
|
))
|
|
146
183
|
|
|
147
184
|
/**
|
|
185
|
+
* Pipes a stream of strings or bytes through a Node `Duplex` using default
|
|
186
|
+
* options and `Cause.UnknownError` for stream failures.
|
|
187
|
+
*
|
|
148
188
|
* @category combinators
|
|
149
|
-
* @since
|
|
189
|
+
* @since 4.0.0
|
|
150
190
|
*/
|
|
151
191
|
export const pipeThroughSimple: {
|
|
152
192
|
/**
|
|
193
|
+
* Pipes a stream of strings or bytes through a Node `Duplex` using default
|
|
194
|
+
* options and `Cause.UnknownError` for stream failures.
|
|
195
|
+
*
|
|
153
196
|
* @category combinators
|
|
154
|
-
* @since
|
|
197
|
+
* @since 4.0.0
|
|
155
198
|
*/
|
|
156
199
|
(duplex: LazyArg<Duplex>): <R, E>(self: Stream.Stream<string | Uint8Array, E, R>) => Stream.Stream<Uint8Array, E | Cause.UnknownError, R>
|
|
157
200
|
/**
|
|
201
|
+
* Pipes a stream of strings or bytes through a Node `Duplex` using default
|
|
202
|
+
* options and `Cause.UnknownError` for stream failures.
|
|
203
|
+
*
|
|
158
204
|
* @category combinators
|
|
159
|
-
* @since
|
|
205
|
+
* @since 4.0.0
|
|
160
206
|
*/
|
|
161
207
|
<R, E>(self: Stream.Stream<string | Uint8Array, E, R>, duplex: LazyArg<Duplex>): Stream.Stream<Uint8Array, Cause.UnknownError | E, R>
|
|
162
208
|
} = dual(2, <R, E>(
|
|
@@ -165,8 +211,12 @@ export const pipeThroughSimple: {
|
|
|
165
211
|
): Stream.Stream<Uint8Array, Cause.UnknownError | E, R> => pipeThroughDuplex(self, { evaluate: duplex }))
|
|
166
212
|
|
|
167
213
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
214
|
+
* Converts an Effect `Stream` into a Node `Readable`, using the caller's
|
|
215
|
+
* Effect context to run the stream and destroying the readable if the stream
|
|
216
|
+
* fails.
|
|
217
|
+
*
|
|
218
|
+
* @category converting
|
|
219
|
+
* @since 4.0.0
|
|
170
220
|
*/
|
|
171
221
|
export const toReadable = <E, R>(stream: Stream.Stream<string | Uint8Array, E, R>): Effect.Effect<Readable, never, R> =>
|
|
172
222
|
Effect.map(
|
|
@@ -175,8 +225,11 @@ export const toReadable = <E, R>(stream: Stream.Stream<string | Uint8Array, E, R
|
|
|
175
225
|
)
|
|
176
226
|
|
|
177
227
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
228
|
+
* Converts a service-free Effect `Stream` into a Node `Readable` using an
|
|
229
|
+
* empty Effect context.
|
|
230
|
+
*
|
|
231
|
+
* @category converting
|
|
232
|
+
* @since 4.0.0
|
|
180
233
|
*/
|
|
181
234
|
export const toReadableNever = <E>(stream: Stream.Stream<string | Uint8Array, E, never>): Readable =>
|
|
182
235
|
new StreamAdapter(
|
|
@@ -185,8 +238,12 @@ export const toReadableNever = <E>(stream: Stream.Stream<string | Uint8Array, E,
|
|
|
185
238
|
)
|
|
186
239
|
|
|
187
240
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
241
|
+
* Consumes a Node readable stream into a string using the selected encoding,
|
|
242
|
+
* failing through `onError` on stream errors or when `maxBytes` is exceeded
|
|
243
|
+
* and destroying the stream on interruption or failure.
|
|
244
|
+
*
|
|
245
|
+
* @category converting
|
|
246
|
+
* @since 4.0.0
|
|
190
247
|
*/
|
|
191
248
|
export const toString = <E = Cause.UnknownError>(
|
|
192
249
|
readable: LazyArg<Readable | NodeJS.ReadableStream>,
|
|
@@ -234,8 +291,12 @@ export const toString = <E = Cause.UnknownError>(
|
|
|
234
291
|
}
|
|
235
292
|
|
|
236
293
|
/**
|
|
237
|
-
*
|
|
238
|
-
*
|
|
294
|
+
* Consumes a Node readable stream into an `ArrayBuffer`, failing through
|
|
295
|
+
* `onError` on stream errors or when `maxBytes` is exceeded and destroying the
|
|
296
|
+
* stream on interruption or failure.
|
|
297
|
+
*
|
|
298
|
+
* @category converting
|
|
299
|
+
* @since 4.0.0
|
|
239
300
|
*/
|
|
240
301
|
export const toArrayBuffer = <E = Cause.UnknownError>(
|
|
241
302
|
readable: LazyArg<Readable | NodeJS.ReadableStream>,
|
|
@@ -281,8 +342,11 @@ export const toArrayBuffer = <E = Cause.UnknownError>(
|
|
|
281
342
|
}
|
|
282
343
|
|
|
283
344
|
/**
|
|
284
|
-
*
|
|
285
|
-
*
|
|
345
|
+
* Consumes a Node readable stream into a `Uint8Array`, using the same error
|
|
346
|
+
* mapping and `maxBytes` handling as `toArrayBuffer`.
|
|
347
|
+
*
|
|
348
|
+
* @category converting
|
|
349
|
+
* @since 4.0.0
|
|
286
350
|
*/
|
|
287
351
|
export const toUint8Array = <E = Cause.UnknownError>(
|
|
288
352
|
readable: LazyArg<Readable | NodeJS.ReadableStream>,
|
package/src/NodeTerminal.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shared Node.js implementation of Effect's `Terminal` service.
|
|
3
|
+
*
|
|
4
|
+
* This module is the process-backed terminal implementation used by Node
|
|
5
|
+
* platform packages. It adapts Node's `readline` APIs and the current
|
|
6
|
+
* process' `stdin` and `stdout` streams into a `Terminal`, making it suitable
|
|
7
|
+
* for CLIs, REPLs, prompts, full-screen terminal programs, and other
|
|
8
|
+
* command-line tools that need line input, keypress input, terminal
|
|
9
|
+
* dimensions, or prompt output.
|
|
10
|
+
*
|
|
11
|
+
* The implementation works with global process streams, so callers should
|
|
12
|
+
* acquire it with a scope or provide `layer` to ensure cleanup. When `stdin`
|
|
13
|
+
* is a TTY, raw mode is enabled while the scoped readline interface is active
|
|
14
|
+
* and restored on release; raw mode changes how keys are delivered and can
|
|
15
|
+
* affect other code reading stdin. In non-TTY environments such as pipes,
|
|
16
|
+
* redirected input, or CI, raw mode is unavailable, keypress behavior is
|
|
17
|
+
* limited, and stdout dimensions may be reported as zero.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
4
21
|
import type * as Cause from "effect/Cause"
|
|
5
22
|
import * as Effect from "effect/Effect"
|
|
@@ -14,8 +31,12 @@ import * as Terminal from "effect/Terminal"
|
|
|
14
31
|
import * as readline from "node:readline"
|
|
15
32
|
|
|
16
33
|
/**
|
|
17
|
-
*
|
|
34
|
+
* Creates a scoped process-backed `Terminal` using Node `readline`, enabling
|
|
35
|
+
* TTY raw mode while in scope and using the supplied predicate to decide when
|
|
36
|
+
* key input should end.
|
|
37
|
+
*
|
|
18
38
|
* @category constructors
|
|
39
|
+
* @since 4.0.0
|
|
19
40
|
*/
|
|
20
41
|
export const make: (
|
|
21
42
|
shouldQuit?: (input: Terminal.UserInput) => boolean
|
|
@@ -47,6 +68,7 @@ export const make: (
|
|
|
47
68
|
})
|
|
48
69
|
|
|
49
70
|
const columns = Effect.sync(() => stdout.columns ?? 0)
|
|
71
|
+
const rows = Effect.sync(() => stdout.rows ?? 0)
|
|
50
72
|
|
|
51
73
|
const readInput = Effect.gen(function*() {
|
|
52
74
|
yield* RcRef.get(rlRef)
|
|
@@ -94,6 +116,7 @@ export const make: (
|
|
|
94
116
|
|
|
95
117
|
return Terminal.make({
|
|
96
118
|
columns,
|
|
119
|
+
rows,
|
|
97
120
|
readInput,
|
|
98
121
|
readLine,
|
|
99
122
|
display
|
|
@@ -102,8 +125,11 @@ export const make: (
|
|
|
102
125
|
)
|
|
103
126
|
|
|
104
127
|
/**
|
|
105
|
-
*
|
|
128
|
+
* Provides the default process-backed `Terminal` service, ending key input on
|
|
129
|
+
* Ctrl+C or Ctrl+D.
|
|
130
|
+
*
|
|
106
131
|
* @category layers
|
|
132
|
+
* @since 4.0.0
|
|
107
133
|
*/
|
|
108
134
|
export const layer: Layer.Layer<Terminal.Terminal> = Layer.effect(Terminal.Terminal, make(defaultShouldQuit))
|
|
109
135
|
|