Update to jsonld.js v0.2.14.
authorDave Longley <dlongley@digitalbazaar.com>
Tue, 08 Jul 2014 13:03:54 -0400
changeset 2159 4d1a199d9e11
parent 2158 016281fb9a68
child 2160 07703498f617
Update to jsonld.js v0.2.14.
playground/jsonld.js
--- a/playground/jsonld.js	Tue Jul 08 18:01:15 2014 +0200
+++ b/playground/jsonld.js	Tue Jul 08 13:03:54 2014 -0400
@@ -955,6 +955,11 @@
 /* Promises API */
 
 jsonld.promises = function() {
+  try {
+    jsonld.Promise = global.Promise || require('es6-promise').Promise;
+  } catch(e) {
+    throw new Error('Unable to find a Promise implementation.');
+  }
   var slice = Array.prototype.slice;
   var promisify = jsonld.promisify;
 
@@ -1021,13 +1026,15 @@
  * @return the promise.
  */
 jsonld.promisify = function(op) {
-  try {
-    var Promise = global.Promise || require('es6-promise').Promise;
-  } catch(e) {
-    throw new Error('Unable to find a Promise implementation.');
+  if(!jsonld.Promise) {
+    try {
+      jsonld.Promise = global.Promise || require('es6-promise').Promise;
+    } catch(e) {
+      throw new Error('Unable to find a Promise implementation.');
+    }
   }
   var args = Array.prototype.slice.call(arguments, 1);
-  return new Promise(function(resolve, reject) {
+  return new jsonld.Promise(function(resolve, reject) {
     op.apply(null, args.concat(function(err, value) {
       if(!err) {
         resolve(value);
@@ -1325,6 +1332,8 @@
  *
  * @param options the options to use:
  *          secure: require all URLs to use HTTPS.
+ *          strictSSL: true to require SSL certificates to be valid,
+ *            false not to (default: true).
  *          maxRedirects: the maximum number of redirects to permit, none by
  *            default.
  *          usePromise: true to use a promises API, false for a
@@ -1334,6 +1343,7 @@
  */
 jsonld.documentLoaders.node = function(options) {
   options = options || {};
+  var strictSSL = ('strictSSL' in options) ? options.strictSSL : true;
   var maxRedirects = ('maxRedirects' in options) ? options.maxRedirects : -1;
   var request = require('request');
   var http = require('http');
@@ -1355,7 +1365,7 @@
       headers: {
         'Accept': 'application/ld+json, application/json'
       },
-      strictSSL: true,
+      strictSSL: strictSSL,
       followRedirect: false
     }, function(err, res, body) {
       doc = {contextUrl: null, documentUrl: url, document: body || null};
@@ -2455,7 +2465,7 @@
     // FIXME: can this be merged with code above to simplify?
     // merge in reverse properties
     if(activeCtx.mappings[key] && activeCtx.mappings[key].reverse) {
-      var reverseMap = rval['@reverse'] = {};
+      var reverseMap = rval['@reverse'] = rval['@reverse'] || {};
       if(!_isArray(expandedValue)) {
         expandedValue = [expandedValue];
       }
@@ -4736,6 +4746,13 @@
       'jsonld.SyntaxError', {code: 'keyword redefinition', context: localCtx});
   }
 
+  if(term === '') {
+    throw new JsonLdError(
+      'Invalid JSON-LD syntax; a term cannot be an empty string.',
+      'jsonld.SyntaxError',
+      {code: 'invalid term definition', context: localCtx});
+  }
+
   // remove old mapping
   if(activeCtx.mappings[term]) {
     delete activeCtx.mappings[term];