@@ -4,8 +4,8 @@ namespace PythonScriptRunner;
44
55/// <summary>Identifier of a run (time-ordered UUID v7). Its timestamp is the creation time of the run.</summary>
66/// <param name="Value">The underlying GUID.</param>
7- [ JsonConverter ( typeof ( RunIdJsonConverter ) ) ]
8- public readonly record struct RunId ( Guid Value )
7+ [ JsonConverter ( typeof ( GuidIdJsonConverter < RunId > ) ) ]
8+ public readonly record struct RunId ( Guid Value ) : IGuidId < RunId >
99{
1010 /// <summary>Creates a new time-ordered identifier.</summary>
1111 public static RunId New ( ) => new ( Guid . CreateVersion7 ( ) ) ;
@@ -21,36 +21,74 @@ public readonly record struct RunId(Guid Value)
2121 /// <summary>Creation time embedded in the identifier (UTC, millisecond precision).</summary>
2222 public DateTimeOffset CreatedAt => UuidV7 . Timestamp ( Value ) ;
2323
24+ /// <summary>Parses the GUID text (route and query binding).</summary>
25+ /// <param name="text">GUID text.</param>
26+ /// <param name="id">The identifier.</param>
27+ public static bool TryParse ( string ? text , out RunId id )
28+ {
29+ var parsed = Guid . TryParse ( text , out var value ) ;
30+ id = new RunId ( value ) ;
31+ return parsed ;
32+ }
33+
34+ static RunId IGuidId < RunId > . From ( Guid value ) => new ( value ) ;
35+
2436 /// <inheritdoc />
2537 public override string ToString ( ) => Value . ToString ( ) ;
2638}
2739
2840/// <summary>Identifier of one attempt of a step (time-ordered UUID v7).</summary>
2941/// <param name="Value">The underlying GUID.</param>
30- public readonly record struct AttemptId ( Guid Value )
42+ [ JsonConverter ( typeof ( GuidIdJsonConverter < AttemptId > ) ) ]
43+ public readonly record struct AttemptId ( Guid Value ) : IGuidId < AttemptId >
3144{
3245 /// <summary>Creates a new time-ordered identifier.</summary>
3346 public static AttemptId New ( ) => new ( Guid . CreateVersion7 ( ) ) ;
3447
48+ /// <summary>Parses the GUID text (route and query binding).</summary>
49+ /// <param name="text">GUID text.</param>
50+ /// <param name="id">The identifier.</param>
51+ public static bool TryParse ( string ? text , out AttemptId id )
52+ {
53+ var parsed = Guid . TryParse ( text , out var value ) ;
54+ id = new AttemptId ( value ) ;
55+ return parsed ;
56+ }
57+
58+ static AttemptId IGuidId < AttemptId > . From ( Guid value ) => new ( value ) ;
59+
3560 /// <inheritdoc />
3661 public override string ToString ( ) => Value . ToString ( ) ;
3762}
3863
3964/// <summary>Identifier of a step within a run (time-ordered UUID v7).</summary>
4065/// <param name="Value">The underlying GUID.</param>
41- [ JsonConverter ( typeof ( StepRunIdJsonConverter ) ) ]
42- public readonly record struct StepRunId ( Guid Value )
66+ [ JsonConverter ( typeof ( GuidIdJsonConverter < StepRunId > ) ) ]
67+ public readonly record struct StepRunId ( Guid Value ) : IGuidId < StepRunId >
4368{
4469 /// <summary>Creates a new time-ordered identifier.</summary>
4570 public static StepRunId New ( ) => new ( Guid . CreateVersion7 ( ) ) ;
4671
72+ /// <summary>Parses the GUID text (route and query binding).</summary>
73+ /// <param name="text">GUID text.</param>
74+ /// <param name="id">The identifier.</param>
75+ public static bool TryParse ( string ? text , out StepRunId id )
76+ {
77+ var parsed = Guid . TryParse ( text , out var value ) ;
78+ id = new StepRunId ( value ) ;
79+ return parsed ;
80+ }
81+
82+ static StepRunId IGuidId < StepRunId > . From ( Guid value ) => new ( value ) ;
83+
4784 /// <inheritdoc />
4885 public override string ToString ( ) => Value . ToString ( ) ;
4986}
5087
5188/// <summary>Identifier of a stored file (time-ordered UUID v7).</summary>
5289/// <param name="Value">The underlying GUID.</param>
53- public readonly record struct ArtifactId ( Guid Value )
90+ [ JsonConverter ( typeof ( GuidIdJsonConverter < ArtifactId > ) ) ]
91+ public readonly record struct ArtifactId ( Guid Value ) : IGuidId < ArtifactId >
5492{
5593 /// <summary>Creates a new time-ordered identifier.</summary>
5694 public static ArtifactId New ( ) => new ( Guid . CreateVersion7 ( ) ) ;
@@ -59,61 +97,138 @@ public readonly record struct ArtifactId(Guid Value)
5997 /// <param name="text">GUID text.</param>
6098 public static ArtifactId Parse ( string text ) => new ( Guid . Parse ( text ) ) ;
6199
100+ /// <summary>Parses the GUID text (route and query binding).</summary>
101+ /// <param name="text">GUID text.</param>
102+ /// <param name="id">The identifier.</param>
103+ public static bool TryParse ( string ? text , out ArtifactId id )
104+ {
105+ var parsed = Guid . TryParse ( text , out var value ) ;
106+ id = new ArtifactId ( value ) ;
107+ return parsed ;
108+ }
109+
110+ static ArtifactId IGuidId < ArtifactId > . From ( Guid value ) => new ( value ) ;
111+
62112 /// <inheritdoc />
63113 public override string ToString ( ) => Value . ToString ( ) ;
64114}
65115
66116/// <summary>Identifier of a stage (UUID v7).</summary>
67117/// <param name="Value">The underlying GUID.</param>
68- public readonly record struct StageId ( Guid Value )
118+ [ JsonConverter ( typeof ( GuidIdJsonConverter < StageId > ) ) ]
119+ public readonly record struct StageId ( Guid Value ) : IGuidId < StageId >
69120{
70121 /// <summary>Creates a new time-ordered identifier.</summary>
71122 public static StageId New ( ) => new ( Guid . CreateVersion7 ( ) ) ;
72123
124+ /// <summary>Parses the GUID text (route and query binding).</summary>
125+ /// <param name="text">GUID text.</param>
126+ /// <param name="id">The identifier.</param>
127+ public static bool TryParse ( string ? text , out StageId id )
128+ {
129+ var parsed = Guid . TryParse ( text , out var value ) ;
130+ id = new StageId ( value ) ;
131+ return parsed ;
132+ }
133+
134+ static StageId IGuidId < StageId > . From ( Guid value ) => new ( value ) ;
135+
73136 /// <inheritdoc />
74137 public override string ToString ( ) => Value . ToString ( ) ;
75138}
76139
77140/// <summary>Identifier of a stage version (UUID v7).</summary>
78141/// <param name="Value">The underlying GUID.</param>
79- public readonly record struct StageVersionId ( Guid Value )
142+ [ JsonConverter ( typeof ( GuidIdJsonConverter < StageVersionId > ) ) ]
143+ public readonly record struct StageVersionId ( Guid Value ) : IGuidId < StageVersionId >
80144{
81145 /// <summary>Creates a new time-ordered identifier.</summary>
82146 public static StageVersionId New ( ) => new ( Guid . CreateVersion7 ( ) ) ;
83147
148+ /// <summary>Parses the GUID text (route and query binding).</summary>
149+ /// <param name="text">GUID text.</param>
150+ /// <param name="id">The identifier.</param>
151+ public static bool TryParse ( string ? text , out StageVersionId id )
152+ {
153+ var parsed = Guid . TryParse ( text , out var value ) ;
154+ id = new StageVersionId ( value ) ;
155+ return parsed ;
156+ }
157+
158+ static StageVersionId IGuidId < StageVersionId > . From ( Guid value ) => new ( value ) ;
159+
84160 /// <inheritdoc />
85161 public override string ToString ( ) => Value . ToString ( ) ;
86162}
87163
88164/// <summary>Identifier of a pipeline (UUID v7).</summary>
89165/// <param name="Value">The underlying GUID.</param>
90- public readonly record struct PipelineId ( Guid Value )
166+ [ JsonConverter ( typeof ( GuidIdJsonConverter < PipelineId > ) ) ]
167+ public readonly record struct PipelineId ( Guid Value ) : IGuidId < PipelineId >
91168{
92169 /// <summary>Creates a new time-ordered identifier.</summary>
93170 public static PipelineId New ( ) => new ( Guid . CreateVersion7 ( ) ) ;
94171
172+ /// <summary>Parses the GUID text (route and query binding).</summary>
173+ /// <param name="text">GUID text.</param>
174+ /// <param name="id">The identifier.</param>
175+ public static bool TryParse ( string ? text , out PipelineId id )
176+ {
177+ var parsed = Guid . TryParse ( text , out var value ) ;
178+ id = new PipelineId ( value ) ;
179+ return parsed ;
180+ }
181+
182+ static PipelineId IGuidId < PipelineId > . From ( Guid value ) => new ( value ) ;
183+
95184 /// <inheritdoc />
96185 public override string ToString ( ) => Value . ToString ( ) ;
97186}
98187
99188/// <summary>Identifier of a pipeline version (UUID v7).</summary>
100189/// <param name="Value">The underlying GUID.</param>
101- public readonly record struct PipelineVersionId ( Guid Value )
190+ [ JsonConverter ( typeof ( GuidIdJsonConverter < PipelineVersionId > ) ) ]
191+ public readonly record struct PipelineVersionId ( Guid Value ) : IGuidId < PipelineVersionId >
102192{
103193 /// <summary>Creates a new time-ordered identifier.</summary>
104194 public static PipelineVersionId New ( ) => new ( Guid . CreateVersion7 ( ) ) ;
105195
196+ /// <summary>Parses the GUID text (route and query binding).</summary>
197+ /// <param name="text">GUID text.</param>
198+ /// <param name="id">The identifier.</param>
199+ public static bool TryParse ( string ? text , out PipelineVersionId id )
200+ {
201+ var parsed = Guid . TryParse ( text , out var value ) ;
202+ id = new PipelineVersionId ( value ) ;
203+ return parsed ;
204+ }
205+
206+ static PipelineVersionId IGuidId < PipelineVersionId > . From ( Guid value ) => new ( value ) ;
207+
106208 /// <inheritdoc />
107209 public override string ToString ( ) => Value . ToString ( ) ;
108210}
109211
110212/// <summary>Identifier of a schedule (UUID v7).</summary>
111213/// <param name="Value">The underlying GUID.</param>
112- public readonly record struct ScheduleId ( Guid Value )
214+ [ JsonConverter ( typeof ( GuidIdJsonConverter < ScheduleId > ) ) ]
215+ public readonly record struct ScheduleId ( Guid Value ) : IGuidId < ScheduleId >
113216{
114217 /// <summary>Creates a new time-ordered identifier.</summary>
115218 public static ScheduleId New ( ) => new ( Guid . CreateVersion7 ( ) ) ;
116219
220+ /// <summary>Parses the GUID text (route and query binding).</summary>
221+ /// <param name="text">GUID text.</param>
222+ /// <param name="id">The identifier.</param>
223+ public static bool TryParse ( string ? text , out ScheduleId id )
224+ {
225+ var parsed = Guid . TryParse ( text , out var value ) ;
226+ id = new ScheduleId ( value ) ;
227+ return parsed ;
228+ }
229+
230+ static ScheduleId IGuidId < ScheduleId > . From ( Guid value ) => new ( value ) ;
231+
117232 /// <inheritdoc />
118233 public override string ToString ( ) => Value . ToString ( ) ;
119234}
0 commit comments