Skip to content

feat: file-based storage#93

Open
ReinhardHatko wants to merge 5 commits intomainfrom
rh/filebased-storage
Open

feat: file-based storage#93
ReinhardHatko wants to merge 5 commits intomainfrom
rh/filebased-storage

Conversation

@ReinhardHatko
Copy link
Copy Markdown
Contributor

adding file-based kvstorage, mainly for cli usage.

Closes #92.

When localStorage is unavailable but node:fs is, persist data as JSON
files under ~/.polkadot-apps/ (override with new storageDir option)
instead of dropping writes silently. Replaces the misleading fallback
to createLocalStorageBackend with an explicit createNoopBackend for
edge runtimes that have neither.
Replace the in-house file-based StorageAdapter with a thin bridge to
createKvStore from @polkadot-apps/storage, which now provides the same
Node.js filesystem backend. node-storage.ts becomes a small adapter that
translates the KvStore API to the novasama StorageAdapter shape, adding
subscribe notifications and neverthrow wrapping.

createTerminalAdapter is now async since it resolves the storage backend
lazily; consumers must await the call.
@polkadot-api/ws-provider@0.7.5 (via polkadot-api@1.23.3) returns a
JsonRpcProvider typed against @polkadot-api/json-rpc-provider@0.0.4
(string messages), while @novasamatech/statement-store@0.6.17's
createLazyClient expects the same interface from json-rpc-provider@0.2.0
(typed JsonRpcMessage). The two are structurally incompatible in
TypeScript but behaviorally identical at runtime.

Cast at the single call site so terminal compiles cleanly. Remove when
upstream packages converge on one json-rpc-provider version.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 97.26% (🎯 90%) 1740 / 1789
🔵 Statements 96.82% (🎯 90%) 1832 / 1892
🔵 Functions 96.3% (🎯 90%) 417 / 433
🔵 Branches 90.43% (🎯 90%) 870 / 962
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/storage/src/kv-store.ts 96.19% 90.62% 100% 96.87% 64, 97, 151, 257
packages/terminal/src/node-storage.ts 100% 83.33% 100% 100%
Generated in workflow #230 for commit 9679bb1 by the Vitest Coverage Report Action

Copy link
Copy Markdown
Member

@UtkarshBhardwaj007 UtkarshBhardwaj007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please address comments and merge.

You also need to update some skills, skills/polkadot-utilities/references/storage-api.md and polkadot-app-builder package selector

@@ -0,0 +1,5 @@
---
"@polkadot-apps/storage": minor
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changeset for @polkadot-apps/terminal. createTerminalAdapter changed from sync to async - breaking change?

async function set(key: string, value: string): Promise<void> {
try {
await ensureDir();
await fs.writeFile(fp(key), value, "utf-8");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Consider write-to-temp-then-rename pattern: writeFile(fp(key) + '.tmp', value) then rename(fp(key) + '.tmp', fp(key)). rename is atomic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: file-based storage implementation

2 participants