Comparing version 1.1.2 to 2.0.2
@@ -6,2 +6,23 @@ (function() { | ||
// ## [Couchbase](https://www.npmjs.com/package/couchbase) + [Q](https://www.npmjs.com/package/q) | ||
// This will create a single couchbase instance with promises on top. | ||
// @examples | ||
// // File setup.coffee | ||
// new require('puffer') { host: '127.0.0.1', name: 'default' } | ||
// new require('puffer') { host: '127.0.0.1', name: 'analytics' } | ||
// // In file model.coffee | ||
// puffer = require('puffer').instances['default'] | ||
// puffer.insert( 'doc1', { color: 'red' } ) | ||
// // In file analytic.coffee | ||
// puffer = require('puffer').instances['analytics'] | ||
// puffer.insert( 'doc1', { total_hits: 10 } ) | ||
// // You can even run it in mock mode | ||
// new require('puffer') { host: '127.0.0.1', name: 'default' }, true | ||
CB = require('couchbase'); | ||
@@ -17,6 +38,13 @@ | ||
Couchbase = (function() { | ||
function Couchbase(options, mock) { | ||
Couchbase = class Couchbase { | ||
// ## Create a puffer instance | ||
// You cannot call this constructor directly as it is singleton. Check above for examples. | ||
// @param {object} options it includes bucket name to connect to, host and port or you can pass all as host. e.g. { host: 'localhost', port: 8200, name: 'default' } or { host: '//couchbase', name: 'default' } or { host: 'localhost', name: 'main', password: '123', callback: fn } | ||
// @param {boolean} mock if you want to have mock server pass true. | ||
constructor(options, mock) { | ||
var cluster, host, params; | ||
host = options.port != null ? options.host + ":" + options.port : options.host; | ||
host = options.port != null ? `${options.host}:${options.port}` : options.host; | ||
cluster = (mock != null) && mock ? new CB.Mock.Cluster : new CB.Cluster(host); | ||
@@ -33,12 +61,56 @@ params = [options.name]; | ||
Couchbase.prototype._exec = function(name) { | ||
// ## _exec( name, key, [doc]) | ||
// You should not call this directly in your code. This is for puffer's internal use. | ||
// @method | ||
// @private | ||
// @param {string} name name of couchbase method to be called. Rest of passed params will be passed to couchbase method as arguments. | ||
// @examples | ||
// @_exec "insert", key, doc | ||
// @_exec "get", key | ||
_exec(name) { | ||
return Q.npost(this.bucket, name, Array.prototype.slice.call(arguments, 1)).fail(errorHandler); | ||
}; | ||
} | ||
Couchbase.prototype.insert = function(key, doc, options) { | ||
// ## Create a document | ||
// This can create a document with the given key only if the key doesn't exist. | ||
// @param {string} key document name. This can be used to get the document back. | ||
// @param {document} doc json object, string or integer which should be saved with the given key. | ||
// @param {object} options same as couchbase options for [insert](http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.8/Bucket.html#insert) | ||
// @examples | ||
// puffer = new require('puffer') { host: '127.0.0.1', name: 'default' } | ||
// puffer.insert( 'doc1', { color: 'red' } ) | ||
// puffer.insert( 'doc2', { color: 'blue' } ).then( (d) -> console.log(d) ) | ||
insert(key, doc, options) { | ||
options || (options = {}); | ||
return this._exec("insert", key, doc, options); | ||
}; | ||
} | ||
Couchbase.prototype.get = function(key, clean) { | ||
// ## Get by key or keys | ||
// This can get a document based on a key. Or get documents if you pass an array of keys. | ||
// @param {string | array} key key or keys of document(s) to get | ||
// @param {boolean} clean if it is true, it will only return the value part of result | ||
// @method get(key, [clean=true]) | ||
// @public | ||
// @examples | ||
// // Make sure you have stored 2 documents as 'doc1', 'doc2' in your couchbase | ||
// puffer.get('doc1').then( (d)-> console.log d ) | ||
// puffer.get(['doc1', 'doc2']).then( (d)-> console.log d ) | ||
get(key, clean) { | ||
if (key.constructor === Array) { | ||
@@ -61,10 +133,42 @@ return this._exec("getMulti", key).then(function(data) { | ||
} | ||
}; | ||
} | ||
Couchbase.prototype.replace = function(key, doc, options) { | ||
// ## Replace a document | ||
// Replace an existing document with a new one | ||
// @param {string} key key of document which should be replaced | ||
// @param {document} doc json object, string or integer which should be saved with the given key. | ||
// @param {object} options same as couchbase options for [replace](http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.8/Bucket.html#replace) | ||
// @examples | ||
// puffer.replace('doc1').then( (d)-> console.log d ) | ||
// puffer.replace('doc1', { cas: { '0': 1927806976, '1': 2727156638 } } ).then( (d)-> console.log d ) | ||
replace(key, doc, options) { | ||
options || (options = {}); | ||
return this._exec("replace", key, doc, options); | ||
}; | ||
} | ||
Couchbase.prototype.update = function(key, data, withCas) { | ||
// ## Get & Update a document | ||
// Get and update an existing document. It will update a document partially. You can pass a function like `(doc) ->` which gets the current stored doc as parameter for changes, make sure you are returning the **doc** at the end of function. | ||
// @param {string} key key of document which should be updated | ||
// @param {object|function} data json object which will extend current json document (No deep merge) or a function which has access to current document as first argument and should return the document. | ||
// @param {Boolean} withCas if true, it will add CAS in replace method | ||
// @examples | ||
// puffer.update('doc1', { propA: 'Value A' }).then( (doc)-> console.log doc ) | ||
// modifier = (doc) -> | ||
// doc.year = 2000 | ||
// doc | ||
// puffer.update('doc1', modifier ).then (doc)-> | ||
// console.log doc | ||
// doc.year = 2001 | ||
// doc | ||
update(key, data, withCas) { | ||
var _this; | ||
@@ -84,43 +188,101 @@ _this = this; | ||
}); | ||
}; | ||
} | ||
Couchbase.prototype.upsert = function(key, doc, options) { | ||
// ## Create or Replace a document | ||
// Replace an existing document with a new one | ||
// @param {string} key key of document which should be inserted or updated | ||
// @param {document} doc json object, string or integer which should be saved with the given key. | ||
// @param {object} options same as couchbase options for [upsert](http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.8/Bucket.html#upsert) | ||
// @examples | ||
// puffer.upsert('doc1', { color: 'blue' }).then( (d)-> console.log d ) | ||
upsert(key, doc, options) { | ||
options || (options = {}); | ||
return this._exec("upsert", key, doc, options); | ||
}; | ||
} | ||
Couchbase.prototype.remove = function(key, options) { | ||
// ## Remove a document | ||
// Remove an existing document | ||
// @param {string} key key of document which should be removed | ||
// @param {object} options same as couchbase options for [remove](http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.8/Bucket.html#remove) | ||
// @examples | ||
// puffer.remove('doc1').then( (d)-> console.log d ) | ||
remove(key, options) { | ||
options || (options = {}); | ||
return this._exec("remove", key, options); | ||
}; | ||
} | ||
Couchbase.prototype.counter = function(key, delta, options) { | ||
// ## Atomic Counter | ||
// Atomic increase/decrease a counter. If the counter doesn't exist and you pass **initial** in options it will create the counter with intial value. | ||
// @param {string} key key of document which should be removed | ||
// @param {integer} delta the amount to add or subtract from the counter value. This value may be any non-zero integer. | ||
// @param {object} options same as couchbase options for [counter](http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.8/Bucket.html#counter) | ||
// @examples | ||
// puffer.counter('doc1', 1, { initial: 5}).then( (d)-> console.log d ) | ||
counter(key, delta, options) { | ||
options || (options = {}); | ||
return this._exec("counter", key, delta, options); | ||
}; | ||
} | ||
Couchbase.prototype.from = function(design, view) { | ||
// ## Create ViewQuery | ||
// This will create a ViewQuery and return for more operations such as range, keys. Read couchbase (ViewQuery)[http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.8/ViewQuery.html] object to understand how you can use it. | ||
// @param {string} design the design name to look up. | ||
// @param {string} view the view name to use for query. | ||
// @examples | ||
// puffer.from('users', 'by_email').range( 'a', 'z' ) | ||
from(design, view) { | ||
return CB.ViewQuery.from(design, view); | ||
}; | ||
} | ||
Couchbase.prototype.commit = function(query) { | ||
// ## Submit a ViewQuery | ||
// Submit a ViewQuery to couchbase and return the result as a list | ||
// @param {ViewQuery} query | ||
// @examples | ||
// query = puffer.from('users', 'by_email').limit(5) | ||
// puffer.commit(query).then( (d)-> console.log d ) | ||
commit(query) { | ||
return this._exec("query", query); | ||
}; | ||
} | ||
return Couchbase; | ||
}; | ||
})(); | ||
module.exports = Database = (function() { | ||
class Database { | ||
constructor(options, mock) { | ||
Database.instances[options.name] = new Couchbase(options, mock); | ||
return Database.instances[options.name]; | ||
} | ||
module.exports = Database = (function() { | ||
}; | ||
Database.instances = []; | ||
function Database(options, mock) { | ||
Database.instances[options.name] = new Couchbase(options, mock); | ||
return Database.instances[options.name]; | ||
} | ||
return Database; | ||
})(); | ||
}).call(this); | ||
}).call(this); |
{ | ||
"name": "puffer", | ||
"description": "Extendable Couchbase ODM for Hapi js", | ||
"version": "1.1.2", | ||
"main": "build/main", | ||
"dependencies": { | ||
"boom": "^4.2.0", | ||
"couchbase": "2.4.6", | ||
"lodash": "^4.17.4", | ||
"q": "^1.1.2" | ||
}, | ||
"engines": { | ||
"node": "0.10.*" | ||
}, | ||
"version": "2.0.2", | ||
"license": "ISC", | ||
"author": "Arash Karimzadeh", | ||
@@ -23,18 +14,8 @@ "repository": { | ||
}, | ||
"devDependencies": { | ||
"coveralls": "2.11.16", | ||
"mocha-lcov-reporter": "1.2.0", | ||
"blanket": "^1.1.6", | ||
"chai": "^3.5.0", | ||
"coffee-script": "^1.8.0", | ||
"groc": "^0.8.0", | ||
"gulp": "^3.8.11", | ||
"gulp-coffee": "^2.2.0", | ||
"mocha": "^3.2.0", | ||
"node-uuid": "^1.4.2" | ||
}, | ||
"main": "build/main", | ||
"scripts": { | ||
"test": "mocha --compilers coffee:coffee-script/register", | ||
"test_reporter": "mocha --compilers coffee:coffee-script/register --require blanket --reporter mocha-lcov-reporter", | ||
"test_coveralls": "mocha --compilers coffee:coffee-script/register --require blanket --reporter mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js" | ||
"test_coveralls": "mocha --compilers coffee:coffee-script/register --require blanket --reporter mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js", | ||
"build": "gulp build" | ||
}, | ||
@@ -50,3 +31,24 @@ "config": { | ||
} | ||
}, | ||
"engines": { | ||
"node": ">=10.0.0" | ||
}, | ||
"dependencies": { | ||
"boom": "^7.3.0", | ||
"couchbase": "^2.6.3", | ||
"lodash": "^4.17.11", | ||
"q": "^1.5.1" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "^3.0.3", | ||
"mocha-lcov-reporter": "^1.3.0", | ||
"blanket": "^1.2.3", | ||
"chai": "^4.2.0", | ||
"coffeescript": "^2.4.1", | ||
"groc": "^0.8.0", | ||
"gulp": "^4.0.0", | ||
"gulp-coffee": "^3.0.3", | ||
"mocha": "^6.1.3", | ||
"uuid": "^3.3.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
0
202
18575
8
1
+ Added@colors/colors@1.6.0(transitive)
+ Added@dabh/diagnostics@2.0.3(transitive)
+ Added@types/triple-beam@1.3.5(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedasync@3.2.6(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbindings@1.5.0(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedboom@7.3.0(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedcolor@3.2.1(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcolor-string@1.9.1(transitive)
+ Addedcolorspace@1.1.4(transitive)
+ Addedcouchbase@2.6.12(transitive)
+ Addeddecompress-response@4.2.1(transitive)
+ Addeddev-null@0.1.1(transitive)
+ Addedenabled@2.0.0(transitive)
+ Addedexpand-template@2.0.3(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfecha@4.2.3(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedfn.name@1.1.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhoek@6.1.3(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedis-arrayish@0.3.2(transitive)
+ Addedis-stream@2.0.1(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedkuler@2.0.0(transitive)
+ Addedlogform@2.7.0(transitive)
+ Addedmimic-response@2.1.0(transitive)
+ Addedmkdirp-classic@0.5.3(transitive)
+ Addedms@2.1.3(transitive)
+ Addednan@2.22.0(transitive)
+ Addednapi-build-utils@1.0.2(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedone-time@1.0.0(transitive)
+ Addedprebuild-install@5.3.6(transitive)
+ Addedpsl@1.10.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-stable-stringify@2.5.0(transitive)
+ Addedsimple-get@3.1.1(transitive)
+ Addedsimple-swizzle@0.2.2(transitive)
+ Addedstack-trace@0.0.10(transitive)
+ Addedtar-fs@2.1.1(transitive)
+ Addedtar-stream@2.2.0(transitive)
+ Addedtext-hex@1.0.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtriple-beam@1.4.1(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedwinston@3.17.0(transitive)
+ Addedwinston-transport@4.9.0(transitive)
- Removedajv@5.5.2(transitive)
- Removedbindings@1.3.1(transitive)
- Removedbl@1.2.3(transitive)
- Removedboom@4.3.15.3.3(transitive)
- Removedbuffer-alloc@1.2.0(transitive)
- Removedbuffer-alloc-unsafe@1.1.0(transitive)
- Removedbuffer-fill@1.0.0(transitive)
- Removedco@4.6.0(transitive)
- Removedcouchbase@2.4.6(transitive)
- Removedcryptiles@3.2.1(transitive)
- Removeddecompress-response@3.3.0(transitive)
- Removedexpand-template@1.1.1(transitive)
- Removedfast-deep-equal@1.1.0(transitive)
- Removedhar-validator@5.0.3(transitive)
- Removedhawk@6.0.2(transitive)
- Removedhoek@4.3.1(transitive)
- Removedjson-schema-traverse@0.3.1(transitive)
- Removedmimic-response@1.0.1(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednan@2.9.2(transitive)
- Removedoauth-sign@0.8.2(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedprebuild-install@2.5.3(transitive)
- Removedpump@1.0.32.0.1(transitive)
- Removedpunycode@1.4.1(transitive)
- Removedrequest@2.83.0(transitive)
- Removedsimple-get@2.8.2(transitive)
- Removedsntp@2.1.0(transitive)
- Removedstringstream@0.0.6(transitive)
- Removedtar-fs@1.16.3(transitive)
- Removedtar-stream@1.6.2(transitive)
- Removedto-buffer@1.1.1(transitive)
- Removedtough-cookie@2.3.4(transitive)
- Removedxtend@4.0.2(transitive)
Updatedboom@^7.3.0
Updatedcouchbase@^2.6.3
Updatedlodash@^4.17.11
Updatedq@^1.5.1