@@ -56,20 +56,28 @@ class Model {
5656 }
5757}
5858
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 ) ;
6169}
62- debug . adapter = ( level , ... args ) => {
70+ debug . adapter = ( level , message , meta ) => {
6371 switch ( level ) {
6472 case 'warn' :
65- console . warn ( ... args ) ;
73+ console . warn ( message , meta ) ;
6674 break ;
6775 case 'error' :
68- console . error ( ... args ) ;
76+ console . error ( message , meta ) ;
6977 break ;
7078 case 'info' :
7179 default :
72- console . log ( ... args ) ;
80+ console . log ( message , meta ) ;
7381 break ;
7482 }
7583} ;
@@ -139,7 +147,7 @@ class Parser {
139147 return new Proxy ( instance , {
140148 get : function ( target , prop ) {
141149 if ( prop === "$_partial" ) {
142- return target [ prop ] ;
150+ return true ;
143151 }
144152 if ( prop in target ) {
145153 return target [ prop ] ;
@@ -148,7 +156,7 @@ class Parser {
148156 debug ( 'error' , `Trying to call property "${ propString } " to a model that is not included. Add "${ loadedElement . type } " to included models.` , {
149157 model : instance ,
150158 property : propString ,
151- type : ' ACCESSING_NOT_INCLUDED_MODEL'
159+ type : DEBUG . ACCESSING_NOT_INCLUDED_MODEL
152160 } ) ;
153161 return target [ prop ] ;
154162 }
@@ -162,7 +170,10 @@ class Parser {
162170 instance [ parser . key ] = parser . parser ( this . parse ( relation , included ) ) ;
163171 } else {
164172 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+ } ) ;
166177 }
167178 }
168179 if ( relsData ) {
@@ -172,7 +183,10 @@ class Parser {
172183 if ( "default" in parser ) {
173184 instance [ parser . key ] = parser . default ;
174185 } 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+ } ) ;
176190 }
177191 }
178192 }
@@ -185,7 +199,10 @@ class Parser {
185199 instance [ parser . key ] = parser . parser ( loadedElement . attributes [ key ] ) ;
186200 } else {
187201 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+ } ) ;
189206 }
190207 }
191208 if ( attrData ) {
@@ -195,7 +212,10 @@ class Parser {
195212 if ( "default" in parser ) {
196213 instance [ parser . key ] = parser . default ;
197214 } 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+ } ) ;
199219 }
200220 }
201221 }
@@ -204,7 +224,10 @@ class Parser {
204224 static load ( element , included ) {
205225 const found = included . find ( e => e . id == element . id && e . type === element . type ) ;
206226 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+ } ) ;
208231 }
209232 return found || {
210233 ...element ,
@@ -265,4 +288,4 @@ function JSONAPI(type) {
265288 } ;
266289}
267290
268- export { Attr , JSONAPI , Model , Parser , Rel , debug } ;
291+ export { Attr , DEBUG , JSONAPI , Model , Parser , Rel , debug } ;
0 commit comments