diff --git a/packages/cli-json-cas/src/index.ts b/packages/cli-json-cas/src/index.ts index 40ad3e5..e1b729d 100644 --- a/packages/cli-json-cas/src/index.ts +++ b/packages/cli-json-cas/src/index.ts @@ -116,10 +116,10 @@ async function cmdSchemaGet(args: string[]): Promise { async function cmdSchemaList(): Promise { const store = openStore(); const metaHash = await bootstrap(store); - for (const hash of store.list()) { + for (const hash of store.listByType(metaHash)) { if (hash === metaHash) continue; const node = store.get(hash); - if (node !== null && node.type === metaHash) { + if (node !== null) { const schema = node.payload as JSONSchema; const name = (schema.title as string | undefined) ?? @@ -176,12 +176,7 @@ async function cmdVerify(args: string[]): Promise { console.log(ok ? "ok" : "corrupted"); } -async function cmdList(): Promise { - const store = openStore(); - for (const hash of store.list()) { - console.log(hash); - } -} + async function cmdRefs(args: string[]): Promise { const hash = args[0]; @@ -271,7 +266,6 @@ Commands: get Print node as JSON has Print true/false verify Verify integrity, print ok/corrupted - list List all hashes refs List direct cas_ref edges walk [--format tree] Recursive traversal hash Compute hash without storing (dry run) @@ -337,10 +331,6 @@ switch (cmd) { await cmdVerify(rest); break; - case "list": - await cmdList(); - break; - case "refs": await cmdRefs(rest); break; diff --git a/packages/json-cas-fs/src/store.test.ts b/packages/json-cas-fs/src/store.test.ts index 5aeefca..d4566a2 100644 --- a/packages/json-cas-fs/src/store.test.ts +++ b/packages/json-cas-fs/src/store.test.ts @@ -30,15 +30,15 @@ describe("createFsStore – init and bootstrap", () => { test("store opens against an existing empty dir", () => { const store = createFsStore(dir); - expect(store.list()).toEqual([]); + expect(store.listByType("0000000000000")).toEqual([]); }); test("store creates the directory on first put", async () => { const nested = join(dir, "sub", "store"); const store = createFsStore(nested); const typeHash = await computeSelfHash({ name: "t" }); - await store.put(typeHash, { x: 1 }); - expect(store.list()).toHaveLength(1); + const hash = await store.put(typeHash, { x: 1 }); + expect(store.has(hash)).toBe(true); }); test("bootstrap returns a valid 13-char self-referencing hash", async () => { @@ -58,7 +58,7 @@ describe("createFsStore – init and bootstrap", () => { const h2 = await bootstrap(store); expect(h1).toBe(h2); - expect(store.list()).toHaveLength(1); + expect(store.listByType(h1)).toHaveLength(1); }); }); @@ -84,7 +84,7 @@ describe("createFsStore – persistence round-trip", () => { const store2 = createFsStore(dir); expect(store2.has(h1)).toBe(true); expect(store2.has(h2)).toBe(true); - expect(store2.list()).toHaveLength(2); + expect(store2.listByType(typeHash)).toHaveLength(2); }); test("round-trip preserves type, payload, and timestamp", async () => { @@ -125,7 +125,7 @@ describe("createFsStore – persistence round-trip", () => { const ts2 = store2.get(hash)?.timestamp; expect(ts1).toBe(ts2); - expect(store2.list()).toHaveLength(1); + expect(store2.listByType(typeHash)).toHaveLength(1); }); }); @@ -151,7 +151,7 @@ describe("createFsStore – has and list", () => { expect(store.has(hash)).toBe(true); }); - test("list returns all stored hashes", async () => { + test("listByType returns all stored hashes for a type", async () => { const store = createFsStore(dir); const typeHash = await computeSelfHash({ name: "t" }); @@ -159,16 +159,16 @@ describe("createFsStore – has and list", () => { const h2 = await store.put(typeHash, { a: 2 }); const h3 = await store.put(typeHash, { a: 3 }); - const all = store.list(); + const all = store.listByType(typeHash); expect(all).toHaveLength(3); expect(all).toContain(h1); expect(all).toContain(h2); expect(all).toContain(h3); }); - test("list returns empty array on fresh store", () => { + test("listByType returns empty array on fresh store", () => { const store = createFsStore(dir); - expect(store.list()).toEqual([]); + expect(store.listByType("0000000000000")).toEqual([]); }); test("get returns null for unknown hash", () => { diff --git a/packages/json-cas-fs/src/store.ts b/packages/json-cas-fs/src/store.ts index c3f1e21..99b8181 100644 --- a/packages/json-cas-fs/src/store.ts +++ b/packages/json-cas-fs/src/store.ts @@ -167,10 +167,6 @@ export function createFsStore(dir: string): Store { return data.has(hash); }, - list(): Hash[] { - return [...data.keys()]; - }, - listByType(typeHash: Hash): Hash[] { return typeIndex.get(typeHash) ?? []; }, diff --git a/packages/json-cas/src/index.test.ts b/packages/json-cas/src/index.test.ts index 3148003..58c45a2 100644 --- a/packages/json-cas/src/index.test.ts +++ b/packages/json-cas/src/index.test.ts @@ -97,7 +97,7 @@ describe("createMemoryStore – put and get", () => { const h1 = await store.put(typeHash, { n: 42 }); const h2 = await store.put(typeHash, { n: 42 }); expect(h1).toBe(h2); - expect(store.list()).toHaveLength(1); + expect(store.listByType(typeHash)).toHaveLength(1); }); test("put does not create self-referencing nodes", async () => { @@ -127,9 +127,9 @@ describe("createMemoryStore – put and get", () => { }); // ────────────────────────────────────────────────────────────────────────────── -// Step 4: store.has() and store.list() +// Step 4: store.has() // ────────────────────────────────────────────────────────────────────────────── -describe("createMemoryStore – has and list", () => { +describe("createMemoryStore – has", () => { test("has returns false before put, true after", async () => { const store = createMemoryStore(); const typeHash = await computeSelfHash({ name: "t" }); @@ -140,7 +140,7 @@ describe("createMemoryStore – has and list", () => { expect(store.has(hash)).toBe(true); }); - test("list returns all stored hashes", async () => { + test("listByType returns all stored hashes for a type", async () => { const store = createMemoryStore(); const typeHash = await computeSelfHash({ name: "t" }); @@ -148,16 +148,16 @@ describe("createMemoryStore – has and list", () => { const h2 = await store.put(typeHash, { a: 2 }); const h3 = await store.put(typeHash, { a: 3 }); - const all = store.list(); + const all = store.listByType(typeHash); expect(all).toHaveLength(3); expect(all).toContain(h1); expect(all).toContain(h2); expect(all).toContain(h3); }); - test("list returns empty array on fresh store", () => { + test("listByType returns empty array on fresh store", () => { const store = createMemoryStore(); - expect(store.list()).toEqual([]); + expect(store.listByType("0000000000000")).toEqual([]); }); }); @@ -249,7 +249,6 @@ describe("bootstrap", () => { put: async () => "0000000000000", get: () => null, has: () => false, - list: () => [], listByType: () => [], }; await expect(bootstrap(store)).rejects.toThrow( @@ -295,6 +294,6 @@ describe("bootstrap", () => { const h2 = await bootstrap(store); expect(h1).toBe(h2); - expect(store.list()).toHaveLength(1); + expect(store.listByType(h1)).toHaveLength(1); }); }); diff --git a/packages/json-cas/src/store.ts b/packages/json-cas/src/store.ts index 211e039..c54df1d 100644 --- a/packages/json-cas/src/store.ts +++ b/packages/json-cas/src/store.ts @@ -44,10 +44,6 @@ export function createMemoryStore(): Store { return data.has(hash); }, - list(): Hash[] { - return [...data.keys()]; - }, - listByType(typeHash: Hash): Hash[] { const set = byType.get(typeHash); return set ? [...set] : []; diff --git a/packages/json-cas/src/types.ts b/packages/json-cas/src/types.ts index be8ee90..a715348 100644 --- a/packages/json-cas/src/types.ts +++ b/packages/json-cas/src/types.ts @@ -23,6 +23,5 @@ export type Store = { put(typeHash: Hash, payload: unknown): Promise; get(hash: Hash): CasNode | null; has(hash: Hash): boolean; - list(): Hash[]; listByType(typeHash: Hash): Hash[]; };