<commit_before>var common = require('./common')
var typ = require('typ')
var DynamoRequest = require('./DynamoRequest')
var DynamoResponse = require('./DynamoResponse')
var Builder = require('./Builder')
var Q = require('kew')
var IndexNotExistError = require('./errors').IndexNotExistError

/**
 * @param {Object} options
 * @constructor
 * @extends {Builder}
 */
function QueryBuilder(options) {
  Builder.call(this, options)

  /** @private {!Array.<{name: string, operator: string, attributes: !Array}>} */
  this._keyConditions = []
}
require('util').inherits(QueryBuilder, Builder)

/**
 * If this query runs on a local index or global index, set a
 * function that can generate an index name based on query
 * conditions.
 *
 * @param {Function(string, string): string} fn The generator function
 */
QueryBuilder.prototype.setIndexNameGenerator = function (fn) {
  this._indexNameGenerator = fn
  return this
}

QueryBuilder.prototype.setHashKey = function (name, val) {
  if (typ.isNullish(val)) throw new Error('Invalid hash key value: ' + val)
  this._hashKeyName = name
  // The condition on the hash key is always an 'EQ'
  this._keyConditions.push({
    name: name,
    operator: 'EQ',
    attributes: [ val ]
  })
  return this
}

QueryBuilder.prototype.indexBeginsWith = function (name, prefix) {
  this._rangeKeyName = name
  if (typ.isNullish(prefix)) throw new Error('Key must be defined')
  this._keyConditions.push({
    name: name,
    operator: 'BEGINS_WITH',
    attributes: [ prefix ]
  })
  return this
}

QueryBuilder.prototype.indexEquals = function (name, val) {
  if (typ.isNullish(val)) throw new Error('Invalid value for the range key: ' + val)
  this._rangeKeyName = name
  this._keyConditions.push({
    name: name,
    operator: 'EQ',
    attributes: [ val ]
  })
  return this
}
QueryBuilder.prototype.indexEqual = QueryBuilder.prototype.indexEquals

QueryBuilder.prototype.indexLessThanEqual = function (name, val) {
  if (typ.isNullish(val)) throw new Error('Invalid value for the range key: ' + val)
  this._rangeKeyName = name
  this._keyConditions.push({
    name: name,
    operator: 'LE',
    attributes: [ val ]
  })

  return this
}

QueryBuilder.prototype.indexLessThan = function (name, val) {
  if (typ.isNullish(val)) throw new Error('Invalid value for the range key: ' + val)
  this._rangeKeyName = name
  this._keyConditions.push({
    name: name,
    operator: 'LT',
    attributes: [ val ]
  })
  return this
}

QueryBuilder.prototype.indexGreaterThanEqual = function (name, val) {
  if (typ.isNullish(val)) throw new Error('Invalid value for the range key: ' + val)
  this._rangeKeyName = name
  this._keyConditions.push({
    name: name,
    operator: 'GE',
    attributes: [ val ]
  })
  return this
}
QueryBuilder.prototype.indexGreaterThanEquals = QueryBuilder.prototype.indexGreaterThanEqual

QueryBuilder.prototype.indexGreaterThan = function (name, val) {
  if (typ.isNullish(val)) throw new Error('Invalid value for the range key: ' + val)
  this._rangeKeyName = name
  this._keyConditions.push({
    name: name,
    operator: 'GT',
    attributes: [ val ]
  })
  return this
}

QueryBuilder.prototype.indexBetween = function (name, val1, val2) {
  if (typ.isNullish(val1)) throw new Error('Invalid lower bound for the range key: ' + val)
  if (typ.isNullish(val2)) throw new Error('Invalid upper bound for the range key: ' + val)
  this._rangeKeyName = name
  this._keyConditions.push({
    name: name,
    operator: 'BETWEEN',
    attributes: [ val1, val2 ]
  })
  return this
}

QueryBuilder.prototype.setStartKey = function (key) {
  this._startKey = key
  return this
}

/**
 * Set the index name of this query.
 *
 * @param {string} indexName
 */
QueryBuilder.prototype.setIndexName = function (indexName) {
  this._indexName = indexName
  return this
}
<commit_msg>Fix simple typo in dynamite error code<commit_after>var common = require('./common')
var typ = require('typ')
var DynamoRequest = require('./DynamoRequest')
var DynamoResponse = require('./DynamoResponse')
var Builder = require('./Builder')
var Q = require('kew')
var IndexNotExistError = require('./errors').IndexNotExistError

/**
 * @param {Object} options
 * @constructor
 * @extends {Builder}
 */
function QueryBuilder(options) {
  Builder.call(this, options)

  /** @private {!Array.<{name: string, operator: string, attributes: !Array}>} */
  this._keyConditions = []
}
require('util').inherits(QueryBuilder, Builder)

/**
 * If this query runs on a local index or global index, set a
 * function that can generate an index name based on query
 * conditions.
 *
 * @param {Function(string, string): string} fn The generator function
 */
QueryBuilder.prototype.setIndexNameGenerator = function (fn) {
  this._indexNameGenerator = fn
  return this
}

QueryBuilder.prototype.setHashKey = function (name, val) {
  if (typ.isNullish(val)) throw new Error('Invalid hash key value: ' + val)
  this._hashKeyName = name
  // The condition on the hash key is always an 'EQ'
  this._keyConditions.push({
    name: name,
    operator: 'EQ',
    attributes: [ val ]
  })
  return this
}

QueryBuilder.prototype.indexBeginsWith = function (name, prefix) {
  this._rangeKeyName = name
  if (typ.isNullish(prefix)) throw new Error('Key must be defined')
  this._keyConditions.push({
    name: name,
    operator: 'BEGINS_WITH',
    attributes: [ prefix ]
  })
  return this
}

QueryBuilder.prototype.indexEquals = function (name, val) {
  if (typ.isNullish(val)) throw new Error('Invalid value for the range key: ' + val)
  this._rangeKeyName = name
  this._keyConditions.push({
    name: name,
    operator: 'EQ',
    attributes: [ val ]
  })
  return this
}
QueryBuilder.prototype.indexEqual = QueryBuilder.prototype.indexEquals

QueryBuilder.prototype.indexLessThanEqual = function (name, val) {
  if (typ.isNullish(val)) throw new Error('Invalid value for the range key: ' + val)
  this._rangeKeyName = name
  this._keyConditions.push({
    name: name,
    operator: 'LE',
    attributes: [ val ]
  })

  return this
}

QueryBuilder.prototype.indexLessThan = function (name, val) {
  if (typ.isNullish(val)) throw new Error('Invalid value for the range key: ' + val)
  this._rangeKeyName = name
  this._keyConditions.push({
    name: name,
    operator: 'LT',
    attributes: [ val ]
  })
  return this
}

QueryBuilder.prototype.indexGreaterThanEqual = function (name, val) {
  if (typ.isNullish(val)) throw new Error('Invalid value for the range key: ' + val)
  this._rangeKeyName = name
  this._keyConditions.push({
    name: name,
    operator: 'GE',
    attributes: [ val ]
  })
  return this
}
QueryBuilder.prototype.indexGreaterThanEquals = QueryBuilder.prototype.indexGreaterThanEqual

QueryBuilder.prototype.indexGreaterThan = function (name, val) {
  if (typ.isNullish(val)) throw new Error('Invalid value for the range key: ' + val)
  this._rangeKeyName = name
  this._keyConditions.push({
    name: name,
    operator: 'GT',
    attributes: [ val ]
  })
  return this
}

QueryBuilder.prototype.indexBetween = function (name, val1, val2) {
  if (typ.isNullish(val1)) throw new Error('Invalid lower bound for the range key: ' + val1)
  if (typ.isNullish(val2)) throw new Error('Invalid upper bound for the range key: ' + val2)
  this._rangeKeyName = name
  this._keyConditions.push({
    name: name,
    operator: 'BETWEEN',
    attributes: [ val1, val2 ]
  })
  return this
}

QueryBuilder.prototype.setStartKey = function (key) {
  this._startKey = key
  return this
}

/**
 * Set the index name of this query.
 *
 * @param {string} indexName
 */
QueryBuilder.prototype.setIndexName = function (indexName) {
  this._indexName = indexName
  return this
}

{'fraction_non_alphanumeric': 0.12348888600025998, 'fraction_numerical': 0.0018198362147406734, 'mean_word_length': 3.9606705351386204, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4850320', 'n_tokens_mistral': 2399, 'n_tokens_neox': 2388, 'n_words': 678}