@effect/platform-node 0.22.0 → 0.23.0
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 +8 -2
- package/CommandExecutor/dist/effect-platform-node-CommandExecutor.cjs.prod.js +8 -2
- package/CommandExecutor/dist/effect-platform-node-CommandExecutor.esm.js +8 -2
- package/Http/FormData/dist/effect-platform-node-Http-FormData.cjs.dev.js +8 -3
- package/Http/FormData/dist/effect-platform-node-Http-FormData.cjs.prod.js +8 -3
- package/Http/FormData/dist/effect-platform-node-Http-FormData.esm.js +8 -3
- package/Http/NodeClient/dist/effect-platform-node-Http-NodeClient.cjs.dev.js +11 -4
- package/Http/NodeClient/dist/effect-platform-node-Http-NodeClient.cjs.prod.js +11 -4
- package/Http/NodeClient/dist/effect-platform-node-Http-NodeClient.esm.js +11 -4
- package/Http/Server/dist/effect-platform-node-Http-Server.cjs.dev.js +13 -8
- package/Http/Server/dist/effect-platform-node-Http-Server.cjs.prod.js +13 -8
- package/Http/Server/dist/effect-platform-node-Http-Server.esm.js +13 -8
- package/HttpClient/dist/effect-platform-node-HttpClient.cjs.dev.js +11 -4
- package/HttpClient/dist/effect-platform-node-HttpClient.cjs.prod.js +11 -4
- package/HttpClient/dist/effect-platform-node-HttpClient.esm.js +11 -4
- package/HttpServer/dist/effect-platform-node-HttpServer.cjs.dev.js +12 -7
- package/HttpServer/dist/effect-platform-node-HttpServer.cjs.prod.js +12 -7
- package/HttpServer/dist/effect-platform-node-HttpServer.esm.js +12 -7
- package/NodeContext/dist/effect-platform-node-NodeContext.cjs.dev.js +8 -2
- package/NodeContext/dist/effect-platform-node-NodeContext.cjs.prod.js +8 -2
- package/NodeContext/dist/effect-platform-node-NodeContext.esm.js +8 -2
- package/Sink/dist/effect-platform-node-Sink.cjs.dev.js +11 -8
- package/Sink/dist/effect-platform-node-Sink.cjs.prod.js +11 -8
- package/Sink/dist/effect-platform-node-Sink.esm.js +11 -8
- package/Stream/dist/effect-platform-node-Stream.cjs.dev.js +33 -2
- package/Stream/dist/effect-platform-node-Stream.cjs.mjs +3 -0
- package/Stream/dist/effect-platform-node-Stream.cjs.prod.js +33 -2
- package/Stream/dist/effect-platform-node-Stream.esm.js +31 -3
- package/dist/{FormData-15af6672.cjs.dev.js → FormData-1b197f9f.cjs.dev.js} +1 -1
- package/dist/{FormData-5ea8a8b6.esm.js → FormData-9c8077af.esm.js} +1 -1
- package/dist/{FormData-d91e8016.cjs.prod.js → FormData-b4b59ecb.cjs.prod.js} +1 -1
- package/dist/{NodeClient-cd56cae8.esm.js → NodeClient-1b5f7152.esm.js} +2 -2
- package/dist/{NodeClient-ebd71893.cjs.dev.js → NodeClient-433f41ed.cjs.dev.js} +2 -2
- package/dist/{NodeClient-3432a6a8.cjs.prod.js → NodeClient-8d8ff956.cjs.prod.js} +2 -2
- package/dist/{Server-5dbcee7b.cjs.prod.js → Server-2dd836bc.cjs.prod.js} +3 -3
- package/dist/{Server-5f055bfd.cjs.dev.js → Server-66eb964d.cjs.dev.js} +3 -3
- package/dist/{Server-c08c825c.esm.js → Server-913d7080.esm.js} +3 -3
- package/dist/declarations/src/Sink.d.ts +2 -9
- package/dist/declarations/src/Sink.d.ts.map +1 -1
- package/dist/declarations/src/Stream.d.ts +42 -11
- package/dist/declarations/src/Stream.d.ts.map +1 -1
- package/dist/{formData-ecf6742b.cjs.prod.js → formData-2d4168a3.cjs.prod.js} +1 -2
- package/dist/{formData-632b1146.cjs.dev.js → formData-5d873a90.cjs.dev.js} +1 -2
- package/dist/{formData-dd75bbe1.esm.js → formData-b50a3c9f.esm.js} +1 -2
- package/dist/{incomingMessage-f56be93e.cjs.prod.js → incomingMessage-4526b216.cjs.prod.js} +2 -4
- package/dist/{incomingMessage-11c9bea6.esm.js → incomingMessage-a56317f6.esm.js} +2 -4
- package/dist/{incomingMessage-86bcf94d.cjs.dev.js → incomingMessage-ac1817d4.cjs.dev.js} +2 -4
- package/dist/sink-3a150604.cjs.dev.js +48 -0
- package/dist/sink-570c8582.cjs.prod.js +48 -0
- package/dist/sink-5dfcc09e.esm.js +23 -0
- package/dist/stream-1667e8bf.cjs.prod.js +209 -0
- package/dist/stream-8bbecb96.cjs.dev.js +209 -0
- package/dist/stream-faaffb40.esm.js +175 -0
- package/package.json +5 -3
- package/src/Sink.ts +3 -11
- package/src/Stream.ts +59 -13
- 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 +42 -47
- package/src/internal/stream.ts +242 -61
- package/dist/sink-bd7ef408.esm.js +0 -34
- package/dist/sink-da49e187.cjs.prod.js +0 -57
- package/dist/sink-daf9e0e5.cjs.dev.js +0 -57
- package/dist/stream-1456ece0.cjs.dev.js +0 -120
- package/dist/stream-860139d3.esm.js +0 -94
- package/dist/stream-ef8b6a66.cjs.prod.js +0 -120
|
@@ -51,8 +51,7 @@ class IncomingMessageImpl {
|
|
|
51
51
|
if (this.textEffect) {
|
|
52
52
|
return this.textEffect;
|
|
53
53
|
}
|
|
54
|
-
this.textEffect = Effect__namespace.runSync(Effect__namespace.cached(Effect__namespace.flatMap(FiberRef__namespace.get(IncomingMessage__namespace.maxBodySize), maxBodySize => Stream_dist_effectPlatformNodeStream.toString({
|
|
55
|
-
readable: () => this.source,
|
|
54
|
+
this.textEffect = Effect__namespace.runSync(Effect__namespace.cached(Effect__namespace.flatMap(FiberRef__namespace.get(IncomingMessage__namespace.maxBodySize), maxBodySize => Stream_dist_effectPlatformNodeStream.toString(() => this.source, {
|
|
56
55
|
onFailure: this.onError,
|
|
57
56
|
maxBytes: Option__namespace.getOrUndefined(maxBodySize)
|
|
58
57
|
}))));
|
|
@@ -74,8 +73,7 @@ class IncomingMessageImpl {
|
|
|
74
73
|
return Stream_dist_effectPlatformNodeStream.fromReadable(() => this.source, this.onError);
|
|
75
74
|
}
|
|
76
75
|
get arrayBuffer() {
|
|
77
|
-
return Effect__namespace.flatMap(FiberRef__namespace.get(IncomingMessage__namespace.maxBodySize), maxBodySize => Stream_dist_effectPlatformNodeStream.toUint8Array({
|
|
78
|
-
readable: () => this.source,
|
|
76
|
+
return Effect__namespace.flatMap(FiberRef__namespace.get(IncomingMessage__namespace.maxBodySize), maxBodySize => Stream_dist_effectPlatformNodeStream.toUint8Array(() => this.source, {
|
|
79
77
|
onFailure: this.onError,
|
|
80
78
|
maxBytes: Option__namespace.getOrUndefined(maxBodySize)
|
|
81
79
|
}));
|
|
@@ -24,8 +24,7 @@ class IncomingMessageImpl {
|
|
|
24
24
|
if (this.textEffect) {
|
|
25
25
|
return this.textEffect;
|
|
26
26
|
}
|
|
27
|
-
this.textEffect = Effect.runSync(Effect.cached(Effect.flatMap(FiberRef.get(IncomingMessage.maxBodySize), maxBodySize => toString({
|
|
28
|
-
readable: () => this.source,
|
|
27
|
+
this.textEffect = Effect.runSync(Effect.cached(Effect.flatMap(FiberRef.get(IncomingMessage.maxBodySize), maxBodySize => toString(() => this.source, {
|
|
29
28
|
onFailure: this.onError,
|
|
30
29
|
maxBytes: Option.getOrUndefined(maxBodySize)
|
|
31
30
|
}))));
|
|
@@ -47,8 +46,7 @@ class IncomingMessageImpl {
|
|
|
47
46
|
return fromReadable(() => this.source, this.onError);
|
|
48
47
|
}
|
|
49
48
|
get arrayBuffer() {
|
|
50
|
-
return Effect.flatMap(FiberRef.get(IncomingMessage.maxBodySize), maxBodySize => toUint8Array({
|
|
51
|
-
readable: () => this.source,
|
|
49
|
+
return Effect.flatMap(FiberRef.get(IncomingMessage.maxBodySize), maxBodySize => toUint8Array(() => this.source, {
|
|
52
50
|
onFailure: this.onError,
|
|
53
51
|
maxBytes: Option.getOrUndefined(maxBodySize)
|
|
54
52
|
}));
|
|
@@ -51,8 +51,7 @@ class IncomingMessageImpl {
|
|
|
51
51
|
if (this.textEffect) {
|
|
52
52
|
return this.textEffect;
|
|
53
53
|
}
|
|
54
|
-
this.textEffect = Effect__namespace.runSync(Effect__namespace.cached(Effect__namespace.flatMap(FiberRef__namespace.get(IncomingMessage__namespace.maxBodySize), maxBodySize => Stream_dist_effectPlatformNodeStream.toString({
|
|
55
|
-
readable: () => this.source,
|
|
54
|
+
this.textEffect = Effect__namespace.runSync(Effect__namespace.cached(Effect__namespace.flatMap(FiberRef__namespace.get(IncomingMessage__namespace.maxBodySize), maxBodySize => Stream_dist_effectPlatformNodeStream.toString(() => this.source, {
|
|
56
55
|
onFailure: this.onError,
|
|
57
56
|
maxBytes: Option__namespace.getOrUndefined(maxBodySize)
|
|
58
57
|
}))));
|
|
@@ -74,8 +73,7 @@ class IncomingMessageImpl {
|
|
|
74
73
|
return Stream_dist_effectPlatformNodeStream.fromReadable(() => this.source, this.onError);
|
|
75
74
|
}
|
|
76
75
|
get arrayBuffer() {
|
|
77
|
-
return Effect__namespace.flatMap(FiberRef__namespace.get(IncomingMessage__namespace.maxBodySize), maxBodySize => Stream_dist_effectPlatformNodeStream.toUint8Array({
|
|
78
|
-
readable: () => this.source,
|
|
76
|
+
return Effect__namespace.flatMap(FiberRef__namespace.get(IncomingMessage__namespace.maxBodySize), maxBodySize => Stream_dist_effectPlatformNodeStream.toUint8Array(() => this.source, {
|
|
79
77
|
onFailure: this.onError,
|
|
80
78
|
maxBytes: Option__namespace.getOrUndefined(maxBodySize)
|
|
81
79
|
}));
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Channel = require('effect/Channel');
|
|
4
|
+
var Deferred = require('effect/Deferred');
|
|
5
|
+
var Effect = require('effect/Effect');
|
|
6
|
+
var Sink = require('effect/Sink');
|
|
7
|
+
var stream = require('./stream-8bbecb96.cjs.dev.js');
|
|
8
|
+
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule) return e;
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n["default"] = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var Channel__namespace = /*#__PURE__*/_interopNamespace(Channel);
|
|
28
|
+
var Deferred__namespace = /*#__PURE__*/_interopNamespace(Deferred);
|
|
29
|
+
var Effect__namespace = /*#__PURE__*/_interopNamespace(Effect);
|
|
30
|
+
var Sink__namespace = /*#__PURE__*/_interopNamespace(Sink);
|
|
31
|
+
|
|
32
|
+
/** @internal */
|
|
33
|
+
const fromWritable = (evaluate, onError, options = {}) => Sink__namespace.suspend(() => Sink__namespace.fromChannel(writeChannel(evaluate(), onError, options)));
|
|
34
|
+
const writeChannel = (writable, onError, options = {}) => Channel__namespace.flatMap(Deferred__namespace.make(), deferred => {
|
|
35
|
+
const input = stream.writeInput(writable, _ => Deferred__namespace.failCause(deferred, _), options, Deferred__namespace.complete(deferred, Effect__namespace.unit));
|
|
36
|
+
return Channel__namespace.embedInput(writableOutput(writable, deferred, onError), input);
|
|
37
|
+
});
|
|
38
|
+
const writableOutput = (writable, deferred, onError) => Effect__namespace.raceFirst(Effect__namespace.async(resume => {
|
|
39
|
+
function handleError(err) {
|
|
40
|
+
resume(Effect__namespace.fail(onError(err)));
|
|
41
|
+
}
|
|
42
|
+
writable.on("error", handleError);
|
|
43
|
+
return Effect__namespace.sync(() => {
|
|
44
|
+
writable.off("error", handleError);
|
|
45
|
+
});
|
|
46
|
+
}), Deferred__namespace.await(deferred));
|
|
47
|
+
|
|
48
|
+
exports.fromWritable = fromWritable;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Channel = require('effect/Channel');
|
|
4
|
+
var Deferred = require('effect/Deferred');
|
|
5
|
+
var Effect = require('effect/Effect');
|
|
6
|
+
var Sink = require('effect/Sink');
|
|
7
|
+
var stream = require('./stream-1667e8bf.cjs.prod.js');
|
|
8
|
+
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule) return e;
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n["default"] = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var Channel__namespace = /*#__PURE__*/_interopNamespace(Channel);
|
|
28
|
+
var Deferred__namespace = /*#__PURE__*/_interopNamespace(Deferred);
|
|
29
|
+
var Effect__namespace = /*#__PURE__*/_interopNamespace(Effect);
|
|
30
|
+
var Sink__namespace = /*#__PURE__*/_interopNamespace(Sink);
|
|
31
|
+
|
|
32
|
+
/** @internal */
|
|
33
|
+
const fromWritable = (evaluate, onError, options = {}) => Sink__namespace.suspend(() => Sink__namespace.fromChannel(writeChannel(evaluate(), onError, options)));
|
|
34
|
+
const writeChannel = (writable, onError, options = {}) => Channel__namespace.flatMap(Deferred__namespace.make(), deferred => {
|
|
35
|
+
const input = stream.writeInput(writable, _ => Deferred__namespace.failCause(deferred, _), options, Deferred__namespace.complete(deferred, Effect__namespace.unit));
|
|
36
|
+
return Channel__namespace.embedInput(writableOutput(writable, deferred, onError), input);
|
|
37
|
+
});
|
|
38
|
+
const writableOutput = (writable, deferred, onError) => Effect__namespace.raceFirst(Effect__namespace.async(resume => {
|
|
39
|
+
function handleError(err) {
|
|
40
|
+
resume(Effect__namespace.fail(onError(err)));
|
|
41
|
+
}
|
|
42
|
+
writable.on("error", handleError);
|
|
43
|
+
return Effect__namespace.sync(() => {
|
|
44
|
+
writable.off("error", handleError);
|
|
45
|
+
});
|
|
46
|
+
}), Deferred__namespace.await(deferred));
|
|
47
|
+
|
|
48
|
+
exports.fromWritable = fromWritable;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as Channel from 'effect/Channel';
|
|
2
|
+
import * as Deferred from 'effect/Deferred';
|
|
3
|
+
import * as Effect from 'effect/Effect';
|
|
4
|
+
import * as Sink from 'effect/Sink';
|
|
5
|
+
import { w as writeInput } from './stream-faaffb40.esm.js';
|
|
6
|
+
|
|
7
|
+
/** @internal */
|
|
8
|
+
const fromWritable = (evaluate, onError, options = {}) => Sink.suspend(() => Sink.fromChannel(writeChannel(evaluate(), onError, options)));
|
|
9
|
+
const writeChannel = (writable, onError, options = {}) => Channel.flatMap(Deferred.make(), deferred => {
|
|
10
|
+
const input = writeInput(writable, _ => Deferred.failCause(deferred, _), options, Deferred.complete(deferred, Effect.unit));
|
|
11
|
+
return Channel.embedInput(writableOutput(writable, deferred, onError), input);
|
|
12
|
+
});
|
|
13
|
+
const writableOutput = (writable, deferred, onError) => Effect.raceFirst(Effect.async(resume => {
|
|
14
|
+
function handleError(err) {
|
|
15
|
+
resume(Effect.fail(onError(err)));
|
|
16
|
+
}
|
|
17
|
+
writable.on("error", handleError);
|
|
18
|
+
return Effect.sync(() => {
|
|
19
|
+
writable.off("error", handleError);
|
|
20
|
+
});
|
|
21
|
+
}), Deferred.await(deferred));
|
|
22
|
+
|
|
23
|
+
export { fromWritable as f };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Channel = require('effect/Channel');
|
|
4
|
+
var Chunk = require('effect/Chunk');
|
|
5
|
+
var Effect = require('effect/Effect');
|
|
6
|
+
var Either = require('effect/Either');
|
|
7
|
+
var Exit = require('effect/Exit');
|
|
8
|
+
var Function = require('effect/Function');
|
|
9
|
+
var Queue = require('effect/Queue');
|
|
10
|
+
var Stream = require('effect/Stream');
|
|
11
|
+
var Error$1 = require('@effect/platform/Error');
|
|
12
|
+
|
|
13
|
+
function _interopNamespace(e) {
|
|
14
|
+
if (e && e.__esModule) return e;
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
Object.keys(e).forEach(function (k) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return e[k]; }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
n["default"] = e;
|
|
28
|
+
return Object.freeze(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var Channel__namespace = /*#__PURE__*/_interopNamespace(Channel);
|
|
32
|
+
var Chunk__namespace = /*#__PURE__*/_interopNamespace(Chunk);
|
|
33
|
+
var Effect__namespace = /*#__PURE__*/_interopNamespace(Effect);
|
|
34
|
+
var Either__namespace = /*#__PURE__*/_interopNamespace(Either);
|
|
35
|
+
var Exit__namespace = /*#__PURE__*/_interopNamespace(Exit);
|
|
36
|
+
var Queue__namespace = /*#__PURE__*/_interopNamespace(Queue);
|
|
37
|
+
var Stream__namespace = /*#__PURE__*/_interopNamespace(Stream);
|
|
38
|
+
|
|
39
|
+
/** @internal */
|
|
40
|
+
const fromReadable = (evaluate, onError, {
|
|
41
|
+
chunkSize
|
|
42
|
+
} = {}) => Stream__namespace.fromChannel(readChannel(evaluate, onError, chunkSize ? Number(chunkSize) : undefined));
|
|
43
|
+
|
|
44
|
+
/** @internal */
|
|
45
|
+
const toString = (readable, options) => {
|
|
46
|
+
const maxBytesNumber = options.maxBytes ? Number(options.maxBytes) : undefined;
|
|
47
|
+
return Effect__namespace.acquireUseRelease(Effect__namespace.sync(() => {
|
|
48
|
+
const stream = readable();
|
|
49
|
+
stream.setEncoding(options.encoding ?? "utf8");
|
|
50
|
+
return stream;
|
|
51
|
+
}), stream => Effect__namespace.async(resume => {
|
|
52
|
+
let string = "";
|
|
53
|
+
let bytes = 0;
|
|
54
|
+
stream.once("error", err => {
|
|
55
|
+
resume(Effect__namespace.fail(options.onFailure(err)));
|
|
56
|
+
});
|
|
57
|
+
stream.once("end", () => {
|
|
58
|
+
resume(Effect__namespace.succeed(string));
|
|
59
|
+
});
|
|
60
|
+
stream.on("data", chunk => {
|
|
61
|
+
string += chunk;
|
|
62
|
+
bytes += Buffer.byteLength(chunk);
|
|
63
|
+
if (maxBytesNumber && bytes > maxBytesNumber) {
|
|
64
|
+
resume(Effect__namespace.fail(options.onFailure(new Error("maxBytes exceeded"))));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}), stream => Effect__namespace.sync(() => {
|
|
68
|
+
stream.removeAllListeners();
|
|
69
|
+
if ("closed" in stream && !stream.closed) {
|
|
70
|
+
stream.destroy();
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** @internal */
|
|
76
|
+
const toUint8Array = (readable, options) => {
|
|
77
|
+
const maxBytesNumber = options.maxBytes ? Number(options.maxBytes) : undefined;
|
|
78
|
+
return Effect__namespace.acquireUseRelease(Effect__namespace.sync(readable), stream => Effect__namespace.async(resume => {
|
|
79
|
+
let buffer = Buffer.alloc(0);
|
|
80
|
+
let bytes = 0;
|
|
81
|
+
stream.once("error", err => {
|
|
82
|
+
resume(Effect__namespace.fail(options.onFailure(err)));
|
|
83
|
+
});
|
|
84
|
+
stream.once("end", () => {
|
|
85
|
+
resume(Effect__namespace.succeed(buffer));
|
|
86
|
+
});
|
|
87
|
+
stream.on("data", chunk => {
|
|
88
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
89
|
+
bytes += chunk.length;
|
|
90
|
+
if (maxBytesNumber && bytes > maxBytesNumber) {
|
|
91
|
+
resume(Effect__namespace.fail(options.onFailure(new Error("maxBytes exceeded"))));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}), stream => Effect__namespace.sync(() => {
|
|
95
|
+
stream.removeAllListeners();
|
|
96
|
+
if ("closed" in stream && !stream.closed) {
|
|
97
|
+
stream.destroy();
|
|
98
|
+
}
|
|
99
|
+
}));
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** @internal */
|
|
103
|
+
const fromDuplex = (evaluate, onError, options = {}) => Channel__namespace.acquireUseRelease(Effect__namespace.tap(Effect__namespace.zip(Effect__namespace.sync(evaluate), Queue__namespace.unbounded()), ([duplex, queue]) => readableOffer(duplex, queue, onError)), ([duplex, queue]) => Channel__namespace.embedInput(readableTake(duplex, queue, options.chunkSize ? Number(options.chunkSize) : undefined), writeInput(duplex, cause => Queue__namespace.offer(queue, Either__namespace.left(Exit__namespace.failCause(cause))), options)), ([duplex, queue]) => Effect__namespace.zipRight(Effect__namespace.sync(() => {
|
|
104
|
+
duplex.removeAllListeners();
|
|
105
|
+
if (!duplex.closed) {
|
|
106
|
+
duplex.destroy();
|
|
107
|
+
}
|
|
108
|
+
}), Queue__namespace.shutdown(queue)));
|
|
109
|
+
|
|
110
|
+
/** @internal */
|
|
111
|
+
const pipeThroughDuplex = /*#__PURE__*/Function.dual(args => Stream__namespace.StreamTypeId in args[0], (self, duplex, onError, options) => Stream__namespace.pipeThroughChannelOrFail(self, fromDuplex(duplex, onError, options)));
|
|
112
|
+
|
|
113
|
+
/** @internal */
|
|
114
|
+
const pipeThroughSimple = /*#__PURE__*/Function.dual(2, (self, duplex) => Stream__namespace.pipeThroughChannelOrFail(self, fromDuplex(duplex, error => Error$1.SystemError({
|
|
115
|
+
module: "Stream",
|
|
116
|
+
method: "pipeThroughSimple",
|
|
117
|
+
pathOrDescriptor: "",
|
|
118
|
+
reason: "Unknown",
|
|
119
|
+
message: String(error)
|
|
120
|
+
}))));
|
|
121
|
+
const readChannel = (evaluate, onError, chunkSize) => Channel__namespace.acquireUseRelease(Effect__namespace.tap(Effect__namespace.zip(Effect__namespace.sync(evaluate), Queue__namespace.unbounded()), ([readable, queue]) => readableOffer(readable, queue, onError)), ([readable, queue]) => readableTake(readable, queue, chunkSize), ([readable, queue]) => Effect__namespace.zipRight(Effect__namespace.sync(() => {
|
|
122
|
+
readable.removeAllListeners();
|
|
123
|
+
if ("closed" in readable && !readable.closed) {
|
|
124
|
+
readable.destroy();
|
|
125
|
+
}
|
|
126
|
+
}), Queue__namespace.shutdown(queue)));
|
|
127
|
+
|
|
128
|
+
/** @internal */
|
|
129
|
+
const writeInput = (writable, onFailure, {
|
|
130
|
+
encoding,
|
|
131
|
+
endOnDone = true
|
|
132
|
+
}, onDone = Effect__namespace.unit) => {
|
|
133
|
+
const write = writeEffect(writable, encoding);
|
|
134
|
+
const close = endOnDone ? Effect__namespace.async(resume => {
|
|
135
|
+
if ("closed" in writable && writable.closed) {
|
|
136
|
+
resume(Effect__namespace.unit);
|
|
137
|
+
} else {
|
|
138
|
+
writable.once("finish", () => resume(Effect__namespace.unit));
|
|
139
|
+
writable.end();
|
|
140
|
+
}
|
|
141
|
+
}) : Effect__namespace.unit;
|
|
142
|
+
return {
|
|
143
|
+
awaitRead: () => Effect__namespace.unit,
|
|
144
|
+
emit: write,
|
|
145
|
+
error: cause => Effect__namespace.zipRight(close, onFailure(cause)),
|
|
146
|
+
done: _ => Effect__namespace.zipRight(close, onDone)
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/** @internal */
|
|
151
|
+
const writeEffect = (writable, encoding) => chunk => chunk.length === 0 ? Effect__namespace.unit : Effect__namespace.async(resume => {
|
|
152
|
+
const iterator = chunk[Symbol.iterator]();
|
|
153
|
+
let next = iterator.next();
|
|
154
|
+
function loop() {
|
|
155
|
+
const item = next;
|
|
156
|
+
next = iterator.next();
|
|
157
|
+
const success = writable.write(item.value, encoding);
|
|
158
|
+
if (next.done) {
|
|
159
|
+
resume(Effect__namespace.unit);
|
|
160
|
+
} else if (success) {
|
|
161
|
+
loop();
|
|
162
|
+
} else {
|
|
163
|
+
writable.once("drain", loop);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
loop();
|
|
167
|
+
});
|
|
168
|
+
const readableOffer = (readable, queue, onError) => Effect__namespace.sync(() => {
|
|
169
|
+
readable.on("readable", () => {
|
|
170
|
+
const size = queue.unsafeSize();
|
|
171
|
+
if (size._tag === "Some" && size.value <= 0) {
|
|
172
|
+
queue.unsafeOffer(Either__namespace.right(void 0));
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
readable.on("error", err => {
|
|
176
|
+
queue.unsafeOffer(Either__namespace.left(Exit__namespace.fail(onError(err))));
|
|
177
|
+
});
|
|
178
|
+
readable.on("end", () => {
|
|
179
|
+
queue.unsafeOffer(Either__namespace.left(Exit__namespace.unit));
|
|
180
|
+
});
|
|
181
|
+
if (readable.readable) {
|
|
182
|
+
queue.unsafeOffer(Either__namespace.right(void 0));
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const readableTake = (readable, queue, chunkSize) => {
|
|
186
|
+
const read = readChunkChannel(readable, chunkSize);
|
|
187
|
+
const loop = Function.pipe(Channel__namespace.fromEffect(Queue__namespace.take(queue)), Channel__namespace.flatMap(Either__namespace.match({
|
|
188
|
+
onLeft: Channel__namespace.fromEffect,
|
|
189
|
+
onRight: _ => Channel__namespace.flatMap(read, () => loop)
|
|
190
|
+
})));
|
|
191
|
+
return loop;
|
|
192
|
+
};
|
|
193
|
+
const readChunkChannel = (readable, chunkSize) => Channel__namespace.flatMap(Channel__namespace.sync(() => {
|
|
194
|
+
const arr = [];
|
|
195
|
+
let chunk = readable.read(chunkSize);
|
|
196
|
+
while (chunk !== null) {
|
|
197
|
+
arr.push(chunk);
|
|
198
|
+
chunk = readable.read(chunkSize);
|
|
199
|
+
}
|
|
200
|
+
return Chunk__namespace.unsafeFromArray(arr);
|
|
201
|
+
}), Channel__namespace.write);
|
|
202
|
+
|
|
203
|
+
exports.fromDuplex = fromDuplex;
|
|
204
|
+
exports.fromReadable = fromReadable;
|
|
205
|
+
exports.pipeThroughDuplex = pipeThroughDuplex;
|
|
206
|
+
exports.pipeThroughSimple = pipeThroughSimple;
|
|
207
|
+
exports.toString = toString;
|
|
208
|
+
exports.toUint8Array = toUint8Array;
|
|
209
|
+
exports.writeInput = writeInput;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Channel = require('effect/Channel');
|
|
4
|
+
var Chunk = require('effect/Chunk');
|
|
5
|
+
var Effect = require('effect/Effect');
|
|
6
|
+
var Either = require('effect/Either');
|
|
7
|
+
var Exit = require('effect/Exit');
|
|
8
|
+
var Function = require('effect/Function');
|
|
9
|
+
var Queue = require('effect/Queue');
|
|
10
|
+
var Stream = require('effect/Stream');
|
|
11
|
+
var Error$1 = require('@effect/platform/Error');
|
|
12
|
+
|
|
13
|
+
function _interopNamespace(e) {
|
|
14
|
+
if (e && e.__esModule) return e;
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
Object.keys(e).forEach(function (k) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return e[k]; }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
n["default"] = e;
|
|
28
|
+
return Object.freeze(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var Channel__namespace = /*#__PURE__*/_interopNamespace(Channel);
|
|
32
|
+
var Chunk__namespace = /*#__PURE__*/_interopNamespace(Chunk);
|
|
33
|
+
var Effect__namespace = /*#__PURE__*/_interopNamespace(Effect);
|
|
34
|
+
var Either__namespace = /*#__PURE__*/_interopNamespace(Either);
|
|
35
|
+
var Exit__namespace = /*#__PURE__*/_interopNamespace(Exit);
|
|
36
|
+
var Queue__namespace = /*#__PURE__*/_interopNamespace(Queue);
|
|
37
|
+
var Stream__namespace = /*#__PURE__*/_interopNamespace(Stream);
|
|
38
|
+
|
|
39
|
+
/** @internal */
|
|
40
|
+
const fromReadable = (evaluate, onError, {
|
|
41
|
+
chunkSize
|
|
42
|
+
} = {}) => Stream__namespace.fromChannel(readChannel(evaluate, onError, chunkSize ? Number(chunkSize) : undefined));
|
|
43
|
+
|
|
44
|
+
/** @internal */
|
|
45
|
+
const toString = (readable, options) => {
|
|
46
|
+
const maxBytesNumber = options.maxBytes ? Number(options.maxBytes) : undefined;
|
|
47
|
+
return Effect__namespace.acquireUseRelease(Effect__namespace.sync(() => {
|
|
48
|
+
const stream = readable();
|
|
49
|
+
stream.setEncoding(options.encoding ?? "utf8");
|
|
50
|
+
return stream;
|
|
51
|
+
}), stream => Effect__namespace.async(resume => {
|
|
52
|
+
let string = "";
|
|
53
|
+
let bytes = 0;
|
|
54
|
+
stream.once("error", err => {
|
|
55
|
+
resume(Effect__namespace.fail(options.onFailure(err)));
|
|
56
|
+
});
|
|
57
|
+
stream.once("end", () => {
|
|
58
|
+
resume(Effect__namespace.succeed(string));
|
|
59
|
+
});
|
|
60
|
+
stream.on("data", chunk => {
|
|
61
|
+
string += chunk;
|
|
62
|
+
bytes += Buffer.byteLength(chunk);
|
|
63
|
+
if (maxBytesNumber && bytes > maxBytesNumber) {
|
|
64
|
+
resume(Effect__namespace.fail(options.onFailure(new Error("maxBytes exceeded"))));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}), stream => Effect__namespace.sync(() => {
|
|
68
|
+
stream.removeAllListeners();
|
|
69
|
+
if ("closed" in stream && !stream.closed) {
|
|
70
|
+
stream.destroy();
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** @internal */
|
|
76
|
+
const toUint8Array = (readable, options) => {
|
|
77
|
+
const maxBytesNumber = options.maxBytes ? Number(options.maxBytes) : undefined;
|
|
78
|
+
return Effect__namespace.acquireUseRelease(Effect__namespace.sync(readable), stream => Effect__namespace.async(resume => {
|
|
79
|
+
let buffer = Buffer.alloc(0);
|
|
80
|
+
let bytes = 0;
|
|
81
|
+
stream.once("error", err => {
|
|
82
|
+
resume(Effect__namespace.fail(options.onFailure(err)));
|
|
83
|
+
});
|
|
84
|
+
stream.once("end", () => {
|
|
85
|
+
resume(Effect__namespace.succeed(buffer));
|
|
86
|
+
});
|
|
87
|
+
stream.on("data", chunk => {
|
|
88
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
89
|
+
bytes += chunk.length;
|
|
90
|
+
if (maxBytesNumber && bytes > maxBytesNumber) {
|
|
91
|
+
resume(Effect__namespace.fail(options.onFailure(new Error("maxBytes exceeded"))));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}), stream => Effect__namespace.sync(() => {
|
|
95
|
+
stream.removeAllListeners();
|
|
96
|
+
if ("closed" in stream && !stream.closed) {
|
|
97
|
+
stream.destroy();
|
|
98
|
+
}
|
|
99
|
+
}));
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** @internal */
|
|
103
|
+
const fromDuplex = (evaluate, onError, options = {}) => Channel__namespace.acquireUseRelease(Effect__namespace.tap(Effect__namespace.zip(Effect__namespace.sync(evaluate), Queue__namespace.unbounded()), ([duplex, queue]) => readableOffer(duplex, queue, onError)), ([duplex, queue]) => Channel__namespace.embedInput(readableTake(duplex, queue, options.chunkSize ? Number(options.chunkSize) : undefined), writeInput(duplex, cause => Queue__namespace.offer(queue, Either__namespace.left(Exit__namespace.failCause(cause))), options)), ([duplex, queue]) => Effect__namespace.zipRight(Effect__namespace.sync(() => {
|
|
104
|
+
duplex.removeAllListeners();
|
|
105
|
+
if (!duplex.closed) {
|
|
106
|
+
duplex.destroy();
|
|
107
|
+
}
|
|
108
|
+
}), Queue__namespace.shutdown(queue)));
|
|
109
|
+
|
|
110
|
+
/** @internal */
|
|
111
|
+
const pipeThroughDuplex = /*#__PURE__*/Function.dual(args => Stream__namespace.StreamTypeId in args[0], (self, duplex, onError, options) => Stream__namespace.pipeThroughChannelOrFail(self, fromDuplex(duplex, onError, options)));
|
|
112
|
+
|
|
113
|
+
/** @internal */
|
|
114
|
+
const pipeThroughSimple = /*#__PURE__*/Function.dual(2, (self, duplex) => Stream__namespace.pipeThroughChannelOrFail(self, fromDuplex(duplex, error => Error$1.SystemError({
|
|
115
|
+
module: "Stream",
|
|
116
|
+
method: "pipeThroughSimple",
|
|
117
|
+
pathOrDescriptor: "",
|
|
118
|
+
reason: "Unknown",
|
|
119
|
+
message: String(error)
|
|
120
|
+
}))));
|
|
121
|
+
const readChannel = (evaluate, onError, chunkSize) => Channel__namespace.acquireUseRelease(Effect__namespace.tap(Effect__namespace.zip(Effect__namespace.sync(evaluate), Queue__namespace.unbounded()), ([readable, queue]) => readableOffer(readable, queue, onError)), ([readable, queue]) => readableTake(readable, queue, chunkSize), ([readable, queue]) => Effect__namespace.zipRight(Effect__namespace.sync(() => {
|
|
122
|
+
readable.removeAllListeners();
|
|
123
|
+
if ("closed" in readable && !readable.closed) {
|
|
124
|
+
readable.destroy();
|
|
125
|
+
}
|
|
126
|
+
}), Queue__namespace.shutdown(queue)));
|
|
127
|
+
|
|
128
|
+
/** @internal */
|
|
129
|
+
const writeInput = (writable, onFailure, {
|
|
130
|
+
encoding,
|
|
131
|
+
endOnDone = true
|
|
132
|
+
}, onDone = Effect__namespace.unit) => {
|
|
133
|
+
const write = writeEffect(writable, encoding);
|
|
134
|
+
const close = endOnDone ? Effect__namespace.async(resume => {
|
|
135
|
+
if ("closed" in writable && writable.closed) {
|
|
136
|
+
resume(Effect__namespace.unit);
|
|
137
|
+
} else {
|
|
138
|
+
writable.once("finish", () => resume(Effect__namespace.unit));
|
|
139
|
+
writable.end();
|
|
140
|
+
}
|
|
141
|
+
}) : Effect__namespace.unit;
|
|
142
|
+
return {
|
|
143
|
+
awaitRead: () => Effect__namespace.unit,
|
|
144
|
+
emit: write,
|
|
145
|
+
error: cause => Effect__namespace.zipRight(close, onFailure(cause)),
|
|
146
|
+
done: _ => Effect__namespace.zipRight(close, onDone)
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/** @internal */
|
|
151
|
+
const writeEffect = (writable, encoding) => chunk => chunk.length === 0 ? Effect__namespace.unit : Effect__namespace.async(resume => {
|
|
152
|
+
const iterator = chunk[Symbol.iterator]();
|
|
153
|
+
let next = iterator.next();
|
|
154
|
+
function loop() {
|
|
155
|
+
const item = next;
|
|
156
|
+
next = iterator.next();
|
|
157
|
+
const success = writable.write(item.value, encoding);
|
|
158
|
+
if (next.done) {
|
|
159
|
+
resume(Effect__namespace.unit);
|
|
160
|
+
} else if (success) {
|
|
161
|
+
loop();
|
|
162
|
+
} else {
|
|
163
|
+
writable.once("drain", loop);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
loop();
|
|
167
|
+
});
|
|
168
|
+
const readableOffer = (readable, queue, onError) => Effect__namespace.sync(() => {
|
|
169
|
+
readable.on("readable", () => {
|
|
170
|
+
const size = queue.unsafeSize();
|
|
171
|
+
if (size._tag === "Some" && size.value <= 0) {
|
|
172
|
+
queue.unsafeOffer(Either__namespace.right(void 0));
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
readable.on("error", err => {
|
|
176
|
+
queue.unsafeOffer(Either__namespace.left(Exit__namespace.fail(onError(err))));
|
|
177
|
+
});
|
|
178
|
+
readable.on("end", () => {
|
|
179
|
+
queue.unsafeOffer(Either__namespace.left(Exit__namespace.unit));
|
|
180
|
+
});
|
|
181
|
+
if (readable.readable) {
|
|
182
|
+
queue.unsafeOffer(Either__namespace.right(void 0));
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const readableTake = (readable, queue, chunkSize) => {
|
|
186
|
+
const read = readChunkChannel(readable, chunkSize);
|
|
187
|
+
const loop = Function.pipe(Channel__namespace.fromEffect(Queue__namespace.take(queue)), Channel__namespace.flatMap(Either__namespace.match({
|
|
188
|
+
onLeft: Channel__namespace.fromEffect,
|
|
189
|
+
onRight: _ => Channel__namespace.flatMap(read, () => loop)
|
|
190
|
+
})));
|
|
191
|
+
return loop;
|
|
192
|
+
};
|
|
193
|
+
const readChunkChannel = (readable, chunkSize) => Channel__namespace.flatMap(Channel__namespace.sync(() => {
|
|
194
|
+
const arr = [];
|
|
195
|
+
let chunk = readable.read(chunkSize);
|
|
196
|
+
while (chunk !== null) {
|
|
197
|
+
arr.push(chunk);
|
|
198
|
+
chunk = readable.read(chunkSize);
|
|
199
|
+
}
|
|
200
|
+
return Chunk__namespace.unsafeFromArray(arr);
|
|
201
|
+
}), Channel__namespace.write);
|
|
202
|
+
|
|
203
|
+
exports.fromDuplex = fromDuplex;
|
|
204
|
+
exports.fromReadable = fromReadable;
|
|
205
|
+
exports.pipeThroughDuplex = pipeThroughDuplex;
|
|
206
|
+
exports.pipeThroughSimple = pipeThroughSimple;
|
|
207
|
+
exports.toString = toString;
|
|
208
|
+
exports.toUint8Array = toUint8Array;
|
|
209
|
+
exports.writeInput = writeInput;
|