refactor: 設定系ストアを汎用ファクトリへ集約し class を廃止 - #51
Merged
Conversation
KeywordRuleStore / NotificationSettingsStore / Kv の 3 つの class を廃止し、 クロージャベースのファクトリへ統一した。 - Kv を class から createKv() クロージャへ。lazy-open 状態 (旧 #kv private フィールド) はクロージャ変数に閉じる - CRUD の骨格を汎用化した collectionStore / singletonStore を server/store/kv.ts に追加。型 CollectionStore<T, Input> / SingletonStore<T> も export する - keyword-rules / notification-settings は prefix・型ガード・正規化を渡すだけの 薄いファクトリ (createKeywordRuleStore / createNotificationSettingsStore) に縮めた - collection の既定ソートを createdAt 降順 → id (登録の新しい順) にし、 keyword-rules 側の重複ソート指定を削除 - main.ts は new X() を createX() に置換。routes はストアのサブセット型 (KeywordRuleStoreLike / NotificationSettingsStoreLike) に構造的に依存するため無変更 - store 系テストは new X(kv) を createX(kv) に追従。挙動契約は変更なし なお Deno KV はレコードに id を自動採番しない (versionstamp は更新のたびに 変わり安定 id にならない) ため、keyword-rules の crypto.randomUUID() による id 採番は現状維持とした。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
設定系データの永続化ストア (
server/store/) を、class ベースからクロージャベースの汎用ファクトリへ集約するリファクタ。挙動は変更しない。動機
KeywordRuleStoreとNotificationSettingsStoreは「KV 配線 + CRUD」の骨格が重複しており、各 store が#kvの保持と注入を個別に書いていた。骨格を汎用化し、各ドメインは「キー設計・型ガード・正規化」を渡すだけの薄い構成にする。あわせて class を廃止し、依存はクロージャに束ねる。変更点
store/kv.tsKvをclass→createKv()クロージャへ。lazy-open 状態 (旧#kvprivate) はクロージャ変数に閉じる。collectionStore(prefix 配下に複数レコード、各id+createdAt持ち)とsingletonStore(単一キー)を追加。型CollectionStore<T, Input>/SingletonStore<T>も export。createdAt降順 →id(登録の新しい順)。store/keyword-rules.ts/store/notification-settings.tscreateKeywordRuleStore(kv)/createNotificationSettingsStore(kv)に。prefix・型ガード(isKeywordRule)・正規化(normalizeNotificationSettings)を渡すだけの薄い factory に縮小。main.ts:new X()→createX()の置換のみ。routes はストアのサブセット型(*Like)に構造的に依存するため無変更。store/*.test.ts:new X(kv)→createX(kv)に追従。挙動契約は不変。設計判断
id)と singleton 型(単一値)は形が異なり、単一 CRUD interface に押し込めると singleton 側に無意味なlist/add/remove(id)が生える。2 種のファクトリへ分けた。isKeywordRule(=matchesStoredSchema)、notification-settings は旧形状補完を含むnormalizeNotificationSettings。汎用list<T>()の無検証キャストでは KV に残る旧形状・壊れた値を drop できないため、検証はドメイン側に残す。idは現状維持: Deno KV はレコードにidを自動採番しない。versionstampは更新のたびに変わり安定idにならないため、crypto.randomUUID()による採番をそのまま使う。確認
deno task test:server→ 92 passed / 0 failed(store/keyword-rules.ts・store/notification-settings.tsは行・分岐 100%)。deno check server/main.ts(ファクトリ返り値 → routes の*Like構造適合)通過。deno lint/deno fmt --check(変更ファイル)通過。🤖 Generated with Claude Code