<commit_before>core.service("AbstractRepo", function ($q, WsApi, ValidationStore) {

	return function AbstractRepo(model, mapping) {

		var abstractRepo = this;

		abstractRepo.mapping = mapping;

		var list = [];

		var initialized = false;

		var defer = $q.defer();

		var listenCallbacks = [];

		var entityName = new model({}).getEntityName();

		var validations = ValidationStore.getValidations(entityName);

		var build = function(data) {
			initialized = false;
			return $q(function(resolve) {
				list.length = 0;
				angular.forEach(data, function(modelJson) {
					list.push(new model(modelJson));
				});
				initialized = true
				resolve();
			});
		};

		var unwrap = function(res) {
			var repoObj = {};
			var payload = angular.fromJson(res.body).payload;
			var keys = Object.keys(payload);
			angular.forEach(keys, function(key) {
				angular.extend(repoObj, payload[key]);
			})
			return repoObj;
		};

		var fetch = function() {
			if(abstractRepo.mapping.all !== undefined) {
				WsApi.fetch(abstractRepo.mapping.all).then(function(res) {
					build(unwrap(res)).then(function() {
						defer.resolve(res);
					});
				});
			}
		};

		WsApi.listen(abstractRepo.mapping.listen).then(null, null, function(res) {
			build(unwrap(res)).then(function() {
				angular.forEach(listenCallbacks, function(cb) {
					cb(res);
				});
			});
		});

		fetch();

		abstractRepo.ValidationResults = {};

		abstractRepo.getEntityName = function() {
			return entityName;
		};

		abstractRepo.getValidations = function() {
			return validations;
		};

		abstractRepo.count = function() {
			if(!initialized) {
				console.error('Repo not initialized!');
			}
			return list.length;
		};

		abstractRepo.getAll = function() {
			return list;
		};

		abstractRepo.saveAll = function() {
			angular.forEach(list, function(model) {
				model.save();
			});
		};

		abstractRepo.ready = function() {
			return defer.promise;
		};

		abstractRepo.reset = function() {
			defer = $q.defer();
			fetch();
		};

		abstractRepo.findById = function(id) {
			var match;
			
			var find = function(id) {
				for(var key in list) {
					if(list[key].id == id) {<commit_msg>Repo can now lazy load by setting mapping.lazy to true<commit_after>core.service("AbstractRepo", function ($q, WsApi, ValidationStore) {

	return function AbstractRepo(model, mapping) {

		var abstractRepo = this;

		abstractRepo.mapping = mapping;

		var list = [];

		var initialized = false;

		var defer = $q.defer();

		var listenCallbacks = [];

		var entityName = new model({}).getEntityName();

		var validations = ValidationStore.getValidations(entityName);

		var build = function(data) {
			initialized = false;
			return $q(function(resolve) {
				list.length = 0;
				angular.forEach(data, function(modelJson) {
					list.push(new model(modelJson));
				});
				initialized = true
				resolve();
			});
		};

		var unwrap = function(res) {
			var repoObj = {};
			var payload = angular.fromJson(res.body).payload;
			var keys = Object.keys(payload);
			angular.forEach(keys, function(key) {
				angular.extend(repoObj, payload[key]);
			})
			return repoObj;
		};

		var fetch = function() {
			if(abstractRepo.mapping.all !== undefined) {
				WsApi.fetch(abstractRepo.mapping.all).then(function(res) {
					build(unwrap(res)).then(function() {
						defer.resolve(res);
					});
				});
			}
		};

		WsApi.listen(abstractRepo.mapping.listen).then(null, null, function(res) {
			build(unwrap(res)).then(function() {
				angular.forEach(listenCallbacks, function(cb) {
					cb(res);
				});
			});
		});

		if(!mapping.lazy) {
			fetch();
		}

		abstractRepo.ValidationResults = {};

		abstractRepo.getEntityName = function() {
			return entityName;
		};

		abstractRepo.getValidations = function() {
			return validations;
		};

		abstractRepo.count = function() {
			if(!initialized) {
				console.error('Repo not initialized!');
			}
			return list.length;
		};

		abstractRepo.getAll = function() {
			if(mapping.lazy) {
				fetch();
			}
			return list;
		};

		abstractRepo.saveAll = function() {
			angular.forEach(list, function(model) {
				model.save();
			});
		};

		abstractRepo.ready = function() {
			return defer.promise;
		};

		abstractRepo.reset = function() {
			defer = $q.defer();
			fetch();
		};

		abstractRepo.findById = function(id) {
			var match;
			
			var find = function(id) {
				for(var key in list) {
					if(list[key].id == id) {
{'fraction_non_alphanumeric': 0.15227170490328384, 'fraction_numerical': 0.000449842555105713, 'mean_word_length': 3.231208372978116, 'pattern_counts': {'":': 0, '<': 3, '<?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': '83975', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1433, 'n_words': 268}