Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#730) Moved pull and purge into readonly table. #733

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class IOfflineTableExtensions
/// <param name="table">The table reference.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the pull operation is complete.</returns>
public static Task PullItemsAsync(this IOfflineTable table, CancellationToken cancellationToken = default)
public static Task PullItemsAsync(this IReadOnlyOfflineTable table, CancellationToken cancellationToken = default)
=> table.PullItemsAsync(string.Empty, new PullOptions(), cancellationToken);

/// <summary>
Expand All @@ -35,7 +35,7 @@ public static Task PullItemsAsync(this IOfflineTable table, CancellationToken ca
/// <param name="options">The pull options to use.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the pull operation is complete.</returns>
public static Task PullItemsAsync(this IOfflineTable table, PullOptions options, CancellationToken cancellationToken = default)
public static Task PullItemsAsync(this IReadOnlyOfflineTable table, PullOptions options, CancellationToken cancellationToken = default)
=> table.PullItemsAsync(string.Empty, options, cancellationToken);

/// <summary>
Expand All @@ -45,7 +45,7 @@ public static Task PullItemsAsync(this IOfflineTable table, PullOptions options,
/// <param name="query">The OData query string.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the pull operation is complete.</returns>
public static Task PullItemsAsync(this IOfflineTable table, string query, CancellationToken cancellationToken = default)
public static Task PullItemsAsync(this IReadOnlyOfflineTable table, string query, CancellationToken cancellationToken = default)
=> table.PullItemsAsync(query, new PullOptions(), cancellationToken);

/// <summary>
Expand All @@ -55,15 +55,15 @@ public static Task PullItemsAsync(this IOfflineTable table, string query, Cancel
/// <param name="query">The LINQ query.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the pull operation is complete.</returns>
public static Task PullItemsAsync<T, U>(this IOfflineTable<T> table, ITableQuery<U> query, CancellationToken cancellationToken = default)
public static Task PullItemsAsync<T, U>(this IReadOnlyOfflineTable<T> table, ITableQuery<U> query, CancellationToken cancellationToken = default)
=> table.PullItemsAsync(query, new PullOptions(), cancellationToken);

/// <summary>
/// Count the number of items that would be returned from the table without returning all the values.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that returns the number of items that will be in the result set when the query finishes.</returns>
public static Task<long> CountItemsAsync<T>(this IOfflineTable<T> table, CancellationToken cancellationToken = default)
public static Task<long> CountItemsAsync<T>(this IReadOnlyOfflineTable<T> table, CancellationToken cancellationToken = default)
=> table.CountItemsAsync(table.CreateQuery(), cancellationToken);

/// <summary>
Expand All @@ -73,7 +73,7 @@ public static Task<long> CountItemsAsync<T>(this IOfflineTable<T> table, Cancell
/// <param name="table">The source table.</param>
/// <param name="cancellationToken">The optional cancellation token to be used for cancelling the sequence at any time.</param>
/// <returns>An array of the results.</returns>
public static ValueTask<TSource[]> ToArrayAsync<TSource>(this IOfflineTable<TSource> table, CancellationToken cancellationToken = default)
public static ValueTask<TSource[]> ToArrayAsync<TSource>(this IReadOnlyOfflineTable<TSource> table, CancellationToken cancellationToken = default)
=> table.ToAsyncEnumerable().ToZumoArrayAsync(cancellationToken);

/// <summary>
Expand All @@ -82,7 +82,7 @@ public static ValueTask<TSource[]> ToArrayAsync<TSource>(this IOfflineTable<TSou
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
/// <param name="table">The source table.</param>
/// <returns>The result set as an <see cref="AsyncPageable{T}"/></returns>
public static AsyncPageable<TSource> ToAsyncPageable<TSource>(this IOfflineTable<TSource> table)
public static AsyncPageable<TSource> ToAsyncPageable<TSource>(this IReadOnlyOfflineTable<TSource> table)
=> (AsyncPageable<TSource>)table.ToAsyncEnumerable();

/// <summary>
Expand All @@ -94,7 +94,7 @@ public static AsyncPageable<TSource> ToAsyncPageable<TSource>(this IOfflineTable
/// <param name="keySelector">A function to extract a key from each element.</param>
/// <param name="cancellationToken">The optional cancellation token to be used for cancelling the sequence at any time.</param>
/// <returns>A dictionary mapping unique key values onto the corresponding result's element.</returns>
public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IOfflineTable<TSource> table, Func<TSource, TKey> keySelector, CancellationToken cancellationToken = default) where TKey : notnull
public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IReadOnlyOfflineTable<TSource> table, Func<TSource, TKey> keySelector, CancellationToken cancellationToken = default) where TKey : notnull
=> table.ToAsyncEnumerable().ToZumoDictionaryAsync(keySelector, cancellationToken);

/// <summary>
Expand All @@ -107,7 +107,7 @@ public static AsyncPageable<TSource> ToAsyncPageable<TSource>(this IOfflineTable
/// <param name="comparer">An equality comparer to compare keys.</param>
/// <param name="cancellationToken">The optional cancellation token to be used for cancelling the sequence at any time.</param>
/// <returns>A dictionary mapping unique key values onto the corresponding result's element.</returns>
public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IOfflineTable<TSource> table, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default) where TKey : notnull
public static ValueTask<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IReadOnlyOfflineTable<TSource> table, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default) where TKey : notnull
=> table.ToAsyncEnumerable().ToZumoDictionaryAsync(keySelector, comparer, cancellationToken);

/// <summary>
Expand All @@ -116,7 +116,7 @@ public static AsyncPageable<TSource> ToAsyncPageable<TSource>(this IOfflineTable
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
/// <param name="table">The source table.</param>
/// <returns>The enumerable sequence containing the elements in the result set.</returns>
public static IEnumerable<TSource> ToEnumerable<TSource>(this IOfflineTable<TSource> table)
public static IEnumerable<TSource> ToEnumerable<TSource>(this IReadOnlyOfflineTable<TSource> table)
=> table.ToAsyncEnumerable().ToZumoEnumerable();

/// <summary>
Expand All @@ -126,7 +126,7 @@ public static IEnumerable<TSource> ToEnumerable<TSource>(this IOfflineTable<TSou
/// <param name="table">The source table.</param>
/// <param name="cancellationToken">The optional cancellation token to be used for cancelling the sequence at any time.</param>
/// <returns>A hash set containing all the elements of the source sequence.</returns>
public static ValueTask<HashSet<TSource>> ToHashSetAsync<TSource>(this IOfflineTable<TSource> table, CancellationToken cancellationToken = default)
public static ValueTask<HashSet<TSource>> ToHashSetAsync<TSource>(this IReadOnlyOfflineTable<TSource> table, CancellationToken cancellationToken = default)
=> table.ToAsyncEnumerable().ToZumoHashSetAsync(cancellationToken);

/// <summary>
Expand All @@ -137,7 +137,7 @@ public static ValueTask<HashSet<TSource>> ToHashSetAsync<TSource>(this IOfflineT
/// <param name="comparer">An equality comparer to compare elements of the sequence.</param>
/// <param name="cancellationToken">The optional cancellation token to be used for cancelling the sequence at any time.</param>
/// <returns>A hash set containing all the elements of the source sequence.</returns>
public static ValueTask<HashSet<TSource>> ToHashSetAsync<TSource>(this IOfflineTable<TSource> table, IEqualityComparer<TSource>? comparer, CancellationToken cancellationToken = default)
public static ValueTask<HashSet<TSource>> ToHashSetAsync<TSource>(this IReadOnlyOfflineTable<TSource> table, IEqualityComparer<TSource>? comparer, CancellationToken cancellationToken = default)
=> table.ToAsyncEnumerable().ToZumoHashSetAsync(comparer, cancellationToken);

/// <summary>
Expand All @@ -147,7 +147,7 @@ public static ValueTask<HashSet<TSource>> ToHashSetAsync<TSource>(this IOfflineT
/// <param name="table">The source table.</param>
/// <param name="cancellationToken">The optional cancellation token to be used for cancelling the sequence at any time.</param>
/// <returns>A list containing all the elements of the source sequence.</returns>
public static ValueTask<List<TSource>> ToListAsync<TSource>(this IOfflineTable<TSource> table, CancellationToken cancellationToken = default)
public static ValueTask<List<TSource>> ToListAsync<TSource>(this IReadOnlyOfflineTable<TSource> table, CancellationToken cancellationToken = default)
=> table.ToAsyncEnumerable().ToZumoListAsync(cancellationToken);

/// <summary>
Expand All @@ -157,7 +157,7 @@ public static ValueTask<List<TSource>> ToListAsync<TSource>(this IOfflineTable<T
/// <param name="table">The source table.</param>
/// <param name="cancellationToken">The optional cancellation token to be used for cancelling the sequence at any time.</param>
/// <returns>A <see cref="ConcurrentObservableCollection{T}"/> containing all the elements of the source sequence.</returns>
public static ValueTask<ConcurrentObservableCollection<TSource>> ToObservableCollection<TSource>(this IOfflineTable<TSource> table, CancellationToken cancellationToken = default)
public static ValueTask<ConcurrentObservableCollection<TSource>> ToObservableCollection<TSource>(this IReadOnlyOfflineTable<TSource> table, CancellationToken cancellationToken = default)
=> table.ToAsyncEnumerable().ToZumoObservableCollectionAsync(cancellationToken);

/// <summary>
Expand All @@ -168,7 +168,7 @@ public static ValueTask<ConcurrentObservableCollection<TSource>> ToObservableCol
/// <param name="collection">The <see cref="ConcurrentObservableCollection{T}"/> to update.</param>
/// <param name="cancellationToken">The optional cancellation token to be used for cancelling the sequence at any time.</param>
/// <returns>The <see cref="ConcurrentObservableCollection{T}"/> passed in containing all the elements of the source sequence (replacing the old content).</returns>
public static ValueTask<ConcurrentObservableCollection<TSource>> ToObservableCollection<TSource>(this IOfflineTable<TSource> table, ConcurrentObservableCollection<TSource> collection, CancellationToken cancellationToken = default)
public static ValueTask<ConcurrentObservableCollection<TSource>> ToObservableCollection<TSource>(this IReadOnlyOfflineTable<TSource> table, ConcurrentObservableCollection<TSource> collection, CancellationToken cancellationToken = default)
=> table.ToAsyncEnumerable().ToZumoObservableCollectionAsync(collection, cancellationToken);
}
}
76 changes: 38 additions & 38 deletions sdk/dotnet/src/Microsoft.Datasync.Client/Table/IOfflineTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ public interface IReadOnlyOfflineTable
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that returns the item when complete.</returns>
Task<JObject> GetItemAsync(string id, CancellationToken cancellationToken = default);

/// <summary>
/// Pulls the items matching the provided query from the remote table.
/// </summary>
/// <param name="query">The OData query that determines which items to pull from the remote table.</param>
/// <param name="options">The options used to configure the pull operation.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the pull operation has finished.</returns>
Task PullItemsAsync(string query, PullOptions options, CancellationToken cancellationToken = default);

/// <summary>
/// Deletes all the items in the offline table that match the query.
/// </summary>
/// <param name="query">An OData query that determines which items to delete.</param>
/// <param name="options">The options used to configure the purge operation.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the purge operation has finished.</returns>
Task PurgeItemsAsync(string query, PurgeOptions options, CancellationToken cancellationToken = default);
}

/// <summary>
Expand All @@ -73,24 +91,6 @@ public interface IOfflineTable : IReadOnlyOfflineTable
/// <returns>A task that returns the inserted data when complete.</returns>
Task<JObject> InsertItemAsync(JObject instance, CancellationToken cancellationToken = default);

/// <summary>
/// Pulls the items matching the provided query from the remote table.
/// </summary>
/// <param name="query">The OData query that determines which items to pull from the remote table.</param>
/// <param name="options">The options used to configure the pull operation.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the pull operation has finished.</returns>
Task PullItemsAsync(string query, PullOptions options, CancellationToken cancellationToken = default);

/// <summary>
/// Deletes all the items in the offline table that match the query.
/// </summary>
/// <param name="query">An OData query that determines which items to delete.</param>
/// <param name="options">The options used to configure the purge operation.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the purge operation has finished.</returns>
Task PurgeItemsAsync(string query, PurgeOptions options, CancellationToken cancellationToken = default);

/// <summary>
/// Pushes all operations for this table in the operations queue to the remote service.
/// </summary>
Expand Down Expand Up @@ -158,6 +158,26 @@ public interface IReadOnlyOfflineTable<T> : IReadOnlyOfflineTable, ILinqMethods<
/// <returns>A task that returns the item when complete.</returns>
new Task<T> GetItemAsync(string id, CancellationToken cancellationToken = default);

/// <summary>
/// Pulls the items matching the provided query from the remote table.
/// </summary>
/// <typeparam name="U">The type of the data transfer object (DTO) or model that is returned by the query.</typeparam>
/// <param name="query">The OData query that determines which items to pull from the remote table.</param>
/// <param name="options">The options used to configure the pull operation.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the pull operation has finished.</returns>
Task PullItemsAsync<U>(ITableQuery<U> query, PullOptions options, CancellationToken cancellationToken = default);

/// <summary>
/// Deletes all the items in the offline table that match the query.
/// </summary>
/// <typeparam name="U">The type of the data transfer object (DTO) or model that is returned by the query.</typeparam>
/// <param name="query">An OData query that determines which items to delete.</param>
/// <param name="options">The options used to configure the purge operation.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the purge operation has finished.</returns>
Task PurgeItemsAsync<U>(ITableQuery<U> query, PurgeOptions options, CancellationToken cancellationToken = default);

/// <summary>
/// Refreshes the current instance with the latest values from the table.
/// </summary>
Expand Down Expand Up @@ -189,26 +209,6 @@ public interface IOfflineTable<T> : IOfflineTable, IReadOnlyOfflineTable<T>
/// <returns>A task that returns when the operation is complete.</returns>
Task InsertItemAsync(T instance, CancellationToken cancellationToken = default);

/// <summary>
/// Pulls the items matching the provided query from the remote table.
/// </summary>
/// <typeparam name="U">The type of the data transfer object (DTO) or model that is returned by the query.</typeparam>
/// <param name="query">The OData query that determines which items to pull from the remote table.</param>
/// <param name="options">The options used to configure the pull operation.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the pull operation has finished.</returns>
Task PullItemsAsync<U>(ITableQuery<U> query, PullOptions options, CancellationToken cancellationToken = default);

/// <summary>
/// Deletes all the items in the offline table that match the query.
/// </summary>
/// <typeparam name="U">The type of the data transfer object (DTO) or model that is returned by the query.</typeparam>
/// <param name="query">An OData query that determines which items to delete.</param>
/// <param name="options">The options used to configure the purge operation.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that completes when the purge operation has finished.</returns>
Task PurgeItemsAsync<U>(ITableQuery<U> query, PurgeOptions options, CancellationToken cancellationToken = default);

/// <summary>
/// Replaces the current instance with the provided instance in the remote table.
/// </summary>
Expand Down