Skip to content

Commit ce5e8a6

Browse files
committed
[red] specify file-backed current-draft recovery invariants
Signed-off-by: Viwat Vchirawongkwin <viwat.v@chula.ac.th>
1 parent 4c4ee3a commit ce5e8a6

5 files changed

Lines changed: 628 additions & 3 deletions

File tree

‎app/lib/data/draft_repository.dart‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: MIT
2+
// Part of PyBLE (https://pyble.dev) — see /LICENSE.
3+
4+
import 'dart:io';
5+
import 'draft_repository.dart';
6+
7+
/// File-backed implementation of the bounded recovery seam.
8+
class DriftDraftRepository implements DraftRepository {
9+
static Future<DriftDraftRepository> open(File file) async =>
10+
DriftDraftRepository();
11+
12+
@override
13+
Future<DraftRead> load() async => throw UnimplementedError();
14+
@override
15+
Future<void> write(DraftSnapshot snapshot, {required int expectedGeneration}) async => throw UnimplementedError();
16+
@override
17+
Future<int> clear({required int expectedGeneration}) async => throw UnimplementedError();
18+
@override
19+
Future<void> close() async {}
20+
}

0 commit comments

Comments
 (0)