diff --git a/Documentation/Books/Users/General-Graphs/Management.mdpp b/Documentation/Books/Users/General-Graphs/Management.mdpp index 10bbbec594..99af161789 100644 --- a/Documentation/Books/Users/General-Graphs/Management.mdpp +++ b/Documentation/Books/Users/General-Graphs/Management.mdpp @@ -20,11 +20,11 @@ The edge definitions for a graph is an Array containing arbitrary many directed !SUBSUBSECTION Undirected Relation -@startDocuBlock JSF_general_graph_undirectedRelationDefinition@startDocuBlock +@startDocuBlock JSF_general_graph_undirectedRelation !SUBSUBSECTION Directed Relation -@startDocuBlock JSF_general_graph_directedRelationDefinition +@startDocuBlock JSF_general_graph_directedRelation !SUBSECTION Orphan Collections @@ -58,8 +58,8 @@ Example Call: ```js > var graph = require("org/arangodb/graph"); > var edgeDefinitions = graph._edgeDefinitions(); -> graph._extendEdgeDefinitions(edgeDefinitions, graph._undirectedRelationDefinition("friend_of", ["Customer"])); -> graph._extendEdgeDefinitions(edgeDefinitions, graph._directedRelationDefinition("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"])); +> graph._extendEdgeDefinitions(edgeDefinitions, graph._undirectedRelation("friend_of", ["Customer"])); +> graph._extendEdgeDefinitions(edgeDefinitions, graph._directedRelation("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"])); > graph._create("myStore", edgeDefinitions); { _id: "_graphs/123", @@ -72,7 +72,7 @@ alternative call: ```js > var graph = require("org/arangodb/graph"); -> var edgeDefinitions = graph._edgeDefinitions(graph._undirectedRelationDefinition("friend_of", ["Customer"]), graph._directedRelationDefinition("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"])); +> var edgeDefinitions = graph._edgeDefinitions(graph._undirectedRelation("friend_of", ["Customer"]), graph._directedRelation("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"])); > graph._create("myStore", edgeDefinitions); { _id: "_graphs/123", diff --git a/Documentation/Books/Users/General-Graphs/Management.orig.mdpp b/Documentation/Books/Users/General-Graphs/Management.orig.mdpp index 667baa24f1..f41a68fe77 100644 --- a/Documentation/Books/Users/General-Graphs/Management.orig.mdpp +++ b/Documentation/Books/Users/General-Graphs/Management.orig.mdpp @@ -20,11 +20,11 @@ The edge definitions for a graph is an Array containing arbitrary many directed !SUBSUBSECTION Undirected Relation - + !SUBSUBSECTION Directed Relation - + !SUBSECTION Orphan Collections @@ -58,8 +58,8 @@ Example Call: ```js > var graph = require("org/arangodb/graph"); > var edgeDefinitions = graph._edgeDefinitions(); -> graph._extendEdgeDefinitions(edgeDefinitions, graph._undirectedRelationDefinition("friend_of", ["Customer"])); -> graph._extendEdgeDefinitions(edgeDefinitions, graph._directedRelationDefinition("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"])); +> graph._extendEdgeDefinitions(edgeDefinitions, graph._undirectedRelation("friend_of", ["Customer"])); +> graph._extendEdgeDefinitions(edgeDefinitions, graph._directedRelation("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"])); > graph._create("myStore", edgeDefinitions); { _id: "_graphs/123", @@ -72,7 +72,7 @@ alternative call: ```js > var graph = require("org/arangodb/graph"); -> var edgeDefinitions = graph._edgeDefinitions(graph._undirectedRelationDefinition("friend_of", ["Customer"]), graph._directedRelationDefinition("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"])); +> var edgeDefinitions = graph._edgeDefinitions(graph._undirectedRelation("friend_of", ["Customer"]), graph._directedRelation("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"])); > graph._create("myStore", edgeDefinitions); { _id: "_graphs/123", diff --git a/Documentation/Books/Users/General-Graphs/README.mdpp b/Documentation/Books/Users/General-Graphs/README.mdpp index 36c91fa1d1..9b060979c7 100644 --- a/Documentation/Books/Users/General-Graphs/README.mdpp +++ b/Documentation/Books/Users/General-Graphs/README.mdpp @@ -1,6 +1,6 @@ -!CHAPTER General Graphs +!CHAPTER Graphs -This chapter describes the multi-collection graph module. +This chapter describes the general-graph module. It allows you to define a graph that is spread across several edge and document collections. This allows you to structure your models in line with your domain and group them logically in collections and giving you the power to query them in the same graph queries. There is no need to include the referenced collections within the query, this module will handle it for you. @@ -8,7 +8,6 @@ There is no need to include the referenced collections within the query, this mo !SECTION First Steps with Graphs A Graph consists of *vertices* and *edges*. Edges are stored as documents in *edge -collections*. A vertex can be a document of a *document collection* or of an edge -collection (so edges can be used as vertices). Which collections are used within +collections*. In general a vertex is stored in a document collection. Which collections are used within a graph is defined via *edge definitions*. A graph can have an arbitrary number of edge definitions. diff --git a/Documentation/Books/Users/HttpTraversal/README.mdpp b/Documentation/Books/Users/HttpTraversal/README.mdpp index f1d33d8ed2..84253aa15e 100644 --- a/Documentation/Books/Users/HttpTraversal/README.mdpp +++ b/Documentation/Books/Users/HttpTraversal/README.mdpp @@ -16,2902 +16,4 @@ are offered. !SECTION Executing Traversals via HTTP -`POST /_api/traversal`*(executes a traversal)* - -!SUBSECTION Body parameters - -`body (string,required)` - -!SUBSECTION Description - -Starts a traversal starting from a given vertex and following. edges contained in a given edgeCollection. The request must contain the following attributes. - -* startVertex: id of the startVertex, e.g. "users/foo". -* edgeCollection: name of the collection that contains the edges. -* filter (optional, default is to include all nodes): body (JavaScript code) of custom filter function function signature: (config, vertex, path) -> mixed can return four different string values: -* "exclude" -> this vertex will not be visited. -* "prune" -> the edges of this vertex will not be followed. -* "" or undefined -> visit the vertex and follow it's edges. -* Array -> containing any combination of the above. If there is at least one "exclude" or "prune" respectivly is contained, it's effect will occur. -* minDepth (optional, ANDed with any existing filters): visits only nodes in at least the given depth -* maxDepth (optional, ANDed with any existing filters): visits only nodes in at most the given depth -* visitor (optional): body (JavaScript) code of custom visitor function function signature: (config, result, vertex, path) -> void visitor function can do anything, but its return value is ignored. To populate a result, use the result variable by reference -* direction (optional): direction for traversal -* if set, must be either "outbound", "inbound", or "any" -* if not set, the expander attribute must be specified -* init (optional): body (JavaScript) code of custom result initialisation function function signature: (config, result) -> void initialise any values in result with what is required -* expander (optional): body (JavaScript) code of custom expander function must be set if direction attribute is not set function signature: (config, vertex, path) -> array expander must return an array of the connections for vertex each connection is an object with the attributes edge and vertex -* sort (optional): body (JavaScript) code of a custom comparison function for the edges. The signature of this function is (l, r) -> integer (where l and r are edges) and must return -1 if l is smaller than, +1 if l is greater than, and 0 if l and r are equal. The reason for this is the following: The order of edges returned for a certain vertex is undefined. This is because there is no natural order of edges for a vertex with multiple connected edges. To explicitly define the order in which edges on the vertex are followed, you can specify an edge comparator function with this attribute. Note that the value here has to be a string to conform to the JSON standard, which in turn is parsed as function body on the server side. Furthermore note that this attribute is only used for the standard expanders. If you use your custom expander you have to do the sorting yourself within the expander code. -* strategy (optional): traversal strategy can be "depthfirst" or "breadthfirst" -* order (optional): traversal order can be "preorder" or "postorder" -* itemOrder (optional): item iteration order can be "forward" or "backward" -* uniqueness (optional): specifies uniqueness for vertices and edges visited if set, must be an object like this: "uniqueness": {"vertices": "none"|"global"|path", "edges": "none"|"global"|"path"} -* maxIterations (optional): Maximum number of iterations in each traversal. This number can be set to prevent endless loops in traversal of cyclic graphs. When a traversal performs as many iterations as the maxIterations value, the traversal will abort with an error. If maxIterations is not set, a server-defined value may be used. - -If the Traversal is successfully executed HTTP 200 will be returned. Additionally the result object will be returned by the traversal. - -For successful traversals, the returned JSON object has the following properties: - -* error: boolean flag to indicate if an error occurred (false in this case) -* code: the HTTP status code -* result: the return value of the traversal - -If the traversal specification is either missing or malformed, the server will respond with HTTP 400. - -The body of the response will then contain a JSON object with additional error details. The object has the following attributes: - -* error: boolean flag to indicate that an error occurred (true in this case) -* code: the HTTP status code -* errorNum: the server error number -* errorMessage: a descriptive error message - -!SUBSECTION Return codes - -`HTTP 200` - -If the traversal is fully executed HTTP 200 will be returned. - -`HTTP 400` - -If the traversal specification is either missing or malformed, the server will respond with HTTP 400. - -`HTTP 404` - -The server will responded with HTTP 404 if the specified edge collection does not exist, or the specified start vertex cannot be found. - -`HTTP 500` - -The server will responded with HTTP 500 when an error occurs inside the traversal or if a traversal performs more than maxIterations iterations. -Examples - -In the following examples the underlying graph will contain five persons Alice, Bob, Charlie, Dave and Eve. We will have the following directed relations: - -* Alice knows Bob -* Bob knows Charlie -* Bob knows Dave -* Eve knows Alice -* Eve knows Bob - -The starting vertex will always be Alice. - -Follow only outbound edges: - -``` -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{ "startVertex": "persons/218620897", "edgeCollection" : "knows", "direction" : "outbound"} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : { - "vertices" : [ - { - "_id" : "persons/218620897", - "_rev" : "218620897", - "_key" : "218620897", - "name" : "Alice" - }, - { - "_id" : "persons/218817505", - "_rev" : "218817505", - "_key" : "218817505", - "name" : "Bob" - }, - { - "_id" : "persons/219079649", - "_rev" : "219079649", - "_key" : "219079649", - "name" : "Charlie" - }, - { - "_id" : "persons/219276257", - "_rev" : "219276257", - "_key" : "219276257", - "name" : "Dave" - } - ], - "paths" : [ - { - "edges" : [ ], - "vertices" : [ - { - "_id" : "persons/218620897", - "_rev" : "218620897", - "_key" : "218620897", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/219800545", - "_rev" : "219800545", - "_key" : "219800545", - "_from" : "persons/218620897", - "_to" : "persons/218817505" - } - ], - "vertices" : [ - { - "_id" : "persons/218620897", - "_rev" : "218620897", - "_key" : "218620897", - "name" : "Alice" - }, - { - "_id" : "persons/218817505", - "_rev" : "218817505", - "_key" : "218817505", - "name" : "Bob" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/219800545", - "_rev" : "219800545", - "_key" : "219800545", - "_from" : "persons/218620897", - "_to" : "persons/218817505" - }, - { - "_id" : "knows/219997153", - "_rev" : "219997153", - "_key" : "219997153", - "_from" : "persons/218817505", - "_to" : "persons/219079649" - } - ], - "vertices" : [ - { - "_id" : "persons/218620897", - "_rev" : "218620897", - "_key" : "218620897", - "name" : "Alice" - }, - { - "_id" : "persons/218817505", - "_rev" : "218817505", - "_key" : "218817505", - "name" : "Bob" - }, - { - "_id" : "persons/219079649", - "_rev" : "219079649", - "_key" : "219079649", - "name" : "Charlie" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/219800545", - "_rev" : "219800545", - "_key" : "219800545", - "_from" : "persons/218620897", - "_to" : "persons/218817505" - }, - { - "_id" : "knows/220193761", - "_rev" : "220193761", - "_key" : "220193761", - "_from" : "persons/218817505", - "_to" : "persons/219276257" - } - ], - "vertices" : [ - { - "_id" : "persons/218620897", - "_rev" : "218620897", - "_key" : "218620897", - "name" : "Alice" - }, - { - "_id" : "persons/218817505", - "_rev" : "218817505", - "_key" : "218817505", - "name" : "Bob" - }, - { - "_id" : "persons/219276257", - "_rev" : "219276257", - "_key" : "219276257", - "name" : "Dave" - } - ] - } - ] - } - }, - "error" : false, - "code" : 200 -} -``` - -Follow only inbound edges: - -``` -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{ "startVertex": "persons/221635553", "edgeCollection" : "knows", "direction" : "inbound"} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : { - "vertices" : [ - { - "_id" : "persons/221635553", - "_rev" : "221635553", - "_key" : "221635553", - "name" : "Alice" - }, - { - "_id" : "persons/222487521", - "_rev" : "222487521", - "_key" : "222487521", - "name" : "Eve" - } - ], - "paths" : [ - { - "edges" : [ ], - "vertices" : [ - { - "_id" : "persons/221635553", - "_rev" : "221635553", - "_key" : "221635553", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/223405025", - "_rev" : "223405025", - "_key" : "223405025", - "_from" : "persons/222487521", - "_to" : "persons/221635553" - } - ], - "vertices" : [ - { - "_id" : "persons/221635553", - "_rev" : "221635553", - "_key" : "221635553", - "name" : "Alice" - }, - { - "_id" : "persons/222487521", - "_rev" : "222487521", - "_key" : "222487521", - "name" : "Eve" - } - ] - } - ] - } - }, - "error" : false, - "code" : 200 -} -``` - -Follow any direction of edges: - -``` -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{"startVertex":"persons/224388065","edgeCollection":"knows","direction":"any","uniqueness":{"vertices":"none","edges":"global"}} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : { - "vertices" : [ - { - "_id" : "persons/224388065", - "_rev" : "224388065", - "_key" : "224388065", - "name" : "Alice" - }, - { - "_id" : "persons/225240033", - "_rev" : "225240033", - "_key" : "225240033", - "name" : "Eve" - }, - { - "_id" : "persons/224584673", - "_rev" : "224584673", - "_key" : "224584673", - "name" : "Bob" - }, - { - "_id" : "persons/224388065", - "_rev" : "224388065", - "_key" : "224388065", - "name" : "Alice" - }, - { - "_id" : "persons/224846817", - "_rev" : "224846817", - "_key" : "224846817", - "name" : "Charlie" - }, - { - "_id" : "persons/225043425", - "_rev" : "225043425", - "_key" : "225043425", - "name" : "Dave" - } - ], - "paths" : [ - { - "edges" : [ ], - "vertices" : [ - { - "_id" : "persons/224388065", - "_rev" : "224388065", - "_key" : "224388065", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/226157537", - "_rev" : "226157537", - "_key" : "226157537", - "_from" : "persons/225240033", - "_to" : "persons/224388065" - } - ], - "vertices" : [ - { - "_id" : "persons/224388065", - "_rev" : "224388065", - "_key" : "224388065", - "name" : "Alice" - }, - { - "_id" : "persons/225240033", - "_rev" : "225240033", - "_key" : "225240033", - "name" : "Eve" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/226157537", - "_rev" : "226157537", - "_key" : "226157537", - "_from" : "persons/225240033", - "_to" : "persons/224388065" - }, - { - "_id" : "knows/226354145", - "_rev" : "226354145", - "_key" : "226354145", - "_from" : "persons/225240033", - "_to" : "persons/224584673" - } - ], - "vertices" : [ - { - "_id" : "persons/224388065", - "_rev" : "224388065", - "_key" : "224388065", - "name" : "Alice" - }, - { - "_id" : "persons/225240033", - "_rev" : "225240033", - "_key" : "225240033", - "name" : "Eve" - }, - { - "_id" : "persons/224584673", - "_rev" : "224584673", - "_key" : "224584673", - "name" : "Bob" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/226157537", - "_rev" : "226157537", - "_key" : "226157537", - "_from" : "persons/225240033", - "_to" : "persons/224388065" - }, - { - "_id" : "knows/226354145", - "_rev" : "226354145", - "_key" : "226354145", - "_from" : "persons/225240033", - "_to" : "persons/224584673" - }, - { - "_id" : "knows/225567713", - "_rev" : "225567713", - "_key" : "225567713", - "_from" : "persons/224388065", - "_to" : "persons/224584673" - } - ], - "vertices" : [ - { - "_id" : "persons/224388065", - "_rev" : "224388065", - "_key" : "224388065", - "name" : "Alice" - }, - { - "_id" : "persons/225240033", - "_rev" : "225240033", - "_key" : "225240033", - "name" : "Eve" - }, - { - "_id" : "persons/224584673", - "_rev" : "224584673", - "_key" : "224584673", - "name" : "Bob" - }, - { - "_id" : "persons/224388065", - "_rev" : "224388065", - "_key" : "224388065", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/226157537", - "_rev" : "226157537", - "_key" : "226157537", - "_from" : "persons/225240033", - "_to" : "persons/224388065" - }, - { - "_id" : "knows/226354145", - "_rev" : "226354145", - "_key" : "226354145", - "_from" : "persons/225240033", - "_to" : "persons/224584673" - }, - { - "_id" : "knows/225764321", - "_rev" : "225764321", - "_key" : "225764321", - "_from" : "persons/224584673", - "_to" : "persons/224846817" - } - ], - "vertices" : [ - { - "_id" : "persons/224388065", - "_rev" : "224388065", - "_key" : "224388065", - "name" : "Alice" - }, - { - "_id" : "persons/225240033", - "_rev" : "225240033", - "_key" : "225240033", - "name" : "Eve" - }, - { - "_id" : "persons/224584673", - "_rev" : "224584673", - "_key" : "224584673", - "name" : "Bob" - }, - { - "_id" : "persons/224846817", - "_rev" : "224846817", - "_key" : "224846817", - "name" : "Charlie" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/226157537", - "_rev" : "226157537", - "_key" : "226157537", - "_from" : "persons/225240033", - "_to" : "persons/224388065" - }, - { - "_id" : "knows/226354145", - "_rev" : "226354145", - "_key" : "226354145", - "_from" : "persons/225240033", - "_to" : "persons/224584673" - }, - { - "_id" : "knows/225960929", - "_rev" : "225960929", - "_key" : "225960929", - "_from" : "persons/224584673", - "_to" : "persons/225043425" - } - ], - "vertices" : [ - { - "_id" : "persons/224388065", - "_rev" : "224388065", - "_key" : "224388065", - "name" : "Alice" - }, - { - "_id" : "persons/225240033", - "_rev" : "225240033", - "_key" : "225240033", - "name" : "Eve" - }, - { - "_id" : "persons/224584673", - "_rev" : "224584673", - "_key" : "224584673", - "name" : "Bob" - }, - { - "_id" : "persons/225043425", - "_rev" : "225043425", - "_key" : "225043425", - "name" : "Dave" - } - ] - } - ] - } - }, - "error" : false, - "code" : 200 -} - -Excluding Charlie and Bob: - -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{ "startVertex": "persons/228123617", "edgeCollection" : "knows", "direction" : "outbound", "filter" : "if (vertex.name === \"Bob\" || vertex.name === \"Charlie\") {return \"exclude\";}return;"} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : { - "vertices" : [ - { - "_id" : "persons/228123617", - "_rev" : "228123617", - "_key" : "228123617", - "name" : "Alice" - }, - { - "_id" : "persons/228778977", - "_rev" : "228778977", - "_key" : "228778977", - "name" : "Dave" - } - ], - "paths" : [ - { - "edges" : [ ], - "vertices" : [ - { - "_id" : "persons/228123617", - "_rev" : "228123617", - "_key" : "228123617", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/229303265", - "_rev" : "229303265", - "_key" : "229303265", - "_from" : "persons/228123617", - "_to" : "persons/228320225" - }, - { - "_id" : "knows/229696481", - "_rev" : "229696481", - "_key" : "229696481", - "_from" : "persons/228320225", - "_to" : "persons/228778977" - } - ], - "vertices" : [ - { - "_id" : "persons/228123617", - "_rev" : "228123617", - "_key" : "228123617", - "name" : "Alice" - }, - { - "_id" : "persons/228320225", - "_rev" : "228320225", - "_key" : "228320225", - "name" : "Bob" - }, - { - "_id" : "persons/228778977", - "_rev" : "228778977", - "_key" : "228778977", - "name" : "Dave" - } - ] - } - ] - } - }, - "error" : false, - "code" : 200 -} - -Do not follow edges from Bob: - -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{ "startVertex": "persons/231138273", "edgeCollection" : "knows", "direction" : "outbound", "filter" : "if (vertex.name === \"Bob\") {return \"prune\";}return;"} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : { - "vertices" : [ - { - "_id" : "persons/231138273", - "_rev" : "231138273", - "_key" : "231138273", - "name" : "Alice" - }, - { - "_id" : "persons/231334881", - "_rev" : "231334881", - "_key" : "231334881", - "name" : "Bob" - } - ], - "paths" : [ - { - "edges" : [ ], - "vertices" : [ - { - "_id" : "persons/231138273", - "_rev" : "231138273", - "_key" : "231138273", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/232317921", - "_rev" : "232317921", - "_key" : "232317921", - "_from" : "persons/231138273", - "_to" : "persons/231334881" - } - ], - "vertices" : [ - { - "_id" : "persons/231138273", - "_rev" : "231138273", - "_key" : "231138273", - "name" : "Alice" - }, - { - "_id" : "persons/231334881", - "_rev" : "231334881", - "_key" : "231334881", - "name" : "Bob" - } - ] - } - ] - } - }, - "error" : false, - "code" : 200 -} - -Visit only nodes in a depth of at least 2: - -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{ "startVertex": "persons/233825249", "edgeCollection" : "knows", "direction" : "outbound", "minDepth" : 2} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : { - "vertices" : [ - { - "_id" : "persons/234284001", - "_rev" : "234284001", - "_key" : "234284001", - "name" : "Charlie" - }, - { - "_id" : "persons/234480609", - "_rev" : "234480609", - "_key" : "234480609", - "name" : "Dave" - } - ], - "paths" : [ - { - "edges" : [ - { - "_id" : "knows/235004897", - "_rev" : "235004897", - "_key" : "235004897", - "_from" : "persons/233825249", - "_to" : "persons/234021857" - }, - { - "_id" : "knows/235201505", - "_rev" : "235201505", - "_key" : "235201505", - "_from" : "persons/234021857", - "_to" : "persons/234284001" - } - ], - "vertices" : [ - { - "_id" : "persons/233825249", - "_rev" : "233825249", - "_key" : "233825249", - "name" : "Alice" - }, - { - "_id" : "persons/234021857", - "_rev" : "234021857", - "_key" : "234021857", - "name" : "Bob" - }, - { - "_id" : "persons/234284001", - "_rev" : "234284001", - "_key" : "234284001", - "name" : "Charlie" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/235004897", - "_rev" : "235004897", - "_key" : "235004897", - "_from" : "persons/233825249", - "_to" : "persons/234021857" - }, - { - "_id" : "knows/235398113", - "_rev" : "235398113", - "_key" : "235398113", - "_from" : "persons/234021857", - "_to" : "persons/234480609" - } - ], - "vertices" : [ - { - "_id" : "persons/233825249", - "_rev" : "233825249", - "_key" : "233825249", - "name" : "Alice" - }, - { - "_id" : "persons/234021857", - "_rev" : "234021857", - "_key" : "234021857", - "name" : "Bob" - }, - { - "_id" : "persons/234480609", - "_rev" : "234480609", - "_key" : "234480609", - "name" : "Dave" - } - ] - } - ] - } - }, - "error" : false, - "code" : 200 -} - -Visit only nodes in a depth of at most 1: - -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{ "startVertex": "persons/236839905", "edgeCollection" : "knows", "direction" : "outbound", "maxDepth" : 1} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : { - "vertices" : [ - { - "_id" : "persons/236839905", - "_rev" : "236839905", - "_key" : "236839905", - "name" : "Alice" - }, - { - "_id" : "persons/237036513", - "_rev" : "237036513", - "_key" : "237036513", - "name" : "Bob" - } - ], - "paths" : [ - { - "edges" : [ ], - "vertices" : [ - { - "_id" : "persons/236839905", - "_rev" : "236839905", - "_key" : "236839905", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/238019553", - "_rev" : "238019553", - "_key" : "238019553", - "_from" : "persons/236839905", - "_to" : "persons/237036513" - } - ], - "vertices" : [ - { - "_id" : "persons/236839905", - "_rev" : "236839905", - "_key" : "236839905", - "name" : "Alice" - }, - { - "_id" : "persons/237036513", - "_rev" : "237036513", - "_key" : "237036513", - "name" : "Bob" - } - ] - } - ] - } - }, - "error" : false, - "code" : 200 -} - -Count all visited nodes and return a list of nodes only: - -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{ "startVertex": "persons/239526881", "edgeCollection" : "knows", "direction" : "outbound", "init" : "result.visited = 0; result.myVertices = [ ];", "visitor" : "result.visited++; result.myVertices.push(vertex);"} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : 4, - "myVertices" : [ - { - "_id" : "persons/239526881", - "_rev" : "239526881", - "_key" : "239526881", - "name" : "Alice" - }, - { - "_id" : "persons/239723489", - "_rev" : "239723489", - "_key" : "239723489", - "name" : "Bob" - }, - { - "_id" : "persons/239985633", - "_rev" : "239985633", - "_key" : "239985633", - "name" : "Charlie" - }, - { - "_id" : "persons/240182241", - "_rev" : "240182241", - "_key" : "240182241", - "name" : "Dave" - } - ] - }, - "error" : false, - "code" : 200 -} - -Expand only inbound edges of Alice and outbound edges of Eve: - -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{"startVertex":"persons/242541537","edgeCollection":"knows","expander":"var connections = [ ];if (vertex.name === \"Alice\") {config.edgeCollection.inEdges(vertex).forEach(function (e) {connections.push({ vertex: require(\"internal\").db._document(e._from), edge: e});});}if (vertex.name === \"Eve\") {config.edgeCollection.outEdges(vertex).forEach(function (e) {connections.push({vertex: require(\"internal\").db._document(e._to), edge: e});});}return connections;"} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : { - "vertices" : [ - { - "_id" : "persons/242541537", - "_rev" : "242541537", - "_key" : "242541537", - "name" : "Alice" - }, - { - "_id" : "persons/243393505", - "_rev" : "243393505", - "_key" : "243393505", - "name" : "Eve" - }, - { - "_id" : "persons/242738145", - "_rev" : "242738145", - "_key" : "242738145", - "name" : "Bob" - } - ], - "paths" : [ - { - "edges" : [ ], - "vertices" : [ - { - "_id" : "persons/242541537", - "_rev" : "242541537", - "_key" : "242541537", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/244311009", - "_rev" : "244311009", - "_key" : "244311009", - "_from" : "persons/243393505", - "_to" : "persons/242541537" - } - ], - "vertices" : [ - { - "_id" : "persons/242541537", - "_rev" : "242541537", - "_key" : "242541537", - "name" : "Alice" - }, - { - "_id" : "persons/243393505", - "_rev" : "243393505", - "_key" : "243393505", - "name" : "Eve" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/244311009", - "_rev" : "244311009", - "_key" : "244311009", - "_from" : "persons/243393505", - "_to" : "persons/242541537" - }, - { - "_id" : "knows/244507617", - "_rev" : "244507617", - "_key" : "244507617", - "_from" : "persons/243393505", - "_to" : "persons/242738145" - } - ], - "vertices" : [ - { - "_id" : "persons/242541537", - "_rev" : "242541537", - "_key" : "242541537", - "name" : "Alice" - }, - { - "_id" : "persons/243393505", - "_rev" : "243393505", - "_key" : "243393505", - "name" : "Eve" - }, - { - "_id" : "persons/242738145", - "_rev" : "242738145", - "_key" : "242738145", - "name" : "Bob" - } - ] - } - ] - } - }, - "error" : false, - "code" : 200 -} - -Follow the depthfirst strategy: - -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{"startVertex":"persons/245425121","edgeCollection":"knows","direction":"any","strategy":"depthfirst"} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : { - "vertices" : [ - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/246277089", - "_rev" : "246277089", - "_key" : "246277089", - "name" : "Eve" - }, - { - "_id" : "persons/245621729", - "_rev" : "245621729", - "_key" : "245621729", - "name" : "Bob" - }, - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/245883873", - "_rev" : "245883873", - "_key" : "245883873", - "name" : "Charlie" - }, - { - "_id" : "persons/246080481", - "_rev" : "246080481", - "_key" : "246080481", - "name" : "Dave" - }, - { - "_id" : "persons/245621729", - "_rev" : "245621729", - "_key" : "245621729", - "name" : "Bob" - }, - { - "_id" : "persons/246277089", - "_rev" : "246277089", - "_key" : "246277089", - "name" : "Eve" - }, - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/245883873", - "_rev" : "245883873", - "_key" : "245883873", - "name" : "Charlie" - }, - { - "_id" : "persons/246080481", - "_rev" : "246080481", - "_key" : "246080481", - "name" : "Dave" - } - ], - "paths" : [ - { - "edges" : [ ], - "vertices" : [ - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/247194593", - "_rev" : "247194593", - "_key" : "247194593", - "_from" : "persons/246277089", - "_to" : "persons/245425121" - } - ], - "vertices" : [ - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/246277089", - "_rev" : "246277089", - "_key" : "246277089", - "name" : "Eve" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/247194593", - "_rev" : "247194593", - "_key" : "247194593", - "_from" : "persons/246277089", - "_to" : "persons/245425121" - }, - { - "_id" : "knows/247391201", - "_rev" : "247391201", - "_key" : "247391201", - "_from" : "persons/246277089", - "_to" : "persons/245621729" - } - ], - "vertices" : [ - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/246277089", - "_rev" : "246277089", - "_key" : "246277089", - "name" : "Eve" - }, - { - "_id" : "persons/245621729", - "_rev" : "245621729", - "_key" : "245621729", - "name" : "Bob" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/247194593", - "_rev" : "247194593", - "_key" : "247194593", - "_from" : "persons/246277089", - "_to" : "persons/245425121" - }, - { - "_id" : "knows/247391201", - "_rev" : "247391201", - "_key" : "247391201", - "_from" : "persons/246277089", - "_to" : "persons/245621729" - }, - { - "_id" : "knows/246604769", - "_rev" : "246604769", - "_key" : "246604769", - "_from" : "persons/245425121", - "_to" : "persons/245621729" - } - ], - "vertices" : [ - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/246277089", - "_rev" : "246277089", - "_key" : "246277089", - "name" : "Eve" - }, - { - "_id" : "persons/245621729", - "_rev" : "245621729", - "_key" : "245621729", - "name" : "Bob" - }, - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/247194593", - "_rev" : "247194593", - "_key" : "247194593", - "_from" : "persons/246277089", - "_to" : "persons/245425121" - }, - { - "_id" : "knows/247391201", - "_rev" : "247391201", - "_key" : "247391201", - "_from" : "persons/246277089", - "_to" : "persons/245621729" - }, - { - "_id" : "knows/246801377", - "_rev" : "246801377", - "_key" : "246801377", - "_from" : "persons/245621729", - "_to" : "persons/245883873" - } - ], - "vertices" : [ - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/246277089", - "_rev" : "246277089", - "_key" : "246277089", - "name" : "Eve" - }, - { - "_id" : "persons/245621729", - "_rev" : "245621729", - "_key" : "245621729", - "name" : "Bob" - }, - { - "_id" : "persons/245883873", - "_rev" : "245883873", - "_key" : "245883873", - "name" : "Charlie" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/247194593", - "_rev" : "247194593", - "_key" : "247194593", - "_from" : "persons/246277089", - "_to" : "persons/245425121" - }, - { - "_id" : "knows/247391201", - "_rev" : "247391201", - "_key" : "247391201", - "_from" : "persons/246277089", - "_to" : "persons/245621729" - }, - { - "_id" : "knows/246997985", - "_rev" : "246997985", - "_key" : "246997985", - "_from" : "persons/245621729", - "_to" : "persons/246080481" - } - ], - "vertices" : [ - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/246277089", - "_rev" : "246277089", - "_key" : "246277089", - "name" : "Eve" - }, - { - "_id" : "persons/245621729", - "_rev" : "245621729", - "_key" : "245621729", - "name" : "Bob" - }, - { - "_id" : "persons/246080481", - "_rev" : "246080481", - "_key" : "246080481", - "name" : "Dave" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/246604769", - "_rev" : "246604769", - "_key" : "246604769", - "_from" : "persons/245425121", - "_to" : "persons/245621729" - } - ], - "vertices" : [ - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/245621729", - "_rev" : "245621729", - "_key" : "245621729", - "name" : "Bob" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/246604769", - "_rev" : "246604769", - "_key" : "246604769", - "_from" : "persons/245425121", - "_to" : "persons/245621729" - }, - { - "_id" : "knows/247391201", - "_rev" : "247391201", - "_key" : "247391201", - "_from" : "persons/246277089", - "_to" : "persons/245621729" - } - ], - "vertices" : [ - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/245621729", - "_rev" : "245621729", - "_key" : "245621729", - "name" : "Bob" - }, - { - "_id" : "persons/246277089", - "_rev" : "246277089", - "_key" : "246277089", - "name" : "Eve" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/246604769", - "_rev" : "246604769", - "_key" : "246604769", - "_from" : "persons/245425121", - "_to" : "persons/245621729" - }, - { - "_id" : "knows/247391201", - "_rev" : "247391201", - "_key" : "247391201", - "_from" : "persons/246277089", - "_to" : "persons/245621729" - }, - { - "_id" : "knows/247194593", - "_rev" : "247194593", - "_key" : "247194593", - "_from" : "persons/246277089", - "_to" : "persons/245425121" - } - ], - "vertices" : [ - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/245621729", - "_rev" : "245621729", - "_key" : "245621729", - "name" : "Bob" - }, - { - "_id" : "persons/246277089", - "_rev" : "246277089", - "_key" : "246277089", - "name" : "Eve" - }, - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/246604769", - "_rev" : "246604769", - "_key" : "246604769", - "_from" : "persons/245425121", - "_to" : "persons/245621729" - }, - { - "_id" : "knows/246801377", - "_rev" : "246801377", - "_key" : "246801377", - "_from" : "persons/245621729", - "_to" : "persons/245883873" - } - ], - "vertices" : [ - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/245621729", - "_rev" : "245621729", - "_key" : "245621729", - "name" : "Bob" - }, - { - "_id" : "persons/245883873", - "_rev" : "245883873", - "_key" : "245883873", - "name" : "Charlie" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/246604769", - "_rev" : "246604769", - "_key" : "246604769", - "_from" : "persons/245425121", - "_to" : "persons/245621729" - }, - { - "_id" : "knows/246997985", - "_rev" : "246997985", - "_key" : "246997985", - "_from" : "persons/245621729", - "_to" : "persons/246080481" - } - ], - "vertices" : [ - { - "_id" : "persons/245425121", - "_rev" : "245425121", - "_key" : "245425121", - "name" : "Alice" - }, - { - "_id" : "persons/245621729", - "_rev" : "245621729", - "_key" : "245621729", - "name" : "Bob" - }, - { - "_id" : "persons/246080481", - "_rev" : "246080481", - "_key" : "246080481", - "name" : "Dave" - } - ] - } - ] - } - }, - "error" : false, - "code" : 200 -} - -Using postorder ordering: - -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{"startVertex":"persons/250143713","edgeCollection":"knows","direction":"any","order":"postorder"} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : { - "vertices" : [ - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - }, - { - "_id" : "persons/250602465", - "_rev" : "250602465", - "_key" : "250602465", - "name" : "Charlie" - }, - { - "_id" : "persons/250799073", - "_rev" : "250799073", - "_key" : "250799073", - "name" : "Dave" - }, - { - "_id" : "persons/250340321", - "_rev" : "250340321", - "_key" : "250340321", - "name" : "Bob" - }, - { - "_id" : "persons/250995681", - "_rev" : "250995681", - "_key" : "250995681", - "name" : "Eve" - }, - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - }, - { - "_id" : "persons/250995681", - "_rev" : "250995681", - "_key" : "250995681", - "name" : "Eve" - }, - { - "_id" : "persons/250602465", - "_rev" : "250602465", - "_key" : "250602465", - "name" : "Charlie" - }, - { - "_id" : "persons/250799073", - "_rev" : "250799073", - "_key" : "250799073", - "name" : "Dave" - }, - { - "_id" : "persons/250340321", - "_rev" : "250340321", - "_key" : "250340321", - "name" : "Bob" - }, - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - } - ], - "paths" : [ - { - "edges" : [ - { - "_id" : "knows/251913185", - "_rev" : "251913185", - "_key" : "251913185", - "_from" : "persons/250995681", - "_to" : "persons/250143713" - }, - { - "_id" : "knows/252109793", - "_rev" : "252109793", - "_key" : "252109793", - "_from" : "persons/250995681", - "_to" : "persons/250340321" - }, - { - "_id" : "knows/251323361", - "_rev" : "251323361", - "_key" : "251323361", - "_from" : "persons/250143713", - "_to" : "persons/250340321" - } - ], - "vertices" : [ - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - }, - { - "_id" : "persons/250995681", - "_rev" : "250995681", - "_key" : "250995681", - "name" : "Eve" - }, - { - "_id" : "persons/250340321", - "_rev" : "250340321", - "_key" : "250340321", - "name" : "Bob" - }, - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/251913185", - "_rev" : "251913185", - "_key" : "251913185", - "_from" : "persons/250995681", - "_to" : "persons/250143713" - }, - { - "_id" : "knows/252109793", - "_rev" : "252109793", - "_key" : "252109793", - "_from" : "persons/250995681", - "_to" : "persons/250340321" - }, - { - "_id" : "knows/251519969", - "_rev" : "251519969", - "_key" : "251519969", - "_from" : "persons/250340321", - "_to" : "persons/250602465" - } - ], - "vertices" : [ - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - }, - { - "_id" : "persons/250995681", - "_rev" : "250995681", - "_key" : "250995681", - "name" : "Eve" - }, - { - "_id" : "persons/250340321", - "_rev" : "250340321", - "_key" : "250340321", - "name" : "Bob" - }, - { - "_id" : "persons/250602465", - "_rev" : "250602465", - "_key" : "250602465", - "name" : "Charlie" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/251913185", - "_rev" : "251913185", - "_key" : "251913185", - "_from" : "persons/250995681", - "_to" : "persons/250143713" - }, - { - "_id" : "knows/252109793", - "_rev" : "252109793", - "_key" : "252109793", - "_from" : "persons/250995681", - "_to" : "persons/250340321" - }, - { - "_id" : "knows/251716577", - "_rev" : "251716577", - "_key" : "251716577", - "_from" : "persons/250340321", - "_to" : "persons/250799073" - } - ], - "vertices" : [ - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - }, - { - "_id" : "persons/250995681", - "_rev" : "250995681", - "_key" : "250995681", - "name" : "Eve" - }, - { - "_id" : "persons/250340321", - "_rev" : "250340321", - "_key" : "250340321", - "name" : "Bob" - }, - { - "_id" : "persons/250799073", - "_rev" : "250799073", - "_key" : "250799073", - "name" : "Dave" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/251913185", - "_rev" : "251913185", - "_key" : "251913185", - "_from" : "persons/250995681", - "_to" : "persons/250143713" - }, - { - "_id" : "knows/252109793", - "_rev" : "252109793", - "_key" : "252109793", - "_from" : "persons/250995681", - "_to" : "persons/250340321" - } - ], - "vertices" : [ - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - }, - { - "_id" : "persons/250995681", - "_rev" : "250995681", - "_key" : "250995681", - "name" : "Eve" - }, - { - "_id" : "persons/250340321", - "_rev" : "250340321", - "_key" : "250340321", - "name" : "Bob" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/251913185", - "_rev" : "251913185", - "_key" : "251913185", - "_from" : "persons/250995681", - "_to" : "persons/250143713" - } - ], - "vertices" : [ - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - }, - { - "_id" : "persons/250995681", - "_rev" : "250995681", - "_key" : "250995681", - "name" : "Eve" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/251323361", - "_rev" : "251323361", - "_key" : "251323361", - "_from" : "persons/250143713", - "_to" : "persons/250340321" - }, - { - "_id" : "knows/252109793", - "_rev" : "252109793", - "_key" : "252109793", - "_from" : "persons/250995681", - "_to" : "persons/250340321" - }, - { - "_id" : "knows/251913185", - "_rev" : "251913185", - "_key" : "251913185", - "_from" : "persons/250995681", - "_to" : "persons/250143713" - } - ], - "vertices" : [ - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - }, - { - "_id" : "persons/250340321", - "_rev" : "250340321", - "_key" : "250340321", - "name" : "Bob" - }, - { - "_id" : "persons/250995681", - "_rev" : "250995681", - "_key" : "250995681", - "name" : "Eve" - }, - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/251323361", - "_rev" : "251323361", - "_key" : "251323361", - "_from" : "persons/250143713", - "_to" : "persons/250340321" - }, - { - "_id" : "knows/252109793", - "_rev" : "252109793", - "_key" : "252109793", - "_from" : "persons/250995681", - "_to" : "persons/250340321" - } - ], - "vertices" : [ - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - }, - { - "_id" : "persons/250340321", - "_rev" : "250340321", - "_key" : "250340321", - "name" : "Bob" - }, - { - "_id" : "persons/250995681", - "_rev" : "250995681", - "_key" : "250995681", - "name" : "Eve" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/251323361", - "_rev" : "251323361", - "_key" : "251323361", - "_from" : "persons/250143713", - "_to" : "persons/250340321" - }, - { - "_id" : "knows/251519969", - "_rev" : "251519969", - "_key" : "251519969", - "_from" : "persons/250340321", - "_to" : "persons/250602465" - } - ], - "vertices" : [ - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - }, - { - "_id" : "persons/250340321", - "_rev" : "250340321", - "_key" : "250340321", - "name" : "Bob" - }, - { - "_id" : "persons/250602465", - "_rev" : "250602465", - "_key" : "250602465", - "name" : "Charlie" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/251323361", - "_rev" : "251323361", - "_key" : "251323361", - "_from" : "persons/250143713", - "_to" : "persons/250340321" - }, - { - "_id" : "knows/251716577", - "_rev" : "251716577", - "_key" : "251716577", - "_from" : "persons/250340321", - "_to" : "persons/250799073" - } - ], - "vertices" : [ - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - }, - { - "_id" : "persons/250340321", - "_rev" : "250340321", - "_key" : "250340321", - "name" : "Bob" - }, - { - "_id" : "persons/250799073", - "_rev" : "250799073", - "_key" : "250799073", - "name" : "Dave" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/251323361", - "_rev" : "251323361", - "_key" : "251323361", - "_from" : "persons/250143713", - "_to" : "persons/250340321" - } - ], - "vertices" : [ - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - }, - { - "_id" : "persons/250340321", - "_rev" : "250340321", - "_key" : "250340321", - "name" : "Bob" - } - ] - }, - { - "edges" : [ ], - "vertices" : [ - { - "_id" : "persons/250143713", - "_rev" : "250143713", - "_key" : "250143713", - "name" : "Alice" - } - ] - } - ] - } - }, - "error" : false, - "code" : 200 -} - -Using backward item-ordering: - -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{"startVertex":"persons/254862305","edgeCollection":"knows","direction":"any","itemOrder":"backward"} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : { - "vertices" : [ - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - }, - { - "_id" : "persons/255058913", - "_rev" : "255058913", - "_key" : "255058913", - "name" : "Bob" - }, - { - "_id" : "persons/255517665", - "_rev" : "255517665", - "_key" : "255517665", - "name" : "Dave" - }, - { - "_id" : "persons/255321057", - "_rev" : "255321057", - "_key" : "255321057", - "name" : "Charlie" - }, - { - "_id" : "persons/255714273", - "_rev" : "255714273", - "_key" : "255714273", - "name" : "Eve" - }, - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - }, - { - "_id" : "persons/255714273", - "_rev" : "255714273", - "_key" : "255714273", - "name" : "Eve" - }, - { - "_id" : "persons/255058913", - "_rev" : "255058913", - "_key" : "255058913", - "name" : "Bob" - }, - { - "_id" : "persons/255517665", - "_rev" : "255517665", - "_key" : "255517665", - "name" : "Dave" - }, - { - "_id" : "persons/255321057", - "_rev" : "255321057", - "_key" : "255321057", - "name" : "Charlie" - }, - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - } - ], - "paths" : [ - { - "edges" : [ ], - "vertices" : [ - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/256041953", - "_rev" : "256041953", - "_key" : "256041953", - "_from" : "persons/254862305", - "_to" : "persons/255058913" - } - ], - "vertices" : [ - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - }, - { - "_id" : "persons/255058913", - "_rev" : "255058913", - "_key" : "255058913", - "name" : "Bob" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/256041953", - "_rev" : "256041953", - "_key" : "256041953", - "_from" : "persons/254862305", - "_to" : "persons/255058913" - }, - { - "_id" : "knows/256435169", - "_rev" : "256435169", - "_key" : "256435169", - "_from" : "persons/255058913", - "_to" : "persons/255517665" - } - ], - "vertices" : [ - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - }, - { - "_id" : "persons/255058913", - "_rev" : "255058913", - "_key" : "255058913", - "name" : "Bob" - }, - { - "_id" : "persons/255517665", - "_rev" : "255517665", - "_key" : "255517665", - "name" : "Dave" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/256041953", - "_rev" : "256041953", - "_key" : "256041953", - "_from" : "persons/254862305", - "_to" : "persons/255058913" - }, - { - "_id" : "knows/256238561", - "_rev" : "256238561", - "_key" : "256238561", - "_from" : "persons/255058913", - "_to" : "persons/255321057" - } - ], - "vertices" : [ - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - }, - { - "_id" : "persons/255058913", - "_rev" : "255058913", - "_key" : "255058913", - "name" : "Bob" - }, - { - "_id" : "persons/255321057", - "_rev" : "255321057", - "_key" : "255321057", - "name" : "Charlie" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/256041953", - "_rev" : "256041953", - "_key" : "256041953", - "_from" : "persons/254862305", - "_to" : "persons/255058913" - }, - { - "_id" : "knows/256828385", - "_rev" : "256828385", - "_key" : "256828385", - "_from" : "persons/255714273", - "_to" : "persons/255058913" - } - ], - "vertices" : [ - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - }, - { - "_id" : "persons/255058913", - "_rev" : "255058913", - "_key" : "255058913", - "name" : "Bob" - }, - { - "_id" : "persons/255714273", - "_rev" : "255714273", - "_key" : "255714273", - "name" : "Eve" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/256041953", - "_rev" : "256041953", - "_key" : "256041953", - "_from" : "persons/254862305", - "_to" : "persons/255058913" - }, - { - "_id" : "knows/256828385", - "_rev" : "256828385", - "_key" : "256828385", - "_from" : "persons/255714273", - "_to" : "persons/255058913" - }, - { - "_id" : "knows/256631777", - "_rev" : "256631777", - "_key" : "256631777", - "_from" : "persons/255714273", - "_to" : "persons/254862305" - } - ], - "vertices" : [ - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - }, - { - "_id" : "persons/255058913", - "_rev" : "255058913", - "_key" : "255058913", - "name" : "Bob" - }, - { - "_id" : "persons/255714273", - "_rev" : "255714273", - "_key" : "255714273", - "name" : "Eve" - }, - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/256631777", - "_rev" : "256631777", - "_key" : "256631777", - "_from" : "persons/255714273", - "_to" : "persons/254862305" - } - ], - "vertices" : [ - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - }, - { - "_id" : "persons/255714273", - "_rev" : "255714273", - "_key" : "255714273", - "name" : "Eve" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/256631777", - "_rev" : "256631777", - "_key" : "256631777", - "_from" : "persons/255714273", - "_to" : "persons/254862305" - }, - { - "_id" : "knows/256828385", - "_rev" : "256828385", - "_key" : "256828385", - "_from" : "persons/255714273", - "_to" : "persons/255058913" - } - ], - "vertices" : [ - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - }, - { - "_id" : "persons/255714273", - "_rev" : "255714273", - "_key" : "255714273", - "name" : "Eve" - }, - { - "_id" : "persons/255058913", - "_rev" : "255058913", - "_key" : "255058913", - "name" : "Bob" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/256631777", - "_rev" : "256631777", - "_key" : "256631777", - "_from" : "persons/255714273", - "_to" : "persons/254862305" - }, - { - "_id" : "knows/256828385", - "_rev" : "256828385", - "_key" : "256828385", - "_from" : "persons/255714273", - "_to" : "persons/255058913" - }, - { - "_id" : "knows/256435169", - "_rev" : "256435169", - "_key" : "256435169", - "_from" : "persons/255058913", - "_to" : "persons/255517665" - } - ], - "vertices" : [ - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - }, - { - "_id" : "persons/255714273", - "_rev" : "255714273", - "_key" : "255714273", - "name" : "Eve" - }, - { - "_id" : "persons/255058913", - "_rev" : "255058913", - "_key" : "255058913", - "name" : "Bob" - }, - { - "_id" : "persons/255517665", - "_rev" : "255517665", - "_key" : "255517665", - "name" : "Dave" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/256631777", - "_rev" : "256631777", - "_key" : "256631777", - "_from" : "persons/255714273", - "_to" : "persons/254862305" - }, - { - "_id" : "knows/256828385", - "_rev" : "256828385", - "_key" : "256828385", - "_from" : "persons/255714273", - "_to" : "persons/255058913" - }, - { - "_id" : "knows/256238561", - "_rev" : "256238561", - "_key" : "256238561", - "_from" : "persons/255058913", - "_to" : "persons/255321057" - } - ], - "vertices" : [ - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - }, - { - "_id" : "persons/255714273", - "_rev" : "255714273", - "_key" : "255714273", - "name" : "Eve" - }, - { - "_id" : "persons/255058913", - "_rev" : "255058913", - "_key" : "255058913", - "name" : "Bob" - }, - { - "_id" : "persons/255321057", - "_rev" : "255321057", - "_key" : "255321057", - "name" : "Charlie" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/256631777", - "_rev" : "256631777", - "_key" : "256631777", - "_from" : "persons/255714273", - "_to" : "persons/254862305" - }, - { - "_id" : "knows/256828385", - "_rev" : "256828385", - "_key" : "256828385", - "_from" : "persons/255714273", - "_to" : "persons/255058913" - }, - { - "_id" : "knows/256041953", - "_rev" : "256041953", - "_key" : "256041953", - "_from" : "persons/254862305", - "_to" : "persons/255058913" - } - ], - "vertices" : [ - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - }, - { - "_id" : "persons/255714273", - "_rev" : "255714273", - "_key" : "255714273", - "name" : "Eve" - }, - { - "_id" : "persons/255058913", - "_rev" : "255058913", - "_key" : "255058913", - "name" : "Bob" - }, - { - "_id" : "persons/254862305", - "_rev" : "254862305", - "_key" : "254862305", - "name" : "Alice" - } - ] - } - ] - } - }, - "error" : false, - "code" : 200 -} - -Edges should only be included once globally, but nodes are included every time they are visited: - -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{"startVertex":"persons/259580897","edgeCollection":"knows","direction":"any","uniqueness":{"vertices":"none","edges":"global"}} - -HTTP/1.1 200 OK -content-type: application/json; charset=utf-8 - -{ - "result" : { - "visited" : { - "vertices" : [ - { - "_id" : "persons/259580897", - "_rev" : "259580897", - "_key" : "259580897", - "name" : "Alice" - }, - { - "_id" : "persons/260432865", - "_rev" : "260432865", - "_key" : "260432865", - "name" : "Eve" - }, - { - "_id" : "persons/259777505", - "_rev" : "259777505", - "_key" : "259777505", - "name" : "Bob" - }, - { - "_id" : "persons/259580897", - "_rev" : "259580897", - "_key" : "259580897", - "name" : "Alice" - }, - { - "_id" : "persons/260039649", - "_rev" : "260039649", - "_key" : "260039649", - "name" : "Charlie" - }, - { - "_id" : "persons/260236257", - "_rev" : "260236257", - "_key" : "260236257", - "name" : "Dave" - } - ], - "paths" : [ - { - "edges" : [ ], - "vertices" : [ - { - "_id" : "persons/259580897", - "_rev" : "259580897", - "_key" : "259580897", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/261350369", - "_rev" : "261350369", - "_key" : "261350369", - "_from" : "persons/260432865", - "_to" : "persons/259580897" - } - ], - "vertices" : [ - { - "_id" : "persons/259580897", - "_rev" : "259580897", - "_key" : "259580897", - "name" : "Alice" - }, - { - "_id" : "persons/260432865", - "_rev" : "260432865", - "_key" : "260432865", - "name" : "Eve" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/261350369", - "_rev" : "261350369", - "_key" : "261350369", - "_from" : "persons/260432865", - "_to" : "persons/259580897" - }, - { - "_id" : "knows/261546977", - "_rev" : "261546977", - "_key" : "261546977", - "_from" : "persons/260432865", - "_to" : "persons/259777505" - } - ], - "vertices" : [ - { - "_id" : "persons/259580897", - "_rev" : "259580897", - "_key" : "259580897", - "name" : "Alice" - }, - { - "_id" : "persons/260432865", - "_rev" : "260432865", - "_key" : "260432865", - "name" : "Eve" - }, - { - "_id" : "persons/259777505", - "_rev" : "259777505", - "_key" : "259777505", - "name" : "Bob" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/261350369", - "_rev" : "261350369", - "_key" : "261350369", - "_from" : "persons/260432865", - "_to" : "persons/259580897" - }, - { - "_id" : "knows/261546977", - "_rev" : "261546977", - "_key" : "261546977", - "_from" : "persons/260432865", - "_to" : "persons/259777505" - }, - { - "_id" : "knows/260760545", - "_rev" : "260760545", - "_key" : "260760545", - "_from" : "persons/259580897", - "_to" : "persons/259777505" - } - ], - "vertices" : [ - { - "_id" : "persons/259580897", - "_rev" : "259580897", - "_key" : "259580897", - "name" : "Alice" - }, - { - "_id" : "persons/260432865", - "_rev" : "260432865", - "_key" : "260432865", - "name" : "Eve" - }, - { - "_id" : "persons/259777505", - "_rev" : "259777505", - "_key" : "259777505", - "name" : "Bob" - }, - { - "_id" : "persons/259580897", - "_rev" : "259580897", - "_key" : "259580897", - "name" : "Alice" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/261350369", - "_rev" : "261350369", - "_key" : "261350369", - "_from" : "persons/260432865", - "_to" : "persons/259580897" - }, - { - "_id" : "knows/261546977", - "_rev" : "261546977", - "_key" : "261546977", - "_from" : "persons/260432865", - "_to" : "persons/259777505" - }, - { - "_id" : "knows/260957153", - "_rev" : "260957153", - "_key" : "260957153", - "_from" : "persons/259777505", - "_to" : "persons/260039649" - } - ], - "vertices" : [ - { - "_id" : "persons/259580897", - "_rev" : "259580897", - "_key" : "259580897", - "name" : "Alice" - }, - { - "_id" : "persons/260432865", - "_rev" : "260432865", - "_key" : "260432865", - "name" : "Eve" - }, - { - "_id" : "persons/259777505", - "_rev" : "259777505", - "_key" : "259777505", - "name" : "Bob" - }, - { - "_id" : "persons/260039649", - "_rev" : "260039649", - "_key" : "260039649", - "name" : "Charlie" - } - ] - }, - { - "edges" : [ - { - "_id" : "knows/261350369", - "_rev" : "261350369", - "_key" : "261350369", - "_from" : "persons/260432865", - "_to" : "persons/259580897" - }, - { - "_id" : "knows/261546977", - "_rev" : "261546977", - "_key" : "261546977", - "_from" : "persons/260432865", - "_to" : "persons/259777505" - }, - { - "_id" : "knows/261153761", - "_rev" : "261153761", - "_key" : "261153761", - "_from" : "persons/259777505", - "_to" : "persons/260236257" - } - ], - "vertices" : [ - { - "_id" : "persons/259580897", - "_rev" : "259580897", - "_key" : "259580897", - "name" : "Alice" - }, - { - "_id" : "persons/260432865", - "_rev" : "260432865", - "_key" : "260432865", - "name" : "Eve" - }, - { - "_id" : "persons/259777505", - "_rev" : "259777505", - "_key" : "259777505", - "name" : "Bob" - }, - { - "_id" : "persons/260236257", - "_rev" : "260236257", - "_key" : "260236257", - "name" : "Dave" - } - ] - } - ] - } - }, - "error" : false, - "code" : 200 -} - -``` -If the underlying graph is cyclic, maxIterations should be set: - -The underlying graph has two vertices Alice and Bob. With the directed edges: - -``` -Alice knows Bob _ Bob knows Alice -unix> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/traversal -{"startVertex":"persons/263316449","edgeCollection":"knows","direction":"any","uniqueness":{"vertices":"none","edges":"none"},"maxIterations":5} - -HTTP/1.1 500 Internal Error -content-type: application/json; charset=utf-8 - -{ - "error" : true, - "code" : 500, - "errorNum" : 1909, - "errorMessage" : "too many iterations" -} -``` - - - \ No newline at end of file +@startDocuBlock JSF_HTTP_API_TRAVERSAL diff --git a/Documentation/RefManual/JSModuleGeneralGraph.md b/Documentation/RefManual/JSModuleGeneralGraph.md index 34f0844183..a3d60efd9c 100644 --- a/Documentation/RefManual/JSModuleGeneralGraph.md +++ b/Documentation/RefManual/JSModuleGeneralGraph.md @@ -67,10 +67,10 @@ To add further edge definitions to the array one must call: #### Undirected Relation -@copydetails JSF_general_graph_undirectedRelationDefinition +@copydetails JSF_general_graph_undirectedRelation ```js -graph._undirectedRelationDefinition(relationName, vertexCollections); +graph._undirectedRelation(relationName, vertexCollections); ``` Define an undirected relation. @@ -80,7 +80,7 @@ Relations are allowed in both directions among all collections in *vertexCollect Example Call: ```js -> graph._undirectedRelationDefinition("eats", ["Human", "Animal"]); +> graph._undirectedRelation("eats", ["Human", "Animal"]); { collection: "eats", from: ["Human", "Animal"], @@ -91,7 +91,7 @@ Example Call: #### Directed Relation ```js -graph._directedRelationDefinition(relationName, fromVertexCollections, toVertexCollections); +graph._directedRelation(relationName, fromVertexCollections, toVertexCollections); ``` Define a directed relation. @@ -102,7 +102,7 @@ Relations are only allowed in the direction from any collection in *fromVertexCo Example Call: ```js -> graph._directedRelationDefinition("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]); +> graph._directedRelation("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]); { collection: "has_bought", from: ["Customer", "Company"], @@ -118,8 +118,8 @@ Example Call: ```js > var graph = require("org/arangodb/graph"); > var edgeDefinitions = graph._edgeDefinitions(); -> graph._extendEdgeDefinitions(edgeDefinitions, graph._undirectedRelationDefinition("friend_of", ["Customer"])); -> graph._extendEdgeDefinitions(edgeDefinitions, graph._directedRelationDefinition("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"])); +> graph._extendEdgeDefinitions(edgeDefinitions, graph._undirectedRelation("friend_of", ["Customer"])); +> graph._extendEdgeDefinitions(edgeDefinitions, graph._directedRelation("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"])); > graph._create("myStore", edgeDefinitions); { _id: "_graphs/123", @@ -132,7 +132,7 @@ alternative call: ```js > var graph = require("org/arangodb/graph"); -> var edgeDefinitions = graph._edgeDefinitions(graph._undirectedRelationDefinition("friend_of", ["Customer"]), graph._directedRelationDefinition("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"])); +> var edgeDefinitions = graph._edgeDefinitions(graph._undirectedRelation("friend_of", ["Customer"]), graph._directedRelation("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"])); > graph._create("myStore", edgeDefinitions); { _id: "_graphs/123", diff --git a/Installation/travisCI/script.sh b/Installation/travisCI/script.sh index 43b4209548..75138ecac5 100755 --- a/Installation/travisCI/script.sh +++ b/Installation/travisCI/script.sh @@ -23,7 +23,7 @@ make -j2 || exit 1 echo echo "$0: testing ArangoDB" -make unittests-shell-server unittests-shell-server-ahuacatl unittests-http-server SKIP_RANGES=1 || exit 1 +make jslint unittests-shell-server unittests-shell-server-ahuacatl unittests-http-server SKIP_RANGES=1 || exit 1 echo echo "$0: done" diff --git a/js/actions/api-traversal.js b/js/actions/api-traversal.js index 253e2efc97..9da6ceb036 100644 --- a/js/actions/api-traversal.js +++ b/js/actions/api-traversal.js @@ -68,6 +68,7 @@ function notFound (req, res, code, message) { //////////////////////////////////////////////////////////////////////////////// /// @brief execute a server-side traversal +/// @startDocuBlock JSF_HTTP_API_TRAVERSAL /// /// @RESTHEADER{POST /_api/traversal,executes a traversal} /// @@ -78,48 +79,48 @@ function notFound (req, res, code, message) { /// edges contained in a given edgeCollection. The request must /// contain the following attributes. /// -/// - `startVertex`: id of the startVertex, e.g. `"users/foo"`. +/// - *startVertex*: id of the startVertex, e.g. *"users/foo"*. /// -/// - `edgeCollection`: **Deprecated** name of the collection that contains the edges. +/// - *edgeCollection*: **Deprecated** name of the collection that contains the edges. /// -/// - `graphName`: name of the graph that contains the edges. +/// - *graphName*: name of the graph that contains the edges. /// -/// - `filter` (optional, default is to include all nodes): +/// - *filter* (optional, default is to include all nodes): /// body (JavaScript code) of custom filter function /// function signature: (config, vertex, path) -> mixed /// can return four different string values: -/// - `"exclude"` -> this vertex will not be visited. -/// - `"prune"` -> the edges of this vertex will not be followed. -/// - `""` or `undefined` -> visit the vertex and follow it's edges. -/// - `Array` -> containing any combination of the above. -/// If there is at least one `"exclude"` or `"prune"` respectivly +/// - *"exclude"* -> this vertex will not be visited. +/// - *"prune"* -> the edges of this vertex will not be followed. +/// - *""* or *undefined* -> visit the vertex and follow it's edges. +/// - *Array* -> containing any combination of the above. +/// If there is at least one *"exclude"* or *"prune"* respectivly /// is contained, it's effect will occur. /// -/// - `minDepth` (optional, ANDed with any existing filters): +/// - *minDepth* (optional, ANDed with any existing filters): /// visits only nodes in at least the given depth /// -/// - `maxDepth` (optional, ANDed with any existing filters): +/// - *maxDepth* (optional, ANDed with any existing filters): /// visits only nodes in at most the given depth /// -/// - `visitor` (optional): body (JavaScript) code of custom visitor function +/// - *visitor* (optional): body (JavaScript) code of custom visitor function /// function signature: (config, result, vertex, path) -> void /// visitor function can do anything, but its return value is ignored. To -/// populate a result, use the `result` variable by reference +/// populate a result, use the *result* variable by reference /// -/// - `direction` (optional): direction for traversal -/// - *if set*, must be either `"outbound"`, `"inbound"`, or `"any"` -/// - *if not set*, the `expander` attribute must be specified +/// - *direction* (optional): direction for traversal +/// - *if set*, must be either *"outbound"*, *"inbound"*, or *"any"* +/// - *if not set*, the *expander* attribute must be specified /// -/// - `init` (optional): body (JavaScript) code of custom result initialisation function +/// - *init* (optional): body (JavaScript) code of custom result initialisation function /// function signature: (config, result) -> void /// initialise any values in result with what is required /// -/// - `expander` (optional): body (JavaScript) code of custom expander function -/// *must* be set if `direction` attribute is *not* set +/// - *expander* (optional): body (JavaScript) code of custom expander function +/// *must* be set if *direction* attribute is **not** set /// function signature: (config, vertex, path) -> array -/// expander must return an array of the connections for `vertex` -/// each connection is an object with the attributes `edge` and `vertex` -/// - `sort` (optional): body (JavaScript) code of a custom comparison function +/// expander must return an array of the connections for *vertex* +/// each connection is an object with the attributes *edge* and *vertex* +/// - *sort* (optional): body (JavaScript) code of a custom comparison function /// for the edges. The signature of this function is /// (l, r) -> integer (where l and r are edges) and must /// return -1 if l is smaller than, +1 if l is greater than, @@ -136,80 +137,80 @@ function notFound (req, res, code, message) { /// expanders. If you use your custom expander you have to /// do the sorting yourself within the expander code. /// -/// - `strategy` (optional): traversal strategy -/// can be `"depthfirst"` or `"breadthfirst"` +/// - *strategy* (optional): traversal strategy +/// can be *"depthfirst"* or *"breadthfirst"* /// -/// - `order` (optional): traversal order -/// can be `"preorder"` or `"postorder"` +/// - *order* (optional): traversal order +/// can be *"preorder"* or *"postorder"* /// -/// - `itemOrder` (optional): item iteration order -/// can be `"forward"` or `"backward"` +/// - *itemOrder* (optional): item iteration order +/// can be *"forward"* or *"backward"* /// -/// - `uniqueness` (optional): specifies uniqueness for vertices and edges visited +/// - *uniqueness* (optional): specifies uniqueness for vertices and edges visited /// if set, must be an object like this: -/// `"uniqueness": {"vertices": "none"|"global"|path", "edges": "none"|"global"|"path"}` +/// *"uniqueness": {"vertices": "none"|"global"|path", "edges": "none"|"global"|"path"}* /// -/// - `maxIterations` (optional): Maximum number of iterations in each traversal. This number can be +/// - *maxIterations* (optional): Maximum number of iterations in each traversal. This number can be /// set to prevent endless loops in traversal of cyclic graphs. When a traversal performs -/// as many iterations as the `maxIterations` value, the traversal will abort with an -/// error. If `maxIterations` is not set, a server-defined value may be used. +/// as many iterations as the *maxIterations* value, the traversal will abort with an +/// error. If *maxIterations* is not set, a server-defined value may be used. /// /// -/// If the Traversal is successfully executed `HTTP 200` will be returned. -/// Additionally the `result` object will be returned by the traversal. +/// If the Traversal is successfully executed *HTTP 200* will be returned. +/// Additionally the *result* object will be returned by the traversal. /// /// For successful traversals, the returned JSON object has the /// following properties: /// -/// - `error`: boolean flag to indicate if an error occurred (`false` +/// - *error*: boolean flag to indicate if an error occurred (*false* /// in this case) /// -/// - `code`: the HTTP status code +/// - *code*: the HTTP status code /// -/// - `result`: the return value of the traversal +/// - *result*: the return value of the traversal /// /// If the traversal specification is either missing or malformed, the server -/// will respond with `HTTP 400`. +/// will respond with *HTTP 400*. /// /// The body of the response will then contain a JSON object with additional error /// details. The object has the following attributes: /// -/// - `error`: boolean flag to indicate that an error occurred (`true` in this case) +/// - *error*: boolean flag to indicate that an error occurred (*true* in this case) /// -/// - `code`: the HTTP status code +/// - *code*: the HTTP status code /// -/// - `errorNum`: the server error number +/// - *errorNum*: the server error number /// -/// - `errorMessage`: a descriptive error message +/// - *errorMessage*: a descriptive error message /// /// @RESTRETURNCODES /// /// @RESTRETURNCODE{200} /// If the traversal is fully executed -/// `HTTP 200` will be returned. +/// *HTTP 200* will be returned. /// /// @RESTRETURNCODE{400} /// If the traversal specification is either missing or malformed, the server -/// will respond with `HTTP 400`. +/// will respond with *HTTP 400*. /// /// @RESTRETURNCODE{404} -/// The server will responded with `HTTP 404` if the specified edge collection +/// The server will responded with *HTTP 404* if the specified edge collection /// does not exist, or the specified start vertex cannot be found. /// /// @RESTRETURNCODE{500} -/// The server will responded with `HTTP 500` when an error occurs inside the -/// traversal or if a traversal performs more than `maxIterations` iterations. +/// The server will responded with *HTTP 500* when an error occurs inside the +/// traversal or if a traversal performs more than *maxIterations* iterations. /// /// *Examples* /// /// In the following examples the underlying graph will contain five persons -/// `Alice`, `Bob`, `Charlie`, `Dave` and `Eve`. +/// *Alice*, *Bob*, *Charlie*, *Dave* and *Eve*. /// We will have the following directed relations: -/// - `Alice` knows `Bob` -/// - `Bob` knows `Charlie` -/// - `Bob` knows `Dave` -/// - `Eve` knows `Alice` -/// - `Eve` knows `Bob` +/// - *Alice* knows *Bob* +/// - *Bob* knows *Charlie* +/// - *Bob* knows *Dave* +/// - *Eve* knows *Alice* +/// - *Eve* knows *Bob* /// /// The starting vertex will always be Alice. /// @@ -273,7 +274,7 @@ function notFound (req, res, code, message) { /// examples.dropGraph("knows_graph"); /// @END_EXAMPLE_ARANGOSH_RUN /// -/// Excluding `Charlie` and `Bob`: +/// Excluding *Charlie* and *Bob*: /// /// @EXAMPLE_ARANGOSH_RUN{RestTraversalFilterExclude} /// var examples = require("org/arangodb/graph-examples/example-graph.js"); @@ -296,7 +297,7 @@ function notFound (req, res, code, message) { /// examples.dropGraph("knows_graph"); /// @END_EXAMPLE_ARANGOSH_RUN /// -/// Do not follow edges from `Bob`: +/// Do not follow edges from *Bob*: /// /// @EXAMPLE_ARANGOSH_RUN{RestTraversalFilterPrune} /// var examples = require("org/arangodb/graph-examples/example-graph.js"); @@ -376,7 +377,7 @@ function notFound (req, res, code, message) { /// examples.dropGraph("knows_graph"); /// @END_EXAMPLE_ARANGOSH_RUN /// -/// Expand only inbound edges of `Alice` and outbound edges of `Eve`: +/// Expand only inbound edges of *Alice* and outbound edges of *Eve*: /// /// @EXAMPLE_ARANGOSH_RUN{RestTraversalVisitorExpander} /// var examples = require("org/arangodb/graph-examples/example-graph.js"); @@ -413,7 +414,7 @@ function notFound (req, res, code, message) { /// examples.dropGraph("knows_graph"); /// @END_EXAMPLE_ARANGOSH_RUN /// -/// Follow the `depthfirst` strategy: +/// Follow the *depthfirst* strategy: /// /// @EXAMPLE_ARANGOSH_RUN{RestTraversalDepthFirst} /// var examples = require("org/arangodb/graph-examples/example-graph.js"); @@ -434,7 +435,7 @@ function notFound (req, res, code, message) { /// examples.dropGraph("knows_graph"); /// @END_EXAMPLE_ARANGOSH_RUN /// -/// Using `postorder` ordering: +/// Using *postorder* ordering: /// /// @EXAMPLE_ARANGOSH_RUN{RestTraversalPostorder} /// var examples = require("org/arangodb/graph-examples/example-graph.js"); @@ -455,7 +456,7 @@ function notFound (req, res, code, message) { /// examples.dropGraph("knows_graph"); /// @END_EXAMPLE_ARANGOSH_RUN /// -/// Using `backward` item-ordering: +/// Using *backward* item-ordering: /// /// @EXAMPLE_ARANGOSH_RUN{RestTraversalBackwardItemOrder} /// var examples = require("org/arangodb/graph-examples/example-graph.js"); @@ -501,12 +502,12 @@ function notFound (req, res, code, message) { /// examples.dropGraph("knows_graph"); /// @END_EXAMPLE_ARANGOSH_RUN /// -/// If the underlying graph is cyclic, `maxIterations` should be set: +/// If the underlying graph is cyclic, *maxIterations* should be set: /// -/// The underlying graph has two vertices `Alice` and `Bob`. +/// The underlying graph has two vertices *Alice* and *Bob*. /// With the directed edges: -/// - `Alice` knows `Bob` -/// _ `Bob` knows `Alice` +/// - *Alice* knows *Bob* +/// _ *Bob* knows *Alice* /// /// /// @EXAMPLE_ARANGOSH_RUN{RestTraversalMaxIterations} @@ -535,6 +536,8 @@ function notFound (req, res, code, message) { /// logJsonResponse(response); /// examples.dropGraph("knows_graph"); /// @END_EXAMPLE_ARANGOSH_RUN +/// +/// @endDocuBlock //////////////////////////////////////////////////////////////////////////////// function post_api_traversal(req, res) { diff --git a/js/apps/system/aardvark/frontend/js/modules/org/arangodb/general-graph.js b/js/apps/system/aardvark/frontend/js/modules/org/arangodb/general-graph.js index 190b4e7f06..3b74bfe7ea 100644 --- a/js/apps/system/aardvark/frontend/js/modules/org/arangodb/general-graph.js +++ b/js/apps/system/aardvark/frontend/js/modules/org/arangodb/general-graph.js @@ -1238,6 +1238,7 @@ AQLGenerator.prototype.count = function() { /// var examples = require("org/arangodb/graph-examples/example-graph.js"); /// var g = examples.loadGraph("social"); /// var query = g._vertices(); +/// while (query.hasNext()) {query.next();} /// @END_EXAMPLE_ARANGOSH_OUTPUT /// @endDocuBlock /// @@ -1299,9 +1300,9 @@ AQLGenerator.prototype.next = function() { // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @startDocuBlock JSF_general_graph_undirectedRelationDefinition +/// @startDocuBlock JSF_general_graph_undirectedRelation /// -/// `general-graph._undirectedRelationDefinition(relationName, vertexCollections)` +/// `general-graph._undirectedRelation(relationName, vertexCollections)` /// *Define an undirected relation.* /// /// Defines an undirected relation with the name *relationName* using the @@ -1315,24 +1316,24 @@ AQLGenerator.prototype.next = function() { /// /// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphUndirectedRelationDefinition1} /// var graph = require("org/arangodb/general-graph"); -/// graph._undirectedRelationDefinition("friend", "user"); +/// graph._undirectedRelation("friend", "user"); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// /// To define a relation between several vertex collections: /// /// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphUndirectedRelationDefinition2} /// var graph = require("org/arangodb/general-graph"); -/// graph._undirectedRelationDefinition("marriage", ["female", "male"]); +/// graph._undirectedRelation("marriage", ["female", "male"]); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// @endDocuBlock /// //////////////////////////////////////////////////////////////////////////////// -var _undirectedRelationDefinition = function (relationName, vertexCollections) { +var _undirectedRelation = function (relationName, vertexCollections) { if (arguments.length < 2) { - throw "method _undirectedRelationDefinition expects 2 arguments"; + throw "method _undirectedRelation expects 2 arguments"; } if (typeof relationName !== "string" || relationName === "") { @@ -1355,9 +1356,9 @@ var _undirectedRelationDefinition = function (relationName, vertexCollections) { /// Define an directed relation. //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -/// @startDocuBlock JSF_general_graph_directedRelationDefinition +/// @startDocuBlock JSF_general_graph_directedRelation /// -/// `general-graph._directedRelationDefinition(relationName, fromVertexCollections, toVertexCollections)` +/// `general-graph._directedRelation(relationName, fromVertexCollections, toVertexCollections)` /// *Define a directed relation.* /// /// The *relationName* defines the name of this relation and references to the underlying edge collection. @@ -1370,18 +1371,18 @@ var _undirectedRelationDefinition = function (relationName, vertexCollections) { /// /// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphDirectedRelationDefinition} /// var graph = require("org/arangodb/general-graph"); -/// graph._directedRelationDefinition("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]); +/// graph._directedRelation("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// @endDocuBlock /// //////////////////////////////////////////////////////////////////////////////// -var _directedRelationDefinition = function ( +var _directedRelation = function ( relationName, fromVertexCollections, toVertexCollections) { if (arguments.length < 3) { - throw "method _directedRelationDefinition expects 3 arguments"; + throw "method _directedRelation expects 3 arguments"; } if (typeof relationName !== "string" || relationName === "") { @@ -1428,8 +1429,28 @@ var _list = function() { return _.pluck(gdb.toArray(), "_key"); }; + + + //////////////////////////////////////////////////////////////////////////////// -/// @brief create a list of edge definitions +/// @startDocuBlock JSF_general_graph_edge_definitions +/// +/// The edge definitions for a graph is an array containing arbitrary many directed +/// and/or undirected relations as defined below. +/// The list of edge definitions of a graph can be managed by the graph module itself. +/// This function is the entry point for the management and will return the correct list. +/// +/// @EXAMPLES +/// +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphEdgeDefinitions} +/// var graph = require("org/arangodb/general-graph"); +/// directed_relation = graph._directedRelation("lives_in", "user", "city"); +/// undirected_relation = graph._directedRelation("knows", "user"); +/// edgedefinitions = graph._edgeDefinitions(directed_relation, undirected_relation); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// @endDocuBlock //////////////////////////////////////////////////////////////////////////////// @@ -1446,25 +1467,80 @@ var _edgeDefinitions = function () { //////////////////////////////////////////////////////////////////////////////// -/// @brief extend a list of edge definitions +/// @startDocuBlock JSF_general_graph_extend_edge_definitions +/// +/// In order to add more edge definitions to the graph before creating +/// this function can be used to add more definitions to the initial list. +/// +/// @EXAMPLES +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphEdgeDefinitionsExtend} +/// var graph = require("org/arangodb/general-graph"); +/// directed_relation = graph._directedRelation("lives_in", "user", "city"); +/// undirected_relation = graph._directedRelation("knows", "user"); +/// edgedefinitions = graph._edgeDefinitions(directed_relation); +/// edgedefinitions = graph._extendEdgeDefinitions(undirected_relation); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// @endDocuBlock //////////////////////////////////////////////////////////////////////////////// - var _extendEdgeDefinitions = function (edgeDefinition) { - var args = arguments, i = 0; - Object.keys(args).forEach(function (x) { - i++; - if (i === 1) {return;} - edgeDefinition.push(args[x]); - }); + Object.keys(args).forEach( + function (x) { + i++; + if (i === 1) { + return; + } + edgeDefinition.push(args[x]); + } + ); }; //////////////////////////////////////////////////////////////////////////////// /// @brief create a new graph //////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +/// @startDocuBlock JSF_general_graph_create +/// `general-graph._create(graph-name, edge-definitions, orphan-collections)` +/// *Create a graph* +/// +/// +/// The creation of a graph requires the name of the graph and a definition of its edges. +/// +/// For every type of edge definition a convenience method exists that can be used to create a graph. +/// Optionaly a list of vertex collections can be added, which are not used in any edge definition. +/// These collections are refered to as orphan collections within this chapter. +/// All collections used within the creation process are created if they do not exist. +/// +/// * *graph-name*: string - unique identifier of the graph +/// * *edge-definitions*: array - list of edge definition objects +/// * *orphan-collections*: array - list of additonal vertex collection names +/// +/// @EXAMPLES +/// +/// Create an empty graph, edge definitions can be added at runtime: +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphCreateGraph} +/// var graph = require("org/arangodb/general-graph"); +/// g = graph._create("mygraph"); +/// ~ graph._drop("mygraph"); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// Create a graph with edge definitions and orphan collections: +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphCreateGraph2} +/// var graph = require("org/arangodb/general-graph"); +/// g = graph._create("mygraph", [graph._undirectedRelationDefinition("relation", ["male", "female"])], ["sessions"]); +/// ~ graph._drop("mygraph"); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// @endDocuBlock +/// +//////////////////////////////////////////////////////////////////////////////// var _create = function (graphName, edgeDefinitions, orphanCollections) { @@ -1563,6 +1639,211 @@ var createHiddenProperty = function(obj, name, value) { }); obj[name] = value; }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief helper for updating binded collections +//////////////////////////////////////////////////////////////////////////////// +var removeEdge = function (edgeId, options, self) { + options = options || {}; + var edgeCollection = edgeId.split("/")[0]; + var graphs = getGraphCollection().toArray(); + self.__idsToRemove.push(edgeId); + self.__collectionsToLock.push(edgeCollection); + graphs.forEach( + function(graph) { + var edgeDefinitions = graph.edgeDefinitions; + if (graph.edgeDefinitions) { + edgeDefinitions.forEach( + function(edgeDefinition) { + var from = edgeDefinition.from; + var to = edgeDefinition.to; + var collection = edgeDefinition.collection; + // if collection of edge to be deleted is in from or to + if (from.indexOf(edgeCollection) !== -1 || to.indexOf(edgeCollection) !== -1) { + //search all edges of the graph + var edges = db[collection].toArray(); + edges.forEach( + function (edge) { + // if from is + if(self.__idsToRemove.indexOf(edge._id) === -1) { + if (edge._from === edgeId || edge._to === edgeId) { + removeEdge(edge._id, options, self); + } + } + } + ); + } + } + ); + } + } + ); + return; +}; + +var bindEdgeCollections = function(self, edgeCollections) { + _.each(edgeCollections, function(key) { + var obj = db._collection(key); + var wrap = wrapCollection(obj); + // save + var old_save = wrap.save; + wrap.save = function(from, to, data) { + //check, if edge is allowed + self.__edgeDefinitions.forEach( + function(edgeDefinition) { + if (edgeDefinition.collection === key) { + var fromCollection = from.split("/")[0]; + var toCollection = to.split("/")[0]; + if (! _.contains(edgeDefinition.from, fromCollection) + || ! _.contains(edgeDefinition.to, toCollection)) { + throw "Edge is not allowed between " + from + " and " + to + "."; + } + } + } + ); + return old_save(from, to, data); + }; + + // remove + wrap.remove = function(edgeId, options) { + var result; + //if _key make _id (only on 1st call) + if (edgeId.indexOf("/") === -1) { + edgeId = key + "/" + edgeId; + } + removeEdge(edgeId, options, self); + + try { + db._executeTransaction({ + collections: { + write: self.__collectionsToLock + }, + action: function (params) { + var db = require("internal").db; + params.ids.forEach( + function(edgeId) { + if (params.options) { + db._remove(edgeId, params.options); + } else { + db._remove(edgeId); + } + } + ); + }, + params: { + ids: self.__idsToRemove, + options: options + } + }); + result = true; + } catch (e) { + result = false; + } + self.__idsToRemove = []; + self.__collectionsToLock = []; + return result; + }; + + self[key] = wrap; + }); +}; + +var bindVertexCollections = function(self, vertexCollections) { + _.each(vertexCollections, function(key) { + var obj = db._collection(key); + var result; + var wrap = wrapCollection(obj); + var old_remove = wrap.remove; + wrap.remove = function(vertexId, options) { + //delete all edges using the vertex in all graphs + var graphs = getGraphCollection().toArray(); + var vertexCollectionName = vertexId.split("/")[0]; + self.__collectionsToLock.push(vertexCollectionName); + graphs.forEach( + function(graph) { + var edgeDefinitions = graph.edgeDefinitions; + if (graph.edgeDefinitions) { + edgeDefinitions.forEach( + function(edgeDefinition) { + var from = edgeDefinition.from; + var to = edgeDefinition.to; + var collection = edgeDefinition.collection; + if (from.indexOf(vertexCollectionName) !== -1 + || to.indexOf(vertexCollectionName) !== -1 + ) { + var edges = db._collection(collection).toArray(); + edges.forEach( + function(edge) { + if (edge._from === vertexId || edge._to === vertexId) { + removeEdge(edge._id, options, self); + } + } + ); + } + } + ); + } + } + ); + + try { + db._executeTransaction({ + collections: { + write: self.__collectionsToLock + }, + action: function (params) { + var db = require("internal").db; + params.ids.forEach( + function(edgeId) { + if (params.options) { + db._remove(edgeId, params.options); + } else { + db._remove(edgeId); + } + } + ); + if (params.options) { + db._remove(params.vertexId, params.options); + } else { + db._remove(params.vertexId); + } + }, + params: { + ids: self.__idsToRemove, + options: options, + vertexId: vertexId + } + }); + result = true; + } catch (e) { + result = false; + } + self.__idsToRemove = []; + self.__collectionsToLock = []; + + return result; + }; + self[key] = wrap; + }); + +}; +var updateBindCollections = function(graph) { + //remove all binded collections + Object.keys(graph).forEach( + function(key) { + if(key.substring(0,1) !== "_") { + delete graph[key]; + } + } + ); + graph.__edgeDefinitions.forEach( + function(edgeDef) { + bindEdgeCollections(graph, [edgeDef.collection]); + bindVertexCollections(graph, edgeDef.from); + bindVertexCollections(graph, edgeDef.to); + } + ); + bindVertexCollections(graph, graph.__orphanCollections); +}; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor. @@ -1624,7 +1905,7 @@ var createHiddenProperty = function(obj, name, value) { /// var examples = require("org/arangodb/graph-examples/example-graph.js"); /// var g = examples.loadGraph("social"); /// g.female.save({name: "Lynda", _key: "linda"}); -/// g.female.update({name: "Linda", _key: "linda"}); +/// g.female.update("female/linda", {name: "Linda", _key: "linda"}); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// /// @endDocuBlock @@ -1763,193 +2044,34 @@ var Graph = function(graphName, edgeDefinitions, vertexCollections, edgeCollecti createHiddenProperty(this, "__idsToRemove", []); createHiddenProperty(this, "__collectionsToLock", []); createHiddenProperty(this, "__orphanCollections", orphanCollections); + updateBindCollections(self); - // fills this.__idsToRemove and this.__collectionsToLock - var removeEdge = function (edgeId, options) { - options = options || {}; - var edgeCollection = edgeId.split("/")[0]; - var graphs = getGraphCollection().toArray(); - self.__idsToRemove.push(edgeId); - self.__collectionsToLock.push(edgeCollection); - graphs.forEach( - function(graph) { - var edgeDefinitions = graph.edgeDefinitions; - if (graph.edgeDefinitions) { - edgeDefinitions.forEach( - function(edgeDefinition) { - var from = edgeDefinition.from; - var to = edgeDefinition.to; - var collection = edgeDefinition.collection; - // if collection of edge to be deleted is in from or to - if (from.indexOf(edgeCollection) !== -1 || to.indexOf(edgeCollection) !== -1) { - //search all edges of the graph - var edges = db[collection].toArray(); - edges.forEach( - function (edge) { - // if from is - if(self.__idsToRemove.indexOf(edge._id) === -1) { - if (edge._from === edgeId || edge._to === edgeId) { - removeEdge(edge._id, options); - } - } - } - ); - } - } - ); - } - } - ); - return; - }; - - - _.each(vertexCollections, function(obj, key) { - var result; - var wrap = wrapCollection(obj); - var old_remove = wrap.remove; - wrap.remove = function(vertexId, options) { - //delete all edges using the vertex in all graphs - var graphs = getGraphCollection().toArray(); - var vertexCollectionName = vertexId.split("/")[0]; - self.__collectionsToLock.push(vertexCollectionName); - graphs.forEach( - function(graph) { - var edgeDefinitions = graph.edgeDefinitions; - if (graph.edgeDefinitions) { - edgeDefinitions.forEach( - function(edgeDefinition) { - var from = edgeDefinition.from; - var to = edgeDefinition.to; - var collection = edgeDefinition.collection; - if (from.indexOf(vertexCollectionName) !== -1 - || to.indexOf(vertexCollectionName) !== -1 - ) { - var edges = db._collection(collection).toArray(); - edges.forEach( - function(edge) { - if (edge._from === vertexId || edge._to === vertexId) { - removeEdge(edge._id, options); - } - } - ); - } - } - ); - } - } - ); - - try { - db._executeTransaction({ - collections: { - write: self.__collectionsToLock - }, - action: function (params) { - var db = require("internal").db; - params.ids.forEach( - function(edgeId) { - if (params.options) { - db._remove(edgeId, params.options); - } else { - db._remove(edgeId); - } - } - ); - if (params.options) { - db._remove(params.vertexId, params.options); - } else { - db._remove(params.vertexId); - } - }, - params: { - ids: self.__idsToRemove, - options: options, - vertexId: vertexId - } - }); - result = true; - } catch (e) { - result = false; - } - self.__idsToRemove = []; - self.__collectionsToLock = []; - - return result; - }; - - self[key] = wrap; - }); - - _.each(edgeCollections, function(obj, key) { - var wrap = wrapCollection(obj); - // save - var old_save = wrap.save; - wrap.save = function(from, to, data) { - //check, if edge is allowed - edgeDefinitions.forEach( - function(edgeDefinition) { - if (edgeDefinition.collection === key) { - var fromCollection = from.split("/")[0]; - var toCollection = to.split("/")[0]; - if (! _.contains(edgeDefinition.from, fromCollection) - || ! _.contains(edgeDefinition.to, toCollection)) { - throw "Edge is not allowed between " + from + " and " + to + "."; - } - } - } - ); - return old_save(from, to, data); - }; - - // remove - wrap.remove = function(edgeId, options) { - var result; - //if _key make _id (only on 1st call) - if (edgeId.indexOf("/") === -1) { - edgeId = key + "/" + edgeId; - } - removeEdge(edgeId, options); - - try { - db._executeTransaction({ - collections: { - write: self.__collectionsToLock - }, - action: function (params) { - var db = require("internal").db; - params.ids.forEach( - function(edgeId) { - if (params.options) { - db._remove(edgeId, params.options); - } else { - db._remove(edgeId); - } - } - ); - }, - params: { - ids: self.__idsToRemove, - options: options - } - }); - result = true; - } catch (e) { - result = false; - } - self.__idsToRemove = []; - self.__collectionsToLock = []; - return result; - }; - - self[key] = wrap; - }); }; //////////////////////////////////////////////////////////////////////////////// -/// @brief load a graph. +/// @startDocuBlock JSF_general_graph_graph +/// `general-graph._graph(graph-name)` +/// *Load a graph* +/// +/// A graph can be loaded by its name. +/// +/// * *graph-name*: string - unique identifier of the graph +/// +/// @EXAMPLES +/// +/// Load a graph: +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphLoadGraph} +/// ~ var examples = require("org/arangodb/graph-examples/example-graph.js"); +/// ~ var g1 = examples.loadGraph("social"); +/// var graph = require("org/arangodb/general-graph"); +/// g = graph._graph("social"); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// @endDocuBlock +/// //////////////////////////////////////////////////////////////////////////////// var _graph = function(graphName) { @@ -2028,7 +2150,31 @@ var checkIfMayBeDropped = function(colName, graphName, graphs) { }; //////////////////////////////////////////////////////////////////////////////// -/// @brief drop a graph. +/// @startDocuBlock JSF_general_graph_drop +/// `general-graph._drop(graphName, dropCollections)` +/// *Remove a graph* +/// +/// A graph can be dropped by its name. +/// This will automatically drop al collections contained in the graph as +/// long as they are not used within other graphs. +/// To drop the collections, the optional parameter *drop-collections* can be set to *true*. +/// +/// * *graphName*: string - unique identifier of the graph +/// * *dropCollections*: boolean (optional) - define if collections should be dropped (default: false) +/// +/// @EXAMPLES +/// +/// Drop a graph: +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphDropGraph} +/// ~ var examples = require("org/arangodb/graph-examples/example-graph.js"); +/// ~ var g1 = examples.loadGraph("social"); +/// var graph = require("org/arangodb/general-graph"); +/// graph._drop("social"); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// @endDocuBlock +/// //////////////////////////////////////////////////////////////////////////////// var _drop = function(graphId, dropCollections) { @@ -2043,7 +2189,7 @@ var _drop = function(graphId, dropCollections) { throw err; } - if (dropCollections !== false) { + if (dropCollections === true) { var graph = gdb.document(graphId); var edgeDefinitions = graph.edgeDefinitions; edgeDefinitions.forEach( @@ -2091,6 +2237,7 @@ var _drop = function(graphId, dropCollections) { return true; }; + //////////////////////////////////////////////////////////////////////////////// /// @brief return all edge collections of the graph. //////////////////////////////////////////////////////////////////////////////// @@ -2373,7 +2520,70 @@ Graph.prototype._getVertexCollectionByName = function(name) { //////////////////////////////////////////////////////////////////////////////// -/// @brief get common neighbors of two vertices in the graph. +/// @startDocuBlock JSF_general_graph_common_neighbors +/// +/// `general_graph._listCommonNeighbors(vertex1Example, vertex2Examples, +/// optionsVertex1, optionsVertex2)` +/// *The general_graph._listCommonNeighbors function returns all common neighbors +/// of the vertices defined by the examples.* +/// +/// The function accepts an id, an example, a list of examples or even an empty +/// example as parameter for vertex1Example and vertex2Example. +/// +/// * String|Object|Array *vertex1Example* : An example for the desired +/// vertices (see below). +/// * String|Object|Array *vertex2Example* : An example for the desired +/// vertices (see below). +/// * Object *optionsVertex1* : Optional options, see below: +/// * Object *optionsVertex2* : Optional options, see below: +/// +/// Possible options and there defaults: +/// * String *direction* : The direction of the +/// edges. Possible values are *outbound*, *inbound* and *any* (default). +/// * String|Object|Array *edgeExamples* : A filter example +/// for the edges to the neighbors (see below). +/// * String|Object|Array *neighborExamples* : An example for +/// the desired neighbors (see below). +/// * String|Array *edgeCollectionRestriction* : One or multiple +/// edge collections that should be considered. +// * String|Array *vertexCollectionRestriction* : One or multiple +/// vertex collections that should be considered. +// / * Number *minDepth* : Defines the minimal +/// depth a path to a neighbor must have to be returned (default is 1). +/// * Number *maxDepth* : Defines the maximal +/// depth a path to a neighbor must have to be returned (default is 1). +/// +/// Examples for vertexExample: +/// * {} : Returns all possible vertices for this graph. +/// * *idString* : Returns the vertex with the id *idString*. +/// * {*key* : *value*} : Returns the vertices that match this example. +/// * [{*key1* : *value1*}, {*key2* : *value2*}] : Returns the vertices that +/// match one of the examples. +/// +/// @EXAMPLES +/// +/// A route planner example, all common neighbors of capitals. +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphModuleCommonNeighbors1} +/// ~ var db = require("internal").db; +/// var examples = require("org/arangodb/graph-examples/example-graph.js"); +/// var g = examples.loadGraph("routeplanner"); +/// g._listCommonNeighbors({isCapital : true}, {isCapital : true}); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// A route planner example, all common outbound neighbors of munich with any other location +/// which have a maximal depth of 2 : +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphModuleCommonNeighbors2} +/// ~ var db = require("internal").db; +/// var examples = require("org/arangodb/graph-examples/example-graph.js"); +/// var g = examples.loadGraph("routeplanner"); +/// |g._listCommonNeighbors('city/Munich', {}, {direction : 'outbound', maxDepth : 2}, +/// {direction : 'outbound', maxDepth : 2}); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// @endDocuBlock +// //////////////////////////////////////////////////////////////////////////////// Graph.prototype._listCommonNeighbors = function(vertex1Example, vertex2Example, optionsVertex1, optionsVertex2) { @@ -2400,7 +2610,70 @@ Graph.prototype._listCommonNeighbors = function(vertex1Example, vertex2Example, }; //////////////////////////////////////////////////////////////////////////////// -/// @brief get amount of common neighbors of two vertices in the graph. +/// @startDocuBlock JSF_general_graph_amount_common_neighbors +/// +/// `general_graph._amountCommonNeighbors(vertex1Example, vertex2Examples, +/// optionsVertex1, optionsVertex2)` +/// *The general_graph._amountCommonNeighbors function returns the amount of +/// common neighbors of the vertices defined by the examples.* +/// +/// The function accepts an id, an example, a list of examples or even an empty +/// example as parameter for vertex1Example and vertex2Example. +/// +/// * String|Object|Array *vertex1Example* : An example for the desired +/// vertices (see below). +/// * String|Object|Array *vertex2Example* : An example for the desired +/// vertices (see below). +/// * Object *optionsVertex1* : Optional options, see below: +/// * Object *optionsVertex2* : Optional options, see below: +/// +/// Possible options and there defaults: +/// * String *direction* : The direction of the +/// edges. Possible values are *outbound*, *inbound* and *any* (default). +/// * String|Object|Array *edgeExamples* : A filter example +/// for the edges to the neighbors (see below). +/// * String|Object|Array *neighborExamples* : An example for +/// the desired neighbors (see below). +/// * String|Array *edgeCollectionRestriction* : One or multiple +/// edge collections that should be considered. +// * String|Array *vertexCollectionRestriction* : One or multiple +/// vertex collections that should be considered. +// / * Number *minDepth* : Defines the minimal +/// depth a path to a neighbor must have to be returned (default is 1). +/// * Number *maxDepth* : Defines the maximal +/// depth a path to a neighbor must have to be returned (default is 1). +/// +/// Examples for vertexExample: +/// * {} : Returns all possible vertices for this graph. +/// * *idString* : Returns the vertex with the id *idString*. +/// * {*key* : *value*} : Returns the vertices that match this example. +/// * [{*key1* : *value1*}, {*key2* : *value2*}] : Returns the vertices that +/// match one of the examples. +/// +/// @EXAMPLES +/// +/// A route planner example, all common neighbors of capitals. +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphModuleCommonNeighborsAmount1} +/// ~ var db = require("internal").db; +/// var examples = require("org/arangodb/graph-examples/example-graph.js"); +/// var g = examples.loadGraph("routeplanner"); +/// g._amountCommonNeighbors({isCapital : true}, {isCapital : true}); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// A route planner example, all common outbound neighbors of munich with any other location +/// which have a maximal depth of 2 : +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphModuleCommonNeighborsAmount2} +/// ~ var db = require("internal").db; +/// var examples = require("org/arangodb/graph-examples/example-graph.js"); +/// var g = examples.loadGraph("routeplanner"); +/// |g._amountCommonNeighbors('city/Munich', {}, {direction : 'outbound', maxDepth : 2}, +/// {direction : 'outbound', maxDepth : 2}); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// @endDocuBlock +// //////////////////////////////////////////////////////////////////////////////// Graph.prototype._amountCommonNeighbors = function(vertex1Example, vertex2Example, optionsVertex1, optionsVertex2) { @@ -2442,7 +2715,60 @@ Graph.prototype._amountCommonNeighbors = function(vertex1Example, vertex2Example }; //////////////////////////////////////////////////////////////////////////////// -/// @brief get common properties of two vertices in the graph. +/// @startDocuBlock JSF_general_graph_common_properties +/// +/// `general_graph._listCommonProperties(vertex1Example, vertex2Examples, +/// options)` +/// *The general_graph._listCommonProperties function returns the vertices of +/// the graph that share common properties.* +/// +/// The function accepts an id, an example, a list of examples or even an empty +/// example as parameter for vertex1Example and vertex2Example. +/// +/// * String|Object|Array *vertex1Example* : An example for the desired +/// vertices (see below). +/// * String|Object|Array *vertex2Example* : An example for the desired +/// vertices (see below). +/// * Object *options* : Optional options, see below: +/// +/// Possible options and there defaults: +// * String|Array *vertex1CollectionRestriction* : One or multiple +/// vertex collections that should be considered. +/// * String|Array *vertex2CollectionRestriction* : One or multiple +/// vertex collections that should be considered. +/// * String|Array *ignoreProperties* : One or multiple +/// attributes of a document that should be ignored. +/// +/// Examples for vertexExample: +/// * {} : Returns all possible vertices for this graph. +/// * *idString* : Returns the vertex with the id *idString*. +/// * {*key* : *value*} : Returns the vertices that match this example. +/// * [{*key1* : *value1*}, {*key2* : *value2*}] : Returns the vertices that +/// match one of the examples. +/// +/// @EXAMPLES +/// +/// A route planner example, all locations with the same properties: +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphModuleProperties1} +/// ~ var db = require("internal").db; +/// var examples = require("org/arangodb/graph-examples/example-graph.js"); +/// var g = examples.loadGraph("routeplanner"); +/// g._listCommonProperties({}, {}); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// A route planner example, all cities which share same properties except for population. +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphModuleProperties2} +/// ~ var db = require("internal").db; +/// var examples = require("org/arangodb/graph-examples/example-graph.js"); +/// var g = examples.loadGraph("routeplanner"); +/// |g._listCommonProperties({}, {}, {vertex1CollectionRestriction : 'city', +/// vertex2CollectionRestriction : 'city' ,ignoreProperties: 'population'}); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// @endDocuBlock +// //////////////////////////////////////////////////////////////////////////////// Graph.prototype._listCommonProperties = function(vertex1Example, vertex2Example, options) { @@ -2467,7 +2793,60 @@ Graph.prototype._listCommonProperties = function(vertex1Example, vertex2Example, }; //////////////////////////////////////////////////////////////////////////////// -/// @brief get amount of common properties of two vertices in the graph. +/// @startDocuBlock JSF_general_graph_amount_common_properties +/// +/// `general_graph._amountCommonProperties(vertex1Example, vertex2Examples, +/// options)` +/// *The general_graph._amountCommonProperties function returns the amount of vertices of +/// the graph that share common properties.* +/// +/// The function accepts an id, an example, a list of examples or even an empty +/// example as parameter for vertex1Example and vertex2Example. +/// +/// * String|Object|Array *vertex1Example* : An example for the desired +/// vertices (see below). +/// * String|Object|Array *vertex2Example* : An example for the desired +/// vertices (see below). +/// * Object *options* : Optional options, see below: +/// +/// Possible options and there defaults: +// * String|Array *vertex1CollectionRestriction* : One or multiple +/// vertex collections that should be considered. +/// * String|Array *vertex2CollectionRestriction* : One or multiple +/// vertex collections that should be considered. +/// * String|Array *ignoreProperties* : One or multiple +/// attributes of a document that should be ignored. +/// +/// Examples for vertexExample: +/// * {} : Returns all possible vertices for this graph. +/// * *idString* : Returns the vertex with the id *idString*. +/// * {*key* : *value*} : Returns the vertices that match this example. +/// * [{*key1* : *value1*}, {*key2* : *value2*}] : Returns the vertices that +/// match one of the examples. +/// +/// @EXAMPLES +/// +/// A route planner example, all locations with the same properties: +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphModuleAmountProperties1} +/// ~ var db = require("internal").db; +/// var examples = require("org/arangodb/graph-examples/example-graph.js"); +/// var g = examples.loadGraph("routeplanner"); +/// g._amountCommonProperties({}, {}); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// A route planner example, all cities which share same properties except for population. +/// +/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphModuleAmountProperties2} +/// ~ var db = require("internal").db; +/// var examples = require("org/arangodb/graph-examples/example-graph.js"); +/// var g = examples.loadGraph("routeplanner"); +/// |g._amountCommonProperties({}, {}, {vertex1CollectionRestriction : 'city', +/// vertex2CollectionRestriction : 'city' ,ignoreProperties: 'population'}); +/// @END_EXAMPLE_ARANGOSH_OUTPUT +/// +/// @endDocuBlock +// //////////////////////////////////////////////////////////////////////////////// Graph.prototype._amountCommonProperties = function(vertex1Example, vertex2Example, options) { @@ -2495,6 +2874,8 @@ Graph.prototype._amountCommonProperties = function(vertex1Example, vertex2Exampl return returnHash; }; + + //////////////////////////////////////////////////////////////////////////////// /// @startDocuBlock JSF_general_graph__extendEdgeDefinitions /// Extends the edge definitions of a graph. If an orphan collection is used in this @@ -2509,11 +2890,13 @@ Graph.prototype._amountCommonProperties = function(vertex1Example, vertex2Exampl /// *Examples* /// /// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__extendEdgeDefinitions} -/// var examples = require("org/arangodb/graph-examples/example-graph.js"); -/// var ed1 = examples._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]); -/// var ed2 = examples._directedRelationDefinition("myEC2", ["myVC1"], ["myVC3"]); -/// var g = examples._create("myGraph", [ed1]); +/// var graph = require("org/arangodb/general-graph") +/// ~ if (graph._exists("myGraph")){var blub = graph._drop("myGraph", true);} +/// var ed1 = graph._directedRelation("myEC1", ["myVC1"], ["myVC2"]); +/// var ed2 = graph._directedRelation("myEC2", ["myVC1"], ["myVC3"]); +/// var g = graph._create("myGraph", [ed1]); /// g._extendEdgeDefinitions(ed2); +/// ~ var blub = graph._drop("myGraph", true); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// /// @endDocuBlock @@ -2556,9 +2939,11 @@ Graph.prototype._extendEdgeDefinitions = function(edgeDefinition) { findOrCreateCollectionsByEdgeDefinitions([edgeDefinition]); this.__edgeDefinitions.push(edgeDefinition); + db._graphs.update(this.__name, {edgeDefinitions: this.__edgeDefinitions}); this.__edgeCollections[edgeDefinition.collection] = db[edgeDefinition.collection]; edgeDefinition.from.forEach( function(vc) { + self[vc] = db[vc]; //remove from __orphanCollections var orphanIndex = self.__orphanCollections.indexOf(vc); if (orphanIndex !== -1) { @@ -2572,6 +2957,7 @@ Graph.prototype._extendEdgeDefinitions = function(edgeDefinition) { ); edgeDefinition.to.forEach( function(vc) { + self[vc] = db[vc]; //remove from __orphanCollections var orphanIndex = self.__orphanCollections.indexOf(vc); if (orphanIndex !== -1) { @@ -2583,6 +2969,7 @@ Graph.prototype._extendEdgeDefinitions = function(edgeDefinition) { } } ); + updateBindCollections(this); }; @@ -2662,11 +3049,13 @@ var changeEdgeDefinitionsForGraph = function(graph, edgeDefinition, newCollectio /// *Examples* /// /// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__editEdgeDefinition} -/// var examples = require("org/arangodb/graph-examples/example-graph.js"); -/// var ed1 = examples._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]); -/// var ed2 = examples._directedRelationDefinition("myEC1", ["myVC2"], ["myVC3"]); -/// var g = examples._create("myGraph", [ed1, ed2]); +/// var graph = require("org/arangodb/general-graph") +/// ~ if (graph._exists("myGraph")){var blub = graph._drop("myGraph", true);} +/// var ed1 = graph._directedRelation("myEC1", ["myVC1"], ["myVC2"]); +/// var ed2 = graph._directedRelation("myEC1", ["myVC2"], ["myVC3"]); +/// var g = graph._create("myGraph", [ed1, ed2]); /// g._editEdgeDefinition(ed2, true); +/// ~ var blub = graph._drop("myGraph", true); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// /// @endDocuBlock @@ -2713,6 +3102,7 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition) { changeEdgeDefinitionsForGraph(graph, edgeDefinition, newCollections, possibleOrphans, self); } ); + updateBindCollections(this); }; @@ -2725,17 +3115,19 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition) { /// /// `general-graph._deleteEdgeDefinition(edgeCollectionName)` /// -/// *edgeCollectionName* - string : name of edge collection defined in *collection* of the edge +/// * *edgeCollectionName*: string - name of edge collection defined in *collection* of the edge /// definition. /// /// *Examples* /// /// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__deleteEdgeDefinition} -/// var examples = require("org/arangodb/graph-examples/example-graph.js"); -/// var ed1 = examples._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]); -/// var ed2 = examples._directedRelationDefinition("myEC2", ["myVC1"], ["myVC3"]); -/// var g = examples._create("myGraph", [ed1, ed2]); +/// var graph = require("org/arangodb/general-graph") +/// ~ if (graph._exists("myGraph")){var blub = graph._drop("myGraph", true);} +/// var ed1 = graph._directedRelation("myEC1", ["myVC1"], ["myVC2"]); +/// var ed2 = graph._directedRelation("myEC2", ["myVC1"], ["myVC3"]); +/// var g = graph._create("myGraph", [ed1, ed2]); /// g._deleteEdgeDefinition("myEC1"); +/// ~ var blub = graph._drop("myGraph", true); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// /// @endDocuBlock @@ -2778,6 +3170,8 @@ Graph.prototype._deleteEdgeDefinition = function(edgeCollection) { } } ); + updateBindCollections(this); + }; //////////////////////////////////////////////////////////////////////////////// @@ -2787,16 +3181,18 @@ Graph.prototype._deleteEdgeDefinition = function(edgeCollection) { /// /// `general-graph._addVertexCollection(vertexCollectionName, createCollection)` /// -/// *vertexCollectionName* - string : name of vertex collection. -/// *createCollection* - bool : if true the collection will be created if it does not exist. Default: true. +/// * *vertexCollectionName* - string : name of vertex collection. +/// * *createCollection* - bool : if true the collection will be created if it does not exist. Default: true. /// /// *Examples* /// /// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__addVertexCollection} -/// var examples = require("org/arangodb/graph-examples/example-graph.js"); -/// var ed1 = examples._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]); -/// var g = examples._create("myGraph", [ed1, ed2]); +/// var graph = require("org/arangodb/general-graph") +/// ~ if (graph._exists("myGraph")){var blub = graph._drop("myGraph", true);} +/// var ed1 = graph._directedRelation("myEC1", ["myVC1"], ["myVC2"]); +/// var g = graph._create("myGraph", [ed1]); /// g._addVertexCollection("myVC3", true); +/// ~ var blub = graph._drop("myGraph", true); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// /// @endDocuBlock @@ -2830,6 +3226,8 @@ Graph.prototype._addVertexCollection = function(vertexCollectionName, createColl } this.__orphanCollections.push(vertexCollectionName); + this[vertexCollectionName] = db[vertexCollectionName]; + updateBindCollections(this); db._graphs.update(this.__name, {orphanCollections: this.__orphanCollections}); }; @@ -2843,11 +3241,13 @@ Graph.prototype._addVertexCollection = function(vertexCollectionName, createColl /// *Examples* /// /// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__orphanCollections} -/// var examples = require("org/arangodb/graph-examples/example-graph.js"); -/// var ed1 = examples._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]); -/// var g = examples._create("myGraph", [ed1]); +/// var graph = require("org/arangodb/general-graph") +/// ~ if (graph._exists("myGraph")){var blub = graph._drop("myGraph", true);} +/// var ed1 = graph._directedRelation("myEC1", ["myVC1"], ["myVC2"]); +/// var g = graph._create("myGraph", [ed1]); /// g._addVertexCollection("myVC3", true); /// g._orphanCollections(); +/// ~ var blub = graph._drop("myGraph", true); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// /// @endDocuBlock @@ -2860,26 +3260,28 @@ Graph.prototype._orphanCollections = function() { //////////////////////////////////////////////////////////////////////////////// /// @startDocuBlock JSF_general_graph__removeVertexCollection -/// Removes an orphan collection from the graph and deletes the collection, if it is not -/// used in any graph. +/// Removes an orphan collection from the graph. Optionally it deletes the collection, +/// if it is not used in any graph. /// /// `general-graph._removeVertexCollection(vertexCollectionName, dropCollection)` /// -/// *vertexCollectionName* - string : name of vertex collection. -/// *dropCollection* - bool : if true the collection will be dropped if it is not used in any graph. -/// Default: true. +/// *vertexCollectionName*: string - name of vertex collection. +/// *dropCollection*: bool (optional) - if true the collection will be dropped if it is +/// not used in any graph. Default: false. /// /// *Examples* /// /// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__removeVertexCollections} -/// var examples = require("org/arangodb/graph-examples/example-graph.js"); -/// var ed1 = examples._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]); -/// var g = examples._create("myGraph", [ed1]); +/// var graph = require("org/arangodb/general-graph") +/// ~ if (graph._exists("myGraph")){var blub = graph._drop("myGraph", true);} +/// var ed1 = graph._directedRelation("myEC1", ["myVC1"], ["myVC2"]); +/// var g = graph._create("myGraph", [ed1]); /// g._addVertexCollection("myVC3", true); /// g._addVertexCollection("myVC4", true); /// g._orphanCollections(); /// g._removeVertexCollection("myVC3"); /// g._orphanCollections(); +/// ~ var blub = graph._drop("myGraph", true); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// /// @endDocuBlock @@ -2902,14 +3304,16 @@ Graph.prototype._removeVertexCollection = function(vertexCollectionName, dropCol throw err; } this.__orphanCollections.splice(index, 1); + delete this[vertexCollectionName]; db._graphs.update(this.__name, {orphanCollections: this.__orphanCollections}); - if (dropCollection !== false) { + if (dropCollection === true) { var graphs = getGraphCollection().toArray(); if (checkIfMayBeDropped(vertexCollectionName, null, graphs)) { db._drop(vertexCollectionName); } } + updateBindCollections(this); }; @@ -2933,8 +3337,8 @@ Graph.prototype._PRINT = function(context) { // --SECTION-- MODULE EXPORTS // ----------------------------------------------------------------------------- -exports._undirectedRelationDefinition = _undirectedRelationDefinition; -exports._directedRelationDefinition = _directedRelationDefinition; +exports._undirectedRelation = _undirectedRelation; +exports._directedRelation = _directedRelation; exports._graph = _graph; exports._edgeDefinitions = _edgeDefinitions; exports._extendEdgeDefinitions = _extendEdgeDefinitions; diff --git a/js/apps/system/aardvark/frontend/js/modules/org/arangodb/graph/traversal.js b/js/apps/system/aardvark/frontend/js/modules/org/arangodb/graph/traversal.js index ffb44a7aa9..24fd201066 100644 --- a/js/apps/system/aardvark/frontend/js/modules/org/arangodb/graph/traversal.js +++ b/js/apps/system/aardvark/frontend/js/modules/org/arangodb/graph/traversal.js @@ -26,6 +26,7 @@ module.define("org/arangodb/graph/traversal", function(exports, module) { /// Copyright holder is triAGENS GmbH, Cologne, Germany /// /// @author Jan Steemann +/// @author Michael Hackstein /// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// @@ -48,7 +49,7 @@ var ArangoTraverser; //////////////////////////////////////////////////////////////////////////////// function clone (obj) { - if (obj === null || typeof(obj) !== "object") { + if (obj === null || typeof obj !== "object") { return obj; } diff --git a/js/common/modules/org/arangodb/general-graph.js b/js/common/modules/org/arangodb/general-graph.js index 27b5c99e77..1fcef5207f 100644 --- a/js/common/modules/org/arangodb/general-graph.js +++ b/js/common/modules/org/arangodb/general-graph.js @@ -1312,9 +1312,9 @@ AQLGenerator.prototype.next = function() { // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @startDocuBlock JSF_general_graph_undirectedRelationDefinition +/// @startDocuBlock JSF_general_graph_undirectedRelation /// -/// `general-graph._undirectedRelationDefinition(relationName, vertexCollections)` +/// `general-graph._undirectedRelation(relationName, vertexCollections)` /// *Define an undirected relation.* /// /// Defines an undirected relation with the name *relationName* using the @@ -1328,24 +1328,24 @@ AQLGenerator.prototype.next = function() { /// /// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphUndirectedRelationDefinition1} /// var graph = require("org/arangodb/general-graph"); -/// graph._undirectedRelationDefinition("friend", "user"); +/// graph._undirectedRelation("friend", "user"); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// /// To define a relation between several vertex collections: /// /// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphUndirectedRelationDefinition2} /// var graph = require("org/arangodb/general-graph"); -/// graph._undirectedRelationDefinition("marriage", ["female", "male"]); +/// graph._undirectedRelation("marriage", ["female", "male"]); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// @endDocuBlock /// //////////////////////////////////////////////////////////////////////////////// -var _undirectedRelationDefinition = function (relationName, vertexCollections) { +var _undirectedRelation = function (relationName, vertexCollections) { if (arguments.length < 2) { - throw "method _undirectedRelationDefinition expects 2 arguments"; + throw "method _undirectedRelation expects 2 arguments"; } if (typeof relationName !== "string" || relationName === "") { @@ -1368,9 +1368,9 @@ var _undirectedRelationDefinition = function (relationName, vertexCollections) { /// Define an directed relation. //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -/// @startDocuBlock JSF_general_graph_directedRelationDefinition +/// @startDocuBlock JSF_general_graph_directedRelation /// -/// `general-graph._directedRelationDefinition(relationName, fromVertexCollections, toVertexCollections)` +/// `general-graph._directedRelation(relationName, fromVertexCollections, toVertexCollections)` /// *Define a directed relation.* /// /// The *relationName* defines the name of this relation and references to the underlying edge collection. @@ -1383,18 +1383,18 @@ var _undirectedRelationDefinition = function (relationName, vertexCollections) { /// /// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphDirectedRelationDefinition} /// var graph = require("org/arangodb/general-graph"); -/// graph._directedRelationDefinition("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]); +/// graph._directedRelation("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// @endDocuBlock /// //////////////////////////////////////////////////////////////////////////////// -var _directedRelationDefinition = function ( +var _directedRelation = function ( relationName, fromVertexCollections, toVertexCollections) { if (arguments.length < 3) { - throw "method _directedRelationDefinition expects 3 arguments"; + throw "method _directedRelation expects 3 arguments"; } if (typeof relationName !== "string" || relationName === "") { @@ -1457,8 +1457,8 @@ var _list = function() { /// /// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphEdgeDefinitions} /// var graph = require("org/arangodb/general-graph"); -/// directed_relation = graph._directedRelationDefinition("lives_in", "user", "city"); -/// undirected_relation = graph._directedRelationDefinition("knows", "user"); +/// directed_relation = graph._directedRelation("lives_in", "user", "city"); +/// undirected_relation = graph._directedRelation("knows", "user"); /// edgedefinitions = graph._edgeDefinitions(directed_relation, undirected_relation); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// @@ -1488,8 +1488,8 @@ var _edgeDefinitions = function () { /// /// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphEdgeDefinitionsExtend} /// var graph = require("org/arangodb/general-graph"); -/// directed_relation = graph._directedRelationDefinition("lives_in", "user", "city"); -/// undirected_relation = graph._directedRelationDefinition("knows", "user"); +/// directed_relation = graph._directedRelation("lives_in", "user", "city"); +/// undirected_relation = graph._directedRelation("knows", "user"); /// edgedefinitions = graph._edgeDefinitions(directed_relation); /// edgedefinitions = graph._extendEdgeDefinitions(undirected_relation); /// @END_EXAMPLE_ARANGOSH_OUTPUT @@ -1546,7 +1546,7 @@ var _extendEdgeDefinitions = function (edgeDefinition) { /// /// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphCreateGraph2} /// var graph = require("org/arangodb/general-graph"); -/// g = graph._create("mygraph", [graph._undirectedRelationDefinition("relation", ["male", "female"])], ["sessions"]); +/// g = graph._create("mygraph", [graph._undirectedRelation("relation", ["male", "female"])], ["sessions"]); /// ~ graph._drop("mygraph"); /// @END_EXAMPLE_ARANGOSH_OUTPUT /// @@ -3600,8 +3600,8 @@ Graph.prototype._diameter = function(options) { /// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__extendEdgeDefinitions} /// var graph = require("org/arangodb/general-graph") /// ~ if (graph._exists("myGraph")){var blub = graph._drop("myGraph", true);} -/// var ed1 = graph._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]); -/// var ed2 = graph._directedRelationDefinition("myEC2", ["myVC1"], ["myVC3"]); +/// var ed1 = graph._directedRelation("myEC1", ["myVC1"], ["myVC2"]); +/// var ed2 = graph._directedRelation("myEC2", ["myVC1"], ["myVC3"]); /// var g = graph._create("myGraph", [ed1]); /// g._extendEdgeDefinitions(ed2); /// ~ var blub = graph._drop("myGraph", true); @@ -3759,8 +3759,8 @@ var changeEdgeDefinitionsForGraph = function(graph, edgeDefinition, newCollectio /// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__editEdgeDefinition} /// var graph = require("org/arangodb/general-graph") /// ~ if (graph._exists("myGraph")){var blub = graph._drop("myGraph", true);} -/// var ed1 = graph._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]); -/// var ed2 = graph._directedRelationDefinition("myEC1", ["myVC2"], ["myVC3"]); +/// var ed1 = graph._directedRelation("myEC1", ["myVC1"], ["myVC2"]); +/// var ed2 = graph._directedRelation("myEC1", ["myVC2"], ["myVC3"]); /// var g = graph._create("myGraph", [ed1, ed2]); /// g._editEdgeDefinition(ed2, true); /// ~ var blub = graph._drop("myGraph", true); @@ -3831,8 +3831,8 @@ Graph.prototype._editEdgeDefinitions = function(edgeDefinition) { /// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__deleteEdgeDefinition} /// var graph = require("org/arangodb/general-graph") /// ~ if (graph._exists("myGraph")){var blub = graph._drop("myGraph", true);} -/// var ed1 = graph._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]); -/// var ed2 = graph._directedRelationDefinition("myEC2", ["myVC1"], ["myVC3"]); +/// var ed1 = graph._directedRelation("myEC1", ["myVC1"], ["myVC2"]); +/// var ed2 = graph._directedRelation("myEC2", ["myVC1"], ["myVC3"]); /// var g = graph._create("myGraph", [ed1, ed2]); /// g._deleteEdgeDefinition("myEC1"); /// ~ var blub = graph._drop("myGraph", true); @@ -3897,7 +3897,7 @@ Graph.prototype._deleteEdgeDefinition = function(edgeCollection) { /// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__addVertexCollection} /// var graph = require("org/arangodb/general-graph") /// ~ if (graph._exists("myGraph")){var blub = graph._drop("myGraph", true);} -/// var ed1 = graph._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]); +/// var ed1 = graph._directedRelation("myEC1", ["myVC1"], ["myVC2"]); /// var g = graph._create("myGraph", [ed1]); /// g._addVertexCollection("myVC3", true); /// ~ var blub = graph._drop("myGraph", true); @@ -3951,7 +3951,7 @@ Graph.prototype._addVertexCollection = function(vertexCollectionName, createColl /// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__orphanCollections} /// var graph = require("org/arangodb/general-graph") /// ~ if (graph._exists("myGraph")){var blub = graph._drop("myGraph", true);} -/// var ed1 = graph._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]); +/// var ed1 = graph._directedRelation("myEC1", ["myVC1"], ["myVC2"]); /// var g = graph._create("myGraph", [ed1]); /// g._addVertexCollection("myVC3", true); /// g._orphanCollections(); @@ -3982,7 +3982,7 @@ Graph.prototype._orphanCollections = function() { /// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__removeVertexCollections} /// var graph = require("org/arangodb/general-graph") /// ~ if (graph._exists("myGraph")){var blub = graph._drop("myGraph", true);} -/// var ed1 = graph._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]); +/// var ed1 = graph._directedRelation("myEC1", ["myVC1"], ["myVC2"]); /// var g = graph._create("myGraph", [ed1]); /// g._addVertexCollection("myVC3", true); /// g._addVertexCollection("myVC4", true); @@ -4045,8 +4045,8 @@ Graph.prototype._PRINT = function(context) { // --SECTION-- MODULE EXPORTS // ----------------------------------------------------------------------------- -exports._undirectedRelationDefinition = _undirectedRelationDefinition; -exports._directedRelationDefinition = _directedRelationDefinition; +exports._undirectedRelation = _undirectedRelation; +exports._directedRelation = _directedRelation; exports._graph = _graph; exports._edgeDefinitions = _edgeDefinitions; exports._extendEdgeDefinitions = _extendEdgeDefinitions; diff --git a/js/common/modules/org/arangodb/graph-examples/example-graph.js b/js/common/modules/org/arangodb/graph-examples/example-graph.js index fa513ba02e..619f1c6abf 100644 --- a/js/common/modules/org/arangodb/graph-examples/example-graph.js +++ b/js/common/modules/org/arangodb/graph-examples/example-graph.js @@ -33,7 +33,7 @@ var createTraversalExample = function() { var g = Graph._create("knows_graph", - [Graph._undirectedRelationDefinition("knows", "persons")] + [Graph._undirectedRelation("knows", "persons")] ); var a = g.persons.save({name: "Alice", _key: "alice"})._id; var b = g.persons.save({name: "Bob", _key: "bob"})._id; @@ -50,7 +50,7 @@ var createSocialGraph = function() { var edgeDefinition = []; - edgeDefinition.push(Graph._undirectedRelationDefinition("relation", ["female", "male"])); + edgeDefinition.push(Graph._undirectedRelation("relation", ["female", "male"])); var g = Graph._create("social", edgeDefinition); var a = g.female.save({name: "Alice", _key: "alice"}); var b = g.male.save({name: "Bob", _key: "bob"}); diff --git a/js/common/tests/shell-general-graph.js b/js/common/tests/shell-general-graph.js index 8f0b40aac7..fb8abac3b2 100644 --- a/js/common/tests/shell-general-graph.js +++ b/js/common/tests/shell-general-graph.js @@ -54,8 +54,8 @@ function GeneralGraphCreationSuite() { var vn4 = "UnitTestVerticies4"; var gn = "UnitTestGraph"; var edgeDef = graph._edgeDefinitions( - graph._undirectedRelationDefinition(rn, vn1), - graph._directedRelationDefinition(rn1, + graph._undirectedRelation(rn, vn1), + graph._directedRelation(rn1, [vn1, vn2], [vn3, vn4] ) ); @@ -110,8 +110,8 @@ function GeneralGraphCreationSuite() { /// @brief test: Graph Creation //////////////////////////////////////////////////////////////////////////////// - test_undirectedRelationDefinition : function () { - var r = graph._undirectedRelationDefinition(rn, [vn1, vn2]); + test_undirectedRelation : function () { + var r = graph._undirectedRelation(rn, [vn1, vn2]); assertEqual(r, { collection: rn, @@ -121,8 +121,8 @@ function GeneralGraphCreationSuite() { }, - test_undirectedRelationDefinitionWithSingleCollection : function () { - var r = graph._undirectedRelationDefinition(rn, vn1); + test_undirectedRelationWithSingleCollection : function () { + var r = graph._undirectedRelation(rn, vn1); assertEqual(r, { collection: rn, @@ -132,9 +132,9 @@ function GeneralGraphCreationSuite() { }, - test_undirectedRelationDefinitionWithMissingName : function () { + test_undirectedRelationWithMissingName : function () { try { - graph._undirectedRelationDefinition("", [vn1, vn2]); + graph._undirectedRelation("", [vn1, vn2]); fail(); } catch (err) { @@ -142,21 +142,21 @@ function GeneralGraphCreationSuite() { } }, - test_undirectedRelationDefinitionWithTooFewArgs : function () { + test_undirectedRelationWithTooFewArgs : function () { try { - graph._undirectedRelationDefinition([vn1, vn2]); + graph._undirectedRelation([vn1, vn2]); fail(); } catch (err) { - assertEqual(err, "method _undirectedRelationDefinition expects 2 arguments"); + assertEqual(err, "method _undirectedRelation expects 2 arguments"); } }, - test_undirectedRelationDefinitionWithInvalidSecondArg : function () { + test_undirectedRelationWithInvalidSecondArg : function () { try { var param = {}; param[vn1] = vn2; - graph._undirectedRelationDefinition(rn, param); + graph._undirectedRelation(rn, param); fail(); } catch (err) { @@ -164,8 +164,8 @@ function GeneralGraphCreationSuite() { } }, - test_directedRelationDefinition : function () { - var r = graph._directedRelationDefinition(rn, + test_directedRelation : function () { + var r = graph._directedRelation(rn, [vn1, vn2], [vn3, vn4]); assertEqual(r, { @@ -176,9 +176,9 @@ function GeneralGraphCreationSuite() { }, - test_directedRelationDefinitionWithMissingName : function () { + test_directedRelationWithMissingName : function () { try { - graph._directedRelationDefinition("", + graph._directedRelation("", [vn1, vn2], [vn3, vn4]); fail(); } @@ -187,21 +187,21 @@ function GeneralGraphCreationSuite() { } }, - test_directedRelationDefinitionWithTooFewArgs : function () { + test_directedRelationWithTooFewArgs : function () { try { - graph._directedRelationDefinition([vn1, vn2], [vn3, vn4]); + graph._directedRelation([vn1, vn2], [vn3, vn4]); fail(); } catch (err) { - assertEqual(err, "method _directedRelationDefinition expects 3 arguments"); + assertEqual(err, "method _directedRelation expects 3 arguments"); } }, - test_directedRelationDefinitionWithInvalidSecondArg : function () { + test_directedRelationWithInvalidSecondArg : function () { try { var param = {}; param[vn1] = vn2; - graph._directedRelationDefinition(rn, param, vn3); + graph._directedRelation(rn, param, vn3); fail(); } catch (err) { @@ -211,11 +211,11 @@ function GeneralGraphCreationSuite() { }, - test_directedRelationDefinitionWithInvalidThirdArg : function () { + test_directedRelationWithInvalidThirdArg : function () { try { var param = {}; param[vn1] = vn2; - graph._directedRelationDefinition(rn, vn3, param); + graph._directedRelation(rn, vn3, param); fail(); } catch (err) { @@ -230,8 +230,8 @@ function GeneralGraphCreationSuite() { //with args assertEqual(graph._edgeDefinitions( - graph._undirectedRelationDefinition(rn, vn1), - graph._directedRelationDefinition(rn1, + graph._undirectedRelation(rn, vn1), + graph._directedRelation(rn1, [vn1, vn2], [vn3, vn4]) ), [ { @@ -255,12 +255,12 @@ function GeneralGraphCreationSuite() { //with args var ed =graph._edgeDefinitions( - graph._undirectedRelationDefinition("relationName", "vertexC1"), - graph._directedRelationDefinition("relationName", + graph._undirectedRelation("relationName", "vertexC1"), + graph._directedRelation("relationName", ["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]) ); graph._extendEdgeDefinitions(ed, - graph._undirectedRelationDefinition("relationName", "vertexC1") + graph._undirectedRelation("relationName", "vertexC1") ); assertEqual(ed, [ { @@ -290,8 +290,8 @@ function GeneralGraphCreationSuite() { var a = graph._create( gn, graph._edgeDefinitions( - graph._undirectedRelationDefinition(rn, vn1), - graph._directedRelationDefinition(rn1, [vn1, vn2], [vn3, vn4]) + graph._undirectedRelation(rn, vn1), + graph._directedRelation(rn1, [vn1, vn2], [vn3, vn4]) ) ); assertTrue(a.__vertexCollections.hasOwnProperty(vn1)); @@ -343,8 +343,8 @@ function GeneralGraphCreationSuite() { graph._create( "", graph._edgeDefinitions( - graph._undirectedRelationDefinition("relationName", "vertexC1"), - graph._directedRelationDefinition("relationName2", + graph._undirectedRelation("relationName", "vertexC1"), + graph._directedRelation("relationName2", ["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"] ) ) @@ -420,7 +420,7 @@ function GeneralGraphCreationSuite() { if(graph._exists(gn)) { graph._drop(gn, true); } - var edgeDef2 = [graph._directedRelationDefinition(rn, vn1, vn2)]; + var edgeDef2 = [graph._directedRelation(rn, vn1, vn2)]; var g = graph._create(gn, edgeDef2); var v1 = g[vn1].save({_key: "1"})._id; var v2 = g[vn2].save({_key: "2"})._id; @@ -458,7 +458,7 @@ function GeneralGraphCreationSuite() { test_deleteEdgeDefinitionFromExistingGraph1: function() { - var dr1 = graph._directedRelationDefinition(ec1, [vc1], [vc1, vc2]), + var dr1 = graph._directedRelation(ec1, [vc1], [vc1, vc2]), g1 = graph._create(gN1, [dr1]); try { @@ -474,9 +474,9 @@ function GeneralGraphCreationSuite() { test_deleteEdgeDefinitionFromExistingGraph2: function() { - var dr1 = graph._directedRelationDefinition(ec1, [vc1], [vc1, vc2]), - dr2 = graph._directedRelationDefinition(ec2, [vc3], [vc4, vc5]), - dr3 = graph._directedRelationDefinition(ec3, [vc4], [vc5]), + var dr1 = graph._directedRelation(ec1, [vc1], [vc1, vc2]), + dr2 = graph._directedRelation(ec2, [vc3], [vc4, vc5]), + dr3 = graph._directedRelation(ec3, [vc4], [vc5]), g1 = graph._create(gN1, [dr1, dr2, dr3]); assertEqual([dr1, dr2, dr3], g1.__edgeDefinitions); @@ -496,8 +496,8 @@ function GeneralGraphCreationSuite() { } catch(ignore) { } - var dr1 = graph._directedRelationDefinition(ec1, [vc1], [vc2]), - dr2 = graph._directedRelationDefinition(ec1, [vc2], [vc3]), + var dr1 = graph._directedRelation(ec1, [vc1], [vc2]), + dr2 = graph._directedRelation(ec1, [vc2], [vc3]), g1 = graph._create(gN1, [dr1]); try { @@ -518,9 +518,9 @@ function GeneralGraphCreationSuite() { test_extendEdgeDefinitionFromExistingGraph2: function() { - var dr1 = graph._directedRelationDefinition(ec1, [vc1], [vc1, vc2]), - dr2 = graph._directedRelationDefinition(ec2, [vc3], [vc4, vc5]), - dr2a = graph._directedRelationDefinition(ec2, [vc3], [vc4]), + var dr1 = graph._directedRelation(ec1, [vc1], [vc1, vc2]), + dr2 = graph._directedRelation(ec2, [vc3], [vc4, vc5]), + dr2a = graph._directedRelation(ec2, [vc3], [vc4]), g1 = graph._create(gN1, [dr1]), g2 = graph._create(gN2, [dr2]); @@ -554,9 +554,9 @@ function GeneralGraphCreationSuite() { } catch(ignore) { } - var dr1 = graph._directedRelationDefinition(ec1, [vc1], [vc1, vc2]), - dr2 = graph._directedRelationDefinition(ec2, [vc3], [vc4, vc5]), - dr3 = graph._directedRelationDefinition(ec3, [vc3], [vc4]), + var dr1 = graph._directedRelation(ec1, [vc1], [vc1, vc2]), + dr2 = graph._directedRelation(ec2, [vc3], [vc4, vc5]), + dr3 = graph._directedRelation(ec3, [vc3], [vc4]), g1 = graph._create(gN1, [dr1]), g2 = graph._create(gN2, [dr2]); @@ -572,8 +572,8 @@ function GeneralGraphCreationSuite() { }, test_editEdgeDefinitionFromExistingGraph1: function() { - var dr1 = graph._directedRelationDefinition(ec1, [vc1], [vc1, vc2]), - dr2 = graph._directedRelationDefinition(ec2, [vc3], [vc4, vc5]), + var dr1 = graph._directedRelation(ec1, [vc1], [vc1, vc2]), + dr2 = graph._directedRelation(ec2, [vc3], [vc4, vc5]), g1 = graph._create(gN1, [dr1]); try { @@ -589,9 +589,9 @@ function GeneralGraphCreationSuite() { test_editEdgeDefinitionFromExistingGraph2: function() { - var dr1 = graph._directedRelationDefinition(ec1, [vc1, vc2], [vc3, vc4]), - dr2 = graph._directedRelationDefinition(ec2, [vc1], [vc4]), - dr3 = graph._directedRelationDefinition(ec1, [vc5], [vc5]), + var dr1 = graph._directedRelation(ec1, [vc1, vc2], [vc3, vc4]), + dr2 = graph._directedRelation(ec2, [vc1], [vc4]), + dr3 = graph._directedRelation(ec1, [vc5], [vc5]), g1 = graph._create(gN1, [dr1, dr2]), g2 = graph._create(gN2, [dr1]); @@ -611,9 +611,9 @@ function GeneralGraphCreationSuite() { test_editEdgeDefinitionFromExistingGraph3: function() { - var dr1 = graph._directedRelationDefinition(ec1, [vc1], [vc1, vc2]), - dr2 = graph._directedRelationDefinition(ec1, [vc3], [vc4, vc5]), - dr3 = graph._directedRelationDefinition(ec2, [vc2], [vc2, vc3]), + var dr1 = graph._directedRelation(ec1, [vc1], [vc1, vc2]), + dr2 = graph._directedRelation(ec1, [vc3], [vc4, vc5]), + dr3 = graph._directedRelation(ec2, [vc2], [vc2, vc3]), g1 = graph._create(gN1, [dr1, dr3]), g2 = graph._create(gN2, [dr1]); @@ -670,10 +670,10 @@ function GeneralGraphAQLQueriesSuite() { var createInclExcl = function() { dropInclExcl(); - var inc = graph._directedRelationDefinition( + var inc = graph._directedRelation( included, [v1], [v1, v2] ); - var exc = graph._directedRelationDefinition( + var exc = graph._directedRelation( excluded, [v1], [v3] ); var g = graph._create(graphName, [inc, exc]); @@ -949,8 +949,8 @@ function ChainedFluentAQLResultsSuite() { var g; var edgeDef = []; - edgeDef.push(graph._undirectedRelationDefinition(isFriend, user)); - edgeDef.push(graph._directedRelationDefinition(hasBought, user, product)); + edgeDef.push(graph._undirectedRelation(isFriend, user)); + edgeDef.push(graph._directedRelation(hasBought, user, product)); var findBoughts = function(result, list) { @@ -1820,8 +1820,8 @@ function EdgesAndVerticesSuite() { g = graph._create( unitTestGraphName, graph._edgeDefinitions( - graph._undirectedRelationDefinition(ec1, vc1), - graph._directedRelationDefinition(ec2, + graph._undirectedRelation(ec1, vc1), + graph._directedRelation(ec2, [vc1, vc2], [vc3, vc4] ) ) @@ -1839,7 +1839,7 @@ function EdgesAndVerticesSuite() { graph._create( myGraphName, graph._edgeDefinitions( - graph._undirectedRelationDefinition(myEdgeColName, myVertexColName) + graph._undirectedRelation(myEdgeColName, myVertexColName) ) ); graph._drop(myGraphName, true); @@ -1855,7 +1855,7 @@ function EdgesAndVerticesSuite() { graph._create( myGraphName, graph._edgeDefinitions( - graph._undirectedRelationDefinition(myEdgeColName, myVertexColName) + graph._undirectedRelation(myEdgeColName, myVertexColName) ) ); graph._drop(myGraphName); @@ -1869,7 +1869,7 @@ function EdgesAndVerticesSuite() { graph._create( myGraphName, graph._edgeDefinitions( - graph._undirectedRelationDefinition(ec1, vc1) + graph._undirectedRelation(ec1, vc1) ) ); assertTrue(graph._exists(myGraphName)); @@ -1885,7 +1885,7 @@ function EdgesAndVerticesSuite() { graph._create( myGraphName, graph._edgeDefinitions( - graph._undirectedRelationDefinition(ec1, vc2) + graph._undirectedRelation(ec1, vc2) ) ); } catch (e) { @@ -1910,8 +1910,8 @@ function EdgesAndVerticesSuite() { graph._create( myGraphName, graph._edgeDefinitions( - graph._undirectedRelationDefinition(myED, myVD1), - graph._undirectedRelationDefinition(myED, myVD2) + graph._undirectedRelation(myED, myVD1), + graph._undirectedRelation(myED, myVD2) ) ); } catch (e) { @@ -2083,7 +2083,7 @@ function EdgesAndVerticesSuite() { var g2 = graph._create( myGraphName, graph._edgeDefinitions( - graph._directedRelationDefinition(myEC02, + graph._directedRelation(myEC02, [ec1], [myVC01] ) ) @@ -2158,25 +2158,25 @@ function EdgesAndVerticesSuite() { var g1 = graph._create( gN1, graph._edgeDefinitions( - graph._directedRelationDefinition(eC1, [eC4], [vC1]) + graph._directedRelation(eC1, [eC4], [vC1]) ) ); var g2 = graph._create( gN2, graph._edgeDefinitions( - graph._directedRelationDefinition(eC2, [eC1], [vC2]) + graph._directedRelation(eC2, [eC1], [vC2]) ) ); var g3 = graph._create( gN3, graph._edgeDefinitions( - graph._directedRelationDefinition(eC3, [eC2], [vC3]) + graph._directedRelation(eC3, [eC2], [vC3]) ) ); var g4 = graph._create( gN4, graph._edgeDefinitions( - graph._directedRelationDefinition(eC4, [eC3], [vC4]) + graph._directedRelation(eC4, [eC3], [vC4]) ) ); @@ -2288,7 +2288,7 @@ function GeneralGraphCommonNeighborsSuite() { testGraph = graph._create( "bla3", graph._edgeDefinitions( - graph._directedRelationDefinition(eColName, + graph._directedRelation(eColName, [v1ColName, v2ColName], [v1ColName, v2ColName] ) @@ -2506,7 +2506,7 @@ function OrphanCollectionSuite() { g1 = graph._create( gN1, graph._edgeDefinitions( - graph._directedRelationDefinition( + graph._directedRelation( eC1, [vC1], [vC1, vC2] ) ) @@ -2514,7 +2514,7 @@ function OrphanCollectionSuite() { g2 = graph._create( gN2, graph._edgeDefinitions( - graph._directedRelationDefinition( + graph._directedRelation( eC2, [vC3], [vC1] ) ) diff --git a/js/common/tests/shell-graph-traversal.js b/js/common/tests/shell-graph-traversal.js index 83eda88577..8e6bfd29a1 100644 --- a/js/common/tests/shell-graph-traversal.js +++ b/js/common/tests/shell-graph-traversal.js @@ -1924,8 +1924,8 @@ function GeneralGraphTraversalSuite () { cleanUp(); var edgeDef = []; - edgeDef.push(generalGraph._directedRelationDefinition(enDir, vnA, vnBDH)); - edgeDef.push(generalGraph._undirectedRelationDefinition(enUndir, [vnBDH, vnCEFGI])); + edgeDef.push(generalGraph._directedRelation(enDir, vnA, vnBDH)); + edgeDef.push(generalGraph._undirectedRelation(enUndir, [vnBDH, vnCEFGI])); g = generalGraph._create(gn, edgeDef); saveVertex(vnA, "A"); diff --git a/js/server/modules/org/arangodb/foxx/controller.js b/js/server/modules/org/arangodb/foxx/controller.js index eda6f33cc7..3bd538fad7 100644 --- a/js/server/modules/org/arangodb/foxx/controller.js +++ b/js/server/modules/org/arangodb/foxx/controller.js @@ -160,7 +160,8 @@ extend(Controller.prototype, { 'use strict'; var newRoute = internal.constructRoute(method, route, callback, this), requestContext = new RequestContext(this.allRoutes, this.models, newRoute, this.rootElement), - summary; + summary, + undocumentedBody; this.routingInfo.routes.push(newRoute); @@ -175,8 +176,8 @@ extend(Controller.prototype, { this.applicationContext.clearComments(); if (method === 'post' || method === 'put' || method === 'patch') { - var UndocumentedBody = require('org/arangodb/foxx').Model.extend(); - requestContext.bodyParam("undocumented body", "Undocumented body param", UndocumentedBody); + undocumentedBody = require('org/arangodb/foxx').Model.extend(); + requestContext.bodyParam("undocumented body", "Undocumented body param", undocumentedBody); } return requestContext; diff --git a/js/server/tests/ahuacatl-general-graph.js b/js/server/tests/ahuacatl-general-graph.js index e9a329aebd..8ebd2d4572 100644 --- a/js/server/tests/ahuacatl-general-graph.js +++ b/js/server/tests/ahuacatl-general-graph.js @@ -89,8 +89,8 @@ function ahuacatlQueryGeneralEdgesTestSuite() { graph._create( "bla3", graph._edgeDefinitions( - graph._undirectedRelationDefinition("UnitTestsAhuacatlEdge1", "UnitTestsAhuacatlVertex1"), - graph._directedRelationDefinition("UnitTestsAhuacatlEdge2", + graph._undirectedRelation("UnitTestsAhuacatlEdge1", "UnitTestsAhuacatlVertex1"), + graph._directedRelation("UnitTestsAhuacatlEdge2", ["UnitTestsAhuacatlVertex1", "UnitTestsAhuacatlVertex2"], ["UnitTestsAhuacatlVertex3", "UnitTestsAhuacatlVertex4"] ) @@ -303,7 +303,7 @@ function ahuacatlQueryGeneralCommonTestSuite() { graph._create( "bla3", graph._edgeDefinitions( - graph._directedRelationDefinition("UnitTestsAhuacatlEdge1", + graph._directedRelation("UnitTestsAhuacatlEdge1", ["UnitTestsAhuacatlVertex1", "UnitTestsAhuacatlVertex2"], ["UnitTestsAhuacatlVertex1", "UnitTestsAhuacatlVertex2"] ) @@ -493,8 +493,8 @@ function ahuacatlQueryGeneralPathsTestSuite() { var g = graph._create( "bla3", graph._edgeDefinitions( - graph._undirectedRelationDefinition("UnitTestsAhuacatlEdge1", "UnitTestsAhuacatlVertex1"), - graph._directedRelationDefinition("UnitTestsAhuacatlEdge2", + graph._undirectedRelation("UnitTestsAhuacatlEdge1", "UnitTestsAhuacatlVertex1"), + graph._directedRelation("UnitTestsAhuacatlEdge2", ["UnitTestsAhuacatlVertex1", "UnitTestsAhuacatlVertex2"], ["UnitTestsAhuacatlVertex3", "UnitTestsAhuacatlVertex4"] ) @@ -661,8 +661,8 @@ function ahuacatlQueryGeneralTraversalTestSuite() { var g = graph._create( "werKenntWen", graph._edgeDefinitions( - graph._undirectedRelationDefinition(KenntAnderenBerliner, "UnitTests_Berliner"), - graph._directedRelationDefinition(KenntAnderen, + graph._undirectedRelation(KenntAnderenBerliner, "UnitTests_Berliner"), + graph._directedRelation(KenntAnderen, ["UnitTests_Hamburger", "UnitTests_Frankfurter", "UnitTests_Berliner", "UnitTests_Leipziger"], ["UnitTests_Hamburger", "UnitTests_Frankfurter", "UnitTests_Berliner", "UnitTests_Leipziger"] ) @@ -1622,8 +1622,8 @@ function ahuacatlQueryGeneralCycleSSuite() { var g = graph._create( "werKenntWen", graph._edgeDefinitions( - graph._undirectedRelationDefinition(KenntAnderenBerliner, "UnitTests_Berliner"), - graph._directedRelationDefinition(KenntAnderen, + graph._undirectedRelation(KenntAnderenBerliner, "UnitTests_Berliner"), + graph._directedRelation(KenntAnderen, ["UnitTests_Hamburger", "UnitTests_Frankfurter", "UnitTests_Berliner", "UnitTests_Leipziger"], ["UnitTests_Hamburger", "UnitTests_Frankfurter", "UnitTests_Berliner", "UnitTests_Leipziger"] )