Socket
Socket
Sign inDemoInstall

giraffe

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

giraffe - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

14

CHANGELOG.md
Changelog
----
### Tue Jan 17 15:26:43 2017 -0600
- Commit: `c53b6ef61ffdd247f4d4ae292257311927a3ff06`
- Author: Tom Bremer <tom@tbremer.com>
- Version: 2.1.1
#### Changes
- Fixes bug introduced when importing `Node` or `Edge` types.
### Tue Jan 17 12:42:20 2017 -0600
- Commit: `b1a28b229c6801a8a59b45425d48b83ce3cf5279`
- Author: Tom Bremer ([tom@tbremer.com](tom@tbremer.com))
- Version 2.1.0
- Version: 2.1.0

@@ -18,3 +26,3 @@ #### Changes

- Author: Tom Bremer ([tom@tbremer.com](tom@tbremer.com))
- Version 2.0.1
- Version: 2.0.1

@@ -28,3 +36,3 @@ #### Changes

- Author: Tom Bremer ([tom@tbremer.com](tom@tbremer.com))
- Version 2.0.0
- Version: 2.0.0

@@ -31,0 +39,0 @@ #### Changes

/**
* Module: giraffe
* Version: 2.1.0
* Version: 2.1.1
* By: Tom Bremer <tom@tbremer.com>

@@ -28,2 +28,4 @@ * URL: https://github.com/tbremer/Giraffe#readme

var validConstructors = [String, Number];
function Node(_ref) {

@@ -42,3 +44,3 @@ var id = _ref.id,

var shape = {
identity: Number,
identity: validConstructors,
properties: Object,

@@ -49,6 +51,6 @@ labels: Array,

var validConstructors = [String, Number];
var validConstructors$1 = [String, Number];
function testConstructor(type) {
return validConstructors.indexOf(type.constructor) > -1;
return validConstructors$1.indexOf(type.constructor) > -1;
}

@@ -73,7 +75,7 @@

var shape$1 = {
identity: Number,
identity: validConstructors$1,
properties: Object,
label: String,
from: Number,
through: Number
from: validConstructors$1,
through: validConstructors$1
};

@@ -129,5 +131,5 @@

for (var key in shape) {
if (!(key in object) || object[key].constructor !== shape[key]) {
throw new Error('Incorrect shape for ' + JSON.stringify(object));
}
var _constructor = shape[key].constructor === Array ? shape[key] : [shape[key]];
if (!(key in object) || _constructor.indexOf(object[key].constructor) === -1) throw new Error('Incorrect shape for ' + JSON.stringify(object));
}

@@ -134,0 +136,0 @@ }

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

!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.Giraffe=r()}(this,function(){"use strict";function e(e){var r=e.id,t=e.label,i=e.data;if(!r&&0!==r)throw new Error("All Node's require an id");this.identity=r,this.properties=u({},i),this.labels=t?t.constructor===Array?t:[t]:[],this.edges=[]}function r(e){return f.indexOf(e.constructor)>-1}function t(e){var t=e.from,i=e.through,s=e.id,n=e.data,a=e.label;if(!a||!r(a))throw new Error("All Edges need a single Label");this.identity=s,this.from=t.identity,this.through=i.identity,this.label=a,this.properties=u({},n)}function i(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var r=16*Math.random()|0,t="x"===e?r:3&r|8;return t.toString(16)})}function s(e,r){var t=e.properties;for(var i in r)if("edges"!==i){if(!(i in t))return!1;if(t[i]!==r[i])return!1}return!0}function n(e,r){return Boolean(r&&e in r)}function a(e,r){if(!e||e.constructor!==Array)throw new Error("Objects needs to be an array");for(var t in e){var i=e[t];for(var s in r)if(!(s in i)||i[s].constructor!==r[s])throw new Error("Incorrect shape for "+JSON.stringify(i))}return!0}function o(e){var r=[];for(var t in e){var i=e[t],s=u({},l(i.from,this.nodes)),n=u({},l(i.through,this.nodes));r.push(u({},i,{from:s,through:n}))}return r}function l(e,r){for(var t in r){var i=r[t];if("identity"in i&&i.identity===e)return i}}function d(e,r){for(var t in r){var i=r[t];if("identity"in i&&i.identity===e)return t}return-1}function h(e,r){e&&e.constructor===Function&&!r&&(r=e,e={}),Object.defineProperty(this,"_ids",{value:[]}),Object.defineProperty(this,"_generateId",{value:function(){var e=i();return this._ids.indexOf(e)!==-1?this._generateId():(this._ids.push(e),e)}}),this.nodes=[],this.edges=[],this.labels={edges:{},nodes:{}},this.callback=r,n("nodes",e)&&a(e.nodes,c)&&(this.nodes=e.nodes),n("edges",e)&&a(e.edges,g)&&(this.edges=e.edges);for(var t in this.nodes){var s=this.nodes[t];if(this._ids.push(s.identity),s.labels.length)for(var o in s.labels){var l=s.labels[o];l in this.labels.nodes||(this.labels.nodes[l]=[]),this.labels.nodes[l].push(s.identity)}}for(var d in this.edges){var h=this.edges[d];if(this._ids.push(h.identity),!h.label)throw new Error("All Edges need a label");var u=h.label;u in this.labels.edges||(this.labels.edges[u]=[]),this.labels.edges[u].push(h.identity)}}var u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},c={identity:Number,properties:Object,labels:Array,edges:Array},f=[String,Number],g={identity:Number,properties:Object,label:String,from:Number,through:Number};return h.prototype.create=function(r,t){r.constructor===Object&&(t=r,r=null);var i=this._generateId(),s=new e({id:i,label:r,data:t});if(this.nodes.push(s),r){var n=this.labels.nodes;r in n||(n[r]=[]),n[r].push(s.identity)}return this.callback&&this.callback("create",s),s},h.prototype.update=function e(e,r,t){e.constructor!==Array&&(e=[e]),r.constructor===Object&&(t=r,r=null),null!==r&&r.constructor!==Array&&(r=[r]),t||(t={});for(var i in e){var s=e[i],n="label"in s;if(n&&r)throw new TypeError("Edge Labels cannot be changed.");r&&(s.labels=s.labels.concat(r)),s.properties=u({},s.properties,t)}return this.callback&&this.callback("update",e),e},h.prototype.remove=function(e){e.constructor!==Array&&(e=[e]);var r=[];for(var t in e){var i=e[t],s=i.identity;r.push(i);for(var n in i.edges){var a=i.edges[n],o=l(a,this.edges),h=o.label,u=o.identity;if(h in this.labels.edges){var c=this.labels.edges[h].indexOf(u);c!==-1&&this.labels.edges[h].splice(c,1)}this.edges.splice(d(a,this.edges),1)}for(var f in i.labels){var h=i.labels[f];if(h in this.labels.nodes){var g=this.labels.nodes[h].indexOf(s);g!==-1&&this.labels.nodes[h].splice(g,1)}}for(var b in this.edges){var v=this.edges[b];if(v&&v.through===s){var p=this.nodes[v.from];if(p){var y=p.edges.indexOf(v.identity);y!==-1&&(p.edges.splice(y,1),this.edges[b]=void 0)}}}this.nodes.splice(d(s,this.nodes),1)}this.callback&&this.callback("remove",r)},h.prototype.edge=function(e,r,i,s){e.constructor!==Array&&(e=[e]),r.constructor!==Array&&(r=[r]);var n=[];for(var a in e){var l=e[a];for(var d in r){var h=r[d],u=this._generateId(),c=new t({id:u,label:i,data:s,from:l,through:h}),f=this.labels.edges;i in f||(f[i]=[]),f[i].push(c.identity),l.edges.push(u),this.edges.push(c),n.push(c)}}return this.callback&&this.callback("edge",o.call(this,n)),n},h.prototype.query=function(e,r){e||r||(e=r=null),e&&e.constructor===Object&&(r=e,e=null);var t=[];for(var i in this.nodes){var n=this.nodes[i];if(n&&(!e||n.labels.indexOf(e)!==-1)){var a=s(n,r),o=r&&"edges"in r;if(o){var d=r.edges.length,h=0;for(var c in r.edges){var f=r.edges[c],g=[];if(f in this.labels.edges){for(var b in this.labels.edges[f]){var v=this.labels.edges[f][b],p=l(v,this.edges);p&&g.push(p.from)}g.indexOf(n.identity)>-1&&h++}}if(h<d)continue}if(!r||a){var y=u({},n);for(var x in y.edges){var m=y.edges[x],O=u({},l(m,this.edges)),w=l(O.through,this.nodes);O.through=u({},w),O.from=y,y.edges[x]=O}t.push(y)}}}return this.callback&&this.callback("query",t),t},h});
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.Giraffe=r()}(this,function(){"use strict";function e(e){var r=e.id,t=e.label,i=e.data;if(!r&&0!==r)throw new Error("All Node's require an id");this.identity=r,this.properties=c({},i),this.labels=t?t.constructor===Array?t:[t]:[],this.edges=[]}function r(e){return g.indexOf(e.constructor)>-1}function t(e){var t=e.from,i=e.through,s=e.id,n=e.data,a=e.label;if(!a||!r(a))throw new Error("All Edges need a single Label");this.identity=s,this.from=t.identity,this.through=i.identity,this.label=a,this.properties=c({},n)}function i(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var r=16*Math.random()|0,t="x"===e?r:3&r|8;return t.toString(16)})}function s(e,r){var t=e.properties;for(var i in r)if("edges"!==i){if(!(i in t))return!1;if(t[i]!==r[i])return!1}return!0}function n(e,r){return Boolean(r&&e in r)}function a(e,r){if(!e||e.constructor!==Array)throw new Error("Objects needs to be an array");for(var t in e){var i=e[t];for(var s in r){var n=r[s].constructor===Array?r[s]:[r[s]];if(!(s in i)||n.indexOf(i[s].constructor)===-1)throw new Error("Incorrect shape for "+JSON.stringify(i))}}return!0}function o(e){var r=[];for(var t in e){var i=e[t],s=c({},l(i.from,this.nodes)),n=c({},l(i.through,this.nodes));r.push(c({},i,{from:s,through:n}))}return r}function l(e,r){for(var t in r){var i=r[t];if("identity"in i&&i.identity===e)return i}}function d(e,r){for(var t in r){var i=r[t];if("identity"in i&&i.identity===e)return t}return-1}function h(e,r){e&&e.constructor===Function&&!r&&(r=e,e={}),Object.defineProperty(this,"_ids",{value:[]}),Object.defineProperty(this,"_generateId",{value:function(){var e=i();return this._ids.indexOf(e)!==-1?this._generateId():(this._ids.push(e),e)}}),this.nodes=[],this.edges=[],this.labels={edges:{},nodes:{}},this.callback=r,n("nodes",e)&&a(e.nodes,f)&&(this.nodes=e.nodes),n("edges",e)&&a(e.edges,b)&&(this.edges=e.edges);for(var t in this.nodes){var s=this.nodes[t];if(this._ids.push(s.identity),s.labels.length)for(var o in s.labels){var l=s.labels[o];l in this.labels.nodes||(this.labels.nodes[l]=[]),this.labels.nodes[l].push(s.identity)}}for(var d in this.edges){var h=this.edges[d];if(this._ids.push(h.identity),!h.label)throw new Error("All Edges need a label");var c=h.label;c in this.labels.edges||(this.labels.edges[c]=[]),this.labels.edges[c].push(h.identity)}}var c=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},u=[String,Number],f={identity:u,properties:Object,labels:Array,edges:Array},g=[String,Number],b={identity:g,properties:Object,label:String,from:g,through:g};return h.prototype.create=function(r,t){r.constructor===Object&&(t=r,r=null);var i=this._generateId(),s=new e({id:i,label:r,data:t});if(this.nodes.push(s),r){var n=this.labels.nodes;r in n||(n[r]=[]),n[r].push(s.identity)}return this.callback&&this.callback("create",s),s},h.prototype.update=function e(e,r,t){e.constructor!==Array&&(e=[e]),r.constructor===Object&&(t=r,r=null),null!==r&&r.constructor!==Array&&(r=[r]),t||(t={});for(var i in e){var s=e[i],n="label"in s;if(n&&r)throw new TypeError("Edge Labels cannot be changed.");r&&(s.labels=s.labels.concat(r)),s.properties=c({},s.properties,t)}return this.callback&&this.callback("update",e),e},h.prototype.remove=function(e){e.constructor!==Array&&(e=[e]);var r=[];for(var t in e){var i=e[t],s=i.identity;r.push(i);for(var n in i.edges){var a=i.edges[n],o=l(a,this.edges),h=o.label,c=o.identity;if(h in this.labels.edges){var u=this.labels.edges[h].indexOf(c);u!==-1&&this.labels.edges[h].splice(u,1)}this.edges.splice(d(a,this.edges),1)}for(var f in i.labels){var h=i.labels[f];if(h in this.labels.nodes){var g=this.labels.nodes[h].indexOf(s);g!==-1&&this.labels.nodes[h].splice(g,1)}}for(var b in this.edges){var v=this.edges[b];if(v&&v.through===s){var p=this.nodes[v.from];if(p){var y=p.edges.indexOf(v.identity);y!==-1&&(p.edges.splice(y,1),this.edges[b]=void 0)}}}this.nodes.splice(d(s,this.nodes),1)}this.callback&&this.callback("remove",r)},h.prototype.edge=function(e,r,i,s){e.constructor!==Array&&(e=[e]),r.constructor!==Array&&(r=[r]);var n=[];for(var a in e){var l=e[a];for(var d in r){var h=r[d],c=this._generateId(),u=new t({id:c,label:i,data:s,from:l,through:h}),f=this.labels.edges;i in f||(f[i]=[]),f[i].push(u.identity),l.edges.push(c),this.edges.push(u),n.push(u)}}return this.callback&&this.callback("edge",o.call(this,n)),n},h.prototype.query=function(e,r){e||r||(e=r=null),e&&e.constructor===Object&&(r=e,e=null);var t=[];for(var i in this.nodes){var n=this.nodes[i];if(n&&(!e||n.labels.indexOf(e)!==-1)){var a=s(n,r),o=r&&"edges"in r;if(o){var d=r.edges.length,h=0;for(var u in r.edges){var f=r.edges[u],g=[];if(f in this.labels.edges){for(var b in this.labels.edges[f]){var v=this.labels.edges[f][b],p=l(v,this.edges);p&&g.push(p.from)}g.indexOf(n.identity)>-1&&h++}}if(h<d)continue}if(!r||a){var y=c({},n);for(var x in y.edges){var O=y.edges[x],m=c({},l(O,this.edges)),w=l(m.through,this.nodes);m.through=c({},w),m.from=y,y.edges[x]=m}t.push(y)}}}return this.callback&&this.callback("query",t),t},h});
{
"name": "giraffe",
"version": "2.1.0",
"version": "2.1.1",
"description": "Lightweight Graph DB implementation",

@@ -5,0 +5,0 @@ "main": "dist/bundle.js",

@@ -18,7 +18,7 @@ const validConstructors = [ String, Number ];

export const shape = {
identity: Number,
identity: validConstructors,
properties: Object,
label: String,
from: Number,
through: Number
from: validConstructors,
through: validConstructors
};

@@ -39,5 +39,5 @@ export function checkProperties(node, properties) {

for (const key in shape) {
if (!(key in object) || object[key].constructor !== shape[key]) {
throw new Error(`Incorrect shape for ${JSON.stringify(object)}`);
}
const _constructor = shape[key].constructor === Array ? shape[key] : [ shape[key] ];
if (!(key in object) || _constructor.indexOf(object[key].constructor) === -1) throw new Error(`Incorrect shape for ${JSON.stringify(object)}`);
}

@@ -44,0 +44,0 @@ }

@@ -0,1 +1,3 @@

const validConstructors = [ String, Number ];
export default function Node({ id, label, data }) {

@@ -10,3 +12,3 @@ if (!id && id !== 0) throw new Error(`All Node's require an id`);

export const shape = {
identity: Number,
identity: validConstructors,
properties: Object,

@@ -13,0 +15,0 @@ labels: Array,

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