@function ImmutableCoreModel

create a new model instance

@param {object} args

@returns {object}

@throws {Error}
182002
function ImmutableCoreModel (args) {
    // store copy of original args
    this.args = _.cloneDeep(args)
    // initialize global data
    this.initGlobal(args)
    // create module and set options
    this.initModule(args)
    // initialize column spec for model
    this.initColumns(args)
    // initialize multi-column indexes
    this.initIndexes(args)
    // create and validate JSON schema
    this.initJsonSchema(args)
    // add create method to module
    this.initCreate(args)
    // add query method to module
    this.initQuery(args)
    // add associated actions
    this.initActions(args)
    // initialize any model views
    this.initViews(args)
    // initialize related models
    this.initRelations(args)
    // initialize access control
    this.initAccessControl(args)
    // create columnsId
    this.initIds()
}
286643
function initModule (args) {
    debug('new ImmutableCoreModel', args)
    // require object for args
    assert.equal(typeof args, 'object', 'argument must be object')
    // require name for model
    assert.equal(typeof args.name, 'string', 'name required')
    // set model name
    this.name = args.name
    // create title from name
    this.title = changeCase.titleCase(this.name)
    // create path from name
    this.path = changeCase.paramCase(this.name)
    // module name is model name with Model appended
    this.moduleName = args.name+'Model'
    // create new immutable module for model - this will throw error
    // if moduleName is already defined
    this.module = immutable.module(this.moduleName, {})
    // add info to module meta
    this.module.meta.class = 'ImmutableCoreModel'
    this.module.meta.instance = this
    // and model to global registers
    this.global().models[this.name] = this
    // set to true if model is an action for another model
    this.isAction = false
    // parent model for action models
    this.model = undefined
    // controller object will be set when controller created for model
    this.controller = undefined
    // transformation functions keyed by property name
    this.transform = {}
    // get transform functions from args
    _.each(args.transform, (transform, property) => {
        // require function
        assert.equal(typeof transform, 'function', `tranform must be function for ${this.name} ${property}`)
        // set transform function
        this.transform[property] = transform
    })

    /* cache */

    if (defined(args.redis)) {
        this.redis(args.redis)
    }

    /* database */

    // database is now deprecated so this will throw error
    if (defined(args.database)) {
        this.database(args.database)
    }

    /* binaryIds */

    // use setting from env if set
    if (defined(process.env.DEFAULT_BINARY_IDS)) {
        this.binaryIds = process.env.DEFAULT_BINARY_IDS === 'true' || process.env.DEFAULT_BINARY_IDS === '1' ? true : false
    }
    // use binary ids setting for model if set
    else if (defined(args.binaryIds)) {
        this.binaryIds = !!args.binaryIds
    }
    // use global setting
    else {
        this.binaryIds = this.global().defaultBinaryIds
    }

    /* compression */

    // use setting from env
    if (defined(process.env.DEFAULT_COMPRESSION)) {
        this.compression = process.env.DEFAULT_COMPRESSION === 'true' || process.env.DEFAULT_COMPRESSION === '0' ? true : false
    }
    // use compresion setting for model if set
    else if (defined(args.compression)) {
        this.compression = !!args.compression
    }
    // use global setting
    else {
        this.compression = this.global().defaultCompression
    }

    /* insert delayed */

    // use insert delayed setting for model if set
    if (args.insertDelayed !== undefined) {
        this.insertDelayed = args.insertDelayed
    }
    // use global setting
    else if (process.env.DEFAULT_INSERT_DELAYED) {
        this.insertDelayed = process.env.DEFAULT_INSERT_DELAYED === 'true' ? true : false
    }
    // use global setting
    else {
        this.insertDelayed = this.global().insertDelayed
    }

    /* concurrency */

    // use concurrency setting from args if set
    if (parseInt(args.concurrency)) {
        this.concurrency = parseInt(args.concurrency)
    }
    // use global setting
    else {
        this.concurrency = this.global().concurrency
    }

    /* charset */

    // charset to use when creating table - this only applies when mode is
    // first syncd and will not be changed
    this.charset = args.charset || process.env.DEFAULT_CHARSET || this.global().defaultCharset

    /* database engine */

    // database engine to use when creating table - this only applies when model
    // is first syncd and will not be changed
    this.engine = args.engine || process.env.DEFAULT_ENGINE || this.global().defaultEngine

    /* elasticsearch configuration */

    // if elasticsearch is true then client will be set later and is required
    if (args.elasticsearch === true) {
        this.elasticsearchClient = true
    }
    // set elasticsearch client
    else if (args.elasticsearch) {
        this.elasticsearch(args.elasticsearch)
    }
    else {
        this.elasticsearchClient = null
    }
    // retain deleted records - default false
    this.esDeleted = !!args.esDeleted
    // set index name - default to model path
    this.esIndex = args.esIndex || this.path
    // set type selector - if not defined model name will also be used for type
    this.esType = args.esType

    /* mysql */

    if (defined(args.mysql)) {
        this.mysql(args.mysql)
    }
    else {
        this.mysqlClient = null
    }
}
423776
function newTask (call) {
    // get clone of call and reset original
    call = resetCall(call)
    // require ImmutableCoreComponent
    assert.ok(GLOBAL.immutableCoreTask !== undefined, 'ImmutableAI configuration error: immutableCoreTask required')
    // get task - throws error if not found
    var task = GLOBAL.immutableCoreTask.task(call.module)
    // return function wrapper that calls new with session
    return args => {
        // make sure args is object
        if (!defined(args)) {
            args = {}
        }
        // add session to args if not defined
        if (!defined(args.session)) {
            args.session = call.session
        }
        // create new component
        return task.new(args)
    }
}
84804
function initModule (args) {
    // require string name
    this.assert(typeof args.name === 'string' && args.name.length, 101)
    // component must not already be defined
    this.assert(!defined(this.global().components[args.name]), 102, `${args.name} component already defined`)
    // store name
    this.name = args.name
    // create module name from string with `Component` appended
    this.moduleName = `${this.name}Component`
    // create new module - throws error if defined
    this.module = ImmutableCore.module(this.moduleName, {})
    // add info to module meta
    this.module.meta.class = 'ImmutableCoreComponent'
    this.module.meta.instance = this
    // add component to global register
    this.global().components[this.name] = this
}
84888
function initModel (args) {
    // if model is not passed then do nothing
    if (!args.model) {
        return
    }
    // if paths is false then do not create any default paths
    if (args.paths === false) {
        return
    }
    // require object to have ImmutableCoreObject class property
    assert.ok(args.model.ImmutableCoreModel, 'invalid model')
    // save model
    this.model = args.model
    // register controller with model
    this.model.controller = this
    // if model has data then create form for it
    if (this.model.schemaData && _.keys(this.model.schemaData.properties).length) {
        // build args for new form
        var formArgs = {
            action: './',
            method: 'POST',
            model: this.model,
            submit: {
                title: 'Create '+changeCase.titleCase(this.model.name),
            },
            title: 'New '+changeCase.titleCase(this.model.name),
        }
        // merge any args for form
        _.merge(formArgs, args.form)
        // create new form instance from model
        this.form = new ImmutableCoreModelForm(formArgs)
    }
    // create path entry if it does not exist
    if (!this.paths) {
        this.paths = {}
    }
    // create actions object
    this.actions = {}
    // merge actions from controller spec
    if (defined(args.actions)) {
        // do not allow array
        if (Array.isArray(args.actions)) {
            throw new Error(`actions array deprecated for controller ${this.model.name}`)
        }
        // get actions from controller spec
        _.merge(this.actions, args.actions)
    }
    // create list view controller
    this.initModelList(args)
    // new instance controller
    this.initModelNew(args)
    // create instance controller
    this.initModelCreate(args)
    // get instance controller
    this.initModelRead(args)
    // update instance controller
    this.initModelUpdate(args)
    // link model to relations controller
    this.initModelLink(args)
    // unlink model from relation controller
    this.initModelUnlink(args)
    // delete instance controller
    this.initModelDelete(args)
    // model schema controller
    this.initModelSchema(args)
    // validate data controller
    this.initModelValidate(args)
}
886142
function immutable(/* a[, b[, ...]] */)
{
  // invoke mutable with new object as first argument
  var args = Array.prototype.slice.call(arguments, 0);
  // use `undefined` as always-override value
  return mutable.apply(this, [undefined].concat(args));
}
588769
function cloneArgs(args) {
    var newArgs = {};
    for(var key in args){
      if (key && args.hasOwnProperty(key)) {
        newArgs[key] = args[key];
      }
    }
    newArgs.isCacheableValue = args.isCacheableValue && args.isCacheableValue.bind(newArgs);
    return newArgs;
  }
353503
function ImmutableCoreController (args) {
    // get copy of original args
    this.args = _.cloneDeep(args)
    // create module and set options
    this.initModule(args)
    // create default paths for model if passed
    this.initModel(args)
    // create paths from arguments
    this.initPaths(args)
    // sort controllers
    this.orderControllers()
}
970100
function newInstance(extend) {
  return (initialValues = {}) => {
    const model = {};
    const publicAPI = {};
    extend(publicAPI, model, initialValues);
    return Object.freeze(publicAPI);
  };
}
626655
function() {
        var C = this;
        var l= arguments.length;
        if (l > 0) {
          var args = new Array(l);
          for (var i = 0; i < l; i++) {
            args[i] = arguments[i];
          }
          this._initMixins(args);
        }
        return new C();
      }
209554
function(Constructor, args) {
        var instance,
            Wrapper = function() {
                return Constructor.apply(this, args || []);
            };

        Wrapper.prototype = Constructor.prototype;
        instance = new Wrapper();
        instance.constructor = Constructor;

        return instance;
    }
171283
def create(cls, arg):
        
        obj = cls()
        obj._connection = arg.connection
        obj._heading = arg.heading.make_subquery_heading()
        obj._arg = arg
        return obj
224235
function validateArgs (validateArgs) {
    // set default if value passed
    if (defined(validateArgs)) {
        immutable.defaultValidateArgs = validateArgs ? true : false
        // return immutable
        return ImmutableCore
    }
    // return default value
    return immutable.defaultValidateArgs
}
145647
public static Scriptable newObject(Object fun, Context cx,
                                       Scriptable scope, Object[] args)
    {
        if (!(fun instanceof Function)) {
            throw notFunctionError(fun);
        }
        Function function = (Function)fun;
        return function.construct(cx, scope, args);
    }
1300885
function createActionArgs (args, action, state, isAsync) {
  var stateMethods = getStateMutatorsAndAccessors(state, action, isAsync);
  return [ args, stateMethods ];
}
737012
function (args) {
    //console.log('PutModel messageContents: json  ' + JSON.stringify(messageContents));
    Model.call(this, args);
    this.modelType = messageContents.modelType;
    this.attributes = [];
    var a, attrib, v;
    for (a in messageContents.attributes) {
      //console.log('PutModel Attribute: json  ' + JSON.stringify(messageContents.attributes[a]));
      if (messageContents.attributes[a].type == 'Model') {
        v = new Attribute.ModelID(createModelFromModelType(messageContents.attributes[a].modelType));
        v.value = messageContents.attributes[a].value.value;
        if (messageContents.attributes[a].value.name)
          v.name = messageContents.attributes[a].value.name;
        attrib = new Attribute({name: messageContents.attributes[a].name, type: 'Model', value: v});
      } else if (messageContents.attributes[a].type == 'Date') {
        attrib = new Attribute(messageContents.attributes[a].name, messageContents.attributes[a].type);
        try {
          attrib.value = messageContents.attributes[a].value === null ? null : new Date(messageContents.attributes[a].value);
        } catch (e) {
          attrib.value = null;
        }
      } else {
        attrib = new Attribute(messageContents.attributes[a].name, messageContents.attributes[a].type);
        if (attrib.name == 'id') { // TODO only If mongo! or refactor mongo to normalize IDs
          if (attrib.value != messageContents.attributes[a].value)
            attrib.value = messageContents.attributes[a].value;
        } else {
          attrib.value = messageContents.attributes[a].value;
        }
      }
      this.attributes.push(attrib);
    }
  }
629349
def instance_for_arguments(self, arguments):
        
        result = ModelInstance()
        for key, value in self.__dict__.items():
            if isinstance(value, AbstractPriorModel):
                value = value.instance_for_arguments(arguments)
            setattr(result, key, value)
        return result