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.
- package/CHANGELOG.md +58 -0
- package/LICENSE +21 -0
- package/README.md +87 -0
- package/dist/src/config/clean-rules.js +39 -0
- package/dist/src/config/config-keys.js +24 -0
- package/dist/src/config/dependency-directories.js +16 -0
- package/dist/src/config/modules.js +38 -0
- package/dist/src/config/protected-paths.js +32 -0
- package/dist/src/config/rebuildable-directories.js +20 -0
- package/dist/src/core/application/command-registry.js +57 -0
- package/dist/src/core/application/config-values.js +33 -0
- package/dist/src/core/application/path-guard.js +69 -0
- package/dist/src/core/application/paths.js +77 -0
- package/dist/src/core/application/plugin-loader.js +100 -0
- package/dist/src/core/application/process-ending.js +28 -0
- package/dist/src/core/application/root-scope.js +123 -0
- package/dist/src/core/application/safety.js +26 -0
- package/dist/src/core/application/text-input.js +44 -0
- package/dist/src/core/application/walk.js +34 -0
- package/dist/src/core/domain/command.js +8 -0
- package/dist/src/core/domain/encodings.js +70 -0
- package/dist/src/core/domain/errors.js +49 -0
- package/dist/src/core/domain/glob.js +57 -0
- package/dist/src/core/domain/global-options.js +10 -0
- package/dist/src/core/domain/input-schema.js +54 -0
- package/dist/src/core/domain/message.js +7 -0
- package/dist/src/core/domain/module.js +2 -0
- package/dist/src/core/domain/names.js +22 -0
- package/dist/src/core/domain/ports/clipboard.js +2 -0
- package/dist/src/core/domain/ports/clock.js +2 -0
- package/dist/src/core/domain/ports/command-catalog.js +2 -0
- package/dist/src/core/domain/ports/compression.js +2 -0
- package/dist/src/core/domain/ports/config-store.js +2 -0
- package/dist/src/core/domain/ports/confirmation.js +2 -0
- package/dist/src/core/domain/ports/environment.js +2 -0
- package/dist/src/core/domain/ports/file-content.js +2 -0
- package/dist/src/core/domain/ports/file-system.js +2 -0
- package/dist/src/core/domain/ports/hasher.js +2 -0
- package/dist/src/core/domain/ports/network.js +2 -0
- package/dist/src/core/domain/ports/opener.js +2 -0
- package/dist/src/core/domain/ports/passthrough.js +2 -0
- package/dist/src/core/domain/ports/plugin-inventory.js +2 -0
- package/dist/src/core/domain/ports/plugin-source.js +2 -0
- package/dist/src/core/domain/ports/port-table.js +2 -0
- package/dist/src/core/domain/ports/process-runner.js +2 -0
- package/dist/src/core/domain/ports/process-table.js +2 -0
- package/dist/src/core/domain/ports/protected-paths.js +2 -0
- package/dist/src/core/domain/ports/random-source.js +2 -0
- package/dist/src/core/domain/ports/standard-input.js +2 -0
- package/dist/src/core/domain/ports/system-info.js +2 -0
- package/dist/src/core/domain/ports/trash.js +2 -0
- package/dist/src/core/domain/secrets.js +59 -0
- package/dist/src/core/domain/targets.js +41 -0
- package/dist/src/core/domain/text-case.js +39 -0
- package/dist/src/core/domain/values/bytes.js +13 -0
- package/dist/src/core/domain/view.js +2 -0
- package/dist/src/core/infrastructure/node/can-listen.js +10 -0
- package/dist/src/core/infrastructure/node/closed-standard-input.adapter.js +12 -0
- package/dist/src/core/infrastructure/node/config-location.js +27 -0
- package/dist/src/core/infrastructure/node/fs-errors.js +22 -0
- package/dist/src/core/infrastructure/node/json-config-store.adapter.js +69 -0
- package/dist/src/core/infrastructure/node/node-compression.adapter.js +82 -0
- package/dist/src/core/infrastructure/node/node-environment.adapter.js +21 -0
- package/dist/src/core/infrastructure/node/node-file-content.adapter.js +99 -0
- package/dist/src/core/infrastructure/node/node-file-system.adapter.js +169 -0
- package/dist/src/core/infrastructure/node/node-hasher.adapter.js +32 -0
- package/dist/src/core/infrastructure/node/node-network.adapter.js +168 -0
- package/dist/src/core/infrastructure/node/node-plugin-source.adapter.js +89 -0
- package/dist/src/core/infrastructure/node/node-process-runner.adapter.js +48 -0
- package/dist/src/core/infrastructure/node/node-random-source.adapter.js +7 -0
- package/dist/src/core/infrastructure/node/node-standard-input.adapter.js +24 -0
- package/dist/src/core/infrastructure/node/node-system-info.adapter.js +63 -0
- package/dist/src/core/infrastructure/node/process-signals.js +51 -0
- package/dist/src/core/infrastructure/node/run-program.js +65 -0
- package/dist/src/core/infrastructure/node/system-clock.adapter.js +22 -0
- package/dist/src/core/infrastructure/node/typed-programs.js +45 -0
- package/dist/src/core/infrastructure/platform/linux/freedesktop-trash.adapter.js +115 -0
- package/dist/src/core/infrastructure/platform/linux/linux-clipboard.adapter.js +70 -0
- package/dist/src/core/infrastructure/platform/linux/linux-opener.adapter.js +21 -0
- package/dist/src/core/infrastructure/platform/linux/linux-port-table.adapter.js +97 -0
- package/dist/src/core/infrastructure/platform/linux/linux-process-table.adapter.js +61 -0
- package/dist/src/core/infrastructure/platform/macos/macos-clipboard.adapter.js +29 -0
- package/dist/src/core/infrastructure/platform/macos/macos-opener.adapter.js +13 -0
- package/dist/src/core/infrastructure/platform/macos/macos-port-table.adapter.js +86 -0
- package/dist/src/core/infrastructure/platform/macos/macos-process-table.adapter.js +62 -0
- package/dist/src/core/infrastructure/platform/macos/macos-trash.adapter.js +64 -0
- package/dist/src/core/infrastructure/platform/windows/system32.js +6 -0
- package/dist/src/core/infrastructure/platform/windows/windows-clipboard.adapter.js +50 -0
- package/dist/src/core/infrastructure/platform/windows/windows-opener.adapter.js +11 -0
- package/dist/src/core/infrastructure/platform/windows/windows-port-table.adapter.js +38 -0
- package/dist/src/core/infrastructure/platform/windows/windows-process-table.adapter.js +134 -0
- package/dist/src/core/infrastructure/platform/windows/windows-trash.adapter.js +86 -0
- package/dist/src/core/presentation/cli/argv.js +83 -0
- package/dist/src/core/presentation/cli/cli-application.js +201 -0
- package/dist/src/core/presentation/cli/cli-view-format.js +46 -0
- package/dist/src/core/presentation/cli/help.js +202 -0
- package/dist/src/core/presentation/cli/json-output.js +28 -0
- package/dist/src/core/presentation/cli/style.js +21 -0
- package/dist/src/core/presentation/cli/suggest.js +25 -0
- package/dist/src/core/presentation/cli/terminal-confirmation.js +63 -0
- package/dist/src/core/presentation/ended-processes.js +18 -0
- package/dist/src/core/presentation/i18n/translator.js +23 -0
- package/dist/src/core/presentation/list-preview.js +10 -0
- package/dist/src/core/presentation/mcp/elicitation.js +55 -0
- package/dist/src/core/presentation/mcp/mcp-application.js +60 -0
- package/dist/src/core/presentation/mcp/mcp-confirmation.js +59 -0
- package/dist/src/core/presentation/mcp/mcp-server.js +355 -0
- package/dist/src/core/presentation/mcp/protocol.js +32 -0
- package/dist/src/core/presentation/mcp/request-state.js +66 -0
- package/dist/src/core/presentation/mcp/tool-definitions.js +149 -0
- package/dist/src/core/presentation/mcp/tool-results.js +56 -0
- package/dist/src/i18n/locales/en.js +827 -0
- package/dist/src/main.js +154 -0
- package/dist/src/modules/archive/application/archive-sources.js +55 -0
- package/dist/src/modules/archive/application/create-tar.use-case.js +123 -0
- package/dist/src/modules/archive/application/create-zip.use-case.js +106 -0
- package/dist/src/modules/archive/application/extract-tar.use-case.js +240 -0
- package/dist/src/modules/archive/application/extract-zip.use-case.js +181 -0
- package/dist/src/modules/archive/application/tar-reader.js +45 -0
- package/dist/src/modules/archive/application/zip-reader.js +57 -0
- package/dist/src/modules/archive/archive.module.js +27 -0
- package/dist/src/modules/archive/domain/crc32.js +18 -0
- package/dist/src/modules/archive/domain/tar-format.js +97 -0
- package/dist/src/modules/archive/domain/tar-stream.js +223 -0
- package/dist/src/modules/archive/domain/zip-format.js +158 -0
- package/dist/src/modules/archive/presentation/tar.view.js +17 -0
- package/dist/src/modules/archive/presentation/untar.view.js +30 -0
- package/dist/src/modules/archive/presentation/unzip.view.js +24 -0
- package/dist/src/modules/archive/presentation/zip.view.js +17 -0
- package/dist/src/modules/clip/application/copy-text.use-case.js +43 -0
- package/dist/src/modules/clip/application/paste-text.use-case.js +25 -0
- package/dist/src/modules/clip/clip.module.js +16 -0
- package/dist/src/modules/clip/presentation/clip.views.js +7 -0
- package/dist/src/modules/completion/application/print-script.use-case.js +38 -0
- package/dist/src/modules/completion/application/suggest-words.use-case.js +37 -0
- package/dist/src/modules/completion/completion.module.js +14 -0
- package/dist/src/modules/completion/domain/scripts.js +91 -0
- package/dist/src/modules/completion/domain/suggest.js +134 -0
- package/dist/src/modules/completion/presentation/completion.views.js +6 -0
- package/dist/src/modules/config/application/config-commands.js +14 -0
- package/dist/src/modules/config/application/get-setting.use-case.js +25 -0
- package/dist/src/modules/config/application/list-config-keys.use-case.js +26 -0
- package/dist/src/modules/config/application/list-settings.use-case.js +28 -0
- package/dist/src/modules/config/application/set-setting.use-case.js +53 -0
- package/dist/src/modules/config/application/show-config-path.use-case.js +21 -0
- package/dist/src/modules/config/application/unset-setting.use-case.js +28 -0
- package/dist/src/modules/config/config.module.js +28 -0
- package/dist/src/modules/config/presentation/config.views.js +33 -0
- package/dist/src/modules/convert/application/convert-case.use-case.js +38 -0
- package/dist/src/modules/convert/application/convert-codecs.use-case.js +92 -0
- package/dist/src/modules/convert/application/convert-input.js +16 -0
- package/dist/src/modules/convert/application/convert-json.use-case.js +51 -0
- package/dist/src/modules/convert/application/convert-time.use-case.js +39 -0
- package/dist/src/modules/convert/application/decode-jwt.use-case.js +52 -0
- package/dist/src/modules/convert/convert.module.js +29 -0
- package/dist/src/modules/convert/domain/json-syntax.js +135 -0
- package/dist/src/modules/convert/domain/jwt.js +29 -0
- package/dist/src/modules/convert/domain/moments.js +20 -0
- package/dist/src/modules/convert/presentation/convert.views.js +44 -0
- package/dist/src/modules/docker/application/clean-engine.use-case.js +77 -0
- package/dist/src/modules/docker/application/compose-project.js +45 -0
- package/dist/src/modules/docker/application/docker-engine.js +40 -0
- package/dist/src/modules/docker/application/list-containers.use-case.js +69 -0
- package/dist/src/modules/docker/application/run-compose.use-case.js +83 -0
- package/dist/src/modules/docker/application/show-logs.use-case.js +51 -0
- package/dist/src/modules/docker/application/stop-project.use-case.js +56 -0
- package/dist/src/modules/docker/docker.module.js +23 -0
- package/dist/src/modules/docker/domain/compose-file.js +105 -0
- package/dist/src/modules/docker/domain/engine-output.js +65 -0
- package/dist/src/modules/docker/presentation/docker.views.js +63 -0
- package/dist/src/modules/doctor/application/run-checks.use-case.js +128 -0
- package/dist/src/modules/doctor/doctor.module.js +13 -0
- package/dist/src/modules/doctor/domain/versions.js +22 -0
- package/dist/src/modules/doctor/presentation/doctor.view.js +30 -0
- package/dist/src/modules/env/application/check-dotenv.use-case.js +116 -0
- package/dist/src/modules/env/application/inspect-path.use-case.js +71 -0
- package/dist/src/modules/env/application/path-entries.js +28 -0
- package/dist/src/modules/env/application/show-variables.use-case.js +47 -0
- package/dist/src/modules/env/domain/dotenv.js +62 -0
- package/dist/src/modules/env/env.module.js +17 -0
- package/dist/src/modules/env/presentation/env.views.js +43 -0
- package/dist/src/modules/files/application/clean-builds.use-case.js +149 -0
- package/dist/src/modules/files/application/compare-paths.use-case.js +127 -0
- package/dist/src/modules/files/application/copy-paths.use-case.js +101 -0
- package/dist/src/modules/files/application/create-paths.use-case.js +85 -0
- package/dist/src/modules/files/application/delete-paths.use-case.js +127 -0
- package/dist/src/modules/files/application/find-duplicates.use-case.js +105 -0
- package/dist/src/modules/files/application/find-files.use-case.js +131 -0
- package/dist/src/modules/files/application/hash-files.use-case.js +73 -0
- package/dist/src/modules/files/application/list-entries.use-case.js +87 -0
- package/dist/src/modules/files/application/measure-folders.use-case.js +102 -0
- package/dist/src/modules/files/application/move-entry.js +19 -0
- package/dist/src/modules/files/application/move-paths.use-case.js +82 -0
- package/dist/src/modules/files/application/read-text.use-case.js +92 -0
- package/dist/src/modules/files/application/rename-paths.use-case.js +184 -0
- package/dist/src/modules/files/application/replace-text.use-case.js +146 -0
- package/dist/src/modules/files/application/search-text.use-case.js +115 -0
- package/dist/src/modules/files/application/show-info.use-case.js +80 -0
- package/dist/src/modules/files/application/show-tree.use-case.js +75 -0
- package/dist/src/modules/files/application/sync-folders.use-case.js +162 -0
- package/dist/src/modules/files/application/text-files.js +46 -0
- package/dist/src/modules/files/application/transfers.js +35 -0
- package/dist/src/modules/files/domain/case-style.js +18 -0
- package/dist/src/modules/files/domain/filters.js +9 -0
- package/dist/src/modules/files/domain/sync-plan.js +35 -0
- package/dist/src/modules/files/domain/text-encoding.js +75 -0
- package/dist/src/modules/files/domain/values.js +28 -0
- package/dist/src/modules/files/files.module.js +70 -0
- package/dist/src/modules/files/presentation/clean.view.js +15 -0
- package/dist/src/modules/files/presentation/compare.view.js +50 -0
- package/dist/src/modules/files/presentation/copy.view.js +17 -0
- package/dist/src/modules/files/presentation/delete.view.js +16 -0
- package/dist/src/modules/files/presentation/dupes.view.js +20 -0
- package/dist/src/modules/files/presentation/find.view.js +16 -0
- package/dist/src/modules/files/presentation/grep.view.js +27 -0
- package/dist/src/modules/files/presentation/hash.view.js +15 -0
- package/dist/src/modules/files/presentation/info.view.js +36 -0
- package/dist/src/modules/files/presentation/list.view.js +17 -0
- package/dist/src/modules/files/presentation/move.view.js +14 -0
- package/dist/src/modules/files/presentation/new.view.js +8 -0
- package/dist/src/modules/files/presentation/read.view.js +6 -0
- package/dist/src/modules/files/presentation/rename.view.js +16 -0
- package/dist/src/modules/files/presentation/replace.view.js +26 -0
- package/dist/src/modules/files/presentation/size.view.js +24 -0
- package/dist/src/modules/files/presentation/sync.view.js +37 -0
- package/dist/src/modules/files/presentation/tree.view.js +22 -0
- package/dist/src/modules/gen/application/gen-options.js +18 -0
- package/dist/src/modules/gen/application/generate-passwords.use-case.js +39 -0
- package/dist/src/modules/gen/application/generate-tokens.use-case.js +38 -0
- package/dist/src/modules/gen/application/generate-ulids.use-case.js +40 -0
- package/dist/src/modules/gen/application/generate-uuids.use-case.js +32 -0
- package/dist/src/modules/gen/domain/identifiers.js +65 -0
- package/dist/src/modules/gen/domain/secrets.js +43 -0
- package/dist/src/modules/gen/gen.module.js +20 -0
- package/dist/src/modules/git/application/fetch-repositories.use-case.js +50 -0
- package/dist/src/modules/git/application/git-client.js +62 -0
- package/dist/src/modules/git/application/pull-repositories.use-case.js +67 -0
- package/dist/src/modules/git/application/repositories.js +67 -0
- package/dist/src/modules/git/application/show-status.use-case.js +49 -0
- package/dist/src/modules/git/application/switch-branch.use-case.js +118 -0
- package/dist/src/modules/git/domain/repository-status.js +37 -0
- package/dist/src/modules/git/git.module.js +25 -0
- package/dist/src/modules/git/presentation/git.views.js +100 -0
- package/dist/src/modules/net/application/check-connection.use-case.js +71 -0
- package/dist/src/modules/net/application/list-addresses.use-case.js +29 -0
- package/dist/src/modules/net/application/lookup-name.use-case.js +55 -0
- package/dist/src/modules/net/net.module.js +17 -0
- package/dist/src/modules/net/presentation/net.views.js +39 -0
- package/dist/src/modules/open/application/open-target.use-case.js +53 -0
- package/dist/src/modules/open/domain/targets.js +45 -0
- package/dist/src/modules/open/open.module.js +12 -0
- package/dist/src/modules/open/presentation/open.view.js +6 -0
- package/dist/src/modules/port/application/end-port-owners.use-case.js +68 -0
- package/dist/src/modules/port/application/find-free-port.use-case.js +40 -0
- package/dist/src/modules/port/application/find-listeners.use-case.js +34 -0
- package/dist/src/modules/port/application/port-owners.js +25 -0
- package/dist/src/modules/port/domain/port-number.js +8 -0
- package/dist/src/modules/port/port.module.js +17 -0
- package/dist/src/modules/port/presentation/port.views.js +27 -0
- package/dist/src/modules/proc/application/end-processes.use-case.js +77 -0
- package/dist/src/modules/proc/application/find-processes.use-case.js +50 -0
- package/dist/src/modules/proc/application/list-processes.use-case.js +41 -0
- package/dist/src/modules/proc/application/show-tree.use-case.js +40 -0
- package/dist/src/modules/proc/domain/process-tree.js +55 -0
- package/dist/src/modules/proc/presentation/proc.views.js +28 -0
- package/dist/src/modules/proc/proc.module.js +19 -0
- package/dist/src/modules/sys/application/create-report.use-case.js +30 -0
- package/dist/src/modules/sys/application/find-tools.use-case.js +20 -0
- package/dist/src/modules/sys/application/machine-facts.js +44 -0
- package/dist/src/modules/sys/application/show-info.use-case.js +29 -0
- package/dist/src/modules/sys/domain/tools.js +17 -0
- package/dist/src/modules/sys/presentation/sys.views.js +67 -0
- package/dist/src/modules/sys/sys.module.js +17 -0
- package/dist/src/modules/wait/application/poll.js +26 -0
- package/dist/src/modules/wait/application/wait-file.use-case.js +55 -0
- package/dist/src/modules/wait/application/wait-port.use-case.js +76 -0
- package/dist/src/modules/wait/application/wait-url.use-case.js +71 -0
- package/dist/src/modules/wait/domain/reasons.js +14 -0
- package/dist/src/modules/wait/domain/wait-input.js +50 -0
- package/dist/src/modules/wait/presentation/wait.views.js +31 -0
- package/dist/src/modules/wait/wait.module.js +21 -0
- 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
|