Collection constructor
Collection({
- required String name,
- required SerializerStrategy serializer,
- required WsChannel ws,
- CryptoStrategy? crypto,
- CacheStrategy? cache,
- SecretKey? secretKey,
- SmartCache? smartCache,
- bool local = false,
- Map<
String, String> serverSchema = const {},
Implementation
Collection({
required String name,
required SerializerStrategy serializer,
required WsChannel ws,
CryptoStrategy? crypto,
CacheStrategy? cache,
SecretKey? secretKey,
SmartCache? smartCache,
bool local = false,
Map<String, String> serverSchema = const {},
}) : _name = name,
_serializer = serializer,
_ws = ws,
_crypto = crypto,
_cache = cache,
_secretKey = secretKey,
_smartCache = smartCache,
_local = local {
_indexMetaKey = '_idx:$_name';
// Initialize from server schema
for (final entry in serverSchema.entries) {
_indexedFields[entry.key] = entry.value;
}
// Merge with locally persisted fields (may upgrade eq → range)
_restoreIndexedFields();
if (!_local) {
_syncSub = syncEvents.listen((e) {
_invalidateQueryCacheFor(e.blockId);
_pendingTags.remove(e.blockId);
if (e.action == 'put' && e.tags.isNotEmpty) {
_syncedRemote[e.blockId] = e.tags;
} else if (e.action == 'delete') {
_syncedRemote.remove(e.blockId);
}
});
}
}