@@ -83,9 +83,9 @@ function flatten(obj, useProperties) {
8383 let val = walk ( obj , key ) ;
8484 if ( typeof val === 'object' && ! Array . isArray ( val ) && val != null ) {
8585 if ( useProperties ) {
86- if ( 'properties ' in val ) {
87- val = val . properties ;
88- key = key + '.properties ' ;
86+ if ( '_cvtProperties ' in val ) {
87+ val = val . _cvtProperties ;
88+ key = key + '._cvtProperties ' ;
8989 } else {
9090 entries . push ( [ key , val ] ) ;
9191 continue ;
@@ -108,7 +108,7 @@ function flatten(obj, useProperties) {
108108 entries . forEach ( function ( entry ) {
109109 let key = entry [ 0 ] ;
110110 if ( useProperties ) {
111- key = key . replace ( / \. p r o p e r t i e s / g, '' ) ;
111+ key = key . replace ( / \. _ c v t P r o p e r t i e s / g, '' ) ;
112112 }
113113 const val = entry [ 1 ] ;
114114 flattened [ key ] = val ;
@@ -125,7 +125,7 @@ function validate(instance, schema, strictValidation) {
125125 } ;
126126
127127 const flatInstance = flatten ( instance ) ;
128- const flatSchema = flatten ( schema . properties , true ) ;
128+ const flatSchema = flatten ( schema . _cvtProperties , true ) ;
129129
130130 Object . keys ( flatSchema ) . forEach ( function ( name ) {
131131 const schemaItem = flatSchema [ name ] ;
@@ -202,14 +202,18 @@ const BUILT_INS = BUILT_IN_NAMES.map(function(name) {
202202} ) ;
203203
204204function normalizeSchema ( name , node , props , fullName , env , argv , sensitive ) {
205+ if ( name === '_cvtProperties' ) {
206+ throw new Error ( "'" + fullName + "': '_cvtProperties' is reserved word of convict." ) ;
207+ }
208+
205209 // If the current schema node is not a config property (has no "default"), recursively normalize it.
206210 if ( typeof node === 'object' && node !== null && ! Array . isArray ( node ) &&
207211 Object . keys ( node ) . length > 0 && ! ( 'default' in node ) ) {
208212 props [ name ] = {
209- properties : { }
213+ _cvtProperties : { }
210214 } ;
211215 Object . keys ( node ) . forEach ( function ( k ) {
212- normalizeSchema ( k , node [ k ] , props [ name ] . properties , fullName + '.' +
216+ normalizeSchema ( k , node [ k ] , props [ name ] . _cvtProperties , fullName + '.' +
213217 k , env , argv , sensitive ) ;
214218 } ) ;
215219 return ;
@@ -328,9 +332,9 @@ function importArguments(o) {
328332}
329333
330334function addDefaultValues ( schema , c , instance ) {
331- Object . keys ( schema . properties ) . forEach ( function ( name ) {
332- let p = schema . properties [ name ] ;
333- if ( p . properties ) {
335+ Object . keys ( schema . _cvtProperties ) . forEach ( function ( name ) {
336+ let p = schema . _cvtProperties [ name ] ;
337+ if ( p . _cvtProperties ) {
334338 let kids = c [ name ] || { } ;
335339 addDefaultValues ( p , kids , instance ) ;
336340 c [ name ] = kids ;
@@ -349,7 +353,7 @@ function overlay(from, to, schema) {
349353 to [ k ] = coerce ( k , from [ k ] , schema ) ;
350354 } else {
351355 if ( ! isObj ( to [ k ] ) ) to [ k ] = { } ;
352- overlay ( from [ k ] , to [ k ] , schema . properties [ k ] ) ;
356+ overlay ( from [ k ] , to [ k ] , schema . _cvtProperties [ k ] ) ;
353357 }
354358 } ) ;
355359}
@@ -359,8 +363,8 @@ function traverseSchema(schema, path) {
359363 let o = schema ;
360364 while ( ar . length > 0 ) {
361365 let k = ar . shift ( ) ;
362- if ( o && o . properties && o . properties [ k ] ) {
363- o = o . properties [ k ] ;
366+ if ( o && o . _cvtProperties && o . _cvtProperties [ k ] ) {
367+ o = o . _cvtProperties [ k ] ;
364368 } else {
365369 o = null ;
366370 break ;
@@ -510,10 +514,10 @@ let convict = function convict(def, opts) {
510514 * notation to reference nested values
511515 */
512516 default : function ( path ) {
513- // The default value for FOO.BAR.BAZ is stored in `_schema.properties ` at:
514- // FOO.properties .BAR.properties .BAZ.default
515- path = ( path . split ( '.' ) . join ( '.properties .' ) ) + '.default' ;
516- let o = walk ( this . _schema . properties , path ) ;
517+ // The default value for FOO.BAR.BAZ is stored in `_schema._cvtProperties ` at:
518+ // FOO._cvtProperties .BAR._cvtProperties .BAZ.default
519+ path = ( path . split ( '.' ) . join ( '._cvtProperties .' ) ) + '.default' ;
520+ let o = walk ( this . _schema . _cvtProperties , path ) ;
517521 return cloneDeep ( o ) ;
518522 } ,
519523
@@ -661,15 +665,15 @@ let convict = function convict(def, opts) {
661665
662666 // build up current config from definition
663667 rv . _schema = {
664- properties : { }
668+ _cvtProperties : { }
665669 } ;
666670
667671 rv . _env = { } ;
668672 rv . _argv = { } ;
669673 rv . _sensitive = new Set ( ) ;
670674
671675 Object . keys ( rv . _def ) . forEach ( function ( k ) {
672- normalizeSchema ( k , rv . _def [ k ] , rv . _schema . properties , k , rv . _env , rv . _argv ,
676+ normalizeSchema ( k , rv . _def [ k ] , rv . _schema . _cvtProperties , k , rv . _env , rv . _argv ,
673677 rv . _sensitive ) ;
674678 } ) ;
675679
0 commit comments