From 9ebfc64e301d6e9bdbfabb9648bdab79f045b908 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 28 Sep 2026 15:11:10 +0000 Subject: [PATCH] fix: give ReadOnlyTabularStorage a putByUniqueKey no-op @workglow/storage 0.6.8 made putByUniqueKey a required ITabularStorage member, so the dry-run wrapper no longer implemented the interface and typecheck failed on main. The new method no-ops like put(), and reports inserted: false so a caller does not skip reading back rows the underlying storage holds. Fixes #382 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014X8ZuuuzKx9jryN5ndaVcb --- src/storage/ReadOnlyTabularStorage.test.ts | 24 ++++++++++++++++++++++ src/storage/ReadOnlyTabularStorage.ts | 13 ++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/storage/ReadOnlyTabularStorage.test.ts diff --git a/src/storage/ReadOnlyTabularStorage.test.ts b/src/storage/ReadOnlyTabularStorage.test.ts new file mode 100644 index 00000000..dacc459c --- /dev/null +++ b/src/storage/ReadOnlyTabularStorage.test.ts @@ -0,0 +1,24 @@ +/** + * @license + * Copyright 2026 Steven Roussey + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, expect, it } from "vitest"; +import { InMemoryTabularStorage } from "workglow"; +import { CikNamePrimaryKeyNames, CikNameSchema } from "./entity/CikNameSchema"; +import { ReadOnlyTabularStorage } from "./ReadOnlyTabularStorage"; + +describe("ReadOnlyTabularStorage", () => { + it("putByUniqueKey writes nothing and reports an overwrite", async () => { + const inner = new InMemoryTabularStorage(CikNameSchema, CikNamePrimaryKeyNames, []); + await inner.put({ cik: 1, name: "Before" }); + const readOnly = new ReadOnlyTabularStorage(inner); + + const result = await readOnly.putByUniqueKey({ cik: 1, name: "After" }, ["cik"]); + + expect(result).toEqual({ entity: { cik: 1, name: "After" }, inserted: false }); + expect(await inner.get({ cik: 1 })).toEqual({ cik: 1, name: "Before" }); + expect(await readOnly.size()).toBe(1); + }); +}); diff --git a/src/storage/ReadOnlyTabularStorage.ts b/src/storage/ReadOnlyTabularStorage.ts index 036b679e..98d9d69c 100644 --- a/src/storage/ReadOnlyTabularStorage.ts +++ b/src/storage/ReadOnlyTabularStorage.ts @@ -20,6 +20,7 @@ import type { TabularEventParameters, TabularSubscribeOptions, TypedArraySchemaOptions, + UniqueKeyPutResult, } from "workglow"; /** @@ -45,6 +46,18 @@ export class ReadOnlyTabularStorage< return _value as unknown as Entity; } + /** + * Reports an overwrite rather than an insert: `inserted: true` tells a caller + * nothing can be keyed by the row yet, so it would skip reading back rows that + * the underlying storage does hold. + */ + async putByUniqueKey( + value: InsertType, + _uniqueKey: ReadonlyArray + ): Promise> { + return { entity: value as unknown as Entity, inserted: false }; + } + async putBulk(values: InsertType[]): Promise { return values as unknown as Entity[]; }