Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

clues

Package Overview
Dependencies
Maintainers
1
Versions
158
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clues - npm Package Compare versions

Comparing version 2.5.0-beta8 to 3.0.0-rc1

test/global-test.js

203

clues.js

@@ -1,129 +0,100 @@

// clues.js (c) 2009-2014 Ziggy.jonsson.nyc@gmail.com @license MIT
var Promise = require('bluebird'),
reArgs = /function.*?\((.*?)\).*/;
(function(self) {
if (typeof module !== 'undefined') {
clues.prototype.Promise = require('bluebird');
module.exports = clues;
} else {
clues.prototype.Promise = self.Promise;
self.clues = clues;
function matchArgs(fn) {
if (!fn.__args__) {
var match = reArgs.exec(fn.prototype.constructor.toString());
fn.__args__ = match[1].replace(/\s/g,'')
.split(',')
.filter(function(d) {
return d.length;
});
}
return fn.__args__;
}
// Extract argument names from a function
var reArgs = /function.*?\((.*?)\).*/;
function matchArgs(fn) {
if (!fn.__args__) {
var match = reArgs.exec(fn.prototype.constructor.toString());
fn.__args__ = match[1].replace(/\s/g,'')
.split(",")
.filter(function(d) {
return d.length;
function clues(logic,fn,$global,caller,fullref) {
var args,ref;
if (!$global) $global = {};
$global.$root = $global.$root || logic;
if (typeof fn === 'string') {
ref = fn;
var dot = ref.indexOf('.');
if (dot > -1) {
var next = ref.slice(0,dot);
return clues(logic,next,$global,caller,fullref)
.then(function(d) {
d.$parent = d.$parent || logic;
logic = d;
ref = ref.slice(dot+1);
fullref = (fullref ? fullref+'.' : '')+next;
return clues(logic,ref,$global,caller,fullref);
})
.catch(function(e) {
if (logic[ref]) return Promise.fulfilled(logic[ref]);
if (logic.$service && typeof logic.$service === 'function')
return logic[ref] = clues(logic,function() { return logic.$service.call(logic,ref); },$global,caller,(fullref ? fullref+'.' : '')+ref);
else throw e;
});
}
return fn.__args__;
fullref = (fullref ? fullref+'.' : '')+ref;
fn = logic[ref];
if (fn === undefined) {
if ($global[ref]) return clues($global,ref,$global,caller,fullref);
if (logic.$property && typeof logic.$property === 'function')
return logic[ref] = clues(logic,function() { return logic.$property.call(logic,ref); },$global,caller,fullref) ;
return Promise.rejected({ref : ref, message: ref+' not defined', fullref:fullref,caller: caller});
}
}
function clues(logic,facts,options) {
if (!(this instanceof clues))
return new clues(logic,facts,options);
this.logic = logic || (typeof window === 'undefined' ? {} : window);
this.facts = facts || {};
this.options = options || {};
this.self = this;
// Support an array with argument names in front and the function as last element
if (typeof fn === 'object' && fn.length && typeof fn[fn.length-1] == 'function') {
args = fn.slice(0,fn.length-1);
fn = fn[fn.length-1];
}
// If the logic reference is not a function, we simply return the value
if (typeof fn !== 'function') return Promise.fulfilled(fn);
clues.version = "2.5.0";
args = (args || matchArgs(fn))
.map(function(arg) {
var optional,showError;
if (optional = (arg[0] === '_')) arg = arg.slice(1);
if (showError = (arg[0] === '_')) arg = arg.slice(1);
return clues(logic,arg,$global,ref,fullref)
.then(null,function(e) {
if (optional) return (showError) ? e : undefined;
else throw e;
});
});
clues.prototype.solve = function(fn,local,caller,fullref) {
var self = this, ref, args;
local = local || {};
var inputs = Promise.all(args);
if (inputs.cancellable) inputs = inputs.cancellable();
if (typeof fn === "string") {
ref = fn;
var value = inputs
.then(function(args) {
return fn.apply(logic, args);
})
.then(function(d) {
return typeof d == 'string' ? d : clues(logic,d,$global,caller,fullref);
},function(e) {
if (e.name && e.name == 'CancellationError')
return args.forEach(function(arg) { arg.cancel(); });
if (typeof e !== 'object')
e = { message : e};
e.error = true;
e.ref = e.ref || ref;
e.fullref = e.fullref || fullref;
e.caller = e.caller || caller || '';
throw e;
});
// If we have already determined the fact we simply return it
if (self.facts[ref] !== undefined) return self.Promise.fulfilled(self.facts[ref]);
if (ref) logic[ref] = value;
return value;
}
// If the reference contains dots we solve recursively
if (!self.options.ignoreDots && ref.indexOf('.') > -1) {
var keys = ref.split('.'), i=-1;
return function next(d) {
var key = keys[++i];
if (!key) return self.Promise.fulfilled(d);
fullref = fullref ? fullref+'.'+key : key;
if (typeof d !== 'object') throw {ref: ref, fullref: fullref || ref, caller: caller, message: ref+' not defined', name: 'Undefined'};
if (!d.solve) d = clues(d,{ parent : d.parent ? undefined : self},self.options);
return d.facts[keys.slice(i).join('.')] = d.solve(key,local,caller,fullref).then(next);
}(self);
}
// If we can't find any logic, we check self and local before returning an error
if (self.logic[ref] === undefined) {
if (caller !== '__user__') {
if (local[ref] !== undefined) return self.Promise.fulfilled(local[ref]);
if (self[ref] !== undefined && typeof self[ref] !== 'function') return self.Promise.fulfilled(self[ref]);
}
if (typeof(self.options.fallback) === 'function') return self.facts[ref] = self.Promise.fulfilled(self.options.fallback.call(this,ref,local,caller));
return self.Promise.rejected({ref: ref, fullref: fullref || ref, caller: caller, message: ref+' not defined', name: 'Undefined'});
}
fn = self.logic[ref];
}
// Support an array with argument names in front and the function as last element
if (typeof fn === 'object' && fn.length && typeof fn[fn.length-1] == 'function') {
args = fn.slice(0,fn.length-1);
fn = fn[fn.length-1];
}
// If the logic reference is not a function, we simply return the value
if (typeof fn !== 'function') return self.facts[ref] = self.Promise.fulfilled(fn);
args = (args || matchArgs(fn))
.map(function(arg) {
var optional = arg[0] === '_';
if (optional) arg = arg.slice(1);
return self.solve(arg,local,ref)
.then(null,function(e) {
if (optional) return undefined;
else throw e;
});
});
// Wait for all arguments to be resolved before executing the function
var inputs = self.Promise.all(args);
if (inputs.cancellable) inputs = inputs.cancellable();
return self.facts[ref] = inputs
.then(function(args) {
return fn.apply(self,args);
})
.then(null,function(e) {
if (e.name && e.name == 'CancellationError')
return args.forEach(function(arg) { arg.cancel(); });
if (typeof e !== 'object')
e = { message : e};
e.ref = e.ref || ref;
e.fullref = e.fullref || fullref;
e.caller = e.caller || caller || '';
throw e;
});
};
clues.prototype.solver = function(d,e,f) {
return this.solve.bind(this,d,e,f);
};
clues.prototype.fork = function(update) {
update = update || {};
var facts = Object.create(this.facts);
Object.keys(update).forEach(function(key) {
facts[key] = update[key];
});
return clues(this.logic,facts,this.options);
};
clues.prototype.clues = clues.bind(undefined);
})(this);
clues.Promise = Promise;
module.exports = clues;
{
"name": "clues",
"version": "2.5.0-beta8",
"version": "3.0.0-rc1",
"description": "Lightweight logic tree solver using promises.",

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

"dependencies": {
"bluebird": "~2.3.11"
"bluebird": "~2.9.14"
},

@@ -20,0 +20,0 @@ "devDependencies": {

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

#### Breaking changes in version 2.0:
* [Bluebird](https://www.npmjs.org/package/bluebird) is now the core promises library and the latest [Mocha](https://www.npmjs.org/package/mocha) is used for testing
* Logic functions have to return either a value or promise, the `resolve` and `reject` methods have been removed
* Text errors are now returned as the `message` property of the thrown object, not as `err`
* Methods `all`, `as` and `wrapper` removed and methods `solver` and `fork` added for better flow control.
## Complete rewrite in version 3.0
### UNDOCUMENTED - see test directory for usage.
# clues.js
# Old docs
[Promises](https://github.com/promises-aplus) provide a very effective mechanism to construct complex interactions between asynchronous functions. Most promise libraries focus on the promise object itself, and leave the actual structuring of complex logic up to the user.

@@ -9,0 +7,0 @@

var clues = require("../clues"),
Promise = require('bluebird'),
assert = require("assert");

@@ -9,6 +10,6 @@

M1 : function() {
return this.Promise
return Promise
.delay(10,130)
.cancellable()
.catch(this.Promise.CancellationError,function() {
.catch(Promise.CancellationError,function() {
cancel.M1 = true;

@@ -18,6 +19,6 @@ });

M2 : function() {
return this.Promise
return Promise
.delay(50,170)
.cancellable()
.catch(this.Promise.CancellationError,function() {
.catch(Promise.CancellationError,function() {
cancel.M2 = true;

@@ -27,5 +28,5 @@ });

M3 : function() {
return this.Promise
return Promise
.delay(10,10)
.catch(this.Promise.CancellationError,function() {
.catch(Promise.CancellationError,function() {
cancel.M3 = true;

@@ -38,5 +39,6 @@ });

var c = clues(logic),
res = c.solve('MTOP');
var facts = Object.create(logic);
var res = clues(facts,'MTOP');
it('should result in undefined value where cancelled',function() {

@@ -62,3 +64,3 @@ return res

assert.equal(cancel.M3,undefined);
assert.equal(c.facts.M3.value(),10);
assert.equal(facts.M3.value(),10);
});

@@ -65,0 +67,0 @@ });

var clues = require("../clues"),
assert = require("assert");
assert = require("assert"),
Promise = require('bluebird');

@@ -7,13 +8,13 @@ describe('complex tree',function() {

var logic = {
M1 : function() { return this.Promise.delay(10,100); },
M2 : function() { return this.Promise.delay(300,20); },
M1 : function() { return Promise.delay(10,100); },
M2 : function() { return Promise.delay(300,20); },
M3 : function(M1,M2) { return M1+M2; },
M4 : function() { return this.Promise.delay(70,150); },
M4 : function() { return Promise.delay(70,150); },
MTOP : function(M3,M4) { return M3+M4; }
};
var c = clues(logic);
var facts = Object.create(logic);
it('should resolve to the top',function() {
return c.solve('MTOP')
return clues(facts,'MTOP')
.then(function(d) {

@@ -25,10 +26,8 @@ assert.equal(d,380);

it('should update the fact table',function() {
return c.solve(function(facts) {
assert.equal(facts.M1.value(),10);
assert.equal(facts.M2.value(),300);
assert.equal(facts.M3.value(),310);
assert.equal(facts.M4.value(),70);
assert.equal(facts.MTOP.value(),380);
});
assert.equal(facts.M1.value(),10);
assert.equal(facts.M2.value(),300);
assert.equal(facts.M3.value(),310);
assert.equal(facts.M4.value(),70);
assert.equal(facts.MTOP.value(),380);
});
});
var clues = require("../clues"),
assert = require("assert");
function shouldErr() { throw 'Should throw an error'; }
describe('error',function() {
var c = {a: function(b) { return b;}};
describe('when argument can´t be found',function() {
var c = clues({a:function(b) { return b;}});
it('should throw an error',function() {
return c.solve('SOMETHING')
.then(null,function(e) {
return clues({},'SOMETHING')
.then(shouldErr,function(e) {
assert.equal(e.ref,'SOMETHING');

@@ -18,4 +19,4 @@ assert.equal(e.message, 'SOMETHING not defined');

it('should show caller if a named logic function',function() {
return c.solve('a')
.then(null,function(e) {
return clues(c,'a')
.then(shouldErr,function(e) {
assert.equal(e.ref,'b');

@@ -30,12 +31,12 @@ assert.equal(e.message,'b not defined');

var logic = {
ERR : function() { throw "Could not process"; },
DEP : function(ERR) { return "Where is the error"; }
ERR : function() { throw 'Could not process'; },
DEP : function(ERR) { return 'Where is the error'; }
};
var facts = Object.create(logic);
describe('directly',function() {
var c = clues(logic);
it('should show up as first argument (err)',function() {
return c.solve('ERR')
.then(null,function(e) {
return clues(facts,'ERR')
.then(shouldErr,function(e) {
assert.equal(e.ref,'ERR');

@@ -46,8 +47,6 @@ assert.equal(e.message,'Could not process');

it ('should update the fact table',function() {
return c.solve(function(facts) {
it ('should update the facts',function() {
var e = facts.ERR.reason();
assert.equal(e.ref,'ERR');
assert.equal(e.message,'Could not process');
});
assert.equal(e.message,'Could not process');
});

@@ -57,6 +56,6 @@ });

describe('indirectly',function() {
var c = clues(logic);
it('should throw same error for dependent logic',function() {
return c.solve('DEP')
.then(null,function(e) {
return clues(facts,'DEP')
.then(shouldErr,function(e) {
assert.equal(e.ref,'ERR');

@@ -68,4 +67,8 @@ assert.equal(e.message,'Could not process');

it('should contain reference to the first caller',function() {
return c.solve('DEP')
.then(null,function(e) {
facts = Object.create(logic);
return clues(facts,'DEP')
.catch(function() {
return clues(facts,'ERR');
})
.then(shouldErr,function(e) {
assert.equal(e.caller,'DEP');

@@ -76,2 +79,3 @@ });

});
});
});
var clues = require("../clues"),
assert = require("assert");
assert = require("assert"),
Promise = require('bluebird');
describe('facts',function() {
var c = clues({
response : function() { return this.Promise.delay(42,500);},
var logic = {
response : function() { return Promise.delay(42,500);},
other : function() { return 5; }
});
};
var facts = Object.create(logic);
it('should return the solved logic when determined',function() {
var start = new Date();
return c.solve('response')
return clues(facts,'response')
.then(function(d) {

@@ -23,3 +25,3 @@ var wait = (new Date()) - start;

var start = new Date();
return c.solve('response')
return clues(facts,'response')
.then(function(d) {

@@ -33,4 +35,4 @@ var wait = (new Date()) - start;

it('should not be solved for unrequested logic',function() {
assert.equal(c.facts.other,undefined);
assert(typeof facts.other === 'function');
});
});
var clues = require("../clues"),
assert = require("assert");
assert = require("assert"),
Promise = require('bluebird');
describe('minified logic',function() {
describe('Angular style minification',function() {
var logic = {
M1 : [function() { return this.Promise.delay(10,100); }],
M2 : function() { return this.Promise.delay(300,20); },
M1 : [function() { return Promise.delay(10,100); }],
M2 : function() { return Promise.delay(300,20); },
M3 : ['M1','M2',function(a,b) { return a+b; }],
M4 : function(M3) { return M3;},
regular_array : [1,2,3,4]
regular_array : [1,2,3,4],
nested : [function() {
return function() {
return ['M1',function(M1) {
return M1+5;
}];
};
}]
};
var c = clues(logic);
var facts = Object.create(logic);
it('should resolve to the top',function() {
return c.solve('M4')
return clues(facts,'M3')
.then(function(d) {

@@ -24,3 +32,3 @@ assert.equal(d,310);

it('should work for individual functions',function() {
return c.solve(['M4',function(a) {
return clues(facts,['M4',function(a) {
assert.equal(a,310);

@@ -30,4 +38,10 @@ }]);

it('should work for nested structures',function() {
return clues(facts,['nested',function(d) {
assert.equal(d,15);
}]);
});
it('should not affect regular arrays',function() {
return c.solve(function(regular_array) {
return clues(facts,function(regular_array) {
assert.equal(regular_array,logic.regular_array);

@@ -34,0 +48,0 @@ });

var clues = require("../clues"),
assert = require("assert");
assert = require("assert"),
Promise = require('bluebird');
describe('optional argument',function() {
var logic = {
data : function() { return this.Promise.delay(5,1000); },
data : function() { return Promise.delay(5,1000); },
passthrough : function(_optional) { return _optional; },

@@ -15,5 +15,4 @@ internalize : function(data,_optional) { return data + (_optional || 2); },

describe('not supplied',function() {
it('should return undefined',function() {
return clues(logic)
.solve('passthrough')
return it('should return undefined',function() {
clues(Object.create(logic),'passthrough')
.then(function(d) {

@@ -27,8 +26,6 @@ assert.deepEqual(d,undefined);

it('should use the internal default',function() {
return clues(logic)
.solve('internalize')
return clues(Object.create(logic),'internalize')
.then(function(d) {
assert.equal(d,7);
});
});

@@ -39,4 +36,3 @@ });

it('should return the right value',function() {
return clues(logic,{optional:10})
.solve('passthrough')
return clues(Object.create(logic),'passthrough',{optional:10})
.then(function(d) {

@@ -50,4 +46,3 @@ assert.equal(d,10);

it('should return the function results',function() {
return clues(logic)
.solve('optional_data')
return clues(Object.create(logic),'optional_data')
.then(function(d) {

@@ -60,10 +55,11 @@ assert.equal(d,5);

describe('as an error',function() {
var c = clues({
var logic2 = {
error : function() { throw "#Error"; },
optional : function(_error) { return _error; },
regular : function(_error) { return _error; }
});
regular : function(error) { return error; },
showerror : function(__error) { return __error;}
};
it('should return undefined, if optional',function() {
c.solve('optional')
return clues(Object.create(logic2),'optional')
.then(function(d) {

@@ -75,7 +71,19 @@ assert.equal(d,undefined);

it('should raise error if non-optonal',function() {
c.solve('regular')
.then(null,function(e) {
assert.equal(d.err,"#Error");
return clues(Object.create(logic2),'regular')
.then(function(d) {
throw 'Should error';
},function(e) {
assert.equal(e.message,"#Error");
});
});
it('should return the error as an object when prefix is two underscores',function() {
return clues(Object.create(logic2),'showerror')
.then(function(e) {
assert.equal(e.error,true);
assert.equal(e.message,'#Error');
assert.equal(e.fullref,'showerror.error');
assert.equal(e.ref,'error');
});
});
});

@@ -82,0 +90,0 @@ });

@@ -1,2 +0,2 @@

var clues = require("../clues"),
var instinct = require("../clues"),
assert = require("assert");

@@ -9,8 +9,8 @@

b: {
c : function(parent) {
return parent.solve('a');
c : function($parent) {
return $parent.a;
}
},
b2 : {
c : ['parent',function(a) {
c : ['$parent.a',function(a) {
return a;

@@ -20,15 +20,16 @@ }]

c : {
parent:function() {
$parent:function() {
return {d: 3};
},
e : function(parent) {
return this.solve('parent.d');
}
}
e : ['$parent.d',function(d) {
return d;
}]
},
f : { g: { h : { a: 3 } } }
};
var c = clues(logic);
var facts = Object.create(logic);
it('should reference prior level through "parent"',function() {
return c.solve('b.c')
it('should reference prior level through "$parent"',function() {
return instinct(facts,'b.c')
.then(function(d) {

@@ -38,4 +39,4 @@ assert.equal(d,123);

});
it('should reference prior level through "parent"',function() {
return c.solve('b2')
it('should reference prior level through "$parent"',function() {
return instinct(facts,'b2.c')
.then(function(d) {

@@ -46,4 +47,4 @@ assert.equal(d,123);

it('should not overwrite a logic function named "parent"',function() {
return c.solve('c.e')
it('should not overwrite a logic function named "$parent"',function() {
return instinct(facts,'c.e')
.then(function(d) {

@@ -54,2 +55,9 @@ assert.equal(d,3);

it('should work through multiple levels',function() {
return instinct(facts,'f.g.h.$parent.$parent.$parent.a')
.then(function(d) {
assert.equal(d,123);
});
});
});
var clues = require("../clues"),
assert = require("assert");
assert = require("assert"),
Promise = require('bluebird');

@@ -9,23 +10,28 @@ describe('In recursive logic',function() {

},
medium : {
bucket : {
value : clues.prototype.Promise.delay(10,100)
},
},
medium : Object.create({
bucket : Object.create({
value : Promise.delay(10,100)
}),
}),
hard : ['simple.value',function(val) {
return {
a : {
b : clues({
b : {
c : {
d : clues({
d : {
id: val+100,
e : clues( {
e : {
f :12,
g : function(f) {
return 2*f;
},
h : function() {
return function(f) {
return f+2;
};
}
})
})
}
}
}
})
}
}

@@ -36,19 +42,16 @@ };

function noError(e) {
throw 'Should not result in an error: '+e.message;
}
var facts = Object.create(logic);
var c = clues(logic);
it('simple nesting works',function() {
return c.solve('simple.value')
return clues(facts,'simple.value')
.then(function(d) {
assert.equal(d,2);
},noError);
});
});
it('medium nesting works',function() {
return c.solve('medium.bucket.value').then(function(value) {
return clues(facts,'medium.bucket.value')
.then(function(value) {
assert.equal(value,10);
},noError);
});
});

@@ -58,10 +61,16 @@

it('works', function() {
return c.solve('hard.a.b.c.d.id').then(function(value) {
return clues(facts,'hard.a.b.c.d.id').then(function(value) {
assert.equal(value,102);
},noError);
});
});
it('works on returned functions',function() {
return clues(facts,'hard.a.b.c.d.e.h')
.then(function(h) {
assert.equal(h,14);
});
});
it('works when clue repeats twice',function() {
return c.solve(['hard.a.b.c.d.e','hard.a.b.c.d.e.f','hard.a.b.c.d.e.g',function(a,b,c) {
assert(a.facts,'hard.a.b.c.d.e should be a clues object');
return clues(facts,['hard.a.b.c.d.e','hard.a.b.c.d.e.f','hard.a.b.c.d.e.g',function(a,b,c) {
assert.equal(b,12);

@@ -72,12 +81,4 @@ assert.equal(c,24);

it('registers dot notion facts at the root factspace',function() {
assert.equal(c.facts['hard.a.b.c.d.id'].value(),102);
});
it ('registers facts inside the tree',function() {
assert.equal(c.facts['hard'].value().a.b.facts['c.d.id'].value(),102);
});
it('supports optional',function() {
return c.solve(['_hard.a.b.c.d.id',function(value) {
return clues(facts,['_hard.a.b.c.d.id',function(value) {
assert.equal(value,102);

@@ -88,5 +89,5 @@ }]);

it('can be resolved manually',function() {
return c.solve(function(hard) {
hard.a.b.solve(function(c) {
c.d.solve(function(id) {
return clues(facts,function(hard) {
return clues(hard.a.b,function(c) {
return clues(c.d,function(id) {
assert.equal(id,102);

@@ -99,3 +100,3 @@ });

it('bad path returns an error',function() {
return c.solve('hard.a.b.c.d.i.oo.oo')
return clues(facts,'hard.a.b.c.d.i.oo.oo')
.then(function() {

@@ -110,10 +111,18 @@ throw 'We should not arrive here';

it('optional bad path returns undefined',function() {
return c.solve(['_hard.a.b.e','simple.value',function(a,b) {
return clues(facts,['_hard.a.b.e','simple.value',function(a,b) {
assert.equal(a,undefined);
assert.equal(b,2);
assert.equal(c.facts['hard.a.b.e'].reason().message,'e not defined');
}]);
});
it('optional bad path returns undefined',function() {
return clues(facts,'hard.a.b.e')
.then(function() {
throw 'This function should return an error';
},function(e) {
assert.equal(e.message,'e not defined');
});
});
});
});

@@ -1,16 +0,30 @@

# express-clues
A client/server wrapper around `clues.js`, providing client access to clues solving to a browser or node client with local fact/logic space.
A simple express wrapper around a clues API. The module.exports is a function that returns an express route when given a custom API object as an argument. Results for each API call are returned as a JSON string. The requested function should be specified as fn in the query params.
### `reptiles-server`
The server is initialized by providing base logic and optionally some options `function(logic,options)`
Typical usage from a running express server would be as follows:
Available options are:
* `safe` : Disregards any input that would otherwise overwrite a logic function with same name
* `debug` Provide debug information with error messages
app.all('/api/:fn',require('express-clues')(api))
Two standard functions are added to the API:
The initialized server is a function that can be placed into `express` paths. If no arguments are given to the function, the API access is unrestricted, with requested variables (comma-delimited) in the `req.param.fn`. If a specific array of values is given to the function, it will solve those variables only. The user must provide all the inputs either as a JSON blob in the body and/or as querystring variables.
multi
Example:
```
express()
.use(bodyParser.json())
.post('/api/:fn',reptilesServer(api))
```
The multi function returns multiple solved facts in one function call. The list of required facts should be defined in the data parameter as a comma separated string. An error in any of the required facts will not prevent other facts to be reported.
### `reptiles-client`
The client can be loaded in a browser or required into node.js and inherits `clues.js` . A client is initialized by `reptile(logic,inputs,options)` and can subsequently be used to solve for facts / render widgets based on data. The inputs should be a json array of known local facts. The following options can be specified
* `url` The default base url for the reptiles-server, by default '/api/'
* `request` A list of options provided to the request object (if run on node)
* `delay` The client tries to aggregate multiple request for data into a single request.
* `applyFn` An optional function run every time a fact has been resolved
help
In addition to providing all standard `clues.js` functions, the client also provides the following (browser only):
* `render(element)` This function looks at the `data-reptile` attribute and solves for the logic function with the same name. The logic function can use the argument `element` to gain access to the dom element itself. If `data-reptile` is comma delimited the client will try to resolve the first value and then moving on to the next if the first resulted in an error, etc.
* `renderAll(element)` This function will call `render(element)` on all subnodes that have `data-reptile` defined.
Returns a list of the functions defined in the api

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