|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +// Part of PyBLE (https://pyble.dev) — see /LICENSE. |
| 3 | + |
| 4 | +/// Neutral local current-text recovery seam (ADR-0048). |
| 5 | +library; |
| 6 | + |
| 7 | +/// One complete, immutable local checkpoint. Origin is historical context, |
| 8 | +/// never authority to write to a board. |
| 9 | +class DraftSnapshot { |
| 10 | + const DraftSnapshot({ |
| 11 | + required this.name, |
| 12 | + required this.content, |
| 13 | + this.originPath, |
| 14 | + required this.generation, |
| 15 | + required this.checkpointTime, |
| 16 | + }); |
| 17 | + |
| 18 | + final String name; |
| 19 | + final String content; |
| 20 | + final String? originPath; |
| 21 | + final int generation; |
| 22 | + final DateTime checkpointTime; |
| 23 | +} |
| 24 | + |
| 25 | +/// A committed slot, including a high-water generation for an empty tombstone. |
| 26 | +class DraftRead { |
| 27 | + const DraftRead({required this.generation, this.snapshot}); |
| 28 | + final int generation; |
| 29 | + final DraftSnapshot? snapshot; |
| 30 | +} |
| 31 | + |
| 32 | +/// Bounded reasons suitable for localized UI; never includes user source/path. |
| 33 | +enum DraftStorageFailure { |
| 34 | + unavailable, |
| 35 | + corrupt, |
| 36 | + unsupportedVersion, |
| 37 | + invalidMetadata, |
| 38 | + invalidText, |
| 39 | + tooLarge, |
| 40 | + conflict, |
| 41 | +} |
| 42 | + |
| 43 | +class DraftStorageException implements Exception { |
| 44 | + const DraftStorageException(this.reason); |
| 45 | + final DraftStorageFailure reason; |
| 46 | + |
| 47 | + @override |
| 48 | + String toString() => 'DraftStorageException(${reason.name})'; |
| 49 | +} |
| 50 | + |
| 51 | +/// Sole serialized writer for one local slot. A successful Future means that |
| 52 | +/// its matching transaction committed, not that a board was contacted. |
| 53 | +abstract interface class DraftRepository { |
| 54 | + Future<DraftRead> load(); |
| 55 | + Future<void> write(DraftSnapshot snapshot, {required int expectedGeneration}); |
| 56 | + Future<int> clear({required int expectedGeneration}); |
| 57 | + Future<void> close(); |
| 58 | +} |
0 commit comments