@@ -39,17 +39,21 @@ export class JsonParseNode implements ParseNode {
39
39
typeof this . _jsonNode === "object" &&
40
40
( this . _jsonNode as { [ key : string ] : any } ) [ identifier ] !== undefined
41
41
? new JsonParseNode (
42
- ( this . _jsonNode as { [ key : string ] : any } ) [ identifier ] ,
42
+ ( this . _jsonNode as { [ key : string ] : any } ) [ identifier ]
43
43
)
44
44
: undefined ;
45
45
public getBooleanValue = ( ) => this . _jsonNode as boolean ;
46
46
public getNumberValue = ( ) => this . _jsonNode as number ;
47
47
public getGuidValue = ( ) => parseGuidString ( this . getStringValue ( ) ) ;
48
- public getDateValue = ( ) => this . _jsonNode ? new Date ( this . _jsonNode as string ) : undefined ;
48
+ public getDateValue = ( ) =>
49
+ this . _jsonNode ? new Date ( this . _jsonNode as string ) : undefined ;
49
50
public getDateOnlyValue = ( ) => DateOnly . parse ( this . getStringValue ( ) ) ;
50
51
public getTimeOnlyValue = ( ) => TimeOnly . parse ( this . getStringValue ( ) ) ;
51
52
public getDurationValue = ( ) => Duration . parse ( this . getStringValue ( ) ) ;
52
53
public getCollectionOfPrimitiveValues = < T > ( ) : T [ ] | undefined => {
54
+ if ( ! Array . isArray ( this . _jsonNode ) ) {
55
+ return undefined ;
56
+ }
53
57
return ( this . _jsonNode as unknown [ ] ) . map ( ( x ) => {
54
58
const currentParseNode = new JsonParseNode ( x ) ;
55
59
const typeOfX = typeof x ;
@@ -69,7 +73,7 @@ export class JsonParseNode implements ParseNode {
69
73
return currentParseNode . getDateValue ( ) as unknown as T ;
70
74
} else {
71
75
throw new Error (
72
- `encountered an unknown type during deserialization ${ typeof x } ` ,
76
+ `encountered an unknown type during deserialization ${ typeof x } `
73
77
) ;
74
78
}
75
79
} ) ;
@@ -82,15 +86,20 @@ export class JsonParseNode implements ParseNode {
82
86
return undefined ;
83
87
}
84
88
public getCollectionOfObjectValues = < T extends Parsable > (
85
- method : ParsableFactory < T > ,
89
+ method : ParsableFactory < T >
86
90
) : T [ ] | undefined => {
87
- return this . _jsonNode ? ( this . _jsonNode as unknown [ ] )
88
- . map ( ( x ) => new JsonParseNode ( x ) )
89
- . map ( ( x ) => x . getObjectValue < T > ( method ) ) : undefined ;
91
+ if ( ! Array . isArray ( this . _jsonNode ) ) {
92
+ return undefined ;
93
+ }
94
+ return this . _jsonNode
95
+ ? ( this . _jsonNode as unknown [ ] )
96
+ . map ( ( x ) => new JsonParseNode ( x ) )
97
+ . map ( ( x ) => x . getObjectValue < T > ( method ) )
98
+ : undefined ;
90
99
} ;
91
100
92
101
public getObjectValue = < T extends Parsable > (
93
- parsableFactory : ParsableFactory < T > ,
102
+ parsableFactory : ParsableFactory < T >
94
103
) : T => {
95
104
const temp : T = { } as T ;
96
105
if ( isUntypedNode ( parsableFactory ( this ) ( temp ) ) ) {
@@ -108,16 +117,16 @@ export class JsonParseNode implements ParseNode {
108
117
( this . _jsonNode as any [ ] ) . forEach ( ( x ) => {
109
118
nodes . push (
110
119
new JsonParseNode ( x ) . getObjectValue (
111
- createUntypedNodeFromDiscriminatorValue ,
112
- ) ,
120
+ createUntypedNodeFromDiscriminatorValue
121
+ )
113
122
) ;
114
123
} ) ;
115
124
value = createUntypedArray ( nodes ) as any as T ;
116
125
} else if ( this . _jsonNode && valueType === "object" ) {
117
126
const properties : Record < string , UntypedNode > = { } ;
118
127
Object . entries ( this . _jsonNode as any ) . forEach ( ( [ k , v ] ) => {
119
128
properties [ k ] = new JsonParseNode ( v ) . getObjectValue (
120
- createUntypedNodeFromDiscriminatorValue ,
129
+ createUntypedNodeFromDiscriminatorValue
121
130
) ;
122
131
} ) ;
123
132
value = createUntypedObject ( properties ) as any as T ;
@@ -126,8 +135,12 @@ export class JsonParseNode implements ParseNode {
126
135
}
127
136
return value ;
128
137
}
129
- const enableBackingStore = isBackingStoreEnabled ( parsableFactory ( this ) ( temp ) ) ;
130
- const value : T = enableBackingStore ? new Proxy ( temp , createBackedModelProxyHandler < T > ( ) ) : temp ;
138
+ const enableBackingStore = isBackingStoreEnabled (
139
+ parsableFactory ( this ) ( temp )
140
+ ) ;
141
+ const value : T = enableBackingStore
142
+ ? new Proxy ( temp , createBackedModelProxyHandler < T > ( ) )
143
+ : temp ;
131
144
if ( this . onBeforeAssignFieldValues ) {
132
145
this . onBeforeAssignFieldValues ( value ) ;
133
146
}
@@ -140,7 +153,7 @@ export class JsonParseNode implements ParseNode {
140
153
141
154
private assignFieldValues = < T extends Parsable > (
142
155
model : T ,
143
- parsableFactory : ParsableFactory < T > ,
156
+ parsableFactory : ParsableFactory < T >
144
157
) : void => {
145
158
const fields = parsableFactory ( this ) ( model ) ;
146
159
if ( ! this . _jsonNode ) return ;
0 commit comments