@@ -79,6 +79,18 @@ function validatePropertyValue(objType, metaData, value, index) {
7979// instantiated; a cache of these classes are maintained on each connection
8080class BaseDbObject {
8181
82+ //---------------------------------------------------------------------------
83+ // _ensureCollection()
84+ //
85+ // Ensures that the object is a collection.
86+ //---------------------------------------------------------------------------
87+ _ensureCollection ( ) {
88+ if ( ! this . isCollection ) {
89+ errors . throwErr ( errors . ERR_OBJECT_IS_NOT_A_COLLECTION ,
90+ this . name ) ;
91+ }
92+ }
93+
8294 //---------------------------------------------------------------------------
8395 // _getAttrValue()
8496 //
@@ -165,6 +177,7 @@ class BaseDbObject {
165177 //---------------------------------------------------------------------------
166178 append ( value ) {
167179 errors . assertArgCount ( arguments , 1 , 1 ) ;
180+ this . _ensureCollection ( ) ;
168181 const info = {
169182 fqn : this . _objType . fqn ,
170183 type : this . _objType . elementType ,
@@ -238,6 +251,7 @@ class BaseDbObject {
238251 //---------------------------------------------------------------------------
239252 deleteElement ( index ) {
240253 errors . assertArgCount ( arguments , 1 , 1 ) ;
254+ this . _ensureCollection ( ) ;
241255 errors . assertParamValue ( Number . isInteger ( index ) , 1 ) ;
242256 return this . _impl . deleteElement ( index ) ;
243257 }
@@ -300,6 +314,7 @@ class BaseDbObject {
300314 //---------------------------------------------------------------------------
301315 getElement ( index ) {
302316 errors . assertArgCount ( arguments , 1 , 1 ) ;
317+ this . _ensureCollection ( ) ;
303318 errors . assertParamValue ( Number . isInteger ( index ) , 1 ) ;
304319 const value = this . _impl . getElement ( index ) ;
305320 return this . _transformValueOut ( value , this . elementTypeClass , this . _objType . elementTypeInfo ) ;
@@ -312,6 +327,7 @@ class BaseDbObject {
312327 //---------------------------------------------------------------------------
313328 getKeys ( ) {
314329 errors . assertArgCount ( arguments , 0 , 0 ) ;
330+ this . _ensureCollection ( ) ;
315331 return this . _impl . getKeys ( ) ;
316332 }
317333
@@ -322,6 +338,7 @@ class BaseDbObject {
322338 //---------------------------------------------------------------------------
323339 getFirstIndex ( ) {
324340 errors . assertArgCount ( arguments , 0 , 0 ) ;
341+ this . _ensureCollection ( ) ;
325342 return this . _impl . getFirstIndex ( ) ;
326343 }
327344
@@ -332,6 +349,7 @@ class BaseDbObject {
332349 //---------------------------------------------------------------------------
333350 getLastIndex ( ) {
334351 errors . assertArgCount ( arguments , 0 , 0 ) ;
352+ this . _ensureCollection ( ) ;
335353 return this . _impl . getLastIndex ( ) ;
336354 }
337355
@@ -342,6 +360,7 @@ class BaseDbObject {
342360 //---------------------------------------------------------------------------
343361 getNextIndex ( index ) {
344362 errors . assertArgCount ( arguments , 1 , 1 ) ;
363+ this . _ensureCollection ( ) ;
345364 errors . assertParamValue ( Number . isInteger ( index ) , 1 ) ;
346365 return this . _impl . getNextIndex ( index ) ;
347366 }
@@ -353,6 +372,7 @@ class BaseDbObject {
353372 //---------------------------------------------------------------------------
354373 getPrevIndex ( index ) {
355374 errors . assertArgCount ( arguments , 1 , 1 ) ;
375+ this . _ensureCollection ( ) ;
356376 errors . assertParamValue ( Number . isInteger ( index ) , 1 ) ;
357377 return this . _impl . getPrevIndex ( index ) ;
358378 }
@@ -364,6 +384,7 @@ class BaseDbObject {
364384 //---------------------------------------------------------------------------
365385 getValues ( ) {
366386 errors . assertArgCount ( arguments , 0 , 0 ) ;
387+ this . _ensureCollection ( ) ;
367388 const values = this . _impl . getValues ( ) ;
368389 for ( let i = 0 ; i < values . length ; i ++ ) {
369390 values [ i ] = this . _transformValueOut ( values [ i ] , this . elementTypeClass , this . _objType . elementTypeInfo ) ;
@@ -378,6 +399,7 @@ class BaseDbObject {
378399 //---------------------------------------------------------------------------
379400 hasElement ( index ) {
380401 errors . assertArgCount ( arguments , 1 , 1 ) ;
402+ this . _ensureCollection ( ) ;
381403 errors . assertParamValue ( Number . isInteger ( index ) , 1 ) ;
382404 return this . _impl . hasElement ( index ) ;
383405 }
@@ -426,6 +448,7 @@ class BaseDbObject {
426448 //---------------------------------------------------------------------------
427449 setElement ( index , value ) {
428450 errors . assertArgCount ( arguments , 2 , 2 ) ;
451+ this . _ensureCollection ( ) ;
429452 errors . assertParamValue ( Number . isInteger ( index ) , 1 ) ;
430453 const info = {
431454 fqn : this . _objType . fqn ,
@@ -445,6 +468,7 @@ class BaseDbObject {
445468 //---------------------------------------------------------------------------
446469 trim ( numToTrim ) {
447470 errors . assertArgCount ( arguments , 1 , 1 ) ;
471+ this . _ensureCollection ( ) ;
448472 errors . assertParamValue ( Number . isInteger ( numToTrim ) && numToTrim >= 0 , 1 ) ;
449473 this . _impl . trim ( numToTrim ) ;
450474 }
@@ -487,10 +511,7 @@ class BaseDbObject {
487511 //---------------------------------------------------------------------------
488512 toMap ( ) {
489513 errors . assertArgCount ( arguments , 0 , 0 ) ;
490- if ( ! this . isCollection ) {
491- errors . throwErr ( errors . ERR_OBJECT_IS_NOT_A_COLLECTION ,
492- this . name ) ;
493- }
514+ this . _ensureCollection ( ) ;
494515 const result = new Map ( ) ;
495516 this . getKeys ( ) . forEach ( element => {
496517 result . set ( element , this . getElement ( element ) ) ;
0 commit comments