getSnapshot method

  1. @override
Future<SessionSnapshot?> getSnapshot({
  1. String? snapshotId,
  2. String? sessionId,
  3. Map<String, dynamic>? context,
})
override

Loads a snapshot either by its snapshotId or by sessionId.

Exactly one of snapshotId / sessionId must be provided. A sessionId resolves to the session's latest leaf snapshot (the most recent snapshot that no other snapshot points to as its parent). A branched history (more than one leaf) resolves to the most-recently created leaf by default, or is rejected with StatusCodes.FAILED_PRECONDITION when the store is configured to reject branching.

context carries the ambient request/action context (e.g. the authenticated user) so multi-tenant stores can route reads.

Implementation

@override
Future<SessionSnapshot?> getSnapshot({
  String? snapshotId,
  String? sessionId,
  Map<String, dynamic>? context,
}) async {
  final normalized = normalizeGetSnapshotOptions(
    snapshotId: snapshotId,
    sessionId: sessionId,
  );

  if (normalized.sessionId != null) {
    return _latestSnapshotForSession(normalized.sessionId!, context);
  }
  return _snapshotById(normalized.snapshotId!, context);
}