src/nopg.js
function parse_search_traits(traits) {
	traits = traits || {};

	// Initialize fields as all fields
	if(!traits.fields) {
		traits.fields = ['$*'];
	}

	// If fields was not an array (but is not negative -- check previous if clause), lets make it that.
	if(!is.array(traits.fields)) {
		traits.fields = [traits.fields];
	}

	debug.assert(traits.fields).is('array');

	// Order by $created by default
	if(!traits.order) {
		// FIXME: Check if `$created` exists in the ObjType!
		traits.order = ['$created'];
	}

	// Enable group by
	if(traits.hasOwnProperty('group')) {
		traits.group = [].concat(traits.group);
	}

	if(!is.array(traits.order)) {
		traits.order = [traits.order];
	}

	debug.assert(traits.order).is('array');

	if(traits.limit) {
		if(!traits.order) {
			debug.warn('Limit without ordering will yeald unpredictable results!');
		}

		if((''+traits.limit).toLowerCase() === 'all') {
			traits.limit = 'ALL';
		} else {
			traits.limit = '' + parseInt(traits.limit, 10);
		}
	}

	if(traits.offset) {
		traits.offset = parseInt(traits.offset, 10);
	}

	if(traits.hasOwnProperty('prepareOnly')) {
		traits.prepareOnly = traits.prepareOnly === true;
	}

	if(traits.hasOwnProperty('typeAwareness')) {
		traits.typeAwareness = traits.typeAwareness === true;
	} else {
		traits.typeAwareness = NoPg.defaults.enableTypeAwareness === true;
	}

	// Append '$documents' to fields if traits.documents is specified and it is missing from there
	if((traits.documents || traits.typeAwareness) && (traits.fields.indexOf('$documents') === -1) ) {
		traits.fields = traits.fields.concat(['$documents']);
	}

	if(traits.hasOwnProperty('count')) {
		traits.count = traits.count === true;
		traits.fields = ['count'];
		delete traits.order;
	}

	return traits;
}
function parse_search_traits(traits) {
	traits = traits || {};

	// Initialize fields as all fields
	if(!traits.fields) {
		traits.fields = ['$*'];
	}

	// If fields was not an array (but is not negative -- check previous if clause), lets make it that.
	if(!is.array(traits.fields)) {
		traits.fields = [traits.fields];
	}

	debug.assert(traits.fields).is('array');

	// Order by $created by default
	if(!traits.order) {
		// FIXME: Check if `$created` exists in the ObjType!
		traits.order = ['$created'];
	}

	// Enable group by
	if(traits.hasOwnProperty('group')) {
		traits.group = [].concat(traits.group);
	}

	if(!is.array(traits.order)) {
		traits.order = [traits.order];
	}

	debug.assert(traits.order).is('array');

	if(traits.limit) {
		if(!traits.order) {
			debug.warn('Limit without ordering will yeald unpredictable results!');
		}

		if((''+traits.limit).toLowerCase() === 'all') {
			traits.limit = 'ALL';
		} else {
			traits.limit = '' + parseInt(traits.limit, 10);
		}
	}

	if(traits.offset) {
		traits.offset = parseInt(traits.offset, 10);
	}

	if(traits.hasOwnProperty('prepareOnly')) {
		traits.prepareOnly = traits.prepareOnly === true;
	}

	if(traits.hasOwnProperty('typeAwareness')) {
		traits.typeAwareness = traits.typeAwareness === true;
	} else {
		traits.typeAwareness = NoPg.defaults.enableTypeAwareness === true;
	}

	// Append '$documents' to fields if traits.documents is specified and it is missing from there
	if((traits.documents || traits.typeAwareness) && (traits.fields.indexOf('$documents') === -1) ) {
		traits.fields = traits.fields.concat(['$documents']);
	}

	if(traits.hasOwnProperty('count')) {
		traits.count = traits.count === true;
		traits.fields = ['count'];
		delete traits.order;
	}

	return traits;
}
function parse_search_traits ( traits ) { traits = traits || { } ; // Initialize fields as all fields if ( ! traits . fields ) { traits . fields = [ '$*' ] ; } // If fields was not an array (but is not negative -- check previous if clause), lets make it that. if ( ! is . array ( traits . fields ) ) { traits . fields = [ traits . fields ] ; } debug . assert ( traits . fields ) . is ( 'array' ) ; // Order by $created by default if ( ! traits . order ) { // FIXME: Check if `$created` exists in the ObjType! traits . order = [ '$created' ] ; } // Enable group by if ( traits . hasOwnProperty ( 'group' ) ) { traits . group = [ ] . concat ( traits . group ) ; } if ( ! is . array ( traits . order ) ) { traits . order = [ traits . order ] ; } debug . assert ( traits . order ) . is ( 'array' ) ; if ( traits . limit ) { if ( ! traits . order ) { debug . warn ( 'Limit without ordering will yeald unpredictable results!' ) ; } if ( ( '' + traits . limit ) . toLowerCase ( ) === 'all' ) { traits . limit = 'ALL' ; } else { traits . limit = '' + parseInt ( traits . limit , 10 ) ; } } if ( traits . offset ) { traits . offset = parseInt ( traits . offset , 10 ) ; } if ( traits . hasOwnProperty ( 'prepareOnly' ) ) { traits . prepareOnly = traits . prepareOnly === true ; } if ( traits . hasOwnProperty ( 'typeAwareness' ) ) { traits . typeAwareness = traits . typeAwareness === true ; } else { traits . typeAwareness = NoPg . defaults . enableTypeAwareness === true ; } // Append '$documents' to fields if traits.documents is specified and it is missing from there if ( ( traits . documents || traits . typeAwareness ) && ( traits . fields . indexOf ( '$documents' ) === - 1 ) ) { traits . fields = traits . fields . concat ( [ '$documents' ] ) ; } if ( traits . hasOwnProperty ( 'count' ) ) { traits . count = traits . count === true ; traits . fields = [ 'count' ] ; delete traits . order ; } return traits ; }
Parse traits object
Parse traits object