"""
Collection-related DTOs for SecretVaults API.
"""
from typing import List, Dict, Optional, Union, Literal
from datetime import datetime
from pydantic import BaseModel, Field, constr, model_validator
from ..common.types import Uuid
[docs]
class CollectionDocumentDto(BaseModel):
"""A summary of a collection, including its ID, type, and name."""
id: Uuid
type: Literal["standard", "owned"]
name: str
[docs]
class ListCollectionsResponse(BaseModel):
"""Response model for listing all collections."""
data: List[CollectionDocumentDto]
[docs]
class CreateCollectionRequest(BaseModel):
"""Request model for creating a new collection."""
id: Uuid = Field(alias="_id")
type: Literal["standard", "owned"]
name: constr(min_length=1)
schema_data: Dict[str, object] = Field(alias="schema")
[docs]
@model_validator(mode="before")
@classmethod
def allow_id_or__id(cls, data):
"""Allow both 'id' and '_id' fields for backward compatibility."""
if "id" in data and "_id" not in data:
data["_id"] = data["id"]
return data
[docs]
class DeleteCollectionRequestParams(BaseModel):
"""Request parameters for deleting a collection by ID."""
id: Uuid
[docs]
class CreateCollectionIndexRequest(BaseModel):
"""Request model for creating an index on a collection."""
collection: Uuid
name: constr(min_length=4)
keys: List[Dict[str, Literal[1, -1]]]
unique: bool
ttl: Optional[float] = 0
[docs]
class CollectionIndexDto(BaseModel):
"""Details of a collection index, including its name and uniqueness."""
v: int
key: Dict[str, Union[str, int, float]]
name: str
unique: bool
[docs]
class DropCollectionIndexParams(BaseModel):
"""Request parameters for dropping a collection index by name."""
id: Uuid
name: constr(min_length=4, max_length=50)