start method
Implementation
@override
Future<void> start(AuthConfig? authConfig) async {
if (opts.debug) {
await _logDatabaseVersion();
}
setClientListeners();
await migrator.up();
final isVerified = await _verifyTableStructure();
if (!isVerified) {
throw Exception('Invalid database schema.');
}
final configClientId = authConfig?.clientId;
final clientId = configClientId != null && configClientId != ''
? configClientId
: await _getClientId();
setAuthState(AuthState(clientId: clientId));
final notifierSubscriptions = {
'_authStateSubscription': _unsubscribeFromAuthState,
'_connectivityChangeSubscription': _unsubscribeFromConnectivityChanges,
'_potentialDataChangeSubscription': _unsubscribeFromPotentialDataChanges,
};
notifierSubscriptions.forEach((name, value) {
if (value != null) {
throw Exception('''
Starting satellite process with an existing `$name`.
This means there is a notifier subscription leak.`''');
}
});
// Monitor auth state changes.
_unsubscribeFromAuthState =
notifier.subscribeToAuthStateChanges(_updateAuthState);
// Request a snapshot whenever the data in our database potentially changes.
_unsubscribeFromPotentialDataChanges =
notifier.subscribeToPotentialDataChanges((_) => throttledSnapshot());
// Start polling to request a snapshot every `pollingInterval` ms.
_pollingInterval?.cancel();
_pollingInterval = Timer.periodic(
opts.pollingInterval,
(_) => throttledSnapshot(),
);
// Starting now!
await throttledSnapshot();
// Need to reload primary keys after schema migration
relations = await getLocalRelations();
await checkMaxSqlParameters();
final lsnBase64 = await getMeta<String?>('lsn');
if (lsnBase64 != null && lsnBase64.isNotEmpty) {
_lsn = base64.decode(lsnBase64);
logger.info('retrieved lsn $_lsn');
} else {
logger.info('no lsn retrieved from store');
}
final subscriptionsState = await getMeta<String>('subscriptions');
if (subscriptionsState.isNotEmpty) {
// this.subscriptions.setState(subscriptionsState)
subscriptionManager.initialize(subscriptionsState);
}
}