@effect/platform-node 0.19.8 → 0.20.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.
Files changed (117) hide show
  1. package/Command/dist/effect-platform-node-Command.cjs.dev.js +32 -32
  2. package/Command/dist/effect-platform-node-Command.cjs.prod.js +32 -32
  3. package/CommandExecutor/dist/effect-platform-node-CommandExecutor.cjs.dev.js +184 -16
  4. package/CommandExecutor/dist/effect-platform-node-CommandExecutor.cjs.prod.js +184 -16
  5. package/CommandExecutor/dist/effect-platform-node-CommandExecutor.esm.js +158 -13
  6. package/Effectify/dist/effect-platform-node-Effectify.cjs.dev.js +2 -2
  7. package/Effectify/dist/effect-platform-node-Effectify.cjs.prod.js +2 -2
  8. package/Error/dist/effect-platform-node-Error.cjs.dev.js +6 -14
  9. package/Error/dist/effect-platform-node-Error.cjs.mjs +1 -3
  10. package/Error/dist/effect-platform-node-Error.cjs.prod.js +6 -14
  11. package/Error/dist/effect-platform-node-Error.esm.js +1 -1
  12. package/FileSystem/dist/effect-platform-node-FileSystem.cjs.dev.js +423 -17
  13. package/FileSystem/dist/effect-platform-node-FileSystem.cjs.prod.js +423 -17
  14. package/FileSystem/dist/effect-platform-node-FileSystem.esm.js +395 -12
  15. package/Http/FormData/dist/effect-platform-node-Http-FormData.cjs.dev.js +3 -3
  16. package/Http/FormData/dist/effect-platform-node-Http-FormData.cjs.prod.js +3 -3
  17. package/Http/FormData/dist/effect-platform-node-Http-FormData.esm.js +3 -3
  18. package/Http/NodeClient/dist/effect-platform-node-Http-NodeClient.cjs.dev.js +4 -4
  19. package/Http/NodeClient/dist/effect-platform-node-Http-NodeClient.cjs.prod.js +4 -4
  20. package/Http/NodeClient/dist/effect-platform-node-Http-NodeClient.esm.js +4 -4
  21. package/Http/Platform/dist/effect-platform-node-Http-Platform.cjs.dev.js +2 -2
  22. package/Http/Platform/dist/effect-platform-node-Http-Platform.cjs.prod.js +2 -2
  23. package/Http/Platform/dist/effect-platform-node-Http-Platform.esm.js +2 -2
  24. package/Http/Server/dist/effect-platform-node-Http-Server.cjs.dev.js +8 -7
  25. package/Http/Server/dist/effect-platform-node-Http-Server.cjs.prod.js +8 -7
  26. package/Http/Server/dist/effect-platform-node-Http-Server.esm.js +8 -7
  27. package/HttpClient/dist/effect-platform-node-HttpClient.cjs.dev.js +19 -19
  28. package/HttpClient/dist/effect-platform-node-HttpClient.cjs.prod.js +19 -19
  29. package/HttpClient/dist/effect-platform-node-HttpClient.esm.js +4 -4
  30. package/HttpServer/dist/effect-platform-node-HttpServer.cjs.dev.js +23 -23
  31. package/HttpServer/dist/effect-platform-node-HttpServer.cjs.prod.js +23 -23
  32. package/HttpServer/dist/effect-platform-node-HttpServer.esm.js +8 -8
  33. package/KeyValueStore/dist/effect-platform-node-KeyValueStore.cjs.dev.js +39 -9
  34. package/KeyValueStore/dist/effect-platform-node-KeyValueStore.cjs.prod.js +39 -9
  35. package/KeyValueStore/dist/effect-platform-node-KeyValueStore.esm.js +18 -4
  36. package/NodeContext/dist/effect-platform-node-NodeContext.cjs.dev.js +39 -7
  37. package/NodeContext/dist/effect-platform-node-NodeContext.cjs.prod.js +39 -7
  38. package/NodeContext/dist/effect-platform-node-NodeContext.esm.js +22 -6
  39. package/Path/dist/effect-platform-node-Path.cjs.dev.js +91 -11
  40. package/Path/dist/effect-platform-node-Path.cjs.prod.js +91 -11
  41. package/Path/dist/effect-platform-node-Path.esm.js +68 -6
  42. package/Runtime/dist/effect-platform-node-Runtime.cjs.dev.js +57 -6
  43. package/Runtime/dist/effect-platform-node-Runtime.cjs.prod.js +57 -6
  44. package/Runtime/dist/effect-platform-node-Runtime.esm.js +38 -3
  45. package/Sink/dist/effect-platform-node-Sink.cjs.dev.js +15 -3
  46. package/Sink/dist/effect-platform-node-Sink.cjs.prod.js +15 -3
  47. package/Sink/dist/effect-platform-node-Sink.esm.js +18 -2
  48. package/Stream/dist/effect-platform-node-Stream.cjs.dev.js +29 -5
  49. package/Stream/dist/effect-platform-node-Stream.cjs.prod.js +29 -5
  50. package/Stream/dist/effect-platform-node-Stream.esm.js +30 -2
  51. package/dist/{FormData-053407d4.cjs.dev.js → FormData-15af6672.cjs.dev.js} +1 -1
  52. package/dist/{FormData-bafc0b9a.esm.js → FormData-5ea8a8b6.esm.js} +1 -1
  53. package/dist/{FormData-c7339a7b.cjs.prod.js → FormData-d91e8016.cjs.prod.js} +1 -1
  54. package/dist/{NodeClient-ea1a9ab0.cjs.prod.js → NodeClient-3432a6a8.cjs.prod.js} +2 -2
  55. package/dist/{NodeClient-e349733e.esm.js → NodeClient-cd56cae8.esm.js} +2 -2
  56. package/dist/{NodeClient-1df9d813.cjs.dev.js → NodeClient-ebd71893.cjs.dev.js} +2 -2
  57. package/dist/{Server-ea100887.cjs.prod.js → Server-33a0b014.cjs.prod.js} +17 -13
  58. package/dist/{Server-264c702d.cjs.dev.js → Server-cf266586.cjs.dev.js} +17 -13
  59. package/dist/{Server-5237fa52.esm.js → Server-eb4f8a51.esm.js} +16 -13
  60. package/dist/declarations/src/Error.d.ts +7 -6
  61. package/dist/declarations/src/Error.d.ts.map +1 -1
  62. package/dist/declarations/src/index.d.ts.map +1 -1
  63. package/dist/effect-platform-node.cjs.dev.js +58 -86
  64. package/dist/effect-platform-node.cjs.prod.js +58 -86
  65. package/dist/effect-platform-node.esm.js +26 -73
  66. package/dist/{formData-fac89256.cjs.dev.js → formData-632b1146.cjs.dev.js} +1 -1
  67. package/dist/{formData-4330f230.esm.js → formData-dd75bbe1.esm.js} +1 -1
  68. package/dist/{formData-09ad7f6d.cjs.prod.js → formData-ecf6742b.cjs.prod.js} +1 -1
  69. package/dist/{incomingMessage-12764c2c.esm.js → incomingMessage-11c9bea6.esm.js} +1 -1
  70. package/dist/{incomingMessage-8a9a29f7.cjs.prod.js → incomingMessage-86bcf94d.cjs.dev.js} +1 -1
  71. package/dist/{incomingMessage-d7f144e7.cjs.dev.js → incomingMessage-f56be93e.cjs.prod.js} +1 -1
  72. package/dist/{platform-f3d31bb1.esm.js → platform-2c00c2c5.esm.js} +1 -1
  73. package/dist/{platform-1c31462c.cjs.dev.js → platform-5b27475e.cjs.dev.js} +1 -1
  74. package/dist/{platform-d09ef04f.cjs.prod.js → platform-80b90f07.cjs.prod.js} +1 -1
  75. package/package.json +8 -5
  76. package/src/Error.ts +9 -6
  77. package/src/index.ts +13 -13
  78. package/src/internal/http/server.ts +24 -16
  79. package/dist/Command-15b84341.cjs.dev.js +0 -29
  80. package/dist/Command-2fc875e9.cjs.prod.js +0 -29
  81. package/dist/Command-56d67f13.esm.js +0 -27
  82. package/dist/CommandExecutor-b7cb55b8.cjs.dev.js +0 -195
  83. package/dist/CommandExecutor-bccc7563.cjs.prod.js +0 -195
  84. package/dist/CommandExecutor-cfc0af4b.esm.js +0 -165
  85. package/dist/Effectify-1676f59e.cjs.prod.js +0 -14
  86. package/dist/Effectify-24bba5b0.esm.js +0 -12
  87. package/dist/Effectify-c94620ca.cjs.dev.js +0 -14
  88. package/dist/Error-004c8162.cjs.prod.js +0 -18
  89. package/dist/Error-6b032e84.esm.js +0 -16
  90. package/dist/Error-6db0ba89.cjs.dev.js +0 -18
  91. package/dist/FileSystem-a207377d.cjs.prod.js +0 -433
  92. package/dist/FileSystem-d4a3521c.esm.js +0 -403
  93. package/dist/FileSystem-d7b8eeac.cjs.dev.js +0 -433
  94. package/dist/HttpClient-11e2237f.esm.js +0 -26
  95. package/dist/HttpClient-19998c5e.cjs.dev.js +0 -54
  96. package/dist/HttpClient-1ad217ea.cjs.prod.js +0 -54
  97. package/dist/HttpServer-08393436.esm.js +0 -34
  98. package/dist/HttpServer-6652ce27.cjs.dev.js +0 -64
  99. package/dist/HttpServer-d510f888.cjs.prod.js +0 -64
  100. package/dist/KeyValueStore-35cb6494.cjs.prod.js +0 -62
  101. package/dist/KeyValueStore-66bca5fd.esm.js +0 -38
  102. package/dist/KeyValueStore-af7495b6.cjs.dev.js +0 -62
  103. package/dist/NodeContext-3c96e955.cjs.dev.js +0 -50
  104. package/dist/NodeContext-4bca6ed4.esm.js +0 -27
  105. package/dist/NodeContext-dff7bc0b.cjs.prod.js +0 -50
  106. package/dist/Path-7a81561f.esm.js +0 -76
  107. package/dist/Path-bf4c3b07.cjs.prod.js +0 -104
  108. package/dist/Path-feae3dcf.cjs.dev.js +0 -104
  109. package/dist/Runtime-3bc7ee1e.esm.js +0 -44
  110. package/dist/Runtime-6aeac6f0.cjs.dev.js +0 -68
  111. package/dist/Runtime-e746c66d.cjs.prod.js +0 -68
  112. package/dist/Sink-536c2b16.cjs.dev.js +0 -26
  113. package/dist/Sink-554d2819.esm.js +0 -23
  114. package/dist/Sink-735101fa.cjs.prod.js +0 -26
  115. package/dist/Stream-2d5b1ece.esm.js +0 -37
  116. package/dist/Stream-53f57af5.cjs.dev.js +0 -42
  117. package/dist/Stream-7424efca.cjs.prod.js +0 -42
@@ -1,15 +1,160 @@
1
- export { l as layer } from '../../dist/CommandExecutor-cfc0af4b.esm.js';
1
+ import * as Command from '@effect/platform/Command';
2
+ import * as CommandExecutor from '@effect/platform/CommandExecutor';
2
3
  export { CommandExecutor } from '@effect/platform/CommandExecutor';
3
- import '@effect/platform/Command';
4
- import '@effect/platform/FileSystem';
5
- import 'effect/Effect';
6
- import 'effect/Function';
7
- import 'effect/Layer';
8
- import 'effect/Option';
9
- import 'effect/Sink';
10
- import 'effect/Stream';
11
- import 'node:child_process';
12
- import '../../dist/error-4865cb95.esm.js';
4
+ import * as FileSystem from '@effect/platform/FileSystem';
5
+ import * as Effect from 'effect/Effect';
6
+ import { pipe, constUndefined } from 'effect/Function';
7
+ import * as Layer from 'effect/Layer';
8
+ import * as Option from 'effect/Option';
9
+ import * as Sink from 'effect/Sink';
10
+ import * as Stream from 'effect/Stream';
11
+ import * as ChildProcess from 'node:child_process';
12
+ import { h as handleErrnoException } from '../../dist/error-4865cb95.esm.js';
13
+ import { f as fromWritable } from '../../dist/sink-bd7ef408.esm.js';
14
+ import { f as fromReadable } from '../../dist/stream-860139d3.esm.js';
13
15
  import '@effect/platform/Error';
14
- import '../../dist/sink-bd7ef408.esm.js';
15
- import '../../dist/stream-860139d3.esm.js';
16
+
17
+ const inputToStdioOption = stdin => Option.match(stdin, {
18
+ onNone: () => "inherit",
19
+ onSome: () => "pipe"
20
+ });
21
+ const outputToStdioOption = output => typeof output === "string" ? output : "pipe";
22
+ const toError = err => err instanceof globalThis.Error ? err : new globalThis.Error(String(err));
23
+ const toPlatformError = (method, error, command) => {
24
+ const flattened = Command.flatten(command).reduce((acc, curr) => {
25
+ const command = `${curr.command} ${curr.args.join(" ")}`;
26
+ return acc.length === 0 ? command : `${acc} | ${command}`;
27
+ }, "");
28
+ return handleErrnoException("Command", method)(error, [flattened]);
29
+ };
30
+ const runCommand = fileSystem => command => {
31
+ switch (command._tag) {
32
+ case "StandardCommand":
33
+ {
34
+ return pipe(
35
+ // Validate that the directory is accessible
36
+ Option.match(command.cwd, {
37
+ onNone: () => Effect.unit,
38
+ onSome: dir => fileSystem.access(dir)
39
+ }), Effect.zipRight(Effect.sync(() => globalThis.process.env)), Effect.flatMap(env => Effect.async(resume => {
40
+ const handle = ChildProcess.spawn(command.command, command.args, {
41
+ stdio: [inputToStdioOption(command.stdin), outputToStdioOption(command.stdout), outputToStdioOption(command.stderr)],
42
+ cwd: Option.getOrElse(command.cwd, constUndefined),
43
+ env: {
44
+ ...env,
45
+ ...Object.fromEntries(command.env)
46
+ }
47
+ });
48
+ let exited = false;
49
+ handle.on("exit", () => {
50
+ exited = true;
51
+ });
52
+
53
+ // If starting the process throws an error, make sure to capture it
54
+ handle.on("error", err => {
55
+ handle.kill("SIGKILL");
56
+ resume(Effect.fail(toPlatformError("spawn", err, command)));
57
+ });
58
+
59
+ // If the process is assigned a process identifier, then we know it
60
+ // was spawned successfully
61
+ if (handle.pid) {
62
+ let stdin = Sink.drain;
63
+ if (handle.stdin !== null) {
64
+ stdin = fromWritable(() => handle.stdin, err => toPlatformError("toWritable", toError(err), command));
65
+ }
66
+ const exitCode = Effect.async(resume => {
67
+ if (exited) {
68
+ return resume(handle.exitCode !== null ? Effect.succeed(CommandExecutor.ExitCode(handle.exitCode)) : Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${handle.signalCode}`), command)));
69
+ }
70
+ handle.on("exit", (code, signal) => {
71
+ if (code !== null) {
72
+ resume(Effect.succeed(CommandExecutor.ExitCode(code)));
73
+ } else {
74
+ // If code is `null`, then `signal` must be defined. See the NodeJS
75
+ // documentation for the `"exit"` event on a `child_process`.
76
+ // https://nodejs.org/api/child_process.html#child_process_event_exit
77
+ resume(Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`), command)));
78
+ }
79
+ });
80
+ // Make sure to terminate the running process if the fiber is
81
+ // terminated
82
+ return Effect.sync(() => {
83
+ handle.kill("SIGKILL");
84
+ });
85
+ });
86
+ const isRunning = Effect.sync(() => handle.exitCode === null && handle.signalCode === null && !handle.killed);
87
+ const kill = (signal = "SIGTERM") => Effect.async(resume => {
88
+ handle.kill(signal);
89
+ handle.on("exit", () => {
90
+ resume(Effect.unit);
91
+ });
92
+ // Make sure to terminate the running process if the fiber
93
+ // is terminated
94
+ return Effect.sync(() => {
95
+ handle.kill("SIGKILL");
96
+ });
97
+ });
98
+ resume(Effect.sync(() => {
99
+ const pid = CommandExecutor.ProcessId(handle.pid);
100
+ const stderr = fromReadable(() => handle.stderr, err => toPlatformError("fromReadable(stderr)", toError(err), command));
101
+ let stdout = fromReadable(() => handle.stdout, err => toPlatformError("fromReadable(stdout)", toError(err), command));
102
+ // TODO: add Sink.isSink
103
+ if (typeof command.stdout !== "string") {
104
+ stdout = Stream.transduce(stdout, command.stdout);
105
+ }
106
+ return {
107
+ [CommandExecutor.ProcessTypeId]: CommandExecutor.ProcessTypeId,
108
+ pid,
109
+ exitCode,
110
+ isRunning,
111
+ kill,
112
+ stdin,
113
+ stderr,
114
+ stdout
115
+ };
116
+ }));
117
+ }
118
+ return Effect.async(resume => {
119
+ if (handle.pid) {
120
+ handle.kill("SIGTERM");
121
+ }
122
+ handle.on("exit", () => {
123
+ resume(Effect.unit);
124
+ });
125
+ });
126
+ })), Effect.tap(process => Option.match(command.stdin, {
127
+ onNone: () => Effect.unit,
128
+ onSome: stdin => Effect.forkDaemon(Stream.run(stdin, process.stdin))
129
+ })));
130
+ }
131
+ case "PipedCommand":
132
+ {
133
+ const flattened = Command.flatten(command);
134
+ if (flattened.length === 1) {
135
+ return pipe(flattened[0], runCommand(fileSystem));
136
+ }
137
+ const head = flattened[0];
138
+ const tail = flattened.slice(1);
139
+ const initial = tail.slice(0, tail.length - 1);
140
+ const last = tail[tail.length - 1];
141
+ const stream = initial.reduce((stdin, command) => pipe(Command.stdin(command, stdin), runCommand(fileSystem), Stream.flatMap(process => process.stdout)), pipe(runCommand(fileSystem)(head), Stream.flatMap(process => process.stdout)));
142
+ return pipe(Command.stdin(last, stream), runCommand(fileSystem));
143
+ }
144
+ }
145
+ };
146
+
147
+ /** @internal */
148
+ const layer$1 = /*#__PURE__*/Layer.effect(CommandExecutor.CommandExecutor, /*#__PURE__*/pipe(FileSystem.FileSystem, /*#__PURE__*/Effect.map(fileSystem => CommandExecutor.makeExecutor(runCommand(fileSystem)))));
149
+
150
+ /**
151
+ * @since 1.0.0
152
+ */
153
+
154
+ /**
155
+ * @since 1.0.0
156
+ * @category layer
157
+ */
158
+ const layer = layer$1;
159
+
160
+ export { layer };
@@ -7,6 +7,6 @@ var Effectify = require('@effect/platform/Effectify');
7
7
 
8
8
 
9
9
  Object.defineProperty(exports, 'effectify', {
10
- enumerable: true,
11
- get: function () { return Effectify.effectify; }
10
+ enumerable: true,
11
+ get: function () { return Effectify.effectify; }
12
12
  });
@@ -7,6 +7,6 @@ var Effectify = require('@effect/platform/Effectify');
7
7
 
8
8
 
9
9
  Object.defineProperty(exports, 'effectify', {
10
- enumerable: true,
11
- get: function () { return Effectify.effectify; }
10
+ enumerable: true,
11
+ get: function () { return Effectify.effectify; }
12
12
  });
@@ -7,22 +7,14 @@ var Error = require('@effect/platform/Error');
7
7
 
8
8
 
9
9
  Object.defineProperty(exports, 'BadArgument', {
10
- enumerable: true,
11
- get: function () { return Error.BadArgument; }
12
- });
13
- Object.defineProperty(exports, 'PlatformError', {
14
- enumerable: true,
15
- get: function () { return Error.PlatformError; }
10
+ enumerable: true,
11
+ get: function () { return Error.BadArgument; }
16
12
  });
17
13
  Object.defineProperty(exports, 'PlatformErrorTypeId', {
18
- enumerable: true,
19
- get: function () { return Error.PlatformErrorTypeId; }
14
+ enumerable: true,
15
+ get: function () { return Error.PlatformErrorTypeId; }
20
16
  });
21
17
  Object.defineProperty(exports, 'SystemError', {
22
- enumerable: true,
23
- get: function () { return Error.SystemError; }
24
- });
25
- Object.defineProperty(exports, 'SystemErrorReason', {
26
- enumerable: true,
27
- get: function () { return Error.SystemErrorReason; }
18
+ enumerable: true,
19
+ get: function () { return Error.SystemError; }
28
20
  });
@@ -1,7 +1,5 @@
1
1
  export {
2
2
  BadArgument,
3
- PlatformError,
4
3
  PlatformErrorTypeId,
5
- SystemError,
6
- SystemErrorReason
4
+ SystemError
7
5
  } from "./effect-platform-node-Error.cjs.js";
@@ -7,22 +7,14 @@ var Error = require('@effect/platform/Error');
7
7
 
8
8
 
9
9
  Object.defineProperty(exports, 'BadArgument', {
10
- enumerable: true,
11
- get: function () { return Error.BadArgument; }
12
- });
13
- Object.defineProperty(exports, 'PlatformError', {
14
- enumerable: true,
15
- get: function () { return Error.PlatformError; }
10
+ enumerable: true,
11
+ get: function () { return Error.BadArgument; }
16
12
  });
17
13
  Object.defineProperty(exports, 'PlatformErrorTypeId', {
18
- enumerable: true,
19
- get: function () { return Error.PlatformErrorTypeId; }
14
+ enumerable: true,
15
+ get: function () { return Error.PlatformErrorTypeId; }
20
16
  });
21
17
  Object.defineProperty(exports, 'SystemError', {
22
- enumerable: true,
23
- get: function () { return Error.SystemError; }
24
- });
25
- Object.defineProperty(exports, 'SystemErrorReason', {
26
- enumerable: true,
27
- get: function () { return Error.SystemErrorReason; }
18
+ enumerable: true,
19
+ get: function () { return Error.SystemError; }
28
20
  });
@@ -1 +1 @@
1
- export { BadArgument, PlatformError, PlatformErrorTypeId, SystemError, SystemErrorReason } from '@effect/platform/Error';
1
+ export { BadArgument, PlatformErrorTypeId, SystemError } from '@effect/platform/Error';