|
35 | 35 |
|
36 | 36 | NODE = 0x4E,
|
37 | 37 | RELATIONSHIP = 0x52,
|
| 38 | + UNBOUND_RELATIONSHIP = 0x72, |
38 | 39 | PATH = 0x50,
|
39 | 40 |
|
40 | 41 | TINY_TEXT = 0x80,
|
|
114 | 115 | return s;
|
115 | 116 | }
|
116 | 117 | }
|
| 118 | + |
| 119 | + function UnboundRelationship(identity, type, properties) { |
| 120 | + this.identity = identity; |
| 121 | + this.type = type; |
| 122 | + this.properties = properties; |
| 123 | + |
| 124 | + this.bind = function bind(start, end) { |
| 125 | + return new Relationship(identity, start, end, type, properties); |
| 126 | + } |
| 127 | + |
| 128 | + this.toString = function toString() { |
| 129 | + var s = "-[:" + this.type; |
| 130 | + var keys = Object.keys(this.properties); |
| 131 | + if (keys.length > 0) { |
| 132 | + s += " {"; |
| 133 | + for(var i = 0; i < keys.length; i++) { |
| 134 | + if (i > 0) s += ","; |
| 135 | + s += keys[i] + ":" + JSON.stringify(this.properties[keys[i]]); |
| 136 | + } |
| 137 | + s += "}"; |
| 138 | + } |
| 139 | + s += "]->"; |
| 140 | + return s; |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + function Path(nodes, rels, sequence) { |
| 145 | + var last_node = nodes[0], |
| 146 | + entities = [last_node]; |
| 147 | + for (var i = 0; i < sequence.length; i += 2) { |
| 148 | + var rel_index = sequence[i], |
| 149 | + next_node = nodes[sequence[2 * i + 1]], |
| 150 | + rel; |
| 151 | + if (rel_index > 0) { |
| 152 | + rel = hydrate(rels[rel_index - 1]); |
| 153 | + } else { |
| 154 | + rel = hydrate(rels[-rel_index - 1]); |
| 155 | + } |
| 156 | + entities.push(rel.bind(next_node, last_node)) |
| 157 | + entities.push(next_node) |
| 158 | + } |
| 159 | + |
| 160 | + this.nodes = [entities[0]]; |
| 161 | + this.relationships = []; |
| 162 | + for (var i = 1; i < entities.length; i++) { |
| 163 | + if (i % 2 == 1) { |
| 164 | + this.nodes.push(entities[i]); |
| 165 | + } else { |
| 166 | + this.relationships.push(entities[i]); |
| 167 | + } |
| 168 | + } |
| 169 | + |
| 170 | + this.toString = function toString() { |
| 171 | + return "<Path>"; |
| 172 | + } |
| 173 | + } |
117 | 174 |
|
118 | 175 | function hydrate(x) {
|
119 | 176 | if (Array.isArray(x)) {
|
|
129 | 186 | case RELATIONSHIP:
|
130 | 187 | x = new Relationship(fields[0], fields[1], fields[2], fields[3], fields[4]);
|
131 | 188 | break;
|
| 189 | + case UNBOUND_RELATIONSHIP: |
| 190 | + x = new UnboundRelationship(fields[0], fields[1], fields[2]); |
| 191 | + break; |
| 192 | + case PATH: |
| 193 | + x = new Path(fields[0], fields[1], fields[2]); |
| 194 | + break; |
132 | 195 | }
|
133 | 196 | }
|
134 | 197 | return x;
|
|
344 | 407 |
|
345 | 408 | function Unpacker(data) {
|
346 | 409 | var p = 0,
|
347 |
| - view = new DataView(data.buffer); |
| 410 | + view = new DataView(data.buffer), |
348 | 411 | decoder = new TextDecoder();
|
349 | 412 |
|
350 | 413 | function read() {
|
|
598 | 661 | }
|
599 | 662 |
|
600 | 663 | var ws = new WebSocket("ws://localhost:7688/"),
|
601 |
| - msg = new Message(ws); |
| 664 | + msg = new Message(ws), |
602 | 665 | packer = new Packer(msg);
|
603 | 666 | ws.onmessage = function(event) {
|
604 | 667 | var reader = new FileReader();
|
|
0 commit comments