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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,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/rename.ts
5
+ function handleNodeRenameError(error) {
6
+ if (typeof error === "object" && error !== null && "code" in error) {
7
+ if (error.code === "ENOENT") return DEither.left("file-system-rename-not-found", error);
8
+ else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-rename-permission-denied", error);
9
+ else if (error.code === "EEXIST") return DEither.left("file-system-rename-already-exists", error);
10
+ else if (error.code === "EISDIR") return DEither.left("file-system-rename-is-directory", error);
11
+ else if (error.code === "ENOTDIR") return DEither.left("file-system-rename-not-directory", error);
12
+ else if (error.code === "ENOTEMPTY") return DEither.left("file-system-rename-directory-not-empty", error);
13
+ else if (error.code === "EROFS") return DEither.left("file-system-rename-read-only", error);
14
+ else if (error.code === "EINVAL") return DEither.left("file-system-rename-invalid-argument", error);
15
+ else if (error.code === "EBUSY") return DEither.left("file-system-rename-busy", error);
16
+ else if (error.code === "EXDEV") return DEither.left("file-system-rename-cross-device", error);
17
+ }
18
+ return DEither.left("file-system-rename-error", error);
19
+ }
20
+ function handleDenoRenameError(error) {
21
+ if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-rename-not-found", error);
22
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-rename-permission-denied", error);
23
+ if (error instanceof Deno.errors.AlreadyExists) return DEither.left("file-system-rename-already-exists", error);
24
+ if (error instanceof Deno.errors.IsADirectory) return DEither.left("file-system-rename-is-directory", error);
25
+ if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-rename-not-directory", error);
26
+ if (error instanceof Deno.errors.InvalidData) return DEither.left("file-system-rename-invalid-argument", error);
27
+ if (error instanceof Deno.errors.Busy) return DEither.left("file-system-rename-busy", error);
28
+ return DEither.left("file-system-rename-error", error);
29
+ }
30
+ const renameImplementation = implementFunction("rename", {
31
+ NODE: async (path, newName) => {
32
+ const fs = await nodeFileSystem.value;
33
+ const parentPath = DPath.getParentFolderPath(path);
34
+ if (!parentPath) return DEither.left("file-system-rename-invalid-argument", /* @__PURE__ */ new Error(`Invalid parent path ${path}.`));
35
+ const newPath = DPath.resolveRelative([parentPath, newName]);
36
+ return fs.rename(path, newPath).then(() => DEither.right("file-system-rename", newPath)).catch(handleNodeRenameError);
37
+ },
38
+ DENO: (path, newName) => {
39
+ const parentPath = DPath.getParentFolderPath(path);
40
+ if (!parentPath) return Promise.resolve(DEither.left("file-system-rename-invalid-argument", /* @__PURE__ */ new Error(`Invalid parent path ${path}.`)));
41
+ const newPath = DPath.resolveRelative([parentPath, newName]);
42
+ return Deno.rename(path, newPath).then(() => DEither.right("file-system-rename", newPath)).catch(handleDenoRenameError);
43
+ }
44
+ });
45
+ function rename(...args) {
46
+ if (args.length === 1) {
47
+ const [newName] = args;
48
+ return (path) => renameImplementation(path, newName);
49
+ }
50
+ return renameImplementation(...args);
51
+ }
52
+ //#endregion
53
+ export { rename };
@@ -0,0 +1,51 @@
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_implementor = require("../implementor.cjs");
3
+ let _duplojs_lang_common = require("@duplojs/lang/common");
4
+ _duplojs_lang_common = require_runtime.__toESM(_duplojs_lang_common, 1);
5
+ let _duplojs_lang_either = require("@duplojs/lang/either");
6
+ _duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
7
+ //#region scripts/file/setMode.ts
8
+ function handleNodeSetModeError(error) {
9
+ if (typeof error === "object" && error !== null && "code" in error) {
10
+ if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-set-mode-not-found", error);
11
+ else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-set-mode-permission-denied", error);
12
+ else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-set-mode-not-directory", error);
13
+ else if (error.code === "EROFS") return _duplojs_lang_either.left("file-system-set-mode-read-only", error);
14
+ else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-set-mode-invalid-argument", error);
15
+ }
16
+ return _duplojs_lang_either.left("file-system-set-mode-error", error);
17
+ }
18
+ function handleDenoSetModeError(error) {
19
+ if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-set-mode-not-found", error);
20
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-set-mode-permission-denied", error);
21
+ if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-set-mode-not-directory", error);
22
+ if (error instanceof Deno.errors.InvalidData) return _duplojs_lang_either.left("file-system-set-mode-invalid-argument", error);
23
+ return _duplojs_lang_either.left("file-system-set-mode-error", error);
24
+ }
25
+ function calculatePermissions(permissions) {
26
+ if (!permissions) return 0;
27
+ return (permissions.read ? 4 : 0) + (permissions.write ? 2 : 0) + (permissions.exec ? 1 : 0);
28
+ }
29
+ function toMode(mode) {
30
+ if (_duplojs_lang_common.isType(mode, "number")) return mode;
31
+ const special = (mode.setUserId ? 4 : 0) + (mode.setGroupId ? 2 : 0) + (mode.sticky ? 1 : 0);
32
+ const user = calculatePermissions(mode.user);
33
+ const group = calculatePermissions(mode.group);
34
+ const other = calculatePermissions(mode.other);
35
+ return special * 512 + user * 64 + group * 8 + other;
36
+ }
37
+ const setModeImplementation = require_implementor.implementFunction("setMode", {
38
+ NODE: async (path, mode) => {
39
+ return (await require_implementor.nodeFileSystem.value).chmod(path, toMode(mode)).then(() => _duplojs_lang_either.right("file-system-set-mode")).catch(handleNodeSetModeError);
40
+ },
41
+ DENO: (path, mode) => Deno.chmod(path, toMode(mode)).then(() => _duplojs_lang_either.right("file-system-set-mode")).catch(handleDenoSetModeError)
42
+ });
43
+ function setMode(...args) {
44
+ if (args.length === 1) {
45
+ const [mode] = args;
46
+ return (path) => setModeImplementation(path, mode);
47
+ }
48
+ return setModeImplementation(...args);
49
+ }
50
+ //#endregion
51
+ exports.setMode = setMode;
@@ -0,0 +1,26 @@
1
+ import { FileSystemEither } from './types';
2
+ import * as DEither from "@duplojs/lang/either";
3
+ import type * as DPath from "@duplojs/lang/path";
4
+ interface Permissions {
5
+ read?: boolean;
6
+ write?: boolean;
7
+ exec?: boolean;
8
+ }
9
+ interface ModeObject {
10
+ user?: Permissions;
11
+ group?: Permissions;
12
+ other?: Permissions;
13
+ setUserId?: boolean;
14
+ setGroupId?: boolean;
15
+ sticky?: boolean;
16
+ }
17
+ type SetMode = ModeObject | number;
18
+ export type SetModeResult = FileSystemEither<DEither.Right<"set-mode", void> | DEither.Left<"set-mode-not-found", unknown> | DEither.Left<"set-mode-permission-denied", unknown> | DEither.Left<"set-mode-not-directory", unknown> | DEither.Left<"set-mode-read-only", unknown> | DEither.Left<"set-mode-invalid-argument", unknown> | DEither.Left<"set-mode-error", unknown>>;
19
+ declare module '../implementor' {
20
+ interface ServerFunction {
21
+ setMode(path: string & DPath.Path, mode: SetMode): Promise<SetModeResult>;
22
+ }
23
+ }
24
+ export declare function setMode(mode: SetMode): (path: string & DPath.Path) => Promise<SetModeResult>;
25
+ export declare function setMode(path: string & DPath.Path, mode: SetMode): Promise<SetModeResult>;
26
+ export {};
@@ -0,0 +1,48 @@
1
+ import { implementFunction, nodeFileSystem } from "../implementor.mjs";
2
+ import * as DCommon from "@duplojs/lang/common";
3
+ import * as DEither from "@duplojs/lang/either";
4
+ //#region scripts/file/setMode.ts
5
+ function handleNodeSetModeError(error) {
6
+ if (typeof error === "object" && error !== null && "code" in error) {
7
+ if (error.code === "ENOENT") return DEither.left("file-system-set-mode-not-found", error);
8
+ else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-set-mode-permission-denied", error);
9
+ else if (error.code === "ENOTDIR") return DEither.left("file-system-set-mode-not-directory", error);
10
+ else if (error.code === "EROFS") return DEither.left("file-system-set-mode-read-only", error);
11
+ else if (error.code === "EINVAL") return DEither.left("file-system-set-mode-invalid-argument", error);
12
+ }
13
+ return DEither.left("file-system-set-mode-error", error);
14
+ }
15
+ function handleDenoSetModeError(error) {
16
+ if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-set-mode-not-found", error);
17
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-set-mode-permission-denied", error);
18
+ if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-set-mode-not-directory", error);
19
+ if (error instanceof Deno.errors.InvalidData) return DEither.left("file-system-set-mode-invalid-argument", error);
20
+ return DEither.left("file-system-set-mode-error", error);
21
+ }
22
+ function calculatePermissions(permissions) {
23
+ if (!permissions) return 0;
24
+ return (permissions.read ? 4 : 0) + (permissions.write ? 2 : 0) + (permissions.exec ? 1 : 0);
25
+ }
26
+ function toMode(mode) {
27
+ if (DCommon.isType(mode, "number")) return mode;
28
+ const special = (mode.setUserId ? 4 : 0) + (mode.setGroupId ? 2 : 0) + (mode.sticky ? 1 : 0);
29
+ const user = calculatePermissions(mode.user);
30
+ const group = calculatePermissions(mode.group);
31
+ const other = calculatePermissions(mode.other);
32
+ return special * 512 + user * 64 + group * 8 + other;
33
+ }
34
+ const setModeImplementation = implementFunction("setMode", {
35
+ NODE: async (path, mode) => {
36
+ return (await nodeFileSystem.value).chmod(path, toMode(mode)).then(() => DEither.right("file-system-set-mode")).catch(handleNodeSetModeError);
37
+ },
38
+ DENO: (path, mode) => Deno.chmod(path, toMode(mode)).then(() => DEither.right("file-system-set-mode")).catch(handleDenoSetModeError)
39
+ });
40
+ function setMode(...args) {
41
+ if (args.length === 1) {
42
+ const [mode] = args;
43
+ return (path) => setModeImplementation(path, mode);
44
+ }
45
+ return setModeImplementation(...args);
46
+ }
47
+ //#endregion
48
+ export { setMode };
@@ -0,0 +1,37 @@
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/setOwner.ts
6
+ function handleNodeSetOwnerError(error) {
7
+ if (typeof error === "object" && error !== null && "code" in error) {
8
+ if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-set-owner-not-found", error);
9
+ else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-set-owner-permission-denied", error);
10
+ else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-set-owner-not-directory", error);
11
+ else if (error.code === "EROFS") return _duplojs_lang_either.left("file-system-set-owner-read-only", error);
12
+ else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-set-owner-invalid-argument", error);
13
+ }
14
+ return _duplojs_lang_either.left("file-system-set-owner-error", error);
15
+ }
16
+ function handleDenoSetOwnerError(error) {
17
+ if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-set-owner-not-found", error);
18
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-set-owner-permission-denied", error);
19
+ if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-set-owner-not-directory", error);
20
+ if (error instanceof Deno.errors.InvalidData) return _duplojs_lang_either.left("file-system-set-owner-invalid-argument", error);
21
+ return _duplojs_lang_either.left("file-system-set-owner-error", error);
22
+ }
23
+ const setOwnerImplementation = require_implementor.implementFunction("setOwner", {
24
+ NODE: async (path, { userId, groupId }) => {
25
+ return (await require_implementor.nodeFileSystem.value).chown(path, userId, groupId).then(() => _duplojs_lang_either.right("file-system-set-owner")).catch(handleNodeSetOwnerError);
26
+ },
27
+ DENO: (path, { userId, groupId }) => Deno.chown(path, userId, groupId).then(() => _duplojs_lang_either.right("file-system-set-owner")).catch(handleDenoSetOwnerError)
28
+ });
29
+ function setOwner(...args) {
30
+ if (args.length === 1) {
31
+ const [params] = args;
32
+ return (path) => setOwnerImplementation(path, params);
33
+ }
34
+ return setOwnerImplementation(...args);
35
+ }
36
+ //#endregion
37
+ exports.setOwner = setOwner;
@@ -0,0 +1,15 @@
1
+ import { FileSystemEither } from './types';
2
+ import * as DEither from "@duplojs/lang/either";
3
+ import type * as DPath from "@duplojs/lang/path";
4
+ export interface SetOwnerParams {
5
+ userId: number;
6
+ groupId: number;
7
+ }
8
+ export type SetOwnerResult = FileSystemEither<DEither.Right<"set-owner", void> | DEither.Left<"set-owner-not-found", unknown> | DEither.Left<"set-owner-permission-denied", unknown> | DEither.Left<"set-owner-not-directory", unknown> | DEither.Left<"set-owner-read-only", unknown> | DEither.Left<"set-owner-invalid-argument", unknown> | DEither.Left<"set-owner-error", unknown>>;
9
+ declare module '../implementor' {
10
+ interface ServerFunction {
11
+ setOwner(path: string & DPath.Path, params: SetOwnerParams): Promise<SetOwnerResult>;
12
+ }
13
+ }
14
+ export declare function setOwner(params: SetOwnerParams): (path: string & DPath.Path) => Promise<SetOwnerResult>;
15
+ export declare function setOwner(path: string & DPath.Path, params: SetOwnerParams): Promise<SetOwnerResult>;
@@ -0,0 +1,35 @@
1
+ import { implementFunction, nodeFileSystem } from "../implementor.mjs";
2
+ import * as DEither from "@duplojs/lang/either";
3
+ //#region scripts/file/setOwner.ts
4
+ function handleNodeSetOwnerError(error) {
5
+ if (typeof error === "object" && error !== null && "code" in error) {
6
+ if (error.code === "ENOENT") return DEither.left("file-system-set-owner-not-found", error);
7
+ else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-set-owner-permission-denied", error);
8
+ else if (error.code === "ENOTDIR") return DEither.left("file-system-set-owner-not-directory", error);
9
+ else if (error.code === "EROFS") return DEither.left("file-system-set-owner-read-only", error);
10
+ else if (error.code === "EINVAL") return DEither.left("file-system-set-owner-invalid-argument", error);
11
+ }
12
+ return DEither.left("file-system-set-owner-error", error);
13
+ }
14
+ function handleDenoSetOwnerError(error) {
15
+ if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-set-owner-not-found", error);
16
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-set-owner-permission-denied", error);
17
+ if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-set-owner-not-directory", error);
18
+ if (error instanceof Deno.errors.InvalidData) return DEither.left("file-system-set-owner-invalid-argument", error);
19
+ return DEither.left("file-system-set-owner-error", error);
20
+ }
21
+ const setOwnerImplementation = implementFunction("setOwner", {
22
+ NODE: async (path, { userId, groupId }) => {
23
+ return (await nodeFileSystem.value).chown(path, userId, groupId).then(() => DEither.right("file-system-set-owner")).catch(handleNodeSetOwnerError);
24
+ },
25
+ DENO: (path, { userId, groupId }) => Deno.chown(path, userId, groupId).then(() => DEither.right("file-system-set-owner")).catch(handleDenoSetOwnerError)
26
+ });
27
+ function setOwner(...args) {
28
+ if (args.length === 1) {
29
+ const [params] = args;
30
+ return (path) => setOwnerImplementation(path, params);
31
+ }
32
+ return setOwnerImplementation(...args);
33
+ }
34
+ //#endregion
35
+ export { setOwner };
@@ -0,0 +1,39 @@
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_chrono = require("@duplojs/lang/chrono");
6
+ _duplojs_lang_chrono = require_runtime.__toESM(_duplojs_lang_chrono, 1);
7
+ //#region scripts/file/setTime.ts
8
+ function handleNodeSetTimeError(error) {
9
+ if (typeof error === "object" && error !== null && "code" in error) {
10
+ if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-set-time-not-found", error);
11
+ else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-set-time-permission-denied", error);
12
+ else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-set-time-not-directory", error);
13
+ else if (error.code === "EROFS") return _duplojs_lang_either.left("file-system-set-time-read-only", error);
14
+ else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-set-time-invalid-argument", error);
15
+ }
16
+ return _duplojs_lang_either.left("file-system-set-time-error", error);
17
+ }
18
+ function handleDenoSetTimeError(error) {
19
+ if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-set-time-not-found", error);
20
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-set-time-permission-denied", error);
21
+ if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-set-time-not-directory", error);
22
+ if (error instanceof Deno.errors.InvalidData) return _duplojs_lang_either.left("file-system-set-time-invalid-argument", error);
23
+ return _duplojs_lang_either.left("file-system-set-time-error", error);
24
+ }
25
+ const setTimeImplementation = require_implementor.implementFunction("setTime", {
26
+ NODE: async (path, { accessTime, modifiedTime }) => {
27
+ return (await require_implementor.nodeFileSystem.value).utimes(path, _duplojs_lang_chrono.toTimestamp(accessTime), _duplojs_lang_chrono.toTimestamp(modifiedTime)).then(() => _duplojs_lang_either.right("file-system-set-time")).catch(handleNodeSetTimeError);
28
+ },
29
+ DENO: (path, { accessTime, modifiedTime }) => Deno.utime(path, _duplojs_lang_chrono.toTimestamp(accessTime), _duplojs_lang_chrono.toTimestamp(modifiedTime)).then(() => _duplojs_lang_either.right("file-system-set-time")).catch(handleDenoSetTimeError)
30
+ });
31
+ function setTime(...args) {
32
+ if (args.length === 1) {
33
+ const [params] = args;
34
+ return (path) => setTimeImplementation(path, params);
35
+ }
36
+ return setTimeImplementation(...args);
37
+ }
38
+ //#endregion
39
+ exports.setTime = setTime;
@@ -0,0 +1,17 @@
1
+ import { FileSystemEither } from './types';
2
+ import * as DEither from "@duplojs/lang/either";
3
+ import * as DChrono from "@duplojs/lang/chrono";
4
+ import type * as DPath from "@duplojs/lang/path";
5
+ interface SetTimeParams {
6
+ accessTime: DChrono.TheDate;
7
+ modifiedTime: DChrono.TheDate;
8
+ }
9
+ export type SetTimeResult = FileSystemEither<DEither.Right<"set-time", void> | DEither.Left<"set-time-not-found", unknown> | DEither.Left<"set-time-permission-denied", unknown> | DEither.Left<"set-time-not-directory", unknown> | DEither.Left<"set-time-read-only", unknown> | DEither.Left<"set-time-invalid-argument", unknown> | DEither.Left<"set-time-error", unknown>>;
10
+ declare module '../implementor' {
11
+ interface ServerFunction {
12
+ setTime(path: string & DPath.Path, params: SetTimeParams): Promise<SetTimeResult>;
13
+ }
14
+ }
15
+ export declare function setTime(params: SetTimeParams): (path: string & DPath.Path) => Promise<SetTimeResult>;
16
+ export declare function setTime(path: string & DPath.Path, params: SetTimeParams): Promise<SetTimeResult>;
17
+ export {};
@@ -0,0 +1,36 @@
1
+ import { implementFunction, nodeFileSystem } from "../implementor.mjs";
2
+ import * as DEither from "@duplojs/lang/either";
3
+ import * as DChrono from "@duplojs/lang/chrono";
4
+ //#region scripts/file/setTime.ts
5
+ function handleNodeSetTimeError(error) {
6
+ if (typeof error === "object" && error !== null && "code" in error) {
7
+ if (error.code === "ENOENT") return DEither.left("file-system-set-time-not-found", error);
8
+ else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-set-time-permission-denied", error);
9
+ else if (error.code === "ENOTDIR") return DEither.left("file-system-set-time-not-directory", error);
10
+ else if (error.code === "EROFS") return DEither.left("file-system-set-time-read-only", error);
11
+ else if (error.code === "EINVAL") return DEither.left("file-system-set-time-invalid-argument", error);
12
+ }
13
+ return DEither.left("file-system-set-time-error", error);
14
+ }
15
+ function handleDenoSetTimeError(error) {
16
+ if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-set-time-not-found", error);
17
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-set-time-permission-denied", error);
18
+ if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-set-time-not-directory", error);
19
+ if (error instanceof Deno.errors.InvalidData) return DEither.left("file-system-set-time-invalid-argument", error);
20
+ return DEither.left("file-system-set-time-error", error);
21
+ }
22
+ const setTimeImplementation = implementFunction("setTime", {
23
+ NODE: async (path, { accessTime, modifiedTime }) => {
24
+ return (await nodeFileSystem.value).utimes(path, DChrono.toTimestamp(accessTime), DChrono.toTimestamp(modifiedTime)).then(() => DEither.right("file-system-set-time")).catch(handleNodeSetTimeError);
25
+ },
26
+ DENO: (path, { accessTime, modifiedTime }) => Deno.utime(path, DChrono.toTimestamp(accessTime), DChrono.toTimestamp(modifiedTime)).then(() => DEither.right("file-system-set-time")).catch(handleDenoSetTimeError)
27
+ });
28
+ function setTime(...args) {
29
+ if (args.length === 1) {
30
+ const [params] = args;
31
+ return (path) => setTimeImplementation(path, params);
32
+ }
33
+ return setTimeImplementation(...args);
34
+ }
35
+ //#endregion
36
+ export { setTime };
@@ -0,0 +1,85 @@
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_implementor = require("../implementor.cjs");
3
+ let _duplojs_lang_common = require("@duplojs/lang/common");
4
+ _duplojs_lang_common = require_runtime.__toESM(_duplojs_lang_common, 1);
5
+ let _duplojs_lang_either = require("@duplojs/lang/either");
6
+ _duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
7
+ let _duplojs_lang_chrono = require("@duplojs/lang/chrono");
8
+ _duplojs_lang_chrono = require_runtime.__toESM(_duplojs_lang_chrono, 1);
9
+ //#region scripts/file/stat.ts
10
+ function handleNodeStatError(error) {
11
+ if (typeof error === "object" && error !== null && "code" in error) {
12
+ if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-stat-not-found", error);
13
+ else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-stat-permission-denied", error);
14
+ else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-stat-not-directory", error);
15
+ else if (error.code === "EMFILE" || error.code === "ENFILE") return _duplojs_lang_either.left("file-system-stat-too-many-open-files", error);
16
+ else if (error.code === "EBUSY") return _duplojs_lang_either.left("file-system-stat-busy", error);
17
+ }
18
+ return _duplojs_lang_either.left("file-system-stat-error", error);
19
+ }
20
+ function handleDenoStatError(error) {
21
+ if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-stat-not-found", error);
22
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-stat-permission-denied", error);
23
+ if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-stat-not-directory", error);
24
+ if (error instanceof Deno.errors.Busy) return _duplojs_lang_either.left("file-system-stat-busy", error);
25
+ return _duplojs_lang_either.left("file-system-stat-error", error);
26
+ }
27
+ function createStatInfoWithFsSource(source) {
28
+ return {
29
+ isFile: source.isFile(),
30
+ isDirectory: source.isDirectory(),
31
+ isSymlink: source.isSymbolicLink(),
32
+ sizeBytes: source.size,
33
+ modifiedAt: _duplojs_lang_chrono.isSafeTimestamp(source.mtime.getTime()) ? _duplojs_lang_chrono.createDateOrThrow(source.mtime) : null,
34
+ accessedAt: _duplojs_lang_chrono.isSafeTimestamp(source.atime.getTime()) ? _duplojs_lang_chrono.createDateOrThrow(source.atime) : null,
35
+ createdAt: _duplojs_lang_chrono.isSafeTimestamp(source.birthtime.getTime()) ? _duplojs_lang_chrono.createDateOrThrow(source.birthtime) : null,
36
+ changedAt: _duplojs_lang_chrono.isSafeTimestamp(source.ctime.getTime()) ? _duplojs_lang_chrono.createDateOrThrow(source.ctime) : null,
37
+ deviceId: source.dev,
38
+ inode: source.ino,
39
+ permissionsMode: source.mode,
40
+ hardLinkCount: source.nlink,
41
+ ownerUserId: source.uid,
42
+ ownerGroupId: source.gid,
43
+ specialDeviceId: source.rdev,
44
+ ioBlockSize: source.blksize,
45
+ allocatedBlockCount: source.blocks,
46
+ isBlockDevice: source.isBlockDevice(),
47
+ isCharacterDevice: source.isCharacterDevice(),
48
+ isFifo: source.isFIFO(),
49
+ isSocket: source.isSocket()
50
+ };
51
+ }
52
+ function createStatInfoWithDeno(source) {
53
+ return {
54
+ isFile: source.isFile,
55
+ isDirectory: source.isDirectory,
56
+ isSymlink: source.isSymlink,
57
+ sizeBytes: source.size,
58
+ modifiedAt: source.mtime && _duplojs_lang_chrono.isSafeTimestamp(source.mtime.getTime()) ? _duplojs_lang_chrono.createDateOrThrow(source.mtime) : null,
59
+ accessedAt: source.atime && _duplojs_lang_chrono.isSafeTimestamp(source.atime.getTime()) ? _duplojs_lang_chrono.createDateOrThrow(source.atime) : null,
60
+ createdAt: source.birthtime && _duplojs_lang_chrono.isSafeTimestamp(source.birthtime.getTime()) ? _duplojs_lang_chrono.createDateOrThrow(source.birthtime) : null,
61
+ changedAt: source.ctime && _duplojs_lang_chrono.isSafeTimestamp(source.ctime.getTime()) ? _duplojs_lang_chrono.createDateOrThrow(source.ctime) : null,
62
+ deviceId: source.dev,
63
+ inode: source.ino,
64
+ permissionsMode: source.mode,
65
+ hardLinkCount: source.nlink,
66
+ ownerUserId: source.uid,
67
+ ownerGroupId: source.gid,
68
+ specialDeviceId: source.rdev,
69
+ ioBlockSize: source.blksize,
70
+ allocatedBlockCount: source.blocks,
71
+ isBlockDevice: source.isBlockDevice,
72
+ isCharacterDevice: source.isCharDevice,
73
+ isFifo: source.isFifo,
74
+ isSocket: source.isSocket
75
+ };
76
+ }
77
+ const stat = require_implementor.implementFunction("stat", {
78
+ NODE: async (path) => {
79
+ return (await require_implementor.nodeFileSystem.value).stat(path).then(_duplojs_lang_common.innerPipe(createStatInfoWithFsSource, (value) => _duplojs_lang_either.right("file-system-stat", value))).catch(handleNodeStatError);
80
+ },
81
+ DENO: (path) => Deno.stat(path).then(_duplojs_lang_common.innerPipe(createStatInfoWithDeno, (value) => _duplojs_lang_either.right("file-system-stat", value))).catch(handleDenoStatError),
82
+ BUN: (path) => Bun.file(path).stat().then(_duplojs_lang_common.innerPipe(createStatInfoWithFsSource, (value) => _duplojs_lang_either.right("file-system-stat", value))).catch(handleNodeStatError)
83
+ });
84
+ //#endregion
85
+ exports.stat = stat;
@@ -0,0 +1,42 @@
1
+ import { FileSystemEither } from './types';
2
+ import type * as DPath from "@duplojs/lang/path";
3
+ import * as DEither from "@duplojs/lang/either";
4
+ import * as DChrono from "@duplojs/lang/chrono";
5
+ export interface StatInfo {
6
+ /** Type of entry */
7
+ isFile: boolean;
8
+ isDirectory: boolean;
9
+ isSymlink: boolean;
10
+ /** Size in bytes */
11
+ sizeBytes: number;
12
+ /** Timestamps */
13
+ modifiedAt: DChrono.TheDate | null;
14
+ accessedAt: DChrono.TheDate | null;
15
+ createdAt: DChrono.TheDate | null;
16
+ changedAt: DChrono.TheDate | null;
17
+ /** Unix/FS identifiers */
18
+ deviceId: number;
19
+ inode: number | null;
20
+ permissionsMode: number | null;
21
+ hardLinkCount: number | null;
22
+ /** Ownership */
23
+ ownerUserId: number | null;
24
+ ownerGroupId: number | null;
25
+ /** Special device id (if file is a device) */
26
+ specialDeviceId: number | null;
27
+ /** FS allocation */
28
+ ioBlockSize: number | null;
29
+ allocatedBlockCount: number | null;
30
+ /** Special file kinds */
31
+ isBlockDevice: boolean | null;
32
+ isCharacterDevice: boolean | null;
33
+ isFifo: boolean | null;
34
+ isSocket: boolean | null;
35
+ }
36
+ export type StatResult = FileSystemEither<DEither.Right<"stat", StatInfo> | DEither.Left<"stat-not-found", unknown> | DEither.Left<"stat-permission-denied", unknown> | DEither.Left<"stat-not-directory", unknown> | DEither.Left<"stat-too-many-open-files", unknown> | DEither.Left<"stat-busy", unknown> | DEither.Left<"stat-error", unknown>>;
37
+ declare module '../implementor' {
38
+ interface ServerFunction {
39
+ stat(path: string & DPath.Path): Promise<StatResult>;
40
+ }
41
+ }
42
+ export declare const stat: (path: string & DPath.Path) => Promise<StatResult>;
@@ -0,0 +1,81 @@
1
+ import { implementFunction, nodeFileSystem } from "../implementor.mjs";
2
+ import * as DCommon from "@duplojs/lang/common";
3
+ import * as DEither from "@duplojs/lang/either";
4
+ import * as DChrono from "@duplojs/lang/chrono";
5
+ //#region scripts/file/stat.ts
6
+ function handleNodeStatError(error) {
7
+ if (typeof error === "object" && error !== null && "code" in error) {
8
+ if (error.code === "ENOENT") return DEither.left("file-system-stat-not-found", error);
9
+ else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-stat-permission-denied", error);
10
+ else if (error.code === "ENOTDIR") return DEither.left("file-system-stat-not-directory", error);
11
+ else if (error.code === "EMFILE" || error.code === "ENFILE") return DEither.left("file-system-stat-too-many-open-files", error);
12
+ else if (error.code === "EBUSY") return DEither.left("file-system-stat-busy", error);
13
+ }
14
+ return DEither.left("file-system-stat-error", error);
15
+ }
16
+ function handleDenoStatError(error) {
17
+ if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-stat-not-found", error);
18
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-stat-permission-denied", error);
19
+ if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-stat-not-directory", error);
20
+ if (error instanceof Deno.errors.Busy) return DEither.left("file-system-stat-busy", error);
21
+ return DEither.left("file-system-stat-error", error);
22
+ }
23
+ function createStatInfoWithFsSource(source) {
24
+ return {
25
+ isFile: source.isFile(),
26
+ isDirectory: source.isDirectory(),
27
+ isSymlink: source.isSymbolicLink(),
28
+ sizeBytes: source.size,
29
+ modifiedAt: DChrono.isSafeTimestamp(source.mtime.getTime()) ? DChrono.createDateOrThrow(source.mtime) : null,
30
+ accessedAt: DChrono.isSafeTimestamp(source.atime.getTime()) ? DChrono.createDateOrThrow(source.atime) : null,
31
+ createdAt: DChrono.isSafeTimestamp(source.birthtime.getTime()) ? DChrono.createDateOrThrow(source.birthtime) : null,
32
+ changedAt: DChrono.isSafeTimestamp(source.ctime.getTime()) ? DChrono.createDateOrThrow(source.ctime) : null,
33
+ deviceId: source.dev,
34
+ inode: source.ino,
35
+ permissionsMode: source.mode,
36
+ hardLinkCount: source.nlink,
37
+ ownerUserId: source.uid,
38
+ ownerGroupId: source.gid,
39
+ specialDeviceId: source.rdev,
40
+ ioBlockSize: source.blksize,
41
+ allocatedBlockCount: source.blocks,
42
+ isBlockDevice: source.isBlockDevice(),
43
+ isCharacterDevice: source.isCharacterDevice(),
44
+ isFifo: source.isFIFO(),
45
+ isSocket: source.isSocket()
46
+ };
47
+ }
48
+ function createStatInfoWithDeno(source) {
49
+ return {
50
+ isFile: source.isFile,
51
+ isDirectory: source.isDirectory,
52
+ isSymlink: source.isSymlink,
53
+ sizeBytes: source.size,
54
+ modifiedAt: source.mtime && DChrono.isSafeTimestamp(source.mtime.getTime()) ? DChrono.createDateOrThrow(source.mtime) : null,
55
+ accessedAt: source.atime && DChrono.isSafeTimestamp(source.atime.getTime()) ? DChrono.createDateOrThrow(source.atime) : null,
56
+ createdAt: source.birthtime && DChrono.isSafeTimestamp(source.birthtime.getTime()) ? DChrono.createDateOrThrow(source.birthtime) : null,
57
+ changedAt: source.ctime && DChrono.isSafeTimestamp(source.ctime.getTime()) ? DChrono.createDateOrThrow(source.ctime) : null,
58
+ deviceId: source.dev,
59
+ inode: source.ino,
60
+ permissionsMode: source.mode,
61
+ hardLinkCount: source.nlink,
62
+ ownerUserId: source.uid,
63
+ ownerGroupId: source.gid,
64
+ specialDeviceId: source.rdev,
65
+ ioBlockSize: source.blksize,
66
+ allocatedBlockCount: source.blocks,
67
+ isBlockDevice: source.isBlockDevice,
68
+ isCharacterDevice: source.isCharDevice,
69
+ isFifo: source.isFifo,
70
+ isSocket: source.isSocket
71
+ };
72
+ }
73
+ const stat = implementFunction("stat", {
74
+ NODE: async (path) => {
75
+ return (await nodeFileSystem.value).stat(path).then(DCommon.innerPipe(createStatInfoWithFsSource, (value) => DEither.right("file-system-stat", value))).catch(handleNodeStatError);
76
+ },
77
+ DENO: (path) => Deno.stat(path).then(DCommon.innerPipe(createStatInfoWithDeno, (value) => DEither.right("file-system-stat", value))).catch(handleDenoStatError),
78
+ BUN: (path) => Bun.file(path).stat().then(DCommon.innerPipe(createStatInfoWithFsSource, (value) => DEither.right("file-system-stat", value))).catch(handleNodeStatError)
79
+ });
80
+ //#endregion
81
+ export { stat };
@@ -0,0 +1,42 @@
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/symlink.ts
6
+ function handleNodeSymlinkError(error) {
7
+ if (typeof error === "object" && error !== null && "code" in error) {
8
+ if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-symlink-not-found", error);
9
+ else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-symlink-permission-denied", error);
10
+ else if (error.code === "EEXIST") return _duplojs_lang_either.left("file-system-symlink-already-exists", error);
11
+ else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-symlink-not-directory", error);
12
+ else if (error.code === "EROFS") return _duplojs_lang_either.left("file-system-symlink-read-only", error);
13
+ else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-symlink-invalid-argument", error);
14
+ else if (error.code === "EMFILE" || error.code === "ENFILE") return _duplojs_lang_either.left("file-system-symlink-too-many-open-files", error);
15
+ else if (error.code === "EBUSY") return _duplojs_lang_either.left("file-system-symlink-busy", error);
16
+ }
17
+ return _duplojs_lang_either.left("file-system-symlink-error", error);
18
+ }
19
+ function handleDenoSymlinkError(error) {
20
+ if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-symlink-not-found", error);
21
+ if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-symlink-permission-denied", error);
22
+ if (error instanceof Deno.errors.AlreadyExists) return _duplojs_lang_either.left("file-system-symlink-already-exists", error);
23
+ if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-symlink-not-directory", error);
24
+ if (error instanceof Deno.errors.InvalidData) return _duplojs_lang_either.left("file-system-symlink-invalid-argument", error);
25
+ if (error instanceof Deno.errors.Busy) return _duplojs_lang_either.left("file-system-symlink-busy", error);
26
+ return _duplojs_lang_either.left("file-system-symlink-error", error);
27
+ }
28
+ const symlinkImplementation = require_implementor.implementFunction("symlink", {
29
+ NODE: async (oldPath, newPath, params) => {
30
+ return (await require_implementor.nodeFileSystem.value).symlink(oldPath, newPath, params?.type).then(() => _duplojs_lang_either.right("file-system-symlink")).catch(handleNodeSymlinkError);
31
+ },
32
+ DENO: (oldPath, newPath, params) => Deno.symlink(oldPath, newPath, params).then(() => _duplojs_lang_either.right("file-system-symlink")).catch(handleDenoSymlinkError)
33
+ });
34
+ function symlink(...args) {
35
+ if (args.length === 1) {
36
+ const [newPath] = args;
37
+ return (oldPath) => symlinkImplementation(oldPath, newPath);
38
+ }
39
+ return symlinkImplementation(...args);
40
+ }
41
+ //#endregion
42
+ exports.symlink = symlink;