/* * Create a data source */ create(source, data = {}, sort = []) { let database = this.read(source); database.push(_.merge({}, data, {id: hasher(data)})); // Sort if we have to if (!_.isEmpty(sort)) database = _.orderBy(database, ...sort); // Dump results this.yaml.dump(path.resolve(this.base, `${source}.yml`), _.uniqBy(database, 'id')); return this.read(source, {id: hasher(data)}); }
_(urls) .map(url => exports.parseUrl(url)) .map(parsedUrl => _.merge({}, parsedUrl, {id: hasher(parsedUrl)})) .uniqBy('id') .value()
it('should mirror process.env', () => { const env = config.defaults().env; expect(hasher(env)).to.equal(hasher(process.env)); process.env.NEW = 'things'; expect(hasher(env)).to.equal(hasher(process.env)); delete process.env.NEW; expect(hasher(env)).to.equal(hasher(process.env)); env.NEW2 = 'morethings'; expect(hasher(env)).to.equal(hasher(process.env)); delete env.NEW2; expect(hasher(env)).to.equal(hasher(process.env)); });
supreme: 'taylor', }; const landoMerge = hasher(config.merge(bands1, bands2)); const lodashMerge = hasher(_.merge(bands1, bands2)); expect(landoMerge).to.equal(lodashMerge); }); const bands = config.merge(theworst, thebest); expect(bands.favs).to.have.length(3); expect(hasher(bands.favs)).to.equal(hasher(['nickelback', 'abba', 'britney'])); }); const ourfavs = config.merge(myfavs, yourfavs); expect(ourfavs.favs).to.have.length(3); expect(hasher(ourfavs.favs)).to.equal(hasher(['nickelback', 'abba', 'britney'])); }); });
describe('#loadFiles', () => { it('should return an empty object if no files are specified', () => { const fileConfig = config.loadFiles(); expect(fileConfig).to.be.empty; }); it('should return data only from files that exist', () => { filesystem({'/tmp/config1.yml': 'obiwan: kenobi'}); const fileConfig = config.loadFiles(['/tmp/config1.yml', '/tmp/doesnotexist.yml']); expect(hasher(fileConfig)).to.equal(hasher({obiwan: 'kenobi'})); filesystem.restore(); }); it('should give priority to the last file loaded', () => { filesystem({ '/tmp/config1.yml': 'scoundrel: lando', '/tmp/config2.yml': 'scoundrel: solo', }); const fileConfig = config.loadFiles(['/tmp/config1.yml', '/tmp/config2.yml']); expect(hasher(fileConfig)).to.equal(hasher({scoundrel: 'solo'})); filesystem.restore(); }); });
const data = yaml.load('/tmp/config1.yml'); expect(data).to.be.an('Object'); expect(hasher(data)).to.equal(hasher({obiwan: 'kenobi', qui: ['gon', 'jinn']})); filesystem.restore(); }); yaml.dump('/tmp/test/file.yml', data); expect(fs.existsSync('/tmp/test/file.yml')).to.equal(true); expect(hasher(yaml.load('/tmp/test/file.yml'))).to.equal(hasher(data)); });
keys.forEach(function (key) { let subDataValue = data[key]; hashes[key] = objectHash(subDataValue) })
_flattenNpmDepsTree (npmDepsTree, npmDepMap = {}) { for (const [depName, depMetadata] of Object.entries(npmDepsTree)) { const depMetadataShortend = { version: depMetadata.version, resolved: depMetadata.resolved ? depMetadata.resolved : depMetadata.version, integrity: depMetadata.integrity, requires: depMetadata.requires } const hashedDepValues = hash(depMetadataShortend) npmDepMap[`${depName}@${depMetadata.version}-${hashedDepValues}`] = depMetadataShortend const nestedDepsTree = depMetadata.dependencies if (nestedDepsTree && Object.keys(nestedDepsTree).length !== 0) { this._flattenNpmDepsTree(nestedDepsTree, npmDepMap) } } return npmDepMap }
addNewBlock() { let block = { timestamp: Date.now(), transactions: this.curr_transactions, }; if(validator.proofOfWork() == TARGET_HASH){ block.hash = hash(block); this.getLastBlock((lastBlock) => { if(lastBlock){ block.prevHash = lastBlock.hash; block.index = lastBlock.index + 1; } let newBlock = blockChainModel(block); newBlock.save((err) => { if(err) return console.log(chalk.red('Cannot save Block to DB ', err.message)); console.log(chalk.green('Block Saved on the DB')); }); this.chain.push(block); this.curr_transactions = []; return block; }); } }
async.forever(function(next) { setTimeout(function() { if (that._unregisterEndPoints.size() > 0) { const serviceManager = require("../services"); serviceManager.remoteClientService().registerEndpoint(that._unregisterEndPoints, function(endPointMapping) { for (let mapping of endPointMapping.entries()) { logger.debug("endpoint-dictionary", "register endpoint[%s, %s].", mapping[0].endpointName(), mapping[1]); that._registerEndPoints.set(hash(mapping[0]), mapping[1]); } endPointMapping.forEach(function(value, key) { that._unregisterEndPoints.remove(key); }); next(); }); } else { next(); } }, 5 * 1000); }, function(err) { logger.error("endpoint-dictionary", "Failed to execute register endpoint task. Reason: %s", err.message); });
const etag = `"${objhash(result)}"`;
}; dbSchema.custom_indexes.push(customIndexObject); dbSchema.index_names[objectHash(customIndexObject)] = row.index_name; } else { if (!dbSchema.indexes) dbSchema.indexes = [];
resolve().then(data => { const cacheKey = hash( Object.assign({scope: info.cacheControl.scope}, args, info.path) );
resolve().then(result => { const cacheKey = hash( Object.assign({scope: info.cacheControl.scope}, args, info.path) );