New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

couchdb-update-views

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

couchdb-update-views - npm Package Compare versions

Comparing version 1.0.9 to 1.0.11

lib/shouldUpdate.js

31

cli.js

@@ -16,5 +16,5 @@ #! /usr/bin/env node

var config = nconf.argv().env().file({file: configFilePath})
var getDB = require('./getDB')
var update = require('./update')
var path = require('path')
var cradleNconf = require('cradle-nconf')
function sync(callback) {

@@ -29,18 +29,17 @@ var couch = config.get('couch')

if (err) { return callback(err) }
getDB(couch, function (err, db) {
getDocs(docsDir, function (err, files) {
async.forEach(
files,
function(file, cb) {
var db = cradleNconf(config)
getDocs(docsDir, function (err, files) {
async.forEach(
files,
function(file, cb) {
var filePath = file.filePath
inspect(filePath, 'updating document at path')
var docPath = '_design/' + file.fileName.replace(/\.js/,'')
var doc = require(filePath)
inspect(docPath, 'docPath')
update(db, docPath, doc, cb)
},
callback
)
})
var filePath = file.filePath
inspect(filePath, 'updating document at path')
var docPath = '_design/' + file.fileName.replace(/\.js/,'')
var doc = require(filePath)
inspect(docPath, 'docPath')
update(db, docPath, doc, cb)
},
callback
)
})

@@ -47,0 +46,0 @@ })

@@ -7,3 +7,6 @@ module.exports = {

if (doc.resource === 'Customer') {
emit(doc._id, doc) }
emit(doc._id, null) }
},
reduce: function(key, values) {
return sum(values)
}

@@ -14,3 +17,3 @@ },

if (doc.resource === 'Customer' && doc.customerName) {
emit(doc.customerName, doc)
emit(doc.customerName, null)
}

@@ -17,0 +20,0 @@ }

{
"name": "couchdb-update-views",
"version": "1.0.9",
"version": "1.0.11",
"description": "Keep couchdb views up to date",

@@ -28,3 +28,2 @@ "main": "sync.js",

"optimist": "~0.3.5",
"cradle": "~0.6.4",
"nconf": "~0.6.7",

@@ -31,0 +30,0 @@ "should": "~1.2.2",

@@ -9,3 +9,3 @@ Keep couchdb views up to date

```bash
npm install -g update-couchdb-views
npm install -g couchdb-update-views
```

@@ -17,3 +17,3 @@

```bash
update-couchdb-views --config ./sampeConfig.json --docsDir ./docs
couchdb-update-views --config ./sampleConfig.json --docsDir ./docs
```

@@ -20,0 +20,0 @@ Look at <project_root>/sampleConfig.json for an example of what your config json file should look like

@@ -11,3 +11,3 @@ var inspect = require('eyespect').inspector()

protocol: 'http',
database: 'fooDB',
database: 'views_test',
port: 5984

@@ -14,0 +14,0 @@ }

@@ -17,2 +17,3 @@ var ce = require('cloneextend')

describe('Customer', function () {
this.slow(300)
var db

@@ -45,13 +46,50 @@ before(function (done) {

var newCustomer = ce.clone(customer)
newCustomer.views.fooView = {
newCustomer.views.test = {
map: function(doc) {
emit(doc._id, doc)
},
reduce: function (keys, values) {
return values.length
}
}
update(db, '_design/customer', newCustomer, done)
update(db, '_design/customer', newCustomer, function (err, reply) {
should.not.exist(err)
// confirm the design document was updated correctly
db.get('_design/customer', function (err, reply) {
should.not.exist(err)
should.exist(reply)
var inputTestView = newCustomer.views.test
var inputTestViewMap = inputTestView.map.toString().replace(/\s/g,'')
var inputTestViewReduce = inputTestView.reduce.toString().replace(/\s/g,'')
var newViews = reply.views
var newViewMap = newViews.test.map.toString().replace(/\s/g,'')
var newViewReduce = newViews.test.reduce.toString().replace(/\s/g,'')
newViewReduce.should.eql(inputTestViewReduce)
newViewMap.should.eql(inputTestViewMap)
done()
})
})
})
it('should reset customer design document back to original', function (done) {
update(db, '_design/customer', customer, done)
update(db, '_design/customer', customer, function (err) {
should.not.exist(err)
db.get('_design/customer', function (err, reply) {
should.not.exist(err)
should.exist(reply)
var inputView = customer.views.all
var inputViewMap = inputView.map.toString().replace(/\s/g,'')
var inputViewReduce = inputView.reduce.toString().replace(/\s/g,'')
var newViews = reply.views
var newViewMap = newViews.all.map.toString().replace(/\s/g,'')
var newViewReduce = newViews.all.reduce.toString().replace(/\s/g,'')
newViewReduce.should.eql(inputViewReduce)
newViewMap.should.eql(inputViewMap)
done()
})
})
})
it('should create new customer', function (done) {

@@ -94,3 +132,7 @@ removeAll(db, function (err) {

function removeAll(db, callback) {
db.view('customer/all', {}, function (err, docs) {
var opts = {
include_docs: true,
reduce: false
}
db.view('customer/all', opts, function (err, docs) {
if (err) { return callback(err) }

@@ -102,5 +144,6 @@ if (docs.length === 0) {

docs,
function (doc, cb) {
var rev = doc.value._rev
var id = doc.value._id
function (element, cb) {
var doc = element.doc
var rev = doc._rev
var id = doc._id
db.remove(id, rev, cb)

@@ -107,0 +150,0 @@ }, callback)

@@ -0,1 +1,6 @@

/**
* See if the "doc" in the database matches the code in the source file
*/
var inspect = require('eyespect').inspector();
var shouldUpdate = require('./lib//shouldUpdate')
module.exports = function updateViews(db, docPath, code, cb) {

@@ -7,11 +12,7 @@ // compare function definitions in document and in code

}
var rev = doc._rev
var docUpdates = doc.updates
var codeUpdates = code.updates
var docViews = doc.views
var codeViews = code.views
var viewsPending = compareDef(doc.views, code.views, docPath)
var updatesPending = compareDef(doc.updates, code.updates, docPath)
if (updatesPending || viewsPending) {
var viewsPending = shouldUpdate(doc.views, code.views)
inspect(viewsPending, 'is update needed?')
if (viewsPending) {
var rev = doc._rev
return updateDoc(db, docPath, code, rev, cb)

@@ -40,24 +41,1 @@ }

}
function compareDef(docDef, codeDef, docPath) {
var u
var i = 0
if (!codeDef && !docDef) {
return false
}
for (u in docDef) {
i++
if (!codeDef[u] || docDef[u] != codeDef[u].toString()) {
return true
}
}
// check that both doc and code have same number of functions
for (u in codeDef) {
i--
if (i < 0) {
return true
}
}
return false
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc