lib/archivist/index.js
function mgetAggregate(queries, options, retriever, cb) {
	// queries: [{ topic: 'foo', index: { id: 1 } }, { topic: 'bar', index: { id: 'abc' } }]
	//   OR:
	// queries: { uniqueID: { topic: 'foo', index: { id: 1 } }, uniqueID2: { etc }

	const getQueryOptions = (query) => Object.assign({}, options, query.options);

	const arrayQuery = () => async.mapSeries(queries, (query, callback) => {
		retriever(query, getQueryOptions(query), callback);
	}, cb);

	function objectQuery() {
		const queryIds = Object.keys(queries);
		const result = {};

		async.forEachSeries(
			queryIds,
			(queryId, callback) => {
				const query = queries[queryId];

				retriever(query, getQueryOptions(query), function (error, data) {
					result[queryId] = data;
					callback(error);
				});
			},
			(error) => cb(error, error ? null : result)
		);
	}

	if (Array.isArray(queries)) {
		arrayQuery();
	} else if (queries && typeof queries === 'object') {
		objectQuery();
	} else {
		cb(new TypeError('mget queries must be an Array or an Object'));
	}
}
function mgetAggregate(queries, options, retriever, cb) {
	// queries: [{ topic: 'foo', index: { id: 1 } }, { topic: 'bar', index: { id: 'abc' } }]
	//   OR:
	// queries: { uniqueID: { topic: 'foo', index: { id: 1 } }, uniqueID2: { etc }

	const getQueryOptions = (query) => Object.assign({}, options, query.options);

	const arrayQuery = () => async.mapSeries(queries, (query, callback) => {
		retriever(query, getQueryOptions(query), callback);
	}, cb);

	function objectQuery() {
		const queryIds = Object.keys(queries);
		const result = {};

		async.forEachSeries(
			queryIds,
			(queryId, callback) => {
				const query = queries[queryId];

				retriever(query, getQueryOptions(query), function (error, data) {
					result[queryId] = data;
					callback(error);
				});
			},
			(error) => cb(error, error ? null : result)
		);
	}

	if (Array.isArray(queries)) {
		arrayQuery();
	} else if (queries && typeof queries === 'object') {
		objectQuery();
	} else {
		cb(new TypeError('mget queries must be an Array or an Object'));
	}
}
function mgetAggregate ( queries , options , retriever , cb ) { // queries: [{ topic: 'foo', index: { id: 1 } }, { topic: 'bar', index: { id: 'abc' } }] //   OR: // queries: { uniqueID: { topic: 'foo', index: { id: 1 } }, uniqueID2: { etc } const getQueryOptions = ( query ) => Object . assign ( { } , options , query . options ) ; const arrayQuery = ( ) => async . mapSeries ( queries , ( query , callback ) => { retriever ( query , getQueryOptions ( query ) , callback ) ; } , cb ) ; function objectQuery ( ) { const queryIds = Object . keys ( queries ) ; const result = { } ; async . forEachSeries ( queryIds , ( queryId , callback ) => { const query = queries [ queryId ] ; retriever ( query , getQueryOptions ( query ) , function ( error , data ) { result [ queryId ] = data ; callback ( error ) ; } ) ; } , ( error ) => cb ( error , error ? null : result ) ) ; } if ( Array . isArray ( queries ) ) { arrayQuery ( ) ; } else if ( queries && typeof queries === 'object' ) { objectQuery ( ) ; } else { cb ( new TypeError ( 'mget queries must be an Array or an Object' ) ) ; } }
multiget helper function
multiget helper function