tejainece on master
Merge pull request #25 from Jag… Jaguar 0.5.x primary changes Big step towards 0.5.0 and 1 more (compare)
Kleak on master
Version bump Merge pull request #24 from Jag… Added glob route matching witho… and 2 more (compare)
// order.validator.dart
const nameValidator = Validate.string
.isNotNull()
.isNotEmpty(trim: true)
.startsWithAlpha()
.hasLengthLessThan(10);
@GenValidator(
fields: {
'productName': nameValidator,
,
}
)
class OrderValidator extends Validator<Order>
with _$OrderValidator {}
// order.validator.jval.dart
abstract class _$OrderValidator implements Validator<Order> {
final _validators = {
'productName': nameValidator,
};
Validator<ProductAttribute> __productAttributeValidator;
Validator<ProductAttribute> get _productAttributeValidator =>
__productAttributeValidator ??= ProductAttributeValidator();
@override
List<dynamic> validate(Order model) {
if (model == null) return null;
ObjectErrors errors = new ObjectErrors();
errors.add(validateField(
'attributes',
codeIterable(
model.attributes,
(val) =>
_productAttributeValidator.validate(val as ProductAttribute))));
errors.add(validateField<String>('productName', model.productName));
errors.add(validateField<int>('quantity', model.quantity));
errors.add(validateField<double>('unitCost', model.unitCost));
errors.add(validateField<double>('subtotal', model.subtotal));
return errors;
}
@override
List<dynamic> validateField<T>(String fieldName, T value) {
const validator = validators[fieldName];
if (validator != null) {
return validator.validate(value);
}
}
}
// Usage:
final orderValidator = OrderValidator();
orderValidator.validate(Order order);
orderValidator.validateField('productName', value);
this is the log of the command running
C:\code\MapManFlutter>flutter pub run build_runner build
[INFO] Generating build script...
[INFO] Generating build script completed, took 467ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 119ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 996ms
[INFO] Running build...
[INFO] Running build completed, took 17ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 63ms
[INFO] Succeeded after 93ms with 0 outputs (0 actions)
[SEVERE] JaguarCliException: Cannot handle TrackState in SampleJsonSerializer!
[SEVERE] #0 AnnotationParser._expandTypeInfo (package:jaguar_serializer_cli/src/instantiater/instantiater.dart:441:5)
#1 AnnotationParser.parse (package:jaguar_serializer_cli/src/instantiater/instantiater.dart:94:20)
#2 JaguarSerializerGenerator.generateForAnnotatedElement (package:jaguar_serializer_cli/src/generator.dart:34:65)
#3 GeneratorForAnnotation.generate (package:source_gen/src/generator_for_annotation.dart:47:30)
<asynchronous suspension>
#4 _generate (package:source_gen/src/builder.dart:280:35)
<asynchronous suspension>
#5 _Builder._generateForLibrary (package:source_gen/src/builder.dart:73:15)
<asynchronous suspension>
#6 _Builder.build (package:source_gen/src/builder.dart:67:11)
<asynchronous suspension>
#7 runBuilder.buildForInput (package:build/src/generate/run_builder.dart:45:21)
Is there an example somewhere on how to do a custom serializer ? Basically I want to manage a string enum like this:
class TxType {
/// The underlying value of this enum member.
final String value;
const TxType._internal(this.value);
static const TxType inject_ = const TxType._internal("inject");
static const TxType transfer_ = const TxType._internal("transfer");
static const TxType burn_ = const TxType._internal("burn");
static const TxType delete_ = const TxType._internal("delete");
}
But I need to serialize/deserialize it correctly as from the backend it will be a simple String. Any ideas ?
class _StripBearerProcessor implements FieldProcessor<String, String> {
const _StripBearerProcessor();
@override
String serialize(String value) => 'Bearer $value';
@override
String deserialize(String value) {
return value.substring(7);
}
}
@GenSerializer(
fields: {
'accessToken': Field(
processor: _StripBearerProcessor(),
),
},
)
class CustomerResponseSerializer extends Serializer<CustomerResponse>
with _$CustomerResponseSerializer {}
const EnDecode(processor: _StripBearerProcessor)
instead of Field(processor: ...)
though, not sure which one is more correct: https://github.com/Jaguar-dart/jaguar_serializer/wiki/Basics
I've got an issue where I have an entity called product groups, it has products. When I save the products and set their FK to catalog like so
@BelongsTo(ProductGroupEntityBean)
int productGroupId;
if I save the products group with cascade the products aren't saved. If I save them both with an insert they're saved but when I get the productGroups I get no products in the collection. It's almost as though the relationships aren't being specified correctly. Is the above right? Is this the correct way to declare a relationship?
Future<void> createTable({bool ifNotExists = false}) async {
final st = Sql.create(tableName, ifNotExists: ifNotExists);
st.addInt(id.name, primary: true, isNullable: false);
st.addStr(name.name, isNullable: false);
st.addInt(productCatalogId.name,
foreignTable: productCatalogEntityBean.tableName,
foreignCol: productCatalogEntityBean.id.name,
isNullable: false);
return adapter.createTable(st);