<commit_before>var defClass = require('../abnfjs/classgenerator');
var exports = module.exports = {};

var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};

var notImplemented = function() { throw new Error('not implemented') }

var Query = defClass(null,
function Query() {},
{
  run: notImplemented,
  sendResults: notImplemented
})

var Query = exports.Query = (function() {
	function Query() {}
	Query.prototype.run = function(db) { throw new Error('not implemented') };
	Query.prototype.sendResults = function(res) { throw new Error('not implemented') };
	return Query;
})();

var UnsupportedQuery = exports.UnsupportedQUery = defClass(Query,
function UnsupportedQuery(text) { this.text = text },
{
  run: function(db) {},
  sendResults: function(res, body) {
		res.statusCode = 400;
		res.end('unsupported query: \n' + this.text && this.text.toString());
  }
})

var EntitySetQuery = exports.EntitySetQuery = defClass(Query,
function EntitySetQuery(args /* := entitySetName, navigationStack, filterOption, expandTree */) { this.args = args },
{
  run: function(db) {
    var schema = db.getSchema();
    var currentSchema = schema.entitySets[this.args.entitySetName];
    if(!currentSchema) return { error: ErrorTypes.ENTITYSET_NOTFOUND };
    var firstPrimitiveQuery = new PrimitiveQuery_EntitySet(this.args.entitySetName, this.args.navigationStack, 0); //only apply filter if many items wanted
    var secondPrimitiveQuery;
    if(this.args.navigationStack.length > firstPrimitiveQuery.getLength()) {
      var firstResult = firstPrimitiveQuery.getResult(db);
      secondPrimitiveQuery = new PrimitiveQuery_Entity(this.args.entitySetName, this.result.result, this.args.navigationStack, firstPrimitiveQuery.getLength());
      this.result = secondPrimitiveQuery.getResult(db);
      if(this.args.navigationStack.length > (firstPrimitiveQuery.getLength()+secondPrimitiveQuery.getLength()))
        throw new Error('unsupported resource path');
    }
    else {
      this.result = firstPrimitiveQuery.getResult(db, { filterOption: this.args.filterOption, expandTree: this.args.expandTree });
    }
  },
  sendResults: function(res) {
    if(!this.result.error) {
      res.writeHeader(200, {'Content-type': 'application/json' });
		  res.end(JSON.stringify(this.result.result, null, 2));
    }
    else handleErrors(this.result, res);
  }
})

//A helper query to retrieve a collection or an element of a collection
var PrimitiveQuery_Base = defClass(null,
function PrimitiveQuery_Base() {},
{
  getLength: notImplemented,
  getResult: notImplemented
})

var PrimitiveQuery_EntitySet = defClass(PrimitiveQuery_Base,
function PrimitiveQuery_EntitySet(entitySetName, navigationStack, stackPos) {
  this._len = 0;
  this.entitySetName = entitySetName;<commit_msg>fix error querying property of single entity<commit_after>var defClass = require('../abnfjs/classgenerator');
var exports = module.exports = {};

var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};

var notImplemented = function() { throw new Error('not implemented') }

var Query = defClass(null,
function Query() {},
{
  run: notImplemented,
  sendResults: notImplemented
})

var Query = exports.Query = (function() {
	function Query() {}
	Query.prototype.run = function(db) { throw new Error('not implemented') };
	Query.prototype.sendResults = function(res) { throw new Error('not implemented') };
	return Query;
})();

var UnsupportedQuery = exports.UnsupportedQUery = defClass(Query,
function UnsupportedQuery(text) { this.text = text },
{
  run: function(db) {},
  sendResults: function(res, body) {
		res.statusCode = 400;
		res.end('unsupported query: \n' + this.text && this.text.toString());
  }
})

var EntitySetQuery = exports.EntitySetQuery = defClass(Query,
function EntitySetQuery(args /* := entitySetName, navigationStack, filterOption, expandTree */) { this.args = args },
{
  run: function(db) {
    var schema = db.getSchema();
    var currentSchema = schema.entitySets[this.args.entitySetName];
    if(!currentSchema) return { error: ErrorTypes.ENTITYSET_NOTFOUND };
    var firstPrimitiveQuery = new PrimitiveQuery_EntitySet(this.args.entitySetName, this.args.navigationStack, 0); //only apply filter if many items wanted
    var secondPrimitiveQuery;
    if(this.args.navigationStack.length > firstPrimitiveQuery.getLength()) {
      var firstResult = firstPrimitiveQuery.getResult(db);
      secondPrimitiveQuery = new PrimitiveQuery_Entity(this.args.entitySetName, firstResult.result, this.args.navigationStack, firstPrimitiveQuery.getLength());
      this.result = secondPrimitiveQuery.getResult(db);
      if(this.args.navigationStack.length > (firstPrimitiveQuery.getLength()+secondPrimitiveQuery.getLength()))
        throw new Error('unsupported resource path');
    }
    else {
      this.result = firstPrimitiveQuery.getResult(db, { filterOption: this.args.filterOption, expandTree: this.args.expandTree });
    }
  },
  sendResults: function(res) {
    if(!this.result.error) {
      res.writeHeader(200, {'Content-type': 'application/json' });
		  res.end(JSON.stringify(this.result.result, null, 2));
    }
    else handleErrors(this.result, res);
  }
})

//A helper query to retrieve a collection or an element of a collection
var PrimitiveQuery_Base = defClass(null,
function PrimitiveQuery_Base() {},
{
  getLength: notImplemented,
  getResult: notImplemented
})

var PrimitiveQuery_EntitySet = defClass(PrimitiveQuery_Base,
function PrimitiveQuery_EntitySet(entitySetName, navigationStack, stackPos) {
  this._len = 0;
  this.entitySetName = entitySetName;
{'fraction_non_alphanumeric': 0.1293759512937595, 'fraction_numerical': 0.0030441400304414, 'mean_word_length': 4.686538461538461, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3563940', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1769, 'n_words': 397}