many<T> method
Updates multiple documents in Localstore with a list of objects.
Implementation
@override
Future<void> many<T>(List<T> objects, { String? subcollection }) async {
if (objects.isEmpty) return Future.value();
if (objects.length > 500) {
throw ArgumentError('Batch limit exceeded. Maximum 500 objects allowed.');
}
final serializer = LS.serializers[objects[0].runtimeType];
if (serializer == null) {
throw UnsupportedError('No serializer found for type: ${objects[0].runtimeType}. Consider re-generating Firestorm data classes.');
}
List<Future> futures = [];
for (var object in objects) {
if (object.runtimeType != T) {
throw ArgumentError('All objects must be of type $T');
}
final map = serializer(object);
if (map["id"].isEmpty) {
throw NullIDException(map);
}
DocumentRef ref = LS.instance.collection(object.runtimeType.toString()).doc(map["id"]);
if (subcollection != null) {
ref = LS.instance.collection(object.runtimeType.toString()).doc(subcollection).collection(subcollection).doc(map["id"]);
}
futures.add(ref.set(map));
}
await Future.wait(futures);
}