EntityGraph class

Normalized entity graph — the single source of truth.

Mirrors the Zustand GraphState from entity-graph-core's graph.ts. All writes are synchronous and notify changes.

Constructors

EntityGraph()
Creates an isolated graph, primarily for provider overrides and tests.

Properties

changes Stream<GraphChange>
Stream of all graph changes. Subscribe once at a high level and selectively react to EntityChanged / ListChanged events.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
viewRecords List<GraphViewRecord>
Current framework view registrations projected without entity copies.
no setter

Methods

appendListResult(String queryKey, List<String> ids, {String? entityType, int? total, String? nextCursor, bool hasNextPage = false}) → void
captureSnapshot() EntityGraphSnapshot
Capture the complete graph-owned data needed for local DevTools rewind.
clearPatch(String type, String id) → void
Drop all patches for an entity.
dispose() Future<void>
Dispose the change stream. Call when the graph is no longer needed.
entityIds(String type) Iterable<String>
All entity ids for a given type.
entityState(String type, String id) EntityState
Fetch/cache state for a single entity.
insertIdInList(String queryKey, String id, Object position, {String? entityType}) → void
invalidateEntity(String type, {String? id}) → void
invalidateLists(String prefix) → void
invalidateListsForType(String type) → void
Mark every list registered for type stale.
invalidateType(String type) → void
listState(String queryKey) ListState
List slot for a query key.
markEntityOptimistic(String type, String id) → void
Mark the current visible entity as a local optimistic value.
markEntitySynced(String type, String id) → void
Mark an entity as confirmed without changing its canonical payload.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patchEntity(String type, String id, Map<String, Object?> patch) → void
Merge UI-only fields into the patch layer.
readCanonicalEntity(String type, String id) Map<String, Object?>?
Read canonical server-confirmed data without UI/optimistic patches.
readEntity(String type, String id) Map<String, Object?>?
Read canonical entity merged with patches, or null if absent.
readEntityPatch(String type, String id) Map<String, Object?>?
Read only the local patch layer for an entity.
readEntitySnapshot(String type, String id) Map<String, Object?>?
Read entity + sync metadata fields (\$synced, \$origin, \$updatedAt).
registerView(GraphViewDefinition definition, {Iterable<GraphEntityIdentity> membership = const []}) GraphViewRegistration
Register one mounted framework view and its current entity membership.
removeEntity(String type, String id) → void
Remove canonical entity, patches, and entity state.
removeEntityOptimistically(String type, String id) EntityRemovalSnapshot
Remove an entity optimistically and return everything needed to roll back.
removeIdFromAllLists(String type, String id) → void
replaceEntity(String type, String id, Map<String, Object?> data) → void
Replace the canonical entity entirely (no merge).
replaceEntityPatch(String type, String id, Map<String, Object?>? patch) → void
Replace the exact local patch for one entity in a single publication.
reset() → void
Reset the entire graph state. Intended for tests only.
restoreRemovedEntity(EntityRemovalSnapshot snapshot) → void
Restore a failed optimistic removal from its graph-owned receipt.
restoreSnapshot(EntityGraphSnapshot snapshot) → void
Restore one graph-owned snapshot through the normal publication boundary.
setEntityError(String type, String id, String? error) → void
setEntityFetched(String type, String id) → void
setEntityFetching(String type, String id, {required bool fetching}) → void
setEntityStale(String type, String id, {required bool stale}) → void
setEntitySyncMetadata(String type, String id, EntitySyncMetadata metadata) → void
Restore an exact sync-metadata value after optimistic rollback.
setListError(String queryKey, String? error) → void
setListFetching(String queryKey, {required bool fetching}) → void
setListFetchingMore(String queryKey, {required bool fetchingMore}) → void
setListResult(String queryKey, List<String> ids, {String? entityType, int? total, String? nextCursor, String? prevCursor, bool hasNextPage = false, bool hasPrevPage = false}) → void
setListStale(String queryKey, {required bool stale}) → void
subscribePublications(GraphPublicationListener listener) → void Function()
Observe complete outer writes without changing graph ownership.
subscribeViewLifecycles(GraphViewLifecycleListener listener) → void Function()
Observe logical framework view registration and membership changes.
syncMetadata(String type, String id) EntitySyncMetadata
Sync metadata for an entity, defaulting to a server-confirmed record.
toString() String
A string representation of this object.
inherited
unpatchEntity(String type, String id, List<String> keys) → void
Remove specific patch keys.
upsertEntities(String type, List<({Map<String, Object?> data, String id})> entries) → void
Batch upsert — single notification pass.
upsertEntity(String type, String id, Map<String, Object?> data) → void
Shallow-merge data into the canonical entity.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

instance EntityGraph
Singleton instance (mirrors the module-global Zustand store).
final