Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[api] Rename circularResolve to ttl

  • Loading branch information...
commit 208214583ffa647bd125a9dbfaec2e23542b6bfa 1 parent 8603658
Marak Marak authored
2  example/resolve-circular-links.js
View
@@ -1,7 +1,7 @@
var Hnet = require('../lib/hnet').Hnet;
var hnet = new Hnet({
- circularDelay: 5000
+ ttl: 5000
});
hnet.on('node', function (node, data, options) {
30 lib/hnet.js
View
@@ -32,7 +32,7 @@ var Hnet = exports.Hnet = function (options) {
self.maxDepth = options.maxDepth || 100;
// Default to not resolviing circular data sets
- self.circularDelay = options.circularDelay || -1;
+ self.ttl = options.ttl || -1;
//
@@ -86,7 +86,9 @@ fs.readdirSync(__dirname + '/hnet/cyphers').forEach(function(cypher){
//
Hnet.prototype.parseDocument = function (node, doc, options) {
+
var self = this;
+ self.emit('node::parsing', node);
try {
doc = JSON.parse(doc);
//
@@ -100,9 +102,9 @@ Hnet.prototype.parseDocument = function (node, doc, options) {
//
// TODO: attempt custom engine.parse if available
//
+ console.log(err);
return null;
}
-
//
// Attempt to determine if we have any JSON-RPC commands to execute in the documents
//
@@ -131,11 +133,13 @@ Hnet.prototype.parseDocument = function (node, doc, options) {
self.load(d.params, { currentDepth: options.currentDepth + 1, maxDepth: self.maxDepth });
}
- if (self.circularDelay && options.currentDepth > 0 && self.nodes[node.uri]) {
+ if (self.ttl) {
+ console.log('setting timeout');
setTimeout(function(){
_load();
- }, self.circularDelay)
+ }, self.ttl)
} else {
+ console.log('NOT setting timeout');
_load();
}
}
@@ -155,7 +159,9 @@ Hnet.prototype.load = function(nodes, options, cb){
var self = this;
- console.log('loading data now...', nodes)
+ if (typeof nodes === 'undefined') {
+ nodes = ['http://hnet.iriscouch.com/public/0'];
+ }
//
// If the incoming node is just a string,
@@ -185,6 +191,8 @@ Hnet.prototype.load = function(nodes, options, cb){
return false;
}
+ self.emit('node::loading', nodes);
+
async.forEach(nodes, function(node, cb){
//
@@ -196,12 +204,17 @@ Hnet.prototype.load = function(nodes, options, cb){
uri: node
};
}
- request({ uri: node.uri }, function(err, response, body) {
+
+ request({ uri: node.uri, method: "GET" }, function(err, response, body) {
+
+ if (err) {
+ return cb(err);
+ }
//
// If the node has no type, attempt to detect one
//
- if (!node.type) {
+ if (typeof node.type === 'undefined') {
node.type = "generic";
Object.keys(self.engines).forEach(function(engine) {
if (self.engines[engine].detect) {
@@ -212,7 +225,7 @@ Hnet.prototype.load = function(nodes, options, cb){
});
}
- if(self.nodes[node.uri] && self.circularDelay < 0){
+ if(self.nodes[node.uri] && self.ttl < 0){
return cb(new Error('Already loaded ' + node.uri + ' Will not re-load circular dependency'));
}
@@ -224,7 +237,6 @@ Hnet.prototype.load = function(nodes, options, cb){
cb(null);
});
}
-
if(self.engines[node.type].load) {
loadSet();
}
26 lib/hnet/engines/gist.js
View
@@ -1,5 +1,7 @@
-var request = require('request'),
- gist = exports;
+var request = require('request');
+
+gist = exports;
+
gist.detect = function (node, response, body) {
if (node.uri.search('raw.github.com') !== -1) {
@@ -14,12 +16,20 @@ gist.load = function (options, cb) {
request({ uri: options.uri, method: "GET" }, cb);
};
-gist.set = function () {
-
- //
- // Perform a post to a gist document
- //
-
+gist.set = function (node, cb) {
+ var self = this;
+ request({ uri: "http://hnet.iriscouch.com/public", json: true, body: JSON.stringify({"h":node}), method: "POST" }, function(err, response, body){
+ cb(err, response, body);
+ /*
+ if(self.nodes[node.uri]) {
+ self.nodes[node.uri].rev = body.rev;
+ } else {
+ self.nodes[node.uri] = {
+ body:rev
+ }
+ }
+ */
+ });
};
gist.get = function (uri) {
Please sign in to comment.
Something went wrong with that request. Please try again.