Socket
Socket
Sign inDemoInstall

resourceful

Package Overview
Dependencies
111
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.2 to 0.3.3

CHANGELOG.md

18

lib/resourceful/engines/couchdb/view.js

@@ -64,12 +64,14 @@ var events = require('events'),

//
R[name] = function (/* [param], callback */) {
var that = this,
promise = new events.EventEmitter(),
args = Array.prototype.slice.call(arguments),
callback = args.pop(),
param = args.pop() || {},
path = [this.resource, name].join('/');
R[name] = function (param, callback) {
var that = this,
path = [this.resource, name].join('/'),
params;
var params = (typeof(param) === 'object' && !Array.isArray(param)) ? param : { key: param };
if (typeof param === 'function') {
callback = param;
param = {};
}
params = (typeof(param) === 'object' && !Array.isArray(param)) ? param : { key: param };
if (options) {

@@ -76,0 +78,0 @@ Object.keys(options).forEach(function (key) {

@@ -232,4 +232,6 @@ var util = require('util'),

Resource.create = function (attrs, callback) {
if (this._timestamps) {
attrs.ctime = attrs.mtime = Date.now();
if (this._ctime || this._mtime) {
var now = Date.now();
if(this._ctime) attrs.ctime = now;
if(this._mtime) attrs.mtime = now;
}

@@ -282,11 +284,14 @@

if (!validate.valid) {
var e = { validate: validate, value: instance, schema: that.schema };
var e = { validate: validate, value: obj, schema: this.schema };
return callback && callback(e);
}
if (this._timestamps) {
obj.mtime = Date.now();
if (obj.isNewRecord) {
obj.ctime = obj.mtime;
if (this._ctime || this._mtime) {
var now = Date.now();
if (this._mtime) {
obj.mtime = now;
}
if (this._ctime && obj.isNewRecord) {
obj.ctime = now;
}
}

@@ -335,3 +340,3 @@

if (this._timestamps) {
if (this._mtime) {
obj.mtime = Date.now();

@@ -545,2 +550,25 @@ }

//
// Parent.getChild(parent, child_id, callback)
//
factory['get' + rstringc] = function (parent, child_id, callback) {
var id = parent.key || parent,
cid = child_id;
id_path = factory.lowerResource + '/' + id + '/' + cid
rfactory.get(id_path, function(err, child){
if(err) {
if(callback) return callback(err);
}
return callback(null, child);
});
}
//
// parent.getChild(child_id, callback)
//
factory.prototype['get' + rstringc] = function (child_id, callback) {
return this.constructor['get' + rstringc](this.key, child_id, callback);
};
//
// Parent.createChild(id, child, callback)

@@ -833,4 +861,6 @@ //

Resource.timestamps = function () {
this._timestamps = true;
Resource.timestamps = function (options) {
this._ctime = !options || !('ctime' in options) || options.ctime;
this._mtime = !options || !('mtime' in options) || options.mtime;
this._atime = !!options && !!options.atime;
//

@@ -843,11 +873,18 @@ // Remark: All timestamps should be considered Unix time format,

//
this.property('ctime', 'number', { format: "unix-time", private: true });
if (this._ctime) {
this.property('ctime', 'number', { format: "unix-time", private: true });
}
//
// The last time the resource was modified
//
this.property('mtime', 'number', { format: "unix-time", private: true });
if (this._mtime) {
this.property('mtime', 'number', { format: "unix-time", private: true });
}
//
// The last time the resource was accessed
//
// TODO: this.property('atime', 'number', { format: "unix-time", private: true });
if (this._atime) {
this.property('atime', 'number', { format: "unix-time", private: true });
//TODO actually update atime
}
};

@@ -854,0 +891,0 @@

{
"name": "resourceful",
"description": "an isomorphic Resource engine for JavaScript",
"version": "0.3.2",
"version": "0.3.3",
"url": "http://github.com/flatiron/resourceful",

@@ -28,3 +28,3 @@ "keywords": [

"node-uuid": "1.3.x",
"utile": "*"
"utile": "0.1.x"
},

@@ -42,2 +42,2 @@ "devDependencies": {

}
}
}

@@ -97,2 +97,17 @@ var assert = require('assert'),

}
},
"<by> ['yoda', 'fitzgerald']": {
topic: function (Article) {
Article.by({
keys: ['yoda', 'fitzgerald']
}, this.callback);
},
"should return an array of Article records by 'yoda' or 'fitzgerald'": function (e, res) {
assert.isArray(res);
assert.equal(res.length, 2);
assert(
(res[0].author === 'yoda' && res[1].author === 'fitzgerald') ||
(res[0].author === 'fitzgerald' && res[1].author === 'yoda')
);
}
}

@@ -99,0 +114,0 @@ }

@@ -97,2 +97,50 @@ var vows = require('vows'),

}
},
"and when 'Parent.getChild()' is used": {
topic: function (obj) {
resources[e].User.getRepository('pavan', 'bullet', this.callback);
},
"should return one repository": function (err, obj) {
assert.isNull(err);
assert.isObject(obj);
assert.equal(obj.id, 'user/pavan/bullet');
assert.equal(obj.name, 'bullet');
},
"should be of proper resource type": function (err, obj) {
assert.isNull(err);
assert.equal(obj.resource, 'Repository');
},
"should have the user_id set correctly": function (err, obj) {
assert.isNull(err);
assert.equal(obj.user_id, 'pavan');
}
},
"and when 'Parent.prototype.getChild()' is used": {
topic: function (obj) {
obj.getRepository('bullet', this.callback);
},
"should return one repository": function (err, obj) {
assert.isNull(err);
assert.isObject(obj);
assert.equal(obj.id, 'user/pavan/bullet');
assert.equal(obj.name, 'bullet');
},
"should be of proper resource type": function (err, obj) {
assert.isNull(err);
assert.equal(obj.resource, 'Repository');
},
"should have the user_id set correctly": function (err, obj) {
assert.isNull(err);
assert.equal(obj.user_id, 'pavan');
}
},
"and when 'Parent.getChild()' is used with an invalid child id": {
topic: function (obj) {
resources[e].User.getRepository('pavan', 'pants', this.callback);
},
"should return 404": function (err, obj) {
assert.isObject(err);
assert.isUndefined(obj);
assert.equal(err.status, 404)
},
}

@@ -99,0 +147,0 @@ }

@@ -167,3 +167,3 @@ var assert = require('assert'),

"and be found by non-sanitized_id": function (r) {
assert.equal(r.toString(), '{"id":"abc","resource":"Resource6"}');
assert.equal(r.id, 'abc');
}

@@ -170,0 +170,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc