collection<T> abstract method
Returns an AtCollection of CItems for the given namespace.
namespace MUST be fully qualified. For example:
- if your application namespace is "app_1.my_apps"
- and the collection name is "tasks"
- then the fully qualified namespace is
"tasks.app_1.my_apps".
The application namespace configured on AtClientPreference is
NOT appended automatically — the caller must pass the complete
namespace. Throws ArgumentError if namespace contains no dot.
defaultExpiration is the ttl (time-to-live) for items in an
AtCollection. In draft() and create(), if you do not set an
expiresAt, the default ttl will be now + defaultExpiration.
Once the time elapses and the item expires, the atServer hard
deletes it, just like how AtKey ttls function.
If fromJson is supplied it is registered as the factory for items
of type T under typeTag (the wire-format identifier), via
AtCollection.registerFactory. fromJson and typeTag travel
together — supplying one without the other throws ArgumentError.
For polymorphic collections, omit both here and call
AtCollection.registerFactory<ConcreteType>(fromJson, typeTag: ...)
per concrete type.
typeTag is required (whenever fromJson is supplied) because
deriving the tag from T.toString() is unsafe under Dart's
minifier / tree-shaker — see AtCollection.registerFactory for
the full rationale.
writeTypeTag stamps items this collection creates with that tag when
no factory is registered for their type, without registering a
fromJson. When typeTag is also set, the two must match.
namespace is folded to lower case, as atProtocol keys are, and a
client hands back the collection it already built for the same folded
namespace and eventSource. While any collection of namespace is
open, an open that would stamp a new T with another tag throws
ArgumentError and caches nothing. An open stamps typeTag, else the
tag of the factory registered for T, else writeTypeTag, else n/a.
The check holds on this client only: another client, session or device
of the atSign does not see it. Implementers should refuse the same way.
When cleanupOrphansOnCreation is true, the returned collection runs
a one-shot cleanupOrphans() sweep before the Future completes.
Idempotent: the sweep runs at most once per collection instance
regardless of how many times collection is invoked with the flag.
Useful at app-startup to reclaim descendants whose parent was
deleted on another atSign while this app was offline.
eventSource selects which underlying source(s) feed the
collection's update / delete event streams. Defaults to
EventSource.both. See the EventSource enum dartdoc for the
per-value semantics.
- EventSource.data subscribes to AtClient.dataEvents only.
Sees ALL local keystore mutations — including locally-driven
writes (which never generate notifications) and TTL expiry
deletions. Recommended when a real
SyncServiceis running. - EventSource.notifs subscribes to
NotificationServiceonly. Locally-driven writes that don't generate notifications are NOT visible on the watch streams. - EventSource.both subscribes to both and emits events from each as they arrive — no de-duplication.
Throws StoppedException after stop.
Implementation
Future<AtCollection<T>> collection<T>(
String namespace,
Duration defaultExpiration, {
EventSource eventSource = EventSource.both,
T Function(Map<String, dynamic>)? fromJson,
String? typeTag,
String? writeTypeTag,
bool cleanupOrphansOnCreation = false,
});