feat: ID-first storage architecture + remove memory-unsafe APIs (v6.0.0)
BREAKING CHANGES:
**ID-First Storage Paths**
- Direct O(1) entity access without type lookups
- Before: entities/nouns/{TYPE}/metadata/{SHARD}/{ID}.json
- After: entities/nouns/{SHARD}/{ID}/metadata.json
- Migration handled automatically on first init()
**Removed Memory-Unsafe APIs**
- Removed brain.merge() - loaded all entities into memory
- Removed brain.diff() - loaded all entities into memory
- Removed brain.data().backup() - loaded all entities into memory
- Removed brain.data().restore() - depended on backup()
- Removed CLI commands: backup, restore, cow merge
**Migration Paths**
- merge() → Use checkout() or manually copy entities with pagination
- diff() → Use asOf() with manual paginated comparison
- backup() → Use fork() for instant COW snapshots
- restore() → Use checkout() to switch to snapshot branch
Core Improvements:
- ✅ All 8 storage adapters properly call super.init()
- ✅ GraphAdjacencyIndex integration in BaseStorage.init()
- ✅ Fixed ID-first path bugs (vector.json → vectors.json)
- ✅ Fixed MemoryStorage.initializeCounts() for ID-first paths
- ✅ New VFS APIs: du(), access(), find()
- ✅ Comprehensive documentation with migration guides
Storage Adapters Fixed:
- MemoryStorage, FileSystemStorage, AzureBlobStorage
- GCSStorage, R2Storage, S3CompatibleStorage
- OPFSStorage, HistoricalStorageAdapter
Files Changed: 28 files, +1,075/-1,933 lines (net -858)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
9730ca41e5
commit
42ae5be455
28 changed files with 1079 additions and 1937 deletions
|
|
@ -123,25 +123,25 @@ await brain.relate({ from: id1, to: id2, type: VerbType.RelatesTo })
|
|||
- Transaction operations don't need to know about shards
|
||||
- Rollback works across all shards involved
|
||||
|
||||
### TypeAware Storage
|
||||
### ID-First Storage (v6.0.0+)
|
||||
|
||||
✅ **Fully Compatible**
|
||||
|
||||
Transactions work with type-specific routing:
|
||||
Transactions work with direct ID-first paths - no type routing needed!
|
||||
|
||||
```typescript
|
||||
// Entities routed to type-specific storage paths
|
||||
// Entities stored with direct ID-first paths
|
||||
const personId = await brain.add({
|
||||
data: { name: 'John Doe' },
|
||||
type: NounType.Person // → entities/nouns/person/<shard>/...
|
||||
type: NounType.Person // → entities/nouns/{shard}/{id}/metadata.json
|
||||
})
|
||||
|
||||
const orgId = await brain.add({
|
||||
data: { name: 'Acme Corp' },
|
||||
type: NounType.Organization // → entities/nouns/organization/<shard>/...
|
||||
type: NounType.Organization // → entities/nouns/{shard}/{id}/metadata.json
|
||||
})
|
||||
|
||||
// Type changes handled atomically
|
||||
// Type changes handled atomically (type is just metadata)
|
||||
await brain.update({
|
||||
id: personId,
|
||||
type: NounType.Organization, // Type change
|
||||
|
|
@ -150,10 +150,11 @@ await brain.update({
|
|||
```
|
||||
|
||||
**How It Works:**
|
||||
- Type information carried in metadata
|
||||
- Storage layer handles type-specific routing
|
||||
- Type cache updated/restored during rollback
|
||||
- Type information stored in metadata.noun field
|
||||
- Storage layer uses O(1) ID-first path construction
|
||||
- No type cache needed (removed in v6.0.0)
|
||||
- Type counters adjusted on commit/rollback
|
||||
- 40x faster on cloud storage (eliminates 42-type search)
|
||||
|
||||
### Distributed Storage
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue