| | | 1 | | namespace TeleFlow.Framework.States; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Identifies the owner and isolation boundary of state records used by state stores, state data, |
| | | 5 | | /// wizard history, and future storage-backed coordination primitives. |
| | | 6 | | /// </summary> |
| | | 7 | | public readonly record struct StateKey( |
| | | 8 | | string Namespace, |
| | | 9 | | string Scope, |
| | | 10 | | string Subject, |
| | | 11 | | string? Partition, |
| | | 12 | | string Destiny) |
| | | 13 | | { |
| | 118 | 14 | | private readonly string _namespace = ValidateRequired(Namespace, nameof(Namespace)); |
| | 116 | 15 | | private readonly string _scope = ValidateRequired(Scope, nameof(Scope)); |
| | 114 | 16 | | private readonly string _subject = ValidateRequired(Subject, nameof(Subject)); |
| | 112 | 17 | | private readonly string? _partition = ValidateOptional(Partition, nameof(Partition)); |
| | 111 | 18 | | private readonly string _destiny = ValidateRequired(Destiny, nameof(Destiny)); |
| | | 19 | | |
| | | 20 | | public StateKey(string scope, string subject) |
| | 0 | 21 | | : this( |
| | 0 | 22 | | StateKeyDefaults.DefaultNamespace, |
| | 0 | 23 | | scope, |
| | 0 | 24 | | subject, |
| | 0 | 25 | | null, |
| | 0 | 26 | | StateKeyDefaults.DefaultDestiny) |
| | | 27 | | { |
| | 0 | 28 | | } |
| | | 29 | | |
| | | 30 | | public StateKey(string scope, string subject, string? partition) |
| | 101 | 31 | | : this( |
| | 101 | 32 | | StateKeyDefaults.DefaultNamespace, |
| | 101 | 33 | | scope, |
| | 101 | 34 | | subject, |
| | 101 | 35 | | partition, |
| | 101 | 36 | | StateKeyDefaults.DefaultDestiny) |
| | | 37 | | { |
| | 101 | 38 | | } |
| | | 39 | | |
| | | 40 | | public string Namespace |
| | | 41 | | { |
| | 7 | 42 | | get => _namespace; |
| | 1 | 43 | | init => _namespace = ValidateRequired(value, nameof(Namespace)); |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | public string Scope |
| | | 47 | | { |
| | 8 | 48 | | get => _scope; |
| | 1 | 49 | | init => _scope = ValidateRequired(value, nameof(Scope)); |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | public string Subject |
| | | 53 | | { |
| | 8 | 54 | | get => _subject; |
| | 1 | 55 | | init => _subject = ValidateRequired(value, nameof(Subject)); |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | public string? Partition |
| | | 59 | | { |
| | 8 | 60 | | get => _partition; |
| | 1 | 61 | | init => _partition = ValidateOptional(value, nameof(Partition)); |
| | | 62 | | } |
| | | 63 | | |
| | | 64 | | public string Destiny |
| | | 65 | | { |
| | 7 | 66 | | get => _destiny; |
| | 1 | 67 | | init => _destiny = ValidateRequired(value, nameof(Destiny)); |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | public static StateKey Create(string scope, string subject, string? partition = null) |
| | | 71 | | { |
| | 101 | 72 | | return new StateKey(scope, subject, partition); |
| | | 73 | | } |
| | | 74 | | |
| | | 75 | | public static StateKey Create( |
| | | 76 | | string keyNamespace, |
| | | 77 | | string scope, |
| | | 78 | | string subject, |
| | | 79 | | string? partition, |
| | | 80 | | string destiny) |
| | | 81 | | { |
| | 0 | 82 | | return new StateKey(keyNamespace, scope, subject, partition, destiny); |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | private static string ValidateRequired(string? value, string parameterName) |
| | | 86 | | { |
| | 463 | 87 | | if (string.IsNullOrWhiteSpace(value)) |
| | | 88 | | { |
| | 12 | 89 | | throw new ArgumentException($"{parameterName} must be provided.", parameterName); |
| | | 90 | | } |
| | | 91 | | |
| | 451 | 92 | | return value; |
| | | 93 | | } |
| | | 94 | | |
| | | 95 | | private static string? ValidateOptional(string? value, string parameterName) |
| | | 96 | | { |
| | 113 | 97 | | if (value is not null && string.IsNullOrWhiteSpace(value)) |
| | | 98 | | { |
| | 2 | 99 | | throw new ArgumentException($"{parameterName} must be null or non-empty.", parameterName); |
| | | 100 | | } |
| | | 101 | | |
| | 111 | 102 | | return value; |
| | | 103 | | } |
| | | 104 | | } |