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:

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 T to and from JSON for the object methods of UnifiedDataSource, such as putObject and getObject.
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 T from 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 T into a JSON object.
WhereClause<T> = bool Function(T item)
Whether item belongs 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 after dispose().
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, clear or drop fails.
LocalDataSourceException
The base of every exception a UnifiedDataSource throws.
UnsupportedOperationException
Thrown when the engine can't do what was asked, such as returning a native accessor for a box that isn't open.