@effect/platform-node-shared 0.0.0-snapshot-c0ae728e57df2c572ea803e1bb7121088cd67b49

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 (154) hide show
  1. package/Http/Etag/package.json +6 -0
  2. package/Http/Multipart/package.json +6 -0
  3. package/LICENSE +21 -0
  4. package/NodeCommandExecutor/package.json +6 -0
  5. package/NodeFileSystem/package.json +6 -0
  6. package/NodeKeyValueStore/package.json +6 -0
  7. package/NodePath/package.json +6 -0
  8. package/NodeRuntime/package.json +6 -0
  9. package/NodeSink/package.json +6 -0
  10. package/NodeStream/package.json +6 -0
  11. package/NodeTerminal/package.json +6 -0
  12. package/README.md +64 -0
  13. package/dist/cjs/Http/Etag.js +43 -0
  14. package/dist/cjs/Http/Etag.js.map +1 -0
  15. package/dist/cjs/Http/Multipart.js +48 -0
  16. package/dist/cjs/Http/Multipart.js.map +1 -0
  17. package/dist/cjs/NodeCommandExecutor.js +38 -0
  18. package/dist/cjs/NodeCommandExecutor.js.map +1 -0
  19. package/dist/cjs/NodeFileSystem.js +42 -0
  20. package/dist/cjs/NodeFileSystem.js.map +1 -0
  21. package/dist/cjs/NodeKeyValueStore.js +42 -0
  22. package/dist/cjs/NodeKeyValueStore.js.map +1 -0
  23. package/dist/cjs/NodePath.js +52 -0
  24. package/dist/cjs/NodePath.js.map +1 -0
  25. package/dist/cjs/NodeRuntime.js +38 -0
  26. package/dist/cjs/NodeRuntime.js.map +1 -0
  27. package/dist/cjs/NodeSink.js +43 -0
  28. package/dist/cjs/NodeSink.js.map +1 -0
  29. package/dist/cjs/NodeStream.js +68 -0
  30. package/dist/cjs/NodeStream.js.map +1 -0
  31. package/dist/cjs/NodeTerminal.js +43 -0
  32. package/dist/cjs/NodeTerminal.js.map +1 -0
  33. package/dist/cjs/internal/commandExecutor.js +151 -0
  34. package/dist/cjs/internal/commandExecutor.js.map +1 -0
  35. package/dist/cjs/internal/error.js +44 -0
  36. package/dist/cjs/internal/error.js.map +1 -0
  37. package/dist/cjs/internal/fileSystem.js +370 -0
  38. package/dist/cjs/internal/fileSystem.js.map +1 -0
  39. package/dist/cjs/internal/http/etag.js +74 -0
  40. package/dist/cjs/internal/http/etag.js.map +1 -0
  41. package/dist/cjs/internal/http/multipart.js +119 -0
  42. package/dist/cjs/internal/http/multipart.js.map +1 -0
  43. package/dist/cjs/internal/path.js +72 -0
  44. package/dist/cjs/internal/path.js.map +1 -0
  45. package/dist/cjs/internal/runtime.js +59 -0
  46. package/dist/cjs/internal/runtime.js.map +1 -0
  47. package/dist/cjs/internal/sink.js +52 -0
  48. package/dist/cjs/internal/sink.js.map +1 -0
  49. package/dist/cjs/internal/stream.js +208 -0
  50. package/dist/cjs/internal/stream.js.map +1 -0
  51. package/dist/cjs/internal/terminal.js +121 -0
  52. package/dist/cjs/internal/terminal.js.map +1 -0
  53. package/dist/dts/Http/Etag.d.ts +16 -0
  54. package/dist/dts/Http/Etag.d.ts.map +1 -0
  55. package/dist/dts/Http/Multipart.d.ts +29 -0
  56. package/dist/dts/Http/Multipart.d.ts.map +1 -0
  57. package/dist/dts/NodeCommandExecutor.d.ts +12 -0
  58. package/dist/dts/NodeCommandExecutor.d.ts.map +1 -0
  59. package/dist/dts/NodeFileSystem.d.ts +11 -0
  60. package/dist/dts/NodeFileSystem.d.ts.map +1 -0
  61. package/dist/dts/NodeKeyValueStore.d.ts +12 -0
  62. package/dist/dts/NodeKeyValueStore.d.ts.map +1 -0
  63. package/dist/dts/NodePath.d.ts +21 -0
  64. package/dist/dts/NodePath.d.ts.map +1 -0
  65. package/dist/dts/NodeRuntime.d.ts +10 -0
  66. package/dist/dts/NodeRuntime.d.ts.map +1 -0
  67. package/dist/dts/NodeSink.d.ts +22 -0
  68. package/dist/dts/NodeSink.d.ts.map +1 -0
  69. package/dist/dts/NodeStream.d.ts +79 -0
  70. package/dist/dts/NodeStream.d.ts.map +1 -0
  71. package/dist/dts/NodeTerminal.d.ts +18 -0
  72. package/dist/dts/NodeTerminal.d.ts.map +1 -0
  73. package/dist/dts/internal/commandExecutor.d.ts +2 -0
  74. package/dist/dts/internal/commandExecutor.d.ts.map +1 -0
  75. package/dist/dts/internal/error.d.ts +2 -0
  76. package/dist/dts/internal/error.d.ts.map +1 -0
  77. package/dist/dts/internal/fileSystem.d.ts +2 -0
  78. package/dist/dts/internal/fileSystem.d.ts.map +1 -0
  79. package/dist/dts/internal/http/etag.d.ts +2 -0
  80. package/dist/dts/internal/http/etag.d.ts.map +1 -0
  81. package/dist/dts/internal/http/multipart.d.ts +2 -0
  82. package/dist/dts/internal/http/multipart.d.ts.map +1 -0
  83. package/dist/dts/internal/path.d.ts +2 -0
  84. package/dist/dts/internal/path.d.ts.map +1 -0
  85. package/dist/dts/internal/runtime.d.ts +2 -0
  86. package/dist/dts/internal/runtime.d.ts.map +1 -0
  87. package/dist/dts/internal/sink.d.ts +2 -0
  88. package/dist/dts/internal/sink.d.ts.map +1 -0
  89. package/dist/dts/internal/stream.d.ts +2 -0
  90. package/dist/dts/internal/stream.d.ts.map +1 -0
  91. package/dist/dts/internal/terminal.d.ts +2 -0
  92. package/dist/dts/internal/terminal.d.ts.map +1 -0
  93. package/dist/esm/Http/Etag.js +12 -0
  94. package/dist/esm/Http/Etag.js.map +1 -0
  95. package/dist/esm/Http/Multipart.js +17 -0
  96. package/dist/esm/Http/Multipart.js.map +1 -0
  97. package/dist/esm/NodeCommandExecutor.js +7 -0
  98. package/dist/esm/NodeCommandExecutor.js.map +1 -0
  99. package/dist/esm/NodeFileSystem.js +10 -0
  100. package/dist/esm/NodeFileSystem.js.map +1 -0
  101. package/dist/esm/NodeKeyValueStore.js +10 -0
  102. package/dist/esm/NodeKeyValueStore.js.map +1 -0
  103. package/dist/esm/NodePath.js +20 -0
  104. package/dist/esm/NodePath.js.map +1 -0
  105. package/dist/esm/NodeRuntime.js +7 -0
  106. package/dist/esm/NodeRuntime.js.map +1 -0
  107. package/dist/esm/NodeSink.js +12 -0
  108. package/dist/esm/NodeSink.js.map +1 -0
  109. package/dist/esm/NodeStream.js +37 -0
  110. package/dist/esm/NodeStream.js.map +1 -0
  111. package/dist/esm/NodeTerminal.js +12 -0
  112. package/dist/esm/NodeTerminal.js.map +1 -0
  113. package/dist/esm/internal/commandExecutor.js +120 -0
  114. package/dist/esm/internal/commandExecutor.js.map +1 -0
  115. package/dist/esm/internal/error.js +37 -0
  116. package/dist/esm/internal/error.js.map +1 -0
  117. package/dist/esm/internal/fileSystem.js +339 -0
  118. package/dist/esm/internal/fileSystem.js.map +1 -0
  119. package/dist/esm/internal/http/etag.js +43 -0
  120. package/dist/esm/internal/http/etag.js.map +1 -0
  121. package/dist/esm/internal/http/multipart.js +85 -0
  122. package/dist/esm/internal/http/multipart.js.map +1 -0
  123. package/dist/esm/internal/path.js +41 -0
  124. package/dist/esm/internal/path.js.map +1 -0
  125. package/dist/esm/internal/runtime.js +27 -0
  126. package/dist/esm/internal/runtime.js.map +1 -0
  127. package/dist/esm/internal/sink.js +19 -0
  128. package/dist/esm/internal/sink.js.map +1 -0
  129. package/dist/esm/internal/stream.js +170 -0
  130. package/dist/esm/internal/stream.js.map +1 -0
  131. package/dist/esm/internal/terminal.js +89 -0
  132. package/dist/esm/internal/terminal.js.map +1 -0
  133. package/dist/esm/package.json +4 -0
  134. package/package.json +105 -0
  135. package/src/Http/Etag.ts +18 -0
  136. package/src/Http/Multipart.ts +40 -0
  137. package/src/NodeCommandExecutor.ts +13 -0
  138. package/src/NodeFileSystem.ts +13 -0
  139. package/src/NodeKeyValueStore.ts +20 -0
  140. package/src/NodePath.ts +25 -0
  141. package/src/NodeRuntime.ts +11 -0
  142. package/src/NodeSink.ts +30 -0
  143. package/src/NodeStream.ts +109 -0
  144. package/src/NodeTerminal.ts +20 -0
  145. package/src/internal/commandExecutor.ts +203 -0
  146. package/src/internal/error.ts +51 -0
  147. package/src/internal/fileSystem.ts +575 -0
  148. package/src/internal/http/etag.ts +44 -0
  149. package/src/internal/http/multipart.ts +107 -0
  150. package/src/internal/path.ts +58 -0
  151. package/src/internal/runtime.ts +36 -0
  152. package/src/internal/sink.ts +57 -0
  153. package/src/internal/stream.ts +325 -0
  154. package/src/internal/terminal.ts +123 -0
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.make = exports.layer = void 0;
7
+ var InternalTerminal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./internal/terminal.js"));
8
+ function _getRequireWildcardCache(e) {
9
+ if ("function" != typeof WeakMap) return null;
10
+ var r = new WeakMap(),
11
+ t = new WeakMap();
12
+ return (_getRequireWildcardCache = function (e) {
13
+ return e ? t : r;
14
+ })(e);
15
+ }
16
+ function _interopRequireWildcard(e, r) {
17
+ if (!r && e && e.__esModule) return e;
18
+ if (null === e || "object" != typeof e && "function" != typeof e) return {
19
+ default: e
20
+ };
21
+ var t = _getRequireWildcardCache(r);
22
+ if (t && t.has(e)) return t.get(e);
23
+ var n = {
24
+ __proto__: null
25
+ },
26
+ a = Object.defineProperty && Object.getOwnPropertyDescriptor;
27
+ for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) {
28
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
29
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
30
+ }
31
+ return n.default = e, t && t.set(e, n), n;
32
+ }
33
+ /**
34
+ * @since 1.0.0
35
+ * @category constructors
36
+ */
37
+ const make = exports.make = InternalTerminal.make;
38
+ /**
39
+ * @since 1.0.0
40
+ * @category layer
41
+ */
42
+ const layer = exports.layer = InternalTerminal.layer;
43
+ //# sourceMappingURL=NodeTerminal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeTerminal.js","names":["InternalTerminal","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","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GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAAA;AAC1D;;;;AAIO,MAAMY,IAAI,GAAAC,OAAA,CAAAD,IAAA,GACfxB,gBAAgB,CAACwB,IAAI;AAEvB;;;;AAIO,MAAME,KAAK,GAAAD,OAAA,CAAAC,KAAA,GAAoB1B,gBAAgB,CAAC0B,KAAK"}
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.layer = void 0;
7
+ var Command = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Command"));
8
+ var CommandExecutor = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/CommandExecutor"));
9
+ var FileSystem = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/FileSystem"));
10
+ var Deferred = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Deferred"));
11
+ var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
12
+ var _Function = /*#__PURE__*/require("effect/Function");
13
+ var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Layer"));
14
+ var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Option"));
15
+ var Sink = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Sink"));
16
+ var Stream = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Stream"));
17
+ var ChildProcess = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("node:child_process"));
18
+ var _error = /*#__PURE__*/require("./error.js");
19
+ var _sink = /*#__PURE__*/require("./sink.js");
20
+ var _stream = /*#__PURE__*/require("./stream.js");
21
+ function _getRequireWildcardCache(e) {
22
+ if ("function" != typeof WeakMap) return null;
23
+ var r = new WeakMap(),
24
+ t = new WeakMap();
25
+ return (_getRequireWildcardCache = function (e) {
26
+ return e ? t : r;
27
+ })(e);
28
+ }
29
+ function _interopRequireWildcard(e, r) {
30
+ if (!r && e && e.__esModule) return e;
31
+ if (null === e || "object" != typeof e && "function" != typeof e) return {
32
+ default: e
33
+ };
34
+ var t = _getRequireWildcardCache(r);
35
+ if (t && t.has(e)) return t.get(e);
36
+ var n = {
37
+ __proto__: null
38
+ },
39
+ a = Object.defineProperty && Object.getOwnPropertyDescriptor;
40
+ for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) {
41
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
42
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
43
+ }
44
+ return n.default = e, t && t.set(e, n), n;
45
+ }
46
+ const inputToStdioOption = stdin => Option.match(stdin, {
47
+ onNone: () => "inherit",
48
+ onSome: () => "pipe"
49
+ });
50
+ const outputToStdioOption = output => typeof output === "string" ? output : "pipe";
51
+ const toError = err => err instanceof globalThis.Error ? err : new globalThis.Error(String(err));
52
+ const toPlatformError = (method, error, command) => {
53
+ const flattened = Command.flatten(command).reduce((acc, curr) => {
54
+ const command = `${curr.command} ${curr.args.join(" ")}`;
55
+ return acc.length === 0 ? command : `${acc} | ${command}`;
56
+ }, "");
57
+ return (0, _error.handleErrnoException)("Command", method)(error, [flattened]);
58
+ };
59
+ const runCommand = fileSystem => command => {
60
+ switch (command._tag) {
61
+ case "StandardCommand":
62
+ {
63
+ const spawn = Effect.flatMap(Deferred.make(), exitCode => Effect.async(resume => {
64
+ const handle = ChildProcess.spawn(command.command, command.args, {
65
+ stdio: [inputToStdioOption(command.stdin), outputToStdioOption(command.stdout), outputToStdioOption(command.stderr)],
66
+ cwd: Option.getOrElse(command.cwd, _Function.constUndefined),
67
+ shell: command.shell,
68
+ env: {
69
+ ...process.env,
70
+ ...Object.fromEntries(command.env)
71
+ }
72
+ });
73
+ handle.on("error", err => {
74
+ resume(Effect.fail(toPlatformError("spawn", err, command)));
75
+ });
76
+ handle.on("exit", (...args) => {
77
+ Deferred.unsafeDone(exitCode, Effect.succeed(args));
78
+ });
79
+ handle.on("spawn", () => {
80
+ resume(Effect.succeed([handle, exitCode]));
81
+ });
82
+ return Effect.sync(() => {
83
+ handle.kill("SIGTERM");
84
+ });
85
+ }));
86
+ return (0, _Function.pipe)(
87
+ // Validate that the directory is accessible
88
+ Option.match(command.cwd, {
89
+ onNone: () => Effect.unit,
90
+ onSome: dir => fileSystem.access(dir)
91
+ }), Effect.zipRight(Effect.acquireRelease(spawn, ([handle, exitCode]) => Effect.flatMap(Deferred.isDone(exitCode), done => done ? Effect.unit : Effect.suspend(() => {
92
+ if (handle.kill("SIGTERM")) {
93
+ return Deferred.await(exitCode);
94
+ }
95
+ return Effect.unit;
96
+ })))), Effect.map(([handle, exitCodeDeferred]) => {
97
+ let stdin = Sink.drain;
98
+ if (handle.stdin !== null) {
99
+ stdin = (0, _sink.fromWritable)(() => handle.stdin, err => toPlatformError("toWritable", toError(err), command));
100
+ }
101
+ const exitCode = Effect.flatMap(Deferred.await(exitCodeDeferred), ([code, signal]) => {
102
+ if (code !== null) {
103
+ return Effect.succeed(CommandExecutor.ExitCode(code));
104
+ }
105
+ // If code is `null`, then `signal` must be defined. See the NodeJS
106
+ // documentation for the `"exit"` event on a `child_process`.
107
+ // https://nodejs.org/api/child_process.html#child_process_event_exit
108
+ return Effect.fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: ${signal}`), command));
109
+ });
110
+ const isRunning = Effect.negate(Deferred.isDone(exitCodeDeferred));
111
+ const kill = (signal = "SIGTERM") => Effect.suspend(() => handle.kill(signal) ? Effect.asUnit(Deferred.await(exitCodeDeferred)) : Effect.fail(toPlatformError("kill", new globalThis.Error("Failed to kill process"), command)));
112
+ const pid = CommandExecutor.ProcessId(handle.pid);
113
+ const stderr = (0, _stream.fromReadable)(() => handle.stderr, err => toPlatformError("fromReadable(stderr)", toError(err), command));
114
+ let stdout = (0, _stream.fromReadable)(() => handle.stdout, err => toPlatformError("fromReadable(stdout)", toError(err), command));
115
+ // TODO: add Sink.isSink
116
+ if (typeof command.stdout !== "string") {
117
+ stdout = Stream.transduce(stdout, command.stdout);
118
+ }
119
+ return {
120
+ [CommandExecutor.ProcessTypeId]: CommandExecutor.ProcessTypeId,
121
+ pid,
122
+ exitCode,
123
+ isRunning,
124
+ kill,
125
+ stdin,
126
+ stderr,
127
+ stdout
128
+ };
129
+ }), Effect.tap(process => Option.match(command.stdin, {
130
+ onNone: () => Effect.unit,
131
+ onSome: stdin => Effect.forkDaemon(Stream.run(stdin, process.stdin))
132
+ })));
133
+ }
134
+ case "PipedCommand":
135
+ {
136
+ const flattened = Command.flatten(command);
137
+ if (flattened.length === 1) {
138
+ return (0, _Function.pipe)(flattened[0], runCommand(fileSystem));
139
+ }
140
+ const head = flattened[0];
141
+ const tail = flattened.slice(1);
142
+ const initial = tail.slice(0, tail.length - 1);
143
+ const last = tail[tail.length - 1];
144
+ const stream = initial.reduce((stdin, command) => (0, _Function.pipe)(Command.stdin(command, stdin), runCommand(fileSystem), Effect.map(process => process.stdout), Stream.unwrapScoped), (0, _Function.pipe)(runCommand(fileSystem)(head), Effect.map(process => process.stdout), Stream.unwrapScoped));
145
+ return (0, _Function.pipe)(Command.stdin(last, stream), runCommand(fileSystem));
146
+ }
147
+ }
148
+ };
149
+ /** @internal */
150
+ const layer = exports.layer = /*#__PURE__*/Layer.effect(CommandExecutor.CommandExecutor, /*#__PURE__*/(0, _Function.pipe)(FileSystem.FileSystem, /*#__PURE__*/Effect.map(fileSystem => CommandExecutor.makeExecutor(runCommand(fileSystem)))));
151
+ //# sourceMappingURL=commandExecutor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commandExecutor.js","names":["Command","_interopRequireWildcard","require","CommandExecutor","FileSystem","Deferred","Effect","_Function","Layer","Option","Sink","Stream","ChildProcess","_error","_sink","_stream","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","inputToStdioOption","stdin","match","onNone","onSome","outputToStdioOption","output","toError","err","globalThis","Error","String","toPlatformError","method","error","command","flattened","flatten","reduce","acc","curr","args","join","length","handleErrnoException","runCommand","fileSystem","_tag","spawn","flatMap","make","exitCode","async","resume","handle","stdio","stdout","stderr","cwd","getOrElse","constUndefined","shell","env","process","fromEntries","on","fail","unsafeDone","succeed","sync","kill","pipe","unit","dir","access","zipRight","acquireRelease","isDone","done","suspend","await","map","exitCodeDeferred","drain","fromWritable","code","signal","ExitCode","isRunning","negate","asUnit","pid","ProcessId","fromReadable","transduce","ProcessTypeId","tap","forkDaemon","run","head","tail","slice","initial","last","stream","unwrapScoped","layer","exports","effect","makeExecutor"],"sources":["../../../src/internal/commandExecutor.ts"],"sourcesContent":[null],"mappings":";;;;;;AAAA,IAAAA,OAAA,gBAAAC,uBAAA,eAAAC,OAAA;AACA,IAAAC,eAAA,gBAAAF,uBAAA,eAAAC,OAAA;AAEA,IAAAE,UAAA,gBAAAH,uBAAA,eAAAC,OAAA;AACA,IAAAG,QAAA,gBAAAJ,uBAAA,eAAAC,OAAA;AACA,IAAAI,MAAA,gBAAAL,uBAAA,eAAAC,OAAA;AACA,IAAAK,SAAA,gBAAAL,OAAA;AACA,IAAAM,KAAA,gBAAAP,uBAAA,eAAAC,OAAA;AACA,IAAAO,MAAA,gBAAAR,uBAAA,eAAAC,OAAA;AAEA,IAAAQ,IAAA,gBAAAT,uBAAA,eAAAC,OAAA;AACA,IAAAS,MAAA,gBAAAV,uBAAA,eAAAC,OAAA;AACA,IAAAU,YAAA,gBAAAX,uBAAA,eAAAC,OAAA;AACA,IAAAW,MAAA,gBAAAX,OAAA;AACA,IAAAY,KAAA,gBAAAZ,OAAA;AACA,IAAAa,OAAA,gBAAAb,OAAA;AAA0C,SAAAc,yBAAAC,CAAA;EAAA,yBAAAC,OAAA;EAAA,IAAAC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,CAACc,OAAO,EAAEd,KAAK,CAAC,EAC7BwB,UAAU,CAACC,UAAU,CAAC,EACtBzD,MAAM,CAAC4F,GAAG,CAAElB,OAAO,IAAKA,OAAO,CAACP,MAAM,CAAC,EACvC9D,MAAM,CAAC+G,YAAY,CACpB,EACH,IAAAnH,SAAA,CAAAiF,IAAI,EACF1B,UAAU,CAACC,UAAU,CAAC,CAACqD,IAAI,CAAC,EAC5B9G,MAAM,CAAC4F,GAAG,CAAElB,OAAO,IAAKA,OAAO,CAACP,MAAM,CAAC,EACvC9D,MAAM,CAAC+G,YAAY,CACpB,CACF;QACD,OAAO,IAAAnH,SAAA,CAAAiF,IAAI,EAACxF,OAAO,CAACsC,KAAK,CAACkF,IAAI,EAAEC,MAAM,CAAC,EAAE3D,UAAU,CAACC,UAAU,CAAC,CAAC;MAClE;EACF;AACF,CAAC;AAEH;AACO,MAAM4D,KAAK,GAAAC,OAAA,CAAAD,KAAA,gBAA+EnH,KAAK,CAACqH,MAAM,CAC3G1H,eAAe,CAACA,eAAe,eAC/B,IAAAI,SAAA,CAAAiF,IAAI,EACFpF,UAAU,CAACA,UAAU,eACrBE,MAAM,CAAC4F,GAAG,CAAEnC,UAAU,IAAK5D,eAAe,CAAC2H,YAAY,CAAChE,UAAU,CAACC,UAAU,CAAC,CAAC,CAAC,CACjF,CACF"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.handleErrnoException = void 0;
7
+ var _Error = /*#__PURE__*/require("@effect/platform/Error");
8
+ /** @internal */
9
+ const handleErrnoException = (module, method) => (err, [path]) => {
10
+ let reason = "Unknown";
11
+ switch (err.code) {
12
+ case "ENOENT":
13
+ reason = "NotFound";
14
+ break;
15
+ case "EACCES":
16
+ reason = "PermissionDenied";
17
+ break;
18
+ case "EEXIST":
19
+ reason = "AlreadyExists";
20
+ break;
21
+ case "EISDIR":
22
+ reason = "BadResource";
23
+ break;
24
+ case "ENOTDIR":
25
+ reason = "BadResource";
26
+ break;
27
+ case "EBUSY":
28
+ reason = "Busy";
29
+ break;
30
+ case "ELOOP":
31
+ reason = "BadResource";
32
+ break;
33
+ }
34
+ return (0, _Error.SystemError)({
35
+ reason,
36
+ module,
37
+ method,
38
+ pathOrDescriptor: path,
39
+ syscall: err.syscall,
40
+ message: err.message
41
+ });
42
+ };
43
+ exports.handleErrnoException = handleErrnoException;
44
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","names":["_Error","require","handleErrnoException","module","method","err","path","reason","code","SystemError","pathOrDescriptor","syscall","message","exports"],"sources":["../../../src/internal/error.ts"],"sourcesContent":[null],"mappings":";;;;;;AACA,IAAAA,MAAA,gBAAAC,OAAA;AAGA;AACO,MAAMC,oBAAoB,GAAGA,CAACC,MAA6B,EAAEC,MAAc,KAClF,CACEC,GAA0B,EAC1B,CAACC,IAAI,CAAiD,KACrC;EACjB,IAAIC,MAAM,GAAsB,SAAS;EAEzC,QAAQF,GAAG,CAACG,IAAI;IACd,KAAK,QAAQ;MACXD,MAAM,GAAG,UAAU;MACnB;IAEF,KAAK,QAAQ;MACXA,MAAM,GAAG,kBAAkB;MAC3B;IAEF,KAAK,QAAQ;MACXA,MAAM,GAAG,eAAe;MACxB;IAEF,KAAK,QAAQ;MACXA,MAAM,GAAG,aAAa;MACtB;IAEF,KAAK,SAAS;MACZA,MAAM,GAAG,aAAa;MACtB;IAEF,KAAK,OAAO;MACVA,MAAM,GAAG,MAAM;MACf;IAEF,KAAK,OAAO;MACVA,MAAM,GAAG,aAAa;MACtB;EACJ;EAEA,OAAO,IAAAP,MAAA,CAAAS,WAAW,EAAC;IACjBF,MAAM;IACNJ,MAAM;IACNC,MAAM;IACNM,gBAAgB,EAAEJ,IAAuB;IACzCK,OAAO,EAAEN,GAAG,CAACM,OAAO;IACpBC,OAAO,EAAEP,GAAG,CAACO;GACd,CAAC;AACJ,CAAC;AAAAC,OAAA,CAAAX,oBAAA,GAAAA,oBAAA"}
@@ -0,0 +1,370 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.layer = void 0;
7
+ var _Effectify = /*#__PURE__*/require("@effect/platform/Effectify");
8
+ var Error = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Error"));
9
+ var FileSystem = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/FileSystem"));
10
+ var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
11
+ var _Function = /*#__PURE__*/require("effect/Function");
12
+ var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Layer"));
13
+ var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Option"));
14
+ var Crypto = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("node:crypto"));
15
+ var NFS = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("node:fs"));
16
+ var OS = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("node:os"));
17
+ var Path = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("node:path"));
18
+ var _error = /*#__PURE__*/require("./error.js");
19
+ function _getRequireWildcardCache(e) {
20
+ if ("function" != typeof WeakMap) return null;
21
+ var r = new WeakMap(),
22
+ t = new WeakMap();
23
+ return (_getRequireWildcardCache = function (e) {
24
+ return e ? t : r;
25
+ })(e);
26
+ }
27
+ function _interopRequireWildcard(e, r) {
28
+ if (!r && e && e.__esModule) return e;
29
+ if (null === e || "object" != typeof e && "function" != typeof e) return {
30
+ default: e
31
+ };
32
+ var t = _getRequireWildcardCache(r);
33
+ if (t && t.has(e)) return t.get(e);
34
+ var n = {
35
+ __proto__: null
36
+ },
37
+ a = Object.defineProperty && Object.getOwnPropertyDescriptor;
38
+ for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) {
39
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
40
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
41
+ }
42
+ return n.default = e, t && t.set(e, n), n;
43
+ }
44
+ const handleBadArgument = method => err => Error.BadArgument({
45
+ module: "FileSystem",
46
+ method,
47
+ message: err.message ?? String(err)
48
+ });
49
+ // == access
50
+ const access = /*#__PURE__*/(() => {
51
+ const nodeAccess = /*#__PURE__*/(0, _Effectify.effectify)(NFS.access, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "access"), /*#__PURE__*/handleBadArgument("access"));
52
+ return (path, options) => {
53
+ let mode = NFS.constants.F_OK;
54
+ if (options?.readable) {
55
+ mode |= NFS.constants.R_OK;
56
+ }
57
+ if (options?.writable) {
58
+ mode |= NFS.constants.W_OK;
59
+ }
60
+ return nodeAccess(path, mode);
61
+ };
62
+ })();
63
+ // == copy
64
+ const copy = /*#__PURE__*/(() => {
65
+ const nodeCp = /*#__PURE__*/(0, _Effectify.effectify)(NFS.cp, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "copy"), /*#__PURE__*/handleBadArgument("copy"));
66
+ return (fromPath, toPath, options) => nodeCp(fromPath, toPath, {
67
+ force: options?.overwrite ?? false,
68
+ preserveTimestamps: options?.preserveTimestamps ?? false,
69
+ recursive: true
70
+ });
71
+ })();
72
+ // == copyFile
73
+ const copyFile = /*#__PURE__*/(() => {
74
+ const nodeCopyFile = /*#__PURE__*/(0, _Effectify.effectify)(NFS.copyFile, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "copyFile"), /*#__PURE__*/handleBadArgument("copyFile"));
75
+ return (fromPath, toPath) => nodeCopyFile(fromPath, toPath);
76
+ })();
77
+ // == chmod
78
+ const chmod = /*#__PURE__*/(() => {
79
+ const nodeChmod = /*#__PURE__*/(0, _Effectify.effectify)(NFS.chmod, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "chmod"), /*#__PURE__*/handleBadArgument("chmod"));
80
+ return (path, mode) => nodeChmod(path, mode);
81
+ })();
82
+ // == chown
83
+ const chown = /*#__PURE__*/(() => {
84
+ const nodeChown = /*#__PURE__*/(0, _Effectify.effectify)(NFS.chown, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "chown"), /*#__PURE__*/handleBadArgument("chown"));
85
+ return (path, uid, gid) => nodeChown(path, uid, gid);
86
+ })();
87
+ // == link
88
+ const link = /*#__PURE__*/(() => {
89
+ const nodeLink = /*#__PURE__*/(0, _Effectify.effectify)(NFS.link, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "link"), /*#__PURE__*/handleBadArgument("link"));
90
+ return (existingPath, newPath) => nodeLink(existingPath, newPath);
91
+ })();
92
+ // == makeDirectory
93
+ const makeDirectory = /*#__PURE__*/(() => {
94
+ const nodeMkdir = /*#__PURE__*/(0, _Effectify.effectify)(NFS.mkdir, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "makeDirectory"), /*#__PURE__*/handleBadArgument("makeDirectory"));
95
+ return (path, options) => nodeMkdir(path, {
96
+ recursive: options?.recursive ?? false,
97
+ mode: options?.mode
98
+ });
99
+ })();
100
+ // == makeTempDirectory
101
+ const makeTempDirectoryFactory = method => {
102
+ const nodeMkdtemp = (0, _Effectify.effectify)(NFS.mkdtemp, (0, _error.handleErrnoException)("FileSystem", method), handleBadArgument(method));
103
+ return options => Effect.suspend(() => {
104
+ const prefix = options?.prefix ?? "";
105
+ const directory = typeof options?.directory === "string" ? Path.join(options.directory, ".") : OS.tmpdir();
106
+ return nodeMkdtemp(prefix ? Path.join(directory, prefix) : directory + "/");
107
+ });
108
+ };
109
+ const makeTempDirectory = /*#__PURE__*/makeTempDirectoryFactory("makeTempDirectory");
110
+ // == remove
111
+ const removeFactory = method => {
112
+ const nodeRm = (0, _Effectify.effectify)(NFS.rm, (0, _error.handleErrnoException)("FileSystem", method), handleBadArgument(method));
113
+ return (path, options) => nodeRm(path, {
114
+ recursive: options?.recursive ?? false
115
+ });
116
+ };
117
+ const remove = /*#__PURE__*/removeFactory("remove");
118
+ // == makeTempDirectoryScoped
119
+ const makeTempDirectoryScoped = /*#__PURE__*/(() => {
120
+ const makeDirectory = /*#__PURE__*/makeTempDirectoryFactory("makeTempDirectoryScoped");
121
+ const removeDirectory = /*#__PURE__*/removeFactory("makeTempDirectoryScoped");
122
+ return options => Effect.acquireRelease(makeDirectory(options), directory => Effect.orDie(removeDirectory(directory, {
123
+ recursive: true
124
+ })));
125
+ })();
126
+ // == open
127
+ const openFactory = method => {
128
+ const nodeOpen = (0, _Effectify.effectify)(NFS.open, (0, _error.handleErrnoException)("FileSystem", method), handleBadArgument(method));
129
+ const nodeClose = (0, _Effectify.effectify)(NFS.close, (0, _error.handleErrnoException)("FileSystem", method), handleBadArgument(method));
130
+ return (path, options) => (0, _Function.pipe)(Effect.acquireRelease(nodeOpen(path, options?.flag ?? "r", options?.mode), fd => Effect.orDie(nodeClose(fd))), Effect.map(fd => makeFile(FileSystem.FileDescriptor(fd), options?.flag?.startsWith("a") ?? false)));
131
+ };
132
+ const open = /*#__PURE__*/openFactory("open");
133
+ const makeFile = /*#__PURE__*/(() => {
134
+ const nodeReadFactory = method => (0, _Effectify.effectify)(NFS.read, (0, _error.handleErrnoException)("FileSystem", method), handleBadArgument(method));
135
+ const nodeRead = /*#__PURE__*/nodeReadFactory("read");
136
+ const nodeReadAlloc = /*#__PURE__*/nodeReadFactory("readAlloc");
137
+ const nodeStat = /*#__PURE__*/(0, _Effectify.effectify)(NFS.fstat, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "stat"), /*#__PURE__*/handleBadArgument("stat"));
138
+ const nodeTruncate = /*#__PURE__*/(0, _Effectify.effectify)(NFS.ftruncate, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "truncate"), /*#__PURE__*/handleBadArgument("truncate"));
139
+ const nodeWriteFactory = method => (0, _Effectify.effectify)(NFS.write, (0, _error.handleErrnoException)("FileSystem", method), handleBadArgument(method));
140
+ const nodeWrite = /*#__PURE__*/nodeWriteFactory("write");
141
+ const nodeWriteAll = /*#__PURE__*/nodeWriteFactory("writeAll");
142
+ class FileImpl {
143
+ fd;
144
+ append;
145
+ [FileSystem.FileTypeId];
146
+ semaphore = Effect.unsafeMakeSemaphore(1);
147
+ position = 0n;
148
+ constructor(fd, append) {
149
+ this.fd = fd;
150
+ this.append = append;
151
+ this[FileSystem.FileTypeId] = FileSystem.FileTypeId;
152
+ }
153
+ get stat() {
154
+ return Effect.map(nodeStat(this.fd), makeFileInfo);
155
+ }
156
+ seek(offset, from) {
157
+ const offsetSize = FileSystem.Size(offset);
158
+ return this.semaphore.withPermits(1)(Effect.sync(() => {
159
+ if (from === "start") {
160
+ this.position = offsetSize;
161
+ } else if (from === "current") {
162
+ this.position = this.position + offsetSize;
163
+ }
164
+ return this.position;
165
+ }));
166
+ }
167
+ read(buffer) {
168
+ return this.semaphore.withPermits(1)(Effect.map(Effect.suspend(() => nodeRead(this.fd, {
169
+ buffer,
170
+ position: this.position
171
+ })), bytesRead => {
172
+ const sizeRead = FileSystem.Size(bytesRead);
173
+ this.position = this.position + sizeRead;
174
+ return sizeRead;
175
+ }));
176
+ }
177
+ readAlloc(size) {
178
+ const sizeNumber = Number(size);
179
+ return this.semaphore.withPermits(1)(Effect.flatMap(Effect.sync(() => Buffer.allocUnsafeSlow(sizeNumber)), buffer => Effect.map(nodeReadAlloc(this.fd, {
180
+ buffer,
181
+ position: this.position
182
+ }), bytesRead => {
183
+ if (bytesRead === 0) {
184
+ return Option.none();
185
+ }
186
+ this.position = this.position + BigInt(bytesRead);
187
+ if (bytesRead === sizeNumber) {
188
+ return Option.some(buffer);
189
+ }
190
+ const dst = Buffer.allocUnsafeSlow(bytesRead);
191
+ buffer.copy(dst, 0, 0, bytesRead);
192
+ return Option.some(dst);
193
+ })));
194
+ }
195
+ truncate(length) {
196
+ return this.semaphore.withPermits(1)(Effect.map(nodeTruncate(this.fd, length ? Number(length) : undefined), () => {
197
+ if (!this.append) {
198
+ const len = BigInt(length ?? 0);
199
+ if (this.position > len) {
200
+ this.position = len;
201
+ }
202
+ }
203
+ }));
204
+ }
205
+ write(buffer) {
206
+ return this.semaphore.withPermits(1)(Effect.map(Effect.suspend(() => nodeWrite(this.fd, buffer, undefined, undefined, this.append ? undefined : Number(this.position))), bytesWritten => {
207
+ const sizeWritten = FileSystem.Size(bytesWritten);
208
+ if (!this.append) {
209
+ this.position = this.position + sizeWritten;
210
+ }
211
+ return sizeWritten;
212
+ }));
213
+ }
214
+ writeAllChunk(buffer) {
215
+ return Effect.flatMap(Effect.suspend(() => nodeWriteAll(this.fd, buffer, undefined, undefined, this.append ? undefined : Number(this.position))), bytesWritten => {
216
+ if (bytesWritten === 0) {
217
+ return Effect.fail(Error.SystemError({
218
+ module: "FileSystem",
219
+ method: "writeAll",
220
+ reason: "WriteZero",
221
+ pathOrDescriptor: this.fd,
222
+ message: "write returned 0 bytes written"
223
+ }));
224
+ }
225
+ if (!this.append) {
226
+ this.position = this.position + BigInt(bytesWritten);
227
+ }
228
+ return bytesWritten < buffer.length ? this.writeAllChunk(buffer.subarray(bytesWritten)) : Effect.unit;
229
+ });
230
+ }
231
+ writeAll(buffer) {
232
+ return this.semaphore.withPermits(1)(this.writeAllChunk(buffer));
233
+ }
234
+ }
235
+ return (fd, append) => new FileImpl(fd, append);
236
+ })();
237
+ // == makeTempFile
238
+ const makeTempFileFactory = method => {
239
+ const makeDirectory = makeTempDirectoryFactory(method);
240
+ const open = openFactory(method);
241
+ const randomHexString = bytes => Effect.sync(() => Crypto.randomBytes(bytes).toString("hex"));
242
+ return options => (0, _Function.pipe)(Effect.zip(makeDirectory(options), randomHexString(6)), Effect.map(([directory, random]) => Path.join(directory, random)), Effect.tap(path => Effect.scoped(open(path, {
243
+ flag: "w+"
244
+ }))));
245
+ };
246
+ const makeTempFile = /*#__PURE__*/makeTempFileFactory("makeTempFile");
247
+ // == makeTempFileScoped
248
+ const makeTempFileScoped = /*#__PURE__*/(() => {
249
+ const makeFile = /*#__PURE__*/makeTempFileFactory("makeTempFileScoped");
250
+ const removeFile = /*#__PURE__*/removeFactory("makeTempFileScoped");
251
+ return options => Effect.acquireRelease(makeFile(options), file => Effect.orDie(removeFile(file)));
252
+ })();
253
+ // == readDirectory
254
+ const readDirectory = /*#__PURE__*/(() => {
255
+ const nodeReadDirectory = /*#__PURE__*/(0, _Effectify.effectify)(NFS.readdir, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "readDirectory"), /*#__PURE__*/handleBadArgument("readDirectory"));
256
+ return (path, options) => nodeReadDirectory(path, options);
257
+ })();
258
+ // == readFile
259
+ const readFile = path => Effect.async((resume, signal) => {
260
+ try {
261
+ NFS.readFile(path, {
262
+ signal
263
+ }, (err, data) => {
264
+ if (err) {
265
+ resume(Effect.fail((0, _error.handleErrnoException)("FileSystem", "readFile")(err, [path])));
266
+ } else {
267
+ resume(Effect.succeed(data));
268
+ }
269
+ });
270
+ } catch (err) {
271
+ resume(Effect.fail(handleBadArgument("readFile")(err)));
272
+ }
273
+ });
274
+ // == readLink
275
+ const readLink = /*#__PURE__*/(() => {
276
+ const nodeReadLink = /*#__PURE__*/(0, _Effectify.effectify)(NFS.readlink, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "readLink"), /*#__PURE__*/handleBadArgument("readLink"));
277
+ return path => nodeReadLink(path);
278
+ })();
279
+ // == realPath
280
+ const realPath = /*#__PURE__*/(() => {
281
+ const nodeRealPath = /*#__PURE__*/(0, _Effectify.effectify)(NFS.realpath, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "realPath"), /*#__PURE__*/handleBadArgument("realPath"));
282
+ return path => nodeRealPath(path);
283
+ })();
284
+ // == rename
285
+ const rename = /*#__PURE__*/(() => {
286
+ const nodeRename = /*#__PURE__*/(0, _Effectify.effectify)(NFS.rename, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "rename"), /*#__PURE__*/handleBadArgument("rename"));
287
+ return (oldPath, newPath) => nodeRename(oldPath, newPath);
288
+ })();
289
+ // == stat
290
+ const makeFileInfo = stat => ({
291
+ type: stat.isFile() ? "File" : stat.isDirectory() ? "Directory" : stat.isSymbolicLink() ? "SymbolicLink" : stat.isBlockDevice() ? "BlockDevice" : stat.isCharacterDevice() ? "CharacterDevice" : stat.isFIFO() ? "FIFO" : stat.isSocket() ? "Socket" : "Unknown",
292
+ mtime: Option.fromNullable(stat.mtime),
293
+ atime: Option.fromNullable(stat.atime),
294
+ birthtime: Option.fromNullable(stat.birthtime),
295
+ dev: stat.dev,
296
+ rdev: Option.fromNullable(stat.rdev),
297
+ ino: Option.fromNullable(stat.ino),
298
+ mode: stat.mode,
299
+ nlink: Option.fromNullable(stat.nlink),
300
+ uid: Option.fromNullable(stat.uid),
301
+ gid: Option.fromNullable(stat.gid),
302
+ size: FileSystem.Size(stat.size),
303
+ blksize: Option.fromNullable(FileSystem.Size(stat.blksize)),
304
+ blocks: Option.fromNullable(stat.blocks)
305
+ });
306
+ const stat = /*#__PURE__*/(() => {
307
+ const nodeStat = /*#__PURE__*/(0, _Effectify.effectify)(NFS.stat, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "stat"), /*#__PURE__*/handleBadArgument("stat"));
308
+ return path => Effect.map(nodeStat(path), makeFileInfo);
309
+ })();
310
+ // == symlink
311
+ const symlink = /*#__PURE__*/(() => {
312
+ const nodeSymlink = /*#__PURE__*/(0, _Effectify.effectify)(NFS.symlink, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "symlink"), /*#__PURE__*/handleBadArgument("symlink"));
313
+ return (target, path) => nodeSymlink(target, path);
314
+ })();
315
+ // == truncate
316
+ const truncate = /*#__PURE__*/(() => {
317
+ const nodeTruncate = /*#__PURE__*/(0, _Effectify.effectify)(NFS.truncate, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "truncate"), /*#__PURE__*/handleBadArgument("truncate"));
318
+ return (path, length) => nodeTruncate(path, length !== undefined ? Number(length) : undefined);
319
+ })();
320
+ // == utimes
321
+ const utimes = /*#__PURE__*/(() => {
322
+ const nodeUtimes = /*#__PURE__*/(0, _Effectify.effectify)(NFS.utimes, /*#__PURE__*/(0, _error.handleErrnoException)("FileSystem", "utime"), /*#__PURE__*/handleBadArgument("utime"));
323
+ return (path, atime, mtime) => nodeUtimes(path, atime, mtime);
324
+ })();
325
+ // == writeFile
326
+ const writeFile = (path, data, options) => Effect.async((resume, signal) => {
327
+ try {
328
+ NFS.writeFile(path, data, {
329
+ signal,
330
+ flag: options?.flag,
331
+ mode: options?.mode
332
+ }, err => {
333
+ if (err) {
334
+ resume(Effect.fail((0, _error.handleErrnoException)("FileSystem", "writeFile")(err, [path])));
335
+ } else {
336
+ resume(Effect.unit);
337
+ }
338
+ });
339
+ } catch (err) {
340
+ resume(Effect.fail(handleBadArgument("writeFile")(err)));
341
+ }
342
+ });
343
+ const fileSystemImpl = /*#__PURE__*/FileSystem.make({
344
+ access,
345
+ chmod,
346
+ chown,
347
+ copy,
348
+ copyFile,
349
+ link,
350
+ makeDirectory,
351
+ makeTempDirectory,
352
+ makeTempDirectoryScoped,
353
+ makeTempFile,
354
+ makeTempFileScoped,
355
+ open,
356
+ readDirectory,
357
+ readFile,
358
+ readLink,
359
+ realPath,
360
+ remove,
361
+ rename,
362
+ stat,
363
+ symlink,
364
+ truncate,
365
+ utimes,
366
+ writeFile
367
+ });
368
+ /** @internal */
369
+ const layer = exports.layer = /*#__PURE__*/Layer.succeed(FileSystem.FileSystem, fileSystemImpl);
370
+ //# sourceMappingURL=fileSystem.js.map