generator: Migration option parsing to null-safety

This commit is contained in:
Simon Binder 2021-03-09 21:33:54 +01:00
parent 65472a9e7d
commit 8c7679568c
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
4 changed files with 47 additions and 51 deletions

View File

@ -1,4 +1,3 @@
//@dart=2.9
import 'package:json_annotation/json_annotation.dart';
part 'options.g.dart';

View File

@ -1,4 +1,3 @@
//@dart=2.9
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'options.dart';
@ -25,60 +24,60 @@ MoorOptions _$MoorOptionsFromJson(Map<String, dynamic> json) {
'apply_converters_on_variables',
'generate_values_in_copy_with',
'named_parameters',
'new_sql_code_generation',
'new_sql_code_generation'
]);
final val = MoorOptions(
generateFromJsonStringConstructor: $checkedConvert(
json, 'write_from_json_string_constructor', (v) => v as bool) ??
json, 'write_from_json_string_constructor', (v) => v as bool?) ??
false,
overrideHashAndEqualsInResultSets: $checkedConvert(json,
'override_hash_and_equals_in_result_sets', (v) => v as bool) ??
'override_hash_and_equals_in_result_sets', (v) => v as bool?) ??
false,
compactQueryMethods:
$checkedConvert(json, 'compact_query_methods', (v) => v as bool) ??
$checkedConvert(json, 'compact_query_methods', (v) => v as bool?) ??
true,
skipVerificationCode:
$checkedConvert(json, 'skip_verification_code', (v) => v as bool) ??
$checkedConvert(json, 'skip_verification_code', (v) => v as bool?) ??
false,
useDataClassNameForCompanions: $checkedConvert(
json, 'use_data_class_name_for_companions', (v) => v as bool) ??
json, 'use_data_class_name_for_companions', (v) => v as bool?) ??
false,
useColumnNameAsJsonKeyWhenDefinedInMoorFile: $checkedConvert(
json,
'use_column_name_as_json_key_when_defined_in_moor_file',
(v) => v as bool) ??
(v) => v as bool?) ??
true,
generateConnectConstructor: $checkedConvert(
json, 'generate_connect_constructor', (v) => v as bool) ??
json, 'generate_connect_constructor', (v) => v as bool?) ??
false,
eagerlyLoadDartAst:
$checkedConvert(json, 'eagerly_load_dart_ast', (v) => v as bool) ??
$checkedConvert(json, 'eagerly_load_dart_ast', (v) => v as bool?) ??
false,
dataClassToCompanions:
$checkedConvert(json, 'data_class_to_companions', (v) => v as bool) ??
true,
dataClassToCompanions: $checkedConvert(
json, 'data_class_to_companions', (v) => v as bool?) ??
true,
generateMutableClasses:
$checkedConvert(json, 'mutable_classes', (v) => v as bool) ?? false,
$checkedConvert(json, 'mutable_classes', (v) => v as bool?) ?? false,
rawResultSetData:
$checkedConvert(json, 'raw_result_set_data', (v) => v as bool) ??
$checkedConvert(json, 'raw_result_set_data', (v) => v as bool?) ??
false,
applyConvertersOnVariables: $checkedConvert(
json, 'apply_converters_on_variables', (v) => v as bool) ??
json, 'apply_converters_on_variables', (v) => v as bool?) ??
false,
generateValuesInCopyWith: $checkedConvert(
json, 'generate_values_in_copy_with', (v) => v as bool) ??
json, 'generate_values_in_copy_with', (v) => v as bool?) ??
false,
generateNamedParameters:
$checkedConvert(json, 'named_parameters', (v) => v as bool) ?? false,
$checkedConvert(json, 'named_parameters', (v) => v as bool?) ?? false,
newSqlCodeGeneration:
$checkedConvert(json, 'new_sql_code_generation', (v) => v as bool) ??
$checkedConvert(json, 'new_sql_code_generation', (v) => v as bool?) ??
false,
modules: $checkedConvert(
json,
'sqlite_modules',
(v) => (v as List)
?.map((e) => _$enumDecodeNullable(_$SqlModuleEnumMap, e))
?.toList()) ??
(v) => (v as List<dynamic>?)
?.map((e) => _$enumDecode(_$SqlModuleEnumMap, e))
.toList()) ??
[],
);
return val;
@ -95,44 +94,39 @@ MoorOptions _$MoorOptionsFromJson(Map<String, dynamic> json) {
'eagerlyLoadDartAst': 'eagerly_load_dart_ast',
'dataClassToCompanions': 'data_class_to_companions',
'generateMutableClasses': 'mutable_classes',
'modules': 'sqlite_modules',
'rawResultSetData': 'raw_result_set_data',
'applyConvertersOnVariables': 'apply_converters_on_variables',
'generateValuesInCopyWith': 'generate_values_in_copy_with',
'generateNamedParameters': 'named_parameters',
'newSqlCodeGeneration': 'new_sql_code_generation',
'modules': 'sqlite_modules'
});
}
T _$enumDecode<T>(
Map<T, dynamic> enumValues,
dynamic source, {
T unknownValue,
K _$enumDecode<K, V>(
Map<K, V> enumValues,
Object? source, {
K? unknownValue,
}) {
if (source == null) {
throw ArgumentError('A value must be provided. Supported values: '
'${enumValues.values.join(', ')}');
throw ArgumentError(
'A value must be provided. Supported values: '
'${enumValues.values.join(', ')}',
);
}
final value = enumValues.entries
.singleWhere((e) => e.value == source, orElse: () => null)
?.key;
if (value == null && unknownValue == null) {
throw ArgumentError('`$source` is not one of the supported values: '
'${enumValues.values.join(', ')}');
}
return value ?? unknownValue;
}
T _$enumDecodeNullable<T>(
Map<T, dynamic> enumValues,
dynamic source, {
T unknownValue,
}) {
if (source == null) {
return null;
}
return _$enumDecode<T>(enumValues, source, unknownValue: unknownValue);
return enumValues.entries.singleWhere(
(e) => e.value == source,
orElse: () {
if (unknownValue == null) {
throw ArgumentError(
'`$source` is not one of the supported values: '
'${enumValues.values.join(', ')}',
);
}
return MapEntry(unknownValue, enumValues.values.first);
},
).key;
}
const _$SqlModuleEnumMap = {

View File

@ -0,0 +1,3 @@
# Build config without moor-specific builders. When running a build in this directory, this file replaces build.yaml,
# which is what we want! Our builders depend on generated code, so they break the generated build script at the start of
# a build.

View File

@ -6,7 +6,7 @@ homepage: https://moor.simonbinder.eu/
issue_tracker: https://github.com/simolus3/moor/issues
environment:
sdk: '>=2.6.0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'
dependencies:
charcode: ^1.2.0