@@ -56,20 +56,28 @@ class Model {
56
56
}
57
57
}
58
58
59
- function debug ( level , ...args ) {
60
- debug . adapter ( level , ...args ) ;
59
+ const DEBUG = {
60
+ ACCESSING_NOT_INCLUDED_MODEL : 'ACCESSING_NOT_INCLUDED_MODEL' ,
61
+ UNDECLARED_RELATIONSHOP : 'UNDECLARED_RELATIONSHOP' ,
62
+ MISSING_RELATIONSHIP : 'MISSING_RELATIONSHIP' ,
63
+ UNDECLARED_ATTRIBUTE : 'UNDECLARED_ATTRIBUTE' ,
64
+ MISSING_ATTRIBUTE : 'MISSING_ATTRIBUTE' ,
65
+ SKIPPED_INCLUDED_RELATIONSHIP : 'SKIPPED_INCLUDED_RELATIONSHIP'
66
+ } ;
67
+ function debug ( level , message , meta ) {
68
+ debug . adapter ( level , message , meta ) ;
61
69
}
62
- debug . adapter = ( level , ... args ) => {
70
+ debug . adapter = ( level , message , meta ) => {
63
71
switch ( level ) {
64
72
case 'warn' :
65
- console . warn ( ... args ) ;
73
+ console . warn ( message , meta ) ;
66
74
break ;
67
75
case 'error' :
68
- console . error ( ... args ) ;
76
+ console . error ( message , meta ) ;
69
77
break ;
70
78
case 'info' :
71
79
default :
72
- console . log ( ... args ) ;
80
+ console . log ( message , meta ) ;
73
81
break ;
74
82
}
75
83
} ;
@@ -139,7 +147,7 @@ class Parser {
139
147
return new Proxy ( instance , {
140
148
get : function ( target , prop ) {
141
149
if ( prop === "$_partial" ) {
142
- return target [ prop ] ;
150
+ return true ;
143
151
}
144
152
if ( prop in target ) {
145
153
return target [ prop ] ;
@@ -148,7 +156,7 @@ class Parser {
148
156
debug ( 'error' , `Trying to call property "${ propString } " to a model that is not included. Add "${ loadedElement . type } " to included models.` , {
149
157
model : instance ,
150
158
property : propString ,
151
- type : ' ACCESSING_NOT_INCLUDED_MODEL'
159
+ type : DEBUG . ACCESSING_NOT_INCLUDED_MODEL
152
160
} ) ;
153
161
return target [ prop ] ;
154
162
}
@@ -162,7 +170,10 @@ class Parser {
162
170
instance [ parser . key ] = parser . parser ( this . parse ( relation , included ) ) ;
163
171
} else {
164
172
instance [ key ] = this . parse ( relation , included ) ;
165
- debug ( 'warn' , `Undeclared relationship "${ key } " in "${ loadedElement . type } "` ) ;
173
+ debug ( 'warn' , `Undeclared relationship "${ key } " in "${ loadedElement . type } "` , {
174
+ relationship : key ,
175
+ type : DEBUG . UNDECLARED_RELATIONSHOP
176
+ } ) ;
166
177
}
167
178
}
168
179
if ( relsData ) {
@@ -172,7 +183,10 @@ class Parser {
172
183
if ( "default" in parser ) {
173
184
instance [ parser . key ] = parser . default ;
174
185
} else {
175
- debug ( 'warn' , `Missing relationships "${ key } " in "${ loadedElement . type } "` ) ;
186
+ debug ( 'warn' , `Missing relationships "${ key } " in "${ loadedElement . type } "` , {
187
+ relationship : key ,
188
+ type : DEBUG . MISSING_RELATIONSHIP
189
+ } ) ;
176
190
}
177
191
}
178
192
}
@@ -185,7 +199,10 @@ class Parser {
185
199
instance [ parser . key ] = parser . parser ( loadedElement . attributes [ key ] ) ;
186
200
} else {
187
201
instance [ key ] = loadedElement . attributes [ key ] ;
188
- debug ( 'warn' , `Undeclared key "${ key } " in "${ loadedElement . type } "` ) ;
202
+ debug ( 'warn' , `Undeclared @Attr() "${ key } " in model "${ loadedElement . type } "` , {
203
+ attribute : key ,
204
+ type : DEBUG . UNDECLARED_ATTRIBUTE
205
+ } ) ;
189
206
}
190
207
}
191
208
if ( attrData ) {
@@ -195,7 +212,10 @@ class Parser {
195
212
if ( "default" in parser ) {
196
213
instance [ parser . key ] = parser . default ;
197
214
} else {
198
- debug ( 'warn' , `Missing attribute "${ key } " in "${ loadedElement . type } "` ) ;
215
+ debug ( 'warn' , `Missing attribute "${ key } " in "${ loadedElement . type } "` , {
216
+ attribute : key ,
217
+ type : DEBUG . MISSING_ATTRIBUTE
218
+ } ) ;
199
219
}
200
220
}
201
221
}
@@ -204,7 +224,10 @@ class Parser {
204
224
static load ( element , included ) {
205
225
const found = included . find ( e => e . id == element . id && e . type === element . type ) ;
206
226
if ( ! found ) {
207
- debug ( 'info' , `Relationship with type ${ element . type } with id ${ element . id } not present in included` ) ;
227
+ debug ( 'info' , `Relationship with type ${ element . type } with id ${ element . id } not present in included. Skipping...` , {
228
+ model : element ,
229
+ type : DEBUG . SKIPPED_INCLUDED_RELATIONSHIP
230
+ } ) ;
208
231
}
209
232
return found || {
210
233
...element ,
@@ -265,4 +288,4 @@ function JSONAPI(type) {
265
288
} ;
266
289
}
267
290
268
- export { Attr , JSONAPI , Model , Parser , Rel , debug } ;
291
+ export { Attr , DEBUG , JSONAPI , Model , Parser , Rel , debug } ;
0 commit comments