mirror of https://gitee.com/bigwinds/arangodb
This commit is contained in:
parent
d5b27f1f29
commit
4736f32fd7
|
@ -86,7 +86,7 @@ static string JS_actions =
|
|||
"\n"
|
||||
" res.responseCode = 200;\n"
|
||||
" res.contentType = \"application/json\";\n"
|
||||
" res.body = toJson(result);\n"
|
||||
" res.body = JSON.stringify(result);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
|
@ -134,7 +134,7 @@ static string JS_actions =
|
|||
"\n"
|
||||
" res.responseCode = 200;\n"
|
||||
" res.contentType = \"application/json\";\n"
|
||||
" res.body = toJson(result);\n"
|
||||
" res.body = JSON.stringify(result);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
|
|
|
@ -37,159 +37,247 @@ static string JS_json =
|
|||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- toJson\n"
|
||||
"// --SECTION-- AvocadoCollection\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Json V8 JSON\n"
|
||||
"/// @addtogroup V8Json\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief JSON representation of an object\n"
|
||||
"///\n"
|
||||
"/// @FUN{toJson(@FA{object}, @FA{useNewLine})}\n"
|
||||
"///\n"
|
||||
"/// The representation of a JSON object as string. If @FA{useNewLine} is true,\n"
|
||||
"/// then new-lines are used to format the output in a nice way.\n"
|
||||
"/// @brief string representation of a collection\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"function toJson (x, useNL, indent) {\n"
|
||||
" if (x === null) {\n"
|
||||
" return \"null\";\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" if (x === undefined) {\n"
|
||||
" return \"undefined\";\n"
|
||||
" }\n"
|
||||
"AvocadoCollection.prototype.toString = function() {\n"
|
||||
" var status;\n"
|
||||
"\n"
|
||||
" if (! indent) {\n"
|
||||
" indent = \"\";\n"
|
||||
" }\n"
|
||||
" if (this instanceof AvocadoCollection) {\n"
|
||||
" status = this.status();\n"
|
||||
"\n"
|
||||
" if (x instanceof String || typeof x === \"string\") {\n"
|
||||
" var s = \"\\\"\";\n"
|
||||
"\n"
|
||||
" for (var i = 0; i < x.length; i++){\n"
|
||||
" switch (x[i]) {\n"
|
||||
" case '\"': s += '\\\\\"'; break;\n"
|
||||
" case '\\\\': s += '\\\\\\\\'; break;\n"
|
||||
" case '\\b': s += '\\\\b'; break;\n"
|
||||
" case '\\f': s += '\\\\f'; break;\n"
|
||||
" case '\\n': s += '\\\\n'; break;\n"
|
||||
" case '\\r': s += '\\\\r'; break;\n"
|
||||
" case '\\t': s += '\\\\t'; break;\n"
|
||||
"\n"
|
||||
" default: {\n"
|
||||
" var code = x.charCodeAt(i);\n"
|
||||
"\n"
|
||||
" if (code < 0x20) {\n"
|
||||
" s += (code < 0x10 ? '\\\\u000' : '\\\\u00') + code.toString(16);\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" s += x[i];\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" if (status == 1) {\n"
|
||||
" return \"[new born collection at \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else if (status == 2) {\n"
|
||||
" return \"[unloaded collection at \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else if (status == 3) {\n"
|
||||
" return \"[collection at \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[corrupted collection at \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" return s + \"\\\"\";\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (x instanceof Number || typeof x === \"number\") {\n"
|
||||
" return \"\" + x;\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (x instanceof Boolean || typeof x === \"boolean\") {\n"
|
||||
" return \"\" + x;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (x instanceof Function) {\n"
|
||||
" return x.toString();\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (x instanceof Object) {\n"
|
||||
" return x.toJson(useNL, indent);\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" return \"\" + x;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief JSON representation of an array\n"
|
||||
"/// @brief JSON representation of a collection\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"Array.prototype.toJson = function(useNL, indent) {\n"
|
||||
" var nl = useNL ? \"\\n\" : \" \";\n"
|
||||
"AvocadoCollection.prototype.toJSON = function() {\n"
|
||||
" if (this instanceof AvocadoCollection) {\n"
|
||||
" status = this.status();\n"
|
||||
"\n"
|
||||
" if (! indent) {\n"
|
||||
" indent = \"\";\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" if (! useNL) {\n"
|
||||
" indent = \"\";\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (this.length == 0) {\n"
|
||||
" return indent + \"[]\";\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" var s = \"[\" + nl;\n"
|
||||
" var oldIndent = indent;\n"
|
||||
"\n"
|
||||
" if (useNL) {\n"
|
||||
" indent += \" \";\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" for (var i = 0; i < this.length; i++) {\n"
|
||||
" s += indent + toJson(this[i], useNL, indent);\n"
|
||||
"\n"
|
||||
" if (i < this.length - 1) {\n"
|
||||
" s += \",\" + nl;\n"
|
||||
" if (status == 1) {\n"
|
||||
" return \"[new born collection \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else if (status == 2) {\n"
|
||||
" return \"[unloaded collection \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else if (status == 3) {\n"
|
||||
" return \"[collection \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[corrupted collection \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" s += nl + oldIndent + \"]\";\n"
|
||||
"\n"
|
||||
" return s;\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief JSON representation of an object\n"
|
||||
"/// @}\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"Object.prototype.toJson = function(useNL, indent) {\n"
|
||||
" var nl = useNL ? \"\\n\" : \" \";\n"
|
||||
" \n"
|
||||
" if (! indent) {\n"
|
||||
" indent = \"\";\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- AvocadoDatabase\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Json\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief string representation of a vocbase\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoDatabase.prototype.toString = function() {\n"
|
||||
" if (this instanceof AvocadoDatabase) {\n"
|
||||
" return \"[vocbase at \" + JSON.stringify(this._path) + \"]\";\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" var s = \"{\" + nl;\n"
|
||||
"\n"
|
||||
" // push one level of indent\n"
|
||||
" var oldIndent = indent;\n"
|
||||
" indent += \" \";\n"
|
||||
" \n"
|
||||
" if (! useNL) {\n"
|
||||
" indent = \"\";\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
" var sep = \"\";\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief JSON representation of a vocbase\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
" for (var k in this) {\n"
|
||||
" if (this.hasOwnProperty(k)) {\n"
|
||||
" var val = this[k];\n"
|
||||
"AvocadoDatabase.prototype.toJSON = function() {\n"
|
||||
" if (this instanceof AvocadoDatabase) {\n"
|
||||
" return \"[vocbase at \" + JSON.stringify(this._path) + \"]\";\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
" s += sep + indent + \"\\\"\" + k + \"\\\" : \" + toJson(val, useNL, indent);\n"
|
||||
" sep = \",\" + nl;\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @}\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- AvocadoEdges\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Json\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief string representation of a vocbase\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoEdges.prototype.toString = function() {\n"
|
||||
" if (this instanceof AvocadoEdges) {\n"
|
||||
" return \"[edges at \" + JSON.stringify(this._path) + \"]\";\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief JSON representation of a vocbase\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoEdges.prototype.toJSON = function() {\n"
|
||||
" if (this instanceof AvocadoEdges) {\n"
|
||||
" return \"[edges at \" + JSON.stringify(this._path) + \"]\";\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @}\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- AvocadoEdgesCollection\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Json\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief string representation of an edges collection\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoEdgesCollection.prototype.toString = function() {\n"
|
||||
" var status;\n"
|
||||
"\n"
|
||||
" if (this instanceof AvocadoEdgesCollection) {\n"
|
||||
" status = this.status();\n"
|
||||
"\n"
|
||||
" if (status == 1) {\n"
|
||||
" return \"[new born collection at \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else if (status == 2) {\n"
|
||||
" return \"[unloaded collection at \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else if (status == 3) {\n"
|
||||
" return \"[collection at \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[corrupted collection at \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
" // pop one level of indent\n"
|
||||
" indent = oldIndent;\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief JSON representation of an edges collection\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
" return s + nl + indent + \"}\";\n"
|
||||
"AvocadoEdgesCollection.prototype.toJSON = function() {\n"
|
||||
" var status;\n"
|
||||
"\n"
|
||||
" if (this instanceof AvocadoEdgesCollection) {\n"
|
||||
" status = this.status();\n"
|
||||
"\n"
|
||||
" if (status == 1) {\n"
|
||||
" return \"[new born collection at \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else if (status == 2) {\n"
|
||||
" return \"[unloaded collection at \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else if (status == 3) {\n"
|
||||
" return \"[collection at \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[corrupted collection at \" + JSON.stringify(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @}\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- AvocadoQuery\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief string representation of a query\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoQuery.prototype.toString = function() {\n"
|
||||
" if (this instanceof AvocadoQuery) {\n"
|
||||
" return \"[query]\";\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief JSON representation of a query\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoQuery.prototype.toJSON = function() {\n"
|
||||
" if (this instanceof AvocadoQuery) {\n"
|
||||
" return \"[query]\";\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
|
|
|
@ -0,0 +1,213 @@
|
|||
static string JS_modules =
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief JavaScript server functions\n"
|
||||
"///\n"
|
||||
"/// @file\n"
|
||||
"///\n"
|
||||
"/// DISCLAIMER\n"
|
||||
"///\n"
|
||||
"/// Copyright by triAGENS GmbH - All rights reserved.\n"
|
||||
"///\n"
|
||||
"/// The Programs (which include both the software and documentation)\n"
|
||||
"/// contain proprietary information of triAGENS GmbH; they are\n"
|
||||
"/// provided under a license agreement containing restrictions on use and\n"
|
||||
"/// disclosure and are also protected by copyright, patent and other\n"
|
||||
"/// intellectual and industrial property laws. Reverse engineering,\n"
|
||||
"/// disassembly or decompilation of the Programs, except to the extent\n"
|
||||
"/// required to obtain interoperability with other independently created\n"
|
||||
"/// software or as specified by law, is prohibited.\n"
|
||||
"///\n"
|
||||
"/// The Programs are not intended for use in any nuclear, aviation, mass\n"
|
||||
"/// transit, medical, or other inherently dangerous applications. It shall\n"
|
||||
"/// be the licensee's responsibility to take all appropriate fail-safe,\n"
|
||||
"/// backup, redundancy, and other measures to ensure the safe use of such\n"
|
||||
"/// applications if the Programs are used for such purposes, and triAGENS\n"
|
||||
"/// GmbH disclaims liability for any damages caused by such use of\n"
|
||||
"/// the Programs.\n"
|
||||
"///\n"
|
||||
"/// This software is the confidential and proprietary information of\n"
|
||||
"/// triAGENS GmbH. You shall not disclose such confidential and\n"
|
||||
"/// proprietary information and shall use it only in accordance with the\n"
|
||||
"/// terms of the license agreement you entered into with triAGENS GmbH.\n"
|
||||
"///\n"
|
||||
"/// Copyright holder is triAGENS GmbH, Cologne, Germany\n"
|
||||
"///\n"
|
||||
"/// @author Dr. Frank Celler\n"
|
||||
"/// @author Copyright 2011, triAGENS GmbH, Cologne, Germany\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @page JSModules JavaScript Modules\n"
|
||||
"///\n"
|
||||
"/// The AvocadoDB uses a <a\n"
|
||||
"/// href=\"http://wiki.commonjs.org/wiki/Modules\">CommonJS</a> compatible module\n"
|
||||
"/// concept. You can use the function @FN{require} in order to load a\n"
|
||||
"/// module. @FN{require} returns the exported variables and functions of the\n"
|
||||
"/// module. You can use the option @CO{startup.modules-path} to specify the\n"
|
||||
"/// location of the JavaScript files.\n"
|
||||
"///\n"
|
||||
"/// @section Modules Modules\n"
|
||||
"///\n"
|
||||
"/// @copydetails JSF_require\n"
|
||||
"///\n"
|
||||
"/// @section InternalFunctions Internal Functions\n"
|
||||
"///\n"
|
||||
"/// The following functions are used internally to implement the module loader.\n"
|
||||
"///\n"
|
||||
"/// @copydetails JS_Execute\n"
|
||||
"///\n"
|
||||
"/// @copydetails JS_Load\n"
|
||||
"///\n"
|
||||
"/// @copydetails JS_Read\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- Module\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Module\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief module cache\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"ModuleCache = {};\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief module constructor\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"function Module (id) {\n"
|
||||
" this.id = id;\n"
|
||||
" this.exports = {};\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief loads a file and creates a new module descriptor\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"Module.prototype.require = function (path) {\n"
|
||||
" var content;\n"
|
||||
" var sandbox;\n"
|
||||
" var module;\n"
|
||||
"\n"
|
||||
" // first get rid of any \"..\" and \".\"\n"
|
||||
" path = this.normalise(path);\n"
|
||||
"\n"
|
||||
" // check if you already know the module, return the exports\n"
|
||||
" if (path in ModuleCache) {\n"
|
||||
" return ModuleCache[path].exports;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" // try to load the file\n"
|
||||
" content = read(\".\" + path + \".js\");\n"
|
||||
"\n"
|
||||
" // create a new sandbox and execute\n"
|
||||
" ModuleCache[path] = module = new Module(path);\n"
|
||||
"\n"
|
||||
" sandbox = {};\n"
|
||||
" sandbox.module = module;\n"
|
||||
" sandbox.exports = module.exports;\n"
|
||||
" sandbox.require = function(path) { return sandbox.module.require(path); }\n"
|
||||
" sandbox.print = print;\n"
|
||||
"\n"
|
||||
" execute(content, sandbox, path);\n"
|
||||
"\n"
|
||||
" module.exports = sandbox.exports;\n"
|
||||
"\n"
|
||||
" return module.exports;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief normalises a path\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"Module.prototype.normalise = function (path) {\n"
|
||||
" var p;\n"
|
||||
" var q;\n"
|
||||
" var x;\n"
|
||||
"\n"
|
||||
" if (path == \"\") {\n"
|
||||
" return this.id;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" p = path.split('/');\n"
|
||||
"\n"
|
||||
" // relative path\n"
|
||||
" if (p[0] == \".\" || p[0] == \"..\") {\n"
|
||||
" q = this.id.split('/');\n"
|
||||
" q.pop();\n"
|
||||
" q = q.concat(p);\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" // absolute path\n"
|
||||
" else {\n"
|
||||
" q = p;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" // normalize path\n"
|
||||
" n = [];\n"
|
||||
"\n"
|
||||
" for (var i = 0; i < q.length; ++i) {\n"
|
||||
" x = q[i];\n"
|
||||
"\n"
|
||||
" if (x == \"\") {\n"
|
||||
" }\n"
|
||||
" else if (x == \".\") {\n"
|
||||
" }\n"
|
||||
" else if (x == \"..\") {\n"
|
||||
" if (n.length == 0) {\n"
|
||||
" throw \"cannot cross module top\";\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" n.pop();\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" n.push(x);\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" return \"/\" + n.join('/');\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief top-level model\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"ModuleCache[\"/\"] = module = new Module(\"/\");\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief top-level require\n"
|
||||
"///\n"
|
||||
"/// @FUN{require(@FA{path})}\n"
|
||||
"///\n"
|
||||
"/// Require checks if the file specified by @FA{path} has already been loaded.\n"
|
||||
"/// If not, the content of the file is executed in a new context. Within the\n"
|
||||
"/// context you can use the global variable @CODE{exports} in order to export\n"
|
||||
"/// variables and functions. This variable is returned by @FN{require}. \n"
|
||||
"///\n"
|
||||
"/// Assume that your module file is @CODE{test1.js} and contains\n"
|
||||
"///\n"
|
||||
"/// @verbinclude modules1\n"
|
||||
"///\n"
|
||||
"/// Then you can use require to load the file and access the exports.\n"
|
||||
"///\n"
|
||||
"/// @verbinclude modules2\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"function require (path) {\n"
|
||||
" return module.require(path);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @}\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// Local Variables:\n"
|
||||
"// mode: outline-minor\n"
|
||||
"// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\)\"\n"
|
||||
"// End:\n"
|
||||
;
|
|
@ -37,11 +37,77 @@ static string JS_shell =
|
|||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- printing\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Shell\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief prints objects to standard output\n"
|
||||
"///\n"
|
||||
"/// @FUN{print(@FA{arg1}, @FA{arg2}, @FA{arg3}, ...)}\n"
|
||||
"///\n"
|
||||
"/// Only available in shell mode.\n"
|
||||
"///\n"
|
||||
"/// Prints the arguments. If an argument is an object having a\n"
|
||||
"/// function @FN{PRINT}, then this function is called. Otherwise @FN{toJson} is\n"
|
||||
"/// used. A final newline is printed\n"
|
||||
"///\n"
|
||||
"/// @verbinclude fluent40\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"function print () {\n"
|
||||
" for (var i = 0; i < arguments.length; ++i) {\n"
|
||||
" if (0 < i) {\n"
|
||||
" output(\" \");\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" PRINT(arguments[i]);\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" output(\"\\n\");\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief prints objects to standard output without a new-line\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"function PRINT (value) {\n"
|
||||
" if (value instanceof Object) {\n"
|
||||
" if ('PRINT' in value) {\n"
|
||||
" value.PRINT();\n"
|
||||
" }\n"
|
||||
" else if (value.prototype == undefined) {\n"
|
||||
" PRINT_OBJECT(value);\n"
|
||||
" }\n"
|
||||
" else if ('toString' in value) {\n"
|
||||
" output(value.toString());\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" PRINT_OBJECT(value);\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" else if (value === undefined) {\n"
|
||||
" output(\"undefined\");\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" output(\"\" + value);\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @}\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- Array\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Shell V8 Shell\n"
|
||||
"/// @addtogroup V8Shell\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
|
@ -49,7 +115,7 @@ static string JS_shell =
|
|||
"/// @brief JSON representation of an array\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"Array.prototype.print = function() {\n"
|
||||
"Array.prototype.PRINT = function() {\n"
|
||||
" if (this.length == 0) {\n"
|
||||
" output(\"[ ]\");\n"
|
||||
" }\n"
|
||||
|
@ -60,7 +126,7 @@ static string JS_shell =
|
|||
"\n"
|
||||
" for (var i = 0; i < this.length; i++) {\n"
|
||||
" output(sep);\n"
|
||||
" print(this[i]);\n"
|
||||
" PRINT(this[i]);\n"
|
||||
" sep = \", \";\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
|
@ -77,15 +143,15 @@ static string JS_shell =
|
|||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Shell V8 Shell\n"
|
||||
"/// @addtogroup V8Shell\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief JSON representation of a function\n"
|
||||
"/// @brief prints a function\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"Function.prototype.print = function() {\n"
|
||||
"Function.prototype.PRINT = function() {\n"
|
||||
" output(this.toString());\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
|
@ -98,7 +164,7 @@ static string JS_shell =
|
|||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Shell V8 Shell\n"
|
||||
"/// @addtogroup V8Shell\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
|
@ -106,17 +172,17 @@ static string JS_shell =
|
|||
"/// @brief string representation of an object\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"Object.prototype.print = function() {\n"
|
||||
"function PRINT_OBJECT (object) {\n"
|
||||
" var sep = \" \";\n"
|
||||
"\n"
|
||||
" output(\"{\");\n"
|
||||
"\n"
|
||||
" for (var k in this) {\n"
|
||||
" if (this.hasOwnProperty(k)) {\n"
|
||||
" var val = this[k];\n"
|
||||
" for (var k in object) {\n"
|
||||
" if (object.hasOwnProperty(k)) {\n"
|
||||
" var val = object[k];\n"
|
||||
"\n"
|
||||
" output(sep, k, \" : \");\n"
|
||||
" print(val);\n"
|
||||
" PRINT(val);\n"
|
||||
" sep = \", \";\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
|
@ -129,182 +195,11 @@ static string JS_shell =
|
|||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- AvocadoCollection\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Shell V8 Shell\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief prints a collection\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoCollection.prototype.print = function() {\n"
|
||||
" if (this instanceof AvocadoCollection) {\n"
|
||||
" status = this.status();\n"
|
||||
"\n"
|
||||
" if (status == 1) {\n"
|
||||
" output(\"[new born collection \", toJson(this._name), \"]\");\n"
|
||||
" }\n"
|
||||
" else if (status == 2) {\n"
|
||||
" output(\"[unloaded collection \", toJson(this._name), \"]\");\n"
|
||||
" }\n"
|
||||
" else if (status == 3) {\n"
|
||||
" output(\"[collection \", toJson(this._name), \"]\");\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" output(\"[corrupted collection \", toJson(this._name), \"]\");\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" output(this.toString(), \"\\n\");\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief string representation of a collection\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoCollection.prototype.toString = function() {\n"
|
||||
" var status;\n"
|
||||
"\n"
|
||||
" if (this instanceof AvocadoCollection) {\n"
|
||||
" status = this.status();\n"
|
||||
"\n"
|
||||
" if (status == 1) {\n"
|
||||
" return \"[new born collection at \" + toJson(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else if (status == 2) {\n"
|
||||
" return \"[unloaded collection at \" + toJson(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else if (status == 3) {\n"
|
||||
" return \"[collection at \" + toJson(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[corrupted collection at \" + toJson(this._name) + \"]\";\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @}\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- AvocadoDatabase\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Shell V8 Shell\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief prints the vocbase\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoDatabase.prototype.print = function() {\n"
|
||||
" if (this instanceof AvocadoDatabase) {\n"
|
||||
" output(\"[vocbase at \", toJson(this._path), \"]\");\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" output(this.toString(), \"\\n\");\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief string representation of a vocbase\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoDatabase.prototype.toString = function() {\n"
|
||||
" if (this instanceof AvocadoDatabase) {\n"
|
||||
" return \"[vocbase at \" + toJson(this._path) + \"]\";\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @}\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- AvocadoEdges\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Shell V8 Shell\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief prints the edges base\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoEdges.prototype.print = function() {\n"
|
||||
" if (this instanceof AvocadoEdges) {\n"
|
||||
" output(\"[edges at \", toJson(this._path), \"]\");\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" output(this.toString(), \"\\n\");\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief string representation of a vocbase\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoEdges.prototype.toString = function() {\n"
|
||||
" if (this instanceof AvocadoEdges) {\n"
|
||||
" return \"[edges at \" + toJson(this._path) + \"]\";\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" return \"[object]\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @}\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- AvocadoEdgesCollection\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Shell V8 Shell\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @brief prints an edges collection\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoEdgesCollection.prototype.print = function() {\n"
|
||||
" if (this instanceof AvocadoEdgesCollection) {\n"
|
||||
" output(\"[edges collection \", toJson(this._name), \"]\");\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" output(this.toString(), \"\\n\");\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @}\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"// --SECTION-- AvocadoQuery\n"
|
||||
"// -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"/// @addtogroup V8Shell V8 Shell\n"
|
||||
"/// @addtogroup V8Shell\n"
|
||||
"/// @{\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
|
@ -324,14 +219,13 @@ static string JS_shell =
|
|||
"/// @brief prints a query\n"
|
||||
"////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"\n"
|
||||
"AvocadoQuery.prototype.print = function() {\n"
|
||||
"AvocadoQuery.prototype.PRINT = function() {\n"
|
||||
" if (this instanceof AvocadoQuery) {\n"
|
||||
" var count = 0;\n"
|
||||
"\n"
|
||||
" try {\n"
|
||||
" while (this.hasNext() && count++ < queryLimit) {\n"
|
||||
" print(this.next());\n"
|
||||
" output(\"\\n\");\n"
|
||||
" output(JSON.stringify(this.next()), \"\\n\");\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if (this.hasNext()) {\n"
|
||||
|
@ -345,7 +239,7 @@ static string JS_shell =
|
|||
" }\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" output(this.toString(), \"\\n\");\n"
|
||||
" output(this.toString());\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
|
|
Loading…
Reference in New Issue