engine library
Building blocks for implementing a UnifiedDataSource engine.
Exports everything in package:unified_local_data/unified_local_data.dart
plus helpers that make an engine behave like the built-in ones:
- guardRead, guardWrite and guardStream report the engine's errors as DataSourceReadException and DataSourceWriteException.
- InMemoryQueryBuilder answers UnifiedDataSource.query for engines without a query language of their own.
An engine has two parts: a UnifiedDataSource implementation, and a UnifiedDataSourceConfig subclass whose UnifiedDataSourceConfig.createDataSource builds it. Pass the config to UnifiedDataSourceFactory.create like any other.
Classes
-
DataModel<
T> - An optional contract for models that convert themselves to and from JSON. The API uses DataModelAdapter, not this interface.
-
DataModelAdapter<
T> -
Converts
Tto and from JSON for the object methods ofUnifiedDataSource, such asputObjectandgetObject. - HiveDataSource
- The Hive engine: each collection is a Hive box, holding values under string keys.
- HiveDataSourceConfig
- Configuration for the Hive engine, which stores each collection in its own Hive box.
- HiveEncryptionConfig
- The AES key that encrypts every Hive box the data source opens.
-
InMemoryQueryBuilder<
T> - A QueryBuilder that loads every object and filters, sorts and pages them in memory.
-
NativeCollectionAccessor<
T> -
Direct access to one collection through the engine's own types, returned
by
UnifiedDataSource.native. -
QueryBuilder<
T> - A chainable query over the objects of one collection.
- UnifiedDataSource
- Local key-value storage that works the same on every engine.
- UnifiedDataSourceConfig
- Which engine a UnifiedDataSource uses, and how.
- UnifiedDataSourceFactory
- Creates the app's UnifiedDataSource and keeps it as a singleton.
Extensions
-
LocalDataSourceStreamX
on Stream<
T> -
Stream helpers for the watch methods of
UnifiedDataSource.
Functions
-
guardRead<
T> (String message, Future< T> action()) → Future<T> -
Runs a read, reporting any failure that isn't already a
LocalDataSourceException as a DataSourceReadException with
message. -
guardStream<
T> (String message, Stream< T> open()) → Stream<T> - Opens a watch stream, reporting a failure to open it, and every error it emits, the way guardRead does.
-
guardWrite<
T> (String message, Future< T> action()) → Future<T> -
Runs a write or a delete, reporting any failure that isn't already a
LocalDataSourceException as a DataSourceWriteException with
message.
Typedefs
-
FromJson<
T> = T Function(JsonMap json) -
Builds a
Tfrom a JSON object. -
JsonMap
= Map<
String, dynamic> - A JSON object.
-
SortComparator<
T> = int Function(T a, T b) - Orders two query results, the way Comparator does.
-
ToJson<
T> = JsonMap Function(T object) -
Turns a
Tinto a JSON object. -
WhereClause<
T> = bool Function(T item) -
Whether
itembelongs in a query's results.
Exceptions / Errors
- DataNotFoundException
- Thrown when requested data doesn't exist.
- DataSourceNotInitializedException
-
Thrown when a data source is used before
init()or afterdispose(). - DataSourceReadException
- Thrown when a read fails, including when a stored value isn't of the requested type. Watch streams emit it as an error.
- DataSourceWriteException
-
Thrown when a write, a delete,
clearordropfails. - LocalDataSourceException
-
The base of every exception a
UnifiedDataSourcethrows. - UnsupportedOperationException
- Thrown when the engine can't do what was asked, such as returning a native accessor for a box that isn't open.