@brown-ds/distribution 0.2.19 → 0.2.20

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 fs=require('fs'),path=require('path'),id=require('../util/id'),serialization=require('../util/se'+'rializatio'+'n'),log=require('../util/lo'+'g'),baseFolder=path['join'](__dirname,'../../stor'+'e');!fs['existsSync'](baseFolder)&&fs['mkdirSync'](baseFolder);const nodeFolder=path['join'](baseFolder,'s-'+globalThis['distributi'+'on']['util']['id']['getSID'](globalThis['distributi'+'on']['node']['config']));!fs['existsSync'](nodeFolder)&&fs['mkdirSync'](nodeFolder);function normalize(_0x3b0f47){if(_0x3b0f47===null)return{'key':null,'gid':null,'action':'put'};else return typeof _0x3b0f47==='string'?{'key':_0x3b0f47,'gid':null,'action':'put'}:_0x3b0f47;}function put(_0x1ec5ba,_0x345ea9,_0x87322d){log('[store.put'+']\x20configur'+'ation:\x20'+JSON['stringify'](_0x345ea9)+'\x20state:\x20'+JSON['stringify'](_0x1ec5ba)),_0x345ea9=normalize(_0x345ea9),_0x345ea9['key']=_0x345ea9['key']||id['getID'](_0x1ec5ba),_0x345ea9['gid']=_0x345ea9['gid']||'local';const _0x3f2527=serialization['serialize'](_0x1ec5ba),_0x4a286f=Buffer['from'](_0x345ea9['key'])['toString']('base64'),_0x2e3100=path['join'](nodeFolder,_0x345ea9['gid']+'-'+_0x4a286f);fs['writeFile'](_0x2e3100,_0x3f2527,_0x4fb0c1=>{return _0x4fb0c1?_0x87322d(_0x4fb0c1):_0x87322d(null,_0x1ec5ba);});}function get(_0x14d784,_0x3fed28){log('[store.get'+']\x20configur'+'ation:\x20'+JSON['stringify'](_0x14d784)),_0x14d784=normalize(_0x14d784),_0x14d784['gid']=_0x14d784['gid']||'local';if(!_0x14d784['key']){fs['readdir'](nodeFolder,(_0x561559,_0x399954)=>{if(_0x561559)return _0x3fed28(_0x561559);const _0x47fbf7=[];for(let _0x372683=-0x8*-0x265+0x161f*-0x1+0x2f7;_0x372683<_0x399954['length'];_0x372683++){const _0x27cae0=_0x399954[_0x372683]['split']('-'),_0x13fc9a=_0x27cae0[-0x4*-0x313+0x622+-0x126e];if(_0x13fc9a!==_0x14d784['gid'])continue;const _0x1ab0cc=_0x27cae0[_0x27cae0['length']-(-0x101a+0x75b+0x8c0)];_0x47fbf7['push'](Buffer['from'](_0x1ab0cc,'base64')['toString']());}return _0x3fed28(null,_0x47fbf7);});return;}const _0x42e084=Buffer['from'](_0x14d784['key'])['toString']('base64'),_0x17e0c8=path['join'](nodeFolder,_0x14d784['gid']+'-'+_0x42e084);fs['readFile'](_0x17e0c8,(_0x52c8db,_0x558936)=>{return _0x52c8db?_0x52c8db['code']==='ENOENT'?_0x3fed28(new Error('File\x20'+_0x17e0c8+('\x20(from\x20key'+'\x20\x27')+_0x14d784['key']+('\x27)\x20not\x20fou'+'nd\x20for\x20gro'+'up\x20')+_0x14d784['gid'])):_0x3fed28(_0x52c8db):_0x3fed28(null,serialization['deserializ'+'e'](_0x558936['toString']()));});}function del(_0x58a169,_0x4db702){log('[store.del'+']\x20configur'+'ation:\x20'+JSON['stringify'](_0x58a169)),_0x58a169=normalize(_0x58a169),_0x58a169['gid']=_0x58a169['gid']||'local';const _0x26992a=Buffer['from'](_0x58a169['key'])['toString']('base64'),_0x5409ab=path['join'](nodeFolder,_0x58a169['gid']+'-'+_0x26992a);get(_0x58a169,(_0x41afcd,_0x26fc3f)=>{if(_0x41afcd)return _0x4db702(_0x41afcd);fs['rm'](_0x5409ab,_0x41ab40=>{return _0x41ab40?_0x4db702(_0x41ab40):_0x4db702(null,_0x26fc3f);});});}module['exports']={'put':put,'get':get,'del':del};
9
+ const fs=require('fs'),path=require('path'),log=require('../util/lo'+'g'),baseFolder=path['join'](__dirname,'../../stor'+'e');!fs['existsSync'](baseFolder)&&fs['mkdirSync'](baseFolder);const nodeFolder=path['join'](baseFolder,'s-'+globalThis['distributi'+'on']['util']['id']['getSID'](globalThis['distributi'+'on']['node']['config']));!fs['existsSync'](nodeFolder)&&fs['mkdirSync'](nodeFolder);function normalize(_0x13584e){if(_0x13584e===null)return{'key':null,'gid':null,'action':'put'};else return typeof _0x13584e==='string'?{'key':_0x13584e,'gid':null,'action':'put'}:_0x13584e;}function put(_0x2d3094,_0x417f9d,_0x225eb2){log('[store.put'+']\x20configur'+'ation:\x20'+JSON['stringify'](_0x417f9d)+'\x20state:\x20'+JSON['stringify'](_0x2d3094)),_0x417f9d=normalize(_0x417f9d),_0x417f9d['key']=_0x417f9d['key']||globalThis['distributi'+'on']['util']['id']['getID'](_0x2d3094),_0x417f9d['gid']=_0x417f9d['gid']||'local';const _0xf73df0=globalThis['distributi'+'on']['util']['serialize'](_0x2d3094),_0x1a5c65=Buffer['from'](_0x417f9d['key'])['toString']('base64'),_0x15df32=path['join'](nodeFolder,_0x417f9d['gid']+'-'+_0x1a5c65);fs['writeFile'](_0x15df32,_0xf73df0,_0x505dc7=>{return _0x505dc7?_0x225eb2(_0x505dc7):_0x225eb2(null,_0x2d3094);});}function get(_0x1bdb0c,_0x1a1526){log('[store.get'+']\x20configur'+'ation:\x20'+JSON['stringify'](_0x1bdb0c)),_0x1bdb0c=normalize(_0x1bdb0c),_0x1bdb0c['gid']=_0x1bdb0c['gid']||'local';if(!_0x1bdb0c['key']){fs['readdir'](nodeFolder,(_0x2e23aa,_0x3b8b2a)=>{if(_0x2e23aa)return _0x1a1526(_0x2e23aa);const _0x1949b1=[];for(let _0x1e79bb=0x1*-0xe2c+0x84f+0x13*0x4f;_0x1e79bb<_0x3b8b2a['length'];_0x1e79bb++){const _0x43672b=_0x3b8b2a[_0x1e79bb]['split']('-'),_0x214097=_0x43672b[-0xd1*0x13+-0x1015+0x3*0xa88];if(_0x214097!==_0x1bdb0c['gid'])continue;const _0x57f0ff=_0x43672b[_0x43672b['length']-(-0x123+-0xefa*0x1+0x101e)];_0x1949b1['push'](Buffer['from'](_0x57f0ff,'base64')['toString']());}return _0x1a1526(null,_0x1949b1);});return;}const _0xdb74fa=Buffer['from'](_0x1bdb0c['key'])['toString']('base64'),_0x202499=path['join'](nodeFolder,_0x1bdb0c['gid']+'-'+_0xdb74fa);fs['readFile'](_0x202499,(_0x59d1bb,_0x168127)=>{return _0x59d1bb?_0x59d1bb['code']==='ENOENT'?_0x1a1526(new Error('File\x20'+_0x202499+('\x20(from\x20key'+'\x20\x27')+_0x1bdb0c['key']+('\x27)\x20not\x20fou'+'nd\x20for\x20gro'+'up\x20')+_0x1bdb0c['gid'])):_0x1a1526(_0x59d1bb):_0x1a1526(null,globalThis['distributi'+'on']['util']['deserializ'+'e'](_0x168127['toString']()));});}function del(_0x4fde27,_0x19d6a5){log('[store.del'+']\x20configur'+'ation:\x20'+JSON['stringify'](_0x4fde27)),_0x4fde27=normalize(_0x4fde27),_0x4fde27['gid']=_0x4fde27['gid']||'local';const _0x5ec45b=Buffer['from'](_0x4fde27['key'])['toString']('base64'),_0x214bf8=path['join'](nodeFolder,_0x4fde27['gid']+'-'+_0x5ec45b);get(_0x4fde27,(_0x2bce8e,_0x4a2f9e)=>{if(_0x2bce8e)return _0x19d6a5(_0x2bce8e);fs['rm'](_0x214bf8,_0x50dca6=>{return _0x50dca6?_0x19d6a5(_0x50dca6):_0x19d6a5(null,_0x4a2f9e);});});}module['exports']={'put':put,'get':get,'del':del};
10
10
  /* eslint-enable */
package/distribution.js CHANGED
@@ -9,35 +9,46 @@ const log = require('./distribution/util/log.js');
9
9
  * @param {Node} [config]
10
10
  */
11
11
  function bootstrap(config) {
12
+ // __start_solution__
13
+ if (false) {
14
+ // __end_solution__
15
+ // This loads the reference implementation in case you want to selectively override parts of your implementation with it (e.g., extra credit ypu are not doing or missing functionality from previous milestones).
16
+ // This needs to run before the rest of the code so that the globalThis.distribution object is populated correctly.
17
+ // @ts-ignore Optional dependency for reference implementation.
18
+ const distributionLib = require('@brown-ds/distribution')(config);
19
+ distributionLib; // To avoid unused variable warning
20
+ // __start_solution__
21
+ }
22
+ // __end_solution__
23
+ const distribution = {};
12
24
  // @ts-ignore This is the first time globalThis.distribution is being initialized, so the object does not have all the necessary properties.
13
- globalThis.distribution = {};
14
- globalThis.distribution.util = require('./distribution/util/util.js');
25
+ globalThis.distribution = distribution;
26
+ distribution.util = require('./distribution/util/util.js');
15
27
  // @ts-ignore node.server is lazily initialized.
16
- globalThis.distribution.node = require('./distribution/local/node.js');
17
- globalThis.distribution.local = require('./distribution/local/local.js');
28
+ distribution.node = require('./distribution/local/node.js');
29
+ distribution.local = require('./distribution/local/local.js');
18
30
 
19
31
  if (config) {
20
- globalThis.distribution.node.config = config;
32
+ distribution.node.config = config;
21
33
  }
22
34
 
23
- for (const [key, service] of Object.entries(globalThis.distribution.local)) {
24
- globalThis.distribution.local.routes.put(service, key, () => {});
35
+ for (const [key, service] of Object.entries(distribution.local)) {
36
+ distribution.local.routes.put(service, key, () => {});
25
37
  }
26
38
 
27
39
  const {setup} = require('./distribution/all/all.js');
28
- globalThis.distribution.all = setup({gid: 'all'});
40
+ distribution.all = setup({gid: 'all'});
29
41
 
30
42
  /* Overrides when missing functionality from previous milestone or extra credit is needed */
31
43
 
32
44
  // For M3, when missing RPC, its path through routes, and status.{spawn, stop}
33
45
  /* __start_M3_solution__
34
- const distributionLib = require('@brown-ds/distribution')(config);
35
- globalThis.distribution.util.wire.createRPC = distributionLib.util.wire.createRPC;
36
- globalThis.distribution.local.routes.get = distributionLib.local.routes.get;
37
- globalThis.distribution.local.status.spawn = distributionLib.local.status.spawn;
38
- globalThis.distribution.local.status.stop = distributionLib.local.status.stop;
46
+ distribution.util.wire.createRPC = distributionLib.util.wire.createRPC;
47
+ distribution.local.routes.get = distributionLib.local.routes.get;
48
+ distribution.local.status.spawn = distributionLib.local.status.spawn;
49
+ distribution.local.status.stop = distributionLib.local.status.stop;
39
50
  __end_M3_solution__ */
40
- return globalThis.distribution;
51
+ return distribution;
41
52
  }
42
53
 
43
54
  /*
@@ -46,7 +57,7 @@ function bootstrap(config) {
46
57
  1. The reference implementation from the library @brown-ds/distribution
47
58
  2. Your own, local implementation
48
59
 
49
- Which one to be used by the tests is determined by the value of the property "useLibrary" in the package.json file.
60
+ Which one to be used by the tests is determined by the "useLibrary" value in the package.json file.
50
61
  */
51
62
  // @ts-ignore JSON import resolved at runtime.
52
63
  const {useLibrary} = require('./package.json');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brown-ds/distribution",
3
- "version": "0.2.19",
3
+ "version": "0.2.20",
4
4
  "description": "A library for building distributed systems.",
5
5
  "main": "distribution.js",
6
6
  "useLibrary": false,