v-common 0.25.0

common part of the veda platform
Documentation
# Storage System Overview

The storage system provides a unified interface for different storage backends including LMDB, Tarantool, Remote Storage, and In-Memory Storage.

## Core Components

### StorageId
Enum that defines different storage spaces:
- `Individuals` - For storing individual objects
- `Tickets` - For storing tickets
- `Az` - For storing authorization data

### StorageMode
Defines storage access modes:
- `ReadOnly` - Only read operations allowed
- `ReadWrite` - Both read and write operations allowed

## VStorage Class
Main storage interface that provides unified access to different storage backends.

### Available Storage Backends
1. LMDB Storage - Persistent disk-based storage
2. Tarantool Storage - In-memory database with persistence
3. Remote Storage - Client for remote storage access

### Creating Storage Instances
```rust
use v_storage::{VStorage, StorageMode};
use v_storage::storage_factory::StorageProvider;

// Create LMDB storage
let lmdb = VStorage::new(StorageProvider::lmdb("/path/to/db", StorageMode::ReadWrite, None));

// Create Tarantool storage
let tt = VStorage::new(StorageProvider::tarantool("host:port", "login", "pass"));

// Create Remote storage
let remote = VStorage::new(StorageProvider::remote("remote_addr"));

// Create empty storage
let none = VStorage::none();
```

## Common Usage Patterns

### Individual Operations
```rust
use v_storage::{StorageId, StorageResult};

let mut storage = VStorage::new(StorageProvider::lmdb("./data", StorageMode::ReadWrite, None));
let mut individual = Individual::default();

// Read individual
let result = storage.get_individual("id", &mut individual);

// Read from specific storage
let result = storage.get_individual_from_storage(StorageId::Individuals, "id", &mut individual);
```

### Key-Value Operations
```rust
// Raw bytes
let raw_value = storage.get_raw_value(StorageId::Individuals, "key");
```

## Async Storage

The `async_storage` module provides async functions for working with storage and authorization.

### AuthorizationProvider

LMDB-backed authorization provider:

```rust
use v_common::storage::async_storage::{AuthorizationProvider, get_individual_from_db, AStorage};
use v_authorization_lmdb_impl::LmdbAzContext;

// Create LMDB-backed authorization (uses sync calls via async mutex)
let az = AuthorizationProvider::from_lmdb(LmdbAzContext::new(1000));

// Async interface
let rights = az.authorize(uri, user_uri, Access::CanRead as u8, false).await?;
let rights = az.authorize_and_trace(uri, user_uri, access, false, &mut trace).await?;
```

### Async Storage Functions

```rust
// Get individual with authorization check
let (indv, result_code) = get_individual_from_db(uri, user_uri, &db, Some(&az)).await?;

// Check if user belongs to a group
let is_member = check_user_in_group(user_id, group_id, Some(&az)).await?;
```

### Migration from Mutex<AzContext>

If migrating from the old `Mutex<AzContext>` API:

| Old API | New API |
|---------|---------|
| `Mutex::new(AzContext::new(1000))` | `AuthorizationProvider::from_lmdb(LmdbAzContext::new(1000))` |
| `az.lock().await.authorize(...)` | `az.authorize(...).await` |
| `az.lock().await.authorize_and_trace(...)` | `az.authorize_and_trace(...).await` |

## Important Notes
1. Remote storage supports only read operations
2. LMDB storage requires proper file system permissions
3. Each storage type may return different results for the same operation
4. Always check operation results for proper error handling
5. LMDB authorization calls are executed directly in async context (no spawn_blocking)

This documentation should help AI understand the storage system's architecture and typical usage patterns when answering questions or providing code examples.