/*
Valid data objects are those which only have two keys: done and
results.
177328
function lomValidData(lomp, data)
{
	var k, i;

	mod_assert.ok(data.hasOwnProperty('results'));
	mod_assert.ok(Array.isArray(data.results));
	mod_assert.bool(data.done);

	if (data.done === false)
		mod_assert.ok(data.results.length > 0 ||
		    lomp.lom_pushed > 0);

	for (k in data) {
		if (!data.hasOwnProperty(k))
			continue;
		for (i = 0; i < LOM_RES_KEYS.length; i++) {
			if (LOM_RES_KEYS[i] === k)
				break;
		}

		mod_assert.ok(i < LOM_RES_KEYS.length,
		    sprintf('unknown result key: %s', k));
	}
}
395061
function(results, done) {
                // Find the index of the fields we want
                var rawIndex = results.fields.indexOf("_raw");
                var sourcetypeIndex = results.fields.indexOf("sourcetype");
                var userIndex = results.fields.indexOf("user");
                
                // Print out each result and the key-value pairs we want
                console.log("Results: ");
                for(var i = 0; i < results.rows.length; i++) {
                    console.log("  Result " + i + ": ");
                    console.log("    sourcetype: " + results.rows[i][sourcetypeIndex]);
                    console.log("    user: " + results.rows[i][userIndex]);
                    console.log("    _raw: " + results.rows[i][rawIndex]);
                }
                
                done();
            }
839817
function ( object ) {
      this.__class__ = 'Unique';

      if ( 'object' === typeof object )
        this.key = object.key;

      this.validate = function ( array ) {
        var value, store = [];

        if ( !_isArray( array ) )
          throw new Violation( this, array, { value: Validator.errorCode.must_be_an_array } );

        for ( var i = 0; i < array.length; i++ ) {
          value = 'object' === typeof array[ i ] ? array[ i ][ this.key ] : array[ i ];

          if ( 'undefined' === typeof value )
            continue;

          if ( -1 !== store.indexOf( value ) )
            throw new Violation( this, array, { value: value } );

          store.push( value );
        }

        return true;
      };

      return this;
    }
1252458
private void validateEntities(JsonNode data) throws InvalidInputException {
    for (JsonNode node : data.findParents(INDEX_START)) {

      for (String key : new String[] {INDEX_START, INDEX_END, ID, TYPE}) {
        if (node.path(key).isMissingNode()) {
          throw new InvalidInputException("Required field \"" + key + "\" missing from the entity payload");
        }
      }

      int startIndex = node.get(INDEX_START).intValue();
      int endIndex = node.get(INDEX_END).intValue();

      if (endIndex <= startIndex) {
        throw new InvalidInputException(String.format("Invalid entity payload: %s (start index: %s, end index: %s)",
            node.get(ID).textValue(), startIndex, endIndex));
      }

    }
  }
57025
function validator (data, schema) {
  const result = Object.assign({}, data)
  Object.keys(schema).map(key => {
    let value = schema[key]
    const type = typeof value
    if (type !== 'object') {
      value = {
        transform: value
      }
    }
    validate(value, result, key)
  })
  return result
}
484369
private void validateSubEntities(Entity obj) {
        // Validate that all sub entities have a "rel" set.
        String relRequired = "Sub entities are required to have a <rel> property set.";
        String hrefReqForEmbed = "Sub entities that are embedded links are required to have a <href> property set.";
        if (!CollectionUtils.isEmpty(obj.getEntities())) {
            for (Entity e : obj.getEntities()) {
                if (e.getRel() == null || ArrayUtils.isEmpty(e.getRel())) {
                    throw new Siren4JBuilderValidationException("entities", obj.getClass(), relRequired);
                }
                if ((e instanceof EmbeddedEntityImpl) && StringUtils.isBlank(e.getHref())) {
                    throw new Siren4JBuilderValidationException("entities", obj.getClass(), hrefReqForEmbed);
                }
            }
        }
    }
88301
function(data, padding) {

		var tempResult = [],
			child_padding = padding + "\t",
			name,
			type,
			result,
			is_complex = false,
			only_key = null,
			is_empty = true;

		// this may be faster than using Object.keys(data), but I haven't done speed comparison yet.
		// Purpose of the following code:
		// 1) if object has something in it then 'is_empty' will be set to false
		// 2) if there is only one property in it, then 'only_key' will contain it's name
		for (name in data) {
			if (only_key !== null) { // strict comparison - in case the key is valid, but evaluates to false
				only_key = null;
				break;
			}
			is_empty = false;
			only_key = name;
		}

		if (only_key) {

			type = Firestorm.getType(data[only_key]);

			if (type in this._complex_types) {
				is_complex = true;
			}

		}

		if (is_empty) {

			result = '{}';

		} else if (only_key && !is_complex) {

			// simple values can be written in one line
			result = '{' + this._serializeObjectProperty(only_key, data[only_key], child_padding) + '}';

		} else {

			for (name in data) {

				tempResult.push(
					this._serializeObjectProperty(name, data[name], child_padding)
				);

			}

			result = '{' + "\n\t" + padding + tempResult.join(",\n\t" + padding) + "\n" + padding + '}';

		}

		return result;

	}
127853
function invalid(data, meta, thing) {
	if (data === undefined && meta.required)
		return true;

	let type = meta.type;
	
	// missing type accepts anything
	if (type === undefined)
		return false;
		
	// application defined type?
	
	if (thing.model.types && thing.model.types.hasOwnProperty(type))
		return invalid(data, thing.model.types[type], thing);
		
	if (typeof (meta.enum) === 'array') {
		list = meta.enum;
		
		for (let i = 0; i < list.length; ++i ) {
			if (data === list[i])
				return false;
		}
		
		return true;
	}
	
	if (type === 'null' && data !== null)
		return true;
		
	if (type === 'const' && data !== meta.const)
		return true;
	
	if (type === 'boolean')
		return !(data === true || data === false);
		
	if (type === 'string') {
		if (typeof data !== 'string')
			return true;
			
		if (meta.regex) {
			const regex = new RegExp(meta.regex);
			return ! regex.test(data);
		}
		
		return false;
	}
		
	if (type === 'number' || type === 'integer') {		
		if (typeof data !== 'number')
			return true;
			
		if (type === 'integer' && !Number.isInteger(data))
			return true;
						
		if (meta.minimum !== undefined && data < meta.minimum)
			return true;
			
		if (meta.maximum !== undefined && data > meta.maximum)
			return true;
			
		return false;
	}
	
	// arrays and objects are more complicated
	// is it acceptable for data to be null when expecting an array?
	
	if (type === 'array') {
		if (!Array.isArray(data))
			return true;
			
		let length = data.length;
		
		if (meta.minItems !== undefined && length < meta.minItems)
			return true;
			
		if (meta.maxItems !== undefined && length > meta.maxItems)
			return true;
			
		let items = meta.items;
		
		if (items !== undefined) {
			for (let i = 0; i < length; ++i) {
				if (!invalid(data[i], meta, thing))
					return true;
			}
		}
		
		return false;
	}
	
	// is it acceptable for data to be null when expecting an object?
	
	if (type === 'object') {
		if (data === null || typeof data !== 'object' || Array.isArray(data))
			return true;
		let properties = meta.properties;
			
		for (name in data) {
			if (data.hasOwnProperty(name)) {
				if (!properties.hasOwnProperty(name))
					return true;
					
				if (invalid(data[name], properties[name], thing)) {
					return true;
				}
			}
		}
		
		let required = meta.required;
		
		if (required === undefined)
			return false;
			
		// we need to check for missing required properties
		
		for (let i = 0; i < required.length; ++i) {
			if (!data.hasOwnProperty(required[i]))
				return true;
		}
			
		return false;
	}
	
	return true;
}
1133981
function(validBidRequests, bidderRequest) {
    const auids = [];
    const bidsMap = {};
    const bids = validBidRequests || [];
    let priceType = 'net';
    let reqId;

    bids.forEach(bid => {
      if (bid.params.priceType === 'gross') {
        priceType = 'gross';
      }
      reqId = bid.bidderRequestId;
      if (!bidsMap[bid.params.uid]) {
        bidsMap[bid.params.uid] = [bid];
        auids.push(bid.params.uid);
      } else {
        bidsMap[bid.params.uid].push(bid);
      }
    });

    const payload = {
      u: utils.getTopWindowUrl(),
      pt: priceType,
      auids: auids.join(','),
      r: reqId
    };

    if (bidderRequest) {
      if (bidderRequest.timeout) {
        payload.wtimeout = bidderRequest.timeout;
      }
      if (bidderRequest.gdprConsent) {
        if (bidderRequest.gdprConsent.consentString) {
          payload.gdpr_consent = bidderRequest.gdprConsent.consentString;
        }
        payload.gdpr_applies =
          (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean')
            ? Number(bidderRequest.gdprConsent.gdprApplies) : 1;
      }
    }

    return {
      method: 'GET',
      url: ENDPOINT_URL,
      data: utils.parseQueryStringParameters(payload).replace(/\&$/, ''),
      bidsMap: bidsMap,
    };
  }
661182
function gotResults(results) {
  results.JSONquery = JSON.stringify(results.query, null, 2);
  console.log('gotResults', results);
  updateResults(results);
}
705463
function validate (schema, data, key) {
  let value = data[key]
  const bool = value == null || value === ''
  const { required, type, validate, transform, elements } = schema
  const def = schema['default']
  // trigger error if undefined but required
  if (required && bool) throw new Error(`field ${key} is missing`)
  // coerce to type
  if (type && !bool) {
    let before = coerce(type, key, value)
    data[key] = elements
      ? (type === 'object' ? validator(before, elements) : before.map(item => validator(item, elements)))
      : before
  }
  // validate value
  if (validate) {
    const cb = check(validate, key)
    if (type === 'array') value.map(cb)
    else cb(value)
  }
  // apply default value
  if (def && bool) data[key] = def
  // apply transform
  if (transform && def == null) {
    data[key] = typeof transform === 'function'
      ? (type === 'array' ? value.map(transform) : transform(value))
      : transform
  }
}
2097
function validate (data, schema) {
  if (!data || !schema) {
    throw new Error('Trying to validate without passing data and schema')
  }
  return Joi.validate(data, schema)
}
625384
function validateParams(dataSources, cb) {
  dataSources = _.map(dataSources, function(dataSourceUpdateData) {
    var failed = validate(dataSourceUpdateData).has(CONSTANTS.DATA_SOURCE_ID);

    if (failed) {
      dataSourceUpdateData.error = buildErrorResponse({error: new Error("Invalid Parameters For Updating Data Source Data Cache"), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS});
    }

    if (!misc.checkId(dataSourceUpdateData._id)) {
      dataSourceUpdateData.error = buildErrorResponse({error: new Error("Invalid ID Paramter " + dataSourceUpdateData._id), code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS});
    }

    return dataSourceUpdateData;
  });

  //Filter out any data sources with invalid parameters.

  cb(undefined, dataSources);
}
737705
function validateObject(node, schema, key) {
    if (typeof node == "object") {
      try {
        validateModel(node, schema[SCHEMADATA]);
      } catch (e) {
        throw new ValidationException(e.message + " at " + key + ".");
      }
    } else {
      throw new ValidationException("Expected object for " + key);
    }
  }
1164285
function filter(store, keyObj) {
      var size = 0;
      var data = store.data.asObject();
      var filteredData = {};
      var isArray = store.data.__sorted;
      var validItem;

      // If no key is specified retrieve root data
      if (keyObj && keyObj.constructor === Object) {
        if (isArray) {
          data = store.data.asArray();
          filteredData = [];

          for (var i = 0; i < data.length; i++) {
            validItem = true;
            // Loop through filter fields keys
            for (var key in keyObj) {
              // Data has the specified filter property
              if (data[i][key] !== keyObj[key]) {
                // Discard item from data
                validItem = false;
                break;
              }
            }
            // Add item to filtered data
            if (validItem) {
              filteredData.push(data[i]);
            }
          }
        } else {
          // Loop through store data
          for (var index in data) {
            validItem = true;
            // Loop through filter fields keys
            for (var key in keyObj) {
              // Data has the specified filter property
              if (data[index][key] !== keyObj[key]) {
                // Discard item from data
                validItem = false;
                break;
              }
            }
            // Add item to filtered data
            if (validItem) {
              filteredData[index] = data[index];
            }
          }
        }

        // Update store data object
        store.data = new Result(filteredData, store, store.data.__sorted);
      } 
      // Update store data items length
      store.size = Object.keys(filteredData).length;
    }
266891
function cacheResults (results) {
    // get id column name
    var idColumn = this.query.model.columnName('id')
    // arguments for multi-set
    var setArgs = []
    // args are list of key, value, key, value
    _.each(results, result => {
        // JSON encode result
        try {
            var cacheValue = JSON.stringify(result)
        }
        catch (err) {
            // ignore errors
        }
        // cache value
        if (defined(cacheValue)) {
            // get cache key
            var cacheKey = this.cacheKey(result[idColumn])
            // debug
            debug('id:set', cacheKey)
            // add to list to cache
            setArgs.push(cacheKey, cacheValue)
        }
    })
    // cache results
    if (setArgs.length > 0) {
        return this.cache.redis.msetAsync(setArgs)
    }
}
487461
function ( datas ) {
            var result = true;
    
            for ( var key in datas ) {
                if ( key !== 'data' ) {
                    if ( this._evtData[key] !== datas[key] ) {
                        result = false;
                        break;
                    }
                }
            }
    
            return result;
        }