66 isDateType ,
77 isNumberType ,
88 getInnerType ,
9- getStructTypes
9+ getStructTypes ,
10+ isStructType
1011} from "./dataTypes" ;
1112import { hydrateDate } from "./hydrateDate" ;
1213
@@ -22,26 +23,38 @@ const hydrateInfNan = (value: string) => {
2223 return NaN ;
2324} ;
2425
26+ const hydrateStruct = (
27+ value : Record < string , unknown > ,
28+ type : string ,
29+ executeQueryOptions : ExecuteQueryOptions
30+ ) : Record < string , unknown > => {
31+ const hydratedStruct : Record < string , unknown > = { } ;
32+ const innerTypes = getStructTypes ( type ) ;
33+ // if number of keys does not match, return value as is
34+ if ( Object . keys ( innerTypes ) . length !== Object . keys ( value ) . length ) {
35+ return value ;
36+ }
37+ for ( const [ key , innerType ] of Object . entries ( innerTypes ) ) {
38+ hydratedStruct [ key ] = getHydratedValue (
39+ value [ key ] ,
40+ innerType ,
41+ executeQueryOptions
42+ ) ;
43+ }
44+ return hydratedStruct ;
45+ } ;
46+
2547const getHydratedValue = (
2648 value : unknown ,
2749 type : string ,
2850 executeQueryOptions : ExecuteQueryOptions
2951) : any => {
30- if ( typeof value === "object" && value !== null && ! Array . isArray ( value ) ) {
31- const hydratedStruct : Record < string , unknown > = { } ;
32- const innerTypes = getStructTypes ( type ) ;
33- // if number of keys does not match, return value as is
34- if ( Object . keys ( innerTypes ) . length !== Object . keys ( value ) . length ) {
35- return value ;
36- }
37- for ( const [ key , innerType ] of Object . entries ( innerTypes ) ) {
38- hydratedStruct [ key ] = getHydratedValue (
39- ( value as Record < string , unknown > ) [ key ] ,
40- innerType ,
41- executeQueryOptions
42- ) ;
43- }
44- return hydratedStruct ;
52+ if ( isStructType ( type ) ) {
53+ return hydrateStruct (
54+ value as Record < string , unknown > ,
55+ type ,
56+ executeQueryOptions
57+ ) ;
4558 }
4659 if ( Array . isArray ( value ) ) {
4760 const innerType = getInnerType ( type ) ;
0 commit comments