jsonToCollection method

Future<void> jsonToCollection({
  1. required String path,
  2. required JsonObject json,
  3. required OnParsedCallback onParsed,
  4. String? changeRootName,
})

Implementation

Future<void> jsonToCollection({
  required String path,
  required JsonObject json,
  required OnParsedCallback onParsed,
  String? changeRootName,
}) async {
  final collectionName = changeRootName ?? (json[metaName] as String?) ?? '';
  if (collectionName.isEmpty) {
    throw FormatException('Wrong `$metaName` value=`$collectionName` '
        'in json=`$json`');
  }

  final collectionPath = di<PathUtils>().join(
    path,
    collectionName,
  );

  final innerDocuments = _jsonCollectionToDocuments(json);

  for (final innerDocument in innerDocuments) {
    await jsonToDocument(
      path: collectionPath,
      json: innerDocument,
      onParsed: onParsed,
    );
  }
}