11const { clone } = require ( './modelClone' ) ;
2- const { asArray } = require ( '../utils/objectUtils' ) ;
32const { bindKnex } = require ( './modelBindKnex' ) ;
43const { validate } = require ( './modelValidate' ) ;
54const { isMsSql } = require ( '../utils/knexUtils' ) ;
@@ -9,6 +8,7 @@ const { hasId, getSetId } = require('./modelId');
98const { toJson, toDatabaseJson } = require ( './modelToJson' ) ;
109const { values, propKey, hasProps } = require ( './modelValues' ) ;
1110const { defineNonEnumerableProperty } = require ( './modelUtils' ) ;
11+ const { asArray, isFunction, isString } = require ( '../utils/objectUtils' ) ;
1212const { parseRelationsIntoModelInstances } = require ( './modelParseRelations' ) ;
1313const { fetchTableMetadata, tableMetadata } = require ( './modelTableMetadata' ) ;
1414const { setJson, setFast, setRelated, appendRelated, setDatabaseJson } = require ( './modelSet' ) ;
@@ -337,7 +337,7 @@ class Model {
337337 } ) ;
338338 }
339339
340- static createNotFoundError ( ctx ) {
340+ static createNotFoundError ( ) {
341341 return new this . NotFoundError ( ) ;
342342 }
343343
@@ -348,11 +348,11 @@ class Model {
348348 static getTableName ( ) {
349349 let tableName = this . tableName ;
350350
351- if ( typeof tableName === 'function' ) {
351+ if ( isFunction ( tableName ) ) {
352352 tableName = this . tableName ( ) ;
353353 }
354354
355- if ( typeof tableName !== 'string' ) {
355+ if ( ! isString ( tableName ) ) {
356356 throw new Error ( `Model ${ this . name } must have a static property tableName` ) ;
357357 }
358358
@@ -362,7 +362,7 @@ class Model {
362362 static getIdColumn ( ) {
363363 let idColumn = this . idColumn ;
364364
365- if ( typeof idColumn === 'function' ) {
365+ if ( isFunction ( idColumn ) ) {
366366 idColumn = this . idColumn ( ) ;
367367 }
368368
@@ -394,7 +394,7 @@ class Model {
394394 return 4 ;
395395 }
396396 } else {
397- if ( typeof this . concurrency === 'function' ) {
397+ if ( isFunction ( this . concurrency ) ) {
398398 return this . concurrency ( ) ;
399399 } else {
400400 return this . concurrency ;
@@ -586,7 +586,7 @@ class Model {
586586 filterConstructor = null ;
587587 }
588588
589- if ( typeof traverser !== 'function' ) {
589+ if ( ! isFunction ( traverser ) ) {
590590 throw new Error ( 'traverser must be a function' ) ;
591591 }
592592
@@ -701,14 +701,14 @@ function getReadOnlyVirtualAttributes(modelClass) {
701701 return false ;
702702 }
703703
704- return ( desc . get && ! desc . set ) || desc . writable === false || typeof desc . value === 'function' ;
704+ return ( desc . get && ! desc . set ) || desc . writable === false || isFunction ( desc . value ) ;
705705 } ) ;
706706}
707707
708708function getRelations ( modelClass ) {
709709 let relationMappings = modelClass . relationMappings ;
710710
711- if ( typeof relationMappings === 'function' ) {
711+ if ( isFunction ( relationMappings ) ) {
712712 relationMappings = relationMappings . call ( modelClass ) ;
713713 }
714714
0 commit comments