reconciliation work

This commit is contained in:
Christien Rioux 2024-05-30 23:25:47 -04:00
parent c9525bde77
commit 490051a650
12 changed files with 457 additions and 196 deletions

View file

@ -209,8 +209,7 @@ class DHTLog implements DHTDeleteable<DHTLog, DHTLog> {
OwnedDHTRecordPointer get recordPointer => _spine.recordPointer;
/// Runs a closure allowing read-only access to the log
Future<T?> operate<T>(
Future<T?> Function(DHTLogReadOperations) closure) async {
Future<T> operate<T>(Future<T> Function(DHTLogReadOperations) closure) async {
if (!isOpen) {
throw StateError('log is not open"');
}

View file

@ -108,6 +108,7 @@ class DHTLogCubit<T> extends Cubit<DHTLogBusyState<T>>
elements: elements, tail: _tail, count: _count, follow: _follow)));
}
// Tail is one past the last element to load
Future<AsyncValue<IList<DHTLogElementState<T>>>> loadElements(
int tail, int count,
{bool forceRefresh = false}) async {
@ -184,8 +185,7 @@ class DHTLogCubit<T> extends Cubit<DHTLogBusyState<T>>
await super.close();
}
Future<R?> operate<R>(
Future<R?> Function(DHTLogReadOperations) closure) async {
Future<R> operate<R>(Future<R> Function(DHTLogReadOperations) closure) async {
await _initWait();
return _log.operate(closure);
}

View file

@ -662,4 +662,46 @@ extension TableDBArrayExt on TableDBArray {
T Function(List<int>) fromBuffer, int start, [int? end]) =>
getRange(start, end ?? _length)
.then((out) => out.map(fromBuffer).toList());
/// Convenience function:
/// Like add but for a JSON value
Future<void> addJson<T>(T value) async => add(jsonEncodeBytes(value));
/// Convenience function:
/// Like add but for a Protobuf value
Future<void> addProtobuf<T extends GeneratedMessage>(T value) =>
add(value.writeToBuffer());
/// Convenience function:
/// Like addAll but for a JSON value
Future<void> addAllJson<T>(List<T> values) async =>
addAll(values.map(jsonEncodeBytes).toList());
/// Convenience function:
/// Like addAll but for a Protobuf value
Future<void> addAllProtobuf<T extends GeneratedMessage>(
List<T> values) async =>
addAll(values.map((x) => x.writeToBuffer()).toList());
/// Convenience function:
/// Like insert but for a JSON value
Future<void> insertJson<T>(int pos, T value) async =>
insert(pos, jsonEncodeBytes(value));
/// Convenience function:
/// Like insert but for a Protobuf value
Future<void> insertProtobuf<T extends GeneratedMessage>(
int pos, T value) async =>
insert(pos, value.writeToBuffer());
/// Convenience function:
/// Like insertAll but for a JSON value
Future<void> insertAllJson<T>(int pos, List<T> values) async =>
insertAll(pos, values.map(jsonEncodeBytes).toList());
/// Convenience function:
/// Like insertAll but for a Protobuf value
Future<void> insertAllProtobuf<T extends GeneratedMessage>(
int pos, List<T> values) async =>
insertAll(pos, values.map((x) => x.writeToBuffer()).toList());
}