<commit_before>"use strict";

import modules = require("modules");
var SerializationPacket = modules.serialization.SerializationPacket;
var nullPacket = SerializationPacket.nullPacket;
import $=require("zepto");
var isArray = $.isArray;
//import lf = require("localforage");
declare var localforage;
declare var realwindow;
var lf = localforage;

var lnks = [];
var objs = {};

var priv = {
    loadLocalForage: function(){
        console.log("fetching from localForage...");
        return lf.getItem("links").then(function(linkJson){
            try{
                lnks = JSON.parse(linkJson) || [];
            }catch(e){
                console.log(e);
                lnks=[];
            }
            return lf.getItem("objs");
        }).then(function(objJson){
            try{
                objs = JSON.parse(objJson) || {};
            }catch(e){
                console.log(e);
                lnks=[];
            }
        }).then(function(){console.log("lf fetch finished")});
    },

    dump: function () {
        console.log("writing localForage...");
        return lf.setItem("objs", JSON.stringify(objs)).then(function(){
            return lf.setItem("links", JSON.stringify(lnks)); // "object cannot be cloned"
        }).then(function(){console.log("lf commit finished")});
    },

    getLinks: function (fromId, type) {
        return lnks.filter(function (l) {
            return l.fromId === fromId && l.type === type;
        });
    },

    indexOfLink: function (fromId, type) {
        var i;<commit_msg>bail on cyclic references<commit_after>"use strict";

import modules = require("modules");
var SerializationPacket = modules.serialization.SerializationPacket;
var nullPacket = SerializationPacket.nullPacket;
import $=require("zepto");
var isArray = $.isArray;
//import lf = require("localforage");
declare var localforage;
declare var realwindow;
var lf = localforage;

var lnks = [];
var objs = {};

var priv = {
    loadLocalForage: function(){
        console.log("fetching from localForage...");
        return lf.getItem("links").then(function(linkJson){
            try{
                lnks = JSON.parse(linkJson) || [];
            }catch(e){
                console.log(e);
                lnks=[];
            }
            return lf.getItem("objs");
        }).then(function(objJson){
            try{
                objs = JSON.parse(objJson) || {};
            }catch(e){
                console.log(e);
                lnks=[];
            }
        }).then(function(){console.log("lf fetch finished")});
    },

    dump: function () {
        console.log("writing localForage...");
        try {
            var odata = JSON.stringify(objs);
            var ldata = JSON.stringify(lnks);
        } catch(e) {
            alert("fakedb.dump JSON FAIL 1");
        }
        return lf.setItem("objs", odata).then(function(){
            return lf.setItem("links", ldata); // "object cannot be cloned"
        }).then(function(){console.log("lf commit finished")});
    },

    getLinks: function (fromId, type) {
        return lnks.filter(function (l) {
            return l.fromId === fromId && l.type === type;
        });
    },

    indexOfLink: function (fromId, type) {
        var i;
{'fraction_non_alphanumeric': 0.15327793167128348, 'fraction_numerical': 0.0003077870113881194, 'mean_word_length': 2.11601150527325, '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': '7641169', 'n_tokens_mistral': 960, 'n_tokens_neox': 923, 'n_words': 204}