<commit_before>let EXPORTED_SYMBOLS = ["db"];

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;

Cu.import("resource://crownconstruction/modules/lib.js");
Cu.import("resource://crownconstruction/modules/toolkit.js");
Cu.import("resource://crownconstruction/modules/log.js");
Cu.import("resource://crownconstruction/modules/configs.js");
Cu.import("resource://crownconstruction/modules/model.js");

/** Entity */
function Entity(key, props)
{
  this.key = function Ent_key() {
    return key;
  };
  this.persistedProperties = function Ent_pp() {
    return props;
  };
}

/** Key */
function Key()
{
  let parts = arguments.length == 1 ? arguments[0].split(" ") : arguments;
  this.realm = parts[0];
  assert((typeof(this.realm) == "string"), "invalid key.realm "+ this.realm);
  assert((typeof(parts[1]) == "string"), "invalid kind "+ parts[1]);
  this.class = model.getClassForKind(parts[1]);
  assert((typeof(this.class) == "string"), "invalid key.class "+ this.class);
  this.kind = parts[1];
  assert((typeof(this.kind) == "string"), "invalid key.kind "+ this.kind);
  this.uri = parts[2];
  assert((typeof(this.uri) == "string"), "invalid key.uri "+ this.uri);
}

/**
 * @constructor
 * Create a Transaction object.
 */
function Transaction(user, message, content)
{
  this.uid = getUUID();
  this.seq = new Date().getTime();
  this.datetime = getUTCDateTime();
  this.message = message;
  this.user = user;
  this.content = content;
}

let db = {};
db.connection = null;
db.logger = null;
db.cache = {};
db.updates = [];
db.Entity = Entity;
db.Key = Key;
db.Transaction = Transaction;

let _burning = false;

db.launch = function DB_launch()
{
  if(_burning)
    return;

  db.logger = log.getLogger("db");
  db.connection = db.getConnection();

  _burning = true;
};

/** create an new entity instance by class */
db.createNewEntity = function DB_createNewEntity(kind)
{
  let props = model.hasKind(kind);
  assert(props, "A model for kind '"+ kind +"' could not be found.");
  if(!props) {
    throw new TypeError("A model for kind '"+ kind
        +"' could not be found.");
  }

  let key = new Key(configs.get("realm"), kind, getUUID());
  let ent = new Entity(key, {});
  db.cache[key.uri] = ent;
  db.updates.push(ent);
  return key;
};
<commit_msg>rename: createNewEntity() -> createNew() in db<commit_after>let EXPORTED_SYMBOLS = ["db"];

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;

Cu.import("resource://crownconstruction/modules/lib.js");
Cu.import("resource://crownconstruction/modules/toolkit.js");
Cu.import("resource://crownconstruction/modules/log.js");
Cu.import("resource://crownconstruction/modules/configs.js");
Cu.import("resource://crownconstruction/modules/model.js");

/** Entity */
function Entity(key, props)
{
  this.key = function Ent_key() {
    return key;
  };
  this.persistedProperties = function Ent_pp() {
    return props;
  };
}

/** Key */
function Key()
{
  let parts = arguments.length == 1 ? arguments[0].split(" ") : arguments;
  this.realm = parts[0];
  assert((typeof(this.realm) == "string"), "invalid key.realm "+ this.realm);
  assert((typeof(parts[1]) == "string"), "invalid kind "+ parts[1]);
  this.class = model.getClassForKind(parts[1]);
  assert((typeof(this.class) == "string"), "invalid key.class "+ this.class);
  this.kind = parts[1];
  assert((typeof(this.kind) == "string"), "invalid key.kind "+ this.kind);
  this.uri = parts[2];
  assert((typeof(this.uri) == "string"), "invalid key.uri "+ this.uri);
}

/**
 * @constructor
 * Create a Transaction object.
 */
function Transaction(user, message, content)
{
  this.uid = getUUID();
  this.seq = new Date().getTime();
  this.datetime = getUTCDateTime();
  this.message = message;
  this.user = user;
  this.content = content;
}

let db = {};
db.connection = null;
db.logger = null;
db.cache = {};
db.updates = [];
db.Entity = Entity;
db.Key = Key;
db.Transaction = Transaction;

let _burning = false;

db.launch = function DB_launch()
{
  if(_burning)
    return;

  db.logger = log.getLogger("db");
  db.connection = db.getConnection();

  _burning = true;
};

/** create an new entity instance by class */
db.createNew = function DB_createNewEntity(kind)
{
  let props = model.hasKind(kind);
  assert(props, "A model for kind '"+ kind +"' could not be found.");
  if(!props) {
    throw new TypeError("A model for kind '"+ kind
        +"' could not be found.");
  }

  let key = new Key(configs.get("realm"), kind, getUUID());
  let ent = new Entity(key, {});
  db.cache[key.uri] = ent;
  db.updates.push(ent);
  return key;
};

{'fraction_non_alphanumeric': 0.1819944001723024, 'fraction_numerical': 0.0034460478139134183, 'mean_word_length': 4.097694840834248, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2058699', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1549, 'n_words': 350}