Brainstorm initial API and modify db to be more FUSE friendly
This commit is contained in:
parent
0a444a55c4
commit
96c9e62354
3 changed files with 183 additions and 105 deletions
75
trovedb/trove.py
Normal file
75
trovedb/trove.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
from typing import Protocol, runtime_checkable, Optional, Dict, List, Self
|
||||
from uuid import UUID
|
||||
from pathlib import PurePosixPath
|
||||
|
||||
NODE_ROOT_ID = 1
|
||||
|
||||
@runtime_checkable
|
||||
class Note(Protocol):
|
||||
"""
|
||||
Protocol for a Note item.
|
||||
Represents access to an individual note's content and metadata.
|
||||
"""
|
||||
@property
|
||||
def object_id(self) -> int:
|
||||
"""The unique identifier for this note."""
|
||||
...
|
||||
|
||||
def get_raw_metadata(self, key: str) -> Optional[bytes]:
|
||||
"""Retrieve metadata value for the given key."""
|
||||
...
|
||||
|
||||
def set_raw_metadata(self, key: str, value: bytes) -> None:
|
||||
"""Set metadata value for the given key."""
|
||||
...
|
||||
|
||||
@runtime_checkable
|
||||
class Blob(Protocol):
|
||||
def read(self) -> bytes:
|
||||
"""Read the raw content of the note."""
|
||||
...
|
||||
|
||||
def write(self, data: bytes) -> None:
|
||||
"""Write new content to the note."""
|
||||
...
|
||||
|
||||
@runtime_checkable
|
||||
class Tree(Protocol):
|
||||
def link(self, name: str, note: Note):
|
||||
"""Link name to a given note."""
|
||||
...
|
||||
|
||||
def unlink(self, name: str):
|
||||
"""Remove name from the tree."""
|
||||
...
|
||||
|
||||
def mkdir(self, name: str) -> Self:
|
||||
"""Create a new Tree with the given name."""
|
||||
...
|
||||
|
||||
class BlobNote(Note, Blob):
|
||||
"""Blob Note"""
|
||||
|
||||
class TreeNote(Note, Tree):
|
||||
"""Tree Note"""
|
||||
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class Trove(Protocol):
|
||||
"""
|
||||
Protocol for the Trove database API.
|
||||
Provides high-level access to notes and trees.
|
||||
"""
|
||||
|
||||
def get_raw_note(self, note: int) -> Optional[Note]:
|
||||
"""Retrieve a note by a UUID"""
|
||||
...
|
||||
|
||||
def create_blob(self, data: bytes | None = None) -> BlobNote:
|
||||
"""Create a new blob node at the given path with content"""
|
||||
...
|
||||
|
||||
def get_root(self) -> TreeNote:
|
||||
"""Get Tree Node at the given path"""
|
||||
...
|
||||
Loading…
Add table
Add a link
Reference in a new issue