mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-24 07:46:26 +01:00
SickDayPool gains keep: mark/clear write state+actor+keep on one tick, setKept re-stamps only keep+actor, read rules 1-5 in sick_day_keep.dart. The native SickDays cache now holds only days on which the alarm stands down, so a sick day that keeps the alarm rings like a normal day. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PAhbNszs5JKdtnD4uBi3xp
117 lines
4.0 KiB
Dart
117 lines
4.0 KiB
Dart
import 'package:crdt_sync/crdt_sync.dart';
|
|
|
|
/// An in-memory `LogPersistence`.
|
|
class MemPersistence implements LogPersistence {
|
|
/// The persisted text, or null before the first write.
|
|
String? text;
|
|
|
|
@override
|
|
Future<String?> read() async => text;
|
|
|
|
@override
|
|
Future<void> write(String value) async => text = value;
|
|
}
|
|
|
|
/// An in-memory `RemoteStore`: a flat path -> text map.
|
|
class MemRemote implements RemoteStore {
|
|
/// Every file, by full path.
|
|
final Map<String, String> files = {};
|
|
|
|
@override
|
|
Future<List<String>> listDirectory(String path) async {
|
|
final prefix = '$path/';
|
|
return files.keys
|
|
.where((k) => k.startsWith(prefix))
|
|
.map((k) => k.substring(prefix.length).split('/').first)
|
|
.toSet()
|
|
.toList();
|
|
}
|
|
|
|
@override
|
|
Future<String?> getFileText(String path) async => files[path];
|
|
|
|
@override
|
|
Future<void> putFileText(
|
|
String path,
|
|
String text, {
|
|
required String message,
|
|
}) async => files[path] = text;
|
|
|
|
@override
|
|
Future<void> deleteFile(String path, {String? message}) async =>
|
|
files.remove(path);
|
|
|
|
@override
|
|
Future<bool> canAccessRemote() async => true;
|
|
|
|
@override
|
|
void close() {}
|
|
}
|
|
|
|
/// A remote that is offline for every read and write.
|
|
class BrokenRemote implements RemoteStore {
|
|
@override
|
|
Future<List<String>> listDirectory(String path) async =>
|
|
throw RemoteSyncError('offline');
|
|
|
|
@override
|
|
Future<String?> getFileText(String path) async =>
|
|
throw RemoteSyncError('offline');
|
|
|
|
@override
|
|
Future<void> putFileText(
|
|
String path,
|
|
String text, {
|
|
required String message,
|
|
}) async => throw RemoteSyncError('offline');
|
|
|
|
@override
|
|
Future<void> deleteFile(String path, {String? message}) async {}
|
|
|
|
@override
|
|
Future<bool> canAccessRemote() async => false;
|
|
|
|
@override
|
|
void close() {}
|
|
}
|
|
|
|
/// A log exactly as `sickdays` 0.1.0 (Python) writes it: 2026-10-20 sick,
|
|
/// 2026-10-21 marked and then cleared. Generated by `add_sick_day` /
|
|
/// `remove_sick_day` on 2026-10-16, not hand-written.
|
|
const pythonSickLog =
|
|
'{"2026-10-20": {"id": "2026-10-20", "fields": {"state": ["sick", '
|
|
'"2026-10-16T11:13:53.005Z-0000-ad78e209-49cd-4989-9235-da5ec179f183"], '
|
|
'"actor": ["ad78e209-49cd-4989-9235-da5ec179f183", '
|
|
'"2026-10-16T11:13:53.005Z-0000-ad78e209-49cd-4989-9235-da5ec179f183"]}, '
|
|
'"deleted": false, "deleted_hlc": null}, "2026-10-21": {"id": '
|
|
'"2026-10-21", "fields": {"state": ["cleared", '
|
|
'"2026-10-16T11:13:53.007Z-0000-ad78e209-49cd-4989-9235-da5ec179f183"], '
|
|
'"actor": ["ad78e209-49cd-4989-9235-da5ec179f183", '
|
|
'"2026-10-16T11:13:53.007Z-0000-ad78e209-49cd-4989-9235-da5ec179f183"]}, '
|
|
'"deleted": false, "deleted_hlc": null}}';
|
|
|
|
/// The PC's device directory in [pythonSickLog].
|
|
const pythonDeviceId = 'ad78e209-49cd-4989-9235-da5ec179f183';
|
|
|
|
/// A log exactly as `sickdays` 0.2.0 (Python) writes it, generated by
|
|
/// `add_sick_day` / `set_kept_lockers` on 2026-10-16, not hand-written:
|
|
/// 2026-10-20 sick keeping leetcode + workout; 2026-10-22 sick, then a
|
|
/// keep-only edit to keep the alarm (state keeps its older tick);
|
|
/// 2026-10-23 sick keeping nothing.
|
|
const pythonKeepLog =
|
|
'{"2026-10-20": {"id": "2026-10-20", "fields": {"state": ["sick", '
|
|
'"2026-10-16T13:16:33.057Z-0000-$_py"], "actor": ["$_py", '
|
|
'"2026-10-16T13:16:33.057Z-0000-$_py"], "keep": [["leetcode", '
|
|
'"workout"], "2026-10-16T13:16:33.057Z-0000-$_py"]}, "deleted": false, '
|
|
'"deleted_hlc": null}, "2026-10-22": {"id": "2026-10-22", "fields": '
|
|
'{"state": ["sick", "2026-10-16T13:16:33.058Z-0000-$_py"], "actor": '
|
|
'["$_py", "2026-10-16T13:16:33.058Z-0001-$_py"], "keep": [["alarm"], '
|
|
'"2026-10-16T13:16:33.058Z-0001-$_py"]}, "deleted": false, '
|
|
'"deleted_hlc": null}, "2026-10-23": {"id": "2026-10-23", "fields": '
|
|
'{"state": ["sick", "2026-10-16T13:16:33.059Z-0000-$_py"], "actor": '
|
|
'["$_py", "2026-10-16T13:16:33.059Z-0000-$_py"], "keep": [[], '
|
|
'"2026-10-16T13:16:33.059Z-0000-$_py"]}, "deleted": false, '
|
|
'"deleted_hlc": null}}';
|
|
|
|
const _py = '578c399d-4b1d-4558-ab86-b8a9c5aa123a';
|