conduit/lib/core/utils/json_normalization.dart
cogwheel d8b161fa5a refactor(api): streamline conversation fetching and parsing logic
- Updated conversation fetching methods to utilize new summary parsing functions, improving clarity and performance.
- Refactored the handling of pinned and archived conversations to enhance data retrieval efficiency.
- Introduced normalization utilities for JSON data handling across various services, ensuring consistent data structures.
- Simplified error handling and data coercion processes in conversation parsing, enhancing robustness.
- Updated related tests to reflect changes in data structures and ensure comprehensive coverage.
2026-05-22 00:25:32 +05:30

23 lines
676 B
Dart

/// Utilities for deep-cloning JSON-like structures without a JSON round trip.
library;
Object? normalizeJsonLikeValue(Object? value) {
if (value == null || value is String || value is num || value is bool) {
return value;
}
if (value is Map) {
return normalizeJsonLikeMap(value);
}
if (value is Iterable) {
return value.map(normalizeJsonLikeValue).toList(growable: false);
}
return value;
}
Map<String, dynamic> normalizeJsonLikeMap(Map<dynamic, dynamic> value) {
final normalized = <String, dynamic>{};
value.forEach((key, entryValue) {
normalized[key?.toString() ?? ''] = normalizeJsonLikeValue(entryValue);
});
return normalized;
}