queryPaginatedTyped<T> method
Same shape as queryPaginated but maps each record through
fromRecord before yielding. The stream emits one batch (a
List<T>) per page.
Mapping failures are wrapped in a SimpleQueryError with
code: invalidQuery and details.recordIndex identifying the
offending row, just like queryTyped.
Implementation
Stream<List<T>> queryPaginatedTyped<T>(
QueryRequest request,
T Function(Map<String, Object?> record) fromRecord,
) async* {
await for (final page in queryPaginated(request)) {
final mapped = <T>[];
for (var index = 0; index < page.records.length; index += 1) {
final record = page.records[index];
try {
mapped.add(fromRecord(record));
} on SimpleQueryError {
rethrow;
} catch (error, stackTrace) {
Error.throwWithStackTrace(
SimpleQueryError(
code: SimpleQueryErrorCode.invalidQuery,
message:
'simple_query: queryPaginatedTyped mapping failed for record at index $index',
domain: request.domain,
operation: QueryOperation.read,
details: <String, Object?>{
'domain': request.domain.name,
'recordIndex': index,
'cause': error.toString(),
},
),
stackTrace,
);
}
}
yield List<T>.unmodifiable(mapped);
}
}