validateConfig<T extends dynamic> static method

void validateConfig<T extends dynamic>(
  1. SyncCollectionConfig<T> cfg
)

Validate the configuration for required mappers or RealmJson fallback inputs.

Implementation

static void validateConfig<T extends RealmObject>(
  SyncCollectionConfig<T> cfg,
) {
  // toSyncMap and propertyNames are OPTIONAL
  // RealmJson.toJsonWith() can auto-detect properties or use toEJson() when propertyNames is null

  // If propertyNames is provided, validate it includes critical sync fields
  final hasRealmJsonBasics = cfg.propertyNames != null;
  if (hasRealmJsonBasics) {
    final names = cfg.propertyNames!;
    final hasId = names.contains('id') || names.contains('_id');
    final hasUpdatedTs = names.contains('sync_updated_at');
    final hasSyncFlag = names.contains('sync_update_db');

    if (!hasId) {
      throw StateError(
        'SyncCollectionConfig(${cfg.collectionName}) propertyNames must include either "id" or "_id" for identification.',
      );
    }
    if (!hasUpdatedTs) {
      throw StateError(
        'SyncCollectionConfig(${cfg.collectionName}) propertyNames must include "sync_updated_at" (UTC millis) for conflict resolution.',
      );
    }
    if (!hasSyncFlag) {
      throw StateError(
        'SyncCollectionConfig(${cfg.collectionName}) propertyNames must include "sync_update_db" (boolean) for sync loop prevention.',
      );
    }
  }

  // Note: toSyncMap and propertyNames validation is skipped due to Dart's type system limitations
  // RealmJson automatically tries toEJson() first, then auto-detection, then explicit propertyNames
  // If custom toSyncMap is provided, we trust it includes '_id', 'sync_updated_at', and 'sync_update_db'
}