30 lines
763 B
Python
30 lines
763 B
Python
from typing import Any, Literal
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
OpKind = Literal["item.create", "item.update", "item.delete", "items.clear_bought"]
|
|
|
|
|
|
class OpIn(BaseModel):
|
|
# Vom Client vergeben, bevor gesendet wird. Grundlage der Idempotenz:
|
|
# dieselbe op_id wird nie zweimal ausgefuehrt.
|
|
op_id: str = Field(min_length=8, max_length=64)
|
|
kind: OpKind
|
|
payload: dict[str, Any] = Field(default_factory=dict)
|
|
|
|
|
|
class OpBatchIn(BaseModel):
|
|
ops: list[OpIn] = Field(default_factory=list, max_length=200)
|
|
|
|
|
|
class OpResult(BaseModel):
|
|
op_id: str
|
|
status: Literal["applied", "duplicate", "rejected"]
|
|
result_id: str | None = None
|
|
error: str | None = None
|
|
|
|
|
|
class OpBatchOut(BaseModel):
|
|
rev: int
|
|
results: list[OpResult]
|