Comparing version 2.0.3 to 2.0.4
@@ -30,3 +30,3 @@ # Graph API | ||
Null field values and empty collections are omitted. | ||
Null field values and empty collections are included. | ||
@@ -33,0 +33,0 @@ Returns null if no if the object does not exist. |
@@ -153,2 +153,4 @@ # Schemas | ||
`Scalar`: Any non-null JavaScript object. | ||
Standard JSON data is supported: | ||
@@ -155,0 +157,0 @@ |
{ | ||
"name": "jseg", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "JavaScript Entity Graph: A super simple, in-memory, JS graph database.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -295,3 +295,5 @@ let {getOwn, eachPair, objEmpty, StringMap} = require('./util'); | ||
let {depth, json} = Object.assign({depth: 1}, options); | ||
depth = depth || -1; | ||
let marshal = (json ? | ||
@@ -312,10 +314,17 @@ (f, x) => f(x) : | ||
let getField = (fieldName) => { | ||
let value = obj[fieldName] | ||
let value = getOwn(obj, fieldName); | ||
let {type, kind, cardinality, compare} = obj.type._field(fieldName); | ||
if (kind === 'scalar') { | ||
return marshal(type._serialize, value); | ||
} | ||
let undef = (typeof value === 'undefined'); | ||
if (cardinality === 'one') { | ||
if (undef) { | ||
return null; | ||
} | ||
if (kind === 'scalar') { | ||
return marshal(type._serialize, value); | ||
} | ||
return rec(value) | ||
} | ||
if (undef) { | ||
return []; | ||
} | ||
let lids = Object.keys(value); | ||
@@ -326,3 +335,3 @@ return lids.map(lid => rec(value[lid])).sort(compare); | ||
let entity = {}; | ||
for (let fieldName in obj) { | ||
for (let fieldName in obj.type._allFields) { | ||
entity[fieldName] = getField(fieldName); | ||
@@ -329,0 +338,0 @@ } |
@@ -141,2 +141,6 @@ let {getOwn} = require('./util'); | ||
this.scalar('Scalar', { | ||
validate: (x) => x, | ||
}); | ||
this.scalar('Key', { | ||
@@ -217,10 +221,8 @@ validate: (x) => { | ||
let Entity = this._types.Entity; | ||
['lid', 'gid'].forEach(attrName => { | ||
Entity._defField({ | ||
kind: 'scalar', | ||
cardinality: 'one', | ||
from: Entity, | ||
name: attrName, | ||
type: this._types.Key, | ||
}); | ||
Entity._defField({ | ||
kind: 'scalar', | ||
cardinality: 'one', | ||
from: Entity, | ||
name: 'lid', | ||
type: this._types.Key, | ||
}); | ||
@@ -227,0 +229,0 @@ Entity._defField({ |
@@ -54,2 +54,3 @@ let assert = require('assert'); | ||
lid: 'root', | ||
parent: null, | ||
children: [ | ||
@@ -62,2 +63,3 @@ { | ||
}, | ||
children: [], | ||
}, | ||
@@ -87,2 +89,4 @@ ], | ||
lid: 'a', | ||
prev: null, | ||
next: null, | ||
}); | ||
@@ -89,0 +93,0 @@ tg.check('b', null); |
@@ -43,2 +43,3 @@ let assert = require('assert'); | ||
lid: 'a', | ||
prev: null, | ||
next: { | ||
@@ -55,3 +56,4 @@ type: t.Node, | ||
lid: 'c', | ||
} | ||
}, | ||
next: null, | ||
}, | ||
@@ -71,2 +73,3 @@ prev: { | ||
lid: 'a', | ||
prev: null, | ||
next: { | ||
@@ -81,2 +84,3 @@ type: t.Node, | ||
lid: 'd', | ||
next: null, | ||
prev: { | ||
@@ -99,2 +103,3 @@ lid: 'c', | ||
lid: 'a', | ||
prev: null, | ||
next: { | ||
@@ -108,2 +113,3 @@ lid: 'b', | ||
lid: 'a', | ||
prev: null, | ||
next: { | ||
@@ -124,2 +130,3 @@ type: t.Node, | ||
lid: 'a', | ||
prev: null, | ||
next: { | ||
@@ -126,0 +133,0 @@ type: t.Node, |
@@ -49,2 +49,3 @@ let assert = require('assert'); | ||
key: 'one', | ||
constructor: null, | ||
}); | ||
@@ -56,2 +57,3 @@ | ||
key: 'two', | ||
constructor: null, | ||
}); | ||
@@ -68,2 +70,3 @@ | ||
key: 'two', | ||
constructor: null, | ||
}); | ||
@@ -79,2 +82,3 @@ | ||
key: 'four', | ||
constructor: null, | ||
}); | ||
@@ -84,2 +88,2 @@ | ||
//XXX check destroy | ||
//XXX check lookup destroys entries |
@@ -41,2 +41,3 @@ let assert = require('assert'); | ||
lid: 'a', | ||
nToM: [], | ||
mToN: [ | ||
@@ -51,2 +52,3 @@ { | ||
], | ||
mToN: [], | ||
}, | ||
@@ -61,2 +63,3 @@ { | ||
], | ||
mToN: [], | ||
}, | ||
@@ -70,2 +73,3 @@ ], | ||
lid: 'a', | ||
nToM: [], | ||
mToN: [ | ||
@@ -80,2 +84,3 @@ { | ||
], | ||
mToN: [], | ||
}, | ||
@@ -89,2 +94,4 @@ ], | ||
lid: 'a', | ||
nToM: [], | ||
mToN: [], | ||
}); | ||
@@ -113,2 +120,3 @@ | ||
lid: 'a', | ||
nToM: [], | ||
mToN: [ | ||
@@ -123,2 +131,3 @@ { | ||
lid: 'b', | ||
nToM: [], | ||
mToN: [ | ||
@@ -131,2 +140,3 @@ { | ||
], | ||
mToN: [], | ||
}); |
@@ -29,2 +29,4 @@ let assert = require('assert'); | ||
lid: 'loner', | ||
parent: null, | ||
children: [], | ||
}); | ||
@@ -54,2 +56,3 @@ | ||
lid: 'root', | ||
parent: null, | ||
children: [ | ||
@@ -62,2 +65,3 @@ { | ||
}, | ||
children: [], | ||
}, | ||
@@ -70,2 +74,3 @@ { | ||
}, | ||
children: [], | ||
}, | ||
@@ -78,2 +83,3 @@ { | ||
}, | ||
children: [], | ||
}, | ||
@@ -87,2 +93,3 @@ ], | ||
lid: 'root', | ||
parent: null, | ||
children: [ | ||
@@ -95,2 +102,3 @@ { | ||
}, | ||
children: [], | ||
}, | ||
@@ -103,2 +111,3 @@ { | ||
}, | ||
children: [], | ||
}, | ||
@@ -112,2 +121,3 @@ ], | ||
lid: 'root', | ||
parent: null, | ||
children: [ | ||
@@ -120,2 +130,3 @@ { | ||
}, | ||
children: [], | ||
}, | ||
@@ -133,2 +144,4 @@ ], | ||
lid: 'root', | ||
parent: null, | ||
children: [], | ||
}); | ||
@@ -149,2 +162,3 @@ | ||
lid: 'root', | ||
parent: null, | ||
children: [ | ||
@@ -154,2 +168,3 @@ {lid: 'x'}, | ||
}, | ||
children: [], | ||
}); |
@@ -57,3 +57,7 @@ let assert = require('assert'); | ||
tg.check('a1', null); | ||
tg.check('b1', {lid: 'b1', type: t.B}); | ||
tg.check('b1', { | ||
lid: 'b1', | ||
type: t.B, | ||
a: null, | ||
}); | ||
@@ -89,3 +93,3 @@ tg.g.destroy('b1'); | ||
lid: 'a2', | ||
b: null, | ||
}); | ||
@@ -54,2 +54,4 @@ let assert = require('assert'); | ||
lid: 'root', | ||
index: null, | ||
parent: null, | ||
children: [ | ||
@@ -61,2 +63,3 @@ { | ||
parent: {lid: 'root'}, | ||
children: [], | ||
}, | ||
@@ -68,2 +71,3 @@ { | ||
parent: {lid: 'root'}, | ||
children: [], | ||
}, | ||
@@ -75,4 +79,5 @@ { | ||
parent: {lid: 'root'}, | ||
children: [], | ||
}, | ||
], | ||
}); |
@@ -13,2 +13,3 @@ let assert = require('assert'); | ||
Thing: { | ||
any: t.Scalar, | ||
text: t.Text, | ||
@@ -41,4 +42,13 @@ deleteme: t.Text, | ||
deleteme: 'ok', | ||
any: null, | ||
bool: null, | ||
}); | ||
class Foo { | ||
constructor(bar) { | ||
this.bar = bar; | ||
} | ||
} | ||
let foo = new Foo(); | ||
tg.g.put({ | ||
@@ -48,2 +58,3 @@ lid: 'x', | ||
bool: false, | ||
any: foo, | ||
}); | ||
@@ -55,3 +66,5 @@ | ||
text: 'y', | ||
deleteme: null, | ||
bool: false, | ||
any: foo, | ||
}); |
@@ -44,3 +44,3 @@ let {inspect} = require('util'); | ||
if (x.length !== y.length) { | ||
fail('length ' + x.length + ' !== ' + y.length); | ||
fail('length ' + x.length + ' but expected ' + y.length); | ||
} | ||
@@ -47,0 +47,0 @@ for (let i = 0; i < x.length; i++) { |
@@ -63,2 +63,3 @@ let assert = require('assert'); | ||
rounded: 6, | ||
even: null, | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50770
1787