@@ -6,44 +6,40 @@ const path = require('path');
66const tmp = require ( 'tmp-promise' ) ;
77
88class Models {
9- #modelsPath;
10- #binPath;
11- #models = [ ] ;
12- #cb;
13-
149 constructor ( modelsPath , binPath , cb ) {
15- this . #modelsPath = modelsPath ;
16- this . #binPath = binPath ;
17- this . #cb = cb ;
10+ this . _modelsPath = modelsPath ;
11+ this . _binPath = binPath ;
12+ this . _cb = cb ;
13+ this . _models = [ ] ;
1814 const onChange = async ( ) => {
1915 try {
20- var items = await fsp . readdir ( this . #modelsPath , { withFileTypes : true } ) ;
16+ var items = await fsp . readdir ( this . _modelsPath , { withFileTypes : true } ) ;
2117 } catch ( err ) {
2218 console . error ( 'Error during readdir' , err ) ;
2319 var items = [ ] ;
2420 }
2521 const models = items . filter ( entry => entry . isDirectory ( ) ) . map ( entry => entry . name ) . sort ( ) ;
26- if ( models . length !== this . #models . length || models . some ( ( value , index ) => value !== this . #models [ index ] ) ) {
22+ if ( models . length !== this . _models . length || models . some ( ( value , index ) => value !== this . _models [ index ] ) ) {
2723 // if array changed
28- this . #models = models ;
29- this . #cb ( this . #models ) ;
24+ this . _models = models ;
25+ this . _cb ( this . _models ) ;
3026 }
3127 } ;
32- fs . watch ( this . #modelsPath , { persistent : false } , onChange ) ;
28+ fs . watch ( this . _modelsPath , { persistent : false } , onChange ) ;
3329 onChange ( ) ;
3430 }
3531
3632 get models ( ) {
37- return this . #models ;
33+ return this . _models ;
3834 }
3935
4036 async loadModel ( name ) {
41- const mopedPath = path . join ( this . #binPath , 'moped' ) ;
42- const topologyFile = path . join ( this . #modelsPath , name , 'topo.xml' ) ;
43- const routingFile = path . join ( this . #modelsPath , name , 'routing.xml' ) ;
37+ const mopedPath = path . join ( this . _binPath , 'moped' ) ;
38+ const topologyFile = path . join ( this . _modelsPath , name , 'topo.xml' ) ;
39+ const routingFile = path . join ( this . _modelsPath , name , 'routing.xml' ) ;
4440 var stdout , stderr ;
4541 try {
46- ( { stdout, stderr } = await execFile ( path . join ( this . #binPath , 'aalwines' ) ,
42+ ( { stdout, stderr } = await execFile ( path . join ( this . _binPath , 'aalwines' ) ,
4743 [ '--topology' , topologyFile , '--routing' , routingFile , '--net' ] ,
4844 { env : { MOPED_PATH : mopedPath } }
4945 ) ) ;
@@ -55,22 +51,22 @@ class Models {
5551 }
5652
5753 async doQuery ( model , query , options ) {
58- const mopedPath = path . join ( this . #binPath , 'moped' ) ;
59- const topologyFile = path . join ( this . #modelsPath , model , 'topo.xml' ) ;
60- const routingFile = path . join ( this . #modelsPath , model , 'routing.xml' ) ;
54+ const mopedPath = path . join ( this . _binPath , 'moped' ) ;
55+ const topologyFile = path . join ( this . _modelsPath , model , 'topo.xml' ) ;
56+ const routingFile = path . join ( this . _modelsPath , model , 'routing.xml' ) ;
6157 var stdout , stderr ;
6258 await tmp . withFile ( async ( { path : tmpQueryFile } ) => {
6359 await fsp . writeFile ( tmpQueryFile , query ) ;
6460 try {
65- ( { stdout, stderr } = await execFile ( path . join ( this . #binPath , 'aalwines' ) ,
61+ ( { stdout, stderr } = await execFile ( path . join ( this . _binPath , 'aalwines' ) ,
6662 [ '--topology' , topologyFile , '--routing' , routingFile , '-e' , options . engine , '-t' , '-q' , tmpQueryFile ] ,
6763 { env : { MOPED_PATH : mopedPath } }
6864 ) ) ;
6965 } catch ( err ) {
7066 console . error ( 'loadModel error' , model , err ) ;
7167 throw err . toString ( ) ;
7268 }
73- } , { discardDescriptor : true /*, dir: path.join(this.#modelsPath , model)*/ } ) ;
69+ } , { discardDescriptor : true /*, dir: path.join(this._modelsPath , model)*/ } ) ;
7470 return JSON . parse ( stdout ) ;
7571 }
7672}
0 commit comments