From b47095a7fb9d020a4d83d4bba54ea51b635e56bd Mon Sep 17 00:00:00 2001 From: Morten Mertner Date: Sun, 14 Jan 2024 23:14:01 +0100 Subject: [PATCH] Nullability review for models (#332) * Nullability review for models. Mark required properties (derived from attribute annotations and code inspection) and avoid assigning default values to required props. Excluded SC1206 warnings (couldn't manage to use the required keywork with it enabled). * Correct invalid uses of ThrowIfNull helper --- .editorconfig | 24 ++++----- .../Models/AccountLimits.cs | 12 ++--- .../Models/AccountPurgeResponse.cs | 4 +- .../Models/AccountStats.cs | 12 ++--- src/NATS.Client.JetStream/Models/ApiError.cs | 6 +-- src/NATS.Client.JetStream/Models/ApiStats.cs | 4 +- .../Models/ClusterInfo.cs | 6 +-- .../Models/ConsumerConfig.cs | 48 ++++++++--------- .../Models/ConsumerCreateRequest.cs | 6 ++- .../Models/ConsumerDeleteResponse.cs | 2 +- .../Models/ConsumerGetnextRequest.cs | 6 +-- .../Models/ConsumerInfo.cs | 26 ++++++---- .../Models/ConsumerLeaderStepdownResponse.cs | 2 +- .../Models/ConsumerListResponse.cs | 2 +- .../Models/ConsumerNamesRequest.cs | 2 +- .../Models/ConsumerNamesResponse.cs | 2 +- .../Models/ExternalStreamSource.cs | 6 ++- .../Models/IterableRequest.cs | 2 +- .../Models/IterableResponse.cs | 6 +-- .../Models/LostStreamData.cs | 4 +- .../Models/MetaLeaderStepdownRequest.cs | 2 +- .../Models/MetaLeaderStepdownResponse.cs | 2 +- .../Models/MetaServerRemoveRequest.cs | 4 +- .../Models/MetaServerRemoveResponse.cs | 2 +- src/NATS.Client.JetStream/Models/PeerInfo.cs | 10 ++-- src/NATS.Client.JetStream/Models/Placement.cs | 6 ++- .../Models/PubAckResponse.cs | 10 ++-- src/NATS.Client.JetStream/Models/Republish.cs | 10 +++- .../Models/SequenceInfo.cs | 6 +-- .../Models/SequencePair.cs | 4 +- .../Models/StoredMessage.cs | 14 +++-- .../Models/StreamAlternate.cs | 10 +++- .../Models/StreamConfig.cs | 52 +++++++++---------- .../Models/StreamCreateResponse.cs | 4 -- .../Models/StreamDeleteResponse.cs | 2 +- .../Models/StreamInfo.cs | 12 ++--- .../Models/StreamInfoRequest.cs | 6 +-- .../Models/StreamInfoResponse.cs | 6 +-- .../Models/StreamLeaderStepdownResponse.cs | 2 +- .../Models/StreamListRequest.cs | 2 +- .../Models/StreamListResponse.cs | 4 +- .../Models/StreamMsgDeleteRequest.cs | 4 +- .../Models/StreamMsgDeleteResponse.cs | 2 +- .../Models/StreamMsgGetRequest.cs | 6 +-- .../Models/StreamMsgGetResponse.cs | 6 ++- .../Models/StreamNamesRequest.cs | 2 +- .../Models/StreamNamesResponse.cs | 2 +- .../Models/StreamPurgeRequest.cs | 6 +-- .../Models/StreamPurgeResponse.cs | 4 +- .../Models/StreamRemovePeerRequest.cs | 4 ++ .../Models/StreamRemovePeerResponse.cs | 2 +- .../Models/StreamRestoreResponse.cs | 4 ++ .../Models/StreamSnapshotRequest.cs | 10 ++-- .../Models/StreamSource.cs | 14 +++-- .../Models/StreamSourceInfo.cs | 14 +++-- .../Models/StreamState.cs | 24 ++++----- .../Models/StreamTemplateConfig.cs | 6 ++- .../Models/StreamTemplateDeleteResponse.cs | 2 +- .../Models/StreamTemplateInfo.cs | 8 ++- .../Models/StreamTemplateNamesResponse.cs | 2 +- .../Models/SubjectTransform.cs | 6 ++- src/NATS.Client.JetStream/Models/Tier.cs | 8 +-- .../NatsJSContext.Streams.cs | 2 + src/NATS.Client.JetStream/NatsJSException.cs | 2 +- .../NatsJSOrderedConsumer.cs | 6 ++- src/NATS.Client.JetStream/NatsJSStream.cs | 6 ++- src/NATS.Client.KeyValueStore/NatsKVStore.cs | 2 +- .../Models/ObjectMetadata.cs | 42 +++++++++------ src/NATS.Client.ObjectStore/NatsObjStore.cs | 18 ++++++- .../PublishTest.cs | 24 ++++----- .../TimeSpanJsonTests.cs | 4 +- tests/Nats.Client.Compat/ObjectStoreCompat.cs | 3 +- 72 files changed, 357 insertions(+), 240 deletions(-) diff --git a/.editorconfig b/.editorconfig index 02fc95eb9..acaace9c5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -149,7 +149,7 @@ dotnet_diagnostic.SA1202.severity = warning # Elements should be ordered by acc dotnet_diagnostic.SA1203.severity = warning # Constants should appear before fields dotnet_diagnostic.SA1204.severity = warning # Static elements should appear before instance elements dotnet_diagnostic.SA1205.severity = warning # Partial elements should declare access -dotnet_diagnostic.SA1206.severity = warning # Declaration keywords should follow order +dotnet_diagnostic.SA1206.severity = none # Declaration keywords should follow order dotnet_diagnostic.SA1207.severity = warning # Protected should come before internal dotnet_diagnostic.SA1208.severity = warning # System using directives should be placed before other using directives dotnet_diagnostic.SA1209.severity = warning # Using alias directives should be placed after other using directives @@ -311,31 +311,31 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case dotnet_naming_symbols.interface.applicable_kinds = interface dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.interface.required_modifiers = +dotnet_naming_symbols.interface.required_modifiers = dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.types.required_modifiers = +dotnet_naming_symbols.types.required_modifiers = dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.non_field_members.required_modifiers = +dotnet_naming_symbols.non_field_members.required_modifiers = # Naming styles dotnet_naming_style.begins_with_i.required_prefix = I -dotnet_naming_style.begins_with_i.required_suffix = -dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = dotnet_naming_style.begins_with_i.capitalization = pascal_case -dotnet_naming_style.pascal_case.required_prefix = -dotnet_naming_style.pascal_case.required_suffix = -dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = dotnet_naming_style.pascal_case.capitalization = pascal_case -dotnet_naming_style.pascal_case.required_prefix = -dotnet_naming_style.pascal_case.required_suffix = -dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = dotnet_naming_style.pascal_case.capitalization = pascal_case dotnet_style_coalesce_expression = true:warning dotnet_style_null_propagation = true:suggestion diff --git a/src/NATS.Client.JetStream/Models/AccountLimits.cs b/src/NATS.Client.JetStream/Models/AccountLimits.cs index aa5e69760..1dbfd6cc7 100644 --- a/src/NATS.Client.JetStream/Models/AccountLimits.cs +++ b/src/NATS.Client.JetStream/Models/AccountLimits.cs @@ -8,7 +8,7 @@ public record AccountLimits [System.Text.Json.Serialization.JsonPropertyName("max_memory")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)] - public int MaxMemory { get; set; } = default!; + public int MaxMemory { get; set; } /// /// The maximum amount of File storage Stream Messages may consume @@ -16,7 +16,7 @@ public record AccountLimits [System.Text.Json.Serialization.JsonPropertyName("max_storage")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)] - public int MaxStorage { get; set; } = default!; + public int MaxStorage { get; set; } /// /// The maximum number of Streams an account can create @@ -24,7 +24,7 @@ public record AccountLimits [System.Text.Json.Serialization.JsonPropertyName("max_streams")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)] - public int MaxStreams { get; set; } = default!; + public int MaxStreams { get; set; } /// /// The maximum number of Consumer an account can create @@ -32,21 +32,21 @@ public record AccountLimits [System.Text.Json.Serialization.JsonPropertyName("max_consumers")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)] - public int MaxConsumers { get; set; } = default!; + public int MaxConsumers { get; set; } /// /// Indicates if Streams created in this account requires the max_bytes property set /// [System.Text.Json.Serialization.JsonPropertyName("max_bytes_required")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool MaxBytesRequired { get; set; } = false; + public bool MaxBytesRequired { get; set; } /// /// The maximum number of outstanding ACKs any consumer may configure /// [System.Text.Json.Serialization.JsonPropertyName("max_ack_pending")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public int MaxAckPending { get; set; } = default!; + public int MaxAckPending { get; set; } /// /// The maximum size any single memory stream may be diff --git a/src/NATS.Client.JetStream/Models/AccountPurgeResponse.cs b/src/NATS.Client.JetStream/Models/AccountPurgeResponse.cs index 340193f24..c395e29e2 100644 --- a/src/NATS.Client.JetStream/Models/AccountPurgeResponse.cs +++ b/src/NATS.Client.JetStream/Models/AccountPurgeResponse.cs @@ -7,9 +7,9 @@ namespace NATS.Client.JetStream.Models; public record AccountPurgeResponse { /// - /// If the purge operation was succesfully started + /// If the purge operation was successfully started /// [System.Text.Json.Serialization.JsonPropertyName("initiated")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool Initiated { get; set; } = false; + public bool Initiated { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/AccountStats.cs b/src/NATS.Client.JetStream/Models/AccountStats.cs index 0c4c9d1b1..cdb1ff39c 100644 --- a/src/NATS.Client.JetStream/Models/AccountStats.cs +++ b/src/NATS.Client.JetStream/Models/AccountStats.cs @@ -8,7 +8,7 @@ public record AccountStats [System.Text.Json.Serialization.JsonPropertyName("memory")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Memory { get; set; } = default!; + public int Memory { get; set; } /// /// File Storage being used for Stream Message storage @@ -16,7 +16,7 @@ public record AccountStats [System.Text.Json.Serialization.JsonPropertyName("storage")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Storage { get; set; } = default!; + public int Storage { get; set; } /// /// Number of active Streams @@ -24,7 +24,7 @@ public record AccountStats [System.Text.Json.Serialization.JsonPropertyName("streams")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Streams { get; set; } = default!; + public int Streams { get; set; } /// /// Number of active Consumers @@ -32,14 +32,14 @@ public record AccountStats [System.Text.Json.Serialization.JsonPropertyName("consumers")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Consumers { get; set; } = default!; + public int Consumers { get; set; } /// /// The JetStream domain this account is in /// [System.Text.Json.Serialization.JsonPropertyName("domain")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string Domain { get; set; } = default!; + public string? Domain { get; set; } [System.Text.Json.Serialization.JsonPropertyName("limits")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] @@ -48,7 +48,7 @@ public record AccountStats [System.Text.Json.Serialization.JsonPropertyName("tiers")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.IDictionary Tiers { get; set; } = default!; + public IDictionary? Tiers { get; set; } [System.Text.Json.Serialization.JsonPropertyName("api")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] diff --git a/src/NATS.Client.JetStream/Models/ApiError.cs b/src/NATS.Client.JetStream/Models/ApiError.cs index d2815051f..3023ce355 100644 --- a/src/NATS.Client.JetStream/Models/ApiError.cs +++ b/src/NATS.Client.JetStream/Models/ApiError.cs @@ -8,14 +8,14 @@ public record ApiError [System.Text.Json.Serialization.JsonPropertyName("code")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(300, 699)] - public int Code { get; set; } = default!; + public int Code { get; set; } /// /// A human friendly description of the error /// [System.Text.Json.Serialization.JsonPropertyName("description")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string Description { get; set; } = default!; + public string? Description { get; set; } /// /// The NATS error code unique to each kind of error @@ -23,5 +23,5 @@ public record ApiError [System.Text.Json.Serialization.JsonPropertyName("err_code")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0, 65535)] - public int ErrCode { get; set; } = default!; + public int ErrCode { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/ApiStats.cs b/src/NATS.Client.JetStream/Models/ApiStats.cs index ed7b6e480..261272e91 100644 --- a/src/NATS.Client.JetStream/Models/ApiStats.cs +++ b/src/NATS.Client.JetStream/Models/ApiStats.cs @@ -8,7 +8,7 @@ public record ApiStats [System.Text.Json.Serialization.JsonPropertyName("total")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Total { get; set; } = default!; + public int Total { get; set; } /// /// API requests that resulted in an error response @@ -16,5 +16,5 @@ public record ApiStats [System.Text.Json.Serialization.JsonPropertyName("errors")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Errors { get; set; } = default!; + public int Errors { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/ClusterInfo.cs b/src/NATS.Client.JetStream/Models/ClusterInfo.cs index ba6244f4f..f35ed7ad1 100644 --- a/src/NATS.Client.JetStream/Models/ClusterInfo.cs +++ b/src/NATS.Client.JetStream/Models/ClusterInfo.cs @@ -7,19 +7,19 @@ public record ClusterInfo /// [System.Text.Json.Serialization.JsonPropertyName("name")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string Name { get; set; } = default!; + public string? Name { get; set; } /// /// The server name of the RAFT leader /// [System.Text.Json.Serialization.JsonPropertyName("leader")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string Leader { get; set; } = default!; + public string? Leader { get; set; } /// /// The members of the RAFT cluster /// [System.Text.Json.Serialization.JsonPropertyName("replicas")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection Replicas { get; set; } = default!; + public ICollection? Replicas { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/ConsumerConfig.cs b/src/NATS.Client.JetStream/Models/ConsumerConfig.cs index 4b1cdb9d8..86cccaa7a 100644 --- a/src/NATS.Client.JetStream/Models/ConsumerConfig.cs +++ b/src/NATS.Client.JetStream/Models/ConsumerConfig.cs @@ -38,16 +38,16 @@ public ConsumerConfig(string name) #if NET6_0 [System.Text.Json.Serialization.JsonConverter(typeof(NatsJSJsonStringEnumConverter))] #endif - public ConsumerConfigDeliverPolicy DeliverPolicy { get; set; } = default!; + public ConsumerConfigDeliverPolicy DeliverPolicy { get; set; } = ConsumerConfigDeliverPolicy.All; [System.Text.Json.Serialization.JsonPropertyName("opt_start_seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public ulong OptStartSeq { get; set; } = default!; + public ulong OptStartSeq { get; set; } [System.Text.Json.Serialization.JsonPropertyName("opt_start_time")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.DateTimeOffset OptStartTime { get; set; } = default!; + public DateTimeOffset OptStartTime { get; set; } /// /// A unique name for a durable consumer @@ -56,7 +56,7 @@ public ConsumerConfig(string name) [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.StringLength(int.MaxValue, MinimumLength = 1)] [System.ComponentModel.DataAnnotations.RegularExpression(@"^[^.*>]+$")] - public string DurableName { get; set; } = default!; + public string? DurableName { get; set; } /// /// A unique name for a consumer @@ -65,7 +65,7 @@ public ConsumerConfig(string name) [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.StringLength(int.MaxValue, MinimumLength = 1)] [System.ComponentModel.DataAnnotations.RegularExpression(@"^[^.*>]+$")] - public string Name { get; set; } = default!; + public string? Name { get; set; } /// /// A short description of the purpose of this consumer @@ -73,12 +73,12 @@ public ConsumerConfig(string name) [System.Text.Json.Serialization.JsonPropertyName("description")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.StringLength(4096)] - public string Description { get; set; } = default!; + public string? Description { get; set; } [System.Text.Json.Serialization.JsonPropertyName("deliver_subject")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.StringLength(int.MaxValue, MinimumLength = 1)] - public string DeliverSubject { get; set; } = default!; + public string? DeliverSubject { get; set; } [System.Text.Json.Serialization.JsonPropertyName("ack_policy")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] @@ -102,21 +102,21 @@ public ConsumerConfig(string name) [System.Text.Json.Serialization.JsonPropertyName("max_deliver")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long MaxDeliver { get; set; } = default!; + public long MaxDeliver { get; set; } /// /// Filter the stream by a single subjects /// [System.Text.Json.Serialization.JsonPropertyName("filter_subject")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string FilterSubject { get; set; } = default!; + public string? FilterSubject { get; set; } /// /// Filter the stream by multiple subjects /// [System.Text.Json.Serialization.JsonPropertyName("filter_subjects")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection FilterSubjects { get; set; } = default!; + public ICollection? FilterSubjects { get; set; } [System.Text.Json.Serialization.JsonPropertyName("replay_policy")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] @@ -124,11 +124,11 @@ public ConsumerConfig(string name) #if NET6_0 [System.Text.Json.Serialization.JsonConverter(typeof(NatsJSJsonStringEnumConverter))] #endif - public ConsumerConfigReplayPolicy ReplayPolicy { get; set; } = NATS.Client.JetStream.Models.ConsumerConfigReplayPolicy.Instant; + public ConsumerConfigReplayPolicy ReplayPolicy { get; set; } = ConsumerConfigReplayPolicy.Instant; [System.Text.Json.Serialization.JsonPropertyName("sample_freq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string SampleFreq { get; set; } = default!; + public string? SampleFreq { get; set; } /// /// The rate at which messages will be delivered to clients, expressed in bit per second @@ -136,7 +136,7 @@ public ConsumerConfig(string name) [System.Text.Json.Serialization.JsonPropertyName("rate_limit_bps")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long RateLimitBps { get; set; } = default!; + public long RateLimitBps { get; set; } /// /// The maximum number of messages without acknowledgement that can be outstanding, once this limit is reached message delivery will be suspended @@ -144,7 +144,7 @@ public ConsumerConfig(string name) [System.Text.Json.Serialization.JsonPropertyName("max_ack_pending")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long MaxAckPending { get; set; } = default!; + public long MaxAckPending { get; set; } /// /// If the Consumer is idle for more than this many nano seconds a empty message with Status header 100 will be sent indicating the consumer is still alive @@ -159,7 +159,7 @@ public ConsumerConfig(string name) /// [System.Text.Json.Serialization.JsonPropertyName("flow_control")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool FlowControl { get; set; } = default!; + public bool FlowControl { get; set; } /// /// The number of pulls that can be outstanding on a pull consumer, pulls received after this is reached are ignored @@ -167,28 +167,28 @@ public ConsumerConfig(string name) [System.Text.Json.Serialization.JsonPropertyName("max_waiting")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long MaxWaiting { get; set; } = default!; + public long MaxWaiting { get; set; } /// /// Creates a special consumer that does not touch the Raft layers, not for general use by clients, internal use only /// [System.Text.Json.Serialization.JsonPropertyName("direct")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool Direct { get; set; } = false; + public bool Direct { get; set; } /// /// Delivers only the headers of messages in the stream and not the bodies. Additionally adds Nats-Msg-Size header to indicate the size of the removed payload /// [System.Text.Json.Serialization.JsonPropertyName("headers_only")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool HeadersOnly { get; set; } = false; + public bool HeadersOnly { get; set; } /// /// The largest batch property that may be specified when doing a pull on a Pull Consumer /// [System.Text.Json.Serialization.JsonPropertyName("max_batch")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public int MaxBatch { get; set; } = 0; + public int MaxBatch { get; set; } /// /// The maximum expires value that may be set when doing a pull on a Pull Consumer @@ -204,7 +204,7 @@ public ConsumerConfig(string name) [System.Text.Json.Serialization.JsonPropertyName("max_bytes")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long MaxBytes { get; set; } = default!; + public long MaxBytes { get; set; } /// /// Duration that instructs the server to cleanup ephemeral consumers that are inactive for that long @@ -219,7 +219,7 @@ public ConsumerConfig(string name) /// [System.Text.Json.Serialization.JsonPropertyName("backoff")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection Backoff { get; set; } = default!; + public ICollection? Backoff { get; set; } /// /// When set do not inherit the replica count from the stream but specifically set it to this amount @@ -227,19 +227,19 @@ public ConsumerConfig(string name) [System.Text.Json.Serialization.JsonPropertyName("num_replicas")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long NumReplicas { get; set; } = default!; + public long NumReplicas { get; set; } /// /// Force the consumer state to be kept in memory rather than inherit the setting from the stream /// [System.Text.Json.Serialization.JsonPropertyName("mem_storage")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool MemStorage { get; set; } = false; + public bool MemStorage { get; set; } /// /// Additional metadata for the Consumer /// [System.Text.Json.Serialization.JsonPropertyName("metadata")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.IDictionary Metadata { get; set; } = default!; + public IDictionary? Metadata { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/ConsumerCreateRequest.cs b/src/NATS.Client.JetStream/Models/ConsumerCreateRequest.cs index b610a1a3d..6ac435f79 100644 --- a/src/NATS.Client.JetStream/Models/ConsumerCreateRequest.cs +++ b/src/NATS.Client.JetStream/Models/ConsumerCreateRequest.cs @@ -12,12 +12,16 @@ internal record ConsumerCreateRequest [System.Text.Json.Serialization.JsonPropertyName("stream_name")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string StreamName { get; set; } = default!; +#else + public required string StreamName { get; set; } +#endif /// /// The consumer configuration /// [System.Text.Json.Serialization.JsonPropertyName("config")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public ConsumerConfig Config { get; set; } = default!; + public ConsumerConfig? Config { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/ConsumerDeleteResponse.cs b/src/NATS.Client.JetStream/Models/ConsumerDeleteResponse.cs index 067c0b0f0..2aa60a896 100644 --- a/src/NATS.Client.JetStream/Models/ConsumerDeleteResponse.cs +++ b/src/NATS.Client.JetStream/Models/ConsumerDeleteResponse.cs @@ -8,5 +8,5 @@ public record ConsumerDeleteResponse { [System.Text.Json.Serialization.JsonPropertyName("success")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public bool Success { get; set; } = default!; + public bool Success { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/ConsumerGetnextRequest.cs b/src/NATS.Client.JetStream/Models/ConsumerGetnextRequest.cs index 915581522..574c4a718 100644 --- a/src/NATS.Client.JetStream/Models/ConsumerGetnextRequest.cs +++ b/src/NATS.Client.JetStream/Models/ConsumerGetnextRequest.cs @@ -22,7 +22,7 @@ public record ConsumerGetnextRequest [System.Text.Json.Serialization.JsonPropertyName("batch")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long Batch { get; set; } = default!; + public long Batch { get; set; } /// /// Sends at most this many bytes to the requestor, limited by consumer configuration max_bytes @@ -30,14 +30,14 @@ public record ConsumerGetnextRequest [System.Text.Json.Serialization.JsonPropertyName("max_bytes")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long MaxBytes { get; set; } = default!; + public long MaxBytes { get; set; } /// /// When true a response with a 404 status header will be returned when no messages are available /// [System.Text.Json.Serialization.JsonPropertyName("no_wait")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool NoWait { get; set; } = default!; + public bool NoWait { get; set; } /// /// When not 0 idle heartbeats will be sent on this interval diff --git a/src/NATS.Client.JetStream/Models/ConsumerInfo.cs b/src/NATS.Client.JetStream/Models/ConsumerInfo.cs index a4170d133..46cc1cd7c 100644 --- a/src/NATS.Client.JetStream/Models/ConsumerInfo.cs +++ b/src/NATS.Client.JetStream/Models/ConsumerInfo.cs @@ -8,7 +8,11 @@ public record ConsumerInfo [System.Text.Json.Serialization.JsonPropertyName("stream_name")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string StreamName { get; set; } = default!; +#else + public required string StreamName { get; set; } +#endif /// /// A unique name for the consumer, either machine generated or the durable name @@ -16,18 +20,22 @@ public record ConsumerInfo [System.Text.Json.Serialization.JsonPropertyName("name")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string Name { get; set; } = default!; +#else + public required string Name { get; set; } +#endif /// /// The server time the consumer info was created /// [System.Text.Json.Serialization.JsonPropertyName("ts")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.DateTimeOffset Ts { get; set; } = default!; + public DateTimeOffset Ts { get; set; } [System.Text.Json.Serialization.JsonPropertyName("config")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public ConsumerConfig Config { get; set; } = default!; + public ConsumerConfig Config { get; set; } = new ConsumerConfig(); /// /// The time the Consumer was created @@ -35,7 +43,7 @@ public record ConsumerInfo [System.Text.Json.Serialization.JsonPropertyName("created")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] - public System.DateTimeOffset Created { get; set; } = default!; + public DateTimeOffset Created { get; set; } /// /// The last message delivered from this Consumer @@ -59,7 +67,7 @@ public record ConsumerInfo [System.Text.Json.Serialization.JsonPropertyName("num_ack_pending")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long NumAckPending { get; set; } = default!; + public long NumAckPending { get; set; } /// /// The number of redeliveries that have been performed @@ -67,7 +75,7 @@ public record ConsumerInfo [System.Text.Json.Serialization.JsonPropertyName("num_redelivered")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long NumRedelivered { get; set; } = default!; + public long NumRedelivered { get; set; } /// /// The number of pull consumers waiting for messages @@ -75,7 +83,7 @@ public record ConsumerInfo [System.Text.Json.Serialization.JsonPropertyName("num_waiting")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long NumWaiting { get; set; } = default!; + public long NumWaiting { get; set; } /// /// The number of messages left unconsumed in this Consumer @@ -83,16 +91,16 @@ public record ConsumerInfo [System.Text.Json.Serialization.JsonPropertyName("num_pending")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long NumPending { get; set; } = default!; + public long NumPending { get; set; } [System.Text.Json.Serialization.JsonPropertyName("cluster")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public ClusterInfo Cluster { get; set; } = default!; + public ClusterInfo? Cluster { get; set; } /// /// Indicates if any client is connected and receiving messages from a push consumer /// [System.Text.Json.Serialization.JsonPropertyName("push_bound")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool PushBound { get; set; } = default!; + public bool PushBound { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/ConsumerLeaderStepdownResponse.cs b/src/NATS.Client.JetStream/Models/ConsumerLeaderStepdownResponse.cs index dbd0aa4f5..dc6f044b4 100644 --- a/src/NATS.Client.JetStream/Models/ConsumerLeaderStepdownResponse.cs +++ b/src/NATS.Client.JetStream/Models/ConsumerLeaderStepdownResponse.cs @@ -11,5 +11,5 @@ public record ConsumerLeaderStepdownResponse /// [System.Text.Json.Serialization.JsonPropertyName("success")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public bool Success { get; set; } = false; + public bool Success { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/ConsumerListResponse.cs b/src/NATS.Client.JetStream/Models/ConsumerListResponse.cs index 7261e3bd7..7a64e829a 100644 --- a/src/NATS.Client.JetStream/Models/ConsumerListResponse.cs +++ b/src/NATS.Client.JetStream/Models/ConsumerListResponse.cs @@ -12,5 +12,5 @@ public record ConsumerListResponse : IterableResponse [System.Text.Json.Serialization.JsonPropertyName("consumers")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required] - public System.Collections.Generic.ICollection Consumers { get; set; } = new System.Collections.ObjectModel.Collection(); + public ICollection Consumers { get; set; } = new System.Collections.ObjectModel.Collection(); } diff --git a/src/NATS.Client.JetStream/Models/ConsumerNamesRequest.cs b/src/NATS.Client.JetStream/Models/ConsumerNamesRequest.cs index 07ca351dc..3744a5970 100644 --- a/src/NATS.Client.JetStream/Models/ConsumerNamesRequest.cs +++ b/src/NATS.Client.JetStream/Models/ConsumerNamesRequest.cs @@ -11,5 +11,5 @@ public record ConsumerNamesRequest : IterableRequest /// [System.Text.Json.Serialization.JsonPropertyName("subject")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string Subject { get; set; } = default!; + public string? Subject { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/ConsumerNamesResponse.cs b/src/NATS.Client.JetStream/Models/ConsumerNamesResponse.cs index 70beb4ac2..803a645ad 100644 --- a/src/NATS.Client.JetStream/Models/ConsumerNamesResponse.cs +++ b/src/NATS.Client.JetStream/Models/ConsumerNamesResponse.cs @@ -9,5 +9,5 @@ public record ConsumerNamesResponse : IterableResponse [System.Text.Json.Serialization.JsonPropertyName("consumers")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required] - public System.Collections.Generic.ICollection Consumers { get; set; } = new System.Collections.ObjectModel.Collection(); + public ICollection Consumers { get; set; } = new System.Collections.ObjectModel.Collection(); } diff --git a/src/NATS.Client.JetStream/Models/ExternalStreamSource.cs b/src/NATS.Client.JetStream/Models/ExternalStreamSource.cs index 62b94ddf2..0898ab641 100644 --- a/src/NATS.Client.JetStream/Models/ExternalStreamSource.cs +++ b/src/NATS.Client.JetStream/Models/ExternalStreamSource.cs @@ -12,12 +12,16 @@ public record ExternalStreamSource [System.Text.Json.Serialization.JsonPropertyName("api")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string Api { get; set; } = default!; +#else + public required string Api { get; set; } +#endif /// /// The delivery subject to use for the push consumer /// [System.Text.Json.Serialization.JsonPropertyName("deliver")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string Deliver { get; set; } = default!; + public string? Deliver { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/IterableRequest.cs b/src/NATS.Client.JetStream/Models/IterableRequest.cs index 3e8296388..621f04f47 100644 --- a/src/NATS.Client.JetStream/Models/IterableRequest.cs +++ b/src/NATS.Client.JetStream/Models/IterableRequest.cs @@ -5,5 +5,5 @@ public record IterableRequest [System.Text.Json.Serialization.JsonPropertyName("offset")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Offset { get; set; } = default!; + public int Offset { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/IterableResponse.cs b/src/NATS.Client.JetStream/Models/IterableResponse.cs index ef2c3f660..da8b10f0c 100644 --- a/src/NATS.Client.JetStream/Models/IterableResponse.cs +++ b/src/NATS.Client.JetStream/Models/IterableResponse.cs @@ -5,15 +5,15 @@ public record IterableResponse [System.Text.Json.Serialization.JsonPropertyName("total")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Total { get; set; } = default!; + public int Total { get; set; } [System.Text.Json.Serialization.JsonPropertyName("offset")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Offset { get; set; } = default!; + public int Offset { get; set; } [System.Text.Json.Serialization.JsonPropertyName("limit")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Limit { get; set; } = default!; + public int Limit { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/LostStreamData.cs b/src/NATS.Client.JetStream/Models/LostStreamData.cs index af4910452..ce113d8bb 100644 --- a/src/NATS.Client.JetStream/Models/LostStreamData.cs +++ b/src/NATS.Client.JetStream/Models/LostStreamData.cs @@ -11,7 +11,7 @@ public record LostStreamData /// [System.Text.Json.Serialization.JsonPropertyName("msgs")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection? Msgs { get; set; } = default!; + public ICollection? Msgs { get; set; } /// /// The number of bytes that were lost @@ -19,5 +19,5 @@ public record LostStreamData [System.Text.Json.Serialization.JsonPropertyName("bytes")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long Bytes { get; set; } = default!; + public long Bytes { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/MetaLeaderStepdownRequest.cs b/src/NATS.Client.JetStream/Models/MetaLeaderStepdownRequest.cs index 6a0bbc7b5..74d648f71 100644 --- a/src/NATS.Client.JetStream/Models/MetaLeaderStepdownRequest.cs +++ b/src/NATS.Client.JetStream/Models/MetaLeaderStepdownRequest.cs @@ -8,5 +8,5 @@ public record MetaLeaderStepdownRequest { [System.Text.Json.Serialization.JsonPropertyName("placement")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public Placement Placement { get; set; } = default!; + public Placement? Placement { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/MetaLeaderStepdownResponse.cs b/src/NATS.Client.JetStream/Models/MetaLeaderStepdownResponse.cs index ca795219e..5fc206609 100644 --- a/src/NATS.Client.JetStream/Models/MetaLeaderStepdownResponse.cs +++ b/src/NATS.Client.JetStream/Models/MetaLeaderStepdownResponse.cs @@ -11,5 +11,5 @@ public record MetaLeaderStepdownResponse /// [System.Text.Json.Serialization.JsonPropertyName("success")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public bool Success { get; set; } = false; + public bool Success { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/MetaServerRemoveRequest.cs b/src/NATS.Client.JetStream/Models/MetaServerRemoveRequest.cs index a61acd89c..001984134 100644 --- a/src/NATS.Client.JetStream/Models/MetaServerRemoveRequest.cs +++ b/src/NATS.Client.JetStream/Models/MetaServerRemoveRequest.cs @@ -11,12 +11,12 @@ public record MetaServerRemoveRequest /// [System.Text.Json.Serialization.JsonPropertyName("peer")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string Peer { get; set; } = default!; + public string? Peer { get; set; } /// /// Peer ID of the peer to be removed. If specified this is used instead of the server name /// [System.Text.Json.Serialization.JsonPropertyName("peer_id")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string PeerId { get; set; } = default!; + public string? PeerId { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/MetaServerRemoveResponse.cs b/src/NATS.Client.JetStream/Models/MetaServerRemoveResponse.cs index ca176a4f4..b853bbea6 100644 --- a/src/NATS.Client.JetStream/Models/MetaServerRemoveResponse.cs +++ b/src/NATS.Client.JetStream/Models/MetaServerRemoveResponse.cs @@ -11,5 +11,5 @@ public record MetaServerRemoveResponse /// [System.Text.Json.Serialization.JsonPropertyName("success")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public bool Success { get; set; } = false; + public bool Success { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/PeerInfo.cs b/src/NATS.Client.JetStream/Models/PeerInfo.cs index 95aa90b0e..ce774063a 100644 --- a/src/NATS.Client.JetStream/Models/PeerInfo.cs +++ b/src/NATS.Client.JetStream/Models/PeerInfo.cs @@ -10,14 +10,18 @@ public record PeerInfo [System.Text.Json.Serialization.JsonPropertyName("name")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string Name { get; set; } = default!; +#else + public required string Name { get; set; } +#endif /// /// Indicates if the server is up to date and synchronised /// [System.Text.Json.Serialization.JsonPropertyName("current")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public bool Current { get; set; } = false; + public bool Current { get; set; } /// /// Nanoseconds since this peer was last seen @@ -32,7 +36,7 @@ public record PeerInfo /// [System.Text.Json.Serialization.JsonPropertyName("offline")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool Offline { get; set; } = false; + public bool Offline { get; set; } /// /// How many uncommitted operations this peer is behind the leader @@ -40,5 +44,5 @@ public record PeerInfo [System.Text.Json.Serialization.JsonPropertyName("lag")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Lag { get; set; } = default!; + public int Lag { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/Placement.cs b/src/NATS.Client.JetStream/Models/Placement.cs index 6ce0f3d9e..dc4829887 100644 --- a/src/NATS.Client.JetStream/Models/Placement.cs +++ b/src/NATS.Client.JetStream/Models/Placement.cs @@ -12,12 +12,16 @@ public record Placement [System.Text.Json.Serialization.JsonPropertyName("cluster")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string Cluster { get; set; } = default!; +#else + public required string Cluster { get; set; } +#endif /// /// Tags required on servers hosting this stream /// [System.Text.Json.Serialization.JsonPropertyName("tags")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection Tags { get; set; } = default!; + public ICollection? Tags { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/PubAckResponse.cs b/src/NATS.Client.JetStream/Models/PubAckResponse.cs index 97d4aab5a..24d837352 100644 --- a/src/NATS.Client.JetStream/Models/PubAckResponse.cs +++ b/src/NATS.Client.JetStream/Models/PubAckResponse.cs @@ -8,7 +8,7 @@ public record PubAckResponse { [System.Text.Json.Serialization.JsonPropertyName("error")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public ApiError Error { get; set; } = default!; + public ApiError? Error { get; set; } /// /// The name of the stream that received the message @@ -16,7 +16,7 @@ public record PubAckResponse [System.Text.Json.Serialization.JsonPropertyName("stream")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required] - public string Stream { get; set; } = default!; + public string? Stream { get; set; } /// /// If successful this will be the sequence the message is stored at @@ -24,19 +24,19 @@ public record PubAckResponse [System.Text.Json.Serialization.JsonPropertyName("seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public ulong Seq { get; set; } = default!; + public ulong Seq { get; set; } /// /// Indicates that the message was not stored due to the Nats-Msg-Id header and duplicate tracking /// [System.Text.Json.Serialization.JsonPropertyName("duplicate")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool Duplicate { get; set; } = false; + public bool Duplicate { get; set; } /// /// If the Stream accepting the message is in a JetStream server configured for a domain this would be that domain /// [System.Text.Json.Serialization.JsonPropertyName("domain")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string Domain { get; set; } = default!; + public string? Domain { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/Republish.cs b/src/NATS.Client.JetStream/Models/Republish.cs index 53276e08e..543669250 100644 --- a/src/NATS.Client.JetStream/Models/Republish.cs +++ b/src/NATS.Client.JetStream/Models/Republish.cs @@ -12,7 +12,11 @@ public record Republish [System.Text.Json.Serialization.JsonPropertyName("src")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string Src { get; set; } = default!; +#else + public required string Src { get; set; } +#endif /// /// The destination to publish to @@ -20,12 +24,16 @@ public record Republish [System.Text.Json.Serialization.JsonPropertyName("dest")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string Dest { get; set; } = default!; +#else + public required string Dest { get; set; } +#endif /// /// Only send message headers, no bodies /// [System.Text.Json.Serialization.JsonPropertyName("headers_only")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool HeadersOnly { get; set; } = false; + public bool HeadersOnly { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/SequenceInfo.cs b/src/NATS.Client.JetStream/Models/SequenceInfo.cs index 08f0e01f8..e19685892 100644 --- a/src/NATS.Client.JetStream/Models/SequenceInfo.cs +++ b/src/NATS.Client.JetStream/Models/SequenceInfo.cs @@ -8,7 +8,7 @@ public record SequenceInfo [System.Text.Json.Serialization.JsonPropertyName("consumer_seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long ConsumerSeq { get; set; } = default!; + public long ConsumerSeq { get; set; } /// /// The sequence number of the Stream @@ -16,12 +16,12 @@ public record SequenceInfo [System.Text.Json.Serialization.JsonPropertyName("stream_seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long StreamSeq { get; set; } = default!; + public long StreamSeq { get; set; } /// /// The last time a message was delivered or acknowledged (for ack_floor) /// [System.Text.Json.Serialization.JsonPropertyName("last_active")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.DateTimeOffset LastActive { get; set; } = default!; + public DateTimeOffset LastActive { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/SequencePair.cs b/src/NATS.Client.JetStream/Models/SequencePair.cs index 8e25ad615..76132b66e 100644 --- a/src/NATS.Client.JetStream/Models/SequencePair.cs +++ b/src/NATS.Client.JetStream/Models/SequencePair.cs @@ -8,7 +8,7 @@ public record SequencePair [System.Text.Json.Serialization.JsonPropertyName("consumer_seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long ConsumerSeq { get; set; } = default!; + public long ConsumerSeq { get; set; } /// /// The sequence number of the Stream @@ -16,5 +16,5 @@ public record SequencePair [System.Text.Json.Serialization.JsonPropertyName("stream_seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long StreamSeq { get; set; } = default!; + public long StreamSeq { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StoredMessage.cs b/src/NATS.Client.JetStream/Models/StoredMessage.cs index 132091a16..f44447dd2 100644 --- a/src/NATS.Client.JetStream/Models/StoredMessage.cs +++ b/src/NATS.Client.JetStream/Models/StoredMessage.cs @@ -8,7 +8,11 @@ public record StoredMessage [System.Text.Json.Serialization.JsonPropertyName("subject")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required] +#if NET6_0 public string Subject { get; set; } = default!; +#else + public required string Subject { get; set; } +#endif /// /// The sequence number of the message in the Stream @@ -16,7 +20,7 @@ public record StoredMessage [System.Text.Json.Serialization.JsonPropertyName("seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public ulong Seq { get; set; } = default!; + public ulong Seq { get; set; } /// /// The base64 encoded payload of the message body @@ -24,7 +28,7 @@ public record StoredMessage [System.Text.Json.Serialization.JsonPropertyName("data")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.StringLength(int.MaxValue)] - public string Data { get; set; } = default!; + public string? Data { get; set; } /// /// The time the message was received @@ -32,12 +36,16 @@ public record StoredMessage [System.Text.Json.Serialization.JsonPropertyName("time")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string Time { get; set; } = default!; +#else + public required string Time { get; set; } +#endif /// /// Base64 encoded headers for the message /// [System.Text.Json.Serialization.JsonPropertyName("hdrs")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string Hdrs { get; set; } = default!; + public string? Hdrs { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamAlternate.cs b/src/NATS.Client.JetStream/Models/StreamAlternate.cs index 5e9698e1b..6806b1a67 100644 --- a/src/NATS.Client.JetStream/Models/StreamAlternate.cs +++ b/src/NATS.Client.JetStream/Models/StreamAlternate.cs @@ -12,7 +12,11 @@ public record StreamAlternate [System.Text.Json.Serialization.JsonPropertyName("name")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string Name { get; set; } = default!; +#else + public required string Name { get; set; } +#endif /// /// The name of the cluster holding the stream @@ -20,12 +24,16 @@ public record StreamAlternate [System.Text.Json.Serialization.JsonPropertyName("cluster")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string Cluster { get; set; } = default!; +#else + public required string Cluster { get; set; } +#endif /// /// The domain holding the string /// [System.Text.Json.Serialization.JsonPropertyName("domain")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string Domain { get; set; } = default!; + public string? Domain { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamConfig.cs b/src/NATS.Client.JetStream/Models/StreamConfig.cs index 1794655fb..1619b27e1 100644 --- a/src/NATS.Client.JetStream/Models/StreamConfig.cs +++ b/src/NATS.Client.JetStream/Models/StreamConfig.cs @@ -21,7 +21,7 @@ public StreamConfig(string name, ICollection subjects) [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.StringLength(int.MaxValue)] [System.ComponentModel.DataAnnotations.RegularExpression(@"^[^.*>]*$")] - public string Name { get; set; } = default!; + public string? Name { get; set; } /// /// A short description of the purpose of this stream @@ -29,21 +29,21 @@ public StreamConfig(string name, ICollection subjects) [System.Text.Json.Serialization.JsonPropertyName("description")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.StringLength(4096)] - public string Description { get; set; } = default!; + public string? Description { get; set; } /// /// A list of subjects to consume, supports wildcards. Must be empty when a mirror is configured. May be empty when sources are configured. /// [System.Text.Json.Serialization.JsonPropertyName("subjects")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection Subjects { get; set; } = default!; + public ICollection? Subjects { get; set; } /// /// Subject transform to apply to matching messages /// [System.Text.Json.Serialization.JsonPropertyName("subject_transform")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public SubjectTransform SubjectTransform { get; set; } = default!; + public SubjectTransform? SubjectTransform { get; set; } /// /// How messages are retained in the Stream, once this is exceeded old messages are removed. @@ -54,7 +54,7 @@ public StreamConfig(string name, ICollection subjects) #if NET6_0 [System.Text.Json.Serialization.JsonConverter(typeof(NatsJSJsonStringEnumConverter))] #endif - public StreamConfigRetention Retention { get; set; } = NATS.Client.JetStream.Models.StreamConfigRetention.Limits; + public StreamConfigRetention Retention { get; set; } = StreamConfigRetention.Limits; /// /// How many Consumers can be defined for a given Stream. -1 for unlimited. @@ -62,7 +62,7 @@ public StreamConfig(string name, ICollection subjects) [System.Text.Json.Serialization.JsonPropertyName("max_consumers")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long MaxConsumers { get; set; } = default!; + public long MaxConsumers { get; set; } /// /// How many messages may be in a Stream, oldest messages will be removed if the Stream exceeds this size. -1 for unlimited. @@ -70,7 +70,7 @@ public StreamConfig(string name, ICollection subjects) [System.Text.Json.Serialization.JsonPropertyName("max_msgs")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long MaxMsgs { get; set; } = default!; + public long MaxMsgs { get; set; } /// /// For wildcard streams ensure that for every unique subject this many messages are kept - a per subject retention limit @@ -78,7 +78,7 @@ public StreamConfig(string name, ICollection subjects) [System.Text.Json.Serialization.JsonPropertyName("max_msgs_per_subject")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long MaxMsgsPerSubject { get; set; } = default!; + public long MaxMsgsPerSubject { get; set; } /// /// How big the Stream may be, when the combined stream size exceeds this old messages are removed. -1 for unlimited. @@ -86,7 +86,7 @@ public StreamConfig(string name, ICollection subjects) [System.Text.Json.Serialization.JsonPropertyName("max_bytes")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long MaxBytes { get; set; } = default!; + public long MaxBytes { get; set; } /// /// Maximum age of any message in the stream, expressed in nanoseconds. 0 for unlimited. @@ -102,7 +102,7 @@ public StreamConfig(string name, ICollection subjects) [System.Text.Json.Serialization.JsonPropertyName("max_msg_size")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(-2147483648, 2147483647)] - public int MaxMsgSize { get; set; } = default!; + public int MaxMsgSize { get; set; } /// /// The storage backend to use for the Stream. @@ -123,7 +123,7 @@ public StreamConfig(string name, ICollection subjects) #if NET6_0 [System.Text.Json.Serialization.JsonConverter(typeof(NatsJSJsonStringEnumConverter))] #endif - public StreamConfigCompression Compression { get; set; } = NATS.Client.JetStream.Models.StreamConfigCompression.None; + public StreamConfigCompression Compression { get; set; } = StreamConfigCompression.None; /// /// How many replicas to keep for each message. @@ -131,21 +131,21 @@ public StreamConfig(string name, ICollection subjects) [System.Text.Json.Serialization.JsonPropertyName("num_replicas")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long NumReplicas { get; set; } = default!; + public long NumReplicas { get; set; } /// /// Disables acknowledging messages that are received by the Stream. /// [System.Text.Json.Serialization.JsonPropertyName("no_ack")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool NoAck { get; set; } = false; + public bool NoAck { get; set; } /// /// When the Stream is managed by a Stream Template this identifies the template that manages the Stream. /// [System.Text.Json.Serialization.JsonPropertyName("template_owner")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string TemplateOwner { get; set; } = default!; + public string? TemplateOwner { get; set; } /// /// When a Stream reach it's limits either old messages are deleted or new ones are denied @@ -170,79 +170,79 @@ public StreamConfig(string name, ICollection subjects) /// [System.Text.Json.Serialization.JsonPropertyName("placement")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public Placement Placement { get; set; } = default!; + public Placement? Placement { get; set; } /// /// Maintains a 1:1 mirror of another stream with name matching this property. When a mirror is configured subjects and sources must be empty. /// [System.Text.Json.Serialization.JsonPropertyName("mirror")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public StreamSource Mirror { get; set; } = default!; + public StreamSource? Mirror { get; set; } /// /// List of Stream names to replicate into this Stream /// [System.Text.Json.Serialization.JsonPropertyName("sources")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection Sources { get; set; } = default!; + public ICollection? Sources { get; set; } /// /// Sealed streams do not allow messages to be deleted via limits or API, sealed streams can not be unsealed via configuration update. Can only be set on already created streams via the Update API /// [System.Text.Json.Serialization.JsonPropertyName("sealed")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool Sealed { get; set; } = false; + public bool Sealed { get; set; } /// /// Restricts the ability to delete messages from a stream via the API. Cannot be changed once set to true /// [System.Text.Json.Serialization.JsonPropertyName("deny_delete")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool DenyDelete { get; set; } = false; + public bool DenyDelete { get; set; } /// /// Restricts the ability to purge messages from a stream via the API. Cannot be change once set to true /// [System.Text.Json.Serialization.JsonPropertyName("deny_purge")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool DenyPurge { get; set; } = false; + public bool DenyPurge { get; set; } /// /// Allows the use of the Nats-Rollup header to replace all contents of a stream, or subject in a stream, with a single new message /// [System.Text.Json.Serialization.JsonPropertyName("allow_rollup_hdrs")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool AllowRollupHdrs { get; set; } = false; + public bool AllowRollupHdrs { get; set; } /// /// Allow higher performance, direct access to get individual messages /// [System.Text.Json.Serialization.JsonPropertyName("allow_direct")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool AllowDirect { get; set; } = false; + public bool AllowDirect { get; set; } /// /// Allow higher performance, direct access for mirrors as well /// [System.Text.Json.Serialization.JsonPropertyName("mirror_direct")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool MirrorDirect { get; set; } = false; + public bool MirrorDirect { get; set; } [System.Text.Json.Serialization.JsonPropertyName("republish")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public Republish Republish { get; set; } = default!; + public Republish? Republish { get; set; } /// /// When discard policy is new and the stream is one with max messages per subject set, this will apply the new behavior to every subject. Essentially turning discard new from maximum number of subjects into maximum number of messages in a subject. /// [System.Text.Json.Serialization.JsonPropertyName("discard_new_per_subject")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool DiscardNewPerSubject { get; set; } = false; + public bool DiscardNewPerSubject { get; set; } /// /// Additional metadata for the Stream /// [System.Text.Json.Serialization.JsonPropertyName("metadata")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.IDictionary Metadata { get; set; } = default!; + public IDictionary? Metadata { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamCreateResponse.cs b/src/NATS.Client.JetStream/Models/StreamCreateResponse.cs index 940b1d396..1dea4c5b6 100644 --- a/src/NATS.Client.JetStream/Models/StreamCreateResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamCreateResponse.cs @@ -1,7 +1,3 @@ -using System.Text.Json; -using NATS.Client.Core; -using NATS.Client.Core.Internal; - namespace NATS.Client.JetStream.Models; /// diff --git a/src/NATS.Client.JetStream/Models/StreamDeleteResponse.cs b/src/NATS.Client.JetStream/Models/StreamDeleteResponse.cs index c7687a56b..d4e7d49c7 100644 --- a/src/NATS.Client.JetStream/Models/StreamDeleteResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamDeleteResponse.cs @@ -8,5 +8,5 @@ public record StreamDeleteResponse { [System.Text.Json.Serialization.JsonPropertyName("success")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public bool Success { get; set; } = default!; + public bool Success { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamInfo.cs b/src/NATS.Client.JetStream/Models/StreamInfo.cs index a52ad0bd0..8d2e02538 100644 --- a/src/NATS.Client.JetStream/Models/StreamInfo.cs +++ b/src/NATS.Client.JetStream/Models/StreamInfo.cs @@ -24,34 +24,34 @@ public record StreamInfo [System.Text.Json.Serialization.JsonPropertyName("created")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] - public System.DateTimeOffset Created { get; set; } = default!; + public DateTimeOffset Created { get; set; } /// /// The server time the stream info was created /// [System.Text.Json.Serialization.JsonPropertyName("ts")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.DateTimeOffset Ts { get; set; } = default!; + public DateTimeOffset Ts { get; set; } [System.Text.Json.Serialization.JsonPropertyName("cluster")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public ClusterInfo Cluster { get; set; } = default!; + public ClusterInfo? Cluster { get; set; } [System.Text.Json.Serialization.JsonPropertyName("mirror")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public StreamSourceInfo Mirror { get; set; } = default!; + public StreamSourceInfo? Mirror { get; set; } /// /// Streams being sourced into this Stream /// [System.Text.Json.Serialization.JsonPropertyName("sources")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection Sources { get; set; } = default!; + public ICollection? Sources { get; set; } /// /// List of mirrors sorted by priority /// [System.Text.Json.Serialization.JsonPropertyName("alternates")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection Alternates { get; set; } = default!; + public ICollection? Alternates { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamInfoRequest.cs b/src/NATS.Client.JetStream/Models/StreamInfoRequest.cs index 35958c167..d83d99731 100644 --- a/src/NATS.Client.JetStream/Models/StreamInfoRequest.cs +++ b/src/NATS.Client.JetStream/Models/StreamInfoRequest.cs @@ -11,14 +11,14 @@ public record StreamInfoRequest /// [System.Text.Json.Serialization.JsonPropertyName("deleted_details")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool DeletedDetails { get; set; } = default!; + public bool DeletedDetails { get; set; } /// /// When set will return a list of subjects and how many messages they hold for all matching subjects. Filter is a standard NATS subject wildcard pattern. /// [System.Text.Json.Serialization.JsonPropertyName("subjects_filter")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string SubjectsFilter { get; set; } = default!; + public string? SubjectsFilter { get; set; } /// /// Paging offset when retrieving pages of subjet details @@ -26,5 +26,5 @@ public record StreamInfoRequest [System.Text.Json.Serialization.JsonPropertyName("offset")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Offset { get; set; } = default!; + public int Offset { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamInfoResponse.cs b/src/NATS.Client.JetStream/Models/StreamInfoResponse.cs index da3342c79..a1243fca3 100644 --- a/src/NATS.Client.JetStream/Models/StreamInfoResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamInfoResponse.cs @@ -9,15 +9,15 @@ public record StreamInfoResponse : StreamInfo [System.Text.Json.Serialization.JsonPropertyName("total")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Total { get; set; } = default!; + public int Total { get; set; } [System.Text.Json.Serialization.JsonPropertyName("offset")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Offset { get; set; } = default!; + public int Offset { get; set; } [System.Text.Json.Serialization.JsonPropertyName("limit")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Limit { get; set; } = default!; + public int Limit { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamLeaderStepdownResponse.cs b/src/NATS.Client.JetStream/Models/StreamLeaderStepdownResponse.cs index 3dc786726..80bffc914 100644 --- a/src/NATS.Client.JetStream/Models/StreamLeaderStepdownResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamLeaderStepdownResponse.cs @@ -11,5 +11,5 @@ public record StreamLeaderStepdownResponse /// [System.Text.Json.Serialization.JsonPropertyName("success")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public bool Success { get; set; } = false; + public bool Success { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamListRequest.cs b/src/NATS.Client.JetStream/Models/StreamListRequest.cs index a0fbd0b95..09e6eb11e 100644 --- a/src/NATS.Client.JetStream/Models/StreamListRequest.cs +++ b/src/NATS.Client.JetStream/Models/StreamListRequest.cs @@ -16,5 +16,5 @@ public record StreamListRequest [System.Text.Json.Serialization.JsonPropertyName("offset")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Offset { get; set; } = default!; + public int Offset { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamListResponse.cs b/src/NATS.Client.JetStream/Models/StreamListResponse.cs index 297c4767b..c848060e1 100644 --- a/src/NATS.Client.JetStream/Models/StreamListResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamListResponse.cs @@ -12,12 +12,12 @@ public record StreamListResponse : IterableResponse [System.Text.Json.Serialization.JsonPropertyName("streams")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required] - public System.Collections.Generic.ICollection Streams { get; set; } = new System.Collections.ObjectModel.Collection(); + public ICollection Streams { get; set; } = new System.Collections.ObjectModel.Collection(); /// /// In clustered environments gathering Stream info might time out, this list would be a list of Streams for which information was not obtainable /// [System.Text.Json.Serialization.JsonPropertyName("missing")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection Missing { get; set; } = default!; + public ICollection? Missing { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamMsgDeleteRequest.cs b/src/NATS.Client.JetStream/Models/StreamMsgDeleteRequest.cs index 27fba40cd..3fef6413b 100644 --- a/src/NATS.Client.JetStream/Models/StreamMsgDeleteRequest.cs +++ b/src/NATS.Client.JetStream/Models/StreamMsgDeleteRequest.cs @@ -12,12 +12,12 @@ public record StreamMsgDeleteRequest [System.Text.Json.Serialization.JsonPropertyName("seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long Seq { get; set; } = default!; + public long Seq { get; set; } /// /// Default will securely remove a message and rewrite the data with random data, set this to true to only remove the message /// [System.Text.Json.Serialization.JsonPropertyName("no_erase")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool NoErase { get; set; } = default!; + public bool NoErase { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamMsgDeleteResponse.cs b/src/NATS.Client.JetStream/Models/StreamMsgDeleteResponse.cs index a616ac796..ffc8bbbc5 100644 --- a/src/NATS.Client.JetStream/Models/StreamMsgDeleteResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamMsgDeleteResponse.cs @@ -8,5 +8,5 @@ public record StreamMsgDeleteResponse { [System.Text.Json.Serialization.JsonPropertyName("success")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public bool Success { get; set; } = default!; + public bool Success { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamMsgGetRequest.cs b/src/NATS.Client.JetStream/Models/StreamMsgGetRequest.cs index 7d45859fb..57e3d225d 100644 --- a/src/NATS.Client.JetStream/Models/StreamMsgGetRequest.cs +++ b/src/NATS.Client.JetStream/Models/StreamMsgGetRequest.cs @@ -11,19 +11,19 @@ public record StreamMsgGetRequest /// [System.Text.Json.Serialization.JsonPropertyName("seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public ulong Seq { get; set; } = default!; + public ulong Seq { get; set; } /// /// Retrieves the last message for a given subject, cannot be combined with seq /// [System.Text.Json.Serialization.JsonPropertyName("last_by_subj")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string LastBySubj { get; set; } = default!; + public string? LastBySubj { get; set; } /// /// Combined with sequence gets the next message for a subject with the given sequence or higher /// [System.Text.Json.Serialization.JsonPropertyName("next_by_subj")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string NextBySubj { get; set; } = default!; + public string? NextBySubj { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamMsgGetResponse.cs b/src/NATS.Client.JetStream/Models/StreamMsgGetResponse.cs index 66c0073b5..0d74562ec 100644 --- a/src/NATS.Client.JetStream/Models/StreamMsgGetResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamMsgGetResponse.cs @@ -9,5 +9,9 @@ public record StreamMsgGetResponse [System.Text.Json.Serialization.JsonPropertyName("message")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required] - public StoredMessage Message { get; set; } = new StoredMessage(); +#if NET6_0 + public StoredMessage Message { get; set; } = default!; +#else + public required StoredMessage Message { get; set; } +#endif } diff --git a/src/NATS.Client.JetStream/Models/StreamNamesRequest.cs b/src/NATS.Client.JetStream/Models/StreamNamesRequest.cs index e40bdb092..562605bbe 100644 --- a/src/NATS.Client.JetStream/Models/StreamNamesRequest.cs +++ b/src/NATS.Client.JetStream/Models/StreamNamesRequest.cs @@ -16,5 +16,5 @@ public record StreamNamesRequest [System.Text.Json.Serialization.JsonPropertyName("offset")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Offset { get; set; } = default!; + public int Offset { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamNamesResponse.cs b/src/NATS.Client.JetStream/Models/StreamNamesResponse.cs index 1b8b933b3..2efc68c13 100644 --- a/src/NATS.Client.JetStream/Models/StreamNamesResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamNamesResponse.cs @@ -8,5 +8,5 @@ public record StreamNamesResponse : IterableResponse { [System.Text.Json.Serialization.JsonPropertyName("streams")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection? Streams { get; set; } + public ICollection? Streams { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamPurgeRequest.cs b/src/NATS.Client.JetStream/Models/StreamPurgeRequest.cs index bd1f37303..1759a1879 100644 --- a/src/NATS.Client.JetStream/Models/StreamPurgeRequest.cs +++ b/src/NATS.Client.JetStream/Models/StreamPurgeRequest.cs @@ -11,7 +11,7 @@ public record StreamPurgeRequest /// [System.Text.Json.Serialization.JsonPropertyName("filter")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string Filter { get; set; } = default!; + public string? Filter { get; set; } /// /// Purge all messages up to but not including the message with this sequence. Can be combined with subject filter but not the keep option @@ -19,7 +19,7 @@ public record StreamPurgeRequest [System.Text.Json.Serialization.JsonPropertyName("seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long Seq { get; set; } = default!; + public long Seq { get; set; } /// /// Ensures this many messages are present after the purge. Can be combined with the subject filter but not the sequence @@ -27,5 +27,5 @@ public record StreamPurgeRequest [System.Text.Json.Serialization.JsonPropertyName("keep")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long Keep { get; set; } = default!; + public long Keep { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamPurgeResponse.cs b/src/NATS.Client.JetStream/Models/StreamPurgeResponse.cs index f7f36c5d7..9e4b3ea15 100644 --- a/src/NATS.Client.JetStream/Models/StreamPurgeResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamPurgeResponse.cs @@ -8,7 +8,7 @@ public record StreamPurgeResponse { [System.Text.Json.Serialization.JsonPropertyName("success")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public bool Success { get; set; } = default!; + public bool Success { get; set; } /// /// Number of messages purged from the Stream @@ -16,5 +16,5 @@ public record StreamPurgeResponse [System.Text.Json.Serialization.JsonPropertyName("purged")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long Purged { get; set; } = default!; + public long Purged { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamRemovePeerRequest.cs b/src/NATS.Client.JetStream/Models/StreamRemovePeerRequest.cs index f83345aa0..c8c7b2a71 100644 --- a/src/NATS.Client.JetStream/Models/StreamRemovePeerRequest.cs +++ b/src/NATS.Client.JetStream/Models/StreamRemovePeerRequest.cs @@ -12,5 +12,9 @@ public record StreamRemovePeerRequest [System.Text.Json.Serialization.JsonPropertyName("peer")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required] +#if NET6_0 public string Peer { get; set; } = default!; +#else + public required string Peer { get; set; } +#endif } diff --git a/src/NATS.Client.JetStream/Models/StreamRemovePeerResponse.cs b/src/NATS.Client.JetStream/Models/StreamRemovePeerResponse.cs index c7a9094e6..1290e81f0 100644 --- a/src/NATS.Client.JetStream/Models/StreamRemovePeerResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamRemovePeerResponse.cs @@ -11,5 +11,5 @@ public record StreamRemovePeerResponse /// [System.Text.Json.Serialization.JsonPropertyName("success")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public bool Success { get; set; } = false; + public bool Success { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamRestoreResponse.cs b/src/NATS.Client.JetStream/Models/StreamRestoreResponse.cs index 860af8f1a..8411898f6 100644 --- a/src/NATS.Client.JetStream/Models/StreamRestoreResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamRestoreResponse.cs @@ -12,5 +12,9 @@ public record StreamRestoreResponse [System.Text.Json.Serialization.JsonPropertyName("deliver_subject")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required] +#if NET6_0 public string DeliverSubject { get; set; } = default!; +#else + public required string DeliverSubject { get; set; } +#endif } diff --git a/src/NATS.Client.JetStream/Models/StreamSnapshotRequest.cs b/src/NATS.Client.JetStream/Models/StreamSnapshotRequest.cs index 2f693faf9..d3fb5e0ab 100644 --- a/src/NATS.Client.JetStream/Models/StreamSnapshotRequest.cs +++ b/src/NATS.Client.JetStream/Models/StreamSnapshotRequest.cs @@ -12,14 +12,18 @@ public record StreamSnapshotRequest [System.Text.Json.Serialization.JsonPropertyName("deliver_subject")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required] +#if NET6_0 public string DeliverSubject { get; set; } = default!; +#else + public required string DeliverSubject { get; set; } +#endif /// /// When true consumer states and configurations will not be present in the snapshot /// [System.Text.Json.Serialization.JsonPropertyName("no_consumers")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool NoConsumers { get; set; } = default!; + public bool NoConsumers { get; set; } /// /// The size of data chunks to send to deliver_subject @@ -27,12 +31,12 @@ public record StreamSnapshotRequest [System.Text.Json.Serialization.JsonPropertyName("chunk_size")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long ChunkSize { get; set; } = default!; + public long ChunkSize { get; set; } /// /// Check all message's checksums prior to snapshot /// [System.Text.Json.Serialization.JsonPropertyName("jsck")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public bool Jsck { get; set; } = false; + public bool Jsck { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamSource.cs b/src/NATS.Client.JetStream/Models/StreamSource.cs index 5c19e7f4f..0ea5637df 100644 --- a/src/NATS.Client.JetStream/Models/StreamSource.cs +++ b/src/NATS.Client.JetStream/Models/StreamSource.cs @@ -14,7 +14,11 @@ public record StreamSource [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] [System.ComponentModel.DataAnnotations.StringLength(int.MaxValue, MinimumLength = 1)] [System.ComponentModel.DataAnnotations.RegularExpression(@"^[^.*>]+$")] +#if NET6_0 public string Name { get; set; } = default!; +#else + public required string Name { get; set; } +#endif /// /// Sequence to start replicating from @@ -22,30 +26,30 @@ public record StreamSource [System.Text.Json.Serialization.JsonPropertyName("opt_start_seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long OptStartSeq { get; set; } = default!; + public long OptStartSeq { get; set; } /// /// Time stamp to start replicating from /// [System.Text.Json.Serialization.JsonPropertyName("opt_start_time")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.DateTimeOffset OptStartTime { get; set; } = default!; + public DateTimeOffset OptStartTime { get; set; } /// /// Replicate only a subset of messages based on filter /// [System.Text.Json.Serialization.JsonPropertyName("filter_subject")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string FilterSubject { get; set; } = default!; + public string? FilterSubject { get; set; } /// /// Subject transforms to apply to matching messages /// [System.Text.Json.Serialization.JsonPropertyName("subject_transforms")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection SubjectTransforms { get; set; } = default!; + public ICollection? SubjectTransforms { get; set; } [System.Text.Json.Serialization.JsonPropertyName("external")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public ExternalStreamSource External { get; set; } = default!; + public ExternalStreamSource? External { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamSourceInfo.cs b/src/NATS.Client.JetStream/Models/StreamSourceInfo.cs index 430a94468..a9abf3c5c 100644 --- a/src/NATS.Client.JetStream/Models/StreamSourceInfo.cs +++ b/src/NATS.Client.JetStream/Models/StreamSourceInfo.cs @@ -14,21 +14,25 @@ public record StreamSourceInfo [System.Text.Json.Serialization.JsonPropertyName("name")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string Name { get; set; } = default!; +#else + public required string Name { get; set; } +#endif /// /// The subject filter to apply to the messages /// [System.Text.Json.Serialization.JsonPropertyName("filter_subject")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string FilterSubject { get; set; } = default!; + public string? FilterSubject { get; set; } /// /// The subject transform destination to apply to the messages /// [System.Text.Json.Serialization.JsonPropertyName("subject_transform_dest")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string SubjectTransformDest { get; set; } = default!; + public string? SubjectTransformDest { get; set; } /// /// How many messages behind the mirror operation is @@ -36,7 +40,7 @@ public record StreamSourceInfo [System.Text.Json.Serialization.JsonPropertyName("lag")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long Lag { get; set; } = default!; + public long Lag { get; set; } /// /// When last the mirror had activity, in nanoseconds. Value will be -1 when there has been no activity. @@ -48,9 +52,9 @@ public record StreamSourceInfo [System.Text.Json.Serialization.JsonPropertyName("external")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public ExternalStreamSource External { get; set; } = default!; + public ExternalStreamSource? External { get; set; } [System.Text.Json.Serialization.JsonPropertyName("error")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public ApiError Error { get; set; } = default!; + public ApiError? Error { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamState.cs b/src/NATS.Client.JetStream/Models/StreamState.cs index 1469e4369..e85567ef4 100644 --- a/src/NATS.Client.JetStream/Models/StreamState.cs +++ b/src/NATS.Client.JetStream/Models/StreamState.cs @@ -8,7 +8,7 @@ public record StreamState [System.Text.Json.Serialization.JsonPropertyName("messages")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long Messages { get; set; } = default!; + public long Messages { get; set; } /// /// Combined size of all messages in the Stream @@ -16,7 +16,7 @@ public record StreamState [System.Text.Json.Serialization.JsonPropertyName("bytes")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long Bytes { get; set; } = default!; + public long Bytes { get; set; } /// /// Sequence number of the first message in the Stream @@ -24,14 +24,14 @@ public record StreamState [System.Text.Json.Serialization.JsonPropertyName("first_seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long FirstSeq { get; set; } = default!; + public long FirstSeq { get; set; } /// /// The timestamp of the first message in the Stream /// [System.Text.Json.Serialization.JsonPropertyName("first_ts")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string FirstTs { get; set; } = default!; + public string? FirstTs { get; set; } /// /// Sequence number of the last message in the Stream @@ -39,28 +39,28 @@ public record StreamState [System.Text.Json.Serialization.JsonPropertyName("last_seq")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0D, 18446744073709552000D)] - public long LastSeq { get; set; } = default!; + public long LastSeq { get; set; } /// /// The timestamp of the last message in the Stream /// [System.Text.Json.Serialization.JsonPropertyName("last_ts")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string LastTs { get; set; } = default!; + public string? LastTs { get; set; } /// /// IDs of messages that were deleted using the Message Delete API or Interest based streams removing messages out of order /// [System.Text.Json.Serialization.JsonPropertyName("deleted")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection Deleted { get; set; } = default!; + public ICollection? Deleted { get; set; } /// /// Subjects and their message counts when a subjects_filter was set /// [System.Text.Json.Serialization.JsonPropertyName("subjects")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.IDictionary? Subjects { get; set; } = null; + public IDictionary? Subjects { get; set; } /// /// The number of unique subjects held in the stream @@ -68,7 +68,7 @@ public record StreamState [System.Text.Json.Serialization.JsonPropertyName("num_subjects")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long NumSubjects { get; set; } = default!; + public long NumSubjects { get; set; } /// /// The number of deleted messages @@ -76,11 +76,11 @@ public record StreamState [System.Text.Json.Serialization.JsonPropertyName("num_deleted")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long NumDeleted { get; set; } = default!; + public long NumDeleted { get; set; } [System.Text.Json.Serialization.JsonPropertyName("lost")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public LostStreamData Lost { get; set; } = default!; + public LostStreamData? Lost { get; set; } /// /// Number of Consumers attached to the Stream @@ -88,5 +88,5 @@ public record StreamState [System.Text.Json.Serialization.JsonPropertyName("consumer_count")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-9223372036854776000D, 9223372036854776000D)] - public long ConsumerCount { get; set; } = default!; + public long ConsumerCount { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamTemplateConfig.cs b/src/NATS.Client.JetStream/Models/StreamTemplateConfig.cs index 9e255365e..718618bb9 100644 --- a/src/NATS.Client.JetStream/Models/StreamTemplateConfig.cs +++ b/src/NATS.Client.JetStream/Models/StreamTemplateConfig.cs @@ -14,7 +14,11 @@ public record StreamTemplateConfig [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] [System.ComponentModel.DataAnnotations.StringLength(int.MaxValue, MinimumLength = 1)] [System.ComponentModel.DataAnnotations.RegularExpression(@"^[^.*>]+$")] +#if NET6_0 public string Name { get; set; } = default!; +#else + public required string Name { get; set; } +#endif /// /// The maximum number of Streams this Template can create, -1 for unlimited. @@ -22,7 +26,7 @@ public record StreamTemplateConfig [System.Text.Json.Serialization.JsonPropertyName("max_streams")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(-2147483648, 2147483647)] - public int MaxStreams { get; set; } = default!; + public int MaxStreams { get; set; } [System.Text.Json.Serialization.JsonPropertyName("config")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] diff --git a/src/NATS.Client.JetStream/Models/StreamTemplateDeleteResponse.cs b/src/NATS.Client.JetStream/Models/StreamTemplateDeleteResponse.cs index a6eec13ef..cbc3b48fe 100644 --- a/src/NATS.Client.JetStream/Models/StreamTemplateDeleteResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamTemplateDeleteResponse.cs @@ -8,5 +8,5 @@ public record StreamTemplateDeleteResponse { [System.Text.Json.Serialization.JsonPropertyName("success")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] - public bool Success { get; set; } = default!; + public bool Success { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/StreamTemplateInfo.cs b/src/NATS.Client.JetStream/Models/StreamTemplateInfo.cs index b2bd9ba95..da995d873 100644 --- a/src/NATS.Client.JetStream/Models/StreamTemplateInfo.cs +++ b/src/NATS.Client.JetStream/Models/StreamTemplateInfo.cs @@ -5,7 +5,11 @@ public record StreamTemplateInfo [System.Text.Json.Serialization.JsonPropertyName("config")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required] - public StreamTemplateConfig Config { get; set; } = new StreamTemplateConfig(); +#if NET6_0 + public StreamTemplateConfig Config { get; set; } = default!; +#else + public required StreamTemplateConfig Config { get; set; } +#endif /// /// List of Streams managed by this Template @@ -13,5 +17,5 @@ public record StreamTemplateInfo [System.Text.Json.Serialization.JsonPropertyName("streams")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required] - public System.Collections.Generic.ICollection Streams { get; set; } = new System.Collections.ObjectModel.Collection(); + public ICollection Streams { get; set; } = new System.Collections.ObjectModel.Collection(); } diff --git a/src/NATS.Client.JetStream/Models/StreamTemplateNamesResponse.cs b/src/NATS.Client.JetStream/Models/StreamTemplateNamesResponse.cs index 285490416..e798588a5 100644 --- a/src/NATS.Client.JetStream/Models/StreamTemplateNamesResponse.cs +++ b/src/NATS.Client.JetStream/Models/StreamTemplateNamesResponse.cs @@ -8,5 +8,5 @@ public record StreamTemplateNamesResponse : IterableResponse { [System.Text.Json.Serialization.JsonPropertyName("consumers")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public System.Collections.Generic.ICollection Consumers { get; set; } = default!; + public ICollection? Consumers { get; set; } } diff --git a/src/NATS.Client.JetStream/Models/SubjectTransform.cs b/src/NATS.Client.JetStream/Models/SubjectTransform.cs index ba5034db5..c074fcae9 100644 --- a/src/NATS.Client.JetStream/Models/SubjectTransform.cs +++ b/src/NATS.Client.JetStream/Models/SubjectTransform.cs @@ -11,7 +11,7 @@ public record SubjectTransform /// [System.Text.Json.Serialization.JsonPropertyName("src")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] - public string Src { get; set; } = default!; + public string? Src { get; set; } /// /// The subject transform destination @@ -19,5 +19,9 @@ public record SubjectTransform [System.Text.Json.Serialization.JsonPropertyName("dest")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] +#if NET6_0 public string Dest { get; set; } = default!; +#else + public required string Dest { get; set; } +#endif } diff --git a/src/NATS.Client.JetStream/Models/Tier.cs b/src/NATS.Client.JetStream/Models/Tier.cs index a05ce7a56..2a2207c5a 100644 --- a/src/NATS.Client.JetStream/Models/Tier.cs +++ b/src/NATS.Client.JetStream/Models/Tier.cs @@ -8,7 +8,7 @@ public record Tier [System.Text.Json.Serialization.JsonPropertyName("memory")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Memory { get; set; } = default!; + public int Memory { get; set; } /// /// File Storage being used for Stream Message storage @@ -16,7 +16,7 @@ public record Tier [System.Text.Json.Serialization.JsonPropertyName("storage")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Storage { get; set; } = default!; + public int Storage { get; set; } /// /// Number of active Streams @@ -24,7 +24,7 @@ public record Tier [System.Text.Json.Serialization.JsonPropertyName("streams")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Streams { get; set; } = default!; + public int Streams { get; set; } /// /// Number of active Consumers @@ -32,7 +32,7 @@ public record Tier [System.Text.Json.Serialization.JsonPropertyName("consumers")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] [System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)] - public int Consumers { get; set; } = default!; + public int Consumers { get; set; } [System.Text.Json.Serialization.JsonPropertyName("limits")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] diff --git a/src/NATS.Client.JetStream/NatsJSContext.Streams.cs b/src/NATS.Client.JetStream/NatsJSContext.Streams.cs index a6e8fd70d..db6ca447b 100644 --- a/src/NATS.Client.JetStream/NatsJSContext.Streams.cs +++ b/src/NATS.Client.JetStream/NatsJSContext.Streams.cs @@ -17,6 +17,7 @@ public async ValueTask CreateStreamAsync( StreamConfig config, CancellationToken cancellationToken = default) { + ArgumentNullException.ThrowIfNull(config.Name, nameof(config.Name)); var response = await JSRequestResponseAsync( subject: $"{Opts.Prefix}.STREAM.CREATE.{config.Name}", config, @@ -118,6 +119,7 @@ public async ValueTask UpdateStreamAsync( StreamConfig request, CancellationToken cancellationToken = default) { + ArgumentNullException.ThrowIfNull(request.Name, nameof(request.Name)); var response = await JSRequestResponseAsync( subject: $"{Opts.Prefix}.STREAM.UPDATE.{request.Name}", request: request, diff --git a/src/NATS.Client.JetStream/NatsJSException.cs b/src/NATS.Client.JetStream/NatsJSException.cs index 036e8f351..4f621a86e 100644 --- a/src/NATS.Client.JetStream/NatsJSException.cs +++ b/src/NATS.Client.JetStream/NatsJSException.cs @@ -83,7 +83,7 @@ public class NatsJSApiException : NatsJSException /// /// Error response received from the server. public NatsJSApiException(ApiError error) - : base(error.Description) => + : base(error.Description ?? string.Empty) => Error = error; /// diff --git a/src/NATS.Client.JetStream/NatsJSOrderedConsumer.cs b/src/NATS.Client.JetStream/NatsJSOrderedConsumer.cs index b5ac1e608..32e7285de 100644 --- a/src/NATS.Client.JetStream/NatsJSOrderedConsumer.cs +++ b/src/NATS.Client.JetStream/NatsJSOrderedConsumer.cs @@ -35,7 +35,11 @@ public NatsJSOrderedConsumer(string stream, NatsJSContext context, NatsJSOrdered // For ordered consumer we start with an empty consumer info object // since consumers are created and updated during fetch and consume. - Info = new ConsumerInfo(); + Info = new ConsumerInfo() + { + Name = string.Empty, + StreamName = string.Empty, + }; } /// diff --git a/src/NATS.Client.JetStream/NatsJSStream.cs b/src/NATS.Client.JetStream/NatsJSStream.cs index 68367ba6f..0e1e6ad13 100644 --- a/src/NATS.Client.JetStream/NatsJSStream.cs +++ b/src/NATS.Client.JetStream/NatsJSStream.cs @@ -13,11 +13,15 @@ public class NatsJSStream : INatsJSStream private readonly string _name; private bool _deleted; +#if DOT_NET_6 + [System.Diagnostics.CodeAnalysis.SetsRequiredMembers] +#endif internal NatsJSStream(NatsJSContext context, StreamInfo info) { + ArgumentNullException.ThrowIfNull(info.Config.Name, nameof(info.Config.Name)); _context = context; Info = info; - _name = info.Config.Name; + _name = info.Config.Name!; } /// diff --git a/src/NATS.Client.KeyValueStore/NatsKVStore.cs b/src/NATS.Client.KeyValueStore/NatsKVStore.cs index 0809ce258..f3f976f5a 100644 --- a/src/NATS.Client.KeyValueStore/NatsKVStore.cs +++ b/src/NATS.Client.KeyValueStore/NatsKVStore.cs @@ -270,7 +270,7 @@ public async ValueTask> GetEntryAsync(string key, ulong revisi var bytes = ArrayPool.Shared.Rent(_context.Connection.Opts.ReaderBufferSize); try { - if (Convert.TryFromBase64String(response.Message.Data, bytes, out var written)) + if (response.Message.Data != null && Convert.TryFromBase64String(response.Message.Data, bytes, out var written)) { var buffer = new ReadOnlySequence(bytes.AsMemory(0, written)); data = serializer.Deserialize(buffer); diff --git a/src/NATS.Client.ObjectStore/Models/ObjectMetadata.cs b/src/NATS.Client.ObjectStore/Models/ObjectMetadata.cs index 24fc6c82f..e056fb57d 100644 --- a/src/NATS.Client.ObjectStore/Models/ObjectMetadata.cs +++ b/src/NATS.Client.ObjectStore/Models/ObjectMetadata.cs @@ -8,80 +8,84 @@ public record ObjectMetadata /// Object name /// [JsonPropertyName("name")] +#if NET6_0 public string Name { get; set; } = default!; +#else + public required string Name { get; set; } +#endif /// /// Object description /// [JsonPropertyName("description")] - public string Description { get; set; } = default!; + public string? Description { get; set; } /// /// Bucket name /// [JsonPropertyName("bucket")] - public string Bucket { get; set; } = default!; + public string? Bucket { get; set; } /// /// Object NUID /// [JsonPropertyName("nuid")] - public string Nuid { get; set; } = default!; + public string? Nuid { get; set; } /// /// Max chunk size /// [JsonPropertyName("size")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public int Size { get; set; } = default!; + public int Size { get; set; } /// /// Modified timestamp /// [JsonPropertyName("mtime")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public DateTimeOffset MTime { get; set; } = default!; + public DateTimeOffset MTime { get; set; } /// /// Number of chunks /// [JsonPropertyName("chunks")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public int Chunks { get; set; } = default!; + public int Chunks { get; set; } /// /// Object digest /// [JsonPropertyName("digest")] - public string Digest { get; set; } = default!; + public string? Digest { get; set; } /// /// Object metadata /// [JsonPropertyName("metadata")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public Dictionary Metadata { get; set; } = default!; + public Dictionary? Metadata { get; set; } /// /// Object metadata /// [JsonPropertyName("headers")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public Dictionary Headers { get; set; } = default!; + public Dictionary? Headers { get; set; } /// /// Object deleted /// [JsonPropertyName("deleted")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public bool Deleted { get; set; } = default!; + public bool Deleted { get; set; } /// /// Object options /// [JsonPropertyName("options")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public MetaDataOptions? Options { get; set; } = default!; + public MetaDataOptions? Options { get; set; } } public record MetaDataOptions @@ -91,14 +95,14 @@ public record MetaDataOptions /// [JsonPropertyName("link")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public NatsObjLink? Link { get; set; } = default!; + public NatsObjLink? Link { get; set; } /// /// Max chunk size /// [JsonPropertyName("max_chunk_size")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public int? MaxChunkSize { get; set; } = default!; + public int? MaxChunkSize { get; set; } } public record NatsObjLink @@ -107,13 +111,21 @@ public record NatsObjLink /// Link name /// [JsonPropertyName("name")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] +#if NET6_0 public string Name { get; set; } = default!; +#else + public required string Name { get; set; } +#endif /// /// Bucket name /// [JsonPropertyName("bucket")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] +#if NET6_0 public string Bucket { get; set; } = default!; +#else + public required string Bucket { get; set; } +#endif } diff --git a/src/NATS.Client.ObjectStore/NatsObjStore.cs b/src/NATS.Client.ObjectStore/NatsObjStore.cs index 2220a528e..54b8eea13 100644 --- a/src/NATS.Client.ObjectStore/NatsObjStore.cs +++ b/src/NATS.Client.ObjectStore/NatsObjStore.cs @@ -2,7 +2,6 @@ using System.Runtime.CompilerServices; using System.Security.Cryptography; using System.Text.Json; -using System.Text.RegularExpressions; using NATS.Client.Core; using NATS.Client.Core.Internal; using NATS.Client.JetStream; @@ -75,6 +74,11 @@ public async ValueTask GetAsync(string key, Stream stream, bool return await store.GetAsync(link.Name, stream, leaveOpen, cancellationToken).ConfigureAwait(false); } + if (info.Nuid is null) + { + throw new NatsObjException("Object-store meta information invalid"); + } + await using var pushConsumer = new NatsJSOrderedPushConsumer>( context: _context, stream: $"OBJ_{Bucket}", @@ -272,7 +276,7 @@ public async ValueTask PutAsync(ObjectMetadata meta, Stream stre await PublishMeta(meta, cancellationToken); // Delete the old object - if (info != null && info.Nuid != nuid) + if (info?.Nuid != null && info.Nuid != nuid) { try { @@ -358,6 +362,11 @@ public async ValueTask AddLinkAsync(string link, ObjectMetadata throw new NatsObjException("Can't link to a deleted object"); } + if (target.Bucket is null) + { + throw new NatsObjException("Can't link to a target without bucket"); + } + if (target.Options?.Link is not null) { throw new NatsObjException("Can't link to a linked object"); @@ -485,6 +494,11 @@ public async ValueTask GetInfoAsync(string key, bool showDeleted { var response = await _stream.GetAsync(request, cancellationToken); + if (response.Message.Data == null) + { + throw new NatsObjException("Can't decode data message value"); + } + var base64String = Convert.FromBase64String(response.Message.Data); var data = NatsObjJsonSerializer.Default.Deserialize(new ReadOnlySequence(base64String)) ?? throw new NatsObjException("Can't deserialize object metadata"); diff --git a/tests/NATS.Client.JetStream.Tests/PublishTest.cs b/tests/NATS.Client.JetStream.Tests/PublishTest.cs index b59cb3d3c..a2f082b9d 100644 --- a/tests/NATS.Client.JetStream.Tests/PublishTest.cs +++ b/tests/NATS.Client.JetStream.Tests/PublishTest.cs @@ -74,9 +74,9 @@ public async Task Publish_test() data: 2, opts: new NatsJSPubOpts { ExpectedStream = "non-existent-stream" }, cancellationToken: cts.Token); - Assert.Equal(400, ack2.Error.Code); - Assert.Equal(10060, ack2.Error.ErrCode); - Assert.Equal("expected stream does not match", ack2.Error.Description); + Assert.Equal(400, ack2.Error?.Code); + Assert.Equal(10060, ack2.Error?.ErrCode); + Assert.Equal("expected stream does not match", ack2.Error?.Description); } // ExpectedLastSequence @@ -99,9 +99,9 @@ public async Task Publish_test() data: 3, opts: new NatsJSPubOpts { ExpectedLastSequence = ack1.Seq }, cancellationToken: cts.Token); - Assert.Equal(400, ack3.Error.Code); - Assert.Equal(10071, ack3.Error.ErrCode); - Assert.Matches(@"wrong last sequence: \d+", ack3.Error.Description); + Assert.Equal(400, ack3.Error?.Code); + Assert.Equal(10071, ack3.Error?.ErrCode); + Assert.Matches(@"wrong last sequence: \d+", ack3.Error?.Description); } // ExpectedLastSubjectSequence @@ -124,9 +124,9 @@ public async Task Publish_test() data: 3, opts: new NatsJSPubOpts { ExpectedLastSubjectSequence = ack1.Seq }, cancellationToken: cts.Token); - Assert.Equal(400, ack3.Error.Code); - Assert.Equal(10071, ack3.Error.ErrCode); - Assert.Matches(@"wrong last sequence: \d+", ack3.Error.Description); + Assert.Equal(400, ack3.Error?.Code); + Assert.Equal(10071, ack3.Error?.ErrCode); + Assert.Matches(@"wrong last sequence: \d+", ack3.Error?.Description); } // ExpectedLastMsgId @@ -150,9 +150,9 @@ public async Task Publish_test() data: 3, opts: new NatsJSPubOpts { MsgId = "ExpectedLastMsgId-3", ExpectedLastMsgId = "unexpected-msg-id" }, cancellationToken: cts.Token); - Assert.Equal(400, ack3.Error.Code); - Assert.Equal(10070, ack3.Error.ErrCode); - Assert.Equal("wrong last msg ID: ExpectedLastMsgId-2", ack3.Error.Description); + Assert.Equal(400, ack3.Error?.Code); + Assert.Equal(10070, ack3.Error?.ErrCode); + Assert.Equal("wrong last msg ID: ExpectedLastMsgId-2", ack3.Error?.Description); } } diff --git a/tests/NATS.Client.JetStream.Tests/TimeSpanJsonTests.cs b/tests/NATS.Client.JetStream.Tests/TimeSpanJsonTests.cs index 511cb2e92..d0abcc10c 100644 --- a/tests/NATS.Client.JetStream.Tests/TimeSpanJsonTests.cs +++ b/tests/NATS.Client.JetStream.Tests/TimeSpanJsonTests.cs @@ -137,7 +137,7 @@ public void PeerInfoActive_test(string value, string expected) var serializer = NatsJSJsonSerializer.Default; var bw = new NatsBufferWriter(); - serializer.Serialize(bw, new PeerInfo { Active = time }); + serializer.Serialize(bw, new PeerInfo { Name = "test", Active = time }); var json = Encoding.UTF8.GetString(bw.WrittenSpan); Assert.Matches(expected, json); @@ -197,7 +197,7 @@ public void StreamSourceInfoActive_test(string value, string expected) var serializer = NatsJSJsonSerializer.Default; var bw = new NatsBufferWriter(); - serializer.Serialize(bw, new StreamSourceInfo { Active = time }); + serializer.Serialize(bw, new StreamSourceInfo { Name = "test", Active = time }); var json = Encoding.UTF8.GetString(bw.WrittenSpan); Assert.Matches(expected, json); diff --git a/tests/Nats.Client.Compat/ObjectStoreCompat.cs b/tests/Nats.Client.Compat/ObjectStoreCompat.cs index ed3b4f8b1..d5813b2ae 100644 --- a/tests/Nats.Client.Compat/ObjectStoreCompat.cs +++ b/tests/Nats.Client.Compat/ObjectStoreCompat.cs @@ -145,7 +145,8 @@ public async Task TestWatch(NatsConnection nats, NatsMsg> msg, Chan var list = new List(); await foreach (var info in store.WatchAsync()) { - list.Add(info.Digest); + if (info.Digest is not null) + list.Add(info.Digest); if (list.Count == 2) break; }