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

clues

Package Overview
Dependencies
Maintainers
2
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 3.5.0-rc-3 to 3.5.0

59

clues.js

@@ -10,19 +10,2 @@ (function(self) {

function checkCircular(d,value) {
var checked = [],circular;
return (function check(c) {
if (circular || !c || checked.indexOf(c) !== -1) return;
checked.push(c);
if (c == value) return (circular = true);
if (c._onCancelField && c._onCancelField._values )
c._onCancelField._values.map(function(d) {
if (d) check(d._cancellationParent);
});
if (c._followee && c._followee())
check(c._followee());
if (c._cancellationParent)
check(c._cancellationParent);
})(d) || circular;
}
var reArgs = /function.*?\(([^)]*?)\).*/;

@@ -41,3 +24,3 @@ function matchArgs(fn) {

function clues(logic,fn,$global,caller,fullref,last) {
function clues(logic,fn,$global,caller,fullref) {
var args,ref;

@@ -48,5 +31,5 @@

if (typeof logic === 'function' || (logic && typeof logic.then === 'function'))
return clues({},logic,$global,caller,fullref,last)
return clues({},logic,$global,caller,fullref)
.then(function(logic) {
return clues(logic,fn,$global,caller,fullref,last);
return clues(logic,fn,$global,caller,fullref);
});

@@ -60,3 +43,3 @@

var next = ref.slice(0,dot);
return clues(logic,next,$global,caller,fullref,last)
return clues(logic,next,$global,caller,fullref)
.then(function(d) {

@@ -66,3 +49,3 @@ logic = d;

fullref = (fullref ? fullref+'.' : '')+next;
return clues(logic,ref,$global,caller,fullref,last);
return clues(logic,ref,$global,caller,fullref);
})

@@ -82,3 +65,3 @@ .catch(function(e) {

else if ($global[ref] && caller && caller !== '__user__')
return clues($global,ref,$global,caller,fullref,last);
return clues($global,ref,$global,caller,fullref);
else if (logic && logic.$property && typeof logic.$property === 'function')

@@ -96,3 +79,3 @@ fn = logic[ref] = function() { return logic.$property.call(logic,ref); };

if (fn.length === 1) fn = fn[0];
return clues(obj,fn,$global,caller,fullref,last);
return clues(obj,fn,$global,caller,fullref);
}

@@ -109,11 +92,7 @@ args = fn.slice(0,fn.length-1);

// If fn name is private or promise private is true, reject when called directly
if (fn && (!caller || caller == '__user__') && ((typeof(fn) === 'function' && fn.name == 'private') || (fn.then && fn.private)))
if (fn && (!caller || caller == '__user__') && ((typeof(fn) === 'function' && (fn.name == '$private' || fn.name == 'private')) || (fn.then && fn.private)))
return clues.Promise.rejected({ref : ref, message: ref+' not defined', fullref:fullref,caller: caller, notDefined:true});
// If the logic reference is not a function, we simply return the value
if (typeof fn !== 'function' || (ref && ref[0] === '$')) {
if (fn && !clues.ignoreCircular && fn.isPending && fn.isPending() && checkCircular(fn,last))
return clues.Promise.rejected({ref: ref, message: 'circular', fullref:fullref, caller: caller});
return clues.Promise.resolve(fn);
}
if (typeof fn !== 'function' || (ref && ref[0] === '$')) return clues.Promise.resolve(fn);

@@ -124,3 +103,4 @@ // Shortcuts to define empty objects with $property or $external

var inputs = clues.Promise.map(args || matchArgs(fn),function(arg) {
args = (args || matchArgs(fn))
.map(function(arg) {
var optional,showError,res;

@@ -139,6 +119,3 @@ if (optional = (arg[0] === '_')) arg = arg.slice(1);

return res || clues.Promise.resolve()
.then(function() {
return clues(logic,arg,$global,ref || 'fn',fullref,value);
})
return res || clues(logic,arg,$global,ref || 'fn',fullref)
.then(null,function(e) {

@@ -150,3 +127,4 @@ if (optional) return (showError) ? e : undefined;

var wait = new Date(),
var inputs = clues.Promise.all(args),
wait = new Date(),
duration;

@@ -162,4 +140,5 @@

$global.$duration(fullref,[(new Date()-duration),(new Date())-wait]);
return (typeof d == 'string' || typeof d == 'number') ? d : clues(logic,d,$global,caller,fullref,last);
},function(e) {
return (typeof d == 'string' || typeof d == 'number') ? d : clues(logic,d,$global,caller,fullref);
})
.catch(function(e) {
if (typeof e !== 'object')

@@ -171,6 +150,8 @@ e = { message : e};

e.caller = e.caller || caller || '';
if (fn && fn.name == '$noThrow')
return e;
throw e;
});
if (fn.name == 'private')
if (fn.name == 'private' || fn.name == '$private')
value.private = true;

@@ -177,0 +158,0 @@

{
"name": "clues",
"version": "3.5.0-rc-3",
"version": "3.5.0",
"description": "Lightweight logic tree solver using promises.",

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

"dependencies": {
"bluebird": "~3.1.1"
"bluebird": "~3.4.0"
},
"devDependencies": {
"mocha": "~2.3.4"
"mocha": "~2.5.3"
},

@@ -23,0 +23,0 @@ "license": "MIT",

@@ -87,3 +87,4 @@ [![NPM Version][npm-image]][npm-url]

* Any [array whose last element is a function](#using-special-arrays-to-define-functions) will be evaluated as a function... Angular style
* Any function explicitly named [`private`](#making-anonymous-functions-private) (regardless of the property name) will not be accessible directly
* Any function explicitly named [`$private`](#making-anonymous-functions-private) (regardless of the property name) will not be accessible directly
* Any function explicitly named `$noThrow` will return any error as an object not as a rejection (similar to `__` prefix in argument names)

@@ -506,7 +507,7 @@ That's pretty much it.

#### making anonymous functions private
An even easier way to declare functions as private is simply [naming](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) them `private`. Any functions named `private` will not be accessible directly, only indirectly through a different function, as an input argument. Specifically the `caller` has to be a defined value and not equal to `__user__`). Here is a quick example:
An even easier way to declare functions as private is simply [naming](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) them `$private` (or `private`). Any functions named `$private` will not be accessible directly, only indirectly through a different function, as an input argument. Specifically the `caller` has to be a defined value and not equal to `__user__`). Here is a quick example:
```js
var facts = {
a : function private() { return 2; },
a : function $private() { return 2; },
b : function(a) { return a+2; }

@@ -513,0 +514,0 @@ };

@@ -73,4 +73,29 @@ var clues = require('../clues'),

});
describe('function named $noThrow',function() {
it('should return the error obj',function() {
return clues(facts,function $noThrow(DEP) {
return DEP;
})
.then(function(e) {
assert.equal(e.ref,'ERR');
assert.equal(e.message,'Could not process');
},function() {
throw 'Should return the error object';
});
});
it('should return the error obj for subsequent fn',function() {
return clues(facts,function $noThrow() {
return ['DEP',Object];
})
.then(function(e) {
assert.equal(e.ref,'ERR');
assert.equal(e.message,'Could not process');
},function() {
throw 'Should return the error object';
});
});
});
});
});

@@ -10,3 +10,3 @@ var clues = require('../clues'),

M1 : function() { return Promise.delay(100,10); },
M2 : function private() { return Promise.delay(20,300); },
M2 : function $private() { return Promise.delay(20,300); },
M3 : ['M1','M2',function private(M1,M2) { return M1+M2; }],

@@ -13,0 +13,0 @@ M4 : function() { return Promise.delay(150,70); },

@@ -12,3 +12,3 @@ var clues = require('../clues'),

if (!value || value instanceof Date) return value;
if (typeof value === 'function' && value.name === 'private') return undefined;
if (typeof value === 'function' && (value.name === 'private' || value.name === '$private')) return undefined;
if (typeof value === 'function' || value.length && typeof value[value.length-1] === 'function')

@@ -51,7 +51,20 @@ return debug ? '[Function]' : undefined;

err.status = 500;
if (typeof options.logger === 'function')
options.logger(err);
if (!options.debug) {
err.message = 'Internal Error';
delete err.stack;
err = {
error : true,
message : 'Internal Error',
status : 500
};
}
}
if (options.single)
return {
error : true,
message : err.message,
status : err.status,
xflash : err.xflash
};
return err;

@@ -127,3 +140,4 @@ }

if (options.single) {
_res.send(d.error ? (d.status||400) : 200, stringify(d,pretty,options.debug)+'\n');
_res.status(d.error ? (d.status||400) : 200)
.end(stringify(d,pretty,options.debug));
_res.write = noop;

@@ -130,0 +144,0 @@ _res.end = noop;

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