1
+ // Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2
+ // for details. All rights reserved. Use of this source code is governed by a
3
+ // BSD-style license that can be found in the LICENSE file.
4
+
1
5
import 'package:logging/logging.dart' ;
2
6
import 'package:yaml/yaml.dart' ;
3
7
@@ -28,7 +32,7 @@ abstract class ConfigSpec<TE extends Object?, RE extends Object?> {
28
32
String ? schemaDescription;
29
33
30
34
/// Custom validation hook, called post validation if successful.
31
- bool Function (ConfigValue node)? customValidation;
35
+ bool Function (ConfigValue < Object ?> node)? customValidation;
32
36
33
37
/// Used to transform the payload to another type before passing to parent
34
38
/// nodes and [result] .
@@ -44,9 +48,9 @@ abstract class ConfigSpec<TE extends Object?, RE extends Object?> {
44
48
required this .result,
45
49
});
46
50
47
- bool _validateNode (ConfigValue o, {bool log = true });
51
+ bool _validateNode (ConfigValue < Object ?> o, {bool log = true });
48
52
49
- ConfigValue <RE > _extractNode (ConfigValue o);
53
+ ConfigValue <RE > _extractNode (ConfigValue < Object ?> o);
50
54
51
55
/// ConfigSpec objects should call [_getJsonRefOrSchemaNode] instead to get
52
56
/// the child json schema.
@@ -82,7 +86,7 @@ abstract class ConfigSpec<TE extends Object?, RE extends Object?> {
82
86
/// all underlying ConfigSpecs if valid.
83
87
/// Should ideally only be called if [validate] returns True. Throws
84
88
/// [ConfigSpecExtractionError] if any validation fails.
85
- ConfigValue extract (dynamic value) {
89
+ ConfigValue < Object ?> extract (dynamic value) {
86
90
return _extractNode (ConfigValue (path: [], value: value));
87
91
}
88
92
}
@@ -159,7 +163,7 @@ class ConfigValue<TE> {
159
163
}
160
164
161
165
class ConfigSpecExtractionError extends Error {
162
- final ConfigValue ? item;
166
+ final ConfigValue < Object ?> ? item;
163
167
final String message;
164
168
ConfigSpecExtractionError (this .item, [this .message = 'Invalid ConfigSpec' ]);
165
169
@@ -216,8 +220,8 @@ class HeterogeneousMapConfigSpec<CE extends Object?, RE extends Object?>
216
220
allKeys = {for (final kv in entries) kv.key};
217
221
218
222
@override
219
- bool _validateNode (ConfigValue o, {bool log = true }) {
220
- if (! o.checkType <Map >(log: log)) {
223
+ bool _validateNode (ConfigValue < Object ?> o, {bool log = true }) {
224
+ if (! o.checkType <Map < dynamic , dynamic > >(log: log)) {
221
225
return false ;
222
226
}
223
227
@@ -266,7 +270,7 @@ class HeterogeneousMapConfigSpec<CE extends Object?, RE extends Object?>
266
270
return result;
267
271
}
268
272
269
- dynamic _getAllDefaults (ConfigValue o) {
273
+ dynamic _getAllDefaults (ConfigValue < Object ?> o) {
270
274
final result = < dynamic , CE > {};
271
275
for (final entry in entries) {
272
276
final path = [...o.path, entry.key];
@@ -298,8 +302,8 @@ class HeterogeneousMapConfigSpec<CE extends Object?, RE extends Object?>
298
302
}
299
303
300
304
@override
301
- ConfigValue <RE > _extractNode (ConfigValue o) {
302
- if (! o.checkType <Map >(log: false )) {
305
+ ConfigValue <RE > _extractNode (ConfigValue < Object ?> o) {
306
+ if (! o.checkType <Map < dynamic , dynamic > >(log: false )) {
303
307
throw ConfigSpecExtractionError (o);
304
308
}
305
309
@@ -405,8 +409,8 @@ class MapConfigSpec<CE extends Object?, RE extends Object?>
405
409
});
406
410
407
411
@override
408
- bool _validateNode (ConfigValue o, {bool log = true }) {
409
- if (! o.checkType <Map >(log: log)) {
412
+ bool _validateNode (ConfigValue < Object ?> o, {bool log = true }) {
413
+ if (! o.checkType <Map < dynamic , dynamic > >(log: log)) {
410
414
return false ;
411
415
}
412
416
@@ -457,8 +461,8 @@ class MapConfigSpec<CE extends Object?, RE extends Object?>
457
461
}
458
462
459
463
@override
460
- ConfigValue <RE > _extractNode (ConfigValue o) {
461
- if (! o.checkType <Map >(log: false )) {
464
+ ConfigValue <RE > _extractNode (ConfigValue < Object ?> o) {
465
+ if (! o.checkType <Map < dynamic , dynamic > >(log: false )) {
462
466
throw ConfigSpecExtractionError (o);
463
467
}
464
468
@@ -522,7 +526,7 @@ class ListConfigSpec<CE extends Object?, RE extends Object?>
522
526
});
523
527
524
528
@override
525
- bool _validateNode (ConfigValue o, {bool log = true }) {
529
+ bool _validateNode (ConfigValue < Object ?> o, {bool log = true }) {
526
530
if (! o.checkType <YamlList >(log: log)) {
527
531
return false ;
528
532
}
@@ -544,7 +548,7 @@ class ListConfigSpec<CE extends Object?, RE extends Object?>
544
548
}
545
549
546
550
@override
547
- ConfigValue <RE > _extractNode (ConfigValue o) {
551
+ ConfigValue <RE > _extractNode (ConfigValue < Object ?> o) {
548
552
if (! o.checkType <YamlList >(log: false )) {
549
553
throw ConfigSpecExtractionError (o);
550
554
}
@@ -591,7 +595,7 @@ class StringConfigSpec<RE extends Object?> extends ConfigSpec<String, RE> {
591
595
}) : _regexp = pattern == null ? null : RegExp (pattern, dotAll: true );
592
596
593
597
@override
594
- bool _validateNode (ConfigValue o, {bool log = true }) {
598
+ bool _validateNode (ConfigValue < Object ?> o, {bool log = true }) {
595
599
if (! o.checkType <String >(log: log)) {
596
600
return false ;
597
601
}
@@ -610,7 +614,7 @@ class StringConfigSpec<RE extends Object?> extends ConfigSpec<String, RE> {
610
614
}
611
615
612
616
@override
613
- ConfigValue <RE > _extractNode (ConfigValue o) {
617
+ ConfigValue <RE > _extractNode (ConfigValue < Object ?> o) {
614
618
if (! o.checkType <String >(log: false )) {
615
619
throw ConfigSpecExtractionError (o);
616
620
}
@@ -642,7 +646,7 @@ class IntConfigSpec<RE extends Object?> extends ConfigSpec<int, RE> {
642
646
});
643
647
644
648
@override
645
- bool _validateNode (ConfigValue o, {bool log = true }) {
649
+ bool _validateNode (ConfigValue < Object ?> o, {bool log = true }) {
646
650
if (! o.checkType <int >(log: log)) {
647
651
return false ;
648
652
}
@@ -653,7 +657,7 @@ class IntConfigSpec<RE extends Object?> extends ConfigSpec<int, RE> {
653
657
}
654
658
655
659
@override
656
- ConfigValue <RE > _extractNode (ConfigValue o) {
660
+ ConfigValue <RE > _extractNode (ConfigValue < Object ?> o) {
657
661
if (! o.checkType <int >(log: false )) {
658
662
throw ConfigSpecExtractionError (o);
659
663
}
@@ -688,7 +692,7 @@ class EnumConfigSpec<CE extends Object?, RE extends Object?>
688
692
});
689
693
690
694
@override
691
- bool _validateNode (ConfigValue o, {bool log = true }) {
695
+ bool _validateNode (ConfigValue < Object ?> o, {bool log = true }) {
692
696
if (! allowedValues.contains (o.value)) {
693
697
if (log) {
694
698
_logger.severe (
@@ -704,7 +708,7 @@ class EnumConfigSpec<CE extends Object?, RE extends Object?>
704
708
}
705
709
706
710
@override
707
- ConfigValue <RE > _extractNode (ConfigValue o) {
711
+ ConfigValue <RE > _extractNode (ConfigValue < Object ?> o) {
708
712
if (! allowedValues.contains (o.value)) {
709
713
throw ConfigSpecExtractionError (o);
710
714
}
@@ -735,7 +739,7 @@ class BoolConfigSpec<RE> extends ConfigSpec<bool, RE> {
735
739
});
736
740
737
741
@override
738
- bool _validateNode (ConfigValue o, {bool log = true }) {
742
+ bool _validateNode (ConfigValue < Object ?> o, {bool log = true }) {
739
743
if (! o.checkType <bool >(log: log)) {
740
744
return false ;
741
745
}
@@ -746,7 +750,7 @@ class BoolConfigSpec<RE> extends ConfigSpec<bool, RE> {
746
750
}
747
751
748
752
@override
749
- ConfigValue <RE > _extractNode (ConfigValue o) {
753
+ ConfigValue <RE > _extractNode (ConfigValue < Object ?> o) {
750
754
if (! o.checkType <bool >(log: false )) {
751
755
throw ConfigSpecExtractionError (o);
752
756
}
@@ -784,7 +788,7 @@ class OneOfConfigSpec<TE extends Object?, RE extends Object?>
784
788
});
785
789
786
790
@override
787
- bool _validateNode (ConfigValue o, {bool log = true }) {
791
+ bool _validateNode (ConfigValue < Object ?> o, {bool log = true }) {
788
792
// Running first time with no logs.
789
793
for (final spec in childConfigSpecs) {
790
794
if (spec._validateNode (o, log: false )) {
@@ -806,7 +810,7 @@ class OneOfConfigSpec<TE extends Object?, RE extends Object?>
806
810
}
807
811
808
812
@override
809
- ConfigValue <RE > _extractNode (ConfigValue o) {
813
+ ConfigValue <RE > _extractNode (ConfigValue < Object ?> o) {
810
814
for (final spec in childConfigSpecs) {
811
815
if (spec._validateNode (o, log: false )) {
812
816
return o
0 commit comments