Files
wehub-resource-sync e4dcfc49aa
Tests / Import Check (Python 3.13) (push) Has been cancelled
Tests / Import Check (Python 3.14) (push) Has been cancelled
Tests / Python Tests (Python 3.11) (push) Has been cancelled
Tests / Python Tests (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.14) (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled
Tests / Lint and Format (push) Has been cancelled
Tests / Web Node Tests (push) Has been cancelled
Tests / Import Check (Python 3.11) (push) Has been cancelled
Tests / Import Check (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.13) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:00:43 +08:00

46 lines
1.1 KiB
Python

"""Snapshot data types.
An ``Entity`` is one unit of L1 content for a non-KB surface — e.g. one
notebook record, one co-writer document, one book, one chat session.
The snapshot is the *current* set of these on disk; the diff log records
how that set has changed across refreshes.
These types are intentionally pure dataclasses with no I/O. Adapters
build ``Entity`` lists; ``diff.diff_snapshots`` consumes two ``state``
dicts to produce ``ChangeEntry`` records.
"""
from __future__ import annotations
from dataclasses import asdict, dataclass, field
from typing import Any, Literal
@dataclass
class Entity:
id: str
label: str
ts: str
content: str
metadata: dict[str, Any] = field(default_factory=dict)
fingerprint: str = ""
def to_dict(self) -> dict[str, Any]:
return asdict(self)
ChangeKind = Literal["added", "modified", "removed"]
@dataclass
class ChangeEntry:
ts: str
kind: ChangeKind
entity_id: str
label: str
prev_fingerprint: str | None = None
new_fingerprint: str | None = None
def to_dict(self) -> dict[str, Any]:
return asdict(self)