/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['manikin-mongodb.js']) {
  _$jscoverage['manikin-mongodb.js'] = [];
  _$jscoverage['manikin-mongodb.js'][2] = 0;
  _$jscoverage['manikin-mongodb.js'][3] = 0;
  _$jscoverage['manikin-mongodb.js'][5] = 0;
  _$jscoverage['manikin-mongodb.js'][8] = 0;
  _$jscoverage['manikin-mongodb.js'][10] = 0;
  _$jscoverage['manikin-mongodb.js'][12] = 0;
  _$jscoverage['manikin-mongodb.js'][14] = 0;
  _$jscoverage['manikin-mongodb.js'][15] = 0;
  _$jscoverage['manikin-mongodb.js'][16] = 0;
  _$jscoverage['manikin-mongodb.js'][17] = 0;
  _$jscoverage['manikin-mongodb.js'][18] = 0;
  _$jscoverage['manikin-mongodb.js'][20] = 0;
  _$jscoverage['manikin-mongodb.js'][21] = 0;
  _$jscoverage['manikin-mongodb.js'][24] = 0;
  _$jscoverage['manikin-mongodb.js'][25] = 0;
  _$jscoverage['manikin-mongodb.js'][26] = 0;
  _$jscoverage['manikin-mongodb.js'][28] = 0;
  _$jscoverage['manikin-mongodb.js'][29] = 0;
  _$jscoverage['manikin-mongodb.js'][30] = 0;
  _$jscoverage['manikin-mongodb.js'][33] = 0;
  _$jscoverage['manikin-mongodb.js'][34] = 0;
  _$jscoverage['manikin-mongodb.js'][35] = 0;
  _$jscoverage['manikin-mongodb.js'][37] = 0;
  _$jscoverage['manikin-mongodb.js'][41] = 0;
  _$jscoverage['manikin-mongodb.js'][42] = 0;
  _$jscoverage['manikin-mongodb.js'][45] = 0;
  _$jscoverage['manikin-mongodb.js'][46] = 0;
  _$jscoverage['manikin-mongodb.js'][47] = 0;
  _$jscoverage['manikin-mongodb.js'][48] = 0;
  _$jscoverage['manikin-mongodb.js'][50] = 0;
  _$jscoverage['manikin-mongodb.js'][55] = 0;
  _$jscoverage['manikin-mongodb.js'][56] = 0;
  _$jscoverage['manikin-mongodb.js'][57] = 0;
  _$jscoverage['manikin-mongodb.js'][58] = 0;
  _$jscoverage['manikin-mongodb.js'][59] = 0;
  _$jscoverage['manikin-mongodb.js'][60] = 0;
  _$jscoverage['manikin-mongodb.js'][62] = 0;
  _$jscoverage['manikin-mongodb.js'][67] = 0;
  _$jscoverage['manikin-mongodb.js'][68] = 0;
  _$jscoverage['manikin-mongodb.js'][69] = 0;
  _$jscoverage['manikin-mongodb.js'][70] = 0;
  _$jscoverage['manikin-mongodb.js'][72] = 0;
  _$jscoverage['manikin-mongodb.js'][73] = 0;
  _$jscoverage['manikin-mongodb.js'][75] = 0;
  _$jscoverage['manikin-mongodb.js'][76] = 0;
  _$jscoverage['manikin-mongodb.js'][77] = 0;
  _$jscoverage['manikin-mongodb.js'][78] = 0;
  _$jscoverage['manikin-mongodb.js'][80] = 0;
  _$jscoverage['manikin-mongodb.js'][82] = 0;
  _$jscoverage['manikin-mongodb.js'][85] = 0;
  _$jscoverage['manikin-mongodb.js'][88] = 0;
  _$jscoverage['manikin-mongodb.js'][89] = 0;
  _$jscoverage['manikin-mongodb.js'][90] = 0;
  _$jscoverage['manikin-mongodb.js'][91] = 0;
  _$jscoverage['manikin-mongodb.js'][92] = 0;
  _$jscoverage['manikin-mongodb.js'][95] = 0;
  _$jscoverage['manikin-mongodb.js'][96] = 0;
  _$jscoverage['manikin-mongodb.js'][97] = 0;
  _$jscoverage['manikin-mongodb.js'][98] = 0;
  _$jscoverage['manikin-mongodb.js'][99] = 0;
  _$jscoverage['manikin-mongodb.js'][100] = 0;
  _$jscoverage['manikin-mongodb.js'][101] = 0;
  _$jscoverage['manikin-mongodb.js'][102] = 0;
  _$jscoverage['manikin-mongodb.js'][103] = 0;
  _$jscoverage['manikin-mongodb.js'][104] = 0;
  _$jscoverage['manikin-mongodb.js'][105] = 0;
  _$jscoverage['manikin-mongodb.js'][106] = 0;
  _$jscoverage['manikin-mongodb.js'][109] = 0;
  _$jscoverage['manikin-mongodb.js'][110] = 0;
  _$jscoverage['manikin-mongodb.js'][112] = 0;
  _$jscoverage['manikin-mongodb.js'][113] = 0;
  _$jscoverage['manikin-mongodb.js'][115] = 0;
  _$jscoverage['manikin-mongodb.js'][116] = 0;
  _$jscoverage['manikin-mongodb.js'][117] = 0;
  _$jscoverage['manikin-mongodb.js'][118] = 0;
  _$jscoverage['manikin-mongodb.js'][119] = 0;
  _$jscoverage['manikin-mongodb.js'][120] = 0;
  _$jscoverage['manikin-mongodb.js'][121] = 0;
  _$jscoverage['manikin-mongodb.js'][123] = 0;
  _$jscoverage['manikin-mongodb.js'][129] = 0;
  _$jscoverage['manikin-mongodb.js'][130] = 0;
  _$jscoverage['manikin-mongodb.js'][132] = 0;
  _$jscoverage['manikin-mongodb.js'][133] = 0;
  _$jscoverage['manikin-mongodb.js'][136] = 0;
  _$jscoverage['manikin-mongodb.js'][137] = 0;
  _$jscoverage['manikin-mongodb.js'][138] = 0;
  _$jscoverage['manikin-mongodb.js'][139] = 0;
  _$jscoverage['manikin-mongodb.js'][140] = 0;
  _$jscoverage['manikin-mongodb.js'][143] = 0;
  _$jscoverage['manikin-mongodb.js'][149] = 0;
  _$jscoverage['manikin-mongodb.js'][150] = 0;
  _$jscoverage['manikin-mongodb.js'][151] = 0;
  _$jscoverage['manikin-mongodb.js'][152] = 0;
  _$jscoverage['manikin-mongodb.js'][153] = 0;
  _$jscoverage['manikin-mongodb.js'][155] = 0;
  _$jscoverage['manikin-mongodb.js'][156] = 0;
  _$jscoverage['manikin-mongodb.js'][157] = 0;
  _$jscoverage['manikin-mongodb.js'][159] = 0;
  _$jscoverage['manikin-mongodb.js'][160] = 0;
  _$jscoverage['manikin-mongodb.js'][161] = 0;
  _$jscoverage['manikin-mongodb.js'][162] = 0;
  _$jscoverage['manikin-mongodb.js'][163] = 0;
  _$jscoverage['manikin-mongodb.js'][164] = 0;
  _$jscoverage['manikin-mongodb.js'][165] = 0;
  _$jscoverage['manikin-mongodb.js'][169] = 0;
  _$jscoverage['manikin-mongodb.js'][170] = 0;
  _$jscoverage['manikin-mongodb.js'][171] = 0;
  _$jscoverage['manikin-mongodb.js'][173] = 0;
  _$jscoverage['manikin-mongodb.js'][174] = 0;
  _$jscoverage['manikin-mongodb.js'][175] = 0;
  _$jscoverage['manikin-mongodb.js'][176] = 0;
  _$jscoverage['manikin-mongodb.js'][177] = 0;
  _$jscoverage['manikin-mongodb.js'][183] = 0;
  _$jscoverage['manikin-mongodb.js'][184] = 0;
  _$jscoverage['manikin-mongodb.js'][185] = 0;
  _$jscoverage['manikin-mongodb.js'][186] = 0;
  _$jscoverage['manikin-mongodb.js'][187] = 0;
  _$jscoverage['manikin-mongodb.js'][188] = 0;
  _$jscoverage['manikin-mongodb.js'][189] = 0;
  _$jscoverage['manikin-mongodb.js'][191] = 0;
  _$jscoverage['manikin-mongodb.js'][197] = 0;
  _$jscoverage['manikin-mongodb.js'][198] = 0;
  _$jscoverage['manikin-mongodb.js'][199] = 0;
  _$jscoverage['manikin-mongodb.js'][200] = 0;
  _$jscoverage['manikin-mongodb.js'][201] = 0;
  _$jscoverage['manikin-mongodb.js'][202] = 0;
  _$jscoverage['manikin-mongodb.js'][203] = 0;
  _$jscoverage['manikin-mongodb.js'][208] = 0;
  _$jscoverage['manikin-mongodb.js'][209] = 0;
  _$jscoverage['manikin-mongodb.js'][210] = 0;
  _$jscoverage['manikin-mongodb.js'][211] = 0;
  _$jscoverage['manikin-mongodb.js'][214] = 0;
  _$jscoverage['manikin-mongodb.js'][215] = 0;
  _$jscoverage['manikin-mongodb.js'][216] = 0;
  _$jscoverage['manikin-mongodb.js'][217] = 0;
  _$jscoverage['manikin-mongodb.js'][218] = 0;
  _$jscoverage['manikin-mongodb.js'][221] = 0;
  _$jscoverage['manikin-mongodb.js'][222] = 0;
  _$jscoverage['manikin-mongodb.js'][223] = 0;
  _$jscoverage['manikin-mongodb.js'][226] = 0;
  _$jscoverage['manikin-mongodb.js'][227] = 0;
  _$jscoverage['manikin-mongodb.js'][230] = 0;
  _$jscoverage['manikin-mongodb.js'][231] = 0;
  _$jscoverage['manikin-mongodb.js'][234] = 0;
  _$jscoverage['manikin-mongodb.js'][235] = 0;
  _$jscoverage['manikin-mongodb.js'][238] = 0;
  _$jscoverage['manikin-mongodb.js'][239] = 0;
  _$jscoverage['manikin-mongodb.js'][243] = 0;
  _$jscoverage['manikin-mongodb.js'][244] = 0;
  _$jscoverage['manikin-mongodb.js'][251] = 0;
  _$jscoverage['manikin-mongodb.js'][261] = 0;
  _$jscoverage['manikin-mongodb.js'][262] = 0;
  _$jscoverage['manikin-mongodb.js'][263] = 0;
  _$jscoverage['manikin-mongodb.js'][264] = 0;
  _$jscoverage['manikin-mongodb.js'][265] = 0;
  _$jscoverage['manikin-mongodb.js'][266] = 0;
  _$jscoverage['manikin-mongodb.js'][267] = 0;
  _$jscoverage['manikin-mongodb.js'][268] = 0;
  _$jscoverage['manikin-mongodb.js'][270] = 0;
  _$jscoverage['manikin-mongodb.js'][271] = 0;
  _$jscoverage['manikin-mongodb.js'][272] = 0;
  _$jscoverage['manikin-mongodb.js'][273] = 0;
  _$jscoverage['manikin-mongodb.js'][274] = 0;
  _$jscoverage['manikin-mongodb.js'][275] = 0;
  _$jscoverage['manikin-mongodb.js'][276] = 0;
  _$jscoverage['manikin-mongodb.js'][280] = 0;
  _$jscoverage['manikin-mongodb.js'][281] = 0;
  _$jscoverage['manikin-mongodb.js'][282] = 0;
  _$jscoverage['manikin-mongodb.js'][283] = 0;
  _$jscoverage['manikin-mongodb.js'][284] = 0;
  _$jscoverage['manikin-mongodb.js'][291] = 0;
  _$jscoverage['manikin-mongodb.js'][292] = 0;
  _$jscoverage['manikin-mongodb.js'][299] = 0;
  _$jscoverage['manikin-mongodb.js'][300] = 0;
  _$jscoverage['manikin-mongodb.js'][301] = 0;
  _$jscoverage['manikin-mongodb.js'][304] = 0;
  _$jscoverage['manikin-mongodb.js'][306] = 0;
  _$jscoverage['manikin-mongodb.js'][307] = 0;
  _$jscoverage['manikin-mongodb.js'][309] = 0;
  _$jscoverage['manikin-mongodb.js'][310] = 0;
  _$jscoverage['manikin-mongodb.js'][311] = 0;
  _$jscoverage['manikin-mongodb.js'][312] = 0;
  _$jscoverage['manikin-mongodb.js'][313] = 0;
  _$jscoverage['manikin-mongodb.js'][314] = 0;
  _$jscoverage['manikin-mongodb.js'][315] = 0;
  _$jscoverage['manikin-mongodb.js'][316] = 0;
  _$jscoverage['manikin-mongodb.js'][317] = 0;
  _$jscoverage['manikin-mongodb.js'][318] = 0;
  _$jscoverage['manikin-mongodb.js'][319] = 0;
  _$jscoverage['manikin-mongodb.js'][320] = 0;
  _$jscoverage['manikin-mongodb.js'][321] = 0;
  _$jscoverage['manikin-mongodb.js'][323] = 0;
  _$jscoverage['manikin-mongodb.js'][324] = 0;
  _$jscoverage['manikin-mongodb.js'][328] = 0;
  _$jscoverage['manikin-mongodb.js'][329] = 0;
  _$jscoverage['manikin-mongodb.js'][331] = 0;
  _$jscoverage['manikin-mongodb.js'][333] = 0;
  _$jscoverage['manikin-mongodb.js'][334] = 0;
  _$jscoverage['manikin-mongodb.js'][335] = 0;
  _$jscoverage['manikin-mongodb.js'][338] = 0;
  _$jscoverage['manikin-mongodb.js'][339] = 0;
  _$jscoverage['manikin-mongodb.js'][340] = 0;
  _$jscoverage['manikin-mongodb.js'][341] = 0;
  _$jscoverage['manikin-mongodb.js'][342] = 0;
  _$jscoverage['manikin-mongodb.js'][343] = 0;
  _$jscoverage['manikin-mongodb.js'][344] = 0;
  _$jscoverage['manikin-mongodb.js'][345] = 0;
  _$jscoverage['manikin-mongodb.js'][346] = 0;
  _$jscoverage['manikin-mongodb.js'][347] = 0;
  _$jscoverage['manikin-mongodb.js'][349] = 0;
  _$jscoverage['manikin-mongodb.js'][352] = 0;
  _$jscoverage['manikin-mongodb.js'][356] = 0;
  _$jscoverage['manikin-mongodb.js'][357] = 0;
  _$jscoverage['manikin-mongodb.js'][358] = 0;
  _$jscoverage['manikin-mongodb.js'][359] = 0;
  _$jscoverage['manikin-mongodb.js'][361] = 0;
  _$jscoverage['manikin-mongodb.js'][362] = 0;
  _$jscoverage['manikin-mongodb.js'][364] = 0;
  _$jscoverage['manikin-mongodb.js'][369] = 0;
  _$jscoverage['manikin-mongodb.js'][370] = 0;
  _$jscoverage['manikin-mongodb.js'][371] = 0;
  _$jscoverage['manikin-mongodb.js'][372] = 0;
  _$jscoverage['manikin-mongodb.js'][374] = 0;
  _$jscoverage['manikin-mongodb.js'][375] = 0;
  _$jscoverage['manikin-mongodb.js'][377] = 0;
  _$jscoverage['manikin-mongodb.js'][381] = 0;
  _$jscoverage['manikin-mongodb.js'][382] = 0;
  _$jscoverage['manikin-mongodb.js'][383] = 0;
  _$jscoverage['manikin-mongodb.js'][384] = 0;
  _$jscoverage['manikin-mongodb.js'][385] = 0;
  _$jscoverage['manikin-mongodb.js'][386] = 0;
  _$jscoverage['manikin-mongodb.js'][387] = 0;
  _$jscoverage['manikin-mongodb.js'][389] = 0;
  _$jscoverage['manikin-mongodb.js'][391] = 0;
  _$jscoverage['manikin-mongodb.js'][392] = 0;
  _$jscoverage['manikin-mongodb.js'][393] = 0;
  _$jscoverage['manikin-mongodb.js'][394] = 0;
  _$jscoverage['manikin-mongodb.js'][395] = 0;
  _$jscoverage['manikin-mongodb.js'][396] = 0;
  _$jscoverage['manikin-mongodb.js'][397] = 0;
  _$jscoverage['manikin-mongodb.js'][399] = 0;
  _$jscoverage['manikin-mongodb.js'][401] = 0;
  _$jscoverage['manikin-mongodb.js'][402] = 0;
  _$jscoverage['manikin-mongodb.js'][404] = 0;
  _$jscoverage['manikin-mongodb.js'][408] = 0;
  _$jscoverage['manikin-mongodb.js'][409] = 0;
  _$jscoverage['manikin-mongodb.js'][410] = 0;
  _$jscoverage['manikin-mongodb.js'][411] = 0;
  _$jscoverage['manikin-mongodb.js'][412] = 0;
  _$jscoverage['manikin-mongodb.js'][413] = 0;
  _$jscoverage['manikin-mongodb.js'][415] = 0;
  _$jscoverage['manikin-mongodb.js'][417] = 0;
  _$jscoverage['manikin-mongodb.js'][418] = 0;
  _$jscoverage['manikin-mongodb.js'][420] = 0;
  _$jscoverage['manikin-mongodb.js'][421] = 0;
  _$jscoverage['manikin-mongodb.js'][426] = 0;
  _$jscoverage['manikin-mongodb.js'][427] = 0;
  _$jscoverage['manikin-mongodb.js'][428] = 0;
  _$jscoverage['manikin-mongodb.js'][429] = 0;
  _$jscoverage['manikin-mongodb.js'][430] = 0;
  _$jscoverage['manikin-mongodb.js'][431] = 0;
  _$jscoverage['manikin-mongodb.js'][432] = 0;
  _$jscoverage['manikin-mongodb.js'][433] = 0;
  _$jscoverage['manikin-mongodb.js'][434] = 0;
  _$jscoverage['manikin-mongodb.js'][435] = 0;
  _$jscoverage['manikin-mongodb.js'][436] = 0;
  _$jscoverage['manikin-mongodb.js'][438] = 0;
  _$jscoverage['manikin-mongodb.js'][439] = 0;
  _$jscoverage['manikin-mongodb.js'][440] = 0;
  _$jscoverage['manikin-mongodb.js'][441] = 0;
  _$jscoverage['manikin-mongodb.js'][443] = 0;
  _$jscoverage['manikin-mongodb.js'][445] = 0;
  _$jscoverage['manikin-mongodb.js'][447] = 0;
  _$jscoverage['manikin-mongodb.js'][448] = 0;
  _$jscoverage['manikin-mongodb.js'][449] = 0;
  _$jscoverage['manikin-mongodb.js'][451] = 0;
  _$jscoverage['manikin-mongodb.js'][452] = 0;
  _$jscoverage['manikin-mongodb.js'][454] = 0;
  _$jscoverage['manikin-mongodb.js'][455] = 0;
  _$jscoverage['manikin-mongodb.js'][459] = 0;
  _$jscoverage['manikin-mongodb.js'][460] = 0;
  _$jscoverage['manikin-mongodb.js'][461] = 0;
  _$jscoverage['manikin-mongodb.js'][462] = 0;
  _$jscoverage['manikin-mongodb.js'][464] = 0;
  _$jscoverage['manikin-mongodb.js'][465] = 0;
  _$jscoverage['manikin-mongodb.js'][466] = 0;
  _$jscoverage['manikin-mongodb.js'][468] = 0;
  _$jscoverage['manikin-mongodb.js'][469] = 0;
  _$jscoverage['manikin-mongodb.js'][470] = 0;
  _$jscoverage['manikin-mongodb.js'][483] = 0;
  _$jscoverage['manikin-mongodb.js'][484] = 0;
  _$jscoverage['manikin-mongodb.js'][485] = 0;
  _$jscoverage['manikin-mongodb.js'][488] = 0;
  _$jscoverage['manikin-mongodb.js'][491] = 0;
  _$jscoverage['manikin-mongodb.js'][492] = 0;
  _$jscoverage['manikin-mongodb.js'][493] = 0;
  _$jscoverage['manikin-mongodb.js'][498] = 0;
  _$jscoverage['manikin-mongodb.js'][499] = 0;
  _$jscoverage['manikin-mongodb.js'][500] = 0;
  _$jscoverage['manikin-mongodb.js'][501] = 0;
  _$jscoverage['manikin-mongodb.js'][502] = 0;
  _$jscoverage['manikin-mongodb.js'][504] = 0;
  _$jscoverage['manikin-mongodb.js'][505] = 0;
  _$jscoverage['manikin-mongodb.js'][506] = 0;
  _$jscoverage['manikin-mongodb.js'][508] = 0;
  _$jscoverage['manikin-mongodb.js'][509] = 0;
  _$jscoverage['manikin-mongodb.js'][510] = 0;
  _$jscoverage['manikin-mongodb.js'][523] = 0;
  _$jscoverage['manikin-mongodb.js'][524] = 0;
  _$jscoverage['manikin-mongodb.js'][526] = 0;
  _$jscoverage['manikin-mongodb.js'][527] = 0;
  _$jscoverage['manikin-mongodb.js'][528] = 0;
  _$jscoverage['manikin-mongodb.js'][531] = 0;
  _$jscoverage['manikin-mongodb.js'][532] = 0;
  _$jscoverage['manikin-mongodb.js'][535] = 0;
  _$jscoverage['manikin-mongodb.js'][537] = 0;
  _$jscoverage['manikin-mongodb.js'][538] = 0;
  _$jscoverage['manikin-mongodb.js'][540] = 0;
  _$jscoverage['manikin-mongodb.js'][541] = 0;
  _$jscoverage['manikin-mongodb.js'][543] = 0;
  _$jscoverage['manikin-mongodb.js'][544] = 0;
  _$jscoverage['manikin-mongodb.js'][545] = 0;
  _$jscoverage['manikin-mongodb.js'][546] = 0;
  _$jscoverage['manikin-mongodb.js'][547] = 0;
  _$jscoverage['manikin-mongodb.js'][548] = 0;
  _$jscoverage['manikin-mongodb.js'][551] = 0;
  _$jscoverage['manikin-mongodb.js'][552] = 0;
  _$jscoverage['manikin-mongodb.js'][553] = 0;
  _$jscoverage['manikin-mongodb.js'][555] = 0;
  _$jscoverage['manikin-mongodb.js'][558] = 0;
  _$jscoverage['manikin-mongodb.js'][559] = 0;
  _$jscoverage['manikin-mongodb.js'][561] = 0;
  _$jscoverage['manikin-mongodb.js'][562] = 0;
  _$jscoverage['manikin-mongodb.js'][564] = 0;
  _$jscoverage['manikin-mongodb.js'][566] = 0;
  _$jscoverage['manikin-mongodb.js'][572] = 0;
  _$jscoverage['manikin-mongodb.js'][573] = 0;
  _$jscoverage['manikin-mongodb.js'][576] = 0;
  _$jscoverage['manikin-mongodb.js'][579] = 0;
}
_$jscoverage['manikin-mongodb.js'][2]++;
(function () {
  _$jscoverage['manikin-mongodb.js'][3]++;
  "use strict";
  _$jscoverage['manikin-mongodb.js'][5]++;
  var async, getKeys, massage, massageCore, massageOne, massaged, preprocFilter, propagate, tools, _, __slice = [].slice;
  _$jscoverage['manikin-mongodb.js'][8]++;
  async = require("async");
  _$jscoverage['manikin-mongodb.js'][10]++;
  _ = require("underscore");
  _$jscoverage['manikin-mongodb.js'][12]++;
  tools = require("./manikin-tools");
  _$jscoverage['manikin-mongodb.js'][14]++;
  preprocFilter = (function (filter) {
  _$jscoverage['manikin-mongodb.js'][15]++;
  var x;
  _$jscoverage['manikin-mongodb.js'][16]++;
  x = _.extend({}, filter);
  _$jscoverage['manikin-mongodb.js'][17]++;
  if (x.id) {
    _$jscoverage['manikin-mongodb.js'][18]++;
    x._id = x.id;
  }
  _$jscoverage['manikin-mongodb.js'][20]++;
  delete x.id;
  _$jscoverage['manikin-mongodb.js'][21]++;
  return x;
});
  _$jscoverage['manikin-mongodb.js'][24]++;
  massageOne = (function (x) {
  _$jscoverage['manikin-mongodb.js'][25]++;
  if (! (x != null)) {
    _$jscoverage['manikin-mongodb.js'][26]++;
    return x;
  }
  _$jscoverage['manikin-mongodb.js'][28]++;
  x.id = x._id;
  _$jscoverage['manikin-mongodb.js'][29]++;
  delete x._id;
  _$jscoverage['manikin-mongodb.js'][30]++;
  return x;
});
  _$jscoverage['manikin-mongodb.js'][33]++;
  massageCore = (function (r2) {
  _$jscoverage['manikin-mongodb.js'][34]++;
  if (Array.isArray(r2)) {
    _$jscoverage['manikin-mongodb.js'][35]++;
    return r2.map(massageOne);
  }
  else {
    _$jscoverage['manikin-mongodb.js'][37]++;
    return massageOne(r2);
  }
});
  _$jscoverage['manikin-mongodb.js'][41]++;
  massage = (function (r2) {
  _$jscoverage['manikin-mongodb.js'][42]++;
  return massageCore(JSON.parse(JSON.stringify(r2)));
});
  _$jscoverage['manikin-mongodb.js'][45]++;
  massaged = (function (f) {
  _$jscoverage['manikin-mongodb.js'][46]++;
  return (function (err, data) {
  _$jscoverage['manikin-mongodb.js'][47]++;
  if (err) {
    _$jscoverage['manikin-mongodb.js'][48]++;
    return f(err);
  }
  else {
    _$jscoverage['manikin-mongodb.js'][50]++;
    return f(null, massage(data));
  }
});
});
  _$jscoverage['manikin-mongodb.js'][55]++;
  propagate = (function (callback, f) {
  _$jscoverage['manikin-mongodb.js'][56]++;
  return (function () {
  _$jscoverage['manikin-mongodb.js'][57]++;
  var args, err;
  _$jscoverage['manikin-mongodb.js'][58]++;
  err = arguments[0], args = 2 <= arguments.length? __slice.call(arguments, 1): [];
  _$jscoverage['manikin-mongodb.js'][59]++;
  if (err) {
    _$jscoverage['manikin-mongodb.js'][60]++;
    return callback(err);
  }
  else {
    _$jscoverage['manikin-mongodb.js'][62]++;
    return f.apply(this, args);
  }
});
});
  _$jscoverage['manikin-mongodb.js'][67]++;
  getKeys = (function (data, target, prefix) {
  _$jscoverage['manikin-mongodb.js'][68]++;
  var valids;
  _$jscoverage['manikin-mongodb.js'][69]++;
  if (target == null) {
    _$jscoverage['manikin-mongodb.js'][70]++;
    target = [];
  }
  _$jscoverage['manikin-mongodb.js'][72]++;
  if (prefix == null) {
    _$jscoverage['manikin-mongodb.js'][73]++;
    prefix = "";
  }
  _$jscoverage['manikin-mongodb.js'][75]++;
  valids = ["Array", "String", "Boolean", "Date", "Number", "Null"];
  _$jscoverage['manikin-mongodb.js'][76]++;
  Object.keys(data).forEach((function (key) {
  _$jscoverage['manikin-mongodb.js'][77]++;
  if (valids.some((function (x) {
  _$jscoverage['manikin-mongodb.js'][78]++;
  return _(data[key])["is" + x]();
}))) {
    _$jscoverage['manikin-mongodb.js'][80]++;
    return target.push(prefix + key);
  }
  else {
    _$jscoverage['manikin-mongodb.js'][82]++;
    return getKeys(data[key], target, prefix + key + ".");
  }
}));
  _$jscoverage['manikin-mongodb.js'][85]++;
  return target;
});
  _$jscoverage['manikin-mongodb.js'][88]++;
  exports.create = (function () {
  _$jscoverage['manikin-mongodb.js'][89]++;
  var Mixed, ObjectID, ObjectId, Schema, api, defModels, getMeta, insertOps, internalListSub, key, makeModel, metaData, models, mongoose, nullablesValidation, preRemoveCascadeNonNullable, preRemoveCascadeNullable, specTransform, specmodels;
  _$jscoverage['manikin-mongodb.js'][90]++;
  if (process.env.NODE_ENV !== "production") {
    _$jscoverage['manikin-mongodb.js'][91]++;
    for (key in require.cache) {
      _$jscoverage['manikin-mongodb.js'][92]++;
      delete require.cache[key];
}
  }
  _$jscoverage['manikin-mongodb.js'][95]++;
  mongoose = require("mongoose");
  _$jscoverage['manikin-mongodb.js'][96]++;
  Schema = mongoose.Schema;
  _$jscoverage['manikin-mongodb.js'][97]++;
  Mixed = mongoose.Schema.Types.Mixed;
  _$jscoverage['manikin-mongodb.js'][98]++;
  ObjectID = mongoose.mongo.ObjectID;
  _$jscoverage['manikin-mongodb.js'][99]++;
  ObjectId = mongoose.Schema.ObjectId;
  _$jscoverage['manikin-mongodb.js'][100]++;
  api = {};
  _$jscoverage['manikin-mongodb.js'][101]++;
  models = {};
  _$jscoverage['manikin-mongodb.js'][102]++;
  specmodels = {};
  _$jscoverage['manikin-mongodb.js'][103]++;
  metaData = null;
  _$jscoverage['manikin-mongodb.js'][104]++;
  makeModel = (function (connection, name, schema) {
  _$jscoverage['manikin-mongodb.js'][105]++;
  var ss;
  _$jscoverage['manikin-mongodb.js'][106]++;
  ss = new Schema(schema, {strict: true});
  _$jscoverage['manikin-mongodb.js'][109]++;
  ss.set("versionKey", false);
  _$jscoverage['manikin-mongodb.js'][110]++;
  return connection.model(name, ss, name);
});
  _$jscoverage['manikin-mongodb.js'][112]++;
  getMeta = (function (modelName) {
  _$jscoverage['manikin-mongodb.js'][113]++;
  return metaData[modelName];
});
  _$jscoverage['manikin-mongodb.js'][115]++;
  nullablesValidation = (function (schema) {
  _$jscoverage['manikin-mongodb.js'][116]++;
  return (function (next) {
  _$jscoverage['manikin-mongodb.js'][117]++;
  var nonNullOuters, outers, paths, self;
  _$jscoverage['manikin-mongodb.js'][118]++;
  self = this;
  _$jscoverage['manikin-mongodb.js'][119]++;
  paths = schema.paths;
  _$jscoverage['manikin-mongodb.js'][120]++;
  outers = Object.keys(paths).filter((function (x) {
  _$jscoverage['manikin-mongodb.js'][121]++;
  return paths[x].options.type === ObjectId && typeof paths[x].options.ref === "string" && ! paths[x].options["x-owner"];
})).map((function (x) {
  _$jscoverage['manikin-mongodb.js'][123]++;
  return ({plur: paths[x].options.ref, sing: x, validation: paths[x].options["x-validation"]});
}));
  _$jscoverage['manikin-mongodb.js'][129]++;
  nonNullOuters = outers.filter((function (x) {
  _$jscoverage['manikin-mongodb.js'][130]++;
  return self[x.sing] != null;
}));
  _$jscoverage['manikin-mongodb.js'][132]++;
  return async.forEach(nonNullOuters, (function (o, callback) {
  _$jscoverage['manikin-mongodb.js'][133]++;
  return api.getOne(o.plur, {id: self[o.sing]}, (function (err, data) {
  _$jscoverage['manikin-mongodb.js'][136]++;
  if (err || ! data) {
    _$jscoverage['manikin-mongodb.js'][137]++;
    return callback(new Error("Invalid pointer"));
  }
  else {
    _$jscoverage['manikin-mongodb.js'][138]++;
    if (o.validation) {
      _$jscoverage['manikin-mongodb.js'][139]++;
      return o.validation(self, data, (function (err) {
  _$jscoverage['manikin-mongodb.js'][140]++;
  return callback(err? new Error(err): void 0);
}));
    }
    else {
      _$jscoverage['manikin-mongodb.js'][143]++;
      return callback();
    }
  }
}));
}), next);
});
});
  _$jscoverage['manikin-mongodb.js'][149]++;
  internalListSub = (function (model, outer, id, filter, callback) {
  _$jscoverage['manikin-mongodb.js'][150]++;
  var finalFilter;
  _$jscoverage['manikin-mongodb.js'][151]++;
  if ((filter[outer] != null) && filter[outer].toString() !== id.toString()) {
    _$jscoverage['manikin-mongodb.js'][152]++;
    callback(new Error("No such id"));
    _$jscoverage['manikin-mongodb.js'][153]++;
    return;
  }
  _$jscoverage['manikin-mongodb.js'][155]++;
  filter = preprocFilter(filter);
  _$jscoverage['manikin-mongodb.js'][156]++;
  finalFilter = _.extend({}, filter, _.object([[outer, id]]));
  _$jscoverage['manikin-mongodb.js'][157]++;
  return models[model].find(finalFilter, callback);
});
  _$jscoverage['manikin-mongodb.js'][159]++;
  preRemoveCascadeNonNullable = (function (owner, id, next) {
  _$jscoverage['manikin-mongodb.js'][160]++;
  var manys;
  _$jscoverage['manikin-mongodb.js'][161]++;
  manys = getMeta(owner.modelName).manyToMany;
  _$jscoverage['manikin-mongodb.js'][162]++;
  return async.forEach(manys, (function (many, callback) {
  _$jscoverage['manikin-mongodb.js'][163]++;
  var obj;
  _$jscoverage['manikin-mongodb.js'][164]++;
  obj = _.object([[many.inverseName, id]]);
  _$jscoverage['manikin-mongodb.js'][165]++;
  return models[many.ref].update(obj, {$pull: obj}, callback);
}), (function (err) {
  _$jscoverage['manikin-mongodb.js'][169]++;
  var flattenedModels;
  _$jscoverage['manikin-mongodb.js'][170]++;
  if (err) {
    _$jscoverage['manikin-mongodb.js'][171]++;
    return next(err);
  }
  _$jscoverage['manikin-mongodb.js'][173]++;
  flattenedModels = getMeta(owner.modelName).owns;
  _$jscoverage['manikin-mongodb.js'][174]++;
  return async.forEach(flattenedModels, (function (mod, callback) {
  _$jscoverage['manikin-mongodb.js'][175]++;
  return internalListSub(mod.name, mod.field, id, {}, propagate(callback, (function (data) {
  _$jscoverage['manikin-mongodb.js'][176]++;
  return async.forEach(data, (function (item, callback) {
  _$jscoverage['manikin-mongodb.js'][177]++;
  return item.remove(callback);
}), callback);
})));
}), next);
}));
});
  _$jscoverage['manikin-mongodb.js'][183]++;
  preRemoveCascadeNullable = (function (owner, id, next) {
  _$jscoverage['manikin-mongodb.js'][184]++;
  var flattenedModels, ownedModels;
  _$jscoverage['manikin-mongodb.js'][185]++;
  ownedModels = Object.keys(models).map((function (modelName) {
  _$jscoverage['manikin-mongodb.js'][186]++;
  var paths;
  _$jscoverage['manikin-mongodb.js'][187]++;
  paths = models[modelName].schema.paths;
  _$jscoverage['manikin-mongodb.js'][188]++;
  return Object.keys(paths).filter((function (x) {
  _$jscoverage['manikin-mongodb.js'][189]++;
  return paths[x].options.type === ObjectId && paths[x].options.ref === owner.modelName && ! paths[x].options["x-owner"];
})).map((function (x) {
  _$jscoverage['manikin-mongodb.js'][191]++;
  return ({name: modelName, field: x});
}));
}));
  _$jscoverage['manikin-mongodb.js'][197]++;
  flattenedModels = _.flatten(ownedModels);
  _$jscoverage['manikin-mongodb.js'][198]++;
  return async.forEach(flattenedModels, (function (mod, callback) {
  _$jscoverage['manikin-mongodb.js'][199]++;
  return internalListSub(mod.name, mod.field, id, {}, propagate(callback, (function (data) {
  _$jscoverage['manikin-mongodb.js'][200]++;
  return async.forEach(data, (function (item, callback) {
  _$jscoverage['manikin-mongodb.js'][201]++;
  item[mod.field] = null;
  _$jscoverage['manikin-mongodb.js'][202]++;
  item.save();
  _$jscoverage['manikin-mongodb.js'][203]++;
  return callback();
}), callback);
})));
}), next);
});
  _$jscoverage['manikin-mongodb.js'][208]++;
  specTransform = (function (allspec, modelName, tgt, src, keys) {
  _$jscoverage['manikin-mongodb.js'][209]++;
  return keys.forEach((function (key) {
  _$jscoverage['manikin-mongodb.js'][210]++;
  if (src[key].type === "mixed") {
    _$jscoverage['manikin-mongodb.js'][211]++;
    return tgt[key] = {type: Mixed};
  }
  else {
    _$jscoverage['manikin-mongodb.js'][214]++;
    if (src[key].type === "nested") {
      _$jscoverage['manikin-mongodb.js'][215]++;
      tgt[key] = {};
      _$jscoverage['manikin-mongodb.js'][216]++;
      return specTransform(allspec, modelName, tgt[key], src[key], _.without(Object.keys(src[key]), "type"));
    }
    else {
      _$jscoverage['manikin-mongodb.js'][217]++;
      if (src[key].type === "string") {
        _$jscoverage['manikin-mongodb.js'][218]++;
        tgt[key] = _.extend({}, src[key], {type: String});
        _$jscoverage['manikin-mongodb.js'][221]++;
        if (src[key].validate != null) {
          _$jscoverage['manikin-mongodb.js'][222]++;
          return tgt[key].validate = (function (value, callback) {
  _$jscoverage['manikin-mongodb.js'][223]++;
  return src[key].validate(api, value, callback);
});
        }
      }
      else {
        _$jscoverage['manikin-mongodb.js'][226]++;
        if (src[key].type === "number") {
          _$jscoverage['manikin-mongodb.js'][227]++;
          return tgt[key] = _.extend({}, src[key], {type: Number});
        }
        else {
          _$jscoverage['manikin-mongodb.js'][230]++;
          if (src[key].type === "date") {
            _$jscoverage['manikin-mongodb.js'][231]++;
            return tgt[key] = _.extend({}, src[key], {type: Date});
          }
          else {
            _$jscoverage['manikin-mongodb.js'][234]++;
            if (src[key].type === "boolean") {
              _$jscoverage['manikin-mongodb.js'][235]++;
              return tgt[key] = _.extend({}, src[key], {type: Boolean});
            }
            else {
              _$jscoverage['manikin-mongodb.js'][238]++;
              if (src[key].type === "hasOne") {
                _$jscoverage['manikin-mongodb.js'][239]++;
                return tgt[key] = {ref: src[key].model, "x-validation": src[key].validation};
              }
              else {
                _$jscoverage['manikin-mongodb.js'][243]++;
                if (src[key].type === "hasMany") {
                  _$jscoverage['manikin-mongodb.js'][244]++;
                  tgt[key] = [{type: ObjectId, ref: src[key].model, inverseName: src[key].inverseName}];
                  _$jscoverage['manikin-mongodb.js'][251]++;
                  return allspec[src[key].model][src[key].inverseName] = [{type: ObjectId, ref: modelName, inverseName: key}];
                }
              }
            }
          }
        }
      }
    }
  }
}));
});
  _$jscoverage['manikin-mongodb.js'][261]++;
  defModels = (function (models) {
  _$jscoverage['manikin-mongodb.js'][262]++;
  var allspec, newrest, toDef;
  _$jscoverage['manikin-mongodb.js'][263]++;
  specmodels = tools.desugar(models);
  _$jscoverage['manikin-mongodb.js'][264]++;
  toDef = [];
  _$jscoverage['manikin-mongodb.js'][265]++;
  newrest = {};
  _$jscoverage['manikin-mongodb.js'][266]++;
  allspec = {};
  _$jscoverage['manikin-mongodb.js'][267]++;
  Object.keys(specmodels).forEach((function (modelName) {
  _$jscoverage['manikin-mongodb.js'][268]++;
  return allspec[modelName] = {};
}));
  _$jscoverage['manikin-mongodb.js'][270]++;
  Object.keys(specmodels).forEach((function (modelName) {
  _$jscoverage['manikin-mongodb.js'][271]++;
  var inspec, owners, spec;
  _$jscoverage['manikin-mongodb.js'][272]++;
  spec = allspec[modelName];
  _$jscoverage['manikin-mongodb.js'][273]++;
  owners = specmodels[modelName].owners || {};
  _$jscoverage['manikin-mongodb.js'][274]++;
  inspec = specmodels[modelName].fields || {};
  _$jscoverage['manikin-mongodb.js'][275]++;
  specTransform(allspec, modelName, spec, inspec, Object.keys(inspec));
  _$jscoverage['manikin-mongodb.js'][276]++;
  return newrest[modelName] = _.extend({}, specmodels[modelName], {fields: spec});
}));
  _$jscoverage['manikin-mongodb.js'][280]++;
  Object.keys(newrest).forEach((function (modelName) {
  _$jscoverage['manikin-mongodb.js'][281]++;
  var conf;
  _$jscoverage['manikin-mongodb.js'][282]++;
  conf = newrest[modelName];
  _$jscoverage['manikin-mongodb.js'][283]++;
  Object.keys(conf.owners).forEach((function (ownerName) {
  _$jscoverage['manikin-mongodb.js'][284]++;
  return conf.fields[ownerName] = {type: ObjectId, ref: conf.owners[ownerName], required: true, "x-owner": true};
}));
  _$jscoverage['manikin-mongodb.js'][291]++;
  Object.keys(conf.indirectOwners).forEach((function (p) {
  _$jscoverage['manikin-mongodb.js'][292]++;
  return conf.fields[p] = {type: ObjectId, ref: conf.indirectOwners[p], required: true, "x-indirect-owner": true};
}));
  _$jscoverage['manikin-mongodb.js'][299]++;
  Object.keys(conf.fields).forEach((function (fieldName) {
  _$jscoverage['manikin-mongodb.js'][300]++;
  if (conf.fields[fieldName].ref != null) {
    _$jscoverage['manikin-mongodb.js'][301]++;
    return conf.fields[fieldName].type = ObjectId;
  }
}));
  _$jscoverage['manikin-mongodb.js'][304]++;
  return toDef.push([modelName, newrest[modelName]]);
}));
  _$jscoverage['manikin-mongodb.js'][306]++;
  metaData = tools.getMeta(specmodels);
  _$jscoverage['manikin-mongodb.js'][307]++;
  return toDef;
});
  _$jscoverage['manikin-mongodb.js'][309]++;
  (function () {
  _$jscoverage['manikin-mongodb.js'][310]++;
  var connection;
  _$jscoverage['manikin-mongodb.js'][311]++;
  connection = null;
  _$jscoverage['manikin-mongodb.js'][312]++;
  api.connect = (function (databaseUrl, inputModels, callback) {
  _$jscoverage['manikin-mongodb.js'][313]++;
  try {
    _$jscoverage['manikin-mongodb.js'][314]++;
    connection = mongoose.createConnection(databaseUrl);
    _$jscoverage['manikin-mongodb.js'][315]++;
    defModels(inputModels).forEach((function (_arg) {
  _$jscoverage['manikin-mongodb.js'][316]++;
  var name, v;
  _$jscoverage['manikin-mongodb.js'][317]++;
  name = _arg[0], v = _arg[1];
  _$jscoverage['manikin-mongodb.js'][318]++;
  models[name] = makeModel(connection, name, v.fields);
  _$jscoverage['manikin-mongodb.js'][319]++;
  models[name].schema.pre("save", nullablesValidation(models[name].schema));
  _$jscoverage['manikin-mongodb.js'][320]++;
  models[name].schema.pre("remove", (function (next) {
  _$jscoverage['manikin-mongodb.js'][321]++;
  return preRemoveCascadeNonNullable(models[name], this._id.toString(), next);
}));
  _$jscoverage['manikin-mongodb.js'][323]++;
  return models[name].schema.pre("remove", (function (next) {
  _$jscoverage['manikin-mongodb.js'][324]++;
  return preRemoveCascadeNullable(models[name], this._id.toString(), next);
}));
}));
  }
  catch (ex) {
    _$jscoverage['manikin-mongodb.js'][328]++;
    callback(ex);
    _$jscoverage['manikin-mongodb.js'][329]++;
    return;
  }
  _$jscoverage['manikin-mongodb.js'][331]++;
  return callback();
});
  _$jscoverage['manikin-mongodb.js'][333]++;
  return api.close = (function (callback) {
  _$jscoverage['manikin-mongodb.js'][334]++;
  connection.close();
  _$jscoverage['manikin-mongodb.js'][335]++;
  return callback();
});
})();
  _$jscoverage['manikin-mongodb.js'][338]++;
  api.post = (function (model, indata, callback) {
  _$jscoverage['manikin-mongodb.js'][339]++;
  var owners, ownersOwners, ownersRaw, saveFunc;
  _$jscoverage['manikin-mongodb.js'][340]++;
  saveFunc = (function (data) {
  _$jscoverage['manikin-mongodb.js'][341]++;
  return new models[model](data).save((function (err) {
  _$jscoverage['manikin-mongodb.js'][342]++;
  var fieldMatch, valueMatch;
  _$jscoverage['manikin-mongodb.js'][343]++;
  if (err && err.code === 11000) {
    _$jscoverage['manikin-mongodb.js'][344]++;
    fieldMatch = err.err.match(/([a-zA-Z]+)_1/);
    _$jscoverage['manikin-mongodb.js'][345]++;
    valueMatch = err.err.match(/"([a-zA-Z]+)"/);
    _$jscoverage['manikin-mongodb.js'][346]++;
    if (fieldMatch && valueMatch) {
      _$jscoverage['manikin-mongodb.js'][347]++;
      return callback(new Error("Duplicate value '" + valueMatch[1] + "' for " + fieldMatch[1]));
    }
    else {
      _$jscoverage['manikin-mongodb.js'][349]++;
      return callback(new Error("Unique constraint violated"));
    }
  }
  else {
    _$jscoverage['manikin-mongodb.js'][352]++;
    return massaged(callback).apply(this, arguments);
  }
}));
});
  _$jscoverage['manikin-mongodb.js'][356]++;
  ownersRaw = getMeta(model).owners;
  _$jscoverage['manikin-mongodb.js'][357]++;
  owners = _(ownersRaw).pluck("plur");
  _$jscoverage['manikin-mongodb.js'][358]++;
  ownersOwners = _.flatten(owners.map((function (x) {
  _$jscoverage['manikin-mongodb.js'][359]++;
  return getMeta(x).owners;
})));
  _$jscoverage['manikin-mongodb.js'][361]++;
  if (ownersOwners.length === 0) {
    _$jscoverage['manikin-mongodb.js'][362]++;
    return saveFunc(indata);
  }
  else {
    _$jscoverage['manikin-mongodb.js'][364]++;
    return api.getOne(owners[0], {filter: {id: indata[ownersRaw[0].sing]}}, propagate(callback, (function (ownerdata) {
  _$jscoverage['manikin-mongodb.js'][369]++;
  var metaFields, paths;
  _$jscoverage['manikin-mongodb.js'][370]++;
  paths = models[owners[0]].schema.paths;
  _$jscoverage['manikin-mongodb.js'][371]++;
  metaFields = Object.keys(paths).filter((function (key) {
  _$jscoverage['manikin-mongodb.js'][372]++;
  return ! ! paths[key].options["x-owner"] || ! ! paths[key].options["x-indirect-owner"];
}));
  _$jscoverage['manikin-mongodb.js'][374]++;
  metaFields.forEach((function (key) {
  _$jscoverage['manikin-mongodb.js'][375]++;
  return indata[key] = ownerdata[key];
}));
  _$jscoverage['manikin-mongodb.js'][377]++;
  return saveFunc(indata);
})));
  }
});
  _$jscoverage['manikin-mongodb.js'][381]++;
  api.list = (function (model, filter, callback) {
  _$jscoverage['manikin-mongodb.js'][382]++;
  var defaultSort, rr;
  _$jscoverage['manikin-mongodb.js'][383]++;
  filter = preprocFilter(filter);
  _$jscoverage['manikin-mongodb.js'][384]++;
  defaultSort = specmodels[model].defaultSort;
  _$jscoverage['manikin-mongodb.js'][385]++;
  rr = models[model].find(filter);
  _$jscoverage['manikin-mongodb.js'][386]++;
  if (defaultSort != null) {
    _$jscoverage['manikin-mongodb.js'][387]++;
    rr = rr.sort(_.object([[defaultSort, "asc"]]));
  }
  _$jscoverage['manikin-mongodb.js'][389]++;
  return rr.exec(massaged(callback));
});
  _$jscoverage['manikin-mongodb.js'][391]++;
  api.getOne = (function (model, config, callback) {
  _$jscoverage['manikin-mongodb.js'][392]++;
  var filter;
  _$jscoverage['manikin-mongodb.js'][393]++;
  filter = preprocFilter(config.filter || {});
  _$jscoverage['manikin-mongodb.js'][394]++;
  return models[model].findOne(filter, (function (err, data) {
  _$jscoverage['manikin-mongodb.js'][395]++;
  if (err) {
    _$jscoverage['manikin-mongodb.js'][396]++;
    if (err.toString() === "Error: Invalid ObjectId") {
      _$jscoverage['manikin-mongodb.js'][397]++;
      callback(new Error("No such id"));
    }
    else {
      _$jscoverage['manikin-mongodb.js'][399]++;
      callback(err);
    }
  }
  else {
    _$jscoverage['manikin-mongodb.js'][401]++;
    if (! (data != null)) {
      _$jscoverage['manikin-mongodb.js'][402]++;
      return callback(new Error("No match"));
    }
    else {
      _$jscoverage['manikin-mongodb.js'][404]++;
      return callback(null, massage(data));
    }
  }
}));
});
  _$jscoverage['manikin-mongodb.js'][408]++;
  api.delOne = (function (model, filter, callback) {
  _$jscoverage['manikin-mongodb.js'][409]++;
  filter = preprocFilter(filter);
  _$jscoverage['manikin-mongodb.js'][410]++;
  return models[model].findOne(filter, (function (err, d) {
  _$jscoverage['manikin-mongodb.js'][411]++;
  if (err) {
    _$jscoverage['manikin-mongodb.js'][412]++;
    if (err.toString() === "Error: Invalid ObjectId") {
      _$jscoverage['manikin-mongodb.js'][413]++;
      return callback(new Error("No such id"));
    }
    else {
      _$jscoverage['manikin-mongodb.js'][415]++;
      return callback(err);
    }
  }
  else {
    _$jscoverage['manikin-mongodb.js'][417]++;
    if (! (d != null)) {
      _$jscoverage['manikin-mongodb.js'][418]++;
      return callback(new Error("No such id"));
    }
    else {
      _$jscoverage['manikin-mongodb.js'][420]++;
      return d.remove((function (err) {
  _$jscoverage['manikin-mongodb.js'][421]++;
  return callback(err, ! err? massage(d): void 0);
}));
    }
  }
}));
});
  _$jscoverage['manikin-mongodb.js'][426]++;
  api.putOne = (function (modelName, data, filter, callback) {
  _$jscoverage['manikin-mongodb.js'][427]++;
  var inputFields, inputFieldsValid, invalidFields, model, validField;
  _$jscoverage['manikin-mongodb.js'][428]++;
  filter = preprocFilter(filter);
  _$jscoverage['manikin-mongodb.js'][429]++;
  model = models[modelName];
  _$jscoverage['manikin-mongodb.js'][430]++;
  inputFieldsValid = getKeys(data);
  _$jscoverage['manikin-mongodb.js'][431]++;
  inputFields = Object.keys(data);
  _$jscoverage['manikin-mongodb.js'][432]++;
  validField = Object.keys(model.schema.paths);
  _$jscoverage['manikin-mongodb.js'][433]++;
  invalidFields = _.difference(inputFieldsValid, validField);
  _$jscoverage['manikin-mongodb.js'][434]++;
  if (invalidFields.length > 0) {
    _$jscoverage['manikin-mongodb.js'][435]++;
    callback(new Error("Invalid fields: " + invalidFields.join(", ")));
    _$jscoverage['manikin-mongodb.js'][436]++;
    return;
  }
  _$jscoverage['manikin-mongodb.js'][438]++;
  return model.findOne(filter, (function (err, d) {
  _$jscoverage['manikin-mongodb.js'][439]++;
  if (err != null) {
    _$jscoverage['manikin-mongodb.js'][440]++;
    if (err.message === "Invalid ObjectId") {
      _$jscoverage['manikin-mongodb.js'][441]++;
      callback(new Error("No such id"));
    }
    else {
      _$jscoverage['manikin-mongodb.js'][443]++;
      callback(err);
    }
    _$jscoverage['manikin-mongodb.js'][445]++;
    return;
  }
  _$jscoverage['manikin-mongodb.js'][447]++;
  if (! (d != null)) {
    _$jscoverage['manikin-mongodb.js'][448]++;
    callback(new Error("No such id"));
    _$jscoverage['manikin-mongodb.js'][449]++;
    return;
  }
  _$jscoverage['manikin-mongodb.js'][451]++;
  inputFields.forEach((function (key) {
  _$jscoverage['manikin-mongodb.js'][452]++;
  return d[key] = data[key];
}));
  _$jscoverage['manikin-mongodb.js'][454]++;
  return d.save((function (err) {
  _$jscoverage['manikin-mongodb.js'][455]++;
  return callback(err, err? null: massage(d));
}));
}));
});
  _$jscoverage['manikin-mongodb.js'][459]++;
  api.delMany = (function (primaryModel, primaryId, propertyName, secondaryId, callback) {
  _$jscoverage['manikin-mongodb.js'][460]++;
  var inverseName, mm, secondaryModel;
  _$jscoverage['manikin-mongodb.js'][461]++;
  mm = getMeta(primaryModel).manyToMany.filter((function (x) {
  _$jscoverage['manikin-mongodb.js'][462]++;
  return x.name === propertyName;
}))[0];
  _$jscoverage['manikin-mongodb.js'][464]++;
  if (! (mm != null)) {
    _$jscoverage['manikin-mongodb.js'][465]++;
    callback(new Error("Invalid many-to-many property"));
    _$jscoverage['manikin-mongodb.js'][466]++;
    return;
  }
  _$jscoverage['manikin-mongodb.js'][468]++;
  secondaryModel = mm.ref;
  _$jscoverage['manikin-mongodb.js'][469]++;
  inverseName = mm.inverseName;
  _$jscoverage['manikin-mongodb.js'][470]++;
  return async.forEach([{model: primaryModel, id: primaryId, property: propertyName, secondaryId: secondaryId}, {model: secondaryModel, id: secondaryId, property: inverseName, secondaryId: primaryId}], (function (item, callback) {
  _$jscoverage['manikin-mongodb.js'][483]++;
  return models[item.model].findById(item.id, propagate(callback, (function (data) {
  _$jscoverage['manikin-mongodb.js'][484]++;
  var conditions, options, update;
  _$jscoverage['manikin-mongodb.js'][485]++;
  conditions = {_id: item.id};
  _$jscoverage['manikin-mongodb.js'][488]++;
  update = {$pull: _.object([[item.property, item.secondaryId]])};
  _$jscoverage['manikin-mongodb.js'][491]++;
  options = {};
  _$jscoverage['manikin-mongodb.js'][492]++;
  return models[item.model].update(conditions, update, options, (function (err, numAffected) {
  _$jscoverage['manikin-mongodb.js'][493]++;
  return callback(err);
}));
})));
}), callback);
});
  _$jscoverage['manikin-mongodb.js'][498]++;
  insertOps = [];
  _$jscoverage['manikin-mongodb.js'][499]++;
  api.postMany = (function (primaryModel, primaryId, propertyName, secondaryId, callback) {
  _$jscoverage['manikin-mongodb.js'][500]++;
  var hasAlready, insertOpMatch, insertOpNow, inverseName, mm, secondaryModel;
  _$jscoverage['manikin-mongodb.js'][501]++;
  mm = getMeta(primaryModel).manyToMany.filter((function (x) {
  _$jscoverage['manikin-mongodb.js'][502]++;
  return x.name === propertyName;
}))[0];
  _$jscoverage['manikin-mongodb.js'][504]++;
  if (! (mm != null)) {
    _$jscoverage['manikin-mongodb.js'][505]++;
    callback(new Error("Invalid many-to-many property"));
    _$jscoverage['manikin-mongodb.js'][506]++;
    return;
  }
  _$jscoverage['manikin-mongodb.js'][508]++;
  secondaryModel = mm.ref;
  _$jscoverage['manikin-mongodb.js'][509]++;
  inverseName = mm.inverseName;
  _$jscoverage['manikin-mongodb.js'][510]++;
  insertOpNow = [{primaryModel: primaryModel, primaryId: primaryId, propertyName: propertyName, secondaryId: secondaryId}, {primaryModel: secondaryModel, primaryId: secondaryId, propertyName: inverseName, secondaryId: primaryId}];
  _$jscoverage['manikin-mongodb.js'][523]++;
  insertOpMatch = (function (x1, x2) {
  _$jscoverage['manikin-mongodb.js'][524]++;
  return x1.primaryModel === x2.primaryModel && x1.primaryId === x2.primaryId && x1.propertyName === x2.propertyName && x1.secondaryId === x2.secondaryId;
});
  _$jscoverage['manikin-mongodb.js'][526]++;
  hasAlready = insertOps.some((function (x) {
  _$jscoverage['manikin-mongodb.js'][527]++;
  return insertOpNow.some((function (y) {
  _$jscoverage['manikin-mongodb.js'][528]++;
  return insertOpMatch(x, y);
}));
}));
  _$jscoverage['manikin-mongodb.js'][531]++;
  if (hasAlready) {
    _$jscoverage['manikin-mongodb.js'][532]++;
    callback(null, {status: "insert already in progress"});
    _$jscoverage['manikin-mongodb.js'][535]++;
    return;
  }
  _$jscoverage['manikin-mongodb.js'][537]++;
  insertOpNow.forEach((function (op) {
  _$jscoverage['manikin-mongodb.js'][538]++;
  return insertOps.push(op);
}));
  _$jscoverage['manikin-mongodb.js'][540]++;
  return async.map(insertOpNow, (function (item, callback) {
  _$jscoverage['manikin-mongodb.js'][541]++;
  return models[item.primaryModel].findById(item.primaryId, callback);
}), propagate(callback, (function (datas) {
  _$jscoverage['manikin-mongodb.js'][543]++;
  var updated;
  _$jscoverage['manikin-mongodb.js'][544]++;
  updated = [false, false];
  _$jscoverage['manikin-mongodb.js'][545]++;
  insertOpNow.forEach((function (conf, i) {
  _$jscoverage['manikin-mongodb.js'][546]++;
  if (-1 === datas[i][conf.propertyName].indexOf(conf.secondaryId)) {
    _$jscoverage['manikin-mongodb.js'][547]++;
    datas[i][conf.propertyName].push(conf.secondaryId);
    _$jscoverage['manikin-mongodb.js'][548]++;
    return updated[i] = true;
  }
}));
  _$jscoverage['manikin-mongodb.js'][551]++;
  return async.forEach([0, 1], (function (index, callback) {
  _$jscoverage['manikin-mongodb.js'][552]++;
  if (updated[index]) {
    _$jscoverage['manikin-mongodb.js'][553]++;
    return datas[index].save(callback);
  }
  else {
    _$jscoverage['manikin-mongodb.js'][555]++;
    return callback();
  }
}), (function (err) {
  _$jscoverage['manikin-mongodb.js'][558]++;
  if (err) {
    _$jscoverage['manikin-mongodb.js'][559]++;
    return callback(err);
  }
  _$jscoverage['manikin-mongodb.js'][561]++;
  insertOps = insertOps.filter((function (x) {
  _$jscoverage['manikin-mongodb.js'][562]++;
  return ! _(insertOpNow).contains(x);
}));
  _$jscoverage['manikin-mongodb.js'][564]++;
  return callback(null, {status: (updated.some((function (x) {
  _$jscoverage['manikin-mongodb.js'][566]++;
  return x;
}))? "inserted": "already inserted")});
}));
})));
});
  _$jscoverage['manikin-mongodb.js'][572]++;
  api.getMany = (function (primaryModel, primaryId, propertyName, callback) {
  _$jscoverage['manikin-mongodb.js'][573]++;
  return models[primaryModel].findOne({_id: primaryId}).populate(propertyName).exec((function (err, story) {
  _$jscoverage['manikin-mongodb.js'][576]++;
  return callback(err, massage(story[propertyName]));
}));
});
  _$jscoverage['manikin-mongodb.js'][579]++;
  return api;
});
}).call(this);
_$jscoverage['manikin-mongodb.js'].source = ["// Generated by CoffeeScript 1.4.0","(function() {","  \"use strict\";","","  var async, getKeys, massage, massageCore, massageOne, massaged, preprocFilter, propagate, tools, _,","    __slice = [].slice;","","  async = require('async');","","  _ = require('underscore');","","  tools = require('./manikin-tools');","","  preprocFilter = function(filter) {","    var x;","    x = _.extend({}, filter);","    if (x.id) {","      x._id = x.id;","    }","    delete x.id;","    return x;","  };","","  massageOne = function(x) {","    if (!(x != null)) {","      return x;","    }","    x.id = x._id;","    delete x._id;","    return x;","  };","","  massageCore = function(r2) {","    if (Array.isArray(r2)) {","      return r2.map(massageOne);","    } else {","      return massageOne(r2);","    }","  };","","  massage = function(r2) {","    return massageCore(JSON.parse(JSON.stringify(r2)));","  };","","  massaged = function(f) {","    return function(err, data) {","      if (err) {","        return f(err);","      } else {","        return f(null, massage(data));","      }","    };","  };","","  propagate = function(callback, f) {","    return function() {","      var args, err;","      err = arguments[0], args = 2 &lt;= arguments.length ? __slice.call(arguments, 1) : [];","      if (err) {","        return callback(err);","      } else {","        return f.apply(this, args);","      }","    };","  };","","  getKeys = function(data, target, prefix) {","    var valids;","    if (target == null) {","      target = [];","    }","    if (prefix == null) {","      prefix = '';","    }","    valids = ['Array', 'String', 'Boolean', 'Date', 'Number', 'Null'];","    Object.keys(data).forEach(function(key) {","      if (valids.some(function(x) {","        return _(data[key])['is' + x]();","      })) {","        return target.push(prefix + key);","      } else {","        return getKeys(data[key], target, prefix + key + '.');","      }","    });","    return target;","  };","","  exports.create = function() {","    var Mixed, ObjectID, ObjectId, Schema, api, defModels, getMeta, insertOps, internalListSub, key, makeModel, metaData, models, mongoose, nullablesValidation, preRemoveCascadeNonNullable, preRemoveCascadeNullable, specTransform, specmodels;","    if (process.env.NODE_ENV !== 'production') {","      for (key in require.cache) {","        delete require.cache[key];","      }","    }","    mongoose = require('mongoose');","    Schema = mongoose.Schema;","    Mixed = mongoose.Schema.Types.Mixed;","    ObjectID = mongoose.mongo.ObjectID;","    ObjectId = mongoose.Schema.ObjectId;","    api = {};","    models = {};","    specmodels = {};","    metaData = null;","    makeModel = function(connection, name, schema) {","      var ss;","      ss = new Schema(schema, {","        strict: true","      });","      ss.set('versionKey', false);","      return connection.model(name, ss, name);","    };","    getMeta = function(modelName) {","      return metaData[modelName];","    };","    nullablesValidation = function(schema) {","      return function(next) {","        var nonNullOuters, outers, paths, self;","        self = this;","        paths = schema.paths;","        outers = Object.keys(paths).filter(function(x) {","          return paths[x].options.type === ObjectId &amp;&amp; typeof paths[x].options.ref === 'string' &amp;&amp; !paths[x].options['x-owner'];","        }).map(function(x) {","          return {","            plur: paths[x].options.ref,","            sing: x,","            validation: paths[x].options['x-validation']","          };","        });","        nonNullOuters = outers.filter(function(x) {","          return self[x.sing] != null;","        });","        return async.forEach(nonNullOuters, function(o, callback) {","          return api.getOne(o.plur, {","            id: self[o.sing]","          }, function(err, data) {","            if (err || !data) {","              return callback(new Error(\"Invalid pointer\"));","            } else if (o.validation) {","              return o.validation(self, data, function(err) {","                return callback(err ? new Error(err) : void 0);","              });","            } else {","              return callback();","            }","          });","        }, next);","      };","    };","    internalListSub = function(model, outer, id, filter, callback) {","      var finalFilter;","      if ((filter[outer] != null) &amp;&amp; filter[outer].toString() !== id.toString()) {","        callback(new Error('No such id'));","        return;","      }","      filter = preprocFilter(filter);","      finalFilter = _.extend({}, filter, _.object([[outer, id]]));","      return models[model].find(finalFilter, callback);","    };","    preRemoveCascadeNonNullable = function(owner, id, next) {","      var manys;","      manys = getMeta(owner.modelName).manyToMany;","      return async.forEach(manys, function(many, callback) {","        var obj;","        obj = _.object([[many.inverseName, id]]);","        return models[many.ref].update(obj, {","          $pull: obj","        }, callback);","      }, function(err) {","        var flattenedModels;","        if (err) {","          return next(err);","        }","        flattenedModels = getMeta(owner.modelName).owns;","        return async.forEach(flattenedModels, function(mod, callback) {","          return internalListSub(mod.name, mod.field, id, {}, propagate(callback, function(data) {","            return async.forEach(data, function(item, callback) {","              return item.remove(callback);","            }, callback);","          }));","        }, next);","      });","    };","    preRemoveCascadeNullable = function(owner, id, next) {","      var flattenedModels, ownedModels;","      ownedModels = Object.keys(models).map(function(modelName) {","        var paths;","        paths = models[modelName].schema.paths;","        return Object.keys(paths).filter(function(x) {","          return paths[x].options.type === ObjectId &amp;&amp; paths[x].options.ref === owner.modelName &amp;&amp; !paths[x].options['x-owner'];","        }).map(function(x) {","          return {","            name: modelName,","            field: x","          };","        });","      });","      flattenedModels = _.flatten(ownedModels);","      return async.forEach(flattenedModels, function(mod, callback) {","        return internalListSub(mod.name, mod.field, id, {}, propagate(callback, function(data) {","          return async.forEach(data, function(item, callback) {","            item[mod.field] = null;","            item.save();","            return callback();","          }, callback);","        }));","      }, next);","    };","    specTransform = function(allspec, modelName, tgt, src, keys) {","      return keys.forEach(function(key) {","        if (src[key].type === 'mixed') {","          return tgt[key] = {","            type: Mixed","          };","        } else if (src[key].type === 'nested') {","          tgt[key] = {};","          return specTransform(allspec, modelName, tgt[key], src[key], _.without(Object.keys(src[key]), 'type'));","        } else if (src[key].type === 'string') {","          tgt[key] = _.extend({}, src[key], {","            type: String","          });","          if (src[key].validate != null) {","            return tgt[key].validate = function(value, callback) {","              return src[key].validate(api, value, callback);","            };","          }","        } else if (src[key].type === 'number') {","          return tgt[key] = _.extend({}, src[key], {","            type: Number","          });","        } else if (src[key].type === 'date') {","          return tgt[key] = _.extend({}, src[key], {","            type: Date","          });","        } else if (src[key].type === 'boolean') {","          return tgt[key] = _.extend({}, src[key], {","            type: Boolean","          });","        } else if (src[key].type === 'hasOne') {","          return tgt[key] = {","            ref: src[key].model,","            'x-validation': src[key].validation","          };","        } else if (src[key].type === 'hasMany') {","          tgt[key] = [","            {","              type: ObjectId,","              ref: src[key].model,","              inverseName: src[key].inverseName","            }","          ];","          return allspec[src[key].model][src[key].inverseName] = [","            {","              type: ObjectId,","              ref: modelName,","              inverseName: key","            }","          ];","        }","      });","    };","    defModels = function(models) {","      var allspec, newrest, toDef;","      specmodels = tools.desugar(models);","      toDef = [];","      newrest = {};","      allspec = {};","      Object.keys(specmodels).forEach(function(modelName) {","        return allspec[modelName] = {};","      });","      Object.keys(specmodels).forEach(function(modelName) {","        var inspec, owners, spec;","        spec = allspec[modelName];","        owners = specmodels[modelName].owners || {};","        inspec = specmodels[modelName].fields || {};","        specTransform(allspec, modelName, spec, inspec, Object.keys(inspec));","        return newrest[modelName] = _.extend({}, specmodels[modelName], {","          fields: spec","        });","      });","      Object.keys(newrest).forEach(function(modelName) {","        var conf;","        conf = newrest[modelName];","        Object.keys(conf.owners).forEach(function(ownerName) {","          return conf.fields[ownerName] = {","            type: ObjectId,","            ref: conf.owners[ownerName],","            required: true,","            'x-owner': true","          };","        });","        Object.keys(conf.indirectOwners).forEach(function(p) {","          return conf.fields[p] = {","            type: ObjectId,","            ref: conf.indirectOwners[p],","            required: true,","            'x-indirect-owner': true","          };","        });","        Object.keys(conf.fields).forEach(function(fieldName) {","          if (conf.fields[fieldName].ref != null) {","            return conf.fields[fieldName].type = ObjectId;","          }","        });","        return toDef.push([modelName, newrest[modelName]]);","      });","      metaData = tools.getMeta(specmodels);","      return toDef;","    };","    (function() {","      var connection;","      connection = null;","      api.connect = function(databaseUrl, inputModels, callback) {","        try {","          connection = mongoose.createConnection(databaseUrl);","          defModels(inputModels).forEach(function(_arg) {","            var name, v;","            name = _arg[0], v = _arg[1];","            models[name] = makeModel(connection, name, v.fields);","            models[name].schema.pre('save', nullablesValidation(models[name].schema));","            models[name].schema.pre('remove', function(next) {","              return preRemoveCascadeNonNullable(models[name], this._id.toString(), next);","            });","            return models[name].schema.pre('remove', function(next) {","              return preRemoveCascadeNullable(models[name], this._id.toString(), next);","            });","          });","        } catch (ex) {","          callback(ex);","          return;","        }","        return callback();","      };","      return api.close = function(callback) {","        connection.close();","        return callback();","      };","    })();","    api.post = function(model, indata, callback) {","      var owners, ownersOwners, ownersRaw, saveFunc;","      saveFunc = function(data) {","        return new models[model](data).save(function(err) {","          var fieldMatch, valueMatch;","          if (err &amp;&amp; err.code === 11000) {","            fieldMatch = err.err.match(/([a-zA-Z]+)_1/);","            valueMatch = err.err.match(/\"([a-zA-Z]+)\"/);","            if (fieldMatch &amp;&amp; valueMatch) {","              return callback(new Error(\"Duplicate value '\" + valueMatch[1] + \"' for \" + fieldMatch[1]));","            } else {","              return callback(new Error(\"Unique constraint violated\"));","            }","          } else {","            return massaged(callback).apply(this, arguments);","          }","        });","      };","      ownersRaw = getMeta(model).owners;","      owners = _(ownersRaw).pluck('plur');","      ownersOwners = _.flatten(owners.map(function(x) {","        return getMeta(x).owners;","      }));","      if (ownersOwners.length === 0) {","        return saveFunc(indata);","      } else {","        return api.getOne(owners[0], {","          filter: {","            id: indata[ownersRaw[0].sing]","          }","        }, propagate(callback, function(ownerdata) {","          var metaFields, paths;","          paths = models[owners[0]].schema.paths;","          metaFields = Object.keys(paths).filter(function(key) {","            return !!paths[key].options['x-owner'] || !!paths[key].options['x-indirect-owner'];","          });","          metaFields.forEach(function(key) {","            return indata[key] = ownerdata[key];","          });","          return saveFunc(indata);","        }));","      }","    };","    api.list = function(model, filter, callback) {","      var defaultSort, rr;","      filter = preprocFilter(filter);","      defaultSort = specmodels[model].defaultSort;","      rr = models[model].find(filter);","      if (defaultSort != null) {","        rr = rr.sort(_.object([[defaultSort, 'asc']]));","      }","      return rr.exec(massaged(callback));","    };","    api.getOne = function(model, config, callback) {","      var filter;","      filter = preprocFilter(config.filter || {});","      return models[model].findOne(filter, function(err, data) {","        if (err) {","          if (err.toString() === 'Error: Invalid ObjectId') {","            callback(new Error('No such id'));","          } else {","            callback(err);","          }","        } else if (!(data != null)) {","          return callback(new Error('No match'));","        } else {","          return callback(null, massage(data));","        }","      });","    };","    api.delOne = function(model, filter, callback) {","      filter = preprocFilter(filter);","      return models[model].findOne(filter, function(err, d) {","        if (err) {","          if (err.toString() === 'Error: Invalid ObjectId') {","            return callback(new Error('No such id'));","          } else {","            return callback(err);","          }","        } else if (!(d != null)) {","          return callback(new Error('No such id'));","        } else {","          return d.remove(function(err) {","            return callback(err, !err ? massage(d) : void 0);","          });","        }","      });","    };","    api.putOne = function(modelName, data, filter, callback) {","      var inputFields, inputFieldsValid, invalidFields, model, validField;","      filter = preprocFilter(filter);","      model = models[modelName];","      inputFieldsValid = getKeys(data);","      inputFields = Object.keys(data);","      validField = Object.keys(model.schema.paths);","      invalidFields = _.difference(inputFieldsValid, validField);","      if (invalidFields.length &gt; 0) {","        callback(new Error(\"Invalid fields: \" + invalidFields.join(', ')));","        return;","      }","      return model.findOne(filter, function(err, d) {","        if (err != null) {","          if (err.message === 'Invalid ObjectId') {","            callback(new Error(\"No such id\"));","          } else {","            callback(err);","          }","          return;","        }","        if (!(d != null)) {","          callback(new Error(\"No such id\"));","          return;","        }","        inputFields.forEach(function(key) {","          return d[key] = data[key];","        });","        return d.save(function(err) {","          return callback(err, err ? null : massage(d));","        });","      });","    };","    api.delMany = function(primaryModel, primaryId, propertyName, secondaryId, callback) {","      var inverseName, mm, secondaryModel;","      mm = getMeta(primaryModel).manyToMany.filter(function(x) {","        return x.name === propertyName;","      })[0];","      if (!(mm != null)) {","        callback(new Error('Invalid many-to-many property'));","        return;","      }","      secondaryModel = mm.ref;","      inverseName = mm.inverseName;","      return async.forEach([","        {","          model: primaryModel,","          id: primaryId,","          property: propertyName,","          secondaryId: secondaryId","        }, {","          model: secondaryModel,","          id: secondaryId,","          property: inverseName,","          secondaryId: primaryId","        }","      ], function(item, callback) {","        return models[item.model].findById(item.id, propagate(callback, function(data) {","          var conditions, options, update;","          conditions = {","            _id: item.id","          };","          update = {","            $pull: _.object([[item.property, item.secondaryId]])","          };","          options = {};","          return models[item.model].update(conditions, update, options, function(err, numAffected) {","            return callback(err);","          });","        }));","      }, callback);","    };","    insertOps = [];","    api.postMany = function(primaryModel, primaryId, propertyName, secondaryId, callback) {","      var hasAlready, insertOpMatch, insertOpNow, inverseName, mm, secondaryModel;","      mm = getMeta(primaryModel).manyToMany.filter(function(x) {","        return x.name === propertyName;","      })[0];","      if (!(mm != null)) {","        callback(new Error('Invalid many-to-many property'));","        return;","      }","      secondaryModel = mm.ref;","      inverseName = mm.inverseName;","      insertOpNow = [","        {","          primaryModel: primaryModel,","          primaryId: primaryId,","          propertyName: propertyName,","          secondaryId: secondaryId","        }, {","          primaryModel: secondaryModel,","          primaryId: secondaryId,","          propertyName: inverseName,","          secondaryId: primaryId","        }","      ];","      insertOpMatch = function(x1, x2) {","        return x1.primaryModel === x2.primaryModel &amp;&amp; x1.primaryId === x2.primaryId &amp;&amp; x1.propertyName === x2.propertyName &amp;&amp; x1.secondaryId === x2.secondaryId;","      };","      hasAlready = insertOps.some(function(x) {","        return insertOpNow.some(function(y) {","          return insertOpMatch(x, y);","        });","      });","      if (hasAlready) {","        callback(null, {","          status: 'insert already in progress'","        });","        return;","      }","      insertOpNow.forEach(function(op) {","        return insertOps.push(op);","      });","      return async.map(insertOpNow, function(item, callback) {","        return models[item.primaryModel].findById(item.primaryId, callback);","      }, propagate(callback, function(datas) {","        var updated;","        updated = [false, false];","        insertOpNow.forEach(function(conf, i) {","          if (-1 === datas[i][conf.propertyName].indexOf(conf.secondaryId)) {","            datas[i][conf.propertyName].push(conf.secondaryId);","            return updated[i] = true;","          }","        });","        return async.forEach([0, 1], function(index, callback) {","          if (updated[index]) {","            return datas[index].save(callback);","          } else {","            return callback();","          }","        }, function(err) {","          if (err) {","            return callback(err);","          }","          insertOps = insertOps.filter(function(x) {","            return !_(insertOpNow).contains(x);","          });","          return callback(null, {","            status: (updated.some(function(x) {","              return x;","            }) ? 'inserted' : 'already inserted')","          });","        });","      }));","    };","    api.getMany = function(primaryModel, primaryId, propertyName, callback) {","      return models[primaryModel].findOne({","        _id: primaryId","      }).populate(propertyName).exec(function(err, story) {","        return callback(err, massage(story[propertyName]));","      });","    };","    return api;","  };","","}).call(this);"];
