Skip to content

Commit cb027a1

Browse files
committed
refactor: rename class to prevent collisions
1 parent 0d49dc4 commit cb027a1

31 files changed

+270
-197
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.7.0
2+
3+
- Rename `Field` class to `VineField`
4+
- Rename `ValidatorContext` class to `VineValidatorContext` to prevent collision with `ValidatorContext` class from another packages
5+
16
## 1.6.2
27

38
- Rename `ErrorReporter` to `VineErrorReporter` to prevent collision with `ErrorReporter` class from anither packages

lib/src/contracts/rule.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:vine/src/contracts/vine.dart';
22

33
abstract interface class VineRule {
4-
void handle(VineValidationContext ctx, FieldContext field);
4+
void handle(VineValidationContext ctx, VineFieldContext field);
55
}

lib/src/contracts/schema.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:vine/src/schema/object/object_schema.dart';
55
abstract interface class VineSchema<T extends VineErrorReporter>
66
implements SchemaIntrospection {
77
/// Validate the field [field] the field to validate
8-
void parse(VineValidationContext ctx, FieldContext field);
8+
void parse(VineValidationContext ctx, VineFieldContext field);
99

1010
/// Clone the schema
1111
VineSchema clone();
@@ -57,7 +57,7 @@ abstract interface class BasicSchema<T extends VineSchema> {
5757

5858
T requiredIfAnyMissing(List<String> values);
5959

60-
T transform(Function(VineValidationContext ctx, FieldContext field) fn);
60+
T transform(Function(VineValidationContext ctx, VineFieldContext field) fn);
6161

6262
T nullable();
6363

@@ -467,7 +467,7 @@ abstract interface class VineGroup implements VineSchema {
467467
/// .otherwise((ctx, field) {
468468
/// field.customKeys.add(field.name);
469469
/// });
470-
VineGroup otherwise(Function(VineValidationContext, FieldContext) fn);
470+
VineGroup otherwise(Function(VineValidationContext, VineFieldContext) fn);
471471
}
472472

473473
abstract interface class VineArray

lib/src/contracts/vine.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ abstract interface class VineErrorReporter {
55

66
bool hasErrorForField(String fieldName);
77

8-
String format(String rule, FieldContext field, String? message,
8+
String format(String rule, VineFieldContext field, String? message,
99
Map<String, dynamic> options);
1010

1111
void report(String rule, List<String> keys, String message);
@@ -15,7 +15,7 @@ abstract interface class VineErrorReporter {
1515
void clear();
1616
}
1717

18-
abstract interface class ValidatorContract {}
18+
abstract interface class VineValidatorContract {}
1919

2020
abstract interface class VineValidationContext<T extends VineErrorReporter> {
2121
T get errorReporter;
@@ -25,7 +25,7 @@ abstract interface class VineValidationContext<T extends VineErrorReporter> {
2525
Map<String, dynamic> getFieldContext(List<String> keys);
2626
}
2727

28-
abstract interface class FieldContext {
28+
abstract interface class VineFieldContext {
2929
List<String> get customKeys;
3030

3131
abstract String name;
@@ -37,6 +37,6 @@ abstract interface class FieldContext {
3737
void mutate(dynamic value);
3838
}
3939

40-
typedef ParseHandler = void Function(VineValidationContext, FieldContext);
40+
typedef ParseHandler = void Function(VineValidationContext, VineFieldContext);
4141

4242
final class MissingValue {}

lib/src/error_reporter.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ class SimpleErrorReporter implements VineErrorReporter {
1616
bool hasError = false;
1717

1818
@override
19-
bool hasErrorForField(String fieldName) => errors.any((element) => element['field'] == fieldName);
19+
bool hasErrorForField(String fieldName) =>
20+
errors.any((element) => element['field'] == fieldName);
2021

2122
@override
22-
String format(String rule, FieldContext field, String? message, Map<String, dynamic> options) {
23-
String content = message ?? _errorMessages[field.name] ?? mappedErrors[rule]!;
23+
String format(String rule, VineFieldContext field, String? message,
24+
Map<String, dynamic> options) {
25+
String content =
26+
message ?? _errorMessages[field.name] ?? mappedErrors[rule]!;
2427

2528
for (final element in options.entries) {
26-
content = content.replaceAll('{${element.key}}', element.value.toString());
29+
content =
30+
content.replaceAll('{${element.key}}', element.value.toString());
2731
}
2832

2933
return content

lib/src/field.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:vine/src/contracts/vine.dart';
22

3-
final class ValidatorContext<T extends VineErrorReporter>
3+
final class VineValidatorContext<T extends VineErrorReporter>
44
implements VineValidationContext<T> {
55
@override
66
final T errorReporter;
@@ -21,10 +21,10 @@ final class ValidatorContext<T extends VineErrorReporter>
2121
return data;
2222
}
2323

24-
ValidatorContext(this.errorReporter, this.data);
24+
VineValidatorContext(this.errorReporter, this.data);
2525
}
2626

27-
final class Field implements FieldContext {
27+
final class VineField implements VineFieldContext {
2828
@override
2929
final List<String> customKeys = [];
3030

@@ -40,7 +40,7 @@ final class Field implements FieldContext {
4040
@override
4141
bool isUnion = false;
4242

43-
Field(this.name, this.value);
43+
VineField(this.name, this.value);
4444

4545
@override
4646
void mutate(dynamic value) {

lib/src/field_pool.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ import 'dart:collection';
22

33
import 'package:vine/vine.dart';
44

5-
class FieldPool {
6-
static final _pool = Queue<Field>();
5+
class VineFieldPool {
6+
static final _pool = Queue<VineField>();
77
static final int _maxSize = 1000;
88

9-
static Field acquire(String name, dynamic value) {
10-
if (_pool.isEmpty) return Field(name, value);
9+
static VineField acquire(String name, dynamic value) {
10+
if (_pool.isEmpty) return VineField(name, value);
1111
return _pool.removeFirst()
1212
..name = name
1313
..value = value
1414
..canBeContinue = true
1515
..customKeys.clear();
1616
}
1717

18-
static void release(Field field) {
18+
static void release(VineField field) {
1919
if (_pool.length < _maxSize) {
2020
_pool.add(field);
2121
}

lib/src/rule_parser.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class RuleParser implements RuleParserContract {
2626
rules.add(rule);
2727
}
2828

29-
FieldContext parse(VineValidationContext ctx, FieldContext field) {
29+
VineFieldContext parse(VineValidationContext ctx, VineFieldContext field) {
3030
if (isNullable) {
3131
addRule(VineNullableRule(), positioned: true);
3232
}

lib/src/rules/any_rule.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import 'package:vine/src/contracts/vine.dart';
33

44
final class VineAnyRule implements VineRule {
55
@override
6-
void handle(VineValidationContext ctx, FieldContext field) {}
6+
void handle(VineValidationContext ctx, VineFieldContext field) {}
77
}

lib/src/rules/array_rule.dart

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ final class VineArrayRule implements VineRule {
1010
const VineArrayRule(this.schema);
1111

1212
@override
13-
void handle(VineValidationContext ctx, FieldContext field) {
13+
void handle(VineValidationContext ctx, VineFieldContext field) {
1414
final copy = field.customKeys;
1515

1616
if (field.value case List values) {
1717
final currentSchema = schema as RuleParser;
1818
final copyRules = currentSchema.rules.toList();
1919

2020
for (int i = 0; i < values.length; i++) {
21-
final currentField = FieldPool.acquire(field.name, values[i]);
21+
final currentField = VineFieldPool.acquire(field.name, values[i]);
2222

2323
currentSchema.rules.clear();
2424
currentSchema.rules.addAll(copyRules);
@@ -31,7 +31,7 @@ final class VineArrayRule implements VineRule {
3131
..addAll(copy);
3232

3333
currentField.mutate([...field.value, currentField.value]);
34-
FieldPool.release(currentField);
34+
VineFieldPool.release(currentField);
3535
}
3636

3737
return;
@@ -48,19 +48,23 @@ final class VineArrayUniqueRule implements VineRule {
4848
const VineArrayUniqueRule(this.message);
4949

5050
@override
51-
void handle(VineValidationContext ctx, FieldContext field) {
51+
void handle(VineValidationContext ctx, VineFieldContext field) {
5252
if (field.value is! List) {
53-
final error = ctx.errorReporter.format('array.unique', field, message, {});
54-
ctx.errorReporter.report('array.unique', [...field.customKeys, field.name], error);
53+
final error =
54+
ctx.errorReporter.format('array.unique', field, message, {});
55+
ctx.errorReporter
56+
.report('array.unique', [...field.customKeys, field.name], error);
5557
return;
5658
}
5759

5860
final values = field.value as List;
5961
final unique = values.toSet().toList();
6062

6163
if (values.length != unique.length) {
62-
final error = ctx.errorReporter.format('array.unique', field, message, {});
63-
ctx.errorReporter.report('array.unique', [...field.customKeys, field.name], error);
64+
final error =
65+
ctx.errorReporter.format('array.unique', field, message, {});
66+
ctx.errorReporter
67+
.report('array.unique', [...field.customKeys, field.name], error);
6468
}
6569
}
6670
}
@@ -72,13 +76,15 @@ final class VineArrayMinLengthRule implements VineRule {
7276
const VineArrayMinLengthRule(this.minValue, this.message);
7377

7478
@override
75-
void handle(VineValidationContext ctx, FieldContext field) {
79+
void handle(VineValidationContext ctx, VineFieldContext field) {
7680
if ((field.value as List).length < minValue) {
77-
final error = ctx.errorReporter.format('array.minLength', field, message, {
81+
final error =
82+
ctx.errorReporter.format('array.minLength', field, message, {
7883
'min': minValue,
7984
});
8085

81-
ctx.errorReporter.report('array.minLength', [...field.customKeys, field.name], error);
86+
ctx.errorReporter
87+
.report('array.minLength', [...field.customKeys, field.name], error);
8288
}
8389
}
8490
}
@@ -90,13 +96,15 @@ final class VineArrayMaxLengthRule implements VineRule {
9096
const VineArrayMaxLengthRule(this.maxValue, this.message);
9197

9298
@override
93-
void handle(VineValidationContext ctx, FieldContext field) {
99+
void handle(VineValidationContext ctx, VineFieldContext field) {
94100
if ((field.value as List).length > maxValue) {
95-
final error = ctx.errorReporter.format('array.maxLength', field, message, {
101+
final error =
102+
ctx.errorReporter.format('array.maxLength', field, message, {
96103
'max': maxValue,
97104
});
98105

99-
ctx.errorReporter.report('array.maxLength', [...field.customKeys, field.name], error);
106+
ctx.errorReporter
107+
.report('array.maxLength', [...field.customKeys, field.name], error);
100108
}
101109
}
102110
}
@@ -108,12 +116,14 @@ final class VineArrayFixedLengthRule implements VineRule {
108116
const VineArrayFixedLengthRule(this.count, this.message);
109117

110118
@override
111-
void handle(VineValidationContext ctx, FieldContext field) {
119+
void handle(VineValidationContext ctx, VineFieldContext field) {
112120
if ((field.value as List).length != count) {
113-
final error = ctx.errorReporter.format('array.fixedLength', field, message, {
121+
final error =
122+
ctx.errorReporter.format('array.fixedLength', field, message, {
114123
'length': count,
115124
});
116-
ctx.errorReporter.report('array.fixedLength', [...field.customKeys, field.name], error);
125+
ctx.errorReporter.report(
126+
'array.fixedLength', [...field.customKeys, field.name], error);
117127
}
118128
}
119129
}

0 commit comments

Comments
 (0)