mirror of https://gitee.com/bigwinds/arangodb
Move shallowCopy and propertyKeys into @arangodb/util
This commit is contained in:
parent
eef85f6202
commit
c1828234d6
|
@ -33,6 +33,7 @@
|
|||
var actions = require("@arangodb/actions");
|
||||
var graph = require("@arangodb/graph-blueprint");
|
||||
var arangodb = require("@arangodb");
|
||||
var shallowCopy = require("@arangodb/util").shallowCopy;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -386,7 +387,7 @@ function update_graph_vertex (req, res, g, isPatch) {
|
|||
waitForSync = true;
|
||||
}
|
||||
|
||||
var shallow = json._shallowCopy;
|
||||
var shallow = shallowCopy(json);
|
||||
|
||||
var id2 = null;
|
||||
if (isPatch) {
|
||||
|
@ -781,7 +782,7 @@ function update_graph_edge (req, res, g, isPatch) {
|
|||
waitForSync = true;
|
||||
}
|
||||
|
||||
var shallow = json._shallowCopy;
|
||||
var shallow = shallowCopy(json);
|
||||
if (json.hasOwnProperty('_from')) {
|
||||
shallow._from = json._from;
|
||||
}
|
||||
|
|
|
@ -1726,11 +1726,6 @@ if (typeof SYS_OPTIONS !== 'undefined') {
|
|||
delete global.SYS_OPTIONS;
|
||||
}
|
||||
|
||||
exports.propertyKeys = (obj) => Object.keys(obj).filter((key) => {
|
||||
return (key.charAt(0) !== '_' && key.charAt(0) !== '$');
|
||||
});
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief print
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -32,18 +32,5 @@
|
|||
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief shallow copies properties
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Object.defineProperty(Object.prototype, '_shallowCopy', {
|
||||
get() {
|
||||
return require('internal').propertyKeys(this).reduce((previous, key) => {
|
||||
previous[key] = this[key];
|
||||
return previous;
|
||||
}, {});
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var is = require("@arangodb/is"),
|
||||
internal = require("internal"),
|
||||
propertyKeys = require("@arangodb/util").propertyKeys,
|
||||
shallowCopy = require("@arangodb/util").shallowCopy,
|
||||
Edge,
|
||||
Graph,
|
||||
Vertex,
|
||||
|
@ -245,7 +246,7 @@ Edge.prototype.getProperty = function (name) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Edge.prototype.getPropertyKeys = function () {
|
||||
return internal.propertyKeys(this._properties);
|
||||
return propertyKeys(this._properties);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -253,7 +254,7 @@ Edge.prototype.getPropertyKeys = function () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Edge.prototype.properties = function () {
|
||||
return this._properties._shallowCopy;
|
||||
return shallowCopy(this._properties);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -432,7 +433,7 @@ Vertex.prototype.getProperty = function (name) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Vertex.prototype.getPropertyKeys = function () {
|
||||
return internal.propertyKeys(this._properties);
|
||||
return propertyKeys(this._properties);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -450,7 +451,7 @@ Vertex.prototype.getPropertyKeys = function () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Vertex.prototype.properties = function () {
|
||||
return this._properties._shallowCopy;
|
||||
return shallowCopy(this._properties);
|
||||
};
|
||||
|
||||
|
||||
|
@ -496,7 +497,7 @@ Graph.prototype._prepareEdgeData = function (data, label) {
|
|||
if (is.notExisty(data) || is.noObject(data)) {
|
||||
edgeData = {};
|
||||
} else {
|
||||
edgeData = data._shallowCopy || {};
|
||||
edgeData = shallowCopy(data) || {};
|
||||
}
|
||||
|
||||
edgeData.$label = label;
|
||||
|
@ -510,7 +511,7 @@ Graph.prototype._prepareVertexData = function (data) {
|
|||
if (is.notExisty(data) || is.noObject(data)) {
|
||||
vertexData = {};
|
||||
} else {
|
||||
vertexData = data._shallowCopy || {};
|
||||
vertexData = shallowCopy(data) || {};
|
||||
}
|
||||
|
||||
return vertexData;
|
||||
|
|
|
@ -85,3 +85,20 @@ exports.inline = function (strs) {
|
|||
}
|
||||
return str.replace(/\s*\n\s*/g, ' ').replace(/(^\s|\s$)/g, '');
|
||||
};
|
||||
|
||||
exports.propertyKeys = function (obj) {
|
||||
return Object.keys(obj).filter((key) => (
|
||||
key.charAt(0) !== '_' && key.charAt(0) !== '$'
|
||||
));
|
||||
};
|
||||
|
||||
exports.shallowCopy = function (src) {
|
||||
const dest = {};
|
||||
if (src === undefined || src === null) {
|
||||
return dest;
|
||||
}
|
||||
for (const key of exports.propertyKeys(src)) {
|
||||
dest[key] = src[key];
|
||||
}
|
||||
return dest;
|
||||
};
|
||||
|
|
|
@ -43,6 +43,7 @@ var console = require("console");
|
|||
|
||||
var arangodb = require("@arangodb");
|
||||
var foxxManager = require("@arangodb/foxx/manager");
|
||||
var shallowCopy = require("@arangodb/util").shallowCopy;
|
||||
var ErrorStackParser = require("error-stack-parser");
|
||||
|
||||
const MIME_DEFAULT = 'text/plain; charset=utf-8';
|
||||
|
@ -970,7 +971,7 @@ function flattenRouting (routes, path, rexpr, urlParameters, depth, prefix) {
|
|||
routes.prefix,
|
||||
path + "/*",
|
||||
rexpr + "(/[^/]+)*/?",
|
||||
urlParameters._shallowCopy,
|
||||
shallowCopy(urlParameters),
|
||||
depth + 1,
|
||||
true));
|
||||
}
|
||||
|
@ -1672,7 +1673,7 @@ function handleRedirect (req, res, options, headers) {
|
|||
+ "</a>.</p></body></html>";
|
||||
|
||||
if (headers !== undefined) {
|
||||
res.headers = headers._shallowCopy;
|
||||
res.headers = shallowCopy(headers);
|
||||
}
|
||||
else {
|
||||
res.headers = {};
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
var db = require("@arangodb").db;
|
||||
var internal = require("internal");
|
||||
var shallowCopy = require("@arangodb/util").shallowCopy;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief the frontend collection
|
||||
|
@ -67,7 +68,7 @@ exports.notifications.versions = function () {
|
|||
}
|
||||
}
|
||||
|
||||
d = d._shallowCopy;
|
||||
d = shallowCopy(d);
|
||||
|
||||
if (! d.hasOwnProperty(v)) {
|
||||
d.versions = {};
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
var arangodb = require("@arangodb"),
|
||||
is = require("@arangodb/is"),
|
||||
shallowCopy = require("@arangodb/util").shallowCopy,
|
||||
db = arangodb.db,
|
||||
ArangoCollection = arangodb.ArangoCollection,
|
||||
common = require("@arangodb/graph-common"),
|
||||
|
@ -88,7 +89,7 @@ var findOrCreateEdgeCollectionByName = function (name) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Edge.prototype.setProperty = function (name, value) {
|
||||
var shallow = this._properties._shallowCopy;
|
||||
var shallow = shallowCopy(this._properties);
|
||||
var id;
|
||||
|
||||
// Could potentially change the weight of edges
|
||||
|
@ -244,7 +245,7 @@ Vertex.prototype.outbound = function () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Vertex.prototype.setProperty = function (name, value) {
|
||||
var shallow = this._properties._shallowCopy;
|
||||
var shallow = shallowCopy(this._properties);
|
||||
var id;
|
||||
|
||||
shallow[name] = value;
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
var internal = require("internal"); // OK: reloadAuth
|
||||
var arangodb = require("@arangodb");
|
||||
var shallowCopy = require("@arangodb/util").shallowCopy;
|
||||
var crypto = require("@arangodb/crypto");
|
||||
|
||||
var db = arangodb.db;
|
||||
|
@ -240,7 +241,7 @@ exports.update = function (username, password, active, userData, changePassword)
|
|||
throw err;
|
||||
}
|
||||
|
||||
var data = user._shallowCopy;
|
||||
var data = shallowCopy(user);
|
||||
|
||||
if (password !== undefined) {
|
||||
data.authData.simple = hashPassword(password);
|
||||
|
@ -419,7 +420,7 @@ exports.changePassword = function (token, password) {
|
|||
|
||||
password = validatePassword(password);
|
||||
|
||||
var authData = user._shallowCopy.authData;
|
||||
var authData = shallowCopy(user).authData;
|
||||
|
||||
delete authData.passwordToken;
|
||||
authData.simple = hashPassword(password);
|
||||
|
|
Loading…
Reference in New Issue