SessionContainer class

A generic, platform-agnostic session container (spec FR-001/FR-005/ FR-006/FR-007).

Sessions are keyed by (scope, type, key): scope namespaces independent sessions (default 'default'), type is the preset name, and key is the caller-chosen identifier inside that scope. The same API works in pure-Dart zuraffa apps and in zuraffa_flutter apps — this class has no Flutter or UI dependencies (spec FR-004/SC-004).

Reads treat expired sessions as not-found (never throwing) and enumeration skips them, so expiry is lazy — no background sweeper.

Available extensions

Constructors

SessionContainer({SessionPresetRegistry? registry})
SessionContainer.decode(String source, {SessionPresetRegistry? registry})
Restores from a JSON string produced by encode, optionally with a custom preset registry (defaults to built-ins).
factory

Properties

hashCode → int
The hash code for this object.
no setterinherited
isEmpty → bool
Whether any live session exists.
no setter
length → int
Number of live sessions across all scopes.
no setter
registry → SessionPresetRegistry
Registry consulted for validation on put and for preset discovery.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear(String type, String key, {String scope = 'default'}) → bool
Clears the session at (scope, type, key); returns whether one was removed (expired sessions count as cleared too).
clearScope(String scope) → int
Clears every session in scope (other scopes untouched — spec FR-007 isolation). Returns the number removed.
create(String type, String key, Map<String, dynamic> payload, {String scope = 'default', String? id}) → Session
Convenience: creates and stores a session from payload under a registered preset type.
encode() → String
Convenience: JSON-string form for transport across runtimes.
get(String type, String key, {String scope = 'default'}) → Session?
Reads the session at (scope, type, key), or null when absent or expired (spec edge case: empty store / expired = not-found).
list({String scope = 'default'}) → List<Session>
All live (non-expired) sessions within scope.
loadFromEnvelope(Map<String, dynamic> envelope) → void
Replaces the container's contents with the sessions in envelope.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
persist(SessionPersistence persistence) → Future<void>

Available on SessionContainer, provided by the SessionContainerPersistence extension

Snapshots the container into persistence.
put(Session session, {String scope = 'default'}) → Session
Stores a new session under (scope, type, key).
restore(SessionPersistence persistence) → Future<bool>

Available on SessionContainer, provided by the SessionContainerPersistence extension

Restores the container from persistence. A null load (nothing persisted yet) leaves the container untouched and returns false.
toJson() → Map<String, dynamic>
Serializes every session (live and expired — expiry is re-evaluated on read after restore, so nothing is silently dropped) into a versioned, portable envelope (spec FR-006). Each entry carries its scope so isolated sessions round-trip into the right namespace.
toString() → String
A string representation of this object.
inherited
update(String type, String key, Map<String, dynamic> payload, {String scope = 'default'}) → Session?
Updates the payload of an existing live session, returning the updated session — or null when it does not exist (or expired).

Operators

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