Skip to content

Commit 0153193

Browse files
committed
Update the CountAsync() API to support flowing a state parameter
1 parent 8b84742 commit 0153193

24 files changed

Lines changed: 236 additions & 36 deletions

src/OpenIddict.Abstractions/Managers/IOpenIddictApplicationManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ public interface IOpenIddictApplicationManager
4848
/// </returns>
4949
ValueTask<long> CountAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
5050

51+
/// <summary>
52+
/// Determines the number of applications that match the specified query.
53+
/// </summary>
54+
/// <typeparam name="TState">The state type.</typeparam>
55+
/// <typeparam name="TResult">The result type.</typeparam>
56+
/// <param name="query">The query to execute.</param>
57+
/// <param name="state">The optional state.</param>
58+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
59+
/// <returns>
60+
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
61+
/// whose result returns the number of applications that match the specified query.
62+
/// </returns>
63+
ValueTask<long> CountAsync<TState, TResult>(
64+
Func<IQueryable<object>, TState, IQueryable<TResult>> query,
65+
TState state, CancellationToken cancellationToken = default);
66+
5167
/// <summary>
5268
/// Creates a new application based on the specified descriptor.
5369
/// Note: the default implementation automatically hashes the client

src/OpenIddict.Abstractions/Managers/IOpenIddictAuthorizationManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ public interface IOpenIddictAuthorizationManager
4646
ValueTask<long> CountAsync<TResult>(
4747
Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
4848

49+
/// <summary>
50+
/// Determines the number of authorizations that match the specified query.
51+
/// </summary>
52+
/// <typeparam name="TState">The state type.</typeparam>
53+
/// <typeparam name="TResult">The result type.</typeparam>
54+
/// <param name="query">The query to execute.</param>
55+
/// <param name="state">The optional state.</param>
56+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
57+
/// <returns>
58+
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
59+
/// whose result returns the number of authorizations that match the specified query.
60+
/// </returns>
61+
ValueTask<long> CountAsync<TState, TResult>(
62+
Func<IQueryable<object>, TState, IQueryable<TResult>> query,
63+
TState state, CancellationToken cancellationToken = default);
64+
4965
/// <summary>
5066
/// Creates a new permanent authorization based on the specified parameters.
5167
/// </summary>

src/OpenIddict.Abstractions/Managers/IOpenIddictScopeManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ public interface IOpenIddictScopeManager
4545
/// </returns>
4646
ValueTask<long> CountAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
4747

48+
/// <summary>
49+
/// Determines the number of scopes that match the specified query.
50+
/// </summary>
51+
/// <typeparam name="TState">The state type.</typeparam>
52+
/// <typeparam name="TResult">The result type.</typeparam>
53+
/// <param name="query">The query to execute.</param>
54+
/// <param name="state">The optional state.</param>
55+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
56+
/// <returns>
57+
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
58+
/// whose result returns the number of scopes that match the specified query.
59+
/// </returns>
60+
ValueTask<long> CountAsync<TState, TResult>(
61+
Func<IQueryable<object>, TState, IQueryable<TResult>> query,
62+
TState state, CancellationToken cancellationToken = default);
63+
4864
/// <summary>
4965
/// Creates a new scope based on the specified descriptor.
5066
/// </summary>

src/OpenIddict.Abstractions/Managers/IOpenIddictTokenManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ public interface IOpenIddictTokenManager
4444
/// </returns>
4545
ValueTask<long> CountAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
4646

47+
/// <summary>
48+
/// Determines the number of tokens that match the specified query.
49+
/// </summary>
50+
/// <typeparam name="TState">The state type.</typeparam>
51+
/// <typeparam name="TResult">The result type.</typeparam>
52+
/// <param name="query">The query to execute.</param>
53+
/// <param name="state">The optional state.</param>
54+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
55+
/// <returns>
56+
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
57+
/// whose result returns the number of tokens that match the specified query.
58+
/// </returns>
59+
ValueTask<long> CountAsync<TState, TResult>(
60+
Func<IQueryable<object>, TState, IQueryable<TResult>> query,
61+
TState state, CancellationToken cancellationToken = default);
62+
4763
/// <summary>
4864
/// Creates a new token based on the specified descriptor.
4965
/// </summary>

src/OpenIddict.Abstractions/Stores/IOpenIddictApplicationStore.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ public interface IOpenIddictApplicationStore<TApplication> where TApplication :
3131
/// <summary>
3232
/// Determines the number of applications that match the specified query.
3333
/// </summary>
34+
/// <typeparam name="TState">The state type.</typeparam>
3435
/// <typeparam name="TResult">The result type.</typeparam>
3536
/// <param name="query">The query to execute.</param>
37+
/// <param name="state">The optional state.</param>
3638
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
3739
/// <returns>
3840
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
3941
/// whose result returns the number of applications that match the specified query.
4042
/// </returns>
41-
ValueTask<long> CountAsync<TResult>(Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken);
43+
ValueTask<long> CountAsync<TState, TResult>(
44+
Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query,
45+
TState state, CancellationToken cancellationToken);
4246

4347
/// <summary>
4448
/// Creates a new application.

src/OpenIddict.Abstractions/Stores/IOpenIddictAuthorizationStore.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ public interface IOpenIddictAuthorizationStore<TAuthorization> where TAuthorizat
2828
/// <summary>
2929
/// Determines the number of authorizations that match the specified query.
3030
/// </summary>
31+
/// <typeparam name="TState">The state type.</typeparam>
3132
/// <typeparam name="TResult">The result type.</typeparam>
3233
/// <param name="query">The query to execute.</param>
34+
/// <param name="state">The optional state.</param>
3335
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
3436
/// <returns>
3537
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
3638
/// whose result returns the number of authorizations that match the specified query.
3739
/// </returns>
38-
ValueTask<long> CountAsync<TResult>(Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken);
40+
ValueTask<long> CountAsync<TState, TResult>(
41+
Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query,
42+
TState state, CancellationToken cancellationToken);
3943

4044
/// <summary>
4145
/// Creates a new authorization.

src/OpenIddict.Abstractions/Stores/IOpenIddictScopeStore.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ public interface IOpenIddictScopeStore<TScope> where TScope : class
2929
/// <summary>
3030
/// Determines the number of scopes that match the specified query.
3131
/// </summary>
32+
/// <typeparam name="TState">The state type.</typeparam>
3233
/// <typeparam name="TResult">The result type.</typeparam>
3334
/// <param name="query">The query to execute.</param>
35+
/// <param name="state">The optional state.</param>
3436
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
3537
/// <returns>
3638
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
3739
/// whose result returns the number of scopes that match the specified query.
3840
/// </returns>
39-
ValueTask<long> CountAsync<TResult>(Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken);
41+
ValueTask<long> CountAsync<TState, TResult>(
42+
Func<IQueryable<TScope>, TState, IQueryable<TResult>> query,
43+
TState state, CancellationToken cancellationToken);
4044

4145
/// <summary>
4246
/// Creates a new scope.

src/OpenIddict.Abstractions/Stores/IOpenIddictTokenStore.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ public interface IOpenIddictTokenStore<TToken> where TToken : class
2828
/// <summary>
2929
/// Determines the number of tokens that match the specified query.
3030
/// </summary>
31+
/// <typeparam name="TState">The state type.</typeparam>
3132
/// <typeparam name="TResult">The result type.</typeparam>
3233
/// <param name="query">The query to execute.</param>
34+
/// <param name="state">The optional state.</param>
3335
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
3436
/// <returns>
3537
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
3638
/// whose result returns the number of tokens that match the specified query.
3739
/// </returns>
38-
ValueTask<long> CountAsync<TResult>(Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken);
40+
ValueTask<long> CountAsync<TState, TResult>(
41+
Func<IQueryable<TToken>, TState, IQueryable<TResult>> query,
42+
TState state, CancellationToken cancellationToken);
3943

4044
/// <summary>
4145
/// Creates a new token.

src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,28 @@ public virtual ValueTask<long> CountAsync<TResult>(
9696
{
9797
ArgumentNullException.ThrowIfNull(query);
9898

99-
return Store.CountAsync(query, cancellationToken);
99+
return CountAsync(static (applications, query) => query(applications), query, cancellationToken);
100+
}
101+
102+
/// <summary>
103+
/// Determines the number of applications that match the specified query.
104+
/// </summary>
105+
/// <typeparam name="TState">The state type.</typeparam>
106+
/// <typeparam name="TResult">The result type.</typeparam>
107+
/// <param name="query">The query to execute.</param>
108+
/// <param name="state">The optional state.</param>
109+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
110+
/// <returns>
111+
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
112+
/// whose result returns the number of applications that match the specified query.
113+
/// </returns>
114+
public virtual ValueTask<long> CountAsync<TState, TResult>(
115+
Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query,
116+
TState state, CancellationToken cancellationToken = default)
117+
{
118+
ArgumentNullException.ThrowIfNull(query);
119+
120+
return Store.CountAsync(query, state, cancellationToken);
100121
}
101122

102123
/// <summary>
@@ -1845,6 +1866,10 @@ ValueTask<long> IOpenIddictApplicationManager.CountAsync(CancellationToken cance
18451866
ValueTask<long> IOpenIddictApplicationManager.CountAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken)
18461867
=> CountAsync(query, cancellationToken);
18471868

1869+
/// <inheritdoc/>
1870+
ValueTask<long> IOpenIddictApplicationManager.CountAsync<TState, TResult>(Func<IQueryable<object>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
1871+
=> CountAsync(query, state, cancellationToken);
1872+
18481873
/// <inheritdoc/>
18491874
async ValueTask<object> IOpenIddictApplicationManager.CreateAsync(OpenIddictApplicationDescriptor descriptor, CancellationToken cancellationToken)
18501875
=> await CreateAsync(descriptor, cancellationToken);

src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,28 @@ public virtual ValueTask<long> CountAsync<TResult>(
9292
{
9393
ArgumentNullException.ThrowIfNull(query);
9494

95-
return Store.CountAsync(query, cancellationToken);
95+
return CountAsync(static (authorizations, query) => query(authorizations), query, cancellationToken);
96+
}
97+
98+
/// <summary>
99+
/// Determines the number of authorizations that match the specified query.
100+
/// </summary>
101+
/// <typeparam name="TState">The state type.</typeparam>
102+
/// <typeparam name="TResult">The result type.</typeparam>
103+
/// <param name="query">The query to execute.</param>
104+
/// <param name="state">The optional state.</param>
105+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
106+
/// <returns>
107+
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
108+
/// whose result returns the number of authorizations that match the specified query.
109+
/// </returns>
110+
public virtual ValueTask<long> CountAsync<TState, TResult>(
111+
Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query,
112+
TState state, CancellationToken cancellationToken = default)
113+
{
114+
ArgumentNullException.ThrowIfNull(query);
115+
116+
return Store.CountAsync(query, state, cancellationToken);
96117
}
97118

98119
/// <summary>
@@ -953,6 +974,10 @@ ValueTask<long> IOpenIddictAuthorizationManager.CountAsync(CancellationToken can
953974
ValueTask<long> IOpenIddictAuthorizationManager.CountAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken)
954975
=> CountAsync(query, cancellationToken);
955976

977+
/// <inheritdoc/>
978+
ValueTask<long> IOpenIddictAuthorizationManager.CountAsync<TState, TResult>(Func<IQueryable<object>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
979+
=> CountAsync(query, state, cancellationToken);
980+
956981
/// <inheritdoc/>
957982
async ValueTask<object> IOpenIddictAuthorizationManager.CreateAsync(ClaimsIdentity identity, string subject, string client, string type, ImmutableArray<string> scopes, CancellationToken cancellationToken)
958983
=> await CreateAsync(identity, subject, client, type, scopes, cancellationToken);

0 commit comments

Comments
 (0)