readAll method

Future<List<T>> readAll({
  1. String? userId,
  2. List<String> withRelated = const [],
})

Reads all entities from the primary local adapter. Reads all entities from the primary local adapter.

The withRelated parameter allows eager loading of related entities.

Implementation

Future<List<T>> readAll({String? userId, List<String> withRelated = const []}) async {
  _ensureInitialized();
  final entities = await localAdapter.readAll(userId: userId);

  if (withRelated.isNotEmpty && entities.isNotEmpty) {
    await _fetchAndStitchRelations(entities, withRelated, DataSource.local, userId);
  }

  final transformedEntities = <T>[];
  for (final entity in entities) {
    try {
      final transformed = await _applyPostFetchTransforms(entity);
      transformedEntities.add(transformed);
    } catch (e, stack) {
      _logger.error('Failed to apply post-fetch transforms to entity ${entity.id}: $e', stack);
      // Continue with other entities instead of failing the entire operation
      transformedEntities.add(entity); // Use original entity if transform fails
    }
  }
  return transformedEntities;
}