<commit_before>'use strict';

/**
 * ButtressJS - Realtime datastore for business software
 *
 * @file index.js
 * @description Model management
 * @module Model
 * @author <NAME>
 *
 */

const path = require('path');
const fs = require('fs');
const Logging = require('../logging');
const Sugar = require('sugar');
const Schema = require('../schema');
const SchemaModel = require('./schemaModel');

/**
 * @param {string} model - name of the model to load
 * @private
 */

/**
 * @class Model
 */
class Model {
  constructor() {
    this.models = {};
    this.Schema = {};
    this.Constants = {};
    this.mongoDb = null;
    this.app = false;
    this.appMetadataChanged = false;
  }

  init(db) {
    this.mongoDb = db;

    // Core Models
    this.initCoreModels();

    // Load schema models
    // this.initSchema();
  }

  initCoreModels(db) {
    if (db) this.mongoDb = db;
    // Core Models
    let models = _getModels();
    Logging.log(models, Logging.Constants.LogLevel.SILLY);
    for (let x = 0; x < models.length; x++) {
      this._initModel(models[x]);
    }
  }

  initSchema(db) {
    if (db) this.mongoDb = db;

    return this.models.App.findAll().toArray()
    .then(apps => {
      apps.forEach(app => {
        if (app.__schema) {
          Schema.buildCollections(app.__schema).forEach(schema => {
            this._initSchemaModel(app, schema);
          });
        }
      });
    });<commit_msg>- TWEAK: Enable init of schema models<commit_after>'use strict';

/**
 * ButtressJS - Realtime datastore for business software
 *
 * @file index.js
 * @description Model management
 * @module Model
 * @author <NAME>
 *
 */

const path = require('path');
const fs = require('fs');
const Logging = require('../logging');
const Sugar = require('sugar');
const Schema = require('../schema');
const SchemaModel = require('./schemaModel');

/**
 * @param {string} model - name of the model to load
 * @private
 */

/**
 * @class Model
 */
class Model {
  constructor() {
    this.models = {};
    this.Schema = {};
    this.Constants = {};
    this.mongoDb = null;
    this.app = false;
    this.appMetadataChanged = false;
  }

  init(db) {
    this.mongoDb = db;

    // Core Models
    this.initCoreModels();

    // Load schema models
    this.initSchema();
  }

  initCoreModels(db) {
    if (db) this.mongoDb = db;
    // Core Models
    let models = _getModels();
    Logging.log(models, Logging.Constants.LogLevel.SILLY);
    for (let x = 0; x < models.length; x++) {
      this._initModel(models[x]);
    }
  }

  initSchema(db) {
    if (db) this.mongoDb = db;

    return this.models.App.findAll().toArray()
    .then(apps => {
      apps.forEach(app => {
        if (app.__schema) {
          Schema.buildCollections(app.__schema).forEach(schema => {
            this._initSchemaModel(app, schema);
          });
        }
      });
    });
{'fraction_non_alphanumeric': 0.16231278300243818, 'fraction_numerical': 0.0006966213862765587, 'mean_word_length': 2.515299877600979, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '2327315', 'n_tokens_mistral': 933, 'n_tokens_neox': 911, 'n_words': 212}