2022-08-29 18:44:45 +02:00
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
|
|
|
|
|
|
|
part 'patch.g.dart';
|
|
|
|
|
|
|
|
@JsonSerializable()
|
2022-08-06 15:04:18 +02:00
|
|
|
class Patch {
|
|
|
|
Patch({
|
|
|
|
required this.name,
|
|
|
|
required this.description,
|
2022-08-29 18:44:45 +02:00
|
|
|
required this.excluded,
|
|
|
|
required this.compatiblePackages,
|
2023-10-12 02:00:39 +02:00
|
|
|
required this.options,
|
2022-08-06 15:04:18 +02:00
|
|
|
});
|
2022-08-29 18:44:45 +02:00
|
|
|
|
2023-10-13 00:12:27 +02:00
|
|
|
factory Patch.fromJson(Map<String, dynamic> json) {
|
2023-10-26 22:56:08 +02:00
|
|
|
_migrateV16ToV17(json);
|
|
|
|
|
|
|
|
return _$PatchFromJson(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _migrateV16ToV17(Map<String, dynamic> json) {
|
2023-10-13 00:12:27 +02:00
|
|
|
if (json['options'] == null) {
|
|
|
|
json['options'] = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-30 13:35:06 +01:00
|
|
|
final String name;
|
2023-09-26 05:14:27 +02:00
|
|
|
final String? description;
|
2023-01-30 13:35:06 +01:00
|
|
|
final bool excluded;
|
|
|
|
final List<Package> compatiblePackages;
|
2023-10-12 02:00:39 +02:00
|
|
|
final List<Option> options;
|
2022-08-29 18:44:45 +02:00
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => _$PatchToJson(this);
|
|
|
|
|
|
|
|
String getSimpleName() {
|
2023-09-26 05:14:27 +02:00
|
|
|
return name;
|
2022-08-29 18:44:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@JsonSerializable()
|
|
|
|
class Package {
|
|
|
|
Package({
|
|
|
|
required this.name,
|
|
|
|
required this.versions,
|
|
|
|
});
|
|
|
|
|
|
|
|
factory Package.fromJson(Map<String, dynamic> json) =>
|
|
|
|
_$PackageFromJson(json);
|
2023-10-12 02:00:39 +02:00
|
|
|
|
2023-01-30 13:35:06 +01:00
|
|
|
final String name;
|
|
|
|
final List<String> versions;
|
2022-08-29 18:44:45 +02:00
|
|
|
|
|
|
|
Map toJson() => _$PackageToJson(this);
|
2022-08-06 15:04:18 +02:00
|
|
|
}
|
2023-10-12 02:00:39 +02:00
|
|
|
|
|
|
|
@JsonSerializable()
|
|
|
|
class Option {
|
|
|
|
Option({
|
|
|
|
required this.key,
|
|
|
|
required this.title,
|
|
|
|
required this.description,
|
|
|
|
required this.value,
|
2023-10-26 22:56:08 +02:00
|
|
|
required this.values,
|
2023-10-12 02:00:39 +02:00
|
|
|
required this.required,
|
2023-10-26 22:56:08 +02:00
|
|
|
required this.valueType,
|
2023-10-12 02:00:39 +02:00
|
|
|
});
|
|
|
|
|
2023-10-26 22:56:08 +02:00
|
|
|
factory Option.fromJson(Map<String, dynamic> json) {
|
|
|
|
_migrateV17ToV19(json);
|
|
|
|
|
|
|
|
return _$OptionFromJson(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _migrateV17ToV19(Map<String, dynamic> json) {
|
|
|
|
if (json['valueType'] == null) {
|
2023-11-04 22:41:18 +01:00
|
|
|
final type = json['optionClassType'];
|
|
|
|
if (type is String) {
|
|
|
|
json['valueType'] = type
|
|
|
|
.replaceAll('PatchOption', '')
|
|
|
|
.replaceAll('List', 'Array');
|
|
|
|
|
|
|
|
json['optionClassType'] = null;
|
|
|
|
}
|
2023-10-26 22:56:08 +02:00
|
|
|
}
|
|
|
|
}
|
2023-10-12 02:00:39 +02:00
|
|
|
|
|
|
|
final String key;
|
|
|
|
final String title;
|
|
|
|
final String description;
|
2023-10-26 22:56:08 +02:00
|
|
|
final dynamic value;
|
|
|
|
final Map<String, dynamic>? values;
|
2023-10-12 02:00:39 +02:00
|
|
|
final bool required;
|
2023-10-26 22:56:08 +02:00
|
|
|
final String valueType;
|
2023-10-12 02:00:39 +02:00
|
|
|
|
|
|
|
Map toJson() => _$OptionToJson(this);
|
|
|
|
}
|