kiss_firebase_repository_rest 0.0.2
kiss_firebase_repository_rest: ^0.0.2 copied to clipboard
A lightweight, type-safe Firestore implementation of the KISS Repository pattern for Dart using the Google Cloud Firestore REST API
KISS Repository Firestore REST API #
A lightweight, type-safe Firestore implementation of the KISS Repository pattern for Dart and Flutter applications.
Overview #
This package provides a Firestore implementation of the Repository pattern using Google's REST API. It allows you to interact with Firestore collections in a type-safe manner, with support for CRUD operations, querying, and document mapping.
This is intended for server side use only
Features #
- π Complete CRUD operations (Create, Read, Update, Delete)
- π Type-safe querying
- ποΈ Collection and subcollection support
- π JSON serialization and deserialization
- π Custom ID generation
- β‘ Efficient Firestore REST API integration
Installation #
Install the package using the Dart CLI:
dart pub add kiss_firebase_repository_rest
dart pub add googleapis
Usage #
Quick Start Example #
import 'package:googleapis/firestore/v1.dart';
import 'package:kiss_firebase_repository_rest/kiss_firebase_repository_rest.dart';
import 'package:google_auth_client/google_auth_client.dart'; // Assuming this is the package for GoogleClient
void main() async {
const serviceAccountJson = '''
{
"type": "service_account",
"project_id": "your-project-id",
"private_key_id": "your-private-key-id",
}
''';
final firestore = FirestoreApi(
await GoogleClient(serviceAccountJson: serviceAccountJson).getClient(),
);
final repository = RepositoryFirestoreJsonRestApi(
projectId: 'your-project-id',
firestore: firestore,
path: 'your-collection-path',
);
final document = await repository.get('your-document-id');
print(document);
}
Type Conversion #
The library provides utilities for converting between Dart types and Firestore types:
- Strings, booleans, integers, doubles
- DateTime (stored as ISO-8601 strings)
- Lists
- Maps (stored as nested documents)
Error Handling #
The repository throws RepositoryException with appropriate error codes:
RepositoryErrorCode.notFound- When a document doesn't existRepositoryErrorCode.alreadyExists- When trying to create a document with an existing ID
Future Development #
- Implement missing methods:
addAll,deleteAll,updateAll - Add support for streaming changes with
streamandstreamQuery - Add patch updates for more efficient document updates
License #
MIT