jsonapi-server
Advanced tools
Comparing version 1.11.0 to 1.12.0
@@ -0,1 +1,3 @@ | ||
- 2016-06-09 - v1.12.0 | ||
- 2016-06-09 - MemoryHandler clones all objects | ||
- 2016-06-02 - v1.11.0 | ||
@@ -2,0 +4,0 @@ - 2016-06-02 - Error when interacting with broken resources |
@@ -39,3 +39,3 @@ /* @flow weak */ | ||
} | ||
return callback(null, results, resultCount); | ||
return callback(null, MemoryStore._clone(results), resultCount); | ||
}; | ||
@@ -63,13 +63,23 @@ | ||
// Return the requested resource | ||
return callback(null, theResource); | ||
return callback(null, MemoryStore._clone(theResource)); | ||
}; | ||
/** | ||
Create (store) a new resource give a resource type and an object. | ||
Create (store) a new resource given a resource type and an object. | ||
*/ | ||
MemoryStore.prototype.create = function(request, newResource, callback) { | ||
// Check to see if the ID already exists | ||
var index = MemoryStore._indexOf(resources[request.params.type], newResource); | ||
if (index !== -1) { | ||
return callback({ | ||
status: "403", | ||
code: "EFORBIDDEN", | ||
title: "Requested resource already exists", | ||
detail: "The requested resource already exists of type " + request.params.type + " with id " + request.params.id | ||
}); | ||
} | ||
// Push the newResource into our in-memory store. | ||
resources[request.params.type].push(newResource); | ||
// Return the newly created resource | ||
return callback(null, newResource); | ||
return callback(null, MemoryStore._clone(newResource)); | ||
}; | ||
@@ -85,5 +95,5 @@ | ||
// Remove the resource from the in-meory store. | ||
var resourceIndex = resources[request.params.type].indexOf(theResource); | ||
resources[request.params.type].splice(resourceIndex, 1); | ||
// Remove the resource from the in-memory store. | ||
var index = MemoryStore._indexOf(resources[request.params.type], theResource); | ||
resources[request.params.type].splice(index, 1); | ||
@@ -108,6 +118,7 @@ // Return with no error | ||
// Push the newly updated resource back into the in-memory store | ||
resources[request.params.type][request.params.id] = theResource; | ||
var index = MemoryStore._indexOf(resources[request.params.type], theResource); | ||
resources[request.params.type][index] = theResource; | ||
// Return the newly updated resource | ||
return callback(null, theResource); | ||
return callback(null, MemoryStore._clone(theResource)); | ||
}); | ||
@@ -140,1 +151,12 @@ }; | ||
}; | ||
MemoryStore._clone = function(obj) { | ||
return JSON.parse(JSON.stringify(obj)); | ||
}; | ||
MemoryStore._indexOf = function(list, obj) { | ||
for (var i in list) { | ||
if (list[i].id === obj.id) return i; | ||
} | ||
return -1; | ||
}; |
{ | ||
"name": "jsonapi-server", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "A config driven NodeJS framework implementing json:api", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
240755
5602
2