@effect/platform-node 0.22.1 → 0.23.1
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/CommandExecutor/dist/effect-platform-node-CommandExecutor.cjs.dev.js +3 -2
- package/CommandExecutor/dist/effect-platform-node-CommandExecutor.cjs.prod.js +3 -2
- package/CommandExecutor/dist/effect-platform-node-CommandExecutor.esm.js +3 -2
- package/Http/FormData/dist/effect-platform-node-Http-FormData.cjs.dev.js +3 -3
- package/Http/FormData/dist/effect-platform-node-Http-FormData.cjs.prod.js +3 -3
- package/Http/FormData/dist/effect-platform-node-Http-FormData.esm.js +3 -3
- package/Http/NodeClient/dist/effect-platform-node-Http-NodeClient.cjs.dev.js +5 -4
- package/Http/NodeClient/dist/effect-platform-node-Http-NodeClient.cjs.prod.js +5 -4
- package/Http/NodeClient/dist/effect-platform-node-Http-NodeClient.esm.js +5 -4
- package/Http/Server/dist/effect-platform-node-Http-Server.cjs.dev.js +6 -5
- package/Http/Server/dist/effect-platform-node-Http-Server.cjs.prod.js +6 -5
- package/Http/Server/dist/effect-platform-node-Http-Server.esm.js +6 -5
- package/HttpClient/dist/effect-platform-node-HttpClient.cjs.dev.js +5 -4
- package/HttpClient/dist/effect-platform-node-HttpClient.cjs.prod.js +5 -4
- package/HttpClient/dist/effect-platform-node-HttpClient.esm.js +5 -4
- package/HttpServer/dist/effect-platform-node-HttpServer.cjs.dev.js +7 -6
- package/HttpServer/dist/effect-platform-node-HttpServer.cjs.prod.js +7 -6
- package/HttpServer/dist/effect-platform-node-HttpServer.esm.js +7 -6
- package/NodeContext/dist/effect-platform-node-NodeContext.cjs.dev.js +3 -2
- package/NodeContext/dist/effect-platform-node-NodeContext.cjs.prod.js +3 -2
- package/NodeContext/dist/effect-platform-node-NodeContext.esm.js +3 -2
- package/Sink/dist/effect-platform-node-Sink.cjs.dev.js +3 -2
- package/Sink/dist/effect-platform-node-Sink.cjs.prod.js +3 -2
- package/Sink/dist/effect-platform-node-Sink.esm.js +3 -2
- package/Stream/dist/effect-platform-node-Stream.cjs.dev.js +1 -1
- package/Stream/dist/effect-platform-node-Stream.cjs.prod.js +1 -1
- package/Stream/dist/effect-platform-node-Stream.esm.js +1 -1
- package/dist/{FormData-b905ea51.cjs.dev.js → FormData-1b197f9f.cjs.dev.js} +1 -1
- package/dist/{FormData-aba95773.esm.js → FormData-9c8077af.esm.js} +1 -1
- package/dist/{FormData-33600671.cjs.prod.js → FormData-b4b59ecb.cjs.prod.js} +1 -1
- package/dist/{NodeClient-f1038dc6.esm.js → NodeClient-25aa9b30.esm.js} +2 -2
- package/dist/{NodeClient-174ebaf2.cjs.prod.js → NodeClient-4a5a22a9.cjs.prod.js} +2 -2
- package/dist/{NodeClient-86d70074.cjs.dev.js → NodeClient-9eb46e81.cjs.dev.js} +2 -2
- package/dist/{Server-d00836e3.cjs.dev.js → Server-6257bf68.cjs.dev.js} +3 -3
- package/dist/{Server-015ebdb2.cjs.prod.js → Server-94a686e6.cjs.prod.js} +3 -3
- package/dist/{Server-07db176b.esm.js → Server-a565a430.esm.js} +3 -3
- package/dist/declarations/src/Sink.d.ts +2 -1
- package/dist/declarations/src/Sink.d.ts.map +1 -1
- package/dist/declarations/src/Stream.d.ts +9 -10
- package/dist/declarations/src/Stream.d.ts.map +1 -1
- package/dist/{formData-59e5f494.cjs.prod.js → formData-2d4168a3.cjs.prod.js} +1 -2
- package/dist/{formData-00b767b9.cjs.dev.js → formData-5d873a90.cjs.dev.js} +1 -2
- package/dist/{formData-3a02d09f.esm.js → formData-b50a3c9f.esm.js} +1 -2
- package/dist/{incomingMessage-890fef7a.cjs.prod.js → incomingMessage-4526b216.cjs.prod.js} +2 -4
- package/dist/{incomingMessage-6970f455.esm.js → incomingMessage-a56317f6.esm.js} +2 -4
- package/dist/{incomingMessage-587c8285.cjs.dev.js → incomingMessage-ac1817d4.cjs.dev.js} +2 -4
- package/dist/{sink-5526bd6c.cjs.prod.js → sink-00a7f5a4.cjs.dev.js} +16 -18
- package/dist/{sink-a2069d86.cjs.dev.js → sink-8f5eb47c.cjs.prod.js} +16 -18
- package/dist/sink-f4bcb905.esm.js +25 -0
- package/dist/{stream-c01737c4.cjs.prod.js → stream-1667e8bf.cjs.prod.js} +29 -30
- package/dist/{stream-c0c7bc20.cjs.dev.js → stream-8bbecb96.cjs.dev.js} +29 -30
- package/dist/{stream-36ca9d0a.esm.js → stream-faaffb40.esm.js} +29 -30
- package/package.json +5 -3
- package/src/Sink.ts +2 -2
- package/src/Stream.ts +7 -10
- package/src/internal/http/formData.ts +1 -2
- package/src/internal/http/incomingMessage.ts +2 -4
- package/src/internal/http/nodeClient.ts +1 -1
- package/src/internal/http/server.ts +3 -1
- package/src/internal/sink.ts +39 -23
- package/src/internal/stream.ts +57 -57
- package/dist/sink-f7795af1.esm.js +0 -28
package/src/internal/stream.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SizeInput } from "@effect/platform/FileSystem"
|
|
2
|
+
import type { Cause } from "effect"
|
|
2
3
|
import * as Channel from "effect/Channel"
|
|
3
4
|
import type * as AsyncInput from "effect/ChannelSingleProducerAsyncInput"
|
|
4
5
|
import * as Chunk from "effect/Chunk"
|
|
@@ -15,7 +16,7 @@ import type { FromReadableOptions, FromWritableOptions } from "../Stream"
|
|
|
15
16
|
|
|
16
17
|
/** @internal */
|
|
17
18
|
export const fromReadable = <E, A = Uint8Array>(
|
|
18
|
-
evaluate: LazyArg<Readable>,
|
|
19
|
+
evaluate: LazyArg<Readable | NodeJS.ReadableStream>,
|
|
19
20
|
onError: (error: unknown) => E,
|
|
20
21
|
{ chunkSize }: FromReadableOptions = {}
|
|
21
22
|
): Stream.Stream<never, E, A> =>
|
|
@@ -25,17 +26,17 @@ export const fromReadable = <E, A = Uint8Array>(
|
|
|
25
26
|
|
|
26
27
|
/** @internal */
|
|
27
28
|
export const toString = <E>(
|
|
29
|
+
readable: LazyArg<Readable | NodeJS.ReadableStream>,
|
|
28
30
|
options: {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
maxBytes?: SizeInput
|
|
31
|
+
readonly onFailure: (error: unknown) => E
|
|
32
|
+
readonly encoding?: BufferEncoding
|
|
33
|
+
readonly maxBytes?: SizeInput
|
|
33
34
|
}
|
|
34
35
|
): Effect.Effect<never, E, string> => {
|
|
35
36
|
const maxBytesNumber = options.maxBytes ? Number(options.maxBytes) : undefined
|
|
36
37
|
return Effect.acquireUseRelease(
|
|
37
38
|
Effect.sync(() => {
|
|
38
|
-
const stream =
|
|
39
|
+
const stream = readable()
|
|
39
40
|
stream.setEncoding(options.encoding ?? "utf8")
|
|
40
41
|
return stream
|
|
41
42
|
}),
|
|
@@ -60,7 +61,7 @@ export const toString = <E>(
|
|
|
60
61
|
(stream) =>
|
|
61
62
|
Effect.sync(() => {
|
|
62
63
|
stream.removeAllListeners()
|
|
63
|
-
if (!stream.closed) {
|
|
64
|
+
if ("closed" in stream && !stream.closed) {
|
|
64
65
|
stream.destroy()
|
|
65
66
|
}
|
|
66
67
|
})
|
|
@@ -69,15 +70,15 @@ export const toString = <E>(
|
|
|
69
70
|
|
|
70
71
|
/** @internal */
|
|
71
72
|
export const toUint8Array = <E>(
|
|
73
|
+
readable: LazyArg<Readable | NodeJS.ReadableStream>,
|
|
72
74
|
options: {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
maxBytes?: SizeInput
|
|
75
|
+
readonly onFailure: (error: unknown) => E
|
|
76
|
+
readonly maxBytes?: SizeInput
|
|
76
77
|
}
|
|
77
78
|
): Effect.Effect<never, E, Uint8Array> => {
|
|
78
79
|
const maxBytesNumber = options.maxBytes ? Number(options.maxBytes) : undefined
|
|
79
80
|
return Effect.acquireUseRelease(
|
|
80
|
-
Effect.sync(
|
|
81
|
+
Effect.sync(readable),
|
|
81
82
|
(stream) =>
|
|
82
83
|
Effect.async((resume) => {
|
|
83
84
|
let buffer = Buffer.alloc(0)
|
|
@@ -99,7 +100,7 @@ export const toUint8Array = <E>(
|
|
|
99
100
|
(stream) =>
|
|
100
101
|
Effect.sync(() => {
|
|
101
102
|
stream.removeAllListeners()
|
|
102
|
-
if (!stream.closed) {
|
|
103
|
+
if ("closed" in stream && !stream.closed) {
|
|
103
104
|
stream.destroy()
|
|
104
105
|
}
|
|
105
106
|
})
|
|
@@ -107,7 +108,7 @@ export const toUint8Array = <E>(
|
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
/** @internal */
|
|
110
|
-
export const fromDuplex = <IE, E, I = Uint8Array, O = Uint8Array>(
|
|
111
|
+
export const fromDuplex = <IE, E, I = Uint8Array | string, O = Uint8Array>(
|
|
111
112
|
evaluate: LazyArg<Duplex>,
|
|
112
113
|
onError: (error: unknown) => E,
|
|
113
114
|
options: FromReadableOptions & FromWritableOptions = {}
|
|
@@ -123,7 +124,11 @@ export const fromDuplex = <IE, E, I = Uint8Array, O = Uint8Array>(
|
|
|
123
124
|
([duplex, queue]) =>
|
|
124
125
|
Channel.embedInput(
|
|
125
126
|
readableTake(duplex, queue, options.chunkSize ? Number(options.chunkSize) : undefined),
|
|
126
|
-
writeInput(
|
|
127
|
+
writeInput(
|
|
128
|
+
duplex,
|
|
129
|
+
(cause) => Queue.offer(queue, Either.left(Exit.failCause(cause))),
|
|
130
|
+
options
|
|
131
|
+
)
|
|
127
132
|
),
|
|
128
133
|
([duplex, queue]) =>
|
|
129
134
|
Effect.zipRight(
|
|
@@ -185,7 +190,7 @@ export const pipeThroughSimple = dual<
|
|
|
185
190
|
)
|
|
186
191
|
|
|
187
192
|
const readChannel = <E, A = Uint8Array>(
|
|
188
|
-
evaluate: LazyArg<Readable>,
|
|
193
|
+
evaluate: LazyArg<Readable | NodeJS.ReadableStream>,
|
|
189
194
|
onError: (error: unknown) => E,
|
|
190
195
|
chunkSize: number | undefined
|
|
191
196
|
): Channel.Channel<never, unknown, unknown, unknown, E, Chunk.Chunk<A>, void> =>
|
|
@@ -202,7 +207,7 @@ const readChannel = <E, A = Uint8Array>(
|
|
|
202
207
|
Effect.zipRight(
|
|
203
208
|
Effect.sync(() => {
|
|
204
209
|
readable.removeAllListeners()
|
|
205
|
-
if (!readable.closed) {
|
|
210
|
+
if ("closed" in readable && !readable.closed) {
|
|
206
211
|
readable.destroy()
|
|
207
212
|
}
|
|
208
213
|
}),
|
|
@@ -210,65 +215,60 @@ const readChannel = <E, A = Uint8Array>(
|
|
|
210
215
|
)
|
|
211
216
|
)
|
|
212
217
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
{ encoding, endOnDone = true }: FromWritableOptions
|
|
218
|
+
/** @internal */
|
|
219
|
+
export const writeInput = <IE, A>(
|
|
220
|
+
writable: Writable | NodeJS.WritableStream,
|
|
221
|
+
onFailure: (cause: Cause.Cause<IE>) => Effect.Effect<never, never, void>,
|
|
222
|
+
{ encoding, endOnDone = true }: FromWritableOptions,
|
|
223
|
+
onDone = Effect.unit
|
|
218
224
|
): AsyncInput.AsyncInputProducer<IE, Chunk.Chunk<A>, unknown> => {
|
|
219
|
-
const write = writeEffect(writable,
|
|
220
|
-
const close = endOnDone
|
|
221
|
-
Effect.async<never, never, void>((resume) => {
|
|
222
|
-
if (writable.closed) {
|
|
225
|
+
const write = writeEffect(writable, encoding)
|
|
226
|
+
const close = endOnDone
|
|
227
|
+
? Effect.async<never, never, void>((resume) => {
|
|
228
|
+
if ("closed" in writable && writable.closed) {
|
|
223
229
|
resume(Effect.unit)
|
|
224
230
|
} else {
|
|
225
|
-
writable.
|
|
231
|
+
writable.once("finish", () => resume(Effect.unit))
|
|
232
|
+
writable.end()
|
|
226
233
|
}
|
|
227
|
-
})
|
|
228
|
-
Effect.unit
|
|
234
|
+
})
|
|
235
|
+
: Effect.unit
|
|
229
236
|
return {
|
|
230
237
|
awaitRead: () => Effect.unit,
|
|
231
|
-
emit:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
(cause) => Queue.offer(queue, Either.left(Exit.failCause(cause)))
|
|
235
|
-
),
|
|
236
|
-
error: (cause) =>
|
|
237
|
-
Effect.zipRight(
|
|
238
|
-
close,
|
|
239
|
-
Queue.offer(queue, Either.left(Exit.failCause(cause)))
|
|
240
|
-
),
|
|
241
|
-
done: (_) => close
|
|
238
|
+
emit: write,
|
|
239
|
+
error: (cause) => Effect.zipRight(close, onFailure(cause)),
|
|
240
|
+
done: (_) => Effect.zipRight(close, onDone)
|
|
242
241
|
}
|
|
243
242
|
}
|
|
244
243
|
|
|
245
244
|
/** @internal */
|
|
246
|
-
export const writeEffect =
|
|
247
|
-
|
|
248
|
-
|
|
245
|
+
export const writeEffect = <A>(
|
|
246
|
+
writable: Writable | NodeJS.WritableStream,
|
|
247
|
+
encoding?: BufferEncoding
|
|
248
|
+
) =>
|
|
249
|
+
(chunk: Chunk.Chunk<A>) =>
|
|
250
|
+
chunk.length === 0 ?
|
|
251
|
+
Effect.unit :
|
|
252
|
+
Effect.async<never, never, void>((resume) => {
|
|
249
253
|
const iterator = chunk[Symbol.iterator]()
|
|
254
|
+
let next = iterator.next()
|
|
250
255
|
function loop() {
|
|
251
|
-
const item =
|
|
252
|
-
|
|
256
|
+
const item = next
|
|
257
|
+
next = iterator.next()
|
|
258
|
+
const success = writable.write(item.value, encoding as any)
|
|
259
|
+
if (next.done) {
|
|
253
260
|
resume(Effect.unit)
|
|
254
|
-
} else if (
|
|
255
|
-
writable.write(item.value, encoding, onDone)
|
|
256
|
-
} else {
|
|
257
|
-
writable.write(item.value, onDone)
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
function onDone(err: unknown) {
|
|
261
|
-
if (err) {
|
|
262
|
-
resume(Effect.fail(onError(err)))
|
|
263
|
-
} else {
|
|
261
|
+
} else if (success) {
|
|
264
262
|
loop()
|
|
263
|
+
} else {
|
|
264
|
+
writable.once("drain", loop)
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
loop()
|
|
268
268
|
})
|
|
269
269
|
|
|
270
270
|
const readableOffer = <E>(
|
|
271
|
-
readable: Readable,
|
|
271
|
+
readable: Readable | NodeJS.ReadableStream,
|
|
272
272
|
queue: Queue.Queue<Either.Either<Exit.Exit<E, void>, void>>,
|
|
273
273
|
onError: (error: unknown) => E
|
|
274
274
|
) =>
|
|
@@ -291,7 +291,7 @@ const readableOffer = <E>(
|
|
|
291
291
|
})
|
|
292
292
|
|
|
293
293
|
const readableTake = <E, A>(
|
|
294
|
-
readable: Readable,
|
|
294
|
+
readable: Readable | NodeJS.ReadableStream,
|
|
295
295
|
queue: Queue.Queue<Either.Either<Exit.Exit<E, void>, void>>,
|
|
296
296
|
chunkSize: number | undefined
|
|
297
297
|
) => {
|
|
@@ -307,7 +307,7 @@ const readableTake = <E, A>(
|
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
const readChunkChannel = <A>(
|
|
310
|
-
readable: Readable,
|
|
310
|
+
readable: Readable | NodeJS.ReadableStream,
|
|
311
311
|
chunkSize: number | undefined
|
|
312
312
|
) =>
|
|
313
313
|
Channel.flatMap(
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as Channel from 'effect/Channel';
|
|
2
|
-
import * as Effect from 'effect/Effect';
|
|
3
|
-
import * as Sink from 'effect/Sink';
|
|
4
|
-
import { w as writeEffect } from './stream-36ca9d0a.esm.js';
|
|
5
|
-
|
|
6
|
-
/** @internal */
|
|
7
|
-
const fromWritable = (evaluate, onError, options = {}) => Sink.suspend(() => Sink.fromChannel(writeChannel(evaluate(), onError, options)));
|
|
8
|
-
const writeChannel = (writable, onError, {
|
|
9
|
-
encoding,
|
|
10
|
-
endOnDone = true
|
|
11
|
-
} = {}) => {
|
|
12
|
-
const write = writeEffect(writable, onError, encoding);
|
|
13
|
-
const close = endOnDone ? Effect.async(resume => {
|
|
14
|
-
if (writable.closed) {
|
|
15
|
-
resume(Effect.unit);
|
|
16
|
-
} else {
|
|
17
|
-
writable.end(() => resume(Effect.unit));
|
|
18
|
-
}
|
|
19
|
-
}) : Channel.unit;
|
|
20
|
-
const loop = Channel.readWithCause({
|
|
21
|
-
onInput: chunk => Channel.flatMap(Channel.fromEffect(write(chunk)), () => loop),
|
|
22
|
-
onFailure: cause => Channel.zipRight(close, Channel.failCause(cause)),
|
|
23
|
-
onDone: _done => close
|
|
24
|
-
});
|
|
25
|
-
return loop;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { fromWritable as f };
|