Comparing version 0.9.0 to 0.10.0
@@ -20,4 +20,2 @@ 'use strict'; | ||
var _validUrl = require('valid-url'); | ||
var _util = require('./util'); | ||
@@ -80,2 +78,3 @@ | ||
listed: options.listed, | ||
namedNode: options.namedNode, | ||
sourceConfig: sourceConfig | ||
@@ -124,2 +123,4 @@ }); | ||
* (public) or unlisted (private). | ||
* @param {Boolean=} options.namedNode - Whether or not this field is a | ||
* NamedNode. | ||
* @param {Object} options.sourceConfig - A configuration object containing | ||
@@ -142,2 +143,3 @@ * the default listed and unlisted source graphs, and a mapping of all source | ||
var value = _ref.value; | ||
var namedNode = _ref.namedNode; | ||
var listed = _ref.listed; | ||
@@ -159,3 +161,3 @@ var originalObject = _ref.originalObject; | ||
this.originalObject = originalObject; | ||
this.value = originalObject.value; | ||
this.value = rdfToJs(originalObject); | ||
} | ||
@@ -169,2 +171,5 @@ if ((0, _util.isDefined)(originalSource)) { | ||
} | ||
if ((0, _util.isDefined)(namedNode)) { | ||
this.namedNode = namedNode || false; | ||
} | ||
if ((0, _util.isDefined)(listed)) { | ||
@@ -212,3 +217,3 @@ this.listed = listed; | ||
} | ||
return rdf.namedNode(sourceURI); | ||
return rdf.NamedNode.fromValue(sourceURI); | ||
} | ||
@@ -231,3 +236,4 @@ | ||
object = (0, _clone2.default)(this.originalObject); | ||
object.value = this.value; | ||
// Convert the native JS value back to the corresponding RDF string value | ||
object.value = this.originalObject.constructor.fromValue(this.value).value; | ||
if ((0, _util.isDefined)(object.uri)) { | ||
@@ -237,3 +243,3 @@ object.uri = this.value; | ||
} else { | ||
object = (0, _validUrl.isUri)(this.value) ? rdf.namedNode(this.value) : rdf.Literal.fromValue(this.value); | ||
object = this.namedNode ? rdf.NamedNode.fromValue(this.value) : rdf.Literal.fromValue(this.value); | ||
} | ||
@@ -293,2 +299,4 @@ | ||
var listed = _ref2$listed === undefined ? null : _ref2$listed; | ||
var _ref2$namedNode = _ref2.namedNode; | ||
var namedNode = _ref2$namedNode === undefined ? false : _ref2$namedNode; | ||
@@ -300,2 +308,3 @@ return new Field({ | ||
value: value !== null ? value : this.value, | ||
namedNode: namedNode, | ||
listed: listed !== null ? listed : this.listed, | ||
@@ -338,2 +347,55 @@ sourceConfig: this._sourceConfig | ||
return Field; | ||
}(); | ||
}(); | ||
/** | ||
* Extracts the value of an rdf node into the native JS representation of that | ||
* node's type/value. For example, it will extract booleans from a node with a | ||
* datatype of xsd:boolean and a value of '0' or '1'. | ||
* | ||
* @param {Object} node - The rdf node object. | ||
* @returns The value of that node. | ||
*/ | ||
function rdfToJs(node) { | ||
var value = void 0; | ||
var rdfVal = node.value; | ||
var datatype = node.datatype; | ||
var throwError = function throwError() { | ||
throw new Error('Cannot parse rdf type/value to JS value. Given value [' + rdfVal + '] of type [' + datatype + '].'); | ||
}; | ||
if (datatype) { | ||
var XMLSchema = 'http://www.w3.org/2001/XMLSchema#'; | ||
switch (datatype.value) { | ||
case XMLSchema + 'boolean': | ||
if (rdfVal === '1') { | ||
value = true; | ||
} else if (rdfVal === '0') { | ||
value = false; | ||
} else { | ||
throwError(); | ||
} | ||
break; | ||
case XMLSchema + 'dateTime': | ||
// Format of date string can be found at: http://books.xmlschemata.org/relaxng/ch19-77049.html | ||
value = new Date(rdfVal); | ||
break; | ||
case XMLSchema + 'decimal': | ||
case XMLSchema + 'double': | ||
value = Number.parseFloat(rdfVal); | ||
break; | ||
case XMLSchema + 'integer': | ||
value = Number.parseInt(rdfVal); | ||
break; | ||
case 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString': | ||
case XMLSchema + 'string': | ||
default: | ||
value = rdfVal; | ||
break; | ||
} | ||
} else { | ||
// Assume string if there's no provided datatype | ||
value = rdfVal; | ||
} | ||
return value; | ||
} |
@@ -70,3 +70,3 @@ 'use strict'; | ||
var fieldCreators = {}; | ||
var subject = rdf.namedNode(subjectStr); | ||
var subject = rdf.NamedNode.fromValue(subjectStr); | ||
var fields = _immutable2.default.Map(Object.keys(fieldMap).reduce(function (prevFields, fieldName) { | ||
@@ -239,2 +239,4 @@ var fieldPredicate = fieldMap[fieldName]; | ||
* @param {Boolean} newFieldOptions.listed - the new field's listed value. | ||
* @param {Boolean} newFieldOptions.namedNode - whether the new field is a | ||
* named node or not. | ||
* @returns {Model} - the updated model. | ||
@@ -259,2 +261,6 @@ */ | ||
* @param fieldValue - the new field value. | ||
* @param {Object} FieldOptions - arguments to create the new field. | ||
* @param {Boolean} FieldOptions.listed - the new field's listed value. | ||
* @param {Boolean} FieldOptions.namedNode - whether the new field is a named | ||
* node or not. | ||
* @returns {Model} - the updated model. | ||
@@ -261,0 +267,0 @@ */ |
{ | ||
"name": "modelld", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "A JavaScript API for selecting and manipulating linked data subgraphs", | ||
@@ -18,3 +18,3 @@ "main": "lib/index.js", | ||
"test": "nyc mocha --compilers js:babel-core/register test/**.spec.js", | ||
"test:develop": "mocha -d -w --compilers js:babel-core/register test/*.spec.js", | ||
"test:develop": "mocha -d -w -G --compilers js:babel-core/register test/*.spec.js", | ||
"coverage:check": "nyc check-coverage --lines 98", | ||
@@ -54,3 +54,3 @@ "coverage:report": "nyc report --repoprter=text-lcov --reporter=html", | ||
"nyc": "^8.1.0", | ||
"rdflib": "^0.9.0", | ||
"rdflib": "^0.12.3", | ||
"sinon": "^1.17.5", | ||
@@ -64,6 +64,4 @@ "solid-namespace": "^0.1.0", | ||
"lodash": "^4.14.2", | ||
"node-uuid": "^1.4.7", | ||
"rdflib": "^0.9.0", | ||
"valid-url": "^1.0.9" | ||
"node-uuid": "^1.4.7" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
173998
3
1324
- Removedrdflib@^0.9.0
- Removedvalid-url@^1.0.9
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasync@0.9.2(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedes6-promise@2.3.0(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsonld@0.4.12(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedn3@0.4.5(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpkginfo@0.4.1(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrdflib@0.9.0(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedvalid-url@1.0.9(transitive)
- Removedverror@1.10.0(transitive)
- Removedxmldom@0.1.190.1.31(transitive)
- Removedxmlhttprequest@1.8.0(transitive)