Merge pull request 'refactor: merge cas get/cat into get, default hides timestamp' (#332) from refactor/merge-cas-get-cat into main

This commit is contained in:
2026-05-18 14:03:50 +00:00
2 changed files with 9 additions and 29 deletions
+4 -16
View File
@@ -12,7 +12,6 @@ import {
import { cmdWorkflowList, cmdWorkflowPut, cmdWorkflowShow } from "./commands/workflow.js";
import { cmdSetup, cmdSetupInteractive } from "./commands/setup.js";
import {
cmdCasCat,
cmdCasGet,
cmdCasHas,
cmdCasPut,
@@ -185,24 +184,13 @@ const cas = program.command("cas").description("Content-addressable storage oper
cas
.command("get")
.description("Read a CAS node as JSON")
.description("Read a CAS node (type + payload; use --timestamp to include timestamp)")
.argument("<hash>", "CAS hash (13 char)")
.action((hash: string) => {
.option("--timestamp", "Include timestamp in output")
.action((hash: string, opts: { timestamp?: boolean }) => {
const storageRoot = resolveStorageRoot();
runAction(async () => {
writeOutput(await cmdCasGet(storageRoot, hash));
});
});
cas
.command("cat")
.description("Output a CAS node (--payload for payload only)")
.argument("<hash>", "CAS hash (13 char)")
.option("--payload", "Output only the payload")
.action((hash: string, opts: { payload?: boolean }) => {
const storageRoot = resolveStorageRoot();
runAction(async () => {
writeOutput(await cmdCasCat(storageRoot, hash, opts));
writeOutput(await cmdCasGet(storageRoot, hash, opts));
});
});
+5 -13
View File
@@ -28,26 +28,18 @@ function readJsonArg(fileOrInline: string): unknown {
export async function cmdCasGet(
storageRoot: string,
hash: string,
opts: { timestamp?: boolean },
): Promise<unknown> {
const store = openStore(storageRoot);
const node = store.get(hash);
if (node === null) {
throw new Error(`Node not found: ${hash}`);
}
return node;
}
export async function cmdCasCat(
storageRoot: string,
hash: string,
opts: { payload?: boolean },
): Promise<unknown> {
const store = openStore(storageRoot);
const node = store.get(hash);
if (node === null) {
throw new Error(`Node not found: ${hash}`);
if (opts.timestamp) {
return node;
}
return opts.payload ? node.payload : node;
const { timestamp: _, ...rest } = node as Record<string, unknown>;
return rest;
}
export async function cmdCasPut(