Skip to content

Commit a5c4a06

Browse files
committed
Rebuilt.
1 parent 43fbbe5 commit a5c4a06

File tree

4 files changed

+266
-82
lines changed

4 files changed

+266
-82
lines changed

dist/arango.all.js

Lines changed: 131 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@ function BaseCollection(connection, body) {
2424
}
2525
extend(BaseCollection.prototype, {
2626
_documentPath: function (documentHandle) {
27+
return (this.type === 3 ? 'edge/' : 'document/') + this._documentHandle(documentHandle);
28+
},
29+
_documentHandle: function (documentHandle) {
30+
if (documentHandle._id) {
31+
documentHandle = documentHandle._id;
32+
} else if (documentHandle._key) {
33+
documentHandle = documentHandle._key;
34+
}
2735
if (documentHandle.indexOf('/') === -1) {
2836
documentHandle = this.name + '/' + documentHandle;
2937
}
30-
return (this.type === 3 ? 'edge/' : 'document/') + documentHandle;
38+
return documentHandle;
3139
},
3240
_get: function (path, update, opts, callback) {
3341
if (typeof opts === 'function') {
@@ -181,7 +189,13 @@ extend(BaseCollection.prototype, {
181189
}
182190
if (!callback)
183191
callback = noop;
184-
this._api.post('import', data, extend({ type: 'auto' }, opts, { collection: this.name }), function (err, body) {
192+
this._api.request({
193+
method: 'POST',
194+
path: 'import',
195+
body: data,
196+
ld: Boolean(opts.type !== 'array'),
197+
qs: extend({}, opts, { collection: this.name })
198+
}, function (err, body) {
185199
if (err)
186200
callback(err);
187201
else
@@ -197,10 +211,7 @@ extend(DocumentCollection.prototype, {
197211
document: function (documentHandle, callback) {
198212
if (!callback)
199213
callback = noop;
200-
if (documentHandle.indexOf('/') === -1) {
201-
documentHandle = this.name + '/' + documentHandle;
202-
}
203-
this._api.get('document/' + documentHandle, function (err, body) {
214+
this._api.get('document/' + this._documentHandle(documentHandle), function (err, body) {
204215
if (err)
205216
callback(err);
206217
else
@@ -226,10 +237,7 @@ extend(EdgeCollection.prototype, {
226237
edge: function (documentHandle, callback) {
227238
if (!callback)
228239
callback = noop;
229-
if (documentHandle.indexOf('/') === -1) {
230-
documentHandle = this.name + '/' + documentHandle;
231-
}
232-
this._api.get('edge/' + documentHandle, function (err, body) {
240+
this._api.get('edge/' + this._documentHandle(documentHandle), function (err, body) {
233241
if (err)
234242
callback(err);
235243
else
@@ -241,20 +249,20 @@ extend(EdgeCollection.prototype, {
241249
callback = noop;
242250
this._api.post('edge/', data, {
243251
collection: this.name,
244-
from: fromId,
245-
to: toId
252+
from: this._documentHandle(fromId),
253+
to: this._documentHandle(toId)
246254
}, function (err, body) {
247255
if (err)
248256
callback(err);
249257
else
250258
callback(null, body);
251259
});
252260
},
253-
_edges: function (vertex, direction, callback) {
261+
_edges: function (documentHandle, direction, callback) {
254262
if (!callback)
255263
callback = noop;
256264
this._api.get('edges/' + this.name, {
257-
vertex: vertex,
265+
vertex: this._documentHandle(documentHandle),
258266
direction: direction
259267
}, function (err, body) {
260268
if (err)
@@ -322,7 +330,10 @@ Connection.defaults = {
322330
extend(Connection.prototype, {
323331
_resolveUrl: function (opts) {
324332
var url = this.config.url;
325-
if (!opts.absolutePath) url += '/_db/' + this.config.databaseName;
333+
if (!opts.absolutePath) {
334+
url += '/_db/' + this.config.databaseName;
335+
if (opts.basePath) url += '/' + opts.basePath;
336+
}
326337
url += opts.path ? (opts.path.charAt(0) === '/' ? '' : '/') + opts.path : '';
327338
if (opts.qs) url += '?' + (typeof opts.qs === 'string' ? opts.qs : qs.stringify(opts.qs));
328339
return url;
@@ -337,8 +348,15 @@ extend(Connection.prototype, {
337348
headers = {'content-type': 'text/plain'};
338349

339350
if (body && typeof body === 'object') {
340-
body = JSON.stringify(body);
341-
headers['content-type'] = 'application/json';
351+
if (opts.ld) {
352+
body = body.map(function (obj) {
353+
return JSON.stringify(obj);
354+
}).join('\r\n') + '\r\n';
355+
headers['content-type'] = 'application/x-ldjson';
356+
} else {
357+
body = JSON.stringify(body);
358+
headers['content-type'] = 'application/json';
359+
}
342360
}
343361

344362
request({
@@ -348,7 +366,7 @@ extend(Connection.prototype, {
348366
body: body
349367
}, function (err, response, rawBody) {
350368
if (err) callback(err);
351-
else if (!response.headers['content-type'].match(jsonMime)) callback(null, rawBody);
369+
else if (!response.headers['content-type'].match(jsonMime)) callback(null, rawBody, response);
352370
else {
353371
try {
354372
var body = JSON.parse(rawBody);
@@ -598,7 +616,21 @@ extend(Database.prototype, {
598616
properties = { name: properties };
599617
}
600618
var self = this;
601-
self._api.post('collection', properties, function (err, body) {
619+
self._api.post('collection', extend({ type: 2 }, properties), function (err, body) {
620+
if (err)
621+
callback(err);
622+
else
623+
callback(null, createCollection(self._connection, body));
624+
});
625+
},
626+
createEdgeCollection: function (properties, callback) {
627+
if (!callback)
628+
callback = noop;
629+
if (typeof properties === 'string') {
630+
properties = { name: properties };
631+
}
632+
var self = this;
633+
self._api.post('collection', extend({}, properties, { type: 3 }), function (err, body) {
602634
if (err)
603635
callback(err);
604636
else
@@ -623,15 +655,24 @@ extend(Database.prototype, {
623655
callback(null, createCollection(self._connection, body));
624656
});
625657
},
626-
collections: function (excludeSystem, callback) {
627-
if (typeof excludeSystem === 'function') {
628-
callback = excludeSystem;
629-
excludeSystem = undefined;
630-
}
658+
collections: function (callback) {
659+
if (!callback)
660+
callback = noop;
661+
var self = this;
662+
self._api.get('collection', { excludeSystem: true }, function (err, body) {
663+
if (err)
664+
callback(err);
665+
else
666+
callback(null, body.collections.map(function (data) {
667+
return createCollection(self._connection, data);
668+
}));
669+
});
670+
},
671+
allCollections: function (callback) {
631672
if (!callback)
632673
callback = noop;
633674
var self = this;
634-
self._api.get('collection', { excludeSystem: excludeSystem }, function (err, body) {
675+
self._api.get('collection', { excludeSystem: false }, function (err, body) {
635676
if (err)
636677
callback(err);
637678
else
@@ -761,15 +802,32 @@ extend(Database.prototype, {
761802
callback(null);
762803
});
763804
},
764-
truncate: function (excludeSystem, callback) {
765-
if (typeof excludeSystem === 'function') {
766-
callback = excludeSystem;
767-
excludeSystem = undefined;
768-
}
805+
truncate: function (callback) {
769806
if (!callback)
770807
callback = noop;
771808
var self = this;
772-
self._api.get('collection', { excludeSystem: excludeSystem }, function (err, body) {
809+
self._api.get('collection', { excludeSystem: true }, function (err, body) {
810+
if (err)
811+
callback(err);
812+
else {
813+
all(body.collections.map(function (data) {
814+
return function (cb) {
815+
self._api.put('collection/' + data.name + '/truncate', function (err, body) {
816+
if (err)
817+
cb(err);
818+
else
819+
cb(null, body);
820+
});
821+
};
822+
}), callback);
823+
}
824+
});
825+
},
826+
truncateAll: function (callback) {
827+
if (!callback)
828+
callback = noop;
829+
var self = this;
830+
self._api.get('collection', { excludeSystem: false }, function (err, body) {
773831
if (err)
774832
callback(err);
775833
else {
@@ -836,6 +894,39 @@ extend(Database.prototype, {
836894
else
837895
callback(null, new ArrayCursor(self._connection, body));
838896
});
897+
},
898+
functions: function (callback) {
899+
if (!callback)
900+
callback = noop;
901+
this._api.get('aqlfunction', function (err, body) {
902+
if (err)
903+
callback(err);
904+
else
905+
callback(null, body);
906+
});
907+
},
908+
createFunction: function (name, code, callback) {
909+
this._api.post('aqlfunction', {
910+
name: name,
911+
code: code
912+
}, function (err, body) {
913+
if (err)
914+
callback(err);
915+
else
916+
callback(null, body);
917+
});
918+
},
919+
dropFunction: function (name, group, callback) {
920+
if (typeof group === 'function') {
921+
callback = group;
922+
group = undefined;
923+
}
924+
this._api['delete']('aqlfunction/' + name, { group: Boolean(group) }, function (err, body) {
925+
if (err)
926+
callback(err);
927+
else
928+
callback(null, body);
929+
});
839930
}
840931
});
841932
},{"./collection":2,"./connection":3,"./cursor":4,"./graph":8,"./util/all":9,"./util/noop":10,"extend":18}],6:[function(require,module,exports){
@@ -857,6 +948,7 @@ extend(Endpoint.prototype, {
857948
},
858949
request: function (opts, callback) {
859950
opts = extend({}, opts);
951+
opts.basePath = this._path;
860952
opts.headers = extend({}, this._headers, opts.headers);
861953
return this._connection.request(opts, callback);
862954
},
@@ -876,7 +968,7 @@ extend(Endpoint.prototype, {
876968
path = '/' + path;
877969
this.request({
878970
method: 'get',
879-
path: this._path + path,
971+
path: path,
880972
qs: qs
881973
}, callback);
882974
},
@@ -901,7 +993,7 @@ extend(Endpoint.prototype, {
901993
path = '/' + path;
902994
this.request({
903995
method: 'post',
904-
path: this._path + path,
996+
path: path,
905997
body: body,
906998
qs: qs
907999
}, callback);
@@ -927,7 +1019,7 @@ extend(Endpoint.prototype, {
9271019
path = '/' + path;
9281020
this.request({
9291021
method: 'put',
930-
path: this._path + path,
1022+
path: path,
9311023
body: body,
9321024
qs: qs
9331025
}, callback);
@@ -953,7 +1045,7 @@ extend(Endpoint.prototype, {
9531045
path = '/' + path;
9541046
this.request({
9551047
method: 'patch',
956-
path: this._path + path,
1048+
path: path,
9571049
body: body,
9581050
qs: qs
9591051
}, callback);
@@ -974,7 +1066,7 @@ extend(Endpoint.prototype, {
9741066
path = '/' + path;
9751067
this.request({
9761068
method: 'delete',
977-
path: this._path + path,
1069+
path: path,
9781070
qs: qs
9791071
}, callback);
9801072
},
@@ -994,7 +1086,7 @@ extend(Endpoint.prototype, {
9941086
path = '/' + path;
9951087
this.request({
9961088
method: 'head',
997-
path: this._path + path,
1089+
path: path,
9981090
qs: qs
9991091
}, callback);
10001092
}
@@ -1159,8 +1251,8 @@ extend(EdgeCollection.prototype, {
11591251
callback = noop;
11601252
this._gharial.post(data, {
11611253
collection: this.name,
1162-
from: fromId,
1163-
to: toId
1254+
from: this._documentHandle(fromId),
1255+
to: this._documentHandle(toId)
11641256
}, function (err, body) {
11651257
if (err)
11661258
callback(err);

dist/arango.all.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)