kiriya 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/LICENSE +21 -0
  3. package/README.md +87 -0
  4. package/dist/src/config/clean-rules.js +39 -0
  5. package/dist/src/config/config-keys.js +24 -0
  6. package/dist/src/config/dependency-directories.js +16 -0
  7. package/dist/src/config/modules.js +38 -0
  8. package/dist/src/config/protected-paths.js +32 -0
  9. package/dist/src/config/rebuildable-directories.js +20 -0
  10. package/dist/src/core/application/command-registry.js +57 -0
  11. package/dist/src/core/application/config-values.js +33 -0
  12. package/dist/src/core/application/path-guard.js +69 -0
  13. package/dist/src/core/application/paths.js +77 -0
  14. package/dist/src/core/application/plugin-loader.js +100 -0
  15. package/dist/src/core/application/process-ending.js +28 -0
  16. package/dist/src/core/application/root-scope.js +123 -0
  17. package/dist/src/core/application/safety.js +26 -0
  18. package/dist/src/core/application/text-input.js +44 -0
  19. package/dist/src/core/application/walk.js +34 -0
  20. package/dist/src/core/domain/command.js +8 -0
  21. package/dist/src/core/domain/encodings.js +70 -0
  22. package/dist/src/core/domain/errors.js +49 -0
  23. package/dist/src/core/domain/glob.js +57 -0
  24. package/dist/src/core/domain/global-options.js +10 -0
  25. package/dist/src/core/domain/input-schema.js +54 -0
  26. package/dist/src/core/domain/message.js +7 -0
  27. package/dist/src/core/domain/module.js +2 -0
  28. package/dist/src/core/domain/names.js +22 -0
  29. package/dist/src/core/domain/ports/clipboard.js +2 -0
  30. package/dist/src/core/domain/ports/clock.js +2 -0
  31. package/dist/src/core/domain/ports/command-catalog.js +2 -0
  32. package/dist/src/core/domain/ports/compression.js +2 -0
  33. package/dist/src/core/domain/ports/config-store.js +2 -0
  34. package/dist/src/core/domain/ports/confirmation.js +2 -0
  35. package/dist/src/core/domain/ports/environment.js +2 -0
  36. package/dist/src/core/domain/ports/file-content.js +2 -0
  37. package/dist/src/core/domain/ports/file-system.js +2 -0
  38. package/dist/src/core/domain/ports/hasher.js +2 -0
  39. package/dist/src/core/domain/ports/network.js +2 -0
  40. package/dist/src/core/domain/ports/opener.js +2 -0
  41. package/dist/src/core/domain/ports/passthrough.js +2 -0
  42. package/dist/src/core/domain/ports/plugin-inventory.js +2 -0
  43. package/dist/src/core/domain/ports/plugin-source.js +2 -0
  44. package/dist/src/core/domain/ports/port-table.js +2 -0
  45. package/dist/src/core/domain/ports/process-runner.js +2 -0
  46. package/dist/src/core/domain/ports/process-table.js +2 -0
  47. package/dist/src/core/domain/ports/protected-paths.js +2 -0
  48. package/dist/src/core/domain/ports/random-source.js +2 -0
  49. package/dist/src/core/domain/ports/standard-input.js +2 -0
  50. package/dist/src/core/domain/ports/system-info.js +2 -0
  51. package/dist/src/core/domain/ports/trash.js +2 -0
  52. package/dist/src/core/domain/secrets.js +59 -0
  53. package/dist/src/core/domain/targets.js +41 -0
  54. package/dist/src/core/domain/text-case.js +39 -0
  55. package/dist/src/core/domain/values/bytes.js +13 -0
  56. package/dist/src/core/domain/view.js +2 -0
  57. package/dist/src/core/infrastructure/node/can-listen.js +10 -0
  58. package/dist/src/core/infrastructure/node/closed-standard-input.adapter.js +12 -0
  59. package/dist/src/core/infrastructure/node/config-location.js +27 -0
  60. package/dist/src/core/infrastructure/node/fs-errors.js +22 -0
  61. package/dist/src/core/infrastructure/node/json-config-store.adapter.js +69 -0
  62. package/dist/src/core/infrastructure/node/node-compression.adapter.js +82 -0
  63. package/dist/src/core/infrastructure/node/node-environment.adapter.js +21 -0
  64. package/dist/src/core/infrastructure/node/node-file-content.adapter.js +99 -0
  65. package/dist/src/core/infrastructure/node/node-file-system.adapter.js +169 -0
  66. package/dist/src/core/infrastructure/node/node-hasher.adapter.js +32 -0
  67. package/dist/src/core/infrastructure/node/node-network.adapter.js +168 -0
  68. package/dist/src/core/infrastructure/node/node-plugin-source.adapter.js +89 -0
  69. package/dist/src/core/infrastructure/node/node-process-runner.adapter.js +48 -0
  70. package/dist/src/core/infrastructure/node/node-random-source.adapter.js +7 -0
  71. package/dist/src/core/infrastructure/node/node-standard-input.adapter.js +24 -0
  72. package/dist/src/core/infrastructure/node/node-system-info.adapter.js +63 -0
  73. package/dist/src/core/infrastructure/node/process-signals.js +51 -0
  74. package/dist/src/core/infrastructure/node/run-program.js +65 -0
  75. package/dist/src/core/infrastructure/node/system-clock.adapter.js +22 -0
  76. package/dist/src/core/infrastructure/node/typed-programs.js +45 -0
  77. package/dist/src/core/infrastructure/platform/linux/freedesktop-trash.adapter.js +115 -0
  78. package/dist/src/core/infrastructure/platform/linux/linux-clipboard.adapter.js +70 -0
  79. package/dist/src/core/infrastructure/platform/linux/linux-opener.adapter.js +21 -0
  80. package/dist/src/core/infrastructure/platform/linux/linux-port-table.adapter.js +97 -0
  81. package/dist/src/core/infrastructure/platform/linux/linux-process-table.adapter.js +61 -0
  82. package/dist/src/core/infrastructure/platform/macos/macos-clipboard.adapter.js +29 -0
  83. package/dist/src/core/infrastructure/platform/macos/macos-opener.adapter.js +13 -0
  84. package/dist/src/core/infrastructure/platform/macos/macos-port-table.adapter.js +86 -0
  85. package/dist/src/core/infrastructure/platform/macos/macos-process-table.adapter.js +62 -0
  86. package/dist/src/core/infrastructure/platform/macos/macos-trash.adapter.js +64 -0
  87. package/dist/src/core/infrastructure/platform/windows/system32.js +6 -0
  88. package/dist/src/core/infrastructure/platform/windows/windows-clipboard.adapter.js +50 -0
  89. package/dist/src/core/infrastructure/platform/windows/windows-opener.adapter.js +11 -0
  90. package/dist/src/core/infrastructure/platform/windows/windows-port-table.adapter.js +38 -0
  91. package/dist/src/core/infrastructure/platform/windows/windows-process-table.adapter.js +134 -0
  92. package/dist/src/core/infrastructure/platform/windows/windows-trash.adapter.js +86 -0
  93. package/dist/src/core/presentation/cli/argv.js +83 -0
  94. package/dist/src/core/presentation/cli/cli-application.js +201 -0
  95. package/dist/src/core/presentation/cli/cli-view-format.js +46 -0
  96. package/dist/src/core/presentation/cli/help.js +202 -0
  97. package/dist/src/core/presentation/cli/json-output.js +28 -0
  98. package/dist/src/core/presentation/cli/style.js +21 -0
  99. package/dist/src/core/presentation/cli/suggest.js +25 -0
  100. package/dist/src/core/presentation/cli/terminal-confirmation.js +63 -0
  101. package/dist/src/core/presentation/ended-processes.js +18 -0
  102. package/dist/src/core/presentation/i18n/translator.js +23 -0
  103. package/dist/src/core/presentation/list-preview.js +10 -0
  104. package/dist/src/core/presentation/mcp/elicitation.js +55 -0
  105. package/dist/src/core/presentation/mcp/mcp-application.js +60 -0
  106. package/dist/src/core/presentation/mcp/mcp-confirmation.js +59 -0
  107. package/dist/src/core/presentation/mcp/mcp-server.js +355 -0
  108. package/dist/src/core/presentation/mcp/protocol.js +32 -0
  109. package/dist/src/core/presentation/mcp/request-state.js +66 -0
  110. package/dist/src/core/presentation/mcp/tool-definitions.js +149 -0
  111. package/dist/src/core/presentation/mcp/tool-results.js +56 -0
  112. package/dist/src/i18n/locales/en.js +827 -0
  113. package/dist/src/main.js +154 -0
  114. package/dist/src/modules/archive/application/archive-sources.js +55 -0
  115. package/dist/src/modules/archive/application/create-tar.use-case.js +123 -0
  116. package/dist/src/modules/archive/application/create-zip.use-case.js +106 -0
  117. package/dist/src/modules/archive/application/extract-tar.use-case.js +240 -0
  118. package/dist/src/modules/archive/application/extract-zip.use-case.js +181 -0
  119. package/dist/src/modules/archive/application/tar-reader.js +45 -0
  120. package/dist/src/modules/archive/application/zip-reader.js +57 -0
  121. package/dist/src/modules/archive/archive.module.js +27 -0
  122. package/dist/src/modules/archive/domain/crc32.js +18 -0
  123. package/dist/src/modules/archive/domain/tar-format.js +97 -0
  124. package/dist/src/modules/archive/domain/tar-stream.js +223 -0
  125. package/dist/src/modules/archive/domain/zip-format.js +158 -0
  126. package/dist/src/modules/archive/presentation/tar.view.js +17 -0
  127. package/dist/src/modules/archive/presentation/untar.view.js +30 -0
  128. package/dist/src/modules/archive/presentation/unzip.view.js +24 -0
  129. package/dist/src/modules/archive/presentation/zip.view.js +17 -0
  130. package/dist/src/modules/clip/application/copy-text.use-case.js +43 -0
  131. package/dist/src/modules/clip/application/paste-text.use-case.js +25 -0
  132. package/dist/src/modules/clip/clip.module.js +16 -0
  133. package/dist/src/modules/clip/presentation/clip.views.js +7 -0
  134. package/dist/src/modules/completion/application/print-script.use-case.js +38 -0
  135. package/dist/src/modules/completion/application/suggest-words.use-case.js +37 -0
  136. package/dist/src/modules/completion/completion.module.js +14 -0
  137. package/dist/src/modules/completion/domain/scripts.js +91 -0
  138. package/dist/src/modules/completion/domain/suggest.js +134 -0
  139. package/dist/src/modules/completion/presentation/completion.views.js +6 -0
  140. package/dist/src/modules/config/application/config-commands.js +14 -0
  141. package/dist/src/modules/config/application/get-setting.use-case.js +25 -0
  142. package/dist/src/modules/config/application/list-config-keys.use-case.js +26 -0
  143. package/dist/src/modules/config/application/list-settings.use-case.js +28 -0
  144. package/dist/src/modules/config/application/set-setting.use-case.js +53 -0
  145. package/dist/src/modules/config/application/show-config-path.use-case.js +21 -0
  146. package/dist/src/modules/config/application/unset-setting.use-case.js +28 -0
  147. package/dist/src/modules/config/config.module.js +28 -0
  148. package/dist/src/modules/config/presentation/config.views.js +33 -0
  149. package/dist/src/modules/convert/application/convert-case.use-case.js +38 -0
  150. package/dist/src/modules/convert/application/convert-codecs.use-case.js +92 -0
  151. package/dist/src/modules/convert/application/convert-input.js +16 -0
  152. package/dist/src/modules/convert/application/convert-json.use-case.js +51 -0
  153. package/dist/src/modules/convert/application/convert-time.use-case.js +39 -0
  154. package/dist/src/modules/convert/application/decode-jwt.use-case.js +52 -0
  155. package/dist/src/modules/convert/convert.module.js +29 -0
  156. package/dist/src/modules/convert/domain/json-syntax.js +135 -0
  157. package/dist/src/modules/convert/domain/jwt.js +29 -0
  158. package/dist/src/modules/convert/domain/moments.js +20 -0
  159. package/dist/src/modules/convert/presentation/convert.views.js +44 -0
  160. package/dist/src/modules/docker/application/clean-engine.use-case.js +77 -0
  161. package/dist/src/modules/docker/application/compose-project.js +45 -0
  162. package/dist/src/modules/docker/application/docker-engine.js +40 -0
  163. package/dist/src/modules/docker/application/list-containers.use-case.js +69 -0
  164. package/dist/src/modules/docker/application/run-compose.use-case.js +83 -0
  165. package/dist/src/modules/docker/application/show-logs.use-case.js +51 -0
  166. package/dist/src/modules/docker/application/stop-project.use-case.js +56 -0
  167. package/dist/src/modules/docker/docker.module.js +23 -0
  168. package/dist/src/modules/docker/domain/compose-file.js +105 -0
  169. package/dist/src/modules/docker/domain/engine-output.js +65 -0
  170. package/dist/src/modules/docker/presentation/docker.views.js +63 -0
  171. package/dist/src/modules/doctor/application/run-checks.use-case.js +128 -0
  172. package/dist/src/modules/doctor/doctor.module.js +13 -0
  173. package/dist/src/modules/doctor/domain/versions.js +22 -0
  174. package/dist/src/modules/doctor/presentation/doctor.view.js +30 -0
  175. package/dist/src/modules/env/application/check-dotenv.use-case.js +116 -0
  176. package/dist/src/modules/env/application/inspect-path.use-case.js +71 -0
  177. package/dist/src/modules/env/application/path-entries.js +28 -0
  178. package/dist/src/modules/env/application/show-variables.use-case.js +47 -0
  179. package/dist/src/modules/env/domain/dotenv.js +62 -0
  180. package/dist/src/modules/env/env.module.js +17 -0
  181. package/dist/src/modules/env/presentation/env.views.js +43 -0
  182. package/dist/src/modules/files/application/clean-builds.use-case.js +149 -0
  183. package/dist/src/modules/files/application/compare-paths.use-case.js +127 -0
  184. package/dist/src/modules/files/application/copy-paths.use-case.js +101 -0
  185. package/dist/src/modules/files/application/create-paths.use-case.js +85 -0
  186. package/dist/src/modules/files/application/delete-paths.use-case.js +127 -0
  187. package/dist/src/modules/files/application/find-duplicates.use-case.js +105 -0
  188. package/dist/src/modules/files/application/find-files.use-case.js +131 -0
  189. package/dist/src/modules/files/application/hash-files.use-case.js +73 -0
  190. package/dist/src/modules/files/application/list-entries.use-case.js +87 -0
  191. package/dist/src/modules/files/application/measure-folders.use-case.js +102 -0
  192. package/dist/src/modules/files/application/move-entry.js +19 -0
  193. package/dist/src/modules/files/application/move-paths.use-case.js +82 -0
  194. package/dist/src/modules/files/application/read-text.use-case.js +92 -0
  195. package/dist/src/modules/files/application/rename-paths.use-case.js +184 -0
  196. package/dist/src/modules/files/application/replace-text.use-case.js +146 -0
  197. package/dist/src/modules/files/application/search-text.use-case.js +115 -0
  198. package/dist/src/modules/files/application/show-info.use-case.js +80 -0
  199. package/dist/src/modules/files/application/show-tree.use-case.js +75 -0
  200. package/dist/src/modules/files/application/sync-folders.use-case.js +162 -0
  201. package/dist/src/modules/files/application/text-files.js +46 -0
  202. package/dist/src/modules/files/application/transfers.js +35 -0
  203. package/dist/src/modules/files/domain/case-style.js +18 -0
  204. package/dist/src/modules/files/domain/filters.js +9 -0
  205. package/dist/src/modules/files/domain/sync-plan.js +35 -0
  206. package/dist/src/modules/files/domain/text-encoding.js +75 -0
  207. package/dist/src/modules/files/domain/values.js +28 -0
  208. package/dist/src/modules/files/files.module.js +70 -0
  209. package/dist/src/modules/files/presentation/clean.view.js +15 -0
  210. package/dist/src/modules/files/presentation/compare.view.js +50 -0
  211. package/dist/src/modules/files/presentation/copy.view.js +17 -0
  212. package/dist/src/modules/files/presentation/delete.view.js +16 -0
  213. package/dist/src/modules/files/presentation/dupes.view.js +20 -0
  214. package/dist/src/modules/files/presentation/find.view.js +16 -0
  215. package/dist/src/modules/files/presentation/grep.view.js +27 -0
  216. package/dist/src/modules/files/presentation/hash.view.js +15 -0
  217. package/dist/src/modules/files/presentation/info.view.js +36 -0
  218. package/dist/src/modules/files/presentation/list.view.js +17 -0
  219. package/dist/src/modules/files/presentation/move.view.js +14 -0
  220. package/dist/src/modules/files/presentation/new.view.js +8 -0
  221. package/dist/src/modules/files/presentation/read.view.js +6 -0
  222. package/dist/src/modules/files/presentation/rename.view.js +16 -0
  223. package/dist/src/modules/files/presentation/replace.view.js +26 -0
  224. package/dist/src/modules/files/presentation/size.view.js +24 -0
  225. package/dist/src/modules/files/presentation/sync.view.js +37 -0
  226. package/dist/src/modules/files/presentation/tree.view.js +22 -0
  227. package/dist/src/modules/gen/application/gen-options.js +18 -0
  228. package/dist/src/modules/gen/application/generate-passwords.use-case.js +39 -0
  229. package/dist/src/modules/gen/application/generate-tokens.use-case.js +38 -0
  230. package/dist/src/modules/gen/application/generate-ulids.use-case.js +40 -0
  231. package/dist/src/modules/gen/application/generate-uuids.use-case.js +32 -0
  232. package/dist/src/modules/gen/domain/identifiers.js +65 -0
  233. package/dist/src/modules/gen/domain/secrets.js +43 -0
  234. package/dist/src/modules/gen/gen.module.js +20 -0
  235. package/dist/src/modules/git/application/fetch-repositories.use-case.js +50 -0
  236. package/dist/src/modules/git/application/git-client.js +62 -0
  237. package/dist/src/modules/git/application/pull-repositories.use-case.js +67 -0
  238. package/dist/src/modules/git/application/repositories.js +67 -0
  239. package/dist/src/modules/git/application/show-status.use-case.js +49 -0
  240. package/dist/src/modules/git/application/switch-branch.use-case.js +118 -0
  241. package/dist/src/modules/git/domain/repository-status.js +37 -0
  242. package/dist/src/modules/git/git.module.js +25 -0
  243. package/dist/src/modules/git/presentation/git.views.js +100 -0
  244. package/dist/src/modules/net/application/check-connection.use-case.js +71 -0
  245. package/dist/src/modules/net/application/list-addresses.use-case.js +29 -0
  246. package/dist/src/modules/net/application/lookup-name.use-case.js +55 -0
  247. package/dist/src/modules/net/net.module.js +17 -0
  248. package/dist/src/modules/net/presentation/net.views.js +39 -0
  249. package/dist/src/modules/open/application/open-target.use-case.js +53 -0
  250. package/dist/src/modules/open/domain/targets.js +45 -0
  251. package/dist/src/modules/open/open.module.js +12 -0
  252. package/dist/src/modules/open/presentation/open.view.js +6 -0
  253. package/dist/src/modules/port/application/end-port-owners.use-case.js +68 -0
  254. package/dist/src/modules/port/application/find-free-port.use-case.js +40 -0
  255. package/dist/src/modules/port/application/find-listeners.use-case.js +34 -0
  256. package/dist/src/modules/port/application/port-owners.js +25 -0
  257. package/dist/src/modules/port/domain/port-number.js +8 -0
  258. package/dist/src/modules/port/port.module.js +17 -0
  259. package/dist/src/modules/port/presentation/port.views.js +27 -0
  260. package/dist/src/modules/proc/application/end-processes.use-case.js +77 -0
  261. package/dist/src/modules/proc/application/find-processes.use-case.js +50 -0
  262. package/dist/src/modules/proc/application/list-processes.use-case.js +41 -0
  263. package/dist/src/modules/proc/application/show-tree.use-case.js +40 -0
  264. package/dist/src/modules/proc/domain/process-tree.js +55 -0
  265. package/dist/src/modules/proc/presentation/proc.views.js +28 -0
  266. package/dist/src/modules/proc/proc.module.js +19 -0
  267. package/dist/src/modules/sys/application/create-report.use-case.js +30 -0
  268. package/dist/src/modules/sys/application/find-tools.use-case.js +20 -0
  269. package/dist/src/modules/sys/application/machine-facts.js +44 -0
  270. package/dist/src/modules/sys/application/show-info.use-case.js +29 -0
  271. package/dist/src/modules/sys/domain/tools.js +17 -0
  272. package/dist/src/modules/sys/presentation/sys.views.js +67 -0
  273. package/dist/src/modules/sys/sys.module.js +17 -0
  274. package/dist/src/modules/wait/application/poll.js +26 -0
  275. package/dist/src/modules/wait/application/wait-file.use-case.js +55 -0
  276. package/dist/src/modules/wait/application/wait-port.use-case.js +76 -0
  277. package/dist/src/modules/wait/application/wait-url.use-case.js +71 -0
  278. package/dist/src/modules/wait/domain/reasons.js +14 -0
  279. package/dist/src/modules/wait/domain/wait-input.js +50 -0
  280. package/dist/src/modules/wait/presentation/wait.views.js +31 -0
  281. package/dist/src/modules/wait/wait.module.js +21 -0
  282. package/package.json +57 -0
@@ -0,0 +1,50 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ import { previewLines } from "../../../core/presentation/list-preview.js";
3
+ const FOLDER_PREVIEW = 50;
4
+ export const compareView = (output, format) => {
5
+ const lines = [`${format.red("a")} ${output.a}`, `${format.green("b")} ${output.b}`, ""];
6
+ if (output.kind === "files") {
7
+ const text = output.text;
8
+ if (output.identical) {
9
+ lines.push(format.green(format.text(message("files.compare.identical", { size: format.bytes(output.sizeA) }))));
10
+ }
11
+ else if (text === null) {
12
+ const sizes = { sizeA: format.bytes(output.sizeA), sizeB: format.bytes(output.sizeB) };
13
+ lines.push(format.text(message("files.compare.files-differ", sizes)));
14
+ }
15
+ else if (text.sameText) {
16
+ const encodings = { encodingA: text.encodingA, encodingB: text.encodingB };
17
+ lines.push(format.text(message("files.compare.same-text", encodings)));
18
+ }
19
+ else {
20
+ const end = format.dim(format.text(message("files.compare.end-of-file")));
21
+ const counts = { line: text.line, linesA: text.linesA, linesB: text.linesB };
22
+ lines.push(format.text(message("files.compare.first-difference", counts)), ` ${format.red("a")} ${text.lineA ?? end}`, ` ${format.green("b")} ${text.lineB ?? end}`);
23
+ }
24
+ return lines;
25
+ }
26
+ const sections = [
27
+ ["files.compare.only-in-a", output.onlyInA],
28
+ ["files.compare.only-in-b", output.onlyInB],
29
+ [
30
+ "files.compare.changed",
31
+ output.different.map((item) => item.reason === "kind" ? format.text(message("files.compare.kind-differs", { path: item.path })) : item.path),
32
+ ],
33
+ ];
34
+ for (const [key, items] of sections) {
35
+ if (items.length === 0)
36
+ continue;
37
+ lines.push(format.bold(format.text(message(key, { count: items.length }))));
38
+ lines.push(...previewLines(items, FOLDER_PREVIEW, (item) => ` ${item}`, format), "");
39
+ }
40
+ const differences = output.onlyInA.length + output.onlyInB.length + output.different.length;
41
+ lines.push(differences === 0
42
+ ? format.green(format.text(message("files.compare.identical-folders", { count: output.entries })))
43
+ : format.text(message("files.compare.folder-total", {
44
+ onlyA: output.onlyInA.length,
45
+ onlyB: output.onlyInB.length,
46
+ different: output.different.length,
47
+ })));
48
+ return lines;
49
+ };
50
+ //# sourceMappingURL=compare.view.js.map
@@ -0,0 +1,17 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ export const copyView = (output, format) => {
3
+ const exists = format.yellow(format.text(message("files.transfer.exists-note")));
4
+ const lines = output.items.map((item) => {
5
+ const note = item.conflict ? ` ${exists}` : "";
6
+ return ` ${format.path(item.source)} -> ${format.path(item.destination)} ${format.dim(format.bytes(item.bytes))}${note}`;
7
+ });
8
+ const conflicts = output.conflicts > 0
9
+ ? `, ${format.text(message("files.transfer.conflicts-note", { count: output.conflicts }))}`
10
+ : "";
11
+ lines.push("", `${format.text(message("files.copy.total", { count: output.items.length, size: format.bytes(output.bytes) }))}${conflicts}`);
12
+ const copied = output.items.filter((item) => item.outcome === "copied").length;
13
+ if (copied > 0)
14
+ lines.push(format.green(format.text(message("files.copy.done", { count: copied }))));
15
+ return lines;
16
+ };
17
+ //# sourceMappingURL=copy.view.js.map
@@ -0,0 +1,16 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ export const deleteView = (output, format) => {
3
+ const lines = [];
4
+ for (const item of output.items) {
5
+ const shown = format.path(item.path) + (item.kind === "directory" ? "/" : "");
6
+ if (item.outcome === "planned")
7
+ lines.push(` ${shown} ${format.dim(format.bytes(item.bytes))}`);
8
+ if (item.outcome === "trashed")
9
+ lines.push(format.green(format.text(message("files.delete.trashed", { path: shown }))));
10
+ if (item.outcome === "deleted")
11
+ lines.push(format.green(format.text(message("files.delete.deleted", { path: shown }))));
12
+ }
13
+ lines.push("", format.text(message("files.delete.total", { count: output.items.length, size: format.bytes(output.bytes) })));
14
+ return lines;
15
+ };
16
+ //# sourceMappingURL=delete.view.js.map
@@ -0,0 +1,20 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ export const dupesView = (output, format) => {
3
+ const lines = [];
4
+ for (const group of output.groups) {
5
+ const extra = message("files.dupes.extra", { size: format.bytes(group.size * (group.paths.length - 1)) });
6
+ lines.push(`${format.bold(`${format.bytes(group.size)} × ${group.paths.length}`)} ${format.dim(format.text(extra))}`);
7
+ for (const item of group.paths)
8
+ lines.push(` ${format.path(item)}`);
9
+ lines.push("");
10
+ }
11
+ lines.push(format.text(output.groups.length === 0
12
+ ? message("files.dupes.none", { checked: output.checked })
13
+ : message("files.dupes.total", {
14
+ groups: output.groups.length,
15
+ size: format.bytes(output.extraBytes),
16
+ checked: output.checked,
17
+ })));
18
+ return lines;
19
+ };
20
+ //# sourceMappingURL=dupes.view.js.map
@@ -0,0 +1,16 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ export const findView = (output, format) => {
3
+ const lines = output.matches.map((match) => {
4
+ const size = match.kind === "directory" ? "" : format.bytes(match.size);
5
+ const shown = format.path(match.path) + (match.kind === "directory" ? "/" : "");
6
+ return ` ${format.time(match.modifiedMs)} ${size.padStart(9)} ${shown}`;
7
+ });
8
+ if (output.total > output.matches.length) {
9
+ lines.push(format.dim(format.text(message("files.find.more", { count: output.total - output.matches.length }))));
10
+ }
11
+ lines.push("", output.total === 0
12
+ ? format.text(message("files.find.none"))
13
+ : format.text(message("files.find.total", { count: output.total, size: format.bytes(output.totalBytes) })));
14
+ return lines;
15
+ };
16
+ //# sourceMappingURL=find.view.js.map
@@ -0,0 +1,27 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ export const grepView = (output, format) => {
3
+ const lines = [];
4
+ if (output.mode === "lines") {
5
+ for (const match of output.lines) {
6
+ lines.push(`${format.bold(format.path(match.path))}:${match.line}: ${match.text}`);
7
+ }
8
+ if (output.matches > output.lines.length) {
9
+ const more = output.matches - output.lines.length;
10
+ lines.push(format.dim(format.text(message("files.grep.more", { count: more }))));
11
+ }
12
+ }
13
+ else {
14
+ for (const file of output.files) {
15
+ lines.push(output.mode === "files" ? format.path(file.path) : `${format.path(file.path)}: ${file.count}`);
16
+ }
17
+ }
18
+ const skipped = output.skipped > 0 ? format.dim(` · ${format.text(message("files.grep.skipped", { count: output.skipped }))}`) : "";
19
+ const total = message("files.grep.total", {
20
+ matches: output.matches,
21
+ matched: output.files.length,
22
+ checked: output.checked,
23
+ });
24
+ lines.push("", `${format.text(total)}${skipped}`);
25
+ return lines;
26
+ };
27
+ //# sourceMappingURL=grep.view.js.map
@@ -0,0 +1,15 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ /** `<hash> <path>`, as sha256sum prints it; a failed check is reported on stderr. */
3
+ export const hashView = (output, format) => {
4
+ if (output.check !== null) {
5
+ if (!output.check.matches)
6
+ return [];
7
+ const matches = message("files.hash.matches", {
8
+ algorithm: output.algorithm,
9
+ path: format.path(output.check.path),
10
+ });
11
+ return [format.green(format.text(matches))];
12
+ }
13
+ return output.files.map((file) => `${file.hash} ${format.path(file.path)}`);
14
+ };
15
+ //# sourceMappingURL=hash.view.js.map
@@ -0,0 +1,36 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ const KIND_KEYS = {
3
+ file: "core.kind.file",
4
+ directory: "core.kind.directory",
5
+ symlink: "core.kind.symlink",
6
+ other: "core.kind.other",
7
+ };
8
+ export const infoView = (output, format) => {
9
+ const label = (key) => format.text(message(key));
10
+ const lines = [];
11
+ for (const item of output.items) {
12
+ const rows = [[label("files.info.label.type"), label(KIND_KEYS[item.kind])]];
13
+ if (item.target !== null)
14
+ rows.push([label("files.info.label.target"), item.target]);
15
+ const size = item.contents === null
16
+ ? message("files.info.size-file", { size: format.bytes(item.bytes), bytes: item.bytes })
17
+ : message("files.info.size-folder", {
18
+ size: format.bytes(item.bytes),
19
+ files: item.contents.files,
20
+ folders: item.contents.directories,
21
+ });
22
+ const access = item.permissions === null
23
+ ? label(item.writable ? "files.info.read-write" : "files.info.read-only")
24
+ : `${item.permissions.symbolic} (${item.permissions.octal})`;
25
+ rows.push([label("files.info.label.size"), format.text(size)], [label("files.info.label.created"), format.time(item.createdMs)], [label("files.info.label.modified"), format.time(item.modifiedMs)], [label("files.info.label.accessed"), format.time(item.accessedMs)], [label("files.info.label.access"), access], [label("files.info.label.hidden"), label(item.hidden ? "files.info.hidden-yes" : "files.info.hidden-no")]);
26
+ if (item.hash !== null)
27
+ rows.push([item.hash.algorithm, item.hash.value]);
28
+ const width = Math.max(...rows.map(([name]) => name.length));
29
+ lines.push(format.bold(format.path(item.path)));
30
+ for (const [name, value] of rows)
31
+ lines.push(` ${name.padEnd(width)} ${value}`);
32
+ lines.push("");
33
+ }
34
+ return lines;
35
+ };
36
+ //# sourceMappingURL=info.view.js.map
@@ -0,0 +1,17 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ export const listView = (output, format) => {
3
+ const lines = [format.bold(format.path(output.path)), ""];
4
+ for (const entry of output.entries) {
5
+ const size = entry.kind === "file" ? format.bytes(entry.size) : "";
6
+ const name = entry.kind === "directory" ? format.bold(`${entry.name}/`) : entry.name;
7
+ const target = entry.target === null ? "" : format.dim(` -> ${entry.target}`);
8
+ lines.push(` ${entry.kind.padEnd(9)} ${size.padStart(9)} ${format.time(entry.modifiedMs)} ${name}${target}`);
9
+ }
10
+ const folders = output.entries.filter((entry) => entry.kind === "directory").length;
11
+ const bytes = output.entries.reduce((sum, entry) => sum + entry.size, 0);
12
+ lines.push("", format.text(message("files.list.total", { folders, files: output.entries.length - folders, size: format.bytes(bytes) })));
13
+ if (output.hidden > 0)
14
+ lines.push(format.dim(format.text(message("files.list.hidden", { count: output.hidden }))));
15
+ return lines;
16
+ };
17
+ //# sourceMappingURL=list.view.js.map
@@ -0,0 +1,14 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ export const moveView = (output, format) => {
3
+ const exists = format.yellow(format.text(message("files.transfer.exists-note")));
4
+ const lines = output.items.map((item) => ` ${format.path(item.source)} -> ${format.path(item.destination)}${item.conflict ? ` ${exists}` : ""}`);
5
+ const conflicts = output.conflicts > 0
6
+ ? `, ${format.text(message("files.transfer.conflicts-note", { count: output.conflicts }))}`
7
+ : "";
8
+ lines.push("", `${format.text(message("files.move.total", { count: output.items.length }))}${conflicts}`);
9
+ const moved = output.items.filter((item) => item.outcome === "moved").length;
10
+ if (moved > 0)
11
+ lines.push(format.green(format.text(message("files.move.done", { count: moved }))));
12
+ return lines;
13
+ };
14
+ //# sourceMappingURL=move.view.js.map
@@ -0,0 +1,8 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ /** Created paths go to stdout; the ones left alone are reported as failures on stderr. */
3
+ export const newView = (output, format) => output.items
4
+ .filter((item) => item.created)
5
+ .map((item) => format.green(format.text(message(item.kind === "directory" ? "files.new.created-folder" : "files.new.created-file", {
6
+ path: format.path(item.path),
7
+ }))));
8
+ //# sourceMappingURL=new.view.js.map
@@ -0,0 +1,6 @@
1
+ /** Only the text, so the output can be piped. */
2
+ export const readView = (output) => {
3
+ const width = String(output.last).length;
4
+ return output.lines.map((line, index) => output.numbered ? `${String(output.first + index).padStart(width)} ${line}` : line);
5
+ };
6
+ //# sourceMappingURL=read.view.js.map
@@ -0,0 +1,16 @@
1
+ import path from "node:path";
2
+ import { message } from "../../../core/domain/message.js";
3
+ export const renameView = (output, format) => {
4
+ if (output.mode === "one") {
5
+ return output.renames.map((rename) => format.green(format.text(message("files.rename.renamed-one", { from: format.path(rename.from), name: path.basename(rename.to) }))));
6
+ }
7
+ const lines = output.renames.map((rename) => ` ${format.path(rename.from)} -> ${format.bold(path.basename(rename.to))}`);
8
+ lines.push("", format.text(message("files.rename.count", { count: output.renames.length })));
9
+ if (output.renames.length === 0 && output.problems.length === 0) {
10
+ lines.push(format.green(format.text(message("files.rename.all-fit"))));
11
+ }
12
+ if (output.renamed > 0)
13
+ lines.push(format.green(format.text(message("files.rename.renamed", { count: output.renamed }))));
14
+ return lines;
15
+ };
16
+ //# sourceMappingURL=rename.view.js.map
@@ -0,0 +1,26 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ export const replaceView = (output, format) => {
3
+ const lines = [];
4
+ for (const file of output.files) {
5
+ const count = format.dim(format.text(message("files.replace.matches", { count: file.count })));
6
+ lines.push(`${format.bold(format.path(file.path))} ${count}`);
7
+ if (file.lineCountChanges)
8
+ lines.push(format.dim(` ${format.text(message("files.replace.lines-change"))}`));
9
+ for (const sample of file.samples) {
10
+ lines.push(` ${String(sample.line).padStart(5)} ${format.red("-")} ${sample.before}`);
11
+ lines.push(` ${"".padStart(5)} ${format.green("+")} ${sample.after}`);
12
+ }
13
+ }
14
+ const skipped = output.skipped > 0 ? format.dim(` · ${format.text(message("files.grep.skipped", { count: output.skipped }))}`) : "";
15
+ const total = message("files.replace.total", {
16
+ total: output.replacements,
17
+ files: output.files.length,
18
+ checked: output.checked,
19
+ });
20
+ lines.push("", `${format.text(total)}${skipped}`);
21
+ if (output.written > 0) {
22
+ lines.push(format.green(format.text(message("files.replace.written", { count: output.written }))));
23
+ }
24
+ return lines;
25
+ };
26
+ //# sourceMappingURL=replace.view.js.map
@@ -0,0 +1,24 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ export const sizeView = (output, format) => {
3
+ const rebuildable = output.rebuildableBytes > 0
4
+ ? format.dim(` ${format.text(message("files.size.rebuildable-total", { size: format.bytes(output.rebuildableBytes) }))}`)
5
+ : "";
6
+ const lines = [`${format.bold(format.path(output.folder))} ${format.bytes(output.bytes)}${rebuildable}`, ""];
7
+ const shown = output.rows.slice(0, output.top);
8
+ const loose = format.text(message("files.size.loose-files"));
9
+ const width = Math.max(8, loose.length, ...shown.map((row) => row.name.length + 1));
10
+ for (const row of shown) {
11
+ const extra = row.rebuildableBytes > 0
12
+ ? format.dim(` ${format.text(message("files.size.rebuildable", { size: format.bytes(row.rebuildableBytes) }))}`)
13
+ : "";
14
+ lines.push(` ${`${row.name}/`.padEnd(width)} ${format.bytes(row.bytes).padStart(9)}${extra}`);
15
+ }
16
+ if (output.rows.length > shown.length) {
17
+ lines.push(format.dim(` ${format.text(message("files.size.more", { count: output.rows.length - shown.length }))}`));
18
+ }
19
+ if (output.looseBytes > 0) {
20
+ lines.push(format.dim(` ${loose.padEnd(width)} ${format.bytes(output.looseBytes).padStart(9)}`));
21
+ }
22
+ return lines;
23
+ };
24
+ //# sourceMappingURL=size.view.js.map
@@ -0,0 +1,37 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ import { previewLines } from "../../../core/presentation/list-preview.js";
3
+ const PREVIEW = 15;
4
+ export const syncView = (output, format) => {
5
+ const label = (key) => format.bold(format.text(message(key)));
6
+ const plan = message("files.sync.plan", {
7
+ copy: output.copy.length,
8
+ update: output.update.length,
9
+ remove: output.remove.length,
10
+ size: format.bytes(output.bytes),
11
+ });
12
+ const lines = [
13
+ `${label("files.sync.label.source")} ${output.source}`,
14
+ `${label("files.sync.label.target")} ${output.target}`,
15
+ "",
16
+ format.text(plan),
17
+ ];
18
+ const sections = [
19
+ ["files.sync.section.copy", output.copy],
20
+ ["files.sync.section.update", output.update],
21
+ ["files.sync.section.delete", output.remove],
22
+ ];
23
+ for (const [key, items] of sections) {
24
+ if (items.length === 0)
25
+ continue;
26
+ lines.push("", label(key), ...previewLines(items, PREVIEW, (item) => ` ${item}`, format));
27
+ }
28
+ if (output.copy.length + output.update.length + output.remove.length === 0) {
29
+ lines.push("", format.green(format.text(message("files.sync.in-sync"))));
30
+ }
31
+ if (output.applied) {
32
+ const counts = { copy: output.copy.length, update: output.update.length, remove: output.remove.length };
33
+ lines.push("", format.green(format.text(message("files.sync.done", counts))));
34
+ }
35
+ return lines;
36
+ };
37
+ //# sourceMappingURL=sync.view.js.map
@@ -0,0 +1,22 @@
1
+ import { message } from "../../../core/domain/message.js";
2
+ export const treeView = (output, format) => {
3
+ const lines = [format.bold(format.path(output.root))];
4
+ const draw = (nodes, prefix) => {
5
+ nodes.forEach((node, index) => {
6
+ const last = index === nodes.length - 1;
7
+ const name = node.kind === "directory" ? format.bold(`${node.name}/`) : node.name;
8
+ const target = node.target === null ? "" : format.dim(` -> ${node.target}`);
9
+ const note = node.closed
10
+ ? format.dim(` ${format.text(message("files.tree.not-opened"))}`)
11
+ : node.unreadable
12
+ ? format.dim(` ${format.text(message("files.tree.unreadable"))}`)
13
+ : "";
14
+ lines.push(`${prefix}${last ? "└── " : "├── "}${name}${target}${note}`);
15
+ draw(node.children, `${prefix}${last ? " " : "│ "}`);
16
+ });
17
+ };
18
+ draw(output.nodes, "");
19
+ lines.push("", format.text(message("files.tree.total", { folders: output.directories, files: output.files, depth: output.depth })));
20
+ return lines;
21
+ };
22
+ //# sourceMappingURL=tree.view.js.map
@@ -0,0 +1,18 @@
1
+ import { UsageError } from "../../../core/domain/errors.js";
2
+ export const MAX_COUNT = 1000;
3
+ /** Every run gives new values, and nothing leaves the machine. */
4
+ export const GENERATOR = { safety: "read", idempotent: false, usesNetwork: false, runsUserCommands: false };
5
+ export const countOption = { type: "string", description: "gen.option.count", valueName: "<n>" };
6
+ export function readCount(reader) {
7
+ const count = reader.positiveInteger("count", 1);
8
+ if (count > MAX_COUNT)
9
+ throw new UsageError("gen.count-too-large", { max: MAX_COUNT });
10
+ return count;
11
+ }
12
+ export function readRange(reader, option, fallback, min, max) {
13
+ const value = reader.positiveInteger(option, fallback);
14
+ if (value < min || value > max)
15
+ throw new UsageError("gen.out-of-range", { option, min, max });
16
+ return value;
17
+ }
18
+ //# sourceMappingURL=gen-options.js.map
@@ -0,0 +1,39 @@
1
+ import { done } from "../../../core/domain/command.js";
2
+ import { RawReader } from "../../../core/domain/input-schema.js";
3
+ import { DIGITS, LOWER, password, SYMBOLS, UPPER } from "../domain/secrets.js";
4
+ import { countOption, GENERATOR, readCount, readRange } from "./gen-options.js";
5
+ export const passwordSpec = {
6
+ id: "gen.password",
7
+ summary: "gen.password.summary",
8
+ examples: ["kiriya gen password", "kiriya gen password --length 40 --no-symbols"],
9
+ ...GENERATOR,
10
+ input: {
11
+ positionals: [],
12
+ options: {
13
+ length: { type: "string", description: "gen.password.option.length", valueName: "<n>" },
14
+ "no-symbols": { type: "boolean", description: "gen.password.option.no-symbols" },
15
+ count: countOption,
16
+ },
17
+ parse(raw) {
18
+ const reader = new RawReader(raw);
19
+ return {
20
+ count: readCount(reader),
21
+ length: readRange(reader, "length", 24, 8, 256),
22
+ symbols: !reader.flag("no-symbols"),
23
+ };
24
+ },
25
+ },
26
+ };
27
+ export class GeneratePasswords {
28
+ random;
29
+ spec = passwordSpec;
30
+ constructor(random) {
31
+ this.random = random;
32
+ }
33
+ execute(input) {
34
+ const classes = input.symbols ? [LOWER, UPPER, DIGITS, SYMBOLS] : [LOWER, UPPER, DIGITS];
35
+ const values = Array.from({ length: input.count }, () => password(input.length, classes, (count) => this.random.bytes(count)));
36
+ return Promise.resolve(done({ values }));
37
+ }
38
+ }
39
+ //# sourceMappingURL=generate-passwords.use-case.js.map
@@ -0,0 +1,38 @@
1
+ import { done } from "../../../core/domain/command.js";
2
+ import { RawReader } from "../../../core/domain/input-schema.js";
3
+ import { formatToken, TOKEN_FORMATS } from "../domain/secrets.js";
4
+ import { countOption, GENERATOR, readCount, readRange } from "./gen-options.js";
5
+ export const tokenSpec = {
6
+ id: "gen.token",
7
+ summary: "gen.token.summary",
8
+ examples: ["kiriya gen token", "kiriya gen token --bytes 64 --format hex"],
9
+ ...GENERATOR,
10
+ input: {
11
+ positionals: [],
12
+ options: {
13
+ bytes: { type: "string", description: "gen.token.option.bytes", valueName: "<n>" },
14
+ format: { type: "string", description: "gen.token.option.format", valueName: "<hex|base64|base64url>" },
15
+ count: countOption,
16
+ },
17
+ parse(raw) {
18
+ const reader = new RawReader(raw);
19
+ return {
20
+ count: readCount(reader),
21
+ bytes: readRange(reader, "bytes", 32, 8, 1024),
22
+ format: reader.choice("format", TOKEN_FORMATS, "base64url"),
23
+ };
24
+ },
25
+ },
26
+ };
27
+ export class GenerateTokens {
28
+ random;
29
+ spec = tokenSpec;
30
+ constructor(random) {
31
+ this.random = random;
32
+ }
33
+ execute(input) {
34
+ const values = Array.from({ length: input.count }, () => formatToken(this.random.bytes(input.bytes), input.format));
35
+ return Promise.resolve(done({ values }));
36
+ }
37
+ }
38
+ //# sourceMappingURL=generate-tokens.use-case.js.map
@@ -0,0 +1,40 @@
1
+ import { done } from "../../../core/domain/command.js";
2
+ import { RawReader } from "../../../core/domain/input-schema.js";
3
+ import { incrementRandom, ulid } from "../domain/identifiers.js";
4
+ import { countOption, GENERATOR, readCount } from "./gen-options.js";
5
+ export const ulidSpec = {
6
+ id: "gen.ulid",
7
+ summary: "gen.ulid.summary",
8
+ examples: ["kiriya gen ulid", "kiriya gen ulid --count 10"],
9
+ ...GENERATOR,
10
+ input: {
11
+ positionals: [],
12
+ options: { count: countOption },
13
+ parse: (raw) => ({ count: readCount(new RawReader(raw)) }),
14
+ },
15
+ };
16
+ export class GenerateUlids {
17
+ random;
18
+ clock;
19
+ spec = ulidSpec;
20
+ constructor(random, clock) {
21
+ this.random = random;
22
+ this.clock = clock;
23
+ }
24
+ execute(input) {
25
+ const values = [];
26
+ let previousTime = -1;
27
+ let previousRandom = null;
28
+ for (let index = 0; index < input.count; index += 1) {
29
+ const time = this.clock.now();
30
+ // Within one millisecond the random part counts up, so the values keep the order they were made in.
31
+ const next = time === previousTime && previousRandom !== null ? incrementRandom(previousRandom) : null;
32
+ const random = next ?? this.random.bytes(10);
33
+ values.push(ulid(time, random));
34
+ previousTime = time;
35
+ previousRandom = random;
36
+ }
37
+ return Promise.resolve(done({ values }));
38
+ }
39
+ }
40
+ //# sourceMappingURL=generate-ulids.use-case.js.map
@@ -0,0 +1,32 @@
1
+ import { done } from "../../../core/domain/command.js";
2
+ import { RawReader } from "../../../core/domain/input-schema.js";
3
+ import { uuidV4, uuidV7 } from "../domain/identifiers.js";
4
+ import { countOption, GENERATOR, readCount } from "./gen-options.js";
5
+ export const uuidSpec = {
6
+ id: "gen.uuid",
7
+ summary: "gen.uuid.summary",
8
+ examples: ["kiriya gen uuid", "kiriya gen uuid --v7 --count 5"],
9
+ ...GENERATOR,
10
+ input: {
11
+ positionals: [],
12
+ options: { v7: { type: "boolean", description: "gen.uuid.option.v7" }, count: countOption },
13
+ parse(raw) {
14
+ const reader = new RawReader(raw);
15
+ return { count: readCount(reader), timeOrdered: reader.flag("v7") };
16
+ },
17
+ },
18
+ };
19
+ export class GenerateUuids {
20
+ random;
21
+ clock;
22
+ spec = uuidSpec;
23
+ constructor(random, clock) {
24
+ this.random = random;
25
+ this.clock = clock;
26
+ }
27
+ execute(input) {
28
+ const values = Array.from({ length: input.count }, () => input.timeOrdered ? uuidV7(this.clock.now(), this.random.bytes(10)) : uuidV4(this.random.bytes(16)));
29
+ return Promise.resolve(done({ values }));
30
+ }
31
+ }
32
+ //# sourceMappingURL=generate-uuids.use-case.js.map
@@ -0,0 +1,65 @@
1
+ import { toHex } from "../../../core/domain/encodings.js";
2
+ const CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
3
+ function formatUuid(bytes) {
4
+ const hex = toHex(bytes);
5
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
6
+ }
7
+ /** A version 4 UUID from 16 random bytes: 122 random bits. */
8
+ export function uuidV4(random) {
9
+ const bytes = Uint8Array.from(random.subarray(0, 16));
10
+ bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40;
11
+ bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;
12
+ return formatUuid(bytes);
13
+ }
14
+ /** A version 7 UUID: 48 bits of Unix milliseconds, then 10 random bytes, so values sort by creation time. */
15
+ export function uuidV7(epochMs, random) {
16
+ const bytes = new Uint8Array(16);
17
+ let time = Math.max(0, Math.floor(epochMs));
18
+ for (let index = 5; index >= 0; index -= 1) {
19
+ bytes[index] = time % 256;
20
+ time = Math.floor(time / 256);
21
+ }
22
+ bytes.set(random.subarray(0, 10), 6);
23
+ bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x70;
24
+ bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;
25
+ return formatUuid(bytes);
26
+ }
27
+ /** A ULID: 10 Crockford base32 characters of Unix milliseconds, then 16 of 10 random bytes. */
28
+ export function ulid(epochMs, random) {
29
+ let time = "";
30
+ let remaining = Math.max(0, Math.floor(epochMs));
31
+ for (let index = 0; index < 10; index += 1) {
32
+ time = CROCKFORD.charAt(remaining % 32) + time;
33
+ remaining = Math.floor(remaining / 32);
34
+ }
35
+ let randomPart = "";
36
+ let buffer = 0;
37
+ let bits = 0;
38
+ for (const byte of random.subarray(0, 10)) {
39
+ buffer = (buffer << 8) | byte;
40
+ bits += 8;
41
+ while (bits >= 5) {
42
+ bits -= 5;
43
+ randomPart += CROCKFORD.charAt((buffer >> bits) & 31);
44
+ }
45
+ buffer &= (1 << bits) - 1;
46
+ }
47
+ return time + randomPart;
48
+ }
49
+ /**
50
+ * The next random part for ULIDs made in the same millisecond: the previous one plus
51
+ * one, so they still sort in the order they were made. null when it would overflow.
52
+ */
53
+ export function incrementRandom(previous) {
54
+ const next = Uint8Array.from(previous);
55
+ for (let index = next.length - 1; index >= 0; index -= 1) {
56
+ const value = next[index] ?? 0;
57
+ if (value < 255) {
58
+ next[index] = value + 1;
59
+ return next;
60
+ }
61
+ next[index] = 0;
62
+ }
63
+ return null;
64
+ }
65
+ //# sourceMappingURL=identifiers.js.map