Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
278eaa9
feat: Add StorageService for offloading large controller data
andrepimenta Nov 19, 2025
e844fdd
refactor(storage-service): Move getAllKeys/clear logic to adapters
andrepimenta Nov 19, 2025
19c7d6f
refactor: Adapters now build storage keys (not core)
andrepimenta Nov 25, 2025
5fedbc0
refactor(storage-service): delegate key building and serialization to…
andrepimenta Nov 25, 2025
5af0861
docs(storage-service): update CHANGELOG for initial release
andrepimenta Nov 25, 2025
de5388c
docs(storage-service): fix CHANGELOG format
andrepimenta Nov 25, 2025
e493d3e
docs(storage-service): update README with current API and precise met…
andrepimenta Nov 25, 2025
81100c2
build: add storage-service to tsconfig.build.json
andrepimenta Nov 26, 2025
f5c5aec
Merge branch 'main' into storage-service
andrepimenta Nov 26, 2025
04939f6
docs(storage-service): add JSDoc guidance for large value storage
andrepimenta Nov 26, 2025
3fe4314
Update packages/storage-service/src/StorageService.ts
andrepimenta Nov 26, 2025
84adfd5
Update packages/storage-service/src/StorageService.ts
andrepimenta Nov 26, 2025
7ac8bfc
refactor(storage-service): remove itemRemoved events, keep only itemSet
andrepimenta Nov 27, 2025
24b150e
Merge branch 'storage-service' of https://github.com/MetaMask/core in…
andrepimenta Nov 27, 2025
65efd41
chore(storage-service): add dual MIT+Apache2 license
andrepimenta Nov 27, 2025
60efad1
refactor(storage-service): use unknown instead of generic types
andrepimenta Nov 27, 2025
2222e57
refactor(storage-service): use generate-method-action-types pattern
andrepimenta Nov 27, 2025
ce68a05
Update packages/storage-service/package.json
andrepimenta Nov 27, 2025
afde837
docs(storage-service): simplify README to focus on usage
andrepimenta Nov 27, 2025
ae501a3
Merge branch 'storage-service' of https://github.com/MetaMask/core in…
andrepimenta Nov 27, 2025
81c9cf8
docs(storage-service): simplify CHANGELOG for initial release
andrepimenta Nov 27, 2025
625eee6
fix(storage-service): change event payload order to [key, value]
andrepimenta Nov 27, 2025
bda7243
Merge branch 'main' into storage-service
andrepimenta Nov 27, 2025
d3a7e4e
Fix prettier
andrepimenta Nov 27, 2025
389e50a
Merge branch 'storage-service' of https://github.com/MetaMask/core in…
andrepimenta Nov 27, 2025
3aeafac
Fix keywords
andrepimenta Nov 27, 2025
c46e2e2
Update packages/storage-service/package.json
andrepimenta Nov 27, 2025
1b48670
test(storage-service): add tests for itemSet event
andrepimenta Nov 27, 2025
8050f20
Merge branch 'storage-service' of https://github.com/MetaMask/core in…
andrepimenta Nov 27, 2025
9a65054
refactor(storage-service): use Json type instead of unknown
andrepimenta Nov 27, 2025
d6fe459
chore(storage-service): add CODEOWNERS and teams.json entries
andrepimenta Nov 27, 2025
5b4faeb
Update packages/storage-service/src/StorageService.ts
andrepimenta Nov 28, 2025
363533a
Update packages/storage-service/src/InMemoryStorageAdapter.ts
andrepimenta Nov 28, 2025
f5ccb18
Update packages/storage-service/src/InMemoryStorageAdapter.ts
andrepimenta Nov 28, 2025
b5c5d79
feat(storage-service): add StorageGetResult type for getItem responses
andrepimenta Nov 28, 2025
8557995
Merge branch 'storage-service' of https://github.com/MetaMask/core in…
andrepimenta Nov 28, 2025
7ccd865
Update packages/storage-service/CHANGELOG.md
andrepimenta Nov 28, 2025
a139816
fix(storage-service): fix prettier formatting in test
andrepimenta Nov 28, 2025
5598df9
Merge branch 'storage-service' of https://github.com/MetaMask/core in…
andrepimenta Nov 28, 2025
bbd8e39
Merge branch 'main' into storage-service
andrepimenta Nov 28, 2025
cf634fb
Prettier fix
andrepimenta Nov 28, 2025
6bf384a
Fix return types on StorageServiceGetItemAction
andrepimenta Nov 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs(storage-service): add JSDoc guidance for large value storage
- Add warnings that service is designed for large values (100KB+)
- Add examples of good vs bad usage patterns
- Discourage many small key-value pairs in favor of single large objects
  • Loading branch information
andrepimenta committed Nov 26, 2025
commit 04939f6e3e3990d8de8efe04e71ebb395d64efa6
20 changes: 18 additions & 2 deletions packages/storage-service/src/StorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,27 @@ export class StorageService {
}

/**
* Store data in storage.
* Store large data in storage.
*
* ⚠️ **Designed for large values (100KB+), not many small ones.**
* Each storage operation has I/O overhead. For best performance,
* store one large object rather than many small key-value pairs.
*
* @example Good: Store entire cache as one value
* ```typescript
* await service.setItem('TokenList', 'cache', { '0x1': [...], '0x38': [...] });
* ```
*
* @example Avoid: Many small values
* ```typescript
* // ❌ Don't do this - too many small writes
* await service.setItem('TokenList', 'cache:0x1', [...]);
* await service.setItem('TokenList', 'cache:0x38', [...]);
* ```
*
* @param namespace - Controller namespace (e.g., 'SnapController').
* @param key - Storage key (e.g., 'npm:@metamask/example-snap:sourceCode').
* @param value - Data to store (will be JSON stringified).
* @param value - Data to store (should be 100KB+ for optimal use).
* @template T - The type of the value being stored.
*/
async setItem<T>(namespace: string, key: string, value: T): Promise<void> {
Expand Down
20 changes: 19 additions & 1 deletion packages/storage-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import type { Messenger } from '@metamask/messenger';
* Each client (mobile, extension) implements this interface
* with their preferred storage mechanism.
*
* ⚠️ **Designed for large, infrequently accessed data (100KB+)**
*
* ✅ **Use for:**
* - Snap source code (~6 MB per snap)
* - Token metadata caches (~4 MB)
* - Large API response caches
*
* ❌ **Avoid for:**
* - Small values (< 10 KB) - use controller state instead
* - Frequently accessed data - use controller state instead
* - Many small key-value pairs - use a single large object instead
*
* @example Mobile implementation using FilesystemStorage
* @example Extension implementation using IndexedDB
* @example Tests using InMemoryStorageAdapter
Expand All @@ -21,7 +33,13 @@ export type StorageAdapter = {
getItem(namespace: string, key: string): Promise<unknown>;

/**
* Store an item in storage.
* Store a large value in storage.
*
* ⚠️ **Store large values, not many small ones.**
* Each storage operation has I/O overhead. For best performance:
* - Store one large object rather than many small key-value pairs
* - Minimum recommended size: 100 KB per value
*
* Adapter is responsible for:
* - Building the full storage key
* - Wrapping value with metadata (timestamp, etc.)
Expand Down
Loading