export function getModelNames(model : mongoose.model, )
480852
function removeOthers(mongoose, model, retainedNames) {
    //console.log('here collectionname' + Object.keys(model));
    //console.log('here collectionname' + model.collectionname);
    return model.aggregate({ $project: { modelname: 1 } }).then((r) => r.map(o => o.modelname)).then((modelnames) => {
        debuglog(" present models " + modelnames.length + ' ' + modelnames);
        var delta = _.difference(modelnames, retainedNames);
        debuglog(' spurious models' + delta.length + ' ' + delta);
        if (delta.length === 0) {
            return Promise.resolve(true);
        }
        return Promise.all(delta.map(modelname => model.remove({ modelname: modelname })));
    });
}
10763
function getModelInfo (modelName) {
    debug('getModelInfo: ' + modelName)

    // Get the model
    const model = Meta.app.models[ modelName ]

    // Create the base return object
    const result = {
      id: model.definition.name,
      name: model.definition.name,
      properties: formatProperties(model.definition.properties)
    }

    // Get the following keys from the settings object, if they are set
    const keys = {
      'acls': [],
      'base': '',
      'description': '',
      'hidden': [],
      'idInjection': true,
      'methods': {},
      'mixins': {},
      'persistUndefinedAsNull': false,
      'plural': '',
      'relations': {},
      'strict': false,
      'validations': [],
    }

    // Loop through the keys and add them to the result with their value
    Object.keys(keys).forEach(key => {
      result[ key ] = _.get(model.definition.settings, key, keys[ key ])
    })
    return result
  }
1222438
def get_field_model(name, model=None):
    
    if '.' in name:
        m, name = name.split('.')
        model = get_model(m)

    if model:
        return getattr(model, name, None), model
    else:
        return None, None
879860
function getProperties(model) {
    const modelName = model.constructor.name;
    const properties = typed_conversions_1.hashToArray(exports.propertiesByModel[modelName], "property") || [];
    let parent = Object.getPrototypeOf(model.constructor);
    while (parent.name) {
        const subClass = new parent();
        const subClassName = subClass.constructor.name;
        properties.push(...typed_conversions_1.hashToArray(exports.propertiesByModel[subClassName], "property"));
        parent = Object.getPrototypeOf(subClass.constructor);
    }
    return properties;
}
994950
function(model, logger) {
    assert(
      model.schema,
      "model not mongoose format. 'schema' property required."
    )
    assert(
      model.schema.paths,
      "model not mongoose format. 'schema.paths' property required."
    )
    assert(
      model.schema.tree,
      "model not mongoose format. 'schema.tree' property required."
    )

    let fields = model.schema.paths
    let fieldNames = Object.keys(fields)

    assert(
      model.routeOptions,
      "model not mongoose format. 'routeOptions' property required."
    )

    for (let i = 0; i < fieldNames.length; i++) {
      let fieldName = fieldNames[i]
      assert(
        fields[fieldName].options,
        "field not mongoose format. 'options' parameter required."
      )
    }

    return true
  }
829454
function _defineModels() {
  const Section = this.sequelize.import('./models/section');
  const Record = this.sequelize.import('./models/record');
  const User = this.sequelize.import('./models/user');

  Section.hasMany(Record, { as: 'records' });
  Record.belongsTo(Section, { as: 'section' });

  return {
    Section,
    Record,
    User,
  };
}
758587
function getModelProperty(model) {
    const className = model.constructor.name;
    const propsForModel = getProperties(model);
    return (prop) => {
        return propsForModel.find(value => {
            return value.property === prop;
        });
    };
}
475107
function listInstanceMethods (Model) {
  var classMethods = Object.keys(Model.schema.methods);
  for (var method in ModelPrototype) {
    if (!isPrivateMethod(method) && isFunction(ModelPrototype[method])) {
      classMethods.push(method);
    }
  }
  return classMethods;
}
1084131
function getSchema(mongooseModels, options) {
  if (!isArray(mongooseModels)) {
    mongooseModels = [mongooseModels];
  }
  const graffitiModels = model.getModels(mongooseModels);
  const fields = getFields(graffitiModels, options);
  return new GraphQLSchema(fields);
}
1097024
function(schema, from) {
    return function(next) {
        var self = this;
        var funcs = [];
    
        for (var key in from) {
            var items = from[key];
            var model = mongoose.model(schema.path(key).options.ref);
        
            funcs.push(function(callback) {
                model.findOne({ _id: self[key] }, function(err, instance) {
                    if (err) return callback(err);
                
                    items.forEach(function(item) {
                        self[item.key] = instance[item.field];
                    });
                
                    callback();
                });
            });
        }
    
        async.parallel(funcs, function(err) {
            if (err) return next(err);
            next();
        });
    };
}
34690
function getRelatedModelFields(User) {
    const fields = {};

    _.forEach(User.relations, (relation) => {

        const model = relation.modelTo;

        fields[_.lowerFirst(relation.name)] = {
            args: Object.assign({
                where: {
                    type: getType('JSON')
                },
                order: {
                    type: getType('JSON')
                },
            }, connectionArgs),
            type: getConnection(model.modelName),
            resolve: (obj, args, context) => {

                if (!context.req.accessToken) return null;

                return findUserFromAccessToken(context.req.accessToken, User)
                    .then(user => connectionFromPromisedArray(findAllRelated(User, user, relation.name, args, context), args, model));
            }
        };
    });

    return fields;
}
125448
function getRootModelName (model) {
    if (!model) {
      throw new Error('Please provide Arrow Model')
    }

    const namespaceDelimiter = '/'
    var parent = model
    while (parent._parent && parent._parent.name) {
      parent = parent._parent
    }
    if (!parent.name) {
      throw new Error('The provided model has no name or parent with name')
    }
    const name = parent.name.split(namespaceDelimiter).pop()
    return {
      nameOnly: name,
      nameOnlyPlural: pluralize(name),
      withNamespace: parent.name
    }
  }
479493
function findModel(name) {
  return loadModels()
  .then(models => {
    const model = _.find(models, model => { return model.getName('spec') === name; });
    if (!model) {
      return Promise.reject(new Error('Could not find the model "' + name + '" in the current project'));
    }
    return model;
  });
}
947206
function (model) {

                var ret = [];

                function getSubModel(obj) {

                    if (obj === model) {
                        return;
                    }

                    if (_.indexOf(ret, obj) !== -1) {
                        // already in list
                        return;
                    }

                    if (obj instanceof Model) {
                        ret.push(obj);
                        return;
                    }

                    for (var key in obj) {
                        if (obj.hasOwnProperty(key)) {
                            var value = obj[key];

                            if (value instanceof Array) {
                                for (var i = 0; i < value.length; i++) {
                                    getSubModel(value[i]);
                                }
                            } else if (value instanceof List) {
                                value.each(getSubModel);
                            } else if (value instanceof Object) {
                                getSubModel(value);
                            }
                        }
                    }
                }

                getSubModel(model.$);

                return ret;

            }
1287566
function lodashFunctionToString(functionName) {
	var moduleText = readFileSync(localRequire.resolve(getLodashId(functionName)), 'utf-8');

	return function () {
		return 'function '+functionName+'() {var module = {exports:{}};'+moduleText+'\nreturn module.exports.apply({}, arguments);};';
	}
}
1181727
function generateModel(path, modelName, modelFields, generateMethod, ts, cb) {
    var fields = formatTools.getFieldsForModelTemplate(modelFields);
    var schemaName = modelName + 'Schema';

    var extension = (ts) ? 'ts' : 'js';
    var model = ft.loadTemplateSync('model.' + extension);
    model = model.replace(/{modelName}/, modelName);
    model = model.replace(/{schemaName}/g, schemaName);
    model = model.replace(/{fields}/, fields);

    if (generateMethod === 't') {
        ft.createDirIfIsNotDefined(path, 'models', function () {
            ft.writeFile(path + '/models/' + modelName + 'Model.' + extension, model, null, cb);
        });
    } else {
        ft.createDirIfIsNotDefined(path, modelName, function () {
            ft.writeFile(path + '/' + modelName + '/' + modelName + 'Model.' + extension, model, null, cb);
        });
    }
}
959548
function Model (name, schema, options) {
  if (typeof(name) != "string") throw "model name must be provided and a string";
  if (arguments.length==1) { options = {}; schema = {} };
  if (arguments.length==2) { options = schema; schema = {} };

  var self = function Document(raw) { return document.Document.call(this, self, raw) }; // Call the Document builder
  _.extend(self, Model.prototype); // Ugly but works - we need to return a function but still inherit prototype
  var emitter = new events.EventEmitter();
  emitter.setMaxListeners(0);
  for (var prop in emitter) self[prop] = emitter[prop];

  self.modelName = name;
  self.schema = schemas.normalize(Object.assign({}, schema)); // Normalize to allow for short-hands
  self.filename = path.normalize(options.filename || path.join(Model.dbPath || ".", name+".db"));
  self.options  = _.extend({}, Model.defaults, options);

  // Indexed by field name, dot notation can be used
  // _id is always indexed and since _ids are generated randomly the underlying
  // binary is always well-balanced
  self.indexes = {};
  self.indexes._id = new Index({ fieldName: '_id', unique: true });
  schemas.indexes(schema).forEach(function(idx) { self.ensureIndex(idx) });

  // Concurrency control for 1) index building and 2) pulling objects from LevelUP
  self._pipe = new bagpipe(1);
  self._pipe.pause();
  self._retrQueue = new bagpipe(LEVELUP_RETR_CONCURRENCY);
  self._retrQueue._locked = {}; self._retrQueue._locks = {}; // Hide those in ._retrQueue
  self._methods = {};

  if (self.options.autoLoad) self.initStore();

  return self;
}