v4: multilayer storage adapter pattern#12
Merged
Conversation
Replace the single in-memory store with a composable IStorageAdapter
contract: reads cascade L1 → Ln, hits back-fill missing layers preserving
storedAt, and writes synthesize meta on L1 then propagate to deeper
layers. Adapters are required at construction; clear/delete/isCached
become async; keys() is removed; an optional namespace prefix isolates
instances that share an adapter; Cacheables gains a TMeta generic for
typed sidecar metadata. Ships a built-in MemoryAdapter and refines
read() to return { value } | undefined so adapters can store undefined
values without colliding with the absence signal.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4 tasks
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.
Summary
IStorageAdaptercontract: reads cascade L1 → Ln, hits back-fill missing layers preservingstoredAt, and writes synthesize meta on L1 then propagate to deeper layers using the samestoredAt.adaptersconstructor option; ship a built-inMemoryAdapter; add an optionalnamespaceprefix; expose aTMetageneric for typed sidecar metadata;delete/clear/isCachedbecome async;keys()is removed; any adapter throw rejectsremember()(strict mode).IStorageAdapter.readreturns{ value: T } | undefinedso adapters can storeundefinedvalues without colliding with the absence signal.Test plan
npm run typecheck(root) andnpx tsc --noEmit -p tests/tsconfig.jsonnpm run eslintplus eslint over testsnpm test— 53 tests across 5 suites: cascade behavior, strict error propagation, dedup, namespace, MemoryAdapter, fetchPolicies, index🤖 Generated with Claude Code