mirror of https://gitee.com/bigwinds/arangodb
258 lines
8.7 KiB
C
258 lines
8.7 KiB
C
string JS_shell =
|
|
"////////////////////////////////////////////////////////////////////////////////\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"
|
|
"// --SECTION-- query evaluation\n"
|
|
"// -----------------------------------------------------------------------------\n"
|
|
"\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"/// @addtogroup V8Shell V8 Shell\n"
|
|
"/// @{\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"/// @brief global variable holding the current printed query\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"\n"
|
|
"var it = undefined;\n"
|
|
"\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"/// @brief number of results to print\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"\n"
|
|
"var queryLimit = 20;\n"
|
|
"\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"/// @brief prints a query\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"\n"
|
|
"AvocadoQuery.prototype.print = function(q) {\n"
|
|
" var count = 0;\n"
|
|
"\n"
|
|
" try {\n"
|
|
" while (q.hasNext() && count++ < queryLimit) {\n"
|
|
" output(toJson(q.next()), \"\\n\");\n"
|
|
" }\n"
|
|
"\n"
|
|
" if (q.hasNext()) {\n"
|
|
" output(\"...more results...\");\n"
|
|
" }\n"
|
|
"\n"
|
|
" it = q;\n"
|
|
" }\n"
|
|
" catch (e) {\n"
|
|
" output(\"encountered error while printing: \" + e);\n"
|
|
" }\n"
|
|
"}\n"
|
|
"\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"/// @}\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"\n"
|
|
"// -----------------------------------------------------------------------------\n"
|
|
"// --SECTION-- toJson\n"
|
|
"// -----------------------------------------------------------------------------\n"
|
|
"\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"/// @addtogroup V8Shell V8 Shell\n"
|
|
"/// @{\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"/// @brief JSON representation of an object\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"\n"
|
|
"toJson = function(x, indent , useNL) {\n"
|
|
" if (x === null) {\n"
|
|
" return \"null\";\n"
|
|
" }\n"
|
|
" \n"
|
|
" if (x === undefined) {\n"
|
|
" return \"undefined\";\n"
|
|
" }\n"
|
|
"\n"
|
|
" if (useNL === undefined && (indent === true || indent === false)) {\n"
|
|
" useNL = indent;\n"
|
|
" indent = \"\";\n"
|
|
" }\n"
|
|
" \n"
|
|
" if (! indent) {\n"
|
|
" indent = \"\";\n"
|
|
" }\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"
|
|
" }\n"
|
|
"\n"
|
|
" return s + \"\\\"\";\n"
|
|
" }\n"
|
|
"\n"
|
|
" if (x instanceof Number || typeof x === \"number\") {\n"
|
|
" return \"\" + x;\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 toJsonObject(x, indent , useNL);\n"
|
|
" }\n"
|
|
"\n"
|
|
" return \"\" + x;\n"
|
|
"}\n"
|
|
"\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"/// @brief JSON representation of an array\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"\n"
|
|
"Array.toJson = function(a, indent, useNL) {\n"
|
|
" var nl = useNL ? \"\\n\" : \" \";\n"
|
|
"\n"
|
|
" if (! indent) {\n"
|
|
" indent = \"\";\n"
|
|
" }\n"
|
|
" \n"
|
|
" if (! useNL) {\n"
|
|
" indent = \"\";\n"
|
|
" }\n"
|
|
"\n"
|
|
" if (a.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 < a.length; i++) {\n"
|
|
" s += indent + toJson(a[i], indent , useNL);\n"
|
|
"\n"
|
|
" if (i < a.length - 1) {\n"
|
|
" s += \",\" + nl;\n"
|
|
" }\n"
|
|
" }\n"
|
|
"\n"
|
|
" s += nl + oldIndent + \"]\";\n"
|
|
"\n"
|
|
" return s;\n"
|
|
"}\n"
|
|
"\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"/// @brief JSON representation of an object\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"\n"
|
|
"toJsonObject = function(x, indent , useNL) {\n"
|
|
" var nl = useNL ? \"\\n\" : \" \";\n"
|
|
" \n"
|
|
" if (! indent) {\n"
|
|
" indent = \"\";\n"
|
|
" }\n"
|
|
" \n"
|
|
" if (typeof(x.toJson) == \"function\" && x.toJson != toJson) {\n"
|
|
" return indent + x.toJson(indent, useNL);\n"
|
|
" }\n"
|
|
" \n"
|
|
" if (x.constructor && typeof(x.constructor.toJson) == \"function\" && x.constructor.toJson != toJson) {\n"
|
|
" return x.constructor.toJson(x, indent , useNL);\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"
|
|
" }\n"
|
|
"\n"
|
|
" var sep = \"\";\n"
|
|
"\n"
|
|
" for (var k in x) {\n"
|
|
" var val = x[k];\n"
|
|
"\n"
|
|
" s += sep + indent + \"\\\"\" + k + \"\\\" : \" + toJson(val, indent , useNL);\n"
|
|
" sep = \",\" + nl;\n"
|
|
" }\n"
|
|
"\n"
|
|
" // pop one level of indent\n"
|
|
" indent = oldIndent;\n"
|
|
"\n"
|
|
" return s + nl + indent + \"}\";\n"
|
|
"}\n"
|
|
"\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"/// @}\n"
|
|
"////////////////////////////////////////////////////////////////////////////////\n"
|
|
"\n"
|
|
"// Local Variables:\n"
|
|
"// mode: outline-minor\n"
|
|
"// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\)\"\n"
|
|
"// End:\n"
|
|
;
|