Skip to content

Commit b986c4b

Browse files
flipsideaseemk
authored andcommitted
unindex now supports optional key/value paramaters
1 parent 77cf907 commit b986c4b

2 files changed

Lines changed: 74 additions & 34 deletions

File tree

lib/Node._coffee

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,30 +160,36 @@ module.exports = class Node extends PropertyContainer
160160

161161
catch error
162162
throw adjustError error
163+
163164
#
164-
# Delete this node from the given index.
165+
# Delete this node from the given index under the key (optional) and value (optional).
165166
#
166167
# @param index {String} The name of the index, e.g. `'users'`.
168+
# @param key {String} The (optional) key to index under, e.g. `'username'`.
169+
# @param value {String} The (optional) value to index under, e.g. `'aseemk'`.
167170
# @param callback {Function}
168171
#
169-
unindex: (index, _) ->
172+
unindex: (index, key, value, _) ->
170173
try
171174
# TODO
172175
if not @exists
173-
throw new Error 'Node must exists before unindexing properties'
176+
throw new Error 'Node must exist before unindexing properties'
174177

175178
services = @db.getServices _
176-
# version = @db.getVersion _
177-
178-
# encodedKey = encodeURIComponent key
179-
# encodedValue = encodeURIComponent value
180-
url = "#{services.node_index}/#{index}/#{@id}"
181-
console.log("unindex")
182-
console.log status.NO_CONTENT
183-
console.log url
184-
console.log @self
185-
response = @_request.del url, _
186179

180+
if key
181+
encodedKey = encodeURIComponent key
182+
183+
if value
184+
encodedValue = encodeURIComponent value
185+
url = "#{services.node_index}/#{index}/#{encodedKey}/#{encodedValue}/#{@id}"
186+
187+
else
188+
url = "#{services.node_index}/#{index}/#{encodedKey}/#{@id}"
189+
else
190+
url = "#{services.node_index}/#{index}/#{@id}"
191+
192+
response = @_request.del url, _
187193

188194
if response.statusCode isnt status.NO_CONTENT
189195
# database error
@@ -194,7 +200,20 @@ module.exports = class Node extends PropertyContainer
194200

195201
catch error
196202
throw adjustError error
203+
204+
# helper for overloaded unindex() method:
205+
do (actual = @::unindex) =>
206+
@::unindex = (index, key, value, callback) ->
207+
if typeof key is 'function'
208+
callback = key
209+
key = null
210+
value = null
211+
else if typeof value is 'function'
212+
callback = value
213+
value = null
197214

215+
actual.call @, index, key, value, callback
216+
198217
#
199218
# Uniquely add this node to the given index under the given key-value pair.
200219
#

lib/Node.js

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Path = require("./Path");
1919

2020
module.exports = Node = (function(_super) {
21+
var _this = this;
2122

2223
__extends(Node, _super);
2324

@@ -33,7 +34,7 @@
3334

3435

3536

36-
Node.prototype.save = function Node_prototype_save__1(_) { var message, response, services, _ref, _ref1, __this = this; var __frame = { name: "Node_prototype_save__1", line: 36 }; return __func(_, this, arguments, Node_prototype_save__1, 0, __frame, function __$Node_prototype_save__1() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$Node_prototype_save__1() { return (function __$Node_prototype_save__1(__then) {
37+
Node.prototype.save = function Node_prototype_save__1(_) { var message, response, services, _ref, _ref1, __this = this; var __frame = { name: "Node_prototype_save__1", line: 37 }; return __func(_, this, arguments, Node_prototype_save__1, 0, __frame, function __$Node_prototype_save__1() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$Node_prototype_save__1() { return (function __$Node_prototype_save__1(__then) {
3738

3839

3940
if (__this.exists) {
@@ -70,7 +71,7 @@
7071

7172

7273

73-
Node.prototype["delete"] = function Node_prototype_delete__2(_, force) { var relationship, relationships, __this = this, __arguments = arguments; var __frame = { name: "Node_prototype_delete__2", line: 73 }; return __func(_, this, arguments, Node_prototype_delete__2, 0, __frame, function __$Node_prototype_delete__2() {
74+
Node.prototype["delete"] = function Node_prototype_delete__2(_, force) { var relationship, relationships, __this = this, __arguments = arguments; var __frame = { name: "Node_prototype_delete__2", line: 74 }; return __func(_, this, arguments, Node_prototype_delete__2, 0, __frame, function __$Node_prototype_delete__2() {
7475

7576
if ((force == null)) {
7677
force = false; } ;
@@ -97,7 +98,7 @@
9798
return __apply(__cb(_, __frame, 24, 13, _, true), Node.__super__["delete"], __this, __arguments, 0); }); }); }); };
9899

99100

100-
Node.prototype.index = function Node_prototype_index__3(index, key, value, _) { var encodedKey, encodedValue, response, services, url, version, __this = this; var __frame = { name: "Node_prototype_index__3", line: 100 }; return __func(_, this, arguments, Node_prototype_index__3, 3, __frame, function __$Node_prototype_index__3() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$Node_prototype_index__3() {
101+
Node.prototype.index = function Node_prototype_index__3(index, key, value, _) { var encodedKey, encodedValue, response, services, url, version, __this = this; var __frame = { name: "Node_prototype_index__3", line: 101 }; return __func(_, this, arguments, Node_prototype_index__3, 3, __frame, function __$Node_prototype_index__3() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$Node_prototype_index__3() {
101102

102103

103104
if (!__this.exists) {
@@ -131,19 +132,25 @@
131132

132133

133134

134-
Node.prototype.unindex = function Node_prototype_unindex__4(index, _) { var response, services, url, __this = this; var __frame = { name: "Node_prototype_unindex__4", line: 134 }; return __func(_, this, arguments, Node_prototype_unindex__4, 1, __frame, function __$Node_prototype_unindex__4() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$Node_prototype_unindex__4() {
135+
Node.prototype.unindex = function Node_prototype_unindex__4(index, key, value, _) { var encodedKey, encodedValue, response, services, url, __this = this; var __frame = { name: "Node_prototype_unindex__4", line: 135 }; return __func(_, this, arguments, Node_prototype_unindex__4, 3, __frame, function __$Node_prototype_unindex__4() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$Node_prototype_unindex__4() {
135136

136137

137138
if (!__this.exists) {
138139
return _(new Error("Node must exists before unindexing properties")); } ;
139140

140141
return __this.db.getServices(__cb(_, __frame, 6, 19, function ___(__0, __1) { services = __1;
141-
url = ((((("" + services.node_index) + "/") + index) + "/") + __this.id);
142-
console.log("unindex");
143-
console.log(status.NO_CONTENT);
144-
console.log(url);
145-
console.log(__this.self);
146-
return __this._request.del(url, __cb(_, __frame, 12, 19, function ___(__0, __2) { response = __2;
142+
if (key) {
143+
encodedKey = encodeURIComponent(key);
144+
if (value) {
145+
encodedValue = encodeURIComponent(value);
146+
url = ((((((((("" + services.node_index) + "/") + index) + "/") + encodedKey) + "/") + encodedValue) + "/") + __this.id); }
147+
else {
148+
url = ((((((("" + services.node_index) + "/") + index) + "/") + encodedKey) + "/") + __this.id); } ; }
149+
150+
else {
151+
url = ((((("" + services.node_index) + "/") + index) + "/") + __this.id); } ;
152+
153+
return __this._request.del(url, __cb(_, __frame, 18, 19, function ___(__0, __2) { response = __2;
147154
if ((response.statusCode !== status.NO_CONTENT)) {
148155
return _(response); } ; __then(); }, true)); }, true)); }); })(function ___(error, __result) { __tryCatch(_, function __$Node_prototype_unindex__4() { if (error) {
149156

@@ -152,15 +159,29 @@
152159

153160

154161

155-
Node.prototype.createRelationshipTo = function Node_prototype_createRelationshipTo__5(otherNode, type, data, _) { var __this = this; var __frame = { name: "Node_prototype_createRelationshipTo__5", line: 155 }; return __func(_, this, arguments, Node_prototype_createRelationshipTo__5, 3, __frame, function __$Node_prototype_createRelationshipTo__5() {
162+
(function(actual) {
163+
return Node.prototype.unindex = function(index, key, value, callback) {
164+
if ((typeof key === "function")) {
165+
callback = key;
166+
key = null;
167+
value = null; }
168+
else if ((typeof value === "function")) {
169+
callback = value;
170+
value = null; } ;
171+
172+
return actual.call(this, index, key, value, callback); };
173+
174+
})(Node.prototype.unindex);
175+
176+
Node.prototype.createRelationshipTo = function Node_prototype_createRelationshipTo__5(otherNode, type, data, _) { var __this = this; var __frame = { name: "Node_prototype_createRelationshipTo__5", line: 176 }; return __func(_, this, arguments, Node_prototype_createRelationshipTo__5, 3, __frame, function __$Node_prototype_createRelationshipTo__5() {
156177
return __this._createRelationship(__this, otherNode, type, data, __cb(_, __frame, 1, 13, _, true)); }); };
157178

158179

159-
Node.prototype.createRelationshipFrom = function Node_prototype_createRelationshipFrom__6(otherNode, type, data, _) { var __this = this; var __frame = { name: "Node_prototype_createRelationshipFrom__6", line: 159 }; return __func(_, this, arguments, Node_prototype_createRelationshipFrom__6, 3, __frame, function __$Node_prototype_createRelationshipFrom__6() {
180+
Node.prototype.createRelationshipFrom = function Node_prototype_createRelationshipFrom__6(otherNode, type, data, _) { var __this = this; var __frame = { name: "Node_prototype_createRelationshipFrom__6", line: 180 }; return __func(_, this, arguments, Node_prototype_createRelationshipFrom__6, 3, __frame, function __$Node_prototype_createRelationshipFrom__6() {
160181
return __this._createRelationship(otherNode, __this, type, data, __cb(_, __frame, 1, 13, _, true)); }); };
161182

162183

163-
Node.prototype._createRelationship = function Node_prototype__createRelationship__7(from, to, type, data, _) { var createRelationshipURL, message, otherNodeURL, response, _ref, _ref1, __this = this; var __frame = { name: "Node_prototype__createRelationship__7", line: 163 }; return __func(_, this, arguments, Node_prototype__createRelationship__7, 4, __frame, function __$Node_prototype__createRelationship__7() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$Node_prototype__createRelationship__7() {
184+
Node.prototype._createRelationship = function Node_prototype__createRelationship__7(from, to, type, data, _) { var createRelationshipURL, message, otherNodeURL, response, _ref, _ref1, __this = this; var __frame = { name: "Node_prototype__createRelationship__7", line: 184 }; return __func(_, this, arguments, Node_prototype__createRelationship__7, 4, __frame, function __$Node_prototype__createRelationship__7() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$Node_prototype__createRelationship__7() {
164185

165186

166187
createRelationshipURL = from._data["create_relationship"];
@@ -194,7 +215,7 @@
194215

195216

196217

197-
Node.prototype._getRelationships = function Node_prototype__getRelationships__8(direction, type, _) { var prefix, relationshipsURL, resp, types, _this, __this = this; var __frame = { name: "Node_prototype__getRelationships__8", line: 197 }; return __func(_, this, arguments, Node_prototype__getRelationships__8, 2, __frame, function __$Node_prototype__getRelationships__8() { _this = __this;
218+
Node.prototype._getRelationships = function Node_prototype__getRelationships__8(direction, type, _) { var prefix, relationshipsURL, resp, types, _this, __this = this; var __frame = { name: "Node_prototype__getRelationships__8", line: 218 }; return __func(_, this, arguments, Node_prototype__getRelationships__8, 2, __frame, function __$Node_prototype__getRelationships__8() { _this = __this;
198219

199220

200221
types = null;
@@ -230,23 +251,23 @@
230251

231252

232253

233-
Node.prototype.getRelationships = function Node_prototype_getRelationships__9(type, _) { var __this = this; var __frame = { name: "Node_prototype_getRelationships__9", line: 233 }; return __func(_, this, arguments, Node_prototype_getRelationships__9, 1, __frame, function __$Node_prototype_getRelationships__9() {
254+
Node.prototype.getRelationships = function Node_prototype_getRelationships__9(type, _) { var __this = this; var __frame = { name: "Node_prototype_getRelationships__9", line: 254 }; return __func(_, this, arguments, Node_prototype_getRelationships__9, 1, __frame, function __$Node_prototype_getRelationships__9() {
234255
return __this.all(type, __cb(_, __frame, 1, 13, _, true)); }); };
235256

236257

237-
Node.prototype.outgoing = function Node_prototype_outgoing__10(type, _) { var __this = this; var __frame = { name: "Node_prototype_outgoing__10", line: 237 }; return __func(_, this, arguments, Node_prototype_outgoing__10, 1, __frame, function __$Node_prototype_outgoing__10() {
258+
Node.prototype.outgoing = function Node_prototype_outgoing__10(type, _) { var __this = this; var __frame = { name: "Node_prototype_outgoing__10", line: 258 }; return __func(_, this, arguments, Node_prototype_outgoing__10, 1, __frame, function __$Node_prototype_outgoing__10() {
238259
return __this._getRelationships("outgoing", type, __cb(_, __frame, 1, 13, _, true)); }); };
239260

240261

241-
Node.prototype.incoming = function Node_prototype_incoming__11(type, _) { var __this = this; var __frame = { name: "Node_prototype_incoming__11", line: 241 }; return __func(_, this, arguments, Node_prototype_incoming__11, 1, __frame, function __$Node_prototype_incoming__11() {
262+
Node.prototype.incoming = function Node_prototype_incoming__11(type, _) { var __this = this; var __frame = { name: "Node_prototype_incoming__11", line: 262 }; return __func(_, this, arguments, Node_prototype_incoming__11, 1, __frame, function __$Node_prototype_incoming__11() {
242263
return __this._getRelationships("incoming", type, __cb(_, __frame, 1, 13, _, true)); }); };
243264

244265

245-
Node.prototype.all = function Node_prototype_all__12(type, _) { var __this = this; var __frame = { name: "Node_prototype_all__12", line: 245 }; return __func(_, this, arguments, Node_prototype_all__12, 1, __frame, function __$Node_prototype_all__12() {
266+
Node.prototype.all = function Node_prototype_all__12(type, _) { var __this = this; var __frame = { name: "Node_prototype_all__12", line: 266 }; return __func(_, this, arguments, Node_prototype_all__12, 1, __frame, function __$Node_prototype_all__12() {
246267
return __this._getRelationships("all", type, __cb(_, __frame, 1, 13, _, true)); }); };
247268

248269

249-
Node.prototype.getRelationshipNodes = function Node_prototype_getRelationshipNodes__13(rels, _) { var resp, traverseURL, _ref, _ref1, _ref2, _this, __this = this; var __frame = { name: "Node_prototype_getRelationshipNodes__13", line: 249 }; return __func(_, this, arguments, Node_prototype_getRelationshipNodes__13, 1, __frame, function __$Node_prototype_getRelationshipNodes__13() { _this = __this;
270+
Node.prototype.getRelationshipNodes = function Node_prototype_getRelationshipNodes__13(rels, _) { var resp, traverseURL, _ref, _ref1, _ref2, _this, __this = this; var __frame = { name: "Node_prototype_getRelationshipNodes__13", line: 270 }; return __func(_, this, arguments, Node_prototype_getRelationshipNodes__13, 1, __frame, function __$Node_prototype_getRelationshipNodes__13() { _this = __this;
250271

251272

252273
rels = ((rels instanceof Array) ? rels : [rels,]); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$Node_prototype_getRelationshipNodes__13() {
@@ -284,7 +305,7 @@
284305

285306

286307

287-
Node.prototype.path = function Node_prototype_path__14(to, type, direction, maxDepth, algorithm, _) { var data, end, length, nodes, pathURL, relationships, res, start, _this, __this = this; var __frame = { name: "Node_prototype_path__14", line: 287 }; return __func(_, this, arguments, Node_prototype_path__14, 5, __frame, function __$Node_prototype_path__14() { _this = __this;
308+
Node.prototype.path = function Node_prototype_path__14(to, type, direction, maxDepth, algorithm, _) { var data, end, length, nodes, pathURL, relationships, res, start, _this, __this = this; var __frame = { name: "Node_prototype_path__14", line: 308 }; return __func(_, this, arguments, Node_prototype_path__14, 5, __frame, function __$Node_prototype_path__14() { _this = __this;
288309

289310

290311
if ((maxDepth == null)) {
@@ -341,6 +362,6 @@
341362

342363
return Node;
343364

344-
})(PropertyContainer);
365+
}).call(this, PropertyContainer);
345366

346367
}).call(this);

0 commit comments

Comments
 (0)