Patapata - Builder

Adds new capabilities to your Repository.


About

This package extends the functionality of Patapata using build_runner.

Currently, it only includes repository_sets_builder, which extends repository.

Getting started

  1. Add the dependency to your pubspec.yaml file
dev_dependencies:
  patapata_builder: ^1.0.0
  build_runner: ^2.4.13

Repository_sets_builder

repository_sets_builder adds the concept of filters to the objects stored in a repository. Normally, the type of an object retrieved from a repository remains the same regardless of the hierarchy level it is retrieved from. However, this can be inconvenient in some cases.

For example, consider a case where the same type of object is stored at different levels of a hierarchy. At the parent level, only Data A is stored, while at the child level, Data B is stored. If you try to access Data B from the parent level, it does not exist. However, it’s unclear whether it is truly null or simply not retrieved at that level.

To solve this, repository_sets_builder provides filters that apply access restrictions based on the hierarchy level. This makes it possible to clearly define which data should be accessible at each level, avoiding ambiguity and improving data integrity.

import 'package:patapata_core/patapata_annotation.dart';
import 'package:provider/provider.dart';

part 'model.g.dart';

mixin DataSet {}

@RepositoryClass(sets: {DataSet})
abstract class _Data extends ProviderModel<Data> {
  _Data({
    required this.id,
  });

  _Data.init(this.id) {
    final tData = Data(id: id);
    final tBatch = tData.begin();

    tBatch
      ..set(_name, 'id: $id')
      ..set(_value, 0)
  }

  @RepositoryId()
  final int id;

  @RepositoryField()
  late final _name = createUnsetVariable<String>();

  @RepositoryField(sets: {DataSet})
  late final _value = createUnsetVariable<int>();
}

By defining a class as shown above and running build_runner, the Data class will be generated. When you store it in the repository, it can be retrieved either as Data or as DataSet.

When retrieved as Data, all members are accessible. However, when retrieved as DataSet, only value1 can be accessed.

For more concrete usage examples, please refer to the repository section of patapata_example_app.

Contributing

Check out the CONTRIBUTING guide to get started.

License

See the LICENSE file

Libraries

patapata_builder