Metadata-Version: 2.4
Name: spltz-viur-revision
Version: 0.1.0
Summary: Automatic revision tracking and rollback for ViUR skeletons.
Author: Andreas H. Kelch
License: MIT License
        
        Copyright © 2026 Andreas H. Kelch
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/sprengplatz/viur-revision
Project-URL: Documentation, https://sprengplatz.github.io/viur-revision/
Project-URL: Repository, https://github.com/sprengplatz/viur-revision.git
Project-URL: Bug Tracker, https://github.com/sprengplatz/viur-revision/issues
Project-URL: Changelog, https://github.com/sprengplatz/viur-revision/blob/main/CHANGELOG.md
Keywords: viur,revision,audit,history,rollback
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: viur-core<4,>=3.7
Provides-Extra: test
Requires-Dist: pytest~=8.0; extra == "test"
Requires-Dist: pytest-cov~=5.0; extra == "test"
Requires-Dist: coverage[toml]~=7.0; extra == "test"
Requires-Dist: spltz-viur-light-mock>=0.2; extra == "test"
Provides-Extra: docs
Requires-Dist: mkdocs-material~=9.5; extra == "docs"
Requires-Dist: mkdocstrings[python]~=0.26; extra == "docs"
Requires-Dist: mkdocs-static-i18n~=1.3; extra == "docs"
Provides-Extra: dev
Requires-Dist: spltz-viur-revision[docs,test]; extra == "dev"
Requires-Dist: build~=1.2; extra == "dev"
Dynamic: license-file

# viur-revision

Automatic revision tracking and rollback for ViUR skeletons.

[![Tests](https://github.com/sprengplatz/viur-revision/actions/workflows/test.yml/badge.svg)](https://github.com/sprengplatz/viur-revision/actions/workflows/test.yml)
[![Docs](https://github.com/sprengplatz/viur-revision/actions/workflows/docs.yml/badge.svg)](https://sprengplatz.github.io/viur-revision/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

## What it does

`viur-revision` snapshots the *pre-write* state of any tracked skeleton into a
companion datastore kind (`<kind>_revision`) on every write. Each revision
entity carries:

- a verbatim copy of all original entity properties
- `origin_key` — the original entity's key
- `revision_index` — monotonically increasing counter per origin
- `revision_date` — UTC timestamp of the snapshot
- `revision_change_list` — bone names that changed in this write

The package adds endpoints to list, view, restore, and delete revisions, plus
a tiered retention task that thins out the history over time.

## Requirements

- Python ≥ 3.12
- viur-core ≥ 3.7, < 4

## Install

```bash
pip install spltz-viur-revision
```

## Usage

### 1. Make a skeleton track revisions

```python
from viur.revision import RevisionAbstractSkel

class ExampleSkel(RevisionAbstractSkel, Skeleton):
    # Track every write (default):
    pass
```

Or only react to changes on specific bones:

```python
class ExampleSkel(RevisionAbstractSkel, Skeleton):
    revision_fields = ["title", "body"]
```

### 2. Expose revision endpoints on the module

```python
from viur.revision import RevisionModule

class Example(RevisionModule, List):
    ...
```

This adds:

- `GET  /<module>/list_revision?key=<entity-key>`
- `GET  /<module>/view_revision?key=<entity-key>&version=<n|latest>`
- `POST /<module>/apply_revision` (skey-protected)
- `POST /<module>/delete_revision` (skey-protected)
- `GET  /<module>/cleanup_revisions_now` (manual retention run)

All endpoints require either the `root` right or `<moduleName>-manage`.

### 3. Retention

A daily `PeriodicTask` thins history per `origin_key`:

| Age          | Retention            |
| ------------ | -------------------- |
| < 24h        | keep all             |
| 1d–7d        | 1 per hour (latest)  |
| 7d–30d       | 1 per day (latest)   |
| > 30d        | 1 per week (latest)  |

## Documentation

Full reference at [sprengplatz.github.io/viur-revision](https://sprengplatz.github.io/viur-revision/).

## Development

```bash
git clone https://github.com/sprengplatz/viur-revision
cd viur-revision
pip install -e ".[dev]"
pytest                  # 100% coverage required
mkdocs serve            # docs at http://localhost:8000
```

## License

MIT — see [LICENSE](LICENSE).
