From 42b15125e51c827558e777f1dd09c04f5f474b0d Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Sun, 10 Nov 2024 18:35:38 +0100 Subject: [PATCH] Fix streaming API. --- .../Directory.Build.props | 2 +- .../Squidex.ClientLibrary/ContentsClient.cs | 3 +- .../Squidex.ClientLibrary/Generated.cs | 415 ++++++++++++++++++ 3 files changed, 417 insertions(+), 3 deletions(-) diff --git a/csharp/Squidex.ClientLibrary/Directory.Build.props b/csharp/Squidex.ClientLibrary/Directory.Build.props index c502920..0a25beb 100644 --- a/csharp/Squidex.ClientLibrary/Directory.Build.props +++ b/csharp/Squidex.ClientLibrary/Directory.Build.props @@ -15,7 +15,7 @@ Squidex HeadlessCMS true snupkg - 19.7.0 + 20.0.0 diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsClient.cs index e6395f3..7455a7c 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsClient.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsClient.cs @@ -55,7 +55,6 @@ public async Task GetAllAsync(Func callback, int batchSize = 200, var isAnyAdded = false; var getResult = await GetAsync(query, context, ct); - foreach (var item in getResult.Items) { if (added.Add(item.Id)) @@ -89,7 +88,7 @@ public async Task StreamAllAsync(Func callback, int skip = 0, Que using (var request = BuildRequest(HttpMethod.Get, BuildUrl($"stream?skip={skip}", false), null, context)) { - using (var response = await httpClient.SendAsync(request, ct)) + using (var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, ct)) { await EnsureResponseIsValidAsync(response); diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Generated.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Generated.cs index 734c663..2667959 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Generated.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Generated.cs @@ -5047,6 +5047,34 @@ public partial interface ISchemasClient /// A server side error occurred. System.Threading.Tasks.Task DisableNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Gets the schema indexes. + /// + /// The name of the schema. + /// Schema indexes returned. + /// A server side error occurred. + System.Threading.Tasks.Task GetIndexesAsync(string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Create a schema indexes. + /// + /// The name of the schema. + /// The request object that represents an index. + /// A server side error occurred. + System.Threading.Tasks.Task PostIndexAsync(string schema, CreateIndexDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Create a schema indexes. + /// + /// The name of the schema. + /// The name of the index. + /// Schema index deletion added to job queue. + /// A server side error occurred. + System.Threading.Tasks.Task DeleteIndexAsync(string schema, string name, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get schemas. @@ -7471,6 +7499,318 @@ private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() #pragma warning restore CS0219 // Variable is assigned but its value is never used } + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Gets the schema indexes. + /// + /// The name of the schema. + /// Schema indexes returned. + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task GetIndexesAsync(string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + { + if (schema == null) + throw new System.ArgumentNullException("schema"); + + var client_ = _options.ClientProvider.Get(); + #pragma warning disable CS0219 // Variable is assigned but its value is never used + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + + // Operation Path: "api/apps/$app$/schemas/{schema}/indexes" + urlBuilder_.Append("api/apps/$app$/schemas/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/indexes"); + urlBuilder_.Replace("$app$", _options.AppName); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new SquidexException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 404) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new SquidexException("Schema or app not found.", status_, responseText_, headers_, null); + } + else + if (status_ == 500) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new SquidexException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new SquidexException("Operation failed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + { + var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new SquidexException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + } + #pragma warning restore CS0219 // Variable is assigned but its value is never used + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Create a schema indexes. + /// + /// The name of the schema. + /// The request object that represents an index. + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task PostIndexAsync(string schema, CreateIndexDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + { + if (schema == null) + throw new System.ArgumentNullException("schema"); + + if (request == null) + throw new System.ArgumentNullException("request"); + + var client_ = _options.ClientProvider.Get(); + #pragma warning disable CS0219 // Variable is assigned but its value is never used + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + + var urlBuilder_ = new System.Text.StringBuilder(); + + // Operation Path: "api/apps/$app$/schemas/{schema}/indexes" + urlBuilder_.Append("api/apps/$app$/schemas/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/indexes"); + urlBuilder_.Replace("$app$", _options.AppName); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 204) + { + return; + } + else + if (status_ == 404) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new SquidexException("Schema or app not found.", status_, responseText_, headers_, null); + } + else + if (status_ == 400) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new SquidexException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new SquidexException("Validation error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new SquidexException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new SquidexException("Operation failed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + { + var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new SquidexException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + } + #pragma warning restore CS0219 // Variable is assigned but its value is never used + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Create a schema indexes. + /// + /// The name of the schema. + /// The name of the index. + /// Schema index deletion added to job queue. + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task DeleteIndexAsync(string schema, string name, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + { + if (schema == null) + throw new System.ArgumentNullException("schema"); + + if (name == null) + throw new System.ArgumentNullException("name"); + + var client_ = _options.ClientProvider.Get(); + #pragma warning disable CS0219 // Variable is assigned but its value is never used + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); + request_.Method = new System.Net.Http.HttpMethod("POST"); + + var urlBuilder_ = new System.Text.StringBuilder(); + + // Operation Path: "api/apps/$app$/schemas/{schema}/indexes/{name}" + urlBuilder_.Append("api/apps/$app$/schemas/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/indexes/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(name, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("$app$", _options.AppName); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 204) + { + return; + } + else + if (status_ == 404) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new SquidexException("Schema or app not found.", status_, responseText_, headers_, null); + } + else + if (status_ == 400) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new SquidexException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new SquidexException("Validation error.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new SquidexException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new SquidexException("Operation failed.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + { + var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new SquidexException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + } + #pragma warning restore CS0219 // Variable is assigned but its value is never used + } + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get schemas. @@ -24297,6 +24637,81 @@ public partial class UpdateFieldDto } + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.1.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class IndexesDto : Resource + { + /// + /// The indexes. + /// + [Newtonsoft.Json.JsonProperty("items", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [System.ComponentModel.DataAnnotations.Required] + public System.Collections.Generic.List Items { get; set; } = new System.Collections.Generic.List(); + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.1.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class IndexDto : Resource + { + /// + /// The name of the index. + /// + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [System.ComponentModel.DataAnnotations.Required] + public string Name { get; set; } + + /// + /// The index fields. + /// + [Newtonsoft.Json.JsonProperty("fields", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [System.ComponentModel.DataAnnotations.Required] + public System.Collections.Generic.List Fields { get; set; } = new System.Collections.Generic.List(); + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.1.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class IndexFieldDto + { + /// + /// The name of the field. + /// + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [System.ComponentModel.DataAnnotations.Required] + public string Name { get; set; } + + /// + /// The sort order of the field. + /// + [Newtonsoft.Json.JsonProperty("order", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] + public SortOrder Order { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.1.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")] + public enum SortOrder + { + + [System.Runtime.Serialization.EnumMember(Value = @"Ascending")] + Ascending = 0, + + [System.Runtime.Serialization.EnumMember(Value = @"Descending")] + Descending = 1, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.1.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class CreateIndexDto + { + /// + /// The index fields. + /// + [Newtonsoft.Json.JsonProperty("fields", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [System.ComponentModel.DataAnnotations.Required] + public System.Collections.Generic.List Fields { get; set; } = new System.Collections.Generic.List(); + + } + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.1.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")] public partial class SchemasDto : Resource {