Last change
on this file since 481 was
479,
checked in by hendrikvanantwerpen, 11 years ago
|
Changes for validation
- Split command line wrappers from processing logic.
- Created a JSON Schema for the database
- Allow off-line validation of database documents.
|
File size:
886 bytes
|
Line | |
---|
1 | var Q = require('q') |
---|
2 | , _ = require('underscore') |
---|
3 | , tv4 = require('tv4') |
---|
4 | , CouchDB = require('../util/couch').CouchDB |
---|
5 | ; |
---|
6 | |
---|
7 | var schema = require('./couchdb-schema'); |
---|
8 | |
---|
9 | module.exports = function(couchDbURL) { |
---|
10 | var server = new CouchDB(couchDbURL); |
---|
11 | var designRe = /^_design\//; |
---|
12 | return server.get('/_all_docs') |
---|
13 | .then(function(allDocs){ |
---|
14 | return _.chain(allDocs.rows) |
---|
15 | .filter(function(doc){ |
---|
16 | return doc.id.match(designRe) === null; |
---|
17 | }) |
---|
18 | .reduce(function(memo, doc){ |
---|
19 | return memo.then(function(result){ |
---|
20 | return server.get(doc.id) |
---|
21 | .then(function(doc){ |
---|
22 | var valid = tv4.validateResult(doc,schema); |
---|
23 | result[doc._id] = valid; |
---|
24 | return result; |
---|
25 | }); |
---|
26 | }); |
---|
27 | }, Q.resolve({})) |
---|
28 | .value(); |
---|
29 | }).all(); |
---|
30 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.