From 5d79b618c75b35d155be29b6eb5516cbd0ce9653 Mon Sep 17 00:00:00 2001 From: Oreste Panaia Date: Mon, 1 Oct 2012 18:36:42 +0800 Subject: [PATCH] strings converted to char* --- js/client/js-client.h | 5521 +++++++++++++++--------------- js/common/bootstrap/js-errors.h | 283 +- js/common/bootstrap/js-modules.h | 1275 +++---- js/common/bootstrap/js-print.h | 667 ++-- js/server/js-ahuacatl.h | 4433 ++++++++++++------------ js/server/js-server.h | 1175 +++---- lib/Utilities/ScriptLoader.cpp | 17 + lib/Utilities/ScriptLoader.h | 2 + 8 files changed, 6699 insertions(+), 6674 deletions(-) diff --git a/js/client/js-client.h b/js/client/js-client.h index 28fd786ca8..b7f91c7c3b 100644 --- a/js/client/js-client.h +++ b/js/client/js-client.h @@ -1,2760 +1,2761 @@ -static string JS_client_client = string("") - + "/*jslint indent: 2,\n" - + " nomen: true,\n" - + " maxlen: 100,\n" - + " sloppy: true,\n" - + " vars: true,\n" - + " white: true,\n" - + " plusplus: true */\n" - + "/*global require, arango, db, edges, ModuleCache, Module */\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief ArangoShell client API\n" - + "///\n" - + "/// @file\n" - + "///\n" - + "/// DISCLAIMER\n" - + "///\n" - + "/// Copyright 2012 triagens GmbH, Cologne, Germany\n" - + "///\n" - + "/// Licensed under the Apache License, Version 2.0 (the \"License\");\n" - + "/// you may not use this file except in compliance with the License.\n" - + "/// You may obtain a copy of the License at\n" - + "///\n" - + "/// http://www.apache.org/licenses/LICENSE-2.0\n" - + "///\n" - + "/// Unless required by applicable law or agreed to in writing, software\n" - + "/// distributed under the License is distributed on an \"AS IS\" BASIS,\n" - + "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" - + "/// See the License for the specific language governing permissions and\n" - + "/// limitations under the License.\n" - + "///\n" - + "/// Copyright holder is triAGENS GmbH, Cologne, Germany\n" - + "///\n" - + "/// @author Achim Brandt\n" - + "/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- ArangoError\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- constructors and destructors\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief constructor\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function ArangoError (error) {\n" - + " if (error !== undefined) {\n" - + " this.error = error.error;\n" - + " this.code = error.code;\n" - + " this.errorNum = error.errorNum;\n" - + " this.errorMessage = error.errorMessage;\n" - + " }\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- private functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "(function () {\n" - + " var internal = require(\"internal\");\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief prints an error\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoError.prototype._PRINT = function() {\n" - + " internal.output(this.toString());\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief toString function\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoError.prototype.toString = function() {\n" - + " var result = \"\";\n" - + "\n" - + " if (internal.COLOR_OUTPUT) {\n" - + " result = internal.COLOR_BRIGHT + \"Error: \" + internal.COLOR_OUTPUT_RESET;\n" - + " }\n" - + " else {\n" - + " result = \"Error: \";\n" - + " }\n" - + "\n" - + " result += \"[\" + this.code + \":\" + this.errorNum + \"] \" + this.errorMessage;\n" - + "\n" - + " return result;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief prints an error\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoError.prototype.toString = function() {\n" - + " var errorNum = this.errorNum;\n" - + " var errorMessage = this.errorMessage;\n" - + "\n" - + " return \"[ArangoError \" + errorNum + \": \" + errorMessage + \"]\";\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "}());\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- Module \"arangosh\"\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8ModuleArangosh\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "ModuleCache[\"/arangosh\"] = new Module(\"/arangosh\");\n" - + "\n" - + "(function () {\n" - + " var internal = require(\"internal\");\n" - + " var client = ModuleCache[\"/arangosh\"].exports;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- private variables\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief help texts\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " client.HELP = \"\";\n" - + " client.helpQueries = \"\";\n" - + " client.helpArangoDatabase = \"\";\n" - + " client.helpArangoCollection = \"\";\n" - + " client.helpArangoQueryCursor = \"\";\n" - + " client.helpArangoStatement = \"\";\n" - + " client.helpExtended = \"\";\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- private functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return a formatted type string for object\n" - + "/// \n" - + "/// If the object has an id, it will be included in the string.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " client.getIdString = function (object, typeName) {\n" - + " var result = \"[object \" + typeName;\n" - + " \n" - + " if (object._id) {\n" - + " result += \":\" + object._id;\n" - + " }\n" - + " else if (object.data && object.data._id) {\n" - + " result += \":\" + object.data._id;\n" - + " }\n" - + "\n" - + " result += \"]\";\n" - + "\n" - + " return result;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief handles error results\n" - + "/// \n" - + "/// throws an exception in case of an an error\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " client.checkRequestResult = function (requestResult) {\n" - + " if (requestResult === undefined) {\n" - + " requestResult = {\n" - + " \"error\" : true,\n" - + " \"code\" : 0,\n" - + " \"errorNum\" : 0,\n" - + " \"errorMessage\" : \"Unknown error. Request result is empty\"\n" - + " };\n" - + " }\n" - + " \n" - + " if (requestResult.error !== undefined && requestResult.error) { \n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief create a formatted headline text \n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " client.createHelpHeadline = function (text) {\n" - + " var i;\n" - + " var p = \"\";\n" - + " var x = parseInt(Math.abs(78 - text.length) / 2);\n" - + "\n" - + " for (i = 0; i < x; ++i) {\n" - + " p += \"-\";\n" - + " }\n" - + " \n" - + " return \"\\n\" + p + \" \" + text + \" \" + p + \"\\n\";\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "}());\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- public functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief turn off pretty printing\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function print_plain (data) {\n" - + " var internal = require(\"internal\");\n" - + "\n" - + " var p = internal.PRETTY_PRINT;\n" - + " internal.PRETTY_PRINT = false;\n" - + "\n" - + " var c = internal.COLOR_OUTPUT;\n" - + " internal.COLOR_OUTPUT = false;\n" - + " \n" - + " try {\n" - + " internal.print(data);\n" - + "\n" - + " internal.PRETTY_PRINT = p;\n" - + " internal.COLOR_OUTPUT = c;\n" - + " }\n" - + " catch (e) {\n" - + " internal.PRETTY_PRINT = p;\n" - + " internal.COLOR_OUTPUT = c;\n" - + "\n" - + " throw e.message; \n" - + " } \n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief start pretty printing\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function start_pretty_print () {\n" - + " var internal = require(\"internal\");\n" - + "\n" - + " if (! internal.PRETTY_PRINT) {\n" - + " internal.print(\"using pretty printing\");\n" - + " internal.PRETTY_PRINT = true;\n" - + " }\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief stop pretty printing\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function stop_pretty_print () {\n" - + " var internal = require(\"internal\");\n" - + "\n" - + " if (internal.PRETTY_PRINT) {\n" - + " internal.PRETTY_PRINT = false;\n" - + " internal.print(\"stop pretty printing\");\n" - + " }\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief start paging\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function start_pager () {\n" - + " var internal = require(\"internal\");\n" - + "\n" - + " internal.start_pager();\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief stop paging\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function stop_pager () {\n" - + " var internal = require(\"internal\");\n" - + " \n" - + " internal.stop_pager();\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief start pretty printing with optional color\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function start_color_print (color) {\n" - + " var internal = require(\"internal\");\n" - + "\n" - + " if (typeof(color) === \"string\") {\n" - + " internal.COLOR_OUTPUT_DEFAULT = color;\n" - + " }\n" - + " else {\n" - + " internal.COLOR_OUTPUT_DEFAULT = internal.COLOR_BRIGHT;\n" - + " }\n" - + "\n" - + " internal.COLOR_OUTPUT = true;\n" - + "\n" - + " internal.print(\"start \"\n" - + " + internal.COLOR_OUTPUT_DEFAULT\n" - + " + \"color\" \n" - + " + internal.COLOR_OUTPUT_RESET\n" - + " + \" printing\");\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief stop pretty printing\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function stop_color_print () {\n" - + " var internal = require(\"internal\");\n" - + "\n" - + " internal.print(\"stop color printing\");\n" - + " internal.COLOR_OUTPUT = false;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief print the overall help\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function help () {\n" - + " var internal = require(\"internal\");\n" - + " var client = require(\"arangosh\");\n" - + "\n" - + " internal.print(client.HELP);\n" - + " internal.print(client.helpQueries);\n" - + " internal.print(client.helpArangoDatabase);\n" - + " internal.print(client.helpArangoCollection);\n" - + " internal.print(client.helpArangoStatement);\n" - + " internal.print(client.helpArangoQueryCursor);\n" - + " internal.print(client.helpExtended);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- Module \"internal\"\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "(function () {\n" - + " var internal = require(\"internal\");\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief be quiet\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.ARANGO_QUIET = ARANGO_QUIET;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief log function\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.log = function (level, msg) {\n" - + " internal.output(level, \": \", msg, \"\\n\");\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief rebuilds the routing cache\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.reloadRouting = function () {\n" - + " if (typeof arango !== 'undefined') {\n" - + " arango.POST(\"/_admin/reloadRouting\", \"\");\n" - + " }\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "}());\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- ArangoQueryCursor\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- constructors and destructors\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief constructor\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function ArangoQueryCursor (database, data) {\n" - + " this._database = database;\n" - + " this.data = data;\n" - + " this._hasNext = false;\n" - + " this._hasMore = false;\n" - + " this._pos = 0;\n" - + " this._count = 0;\n" - + " this._total = 0;\n" - + " \n" - + " if (data.result !== undefined) {\n" - + " this._count = data.result.length;\n" - + " \n" - + " if (this._pos < this._count) {\n" - + " this._hasNext = true;\n" - + " }\n" - + " \n" - + " if (data.hasMore !== undefined && data.hasMore) {\n" - + " this._hasMore = true;\n" - + " } \n" - + " }\n" - + "}\n" - + "\n" - + "(function () {\n" - + " var internal = require(\"internal\");\n" - + " var client = require(\"arangosh\");\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- private functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief help for ArangoQueryCursor\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " client.helpArangoQueryCursor = client.createHelpHeadline(\"ArangoQueryCursor help\") +\n" - + " 'ArangoQueryCursor constructor: ' + \"\\n\" +\n" - + " ' > cu1 = qi1.execute(); ' + \"\\n\" +\n" - + " 'Functions: ' + \"\\n\" +\n" - + " ' hasNext(); returns true if there ' + \"\\n\" +\n" - + " ' are more results ' + \"\\n\" +\n" - + " ' next(); returns the next document ' + \"\\n\" +\n" - + " ' elements(); returns all documents ' + \"\\n\" +\n" - + " ' _help(); this help ' + \"\\n\" +\n" - + " 'Attributes: ' + \"\\n\" +\n" - + " ' _database database object ' + \"\\n\" +\n" - + " 'Example: ' + \"\\n\" +\n" - + " ' > st = db._createStatement({ \"query\" : \"for c in coll return c\" });' + \"\\n\" +\n" - + " ' > c = st.execute(); ' + \"\\n\" +\n" - + " ' > documents = c.elements(); ' + \"\\n\" +\n" - + " ' > c = st.execute(); ' + \"\\n\" +\n" - + " ' > while (c.hasNext()) { print( c.next() ); } ';\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief print the help for the cursor\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoQueryCursor.prototype._help = function () {\n" - + " internal.print(client.helpArangoQueryCursor);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return a string representation of the cursor\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoQueryCursor.prototype.toString = function () { \n" - + " return client.getIdString(this, \"ArangoQueryCursor\");\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- public functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return whether there are more results available in the cursor\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoQueryCursor.prototype.hasNext = function () {\n" - + " return this._hasNext;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return the next result document from the cursor\n" - + "///\n" - + "/// If no more results are available locally but more results are available on\n" - + "/// the server, this function will make a roundtrip to the server\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoQueryCursor.prototype.next = function () {\n" - + " if (!this._hasNext) {\n" - + " throw \"No more results\";\n" - + " }\n" - + "\n" - + " var result = this.data.result[this._pos];\n" - + " this._pos++;\n" - + "\n" - + " // reached last result\n" - + " if (this._pos === this._count) {\n" - + " this._hasNext = false;\n" - + " this._pos = 0;\n" - + "\n" - + " if (this._hasMore && this.data.id) {\n" - + " this._hasMore = false;\n" - + "\n" - + " // load more results \n" - + " var requestResult = this._database._connection.PUT(\n" - + " \"/_api/cursor/\"+ encodeURIComponent(this.data.id),\n" - + " \"\");\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " this.data = requestResult;\n" - + " this._count = requestResult.result.length;\n" - + "\n" - + " if (this._pos < this._count) {\n" - + " this._hasNext = true;\n" - + " }\n" - + "\n" - + " if (requestResult.hasMore !== undefined && requestResult.hasMore) {\n" - + " this._hasMore = true;\n" - + " } \n" - + " } \n" - + " }\n" - + "\n" - + " return result;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return all remaining result documents from the cursor\n" - + "///\n" - + "/// If no more results are available locally but more results are available on\n" - + "/// the server, this function will make one or multiple roundtrips to the \n" - + "/// server. Calling this function will also fully exhaust the cursor.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoQueryCursor.prototype.elements = function () { \n" - + " var result = [];\n" - + "\n" - + " while (this.hasNext()) { \n" - + " result.push( this.next() ); \n" - + " }\n" - + "\n" - + " return result;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief explicitly dispose the cursor\n" - + "///\n" - + "/// Calling this function will mark the cursor as deleted on the server. It will\n" - + "/// therefore make a roundtrip to the server. Using a cursor after it has been\n" - + "/// disposed is considered a user error\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoQueryCursor.prototype.dispose = function () {\n" - + " if (!this.data.id) {\n" - + " // client side only cursor\n" - + " return;\n" - + " }\n" - + "\n" - + " var requestResult = this._database._connection.DELETE(\n" - + " \"/_api/cursor/\"+ encodeURIComponent(this.data.id),\n" - + " \"\");\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " this.data.id = undefined;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return the total number of documents in the cursor\n" - + "///\n" - + "/// The number will remain the same regardless how much result documents have\n" - + "/// already been fetched from the cursor.\n" - + "///\n" - + "/// This function will return the number only if the cursor was constructed \n" - + "/// with the \"doCount\" attribute. Otherwise it will return undefined.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoQueryCursor.prototype.count = function () {\n" - + " if (!this.data.id) {\n" - + " throw \"cursor has been disposed\";\n" - + " }\n" - + "\n" - + " return this.data.count;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "}());\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- ArangoStatement\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- constructors and destructors\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief constructor\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function ArangoStatement (database, data) {\n" - + " this._database = database;\n" - + " this._doCount = false;\n" - + " this._batchSize = null;\n" - + " this._bindVars = {};\n" - + " \n" - + " if (!(data instanceof Object)) {\n" - + " throw \"ArangoStatement needs initial data\";\n" - + " }\n" - + " \n" - + " if (data.query === undefined || data.query === \"\") {\n" - + " throw \"ArangoStatement needs a valid query attribute\";\n" - + " }\n" - + " this.setQuery(data.query);\n" - + "\n" - + " if (data.count !== undefined) {\n" - + " this.setCount(data.count);\n" - + " }\n" - + " if (data.batchSize !== undefined) {\n" - + " this.setBatchSize(data.batchSize);\n" - + " }\n" - + "}\n" - + "\n" - + "(function () {\n" - + " var internal = require(\"internal\");\n" - + " var client = require(\"arangosh\");\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- private functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief help for ArangoStatement\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " client.helpArangoStatement = client.createHelpHeadline(\"ArangoStatement help\") +\n" - + " 'ArangoStatement constructor: ' + \"\\n\" +\n" - + " ' > st = new ArangoStatement(db, { \"query\" : \"for ...\" }); ' + \"\\n\" +\n" - + " ' > st = db._createStatement({ \"query\" : \"for ...\" }); ' + \"\\n\" +\n" - + " 'Functions: ' + \"\\n\" +\n" - + " ' bind(, ); bind single variable ' + \"\\n\" +\n" - + " ' bind(); bind multiple variables ' + \"\\n\" +\n" - + " ' setBatchSize(); set max. number of results ' + \"\\n\" +\n" - + " ' to be transferred per roundtrip ' + \"\\n\" +\n" - + " ' setCount(); set count flag (return number of ' + \"\\n\" +\n" - + " ' results in \"count\" attribute) ' + \"\\n\" +\n" - + " ' getBatchSize(); return max. number of results ' + \"\\n\" +\n" - + " ' to be transferred per roundtrip ' + \"\\n\" +\n" - + " ' getCount(); return count flag (return number of' + \"\\n\" +\n" - + " ' results in \"count\" attribute) ' + \"\\n\" +\n" - + " ' getQuery(); return query string ' + \"\\n\" +\n" - + " ' execute(); execute query and return cursor ' + \"\\n\" +\n" - + " ' _help(); this help ' + \"\\n\" +\n" - + " 'Attributes: ' + \"\\n\" +\n" - + " ' _database database object ' + \"\\n\" +\n" - + " 'Example: ' + \"\\n\" +\n" - + " ' > st = db._createStatement({ \"query\" : \"for c in coll filter ' + \"\\n\" +\n" - + " ' c.x == @a && c.y == @b return c\" }); ' + \"\\n\" +\n" - + " ' > st.bind(\"a\", \"hello\"); ' + \"\\n\" +\n" - + " ' > st.bind(\"b\", \"world\"); ' + \"\\n\" +\n" - + " ' > c = st.execute(); ' + \"\\n\" +\n" - + " ' > print(c.elements()); ';\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief print the help for ArangoStatement\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoStatement.prototype._help = function () {\n" - + " internal.print(client.helpArangoStatement);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return a string representation of the statement\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoStatement.prototype.toString = function () { \n" - + " return client.getIdString(this, \"ArangoStatement\");\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- public functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief bind a parameter to the statement\n" - + "///\n" - + "/// This function can be called multiple times, once for each bind parameter.\n" - + "/// All bind parameters will be transferred to the server in one go when \n" - + "/// execute() is called.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoStatement.prototype.bind = function (key, value) {\n" - + " if (key instanceof Object) {\n" - + " if (value !== undefined) {\n" - + " throw \"invalid bind parameter declaration\";\n" - + " }\n" - + "\n" - + " this._bindVars = key;\n" - + " }\n" - + " else if (typeof(key) === \"string\") {\n" - + " if (this._bindVars[key] !== undefined) {\n" - + " throw \"redeclaration of bind parameter\";\n" - + " }\n" - + "\n" - + " this._bindVars[key] = value;\n" - + " }\n" - + " else if (typeof(key) === \"number\") {\n" - + " var strKey = String(parseInt(key));\n" - + "\n" - + " if (strKey !== String(key)) {\n" - + " throw \"invalid bind parameter declaration\";\n" - + " }\n" - + "\n" - + " if (this._bindVars[strKey] !== undefined) {\n" - + " throw \"redeclaration of bind parameter\";\n" - + " }\n" - + "\n" - + " this._bindVars[strKey] = value;\n" - + " }\n" - + " else {\n" - + " throw \"invalid bind parameter declaration\";\n" - + " }\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return the bind variables already set\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoStatement.prototype.getBindVariables = function () {\n" - + " return this._bindVars;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get the count flag for the statement\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoStatement.prototype.getCount = function () {\n" - + " return this._doCount;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get the maximum number of results documents the cursor will return\n" - + "/// in a single server roundtrip.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoStatement.prototype.getBatchSize = function () {\n" - + " return this._batchSize;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get query string\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoStatement.prototype.getQuery = function () {\n" - + " return this._query;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief set the count flag for the statement\n" - + "///\n" - + "/// Setting the count flag will make the statement's result cursor return the\n" - + "/// total number of result documents. The count flag is not set by default.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoStatement.prototype.setCount = function (bool) {\n" - + " this._doCount = bool ? true : false;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief set the maximum number of results documents the cursor will return\n" - + "/// in a single server roundtrip.\n" - + "/// The higher this number is, the less server roundtrips will be made when\n" - + "/// iterating over the result documents of a cursor.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoStatement.prototype.setBatchSize = function (value) {\n" - + " if (parseInt(value) > 0) {\n" - + " this._batchSize = parseInt(value);\n" - + " }\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief set the query string\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoStatement.prototype.setQuery = function (query) {\n" - + " this._query = query;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief parse a query and return the results\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoStatement.prototype.parse = function () {\n" - + " var body = {\n" - + " \"query\" : this._query,\n" - + " };\n" - + "\n" - + " var requestResult = this._database._connection.POST(\n" - + " \"/_api/query\",\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return true;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief execute the query\n" - + "///\n" - + "/// Invoking execute() will transfer the query and all bind parameters to the\n" - + "/// server. It will return a cursor with the query results in case of success.\n" - + "/// In case of an error, the error will be printed\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoStatement.prototype.execute = function () {\n" - + " var body = {\n" - + " \"query\" : this._query,\n" - + " \"count\" : this._doCount,\n" - + " \"bindVars\" : this._bindVars\n" - + " };\n" - + "\n" - + " if (this._batchSize) {\n" - + " body[\"batchSize\"] = this._batchSize;\n" - + " }\n" - + "\n" - + " var requestResult = this._database._connection.POST(\n" - + " \"/_api/cursor\",\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return new ArangoQueryCursor(this._database, requestResult);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "}());\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- ArangoCollection\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- constructors and destructors\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief constructor\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function ArangoCollection (database, data) {\n" - + " this._database = database;\n" - + "\n" - + " if (typeof data === \"string\") {\n" - + " this._id = null;\n" - + " this._name = data;\n" - + " this._status = null;\n" - + " this._type = null;\n" - + " }\n" - + " else if (data !== undefined) {\n" - + " this._id = data.id;\n" - + " this._name = data.name;\n" - + " this._status = data.status;\n" - + " this._type = data.type;\n" - + " }\n" - + " else {\n" - + " this._id = null;\n" - + " this._name = null;\n" - + " this._status = null;\n" - + " this._type = null;\n" - + " }\n" - + "}\n" - + "\n" - + "(function () {\n" - + " var internal = require(\"internal\");\n" - + " var client = require(\"arangosh\");\n" - + "\n" - + " internal.ArangoCollection = ArangoCollection;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- constants\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief collection is corrupted\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.STATUS_CORRUPTED = 0;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief collection is new born\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.STATUS_NEW_BORN = 1;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief collection is unloaded\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.STATUS_UNLOADED = 2;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief collection is loaded\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.STATUS_LOADED = 3;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief collection is unloading\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.STATUS_UNLOADING = 4;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief collection is deleted\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.STATUS_DELETED = 5;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief document collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + " \n" - + " ArangoCollection.TYPE_DOCUMENT = 2;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief edge collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.TYPE_EDGE = 3;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief attachment collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.TYPE_ATTACHMENT = 4;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- private functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief help for ArangoCollection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " client.helpArangoCollection = client.createHelpHeadline(\"ArangoCollection help\") +\n" - + " 'ArangoCollection constructor: ' + \"\\n\" +\n" - + " ' > col = db.mycoll; ' + \"\\n\" +\n" - + " ' > col = db._create(\"mycoll\"); ' + \"\\n\" +\n" - + " ' ' + \"\\n\" +\n" - + " 'Administration Functions: ' + \"\\n\" +\n" - + " ' name() collection name ' + \"\\n\" +\n" - + " ' status() status of the collection ' + \"\\n\" +\n" - + " ' type() type of the collection ' + \"\\n\" +\n" - + " ' truncate() delete all documents ' + \"\\n\" +\n" - + " ' properties() show collection properties ' + \"\\n\" +\n" - + " ' drop() delete a collection ' + \"\\n\" +\n" - + " ' load() load a collection into memeory ' + \"\\n\" +\n" - + " ' unload() unload a collection from memory ' + \"\\n\" +\n" - + " ' rename(new-name) renames a collection ' + \"\\n\" +\n" - + " ' refresh() refreshes the status and name ' + \"\\n\" +\n" - + " ' _help(); this help ' + \"\\n\" +\n" - + " ' ' + \"\\n\" +\n" - + " 'Document Functions: ' + \"\\n\" +\n" - + " ' count() number of documents ' + \"\\n\" +\n" - + " ' save() create document and return handle ' + \"\\n\" +\n" - + " ' document() get document by handle ' + \"\\n\" +\n" - + " ' replace(, , overwrite document ' + \"\\n\" +\n" - + " ' ) ' + \"\\n\" +\n" - + " ' update(, , partially update document ' + \"\\n\" +\n" - + " ' , ) ' + \"\\n\" +\n" - + " ' delete() delete document ' + \"\\n\" +\n" - + " ' ' + \"\\n\" +\n" - + " 'Attributes: ' + \"\\n\" +\n" - + " ' _database database object ' + \"\\n\" +\n" - + " ' _id collection identifier ';\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return a string representation of the collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.toString = function () { \n" - + " return client.getIdString(this, \"ArangoCollection\");\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief prints the collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype._PRINT = function () { \n" - + " var status = type = \"unknown\";\n" - + "\n" - + " switch (this.status()) {\n" - + " case ArangoCollection.STATUS_NEW_BORN: status = \"new born\"; break;\n" - + " case ArangoCollection.STATUS_UNLOADED: status = \"unloaded\"; break;\n" - + " case ArangoCollection.STATUS_UNLOADING: status = \"unloading\"; break;\n" - + " case ArangoCollection.STATUS_LOADED: status = \"loaded\"; break;\n" - + " case ArangoCollection.STATUS_CORRUPTED: status = \"corrupted\"; break;\n" - + " case ArangoCollection.STATUS_DELETED: status = \"deleted\"; break;\n" - + " }\n" - + "\n" - + " switch (this.type()) {\n" - + " case ArangoCollection.TYPE_DOCUMENT: type = \"document\"; break;\n" - + " case ArangoCollection.TYPE_EDGE: type = \"edge\"; break;\n" - + " case ArangoCollection.TYPE_ATTACHMENT: type = \"attachment\"; break;\n" - + " }\n" - + "\n" - + " internal.output(\"[ArangoCollection \",\n" - + " this._id, \n" - + " \", \\\"\", \n" - + " this.name(), \n" - + " \"\\\" (type \",\n" - + " type, \", status \",\n" - + " status,\n" - + " \")]\");\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief print the help for ArangoCollection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype._help = function () { \n" - + " internal.print(client.helpArangoCollection);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- public functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief returns the name of a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.name = function () {\n" - + " if (this._name === null) {\n" - + " this.refresh();\n" - + " }\n" - + "\n" - + " return this._name;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief returns the status of a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.status = function () {\n" - + " var result;\n" - + "\n" - + " if (this._status === null) {\n" - + " this.refresh();\n" - + " }\n" - + "\n" - + " // save original status\n" - + " result = this._status;\n" - + "\n" - + " if (this._status == ArangoCollection.STATUS_UNLOADING) {\n" - + " // if collection is currently unloading, we must not cache this info\n" - + " this._status = null;\n" - + " }\n" - + "\n" - + " // return the correct result\n" - + " return result;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief returns the type of a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.type = function () {\n" - + " var result;\n" - + "\n" - + " if (this._type === null) {\n" - + " this.refresh();\n" - + " }\n" - + "\n" - + " return this._type;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief gets or sets the properties of a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.properties = function (properties) {\n" - + " var requestResult;\n" - + "\n" - + " if (properties === undefined) {\n" - + " requestResult = this._database._connection.GET(\n" - + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/properties\");\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + " }\n" - + " else {\n" - + " var body = {};\n" - + "\n" - + " if (properties.hasOwnProperty(\"waitForSync\")) {\n" - + " body.waitForSync = properties.waitForSync;\n" - + " }\n" - + "\n" - + " requestResult = this._database._connection.PUT(\n" - + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/properties\",\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + " }\n" - + "\n" - + " return { \n" - + " waitForSync : requestResult.waitForSync,\n" - + " journalSize : requestResult.journalSize\n" - + " };\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief gets the figures of a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.figures = function () {\n" - + " var requestResult = this._database._connection.GET(\n" - + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/figures\");\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult.figures;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief drops a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.drop = function () {\n" - + " var requestResult = this._database._connection.DELETE(\n" - + " \"/_api/collection/\" + encodeURIComponent(this._id));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " this._status = ArangoCollection.STATUS_DELETED;\n" - + "\n" - + " var database = this._database;\n" - + " var name;\n" - + "\n" - + " for (name in database) {\n" - + " if (database.hasOwnProperty(name)) {\n" - + " var collection = database[name];\n" - + "\n" - + " if (collection instanceof ArangoCollection) {\n" - + " if (collection._id === this._id) {\n" - + " delete database[name];\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief returns all documents\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.toArray = function () {\n" - + " return this.all().toArray();\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief returns all indexes\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.getIndexes = function () {\n" - + " var requestResult = this._database._connection.GET(\n" - + " \"/_api/index?collection=\" + encodeURIComponent(this._id));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult.indexes;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief returns one index\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.index = function (id) {\n" - + " if (id.hasOwnProperty(\"id\")) {\n" - + " id = id.id;\n" - + " }\n" - + "\n" - + " var requestResult;\n" - + " var s = id.split(\"/\");\n" - + "\n" - + " if (s.length !== 2) {\n" - + " requestResult = {\n" - + " errorNum: internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code,\n" - + " errorMessage: internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message\n" - + " };\n" - + "\n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + " else if (parseInt(s[0]) !== this._id) {\n" - + " requestResult = {\n" - + " errorNum: internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code,\n" - + " errorMessage: \n" - + " internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.message\n" - + " };\n" - + "\n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + "\n" - + " requestResult = this._database._connection.GET(\"/_api/index/\" + id);\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief deletes one index\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.dropIndex = function (id) {\n" - + " if (id.hasOwnProperty(\"id\")) {\n" - + " id = id.id;\n" - + " }\n" - + "\n" - + " var requestResult;\n" - + " var s = id.split(\"/\");\n" - + "\n" - + " if (s.length !== 2) {\n" - + " requestResult = {\n" - + " errorNum: internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code,\n" - + " errorMessage: internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message\n" - + " };\n" - + "\n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + " else if (parseInt(s[0]) !== this._id) {\n" - + " requestResult = {\n" - + " errorNum: internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code,\n" - + " errorMessage:\n" - + " internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.message\n" - + " };\n" - + "\n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + "\n" - + " requestResult = this._database._connection.DELETE(\"/_api/index/\" + id);\n" - + "\n" - + " if (requestResult !== null\n" - + " && requestResult.error === true \n" - + " && requestResult.errorNum\n" - + " === internal.errors.ERROR_ARANGO_INDEX_NOT_FOUND.code) {\n" - + " return false;\n" - + " }\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return true;\n" - + " };\n" - + "\n" - + " \n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief adds a bitarray index\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.ensureBitarray = function () {\n" - + " var i;\n" - + " var body;\n" - + " var fields = [];\n" - + "\n" - + " for (i = 0; i < arguments.length; ++i) {\n" - + " fields.push(arguments[i]);\n" - + " }\n" - + "\n" - + " body = { type : \"bitarray\", unique : false, fields : fields };\n" - + "\n" - + " var requestResult = this._database._connection.POST(\n" - + " \"/_api/index?collection=\" + encodeURIComponent(this._id),\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + " \n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief adds a cap constraint\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.ensureCapConstraint = function (size) {\n" - + " var body;\n" - + "\n" - + " body = { type : \"cap\", size : size };\n" - + "\n" - + " var requestResult = this._database._connection.POST(\n" - + " \"/_api/index?collection=\" + encodeURIComponent(this._id),\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief adds a unique skip-list index\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.ensureUniqueSkiplist = function () {\n" - + " var i;\n" - + " var body;\n" - + " var fields = [];\n" - + "\n" - + " for (i = 0; i < arguments.length; ++i) {\n" - + " fields.push(arguments[i]);\n" - + " }\n" - + "\n" - + " body = { type : \"skiplist\", unique : true, fields : fields };\n" - + "\n" - + " var requestResult = this._database._connection.POST(\n" - + " \"/_api/index?collection=\" + encodeURIComponent(this._id),\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief adds a skip-list index\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.ensureSkiplist = function () {\n" - + " var i;\n" - + " var body;\n" - + " var fields = [];\n" - + "\n" - + " for (i = 0; i < arguments.length; ++i) {\n" - + " fields.push(arguments[i]);\n" - + " }\n" - + "\n" - + " body = { type : \"skiplist\", unique : false, fields : fields };\n" - + "\n" - + " var requestResult = this._database._connection.POST(\n" - + " \"/_api/index?collection=\" + encodeURIComponent(this._id),\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief adds a unique constraint\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.ensureUniqueConstraint = function () {\n" - + " var i;\n" - + " var body;\n" - + " var fields = [];\n" - + "\n" - + " for (i = 0; i < arguments.length; ++i) {\n" - + " fields.push(arguments[i]);\n" - + " }\n" - + "\n" - + " body = { type : \"hash\", unique : true, fields : fields };\n" - + "\n" - + " var requestResult = this._database._connection.POST(\n" - + " \"/_api/index?collection=\" + encodeURIComponent(this._id),\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief adds a hash index\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.ensureHashIndex = function () {\n" - + " var i;\n" - + " var body;\n" - + " var fields = [];\n" - + "\n" - + " for (i = 0; i < arguments.length; ++i) {\n" - + " fields.push(arguments[i]);\n" - + " }\n" - + "\n" - + " body = { type : \"hash\", unique : false, fields : fields };\n" - + "\n" - + " var requestResult = this._database._connection.POST(\n" - + " \"/_api/index?collection=\" + encodeURIComponent(this._id),\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief adds an geo index\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.ensureGeoIndex = function (lat, lon) {\n" - + " var body;\n" - + "\n" - + " if (typeof lat !== \"string\") {\n" - + " throw \"usage: ensureGeoIndex(, ) or ensureGeoIndex([, ])\";\n" - + " }\n" - + "\n" - + " if (typeof lon === \"boolean\") {\n" - + " body = { \n" - + " type : \"geo\", \n" - + " fields : [ lat ], \n" - + " geoJson : lon, \n" - + " constraint : false\n" - + " };\n" - + " }\n" - + " else if (lon === undefined) {\n" - + " body = {\n" - + " type : \"geo\", \n" - + " fields : [ lat ],\n" - + " geoJson : false, \n" - + " constraint : false \n" - + " };\n" - + " }\n" - + " else {\n" - + " body = {\n" - + " type : \"geo\",\n" - + " fields : [ lat, lon ],\n" - + " constraint : false\n" - + " };\n" - + " }\n" - + "\n" - + " var requestResult = this._database._connection.POST(\n" - + " \"/_api/index?collection=\" + encodeURIComponent(this._id), \n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief adds an geo constraint\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.ensureGeoConstraint = function (lat, lon, ignoreNull) {\n" - + " var body;\n" - + "\n" - + " // only two parameter\n" - + " if (ignoreNull === undefined) {\n" - + " ignoreNull = lon;\n" - + "\n" - + " if (typeof ignoreNull !== \"boolean\") {\n" - + " throw \"usage: ensureGeoConstraint(, , )\"\n" - + " + \" or ensureGeoConstraint(, , )\";\n" - + " }\n" - + "\n" - + " body = {\n" - + " type : \"geo\",\n" - + " fields : [ lat ],\n" - + " geoJson : false, \n" - + " constraint : true,\n" - + " ignoreNull : ignoreNull \n" - + " };\n" - + " }\n" - + "\n" - + " // three parameter\n" - + " else {\n" - + " if (typeof lon === \"boolean\") {\n" - + " body = {\n" - + " type : \"geo\",\n" - + " fields : [ lat ],\n" - + " geoJson : lon,\n" - + " constraint : true,\n" - + " ignoreNull : ignoreNull\n" - + " };\n" - + " }\n" - + " else {\n" - + " body = {\n" - + " type : \"geo\",\n" - + " fields : [ lat, lon ],\n" - + " constraint : true,\n" - + " ignoreNull : ignoreNull\n" - + " };\n" - + " }\n" - + " }\n" - + "\n" - + " var requestResult = this._database._connection.POST(\n" - + " \"/_api/index?collection=\" + encodeURIComponent(this._id),\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief queries by example\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.BY_EXAMPLE_HASH = function (index, example, skip, limit) {\n" - + " var key;\n" - + " var body;\n" - + "\n" - + " limit = limit || null;\n" - + " skip = skip || null;\n" - + "\n" - + " if (index.hasOwnProperty(\"id\")) {\n" - + " index = index.id;\n" - + " }\n" - + "\n" - + " body = {\n" - + " collection : this._id,\n" - + " index : index,\n" - + " skip : skip,\n" - + " limit : limit,\n" - + " example : {} \n" - + " };\n" - + "\n" - + " for (key in example) {\n" - + " if (example.hasOwnProperty(key)) {\n" - + " body.example[key] = example[key];\n" - + " }\n" - + " }\n" - + "\n" - + " var requestResult = this._database._connection.PUT(\n" - + " \"/_api/simple/BY-EXAMPLE-HASH\",\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief truncates a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.truncate = function () {\n" - + " var requestResult = this._database._connection.PUT(\n" - + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/truncate\", \"\");\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " this._status = null;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief loads a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.load = function () {\n" - + " var requestResult = this._database._connection.PUT(\n" - + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/load\",\n" - + " \"\");\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " this._status = null;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief unloads a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.unload = function () {\n" - + " var requestResult = this._database._connection.PUT(\n" - + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/unload\",\n" - + " \"\");\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " this._status = null;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief renames a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.rename = function (name) {\n" - + " var body = { name : name };\n" - + " var requestResult = this._database._connection.PUT(\n" - + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/rename\",\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " delete this._database[this._name];\n" - + " this._database[name] = this;\n" - + "\n" - + " this._status = null;\n" - + " this._name = null;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief refreshes a collection status and name\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.refresh = function () {\n" - + " var requestResult = this._database._connection.GET(\n" - + " \"/_api/collection/\" + encodeURIComponent(this._id));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " this._name = requestResult['name'];\n" - + " this._status = requestResult['status'];\n" - + " this._type = requestResult['type'];\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- document functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief returns the number of documents\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.count = function () {\n" - + " var requestResult = this._database._connection.GET(\n" - + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/count\");\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult[\"count\"];\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return a single document from the collection, identified by its id\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.document = function (id) {\n" - + " var rev = null;\n" - + " var requestResult;\n" - + "\n" - + " if (id.hasOwnProperty(\"_id\")) {\n" - + " if (id.hasOwnProperty(\"_rev\")) {\n" - + " rev = id._rev;\n" - + " }\n" - + "\n" - + " id = id._id;\n" - + " }\n" - + "\n" - + " if (rev === null) {\n" - + " requestResult = this._database._connection.GET(\"/_api/document/\" + id);\n" - + " }\n" - + " else {\n" - + " requestResult = this._database._connection.GET(\n" - + " \"/_api/document/\" + id,\n" - + " {'if-match' : '\"' + rev + '\"' });\n" - + " }\n" - + "\n" - + " if (requestResult !== null\n" - + " && requestResult.error === true \n" - + " && requestResult.errorNum === internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code) {\n" - + " var s = id.split(\"/\");\n" - + "\n" - + " if (s.length !== 2) {\n" - + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" - + " }\n" - + " else if (parseInt(s[0]) !== this._id) {\n" - + " requestResult.errorNum = internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.code;\n" - + " }\n" - + "\n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief save a document in the collection, return its id\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.save = function () {\n" - + " var requestResult;\n" - + " var type = this.type();\n" - + " \n" - + " if (type == undefined) {\n" - + " type = ArangoCollection.TYPE_DOCUMENT;\n" - + " }\n" - + "\n" - + " if (type == ArangoCollection.TYPE_DOCUMENT) { \n" - + " var data = arguments[0];\n" - + "\n" - + " requestResult = this._database._connection.POST(\n" - + " \"/_api/document?collection=\" + encodeURIComponent(this._id),\n" - + " JSON.stringify(data));\n" - + " }\n" - + " else if (type == ArangoCollection.TYPE_EDGE) {\n" - + " var from = arguments[0];\n" - + " var to = arguments[1];\n" - + " var data = arguments[2];\n" - + "\n" - + " if (from.hasOwnProperty(\"_id\")) {\n" - + " from = from._id;\n" - + " }\n" - + "\n" - + " if (to.hasOwnProperty(\"_id\")) {\n" - + " to = to._id;\n" - + " }\n" - + "\n" - + " var url = \"/_api/edge?collection=\" + encodeURIComponent(this._id)\n" - + " + \"&from=\" + encodeURIComponent(from)\n" - + " + \"&to=\" + encodeURIComponent(to);\n" - + "\n" - + " requestResult = this._database._connection.POST(\n" - + " url,\n" - + " JSON.stringify(data));\n" - + " }\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief delete a document in the collection, identified by its id\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.remove = function (id, overwrite) {\n" - + " var rev = null;\n" - + " var requestResult;\n" - + "\n" - + " if (id.hasOwnProperty(\"_id\")) {\n" - + " if (id.hasOwnProperty(\"_rev\")) {\n" - + " rev = id._rev;\n" - + " }\n" - + "\n" - + " id = id._id;\n" - + " }\n" - + "\n" - + " var policy = \"\";\n" - + "\n" - + " if (overwrite) {\n" - + " policy = \"?policy=last\";\n" - + " }\n" - + "\n" - + " if (rev === null) {\n" - + " requestResult = this._database._connection.DELETE(\n" - + " \"/_api/document/\" + id + policy);\n" - + " }\n" - + " else {\n" - + " requestResult = this._database._connection.DELETE(\n" - + " \"/_api/document/\" + id + policy, {'if-match' : '\"' + rev + '\"' });\n" - + " }\n" - + "\n" - + " if (requestResult !== null && requestResult.error === true) {\n" - + " var s = id.split(\"/\");\n" - + "\n" - + " if (s.length !== 2) {\n" - + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" - + " }\n" - + " else if (parseInt(s[0]) !== this._id) {\n" - + " requestResult.errorNum = internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.code;\n" - + " }\n" - + "\n" - + " if (overwrite) {\n" - + " if (requestResult.errorNum === internal.errors.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code) {\n" - + " return false;\n" - + " }\n" - + " }\n" - + "\n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return true;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief replace a document in the collection, identified by its id\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.replace = function (id, data, overwrite) { \n" - + " var rev = null;\n" - + " var requestResult;\n" - + "\n" - + " if (id.hasOwnProperty(\"_id\")) {\n" - + " if (id.hasOwnProperty(\"_rev\")) {\n" - + " rev = id._rev;\n" - + " }\n" - + "\n" - + " id = id._id;\n" - + " }\n" - + "\n" - + " var policy = \"\";\n" - + "\n" - + " if (overwrite) {\n" - + " policy = \"?policy=last\";\n" - + " }\n" - + "\n" - + " if (rev === null) {\n" - + " requestResult = this._database._connection.PUT(\n" - + " \"/_api/document/\" + id + policy, \n" - + " JSON.stringify(data));\n" - + " }\n" - + " else {\n" - + " requestResult = this._database._connection.PUT(\n" - + " \"/_api/document/\" + id + policy, JSON.stringify(data),\n" - + " {'if-match' : '\"' + rev + '\"' });\n" - + " }\n" - + "\n" - + " if (requestResult !== null && requestResult.error === true) {\n" - + " var s = id.split(\"/\");\n" - + "\n" - + " if (s.length !== 2) {\n" - + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" - + " }\n" - + " else if (parseInt(s[0]) !== this._id) {\n" - + " requestResult.errorNum = internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.code;\n" - + " }\n" - + "\n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief update a document in the collection, identified by its id\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.update = function (id, data, overwrite, keepNull) { \n" - + " var rev = null;\n" - + " var requestResult;\n" - + "\n" - + " if (id.hasOwnProperty(\"_id\")) {\n" - + " if (id.hasOwnProperty(\"_rev\")) {\n" - + " rev = id._rev;\n" - + " }\n" - + "\n" - + " id = id._id;\n" - + " }\n" - + "\n" - + " // set default value for keepNull\n" - + " var keepNullValue = ((typeof keepNull == \"undefined\") ? true : keepNull);\n" - + " var params = \"?keepNull=\" + (keepNullValue ? \"true\" : \"false\");\n" - + "\n" - + " if (overwrite) {\n" - + " params += \"&policy=last\";\n" - + " }\n" - + "\n" - + " if (rev === null) {\n" - + " requestResult = this._database._connection.PATCH(\n" - + " \"/_api/document/\" + id + params, \n" - + " JSON.stringify(data));\n" - + " }\n" - + " else {\n" - + " requestResult = this._database._connection.PATCH(\n" - + " \"/_api/document/\" + id + params, JSON.stringify(data),\n" - + " {'if-match' : '\"' + rev + '\"' });\n" - + " }\n" - + "\n" - + " if (requestResult !== null && requestResult.error === true) {\n" - + " var s = id.split(\"/\");\n" - + "\n" - + " if (s.length !== 2) {\n" - + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" - + " }\n" - + " else if (parseInt(s[0]) !== this._id) {\n" - + " requestResult.errorNum = internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.code;\n" - + " }\n" - + "\n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief returns the edges starting or ending in a vertex\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.edges = function (vertex) {\n" - + " // if vertex is a list, iterator and concat\n" - + " if (vertex instanceof Array) {\n" - + " var edges = [];\n" - + " var i;\n" - + "\n" - + " for (i = 0; i < vertex.length; ++i) {\n" - + " var e = this.edges(vertex[i]);\n" - + "\n" - + " edges.push.apply(edges, e);\n" - + " }\n" - + "\n" - + " return edges;\n" - + " }\n" - + "\n" - + " if (vertex.hasOwnProperty(\"_id\")) {\n" - + " vertex = vertex._id;\n" - + " }\n" - + "\n" - + " // get the edges\n" - + " var requestResult = this._database._connection.GET(\n" - + " \"/_api/edges/\" + encodeURIComponent(this._id) + \"?vertex=\" + encodeURIComponent(vertex));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult['edges'];\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief returns the edges ending in a vertex\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.inEdges = function (vertex) {\n" - + " // if vertex is a list, iterator and concat\n" - + " if (vertex instanceof Array) {\n" - + " var edges = [];\n" - + " var i;\n" - + "\n" - + " for (i = 0; i < vertex.length; ++i) {\n" - + " var e = this.inEdges(vertex[i]);\n" - + "\n" - + " edges.push.apply(edges, e);\n" - + " }\n" - + "\n" - + " return edges;\n" - + " }\n" - + "\n" - + " if (vertex.hasOwnProperty(\"_id\")) {\n" - + " vertex = vertex._id;\n" - + " }\n" - + "\n" - + " // get the edges\n" - + " var requestResult = this._database._connection.GET(\n" - + " \"/_api/edges/\" + encodeURIComponent(this._id)\n" - + " + \"?direction=in&vertex=\" + encodeURIComponent(vertex));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult['edges'];\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief returns the edges starting in a vertex\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.outEdges = function (vertex) {\n" - + " // if vertex is a list, iterator and concat\n" - + " if (vertex instanceof Array) {\n" - + " var edges = [];\n" - + " var i;\n" - + "\n" - + " for (i = 0; i < vertex.length; ++i) {\n" - + " var e = this.outEdges(vertex[i]);\n" - + "\n" - + " edges.push.apply(edges, e);\n" - + " }\n" - + "\n" - + " return edges;\n" - + " }\n" - + "\n" - + " if (vertex.hasOwnProperty(\"_id\")) {\n" - + " vertex = vertex._id;\n" - + " }\n" - + "\n" - + " // get the edges\n" - + " var requestResult = this._database._connection.GET(\n" - + " \"/_api/edges/\" + encodeURIComponent(this._id)\n" - + " + \"?direction=out&vertex=\" + encodeURIComponent(vertex));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult['edges'];\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "}());\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- ArangoDatabase\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- constructors and destructors\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief constructor\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function ArangoDatabase (connection) {\n" - + " this._connection = connection;\n" - + " this._collectionConstructor = ArangoCollection;\n" - + "}\n" - + "\n" - + "(function () {\n" - + " var internal = require(\"internal\");\n" - + " var client = require(\"arangosh\");\n" - + " \n" - + " internal.ArangoDatabase = ArangoDatabase;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- private functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief help for ArangoDatabase\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " client.helpArangoDatabase = client.createHelpHeadline(\"ArangoDatabase help\") +\n" - + " 'ArangoDatabase constructor: ' + \"\\n\" +\n" - + " ' > db = new ArangoDatabase(connection); ' + \"\\n\" +\n" - + " ' ' + \"\\n\" +\n" - + " 'Administration Functions: ' + \"\\n\" +\n" - + " ' _help(); this help ' + \"\\n\" +\n" - + " ' ' + \"\\n\" +\n" - + " 'Collection Functions: ' + \"\\n\" +\n" - + " ' _collections() list all collections ' + \"\\n\" +\n" - + " ' _collection() get collection by identifier/name' + \"\\n\" +\n" - + " ' _create(, ) creates a new collection ' + \"\\n\" +\n" - + " ' _truncate() delete all documents ' + \"\\n\" +\n" - + " ' _drop() delete a collection ' + \"\\n\" +\n" - + " ' ' + \"\\n\" +\n" - + " 'Document Functions: ' + \"\\n\" +\n" - + " ' _document() get document by handle ' + \"\\n\" +\n" - + " ' _replace(, , overwrite document ' + \"\\n\" +\n" - + " ' ) ' + \"\\n\" +\n" - + " ' _update(, , update document ' + \"\\n\" +\n" - + " ' , ) ' + \"\\n\" +\n" - + " ' _remove() delete document ' + \"\\n\" +\n" - + " ' ' + \"\\n\" +\n" - + " 'Query Functions: ' + \"\\n\" +\n" - + " ' _createStatement(); create and return select query ' + \"\\n\" +\n" - + " ' ' + \"\\n\" +\n" - + " 'Attributes: ' + \"\\n\" +\n" - + " ' collection with the given name ';\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief print the help for ArangoDatabase\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._help = function () { \n" - + " internal.print(client.helpArangoDatabase);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return a string representation of the database object\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype.toString = function () { \n" - + " return \"[object ArangoDatabase]\";\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- collection functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return all collections from the database\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._collections = function () {\n" - + " var requestResult = this._connection.GET(\"/_api/collection\");\n" - + " \n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " if (requestResult[\"collections\"] !== undefined) {\n" - + " var collections = requestResult[\"collections\"];\n" - + " var result = [];\n" - + " var i;\n" - + " \n" - + " // add all collentions to object\n" - + " for (i = 0; i < collections.length; ++i) {\n" - + " var collection = new this._collectionConstructor(this, collections[i]);\n" - + "\n" - + " this[collection._name] = collection;\n" - + " result.push(collection);\n" - + " }\n" - + " \n" - + " return result;\n" - + " }\n" - + " \n" - + " return undefined;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return a single collection, identified by its id or name\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._collection = function (id) {\n" - + " var requestResult = this._connection.GET(\n" - + " \"/_api/collection/\" + encodeURIComponent(id));\n" - + " \n" - + " // return null in case of not found\n" - + " if (requestResult !== null\n" - + " && requestResult.error === true \n" - + " && requestResult.errorNum === internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " // check all other errors and throw them\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " var name = requestResult[\"name\"];\n" - + "\n" - + " if (name !== undefined) {\n" - + " this[name] = new this._collectionConstructor(this, requestResult);\n" - + " return this[name];\n" - + " }\n" - + " \n" - + " return undefined;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief creates a new collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._create = function (name, properties, type) {\n" - + " var body = {\n" - + " \"name\" : name,\n" - + " \"type\" : ArangoCollection.TYPE_DOCUMENT\n" - + " };\n" - + "\n" - + " if (properties !== undefined) {\n" - + " if (properties.hasOwnProperty(\"waitForSync\")) {\n" - + " body.waitForSync = properties.waitForSync;\n" - + " }\n" - + "\n" - + " if (properties.hasOwnProperty(\"journalSize\")) {\n" - + " body.journalSize = properties.journalSize;\n" - + " }\n" - + "\n" - + " if (properties.hasOwnProperty(\"isSystem\")) {\n" - + " body.isSystem = properties.isSystem;\n" - + " }\n" - + " }\n" - + "\n" - + " if (type != undefined && type == ArangoCollection.TYPE_EDGE) {\n" - + " body.type = type;\n" - + " }\n" - + "\n" - + " var requestResult = this._connection.POST(\n" - + " \"/_api/collection\",\n" - + " JSON.stringify(body));\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " var nname = requestResult[\"name\"];\n" - + "\n" - + " if (nname !== undefined) {\n" - + " this[nname] = new this._collectionConstructor(this, requestResult);\n" - + " return this[nname];\n" - + " }\n" - + " \n" - + " return undefined;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief creates a new document collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._createDocumentCollection = function (name, properties) {\n" - + " return this._create(name, properties, ArangoCollection.TYPE_DOCUMENT);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief creates a new edges collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._createEdgeCollection = function (name, properties) {\n" - + " return this._create(name, properties, ArangoCollection.TYPE_EDGE);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief truncates a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._truncate = function (id) {\n" - + " var name;\n" - + "\n" - + " for (name in this) {\n" - + " if (this.hasOwnProperty(name)) {\n" - + " var collection = this[name];\n" - + "\n" - + " if (collection instanceof this._collectionConstructor) {\n" - + " if (collection._id === id || collection._name === id) {\n" - + " return collection.truncate();\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "\n" - + " return undefined;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief drops a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._drop = function (id) {\n" - + " var name;\n" - + "\n" - + " for (name in this) {\n" - + " if (this.hasOwnProperty(name)) {\n" - + " var collection = this[name];\n" - + "\n" - + " if (collection instanceof this._collectionConstructor) {\n" - + " if (collection._id === id || collection._name === id) {\n" - + " return collection.drop();\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "\n" - + " return undefined;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief returns one index\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._index = function (id) {\n" - + " if (id.hasOwnProperty(\"id\")) {\n" - + " id = id.id;\n" - + " }\n" - + "\n" - + " var requestResult = this._connection.GET(\"/_api/index/\" + id);\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief deletes one index\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._dropIndex = function (id) {\n" - + " if (id.hasOwnProperty(\"id\")) {\n" - + " id = id.id;\n" - + " }\n" - + "\n" - + " var requestResult = this._connection.DELETE(\"/_api/index/\" + id);\n" - + "\n" - + " if (requestResult !== null\n" - + " && requestResult.error === true \n" - + " && requestResult.errorNum === internal.errors.ERROR_ARANGO_INDEX_NOT_FOUND.code) {\n" - + " return false;\n" - + " }\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return true;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- document functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return a single document from the collection, identified by its id\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._document = function (id) {\n" - + " var rev = null;\n" - + " var requestResult;\n" - + "\n" - + " if (id.hasOwnProperty(\"_id\")) {\n" - + " if (id.hasOwnProperty(\"_rev\")) {\n" - + " rev = id._rev;\n" - + " }\n" - + "\n" - + " id = id._id;\n" - + " }\n" - + "\n" - + " if (rev === null) {\n" - + " requestResult = this._connection.GET(\"/_api/document/\" + id);\n" - + " }\n" - + " else {\n" - + " requestResult = this._connection.GET(\n" - + " \"/_api/document/\" + id,\n" - + " {'if-match' : '\"' + rev + '\"' });\n" - + " }\n" - + "\n" - + " if (requestResult !== null\n" - + " && requestResult.error === true \n" - + " && requestResult.errorNum === internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code) {\n" - + " var s = id.split(\"/\");\n" - + "\n" - + " if (s.length !== 2) {\n" - + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" - + " }\n" - + "\n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief delete a document in the collection, identified by its id\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._remove = function (id, overwrite) {\n" - + " var rev = null;\n" - + " var requestResult;\n" - + "\n" - + " if (id.hasOwnProperty(\"_id\")) {\n" - + " if (id.hasOwnProperty(\"_rev\")) {\n" - + " rev = id._rev;\n" - + " }\n" - + "\n" - + " id = id._id;\n" - + " }\n" - + "\n" - + " var policy = \"\";\n" - + "\n" - + " if (overwrite) {\n" - + " policy = \"?policy=last\";\n" - + " }\n" - + "\n" - + " if (rev === null) {\n" - + " requestResult = this._connection.DELETE(\"/_api/document/\" + id + policy);\n" - + " }\n" - + " else {\n" - + " requestResult = this._connection.DELETE(\n" - + " \"/_api/document/\" + id + policy,\n" - + " {'if-match' : '\"' + rev + '\"' });\n" - + " }\n" - + "\n" - + " if (requestResult !== null && requestResult.error === true) {\n" - + " var s = id.split(\"/\");\n" - + "\n" - + " if (s.length !== 2) {\n" - + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" - + " }\n" - + "\n" - + " if (overwrite) {\n" - + " if (requestResult.errorNum === internal.errors.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code) {\n" - + " return false;\n" - + " }\n" - + " }\n" - + "\n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return true;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief replace a document in the collection, identified by its id\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._replace = function (id, data, overwrite) { \n" - + " var rev = null;\n" - + " var requestResult;\n" - + "\n" - + " if (id.hasOwnProperty(\"_id\")) {\n" - + " if (id.hasOwnProperty(\"_rev\")) {\n" - + " rev = id._rev;\n" - + " }\n" - + "\n" - + " id = id._id;\n" - + " }\n" - + "\n" - + " var policy = \"\";\n" - + "\n" - + " if (overwrite) {\n" - + " policy = \"?policy=last\";\n" - + " }\n" - + "\n" - + " if (rev === null) {\n" - + " requestResult = this._connection.PUT(\n" - + " \"/_api/document/\" + id + policy,\n" - + " JSON.stringify(data));\n" - + " }\n" - + " else {\n" - + " requestResult = this._connection.PUT(\n" - + " \"/_api/document/\" + id + policy,\n" - + " JSON.stringify(data),\n" - + " {'if-match' : '\"' + rev + '\"' });\n" - + " }\n" - + "\n" - + " if (requestResult !== null && requestResult.error === true) {\n" - + " var s = id.split(\"/\");\n" - + "\n" - + " if (s.length !== 2) {\n" - + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" - + " }\n" - + "\n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief update a document in the collection, identified by its id\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._update = function (id, data, overwrite, keepNull) { \n" - + " var rev = null;\n" - + " var requestResult;\n" - + " \n" - + " if (id.hasOwnProperty(\"_id\")) {\n" - + " if (id.hasOwnProperty(\"_rev\")) {\n" - + " rev = id._rev;\n" - + " }\n" - + "\n" - + " id = id._id;\n" - + " }\n" - + "\n" - + " // set default value for keepNull\n" - + " var keepNullValue = ((typeof keepNull == \"undefined\") ? true : keepNull);\n" - + " var params = \"?keepNull=\" + (keepNullValue ? \"true\" : \"false\");\n" - + "\n" - + " if (overwrite) {\n" - + " params += \"&policy=last\";\n" - + " }\n" - + "\n" - + " if (rev === null) {\n" - + " requestResult = this._connection.PATCH(\n" - + " \"/_api/document/\" + id + params,\n" - + " JSON.stringify(data));\n" - + " }\n" - + " else {\n" - + " requestResult = this._connection.PATCH(\n" - + " \"/_api/document/\" + id + params,\n" - + " JSON.stringify(data),\n" - + " {'if-match' : '\"' + rev + '\"' });\n" - + " }\n" - + "\n" - + " if (requestResult !== null && requestResult.error === true) {\n" - + " var s = id.split(\"/\");\n" - + "\n" - + " if (s.length !== 2) {\n" - + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" - + " }\n" - + "\n" - + " throw new ArangoError(requestResult);\n" - + " }\n" - + "\n" - + " client.checkRequestResult(requestResult);\n" - + "\n" - + " return requestResult;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- query functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief factory method to create a new statement\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._createStatement = function (data) { \n" - + " return new ArangoStatement(this, data);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "}());\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- initialisers\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup ArangoShell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "(function () {\n" - + " var internal = require(\"internal\");\n" - + " var client = require(\"arangosh\");\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief general help\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " client.HELP = client.createHelpHeadline(\"Help\") +\n" - + " 'Predefined objects: ' + \"\\n\" +\n" - + " ' arango: ArangoConnection ' + \"\\n\" +\n" - + " ' db: ArangoDatabase ' + \"\\n\" +\n" - + " 'Example: ' + \"\\n\" +\n" - + " ' > db._collections(); list all collections ' + \"\\n\" +\n" - + " ' > db..all().toArray(); list all documents ' + \"\\n\" +\n" - + " ' > id = db..save({ ... }); save a document ' + \"\\n\" +\n" - + " ' > db..remove(<_id>); delete a document ' + \"\\n\" +\n" - + " ' > db..document(<_id>); get a document ' + \"\\n\" +\n" - + " ' > db..replace(<_id>, {...}); overwrite a document ' + \"\\n\" +\n" - + " ' > db..update(<_id>, {...}); partially update a document' + \"\\n\" +\n" - + " ' > help show help pages ' + \"\\n\" +\n" - + " ' > exit ' + \"\\n\" +\n" - + " 'Note: collection names may be cached in arangosh. To refresh them, issue: ' + \"\\n\" +\n" - + " ' > db._collections(); ';\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief query help\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " client.helpQueries = client.createHelpHeadline(\"Select query help\") +\n" - + " 'Create a select query: ' + \"\\n\" +\n" - + " ' > st = new ArangoStatement(db, { \"query\" : \"for...\" }); ' + \"\\n\" +\n" - + " ' > st = db._createStatement({ \"query\" : \"for...\" }); ' + \"\\n\" +\n" - + " 'Set query options: ' + \"\\n\" +\n" - + " ' > st.setBatchSize(); set the max. number of results ' + \"\\n\" +\n" - + " ' to be transferred per roundtrip ' + \"\\n\" +\n" - + " ' > st.setCount(); set count flag (return number of ' + \"\\n\" +\n" - + " ' results in \"count\" attribute) ' + \"\\n\" +\n" - + " 'Get query options: ' + \"\\n\" +\n" - + " ' > st.setBatchSize(); return the max. number of results ' + \"\\n\" +\n" - + " ' to be transferred per roundtrip ' + \"\\n\" +\n" - + " ' > st.getCount(); return count flag (return number of' + \"\\n\" +\n" - + " ' results in \"count\" attribute) ' + \"\\n\" +\n" - + " ' > st.getQuery(); return query string ' + \"\\n\" +\n" - + " ' results in \"count\" attribute) ' + \"\\n\" +\n" - + " 'Bind parameters to a query: ' + \"\\n\" +\n" - + " ' > st.bind(, ); bind single variable ' + \"\\n\" +\n" - + " ' > st.bind(); bind multiple variables ' + \"\\n\" +\n" - + " 'Execute query: ' + \"\\n\" +\n" - + " ' > c = st.execute(); returns a cursor ' + \"\\n\" +\n" - + " 'Get all results in an array: ' + \"\\n\" +\n" - + " ' > e = c.elements(); ' + \"\\n\" +\n" - + " 'Or loop over the result set: ' + \"\\n\" +\n" - + " ' > while (c.hasNext()) { print( c.next() ); } ';\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief extended help\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " client.helpExtended = client.createHelpHeadline(\"More help\") +\n" - + " 'Pager: ' + \"\\n\" +\n" - + " ' > stop_pager() stop the pager output ' + \"\\n\" +\n" - + " ' > start_pager() start the pager ' + \"\\n\" +\n" - + " 'Pretty printing: ' + \"\\n\" +\n" - + " ' > stop_pretty_print() stop pretty printing ' + \"\\n\" +\n" - + " ' > start_pretty_print() start pretty printing ' + \"\\n\" +\n" - + " 'Color output: ' + \"\\n\" +\n" - + " ' > stop_color_print() stop color printing ' + \"\\n\" +\n" - + " ' > start_color_print() start color printing ' + \"\\n\" +\n" - + " ' > start_color_print(COLOR_BLUE) set color ' + \"\\n\" +\n" - + " 'Print function: ' + \"\\n\" +\n" - + " ' > print(x) std. print function ' + \"\\n\" +\n" - + " ' > print_plain(x) print without pretty printing' + \"\\n\" +\n" - + " ' and without colors ';\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief create the global db object and load the collections\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " try {\n" - + " if (typeof arango !== 'undefined') {\n" - + "\n" - + " // default databases\n" - + " db = internal.db = new ArangoDatabase(arango);\n" - + " edges = internal.edges = db;\n" - + "\n" - + " // load collection data\n" - + " internal.db._collections();\n" - + "\n" - + " // load simple queries\n" - + " require(\"simple-query\");\n" - + "\n" - + " if (! internal.ARANGO_QUIET) {\n" - + " internal.print(client.HELP);\n" - + " }\n" - + " }\n" - + " }\n" - + " catch (err) {\n" - + " internal.print(String(err));\n" - + " }\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "}());\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- END-OF-FILE\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "// Local Variables:\n" - + "// mode: outline-minor\n" - + "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @}\\\\|/\\\\*jslint\\\\)\"\n" - + "// End:\n" -; +const char* JS_client_client[] = { + "/*jslint indent: 2,", + " nomen: true,", + " maxlen: 100,", + " sloppy: true,", + " vars: true,", + " white: true,", + " plusplus: true */", + "/*global require, arango, db, edges, ModuleCache, Module */", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief ArangoShell client API", + "///", + "/// @file", + "///", + "/// DISCLAIMER", + "///", + "/// Copyright 2012 triagens GmbH, Cologne, Germany", + "///", + "/// Licensed under the Apache License, Version 2.0 (the \"License\");", + "/// you may not use this file except in compliance with the License.", + "/// You may obtain a copy of the License at", + "///", + "/// http://www.apache.org/licenses/LICENSE-2.0", + "///", + "/// Unless required by applicable law or agreed to in writing, software", + "/// distributed under the License is distributed on an \"AS IS\" BASIS,", + "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "/// See the License for the specific language governing permissions and", + "/// limitations under the License.", + "///", + "/// Copyright holder is triAGENS GmbH, Cologne, Germany", + "///", + "/// @author Achim Brandt", + "/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- ArangoError", + "// -----------------------------------------------------------------------------", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- constructors and destructors", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief constructor", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function ArangoError (error) {", + " if (error !== undefined) {", + " this.error = error.error;", + " this.code = error.code;", + " this.errorNum = error.errorNum;", + " this.errorMessage = error.errorMessage;", + " }", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- private functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "(function () {", + " var internal = require(\"internal\");", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief prints an error", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoError.prototype._PRINT = function() {", + " internal.output(this.toString());", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief toString function", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoError.prototype.toString = function() {", + " var result = \"\";", + "", + " if (internal.COLOR_OUTPUT) {", + " result = internal.COLOR_BRIGHT + \"Error: \" + internal.COLOR_OUTPUT_RESET;", + " }", + " else {", + " result = \"Error: \";", + " }", + "", + " result += \"[\" + this.code + \":\" + this.errorNum + \"] \" + this.errorMessage;", + "", + " return result;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief prints an error", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoError.prototype.toString = function() {", + " var errorNum = this.errorNum;", + " var errorMessage = this.errorMessage;", + "", + " return \"[ArangoError \" + errorNum + \": \" + errorMessage + \"]\";", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "}());", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- Module \"arangosh\"", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8ModuleArangosh", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "ModuleCache[\"/arangosh\"] = new Module(\"/arangosh\");", + "", + "(function () {", + " var internal = require(\"internal\");", + " var client = ModuleCache[\"/arangosh\"].exports;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- private variables", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief help texts", + "////////////////////////////////////////////////////////////////////////////////", + "", + " client.HELP = \"\";", + " client.helpQueries = \"\";", + " client.helpArangoDatabase = \"\";", + " client.helpArangoCollection = \"\";", + " client.helpArangoQueryCursor = \"\";", + " client.helpArangoStatement = \"\";", + " client.helpExtended = \"\";", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- private functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return a formatted type string for object", + "/// ", + "/// If the object has an id, it will be included in the string.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " client.getIdString = function (object, typeName) {", + " var result = \"[object \" + typeName;", + " ", + " if (object._id) {", + " result += \":\" + object._id;", + " }", + " else if (object.data && object.data._id) {", + " result += \":\" + object.data._id;", + " }", + "", + " result += \"]\";", + "", + " return result;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief handles error results", + "/// ", + "/// throws an exception in case of an an error", + "////////////////////////////////////////////////////////////////////////////////", + "", + " client.checkRequestResult = function (requestResult) {", + " if (requestResult === undefined) {", + " requestResult = {", + " \"error\" : true,", + " \"code\" : 0,", + " \"errorNum\" : 0,", + " \"errorMessage\" : \"Unknown error. Request result is empty\"", + " };", + " }", + " ", + " if (requestResult.error !== undefined && requestResult.error) { ", + " throw new ArangoError(requestResult);", + " }", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief create a formatted headline text ", + "////////////////////////////////////////////////////////////////////////////////", + "", + " client.createHelpHeadline = function (text) {", + " var i;", + " var p = \"\";", + " var x = parseInt(Math.abs(78 - text.length) / 2);", + "", + " for (i = 0; i < x; ++i) {", + " p += \"-\";", + " }", + " ", + " return \"\\n\" + p + \" \" + text + \" \" + p + \"\\n\";", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "}());", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- public functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief turn off pretty printing", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function print_plain (data) {", + " var internal = require(\"internal\");", + "", + " var p = internal.PRETTY_PRINT;", + " internal.PRETTY_PRINT = false;", + "", + " var c = internal.COLOR_OUTPUT;", + " internal.COLOR_OUTPUT = false;", + " ", + " try {", + " internal.print(data);", + "", + " internal.PRETTY_PRINT = p;", + " internal.COLOR_OUTPUT = c;", + " }", + " catch (e) {", + " internal.PRETTY_PRINT = p;", + " internal.COLOR_OUTPUT = c;", + "", + " throw e.message; ", + " } ", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief start pretty printing", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function start_pretty_print () {", + " var internal = require(\"internal\");", + "", + " if (! internal.PRETTY_PRINT) {", + " internal.print(\"using pretty printing\");", + " internal.PRETTY_PRINT = true;", + " }", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief stop pretty printing", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function stop_pretty_print () {", + " var internal = require(\"internal\");", + "", + " if (internal.PRETTY_PRINT) {", + " internal.PRETTY_PRINT = false;", + " internal.print(\"stop pretty printing\");", + " }", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief start paging", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function start_pager () {", + " var internal = require(\"internal\");", + "", + " internal.start_pager();", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief stop paging", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function stop_pager () {", + " var internal = require(\"internal\");", + " ", + " internal.stop_pager();", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief start pretty printing with optional color", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function start_color_print (color) {", + " var internal = require(\"internal\");", + "", + " if (typeof(color) === \"string\") {", + " internal.COLOR_OUTPUT_DEFAULT = color;", + " }", + " else {", + " internal.COLOR_OUTPUT_DEFAULT = internal.COLOR_BRIGHT;", + " }", + "", + " internal.COLOR_OUTPUT = true;", + "", + " internal.print(\"start \"", + " + internal.COLOR_OUTPUT_DEFAULT", + " + \"color\" ", + " + internal.COLOR_OUTPUT_RESET", + " + \" printing\");", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief stop pretty printing", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function stop_color_print () {", + " var internal = require(\"internal\");", + "", + " internal.print(\"stop color printing\");", + " internal.COLOR_OUTPUT = false;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief print the overall help", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function help () {", + " var internal = require(\"internal\");", + " var client = require(\"arangosh\");", + "", + " internal.print(client.HELP);", + " internal.print(client.helpQueries);", + " internal.print(client.helpArangoDatabase);", + " internal.print(client.helpArangoCollection);", + " internal.print(client.helpArangoStatement);", + " internal.print(client.helpArangoQueryCursor);", + " internal.print(client.helpExtended);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- Module \"internal\"", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "(function () {", + " var internal = require(\"internal\");", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief be quiet", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.ARANGO_QUIET = ARANGO_QUIET;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief log function", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.log = function (level, msg) {", + " internal.output(level, \": \", msg, \"\\n\");", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief rebuilds the routing cache", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.reloadRouting = function () {", + " if (typeof arango !== 'undefined') {", + " arango.POST(\"/_admin/reloadRouting\", \"\");", + " }", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "}());", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- ArangoQueryCursor", + "// -----------------------------------------------------------------------------", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- constructors and destructors", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief constructor", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function ArangoQueryCursor (database, data) {", + " this._database = database;", + " this.data = data;", + " this._hasNext = false;", + " this._hasMore = false;", + " this._pos = 0;", + " this._count = 0;", + " this._total = 0;", + " ", + " if (data.result !== undefined) {", + " this._count = data.result.length;", + " ", + " if (this._pos < this._count) {", + " this._hasNext = true;", + " }", + " ", + " if (data.hasMore !== undefined && data.hasMore) {", + " this._hasMore = true;", + " } ", + " }", + "}", + "", + "(function () {", + " var internal = require(\"internal\");", + " var client = require(\"arangosh\");", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- private functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief help for ArangoQueryCursor", + "////////////////////////////////////////////////////////////////////////////////", + "", + " client.helpArangoQueryCursor = client.createHelpHeadline(\"ArangoQueryCursor help\") +", + " 'ArangoQueryCursor constructor: ' + \"\\n\" +", + " ' > cu1 = qi1.execute(); ' + \"\\n\" +", + " 'Functions: ' + \"\\n\" +", + " ' hasNext(); returns true if there ' + \"\\n\" +", + " ' are more results ' + \"\\n\" +", + " ' next(); returns the next document ' + \"\\n\" +", + " ' elements(); returns all documents ' + \"\\n\" +", + " ' _help(); this help ' + \"\\n\" +", + " 'Attributes: ' + \"\\n\" +", + " ' _database database object ' + \"\\n\" +", + " 'Example: ' + \"\\n\" +", + " ' > st = db._createStatement({ \"query\" : \"for c in coll return c\" });' + \"\\n\" +", + " ' > c = st.execute(); ' + \"\\n\" +", + " ' > documents = c.elements(); ' + \"\\n\" +", + " ' > c = st.execute(); ' + \"\\n\" +", + " ' > while (c.hasNext()) { print( c.next() ); } ';", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief print the help for the cursor", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoQueryCursor.prototype._help = function () {", + " internal.print(client.helpArangoQueryCursor);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return a string representation of the cursor", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoQueryCursor.prototype.toString = function () { ", + " return client.getIdString(this, \"ArangoQueryCursor\");", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- public functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return whether there are more results available in the cursor", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoQueryCursor.prototype.hasNext = function () {", + " return this._hasNext;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return the next result document from the cursor", + "///", + "/// If no more results are available locally but more results are available on", + "/// the server, this function will make a roundtrip to the server", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoQueryCursor.prototype.next = function () {", + " if (!this._hasNext) {", + " throw \"No more results\";", + " }", + "", + " var result = this.data.result[this._pos];", + " this._pos++;", + "", + " // reached last result", + " if (this._pos === this._count) {", + " this._hasNext = false;", + " this._pos = 0;", + "", + " if (this._hasMore && this.data.id) {", + " this._hasMore = false;", + "", + " // load more results ", + " var requestResult = this._database._connection.PUT(", + " \"/_api/cursor/\"+ encodeURIComponent(this.data.id),", + " \"\");", + "", + " client.checkRequestResult(requestResult);", + "", + " this.data = requestResult;", + " this._count = requestResult.result.length;", + "", + " if (this._pos < this._count) {", + " this._hasNext = true;", + " }", + "", + " if (requestResult.hasMore !== undefined && requestResult.hasMore) {", + " this._hasMore = true;", + " } ", + " } ", + " }", + "", + " return result;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return all remaining result documents from the cursor", + "///", + "/// If no more results are available locally but more results are available on", + "/// the server, this function will make one or multiple roundtrips to the ", + "/// server. Calling this function will also fully exhaust the cursor.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoQueryCursor.prototype.elements = function () { ", + " var result = [];", + "", + " while (this.hasNext()) { ", + " result.push( this.next() ); ", + " }", + "", + " return result;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief explicitly dispose the cursor", + "///", + "/// Calling this function will mark the cursor as deleted on the server. It will", + "/// therefore make a roundtrip to the server. Using a cursor after it has been", + "/// disposed is considered a user error", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoQueryCursor.prototype.dispose = function () {", + " if (!this.data.id) {", + " // client side only cursor", + " return;", + " }", + "", + " var requestResult = this._database._connection.DELETE(", + " \"/_api/cursor/\"+ encodeURIComponent(this.data.id),", + " \"\");", + "", + " client.checkRequestResult(requestResult);", + "", + " this.data.id = undefined;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return the total number of documents in the cursor", + "///", + "/// The number will remain the same regardless how much result documents have", + "/// already been fetched from the cursor.", + "///", + "/// This function will return the number only if the cursor was constructed ", + "/// with the \"doCount\" attribute. Otherwise it will return undefined.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoQueryCursor.prototype.count = function () {", + " if (!this.data.id) {", + " throw \"cursor has been disposed\";", + " }", + "", + " return this.data.count;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "}());", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- ArangoStatement", + "// -----------------------------------------------------------------------------", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- constructors and destructors", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief constructor", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function ArangoStatement (database, data) {", + " this._database = database;", + " this._doCount = false;", + " this._batchSize = null;", + " this._bindVars = {};", + " ", + " if (!(data instanceof Object)) {", + " throw \"ArangoStatement needs initial data\";", + " }", + " ", + " if (data.query === undefined || data.query === \"\") {", + " throw \"ArangoStatement needs a valid query attribute\";", + " }", + " this.setQuery(data.query);", + "", + " if (data.count !== undefined) {", + " this.setCount(data.count);", + " }", + " if (data.batchSize !== undefined) {", + " this.setBatchSize(data.batchSize);", + " }", + "}", + "", + "(function () {", + " var internal = require(\"internal\");", + " var client = require(\"arangosh\");", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- private functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief help for ArangoStatement", + "////////////////////////////////////////////////////////////////////////////////", + "", + " client.helpArangoStatement = client.createHelpHeadline(\"ArangoStatement help\") +", + " 'ArangoStatement constructor: ' + \"\\n\" +", + " ' > st = new ArangoStatement(db, { \"query\" : \"for ...\" }); ' + \"\\n\" +", + " ' > st = db._createStatement({ \"query\" : \"for ...\" }); ' + \"\\n\" +", + " 'Functions: ' + \"\\n\" +", + " ' bind(, ); bind single variable ' + \"\\n\" +", + " ' bind(); bind multiple variables ' + \"\\n\" +", + " ' setBatchSize(); set max. number of results ' + \"\\n\" +", + " ' to be transferred per roundtrip ' + \"\\n\" +", + " ' setCount(); set count flag (return number of ' + \"\\n\" +", + " ' results in \"count\" attribute) ' + \"\\n\" +", + " ' getBatchSize(); return max. number of results ' + \"\\n\" +", + " ' to be transferred per roundtrip ' + \"\\n\" +", + " ' getCount(); return count flag (return number of' + \"\\n\" +", + " ' results in \"count\" attribute) ' + \"\\n\" +", + " ' getQuery(); return query string ' + \"\\n\" +", + " ' execute(); execute query and return cursor ' + \"\\n\" +", + " ' _help(); this help ' + \"\\n\" +", + " 'Attributes: ' + \"\\n\" +", + " ' _database database object ' + \"\\n\" +", + " 'Example: ' + \"\\n\" +", + " ' > st = db._createStatement({ \"query\" : \"for c in coll filter ' + \"\\n\" +", + " ' c.x == @a && c.y == @b return c\" }); ' + \"\\n\" +", + " ' > st.bind(\"a\", \"hello\"); ' + \"\\n\" +", + " ' > st.bind(\"b\", \"world\"); ' + \"\\n\" +", + " ' > c = st.execute(); ' + \"\\n\" +", + " ' > print(c.elements()); ';", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief print the help for ArangoStatement", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoStatement.prototype._help = function () {", + " internal.print(client.helpArangoStatement);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return a string representation of the statement", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoStatement.prototype.toString = function () { ", + " return client.getIdString(this, \"ArangoStatement\");", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- public functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief bind a parameter to the statement", + "///", + "/// This function can be called multiple times, once for each bind parameter.", + "/// All bind parameters will be transferred to the server in one go when ", + "/// execute() is called.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoStatement.prototype.bind = function (key, value) {", + " if (key instanceof Object) {", + " if (value !== undefined) {", + " throw \"invalid bind parameter declaration\";", + " }", + "", + " this._bindVars = key;", + " }", + " else if (typeof(key) === \"string\") {", + " if (this._bindVars[key] !== undefined) {", + " throw \"redeclaration of bind parameter\";", + " }", + "", + " this._bindVars[key] = value;", + " }", + " else if (typeof(key) === \"number\") {", + " var strKey = String(parseInt(key));", + "", + " if (strKey !== String(key)) {", + " throw \"invalid bind parameter declaration\";", + " }", + "", + " if (this._bindVars[strKey] !== undefined) {", + " throw \"redeclaration of bind parameter\";", + " }", + "", + " this._bindVars[strKey] = value;", + " }", + " else {", + " throw \"invalid bind parameter declaration\";", + " }", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return the bind variables already set", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoStatement.prototype.getBindVariables = function () {", + " return this._bindVars;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get the count flag for the statement", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoStatement.prototype.getCount = function () {", + " return this._doCount;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get the maximum number of results documents the cursor will return", + "/// in a single server roundtrip.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoStatement.prototype.getBatchSize = function () {", + " return this._batchSize;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get query string", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoStatement.prototype.getQuery = function () {", + " return this._query;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief set the count flag for the statement", + "///", + "/// Setting the count flag will make the statement's result cursor return the", + "/// total number of result documents. The count flag is not set by default.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoStatement.prototype.setCount = function (bool) {", + " this._doCount = bool ? true : false;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief set the maximum number of results documents the cursor will return", + "/// in a single server roundtrip.", + "/// The higher this number is, the less server roundtrips will be made when", + "/// iterating over the result documents of a cursor.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoStatement.prototype.setBatchSize = function (value) {", + " if (parseInt(value) > 0) {", + " this._batchSize = parseInt(value);", + " }", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief set the query string", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoStatement.prototype.setQuery = function (query) {", + " this._query = query;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief parse a query and return the results", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoStatement.prototype.parse = function () {", + " var body = {", + " \"query\" : this._query,", + " };", + "", + " var requestResult = this._database._connection.POST(", + " \"/_api/query\",", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " return true;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief execute the query", + "///", + "/// Invoking execute() will transfer the query and all bind parameters to the", + "/// server. It will return a cursor with the query results in case of success.", + "/// In case of an error, the error will be printed", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoStatement.prototype.execute = function () {", + " var body = {", + " \"query\" : this._query,", + " \"count\" : this._doCount,", + " \"bindVars\" : this._bindVars", + " };", + "", + " if (this._batchSize) {", + " body[\"batchSize\"] = this._batchSize;", + " }", + "", + " var requestResult = this._database._connection.POST(", + " \"/_api/cursor\",", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " return new ArangoQueryCursor(this._database, requestResult);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "}());", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- ArangoCollection", + "// -----------------------------------------------------------------------------", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- constructors and destructors", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief constructor", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function ArangoCollection (database, data) {", + " this._database = database;", + "", + " if (typeof data === \"string\") {", + " this._id = null;", + " this._name = data;", + " this._status = null;", + " this._type = null;", + " }", + " else if (data !== undefined) {", + " this._id = data.id;", + " this._name = data.name;", + " this._status = data.status;", + " this._type = data.type;", + " }", + " else {", + " this._id = null;", + " this._name = null;", + " this._status = null;", + " this._type = null;", + " }", + "}", + "", + "(function () {", + " var internal = require(\"internal\");", + " var client = require(\"arangosh\");", + "", + " internal.ArangoCollection = ArangoCollection;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- constants", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief collection is corrupted", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.STATUS_CORRUPTED = 0;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief collection is new born", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.STATUS_NEW_BORN = 1;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief collection is unloaded", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.STATUS_UNLOADED = 2;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief collection is loaded", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.STATUS_LOADED = 3;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief collection is unloading", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.STATUS_UNLOADING = 4;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief collection is deleted", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.STATUS_DELETED = 5;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief document collection", + "////////////////////////////////////////////////////////////////////////////////", + " ", + " ArangoCollection.TYPE_DOCUMENT = 2;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief edge collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.TYPE_EDGE = 3;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief attachment collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.TYPE_ATTACHMENT = 4;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- private functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief help for ArangoCollection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " client.helpArangoCollection = client.createHelpHeadline(\"ArangoCollection help\") +", + " 'ArangoCollection constructor: ' + \"\\n\" +", + " ' > col = db.mycoll; ' + \"\\n\" +", + " ' > col = db._create(\"mycoll\"); ' + \"\\n\" +", + " ' ' + \"\\n\" +", + " 'Administration Functions: ' + \"\\n\" +", + " ' name() collection name ' + \"\\n\" +", + " ' status() status of the collection ' + \"\\n\" +", + " ' type() type of the collection ' + \"\\n\" +", + " ' truncate() delete all documents ' + \"\\n\" +", + " ' properties() show collection properties ' + \"\\n\" +", + " ' drop() delete a collection ' + \"\\n\" +", + " ' load() load a collection into memeory ' + \"\\n\" +", + " ' unload() unload a collection from memory ' + \"\\n\" +", + " ' rename(new-name) renames a collection ' + \"\\n\" +", + " ' refresh() refreshes the status and name ' + \"\\n\" +", + " ' _help(); this help ' + \"\\n\" +", + " ' ' + \"\\n\" +", + " 'Document Functions: ' + \"\\n\" +", + " ' count() number of documents ' + \"\\n\" +", + " ' save() create document and return handle ' + \"\\n\" +", + " ' document() get document by handle ' + \"\\n\" +", + " ' replace(, , overwrite document ' + \"\\n\" +", + " ' ) ' + \"\\n\" +", + " ' update(, , partially update document ' + \"\\n\" +", + " ' , ) ' + \"\\n\" +", + " ' delete() delete document ' + \"\\n\" +", + " ' ' + \"\\n\" +", + " 'Attributes: ' + \"\\n\" +", + " ' _database database object ' + \"\\n\" +", + " ' _id collection identifier ';", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return a string representation of the collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.toString = function () { ", + " return client.getIdString(this, \"ArangoCollection\");", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief prints the collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.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(\"[ArangoCollection \",", + " this._id, ", + " \", \\\"\", ", + " this.name(), ", + " \"\\\" (type \",", + " type, \", status \",", + " status,", + " \")]\");", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief print the help for ArangoCollection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype._help = function () { ", + " internal.print(client.helpArangoCollection);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- public functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief returns the name of a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.name = function () {", + " if (this._name === null) {", + " this.refresh();", + " }", + "", + " return this._name;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief returns the status of a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.status = function () {", + " var result;", + "", + " if (this._status === null) {", + " this.refresh();", + " }", + "", + " // save original status", + " result = this._status;", + "", + " if (this._status == ArangoCollection.STATUS_UNLOADING) {", + " // if collection is currently unloading, we must not cache this info", + " this._status = null;", + " }", + "", + " // return the correct result", + " return result;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief returns the type of a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.type = function () {", + " var result;", + "", + " if (this._type === null) {", + " this.refresh();", + " }", + "", + " return this._type;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief gets or sets the properties of a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.properties = function (properties) {", + " var requestResult;", + "", + " if (properties === undefined) {", + " requestResult = this._database._connection.GET(", + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/properties\");", + "", + " client.checkRequestResult(requestResult);", + " }", + " else {", + " var body = {};", + "", + " if (properties.hasOwnProperty(\"waitForSync\")) {", + " body.waitForSync = properties.waitForSync;", + " }", + "", + " requestResult = this._database._connection.PUT(", + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/properties\",", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + " }", + "", + " return { ", + " waitForSync : requestResult.waitForSync,", + " journalSize : requestResult.journalSize", + " };", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief gets the figures of a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.figures = function () {", + " var requestResult = this._database._connection.GET(", + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/figures\");", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult.figures;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief drops a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.drop = function () {", + " var requestResult = this._database._connection.DELETE(", + " \"/_api/collection/\" + encodeURIComponent(this._id));", + "", + " client.checkRequestResult(requestResult);", + "", + " this._status = ArangoCollection.STATUS_DELETED;", + "", + " var database = this._database;", + " var name;", + "", + " for (name in database) {", + " if (database.hasOwnProperty(name)) {", + " var collection = database[name];", + "", + " if (collection instanceof ArangoCollection) {", + " if (collection._id === this._id) {", + " delete database[name];", + " }", + " }", + " }", + " }", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief returns all documents", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.toArray = function () {", + " return this.all().toArray();", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief returns all indexes", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.getIndexes = function () {", + " var requestResult = this._database._connection.GET(", + " \"/_api/index?collection=\" + encodeURIComponent(this._id));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult.indexes;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief returns one index", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.index = function (id) {", + " if (id.hasOwnProperty(\"id\")) {", + " id = id.id;", + " }", + "", + " var requestResult;", + " var s = id.split(\"/\");", + "", + " if (s.length !== 2) {", + " requestResult = {", + " errorNum: internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code,", + " errorMessage: internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message", + " };", + "", + " throw new ArangoError(requestResult);", + " }", + " else if (parseInt(s[0]) !== this._id) {", + " requestResult = {", + " errorNum: internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code,", + " errorMessage: ", + " internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.message", + " };", + "", + " throw new ArangoError(requestResult);", + " }", + "", + " requestResult = this._database._connection.GET(\"/_api/index/\" + id);", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief deletes one index", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.dropIndex = function (id) {", + " if (id.hasOwnProperty(\"id\")) {", + " id = id.id;", + " }", + "", + " var requestResult;", + " var s = id.split(\"/\");", + "", + " if (s.length !== 2) {", + " requestResult = {", + " errorNum: internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code,", + " errorMessage: internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message", + " };", + "", + " throw new ArangoError(requestResult);", + " }", + " else if (parseInt(s[0]) !== this._id) {", + " requestResult = {", + " errorNum: internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code,", + " errorMessage:", + " internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.message", + " };", + "", + " throw new ArangoError(requestResult);", + " }", + "", + " requestResult = this._database._connection.DELETE(\"/_api/index/\" + id);", + "", + " if (requestResult !== null", + " && requestResult.error === true ", + " && requestResult.errorNum", + " === internal.errors.ERROR_ARANGO_INDEX_NOT_FOUND.code) {", + " return false;", + " }", + "", + " client.checkRequestResult(requestResult);", + "", + " return true;", + " };", + "", + " ", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief adds a bitarray index", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.ensureBitarray = function () {", + " var i;", + " var body;", + " var fields = [];", + "", + " for (i = 0; i < arguments.length; ++i) {", + " fields.push(arguments[i]);", + " }", + "", + " body = { type : \"bitarray\", unique : false, fields : fields };", + "", + " var requestResult = this._database._connection.POST(", + " \"/_api/index?collection=\" + encodeURIComponent(this._id),", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + " ", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief adds a cap constraint", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.ensureCapConstraint = function (size) {", + " var body;", + "", + " body = { type : \"cap\", size : size };", + "", + " var requestResult = this._database._connection.POST(", + " \"/_api/index?collection=\" + encodeURIComponent(this._id),", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief adds a unique skip-list index", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.ensureUniqueSkiplist = function () {", + " var i;", + " var body;", + " var fields = [];", + "", + " for (i = 0; i < arguments.length; ++i) {", + " fields.push(arguments[i]);", + " }", + "", + " body = { type : \"skiplist\", unique : true, fields : fields };", + "", + " var requestResult = this._database._connection.POST(", + " \"/_api/index?collection=\" + encodeURIComponent(this._id),", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief adds a skip-list index", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.ensureSkiplist = function () {", + " var i;", + " var body;", + " var fields = [];", + "", + " for (i = 0; i < arguments.length; ++i) {", + " fields.push(arguments[i]);", + " }", + "", + " body = { type : \"skiplist\", unique : false, fields : fields };", + "", + " var requestResult = this._database._connection.POST(", + " \"/_api/index?collection=\" + encodeURIComponent(this._id),", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief adds a unique constraint", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.ensureUniqueConstraint = function () {", + " var i;", + " var body;", + " var fields = [];", + "", + " for (i = 0; i < arguments.length; ++i) {", + " fields.push(arguments[i]);", + " }", + "", + " body = { type : \"hash\", unique : true, fields : fields };", + "", + " var requestResult = this._database._connection.POST(", + " \"/_api/index?collection=\" + encodeURIComponent(this._id),", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief adds a hash index", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.ensureHashIndex = function () {", + " var i;", + " var body;", + " var fields = [];", + "", + " for (i = 0; i < arguments.length; ++i) {", + " fields.push(arguments[i]);", + " }", + "", + " body = { type : \"hash\", unique : false, fields : fields };", + "", + " var requestResult = this._database._connection.POST(", + " \"/_api/index?collection=\" + encodeURIComponent(this._id),", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief adds an geo index", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.ensureGeoIndex = function (lat, lon) {", + " var body;", + "", + " if (typeof lat !== \"string\") {", + " throw \"usage: ensureGeoIndex(, ) or ensureGeoIndex([, ])\";", + " }", + "", + " if (typeof lon === \"boolean\") {", + " body = { ", + " type : \"geo\", ", + " fields : [ lat ], ", + " geoJson : lon, ", + " constraint : false", + " };", + " }", + " else if (lon === undefined) {", + " body = {", + " type : \"geo\", ", + " fields : [ lat ],", + " geoJson : false, ", + " constraint : false ", + " };", + " }", + " else {", + " body = {", + " type : \"geo\",", + " fields : [ lat, lon ],", + " constraint : false", + " };", + " }", + "", + " var requestResult = this._database._connection.POST(", + " \"/_api/index?collection=\" + encodeURIComponent(this._id), ", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief adds an geo constraint", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.ensureGeoConstraint = function (lat, lon, ignoreNull) {", + " var body;", + "", + " // only two parameter", + " if (ignoreNull === undefined) {", + " ignoreNull = lon;", + "", + " if (typeof ignoreNull !== \"boolean\") {", + " throw \"usage: ensureGeoConstraint(, , )\"", + " + \" or ensureGeoConstraint(, , )\";", + " }", + "", + " body = {", + " type : \"geo\",", + " fields : [ lat ],", + " geoJson : false, ", + " constraint : true,", + " ignoreNull : ignoreNull ", + " };", + " }", + "", + " // three parameter", + " else {", + " if (typeof lon === \"boolean\") {", + " body = {", + " type : \"geo\",", + " fields : [ lat ],", + " geoJson : lon,", + " constraint : true,", + " ignoreNull : ignoreNull", + " };", + " }", + " else {", + " body = {", + " type : \"geo\",", + " fields : [ lat, lon ],", + " constraint : true,", + " ignoreNull : ignoreNull", + " };", + " }", + " }", + "", + " var requestResult = this._database._connection.POST(", + " \"/_api/index?collection=\" + encodeURIComponent(this._id),", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief queries by example", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.BY_EXAMPLE_HASH = function (index, example, skip, limit) {", + " var key;", + " var body;", + "", + " limit = limit || null;", + " skip = skip || null;", + "", + " if (index.hasOwnProperty(\"id\")) {", + " index = index.id;", + " }", + "", + " body = {", + " collection : this._id,", + " index : index,", + " skip : skip,", + " limit : limit,", + " example : {} ", + " };", + "", + " for (key in example) {", + " if (example.hasOwnProperty(key)) {", + " body.example[key] = example[key];", + " }", + " }", + "", + " var requestResult = this._database._connection.PUT(", + " \"/_api/simple/BY-EXAMPLE-HASH\",", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief truncates a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.truncate = function () {", + " var requestResult = this._database._connection.PUT(", + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/truncate\", \"\");", + "", + " client.checkRequestResult(requestResult);", + "", + " this._status = null;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief loads a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.load = function () {", + " var requestResult = this._database._connection.PUT(", + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/load\",", + " \"\");", + "", + " client.checkRequestResult(requestResult);", + "", + " this._status = null;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief unloads a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.unload = function () {", + " var requestResult = this._database._connection.PUT(", + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/unload\",", + " \"\");", + "", + " client.checkRequestResult(requestResult);", + "", + " this._status = null;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief renames a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.rename = function (name) {", + " var body = { name : name };", + " var requestResult = this._database._connection.PUT(", + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/rename\",", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " delete this._database[this._name];", + " this._database[name] = this;", + "", + " this._status = null;", + " this._name = null;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief refreshes a collection status and name", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.refresh = function () {", + " var requestResult = this._database._connection.GET(", + " \"/_api/collection/\" + encodeURIComponent(this._id));", + "", + " client.checkRequestResult(requestResult);", + "", + " this._name = requestResult['name'];", + " this._status = requestResult['status'];", + " this._type = requestResult['type'];", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- document functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief returns the number of documents", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.count = function () {", + " var requestResult = this._database._connection.GET(", + " \"/_api/collection/\" + encodeURIComponent(this._id) + \"/count\");", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult[\"count\"];", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return a single document from the collection, identified by its id", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.document = function (id) {", + " var rev = null;", + " var requestResult;", + "", + " if (id.hasOwnProperty(\"_id\")) {", + " if (id.hasOwnProperty(\"_rev\")) {", + " rev = id._rev;", + " }", + "", + " id = id._id;", + " }", + "", + " if (rev === null) {", + " requestResult = this._database._connection.GET(\"/_api/document/\" + id);", + " }", + " else {", + " requestResult = this._database._connection.GET(", + " \"/_api/document/\" + id,", + " {'if-match' : '\"' + rev + '\"' });", + " }", + "", + " if (requestResult !== null", + " && requestResult.error === true ", + " && requestResult.errorNum === internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code) {", + " var s = id.split(\"/\");", + "", + " if (s.length !== 2) {", + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;", + " }", + " else if (parseInt(s[0]) !== this._id) {", + " requestResult.errorNum = internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.code;", + " }", + "", + " throw new ArangoError(requestResult);", + " }", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief save a document in the collection, return its id", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.save = function () {", + " var requestResult;", + " var type = this.type();", + " ", + " if (type == undefined) {", + " type = ArangoCollection.TYPE_DOCUMENT;", + " }", + "", + " if (type == ArangoCollection.TYPE_DOCUMENT) { ", + " var data = arguments[0];", + "", + " requestResult = this._database._connection.POST(", + " \"/_api/document?collection=\" + encodeURIComponent(this._id),", + " JSON.stringify(data));", + " }", + " else if (type == ArangoCollection.TYPE_EDGE) {", + " var from = arguments[0];", + " var to = arguments[1];", + " var data = arguments[2];", + "", + " if (from.hasOwnProperty(\"_id\")) {", + " from = from._id;", + " }", + "", + " if (to.hasOwnProperty(\"_id\")) {", + " to = to._id;", + " }", + "", + " var url = \"/_api/edge?collection=\" + encodeURIComponent(this._id)", + " + \"&from=\" + encodeURIComponent(from)", + " + \"&to=\" + encodeURIComponent(to);", + "", + " requestResult = this._database._connection.POST(", + " url,", + " JSON.stringify(data));", + " }", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief delete a document in the collection, identified by its id", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.remove = function (id, overwrite) {", + " var rev = null;", + " var requestResult;", + "", + " if (id.hasOwnProperty(\"_id\")) {", + " if (id.hasOwnProperty(\"_rev\")) {", + " rev = id._rev;", + " }", + "", + " id = id._id;", + " }", + "", + " var policy = \"\";", + "", + " if (overwrite) {", + " policy = \"?policy=last\";", + " }", + "", + " if (rev === null) {", + " requestResult = this._database._connection.DELETE(", + " \"/_api/document/\" + id + policy);", + " }", + " else {", + " requestResult = this._database._connection.DELETE(", + " \"/_api/document/\" + id + policy, {'if-match' : '\"' + rev + '\"' });", + " }", + "", + " if (requestResult !== null && requestResult.error === true) {", + " var s = id.split(\"/\");", + "", + " if (s.length !== 2) {", + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;", + " }", + " else if (parseInt(s[0]) !== this._id) {", + " requestResult.errorNum = internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.code;", + " }", + "", + " if (overwrite) {", + " if (requestResult.errorNum === internal.errors.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code) {", + " return false;", + " }", + " }", + "", + " throw new ArangoError(requestResult);", + " }", + "", + " client.checkRequestResult(requestResult);", + "", + " return true;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief replace a document in the collection, identified by its id", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.replace = function (id, data, overwrite) { ", + " var rev = null;", + " var requestResult;", + "", + " if (id.hasOwnProperty(\"_id\")) {", + " if (id.hasOwnProperty(\"_rev\")) {", + " rev = id._rev;", + " }", + "", + " id = id._id;", + " }", + "", + " var policy = \"\";", + "", + " if (overwrite) {", + " policy = \"?policy=last\";", + " }", + "", + " if (rev === null) {", + " requestResult = this._database._connection.PUT(", + " \"/_api/document/\" + id + policy, ", + " JSON.stringify(data));", + " }", + " else {", + " requestResult = this._database._connection.PUT(", + " \"/_api/document/\" + id + policy, JSON.stringify(data),", + " {'if-match' : '\"' + rev + '\"' });", + " }", + "", + " if (requestResult !== null && requestResult.error === true) {", + " var s = id.split(\"/\");", + "", + " if (s.length !== 2) {", + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;", + " }", + " else if (parseInt(s[0]) !== this._id) {", + " requestResult.errorNum = internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.code;", + " }", + "", + " throw new ArangoError(requestResult);", + " }", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief update a document in the collection, identified by its id", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.update = function (id, data, overwrite, keepNull) { ", + " var rev = null;", + " var requestResult;", + "", + " if (id.hasOwnProperty(\"_id\")) {", + " if (id.hasOwnProperty(\"_rev\")) {", + " rev = id._rev;", + " }", + "", + " id = id._id;", + " }", + "", + " // set default value for keepNull", + " var keepNullValue = ((typeof keepNull == \"undefined\") ? true : keepNull);", + " var params = \"?keepNull=\" + (keepNullValue ? \"true\" : \"false\");", + "", + " if (overwrite) {", + " params += \"&policy=last\";", + " }", + "", + " if (rev === null) {", + " requestResult = this._database._connection.PATCH(", + " \"/_api/document/\" + id + params, ", + " JSON.stringify(data));", + " }", + " else {", + " requestResult = this._database._connection.PATCH(", + " \"/_api/document/\" + id + params, JSON.stringify(data),", + " {'if-match' : '\"' + rev + '\"' });", + " }", + "", + " if (requestResult !== null && requestResult.error === true) {", + " var s = id.split(\"/\");", + "", + " if (s.length !== 2) {", + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;", + " }", + " else if (parseInt(s[0]) !== this._id) {", + " requestResult.errorNum = internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.code;", + " }", + "", + " throw new ArangoError(requestResult);", + " }", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief returns the edges starting or ending in a vertex", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.edges = function (vertex) {", + " // if vertex is a list, iterator and concat", + " if (vertex instanceof Array) {", + " var edges = [];", + " var i;", + "", + " for (i = 0; i < vertex.length; ++i) {", + " var e = this.edges(vertex[i]);", + "", + " edges.push.apply(edges, e);", + " }", + "", + " return edges;", + " }", + "", + " if (vertex.hasOwnProperty(\"_id\")) {", + " vertex = vertex._id;", + " }", + "", + " // get the edges", + " var requestResult = this._database._connection.GET(", + " \"/_api/edges/\" + encodeURIComponent(this._id) + \"?vertex=\" + encodeURIComponent(vertex));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult['edges'];", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief returns the edges ending in a vertex", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.inEdges = function (vertex) {", + " // if vertex is a list, iterator and concat", + " if (vertex instanceof Array) {", + " var edges = [];", + " var i;", + "", + " for (i = 0; i < vertex.length; ++i) {", + " var e = this.inEdges(vertex[i]);", + "", + " edges.push.apply(edges, e);", + " }", + "", + " return edges;", + " }", + "", + " if (vertex.hasOwnProperty(\"_id\")) {", + " vertex = vertex._id;", + " }", + "", + " // get the edges", + " var requestResult = this._database._connection.GET(", + " \"/_api/edges/\" + encodeURIComponent(this._id)", + " + \"?direction=in&vertex=\" + encodeURIComponent(vertex));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult['edges'];", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief returns the edges starting in a vertex", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.outEdges = function (vertex) {", + " // if vertex is a list, iterator and concat", + " if (vertex instanceof Array) {", + " var edges = [];", + " var i;", + "", + " for (i = 0; i < vertex.length; ++i) {", + " var e = this.outEdges(vertex[i]);", + "", + " edges.push.apply(edges, e);", + " }", + "", + " return edges;", + " }", + "", + " if (vertex.hasOwnProperty(\"_id\")) {", + " vertex = vertex._id;", + " }", + "", + " // get the edges", + " var requestResult = this._database._connection.GET(", + " \"/_api/edges/\" + encodeURIComponent(this._id)", + " + \"?direction=out&vertex=\" + encodeURIComponent(vertex));", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult['edges'];", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "}());", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- ArangoDatabase", + "// -----------------------------------------------------------------------------", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- constructors and destructors", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief constructor", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function ArangoDatabase (connection) {", + " this._connection = connection;", + " this._collectionConstructor = ArangoCollection;", + "}", + "", + "(function () {", + " var internal = require(\"internal\");", + " var client = require(\"arangosh\");", + " ", + " internal.ArangoDatabase = ArangoDatabase;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- private functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief help for ArangoDatabase", + "////////////////////////////////////////////////////////////////////////////////", + "", + " client.helpArangoDatabase = client.createHelpHeadline(\"ArangoDatabase help\") +", + " 'ArangoDatabase constructor: ' + \"\\n\" +", + " ' > db = new ArangoDatabase(connection); ' + \"\\n\" +", + " ' ' + \"\\n\" +", + " 'Administration Functions: ' + \"\\n\" +", + " ' _help(); this help ' + \"\\n\" +", + " ' ' + \"\\n\" +", + " 'Collection Functions: ' + \"\\n\" +", + " ' _collections() list all collections ' + \"\\n\" +", + " ' _collection() get collection by identifier/name' + \"\\n\" +", + " ' _create(, ) creates a new collection ' + \"\\n\" +", + " ' _truncate() delete all documents ' + \"\\n\" +", + " ' _drop() delete a collection ' + \"\\n\" +", + " ' ' + \"\\n\" +", + " 'Document Functions: ' + \"\\n\" +", + " ' _document() get document by handle ' + \"\\n\" +", + " ' _replace(, , overwrite document ' + \"\\n\" +", + " ' ) ' + \"\\n\" +", + " ' _update(, , update document ' + \"\\n\" +", + " ' , ) ' + \"\\n\" +", + " ' _remove() delete document ' + \"\\n\" +", + " ' ' + \"\\n\" +", + " 'Query Functions: ' + \"\\n\" +", + " ' _createStatement(); create and return select query ' + \"\\n\" +", + " ' ' + \"\\n\" +", + " 'Attributes: ' + \"\\n\" +", + " ' collection with the given name ';", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief print the help for ArangoDatabase", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._help = function () { ", + " internal.print(client.helpArangoDatabase);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return a string representation of the database object", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype.toString = function () { ", + " return \"[object ArangoDatabase]\";", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- collection functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return all collections from the database", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._collections = function () {", + " var requestResult = this._connection.GET(\"/_api/collection\");", + " ", + " client.checkRequestResult(requestResult);", + "", + " if (requestResult[\"collections\"] !== undefined) {", + " var collections = requestResult[\"collections\"];", + " var result = [];", + " var i;", + " ", + " // add all collentions to object", + " for (i = 0; i < collections.length; ++i) {", + " var collection = new this._collectionConstructor(this, collections[i]);", + "", + " this[collection._name] = collection;", + " result.push(collection);", + " }", + " ", + " return result;", + " }", + " ", + " return undefined;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return a single collection, identified by its id or name", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._collection = function (id) {", + " var requestResult = this._connection.GET(", + " \"/_api/collection/\" + encodeURIComponent(id));", + " ", + " // return null in case of not found", + " if (requestResult !== null", + " && requestResult.error === true ", + " && requestResult.errorNum === internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code) {", + " return null;", + " }", + "", + " // check all other errors and throw them", + " client.checkRequestResult(requestResult);", + "", + " var name = requestResult[\"name\"];", + "", + " if (name !== undefined) {", + " this[name] = new this._collectionConstructor(this, requestResult);", + " return this[name];", + " }", + " ", + " return undefined;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief creates a new collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._create = function (name, properties, type) {", + " var body = {", + " \"name\" : name,", + " \"type\" : ArangoCollection.TYPE_DOCUMENT", + " };", + "", + " if (properties !== undefined) {", + " if (properties.hasOwnProperty(\"waitForSync\")) {", + " body.waitForSync = properties.waitForSync;", + " }", + "", + " if (properties.hasOwnProperty(\"journalSize\")) {", + " body.journalSize = properties.journalSize;", + " }", + "", + " if (properties.hasOwnProperty(\"isSystem\")) {", + " body.isSystem = properties.isSystem;", + " }", + " }", + "", + " if (type != undefined && type == ArangoCollection.TYPE_EDGE) {", + " body.type = type;", + " }", + "", + " var requestResult = this._connection.POST(", + " \"/_api/collection\",", + " JSON.stringify(body));", + "", + " client.checkRequestResult(requestResult);", + "", + " var nname = requestResult[\"name\"];", + "", + " if (nname !== undefined) {", + " this[nname] = new this._collectionConstructor(this, requestResult);", + " return this[nname];", + " }", + " ", + " return undefined;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief creates a new document collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._createDocumentCollection = function (name, properties) {", + " return this._create(name, properties, ArangoCollection.TYPE_DOCUMENT);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief creates a new edges collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._createEdgeCollection = function (name, properties) {", + " return this._create(name, properties, ArangoCollection.TYPE_EDGE);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief truncates a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._truncate = function (id) {", + " var name;", + "", + " for (name in this) {", + " if (this.hasOwnProperty(name)) {", + " var collection = this[name];", + "", + " if (collection instanceof this._collectionConstructor) {", + " if (collection._id === id || collection._name === id) {", + " return collection.truncate();", + " }", + " }", + " }", + " }", + "", + " return undefined;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief drops a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._drop = function (id) {", + " var name;", + "", + " for (name in this) {", + " if (this.hasOwnProperty(name)) {", + " var collection = this[name];", + "", + " if (collection instanceof this._collectionConstructor) {", + " if (collection._id === id || collection._name === id) {", + " return collection.drop();", + " }", + " }", + " }", + " }", + "", + " return undefined;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief returns one index", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._index = function (id) {", + " if (id.hasOwnProperty(\"id\")) {", + " id = id.id;", + " }", + "", + " var requestResult = this._connection.GET(\"/_api/index/\" + id);", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief deletes one index", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._dropIndex = function (id) {", + " if (id.hasOwnProperty(\"id\")) {", + " id = id.id;", + " }", + "", + " var requestResult = this._connection.DELETE(\"/_api/index/\" + id);", + "", + " if (requestResult !== null", + " && requestResult.error === true ", + " && requestResult.errorNum === internal.errors.ERROR_ARANGO_INDEX_NOT_FOUND.code) {", + " return false;", + " }", + "", + " client.checkRequestResult(requestResult);", + "", + " return true;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- document functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return a single document from the collection, identified by its id", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._document = function (id) {", + " var rev = null;", + " var requestResult;", + "", + " if (id.hasOwnProperty(\"_id\")) {", + " if (id.hasOwnProperty(\"_rev\")) {", + " rev = id._rev;", + " }", + "", + " id = id._id;", + " }", + "", + " if (rev === null) {", + " requestResult = this._connection.GET(\"/_api/document/\" + id);", + " }", + " else {", + " requestResult = this._connection.GET(", + " \"/_api/document/\" + id,", + " {'if-match' : '\"' + rev + '\"' });", + " }", + "", + " if (requestResult !== null", + " && requestResult.error === true ", + " && requestResult.errorNum === internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code) {", + " var s = id.split(\"/\");", + "", + " if (s.length !== 2) {", + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;", + " }", + "", + " throw new ArangoError(requestResult);", + " }", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief delete a document in the collection, identified by its id", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._remove = function (id, overwrite) {", + " var rev = null;", + " var requestResult;", + "", + " if (id.hasOwnProperty(\"_id\")) {", + " if (id.hasOwnProperty(\"_rev\")) {", + " rev = id._rev;", + " }", + "", + " id = id._id;", + " }", + "", + " var policy = \"\";", + "", + " if (overwrite) {", + " policy = \"?policy=last\";", + " }", + "", + " if (rev === null) {", + " requestResult = this._connection.DELETE(\"/_api/document/\" + id + policy);", + " }", + " else {", + " requestResult = this._connection.DELETE(", + " \"/_api/document/\" + id + policy,", + " {'if-match' : '\"' + rev + '\"' });", + " }", + "", + " if (requestResult !== null && requestResult.error === true) {", + " var s = id.split(\"/\");", + "", + " if (s.length !== 2) {", + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;", + " }", + "", + " if (overwrite) {", + " if (requestResult.errorNum === internal.errors.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code) {", + " return false;", + " }", + " }", + "", + " throw new ArangoError(requestResult);", + " }", + "", + " client.checkRequestResult(requestResult);", + "", + " return true;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief replace a document in the collection, identified by its id", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._replace = function (id, data, overwrite) { ", + " var rev = null;", + " var requestResult;", + "", + " if (id.hasOwnProperty(\"_id\")) {", + " if (id.hasOwnProperty(\"_rev\")) {", + " rev = id._rev;", + " }", + "", + " id = id._id;", + " }", + "", + " var policy = \"\";", + "", + " if (overwrite) {", + " policy = \"?policy=last\";", + " }", + "", + " if (rev === null) {", + " requestResult = this._connection.PUT(", + " \"/_api/document/\" + id + policy,", + " JSON.stringify(data));", + " }", + " else {", + " requestResult = this._connection.PUT(", + " \"/_api/document/\" + id + policy,", + " JSON.stringify(data),", + " {'if-match' : '\"' + rev + '\"' });", + " }", + "", + " if (requestResult !== null && requestResult.error === true) {", + " var s = id.split(\"/\");", + "", + " if (s.length !== 2) {", + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;", + " }", + "", + " throw new ArangoError(requestResult);", + " }", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief update a document in the collection, identified by its id", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._update = function (id, data, overwrite, keepNull) { ", + " var rev = null;", + " var requestResult;", + " ", + " if (id.hasOwnProperty(\"_id\")) {", + " if (id.hasOwnProperty(\"_rev\")) {", + " rev = id._rev;", + " }", + "", + " id = id._id;", + " }", + "", + " // set default value for keepNull", + " var keepNullValue = ((typeof keepNull == \"undefined\") ? true : keepNull);", + " var params = \"?keepNull=\" + (keepNullValue ? \"true\" : \"false\");", + "", + " if (overwrite) {", + " params += \"&policy=last\";", + " }", + "", + " if (rev === null) {", + " requestResult = this._connection.PATCH(", + " \"/_api/document/\" + id + params,", + " JSON.stringify(data));", + " }", + " else {", + " requestResult = this._connection.PATCH(", + " \"/_api/document/\" + id + params,", + " JSON.stringify(data),", + " {'if-match' : '\"' + rev + '\"' });", + " }", + "", + " if (requestResult !== null && requestResult.error === true) {", + " var s = id.split(\"/\");", + "", + " if (s.length !== 2) {", + " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;", + " }", + "", + " throw new ArangoError(requestResult);", + " }", + "", + " client.checkRequestResult(requestResult);", + "", + " return requestResult;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- query functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief factory method to create a new statement", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._createStatement = function (data) { ", + " return new ArangoStatement(this, data);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "}());", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- initialisers", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup ArangoShell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "(function () {", + " var internal = require(\"internal\");", + " var client = require(\"arangosh\");", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief general help", + "////////////////////////////////////////////////////////////////////////////////", + "", + " client.HELP = client.createHelpHeadline(\"Help\") +", + " 'Predefined objects: ' + \"\\n\" +", + " ' arango: ArangoConnection ' + \"\\n\" +", + " ' db: ArangoDatabase ' + \"\\n\" +", + " 'Example: ' + \"\\n\" +", + " ' > db._collections(); list all collections ' + \"\\n\" +", + " ' > db..all().toArray(); list all documents ' + \"\\n\" +", + " ' > id = db..save({ ... }); save a document ' + \"\\n\" +", + " ' > db..remove(<_id>); delete a document ' + \"\\n\" +", + " ' > db..document(<_id>); get a document ' + \"\\n\" +", + " ' > db..replace(<_id>, {...}); overwrite a document ' + \"\\n\" +", + " ' > db..update(<_id>, {...}); partially update a document' + \"\\n\" +", + " ' > help show help pages ' + \"\\n\" +", + " ' > exit ' + \"\\n\" +", + " 'Note: collection names may be cached in arangosh. To refresh them, issue: ' + \"\\n\" +", + " ' > db._collections(); ';", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief query help", + "////////////////////////////////////////////////////////////////////////////////", + "", + " client.helpQueries = client.createHelpHeadline(\"Select query help\") +", + " 'Create a select query: ' + \"\\n\" +", + " ' > st = new ArangoStatement(db, { \"query\" : \"for...\" }); ' + \"\\n\" +", + " ' > st = db._createStatement({ \"query\" : \"for...\" }); ' + \"\\n\" +", + " 'Set query options: ' + \"\\n\" +", + " ' > st.setBatchSize(); set the max. number of results ' + \"\\n\" +", + " ' to be transferred per roundtrip ' + \"\\n\" +", + " ' > st.setCount(); set count flag (return number of ' + \"\\n\" +", + " ' results in \"count\" attribute) ' + \"\\n\" +", + " 'Get query options: ' + \"\\n\" +", + " ' > st.setBatchSize(); return the max. number of results ' + \"\\n\" +", + " ' to be transferred per roundtrip ' + \"\\n\" +", + " ' > st.getCount(); return count flag (return number of' + \"\\n\" +", + " ' results in \"count\" attribute) ' + \"\\n\" +", + " ' > st.getQuery(); return query string ' + \"\\n\" +", + " ' results in \"count\" attribute) ' + \"\\n\" +", + " 'Bind parameters to a query: ' + \"\\n\" +", + " ' > st.bind(, ); bind single variable ' + \"\\n\" +", + " ' > st.bind(); bind multiple variables ' + \"\\n\" +", + " 'Execute query: ' + \"\\n\" +", + " ' > c = st.execute(); returns a cursor ' + \"\\n\" +", + " 'Get all results in an array: ' + \"\\n\" +", + " ' > e = c.elements(); ' + \"\\n\" +", + " 'Or loop over the result set: ' + \"\\n\" +", + " ' > while (c.hasNext()) { print( c.next() ); } ';", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief extended help", + "////////////////////////////////////////////////////////////////////////////////", + "", + " client.helpExtended = client.createHelpHeadline(\"More help\") +", + " 'Pager: ' + \"\\n\" +", + " ' > stop_pager() stop the pager output ' + \"\\n\" +", + " ' > start_pager() start the pager ' + \"\\n\" +", + " 'Pretty printing: ' + \"\\n\" +", + " ' > stop_pretty_print() stop pretty printing ' + \"\\n\" +", + " ' > start_pretty_print() start pretty printing ' + \"\\n\" +", + " 'Color output: ' + \"\\n\" +", + " ' > stop_color_print() stop color printing ' + \"\\n\" +", + " ' > start_color_print() start color printing ' + \"\\n\" +", + " ' > start_color_print(COLOR_BLUE) set color ' + \"\\n\" +", + " 'Print function: ' + \"\\n\" +", + " ' > print(x) std. print function ' + \"\\n\" +", + " ' > print_plain(x) print without pretty printing' + \"\\n\" +", + " ' and without colors ';", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief create the global db object and load the collections", + "////////////////////////////////////////////////////////////////////////////////", + "", + " try {", + " if (typeof arango !== 'undefined') {", + "", + " // default databases", + " db = internal.db = new ArangoDatabase(arango);", + " edges = internal.edges = db;", + "", + " // load collection data", + " internal.db._collections();", + "", + " // load simple queries", + " require(\"simple-query\");", + "", + " if (! internal.ARANGO_QUIET) {", + " internal.print(client.HELP);", + " }", + " }", + " }", + " catch (err) {", + " internal.print(String(err));", + " }", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "}());", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- END-OF-FILE", + "// -----------------------------------------------------------------------------", + "", + "// Local Variables:", + "// mode: outline-minor", + "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @}\\\\|/\\\\*jslint\\\\)\"", + "// End:", + "//__end__" +}; diff --git a/js/common/bootstrap/js-errors.h b/js/common/bootstrap/js-errors.h index 43a1f5bd5a..bbce46d191 100644 --- a/js/common/bootstrap/js-errors.h +++ b/js/common/bootstrap/js-errors.h @@ -1,141 +1,142 @@ -static string JS_common_bootstrap_errors = string("") - + "/*jslint indent: 2,\n" - + " nomen: true,\n" - + " maxlen: 240,\n" - + " sloppy: true,\n" - + " vars: true,\n" - + " white: true,\n" - + " plusplus: true */\n" - + "/*global require */\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief auto-generated file generated from errors.dat\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "(function () {\n" - + " var internal = require(\"internal\");\n" - + "\n" - + " internal.errors = {\n" - + " \"ERROR_NO_ERROR\" : { \"code\" : 0, \"message\" : \"no error\" }, \n" - + " \"ERROR_FAILED\" : { \"code\" : 1, \"message\" : \"failed\" }, \n" - + " \"ERROR_SYS_ERROR\" : { \"code\" : 2, \"message\" : \"system error\" }, \n" - + " \"ERROR_OUT_OF_MEMORY\" : { \"code\" : 3, \"message\" : \"out of memory\" }, \n" - + " \"ERROR_INTERNAL\" : { \"code\" : 4, \"message\" : \"internal error\" }, \n" - + " \"ERROR_ILLEGAL_NUMBER\" : { \"code\" : 5, \"message\" : \"illegal number\" }, \n" - + " \"ERROR_NUMERIC_OVERFLOW\" : { \"code\" : 6, \"message\" : \"numeric overflow\" }, \n" - + " \"ERROR_ILLEGAL_OPTION\" : { \"code\" : 7, \"message\" : \"illegal option\" }, \n" - + " \"ERROR_DEAD_PID\" : { \"code\" : 8, \"message\" : \"dead process identifier\" }, \n" - + " \"ERROR_NOT_IMPLEMENTED\" : { \"code\" : 9, \"message\" : \"not implemented\" }, \n" - + " \"ERROR_BAD_PARAMETER\" : { \"code\" : 10, \"message\" : \"bad parameter\" }, \n" - + " \"ERROR_FORBIDDEN\" : { \"code\" : 11, \"message\" : \"forbidden\" }, \n" - + " \"ERROR_OUT_OF_MEMORY_MMAP\" : { \"code\" : 12, \"message\" : \"out of memory in mmap\" }, \n" - + " \"ERROR_CORRUPTED_CSV\" : { \"code\" : 13, \"message\" : \"csv is corrupt\" }, \n" - + " \"ERROR_HTTP_BAD_PARAMETER\" : { \"code\" : 400, \"message\" : \"bad parameter\" }, \n" - + " \"ERROR_HTTP_FORBIDDEN\" : { \"code\" : 403, \"message\" : \"forbidden\" }, \n" - + " \"ERROR_HTTP_NOT_FOUND\" : { \"code\" : 404, \"message\" : \"not found\" }, \n" - + " \"ERROR_HTTP_METHOD_NOT_ALLOWED\" : { \"code\" : 405, \"message\" : \"method not supported\" }, \n" - + " \"ERROR_HTTP_SERVER_ERROR\" : { \"code\" : 500, \"message\" : \"internal server error\" }, \n" - + " \"ERROR_HTTP_CORRUPTED_JSON\" : { \"code\" : 600, \"message\" : \"invalid JSON object\" }, \n" - + " \"ERROR_HTTP_SUPERFLUOUS_SUFFICES\" : { \"code\" : 601, \"message\" : \"superfluous URL suffices\" }, \n" - + " \"ERROR_ARANGO_ILLEGAL_STATE\" : { \"code\" : 1000, \"message\" : \"illegal state\" }, \n" - + " \"ERROR_ARANGO_SHAPER_FAILED\" : { \"code\" : 1001, \"message\" : \"illegal shaper\" }, \n" - + " \"ERROR_ARANGO_DATAFILE_SEALED\" : { \"code\" : 1002, \"message\" : \"datafile sealed\" }, \n" - + " \"ERROR_ARANGO_UNKNOWN_COLLECTION_TYPE\" : { \"code\" : 1003, \"message\" : \"unknown type\" }, \n" - + " \"ERROR_ARANGO_READ_ONLY\" : { \"code\" : 1004, \"message\" : \"ready only\" }, \n" - + " \"ERROR_ARANGO_DUPLICATE_IDENTIFIER\" : { \"code\" : 1005, \"message\" : \"duplicate identifier\" }, \n" - + " \"ERROR_ARANGO_DATAFILE_UNREADABLE\" : { \"code\" : 1006, \"message\" : \"datafile unreadable\" }, \n" - + " \"ERROR_ARANGO_CORRUPTED_DATAFILE\" : { \"code\" : 1100, \"message\" : \"corrupted datafile\" }, \n" - + " \"ERROR_ARANGO_ILLEGAL_PARAMETER_FILE\" : { \"code\" : 1101, \"message\" : \"illegal parameter file\" }, \n" - + " \"ERROR_ARANGO_CORRUPTED_COLLECTION\" : { \"code\" : 1102, \"message\" : \"corrupted collection\" }, \n" - + " \"ERROR_ARANGO_MMAP_FAILED\" : { \"code\" : 1103, \"message\" : \"mmap failed\" }, \n" - + " \"ERROR_ARANGO_FILESYSTEM_FULL\" : { \"code\" : 1104, \"message\" : \"filesystem full\" }, \n" - + " \"ERROR_ARANGO_NO_JOURNAL\" : { \"code\" : 1105, \"message\" : \"no journal\" }, \n" - + " \"ERROR_ARANGO_DATAFILE_ALREADY_EXISTS\" : { \"code\" : 1106, \"message\" : \"cannot create/rename datafile because it already exists\" }, \n" - + " \"ERROR_ARANGO_DATABASE_LOCKED\" : { \"code\" : 1107, \"message\" : \"database is locked\" }, \n" - + " \"ERROR_ARANGO_COLLECTION_DIRECTORY_ALREADY_EXISTS\" : { \"code\" : 1108, \"message\" : \"cannot create/rename collection because directory already exists\" }, \n" - + " \"ERROR_ARANGO_CONFLICT\" : { \"code\" : 1200, \"message\" : \"conflict\" }, \n" - + " \"ERROR_ARANGO_WRONG_VOCBASE_PATH\" : { \"code\" : 1201, \"message\" : \"wrong path for database\" }, \n" - + " \"ERROR_ARANGO_DOCUMENT_NOT_FOUND\" : { \"code\" : 1202, \"message\" : \"document not found\" }, \n" - + " \"ERROR_ARANGO_COLLECTION_NOT_FOUND\" : { \"code\" : 1203, \"message\" : \"collection not found\" }, \n" - + " \"ERROR_ARANGO_COLLECTION_PARAMETER_MISSING\" : { \"code\" : 1204, \"message\" : \"parameter 'collection' not found\" }, \n" - + " \"ERROR_ARANGO_DOCUMENT_HANDLE_BAD\" : { \"code\" : 1205, \"message\" : \"illegal document handle\" }, \n" - + " \"ERROR_ARANGO_MAXIMAL_SIZE_TOO_SMALL\" : { \"code\" : 1206, \"message\" : \"maixaml size of journal too small\" }, \n" - + " \"ERROR_ARANGO_DUPLICATE_NAME\" : { \"code\" : 1207, \"message\" : \"duplicate name\" }, \n" - + " \"ERROR_ARANGO_ILLEGAL_NAME\" : { \"code\" : 1208, \"message\" : \"illegal name\" }, \n" - + " \"ERROR_ARANGO_NO_INDEX\" : { \"code\" : 1209, \"message\" : \"no suitable index known\" }, \n" - + " \"ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED\" : { \"code\" : 1210, \"message\" : \"unique constraint violated\" }, \n" - + " \"ERROR_ARANGO_GEO_INDEX_VIOLATED\" : { \"code\" : 1211, \"message\" : \"geo index violated\" }, \n" - + " \"ERROR_ARANGO_INDEX_NOT_FOUND\" : { \"code\" : 1212, \"message\" : \"index not found\" }, \n" - + " \"ERROR_ARANGO_CROSS_COLLECTION_REQUEST\" : { \"code\" : 1213, \"message\" : \"cross collection request not allowed\" }, \n" - + " \"ERROR_ARANGO_INDEX_HANDLE_BAD\" : { \"code\" : 1214, \"message\" : \"illegal index handle\" }, \n" - + " \"ERROR_ARANGO_CAP_CONSTRAINT_ALREADY_DEFINED\" : { \"code\" : 1215, \"message\" : \"cap constraint already defined\" }, \n" - + " \"ERROR_ARANGO_DOCUMENT_TOO_LARGE\" : { \"code\" : 1216, \"message\" : \"document too large\" }, \n" - + " \"ERROR_ARANGO_COLLECTION_NOT_UNLOADED\" : { \"code\" : 1217, \"message\" : \"collection must be unloaded\" }, \n" - + " \"ERROR_ARANGO_COLLECTION_TYPE_INVALID\" : { \"code\" : 1218, \"message\" : \"collection type invalid\" }, \n" - + " \"ERROR_ARANGO_DATAFILE_FULL\" : { \"code\" : 1300, \"message\" : \"datafile full\" }, \n" - + " \"ERROR_QUERY_KILLED\" : { \"code\" : 1500, \"message\" : \"query killed\" }, \n" - + " \"ERROR_QUERY_PARSE\" : { \"code\" : 1501, \"message\" : \"%s\" }, \n" - + " \"ERROR_QUERY_EMPTY\" : { \"code\" : 1502, \"message\" : \"query is empty\" }, \n" - + " \"ERROR_QUERY_SCRIPT\" : { \"code\" : 1503, \"message\" : \"runtime error '%s'\" }, \n" - + " \"ERROR_QUERY_NUMBER_OUT_OF_RANGE\" : { \"code\" : 1504, \"message\" : \"number out of range\" }, \n" - + " \"ERROR_QUERY_VARIABLE_NAME_INVALID\" : { \"code\" : 1510, \"message\" : \"variable name '%s' has an invalid format\" }, \n" - + " \"ERROR_QUERY_VARIABLE_REDECLARED\" : { \"code\" : 1511, \"message\" : \"variable '%s' is assigned multiple times\" }, \n" - + " \"ERROR_QUERY_VARIABLE_NAME_UNKNOWN\" : { \"code\" : 1512, \"message\" : \"unknown variable '%s'\" }, \n" - + " \"ERROR_QUERY_COLLECTION_NOT_FOUND\" : { \"code\" : 1520, \"message\" : \"unable to open collection '%s'\" }, \n" - + " \"ERROR_QUERY_COLLECTION_LOCK_FAILED\" : { \"code\" : 1521, \"message\" : \"unable to read-lock collection %s\" }, \n" - + " \"ERROR_QUERY_TOO_MANY_COLLECTIONS\" : { \"code\" : 1522, \"message\" : \"too many collections\" }, \n" - + " \"ERROR_QUERY_DOCUMENT_ATTRIBUTE_REDECLARED\" : { \"code\" : 1530, \"message\" : \"document attribute '%s' is assigned multiple times\" }, \n" - + " \"ERROR_QUERY_FUNCTION_NAME_UNKNOWN\" : { \"code\" : 1540, \"message\" : \"usage of unknown function '%s'\" }, \n" - + " \"ERROR_QUERY_FUNCTION_ARGUMENT_NUMBER_MISMATCH\" : { \"code\" : 1541, \"message\" : \"invalid number of arguments for function '%s'\" }, \n" - + " \"ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH\" : { \"code\" : 1542, \"message\" : \"invalid argument type used in call to function '%s()'\" }, \n" - + " \"ERROR_QUERY_BIND_PARAMETERS_INVALID\" : { \"code\" : 1550, \"message\" : \"invalid structure of bind parameters\" }, \n" - + " \"ERROR_QUERY_BIND_PARAMETER_MISSING\" : { \"code\" : 1551, \"message\" : \"no value specified for declared bind parameter '%s'\" }, \n" - + " \"ERROR_QUERY_BIND_PARAMETER_UNDECLARED\" : { \"code\" : 1552, \"message\" : \"bind parameter '%s' was not declared in the query\" }, \n" - + " \"ERROR_QUERY_BIND_PARAMETER_TYPE\" : { \"code\" : 1553, \"message\" : \"bind parameter '%s' has an invalid value or type\" }, \n" - + " \"ERROR_QUERY_INVALID_LOGICAL_VALUE\" : { \"code\" : 1560, \"message\" : \"invalid logical value\" }, \n" - + " \"ERROR_QUERY_INVALID_ARITHMETIC_VALUE\" : { \"code\" : 1561, \"message\" : \"invalid arithmetic value\" }, \n" - + " \"ERROR_QUERY_DIVISION_BY_ZERO\" : { \"code\" : 1562, \"message\" : \"division by zero\" }, \n" - + " \"ERROR_QUERY_LIST_EXPECTED\" : { \"code\" : 1563, \"message\" : \"list expected\" }, \n" - + " \"ERROR_QUERY_FAIL_CALLED\" : { \"code\" : 1569, \"message\" : \"FAIL(%s) called\" }, \n" - + " \"ERROR_QUERY_GEO_INDEX_MISSING\" : { \"code\" : 1570, \"message\" : \"no suitable geo index found for geo restriction on '%s'\" }, \n" - + " \"ERROR_CURSOR_NOT_FOUND\" : { \"code\" : 1600, \"message\" : \"cursor not found\" }, \n" - + " \"ERROR_KEYVALUE_INVALID_KEY\" : { \"code\" : 1800, \"message\" : \"invalid key declaration\" }, \n" - + " \"ERROR_KEYVALUE_KEY_EXISTS\" : { \"code\" : 1801, \"message\" : \"key already exists\" }, \n" - + " \"ERROR_KEYVALUE_KEY_NOT_FOUND\" : { \"code\" : 1802, \"message\" : \"key not found\" }, \n" - + " \"ERROR_KEYVALUE_KEY_NOT_UNIQUE\" : { \"code\" : 1803, \"message\" : \"key is not unique\" }, \n" - + " \"ERROR_KEYVALUE_KEY_NOT_CHANGED\" : { \"code\" : 1804, \"message\" : \"key value not changed\" }, \n" - + " \"ERROR_KEYVALUE_KEY_NOT_REMOVED\" : { \"code\" : 1805, \"message\" : \"key value not removed\" }, \n" - + " \"ERROR_KEYVALUE_NO_VALUE\" : { \"code\" : 1806, \"message\" : \"missing value\" }, \n" - + " \"ERROR_GRAPH_INVALID_GRAPH\" : { \"code\" : 1901, \"message\" : \"invalid graph\" }, \n" - + " \"ERROR_GRAPH_COULD_NOT_CREATE_GRAPH\" : { \"code\" : 1902, \"message\" : \"could not create graph\" }, \n" - + " \"ERROR_GRAPH_INVALID_VERTEX\" : { \"code\" : 1903, \"message\" : \"invalid vertex\" }, \n" - + " \"ERROR_GRAPH_COULD_NOT_CREATE_VERTEX\" : { \"code\" : 1904, \"message\" : \"could not create vertex\" }, \n" - + " \"ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX\" : { \"code\" : 1905, \"message\" : \"could not change vertex\" }, \n" - + " \"ERROR_GRAPH_INVALID_EDGE\" : { \"code\" : 1906, \"message\" : \"invalid edge\" }, \n" - + " \"ERROR_GRAPH_COULD_NOT_CREATE_EDGE\" : { \"code\" : 1907, \"message\" : \"could not create edge\" }, \n" - + " \"ERROR_GRAPH_COULD_NOT_CHANGE_EDGE\" : { \"code\" : 1908, \"message\" : \"could not change edge\" }, \n" - + " \"SIMPLE_CLIENT_UNKNOWN_ERROR\" : { \"code\" : 2000, \"message\" : \"unknown client error\" }, \n" - + " \"SIMPLE_CLIENT_COULD_NOT_CONNECT\" : { \"code\" : 2001, \"message\" : \"could not connect to server\" }, \n" - + " \"SIMPLE_CLIENT_COULD_NOT_WRITE\" : { \"code\" : 2002, \"message\" : \"could not write to server\" }, \n" - + " \"SIMPLE_CLIENT_COULD_NOT_READ\" : { \"code\" : 2003, \"message\" : \"could not read from server\" }, \n" - + " \"ERROR_ARANGO_INDEX_PQ_INSERT_FAILED\" : { \"code\" : 3100, \"message\" : \"priority queue insert failure\" }, \n" - + " \"ERROR_ARANGO_INDEX_PQ_REMOVE_FAILED\" : { \"code\" : 3110, \"message\" : \"priority queue remove failure\" }, \n" - + " \"ERROR_ARANGO_INDEX_PQ_REMOVE_ITEM_MISSING\" : { \"code\" : 3111, \"message\" : \"priority queue remove failure - item missing in index\" }, \n" - + " \"ERROR_ARANGO_INDEX_HASH_INSERT_ITEM_DUPLICATED\" : { \"code\" : 3312, \"message\" : \"(non-unique) hash index insert failure - document duplicated in index\" }, \n" - + " \"ERROR_ARANGO_INDEX_SKIPLIST_INSERT_ITEM_DUPLICATED\" : { \"code\" : 3313, \"message\" : \"(non-unique) skiplist index insert failure - document duplicated in index\" }, \n" - + " \"WARNING_ARANGO_INDEX_HASH_DOCUMENT_ATTRIBUTE_MISSING\" : { \"code\" : 3200, \"message\" : \"hash index insertion warning - attribute missing in document\" }, \n" - + " \"WARNING_ARANGO_INDEX_HASH_UPDATE_ATTRIBUTE_MISSING\" : { \"code\" : 3202, \"message\" : \"hash index update warning - attribute missing in revised document\" }, \n" - + " \"WARNING_ARANGO_INDEX_HASH_REMOVE_ITEM_MISSING\" : { \"code\" : 3211, \"message\" : \"hash index remove failure - item missing in index\" }, \n" - + " \"WARNING_ARANGO_INDEX_SKIPLIST_DOCUMENT_ATTRIBUTE_MISSING\" : { \"code\" : 3300, \"message\" : \"skiplist index insertion warning - attribute missing in document\" }, \n" - + " \"WARNING_ARANGO_INDEX_SKIPLIST_UPDATE_ATTRIBUTE_MISSING\" : { \"code\" : 3302, \"message\" : \"skiplist index update warning - attribute missing in revised document\" }, \n" - + " \"WARNING_ARANGO_INDEX_SKIPLIST_REMOVE_ITEM_MISSING\" : { \"code\" : 3311, \"message\" : \"skiplist index remove failure - item missing in index\" }, \n" - + " \"WARNING_ARANGO_INDEX_BITARRAY_DOCUMENT_ATTRIBUTE_MISSING\" : { \"code\" : 3400, \"message\" : \"bitarray index insertion warning - attribute missing in document\" }, \n" - + " \"WARNING_ARANGO_INDEX_BITARRAY_UPDATE_ATTRIBUTE_MISSING\" : { \"code\" : 3402, \"message\" : \"bitarray index update warning - attribute missing in revised document\" }, \n" - + " \"WARNING_ARANGO_INDEX_BITARRAY_REMOVE_ITEM_MISSING\" : { \"code\" : 3411, \"message\" : \"bitarray index remove failure - item missing in index\" }, \n" - + " \"ERROR_ARANGO_INDEX_BITARRAY_INSERT_ITEM_UNSUPPORTED_VALUE\" : { \"code\" : 3413, \"message\" : \"bitarray index insert failure - document attribute value unsupported in index\" }, \n" - + " \"ERROR_ARANGO_INDEX_BITARRAY_CREATION_FAILURE_DUPLICATE_ATTRIBUTES\" : { \"code\" : 3415, \"message\" : \"bitarray index creation failure - one or more index attributes are duplicated.\" }, \n" - + " \"ERROR_ARANGO_INDEX_BITARRAY_CREATION_FAILURE_DUPLICATE_VALUES\" : { \"code\" : 3417, \"message\" : \"bitarray index creation failure - one or more index attribute values are duplicated.\" }, \n" - + "};\n" - + "}());\n" - + "\n" -; +const char* JS_common_bootstrap_errors[] = { + "/*jslint indent: 2,", + " nomen: true,", + " maxlen: 240,", + " sloppy: true,", + " vars: true,", + " white: true,", + " plusplus: true */", + "/*global require */", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief auto-generated file generated from errors.dat", + "////////////////////////////////////////////////////////////////////////////////", + "", + "(function () {", + " var internal = require(\"internal\");", + "", + " internal.errors = {", + " \"ERROR_NO_ERROR\" : { \"code\" : 0, \"message\" : \"no error\" }, ", + " \"ERROR_FAILED\" : { \"code\" : 1, \"message\" : \"failed\" }, ", + " \"ERROR_SYS_ERROR\" : { \"code\" : 2, \"message\" : \"system error\" }, ", + " \"ERROR_OUT_OF_MEMORY\" : { \"code\" : 3, \"message\" : \"out of memory\" }, ", + " \"ERROR_INTERNAL\" : { \"code\" : 4, \"message\" : \"internal error\" }, ", + " \"ERROR_ILLEGAL_NUMBER\" : { \"code\" : 5, \"message\" : \"illegal number\" }, ", + " \"ERROR_NUMERIC_OVERFLOW\" : { \"code\" : 6, \"message\" : \"numeric overflow\" }, ", + " \"ERROR_ILLEGAL_OPTION\" : { \"code\" : 7, \"message\" : \"illegal option\" }, ", + " \"ERROR_DEAD_PID\" : { \"code\" : 8, \"message\" : \"dead process identifier\" }, ", + " \"ERROR_NOT_IMPLEMENTED\" : { \"code\" : 9, \"message\" : \"not implemented\" }, ", + " \"ERROR_BAD_PARAMETER\" : { \"code\" : 10, \"message\" : \"bad parameter\" }, ", + " \"ERROR_FORBIDDEN\" : { \"code\" : 11, \"message\" : \"forbidden\" }, ", + " \"ERROR_OUT_OF_MEMORY_MMAP\" : { \"code\" : 12, \"message\" : \"out of memory in mmap\" }, ", + " \"ERROR_CORRUPTED_CSV\" : { \"code\" : 13, \"message\" : \"csv is corrupt\" }, ", + " \"ERROR_HTTP_BAD_PARAMETER\" : { \"code\" : 400, \"message\" : \"bad parameter\" }, ", + " \"ERROR_HTTP_FORBIDDEN\" : { \"code\" : 403, \"message\" : \"forbidden\" }, ", + " \"ERROR_HTTP_NOT_FOUND\" : { \"code\" : 404, \"message\" : \"not found\" }, ", + " \"ERROR_HTTP_METHOD_NOT_ALLOWED\" : { \"code\" : 405, \"message\" : \"method not supported\" }, ", + " \"ERROR_HTTP_SERVER_ERROR\" : { \"code\" : 500, \"message\" : \"internal server error\" }, ", + " \"ERROR_HTTP_CORRUPTED_JSON\" : { \"code\" : 600, \"message\" : \"invalid JSON object\" }, ", + " \"ERROR_HTTP_SUPERFLUOUS_SUFFICES\" : { \"code\" : 601, \"message\" : \"superfluous URL suffices\" }, ", + " \"ERROR_ARANGO_ILLEGAL_STATE\" : { \"code\" : 1000, \"message\" : \"illegal state\" }, ", + " \"ERROR_ARANGO_SHAPER_FAILED\" : { \"code\" : 1001, \"message\" : \"illegal shaper\" }, ", + " \"ERROR_ARANGO_DATAFILE_SEALED\" : { \"code\" : 1002, \"message\" : \"datafile sealed\" }, ", + " \"ERROR_ARANGO_UNKNOWN_COLLECTION_TYPE\" : { \"code\" : 1003, \"message\" : \"unknown type\" }, ", + " \"ERROR_ARANGO_READ_ONLY\" : { \"code\" : 1004, \"message\" : \"ready only\" }, ", + " \"ERROR_ARANGO_DUPLICATE_IDENTIFIER\" : { \"code\" : 1005, \"message\" : \"duplicate identifier\" }, ", + " \"ERROR_ARANGO_DATAFILE_UNREADABLE\" : { \"code\" : 1006, \"message\" : \"datafile unreadable\" }, ", + " \"ERROR_ARANGO_CORRUPTED_DATAFILE\" : { \"code\" : 1100, \"message\" : \"corrupted datafile\" }, ", + " \"ERROR_ARANGO_ILLEGAL_PARAMETER_FILE\" : { \"code\" : 1101, \"message\" : \"illegal parameter file\" }, ", + " \"ERROR_ARANGO_CORRUPTED_COLLECTION\" : { \"code\" : 1102, \"message\" : \"corrupted collection\" }, ", + " \"ERROR_ARANGO_MMAP_FAILED\" : { \"code\" : 1103, \"message\" : \"mmap failed\" }, ", + " \"ERROR_ARANGO_FILESYSTEM_FULL\" : { \"code\" : 1104, \"message\" : \"filesystem full\" }, ", + " \"ERROR_ARANGO_NO_JOURNAL\" : { \"code\" : 1105, \"message\" : \"no journal\" }, ", + " \"ERROR_ARANGO_DATAFILE_ALREADY_EXISTS\" : { \"code\" : 1106, \"message\" : \"cannot create/rename datafile because it already exists\" }, ", + " \"ERROR_ARANGO_DATABASE_LOCKED\" : { \"code\" : 1107, \"message\" : \"database is locked\" }, ", + " \"ERROR_ARANGO_COLLECTION_DIRECTORY_ALREADY_EXISTS\" : { \"code\" : 1108, \"message\" : \"cannot create/rename collection because directory already exists\" }, ", + " \"ERROR_ARANGO_CONFLICT\" : { \"code\" : 1200, \"message\" : \"conflict\" }, ", + " \"ERROR_ARANGO_WRONG_VOCBASE_PATH\" : { \"code\" : 1201, \"message\" : \"wrong path for database\" }, ", + " \"ERROR_ARANGO_DOCUMENT_NOT_FOUND\" : { \"code\" : 1202, \"message\" : \"document not found\" }, ", + " \"ERROR_ARANGO_COLLECTION_NOT_FOUND\" : { \"code\" : 1203, \"message\" : \"collection not found\" }, ", + " \"ERROR_ARANGO_COLLECTION_PARAMETER_MISSING\" : { \"code\" : 1204, \"message\" : \"parameter 'collection' not found\" }, ", + " \"ERROR_ARANGO_DOCUMENT_HANDLE_BAD\" : { \"code\" : 1205, \"message\" : \"illegal document handle\" }, ", + " \"ERROR_ARANGO_MAXIMAL_SIZE_TOO_SMALL\" : { \"code\" : 1206, \"message\" : \"maixaml size of journal too small\" }, ", + " \"ERROR_ARANGO_DUPLICATE_NAME\" : { \"code\" : 1207, \"message\" : \"duplicate name\" }, ", + " \"ERROR_ARANGO_ILLEGAL_NAME\" : { \"code\" : 1208, \"message\" : \"illegal name\" }, ", + " \"ERROR_ARANGO_NO_INDEX\" : { \"code\" : 1209, \"message\" : \"no suitable index known\" }, ", + " \"ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED\" : { \"code\" : 1210, \"message\" : \"unique constraint violated\" }, ", + " \"ERROR_ARANGO_GEO_INDEX_VIOLATED\" : { \"code\" : 1211, \"message\" : \"geo index violated\" }, ", + " \"ERROR_ARANGO_INDEX_NOT_FOUND\" : { \"code\" : 1212, \"message\" : \"index not found\" }, ", + " \"ERROR_ARANGO_CROSS_COLLECTION_REQUEST\" : { \"code\" : 1213, \"message\" : \"cross collection request not allowed\" }, ", + " \"ERROR_ARANGO_INDEX_HANDLE_BAD\" : { \"code\" : 1214, \"message\" : \"illegal index handle\" }, ", + " \"ERROR_ARANGO_CAP_CONSTRAINT_ALREADY_DEFINED\" : { \"code\" : 1215, \"message\" : \"cap constraint already defined\" }, ", + " \"ERROR_ARANGO_DOCUMENT_TOO_LARGE\" : { \"code\" : 1216, \"message\" : \"document too large\" }, ", + " \"ERROR_ARANGO_COLLECTION_NOT_UNLOADED\" : { \"code\" : 1217, \"message\" : \"collection must be unloaded\" }, ", + " \"ERROR_ARANGO_COLLECTION_TYPE_INVALID\" : { \"code\" : 1218, \"message\" : \"collection type invalid\" }, ", + " \"ERROR_ARANGO_DATAFILE_FULL\" : { \"code\" : 1300, \"message\" : \"datafile full\" }, ", + " \"ERROR_QUERY_KILLED\" : { \"code\" : 1500, \"message\" : \"query killed\" }, ", + " \"ERROR_QUERY_PARSE\" : { \"code\" : 1501, \"message\" : \"%s\" }, ", + " \"ERROR_QUERY_EMPTY\" : { \"code\" : 1502, \"message\" : \"query is empty\" }, ", + " \"ERROR_QUERY_SCRIPT\" : { \"code\" : 1503, \"message\" : \"runtime error '%s'\" }, ", + " \"ERROR_QUERY_NUMBER_OUT_OF_RANGE\" : { \"code\" : 1504, \"message\" : \"number out of range\" }, ", + " \"ERROR_QUERY_VARIABLE_NAME_INVALID\" : { \"code\" : 1510, \"message\" : \"variable name '%s' has an invalid format\" }, ", + " \"ERROR_QUERY_VARIABLE_REDECLARED\" : { \"code\" : 1511, \"message\" : \"variable '%s' is assigned multiple times\" }, ", + " \"ERROR_QUERY_VARIABLE_NAME_UNKNOWN\" : { \"code\" : 1512, \"message\" : \"unknown variable '%s'\" }, ", + " \"ERROR_QUERY_COLLECTION_NOT_FOUND\" : { \"code\" : 1520, \"message\" : \"unable to open collection '%s'\" }, ", + " \"ERROR_QUERY_COLLECTION_LOCK_FAILED\" : { \"code\" : 1521, \"message\" : \"unable to read-lock collection %s\" }, ", + " \"ERROR_QUERY_TOO_MANY_COLLECTIONS\" : { \"code\" : 1522, \"message\" : \"too many collections\" }, ", + " \"ERROR_QUERY_DOCUMENT_ATTRIBUTE_REDECLARED\" : { \"code\" : 1530, \"message\" : \"document attribute '%s' is assigned multiple times\" }, ", + " \"ERROR_QUERY_FUNCTION_NAME_UNKNOWN\" : { \"code\" : 1540, \"message\" : \"usage of unknown function '%s'\" }, ", + " \"ERROR_QUERY_FUNCTION_ARGUMENT_NUMBER_MISMATCH\" : { \"code\" : 1541, \"message\" : \"invalid number of arguments for function '%s'\" }, ", + " \"ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH\" : { \"code\" : 1542, \"message\" : \"invalid argument type used in call to function '%s()'\" }, ", + " \"ERROR_QUERY_BIND_PARAMETERS_INVALID\" : { \"code\" : 1550, \"message\" : \"invalid structure of bind parameters\" }, ", + " \"ERROR_QUERY_BIND_PARAMETER_MISSING\" : { \"code\" : 1551, \"message\" : \"no value specified for declared bind parameter '%s'\" }, ", + " \"ERROR_QUERY_BIND_PARAMETER_UNDECLARED\" : { \"code\" : 1552, \"message\" : \"bind parameter '%s' was not declared in the query\" }, ", + " \"ERROR_QUERY_BIND_PARAMETER_TYPE\" : { \"code\" : 1553, \"message\" : \"bind parameter '%s' has an invalid value or type\" }, ", + " \"ERROR_QUERY_INVALID_LOGICAL_VALUE\" : { \"code\" : 1560, \"message\" : \"invalid logical value\" }, ", + " \"ERROR_QUERY_INVALID_ARITHMETIC_VALUE\" : { \"code\" : 1561, \"message\" : \"invalid arithmetic value\" }, ", + " \"ERROR_QUERY_DIVISION_BY_ZERO\" : { \"code\" : 1562, \"message\" : \"division by zero\" }, ", + " \"ERROR_QUERY_LIST_EXPECTED\" : { \"code\" : 1563, \"message\" : \"list expected\" }, ", + " \"ERROR_QUERY_FAIL_CALLED\" : { \"code\" : 1569, \"message\" : \"FAIL(%s) called\" }, ", + " \"ERROR_QUERY_GEO_INDEX_MISSING\" : { \"code\" : 1570, \"message\" : \"no suitable geo index found for geo restriction on '%s'\" }, ", + " \"ERROR_CURSOR_NOT_FOUND\" : { \"code\" : 1600, \"message\" : \"cursor not found\" }, ", + " \"ERROR_KEYVALUE_INVALID_KEY\" : { \"code\" : 1800, \"message\" : \"invalid key declaration\" }, ", + " \"ERROR_KEYVALUE_KEY_EXISTS\" : { \"code\" : 1801, \"message\" : \"key already exists\" }, ", + " \"ERROR_KEYVALUE_KEY_NOT_FOUND\" : { \"code\" : 1802, \"message\" : \"key not found\" }, ", + " \"ERROR_KEYVALUE_KEY_NOT_UNIQUE\" : { \"code\" : 1803, \"message\" : \"key is not unique\" }, ", + " \"ERROR_KEYVALUE_KEY_NOT_CHANGED\" : { \"code\" : 1804, \"message\" : \"key value not changed\" }, ", + " \"ERROR_KEYVALUE_KEY_NOT_REMOVED\" : { \"code\" : 1805, \"message\" : \"key value not removed\" }, ", + " \"ERROR_KEYVALUE_NO_VALUE\" : { \"code\" : 1806, \"message\" : \"missing value\" }, ", + " \"ERROR_GRAPH_INVALID_GRAPH\" : { \"code\" : 1901, \"message\" : \"invalid graph\" }, ", + " \"ERROR_GRAPH_COULD_NOT_CREATE_GRAPH\" : { \"code\" : 1902, \"message\" : \"could not create graph\" }, ", + " \"ERROR_GRAPH_INVALID_VERTEX\" : { \"code\" : 1903, \"message\" : \"invalid vertex\" }, ", + " \"ERROR_GRAPH_COULD_NOT_CREATE_VERTEX\" : { \"code\" : 1904, \"message\" : \"could not create vertex\" }, ", + " \"ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX\" : { \"code\" : 1905, \"message\" : \"could not change vertex\" }, ", + " \"ERROR_GRAPH_INVALID_EDGE\" : { \"code\" : 1906, \"message\" : \"invalid edge\" }, ", + " \"ERROR_GRAPH_COULD_NOT_CREATE_EDGE\" : { \"code\" : 1907, \"message\" : \"could not create edge\" }, ", + " \"ERROR_GRAPH_COULD_NOT_CHANGE_EDGE\" : { \"code\" : 1908, \"message\" : \"could not change edge\" }, ", + " \"SIMPLE_CLIENT_UNKNOWN_ERROR\" : { \"code\" : 2000, \"message\" : \"unknown client error\" }, ", + " \"SIMPLE_CLIENT_COULD_NOT_CONNECT\" : { \"code\" : 2001, \"message\" : \"could not connect to server\" }, ", + " \"SIMPLE_CLIENT_COULD_NOT_WRITE\" : { \"code\" : 2002, \"message\" : \"could not write to server\" }, ", + " \"SIMPLE_CLIENT_COULD_NOT_READ\" : { \"code\" : 2003, \"message\" : \"could not read from server\" }, ", + " \"ERROR_ARANGO_INDEX_PQ_INSERT_FAILED\" : { \"code\" : 3100, \"message\" : \"priority queue insert failure\" }, ", + " \"ERROR_ARANGO_INDEX_PQ_REMOVE_FAILED\" : { \"code\" : 3110, \"message\" : \"priority queue remove failure\" }, ", + " \"ERROR_ARANGO_INDEX_PQ_REMOVE_ITEM_MISSING\" : { \"code\" : 3111, \"message\" : \"priority queue remove failure - item missing in index\" }, ", + " \"ERROR_ARANGO_INDEX_HASH_INSERT_ITEM_DUPLICATED\" : { \"code\" : 3312, \"message\" : \"(non-unique) hash index insert failure - document duplicated in index\" }, ", + " \"ERROR_ARANGO_INDEX_SKIPLIST_INSERT_ITEM_DUPLICATED\" : { \"code\" : 3313, \"message\" : \"(non-unique) skiplist index insert failure - document duplicated in index\" }, ", + " \"WARNING_ARANGO_INDEX_HASH_DOCUMENT_ATTRIBUTE_MISSING\" : { \"code\" : 3200, \"message\" : \"hash index insertion warning - attribute missing in document\" }, ", + " \"WARNING_ARANGO_INDEX_HASH_UPDATE_ATTRIBUTE_MISSING\" : { \"code\" : 3202, \"message\" : \"hash index update warning - attribute missing in revised document\" }, ", + " \"WARNING_ARANGO_INDEX_HASH_REMOVE_ITEM_MISSING\" : { \"code\" : 3211, \"message\" : \"hash index remove failure - item missing in index\" }, ", + " \"WARNING_ARANGO_INDEX_SKIPLIST_DOCUMENT_ATTRIBUTE_MISSING\" : { \"code\" : 3300, \"message\" : \"skiplist index insertion warning - attribute missing in document\" }, ", + " \"WARNING_ARANGO_INDEX_SKIPLIST_UPDATE_ATTRIBUTE_MISSING\" : { \"code\" : 3302, \"message\" : \"skiplist index update warning - attribute missing in revised document\" }, ", + " \"WARNING_ARANGO_INDEX_SKIPLIST_REMOVE_ITEM_MISSING\" : { \"code\" : 3311, \"message\" : \"skiplist index remove failure - item missing in index\" }, ", + " \"WARNING_ARANGO_INDEX_BITARRAY_DOCUMENT_ATTRIBUTE_MISSING\" : { \"code\" : 3400, \"message\" : \"bitarray index insertion warning - attribute missing in document\" }, ", + " \"WARNING_ARANGO_INDEX_BITARRAY_UPDATE_ATTRIBUTE_MISSING\" : { \"code\" : 3402, \"message\" : \"bitarray index update warning - attribute missing in revised document\" }, ", + " \"WARNING_ARANGO_INDEX_BITARRAY_REMOVE_ITEM_MISSING\" : { \"code\" : 3411, \"message\" : \"bitarray index remove failure - item missing in index\" }, ", + " \"ERROR_ARANGO_INDEX_BITARRAY_INSERT_ITEM_UNSUPPORTED_VALUE\" : { \"code\" : 3413, \"message\" : \"bitarray index insert failure - document attribute value unsupported in index\" }, ", + " \"ERROR_ARANGO_INDEX_BITARRAY_CREATION_FAILURE_DUPLICATE_ATTRIBUTES\" : { \"code\" : 3415, \"message\" : \"bitarray index creation failure - one or more index attributes are duplicated.\" }, ", + " \"ERROR_ARANGO_INDEX_BITARRAY_CREATION_FAILURE_DUPLICATE_VALUES\" : { \"code\" : 3417, \"message\" : \"bitarray index creation failure - one or more index attribute values are duplicated.\" }, ", + "};", + "}());", + "", + "//__end__" +}; diff --git a/js/common/bootstrap/js-modules.h b/js/common/bootstrap/js-modules.h index 114d800db2..33177c2fa0 100644 --- a/js/common/bootstrap/js-modules.h +++ b/js/common/bootstrap/js-modules.h @@ -1,637 +1,638 @@ -static string JS_common_bootstrap_modules = string("") - + "/*jslint indent: 2,\n" - + " nomen: true,\n" - + " maxlen: 100,\n" - + " sloppy: true,\n" - + " vars: true,\n" - + " white: true,\n" - + " plusplus: true */\n" - + "/*global require, module, ModuleCache, SYS_EXECUTE, CONSOLE_ERROR,\n" - + " FS_MOVE, FS_REMOVE, FS_EXISTS, \n" - + " SYS_LOAD, SYS_LOG, SYS_LOG_LEVEL, SYS_OUTPUT,\n" - + " SYS_PROCESS_STAT, SYS_READ, SYS_SPRINTF, SYS_TIME,\n" - + " SYS_START_PAGER, SYS_STOP_PAGER, ARANGO_QUIET, MODULES_PATH,\n" - + " COLOR_OUTPUT, COLOR_OUTPUT_RESET, COLOR_BRIGHT, PRETTY_PRINT,\n" - + " SYS_SHA256, SYS_WAIT, SYS_GETLINE */\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief JavaScript server functions\n" - + "///\n" - + "/// @file\n" - + "///\n" - + "/// DISCLAIMER\n" - + "///\n" - + "/// Copyright 2010-2011 triagens GmbH, Cologne, Germany\n" - + "///\n" - + "/// Licensed under the Apache License, Version 2.0 (the \"License\");\n" - + "/// you may not use this file except in compliance with the License.\n" - + "/// You may obtain a copy of the License at\n" - + "///\n" - + "/// http://www.apache.org/licenses/LICENSE-2.0\n" - + "///\n" - + "/// Unless required by applicable law or agreed to in writing, software\n" - + "/// distributed under the License is distributed on an \"AS IS\" BASIS,\n" - + "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" - + "/// See the License for the specific language governing permissions and\n" - + "/// limitations under the License.\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-- 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 f;\n" - + " var module;\n" - + " var paths;\n" - + " var raw;\n" - + " var sandbox;\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 (ModuleCache.hasOwnProperty(path)) {\n" - + " return ModuleCache[path].exports;\n" - + " }\n" - + "\n" - + " // locate file and read content\n" - + " raw = ModuleCache[\"/internal\"].exports.readFile(path);\n" - + "\n" - + " // create a new sandbox and execute\n" - + " module = ModuleCache[path] = new Module(path);\n" - + "\n" - + " content = \"(function (module, exports, require, print) {\"\n" - + " + raw.content \n" - + " + \"\\n});\";\n" - + "\n" - + " f = SYS_EXECUTE(content, undefined, path);\n" - + "\n" - + " if (f === undefined) {\n" - + " throw \"cannot create context function\";\n" - + " }\n" - + "\n" - + " f(module,\n" - + " module.exports,\n" - + " function(path) { return module.require(path); },\n" - + " ModuleCache[\"/internal\"].exports.print);\n" - + "\n" - + " return module.exports;\n" - + "};\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief normalises a path\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "Module.prototype.normalise = function (path) {\n" - + " var i;\n" - + " var n;\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 (i = 0; i < q.length; ++i) {\n" - + " x = q[i];\n" - + "\n" - + " if (x === \"..\") {\n" - + " if (n.length === 0) {\n" - + " throw \"cannot cross module top\";\n" - + " }\n" - + "\n" - + " n.pop();\n" - + " }\n" - + " else if (x !== \"\" && x !== \".\") {\n" - + " n.push(x);\n" - + " }\n" - + " }\n" - + "\n" - + " return \"/\" + n.join('/');\n" - + "};\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief unloads module\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "Module.prototype.unload = function (path) {\n" - + " if (! path) {\n" - + " return;\n" - + " }\n" - + "\n" - + " var norm = module.normalise(path);\n" - + "\n" - + " if ( norm === \"/\"\n" - + " || norm === \"/internal\"\n" - + " || norm === \"/console\"\n" - + " || norm === \"/fs\") {\n" - + " return;\n" - + " }\n" - + "\n" - + " delete ModuleCache[norm];\n" - + "};\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief unloads module\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "Module.prototype.unloadAll = function () {\n" - + " var path;\n" - + "\n" - + " for (path in ModuleCache) {\n" - + " if (ModuleCache.hasOwnProperty(path)) {\n" - + " this.unload(path);\n" - + " }\n" - + " }\n" - + "};\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief top-level module\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "module = ModuleCache[\"/\"] = new Module(\"/\");\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief global require function\n" - + "///\n" - + "/// @FUN{require(@FA{path})}\n" - + "///\n" - + "/// @FN{require} checks if the file specified by @FA{path} has already been\n" - + "/// loaded. If not, the content of the file is executed in a new\n" - + "/// context. Within the context you can use the global variable @CODE{exports}\n" - + "/// in order to export variables and functions. This variable is returned by\n" - + "/// @FN{require}.\n" - + "///\n" - + "/// Assume that your module file is @CODE{test1.js} and contains\n" - + "///\n" - + "/// @verbinclude modules-require-1\n" - + "///\n" - + "/// Then you can use @FN{require} to load the file and access the exports.\n" - + "///\n" - + "/// @verbinclude modules-require-2\n" - + "///\n" - + "/// @FN{require} follows the specification\n" - + "/// Modules/1.1.1.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function require (path) {\n" - + " return module.require(path);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- Module \"fs\"\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8ModuleFS\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief file-system module\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "ModuleCache[\"/fs\"] = new Module(\"/fs\");\n" - + "\n" - + "(function () {\n" - + " var fs = ModuleCache[\"/fs\"].exports;\n" - + "\n" - + " fs.exists = FS_EXISTS;\n" - + " fs.move = FS_MOVE;\n" - + " fs.remove = FS_REMOVE;\n" - + "}());\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- Module \"internal\"\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8ModuleInternal\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief internal module\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "ModuleCache[\"/internal\"] = new Module(\"/internal\");\n" - + "\n" - + "(function () {\n" - + " var internal = ModuleCache[\"/internal\"].exports;\n" - + " var fs = ModuleCache[\"/fs\"].exports;\n" - + "\n" - + " // system functions\n" - + " internal.execute = SYS_EXECUTE;\n" - + " internal.load = SYS_LOAD;\n" - + " internal.log = SYS_LOG;\n" - + " internal.logLevel = SYS_LOG_LEVEL;\n" - + " internal.output = SYS_OUTPUT;\n" - + " internal.processStat = SYS_PROCESS_STAT;\n" - + " internal.read = SYS_READ;\n" - + " internal.sprintf = SYS_SPRINTF;\n" - + " internal.time = SYS_TIME;\n" - + " internal.sha256 = SYS_SHA256;\n" - + " internal.wait = SYS_WAIT;\n" - + "\n" - + "\n" - + " // password interface\n" - + " internal.encodePassword = function (password) {\n" - + " var salt;\n" - + " var encoded;\n" - + "\n" - + " salt = internal.sha256(\"time:\" + SYS_TIME());\n" - + " salt = salt.substr(0,8);\n" - + "\n" - + " encoded = \"$1$\" + salt + \"$\" + internal.sha256(salt + password);\n" - + " \n" - + " return encoded;\n" - + " }\n" - + "\n" - + "\n" - + "\n" - + " // command line parameter\n" - + " internal.MODULES_PATH = \"\";\n" - + "\n" - + " if (typeof MODULES_PATH !== \"undefined\") {\n" - + " internal.MODULES_PATH = MODULES_PATH;\n" - + " }\n" - + "\n" - + "\n" - + " // output \n" - + " internal.start_pager = function () {};\n" - + " internal.stop_pager = function () {};\n" - + "\n" - + " internal.ARANGO_QUIET = false;\n" - + "\n" - + " internal.COLOR_OUTPUT = false;\n" - + " internal.COLOR_OUTPUT_DEFAULT = \"\";\n" - + " internal.COLOR_OUTPUT_RESET = \"\";\n" - + " internal.COLOR_BRIGHT = \"\";\n" - + "\n" - + " internal.PRETTY_PRINT = false;\n" - + "\n" - + " if (typeof SYS_START_PAGER !== \"undefined\") {\n" - + " internal.start_pager = SYS_START_PAGER;\n" - + " }\n" - + "\n" - + " if (typeof SYS_STOP_PAGER !== \"undefined\") {\n" - + " internal.stop_pager = SYS_STOP_PAGER;\n" - + " }\n" - + "\n" - + " if (typeof COLOR_OUTPUT !== \"undefined\") {\n" - + " internal.COLOR_OUTPUT = COLOR_OUTPUT;\n" - + " }\n" - + "\n" - + " if (typeof COLOR_OUTPUT_RESET !== \"undefined\") {\n" - + " internal.COLOR_OUTPUT_RESET = COLOR_OUTPUT_RESET;\n" - + " }\n" - + "\n" - + " if (typeof COLOR_BRIGHT !== \"undefined\") {\n" - + " internal.COLOR_BRIGHT = COLOR_BRIGHT;\n" - + " }\n" - + "\n" - + " if (typeof PRETTY_PRINT !== \"undefined\") {\n" - + " internal.PRETTY_PRINT = PRETTY_PRINT;\n" - + " }\n" - + "\n" - + " if (internal.COLOR_OUTPUT) {\n" - + " internal.COLOR_OUTPUT_DEFAULT = internal.COLOR_BRIGHT;\n" - + "\n" - + " internal.COLOR_BLACK = COLOR_BLACK;\n" - + " internal.COLOR_BOLD_BLACK = COLOR_BOLD_BLACK;\n" - + " internal.COLOR_BLINK = COLOR_BLINK;\n" - + " internal.COLOR_BLUE = COLOR_BLUE;\n" - + " internal.COLOR_BOLD_BLUE = COLOR_BOLD_BLUE;\n" - + " internal.COLOR_BRIGHT = COLOR_BRIGHT;\n" - + " internal.COLOR_GREEN = COLOR_GREEN;\n" - + " internal.COLOR_BOLD_GREEN = COLOR_BOLD_GREEN;\n" - + " internal.COLOR_RED = COLOR_RED;\n" - + " internal.COLOR_BOLD_RED = COLOR_BOLD_RED;\n" - + " internal.COLOR_WHITE = COLOR_WHITE;\n" - + " internal.COLOR_BOLD_WHITE = COLOR_BOLD_WHITE;\n" - + " internal.COLOR_YELLOW = COLOR_YELLOW;\n" - + " internal.COLOR_BOLD_YELLOW = COLOR_BOLD_YELLOW;\n" - + " internal.COLOR_OUTPUT_RESET = COLOR_OUTPUT_RESET;\n" - + " }\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief reads a file from the module path or the database\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.readFile = function (path) {\n" - + " var i;\n" - + " var mc;\n" - + " var n;\n" - + "\n" - + " // try to load the file\n" - + " var paths = internal.MODULES_PATH;\n" - + "\n" - + " for (i = 0; i < paths.length; ++i) {\n" - + " var p = paths[i];\n" - + "\n" - + " if (p === \"\") {\n" - + " n = \".\" + path + \".js\";\n" - + " }\n" - + " else {\n" - + " n = p + \"/\" + path + \".js\";\n" - + " }\n" - + "\n" - + " if (fs.exists(n)) {\n" - + " return { path : n, content : internal.read(n) };\n" - + " }\n" - + " }\n" - + "\n" - + " // try to load the module from the database\n" - + " mc = internal.db._collection(\"_modules\");\n" - + "\n" - + " if (mc !== null) {\n" - + " n = mc.firstExample({ path: path });\n" - + "\n" - + " if (n !== null) {\n" - + " return { path : \"_collection/\" + path, content : n.module };\n" - + " }\n" - + " }\n" - + "\n" - + " throw \"cannot find a file named '\"\n" - + " + path\n" - + " + \"' using the module path(s) '\" \n" - + " + internal.MODULES_PATH + \"'\";\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief loads a file from the file-system\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.loadFile = function (path) {\n" - + " var i;\n" - + "\n" - + " // try to load the file\n" - + " var paths = internal.MODULES_PATH;\n" - + "\n" - + " for (i = 0; i < paths.length; ++i) {\n" - + " var p = paths[i];\n" - + " var n;\n" - + "\n" - + " if (p === \"\") {\n" - + " n = \".\" + path + \".js\";\n" - + " }\n" - + " else {\n" - + " n = p + \"/\" + path + \".js\";\n" - + " }\n" - + "\n" - + " if (fs.exists(n)) {\n" - + " return internal.load(n);\n" - + " }\n" - + " }\n" - + "\n" - + " throw \"cannot find a file named '\"\n" - + " + path \n" - + " + \"' using the module path(s) '\" \n" - + " + internal.MODULES_PATH + \"'\";\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief defines a module\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.defineModule = function (path, file) {\n" - + " var content;\n" - + " var m;\n" - + " var mc;\n" - + "\n" - + " content = internal.read(file);\n" - + "\n" - + " mc = internal.db._collection(\"_modules\");\n" - + "\n" - + " if (mc === null) {\n" - + " throw \"you need to upgrade your database using 'arango-upgrade'\";\n" - + " }\n" - + "\n" - + " path = module.normalise(path);\n" - + " m = mc.firstExample({ path: path });\n" - + "\n" - + " if (m === null) {\n" - + " mc.save({ path: path, module: content });\n" - + " }\n" - + " else {\n" - + " m.module = content;\n" - + " mc.replace(m, m);\n" - + " }\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "}());\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- Module \"console\"\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8ModuleConsole\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief console module\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "ModuleCache[\"/console\"] = new Module(\"/console\");\n" - + "\n" - + "(function () {\n" - + " var internal = ModuleCache[\"/internal\"].exports;\n" - + " var console = ModuleCache[\"/console\"].exports;\n" - + "\n" - + " console.getline = SYS_GETLINE;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief logs debug message\n" - + "///\n" - + "/// @FUN{console.debug(@FA{format}, @FA{argument1}, ...)}\n" - + "///\n" - + "/// Formats the arguments according to @FA{format} and logs the result as\n" - + "/// debug message.\n" - + "///\n" - + "/// String substitution patterns, which can be used in @FA{format}.\n" - + "///\n" - + "/// - @LIT{\\%s} string\n" - + "/// - @LIT{\\%d}, @LIT{\\%i} integer\n" - + "/// - @LIT{\\%f} floating point number\n" - + "/// - @LIT{\\%o} object hyperlink\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " console.debug = function () {\n" - + " var msg;\n" - + "\n" - + " try {\n" - + " msg = internal.sprintf.apply(internal.sprintf, arguments);\n" - + " }\n" - + " catch (err) {\n" - + " msg = err + \": \" + arguments;\n" - + " }\n" - + "\n" - + " internal.log(\"debug\", msg);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief logs error message\n" - + "///\n" - + "/// @FUN{console.error(@FA{format}, @FA{argument1}, ...)}\n" - + "///\n" - + "/// Formats the arguments according to @FA{format} and logs the result as\n" - + "/// error message.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " console.error = function () {\n" - + " var msg;\n" - + "\n" - + " try {\n" - + " msg = internal.sprintf.apply(internal.sprintf, arguments);\n" - + " }\n" - + " catch (err) {\n" - + " msg = err + \": \" + arguments;\n" - + " }\n" - + "\n" - + " internal.log(\"error\", msg);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief logs info message\n" - + "///\n" - + "/// @FUN{console.info(@FA{format}, @FA{argument1}, ...)}\n" - + "///\n" - + "/// Formats the arguments according to @FA{format} and logs the result as\n" - + "/// info message.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " console.info = function () {\n" - + " var msg;\n" - + "\n" - + " try {\n" - + " msg = internal.sprintf.apply(internal.sprintf, arguments);\n" - + " }\n" - + " catch (err) {\n" - + " msg = err + \": \" + arguments;\n" - + " }\n" - + "\n" - + " internal.log(\"info\", msg);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief logs log message\n" - + "///\n" - + "/// @FUN{console.log(@FA{format}, @FA{argument1}, ...)}\n" - + "///\n" - + "/// Formats the arguments according to @FA{format} and logs the result as\n" - + "/// log message.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " console.log = function () {\n" - + " var msg;\n" - + "\n" - + " try {\n" - + " msg = internal.sprintf.apply(internal.sprintf, arguments);\n" - + " }\n" - + " catch (err) {\n" - + " msg = err + \": \" + arguments;\n" - + " }\n" - + "\n" - + " internal.log(\"info\", msg);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief logs warn message\n" - + "///\n" - + "/// @FUN{console.warn(@FA{format}, @FA{argument1}, ...)}\n" - + "///\n" - + "/// Formats the arguments according to @FA{format} and logs the result as\n" - + "/// warn message.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " console.warn = function () {\n" - + " var msg;\n" - + "\n" - + " try {\n" - + " msg = internal.sprintf.apply(internal.sprintf, arguments);\n" - + " }\n" - + " catch (err) {\n" - + " msg = err + \": \" + arguments;\n" - + " }\n" - + "\n" - + " internal.log(\"warn\", msg);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "}());\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- END-OF-FILE\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "// Local Variables:\n" - + "// mode: outline-minor\n" - + "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @page\\\\|/// @}\\\\)\"\n" - + "// End:\n" -; +const char* JS_common_bootstrap_modules[] = { + "/*jslint indent: 2,", + " nomen: true,", + " maxlen: 100,", + " sloppy: true,", + " vars: true,", + " white: true,", + " plusplus: true */", + "/*global require, module, ModuleCache, SYS_EXECUTE, CONSOLE_ERROR,", + " FS_MOVE, FS_REMOVE, FS_EXISTS, ", + " SYS_LOAD, SYS_LOG, SYS_LOG_LEVEL, SYS_OUTPUT,", + " SYS_PROCESS_STAT, SYS_READ, SYS_SPRINTF, SYS_TIME,", + " SYS_START_PAGER, SYS_STOP_PAGER, ARANGO_QUIET, MODULES_PATH,", + " COLOR_OUTPUT, COLOR_OUTPUT_RESET, COLOR_BRIGHT, PRETTY_PRINT,", + " SYS_SHA256, SYS_WAIT, SYS_GETLINE */", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief JavaScript server functions", + "///", + "/// @file", + "///", + "/// DISCLAIMER", + "///", + "/// Copyright 2010-2011 triagens GmbH, Cologne, Germany", + "///", + "/// Licensed under the Apache License, Version 2.0 (the \"License\");", + "/// you may not use this file except in compliance with the License.", + "/// You may obtain a copy of the License at", + "///", + "/// http://www.apache.org/licenses/LICENSE-2.0", + "///", + "/// Unless required by applicable law or agreed to in writing, software", + "/// distributed under the License is distributed on an \"AS IS\" BASIS,", + "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "/// See the License for the specific language governing permissions and", + "/// limitations under the License.", + "///", + "/// Copyright holder is triAGENS GmbH, Cologne, Germany", + "///", + "/// @author Dr. Frank Celler", + "/// @author Copyright 2011, triAGENS GmbH, Cologne, Germany", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- Module", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8Module", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief module cache", + "////////////////////////////////////////////////////////////////////////////////", + "", + "ModuleCache = {};", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief module constructor", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function Module (id) {", + " this.id = id;", + " this.exports = {};", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief loads a file and creates a new module descriptor", + "////////////////////////////////////////////////////////////////////////////////", + "", + "Module.prototype.require = function (path) {", + " var content;", + " var f;", + " var module;", + " var paths;", + " var raw;", + " var sandbox;", + "", + " // first get rid of any \"..\" and \".\"", + " path = this.normalise(path);", + "", + " // check if you already know the module, return the exports", + " if (ModuleCache.hasOwnProperty(path)) {", + " return ModuleCache[path].exports;", + " }", + "", + " // locate file and read content", + " raw = ModuleCache[\"/internal\"].exports.readFile(path);", + "", + " // create a new sandbox and execute", + " module = ModuleCache[path] = new Module(path);", + "", + " content = \"(function (module, exports, require, print) {\"", + " + raw.content ", + " + \"\\n});\";", + "", + " f = SYS_EXECUTE(content, undefined, path);", + "", + " if (f === undefined) {", + " throw \"cannot create context function\";", + " }", + "", + " f(module,", + " module.exports,", + " function(path) { return module.require(path); },", + " ModuleCache[\"/internal\"].exports.print);", + "", + " return module.exports;", + "};", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief normalises a path", + "////////////////////////////////////////////////////////////////////////////////", + "", + "Module.prototype.normalise = function (path) {", + " var i;", + " var n;", + " var p;", + " var q;", + " var x;", + "", + " if (path === \"\") {", + " return this.id;", + " }", + "", + " p = path.split('/');", + "", + " // relative path", + " if (p[0] === \".\" || p[0] === \"..\") {", + " q = this.id.split('/');", + " q.pop();", + " q = q.concat(p);", + " }", + "", + " // absolute path", + " else {", + " q = p;", + " }", + "", + " // normalize path", + " n = [];", + "", + " for (i = 0; i < q.length; ++i) {", + " x = q[i];", + "", + " if (x === \"..\") {", + " if (n.length === 0) {", + " throw \"cannot cross module top\";", + " }", + "", + " n.pop();", + " }", + " else if (x !== \"\" && x !== \".\") {", + " n.push(x);", + " }", + " }", + "", + " return \"/\" + n.join('/');", + "};", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief unloads module", + "////////////////////////////////////////////////////////////////////////////////", + "", + "Module.prototype.unload = function (path) {", + " if (! path) {", + " return;", + " }", + "", + " var norm = module.normalise(path);", + "", + " if ( norm === \"/\"", + " || norm === \"/internal\"", + " || norm === \"/console\"", + " || norm === \"/fs\") {", + " return;", + " }", + "", + " delete ModuleCache[norm];", + "};", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief unloads module", + "////////////////////////////////////////////////////////////////////////////////", + "", + "Module.prototype.unloadAll = function () {", + " var path;", + "", + " for (path in ModuleCache) {", + " if (ModuleCache.hasOwnProperty(path)) {", + " this.unload(path);", + " }", + " }", + "};", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief top-level module", + "////////////////////////////////////////////////////////////////////////////////", + "", + "module = ModuleCache[\"/\"] = new Module(\"/\");", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief global require function", + "///", + "/// @FUN{require(@FA{path})}", + "///", + "/// @FN{require} checks if the file specified by @FA{path} has already been", + "/// loaded. If not, the content of the file is executed in a new", + "/// context. Within the context you can use the global variable @CODE{exports}", + "/// in order to export variables and functions. This variable is returned by", + "/// @FN{require}.", + "///", + "/// Assume that your module file is @CODE{test1.js} and contains", + "///", + "/// @verbinclude modules-require-1", + "///", + "/// Then you can use @FN{require} to load the file and access the exports.", + "///", + "/// @verbinclude modules-require-2", + "///", + "/// @FN{require} follows the specification", + "/// Modules/1.1.1.", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function require (path) {", + " return module.require(path);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- Module \"fs\"", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8ModuleFS", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief file-system module", + "////////////////////////////////////////////////////////////////////////////////", + "", + "ModuleCache[\"/fs\"] = new Module(\"/fs\");", + "", + "(function () {", + " var fs = ModuleCache[\"/fs\"].exports;", + "", + " fs.exists = FS_EXISTS;", + " fs.move = FS_MOVE;", + " fs.remove = FS_REMOVE;", + "}());", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- Module \"internal\"", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8ModuleInternal", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief internal module", + "////////////////////////////////////////////////////////////////////////////////", + "", + "ModuleCache[\"/internal\"] = new Module(\"/internal\");", + "", + "(function () {", + " var internal = ModuleCache[\"/internal\"].exports;", + " var fs = ModuleCache[\"/fs\"].exports;", + "", + " // system functions", + " internal.execute = SYS_EXECUTE;", + " internal.load = SYS_LOAD;", + " internal.log = SYS_LOG;", + " internal.logLevel = SYS_LOG_LEVEL;", + " internal.output = SYS_OUTPUT;", + " internal.processStat = SYS_PROCESS_STAT;", + " internal.read = SYS_READ;", + " internal.sprintf = SYS_SPRINTF;", + " internal.time = SYS_TIME;", + " internal.sha256 = SYS_SHA256;", + " internal.wait = SYS_WAIT;", + "", + "", + " // password interface", + " internal.encodePassword = function (password) {", + " var salt;", + " var encoded;", + "", + " salt = internal.sha256(\"time:\" + SYS_TIME());", + " salt = salt.substr(0,8);", + "", + " encoded = \"$1$\" + salt + \"$\" + internal.sha256(salt + password);", + " ", + " return encoded;", + " }", + "", + "", + "", + " // command line parameter", + " internal.MODULES_PATH = \"\";", + "", + " if (typeof MODULES_PATH !== \"undefined\") {", + " internal.MODULES_PATH = MODULES_PATH;", + " }", + "", + "", + " // output ", + " internal.start_pager = function () {};", + " internal.stop_pager = function () {};", + "", + " internal.ARANGO_QUIET = false;", + "", + " internal.COLOR_OUTPUT = false;", + " internal.COLOR_OUTPUT_DEFAULT = \"\";", + " internal.COLOR_OUTPUT_RESET = \"\";", + " internal.COLOR_BRIGHT = \"\";", + "", + " internal.PRETTY_PRINT = false;", + "", + " if (typeof SYS_START_PAGER !== \"undefined\") {", + " internal.start_pager = SYS_START_PAGER;", + " }", + "", + " if (typeof SYS_STOP_PAGER !== \"undefined\") {", + " internal.stop_pager = SYS_STOP_PAGER;", + " }", + "", + " if (typeof COLOR_OUTPUT !== \"undefined\") {", + " internal.COLOR_OUTPUT = COLOR_OUTPUT;", + " }", + "", + " if (typeof COLOR_OUTPUT_RESET !== \"undefined\") {", + " internal.COLOR_OUTPUT_RESET = COLOR_OUTPUT_RESET;", + " }", + "", + " if (typeof COLOR_BRIGHT !== \"undefined\") {", + " internal.COLOR_BRIGHT = COLOR_BRIGHT;", + " }", + "", + " if (typeof PRETTY_PRINT !== \"undefined\") {", + " internal.PRETTY_PRINT = PRETTY_PRINT;", + " }", + "", + " if (internal.COLOR_OUTPUT) {", + " internal.COLOR_OUTPUT_DEFAULT = internal.COLOR_BRIGHT;", + "", + " internal.COLOR_BLACK = COLOR_BLACK;", + " internal.COLOR_BOLD_BLACK = COLOR_BOLD_BLACK;", + " internal.COLOR_BLINK = COLOR_BLINK;", + " internal.COLOR_BLUE = COLOR_BLUE;", + " internal.COLOR_BOLD_BLUE = COLOR_BOLD_BLUE;", + " internal.COLOR_BRIGHT = COLOR_BRIGHT;", + " internal.COLOR_GREEN = COLOR_GREEN;", + " internal.COLOR_BOLD_GREEN = COLOR_BOLD_GREEN;", + " internal.COLOR_RED = COLOR_RED;", + " internal.COLOR_BOLD_RED = COLOR_BOLD_RED;", + " internal.COLOR_WHITE = COLOR_WHITE;", + " internal.COLOR_BOLD_WHITE = COLOR_BOLD_WHITE;", + " internal.COLOR_YELLOW = COLOR_YELLOW;", + " internal.COLOR_BOLD_YELLOW = COLOR_BOLD_YELLOW;", + " internal.COLOR_OUTPUT_RESET = COLOR_OUTPUT_RESET;", + " }", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief reads a file from the module path or the database", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.readFile = function (path) {", + " var i;", + " var mc;", + " var n;", + "", + " // try to load the file", + " var paths = internal.MODULES_PATH;", + "", + " for (i = 0; i < paths.length; ++i) {", + " var p = paths[i];", + "", + " if (p === \"\") {", + " n = \".\" + path + \".js\";", + " }", + " else {", + " n = p + \"/\" + path + \".js\";", + " }", + "", + " if (fs.exists(n)) {", + " return { path : n, content : internal.read(n) };", + " }", + " }", + "", + " // try to load the module from the database", + " mc = internal.db._collection(\"_modules\");", + "", + " if (mc !== null) {", + " n = mc.firstExample({ path: path });", + "", + " if (n !== null) {", + " return { path : \"_collection/\" + path, content : n.module };", + " }", + " }", + "", + " throw \"cannot find a file named '\"", + " + path", + " + \"' using the module path(s) '\" ", + " + internal.MODULES_PATH + \"'\";", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief loads a file from the file-system", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.loadFile = function (path) {", + " var i;", + "", + " // try to load the file", + " var paths = internal.MODULES_PATH;", + "", + " for (i = 0; i < paths.length; ++i) {", + " var p = paths[i];", + " var n;", + "", + " if (p === \"\") {", + " n = \".\" + path + \".js\";", + " }", + " else {", + " n = p + \"/\" + path + \".js\";", + " }", + "", + " if (fs.exists(n)) {", + " return internal.load(n);", + " }", + " }", + "", + " throw \"cannot find a file named '\"", + " + path ", + " + \"' using the module path(s) '\" ", + " + internal.MODULES_PATH + \"'\";", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief defines a module", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.defineModule = function (path, file) {", + " var content;", + " var m;", + " var mc;", + "", + " content = internal.read(file);", + "", + " mc = internal.db._collection(\"_modules\");", + "", + " if (mc === null) {", + " throw \"you need to upgrade your database using 'arango-upgrade'\";", + " }", + "", + " path = module.normalise(path);", + " m = mc.firstExample({ path: path });", + "", + " if (m === null) {", + " mc.save({ path: path, module: content });", + " }", + " else {", + " m.module = content;", + " mc.replace(m, m);", + " }", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "}());", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- Module \"console\"", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8ModuleConsole", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief console module", + "////////////////////////////////////////////////////////////////////////////////", + "", + "ModuleCache[\"/console\"] = new Module(\"/console\");", + "", + "(function () {", + " var internal = ModuleCache[\"/internal\"].exports;", + " var console = ModuleCache[\"/console\"].exports;", + "", + " console.getline = SYS_GETLINE;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief logs debug message", + "///", + "/// @FUN{console.debug(@FA{format}, @FA{argument1}, ...)}", + "///", + "/// Formats the arguments according to @FA{format} and logs the result as", + "/// debug message.", + "///", + "/// String substitution patterns, which can be used in @FA{format}.", + "///", + "/// - @LIT{\\%s} string", + "/// - @LIT{\\%d}, @LIT{\\%i} integer", + "/// - @LIT{\\%f} floating point number", + "/// - @LIT{\\%o} object hyperlink", + "////////////////////////////////////////////////////////////////////////////////", + "", + " console.debug = function () {", + " var msg;", + "", + " try {", + " msg = internal.sprintf.apply(internal.sprintf, arguments);", + " }", + " catch (err) {", + " msg = err + \": \" + arguments;", + " }", + "", + " internal.log(\"debug\", msg);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief logs error message", + "///", + "/// @FUN{console.error(@FA{format}, @FA{argument1}, ...)}", + "///", + "/// Formats the arguments according to @FA{format} and logs the result as", + "/// error message.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " console.error = function () {", + " var msg;", + "", + " try {", + " msg = internal.sprintf.apply(internal.sprintf, arguments);", + " }", + " catch (err) {", + " msg = err + \": \" + arguments;", + " }", + "", + " internal.log(\"error\", msg);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief logs info message", + "///", + "/// @FUN{console.info(@FA{format}, @FA{argument1}, ...)}", + "///", + "/// Formats the arguments according to @FA{format} and logs the result as", + "/// info message.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " console.info = function () {", + " var msg;", + "", + " try {", + " msg = internal.sprintf.apply(internal.sprintf, arguments);", + " }", + " catch (err) {", + " msg = err + \": \" + arguments;", + " }", + "", + " internal.log(\"info\", msg);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief logs log message", + "///", + "/// @FUN{console.log(@FA{format}, @FA{argument1}, ...)}", + "///", + "/// Formats the arguments according to @FA{format} and logs the result as", + "/// log message.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " console.log = function () {", + " var msg;", + "", + " try {", + " msg = internal.sprintf.apply(internal.sprintf, arguments);", + " }", + " catch (err) {", + " msg = err + \": \" + arguments;", + " }", + "", + " internal.log(\"info\", msg);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief logs warn message", + "///", + "/// @FUN{console.warn(@FA{format}, @FA{argument1}, ...)}", + "///", + "/// Formats the arguments according to @FA{format} and logs the result as", + "/// warn message.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " console.warn = function () {", + " var msg;", + "", + " try {", + " msg = internal.sprintf.apply(internal.sprintf, arguments);", + " }", + " catch (err) {", + " msg = err + \": \" + arguments;", + " }", + "", + " internal.log(\"warn\", msg);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "}());", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- END-OF-FILE", + "// -----------------------------------------------------------------------------", + "", + "// Local Variables:", + "// mode: outline-minor", + "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @page\\\\|/// @}\\\\)\"", + "// End:", + "//__end__" +}; diff --git a/js/common/bootstrap/js-print.h b/js/common/bootstrap/js-print.h index cdc1486bf3..cf9ab33723 100644 --- a/js/common/bootstrap/js-print.h +++ b/js/common/bootstrap/js-print.h @@ -1,333 +1,334 @@ -static string JS_common_bootstrap_print = string("") - + "/*jslint indent: 2,\n" - + " nomen: true,\n" - + " maxlen: 100,\n" - + " sloppy: true,\n" - + " vars: true,\n" - + " white: true,\n" - + " plusplus: true */\n" - + "/*global require, print */\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief printing\n" - + "///\n" - + "/// @file\n" - + "///\n" - + "/// DISCLAIMER\n" - + "///\n" - + "/// Copyright 2010-2012 triagens GmbH, Cologne, Germany\n" - + "///\n" - + "/// Licensed under the Apache License, Version 2.0 (the \"License\");\n" - + "/// you may not use this file except in compliance with the License.\n" - + "/// You may obtain a copy of the License at\n" - + "///\n" - + "/// http://www.apache.org/licenses/LICENSE-2.0\n" - + "///\n" - + "/// Unless required by applicable law or agreed to in writing, software\n" - + "/// distributed under the License is distributed on an \"AS IS\" BASIS,\n" - + "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" - + "/// See the License for the specific language governing permissions and\n" - + "/// limitations under the License.\n" - + "///\n" - + "/// Copyright holder is triAGENS GmbH, Cologne, Germany\n" - + "///\n" - + "/// @author Dr. Frank Celler\n" - + "/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "(function () {\n" - + " var internal = require(\"internal\");\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- Module \"internal\"\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- private functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8Shell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief prints objects to standard output\n" - + "///\n" - + "/// @FUN{internal.printShell(@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" - + " internal.printShell = function () {\n" - + " var i;\n" - + "\n" - + " for (i = 0; i < arguments.length; ++i) {\n" - + " if (0 < i) {\n" - + " internal.output(\" \");\n" - + " }\n" - + "\n" - + " if (typeof(arguments[i]) === \"string\") {\n" - + " internal.output(arguments[i]);\n" - + " }\n" - + " else {\n" - + " internal.printRecursive(arguments[i], [], \"~\", [], 0);\n" - + " }\n" - + " }\n" - + "\n" - + " if (internal.COLOR_OUTPUT) {\n" - + " internal.output(internal.COLOR_OUTPUT_RESET);\n" - + " }\n" - + "\n" - + " internal.output(\"\\n\");\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief quote cache\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.characterQuoteCache = {\n" - + " '\\b': '\\\\b', // ASCII 8, Backspace\n" - + " '\\t': '\\\\t', // ASCII 9, Tab\n" - + " '\\n': '\\\\n', // ASCII 10, Newline\n" - + " '\\f': '\\\\f', // ASCII 12, Formfeed\n" - + " '\\r': '\\\\r', // ASCII 13, Carriage Return\n" - + " '\\\"': '\\\\\"',\n" - + " '\\\\': '\\\\\\\\'\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief quotes a single character\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.quoteSingleJsonCharacter = function (c) {\n" - + " if (internal.characterQuoteCache.hasOwnProperty[c]) {\n" - + " return internal.characterQuoteCache[c];\n" - + " }\n" - + "\n" - + " var charCode = c.charCodeAt(0);\n" - + " var result;\n" - + "\n" - + " if (charCode < 16) {\n" - + " result = '\\\\u000';\n" - + " }\n" - + " else if (charCode < 256) {\n" - + " result = '\\\\u00';\n" - + " }\n" - + " else if (charCode < 4096) {\n" - + " result = '\\\\u0';\n" - + " }\n" - + " else {\n" - + " result = '\\\\u';\n" - + " }\n" - + "\n" - + " result += charCode.toString(16);\n" - + " internal.characterQuoteCache[c] = result;\n" - + "\n" - + " return result;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief quotes a string character\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.quoteJsonString = function (str) {\n" - + " var quotable = /[\\\\\\\"\\x00-\\x1f]/g;\n" - + " return '\"' + str.replace(quotable, internal.quoteSingleJsonCharacter) + '\"';\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief prints objects to standard output without a new-line\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.printRecursive = function (value, seen, path, names, level) {\n" - + " var p;\n" - + "\n" - + " if (seen === undefined) {\n" - + " seen = [];\n" - + " names = [];\n" - + " }\n" - + "\n" - + " p = seen.indexOf(value);\n" - + "\n" - + " if (0 <= p) {\n" - + " internal.output(names[p]);\n" - + " }\n" - + " else {\n" - + " if (value instanceof Object) {\n" - + " seen.push(value);\n" - + " names.push(path);\n" - + " }\n" - + "\n" - + " if (value instanceof Object) {\n" - + " if ('_PRINT' in value) {\n" - + " value._PRINT(seen, path, names, level);\n" - + " }\n" - + " else if (value instanceof Array) {\n" - + " internal.printArray(value, seen, path, names, level);\n" - + " }\n" - + " else if (value.__proto__ === Object.prototype) {\n" - + " internal.printObject(value, seen, path, names, level);\n" - + " }\n" - + " else if ('toString' in value) {\n" - + " internal.output(value.toString());\n" - + " }\n" - + " else {\n" - + " internal.printObject(value, seen, path, names, level);\n" - + " }\n" - + " }\n" - + " else if (value === undefined) {\n" - + " internal.output(\"undefined\");\n" - + " }\n" - + " else {\n" - + " if (typeof(value) === \"string\") {\n" - + " internal.output(internal.quoteJsonString(value));\n" - + " }\n" - + " else {\n" - + " internal.output(String(value));\n" - + " }\n" - + " }\n" - + " }\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief prints the ident for pretty printing\n" - + "///\n" - + "/// @FUN{internal.printIndent(@FA{level})}\n" - + "///\n" - + "/// Only available in shell mode.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.printIndent = function (level) {\n" - + " var j;\n" - + "\n" - + " if (internal.PRETTY_PRINT) {\n" - + " internal.output(\"\\n\");\n" - + "\n" - + " for (j = 0; j < level; ++j) {\n" - + " internal.output(\" \");\n" - + " }\n" - + " }\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief JSON representation of an array\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.printArray = function (object, seen, path, names, level) {\n" - + " if (object.length === 0) {\n" - + " internal.output(\"[ ]\");\n" - + " }\n" - + " else {\n" - + " var i;\n" - + " var sep = \"\";\n" - + "\n" - + " internal.output(\"[\");\n" - + "\n" - + " var newLevel = level + 1;\n" - + "\n" - + " for (i = 0; i < object.length; i++) {\n" - + " internal.output(sep);\n" - + "\n" - + " internal.printIndent(newLevel);\n" - + "\n" - + " internal.printRecursive(object[i],\n" - + " seen,\n" - + " path + \"[\" + i + \"]\",\n" - + " names,\n" - + " newLevel);\n" - + " sep = \", \";\n" - + " }\n" - + "\n" - + " internal.printIndent(level);\n" - + "\n" - + " internal.output(\"]\");\n" - + " }\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief prints an object\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " internal.printObject = function (object, seen, path, names, level) {\n" - + " var sep = \" \";\n" - + " var k;\n" - + "\n" - + " internal.output(\"{\");\n" - + "\n" - + " var newLevel = level + 1;\n" - + "\n" - + " for (k in object) {\n" - + " if (object.hasOwnProperty(k)) {\n" - + " var val = object[k];\n" - + "\n" - + " internal.output(sep);\n" - + "\n" - + " internal.printIndent(newLevel);\n" - + "\n" - + " if (internal.COLOR_OUTPUT) {\n" - + " internal.output(internal.COLOR_OUTPUT_DEFAULT,\n" - + " k,\n" - + " internal.COLOR_OUTPUT_RESET, \n" - + " \" : \");\n" - + " }\n" - + " else {\n" - + " internal.output(internal.quoteJsonString(k), \" : \");\n" - + " }\n" - + "\n" - + " internal.printRecursive(val,\n" - + " seen,\n" - + " path + \"[\" + k + \"]\",\n" - + " names,\n" - + " newLevel);\n" - + " sep = \", \";\n" - + " }\n" - + " }\n" - + "\n" - + " internal.printIndent(level);\n" - + "\n" - + " internal.output(\" }\");\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "}());\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- global functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8Shell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief global print\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// must be a variable definition for the browser\n" - + "if (typeof require(\"internal\").printBrowser === \"function\") {\n" - + " print = require(\"internal\").print = require(\"internal\").printBrowser;\n" - + "}\n" - + "else {\n" - + " print = require(\"internal\").print = require(\"internal\").printShell;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// Local Variables:\n" - + "// mode: outline-minor\n" - + "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @page\\\\|/// @}\\\\)\"\n" - + "// End:\n" -; +const char* JS_common_bootstrap_print[] = { + "/*jslint indent: 2,", + " nomen: true,", + " maxlen: 100,", + " sloppy: true,", + " vars: true,", + " white: true,", + " plusplus: true */", + "/*global require, print */", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief printing", + "///", + "/// @file", + "///", + "/// DISCLAIMER", + "///", + "/// Copyright 2010-2012 triagens GmbH, Cologne, Germany", + "///", + "/// Licensed under the Apache License, Version 2.0 (the \"License\");", + "/// you may not use this file except in compliance with the License.", + "/// You may obtain a copy of the License at", + "///", + "/// http://www.apache.org/licenses/LICENSE-2.0", + "///", + "/// Unless required by applicable law or agreed to in writing, software", + "/// distributed under the License is distributed on an \"AS IS\" BASIS,", + "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "/// See the License for the specific language governing permissions and", + "/// limitations under the License.", + "///", + "/// Copyright holder is triAGENS GmbH, Cologne, Germany", + "///", + "/// @author Dr. Frank Celler", + "/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany", + "////////////////////////////////////////////////////////////////////////////////", + "", + "(function () {", + " var internal = require(\"internal\");", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- Module \"internal\"", + "// -----------------------------------------------------------------------------", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- private functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8Shell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief prints objects to standard output", + "///", + "/// @FUN{internal.printShell(@FA{arg1}, @FA{arg2}, @FA{arg3}, ...)}", + "///", + "/// Only available in shell mode.", + "///", + "/// Prints the arguments. If an argument is an object having a", + "/// function @FN{_PRINT}, then this function is called. Otherwise @FN{toJson} is", + "/// used. A final newline is printed", + "///", + "/// @verbinclude fluent40", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.printShell = function () {", + " var i;", + "", + " for (i = 0; i < arguments.length; ++i) {", + " if (0 < i) {", + " internal.output(\" \");", + " }", + "", + " if (typeof(arguments[i]) === \"string\") {", + " internal.output(arguments[i]);", + " }", + " else {", + " internal.printRecursive(arguments[i], [], \"~\", [], 0);", + " }", + " }", + "", + " if (internal.COLOR_OUTPUT) {", + " internal.output(internal.COLOR_OUTPUT_RESET);", + " }", + "", + " internal.output(\"\\n\");", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief quote cache", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.characterQuoteCache = {", + " '\\b': '\\\\b', // ASCII 8, Backspace", + " '\\t': '\\\\t', // ASCII 9, Tab", + " '\\n': '\\\\n', // ASCII 10, Newline", + " '\\f': '\\\\f', // ASCII 12, Formfeed", + " '\\r': '\\\\r', // ASCII 13, Carriage Return", + " '\\\"': '\\\\\"',", + " '\\\\': '\\\\\\\\'", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief quotes a single character", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.quoteSingleJsonCharacter = function (c) {", + " if (internal.characterQuoteCache.hasOwnProperty[c]) {", + " return internal.characterQuoteCache[c];", + " }", + "", + " var charCode = c.charCodeAt(0);", + " var result;", + "", + " if (charCode < 16) {", + " result = '\\\\u000';", + " }", + " else if (charCode < 256) {", + " result = '\\\\u00';", + " }", + " else if (charCode < 4096) {", + " result = '\\\\u0';", + " }", + " else {", + " result = '\\\\u';", + " }", + "", + " result += charCode.toString(16);", + " internal.characterQuoteCache[c] = result;", + "", + " return result;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief quotes a string character", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.quoteJsonString = function (str) {", + " var quotable = /[\\\\\\\"\\x00-\\x1f]/g;", + " return '\"' + str.replace(quotable, internal.quoteSingleJsonCharacter) + '\"';", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief prints objects to standard output without a new-line", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.printRecursive = function (value, seen, path, names, level) {", + " var p;", + "", + " if (seen === undefined) {", + " seen = [];", + " names = [];", + " }", + "", + " p = seen.indexOf(value);", + "", + " if (0 <= p) {", + " internal.output(names[p]);", + " }", + " else {", + " if (value instanceof Object) {", + " seen.push(value);", + " names.push(path);", + " }", + "", + " if (value instanceof Object) {", + " if ('_PRINT' in value) {", + " value._PRINT(seen, path, names, level);", + " }", + " else if (value instanceof Array) {", + " internal.printArray(value, seen, path, names, level);", + " }", + " else if (value.__proto__ === Object.prototype) {", + " internal.printObject(value, seen, path, names, level);", + " }", + " else if ('toString' in value) {", + " internal.output(value.toString());", + " }", + " else {", + " internal.printObject(value, seen, path, names, level);", + " }", + " }", + " else if (value === undefined) {", + " internal.output(\"undefined\");", + " }", + " else {", + " if (typeof(value) === \"string\") {", + " internal.output(internal.quoteJsonString(value));", + " }", + " else {", + " internal.output(String(value));", + " }", + " }", + " }", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief prints the ident for pretty printing", + "///", + "/// @FUN{internal.printIndent(@FA{level})}", + "///", + "/// Only available in shell mode.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.printIndent = function (level) {", + " var j;", + "", + " if (internal.PRETTY_PRINT) {", + " internal.output(\"\\n\");", + "", + " for (j = 0; j < level; ++j) {", + " internal.output(\" \");", + " }", + " }", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief JSON representation of an array", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.printArray = function (object, seen, path, names, level) {", + " if (object.length === 0) {", + " internal.output(\"[ ]\");", + " }", + " else {", + " var i;", + " var sep = \"\";", + "", + " internal.output(\"[\");", + "", + " var newLevel = level + 1;", + "", + " for (i = 0; i < object.length; i++) {", + " internal.output(sep);", + "", + " internal.printIndent(newLevel);", + "", + " internal.printRecursive(object[i],", + " seen,", + " path + \"[\" + i + \"]\",", + " names,", + " newLevel);", + " sep = \", \";", + " }", + "", + " internal.printIndent(level);", + "", + " internal.output(\"]\");", + " }", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief prints an object", + "////////////////////////////////////////////////////////////////////////////////", + "", + " internal.printObject = function (object, seen, path, names, level) {", + " var sep = \" \";", + " var k;", + "", + " internal.output(\"{\");", + "", + " var newLevel = level + 1;", + "", + " for (k in object) {", + " if (object.hasOwnProperty(k)) {", + " var val = object[k];", + "", + " internal.output(sep);", + "", + " internal.printIndent(newLevel);", + "", + " if (internal.COLOR_OUTPUT) {", + " internal.output(internal.COLOR_OUTPUT_DEFAULT,", + " k,", + " internal.COLOR_OUTPUT_RESET, ", + " \" : \");", + " }", + " else {", + " internal.output(internal.quoteJsonString(k), \" : \");", + " }", + "", + " internal.printRecursive(val,", + " seen,", + " path + \"[\" + k + \"]\",", + " names,", + " newLevel);", + " sep = \", \";", + " }", + " }", + "", + " internal.printIndent(level);", + "", + " internal.output(\" }\");", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "}());", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- global functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8Shell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief global print", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// must be a variable definition for the browser", + "if (typeof require(\"internal\").printBrowser === \"function\") {", + " print = require(\"internal\").print = require(\"internal\").printBrowser;", + "}", + "else {", + " print = require(\"internal\").print = require(\"internal\").printShell;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// Local Variables:", + "// mode: outline-minor", + "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @page\\\\|/// @}\\\\)\"", + "// End:", + "//__end__" +}; diff --git a/js/server/js-ahuacatl.h b/js/server/js-ahuacatl.h index de87c5a3aa..6acf7b102c 100644 --- a/js/server/js-ahuacatl.h +++ b/js/server/js-ahuacatl.h @@ -1,2216 +1,2217 @@ -static string JS_server_ahuacatl = string("") - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief Ahuacatl, internal query functions \n" - + "///\n" - + "/// @file\n" - + "///\n" - + "/// DISCLAIMER\n" - + "///\n" - + "/// Copyright 2010-2012 triagens GmbH, Cologne, Germany\n" - + "///\n" - + "/// Licensed under the Apache License, Version 2.0 (the \"License\");\n" - + "/// you may not use this file except in compliance with the License.\n" - + "/// You may obtain a copy of the License at\n" - + "///\n" - + "/// http://www.apache.org/licenses/LICENSE-2.0\n" - + "///\n" - + "/// Unless required by applicable law or agreed to in writing, software\n" - + "/// distributed under the License is distributed on an \"AS IS\" BASIS,\n" - + "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" - + "/// See the License for the specific language governing permissions and\n" - + "/// limitations under the License.\n" - + "///\n" - + "/// Copyright holder is triAGENS GmbH, Cologne, Germany\n" - + "///\n" - + "/// @author Jan Steemann\n" - + "/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "var internal = require(\"internal\");\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief type weight used for sorting and comparing\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "var AHUACATL_TYPEWEIGHT_NULL = 0;\n" - + "var AHUACATL_TYPEWEIGHT_BOOL = 1;\n" - + "var AHUACATL_TYPEWEIGHT_NUMBER = 2;\n" - + "var AHUACATL_TYPEWEIGHT_STRING = 4;\n" - + "var AHUACATL_TYPEWEIGHT_LIST = 8;\n" - + "var AHUACATL_TYPEWEIGHT_DOCUMENT = 16;\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- helper functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief throw a runtime exception\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_THROW (error, data) {\n" - + " var err = new ArangoError\n" - + "\n" - + " err.errorNum = error.code;\n" - + " if (data) {\n" - + " err.errorMessage = error.message.replace(/%s/, data);\n" - + " }\n" - + " else {\n" - + " err.errorMessage = error.message;\n" - + " }\n" - + "\n" - + " throw err;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief find an index of a certain type for a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_INDEX (collection, indexTypes) {\n" - + " var indexes = collection.getIndexesNL();\n" - + "\n" - + " for (var i = 0; i < indexes.length; ++i) {\n" - + " var index = indexes[i];\n" - + "\n" - + " for (var j = 0; j < indexTypes.length; ++j) {\n" - + " if (index.type == indexTypes[j]) {\n" - + " return index.id;\n" - + " }\n" - + " }\n" - + " }\n" - + "\n" - + " return null;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief normalize a value for comparison, sorting etc.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_NORMALIZE (value) {\n" - + " if (value === null || value === undefined) {\n" - + " return null;\n" - + " }\n" - + " if (typeof(value) !== \"object\") {\n" - + " return value;\n" - + " }\n" - + "\n" - + " if (Array.isArray(value)) {\n" - + " var result = [ ];\n" - + " var length = value.length;\n" - + " for (var i = 0; i < length; ++i) {\n" - + " result.push(AHUACATL_NORMALIZE(value[i]));\n" - + " }\n" - + " \n" - + " return result;\n" - + " } \n" - + " else {\n" - + " var attributes = [ ];\n" - + " for (var attribute in value) {\n" - + " if (!value.hasOwnProperty(attribute)) {\n" - + " continue;\n" - + " }\n" - + " attributes.push(attribute);\n" - + " }\n" - + " attributes.sort();\n" - + "\n" - + " var result = { };\n" - + " var length = attributes.length;\n" - + " for (var i = 0; i < length; ++i) {\n" - + " result[attributes[i]] = AHUACATL_NORMALIZE(value[attributes[i]]);\n" - + " }\n" - + "\n" - + " return result;\n" - + " }\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief clone an object\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_CLONE (obj) {\n" - + " if (obj == null) {\n" - + " return obj;\n" - + " }\n" - + "\n" - + " if (typeof(obj) != \"object\") {\n" - + " return obj;\n" - + " }\n" - + "\n" - + " if (Array.isArray(obj)) {\n" - + " var copy = [];\n" - + " var length = obj.length;\n" - + " for (var i = 0; i < length; ++i) {\n" - + " copy[i] = AHUACATL_CLONE(obj[i]);\n" - + " }\n" - + " return copy;\n" - + " }\n" - + "\n" - + " if (obj instanceof Object) {\n" - + " var copy = {};\n" - + " for (var attr in obj) {\n" - + " if (obj.hasOwnProperty(attr)) {\n" - + " copy[attr] = AHUACATL_CLONE(obj[attr]);\n" - + " }\n" - + " }\n" - + " return copy;\n" - + " }\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief validate function call argument\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_ARG_CHECK (actualValue, expectedType, functionName) {\n" - + " if (AHUACATL_TYPEWEIGHT(actualValue) !== expectedType) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, functionName);\n" - + " }\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief call a function\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_FCALL (name, parameters) {\n" - + " return name.apply(null, parameters);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return the numeric value or undefined if it is out of range\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_NUMERIC_VALUE (value) {\n" - + " if (isNaN(value) || !isFinite(value)) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " return value;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief fix a value for a comparison\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_FIX (value) {\n" - + " if (value === undefined) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " return value;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get the name for a type\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_TYPENAME (value) {\n" - + " switch (value) {\n" - + " case AHUCATL_TYPEWEIGHT_BOOL:\n" - + " return 'boolean';\n" - + " case AHUCATL_TYPEWEIGHT_NUMBER:\n" - + " return 'number';\n" - + " case AHUCATL_TYPEWEIGHT_STRING:\n" - + " return 'string';\n" - + " case AHUCATL_TYPEWEIGHT_LIST:\n" - + " return 'list';\n" - + " case AHUCATL_TYPEWEIGHT_DOCUMENT:\n" - + " return 'document';\n" - + " case AHUCATL_TYPEWEIGHT_NULL:\n" - + " default:\n" - + " return 'null';\n" - + " }\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get the sort type of an operand\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_TYPEWEIGHT (value) {\n" - + " if (value === undefined || value === null) {\n" - + " return AHUACATL_TYPEWEIGHT_NULL;\n" - + " }\n" - + "\n" - + " if (Array.isArray(value)) {\n" - + " return AHUACATL_TYPEWEIGHT_LIST;\n" - + " }\n" - + "\n" - + " switch (typeof(value)) {\n" - + " case 'boolean':\n" - + " return AHUACATL_TYPEWEIGHT_BOOL;\n" - + " case 'number':\n" - + " if (isNaN(value) || !isFinite(value)) {\n" - + " // not a number => undefined\n" - + " return AHUACATL_TYPEWEIGHT_NULL; \n" - + " }\n" - + " return AHUACATL_TYPEWEIGHT_NUMBER;\n" - + " case 'string':\n" - + " return AHUACATL_TYPEWEIGHT_STRING;\n" - + " case 'object':\n" - + " return AHUACATL_TYPEWEIGHT_DOCUMENT;\n" - + " }\n" - + "\n" - + " return AHUACATL_TYPEWEIGHT_NULL;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get the keys of an array or object in a comparable way\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_KEYS (value, doSort) {\n" - + " var keys = [];\n" - + " \n" - + " if (Array.isArray(value)) {\n" - + " var n = value.length;\n" - + " for (var j = 0; j < n; ++j) {\n" - + " keys.push(j);\n" - + " }\n" - + " }\n" - + " else {\n" - + " for (var k in value) {\n" - + " if (value.hasOwnProperty(k)) {\n" - + " keys.push(k);\n" - + " }\n" - + " }\n" - + "\n" - + " if (doSort) {\n" - + " // object keys need to be sorted by names\n" - + " keys.sort();\n" - + " }\n" - + " }\n" - + "\n" - + " return keys;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get the keys of an array or object in a comparable way\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_KEYLIST (lhs, rhs) {\n" - + " var keys = [];\n" - + " \n" - + " if (Array.isArray(lhs)) {\n" - + " // lhs & rhs are lists\n" - + " var n;\n" - + " if (lhs.length > rhs.length) {\n" - + " n = lhs.length;\n" - + " }\n" - + " else {\n" - + " n = rhs.length;\n" - + " }\n" - + " for (var j = 0; j < n; ++j) {\n" - + " keys.push(j);\n" - + " }\n" - + " return keys;\n" - + " }\n" - + "\n" - + " // lhs & rhs are arrays\n" - + " var k;\n" - + " for (k in lhs) {\n" - + " keys.push(k);\n" - + " }\n" - + " for (k in rhs) {\n" - + " if (lhs.hasOwnProperty(k)) {\n" - + " continue;\n" - + " }\n" - + " keys.push(k);\n" - + " }\n" - + "\n" - + " // object keys need to be sorted by names\n" - + " keys.sort();\n" - + "\n" - + " return keys;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get an indexed value from an array or document (e.g. users[3])\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GET_INDEX (value, index) {\n" - + " if (AHUACATL_TYPEWEIGHT(value) == AHUACATL_TYPEWEIGHT_NULL) {\n" - + " return null;\n" - + " }\n" - + " \n" - + " if (AHUACATL_TYPEWEIGHT(value) != AHUACATL_TYPEWEIGHT_LIST &&\n" - + " AHUACATL_TYPEWEIGHT(value) != AHUACATL_TYPEWEIGHT_DOCUMENT) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_LIST_EXPECTED);\n" - + " }\n" - + "\n" - + " var result = value[index];\n" - + "\n" - + " if (AHUACATL_TYPEWEIGHT(result) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get an attribute from a document (e.g. users.name)\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_DOCUMENT_MEMBER (value, attributeName) {\n" - + " if (AHUACATL_TYPEWEIGHT(value) == AHUACATL_TYPEWEIGHT_NULL) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " if (AHUACATL_TYPEWEIGHT(value) != AHUACATL_TYPEWEIGHT_DOCUMENT) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " var result = value[attributeName];\n" - + "\n" - + " if (AHUACATL_TYPEWEIGHT(result) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief assert that a value is a list, fail otherwise\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_LIST (value) {\n" - + " if (AHUACATL_TYPEWEIGHT(value) !== AHUACATL_TYPEWEIGHT_LIST) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_LIST_EXPECTED);\n" - + " }\n" - + "\n" - + " return value;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get all documents from the specified collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GET_DOCUMENTS (collection) {\n" - + " return internal.db[collection].ALL_NL(0, null).documents;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get documents from the specified collection using the primary index\n" - + "/// (single index value)\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GET_DOCUMENTS_PRIMARY (collection, idx, id) {\n" - + " try {\n" - + " return [ internal.db[collection].document_nl(id) ];\n" - + " }\n" - + " catch (e) {\n" - + " return [ ];\n" - + " }\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get documents from the specified collection using the primary index\n" - + "/// (multiple index values)\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GET_DOCUMENTS_PRIMARY_LIST (collection, idx, values) {\n" - + " var result = [ ];\n" - + "\n" - + " for (var i in values) {\n" - + " var id = values[i];\n" - + " try {\n" - + " var d = internal.db[collection].document_nl(id);\n" - + " result.push(d);\n" - + " }\n" - + " catch (e) {\n" - + " }\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get documents from the specified collection using a hash index\n" - + "/// (single index value)\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GET_DOCUMENTS_HASH (collection, idx, example) {\n" - + " return internal.db[collection].BY_EXAMPLE_HASH_NL(idx, example).documents;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get documents from the specified collection using a hash index\n" - + "/// (multiple index values)\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GET_DOCUMENTS_HASH_LIST (collection, idx, attribute, values) {\n" - + " var result = [ ];\n" - + "\n" - + " for (var i in values) {\n" - + " var value = values[i];\n" - + " var example = { };\n" - + "\n" - + " example[attribute] = value;\n" - + "\n" - + " var documents = internal.db[collection].BY_EXAMPLE_HASH_NL(idx, example).documents;\n" - + " for (var j in documents) {\n" - + " result.push(documents[j]);\n" - + " }\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get documents from the specified collection using a bitarray\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GET_DOCUMENTS_BITARRAY (collection, idx, example) {\n" - + " return internal.db[collection].BY_CONDITION_BITARRAY(idx, example).documents;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get documents from the specified collection using a bitarray\n" - + "/// (multiple index values) TODO: replace by 'IN index operator'\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GET_DOCUMENTS_BITARRAY_LIST (collection, idx, attribute, values) {\n" - + " var result = [ ];\n" - + "\n" - + " for (var i in values) {\n" - + " var value = values[i];\n" - + " var example = { };\n" - + "\n" - + " example[attribute] = value;\n" - + "\n" - + " var documents = internal.db[collection].BY_EXAMPLE_BITARRAY(idx, example).documents;\n" - + " for (var j in documents) {\n" - + " result.push(documents[j]);\n" - + " }\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get documents from the specified collection using a skiplist\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GET_DOCUMENTS_SKIPLIST (collection, idx, example) {\n" - + " return internal.db[collection].BY_CONDITION_SKIPLIST_NL(idx, example).documents;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get documents from the specified collection using a skiplist\n" - + "/// (multiple index values)\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GET_DOCUMENTS_SKIPLIST_LIST (collection, idx, attribute, values) {\n" - + " var result = [ ];\n" - + "\n" - + " for (var i in values) {\n" - + " var value = values[i];\n" - + " var example = { };\n" - + "\n" - + " example[attribute] = value;\n" - + "\n" - + " var documents = internal.db[collection].BY_EXAMPLE_SKIPLIST_NL(idx, example).documents;\n" - + " for (var j in documents) {\n" - + " result.push(documents[j]);\n" - + " }\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get names of all collections\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_COLLECTIONS () {\n" - + " var collections = internal.db._collections();\n" - + " var result = [ ];\n" - + "\n" - + " for (var i = 0; i < collections.length; ++i) {\n" - + " result.push({ \"_id\" : collections[i]._id, \"name\" : collections[i].name() });\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- logical operations\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief execute ternary operator\n" - + "///\n" - + "/// the condition operand must be a boolean value, returns either the truepart\n" - + "/// or the falsepart \n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_TERNARY_OPERATOR (condition, truePart, falsePart) {\n" - + " if (AHUACATL_TYPEWEIGHT(condition) !== AHUACATL_TYPEWEIGHT_BOOL) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);\n" - + " }\n" - + "\n" - + " if (condition) {\n" - + " return truePart;\n" - + " }\n" - + " return falsePart;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform logical and\n" - + "///\n" - + "/// both operands must be boolean values, returns a boolean, uses short-circuit\n" - + "/// evaluation\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_LOGICAL_AND (lhs, rhs) {\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_BOOL ||\n" - + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_BOOL) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);\n" - + " }\n" - + "\n" - + " if (!lhs) {\n" - + " return false;\n" - + " }\n" - + "\n" - + " return rhs;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform logical or\n" - + "///\n" - + "/// both operands must be boolean values, returns a boolean, uses short-circuit\n" - + "/// evaluation\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_LOGICAL_OR (lhs, rhs) {\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_BOOL ||\n" - + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_BOOL) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);\n" - + " }\n" - + " \n" - + " if (lhs) {\n" - + " return true;\n" - + " }\n" - + "\n" - + " return rhs;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform logical negation\n" - + "///\n" - + "/// the operand must be a boolean values, returns a boolean\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_LOGICAL_NOT (lhs) {\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_BOOL) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);\n" - + " }\n" - + "\n" - + " return !lhs;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- comparison operations\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform equality check \n" - + "///\n" - + "/// returns true if the operands are equal, false otherwise\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_RELATIONAL_EQUAL (lhs, rhs) {\n" - + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - + "\n" - + " if (leftWeight != rightWeight) {\n" - + " return false;\n" - + " }\n" - + "\n" - + " // lhs and rhs have the same type\n" - + "\n" - + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - + " // arrays and objects\n" - + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - + "\n" - + " for (var i in keys) {\n" - + " var key = keys[i];\n" - + " var result = AHUACATL_RELATIONAL_EQUAL(lhs[key], rhs[key]);\n" - + " if (result === false) {\n" - + " return result;\n" - + " }\n" - + " }\n" - + " return true;\n" - + " }\n" - + "\n" - + " // primitive type\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " lhs = null;\n" - + " }\n" - + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " rhs = null;\n" - + " }\n" - + "\n" - + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - + " return COMPARE_STRING(lhs, rhs) == 0;\n" - + " }\n" - + "\n" - + " return (lhs === rhs);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform inequality check \n" - + "///\n" - + "/// returns true if the operands are unequal, false otherwise\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_RELATIONAL_UNEQUAL (lhs, rhs) {\n" - + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - + " \n" - + " if (leftWeight != rightWeight) {\n" - + " return true;\n" - + " }\n" - + "\n" - + " // lhs and rhs have the same type\n" - + "\n" - + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - + " // arrays and objects\n" - + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - + "\n" - + " for (var i in keys) {\n" - + " var key = keys[i];\n" - + " var result = AHUACATL_RELATIONAL_UNEQUAL(lhs[key], rhs[key]);\n" - + " if (result === true) {\n" - + " return result;\n" - + " }\n" - + " }\n" - + "\n" - + " return false;\n" - + " }\n" - + "\n" - + " // primitive type\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " lhs = null;\n" - + " }\n" - + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " rhs = null;\n" - + " }\n" - + "\n" - + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - + " return COMPARE_STRING(lhs, rhs) != 0;\n" - + " }\n" - + "\n" - + " return (lhs !== rhs);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform greater than check (inner function)\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_RELATIONAL_GREATER_REC (lhs, rhs) {\n" - + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - + " \n" - + " if (leftWeight > rightWeight) {\n" - + " return true;\n" - + " }\n" - + " if (leftWeight < rightWeight) {\n" - + " return false;\n" - + " }\n" - + "\n" - + " // lhs and rhs have the same type\n" - + "\n" - + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - + " // arrays and objects\n" - + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - + "\n" - + " for (var i in keys) {\n" - + " var key = keys[i];\n" - + " var result = AHUACATL_RELATIONAL_GREATER_REC(lhs[key], rhs[key]);\n" - + " if (result !== null) {\n" - + " return result;\n" - + " }\n" - + " }\n" - + " \n" - + " return null;\n" - + " }\n" - + "\n" - + " // primitive type\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " lhs = null;\n" - + " }\n" - + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " rhs = null;\n" - + " }\n" - + "\n" - + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - + " return COMPARE_STRING(lhs, rhs) > 0;\n" - + " }\n" - + "\n" - + " if (lhs === rhs) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " return (lhs > rhs);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform greater than check \n" - + "///\n" - + "/// returns true if the left operand is greater than the right operand\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_RELATIONAL_GREATER (lhs, rhs) {\n" - + " var result = AHUACATL_RELATIONAL_GREATER_REC(lhs, rhs);\n" - + "\n" - + " if (result === null) {\n" - + " result = false;\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform greater equal check (inner function)\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_RELATIONAL_GREATEREQUAL_REC (lhs, rhs) {\n" - + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - + " \n" - + " if (leftWeight > rightWeight) {\n" - + " return true;\n" - + " }\n" - + " if (leftWeight < rightWeight) {\n" - + " return false;\n" - + " }\n" - + "\n" - + " // lhs and rhs have the same type\n" - + "\n" - + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - + " // arrays and objects\n" - + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - + "\n" - + " for (var i in keys) {\n" - + " var key = keys[i];\n" - + " var result = AHUACATL_RELATIONAL_GREATEREQUAL_REC(lhs[key], rhs[key]);\n" - + " if (result !== null) {\n" - + " return result;\n" - + " }\n" - + " }\n" - + " \n" - + " return null;\n" - + " }\n" - + "\n" - + " // primitive type\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " lhs = null;\n" - + " }\n" - + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " rhs = null;\n" - + " }\n" - + "\n" - + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - + " return COMPARE_STRING(lhs, rhs) >= 0;\n" - + " }\n" - + "\n" - + " if (lhs === rhs) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " return (lhs >= rhs);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform greater equal check \n" - + "///\n" - + "/// returns true if the left operand is greater or equal to the right operand\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_RELATIONAL_GREATEREQUAL (lhs, rhs) {\n" - + " var result = AHUACATL_RELATIONAL_GREATEREQUAL_REC(lhs, rhs);\n" - + "\n" - + " if (result === null) {\n" - + " result = true;\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform less than check (inner function)\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_RELATIONAL_LESS_REC (lhs, rhs) {\n" - + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - + " \n" - + " if (leftWeight < rightWeight) {\n" - + " return true;\n" - + " }\n" - + " if (leftWeight > rightWeight) {\n" - + " return false;\n" - + " }\n" - + "\n" - + " // lhs and rhs have the same type\n" - + "\n" - + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - + " // arrays and objects\n" - + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - + "\n" - + " for (var i in keys) {\n" - + " var key = keys[i];\n" - + " var result = AHUACATL_RELATIONAL_LESS_REC(lhs[key], rhs[key]);\n" - + " if (result !== null) {\n" - + " return result;\n" - + " }\n" - + " }\n" - + " \n" - + " return null;\n" - + " }\n" - + "\n" - + " // primitive type\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " lhs = null;\n" - + " }\n" - + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " rhs = null;\n" - + " }\n" - + "\n" - + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - + " return COMPARE_STRING(lhs, rhs) < 0;\n" - + " }\n" - + "\n" - + " if (lhs === rhs) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " return (lhs < rhs);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform less than check \n" - + "///\n" - + "/// returns true if the left operand is less than the right operand\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_RELATIONAL_LESS (lhs, rhs) {\n" - + " var result = AHUACATL_RELATIONAL_LESS_REC(lhs, rhs);\n" - + "\n" - + " if (result === null) {\n" - + " result = false;\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform less equal check (inner function)\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_RELATIONAL_LESSEQUAL_REC (lhs, rhs) {\n" - + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - + " \n" - + " if (leftWeight < rightWeight) {\n" - + " return true;\n" - + " }\n" - + " if (leftWeight > rightWeight) {\n" - + " return false;\n" - + " }\n" - + "\n" - + " // lhs and rhs have the same type\n" - + "\n" - + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - + " // arrays and objects\n" - + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - + "\n" - + " for (var i in keys) {\n" - + " var key = keys[i];\n" - + " var result = AHUACATL_RELATIONAL_LESSEQUAL_REC(lhs[key], rhs[key]);\n" - + " if (result !== null) {\n" - + " return result;\n" - + " }\n" - + " }\n" - + "\n" - + " return null;\n" - + " }\n" - + " \n" - + " // primitive type\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " lhs = null;\n" - + " }\n" - + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " rhs = null;\n" - + " }\n" - + " \n" - + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - + " return COMPARE_STRING(lhs, rhs) <= 0;\n" - + " }\n" - + " \n" - + " if (lhs === rhs) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " return (lhs <= rhs);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform less equal check \n" - + "///\n" - + "/// returns true if the left operand is less or equal to the right operand\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_RELATIONAL_LESSEQUAL (lhs, rhs) {\n" - + " var result = AHUACATL_RELATIONAL_LESSEQUAL_REC(lhs, rhs);\n" - + "\n" - + " if (result === null) {\n" - + " result = true;\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform comparison\n" - + "///\n" - + "/// returns -1 if the left operand is less than the right operand, 1 if it is\n" - + "/// greater, 0 if both operands are equal\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_RELATIONAL_CMP (lhs, rhs) {\n" - + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - + " \n" - + " if (leftWeight < rightWeight) {\n" - + " return -1;\n" - + " }\n" - + " if (leftWeight > rightWeight) {\n" - + " return 1;\n" - + " }\n" - + "\n" - + " // lhs and rhs have the same type\n" - + "\n" - + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - + " // arrays and objects\n" - + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - + "\n" - + " for (var i in keys) {\n" - + " var key = keys[i];\n" - + " var result = AHUACATL_RELATIONAL_CMP(lhs[key], rhs[key]);\n" - + " if (result !== 0) {\n" - + " return result;\n" - + " }\n" - + " }\n" - + " \n" - + " return 0;\n" - + " }\n" - + "\n" - + " // primitive type\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " lhs = null;\n" - + " }\n" - + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " rhs = null;\n" - + " }\n" - + "\n" - + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - + " return COMPARE_STRING(lhs, rhs);\n" - + " }\n" - + "\n" - + " if (lhs < rhs) {\n" - + " return -1;\n" - + " }\n" - + " \n" - + " if (lhs > rhs) {\n" - + " return 1;\n" - + " }\n" - + "\n" - + " return 0;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform in list check \n" - + "///\n" - + "/// returns true if the left operand is contained in the right operand\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_RELATIONAL_IN (lhs, rhs) {\n" - + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - + " \n" - + " if (rightWeight !== AHUACATL_TYPEWEIGHT_LIST) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_LIST_EXPECTED);\n" - + " }\n" - + "\n" - + " var numRight = rhs.length;\n" - + " for (var i = 0; i < numRight; ++i) {\n" - + " if (AHUACATL_RELATIONAL_EQUAL(lhs, rhs[i])) {\n" - + " return true;\n" - + " }\n" - + " }\n" - + "\n" - + " return false;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- arithmetic operations\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform unary plus operation\n" - + "///\n" - + "/// the operand must be numeric or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_UNARY_PLUS (value) {\n" - + " if (AHUACATL_TYPEWEIGHT(value) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - + " }\n" - + "\n" - + " var result = AHUACATL_NUMERIC_VALUE(value);\n" - + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform unary minus operation\n" - + "///\n" - + "/// the operand must be numeric or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_UNARY_MINUS (value) {\n" - + " if (AHUACATL_TYPEWEIGHT(value) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - + " }\n" - + "\n" - + " var result = AHUACATL_NUMERIC_VALUE(-value);\n" - + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform artithmetic plus\n" - + "///\n" - + "/// both operands must be numeric or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_ARITHMETIC_PLUS (lhs, rhs) { \n" - + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" - + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - + " }\n" - + "\n" - + " var result = AHUACATL_NUMERIC_VALUE(lhs + rhs);\n" - + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform artithmetic minus\n" - + "///\n" - + "/// both operands must be numeric or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_ARITHMETIC_MINUS (lhs, rhs) {\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" - + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - + " }\n" - + "\n" - + " var result = AHUACATL_NUMERIC_VALUE(lhs - rhs);\n" - + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform artithmetic multiplication\n" - + "///\n" - + "/// both operands must be numeric or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_ARITHMETIC_TIMES (lhs, rhs) {\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" - + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - + " }\n" - + "\n" - + " var result = AHUACATL_NUMERIC_VALUE(lhs * rhs);\n" - + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform artithmetic division\n" - + "///\n" - + "/// both operands must be numeric or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_ARITHMETIC_DIVIDE (lhs, rhs) {\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" - + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - + " }\n" - + " \n" - + " if (rhs == 0) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_DIVISION_BY_ZERO);\n" - + " }\n" - + "\n" - + " var result = AHUACATL_NUMERIC_VALUE(lhs / rhs);\n" - + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform artithmetic modulus\n" - + "///\n" - + "/// both operands must be numeric or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_ARITHMETIC_MODULUS (lhs, rhs) {\n" - + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" - + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - + " }\n" - + "\n" - + " if (rhs == 0) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_DIVISION_BY_ZERO);\n" - + " }\n" - + "\n" - + " var result = AHUACATL_NUMERIC_VALUE(lhs % rhs);\n" - + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- string functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform string concatenation\n" - + "///\n" - + "/// all operands must be strings or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_STRING_CONCAT () {\n" - + " var result = '';\n" - + "\n" - + " for (var i in arguments) {\n" - + " var element = arguments[i];\n" - + "\n" - + " if (AHUACATL_TYPEWEIGHT(element) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " continue;\n" - + " }\n" - + "\n" - + " AHUACATL_ARG_CHECK(element, AHUACATL_TYPEWEIGHT_STRING, \"CONCAT\");\n" - + "\n" - + " result += element;\n" - + " }\n" - + "\n" - + " return result; \n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief perform string concatenation using a separator character\n" - + "///\n" - + "/// all operands must be strings or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_STRING_CONCAT_SEPARATOR () {\n" - + " var separator;\n" - + " var found = false;\n" - + " var result = '';\n" - + "\n" - + " for (var i in arguments) {\n" - + " var element = arguments[i];\n" - + "\n" - + " if (i > 0 && AHUACATL_TYPEWEIGHT(element) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " continue;\n" - + " }\n" - + " \n" - + " AHUACATL_ARG_CHECK(element, AHUACATL_TYPEWEIGHT_STRING, \"CONCAT_SEPARATOR\");\n" - + "\n" - + " if (i == 0) {\n" - + " separator = element;\n" - + " continue;\n" - + " }\n" - + " else if (found) {\n" - + " result += separator;\n" - + " }\n" - + "\n" - + " found = true;\n" - + "\n" - + " result += element;\n" - + " }\n" - + "\n" - + " return result; \n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return the length of a string in characters (not bytes)\n" - + "///\n" - + "/// the input operand must be a string or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_STRING_LENGTH (value) {\n" - + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"STRING_LENGTH\");\n" - + "\n" - + " return value.length;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief convert a string to lower case\n" - + "///\n" - + "/// the input operand must be a string or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_STRING_LOWER (value) {\n" - + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"LOWER\");\n" - + "\n" - + " return value.toLowerCase();\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief convert a string to upper case\n" - + "///\n" - + "/// the input operand must be a string or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_STRING_UPPER (value) {\n" - + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"UPPER\");\n" - + "\n" - + " return value.toUpperCase();\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return a substring of the string\n" - + "///\n" - + "/// the input operand must be a string or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_STRING_SUBSTRING (value, offset, count) {\n" - + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"SUBSTRING\");\n" - + " AHUACATL_ARG_CHECK(offset, AHUACATL_TYPEWEIGHT_NUMBER, \"SUBSTRING\");\n" - + "\n" - + " return value.substr(offset, count);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief searches a substring in a string\n" - + "///\n" - + "/// the two input operands must be strings or this function will fail\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_STRING_CONTAINS (value, search) {\n" - + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"CONTAINS\");\n" - + " AHUACATL_ARG_CHECK(search, AHUACATL_TYPEWEIGHT_STRING, \"CONTAINS\");\n" - + "\n" - + " if (search.length == 0) {\n" - + " return false;\n" - + " }\n" - + "\n" - + " return value.indexOf(search) != -1;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- typecast functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief cast to a bool\n" - + "///\n" - + "/// the operand can have any type, always returns a bool\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_CAST_BOOL (value) {\n" - + " switch (AHUACATL_TYPEWEIGHT(value)) {\n" - + " case AHUACATL_TYPEWEIGHT_NULL:\n" - + " return false;\n" - + " case AHUACATL_TYPEWEIGHT_BOOL:\n" - + " return value;\n" - + " case AHUACATL_TYPEWEIGHT_NUMBER:\n" - + " return (value != 0);\n" - + " case AHUACATL_TYPEWEIGHT_STRING: \n" - + " return (value !== '');\n" - + " case AHUACATL_TYPEWEIGHT_LIST:\n" - + " return (value.length > 0);\n" - + " case AHUACATL_TYPEWEIGHT_DOCUMENT:\n" - + " return (AHUACATL_KEYS(value, false).length > 0);\n" - + " }\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief cast to a number\n" - + "///\n" - + "/// the operand can have any type, always returns a number\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_CAST_NUMBER (value) {\n" - + " switch (AHUACATL_TYPEWEIGHT(value)) {\n" - + " case AHUACATL_TYPEWEIGHT_NULL:\n" - + " case AHUACATL_TYPEWEIGHT_LIST:\n" - + " case AHUACATL_TYPEWEIGHT_DOCUMENT:\n" - + " return 0.0;\n" - + " case AHUACATL_TYPEWEIGHT_BOOL:\n" - + " return (value ? 1 : 0);\n" - + " case AHUACATL_TYPEWEIGHT_NUMBER:\n" - + " return value;\n" - + " case AHUACATL_TYPEWEIGHT_STRING:\n" - + " var result = parseFloat(value);\n" - + " return ((AHUACATL_TYPEWEIGHT(result) === AHUACATL_TYPEWEIGHT_NUMBER) ? result : 0);\n" - + " }\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief cast to a string\n" - + "///\n" - + "/// the operand can have any type, always returns a string\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_CAST_STRING (value) {\n" - + " switch (AHUACATL_TYPEWEIGHT(value)) {\n" - + " case AHUACATL_TYPEWEIGHT_STRING:\n" - + " return value;\n" - + " case AHUACATL_TYPEWEIGHT_NULL:\n" - + " return 'null';\n" - + " case AHUACATL_TYPEWEIGHT_BOOL:\n" - + " return (value ? 'true' : 'false');\n" - + " case AHUACATL_TYPEWEIGHT_NUMBER:\n" - + " case AHUACATL_TYPEWEIGHT_LIST:\n" - + " case AHUACATL_TYPEWEIGHT_DOCUMENT:\n" - + " return value.toString();\n" - + " }\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- typecheck functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief test if value is of type null\n" - + "///\n" - + "/// returns a bool\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_IS_NULL (value) {\n" - + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NULL);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief test if value is of type bool\n" - + "///\n" - + "/// returns a bool\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_IS_BOOL (value) {\n" - + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_BOOL);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief test if value is of type number\n" - + "///\n" - + "/// returns a bool\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_IS_NUMBER (value) {\n" - + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NUMBER);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief test if value is of type string\n" - + "///\n" - + "/// returns a bool\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_IS_STRING (value) {\n" - + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_STRING);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief test if value is of type list\n" - + "///\n" - + "/// returns a bool\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_IS_LIST (value) {\n" - + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_LIST);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief test if value is of type document\n" - + "///\n" - + "/// returns a bool\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_IS_DOCUMENT (value) {\n" - + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_DOCUMENT);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- numeric functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief integer closest to value, not greater than value\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_NUMBER_FLOOR (value) {\n" - + " if (!AHUACATL_IS_NUMBER(value)) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"FLOOR\");\n" - + " }\n" - + " \n" - + " return Math.floor(value);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief integer closest to value and not less than value\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_NUMBER_CEIL (value) {\n" - + " if (!AHUACATL_IS_NUMBER(value)) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"CEIL\");\n" - + " }\n" - + " \n" - + " return Math.ceil(value);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief integer closest to value \n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_NUMBER_ROUND (value) {\n" - + " if (!AHUACATL_IS_NUMBER(value)) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"ROUND\");\n" - + " }\n" - + " \n" - + " return Math.round(value);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief absolute value\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_NUMBER_ABS (value) {\n" - + " if (!AHUACATL_IS_NUMBER(value)) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"ABS\");\n" - + " }\n" - + " \n" - + " return Math.abs(value);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief a random value between 0 and 1\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_NUMBER_RAND () {\n" - + " return Math.random();\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- high level query functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief sort the results\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_SORT (value, sortFunction) {\n" - + " AHUACATL_LIST(value);\n" - + " \n" - + " var n = value.length;\n" - + " if (n > 0) {\n" - + " value.sort(sortFunction);\n" - + " }\n" - + "\n" - + " return value;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief group the results\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GROUP (value, sortFunction, groupFunction, into) {\n" - + " AHUACATL_LIST(value);\n" - + "\n" - + " var n = value.length;\n" - + " if (n == 0) {\n" - + " return [ ];\n" - + " }\n" - + "\n" - + " AHUACATL_SORT(value, sortFunction);\n" - + "\n" - + " var result = [ ];\n" - + " var currentGroup = undefined;\n" - + " var oldGroup = undefined;\n" - + " \n" - + " for (var i = 0; i < n; ++i) {\n" - + " var row = value[i];\n" - + " var groupValue = groupFunction(row);\n" - + "\n" - + " if (AHUACATL_RELATIONAL_UNEQUAL(oldGroup, groupValue)) {\n" - + " oldGroup = AHUACATL_CLONE(groupValue);\n" - + "\n" - + " if (currentGroup) {\n" - + " result.push(AHUACATL_CLONE(currentGroup));\n" - + " }\n" - + " \n" - + " currentGroup = groupValue;\n" - + " if (into) {\n" - + " currentGroup[into] = [ ];\n" - + " }\n" - + " }\n" - + "\n" - + " if (into) {\n" - + " currentGroup[into].push(AHUACATL_CLONE(row));\n" - + " }\n" - + " }\n" - + "\n" - + " if (currentGroup) {\n" - + " result.push(AHUACATL_CLONE(currentGroup));\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief limit the number of results\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_LIMIT (value, offset, count) {\n" - + " AHUACATL_LIST(value);\n" - + "\n" - + " if (count < 0) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - + " }\n" - + "\n" - + " return value.slice(offset, offset + count);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- list processing functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get the length of a list\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_LENGTH () {\n" - + " var value = arguments[0];\n" - + "\n" - + " AHUACATL_LIST(value);\n" - + "\n" - + " return value.length;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get the first element of a list\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_FIRST () {\n" - + " var value = arguments[0];\n" - + "\n" - + " AHUACATL_LIST(value);\n" - + "\n" - + " if (value.length == 0) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " return value[0];\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief get the last element of a list\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_LAST () {\n" - + " var value = arguments[0];\n" - + "\n" - + " AHUACATL_LIST(value);\n" - + "\n" - + " if (value.length == 0) {\n" - + " return null;\n" - + " }\n" - + "\n" - + " return value[value.length - 1];\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief reverse the elements in a list\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_REVERSE () {\n" - + " var value = arguments[0];\n" - + "\n" - + " AHUACATL_LIST(value);\n" - + "\n" - + " return value.reverse();\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return a list of unique elements from the list\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_UNIQUE () {\n" - + " var value = arguments[0];\n" - + "\n" - + " AHUACATL_LIST(value);\n" - + "\n" - + " var length = value.length;\n" - + " var keys = { };\n" - + " for (var i = 0; i < length; ++i) {\n" - + " var normalized = AHUACATL_NORMALIZE(value[i]);\n" - + " keys[JSON.stringify(normalized)] = normalized;\n" - + " }\n" - + "\n" - + " var result = [];\n" - + " for (var i in keys) {\n" - + " result.push(keys[i]);\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief create the union (all) of all arguments\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_UNION () {\n" - + " var result = [ ];\n" - + "\n" - + " for (var i in arguments) {\n" - + " var element = arguments[i];\n" - + "\n" - + " if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_LIST) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"UNION\");\n" - + " }\n" - + "\n" - + " for (var k in element) {\n" - + " if (!element.hasOwnProperty(k)) {\n" - + " continue;\n" - + " }\n" - + "\n" - + " result.push(element[k]);\n" - + " }\n" - + " }\n" - + "\n" - + " return result; \n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief maximum of all values\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_MAX () {\n" - + " var result = null;\n" - + " var value = arguments[0];\n" - + "\n" - + " AHUACATL_LIST(value);\n" - + "\n" - + " for (var i in value) {\n" - + " var currentValue = value[i];\n" - + " \n" - + " if (AHUACATL_TYPEWEIGHT(currentValue) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " continue;\n" - + " }\n" - + "\n" - + " if (result === null || AHUACATL_RELATIONAL_GREATER(currentValue, result)) {\n" - + " result = currentValue;\n" - + " }\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief minimum of all values\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_MIN () {\n" - + " var result = null;\n" - + " var value = arguments[0];\n" - + "\n" - + " AHUACATL_LIST(value);\n" - + "\n" - + " for (var i in value) {\n" - + " var currentValue = value[i];\n" - + " \n" - + " if (AHUACATL_TYPEWEIGHT(currentValue) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " continue;\n" - + " }\n" - + " \n" - + " if (result === null || AHUACATL_RELATIONAL_LESS(currentValue, result)) {\n" - + " result = currentValue;\n" - + " }\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief sum of all values\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_SUM () {\n" - + " var result = null;\n" - + " var value = arguments[0];\n" - + "\n" - + " AHUACATL_LIST(value);\n" - + "\n" - + " for (var i in value) {\n" - + " var currentValue = value[i];\n" - + " \n" - + " if (AHUACATL_TYPEWEIGHT(currentValue) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " continue;\n" - + " }\n" - + "\n" - + " if (AHUACATL_TYPEWEIGHT(currentValue) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"SUM\");\n" - + " }\n" - + " \n" - + " if (result === null) {\n" - + " result = currentValue;\n" - + " }\n" - + " else {\n" - + " result += currentValue;\n" - + " }\n" - + " }\n" - + "\n" - + " return AHUACATL_NUMERIC_VALUE(result);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- geo functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return at most documents near a certain point\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GEO_NEAR () {\n" - + " var collection = arguments[0];\n" - + " var latitude = arguments[1];\n" - + " var longitude = arguments[2];\n" - + " var limit = arguments[3];\n" - + " var distanceAttribute = arguments[4];\n" - + "\n" - + " var idx = AHUACATL_INDEX(internal.db[collection], [ \"geo1\", \"geo2\" ]); \n" - + " if (idx == null) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_GEO_INDEX_MISSING, collection);\n" - + " }\n" - + "\n" - + " var result = internal.db[collection].NEAR_NL(idx, latitude, longitude, limit);\n" - + " if (distanceAttribute == null) {\n" - + " return result.documents;\n" - + " }\n" - + "\n" - + " // inject distances\n" - + " var documents = result.documents;\n" - + " var distances = result.distances;\n" - + " var n = documents.length;\n" - + " for (var i = 0; i < n; ++i) {\n" - + " documents[i][distanceAttribute] = distances[i];\n" - + " }\n" - + "\n" - + " return documents;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return documents within around a certain point\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GEO_WITHIN () {\n" - + " var collection = arguments[0];\n" - + " var latitude = arguments[1];\n" - + " var longitude = arguments[2];\n" - + " var radius = arguments[3];\n" - + " var distanceAttribute = arguments[4];\n" - + "\n" - + " var idx = AHUACATL_INDEX(internal.db[collection], [ \"geo1\", \"geo2\" ]); \n" - + " if (idx == null) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_GEO_INDEX_MISSING, collection);\n" - + " }\n" - + "\n" - + " var result = internal.db[collection].WITHIN_NL(idx, latitude, longitude, radius);\n" - + " if (distanceAttribute == null) {\n" - + " return result.documents;\n" - + " }\n" - + "\n" - + " // inject distances\n" - + " var documents = result.documents;\n" - + " var distances = result.distances;\n" - + " var n = documents.length;\n" - + " for (var i = 0; i < n; ++i) {\n" - + " documents[i][distanceAttribute] = distances[i];\n" - + " }\n" - + "\n" - + " return documents;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- graph functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief find all paths through a graph\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GRAPH_PATHS () {\n" - + " var vertices = arguments[0];\n" - + " var edgeCollection = arguments[1];\n" - + " var direction = arguments[2] != undefined ? arguments[2] : \"outbound\";\n" - + " var followCycles = arguments[3] ? arguments[3] : false;\n" - + "\n" - + " var minLength = 0;\n" - + " var maxLength = 10;\n" - + " var searchDirection;\n" - + "\n" - + " AHUACATL_LIST(vertices);\n" - + "\n" - + " // validate arguments\n" - + " if (direction == \"outbound\") {\n" - + " searchDirection = 1;\n" - + " }\n" - + " else if (direction == \"inbound\") {\n" - + " searchDirection = 2;\n" - + " }\n" - + " else if (direction == \"any\") {\n" - + " searchDirection = 3;\n" - + " maxLength = 3;\n" - + " }\n" - + " else {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"PATHS\");\n" - + " }\n" - + "\n" - + " if (minLength < 0 || maxLength < 0 || minLength > maxLength) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"PATHS\");\n" - + " }\n" - + "\n" - + " var searchAttributes = { \n" - + " \"edgeCollection\" : internal.db[edgeCollection],\n" - + " \"minLength\" : minLength, \n" - + " \"maxLength\" : maxLength, \n" - + " \"direction\" : searchDirection,\n" - + " \"followCycles\" : followCycles,\n" - + " };\n" - + "\n" - + " // TODO: restrict allEdges to edges with certain _from values etc.\n" - + "\n" - + " var result = [ ];\n" - + " var n = vertices.length;\n" - + " for (var i = 0; i < n; ++i) {\n" - + " var vertex = vertices[i];\n" - + " var visited = { };\n" - + " visited[vertex._id] = true;\n" - + " var connected = AHUACATL_GRAPH_SUBNODES(searchAttributes, vertex._id, visited, [ ], [ vertex ], 0);\n" - + " for (j = 0; j < connected.length; ++j) {\n" - + " result.push(connected[j]);\n" - + " }\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief find all paths through a graph, internal part called recursively\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_GRAPH_SUBNODES (searchAttributes, vertexId, visited, edges, vertices, level) {\n" - + " var result = [ ];\n" - + "\n" - + " if (level >= searchAttributes.minLength) {\n" - + " result.push({ \n" - + " \"vertices\" : vertices, \n" - + " \"edges\" : edges,\n" - + " \"source\" : vertices[0],\n" - + " \"destination\" : vertices[vertices.length - 1],\n" - + " });\n" - + " }\n" - + "\n" - + " if (level + 1 > searchAttributes.maxLength) {\n" - + " return result;\n" - + " }\n" - + "\n" - + " var subEdges;\n" - + "\n" - + " if (searchAttributes.direction == 1) {\n" - + " subEdges = searchAttributes.edgeCollection.outEdges(vertexId);\n" - + " }\n" - + " else if (searchAttributes.direction == 2) {\n" - + " subEdges = searchAttributes.edgeCollection.inEdges(vertexId);\n" - + " }\n" - + " else if (searchAttributes.direction == 3) {\n" - + " subEdges = searchAttributes.edgeCollection.edges(vertexId);\n" - + " }\n" - + "\n" - + " for (var i = 0; i < subEdges.length; ++i) {\n" - + " var subEdge = subEdges[i];\n" - + " var targets = [ ];\n" - + "\n" - + " if (searchAttributes.direction & 1) {\n" - + " targets.push(subEdge._to);\n" - + " }\n" - + " if (searchAttributes.direction & 2) {\n" - + " targets.push(subEdge._from);\n" - + " }\n" - + "\n" - + " for (var j = 0; j < targets.length; ++j) {\n" - + " var targetId = targets[j];\n" - + " \n" - + " if (!searchAttributes.followCycles) {\n" - + " if (visited[targetId]) {\n" - + " continue;\n" - + " }\n" - + " visited[targetId] = true;\n" - + " }\n" - + "\n" - + " var clonedEdges = AHUACATL_CLONE(edges);\n" - + " var clonedVertices = AHUACATL_CLONE(vertices);\n" - + " clonedEdges.push(subEdge);\n" - + " clonedVertices.push(internal.db._document_nl(targetId));\n" - + " \n" - + " var connected = AHUACATL_GRAPH_SUBNODES(searchAttributes, targetId, AHUACATL_CLONE(visited), clonedEdges, clonedVertices, level + 1);\n" - + " for (k = 0; k < connected.length; ++k) {\n" - + " result.push(connected[k]);\n" - + " }\n" - + "\n" - + " if (!searchAttributes.followCycles) {\n" - + " delete visited[targetId];\n" - + " }\n" - + " }\n" - + " }\n" - + "\n" - + " return result;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- misc functions\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup Ahuacatl\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief return value if it's not null, otherwise return alternative\n" - + "///\n" - + "/// the operands can have any type\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_NOT_NULL (value, alternative) {\n" - + " if (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " return alternative;\n" - + " }\n" - + "\n" - + " return value;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief check whether a document has an attribute\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_HAS () {\n" - + " var element = arguments[0];\n" - + " var name = arguments[1];\n" - + " \n" - + " if (AHUACATL_TYPEWEIGHT(element) === AHUACATL_TYPEWEIGHT_NULL) {\n" - + " return false;\n" - + " }\n" - + "\n" - + " if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_DOCUMENT) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"HAS\");\n" - + " }\n" - + "\n" - + " return element.hasOwnProperty(name);\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief merge all arguments\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_MERGE () {\n" - + " var result = { };\n" - + "\n" - + " for (var i in arguments) {\n" - + " var element = arguments[i];\n" - + "\n" - + " if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_DOCUMENT) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"MERGE\");\n" - + " }\n" - + "\n" - + " for (var k in element) {\n" - + " if (!element.hasOwnProperty(k)) {\n" - + " continue;\n" - + " }\n" - + "\n" - + " result[k] = element[k];\n" - + " }\n" - + " }\n" - + "\n" - + " return result; \n" - + "}\n" - + "\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief passthru the argument\n" - + "///\n" - + "/// this function is marked as non-deterministic so its argument withstands\n" - + "/// query optimisation. this function can be used for testing\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_PASSTHRU () {\n" - + " var value = arguments[0];\n" - + "\n" - + " return value;\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief always fail\n" - + "///\n" - + "/// this function is non-deterministic so it is not executed at query \n" - + "/// optimisation time. this function can be used for testing\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "function AHUACATL_FAIL () {\n" - + " var message = arguments[0];\n" - + "\n" - + " if (AHUACATL_TYPEWEIGHT(message) === AHUACATL_TYPEWEIGHT_STRING) {\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FAIL_CALLED, message);\n" - + " }\n" - + "\n" - + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FAIL_CALLED, \"\");\n" - + "}\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" -; +const char* JS_server_ahuacatl[] = { + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief Ahuacatl, internal query functions ", + "///", + "/// @file", + "///", + "/// DISCLAIMER", + "///", + "/// Copyright 2010-2012 triagens GmbH, Cologne, Germany", + "///", + "/// Licensed under the Apache License, Version 2.0 (the \"License\");", + "/// you may not use this file except in compliance with the License.", + "/// You may obtain a copy of the License at", + "///", + "/// http://www.apache.org/licenses/LICENSE-2.0", + "///", + "/// Unless required by applicable law or agreed to in writing, software", + "/// distributed under the License is distributed on an \"AS IS\" BASIS,", + "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "/// See the License for the specific language governing permissions and", + "/// limitations under the License.", + "///", + "/// Copyright holder is triAGENS GmbH, Cologne, Germany", + "///", + "/// @author Jan Steemann", + "/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany", + "////////////////////////////////////////////////////////////////////////////////", + "", + "var internal = require(\"internal\");", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief type weight used for sorting and comparing", + "////////////////////////////////////////////////////////////////////////////////", + "", + "var AHUACATL_TYPEWEIGHT_NULL = 0;", + "var AHUACATL_TYPEWEIGHT_BOOL = 1;", + "var AHUACATL_TYPEWEIGHT_NUMBER = 2;", + "var AHUACATL_TYPEWEIGHT_STRING = 4;", + "var AHUACATL_TYPEWEIGHT_LIST = 8;", + "var AHUACATL_TYPEWEIGHT_DOCUMENT = 16;", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- helper functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief throw a runtime exception", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_THROW (error, data) {", + " var err = new ArangoError", + "", + " err.errorNum = error.code;", + " if (data) {", + " err.errorMessage = error.message.replace(/%s/, data);", + " }", + " else {", + " err.errorMessage = error.message;", + " }", + "", + " throw err;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief find an index of a certain type for a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_INDEX (collection, indexTypes) {", + " var indexes = collection.getIndexesNL();", + "", + " for (var i = 0; i < indexes.length; ++i) {", + " var index = indexes[i];", + "", + " for (var j = 0; j < indexTypes.length; ++j) {", + " if (index.type == indexTypes[j]) {", + " return index.id;", + " }", + " }", + " }", + "", + " return null;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief normalize a value for comparison, sorting etc.", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_NORMALIZE (value) {", + " if (value === null || value === undefined) {", + " return null;", + " }", + " if (typeof(value) !== \"object\") {", + " return value;", + " }", + "", + " if (Array.isArray(value)) {", + " var result = [ ];", + " var length = value.length;", + " for (var i = 0; i < length; ++i) {", + " result.push(AHUACATL_NORMALIZE(value[i]));", + " }", + " ", + " return result;", + " } ", + " else {", + " var attributes = [ ];", + " for (var attribute in value) {", + " if (!value.hasOwnProperty(attribute)) {", + " continue;", + " }", + " attributes.push(attribute);", + " }", + " attributes.sort();", + "", + " var result = { };", + " var length = attributes.length;", + " for (var i = 0; i < length; ++i) {", + " result[attributes[i]] = AHUACATL_NORMALIZE(value[attributes[i]]);", + " }", + "", + " return result;", + " }", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief clone an object", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_CLONE (obj) {", + " if (obj == null) {", + " return obj;", + " }", + "", + " if (typeof(obj) != \"object\") {", + " return obj;", + " }", + "", + " if (Array.isArray(obj)) {", + " var copy = [];", + " var length = obj.length;", + " for (var i = 0; i < length; ++i) {", + " copy[i] = AHUACATL_CLONE(obj[i]);", + " }", + " return copy;", + " }", + "", + " if (obj instanceof Object) {", + " var copy = {};", + " for (var attr in obj) {", + " if (obj.hasOwnProperty(attr)) {", + " copy[attr] = AHUACATL_CLONE(obj[attr]);", + " }", + " }", + " return copy;", + " }", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief validate function call argument", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_ARG_CHECK (actualValue, expectedType, functionName) {", + " if (AHUACATL_TYPEWEIGHT(actualValue) !== expectedType) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, functionName);", + " }", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief call a function", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_FCALL (name, parameters) {", + " return name.apply(null, parameters);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return the numeric value or undefined if it is out of range", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_NUMERIC_VALUE (value) {", + " if (isNaN(value) || !isFinite(value)) {", + " return null;", + " }", + "", + " return value;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief fix a value for a comparison", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_FIX (value) {", + " if (value === undefined) {", + " return null;", + " }", + "", + " return value;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get the name for a type", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_TYPENAME (value) {", + " switch (value) {", + " case AHUCATL_TYPEWEIGHT_BOOL:", + " return 'boolean';", + " case AHUCATL_TYPEWEIGHT_NUMBER:", + " return 'number';", + " case AHUCATL_TYPEWEIGHT_STRING:", + " return 'string';", + " case AHUCATL_TYPEWEIGHT_LIST:", + " return 'list';", + " case AHUCATL_TYPEWEIGHT_DOCUMENT:", + " return 'document';", + " case AHUCATL_TYPEWEIGHT_NULL:", + " default:", + " return 'null';", + " }", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get the sort type of an operand", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_TYPEWEIGHT (value) {", + " if (value === undefined || value === null) {", + " return AHUACATL_TYPEWEIGHT_NULL;", + " }", + "", + " if (Array.isArray(value)) {", + " return AHUACATL_TYPEWEIGHT_LIST;", + " }", + "", + " switch (typeof(value)) {", + " case 'boolean':", + " return AHUACATL_TYPEWEIGHT_BOOL;", + " case 'number':", + " if (isNaN(value) || !isFinite(value)) {", + " // not a number => undefined", + " return AHUACATL_TYPEWEIGHT_NULL; ", + " }", + " return AHUACATL_TYPEWEIGHT_NUMBER;", + " case 'string':", + " return AHUACATL_TYPEWEIGHT_STRING;", + " case 'object':", + " return AHUACATL_TYPEWEIGHT_DOCUMENT;", + " }", + "", + " return AHUACATL_TYPEWEIGHT_NULL;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get the keys of an array or object in a comparable way", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_KEYS (value, doSort) {", + " var keys = [];", + " ", + " if (Array.isArray(value)) {", + " var n = value.length;", + " for (var j = 0; j < n; ++j) {", + " keys.push(j);", + " }", + " }", + " else {", + " for (var k in value) {", + " if (value.hasOwnProperty(k)) {", + " keys.push(k);", + " }", + " }", + "", + " if (doSort) {", + " // object keys need to be sorted by names", + " keys.sort();", + " }", + " }", + "", + " return keys;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get the keys of an array or object in a comparable way", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_KEYLIST (lhs, rhs) {", + " var keys = [];", + " ", + " if (Array.isArray(lhs)) {", + " // lhs & rhs are lists", + " var n;", + " if (lhs.length > rhs.length) {", + " n = lhs.length;", + " }", + " else {", + " n = rhs.length;", + " }", + " for (var j = 0; j < n; ++j) {", + " keys.push(j);", + " }", + " return keys;", + " }", + "", + " // lhs & rhs are arrays", + " var k;", + " for (k in lhs) {", + " keys.push(k);", + " }", + " for (k in rhs) {", + " if (lhs.hasOwnProperty(k)) {", + " continue;", + " }", + " keys.push(k);", + " }", + "", + " // object keys need to be sorted by names", + " keys.sort();", + "", + " return keys;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get an indexed value from an array or document (e.g. users[3])", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GET_INDEX (value, index) {", + " if (AHUACATL_TYPEWEIGHT(value) == AHUACATL_TYPEWEIGHT_NULL) {", + " return null;", + " }", + " ", + " if (AHUACATL_TYPEWEIGHT(value) != AHUACATL_TYPEWEIGHT_LIST &&", + " AHUACATL_TYPEWEIGHT(value) != AHUACATL_TYPEWEIGHT_DOCUMENT) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_LIST_EXPECTED);", + " }", + "", + " var result = value[index];", + "", + " if (AHUACATL_TYPEWEIGHT(result) === AHUACATL_TYPEWEIGHT_NULL) {", + " return null;", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get an attribute from a document (e.g. users.name)", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_DOCUMENT_MEMBER (value, attributeName) {", + " if (AHUACATL_TYPEWEIGHT(value) == AHUACATL_TYPEWEIGHT_NULL) {", + " return null;", + " }", + "", + " if (AHUACATL_TYPEWEIGHT(value) != AHUACATL_TYPEWEIGHT_DOCUMENT) {", + " return null;", + " }", + "", + " var result = value[attributeName];", + "", + " if (AHUACATL_TYPEWEIGHT(result) === AHUACATL_TYPEWEIGHT_NULL) {", + " return null;", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief assert that a value is a list, fail otherwise", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_LIST (value) {", + " if (AHUACATL_TYPEWEIGHT(value) !== AHUACATL_TYPEWEIGHT_LIST) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_LIST_EXPECTED);", + " }", + "", + " return value;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get all documents from the specified collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GET_DOCUMENTS (collection) {", + " return internal.db[collection].ALL_NL(0, null).documents;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get documents from the specified collection using the primary index", + "/// (single index value)", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GET_DOCUMENTS_PRIMARY (collection, idx, id) {", + " try {", + " return [ internal.db[collection].document_nl(id) ];", + " }", + " catch (e) {", + " return [ ];", + " }", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get documents from the specified collection using the primary index", + "/// (multiple index values)", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GET_DOCUMENTS_PRIMARY_LIST (collection, idx, values) {", + " var result = [ ];", + "", + " for (var i in values) {", + " var id = values[i];", + " try {", + " var d = internal.db[collection].document_nl(id);", + " result.push(d);", + " }", + " catch (e) {", + " }", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get documents from the specified collection using a hash index", + "/// (single index value)", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GET_DOCUMENTS_HASH (collection, idx, example) {", + " return internal.db[collection].BY_EXAMPLE_HASH_NL(idx, example).documents;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get documents from the specified collection using a hash index", + "/// (multiple index values)", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GET_DOCUMENTS_HASH_LIST (collection, idx, attribute, values) {", + " var result = [ ];", + "", + " for (var i in values) {", + " var value = values[i];", + " var example = { };", + "", + " example[attribute] = value;", + "", + " var documents = internal.db[collection].BY_EXAMPLE_HASH_NL(idx, example).documents;", + " for (var j in documents) {", + " result.push(documents[j]);", + " }", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get documents from the specified collection using a bitarray", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GET_DOCUMENTS_BITARRAY (collection, idx, example) {", + " return internal.db[collection].BY_CONDITION_BITARRAY(idx, example).documents;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get documents from the specified collection using a bitarray", + "/// (multiple index values) TODO: replace by 'IN index operator'", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GET_DOCUMENTS_BITARRAY_LIST (collection, idx, attribute, values) {", + " var result = [ ];", + "", + " for (var i in values) {", + " var value = values[i];", + " var example = { };", + "", + " example[attribute] = value;", + "", + " var documents = internal.db[collection].BY_EXAMPLE_BITARRAY(idx, example).documents;", + " for (var j in documents) {", + " result.push(documents[j]);", + " }", + " }", + "", + " return result;", + "}", + "", + "", + "", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get documents from the specified collection using a skiplist", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GET_DOCUMENTS_SKIPLIST (collection, idx, example) {", + " return internal.db[collection].BY_CONDITION_SKIPLIST_NL(idx, example).documents;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get documents from the specified collection using a skiplist", + "/// (multiple index values)", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GET_DOCUMENTS_SKIPLIST_LIST (collection, idx, attribute, values) {", + " var result = [ ];", + "", + " for (var i in values) {", + " var value = values[i];", + " var example = { };", + "", + " example[attribute] = value;", + "", + " var documents = internal.db[collection].BY_EXAMPLE_SKIPLIST_NL(idx, example).documents;", + " for (var j in documents) {", + " result.push(documents[j]);", + " }", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get names of all collections", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_COLLECTIONS () {", + " var collections = internal.db._collections();", + " var result = [ ];", + "", + " for (var i = 0; i < collections.length; ++i) {", + " result.push({ \"_id\" : collections[i]._id, \"name\" : collections[i].name() });", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- logical operations", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief execute ternary operator", + "///", + "/// the condition operand must be a boolean value, returns either the truepart", + "/// or the falsepart ", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_TERNARY_OPERATOR (condition, truePart, falsePart) {", + " if (AHUACATL_TYPEWEIGHT(condition) !== AHUACATL_TYPEWEIGHT_BOOL) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);", + " }", + "", + " if (condition) {", + " return truePart;", + " }", + " return falsePart;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform logical and", + "///", + "/// both operands must be boolean values, returns a boolean, uses short-circuit", + "/// evaluation", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_LOGICAL_AND (lhs, rhs) {", + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_BOOL ||", + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_BOOL) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);", + " }", + "", + " if (!lhs) {", + " return false;", + " }", + "", + " return rhs;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform logical or", + "///", + "/// both operands must be boolean values, returns a boolean, uses short-circuit", + "/// evaluation", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_LOGICAL_OR (lhs, rhs) {", + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_BOOL ||", + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_BOOL) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);", + " }", + " ", + " if (lhs) {", + " return true;", + " }", + "", + " return rhs;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform logical negation", + "///", + "/// the operand must be a boolean values, returns a boolean", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_LOGICAL_NOT (lhs) {", + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_BOOL) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);", + " }", + "", + " return !lhs;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- comparison operations", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform equality check ", + "///", + "/// returns true if the operands are equal, false otherwise", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_RELATIONAL_EQUAL (lhs, rhs) {", + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);", + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);", + "", + " if (leftWeight != rightWeight) {", + " return false;", + " }", + "", + " // lhs and rhs have the same type", + "", + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {", + " // arrays and objects", + " var keys = AHUACATL_KEYLIST(lhs, rhs);", + "", + " for (var i in keys) {", + " var key = keys[i];", + " var result = AHUACATL_RELATIONAL_EQUAL(lhs[key], rhs[key]);", + " if (result === false) {", + " return result;", + " }", + " }", + " return true;", + " }", + "", + " // primitive type", + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " lhs = null;", + " }", + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " rhs = null;", + " }", + "", + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {", + " return COMPARE_STRING(lhs, rhs) == 0;", + " }", + "", + " return (lhs === rhs);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform inequality check ", + "///", + "/// returns true if the operands are unequal, false otherwise", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_RELATIONAL_UNEQUAL (lhs, rhs) {", + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);", + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);", + " ", + " if (leftWeight != rightWeight) {", + " return true;", + " }", + "", + " // lhs and rhs have the same type", + "", + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {", + " // arrays and objects", + " var keys = AHUACATL_KEYLIST(lhs, rhs);", + "", + " for (var i in keys) {", + " var key = keys[i];", + " var result = AHUACATL_RELATIONAL_UNEQUAL(lhs[key], rhs[key]);", + " if (result === true) {", + " return result;", + " }", + " }", + "", + " return false;", + " }", + "", + " // primitive type", + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " lhs = null;", + " }", + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " rhs = null;", + " }", + "", + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {", + " return COMPARE_STRING(lhs, rhs) != 0;", + " }", + "", + " return (lhs !== rhs);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform greater than check (inner function)", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_RELATIONAL_GREATER_REC (lhs, rhs) {", + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);", + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);", + " ", + " if (leftWeight > rightWeight) {", + " return true;", + " }", + " if (leftWeight < rightWeight) {", + " return false;", + " }", + "", + " // lhs and rhs have the same type", + "", + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {", + " // arrays and objects", + " var keys = AHUACATL_KEYLIST(lhs, rhs);", + "", + " for (var i in keys) {", + " var key = keys[i];", + " var result = AHUACATL_RELATIONAL_GREATER_REC(lhs[key], rhs[key]);", + " if (result !== null) {", + " return result;", + " }", + " }", + " ", + " return null;", + " }", + "", + " // primitive type", + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " lhs = null;", + " }", + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " rhs = null;", + " }", + "", + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {", + " return COMPARE_STRING(lhs, rhs) > 0;", + " }", + "", + " if (lhs === rhs) {", + " return null;", + " }", + "", + " return (lhs > rhs);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform greater than check ", + "///", + "/// returns true if the left operand is greater than the right operand", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_RELATIONAL_GREATER (lhs, rhs) {", + " var result = AHUACATL_RELATIONAL_GREATER_REC(lhs, rhs);", + "", + " if (result === null) {", + " result = false;", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform greater equal check (inner function)", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_RELATIONAL_GREATEREQUAL_REC (lhs, rhs) {", + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);", + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);", + " ", + " if (leftWeight > rightWeight) {", + " return true;", + " }", + " if (leftWeight < rightWeight) {", + " return false;", + " }", + "", + " // lhs and rhs have the same type", + "", + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {", + " // arrays and objects", + " var keys = AHUACATL_KEYLIST(lhs, rhs);", + "", + " for (var i in keys) {", + " var key = keys[i];", + " var result = AHUACATL_RELATIONAL_GREATEREQUAL_REC(lhs[key], rhs[key]);", + " if (result !== null) {", + " return result;", + " }", + " }", + " ", + " return null;", + " }", + "", + " // primitive type", + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " lhs = null;", + " }", + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " rhs = null;", + " }", + "", + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {", + " return COMPARE_STRING(lhs, rhs) >= 0;", + " }", + "", + " if (lhs === rhs) {", + " return null;", + " }", + "", + " return (lhs >= rhs);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform greater equal check ", + "///", + "/// returns true if the left operand is greater or equal to the right operand", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_RELATIONAL_GREATEREQUAL (lhs, rhs) {", + " var result = AHUACATL_RELATIONAL_GREATEREQUAL_REC(lhs, rhs);", + "", + " if (result === null) {", + " result = true;", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform less than check (inner function)", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_RELATIONAL_LESS_REC (lhs, rhs) {", + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);", + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);", + " ", + " if (leftWeight < rightWeight) {", + " return true;", + " }", + " if (leftWeight > rightWeight) {", + " return false;", + " }", + "", + " // lhs and rhs have the same type", + "", + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {", + " // arrays and objects", + " var keys = AHUACATL_KEYLIST(lhs, rhs);", + "", + " for (var i in keys) {", + " var key = keys[i];", + " var result = AHUACATL_RELATIONAL_LESS_REC(lhs[key], rhs[key]);", + " if (result !== null) {", + " return result;", + " }", + " }", + " ", + " return null;", + " }", + "", + " // primitive type", + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " lhs = null;", + " }", + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " rhs = null;", + " }", + "", + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {", + " return COMPARE_STRING(lhs, rhs) < 0;", + " }", + "", + " if (lhs === rhs) {", + " return null;", + " }", + "", + " return (lhs < rhs);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform less than check ", + "///", + "/// returns true if the left operand is less than the right operand", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_RELATIONAL_LESS (lhs, rhs) {", + " var result = AHUACATL_RELATIONAL_LESS_REC(lhs, rhs);", + "", + " if (result === null) {", + " result = false;", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform less equal check (inner function)", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_RELATIONAL_LESSEQUAL_REC (lhs, rhs) {", + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);", + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);", + " ", + " if (leftWeight < rightWeight) {", + " return true;", + " }", + " if (leftWeight > rightWeight) {", + " return false;", + " }", + "", + " // lhs and rhs have the same type", + "", + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {", + " // arrays and objects", + " var keys = AHUACATL_KEYLIST(lhs, rhs);", + "", + " for (var i in keys) {", + " var key = keys[i];", + " var result = AHUACATL_RELATIONAL_LESSEQUAL_REC(lhs[key], rhs[key]);", + " if (result !== null) {", + " return result;", + " }", + " }", + "", + " return null;", + " }", + " ", + " // primitive type", + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " lhs = null;", + " }", + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " rhs = null;", + " }", + " ", + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {", + " return COMPARE_STRING(lhs, rhs) <= 0;", + " }", + " ", + " if (lhs === rhs) {", + " return null;", + " }", + "", + " return (lhs <= rhs);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform less equal check ", + "///", + "/// returns true if the left operand is less or equal to the right operand", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_RELATIONAL_LESSEQUAL (lhs, rhs) {", + " var result = AHUACATL_RELATIONAL_LESSEQUAL_REC(lhs, rhs);", + "", + " if (result === null) {", + " result = true;", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform comparison", + "///", + "/// returns -1 if the left operand is less than the right operand, 1 if it is", + "/// greater, 0 if both operands are equal", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_RELATIONAL_CMP (lhs, rhs) {", + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);", + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);", + " ", + " if (leftWeight < rightWeight) {", + " return -1;", + " }", + " if (leftWeight > rightWeight) {", + " return 1;", + " }", + "", + " // lhs and rhs have the same type", + "", + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {", + " // arrays and objects", + " var keys = AHUACATL_KEYLIST(lhs, rhs);", + "", + " for (var i in keys) {", + " var key = keys[i];", + " var result = AHUACATL_RELATIONAL_CMP(lhs[key], rhs[key]);", + " if (result !== 0) {", + " return result;", + " }", + " }", + " ", + " return 0;", + " }", + "", + " // primitive type", + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " lhs = null;", + " }", + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {", + " rhs = null;", + " }", + "", + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {", + " return COMPARE_STRING(lhs, rhs);", + " }", + "", + " if (lhs < rhs) {", + " return -1;", + " }", + " ", + " if (lhs > rhs) {", + " return 1;", + " }", + "", + " return 0;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform in list check ", + "///", + "/// returns true if the left operand is contained in the right operand", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_RELATIONAL_IN (lhs, rhs) {", + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);", + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);", + " ", + " if (rightWeight !== AHUACATL_TYPEWEIGHT_LIST) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_LIST_EXPECTED);", + " }", + "", + " var numRight = rhs.length;", + " for (var i = 0; i < numRight; ++i) {", + " if (AHUACATL_RELATIONAL_EQUAL(lhs, rhs[i])) {", + " return true;", + " }", + " }", + "", + " return false;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- arithmetic operations", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform unary plus operation", + "///", + "/// the operand must be numeric or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_UNARY_PLUS (value) {", + " if (AHUACATL_TYPEWEIGHT(value) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);", + " }", + "", + " var result = AHUACATL_NUMERIC_VALUE(value);", + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform unary minus operation", + "///", + "/// the operand must be numeric or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_UNARY_MINUS (value) {", + " if (AHUACATL_TYPEWEIGHT(value) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);", + " }", + "", + " var result = AHUACATL_NUMERIC_VALUE(-value);", + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform artithmetic plus", + "///", + "/// both operands must be numeric or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_ARITHMETIC_PLUS (lhs, rhs) { ", + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||", + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);", + " }", + "", + " var result = AHUACATL_NUMERIC_VALUE(lhs + rhs);", + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform artithmetic minus", + "///", + "/// both operands must be numeric or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_ARITHMETIC_MINUS (lhs, rhs) {", + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||", + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);", + " }", + "", + " var result = AHUACATL_NUMERIC_VALUE(lhs - rhs);", + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform artithmetic multiplication", + "///", + "/// both operands must be numeric or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_ARITHMETIC_TIMES (lhs, rhs) {", + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||", + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);", + " }", + "", + " var result = AHUACATL_NUMERIC_VALUE(lhs * rhs);", + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform artithmetic division", + "///", + "/// both operands must be numeric or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_ARITHMETIC_DIVIDE (lhs, rhs) {", + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||", + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);", + " }", + " ", + " if (rhs == 0) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_DIVISION_BY_ZERO);", + " }", + "", + " var result = AHUACATL_NUMERIC_VALUE(lhs / rhs);", + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform artithmetic modulus", + "///", + "/// both operands must be numeric or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_ARITHMETIC_MODULUS (lhs, rhs) {", + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||", + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);", + " }", + "", + " if (rhs == 0) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_DIVISION_BY_ZERO);", + " }", + "", + " var result = AHUACATL_NUMERIC_VALUE(lhs % rhs);", + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- string functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform string concatenation", + "///", + "/// all operands must be strings or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_STRING_CONCAT () {", + " var result = '';", + "", + " for (var i in arguments) {", + " var element = arguments[i];", + "", + " if (AHUACATL_TYPEWEIGHT(element) === AHUACATL_TYPEWEIGHT_NULL) {", + " continue;", + " }", + "", + " AHUACATL_ARG_CHECK(element, AHUACATL_TYPEWEIGHT_STRING, \"CONCAT\");", + "", + " result += element;", + " }", + "", + " return result; ", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief perform string concatenation using a separator character", + "///", + "/// all operands must be strings or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_STRING_CONCAT_SEPARATOR () {", + " var separator;", + " var found = false;", + " var result = '';", + "", + " for (var i in arguments) {", + " var element = arguments[i];", + "", + " if (i > 0 && AHUACATL_TYPEWEIGHT(element) === AHUACATL_TYPEWEIGHT_NULL) {", + " continue;", + " }", + " ", + " AHUACATL_ARG_CHECK(element, AHUACATL_TYPEWEIGHT_STRING, \"CONCAT_SEPARATOR\");", + "", + " if (i == 0) {", + " separator = element;", + " continue;", + " }", + " else if (found) {", + " result += separator;", + " }", + "", + " found = true;", + "", + " result += element;", + " }", + "", + " return result; ", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return the length of a string in characters (not bytes)", + "///", + "/// the input operand must be a string or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_STRING_LENGTH (value) {", + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"STRING_LENGTH\");", + "", + " return value.length;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief convert a string to lower case", + "///", + "/// the input operand must be a string or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_STRING_LOWER (value) {", + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"LOWER\");", + "", + " return value.toLowerCase();", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief convert a string to upper case", + "///", + "/// the input operand must be a string or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_STRING_UPPER (value) {", + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"UPPER\");", + "", + " return value.toUpperCase();", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return a substring of the string", + "///", + "/// the input operand must be a string or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_STRING_SUBSTRING (value, offset, count) {", + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"SUBSTRING\");", + " AHUACATL_ARG_CHECK(offset, AHUACATL_TYPEWEIGHT_NUMBER, \"SUBSTRING\");", + "", + " return value.substr(offset, count);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief searches a substring in a string", + "///", + "/// the two input operands must be strings or this function will fail", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_STRING_CONTAINS (value, search) {", + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"CONTAINS\");", + " AHUACATL_ARG_CHECK(search, AHUACATL_TYPEWEIGHT_STRING, \"CONTAINS\");", + "", + " if (search.length == 0) {", + " return false;", + " }", + "", + " return value.indexOf(search) != -1;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- typecast functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief cast to a bool", + "///", + "/// the operand can have any type, always returns a bool", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_CAST_BOOL (value) {", + " switch (AHUACATL_TYPEWEIGHT(value)) {", + " case AHUACATL_TYPEWEIGHT_NULL:", + " return false;", + " case AHUACATL_TYPEWEIGHT_BOOL:", + " return value;", + " case AHUACATL_TYPEWEIGHT_NUMBER:", + " return (value != 0);", + " case AHUACATL_TYPEWEIGHT_STRING: ", + " return (value !== '');", + " case AHUACATL_TYPEWEIGHT_LIST:", + " return (value.length > 0);", + " case AHUACATL_TYPEWEIGHT_DOCUMENT:", + " return (AHUACATL_KEYS(value, false).length > 0);", + " }", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief cast to a number", + "///", + "/// the operand can have any type, always returns a number", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_CAST_NUMBER (value) {", + " switch (AHUACATL_TYPEWEIGHT(value)) {", + " case AHUACATL_TYPEWEIGHT_NULL:", + " case AHUACATL_TYPEWEIGHT_LIST:", + " case AHUACATL_TYPEWEIGHT_DOCUMENT:", + " return 0.0;", + " case AHUACATL_TYPEWEIGHT_BOOL:", + " return (value ? 1 : 0);", + " case AHUACATL_TYPEWEIGHT_NUMBER:", + " return value;", + " case AHUACATL_TYPEWEIGHT_STRING:", + " var result = parseFloat(value);", + " return ((AHUACATL_TYPEWEIGHT(result) === AHUACATL_TYPEWEIGHT_NUMBER) ? result : 0);", + " }", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief cast to a string", + "///", + "/// the operand can have any type, always returns a string", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_CAST_STRING (value) {", + " switch (AHUACATL_TYPEWEIGHT(value)) {", + " case AHUACATL_TYPEWEIGHT_STRING:", + " return value;", + " case AHUACATL_TYPEWEIGHT_NULL:", + " return 'null';", + " case AHUACATL_TYPEWEIGHT_BOOL:", + " return (value ? 'true' : 'false');", + " case AHUACATL_TYPEWEIGHT_NUMBER:", + " case AHUACATL_TYPEWEIGHT_LIST:", + " case AHUACATL_TYPEWEIGHT_DOCUMENT:", + " return value.toString();", + " }", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- typecheck functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief test if value is of type null", + "///", + "/// returns a bool", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_IS_NULL (value) {", + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NULL);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief test if value is of type bool", + "///", + "/// returns a bool", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_IS_BOOL (value) {", + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_BOOL);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief test if value is of type number", + "///", + "/// returns a bool", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_IS_NUMBER (value) {", + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NUMBER);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief test if value is of type string", + "///", + "/// returns a bool", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_IS_STRING (value) {", + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_STRING);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief test if value is of type list", + "///", + "/// returns a bool", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_IS_LIST (value) {", + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_LIST);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief test if value is of type document", + "///", + "/// returns a bool", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_IS_DOCUMENT (value) {", + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_DOCUMENT);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- numeric functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief integer closest to value, not greater than value", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_NUMBER_FLOOR (value) {", + " if (!AHUACATL_IS_NUMBER(value)) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"FLOOR\");", + " }", + " ", + " return Math.floor(value);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief integer closest to value and not less than value", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_NUMBER_CEIL (value) {", + " if (!AHUACATL_IS_NUMBER(value)) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"CEIL\");", + " }", + " ", + " return Math.ceil(value);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief integer closest to value ", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_NUMBER_ROUND (value) {", + " if (!AHUACATL_IS_NUMBER(value)) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"ROUND\");", + " }", + " ", + " return Math.round(value);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief absolute value", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_NUMBER_ABS (value) {", + " if (!AHUACATL_IS_NUMBER(value)) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"ABS\");", + " }", + " ", + " return Math.abs(value);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief a random value between 0 and 1", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_NUMBER_RAND () {", + " return Math.random();", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- high level query functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief sort the results", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_SORT (value, sortFunction) {", + " AHUACATL_LIST(value);", + " ", + " var n = value.length;", + " if (n > 0) {", + " value.sort(sortFunction);", + " }", + "", + " return value;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief group the results", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GROUP (value, sortFunction, groupFunction, into) {", + " AHUACATL_LIST(value);", + "", + " var n = value.length;", + " if (n == 0) {", + " return [ ];", + " }", + "", + " AHUACATL_SORT(value, sortFunction);", + "", + " var result = [ ];", + " var currentGroup = undefined;", + " var oldGroup = undefined;", + " ", + " for (var i = 0; i < n; ++i) {", + " var row = value[i];", + " var groupValue = groupFunction(row);", + "", + " if (AHUACATL_RELATIONAL_UNEQUAL(oldGroup, groupValue)) {", + " oldGroup = AHUACATL_CLONE(groupValue);", + "", + " if (currentGroup) {", + " result.push(AHUACATL_CLONE(currentGroup));", + " }", + " ", + " currentGroup = groupValue;", + " if (into) {", + " currentGroup[into] = [ ];", + " }", + " }", + "", + " if (into) {", + " currentGroup[into].push(AHUACATL_CLONE(row));", + " }", + " }", + "", + " if (currentGroup) {", + " result.push(AHUACATL_CLONE(currentGroup));", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief limit the number of results", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_LIMIT (value, offset, count) {", + " AHUACATL_LIST(value);", + "", + " if (count < 0) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);", + " }", + "", + " return value.slice(offset, offset + count);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- list processing functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get the length of a list", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_LENGTH () {", + " var value = arguments[0];", + "", + " AHUACATL_LIST(value);", + "", + " return value.length;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get the first element of a list", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_FIRST () {", + " var value = arguments[0];", + "", + " AHUACATL_LIST(value);", + "", + " if (value.length == 0) {", + " return null;", + " }", + "", + " return value[0];", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief get the last element of a list", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_LAST () {", + " var value = arguments[0];", + "", + " AHUACATL_LIST(value);", + "", + " if (value.length == 0) {", + " return null;", + " }", + "", + " return value[value.length - 1];", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief reverse the elements in a list", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_REVERSE () {", + " var value = arguments[0];", + "", + " AHUACATL_LIST(value);", + "", + " return value.reverse();", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return a list of unique elements from the list", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_UNIQUE () {", + " var value = arguments[0];", + "", + " AHUACATL_LIST(value);", + "", + " var length = value.length;", + " var keys = { };", + " for (var i = 0; i < length; ++i) {", + " var normalized = AHUACATL_NORMALIZE(value[i]);", + " keys[JSON.stringify(normalized)] = normalized;", + " }", + "", + " var result = [];", + " for (var i in keys) {", + " result.push(keys[i]);", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief create the union (all) of all arguments", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_UNION () {", + " var result = [ ];", + "", + " for (var i in arguments) {", + " var element = arguments[i];", + "", + " if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_LIST) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"UNION\");", + " }", + "", + " for (var k in element) {", + " if (!element.hasOwnProperty(k)) {", + " continue;", + " }", + "", + " result.push(element[k]);", + " }", + " }", + "", + " return result; ", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief maximum of all values", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_MAX () {", + " var result = null;", + " var value = arguments[0];", + "", + " AHUACATL_LIST(value);", + "", + " for (var i in value) {", + " var currentValue = value[i];", + " ", + " if (AHUACATL_TYPEWEIGHT(currentValue) === AHUACATL_TYPEWEIGHT_NULL) {", + " continue;", + " }", + "", + " if (result === null || AHUACATL_RELATIONAL_GREATER(currentValue, result)) {", + " result = currentValue;", + " }", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief minimum of all values", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_MIN () {", + " var result = null;", + " var value = arguments[0];", + "", + " AHUACATL_LIST(value);", + "", + " for (var i in value) {", + " var currentValue = value[i];", + " ", + " if (AHUACATL_TYPEWEIGHT(currentValue) === AHUACATL_TYPEWEIGHT_NULL) {", + " continue;", + " }", + " ", + " if (result === null || AHUACATL_RELATIONAL_LESS(currentValue, result)) {", + " result = currentValue;", + " }", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief sum of all values", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_SUM () {", + " var result = null;", + " var value = arguments[0];", + "", + " AHUACATL_LIST(value);", + "", + " for (var i in value) {", + " var currentValue = value[i];", + " ", + " if (AHUACATL_TYPEWEIGHT(currentValue) === AHUACATL_TYPEWEIGHT_NULL) {", + " continue;", + " }", + "", + " if (AHUACATL_TYPEWEIGHT(currentValue) !== AHUACATL_TYPEWEIGHT_NUMBER) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"SUM\");", + " }", + " ", + " if (result === null) {", + " result = currentValue;", + " }", + " else {", + " result += currentValue;", + " }", + " }", + "", + " return AHUACATL_NUMERIC_VALUE(result);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- geo functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return at most documents near a certain point", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GEO_NEAR () {", + " var collection = arguments[0];", + " var latitude = arguments[1];", + " var longitude = arguments[2];", + " var limit = arguments[3];", + " var distanceAttribute = arguments[4];", + "", + " var idx = AHUACATL_INDEX(internal.db[collection], [ \"geo1\", \"geo2\" ]); ", + " if (idx == null) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_GEO_INDEX_MISSING, collection);", + " }", + "", + " var result = internal.db[collection].NEAR_NL(idx, latitude, longitude, limit);", + " if (distanceAttribute == null) {", + " return result.documents;", + " }", + "", + " // inject distances", + " var documents = result.documents;", + " var distances = result.distances;", + " var n = documents.length;", + " for (var i = 0; i < n; ++i) {", + " documents[i][distanceAttribute] = distances[i];", + " }", + "", + " return documents;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return documents within around a certain point", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GEO_WITHIN () {", + " var collection = arguments[0];", + " var latitude = arguments[1];", + " var longitude = arguments[2];", + " var radius = arguments[3];", + " var distanceAttribute = arguments[4];", + "", + " var idx = AHUACATL_INDEX(internal.db[collection], [ \"geo1\", \"geo2\" ]); ", + " if (idx == null) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_GEO_INDEX_MISSING, collection);", + " }", + "", + " var result = internal.db[collection].WITHIN_NL(idx, latitude, longitude, radius);", + " if (distanceAttribute == null) {", + " return result.documents;", + " }", + "", + " // inject distances", + " var documents = result.documents;", + " var distances = result.distances;", + " var n = documents.length;", + " for (var i = 0; i < n; ++i) {", + " documents[i][distanceAttribute] = distances[i];", + " }", + "", + " return documents;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- graph functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief find all paths through a graph", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GRAPH_PATHS () {", + " var vertices = arguments[0];", + " var edgeCollection = arguments[1];", + " var direction = arguments[2] != undefined ? arguments[2] : \"outbound\";", + " var followCycles = arguments[3] ? arguments[3] : false;", + "", + " var minLength = 0;", + " var maxLength = 10;", + " var searchDirection;", + "", + " AHUACATL_LIST(vertices);", + "", + " // validate arguments", + " if (direction == \"outbound\") {", + " searchDirection = 1;", + " }", + " else if (direction == \"inbound\") {", + " searchDirection = 2;", + " }", + " else if (direction == \"any\") {", + " searchDirection = 3;", + " maxLength = 3;", + " }", + " else {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"PATHS\");", + " }", + "", + " if (minLength < 0 || maxLength < 0 || minLength > maxLength) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"PATHS\");", + " }", + "", + " var searchAttributes = { ", + " \"edgeCollection\" : internal.db[edgeCollection],", + " \"minLength\" : minLength, ", + " \"maxLength\" : maxLength, ", + " \"direction\" : searchDirection,", + " \"followCycles\" : followCycles,", + " };", + "", + " // TODO: restrict allEdges to edges with certain _from values etc.", + "", + " var result = [ ];", + " var n = vertices.length;", + " for (var i = 0; i < n; ++i) {", + " var vertex = vertices[i];", + " var visited = { };", + " visited[vertex._id] = true;", + " var connected = AHUACATL_GRAPH_SUBNODES(searchAttributes, vertex._id, visited, [ ], [ vertex ], 0);", + " for (j = 0; j < connected.length; ++j) {", + " result.push(connected[j]);", + " }", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief find all paths through a graph, internal part called recursively", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_GRAPH_SUBNODES (searchAttributes, vertexId, visited, edges, vertices, level) {", + " var result = [ ];", + "", + " if (level >= searchAttributes.minLength) {", + " result.push({ ", + " \"vertices\" : vertices, ", + " \"edges\" : edges,", + " \"source\" : vertices[0],", + " \"destination\" : vertices[vertices.length - 1],", + " });", + " }", + "", + " if (level + 1 > searchAttributes.maxLength) {", + " return result;", + " }", + "", + " var subEdges;", + "", + " if (searchAttributes.direction == 1) {", + " subEdges = searchAttributes.edgeCollection.outEdges(vertexId);", + " }", + " else if (searchAttributes.direction == 2) {", + " subEdges = searchAttributes.edgeCollection.inEdges(vertexId);", + " }", + " else if (searchAttributes.direction == 3) {", + " subEdges = searchAttributes.edgeCollection.edges(vertexId);", + " }", + "", + " for (var i = 0; i < subEdges.length; ++i) {", + " var subEdge = subEdges[i];", + " var targets = [ ];", + "", + " if (searchAttributes.direction & 1) {", + " targets.push(subEdge._to);", + " }", + " if (searchAttributes.direction & 2) {", + " targets.push(subEdge._from);", + " }", + "", + " for (var j = 0; j < targets.length; ++j) {", + " var targetId = targets[j];", + " ", + " if (!searchAttributes.followCycles) {", + " if (visited[targetId]) {", + " continue;", + " }", + " visited[targetId] = true;", + " }", + "", + " var clonedEdges = AHUACATL_CLONE(edges);", + " var clonedVertices = AHUACATL_CLONE(vertices);", + " clonedEdges.push(subEdge);", + " clonedVertices.push(internal.db._document_nl(targetId));", + " ", + " var connected = AHUACATL_GRAPH_SUBNODES(searchAttributes, targetId, AHUACATL_CLONE(visited), clonedEdges, clonedVertices, level + 1);", + " for (k = 0; k < connected.length; ++k) {", + " result.push(connected[k]);", + " }", + "", + " if (!searchAttributes.followCycles) {", + " delete visited[targetId];", + " }", + " }", + " }", + "", + " return result;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- misc functions", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup Ahuacatl", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief return value if it's not null, otherwise return alternative", + "///", + "/// the operands can have any type", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_NOT_NULL (value, alternative) {", + " if (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NULL) {", + " return alternative;", + " }", + "", + " return value;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief check whether a document has an attribute", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_HAS () {", + " var element = arguments[0];", + " var name = arguments[1];", + " ", + " if (AHUACATL_TYPEWEIGHT(element) === AHUACATL_TYPEWEIGHT_NULL) {", + " return false;", + " }", + "", + " if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_DOCUMENT) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"HAS\");", + " }", + "", + " return element.hasOwnProperty(name);", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief merge all arguments", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_MERGE () {", + " var result = { };", + "", + " for (var i in arguments) {", + " var element = arguments[i];", + "", + " if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_DOCUMENT) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"MERGE\");", + " }", + "", + " for (var k in element) {", + " if (!element.hasOwnProperty(k)) {", + " continue;", + " }", + "", + " result[k] = element[k];", + " }", + " }", + "", + " return result; ", + "}", + "", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief passthru the argument", + "///", + "/// this function is marked as non-deterministic so its argument withstands", + "/// query optimisation. this function can be used for testing", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_PASSTHRU () {", + " var value = arguments[0];", + "", + " return value;", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief always fail", + "///", + "/// this function is non-deterministic so it is not executed at query ", + "/// optimisation time. this function can be used for testing", + "////////////////////////////////////////////////////////////////////////////////", + "", + "function AHUACATL_FAIL () {", + " var message = arguments[0];", + "", + " if (AHUACATL_TYPEWEIGHT(message) === AHUACATL_TYPEWEIGHT_STRING) {", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FAIL_CALLED, message);", + " }", + "", + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FAIL_CALLED, \"\");", + "}", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "//__end__" +}; diff --git a/js/server/js-server.h b/js/server/js-server.h index 05b733978a..5336df6a8e 100644 --- a/js/server/js-server.h +++ b/js/server/js-server.h @@ -1,587 +1,588 @@ -static string JS_server_server = string("") - + "/*jslint indent: 2,\n" - + " nomen: true,\n" - + " maxlen: 100,\n" - + " sloppy: true,\n" - + " vars: true,\n" - + " white: true,\n" - + " plusplus: true */\n" - + "/*global require, db, edges, ModuleCache, Module,\n" - + " ArangoCollection, ArangoDatabase,\n" - + " ArangoError, ShapedJson,\n" - + " SYS_DEFINE_ACTION */\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief JavaScript server functions\n" - + "///\n" - + "/// @file\n" - + "///\n" - + "/// DISCLAIMER\n" - + "///\n" - + "/// Copyright 2011-2012 triagens GmbH, Cologne, Germany\n" - + "///\n" - + "/// Licensed under the Apache License, Version 2.0 (the \"License\");\n" - + "/// you may not use this file except in compliance with the License.\n" - + "/// You may obtain a copy of the License at\n" - + "///\n" - + "/// http://www.apache.org/licenses/LICENSE-2.0\n" - + "///\n" - + "/// Unless required by applicable law or agreed to in writing, software\n" - + "/// distributed under the License is distributed on an \"AS IS\" BASIS,\n" - + "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" - + "/// See the License for the specific language governing permissions and\n" - + "/// limitations under the License.\n" - + "///\n" - + "/// Copyright holder is triAGENS GmbH, Cologne, Germany\n" - + "///\n" - + "/// @author Dr. Frank Celler\n" - + "/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- Module \"internal\"\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8ModuleInternal\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief internal module\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "(function () {\n" - + " var internal = require(\"internal\");\n" - + " var console = require(\"console\");\n" - + "\n" - + " internal.db = db;\n" - + " internal.edges = db;\n" - + " internal.ArangoCollection = ArangoCollection;\n" - + "\n" - + " if (typeof SYS_DEFINE_ACTION === \"undefined\") {\n" - + " internal.defineAction = function() {\n" - + " console.error(\"SYS_DEFINE_ACTION not available\");\n" - + " };\n" - + " }\n" - + " else {\n" - + " internal.defineAction = SYS_DEFINE_ACTION;\n" - + " }\n" - + "\n" - + " if (typeof SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION === \"undefined\") {\n" - + " internal.executeGlobalContextFunction = function() {\n" - + " console.error(\"SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION not available\");\n" - + " };\n" - + " }\n" - + " else {\n" - + " internal.executeGlobalContextFunction = SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION;\n" - + " }\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- Module \"simple-query\"\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8ModuleSimpleQuery\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief simple-query module\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " try {\n" - + " require(\"simple-query\");\n" - + " }\n" - + " catch (err) {\n" - + " console.error(\"while loading 'simple-query' module: %s\", err);\n" - + " }\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- Module \"monkeypatches\"\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8ModuleMonkeypatches\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief monkeypatches module\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " try {\n" - + " require(\"monkeypatches\");\n" - + " }\n" - + " catch (err) {\n" - + " console.error(\"while loading 'monkeypatches' module: %s\", err);\n" - + " }\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- ShapedJson\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8Shell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief prints a shaped json\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ShapedJson.prototype._PRINT = function(seen, path, names, level) {\n" - + " if (this instanceof ShapedJson) {\n" - + " internal.printObject(this, seen, path, names, level);\n" - + " }\n" - + " else {\n" - + " internal.output(this.toString());\n" - + " }\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- ArangoError\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8Shell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief prints an error\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoError.prototype._PRINT = function() {\n" - + " var errorNum = this.errorNum;\n" - + " var errorMessage = this.errorMessage;\n" - + "\n" - + " internal.output(\"[ArangoError \", errorNum, \": \", errorMessage, \"]\");\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief converts error to string\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoError.prototype.toString = function() {\n" - + " var errorNum = this.errorNum;\n" - + " var errorMessage = this.errorMessage;\n" - + "\n" - + " return \"[ArangoError \" + errorNum + \": \" + errorMessage + \"]\";\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- ArangoDatabase\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8Shell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief drops a collection\n" - + "///\n" - + "/// @FUN{db._drop(@FA{collection})}\n" - + "///\n" - + "/// Drops a @FA{collection} and all its indexes.\n" - + "///\n" - + "/// @FUN{db._drop(@FA{collection-identifier})}\n" - + "///\n" - + "/// Drops a collection identified by @FA{collection-identifier} and all its\n" - + "/// indexes. No error is thrown if there is no such collection.\n" - + "///\n" - + "/// @FUN{db._drop(@FA{collection-name})}\n" - + "///\n" - + "/// Drops a collection named @FA{collection-name} and all its indexes. No error\n" - + "/// is thrown if there is no such collection.\n" - + "///\n" - + "/// @EXAMPLES\n" - + "///\n" - + "/// Drops a collection:\n" - + "///\n" - + "/// @verbinclude shell_collection-drop-db\n" - + "///\n" - + "/// Drops a collection identified by name:\n" - + "///\n" - + "/// @verbinclude shell_collection-drop-name-db\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._drop = function(name) {\n" - + " var collection = name;\n" - + "\n" - + " if (! (name instanceof ArangoCollection)) {\n" - + " collection = internal.db._collection(name);\n" - + " }\n" - + "\n" - + " if (collection === null) {\n" - + " return;\n" - + " }\n" - + "\n" - + " return collection.drop();\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief truncates a collection\n" - + "///\n" - + "/// @FUN{db._truncate(@FA{collection})}\n" - + "///\n" - + "/// Truncates a @FA{collection}, removing all documents but keeping all its\n" - + "/// indexes.\n" - + "///\n" - + "/// @FUN{db._truncate(@FA{collection-identifier})}\n" - + "///\n" - + "/// Truncates a collection identified by @FA{collection-identified}. No error is\n" - + "/// thrown if there is no such collection.\n" - + "///\n" - + "/// @FUN{db._truncate(@FA{collection-name})}\n" - + "///\n" - + "/// Truncates a collection named @FA{collection-name}. No error is thrown if\n" - + "/// there is no such collection.\n" - + "///\n" - + "/// @EXAMPLES\n" - + "///\n" - + "/// Truncates a collection:\n" - + "///\n" - + "/// @verbinclude shell_collection-truncate-db\n" - + "///\n" - + "/// Truncates a collection identified by name:\n" - + "///\n" - + "/// @verbinclude shell_collection-truncate-name-db\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._truncate = function(name) {\n" - + " var collection = name;\n" - + "\n" - + " if (! (name instanceof ArangoCollection)) {\n" - + " collection = internal.db._collection(name);\n" - + " }\n" - + "\n" - + " if (collection === null) {\n" - + " return;\n" - + " }\n" - + "\n" - + " collection.truncate();\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief finds an index\n" - + "///\n" - + "/// @FUN{db._index(@FA{index-handle})}\n" - + "///\n" - + "/// Returns the index with @FA{index-handle} or null if no such index exists.\n" - + "///\n" - + "/// @EXAMPLES\n" - + "///\n" - + "/// @verbinclude shell_index-read-db\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._index = function(id) {\n" - + " if (id.hasOwnProperty(\"id\")) {\n" - + " id = id.id;\n" - + " }\n" - + "\n" - + " var re = /^([0-9]+)\\/([0-9]+)/;\n" - + " var pa = re.exec(id);\n" - + " var err;\n" - + "\n" - + " if (pa === null) {\n" - + " err = new ArangoError();\n" - + " err.errorNum = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code;\n" - + " err.errorMessage = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message;\n" - + " throw err;\n" - + " }\n" - + "\n" - + " var col = this._collection(parseInt(pa[1]));\n" - + "\n" - + " if (col === null) {\n" - + " err = new ArangoError();\n" - + " err.errorNum = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code;\n" - + " err.errorMessage = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.message;\n" - + " throw err;\n" - + " }\n" - + "\n" - + " var indexes = col.getIndexes();\n" - + " var i;\n" - + "\n" - + " for (i = 0; i < indexes.length; ++i) {\n" - + " var index = indexes[i];\n" - + "\n" - + " if (index.id === id) {\n" - + " return index;\n" - + " }\n" - + " }\n" - + "\n" - + " return null;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief drops an index\n" - + "///\n" - + "/// @FUN{db._dropIndex(@FA{index})}\n" - + "///\n" - + "/// Drops the @FA{index}. If the index does not exists, then @LIT{false} is\n" - + "/// returned. If the index existed and was dropped, then @LIT{true} is\n" - + "/// returned. Note that you cannot drop the primary index.\n" - + "///\n" - + "/// @FUN{db._dropIndex(@FA{index-handle})}\n" - + "///\n" - + "/// Drops the index with @FA{index-handle}.\n" - + "///\n" - + "/// @EXAMPLES\n" - + "///\n" - + "/// @verbinclude shell_index-drop-index-db\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._dropIndex = function(id) {\n" - + " if (id.hasOwnProperty(\"id\")) {\n" - + " id = id.id;\n" - + " }\n" - + "\n" - + " var re = /^([0-9]+)\\/([0-9]+)/;\n" - + " var pa = re.exec(id);\n" - + " var err;\n" - + "\n" - + " if (pa === null) {\n" - + " err = new ArangoError();\n" - + " err.errorNum = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code;\n" - + " err.errorMessage = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message;\n" - + " throw err;\n" - + " }\n" - + "\n" - + " var col = this._collection(parseInt(pa[1]));\n" - + "\n" - + " if (col === null) {\n" - + " err = new ArangoError();\n" - + " err.errorNum = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code;\n" - + " err.errorMessage = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.message;\n" - + " throw err;\n" - + " }\n" - + "\n" - + " return col.dropIndex(id);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief prints a database\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype._PRINT = function(seen, path, names, level) {\n" - + " internal.output(\"[ArangoDatabase \\\"\" + this._path + \"\\\"]\");\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief strng representation of a database\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoDatabase.prototype.toString = function(seen, path, names, level) {\n" - + " return \"[ArangoDatabase \\\"\" + this._path + \"\\\"]\";\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- ArangoCollection\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @addtogroup V8Shell\n" - + "/// @{\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief collection is corrupted\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.STATUS_CORRUPTED = 0;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief collection is new born\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.STATUS_NEW_BORN = 1;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief collection is unloaded\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.STATUS_UNLOADED = 2;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief collection is loaded\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.STATUS_LOADED = 3;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief collection is unloading\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.STATUS_UNLOADING = 4;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief collection is deleted\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.STATUS_DELETED = 5;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief document collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + " \n" - + " ArangoCollection.TYPE_DOCUMENT = 2;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief edge collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.TYPE_EDGE = 3;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief attachment collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.TYPE_ATTACHMENT = 4;\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief converts collection into an array\n" - + "///\n" - + "/// @FUN{@FA{collection}.toArray()}\n" - + "///\n" - + "/// Converts the collection into an array of documents. Never use this call\n" - + "/// in a production environment.\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.toArray = function() {\n" - + " return this.ALL(null, null).documents;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief truncates a collection\n" - + "///\n" - + "/// @FUN{@FA{collection}.truncate()}\n" - + "///\n" - + "/// Truncates a @FA{collection}, removing all documents but keeping all its\n" - + "/// indexes.\n" - + "///\n" - + "/// @EXAMPLES\n" - + "///\n" - + "/// Truncates a collection:\n" - + "///\n" - + "/// @verbinclude shell_collection-truncate\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.truncate = function() {\n" - + " return internal.db._truncate(this);\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief finds an index of a collection\n" - + "///\n" - + "/// @FUN{@FA{collection}.index(@FA{index-handle})}\n" - + "///\n" - + "/// Returns the index with @FA{index-handle} or null if no such index exists.\n" - + "///\n" - + "/// @EXAMPLES\n" - + "///\n" - + "/// @verbinclude shell_index-read\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.index = function(id) {\n" - + " var indexes = this.getIndexes();\n" - + " var i;\n" - + "\n" - + " if (typeof id === \"string\") {\n" - + " var re = /^([0-9]+)\\/([0-9]+)/;\n" - + " var pa = re.exec(id);\n" - + "\n" - + " if (pa === null) {\n" - + " id = this._id + \"/\" + id;\n" - + " }\n" - + " }\n" - + " else if (id.hasOwnProperty(\"id\")) {\n" - + " id = id.id;\n" - + " }\n" - + "\n" - + " for (i = 0; i < indexes.length; ++i) {\n" - + " var index = indexes[i];\n" - + "\n" - + " if (index.id === id) {\n" - + " return index;\n" - + " }\n" - + " }\n" - + "\n" - + " return null;\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief prints a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype._PRINT = function() {\n" - + " var status = type = \"unknown\";\n" - + "\n" - + " switch (this.status()) {\n" - + " case ArangoCollection.STATUS_NEW_BORN: status = \"new born\"; break;\n" - + " case ArangoCollection.STATUS_UNLOADED: status = \"unloaded\"; break;\n" - + " case ArangoCollection.STATUS_UNLOADING: status = \"unloading\"; break;\n" - + " case ArangoCollection.STATUS_LOADED: status = \"loaded\"; break;\n" - + " case ArangoCollection.STATUS_CORRUPTED: status = \"corrupted\"; break;\n" - + " case ArangoCollection.STATUS_DELETED: status = \"deleted\"; break;\n" - + " }\n" - + "\n" - + " switch (this.type()) {\n" - + " case ArangoCollection.TYPE_DOCUMENT: type = \"document\"; break;\n" - + " case ArangoCollection.TYPE_EDGE: type = \"edge\"; break;\n" - + " case ArangoCollection.TYPE_ATTACHMENT: type = \"attachment\"; break;\n" - + " }\n" - + "\n" - + " internal.output(\"[ArangoCollection \",\n" - + " this._id, \n" - + " \", \\\"\", this.name(), \"\\\" (type \", type, \", status \", status, \")]\");\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @brief strng representation of a collection\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + " ArangoCollection.prototype.toString = function(seen, path, names, level) {\n" - + " return \"[ArangoCollection \" + this._id + \"]\";\n" - + " };\n" - + "\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "/// @}\n" - + "////////////////////////////////////////////////////////////////////////////////\n" - + "\n" - + "}());\n" - + "\n" - + "// -----------------------------------------------------------------------------\n" - + "// --SECTION-- END-OF-FILE\n" - + "// -----------------------------------------------------------------------------\n" - + "\n" - + "// Local Variables:\n" - + "// mode: outline-minor\n" - + "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @page\\\\|/// @\\\\}\\\\)\"\n" - + "// End:\n" -; +const char* JS_server_server[] = { + "/*jslint indent: 2,", + " nomen: true,", + " maxlen: 100,", + " sloppy: true,", + " vars: true,", + " white: true,", + " plusplus: true */", + "/*global require, db, edges, ModuleCache, Module,", + " ArangoCollection, ArangoDatabase,", + " ArangoError, ShapedJson,", + " SYS_DEFINE_ACTION */", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief JavaScript server functions", + "///", + "/// @file", + "///", + "/// DISCLAIMER", + "///", + "/// Copyright 2011-2012 triagens GmbH, Cologne, Germany", + "///", + "/// Licensed under the Apache License, Version 2.0 (the \"License\");", + "/// you may not use this file except in compliance with the License.", + "/// You may obtain a copy of the License at", + "///", + "/// http://www.apache.org/licenses/LICENSE-2.0", + "///", + "/// Unless required by applicable law or agreed to in writing, software", + "/// distributed under the License is distributed on an \"AS IS\" BASIS,", + "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "/// See the License for the specific language governing permissions and", + "/// limitations under the License.", + "///", + "/// Copyright holder is triAGENS GmbH, Cologne, Germany", + "///", + "/// @author Dr. Frank Celler", + "/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- Module \"internal\"", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8ModuleInternal", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief internal module", + "////////////////////////////////////////////////////////////////////////////////", + "", + "(function () {", + " var internal = require(\"internal\");", + " var console = require(\"console\");", + "", + " internal.db = db;", + " internal.edges = db;", + " internal.ArangoCollection = ArangoCollection;", + "", + " if (typeof SYS_DEFINE_ACTION === \"undefined\") {", + " internal.defineAction = function() {", + " console.error(\"SYS_DEFINE_ACTION not available\");", + " };", + " }", + " else {", + " internal.defineAction = SYS_DEFINE_ACTION;", + " }", + "", + " if (typeof SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION === \"undefined\") {", + " internal.executeGlobalContextFunction = function() {", + " console.error(\"SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION not available\");", + " };", + " }", + " else {", + " internal.executeGlobalContextFunction = SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION;", + " }", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- Module \"simple-query\"", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8ModuleSimpleQuery", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief simple-query module", + "////////////////////////////////////////////////////////////////////////////////", + "", + " try {", + " require(\"simple-query\");", + " }", + " catch (err) {", + " console.error(\"while loading 'simple-query' module: %s\", err);", + " }", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- Module \"monkeypatches\"", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8ModuleMonkeypatches", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief monkeypatches module", + "////////////////////////////////////////////////////////////////////////////////", + "", + " try {", + " require(\"monkeypatches\");", + " }", + " catch (err) {", + " console.error(\"while loading 'monkeypatches' module: %s\", err);", + " }", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- ShapedJson", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8Shell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief prints a shaped json", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ShapedJson.prototype._PRINT = function(seen, path, names, level) {", + " if (this instanceof ShapedJson) {", + " internal.printObject(this, seen, path, names, level);", + " }", + " else {", + " internal.output(this.toString());", + " }", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- ArangoError", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8Shell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief prints an error", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoError.prototype._PRINT = function() {", + " var errorNum = this.errorNum;", + " var errorMessage = this.errorMessage;", + "", + " internal.output(\"[ArangoError \", errorNum, \": \", errorMessage, \"]\");", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief converts error to string", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoError.prototype.toString = function() {", + " var errorNum = this.errorNum;", + " var errorMessage = this.errorMessage;", + "", + " return \"[ArangoError \" + errorNum + \": \" + errorMessage + \"]\";", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- ArangoDatabase", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8Shell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief drops a collection", + "///", + "/// @FUN{db._drop(@FA{collection})}", + "///", + "/// Drops a @FA{collection} and all its indexes.", + "///", + "/// @FUN{db._drop(@FA{collection-identifier})}", + "///", + "/// Drops a collection identified by @FA{collection-identifier} and all its", + "/// indexes. No error is thrown if there is no such collection.", + "///", + "/// @FUN{db._drop(@FA{collection-name})}", + "///", + "/// Drops a collection named @FA{collection-name} and all its indexes. No error", + "/// is thrown if there is no such collection.", + "///", + "/// @EXAMPLES", + "///", + "/// Drops a collection:", + "///", + "/// @verbinclude shell_collection-drop-db", + "///", + "/// Drops a collection identified by name:", + "///", + "/// @verbinclude shell_collection-drop-name-db", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._drop = function(name) {", + " var collection = name;", + "", + " if (! (name instanceof ArangoCollection)) {", + " collection = internal.db._collection(name);", + " }", + "", + " if (collection === null) {", + " return;", + " }", + "", + " return collection.drop();", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief truncates a collection", + "///", + "/// @FUN{db._truncate(@FA{collection})}", + "///", + "/// Truncates a @FA{collection}, removing all documents but keeping all its", + "/// indexes.", + "///", + "/// @FUN{db._truncate(@FA{collection-identifier})}", + "///", + "/// Truncates a collection identified by @FA{collection-identified}. No error is", + "/// thrown if there is no such collection.", + "///", + "/// @FUN{db._truncate(@FA{collection-name})}", + "///", + "/// Truncates a collection named @FA{collection-name}. No error is thrown if", + "/// there is no such collection.", + "///", + "/// @EXAMPLES", + "///", + "/// Truncates a collection:", + "///", + "/// @verbinclude shell_collection-truncate-db", + "///", + "/// Truncates a collection identified by name:", + "///", + "/// @verbinclude shell_collection-truncate-name-db", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._truncate = function(name) {", + " var collection = name;", + "", + " if (! (name instanceof ArangoCollection)) {", + " collection = internal.db._collection(name);", + " }", + "", + " if (collection === null) {", + " return;", + " }", + "", + " collection.truncate();", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief finds an index", + "///", + "/// @FUN{db._index(@FA{index-handle})}", + "///", + "/// Returns the index with @FA{index-handle} or null if no such index exists.", + "///", + "/// @EXAMPLES", + "///", + "/// @verbinclude shell_index-read-db", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._index = function(id) {", + " if (id.hasOwnProperty(\"id\")) {", + " id = id.id;", + " }", + "", + " var re = /^([0-9]+)\\/([0-9]+)/;", + " var pa = re.exec(id);", + " var err;", + "", + " if (pa === null) {", + " err = new ArangoError();", + " err.errorNum = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code;", + " err.errorMessage = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message;", + " throw err;", + " }", + "", + " var col = this._collection(parseInt(pa[1]));", + "", + " if (col === null) {", + " err = new ArangoError();", + " err.errorNum = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code;", + " err.errorMessage = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.message;", + " throw err;", + " }", + "", + " var indexes = col.getIndexes();", + " var i;", + "", + " for (i = 0; i < indexes.length; ++i) {", + " var index = indexes[i];", + "", + " if (index.id === id) {", + " return index;", + " }", + " }", + "", + " return null;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief drops an index", + "///", + "/// @FUN{db._dropIndex(@FA{index})}", + "///", + "/// Drops the @FA{index}. If the index does not exists, then @LIT{false} is", + "/// returned. If the index existed and was dropped, then @LIT{true} is", + "/// returned. Note that you cannot drop the primary index.", + "///", + "/// @FUN{db._dropIndex(@FA{index-handle})}", + "///", + "/// Drops the index with @FA{index-handle}.", + "///", + "/// @EXAMPLES", + "///", + "/// @verbinclude shell_index-drop-index-db", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._dropIndex = function(id) {", + " if (id.hasOwnProperty(\"id\")) {", + " id = id.id;", + " }", + "", + " var re = /^([0-9]+)\\/([0-9]+)/;", + " var pa = re.exec(id);", + " var err;", + "", + " if (pa === null) {", + " err = new ArangoError();", + " err.errorNum = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code;", + " err.errorMessage = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message;", + " throw err;", + " }", + "", + " var col = this._collection(parseInt(pa[1]));", + "", + " if (col === null) {", + " err = new ArangoError();", + " err.errorNum = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code;", + " err.errorMessage = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.message;", + " throw err;", + " }", + "", + " return col.dropIndex(id);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief prints a database", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype._PRINT = function(seen, path, names, level) {", + " internal.output(\"[ArangoDatabase \\\"\" + this._path + \"\\\"]\");", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief strng representation of a database", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoDatabase.prototype.toString = function(seen, path, names, level) {", + " return \"[ArangoDatabase \\\"\" + this._path + \"\\\"]\";", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- ArangoCollection", + "// -----------------------------------------------------------------------------", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @addtogroup V8Shell", + "/// @{", + "////////////////////////////////////////////////////////////////////////////////", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief collection is corrupted", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.STATUS_CORRUPTED = 0;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief collection is new born", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.STATUS_NEW_BORN = 1;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief collection is unloaded", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.STATUS_UNLOADED = 2;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief collection is loaded", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.STATUS_LOADED = 3;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief collection is unloading", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.STATUS_UNLOADING = 4;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief collection is deleted", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.STATUS_DELETED = 5;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief document collection", + "////////////////////////////////////////////////////////////////////////////////", + " ", + " ArangoCollection.TYPE_DOCUMENT = 2;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief edge collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.TYPE_EDGE = 3;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief attachment collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.TYPE_ATTACHMENT = 4;", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief converts collection into an array", + "///", + "/// @FUN{@FA{collection}.toArray()}", + "///", + "/// Converts the collection into an array of documents. Never use this call", + "/// in a production environment.", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.toArray = function() {", + " return this.ALL(null, null).documents;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief truncates a collection", + "///", + "/// @FUN{@FA{collection}.truncate()}", + "///", + "/// Truncates a @FA{collection}, removing all documents but keeping all its", + "/// indexes.", + "///", + "/// @EXAMPLES", + "///", + "/// Truncates a collection:", + "///", + "/// @verbinclude shell_collection-truncate", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.truncate = function() {", + " return internal.db._truncate(this);", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief finds an index of a collection", + "///", + "/// @FUN{@FA{collection}.index(@FA{index-handle})}", + "///", + "/// Returns the index with @FA{index-handle} or null if no such index exists.", + "///", + "/// @EXAMPLES", + "///", + "/// @verbinclude shell_index-read", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.index = function(id) {", + " var indexes = this.getIndexes();", + " var i;", + "", + " if (typeof id === \"string\") {", + " var re = /^([0-9]+)\\/([0-9]+)/;", + " var pa = re.exec(id);", + "", + " if (pa === null) {", + " id = this._id + \"/\" + id;", + " }", + " }", + " else if (id.hasOwnProperty(\"id\")) {", + " id = id.id;", + " }", + "", + " for (i = 0; i < indexes.length; ++i) {", + " var index = indexes[i];", + "", + " if (index.id === id) {", + " return index;", + " }", + " }", + "", + " return null;", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief prints a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.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(\"[ArangoCollection \",", + " this._id, ", + " \", \\\"\", this.name(), \"\\\" (type \", type, \", status \", status, \")]\");", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @brief strng representation of a collection", + "////////////////////////////////////////////////////////////////////////////////", + "", + " ArangoCollection.prototype.toString = function(seen, path, names, level) {", + " return \"[ArangoCollection \" + this._id + \"]\";", + " };", + "", + "////////////////////////////////////////////////////////////////////////////////", + "/// @}", + "////////////////////////////////////////////////////////////////////////////////", + "", + "}());", + "", + "// -----------------------------------------------------------------------------", + "// --SECTION-- END-OF-FILE", + "// -----------------------------------------------------------------------------", + "", + "// Local Variables:", + "// mode: outline-minor", + "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @page\\\\|/// @\\\\}\\\\)\"", + "// End:", + "//__end__" +}; diff --git a/lib/Utilities/ScriptLoader.cpp b/lib/Utilities/ScriptLoader.cpp index be0da973b6..d3613db53b 100644 --- a/lib/Utilities/ScriptLoader.cpp +++ b/lib/Utilities/ScriptLoader.cpp @@ -97,6 +97,23 @@ void ScriptLoader::defineScript (string const& name, string const& script) { _scripts[name] = script; } +void ScriptLoader::defineScript (const string& name, const char** script) { + string scriptString; + + MUTEX_LOCKER(_lock); + + while (true) { + string tempStr = string(*script); + if (tempStr == "//__end__") { + break; + } + scriptString += tempStr + "\n"; + ++script; + } + + _scripts[name] = scriptString; +} + //////////////////////////////////////////////////////////////////////////////// /// @brief finds a named script //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/Utilities/ScriptLoader.h b/lib/Utilities/ScriptLoader.h index 4389df281f..071e07011f 100644 --- a/lib/Utilities/ScriptLoader.h +++ b/lib/Utilities/ScriptLoader.h @@ -103,6 +103,8 @@ namespace triagens { //////////////////////////////////////////////////////////////////////////////// void defineScript (string const& name, string const& script); + + void defineScript (const string& name, const char** script); //////////////////////////////////////////////////////////////////////////////// /// @brief finds a named script