ワンクリックで
defining-a-repository
Repositories are simple wrappers around SourceLists plus custom business logic.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Repositories are simple wrappers around SourceLists plus custom business logic.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Understand how sources declare operation capabilities via supportedOperations and how SourceList respects them.
FirestoreAdminSource connects google_cloud_firestore for server-side Dart applications to a SourceList.
FirestoreSource seamlessly connects Cloud Firestore streams to a SourceList.
Perform untyped Firestore document merges using the raw method on Firestore sources.
Cached data is mapped uniquely per request hash (RequestDetails with specific filter and pagination), supporting a powerful request-based caching behavior.
The SourceList class manages the delegation of read/write attempts to various configured Sources, with a read-thru cache system prioritizing local Sources.
| name | defining-a-repository |
| description | Repositories are simple wrappers around SourceLists plus custom business logic. |
| metadata | {"last_modified":"Sat, 18 Apr 2026 1:52:50 GMT"} |
Defining a Repository<T> often amounts to defining a SourceList<T>. However, this begs the question: Why does the Repository class exist?
The answer to this question is two-fold.
First, Repositories are the public-facing utility in pkg:data_layer, exposing a simpler API with simpler parameters. Specifically, the inner Operation construct is hidden from developers by the Repository, which creates one for the SourceList for each data request.
Second, Repositories are where you should place any custom business logic which does not neatly fall into one of the core DataContract methods.
One way to define a repository is to create a dedicated subclass for your specific data type. This is useful when you want to hide the constructor complexity from external consumers, or when you want custom business logic.
class UserRepository extends Repository<User> {
UserRepository() : super(
SourceList<User>(...),
);
Future<Result<User>> getByEmail(String email) async {
return getItems(
details: RequestDetails(filter: EmailFilter(email)),
);
}
}
The second way to define a repository is to directly instantiate what you need. This works well for simple cases where you don't need custom business logic.
final userRepository = Repository<User>(
SourceList<User>(...),
);
Repositories should all be singletons, completely owning the reading and writing of that data type across your entire application. pkg:data_layer's request-based caching will prevent the same Repository from cross-contaminating data when used in different corners of your application.