@@ -19,12 +19,14 @@ pub struct DocumentNodePersistentMetadataInputNames {
1919 pub network_metadata : Option < NodeNetworkMetadata > ,
2020}
2121
22- impl From < DocumentNodePersistentMetadataInputNames > for DocumentNodePersistentMetadata {
22+ impl From < DocumentNodePersistentMetadataInputNames > for DocumentNodePersistentMetadataPropertiesRow {
2323 fn from ( old : DocumentNodePersistentMetadataInputNames ) -> Self {
24- DocumentNodePersistentMetadata {
25- input_metadata : Vec :: new ( ) ,
24+ DocumentNodePersistentMetadataPropertiesRow {
25+ reference : old. reference ,
26+ input_properties : Vec :: new ( ) ,
2627 display_name : old. display_name ,
2728 output_names : old. output_names ,
29+ has_primary_output : old. has_primary_output ,
2830 locked : old. locked ,
2931 pinned : old. pinned ,
3032 node_type_metadata : old. node_type_metadata ,
@@ -59,7 +61,7 @@ pub struct PropertiesRow {
5961 pub input_description : String ,
6062}
6163
62- impl From < DocumentNodePersistentMetadataPropertiesRow > for DocumentNodePersistentMetadata {
64+ impl From < DocumentNodePersistentMetadataPropertiesRow > for DocumentNodePersistentMetadataHasPrimaryOutput {
6365 fn from ( old : DocumentNodePersistentMetadataPropertiesRow ) -> Self {
6466 let mut input_metadata = Vec :: new ( ) ;
6567 for properties_row in old. input_properties {
@@ -73,10 +75,12 @@ impl From<DocumentNodePersistentMetadataPropertiesRow> for DocumentNodePersisten
7375 ..Default :: default ( )
7476 } )
7577 }
76- DocumentNodePersistentMetadata {
78+ DocumentNodePersistentMetadataHasPrimaryOutput {
79+ reference : old. reference ,
7780 display_name : old. display_name ,
7881 input_metadata : Vec :: new ( ) ,
7982 output_names : old. output_names ,
83+ has_primary_output : old. has_primary_output ,
8084 locked : old. locked ,
8185 pinned : old. pinned ,
8286 node_type_metadata : old. node_type_metadata ,
@@ -102,9 +106,10 @@ pub struct DocumentNodePersistentMetadataHasPrimaryOutput {
102106 pub network_metadata : Option < NodeNetworkMetadata > ,
103107}
104108
105- impl From < DocumentNodePersistentMetadataHasPrimaryOutput > for DocumentNodePersistentMetadata {
109+ impl From < DocumentNodePersistentMetadataHasPrimaryOutput > for DocumentNodePersistentMetadataStringReference {
106110 fn from ( old : DocumentNodePersistentMetadataHasPrimaryOutput ) -> Self {
107- DocumentNodePersistentMetadata {
111+ DocumentNodePersistentMetadataStringReference {
112+ reference : old. reference ,
108113 display_name : old. display_name ,
109114 input_metadata : old. input_metadata ,
110115 output_names : old. output_names ,
@@ -133,6 +138,7 @@ struct DocumentNodePersistentMetadataStringReference {
133138
134139impl From < DocumentNodePersistentMetadataStringReference > for DocumentNodePersistentMetadata {
135140 fn from ( mut old : DocumentNodePersistentMetadataStringReference ) -> Self {
141+ log:: debug!( "Converting from DocumentNodePersistentMetadataStringReference with reference: {:?}" , old. reference) ;
136142 if let Some ( metadata) = old. network_metadata . as_mut ( ) {
137143 metadata. persistent_metadata . reference = old. reference ;
138144 }
@@ -148,27 +154,57 @@ impl From<DocumentNodePersistentMetadataStringReference> for DocumentNodePersist
148154 }
149155}
150156
157+ #[ derive( serde:: Deserialize ) ]
158+ #[ serde( untagged) ]
159+ enum DocumentNodePersistentMetadataVersioned {
160+ // Newest first
161+ Current ( DocumentNodePersistentMetadata ) ,
162+
163+ StringReference ( DocumentNodePersistentMetadataStringReference ) ,
164+
165+ HasPrimaryOutput ( DocumentNodePersistentMetadataHasPrimaryOutput ) ,
166+
167+ PropertiesRow ( DocumentNodePersistentMetadataPropertiesRow ) ,
168+
169+ InputNames ( DocumentNodePersistentMetadataInputNames ) ,
170+ }
171+
151172pub fn deserialize_node_persistent_metadata < ' de , D > ( deserializer : D ) -> Result < DocumentNodePersistentMetadata , D :: Error >
152173where
153174 D : serde:: Deserializer < ' de > ,
154175{
155176 use serde:: Deserialize ;
156177
157178 let value = Value :: deserialize ( deserializer) ?;
158- if let Ok ( document) = serde_json:: from_value :: < DocumentNodePersistentMetadata > ( value. clone ( ) ) {
159- return Ok ( document) ;
160- } ;
161- if let Ok ( document) = serde_json:: from_value :: < DocumentNodePersistentMetadataHasPrimaryOutput > ( value. clone ( ) ) {
162- return Ok ( document. into ( ) ) ;
163- } ;
164- if let Ok ( document) = serde_json:: from_value :: < DocumentNodePersistentMetadataPropertiesRow > ( value. clone ( ) ) {
165- return Ok ( document. into ( ) ) ;
166- } ;
167- if let Ok ( document) = serde_json:: from_value :: < DocumentNodePersistentMetadataStringReference > ( value. clone ( ) ) {
168- return Ok ( document. into ( ) ) ;
179+
180+ let versioned_document = serde_json:: from_value :: < DocumentNodePersistentMetadataVersioned > ( value) . map_err ( serde:: de:: Error :: custom) ?;
181+
182+ let current: DocumentNodePersistentMetadata = match versioned_document {
183+ DocumentNodePersistentMetadataVersioned :: Current ( v) => v,
184+
185+ DocumentNodePersistentMetadataVersioned :: StringReference ( v) => {
186+ let v: DocumentNodePersistentMetadataStringReference = v;
187+ v. into ( )
188+ }
189+
190+ DocumentNodePersistentMetadataVersioned :: HasPrimaryOutput ( v) => {
191+ let v: DocumentNodePersistentMetadataStringReference = v. into ( ) ;
192+ v. into ( )
193+ }
194+
195+ DocumentNodePersistentMetadataVersioned :: PropertiesRow ( v) => {
196+ let v: DocumentNodePersistentMetadataHasPrimaryOutput = v. into ( ) ;
197+ let v: DocumentNodePersistentMetadataStringReference = v. into ( ) ;
198+ v. into ( )
199+ }
200+
201+ DocumentNodePersistentMetadataVersioned :: InputNames ( v) => {
202+ let v: DocumentNodePersistentMetadataPropertiesRow = v. into ( ) ;
203+ let v: DocumentNodePersistentMetadataHasPrimaryOutput = v. into ( ) ;
204+ let v: DocumentNodePersistentMetadataStringReference = v. into ( ) ;
205+ v. into ( )
206+ }
169207 } ;
170- match serde_json:: from_value :: < DocumentNodePersistentMetadataInputNames > ( value. clone ( ) ) {
171- Ok ( document) => Ok ( document. into ( ) ) ,
172- Err ( e) => Err ( serde:: de:: Error :: custom ( e) ) ,
173- }
208+
209+ Ok ( current)
174210}
0 commit comments