locorda_objects
Type-safe, object-oriented API layer for the locorda CRDT sync engine.
This package wraps the raw SyncEngine (which operates on RdfGraph) with an
ObjectSyncEngine that works directly with your Dart domain objects, handling
all RDF serialization via RdfMapper transparently.
Most applications should use the
locordapackage instead. Uselocorda_objectsdirectly when building non-Flutter apps or custom abstractions over the sync system.
Features
- ✅ Type-Safe API:
save<Note>(),hydrateStream<Note>(),delete<Note>()— no raw RDF - ✅ Automatic RDF Mapping: Uses
RdfMappergenerated bylocorda_builder - ✅ Index Configuration:
FullIndexConfigandGroupIndexConfigwithRootResourceFetchPolicy - ✅ Pure Dart: No Flutter dependency — usable in server or CLI contexts
Installation
dart pub add locorda_objects
Key types
| Type | Description |
|---|---|
ObjectSyncEngine |
Main facade — wraps SyncEngine with domain-object API |
LocordaConfig |
Declarative sync configuration for your resource types |
ResourceConfig |
Per-type config: storage layout, index type, fetch policy |
FullIndexConfig |
Single index for all items of a type |
GroupIndexConfig |
Partitioned index with regex-based group keys |
RootResourceFetchPolicy |
onRequest (lazy) or prefetch (eager) |
TypedHydrationBatch<T> |
Decoded batch: updates, deletions, cursor |
Usage
import 'package:locorda_objects/locorda_objects.dart';
final engine = await ObjectSyncEngine.create(
config: LocordaConfig(
resources: [
ResourceConfig<Note>(
index: FullIndexConfig(fetchPolicy: RootResourceFetchPolicy.prefetch),
storageLayout: ShardDataset(shardCount: 4),
),
],
),
mapperInitializer: initRdfMapper, // generated by locorda_builder
syncEngineFactory: SyncEngine.create,
);
// Stream new/updated/deleted items from remote
engine.hydrateStream<Note>().listen((batch) {
for (final note in batch.updates) { /* upsert locally */ }
for (final id in batch.deletions) { /* remove locally */ }
});
// Persist changes — triggers CRDT merge and sync
await engine.save(note);
await engine.delete<Note>('note-id');
Further reading
- locorda package — high-level Flutter entry point
- locorda_builder — code generator for
initRdfMapperand CRDT annotations