@wovin/storage-fs 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +170 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# @wovin/storage-fs
|
|
2
|
+
|
|
3
|
+
Local filesystem storage backend for wovin using LMDB (Lightning Memory-Mapped Database).
|
|
4
|
+
|
|
5
|
+
Persists wovin threads (applogs/blocks) to the local filesystem.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **StorageConnector** interface - Store CAR files in LMDB
|
|
10
|
+
- **RetrievalConnector** interface - Retrieve CAR files by CID
|
|
11
|
+
- **Single file storage** - Stores all blocks in one LMDB database file
|
|
12
|
+
- **ACID transactions** - Atomic writes via LMDB transactions
|
|
13
|
+
- **Built on LMDB** - Leverages Lightning Memory-Mapped Database for reliability
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @wovin/storage-fs
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Basic Storage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { LmdbConnector } from '@wovin/storage-fs'
|
|
27
|
+
import { makeCarBlob, encodeBlockOriginal } from '@wovin/core/ipfs'
|
|
28
|
+
|
|
29
|
+
// Initialize connector
|
|
30
|
+
const connector = await LmdbConnector.init('./data/wovin-storage')
|
|
31
|
+
|
|
32
|
+
// Create and store a block
|
|
33
|
+
const testData = { hello: 'world', ts: Date.now() }
|
|
34
|
+
const block = await encodeBlockOriginal(testData)
|
|
35
|
+
const carBlob = await makeCarBlob(block.cid, [block])
|
|
36
|
+
|
|
37
|
+
// Store the CAR file
|
|
38
|
+
const rootCid = await connector.storeCar(carBlob)
|
|
39
|
+
console.log('Stored with CID:', rootCid.toString())
|
|
40
|
+
|
|
41
|
+
// Verify block exists
|
|
42
|
+
console.log('Block exists:', connector.has(rootCid))
|
|
43
|
+
|
|
44
|
+
// Retrieve the block
|
|
45
|
+
const retrievedBytes = connector.get(rootCid)
|
|
46
|
+
|
|
47
|
+
// Retrieve as CAR
|
|
48
|
+
const car = await connector.retrieveCar(rootCid)
|
|
49
|
+
|
|
50
|
+
// Clean up
|
|
51
|
+
connector.close()
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Thread Snapshots
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { LmdbConnector } from '@wovin/storage-fs'
|
|
58
|
+
import { makeCarBlob, encodeBlock } from '@wovin/core/ipfs'
|
|
59
|
+
import { ThreadInMemory } from '@wovin/core/thread'
|
|
60
|
+
|
|
61
|
+
const connector = await LmdbConnector.init('./data/wovin-storage')
|
|
62
|
+
|
|
63
|
+
// Create applogs
|
|
64
|
+
const applogs = [
|
|
65
|
+
{ ag: 'alice', en: 'thread-123', at: 'text', vl: 'Hello' },
|
|
66
|
+
{ ag: 'alice', en: 'thread-123', at: 'text', vl: 'World' },
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
// Encode as blocks
|
|
70
|
+
const blocks = applogs.map(applog => encodeBlock(applog))
|
|
71
|
+
|
|
72
|
+
// Create thread snapshot CAR
|
|
73
|
+
const snapshotRoot = blocks[0]
|
|
74
|
+
const snapshotCar = await makeCarBlob(snapshotRoot.cid, blocks)
|
|
75
|
+
|
|
76
|
+
// Store thread snapshot
|
|
77
|
+
const snapshotCid = await connector.storeCar(snapshotCar)
|
|
78
|
+
|
|
79
|
+
// Later: retrieve and restore thread
|
|
80
|
+
const retrievedCar = await connector.retrieveCar(snapshotCid)
|
|
81
|
+
// Use CarReader to decode applogs...
|
|
82
|
+
|
|
83
|
+
connector.close()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## API
|
|
87
|
+
|
|
88
|
+
### `LmdbConnector.init(path: string): Promise<LmdbConnector>`
|
|
89
|
+
|
|
90
|
+
Initialize the connector with an LMDB database at the specified path.
|
|
91
|
+
|
|
92
|
+
**Parameters:**
|
|
93
|
+
- `path` - Filesystem path where LMDB data will be stored
|
|
94
|
+
|
|
95
|
+
**Returns:** Promise resolving to LmdbConnector instance
|
|
96
|
+
|
|
97
|
+
### `storeCar(car: Blob): Promise<CID>`
|
|
98
|
+
|
|
99
|
+
Store a CAR (Content Addressable aRchive) file. Extracts all blocks and stores them individually in LMDB.
|
|
100
|
+
|
|
101
|
+
**Parameters:**
|
|
102
|
+
- `car` - CAR file as Blob
|
|
103
|
+
|
|
104
|
+
**Returns:** Promise resolving to the root CID
|
|
105
|
+
|
|
106
|
+
### `retrieveCar(cid: CID): Promise<CarReader>`
|
|
107
|
+
|
|
108
|
+
Retrieve a CAR file by CID. Reconstructs the CAR from stored blocks.
|
|
109
|
+
|
|
110
|
+
**Parameters:**
|
|
111
|
+
- `cid` - The CID to retrieve
|
|
112
|
+
|
|
113
|
+
**Returns:** Promise resolving to CarReader
|
|
114
|
+
|
|
115
|
+
### `get(cid: CID): Uint8Array | undefined`
|
|
116
|
+
|
|
117
|
+
Get a single block's bytes by CID.
|
|
118
|
+
|
|
119
|
+
**Parameters:**
|
|
120
|
+
- `cid` - The CID to retrieve
|
|
121
|
+
|
|
122
|
+
**Returns:** Block bytes or undefined if not found
|
|
123
|
+
|
|
124
|
+
### `has(cid: CID): boolean`
|
|
125
|
+
|
|
126
|
+
Check if a block exists in the store.
|
|
127
|
+
|
|
128
|
+
**Parameters:**
|
|
129
|
+
- `cid` - The CID to check
|
|
130
|
+
|
|
131
|
+
**Returns:** boolean
|
|
132
|
+
|
|
133
|
+
### `close(): void`
|
|
134
|
+
|
|
135
|
+
Close the LMDB database and clean up resources.
|
|
136
|
+
|
|
137
|
+
## Storage Backend: LMDB
|
|
138
|
+
|
|
139
|
+
This package uses [lmdb-js](https://github.com/kriszyp/lmdb-js) as the storage backend:
|
|
140
|
+
|
|
141
|
+
- **Memory-mapped** - OS-level memory mapping for efficient data access
|
|
142
|
+
- **ACID** - Atomic, consistent, isolated, durable transactions
|
|
143
|
+
- **Single file** - Stores entire database in one file
|
|
144
|
+
- **Cross-process** - Shared memory allows multiple processes to access simultaneously
|
|
145
|
+
- **Compression** - Optional compression for small values
|
|
146
|
+
|
|
147
|
+
## When to Use
|
|
148
|
+
|
|
149
|
+
- ✅ Local development environments
|
|
150
|
+
- ✅ Desktop/Electron apps
|
|
151
|
+
- ✅ Node.js servers with persistent storage
|
|
152
|
+
- ✅ Testing and integration tests
|
|
153
|
+
- ✅ Offline-first applications
|
|
154
|
+
|
|
155
|
+
## When NOT to Use
|
|
156
|
+
|
|
157
|
+
- ❌ Browser/WASM environments (use `@wovin/connect-web3storage` instead)
|
|
158
|
+
- ❌ Cloud-only deployments (use `@wovin/connect-nftstorage` instead)
|
|
159
|
+
- ❌ Multi-machine clusters (use `@wovin/connect-s3` instead)
|
|
160
|
+
|
|
161
|
+
## Related Packages
|
|
162
|
+
|
|
163
|
+
- [`@wovin/core`](../core) - Core wovin types and utilities
|
|
164
|
+
- [`@wovin/connect-nftstorage`](../connect-nftstorage) - Cloud storage via NFT.storage
|
|
165
|
+
- [`@wovin/connect-s3`](../connect-s3) - Cloud storage via AWS S3
|
|
166
|
+
- [`@wovin/connect-web3storage`](../connect-web3storage) - Cloud storage via Web3.storage
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
Same as wovin monorepo
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wovin/storage-fs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.min.js",
|
|
6
6
|
"module": "./dist/index.min.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@ipld/car": "^5.2.6",
|
|
26
|
-
"@wovin/core": "0.0.
|
|
26
|
+
"@wovin/core": "0.0.18",
|
|
27
27
|
"besonders-logger": "1.0.1",
|
|
28
28
|
"lmdb": "^3.0.0",
|
|
29
29
|
"multiformats": "^13.0.1"
|