handleColdStartIfNeeded<T extends DatumEntityInterface> method

Future<bool> handleColdStartIfNeeded<T extends DatumEntityInterface>(
  1. String? userId,
  2. Future<DatumSyncResult<T>> syncFunction(
    1. DatumSyncOptions<DatumEntityInterface>
    ), {
  3. bool synchronous = false,
})

Handles cold start synchronization if needed for the specified user and entity type.

This method checks if a cold start sync is required based on the configured strategy and performs the sync if necessary.

Returns true if a cold start sync was performed, false otherwise.

Implementation

Future<bool> handleColdStartIfNeeded<T extends DatumEntityInterface>(
  String? userId,
  Future<DatumSyncResult<T>> Function(DatumSyncOptions) syncFunction, {
  bool synchronous = false,
}) async {
  return Datum.manager<T>().coldStartManager.handleColdStartIfNeeded(
    userId,
    (options) async {
      // Convert the generic DatumSyncOptions to the specific type expected
      final typedOptions = DatumSyncOptions<T>(
        forceFullSync: options.forceFullSync,
        timeout: options.timeout,
        direction: options.direction,
        includeDeletes: options.includeDeletes,
        resolveConflicts: options.resolveConflicts,
        overrideBatchSize: options.overrideBatchSize,
        conflictResolver: options.conflictResolver != null ? (options.conflictResolver is DatumConflictResolver<T> ? options.conflictResolver as DatumConflictResolver<T> : null) : null,
        query: options.query,
      );
      return await syncFunction(typedOptions);
    },
    entityType: T.toString(),
    synchronous: synchronous,
  );
}