json-schema-models
Advanced tools
Comparing version 0.5.6 to 0.6.0
@@ -56,32 +56,35 @@ 'use strict'; | ||
if (compileErr) { | ||
return cb(compileErr); | ||
return cb(compileErr, null); | ||
} | ||
if (!Object.keys(this.schema.records).length) { | ||
return cb('No record schemas loaded, please use addSchemas to add schema definitions'); | ||
return cb('No record schemas loaded, please use addSchemas to add schema definitions', null); | ||
} | ||
return this.validate(this.schema, (err) => { | ||
this.validate(this.schema, (err) => { | ||
if (err) { | ||
return cb(err); | ||
return cb(err, null); | ||
} | ||
const conn = internals.prepareConnection(this.settings.mongo); | ||
return MongoClient.connect(conn.url, conn.options, (err, db) => { | ||
MongoClient.connect(conn.url, conn.options, (err, db) => { | ||
if (err) { | ||
return cb(err); | ||
return cb(err, null); | ||
} | ||
this.db = db; | ||
return this.createCollections((err, collections) => { | ||
this.createCollections((err, collections) => { | ||
if (err) { | ||
return cb(err); | ||
return cb(err, null); | ||
} | ||
return this.createSchemas(db, (err, schemas) => { | ||
this.createSchemas(db, (err, schemas) => { | ||
if (err) { | ||
return cb(err); | ||
return cb(err, null); | ||
} | ||
const definitions = schemas.definitions; | ||
@@ -137,3 +140,3 @@ const records = schemas.records; | ||
} | ||
return callback(); | ||
return callback(null); | ||
@@ -158,2 +161,3 @@ }; | ||
} | ||
this.db.close(); | ||
@@ -166,12 +170,13 @@ return null; | ||
const collections = this.collections; | ||
Async.eachSeries(collections, (collection, next) => { | ||
const collectionName = collection.name; | ||
const iterator = (collection, next) => { | ||
const name = collection.name; | ||
const indexes = collection.indexes; | ||
Async.eachSeries(indexes, (index, done) => { | ||
const createIndexes = (index, done) => { | ||
this.db.createIndex(collectionName, index.key, index.options, (err, res) => { | ||
this.db.createIndex(name, index.key, index.options, (err, res) => { | ||
if (err) { | ||
return done('Cannot create collection indices: ' + collectionName + ' - ' + err); | ||
return done('Cannot create collection indices: ' + collection.name + ' - ' + err); | ||
} | ||
@@ -181,10 +186,18 @@ return done(); | ||
}, (err) => { | ||
}; | ||
Async.eachSeries(indexes, createIndexes, (err) => { | ||
return next(err); | ||
}); | ||
}, (err) => { | ||
}; | ||
Async.eachSeries(collections, iterator, (err) => { | ||
return callback(err); | ||
}); | ||
}; | ||
@@ -196,9 +209,10 @@ | ||
const collections = {}; | ||
Async.eachSeries(rawCollections, (rawCollection, next) => { | ||
const collectionName = rawCollection.name; | ||
const iterator = (item, next) => { | ||
const collectionName = item.name; | ||
this._collectionNames.push(collectionName); | ||
const options = rawCollection.options; | ||
const options = item.options; | ||
return this.db.createCollection(collectionName, options, (err, collection) => { | ||
this.db.createCollection(collectionName, options, (err, collection) => { | ||
@@ -208,2 +222,3 @@ if (err) { | ||
} | ||
collections[collectionName] = collection; | ||
@@ -213,7 +228,9 @@ return next(); | ||
}); | ||
}; | ||
}, (err) => { | ||
Async.eachSeries(rawCollections, iterator, (err) => { | ||
return callback(err, collections); | ||
}); | ||
}; | ||
@@ -267,3 +284,3 @@ | ||
const url = connection.url + '/' + connection.name; | ||
const url = `${connection.url}/${connection.name}`; | ||
return { | ||
@@ -270,0 +287,0 @@ name: connection.name, |
{ | ||
"name": "json-schema-models", | ||
"version": "0.5.6", | ||
"version": "0.6.0", | ||
"description": "json schema based models", | ||
@@ -8,3 +8,4 @@ "main": "lib/index.js", | ||
"pretest": "mongo localhost:27017/wadofgum_db ./scripts/mongo.js", | ||
"test": "lab -a code -v -t 100 -L" | ||
"test": "lab -a code -v -t 100 -L", | ||
"coveralls": "lab -r lcov | coveralls" | ||
}, | ||
@@ -21,17 +22,17 @@ "engines": { | ||
"dependencies": { | ||
"basic-utils": "^1.1.0", | ||
"hoek": "^3.0.1", | ||
"joi": "^7.0.1", | ||
"mongodb": "^2.1.0", | ||
"hoek": "^4.0.0", | ||
"joi": "^8.4.0", | ||
"mongodb": "^2.1.21", | ||
"neo-async": "^1.7.1", | ||
"wadofgum": "^4.1.0", | ||
"wadofgum-json-schema": "^0.4.1", | ||
"wadofgum-mongodb": "^0.4.0", | ||
"yajsv": "^0.6.1", | ||
"wadofgum": "^5.1.0", | ||
"wadofgum-json-schema": "^1.1.1", | ||
"wadofgum-mongodb": "^1.1.1", | ||
"yajsv": "^0.7.0", | ||
"z-schema": "^3.16.1" | ||
}, | ||
"devDependencies": { | ||
"code": "^2.0.1", | ||
"lab": "^8.0.0" | ||
"code": "^3.0.0", | ||
"coveralls": "^2.11.9", | ||
"lab": "^10.7.1" | ||
} | ||
} |
@@ -1,2 +0,4 @@ | ||
# json-schema-models [![build status](https://travis-ci.org/simon-p-r/json-schema-models.svg?branch=master)](https://travis-ci.org/simon-p-r/json-schema-models) | ||
# json-schema-models | ||
[![build status](https://travis-ci.org/simon-p-r/json-schema-models.svg?branch=master)](https://travis-ci.org/simon-p-r/json-schema-models) | ||
[![Coverage Status](https://coveralls.io/repos/github/simon-p-r/json-schema-models/badge.svg?branch=master)](https://coveralls.io/github/simon-p-r/json-schema-models?branch=master) | ||
@@ -27,4 +29,4 @@ Data models for mongodb using json schema to define polymorphic schemas to be used with mongodb. | ||
##### .start(callback) | ||
@@ -31,0 +33,0 @@ |
@@ -6,3 +6,2 @@ 'use strict'; | ||
db.example.dropIndexes(); | ||
print('Creating index'); | ||
db.dropDatabase(); |
Sorry, the diff of this file is not supported yet
24184
9
639
57
3
+ Addedbossy@3.0.4(transitive)
+ Addeditems@2.2.1(transitive)
+ Addedjoi@10.6.08.4.2(transitive)
+ Addedneo-async@2.6.2(transitive)
+ Addedwadofgum@5.1.0(transitive)
+ Addedwadofgum-json-schema@1.2.2(transitive)
+ Addedwadofgum-mongodb@1.2.2(transitive)
+ Addedyajsv@0.7.5(transitive)
- Removedbasic-utils@^1.1.0
- Removedbossy@2.0.1(transitive)
- Removeddeep-compact@0.2.4(transitive)
- Removeddeep-filter@0.1.2(transitive)
- Removeddeepmerge@0.2.10(transitive)
- Removedhoek@2.16.33.0.4(transitive)
- Removedis-plain-object@0.1.0(transitive)
- Removedisemail@1.2.0(transitive)
- Removedjoi@6.10.17.3.0(transitive)
- Removedtopo@1.1.0(transitive)
- Removedwadofgum@4.1.0(transitive)
- Removedwadofgum-json-schema@0.4.2(transitive)
- Removedwadofgum-mongodb@0.4.1(transitive)
- Removedyajsv@0.6.1(transitive)
Updatedhoek@^4.0.0
Updatedjoi@^8.4.0
Updatedmongodb@^2.1.21
Updatedwadofgum@^5.1.0
Updatedwadofgum-json-schema@^1.1.1
Updatedwadofgum-mongodb@^1.1.1
Updatedyajsv@^0.7.0