@duplojs/server 0.0.0-stage → 0.1.0-beta.2

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 (262) hide show
  1. package/README +9 -0
  2. package/dist/_virtual/_rolldown/runtime.cjs +33 -0
  3. package/dist/_virtual/_rolldown/runtime.mjs +13 -0
  4. package/dist/command/argument.cjs +27 -0
  5. package/dist/command/argument.d.ts +18 -0
  6. package/dist/command/argument.mjs +24 -0
  7. package/dist/command/create.cjs +94 -0
  8. package/dist/command/create.d.ts +47 -0
  9. package/dist/command/create.mjs +88 -0
  10. package/dist/command/error.cjs +153 -0
  11. package/dist/command/error.d.ts +53 -0
  12. package/dist/command/error.mjs +140 -0
  13. package/dist/command/exec.cjs +19 -0
  14. package/dist/command/exec.d.ts +13 -0
  15. package/dist/command/exec.mjs +17 -0
  16. package/dist/command/execOptions.cjs +41 -0
  17. package/dist/command/execOptions.d.ts +14 -0
  18. package/dist/command/execOptions.mjs +37 -0
  19. package/dist/command/help.cjs +257 -0
  20. package/dist/command/help.d.ts +10 -0
  21. package/dist/command/help.mjs +244 -0
  22. package/dist/command/index.cjs +78 -0
  23. package/dist/command/index.d.ts +8 -0
  24. package/dist/command/index.mjs +45 -0
  25. package/dist/command/kind.cjs +7 -0
  26. package/dist/command/kind.d.ts +2 -0
  27. package/dist/command/kind.mjs +5 -0
  28. package/dist/command/options/base.cjs +68 -0
  29. package/dist/command/options/base.d.ts +24 -0
  30. package/dist/command/options/base.mjs +63 -0
  31. package/dist/command/options/defaults/array.cjs +35 -0
  32. package/dist/command/options/defaults/array.d.ts +24 -0
  33. package/dist/command/options/defaults/array.mjs +29 -0
  34. package/dist/command/options/defaults/boolean.cjs +14 -0
  35. package/dist/command/options/defaults/boolean.d.ts +11 -0
  36. package/dist/command/options/defaults/boolean.mjs +13 -0
  37. package/dist/command/options/defaults/index.d.ts +3 -0
  38. package/dist/command/options/defaults/simple.cjs +25 -0
  39. package/dist/command/options/defaults/simple.d.ts +16 -0
  40. package/dist/command/options/defaults/simple.mjs +22 -0
  41. package/dist/command/options/identifier.cjs +7 -0
  42. package/dist/command/options/identifier.d.ts +4 -0
  43. package/dist/command/options/identifier.mjs +5 -0
  44. package/dist/command/options/index.d.ts +4 -0
  45. package/dist/command/options/types/index.d.ts +1 -0
  46. package/dist/command/options/types/options.d.ts +9 -0
  47. package/dist/command/types/eligibleType.d.ts +4 -0
  48. package/dist/command/types/forbiddenDuplicateName.d.ts +11 -0
  49. package/dist/command/types/index.d.ts +2 -0
  50. package/dist/common/environmentVariable/expandEnvironmentVariables.cjs +27 -0
  51. package/dist/common/environmentVariable/expandEnvironmentVariables.d.ts +2 -0
  52. package/dist/common/environmentVariable/expandEnvironmentVariables.mjs +22 -0
  53. package/dist/common/environmentVariable/index.cjs +47 -0
  54. package/dist/common/environmentVariable/index.d.ts +16 -0
  55. package/dist/common/environmentVariable/index.mjs +41 -0
  56. package/dist/common/environmentVariable/overrideEnvironmentVariables.cjs +13 -0
  57. package/dist/common/environmentVariable/overrideEnvironmentVariables.d.ts +3 -0
  58. package/dist/common/environmentVariable/overrideEnvironmentVariables.mjs +9 -0
  59. package/dist/common/environmentVariable/parseEnvironmentFiles.cjs +32 -0
  60. package/dist/common/environmentVariable/parseEnvironmentFiles.d.ts +4 -0
  61. package/dist/common/environmentVariable/parseEnvironmentFiles.mjs +26 -0
  62. package/dist/common/environmentVariableOrThrow.cjs +23 -0
  63. package/dist/common/environmentVariableOrThrow.d.ts +12 -0
  64. package/dist/common/environmentVariableOrThrow.mjs +19 -0
  65. package/dist/common/exitProcess.cjs +7 -0
  66. package/dist/common/exitProcess.d.ts +6 -0
  67. package/dist/common/exitProcess.mjs +8 -0
  68. package/dist/common/getCurrentWorkDirectory.cjs +15 -0
  69. package/dist/common/getCurrentWorkDirectory.d.ts +8 -0
  70. package/dist/common/getCurrentWorkDirectory.mjs +11 -0
  71. package/dist/common/getCurrentWorkDirectoryOrThrow.cjs +25 -0
  72. package/dist/common/getCurrentWorkDirectoryOrThrow.d.ts +8 -0
  73. package/dist/common/getCurrentWorkDirectoryOrThrow.mjs +20 -0
  74. package/dist/common/getProcessArguments.cjs +18 -0
  75. package/dist/common/getProcessArguments.d.ts +6 -0
  76. package/dist/common/getProcessArguments.mjs +18 -0
  77. package/dist/common/index.cjs +41 -0
  78. package/dist/common/index.d.ts +8 -0
  79. package/dist/common/index.mjs +25 -0
  80. package/dist/common/setCurrentWorkingDirectory.cjs +11 -0
  81. package/dist/common/setCurrentWorkingDirectory.d.ts +8 -0
  82. package/dist/common/setCurrentWorkingDirectory.mjs +9 -0
  83. package/dist/common/setCurrentWorkingDirectoryOrThrow.cjs +23 -0
  84. package/dist/common/setCurrentWorkingDirectoryOrThrow.d.ts +8 -0
  85. package/dist/common/setCurrentWorkingDirectoryOrThrow.mjs +18 -0
  86. package/dist/dataStructure/common/codec/defaults/index.d.ts +2 -0
  87. package/dist/dataStructure/common/codec/defaults/json.cjs +14 -0
  88. package/dist/dataStructure/common/codec/defaults/json.d.ts +9 -0
  89. package/dist/dataStructure/common/codec/defaults/json.mjs +11 -0
  90. package/dist/dataStructure/common/codec/defaults/string.cjs +14 -0
  91. package/dist/dataStructure/common/codec/defaults/string.d.ts +13 -0
  92. package/dist/dataStructure/common/codec/defaults/string.mjs +11 -0
  93. package/dist/dataStructure/common/codec/index.d.ts +1 -0
  94. package/dist/dataStructure/common/error/defaultInterpreter.cjs +27 -0
  95. package/dist/dataStructure/common/error/defaultInterpreter.d.ts +64 -0
  96. package/dist/dataStructure/common/error/defaultInterpreter.mjs +24 -0
  97. package/dist/dataStructure/common/error/index.d.ts +1 -0
  98. package/dist/dataStructure/common/index.d.ts +2 -0
  99. package/dist/dataStructure/constraint/exist.cjs +19 -0
  100. package/dist/dataStructure/constraint/exist.d.ts +10 -0
  101. package/dist/dataStructure/constraint/exist.mjs +15 -0
  102. package/dist/dataStructure/constraint/index.d.ts +4 -0
  103. package/dist/dataStructure/constraint/mimeType.cjs +18 -0
  104. package/dist/dataStructure/constraint/mimeType.d.ts +11 -0
  105. package/dist/dataStructure/constraint/mimeType.mjs +14 -0
  106. package/dist/dataStructure/constraint/size.cjs +29 -0
  107. package/dist/dataStructure/constraint/size.d.ts +16 -0
  108. package/dist/dataStructure/constraint/size.mjs +24 -0
  109. package/dist/dataStructure/constraint/types/constraints.d.ts +10 -0
  110. package/dist/dataStructure/constraint/types/index.d.ts +1 -0
  111. package/dist/dataStructure/fundamentalType/file.cjs +11 -0
  112. package/dist/dataStructure/fundamentalType/file.d.ts +8 -0
  113. package/dist/dataStructure/fundamentalType/file.mjs +8 -0
  114. package/dist/dataStructure/fundamentalType/index.d.ts +2 -0
  115. package/dist/dataStructure/fundamentalType/types/fundamentalTypes.d.ts +6 -0
  116. package/dist/dataStructure/fundamentalType/types/index.d.ts +1 -0
  117. package/dist/dataStructure/helper/exist.cjs +7 -0
  118. package/dist/dataStructure/helper/exist.d.ts +2 -0
  119. package/dist/dataStructure/helper/exist.mjs +7 -0
  120. package/dist/dataStructure/helper/file.cjs +10 -0
  121. package/dist/dataStructure/helper/file.d.ts +3 -0
  122. package/dist/dataStructure/helper/file.mjs +8 -0
  123. package/dist/dataStructure/helper/index.d.ts +4 -0
  124. package/dist/dataStructure/helper/mimeType.cjs +7 -0
  125. package/dist/dataStructure/helper/mimeType.d.ts +2 -0
  126. package/dist/dataStructure/helper/mimeType.mjs +7 -0
  127. package/dist/dataStructure/helper/size.cjs +7 -0
  128. package/dist/dataStructure/helper/size.d.ts +2 -0
  129. package/dist/dataStructure/helper/size.mjs +7 -0
  130. package/dist/dataStructure/index.cjs +62 -0
  131. package/dist/dataStructure/index.d.ts +6 -0
  132. package/dist/dataStructure/index.mjs +38 -0
  133. package/dist/dataStructure/kind.cjs +7 -0
  134. package/dist/dataStructure/kind.d.ts +2 -0
  135. package/dist/dataStructure/kind.mjs +5 -0
  136. package/dist/dataStructure/type/file.cjs +14 -0
  137. package/dist/dataStructure/type/file.d.ts +11 -0
  138. package/dist/dataStructure/type/file.mjs +11 -0
  139. package/dist/dataStructure/type/index.d.ts +2 -0
  140. package/dist/dataStructure/type/types/index.d.ts +1 -0
  141. package/dist/dataStructure/type/types/types.d.ts +6 -0
  142. package/dist/file/appendFile.cjs +43 -0
  143. package/dist/file/appendFile.d.ts +11 -0
  144. package/dist/file/appendFile.mjs +41 -0
  145. package/dist/file/appendTextFile.cjs +43 -0
  146. package/dist/file/appendTextFile.d.ts +11 -0
  147. package/dist/file/appendTextFile.mjs +41 -0
  148. package/dist/file/copy.cjs +31 -0
  149. package/dist/file/copy.d.ts +11 -0
  150. package/dist/file/copy.mjs +29 -0
  151. package/dist/file/createEntryInterface.cjs +16 -0
  152. package/dist/file/createEntryInterface.d.ts +3 -0
  153. package/dist/file/createEntryInterface.mjs +13 -0
  154. package/dist/file/ensureDirectory.cjs +32 -0
  155. package/dist/file/ensureDirectory.d.ts +10 -0
  156. package/dist/file/ensureDirectory.mjs +30 -0
  157. package/dist/file/ensureFile.cjs +38 -0
  158. package/dist/file/ensureFile.d.ts +10 -0
  159. package/dist/file/ensureFile.mjs +36 -0
  160. package/dist/file/exists.cjs +29 -0
  161. package/dist/file/exists.d.ts +10 -0
  162. package/dist/file/exists.mjs +27 -0
  163. package/dist/file/fileInterface.cjs +74 -0
  164. package/dist/file/fileInterface.d.ts +30 -0
  165. package/dist/file/fileInterface.mjs +69 -0
  166. package/dist/file/folderInterface.cjs +74 -0
  167. package/dist/file/folderInterface.d.ts +32 -0
  168. package/dist/file/folderInterface.mjs +69 -0
  169. package/dist/file/index.cjs +122 -0
  170. package/dist/file/index.d.ts +36 -0
  171. package/dist/file/index.mjs +79 -0
  172. package/dist/file/link.cjs +44 -0
  173. package/dist/file/link.d.ts +11 -0
  174. package/dist/file/link.mjs +42 -0
  175. package/dist/file/linkStat.cjs +84 -0
  176. package/dist/file/linkStat.d.ts +11 -0
  177. package/dist/file/linkStat.mjs +80 -0
  178. package/dist/file/makeDirectory.cjs +36 -0
  179. package/dist/file/makeDirectory.d.ts +14 -0
  180. package/dist/file/makeDirectory.mjs +34 -0
  181. package/dist/file/makeTemporaryDirectory.cjs +30 -0
  182. package/dist/file/makeTemporaryDirectory.d.ts +9 -0
  183. package/dist/file/makeTemporaryDirectory.mjs +28 -0
  184. package/dist/file/makeTemporaryFile.cjs +45 -0
  185. package/dist/file/makeTemporaryFile.d.ts +10 -0
  186. package/dist/file/makeTemporaryFile.mjs +41 -0
  187. package/dist/file/move.cjs +45 -0
  188. package/dist/file/move.d.ts +11 -0
  189. package/dist/file/move.mjs +43 -0
  190. package/dist/file/readDirectory.cjs +20 -0
  191. package/dist/file/readDirectory.d.ts +14 -0
  192. package/dist/file/readDirectory.mjs +18 -0
  193. package/dist/file/readFile.cjs +33 -0
  194. package/dist/file/readFile.d.ts +10 -0
  195. package/dist/file/readFile.mjs +31 -0
  196. package/dist/file/readJsonFile.cjs +33 -0
  197. package/dist/file/readJsonFile.d.ts +11 -0
  198. package/dist/file/readJsonFile.mjs +31 -0
  199. package/dist/file/readLink.cjs +30 -0
  200. package/dist/file/readLink.d.ts +10 -0
  201. package/dist/file/readLink.mjs +28 -0
  202. package/dist/file/readTextFile.cjs +33 -0
  203. package/dist/file/readTextFile.d.ts +10 -0
  204. package/dist/file/readTextFile.mjs +31 -0
  205. package/dist/file/realPath.cjs +28 -0
  206. package/dist/file/realPath.d.ts +10 -0
  207. package/dist/file/realPath.mjs +26 -0
  208. package/dist/file/relocate.cjs +56 -0
  209. package/dist/file/relocate.d.ts +11 -0
  210. package/dist/file/relocate.mjs +53 -0
  211. package/dist/file/remove.cjs +38 -0
  212. package/dist/file/remove.d.ts +14 -0
  213. package/dist/file/remove.mjs +36 -0
  214. package/dist/file/rename.cjs +56 -0
  215. package/dist/file/rename.d.ts +11 -0
  216. package/dist/file/rename.mjs +53 -0
  217. package/dist/file/setMode.cjs +51 -0
  218. package/dist/file/setMode.d.ts +26 -0
  219. package/dist/file/setMode.mjs +48 -0
  220. package/dist/file/setOwner.cjs +37 -0
  221. package/dist/file/setOwner.d.ts +15 -0
  222. package/dist/file/setOwner.mjs +35 -0
  223. package/dist/file/setTime.cjs +39 -0
  224. package/dist/file/setTime.d.ts +17 -0
  225. package/dist/file/setTime.mjs +36 -0
  226. package/dist/file/stat.cjs +85 -0
  227. package/dist/file/stat.d.ts +42 -0
  228. package/dist/file/stat.mjs +81 -0
  229. package/dist/file/symlink.cjs +42 -0
  230. package/dist/file/symlink.d.ts +19 -0
  231. package/dist/file/symlink.mjs +40 -0
  232. package/dist/file/truncate.cjs +38 -0
  233. package/dist/file/truncate.d.ts +10 -0
  234. package/dist/file/truncate.mjs +35 -0
  235. package/dist/file/types/fileSystemEither.d.ts +2 -0
  236. package/dist/file/types/index.d.ts +1 -0
  237. package/dist/file/unknownEntryInterface.cjs +36 -0
  238. package/dist/file/unknownEntryInterface.d.ts +15 -0
  239. package/dist/file/unknownEntryInterface.mjs +33 -0
  240. package/dist/file/walkDirectory.cjs +34 -0
  241. package/dist/file/walkDirectory.d.ts +16 -0
  242. package/dist/file/walkDirectory.mjs +28 -0
  243. package/dist/file/writeFile.cjs +44 -0
  244. package/dist/file/writeFile.d.ts +11 -0
  245. package/dist/file/writeFile.mjs +42 -0
  246. package/dist/file/writeJsonFile.cjs +56 -0
  247. package/dist/file/writeJsonFile.d.ts +15 -0
  248. package/dist/file/writeJsonFile.mjs +53 -0
  249. package/dist/file/writeTextFile.cjs +44 -0
  250. package/dist/file/writeTextFile.d.ts +11 -0
  251. package/dist/file/writeTextFile.mjs +42 -0
  252. package/dist/implementor.cjs +64 -0
  253. package/dist/implementor.d.ts +35 -0
  254. package/dist/implementor.mjs +52 -0
  255. package/dist/index.cjs +74 -0
  256. package/dist/index.d.ts +9 -0
  257. package/dist/index.mjs +14 -0
  258. package/dist/kind.cjs +7 -0
  259. package/dist/kind.d.ts +2 -0
  260. package/dist/kind.mjs +5 -0
  261. package/package.json +81 -3
  262. package/README.md +0 -3
@@ -0,0 +1,33 @@
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_implementor = require("../implementor.cjs");
3
+ let _duplojs_lang_either = require("@duplojs/lang/either");
4
+ _duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
5
+ //#region scripts/file/readJsonFile.ts
6
+ function handleNodeReadJsonFileError(error) {
7
+ if (typeof error === "object" && error !== null && "code" in error) {
8
+ if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-read-json-file-not-found", error);
9
+ else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-read-json-file-permission-denied", error);
10
+ else if (error.code === "EISDIR") return _duplojs_lang_either.left("file-system-read-json-file-is-directory", error);
11
+ else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-read-json-file-not-directory", error);
12
+ else if (error.code === "EMFILE" || error.code === "ENFILE") return _duplojs_lang_either.left("file-system-read-json-file-too-many-open-files", error);
13
+ else if (error.code === "EBUSY") return _duplojs_lang_either.left("file-system-read-json-file-busy", error);
14
+ }
15
+ return _duplojs_lang_either.left("file-system-read-json-file-error", error);
16
+ }
17
+ function handleDenoReadJsonFileError(error) {
18
+ if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-read-json-file-not-found", error);
19
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-read-json-file-permission-denied", error);
20
+ if (error instanceof Deno.errors.IsADirectory) return _duplojs_lang_either.left("file-system-read-json-file-is-directory", error);
21
+ if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-read-json-file-not-directory", error);
22
+ if (error instanceof Deno.errors.Busy) return _duplojs_lang_either.left("file-system-read-json-file-busy", error);
23
+ return _duplojs_lang_either.left("file-system-read-json-file-error", error);
24
+ }
25
+ const readJsonFile = require_implementor.implementFunction("readJsonFile", {
26
+ NODE: async (path) => {
27
+ return (await require_implementor.nodeFileSystem.value).readFile(path, { encoding: "utf-8" }).then(JSON.parse).then((value) => _duplojs_lang_either.right("file-system-read-json-file", value)).catch(handleNodeReadJsonFileError);
28
+ },
29
+ DENO: (path) => Deno.readTextFile(path).then(JSON.parse).then((value) => _duplojs_lang_either.right("file-system-read-json-file", value)).catch(handleDenoReadJsonFileError),
30
+ BUN: (path) => Bun.file(path).text().then(JSON.parse).then((value) => _duplojs_lang_either.right("file-system-read-json-file", value)).catch(handleNodeReadJsonFileError)
31
+ });
32
+ //#endregion
33
+ exports.readJsonFile = readJsonFile;
@@ -0,0 +1,11 @@
1
+ import { FileSystemEither } from './types';
2
+ import type * as DCommon from "@duplojs/lang/common";
3
+ import * as DEither from "@duplojs/lang/either";
4
+ import type * as DPath from "@duplojs/lang/path";
5
+ export type ReadJsonFileResult = FileSystemEither<DEither.Right<"read-json-file", DCommon.Json> | DEither.Left<"read-json-file-not-found", unknown> | DEither.Left<"read-json-file-permission-denied", unknown> | DEither.Left<"read-json-file-is-directory", unknown> | DEither.Left<"read-json-file-not-directory", unknown> | DEither.Left<"read-json-file-too-many-open-files", unknown> | DEither.Left<"read-json-file-busy", unknown> | DEither.Left<"read-json-file-error", unknown>>;
6
+ declare module '../implementor' {
7
+ interface ServerFunction {
8
+ readJsonFile(path: string & DPath.Path): Promise<ReadJsonFileResult>;
9
+ }
10
+ }
11
+ export declare const readJsonFile: (path: string & DPath.Path) => Promise<ReadJsonFileResult>;
@@ -0,0 +1,31 @@
1
+ import { implementFunction, nodeFileSystem } from "../implementor.mjs";
2
+ import * as DEither from "@duplojs/lang/either";
3
+ //#region scripts/file/readJsonFile.ts
4
+ function handleNodeReadJsonFileError(error) {
5
+ if (typeof error === "object" && error !== null && "code" in error) {
6
+ if (error.code === "ENOENT") return DEither.left("file-system-read-json-file-not-found", error);
7
+ else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-read-json-file-permission-denied", error);
8
+ else if (error.code === "EISDIR") return DEither.left("file-system-read-json-file-is-directory", error);
9
+ else if (error.code === "ENOTDIR") return DEither.left("file-system-read-json-file-not-directory", error);
10
+ else if (error.code === "EMFILE" || error.code === "ENFILE") return DEither.left("file-system-read-json-file-too-many-open-files", error);
11
+ else if (error.code === "EBUSY") return DEither.left("file-system-read-json-file-busy", error);
12
+ }
13
+ return DEither.left("file-system-read-json-file-error", error);
14
+ }
15
+ function handleDenoReadJsonFileError(error) {
16
+ if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-read-json-file-not-found", error);
17
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-read-json-file-permission-denied", error);
18
+ if (error instanceof Deno.errors.IsADirectory) return DEither.left("file-system-read-json-file-is-directory", error);
19
+ if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-read-json-file-not-directory", error);
20
+ if (error instanceof Deno.errors.Busy) return DEither.left("file-system-read-json-file-busy", error);
21
+ return DEither.left("file-system-read-json-file-error", error);
22
+ }
23
+ const readJsonFile = implementFunction("readJsonFile", {
24
+ NODE: async (path) => {
25
+ return (await nodeFileSystem.value).readFile(path, { encoding: "utf-8" }).then(JSON.parse).then((value) => DEither.right("file-system-read-json-file", value)).catch(handleNodeReadJsonFileError);
26
+ },
27
+ DENO: (path) => Deno.readTextFile(path).then(JSON.parse).then((value) => DEither.right("file-system-read-json-file", value)).catch(handleDenoReadJsonFileError),
28
+ BUN: (path) => Bun.file(path).text().then(JSON.parse).then((value) => DEither.right("file-system-read-json-file", value)).catch(handleNodeReadJsonFileError)
29
+ });
30
+ //#endregion
31
+ export { readJsonFile };
@@ -0,0 +1,30 @@
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_implementor = require("../implementor.cjs");
3
+ let _duplojs_lang_either = require("@duplojs/lang/either");
4
+ _duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
5
+ //#region scripts/file/readLink.ts
6
+ function handleNodeReadLinkError(error) {
7
+ if (typeof error === "object" && error !== null && "code" in error) {
8
+ if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-read-link-not-found", error);
9
+ else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-read-link-permission-denied", error);
10
+ else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-read-link-invalid-argument", error);
11
+ else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-read-link-not-directory", error);
12
+ else if (error.code === "EMFILE" || error.code === "ENFILE") return _duplojs_lang_either.left("file-system-read-link-too-many-open-files", error);
13
+ }
14
+ return _duplojs_lang_either.left("file-system-read-link-error", error);
15
+ }
16
+ function handleDenoReadLinkError(error) {
17
+ if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-read-link-not-found", error);
18
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-read-link-permission-denied", error);
19
+ if (error instanceof Deno.errors.InvalidData) return _duplojs_lang_either.left("file-system-read-link-invalid-argument", error);
20
+ if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-read-link-not-directory", error);
21
+ return _duplojs_lang_either.left("file-system-read-link-error", error);
22
+ }
23
+ const readLink = require_implementor.implementFunction("readLink", {
24
+ NODE: async (path) => {
25
+ return (await require_implementor.nodeFileSystem.value).readlink(path, { encoding: "utf-8" }).then((value) => _duplojs_lang_either.right("file-system-read-link", value)).catch(handleNodeReadLinkError);
26
+ },
27
+ DENO: (path) => Deno.readLink(path).then((value) => _duplojs_lang_either.right("file-system-read-link", value)).catch(handleDenoReadLinkError)
28
+ });
29
+ //#endregion
30
+ exports.readLink = readLink;
@@ -0,0 +1,10 @@
1
+ import { FileSystemEither } from './types';
2
+ import * as DEither from "@duplojs/lang/either";
3
+ import type * as DPath from "@duplojs/lang/path";
4
+ export type ReadLinkResult = FileSystemEither<DEither.Right<"read-link", string> | DEither.Left<"read-link-not-found", unknown> | DEither.Left<"read-link-permission-denied", unknown> | DEither.Left<"read-link-invalid-argument", unknown> | DEither.Left<"read-link-not-directory", unknown> | DEither.Left<"read-link-too-many-open-files", unknown> | DEither.Left<"read-link-error", unknown>>;
5
+ declare module '../implementor' {
6
+ interface ServerFunction {
7
+ readLink(path: string & DPath.Path): Promise<ReadLinkResult>;
8
+ }
9
+ }
10
+ export declare const readLink: (path: string & DPath.Path) => Promise<ReadLinkResult>;
@@ -0,0 +1,28 @@
1
+ import { implementFunction, nodeFileSystem } from "../implementor.mjs";
2
+ import * as DEither from "@duplojs/lang/either";
3
+ //#region scripts/file/readLink.ts
4
+ function handleNodeReadLinkError(error) {
5
+ if (typeof error === "object" && error !== null && "code" in error) {
6
+ if (error.code === "ENOENT") return DEither.left("file-system-read-link-not-found", error);
7
+ else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-read-link-permission-denied", error);
8
+ else if (error.code === "EINVAL") return DEither.left("file-system-read-link-invalid-argument", error);
9
+ else if (error.code === "ENOTDIR") return DEither.left("file-system-read-link-not-directory", error);
10
+ else if (error.code === "EMFILE" || error.code === "ENFILE") return DEither.left("file-system-read-link-too-many-open-files", error);
11
+ }
12
+ return DEither.left("file-system-read-link-error", error);
13
+ }
14
+ function handleDenoReadLinkError(error) {
15
+ if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-read-link-not-found", error);
16
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-read-link-permission-denied", error);
17
+ if (error instanceof Deno.errors.InvalidData) return DEither.left("file-system-read-link-invalid-argument", error);
18
+ if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-read-link-not-directory", error);
19
+ return DEither.left("file-system-read-link-error", error);
20
+ }
21
+ const readLink = implementFunction("readLink", {
22
+ NODE: async (path) => {
23
+ return (await nodeFileSystem.value).readlink(path, { encoding: "utf-8" }).then((value) => DEither.right("file-system-read-link", value)).catch(handleNodeReadLinkError);
24
+ },
25
+ DENO: (path) => Deno.readLink(path).then((value) => DEither.right("file-system-read-link", value)).catch(handleDenoReadLinkError)
26
+ });
27
+ //#endregion
28
+ export { readLink };
@@ -0,0 +1,33 @@
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_implementor = require("../implementor.cjs");
3
+ let _duplojs_lang_either = require("@duplojs/lang/either");
4
+ _duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
5
+ //#region scripts/file/readTextFile.ts
6
+ function handleNodeReadTextFileError(error) {
7
+ if (typeof error === "object" && error !== null && "code" in error) {
8
+ if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-read-text-file-not-found", error);
9
+ else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-read-text-file-permission-denied", error);
10
+ else if (error.code === "EISDIR") return _duplojs_lang_either.left("file-system-read-text-file-is-directory", error);
11
+ else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-read-text-file-not-directory", error);
12
+ else if (error.code === "EMFILE" || error.code === "ENFILE") return _duplojs_lang_either.left("file-system-read-text-file-too-many-open-files", error);
13
+ else if (error.code === "EBUSY") return _duplojs_lang_either.left("file-system-read-text-file-busy", error);
14
+ }
15
+ return _duplojs_lang_either.left("file-system-read-text-file-error", error);
16
+ }
17
+ function handleDenoReadTextFileError(error) {
18
+ if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-read-text-file-not-found", error);
19
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-read-text-file-permission-denied", error);
20
+ if (error instanceof Deno.errors.IsADirectory) return _duplojs_lang_either.left("file-system-read-text-file-is-directory", error);
21
+ if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-read-text-file-not-directory", error);
22
+ if (error instanceof Deno.errors.Busy) return _duplojs_lang_either.left("file-system-read-text-file-busy", error);
23
+ return _duplojs_lang_either.left("file-system-read-text-file-error", error);
24
+ }
25
+ const readTextFile = require_implementor.implementFunction("readTextFile", {
26
+ NODE: async (path) => {
27
+ return (await require_implementor.nodeFileSystem.value).readFile(path, { encoding: "utf-8" }).then((value) => _duplojs_lang_either.right("file-system-read-text-file", value)).catch(handleNodeReadTextFileError);
28
+ },
29
+ DENO: (path) => Deno.readTextFile(path).then((value) => _duplojs_lang_either.right("file-system-read-text-file", value)).catch(handleDenoReadTextFileError),
30
+ BUN: (path) => Bun.file(path).text().then((value) => _duplojs_lang_either.right("file-system-read-text-file", value)).catch(handleNodeReadTextFileError)
31
+ });
32
+ //#endregion
33
+ exports.readTextFile = readTextFile;
@@ -0,0 +1,10 @@
1
+ import { FileSystemEither } from './types';
2
+ import * as DEither from "@duplojs/lang/either";
3
+ import type * as DPath from "@duplojs/lang/path";
4
+ export type ReadTextFileResult = FileSystemEither<DEither.Right<"read-text-file", string> | DEither.Left<"read-text-file-not-found", unknown> | DEither.Left<"read-text-file-permission-denied", unknown> | DEither.Left<"read-text-file-is-directory", unknown> | DEither.Left<"read-text-file-not-directory", unknown> | DEither.Left<"read-text-file-too-many-open-files", unknown> | DEither.Left<"read-text-file-busy", unknown> | DEither.Left<"read-text-file-error", unknown>>;
5
+ declare module '../implementor' {
6
+ interface ServerFunction {
7
+ readTextFile(path: string & DPath.Path): Promise<ReadTextFileResult>;
8
+ }
9
+ }
10
+ export declare const readTextFile: (path: string & DPath.Path) => Promise<ReadTextFileResult>;
@@ -0,0 +1,31 @@
1
+ import { implementFunction, nodeFileSystem } from "../implementor.mjs";
2
+ import * as DEither from "@duplojs/lang/either";
3
+ //#region scripts/file/readTextFile.ts
4
+ function handleNodeReadTextFileError(error) {
5
+ if (typeof error === "object" && error !== null && "code" in error) {
6
+ if (error.code === "ENOENT") return DEither.left("file-system-read-text-file-not-found", error);
7
+ else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-read-text-file-permission-denied", error);
8
+ else if (error.code === "EISDIR") return DEither.left("file-system-read-text-file-is-directory", error);
9
+ else if (error.code === "ENOTDIR") return DEither.left("file-system-read-text-file-not-directory", error);
10
+ else if (error.code === "EMFILE" || error.code === "ENFILE") return DEither.left("file-system-read-text-file-too-many-open-files", error);
11
+ else if (error.code === "EBUSY") return DEither.left("file-system-read-text-file-busy", error);
12
+ }
13
+ return DEither.left("file-system-read-text-file-error", error);
14
+ }
15
+ function handleDenoReadTextFileError(error) {
16
+ if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-read-text-file-not-found", error);
17
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-read-text-file-permission-denied", error);
18
+ if (error instanceof Deno.errors.IsADirectory) return DEither.left("file-system-read-text-file-is-directory", error);
19
+ if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-read-text-file-not-directory", error);
20
+ if (error instanceof Deno.errors.Busy) return DEither.left("file-system-read-text-file-busy", error);
21
+ return DEither.left("file-system-read-text-file-error", error);
22
+ }
23
+ const readTextFile = implementFunction("readTextFile", {
24
+ NODE: async (path) => {
25
+ return (await nodeFileSystem.value).readFile(path, { encoding: "utf-8" }).then((value) => DEither.right("file-system-read-text-file", value)).catch(handleNodeReadTextFileError);
26
+ },
27
+ DENO: (path) => Deno.readTextFile(path).then((value) => DEither.right("file-system-read-text-file", value)).catch(handleDenoReadTextFileError),
28
+ BUN: (path) => Bun.file(path).text().then((value) => DEither.right("file-system-read-text-file", value)).catch(handleNodeReadTextFileError)
29
+ });
30
+ //#endregion
31
+ export { readTextFile };
@@ -0,0 +1,28 @@
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_implementor = require("../implementor.cjs");
3
+ let _duplojs_lang_either = require("@duplojs/lang/either");
4
+ _duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
5
+ //#region scripts/file/realPath.ts
6
+ function handleNodeRealPathError(error) {
7
+ if (typeof error === "object" && error !== null && "code" in error) {
8
+ if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-real-path-not-found", error);
9
+ else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-real-path-permission-denied", error);
10
+ else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-real-path-not-directory", error);
11
+ else if (error.code === "EMFILE" || error.code === "ENFILE") return _duplojs_lang_either.left("file-system-real-path-too-many-open-files", error);
12
+ }
13
+ return _duplojs_lang_either.left("file-system-real-path-error", error);
14
+ }
15
+ function handleDenoRealPathError(error) {
16
+ if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-real-path-not-found", error);
17
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-real-path-permission-denied", error);
18
+ if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-real-path-not-directory", error);
19
+ return _duplojs_lang_either.left("file-system-real-path-error", error);
20
+ }
21
+ const realPath = require_implementor.implementFunction("realPath", {
22
+ NODE: async (path) => {
23
+ return (await require_implementor.nodeFileSystem.value).realpath(path).then((value) => _duplojs_lang_either.right("file-system-real-path", value)).catch(handleNodeRealPathError);
24
+ },
25
+ DENO: (path) => Deno.realPath(path).then((value) => _duplojs_lang_either.right("file-system-real-path", value)).catch(handleDenoRealPathError)
26
+ });
27
+ //#endregion
28
+ exports.realPath = realPath;
@@ -0,0 +1,10 @@
1
+ import { FileSystemEither } from './types';
2
+ import * as DEither from "@duplojs/lang/either";
3
+ import type * as DPath from "@duplojs/lang/path";
4
+ export type RealPathResult = FileSystemEither<DEither.Right<"real-path", string> | DEither.Left<"real-path-not-found", unknown> | DEither.Left<"real-path-permission-denied", unknown> | DEither.Left<"real-path-not-directory", unknown> | DEither.Left<"real-path-too-many-open-files", unknown> | DEither.Left<"real-path-error", unknown>>;
5
+ declare module '../implementor' {
6
+ interface ServerFunction {
7
+ realPath(path: string & DPath.Path): Promise<RealPathResult>;
8
+ }
9
+ }
10
+ export declare const realPath: (path: string & DPath.Path) => Promise<RealPathResult>;
@@ -0,0 +1,26 @@
1
+ import { implementFunction, nodeFileSystem } from "../implementor.mjs";
2
+ import * as DEither from "@duplojs/lang/either";
3
+ //#region scripts/file/realPath.ts
4
+ function handleNodeRealPathError(error) {
5
+ if (typeof error === "object" && error !== null && "code" in error) {
6
+ if (error.code === "ENOENT") return DEither.left("file-system-real-path-not-found", error);
7
+ else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-real-path-permission-denied", error);
8
+ else if (error.code === "ENOTDIR") return DEither.left("file-system-real-path-not-directory", error);
9
+ else if (error.code === "EMFILE" || error.code === "ENFILE") return DEither.left("file-system-real-path-too-many-open-files", error);
10
+ }
11
+ return DEither.left("file-system-real-path-error", error);
12
+ }
13
+ function handleDenoRealPathError(error) {
14
+ if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-real-path-not-found", error);
15
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-real-path-permission-denied", error);
16
+ if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-real-path-not-directory", error);
17
+ return DEither.left("file-system-real-path-error", error);
18
+ }
19
+ const realPath = implementFunction("realPath", {
20
+ NODE: async (path) => {
21
+ return (await nodeFileSystem.value).realpath(path).then((value) => DEither.right("file-system-real-path", value)).catch(handleNodeRealPathError);
22
+ },
23
+ DENO: (path) => Deno.realPath(path).then((value) => DEither.right("file-system-real-path", value)).catch(handleDenoRealPathError)
24
+ });
25
+ //#endregion
26
+ export { realPath };
@@ -0,0 +1,56 @@
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_implementor = require("../implementor.cjs");
3
+ let _duplojs_lang_either = require("@duplojs/lang/either");
4
+ _duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
5
+ let _duplojs_lang_path = require("@duplojs/lang/path");
6
+ _duplojs_lang_path = require_runtime.__toESM(_duplojs_lang_path, 1);
7
+ //#region scripts/file/relocate.ts
8
+ function handleNodeRelocateError(error) {
9
+ if (typeof error === "object" && error !== null && "code" in error) {
10
+ if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-relocate-not-found", error);
11
+ else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-relocate-permission-denied", error);
12
+ else if (error.code === "EEXIST") return _duplojs_lang_either.left("file-system-relocate-already-exists", error);
13
+ else if (error.code === "EISDIR") return _duplojs_lang_either.left("file-system-relocate-is-directory", error);
14
+ else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-relocate-not-directory", error);
15
+ else if (error.code === "ENOTEMPTY") return _duplojs_lang_either.left("file-system-relocate-directory-not-empty", error);
16
+ else if (error.code === "EROFS") return _duplojs_lang_either.left("file-system-relocate-read-only", error);
17
+ else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-relocate-invalid-argument", error);
18
+ else if (error.code === "EBUSY") return _duplojs_lang_either.left("file-system-relocate-busy", error);
19
+ else if (error.code === "EXDEV") return _duplojs_lang_either.left("file-system-relocate-cross-device", error);
20
+ }
21
+ return _duplojs_lang_either.left("file-system-relocate-error", error);
22
+ }
23
+ function handleDenoRelocateError(error) {
24
+ if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-relocate-not-found", error);
25
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-relocate-permission-denied", error);
26
+ if (error instanceof Deno.errors.AlreadyExists) return _duplojs_lang_either.left("file-system-relocate-already-exists", error);
27
+ if (error instanceof Deno.errors.IsADirectory) return _duplojs_lang_either.left("file-system-relocate-is-directory", error);
28
+ if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-relocate-not-directory", error);
29
+ if (error instanceof Deno.errors.InvalidData) return _duplojs_lang_either.left("file-system-relocate-invalid-argument", error);
30
+ if (error instanceof Deno.errors.Busy) return _duplojs_lang_either.left("file-system-relocate-busy", error);
31
+ return _duplojs_lang_either.left("file-system-relocate-error", error);
32
+ }
33
+ const relocateImplementation = require_implementor.implementFunction("relocate", {
34
+ NODE: async (fromPath, newParentPath) => {
35
+ const fs = await require_implementor.nodeFileSystem.value;
36
+ const baseName = _duplojs_lang_path.getBaseName(fromPath);
37
+ if (!baseName) return _duplojs_lang_either.left("file-system-relocate-invalid-argument", /* @__PURE__ */ new Error(`Invalid base name ${fromPath}`));
38
+ const newPath = _duplojs_lang_path.resolveRelative([newParentPath, baseName]);
39
+ return fs.rename(fromPath, newPath).then(() => _duplojs_lang_either.right("file-system-relocate", newPath)).catch(handleNodeRelocateError);
40
+ },
41
+ DENO: (fromPath, newParentPath) => {
42
+ const baseName = _duplojs_lang_path.getBaseName(fromPath);
43
+ if (!baseName) return Promise.resolve(_duplojs_lang_either.left("file-system-relocate-invalid-argument", /* @__PURE__ */ new Error(`Invalid base name ${fromPath}`)));
44
+ const newPath = _duplojs_lang_path.resolveRelative([newParentPath, baseName]);
45
+ return Deno.rename(fromPath, newPath).then(() => _duplojs_lang_either.right("file-system-relocate", newPath)).catch(handleDenoRelocateError);
46
+ }
47
+ });
48
+ function relocate(...args) {
49
+ if (args.length === 1) {
50
+ const [toPath] = args;
51
+ return (fromPath) => relocateImplementation(fromPath, toPath);
52
+ }
53
+ return relocateImplementation(...args);
54
+ }
55
+ //#endregion
56
+ exports.relocate = relocate;
@@ -0,0 +1,11 @@
1
+ import { FileSystemEither } from './types';
2
+ import * as DPath from "@duplojs/lang/path";
3
+ import * as DEither from "@duplojs/lang/either";
4
+ export type RelocateResult = FileSystemEither<DEither.Right<"relocate", string & DPath.Path> | DEither.Left<"relocate-not-found", unknown> | DEither.Left<"relocate-permission-denied", unknown> | DEither.Left<"relocate-already-exists", unknown> | DEither.Left<"relocate-is-directory", unknown> | DEither.Left<"relocate-not-directory", unknown> | DEither.Left<"relocate-directory-not-empty", unknown> | DEither.Left<"relocate-read-only", unknown> | DEither.Left<"relocate-invalid-argument", unknown> | DEither.Left<"relocate-busy", unknown> | DEither.Left<"relocate-cross-device", unknown> | DEither.Left<"relocate-error", unknown>>;
5
+ declare module '../implementor' {
6
+ interface ServerFunction {
7
+ relocate(fromPath: string & DPath.Path, toPath: string & DPath.Path): Promise<RelocateResult>;
8
+ }
9
+ }
10
+ export declare function relocate(toPath: string & DPath.Path): (fromPath: string & DPath.Path) => Promise<RelocateResult>;
11
+ export declare function relocate(fromPath: string & DPath.Path, toPath: string & DPath.Path): Promise<RelocateResult>;
@@ -0,0 +1,53 @@
1
+ import { implementFunction, nodeFileSystem } from "../implementor.mjs";
2
+ import * as DEither from "@duplojs/lang/either";
3
+ import * as DPath from "@duplojs/lang/path";
4
+ //#region scripts/file/relocate.ts
5
+ function handleNodeRelocateError(error) {
6
+ if (typeof error === "object" && error !== null && "code" in error) {
7
+ if (error.code === "ENOENT") return DEither.left("file-system-relocate-not-found", error);
8
+ else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-relocate-permission-denied", error);
9
+ else if (error.code === "EEXIST") return DEither.left("file-system-relocate-already-exists", error);
10
+ else if (error.code === "EISDIR") return DEither.left("file-system-relocate-is-directory", error);
11
+ else if (error.code === "ENOTDIR") return DEither.left("file-system-relocate-not-directory", error);
12
+ else if (error.code === "ENOTEMPTY") return DEither.left("file-system-relocate-directory-not-empty", error);
13
+ else if (error.code === "EROFS") return DEither.left("file-system-relocate-read-only", error);
14
+ else if (error.code === "EINVAL") return DEither.left("file-system-relocate-invalid-argument", error);
15
+ else if (error.code === "EBUSY") return DEither.left("file-system-relocate-busy", error);
16
+ else if (error.code === "EXDEV") return DEither.left("file-system-relocate-cross-device", error);
17
+ }
18
+ return DEither.left("file-system-relocate-error", error);
19
+ }
20
+ function handleDenoRelocateError(error) {
21
+ if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-relocate-not-found", error);
22
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-relocate-permission-denied", error);
23
+ if (error instanceof Deno.errors.AlreadyExists) return DEither.left("file-system-relocate-already-exists", error);
24
+ if (error instanceof Deno.errors.IsADirectory) return DEither.left("file-system-relocate-is-directory", error);
25
+ if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-relocate-not-directory", error);
26
+ if (error instanceof Deno.errors.InvalidData) return DEither.left("file-system-relocate-invalid-argument", error);
27
+ if (error instanceof Deno.errors.Busy) return DEither.left("file-system-relocate-busy", error);
28
+ return DEither.left("file-system-relocate-error", error);
29
+ }
30
+ const relocateImplementation = implementFunction("relocate", {
31
+ NODE: async (fromPath, newParentPath) => {
32
+ const fs = await nodeFileSystem.value;
33
+ const baseName = DPath.getBaseName(fromPath);
34
+ if (!baseName) return DEither.left("file-system-relocate-invalid-argument", /* @__PURE__ */ new Error(`Invalid base name ${fromPath}`));
35
+ const newPath = DPath.resolveRelative([newParentPath, baseName]);
36
+ return fs.rename(fromPath, newPath).then(() => DEither.right("file-system-relocate", newPath)).catch(handleNodeRelocateError);
37
+ },
38
+ DENO: (fromPath, newParentPath) => {
39
+ const baseName = DPath.getBaseName(fromPath);
40
+ if (!baseName) return Promise.resolve(DEither.left("file-system-relocate-invalid-argument", /* @__PURE__ */ new Error(`Invalid base name ${fromPath}`)));
41
+ const newPath = DPath.resolveRelative([newParentPath, baseName]);
42
+ return Deno.rename(fromPath, newPath).then(() => DEither.right("file-system-relocate", newPath)).catch(handleDenoRelocateError);
43
+ }
44
+ });
45
+ function relocate(...args) {
46
+ if (args.length === 1) {
47
+ const [toPath] = args;
48
+ return (fromPath) => relocateImplementation(fromPath, toPath);
49
+ }
50
+ return relocateImplementation(...args);
51
+ }
52
+ //#endregion
53
+ export { relocate };
@@ -0,0 +1,38 @@
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_implementor = require("../implementor.cjs");
3
+ let _duplojs_lang_either = require("@duplojs/lang/either");
4
+ _duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
5
+ //#region scripts/file/remove.ts
6
+ function handleNodeRemoveError(error) {
7
+ if (typeof error === "object" && error !== null && "code" in error) {
8
+ if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-remove-not-found", error);
9
+ else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-remove-permission-denied", error);
10
+ else if (error.code === "EISDIR") return _duplojs_lang_either.left("file-system-remove-is-directory", error);
11
+ else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-remove-not-directory", error);
12
+ else if (error.code === "ENOTEMPTY") return _duplojs_lang_either.left("file-system-remove-directory-not-empty", error);
13
+ else if (error.code === "EROFS") return _duplojs_lang_either.left("file-system-remove-read-only", error);
14
+ else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-remove-invalid-argument", error);
15
+ else if (error.code === "EBUSY") return _duplojs_lang_either.left("file-system-remove-busy", error);
16
+ }
17
+ return _duplojs_lang_either.left("file-system-remove-error", error);
18
+ }
19
+ function handleDenoRemoveError(error) {
20
+ if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-remove-not-found", error);
21
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-remove-permission-denied", error);
22
+ if (error instanceof Deno.errors.IsADirectory) return _duplojs_lang_either.left("file-system-remove-is-directory", error);
23
+ if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-remove-not-directory", error);
24
+ if (error instanceof Deno.errors.InvalidData) return _duplojs_lang_either.left("file-system-remove-invalid-argument", error);
25
+ if (error instanceof Deno.errors.Busy) return _duplojs_lang_either.left("file-system-remove-busy", error);
26
+ return _duplojs_lang_either.left("file-system-remove-error", error);
27
+ }
28
+ const remove = require_implementor.implementFunction("remove", {
29
+ NODE: async (path, params) => {
30
+ return (await require_implementor.nodeFileSystem.value).rm(path, {
31
+ recursive: params?.recursive ?? false,
32
+ force: true
33
+ }).then(() => _duplojs_lang_either.right("file-system-remove")).catch(handleNodeRemoveError);
34
+ },
35
+ DENO: (path, params) => Deno.remove(path, { recursive: params?.recursive }).then(() => _duplojs_lang_either.right("file-system-remove")).catch(handleDenoRemoveError)
36
+ });
37
+ //#endregion
38
+ exports.remove = remove;
@@ -0,0 +1,14 @@
1
+ import { FileSystemEither } from './types';
2
+ import * as DEither from "@duplojs/lang/either";
3
+ import type * as DPath from "@duplojs/lang/path";
4
+ interface RemoveDirectoryParams {
5
+ recursive?: boolean;
6
+ }
7
+ export type RemoveResult = FileSystemEither<DEither.Right<"remove", void> | DEither.Left<"remove-not-found", unknown> | DEither.Left<"remove-permission-denied", unknown> | DEither.Left<"remove-is-directory", unknown> | DEither.Left<"remove-not-directory", unknown> | DEither.Left<"remove-directory-not-empty", unknown> | DEither.Left<"remove-read-only", unknown> | DEither.Left<"remove-invalid-argument", unknown> | DEither.Left<"remove-busy", unknown> | DEither.Left<"remove-error", unknown>>;
8
+ declare module '../implementor' {
9
+ interface ServerFunction {
10
+ remove(path: string & DPath.Path, params?: RemoveDirectoryParams): Promise<RemoveResult>;
11
+ }
12
+ }
13
+ export declare const remove: (path: string & DPath.Path, params?: RemoveDirectoryParams) => Promise<RemoveResult>;
14
+ export {};
@@ -0,0 +1,36 @@
1
+ import { implementFunction, nodeFileSystem } from "../implementor.mjs";
2
+ import * as DEither from "@duplojs/lang/either";
3
+ //#region scripts/file/remove.ts
4
+ function handleNodeRemoveError(error) {
5
+ if (typeof error === "object" && error !== null && "code" in error) {
6
+ if (error.code === "ENOENT") return DEither.left("file-system-remove-not-found", error);
7
+ else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-remove-permission-denied", error);
8
+ else if (error.code === "EISDIR") return DEither.left("file-system-remove-is-directory", error);
9
+ else if (error.code === "ENOTDIR") return DEither.left("file-system-remove-not-directory", error);
10
+ else if (error.code === "ENOTEMPTY") return DEither.left("file-system-remove-directory-not-empty", error);
11
+ else if (error.code === "EROFS") return DEither.left("file-system-remove-read-only", error);
12
+ else if (error.code === "EINVAL") return DEither.left("file-system-remove-invalid-argument", error);
13
+ else if (error.code === "EBUSY") return DEither.left("file-system-remove-busy", error);
14
+ }
15
+ return DEither.left("file-system-remove-error", error);
16
+ }
17
+ function handleDenoRemoveError(error) {
18
+ if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-remove-not-found", error);
19
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-remove-permission-denied", error);
20
+ if (error instanceof Deno.errors.IsADirectory) return DEither.left("file-system-remove-is-directory", error);
21
+ if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-remove-not-directory", error);
22
+ if (error instanceof Deno.errors.InvalidData) return DEither.left("file-system-remove-invalid-argument", error);
23
+ if (error instanceof Deno.errors.Busy) return DEither.left("file-system-remove-busy", error);
24
+ return DEither.left("file-system-remove-error", error);
25
+ }
26
+ const remove = implementFunction("remove", {
27
+ NODE: async (path, params) => {
28
+ return (await nodeFileSystem.value).rm(path, {
29
+ recursive: params?.recursive ?? false,
30
+ force: true
31
+ }).then(() => DEither.right("file-system-remove")).catch(handleNodeRemoveError);
32
+ },
33
+ DENO: (path, params) => Deno.remove(path, { recursive: params?.recursive }).then(() => DEither.right("file-system-remove")).catch(handleDenoRemoveError)
34
+ });
35
+ //#endregion
36
+ export { remove };
@@ -0,0 +1,56 @@
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_implementor = require("../implementor.cjs");
3
+ let _duplojs_lang_either = require("@duplojs/lang/either");
4
+ _duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
5
+ let _duplojs_lang_path = require("@duplojs/lang/path");
6
+ _duplojs_lang_path = require_runtime.__toESM(_duplojs_lang_path, 1);
7
+ //#region scripts/file/rename.ts
8
+ function handleNodeRenameError(error) {
9
+ if (typeof error === "object" && error !== null && "code" in error) {
10
+ if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-rename-not-found", error);
11
+ else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-rename-permission-denied", error);
12
+ else if (error.code === "EEXIST") return _duplojs_lang_either.left("file-system-rename-already-exists", error);
13
+ else if (error.code === "EISDIR") return _duplojs_lang_either.left("file-system-rename-is-directory", error);
14
+ else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-rename-not-directory", error);
15
+ else if (error.code === "ENOTEMPTY") return _duplojs_lang_either.left("file-system-rename-directory-not-empty", error);
16
+ else if (error.code === "EROFS") return _duplojs_lang_either.left("file-system-rename-read-only", error);
17
+ else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-rename-invalid-argument", error);
18
+ else if (error.code === "EBUSY") return _duplojs_lang_either.left("file-system-rename-busy", error);
19
+ else if (error.code === "EXDEV") return _duplojs_lang_either.left("file-system-rename-cross-device", error);
20
+ }
21
+ return _duplojs_lang_either.left("file-system-rename-error", error);
22
+ }
23
+ function handleDenoRenameError(error) {
24
+ if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-rename-not-found", error);
25
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-rename-permission-denied", error);
26
+ if (error instanceof Deno.errors.AlreadyExists) return _duplojs_lang_either.left("file-system-rename-already-exists", error);
27
+ if (error instanceof Deno.errors.IsADirectory) return _duplojs_lang_either.left("file-system-rename-is-directory", error);
28
+ if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-rename-not-directory", error);
29
+ if (error instanceof Deno.errors.InvalidData) return _duplojs_lang_either.left("file-system-rename-invalid-argument", error);
30
+ if (error instanceof Deno.errors.Busy) return _duplojs_lang_either.left("file-system-rename-busy", error);
31
+ return _duplojs_lang_either.left("file-system-rename-error", error);
32
+ }
33
+ const renameImplementation = require_implementor.implementFunction("rename", {
34
+ NODE: async (path, newName) => {
35
+ const fs = await require_implementor.nodeFileSystem.value;
36
+ const parentPath = _duplojs_lang_path.getParentFolderPath(path);
37
+ if (!parentPath) return _duplojs_lang_either.left("file-system-rename-invalid-argument", /* @__PURE__ */ new Error(`Invalid parent path ${path}.`));
38
+ const newPath = _duplojs_lang_path.resolveRelative([parentPath, newName]);
39
+ return fs.rename(path, newPath).then(() => _duplojs_lang_either.right("file-system-rename", newPath)).catch(handleNodeRenameError);
40
+ },
41
+ DENO: (path, newName) => {
42
+ const parentPath = _duplojs_lang_path.getParentFolderPath(path);
43
+ if (!parentPath) return Promise.resolve(_duplojs_lang_either.left("file-system-rename-invalid-argument", /* @__PURE__ */ new Error(`Invalid parent path ${path}.`)));
44
+ const newPath = _duplojs_lang_path.resolveRelative([parentPath, newName]);
45
+ return Deno.rename(path, newPath).then(() => _duplojs_lang_either.right("file-system-rename", newPath)).catch(handleDenoRenameError);
46
+ }
47
+ });
48
+ function rename(...args) {
49
+ if (args.length === 1) {
50
+ const [newName] = args;
51
+ return (path) => renameImplementation(path, newName);
52
+ }
53
+ return renameImplementation(...args);
54
+ }
55
+ //#endregion
56
+ exports.rename = rename;
@@ -0,0 +1,11 @@
1
+ import { FileSystemEither } from './types';
2
+ import * as DPath from "@duplojs/lang/path";
3
+ import * as DEither from "@duplojs/lang/either";
4
+ export type RenameResult = FileSystemEither<DEither.Right<"rename", string & DPath.Path> | DEither.Left<"rename-not-found", unknown> | DEither.Left<"rename-permission-denied", unknown> | DEither.Left<"rename-already-exists", unknown> | DEither.Left<"rename-is-directory", unknown> | DEither.Left<"rename-not-directory", unknown> | DEither.Left<"rename-directory-not-empty", unknown> | DEither.Left<"rename-read-only", unknown> | DEither.Left<"rename-invalid-argument", unknown> | DEither.Left<"rename-busy", unknown> | DEither.Left<"rename-cross-device", unknown> | DEither.Left<"rename-error", unknown>>;
5
+ declare module '../implementor' {
6
+ interface ServerFunction {
7
+ rename(path: string & DPath.Path, newName: string & DPath.Segment): Promise<RenameResult>;
8
+ }
9
+ }
10
+ export declare function rename(newName: string & DPath.Segment): (path: string & DPath.Path) => Promise<RenameResult>;
11
+ export declare function rename(path: string & DPath.Path, newName: string & DPath.Segment): Promise<RenameResult>;