@brown-ds/distribution 0.2.21 → 0.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,5 +6,5 @@ Do NOT edit this file directly. Use it as a black box.
|
|
|
6
6
|
|
|
7
7
|
If you notice any issues with using this file, please contact the TAs.
|
|
8
8
|
*/
|
|
9
|
-
const http=require('node:http'),url=require('node:url'),log=require('../util/lo'+'g.js'),yargs=require('yargs/yarg'+'s');function setNodeConfig(){const
|
|
9
|
+
const http=require('node:http'),url=require('node:url'),log=require('../util/lo'+'g.js'),yargs=require('yargs/yarg'+'s');function setNodeConfig(){const _0x5ac1e9=yargs(process['argv'])['help'](![])['version'](![])['parse']();let _0x58b69f,_0x318377,_0x5ac937;typeof _0x5ac1e9['ip']==='string'&&(_0x58b69f=_0x5ac1e9['ip']);(typeof _0x5ac1e9['port']==='string'||typeof _0x5ac1e9['port']==='number')&&(_0x318377=parseInt(String(_0x5ac1e9['port']),-0x409*-0x1+0x22cd+-0x26cc));(_0x5ac1e9['help']===!![]||_0x5ac1e9['h']===!![])&&(console['log']('Node\x20usage'+':'),console['log']('\x20\x20--ip\x20<ip'+'\x20address>\x20'+'\x20\x20\x20\x20\x20The\x20i'+'p\x20address\x20'+'to\x20bind\x20th'+'e\x20node\x20to'),console['log']('\x20\x20--port\x20<'+'port>\x20\x20\x20\x20\x20'+'\x20\x20\x20\x20\x20The\x20p'+'ort\x20to\x20bin'+'d\x20the\x20node'+'\x20to'),console['log']('\x20\x20--config'+'\x20<config>\x20'+'\x20\x20\x20\x20\x20The\x20s'+'erialized\x20'+'config\x20str'+'ing'),process['exit'](-0xc23+0x9bf*0x1+-0x99*-0x4));if(typeof _0x5ac1e9['config']==='string'){let _0x4fe36b=undefined;try{_0x4fe36b=globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x5ac1e9['config']);}catch(_0x9d2859){try{_0x4fe36b=JSON['parse'](_0x5ac1e9['config']);}catch{console['error']('Cannot\x20des'+'erialize\x20c'+'onfig\x20stri'+'ng:\x20'+_0x5ac1e9['config']),process['exit'](0x2534*-0x1+-0xb*0x2+0x254b);}}typeof _0x4fe36b?.['ip']==='string'&&(_0x58b69f=_0x4fe36b?.['ip']),typeof _0x4fe36b?.['port']==='number'&&(_0x318377=_0x4fe36b?.['port']),typeof _0x4fe36b?.['onStart']==='function'&&(_0x5ac937=_0x4fe36b?.['onStart']);}return _0x58b69f=_0x58b69f??'127.0.0.1',_0x318377=_0x318377??-0xe73+0x7ce+-0x24b*-0x5,{'ip':_0x58b69f,'port':_0x318377,'onStart':_0x5ac937};}function validate(_0x23c72e){if(_0x23c72e['length']===0x5b5+0x1590+-0x1b45)throw new Error('No\x20body');return JSON['parse'](_0x23c72e);}function start(_0x4ea169){const _0x5df02a=http['createServ'+'er']((_0x5f8ee6,_0x189323)=>{if(_0x5f8ee6['method']!=='PUT'){_0x189323['end'](globalThis['distributi'+'on']['util']['serialize'](new Error('Method\x20not'+'\x20allowed!')));return;}const [,_0x44d9a4,_0x211999,_0x4207f6]=url['parse'](_0x5f8ee6['url'])['pathname']['split']('/');log('[server]\x20g'+'ot\x20request'+'\x20'+_0x44d9a4+'\x20'+_0x211999+':'+_0x4207f6+'\x20from\x20'+_0x5f8ee6['socket']['remoteAddr'+'ess']);const _0x24d1c6=[];_0x5f8ee6['on']('data',_0x3900dc=>{_0x24d1c6['push'](_0x3900dc);}),_0x5f8ee6['on']('end',()=>{let _0x1453e1;try{_0x1453e1=validate(Buffer['concat'](_0x24d1c6)['toString']());}catch(_0x176127){_0x189323['end'](globalThis['distributi'+'on']['util']['serialize']([_0x176127]));return;}const _0x544639=globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x1453e1);!Array['isArray'](_0x544639)&&_0x189323['end'](globalThis['distributi'+'on']['util']['serialize']([new Error('Invalid\x20ar'+'gument\x20typ'+'e,\x20expecte'+'d\x20array,\x20g'+'ot\x20'+typeof _0x544639)]));const _0x39b28a=_0x211999;globalThis['distributi'+'on']['local']['routes']['get']({'service':_0x211999,'gid':_0x44d9a4},(_0x39ce9f,_0x4f9c34)=>{if(_0x39ce9f){_0x189323['end'](globalThis['distributi'+'on']['util']['serialize']([_0x39ce9f,null]));return;}if(!_0x4f9c34[_0x4207f6]){_0x189323['end'](globalThis['distributi'+'on']['util']['serialize']([new Error('Method\x20'+_0x4207f6+('\x20not\x20found'+'\x20in\x20servic'+'e\x20')+_0x39b28a),null]));return;}log('[server]\x20\x20'+'Calling\x20se'+'rvice:\x20'+_0x39b28a+':'+_0x4207f6+('\x20with\x20args'+':\x20')+JSON['stringify'](_0x544639));_0x544639['length']===0x12d2+0x2f*-0x61+-0x102&&_0x4f9c34[_0x4207f6]['length']===-0x1c17+0x3b2+0x1868&&_0x544639['push'](undefined);const _0x40a06c=_0x4f9c34[_0x4207f6]['bind'](_0x4f9c34),_0x156f79=globalThis['distributi'+'on']['util']['normalize'](_0x40a06c,_0x544639);try{_0x40a06c(..._0x156f79,(_0x538e4a,_0x35be1c)=>_0x189323['end'](globalThis['distributi'+'on']['util']['serialize']([_0x538e4a,_0x35be1c])));}catch(_0x51a50e){_0x189323['end'](globalThis['distributi'+'on']['util']['serialize']([_0x51a50e,null]));}});});});globalThis['distributi'+'on']['node']['server']=_0x5df02a;const _0x18c49f=globalThis['distributi'+'on']['node']['config'];_0x5df02a['once']('listening',()=>{log('Server\x20run'+'ning\x20at\x20ht'+'tp://'+_0x18c49f['ip']+':'+_0x18c49f['port']+'/'),_0x4ea169(null);}),_0x5df02a['once']('error',_0x339745=>{log('Server\x20err'+'or:\x20'+_0x339745),_0x4ea169(_0x339745);}),_0x5df02a['listen'](_0x18c49f['port'],_0x18c49f['ip']);}module['exports']={'start':start,'config':setNodeConfig()};
|
|
10
10
|
/* eslint-enable */
|
|
@@ -6,5 +6,5 @@ Do NOT edit this file directly. Use it as a black box.
|
|
|
6
6
|
|
|
7
7
|
If you notice any issues with using this file, please contact the TAs.
|
|
8
8
|
*/
|
|
9
|
-
const log=require('../util/lo'+'g'),routesStore=new Map();function get(
|
|
9
|
+
const log=require('../util/lo'+'g'),routesStore=new Map();function get(_0x3b8f9b,_0xd999cf){log('[routes.ge'+'t]\x20Getting'+'\x20service:\x20'+JSON['stringify'](_0x3b8f9b));if(!_0x3b8f9b)return _0xd999cf(new Error('No\x20configu'+'ration\x20pro'+'vided!'));typeof _0x3b8f9b==='string'&&(_0x3b8f9b={'service':_0x3b8f9b});const _0x261a09=_0x3b8f9b['service'],_0x5a7a79=_0x3b8f9b['gid'];if(_0x5a7a79&&_0x5a7a79!=='local')return log('[routes.ge'+'t]\x20Found\x20d'+'istributed'+'\x20service:\x20'+_0x261a09),_0xd999cf(null,globalThis['distributi'+'on'][_0x5a7a79][_0x261a09]);else{const _0x2a941b=routesStore['get'](_0x261a09);if(_0x2a941b)return log('[routes.ge'+'t]\x20Found\x20l'+'ocal\x20servi'+'ce:\x20'+_0x261a09),_0xd999cf(null,_0x2a941b);else{const _0x7718e2=globalThis['toLocal']['get'](_0x261a09);return _0x7718e2?(log('[routes.ge'+'t]\x20Found\x20R'+'PC:\x20'+_0x261a09),_0xd999cf(null,{'call':_0x7718e2})):_0xd999cf(new Error('Service\x20'+_0x261a09+('\x20not\x20found'+'\x20in\x20routes')));}}}function put(_0x2a5b78,_0x187cc1,_0x49386c){log('[routes.pu'+'t]\x20Putting'+'\x20service:\x20'+_0x187cc1),routesStore['set'](_0x187cc1,_0x2a5b78);if(_0x49386c)return _0x49386c(null,_0x187cc1);}function rem(_0x3c28d1,_0x2f32b8){const _0x4533ce=routesStore['get'](_0x3c28d1);return routesStore['delete'](_0x3c28d1),_0x2f32b8(null,_0x4533ce);}module['exports']={'get':get,'put':put,'rem':rem};
|
|
10
10
|
/* eslint-enable */
|
|
@@ -6,5 +6,5 @@ Do NOT edit this file directly. Use it as a black box.
|
|
|
6
6
|
|
|
7
7
|
If you notice any issues with using this file, please contact the TAs.
|
|
8
8
|
*/
|
|
9
|
-
const log=require('../util/lo'+'g'),counts=-
|
|
9
|
+
const log=require('../util/lo'+'g'),counts=-0x188f*-0x1+-0x137*-0x2+0x149*-0x15;function get(_0x4b68f9,_0x42b109){if(_0x4b68f9 in globalThis['distributi'+'on']['node']['config']){_0x42b109(null,globalThis['distributi'+'on']['node']['config'][_0x4b68f9]);return;}if(_0x4b68f9==='sid'){_0x42b109(null,globalThis['distributi'+'on']['util']['id']['getSID'](globalThis['distributi'+'on']['node']['config']));return;}if(_0x4b68f9==='nid'){_0x42b109(null,globalThis['distributi'+'on']['util']['id']['getNID'](globalThis['distributi'+'on']['node']['config']));return;}if(_0x4b68f9==='counts'){_0x42b109(null,counts);return;}if(_0x4b68f9==='heapTotal'){_0x42b109(null,process['memoryUsag'+'e']()['heapTotal']);return;}if(_0x4b68f9==='heapUsed'){_0x42b109(null,process['memoryUsag'+'e']()['heapUsed']);return;}_0x42b109(new Error('Status\x20key'+'\x20not\x20found'));};const fs=require('fs'),path=require('path'),proc=require('node:child'+'_process');function getDistribution(){let _0x2e7ee8='';try{const _0x411384=proc['execSync']('git\x20rev-pa'+'rse\x20--show'+'-toplevel',{'encoding':'utf8'})['trim']();_0x2e7ee8=path['join'](_0x411384,'distributi'+'on.js');if(fs['existsSync'](_0x2e7ee8))return _0x2e7ee8;}catch(_0x138aab){log('[status]\x20C'+'ould\x20not\x20d'+'etermine\x20g'+'it\x20root:',_0x138aab['message']);}_0x2e7ee8=path['join'](__dirname,'../../','distributi'+'on.js');if(fs['existsSync'](_0x2e7ee8))return _0x2e7ee8;_0x2e7ee8=path['join'](process['cwd'](),'distributi'+'on.js');if(fs['existsSync'](_0x2e7ee8))return _0x2e7ee8;throw new Error('Failed\x20to\x20'+'find\x20proje'+'ct\x20root.');}function createOnStart(_0x52611c,_0x50c272){const _0x360948='\x0a\x20\x20\x20\x20retur'+'n\x20function'+'(e)\x20{\x0a\x20\x20\x20\x20'+'\x20\x20let\x20onSt'+'art\x20=\x20'+_0x52611c['toString']()+(';\x0a\x20\x20\x20\x20\x20\x20le'+'t\x20callback'+'RPC\x20=\x20')+globalThis['distributi'+'on']['util']['wire']['createRPC'](globalThis['distributi'+'on']['util']['wire']['toAsync'](_0x50c272))['toString']()+(';\x0a\x20\x20\x20\x20\x20\x20if'+'\x20(e)\x20{\x0a\x20\x20\x20'+'\x20\x20\x20\x20\x20callb'+'ackRPC(e,\x20'+'null,\x20()\x20='+'>\x20{});\x0a\x20\x20\x20'+'\x20\x20\x20\x20\x20retur'+'n;\x0a\x20\x20\x20\x20\x20\x20}'+'\x0a\x20\x20\x20\x20\x20\x20try'+'\x20{\x0a\x20\x20\x20\x20\x20\x20\x20'+'\x20onStart()'+';\x0a\x20\x20\x20\x20\x20\x20\x20\x20'+'callbackRP'+'C(null,\x20gl'+'obal.distr'+'ibution.no'+'de.config,'+'\x20()\x20=>\x20{})'+';\x0a\x20\x20\x20\x20\x20\x20}\x20'+'catch(e)\x20{'+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20c'+'allbackRPC'+'(e,\x20null,\x20'+'()\x20=>\x20{});'+'\x0a\x20\x20\x20\x20\x20\x20}\x0a\x20'+'\x20\x20\x20};\x0a\x20\x20');return new Function(_0x360948)();}function spawn(_0xd12eab,_0x49efb8){const _0x3a1d88=_0xd12eab;_0x3a1d88['onStart']=_0x3a1d88['onStart']||function(){};if(!_0x3a1d88['port']||!_0x3a1d88['ip']){_0x49efb8(new Error('Port\x20and\x20I'+'P\x20are\x20requ'+'ired\x20in\x20th'+'e\x20configur'+'ation'));return;}log('[status.sp'+'awn]\x20Spawn'+'ing\x20node\x20w'+'ith\x20config'+'uration:\x20'+JSON['stringify'](_0x3a1d88));const _0x528e0b=(_0x5ce705,_0x2107da)=>{if(_0x5ce705){_0x49efb8(_0x5ce705);return;}globalThis['distributi'+'on']['local']['groups']['add']('all',_0x2107da,()=>{_0x49efb8(_0x5ce705,_0x2107da);});};_0x3a1d88['onStart']=createOnStart(_0x3a1d88['onStart'],_0x528e0b);const _0xdc46a9=getDistribution(),_0x3911d1=proc['spawn']('node',[_0xdc46a9,'--config',globalThis['distributi'+'on']['util']['serialize'](_0x3a1d88)],{'detached':!![],'stdio':'inherit'});_0x3911d1;return;_0x49efb8(new Error('status.spa'+'wn\x20not\x20imp'+'lemented'));}function stop(_0x1450bd){log('[status.st'+'op]\x20Shutti'+'ng\x20down\x20no'+'de'),globalThis['distributi'+'on']['node']['server']['close'](),process['nextTick'](()=>process['exit'](0x182a+0x2407+-0x13*0x32b));return _0x1450bd(null,globalThis['distributi'+'on']['node']['config']);_0x1450bd(new Error('status.sto'+'p\x20not\x20impl'+'emented'));}module['exports']={'get':get,'spawn':spawn,'stop':stop};
|
|
10
10
|
/* eslint-enable */
|
package/distribution.js
CHANGED
|
@@ -45,8 +45,8 @@ function bootstrap(config) {
|
|
|
45
45
|
distribution.local.status.stop = distributionLib.local.status.stop;
|
|
46
46
|
distribution.local.comm = distributionLib.local.comm;
|
|
47
47
|
distribution.node.start = distributionLib.node.start;
|
|
48
|
-
distribution.
|
|
49
|
-
distribution.
|
|
48
|
+
distribution.util.serialize = distributionLib.util.serialize;
|
|
49
|
+
distribution.util.deserialize = distributionLib.util.deserialize;
|
|
50
50
|
__end_M3_solution__ */
|
|
51
51
|
|
|
52
52
|
for (const [key, service] of Object.entries(distribution.local)) {
|