mirror of https://gitee.com/bigwinds/arangodb
fixed jslint errors
This commit is contained in:
parent
24fc2d371e
commit
c91b7c0f14
|
@ -215,7 +215,8 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ArangoCollection.prototype._PRINT = function() {
|
ArangoCollection.prototype._PRINT = function() {
|
||||||
var status = type = "unknown";
|
var status = "unknown";
|
||||||
|
var type = "unknown";
|
||||||
|
|
||||||
switch (this.status()) {
|
switch (this.status()) {
|
||||||
case ArangoCollection.STATUS_NEW_BORN: status = "new born"; break;
|
case ArangoCollection.STATUS_NEW_BORN: status = "new born"; break;
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
this._id = collection._id;
|
this._id = collection._id;
|
||||||
this._collection = collection;
|
this._collection = collection;
|
||||||
this._language = lang;
|
this._language = lang;
|
||||||
};
|
}
|
||||||
|
|
||||||
internal.ArangoStructure = ArangoStructure;
|
internal.ArangoStructure = ArangoStructure;
|
||||||
|
|
||||||
|
@ -67,6 +67,297 @@
|
||||||
/// @}
|
/// @}
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- private methods
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @addtogroup V8Shell
|
||||||
|
/// @{
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief prints a collection
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ArangoStructure.prototype._PRINT = function () {
|
||||||
|
var status = "unknown";
|
||||||
|
var type = "unknown";
|
||||||
|
|
||||||
|
switch (this.status()) {
|
||||||
|
case ArangoCollection.STATUS_NEW_BORN: status = "new born"; break;
|
||||||
|
case ArangoCollection.STATUS_UNLOADED: status = "unloaded"; break;
|
||||||
|
case ArangoCollection.STATUS_UNLOADING: status = "unloading"; break;
|
||||||
|
case ArangoCollection.STATUS_LOADED: status = "loaded"; break;
|
||||||
|
case ArangoCollection.STATUS_CORRUPTED: status = "corrupted"; break;
|
||||||
|
case ArangoCollection.STATUS_DELETED: status = "deleted"; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (this.type()) {
|
||||||
|
case ArangoCollection.TYPE_DOCUMENT: type = "document"; break;
|
||||||
|
case ArangoCollection.TYPE_EDGE: type = "edge"; break;
|
||||||
|
case ArangoCollection.TYPE_ATTACHMENT: type = "attachment"; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal.output("[ArangoStructure ", this._id, ", \"", this.name(),
|
||||||
|
"\" (type ", type, ", status ", status, "lang ",
|
||||||
|
this._language, ")]");
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief parses a single attribute
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function parse (lang, info, value) {
|
||||||
|
var error;
|
||||||
|
var module;
|
||||||
|
|
||||||
|
try {
|
||||||
|
module = require(info.module);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
error = new ArangoError();
|
||||||
|
error.errorNum = internal.errors.ERROR_NOT_IMPLEMENTED.code;
|
||||||
|
error.errorMessage = String(err);
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return module[info['do']](value, info, lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief validates a single attribute
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function validate (lang, info, value) {
|
||||||
|
var error;
|
||||||
|
var module;
|
||||||
|
|
||||||
|
try {
|
||||||
|
module = require(info.module);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
error = new ArangoError();
|
||||||
|
error.errorNum = internal.errors.ERROR_NOT_IMPLEMENTED.code;
|
||||||
|
error.errorMessage = String(err);
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
module[info['do']](value, info, lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief parses and validates a single attribute
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function parseAndValidate (lang, info, value) {
|
||||||
|
var type;
|
||||||
|
|
||||||
|
// parse the input
|
||||||
|
if (info.hasOwnProperty("parser")) {
|
||||||
|
if (info.parser.hasOwnProperty(lang)) {
|
||||||
|
value = parse(lang, info.parser[lang], value);
|
||||||
|
}
|
||||||
|
else if (info.parser.hasOwnProperty('default')) {
|
||||||
|
value = parse(lang, info.parser['default'], value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (info.hasOwnProperty("type")) {
|
||||||
|
type = info.type;
|
||||||
|
|
||||||
|
if (type === "number") {
|
||||||
|
value = parseFloat(value);
|
||||||
|
}
|
||||||
|
else if (type === "string") {
|
||||||
|
value = String(value);
|
||||||
|
}
|
||||||
|
else if (type === "boolean") {
|
||||||
|
if (value === 1 || value === "1" || (/^true$/i).test(value)) {
|
||||||
|
value = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate the input
|
||||||
|
if (info.hasOwnProperty("validator")) {
|
||||||
|
if (info.validator.hasOwnProperty(lang)) {
|
||||||
|
validate(lang, info.validator[lang], value);
|
||||||
|
}
|
||||||
|
else if (info.validator.hasOwnProperty('default')) {
|
||||||
|
validate(lang, info.validator['default'], value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// and return
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief parses and validates the structure information recursively
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function parseStructureInformationRecursive (lang, info, path, key, value) {
|
||||||
|
var k;
|
||||||
|
var result;
|
||||||
|
|
||||||
|
if (info.attributes.hasOwnProperty(path)) {
|
||||||
|
value = parseAndValidate(lang, info.attributes[path], value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value instanceof Array) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value instanceof Object) {
|
||||||
|
result = {};
|
||||||
|
|
||||||
|
for (k in value) {
|
||||||
|
if (value.hasOwnProperty(k)) {
|
||||||
|
result[k] = parseStructureInformationRecursive(lang, info, path + "." + k, k, value[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief parses and validates the structure information
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function parseStructureInformation (lang, name, data) {
|
||||||
|
var info;
|
||||||
|
var key;
|
||||||
|
var validated;
|
||||||
|
|
||||||
|
info = internal.db._collection("_structures").firstExample({ collection: name });
|
||||||
|
|
||||||
|
if (info === null) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
validated = {};
|
||||||
|
|
||||||
|
for (key in data) {
|
||||||
|
if (data.hasOwnProperty(key)) {
|
||||||
|
validated[key] = parseStructureInformationRecursive(lang, info, key, key, data[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return validated;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief formats a single attribute
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function format (lang, info, value) {
|
||||||
|
var error;
|
||||||
|
var module;
|
||||||
|
|
||||||
|
try {
|
||||||
|
module = require(info.module);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
error = new ArangoError();
|
||||||
|
error.errorNum = internal.errors.ERROR_NOT_IMPLEMENTED.code;
|
||||||
|
error.errorMessage = String(err);
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return module[info['do']](value, info, lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief formats a single attribute
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function formatValue (lang, info, value) {
|
||||||
|
var type;
|
||||||
|
|
||||||
|
// parse the input
|
||||||
|
if (info.hasOwnProperty("formatter")) {
|
||||||
|
if (info.formatter.hasOwnProperty(lang)) {
|
||||||
|
value = format(lang, info.formatter[lang], value);
|
||||||
|
}
|
||||||
|
else if (info.formatter.hasOwnProperty('default')) {
|
||||||
|
value = format(lang, info.formatter['default'], value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// and return
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief formats the structure information recursively
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function formatStructureInformationRecursive (lang, info, path, key, value) {
|
||||||
|
var k;
|
||||||
|
var result;
|
||||||
|
|
||||||
|
if (info.attributes.hasOwnProperty(path)) {
|
||||||
|
value = formatValue(lang, info.attributes[path], value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value instanceof Array) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value instanceof Object) {
|
||||||
|
result = {};
|
||||||
|
|
||||||
|
for (k in value) {
|
||||||
|
if (value.hasOwnProperty(k)) {
|
||||||
|
result[k] = formatStructureInformationRecursive(lang, info, path + "." + k, k, value[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief formats the structure information
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function formatStructureInformation (lang, name, data) {
|
||||||
|
var info;
|
||||||
|
var key;
|
||||||
|
var formatted;
|
||||||
|
|
||||||
|
info = internal.db._collection("_structures").firstExample({ collection: name });
|
||||||
|
|
||||||
|
if (info === null) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
formatted = {};
|
||||||
|
|
||||||
|
for (key in data) {
|
||||||
|
if (data.hasOwnProperty(key)) {
|
||||||
|
formatted[key] = formatStructureInformationRecursive(lang, info, key, key, data[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatted;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- public methods
|
// --SECTION-- public methods
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -82,7 +373,7 @@
|
||||||
|
|
||||||
ArangoStructure.prototype.name = function () {
|
ArangoStructure.prototype.name = function () {
|
||||||
return this._collection.name();
|
return this._collection.name();
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief status of a structure
|
/// @brief status of a structure
|
||||||
|
@ -90,7 +381,7 @@
|
||||||
|
|
||||||
ArangoStructure.prototype.status = function () {
|
ArangoStructure.prototype.status = function () {
|
||||||
return this._collection.status();
|
return this._collection.status();
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief type of a structure
|
/// @brief type of a structure
|
||||||
|
@ -98,27 +389,27 @@
|
||||||
|
|
||||||
ArangoStructure.prototype.type = function () {
|
ArangoStructure.prototype.type = function () {
|
||||||
return this._collection.type();
|
return this._collection.type();
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief saves a document
|
/// @brief saves a document
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ArangoStructure.prototype.save = function (data, waitForSync) {
|
ArangoStructure.prototype.save = function (data, waitForSync) {
|
||||||
data = ParseStructureInformation(this._language, this._collection.name(), data);
|
data = parseStructureInformation(this._language, this._collection.name(), data);
|
||||||
|
|
||||||
return this._collection.save(data, waitForSync);
|
return this._collection.save(data, waitForSync);
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief replaces a document
|
/// @brief replaces a document
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ArangoStructure.prototype.replace = function (document, data, overwrite, waitForSync) {
|
ArangoStructure.prototype.replace = function (document, data, overwrite, waitForSync) {
|
||||||
data = ParseStructureInformation(this._language, this._collection.name(), data);
|
data = parseStructureInformation(this._language, this._collection.name(), data);
|
||||||
|
|
||||||
return this._collection.save(document, data, overwrite, waitForSync);
|
return this._collection.save(document, data, overwrite, waitForSync);
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief deletes a document
|
/// @brief deletes a document
|
||||||
|
@ -126,7 +417,7 @@
|
||||||
|
|
||||||
ArangoStructure.prototype.remove = function (document, overwrite, waitForSync) {
|
ArangoStructure.prototype.remove = function (document, overwrite, waitForSync) {
|
||||||
return this._collection.remove(document, overwrite, waitForSync);
|
return this._collection.remove(document, overwrite, waitForSync);
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief reads a document
|
/// @brief reads a document
|
||||||
|
@ -137,8 +428,8 @@
|
||||||
|
|
||||||
data = this._collection.document(handle);
|
data = this._collection.document(handle);
|
||||||
|
|
||||||
return FormatStructureInformation(this._language, this._collection.name(), data);
|
return formatStructureInformation(this._language, this._collection.name(), data);
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief database accessor
|
/// @brief database accessor
|
||||||
|
@ -164,296 +455,6 @@
|
||||||
/// @}
|
/// @}
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// --SECTION-- private methods
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @addtogroup V8Shell
|
|
||||||
/// @{
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief prints a collection
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
ArangoStructure.prototype._PRINT = function () {
|
|
||||||
var status = type = "unknown";
|
|
||||||
|
|
||||||
switch (this.status()) {
|
|
||||||
case ArangoCollection.STATUS_NEW_BORN: status = "new born"; break;
|
|
||||||
case ArangoCollection.STATUS_UNLOADED: status = "unloaded"; break;
|
|
||||||
case ArangoCollection.STATUS_UNLOADING: status = "unloading"; break;
|
|
||||||
case ArangoCollection.STATUS_LOADED: status = "loaded"; break;
|
|
||||||
case ArangoCollection.STATUS_CORRUPTED: status = "corrupted"; break;
|
|
||||||
case ArangoCollection.STATUS_DELETED: status = "deleted"; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (this.type()) {
|
|
||||||
case ArangoCollection.TYPE_DOCUMENT: type = "document"; break;
|
|
||||||
case ArangoCollection.TYPE_EDGE: type = "edge"; break;
|
|
||||||
case ArangoCollection.TYPE_ATTACHMENT: type = "attachment"; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal.output("[ArangoStructure ",
|
|
||||||
this._id,
|
|
||||||
", \"", this.name(), "\" (type ", type, ", status ", status, "lang ", this._language, ")]");
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief parses and validates the structure information
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
function ParseStructureInformation (lang, name, data) {
|
|
||||||
var info;
|
|
||||||
var key;
|
|
||||||
var validated;
|
|
||||||
|
|
||||||
info = internal.db._collection("_structures").firstExample({ collection: name });
|
|
||||||
|
|
||||||
if (info === null) {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
validated = {};
|
|
||||||
|
|
||||||
for (key in data) {
|
|
||||||
if (data.hasOwnProperty(key)) {
|
|
||||||
validated[key] = ParseStructureInformationRecursive(lang, info, key, key, data[key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return validated;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief parses and validates the structure information recursively
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
function ParseStructureInformationRecursive (lang, info, path, key, value) {
|
|
||||||
var k;
|
|
||||||
var result;
|
|
||||||
|
|
||||||
if (info.attributes.hasOwnProperty(path)) {
|
|
||||||
value = ParseAndValidate(lang, info.attributes[path], value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value instanceof Array) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
else if (value instanceof Object) {
|
|
||||||
result = {};
|
|
||||||
|
|
||||||
for (k in value) {
|
|
||||||
if (value.hasOwnProperty(k)) {
|
|
||||||
result[k] = ParseStructureInformationRecursive(lang, info, path + "." + k, k, value[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief parses and validates a single attribute
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
function ParseAndValidate (lang, info, value) {
|
|
||||||
var type;
|
|
||||||
|
|
||||||
// parse the input
|
|
||||||
if (info.hasOwnProperty("parser")) {
|
|
||||||
if (info.parser.hasOwnProperty(lang)) {
|
|
||||||
value = Parse(lang, info.parser[lang], value);
|
|
||||||
}
|
|
||||||
else if (info.parser.hasOwnProperty('default')) {
|
|
||||||
value = Parse(lang, info.parser['default'], value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (info.hasOwnProperty("type")) {
|
|
||||||
type = info.type;
|
|
||||||
|
|
||||||
if (type === "number") {
|
|
||||||
value = parseFloat(value);
|
|
||||||
}
|
|
||||||
else if (type === "string") {
|
|
||||||
value = String(value);
|
|
||||||
}
|
|
||||||
else if (type === "boolean") {
|
|
||||||
if (value === 1 || value === "1" || (/^true$/i).test(value)) {
|
|
||||||
value = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// validate the input
|
|
||||||
if (info.hasOwnProperty("validator")) {
|
|
||||||
if (info.validator.hasOwnProperty(lang)) {
|
|
||||||
Validate(lang, info.validator[lang], value);
|
|
||||||
}
|
|
||||||
else if (info.validator.hasOwnProperty('default')) {
|
|
||||||
Validate(lang, info.validator['default'], value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// and return
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief parses a single attribute
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
function Parse (lang, info, value) {
|
|
||||||
var error;
|
|
||||||
var module;
|
|
||||||
|
|
||||||
try {
|
|
||||||
module = require(info.module);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
error = new ArangoError();
|
|
||||||
error.errorNum = internal.errors.ERROR_NOT_IMPLEMENTED.code;
|
|
||||||
error.errorMessage = String(err);
|
|
||||||
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return module[info['do']](value, info, lang);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief validates a single attribute
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
function Validate (lang, info, value) {
|
|
||||||
var error;
|
|
||||||
var module;
|
|
||||||
|
|
||||||
try {
|
|
||||||
module = require(info.module);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
error = new ArangoError();
|
|
||||||
error.errorNum = internal.errors.ERROR_NOT_IMPLEMENTED.code;
|
|
||||||
error.errorMessage = String(err);
|
|
||||||
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
module[info['do']](value, info, lang);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief formats the structure information
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
function FormatStructureInformation (lang, name, data) {
|
|
||||||
var info;
|
|
||||||
var key;
|
|
||||||
var formatted;
|
|
||||||
|
|
||||||
info = internal.db._collection("_structures").firstExample({ collection: name });
|
|
||||||
|
|
||||||
if (info === null) {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
formatted = {};
|
|
||||||
|
|
||||||
for (key in data) {
|
|
||||||
if (data.hasOwnProperty(key)) {
|
|
||||||
formatted[key] = FormatStructureInformationRecursive(lang, info, key, key, data[key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return formatted;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief formats the structure information recursively
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
function FormatStructureInformationRecursive (lang, info, path, key, value) {
|
|
||||||
var k;
|
|
||||||
var result;
|
|
||||||
|
|
||||||
if (info.attributes.hasOwnProperty(path)) {
|
|
||||||
value = FormatValue(lang, info.attributes[path], value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value instanceof Array) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
else if (value instanceof Object) {
|
|
||||||
result = {};
|
|
||||||
|
|
||||||
for (k in value) {
|
|
||||||
if (value.hasOwnProperty(k)) {
|
|
||||||
result[k] = FormatStructureInformationRecursive(lang, info, path + "." + k, k, value[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief formats a single attribute
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
function FormatValue (lang, info, value) {
|
|
||||||
var type;
|
|
||||||
|
|
||||||
// parse the input
|
|
||||||
if (info.hasOwnProperty("formatter")) {
|
|
||||||
if (info.formatter.hasOwnProperty(lang)) {
|
|
||||||
value = Format(lang, info.formatter[lang], value);
|
|
||||||
}
|
|
||||||
else if (info.formatter.hasOwnProperty('default')) {
|
|
||||||
value = Format(lang, info.formatter['default'], value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// and return
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief formats a single attribute
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
function Format (lang, info, value) {
|
|
||||||
var error;
|
|
||||||
var module;
|
|
||||||
|
|
||||||
try {
|
|
||||||
module = require(info.module);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
error = new ArangoError();
|
|
||||||
error.errorNum = internal.errors.ERROR_NOT_IMPLEMENTED.code;
|
|
||||||
error.errorMessage = String(err);
|
|
||||||
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return module[info['do']](value, info, lang);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue