<commit_before>(function() {
  var ResourceClient, Spine, assert;

  Spine = require('spine');

  assert = require('./util').assert;

  ResourceClient = (function() {

    function ResourceClient(options) {
      this.sync = options.sync;
      this.appContext = options.appContext;
      this.base = null;
      this.headers = {};
      this.routes = null;
      this.IDField = "id";
      this.dataCoding = "form";
    }

    ResourceClient.prototype.fetch = function(model, options) {
      var collection, ids, path,
        _this = this;
      if (options == null) options = {};
      console.log("[ResourceClient] Fetching with options", options);
      collection = model.className;
      path = this._findPath(collection, "index", options.pathParams);
      ids = [];
      return this._request(path, options.params, function(result) {
        var item, items, uri, _i, _len;
        items = _this.itemsFromResult(result);
        if (items == null) {
          console.log("[ResourceClient] Items not found in response", result);
          return;
        }
        console.log("[ResourceClient] Found " + items.length + " items");
        for (_i = 0, _len = items.length; _i < _len; _i++) {
          item = items[_i];
          item.id = item[_this.IDField];
          assert(item.id, "[ResourceClient] There's no field '" + _this.IDField + "' that is configured as IDField in incoming object");
          ids.push(item.id);
          uri = {
            collection: collection,
            id: item.id
          };
          if (options.updateData != null) options.updateData(item);
          console.log("updated", item);
          _this.sync.updateOrCreate(uri, item);
          _this.sync.markURISynced(uri);
        }
        if (options.remove === true) {
          return _this._removeObjectsNotInList(collection, ids);
        }
      });
    };

    ResourceClient.prototype._removeObjectsNotInList = function(collection, ids) {
      var isInList, uri, uris, _i, _len, _results;
      uris = this.appContext.allURIs(collection);
      _results = [];
      for (_i = 0, _len = uris.length; _i < _len; _i++) {
        uri = uris[_i];
        isInList = ids.indexOf(uri.id) !== -1;
        if (!isInList) {
          console.log("[ResourceClient] Local id " + uri.id + " wasn't retrieved, destroying.");
          _results.push(this.appContext.destroy(uri));
        } else {
          _results.push(void 0);
        }
      }
      return _results;
    };

    ResourceClient.prototype.itemsFromResult = function(result) {<commit_msg>Building<commit_after>(function() {
  var ResourceClient, Spine, assert;

  Spine = require('spine');

  assert = require('./util').assert;

  ResourceClient = (function() {

    function ResourceClient(options) {
      this.sync = options.sync;
      this.appContext = options.appContext;
      this.base = null;
      this.headers = {};
      this.routes = null;
      this.IDField = "id";
      this.dataCoding = "form";
    }

    ResourceClient.prototype.fetch = function(model, options) {
      var collection, ids, path,
        _this = this;
      if (options == null) options = {};
      console.log("[ResourceClient] Fetching with options", options);
      collection = model.className;
      path = this._findPath(collection, "index", options.pathParams);
      ids = [];
      return this._request(path, options.params, function(result) {
        var item, items, uri, _i, _len;
        items = _this.itemsFromResult(result);
        if (items == null) {
          console.log("[ResourceClient] Items not found in response", result);
          return;
        }
        console.log("[ResourceClient] Found " + items.length + " items");
        for (_i = 0, _len = items.length; _i < _len; _i++) {
          item = items[_i];
          item.id = item[_this.IDField];
          assert(item.id, "[ResourceClient] There's no field '" + _this.IDField + "' that is configured as IDField in incoming object");
          ids.push(item.id);
          uri = {
            collection: collection,
            id: item.id
          };
          if (options.updateData != null) options.updateData(item);
          _this.sync.updateOrCreate(uri, item);
          _this.sync.markURISynced(uri);
        }
        if (options.remove === true) {
          return _this._removeObjectsNotInList(collection, ids);
        }
      });
    };

    ResourceClient.prototype._removeObjectsNotInList = function(collection, ids) {
      var isInList, uri, uris, _i, _len, _results;
      uris = this.appContext.allURIs(collection);
      _results = [];
      for (_i = 0, _len = uris.length; _i < _len; _i++) {
        uri = uris[_i];
        isInList = ids.indexOf(uri.id) !== -1;
        if (!isInList) {
          console.log("[ResourceClient] Local id " + uri.id + " wasn't retrieved, destroying.");
          _results.push(this.appContext.destroy(uri));
        } else {
          _results.push(void 0);
        }
      }
      return _results;
    };

    ResourceClient.prototype.itemsFromResult = function(result) {
{'fraction_non_alphanumeric': 0.1360853249061821, 'fraction_numerical': 0.0015800908552241755, 'mean_word_length': 2.2883116883116883, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '7211407', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1478, 'n_words': 334}