Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createModel(optns, ...plugins) {
// ensure options
let { connection, modelName, bucketName } = _.merge({}, optns);
connection = (connection || mongoose.connection);
modelName = (_.isEmpty(modelName) ? DEFAULT_BUCKET_MODEL_NAME : modelName);
bucketName = toCollectionName(modelName);
bucketName =
(modelName === DEFAULT_BUCKET_MODEL_NAME ? DEFAULT_BUCKET_NAME : bucketName);
// create bucket
const options =
_.merge({}, { connection, modelName, bucketName }, optns);
const bucket = createBucket(options);
// construct file schema
const schema = createFileSchema(bucket);
// apply schema plugins with model options
const schemaOptions = _.merge({}, schema.options);
_.forEach([...plugins], plugin => {
schema.plugin(plugin, schemaOptions);
});