var
  mongoose = require('mongoose'),
  Dependency = require('./dependency'),
  _ = require('underscore');

var Component = new mongoose.Schema({
  // Component attributes
  name : { type: String, required: true, index: true, unique: true, lowercase: true },
  repo : { type: String, required: true  },
  description : { type: String },
  version : { type: String, required: true },
  keywords : { type: Array },
  main : { type: String, default: 'index.js' },
  scripts : { type: Array, required: true },
  dependencies : [ Dependency ],
  twitter : { type: String },
  license : { type: String },

  stars : { type: Number, default: 0 },
  script : { type: Buffer, require: true },
  build: { type: Buffer, required: true },
  updated : { type: Date, default: Date.now, set: isoToDate },
  type: { type: String },
  
  // Not yet implemented
  ui : { type: Boolean }
});

// TODO More efficient querying???
// TODO Better matching???
Component.statics.search = function (query, returnFields, callback) {
  this.find({}, returnFields).or([
      { name : { $regex : query, $options : '-i' }},
      { keywords : query },
      { description : { $regex : query, $options : '-i' }}
      ]).exec(callback);
};

// Takes an ISO6801 string and converts it to a date object
function isoToDate(s) {
  if (s instanceof Date) { return s; }
  if (typeof s === 'string') { return new Date(s); }
}

module.exports = Component;

@@ -208,23 +208,53 @@
 true
-, index
+ %7D,%0A  repo : %7B type: String, required
 : true, 
 uniq
@@ -253,22 +253,21 @@
 ue, 
-unique
+index
 : true, 
 lowe
@@ -266,24 +266,21 @@
 ue, 
-lowercas
+uniqu
 e: true 
 %7D,%0A 
@@ -271,33 +271,41 @@
 nique: true 
+ 
 %7D,%0A  
-repo
+description
  : %7B type: S
@@ -313,42 +313,20 @@
 ring
-, required: true  %7D,%0A  description
+ %7D,%0A  author
  : %7B
@@ -649,95 +649,8 @@
  %7D,%0A
-  script : %7B type: Buffer, require: true %7D,%0A  build: %7B type: Buffer, required: true %7D,%0A
   up

Remove stored DB scripts in component model, make repo the unique/index