@@ -11,29 +11,21 @@ module.exports = Graph;
1111function Graph ( connection , body ) {
1212 this . _connection = connection ;
1313 this . _api = this . _connection . endpoint ( '_api' ) ;
14+ this . _gharial = this . _api . endpoint ( 'gharial/' + this . name ) ;
1415 extend ( this , body ) ;
1516}
1617
17- Graph . _GraphBaseCollection = GraphBaseCollection ;
1818Graph . VertexCollection = VertexCollection ;
1919Graph . EdgeCollection = EdgeCollection ;
2020
2121extend ( Graph . prototype , {
22- _post : function ( path , data , callback ) {
23- if ( ! callback ) callback = noop ;
24- this . _api . post ( 'gharial/' + this . name + '/' + path , data , callback ) ;
25- } ,
26- _delete : function ( path , data , callback ) {
27- if ( ! callback ) callback = noop ;
28- this . _api . delete ( 'gharial/' + this . name + '/' + path , data , callback ) ;
29- } ,
3022 drop : function ( dropCollections , callback ) {
3123 if ( typeof dropCollections === 'function' ) {
3224 callback = dropCollections ;
3325 dropCollections = undefined ;
3426 }
3527 if ( ! callback ) callback = noop ;
36- this . _api . delete ( 'gharial/' + this . name , {
28+ this . _gharial . delete ( {
3729 dropCollections : dropCollections
3830 } , callback ) ;
3931 } ,
@@ -46,14 +38,14 @@ extend(Graph.prototype, {
4638 } ) ;
4739 } ,
4840 addVertexCollection : function ( collectionName , callback ) {
49- this . _post ( 'vertex' , { collection : collectionName } , callback ) ;
41+ this . _gharial . post ( 'vertex' , { collection : collectionName } , callback ) ;
5042 } ,
5143 removeVertexCollection : function ( collectionName , dropCollection , callback ) {
5244 if ( typeof dropCollection === 'function' ) {
5345 callback = dropCollection ;
5446 dropCollection = undefined ;
5547 }
56- this . _delete ( 'vertex/' + collectionName , { dropCollection : dropCollection } , callback ) ;
48+ this . _gharial . delete ( 'vertex/' + collectionName , { dropCollection : dropCollection } , callback ) ;
5749 } ,
5850 edgeCollection : function ( collectionName , callback ) {
5951 if ( ! callback ) callback = noop ;
@@ -64,7 +56,7 @@ extend(Graph.prototype, {
6456 } ) ;
6557 } ,
6658 addEdgeDefinition : function ( definition , callback ) {
67- this . _post ( 'edge' , definition , callback ) ;
59+ this . _gharial . post ( 'edge' , definition , callback ) ;
6860 } ,
6961 replaceEdgeDefinition : function ( definitionName , definition , callback ) {
7062 if ( ! callback ) callback = noop ;
@@ -75,42 +67,28 @@ extend(Graph.prototype, {
7567 callback = dropCollection ;
7668 dropCollection = undefined ;
7769 }
78- this . _delete ( 'edge/' + definitionName , { dropCollection : dropCollection } , callback ) ;
70+ this . _gharial . delete ( 'edge/' + definitionName , { dropCollection : dropCollection } , callback ) ;
7971 }
8072} ) ;
8173
82- function GraphBaseCollection ( connection , body , graph ) {
74+ function VertexCollection ( connection , body , graph ) {
8375 this . graph = graph ;
8476 BaseCollection . call ( this , connection , body ) ;
77+ this . _gharial = this . _api . endpoint ( 'gharial/' + this . graph . name + '/vertex/' + this . name ) ;
8578}
86- inherits ( GraphBaseCollection , BaseCollection ) ;
87-
88- extend ( GraphBaseCollection . prototype , {
89- _documentPath : function ( documentHandle ) {
90- var tokens = documentHandle . split ( '/' ) ;
91- return this . _relativePath ( tokens [ tokens . length - 1 ] ) ;
92- }
93- } ) ;
94-
95- function VertexCollection ( connection , body , graph ) {
96- GraphBaseCollection . call ( this , connection , body , graph ) ;
97- }
98- inherits ( VertexCollection , GraphBaseCollection ) ;
79+ inherits ( VertexCollection , BaseCollection ) ;
9980
10081extend ( VertexCollection . prototype , {
101- _relativePath : function ( path ) {
102- return 'gharial/' + this . graph . name + '/vertex/' + this . name + '/' + ( path || '' ) ;
103- } ,
10482 vertex : function ( documentHandle , callback ) {
10583 if ( ! callback ) callback = noop ;
106- this . _api . get ( this . _documentPath ( documentHandle ) , function ( err , body ) {
84+ this . _gharial . get ( documentHandle , function ( err , body ) {
10785 if ( err ) callback ( err ) ;
10886 else callback ( null , body ) ;
10987 } ) ;
11088 } ,
11189 save : function ( data , callback ) {
11290 if ( ! callback ) callback = noop ;
113- this . _api . post ( this . _relativePath ( '' ) , data , {
91+ this . _gharial . post ( data , {
11492 collection : this . name
11593 } , function ( err , body ) {
11694 if ( err ) callback ( err ) ;
@@ -120,24 +98,23 @@ extend(VertexCollection.prototype, {
12098} ) ;
12199
122100function EdgeCollection ( connection , body , graph ) {
123- GraphBaseCollection . call ( this , connection , body , graph ) ;
101+ this . graph = graph ;
102+ BaseCollection . call ( this , connection , body ) ;
103+ this . _gharial = this . _api . endpoint ( 'gharial/' + this . graph . name + '/edge/' + this . name ) ;
124104}
125- inherits ( EdgeCollection , GraphBaseCollection ) ;
105+ inherits ( EdgeCollection , BaseCollection ) ;
126106
127107extend ( EdgeCollection . prototype , {
128- _relativePath : function ( path ) {
129- return 'gharial/' + this . graph . name + '/edge/' + this . name + '/' + ( path || '' ) ;
130- } ,
131108 edge : function ( documentHandle , callback ) {
132109 if ( ! callback ) callback = noop ;
133- this . _api . get ( this . _documentPath ( documentHandle ) , function ( err , body ) {
110+ this . _gharial . get ( documentHandle , function ( err , body ) {
134111 if ( err ) callback ( err ) ;
135112 else callback ( null , body ) ;
136113 } ) ;
137114 } ,
138115 save : function ( data , fromId , toId , callback ) {
139116 if ( ! callback ) callback = noop ;
140- this . _api . post ( this . _relativePath ( '' ) , data , {
117+ this . _gharial . post ( data , {
141118 collection : this . name ,
142119 from : fromId ,
143120 to : toId
0 commit comments